Skip to content

Commit e531089

Browse files
authored
Get things working again (#4)
* wip * rx pins correct * bruh - I think i updated something here? * it's working, but at what cost. * Remove AV stuff * reformat
1 parent c9d8212 commit e531089

File tree

15 files changed

+398
-535
lines changed

15 files changed

+398
-535
lines changed

Cargo.lock

Lines changed: 244 additions & 224 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ publish = false
88
cfg-if = "1.0.0"
99
critical-section = "1.1.3"
1010

11-
embassy-executor = { version = "0.5.0", features = ["task-arena-size-8192", "defmt"] }
11+
embassy-executor = { version = "0.6.3", features = ["task-arena-size-8192", "defmt"] }
1212
embassy-sync = "0.5.0"
1313
embassy-time = { version = "0.3.1", features = ["defmt"]}
1414
embassy-time-driver = { version = "0.1.0", optional = true }
@@ -20,14 +20,14 @@ embedded-hal-bus = { version = "0.1.0", features = ["async"] }
2020
embedded-io-async = "0.6.1"
2121

2222
esp-backtrace = { version = "0.14.1", features = ["esp32c3", "exception-handler", "panic-handler", "println"] }
23-
esp-hal = { version = "0.18.0", features = ["esp32c3", "async", "opsram-2m", "defmt"] }
24-
esp-hal-embassy = { version = "0.1.0", features = ["esp32c3", "defmt", "integrated-timers", "time-timg0"]}
23+
esp-hal = { version = "0.22.0", features = ["esp32c3", "defmt"] }
24+
esp-hal-embassy = { version = "0.5.0", features = ["esp32c3", "defmt", "integrated-timers"]}
2525
esp-println = { version = "0.11.0", features = ["esp32c3", "defmt-espflash"] }
2626
defmt = "0.3.6"
2727

2828
nmea0183 = "0.4.0"
2929
micromath = "2.1.0"
30-
lora-phy = "3.0.0"
30+
lora-phy = "3.0.1"
3131

3232

3333
fugit = "0.3.7"

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ The reciever (`rx`) has:
1919
- an SX1278-based LoRA Radio
2020

2121
The transmitter (`tx`) additionally includes:
22-
- a u-blox NEO-M8N/MAX-M8N GNSS module,
23-
- a custom LiPo power regulation and monitoring
24-
25-
The full avionics setup (`av`) additionally includes:
26-
- a BMP280 altimeter,
27-
- a BMO055 IMU,
28-
- multiple n-MOSFET terminals for firing pyrotechnic charges,
29-
- additional hardware lockouts preventing unwanted firings.
22+
- a u-blox GNSS module,
3023

3124
### Software
3225
All written in async Rust, using [embassy](https://embassy.dev).
3326

34-
Each platform (`rx`, `tx`, and `av`) has a seperate binary, in `/src/bin/[platform].rs`.
27+
Each platform has a seperate binary, in `/src/bin/[platform].rs`.
3528

3629
Each prehipheral is maintained in a resuable library in `/src/[prehipheral].rs`
3730

resources/pinmap.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# rx v0.0.1
2+
LORA NSS -> Pin 1
3+
LORA MOSI -> Pin 2
4+
LORA MISO -> Pin 3
5+
LORA CLK -> Pin 4
6+
LORA RST -> Pin 6
7+
LORA IRQ -> Pin 5
8+
9+
# tx/rx breadboard
10+
LORA NSS -> Pin 0
11+
LORA MOSI -> Pin 1
12+
LORA MISO -> Pin 21
13+
LORA CLK -> Pin 20
14+
LORA RST -> Pin 10
15+
LORA IRQ -> Pin 2
16+
17+
UART RX -> Pin 5
18+
UART TX -> Pin 6

src/alt.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/bin/av.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/bin/rx.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,59 @@
22
#![no_main]
33
#![no_std]
44

5+
use defmt::info;
56
use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice;
6-
use embassy_executor::{task, Spawner};
7+
use embassy_executor::Spawner;
78
use embassy_time::Timer;
8-
9+
use esp_backtrace as _;
910
use esp_hal::{
10-
clock::{ClockControl, CpuClock},
11-
gpio::{any_pin::AnyPin, AnyInput, AnyOutput, Io, Level, Pull},
11+
gpio::{Input, Level, Output, Pin, Pull},
1212
peripherals::Peripherals,
13-
prelude::*,
14-
system::SystemControl,
1513
timer::timg::TimerGroup,
1614
};
1715

18-
use defmt::info;
19-
use esp_backtrace as _;
20-
2116
use stack_ripper::{lora, spi, state};
2217

23-
#[task]
18+
#[embassy_executor::task]
2419
async fn print_state() -> ! {
2520
loop {
2621
info!("{:?}", *state::STATE.lock().await);
2722
Timer::after_millis(5_000).await;
2823
}
2924
}
3025

31-
#[main]
32-
async fn main(_spawner: Spawner) -> () {
26+
#[esp_hal_embassy::main]
27+
async fn main(spawner: Spawner) {
3328
info!("Initializing");
3429

35-
let peripherals: Peripherals = Peripherals::take();
36-
let system = SystemControl::new(peripherals.SYSTEM);
37-
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze();
38-
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
30+
let peripherals: Peripherals = esp_hal::init(esp_hal::Config::default());
31+
let timg0 = TimerGroup::new(peripherals.TIMG0);
3932

40-
esp_hal_embassy::init(&clocks, timg0);
41-
42-
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
33+
esp_hal_embassy::init(timg0.timer0);
4334

4435
info!("Initializing compete");
4536

4637
// Set SPI bus
47-
let spi_clock = AnyPin::new(io.pins.gpio4);
48-
let spi_miso = AnyPin::new(io.pins.gpio3);
49-
let spi_mosi = AnyPin::new(io.pins.gpio2);
38+
let spi_clock = peripherals.GPIO4.degrade();
39+
let spi_miso = peripherals.GPIO3.degrade();
40+
let spi_mosi = peripherals.GPIO2.degrade();
5041

5142
let spi_bus = spi::init(
5243
peripherals.DMA,
5344
peripherals.SPI2,
54-
&clocks,
5545
spi_clock,
5646
spi_mosi,
5747
spi_miso,
5848
);
5949

60-
let lora_spi_csb = AnyOutput::new(io.pins.gpio1, Level::High);
61-
let lora_spi = SpiDevice::new(spi_bus, lora_spi_csb.into());
50+
let lora_spi_csb = Output::new(peripherals.GPIO1.degrade(), Level::High);
51+
52+
let lora_spi = SpiDevice::new(spi_bus, lora_spi_csb);
6253

63-
let lora_rst = AnyOutput::new(io.pins.gpio6, Level::High);
64-
let lora_irq = AnyInput::new(io.pins.gpio5, Pull::Up);
54+
let lora_rst = Output::new(peripherals.GPIO6.degrade(), Level::High);
55+
let lora_irq = Input::new(peripherals.GPIO5.degrade(), Pull::Up);
6556

66-
_spawner
67-
.spawn(lora::receive(lora_spi, lora_irq.into(), lora_rst.into()))
57+
spawner
58+
.spawn(lora::receive(lora_spi, lora_irq, lora_rst))
6859
.ok();
6960
}

src/bin/tx.rs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,67 @@
33
#![no_std]
44

55
use embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice;
6-
use embassy_executor::{task, Spawner};
7-
use embassy_time::Timer;
6+
use embassy_executor::Spawner;
87

98
use esp_hal::{
10-
clock::{ClockControl, CpuClock},
11-
gpio::{any_pin::AnyPin, AnyInput, AnyOutput, Io, Level, Pull},
9+
gpio::{Input, Level, Output, Pull},
1210
peripherals::Peripherals,
1311
prelude::*,
14-
system::SystemControl,
1512
timer::timg::TimerGroup,
16-
uart::{config::Config, TxRxPins, Uart},
13+
uart::{Config, Uart},
1714
};
1815

1916
use defmt::info;
2017
use esp_backtrace as _;
2118

22-
use stack_ripper::{gps, lora, spi, state};
23-
24-
#[task]
25-
async fn print_state() -> ! {
26-
loop {
27-
info!("{:?}", *state::STATE.lock().await);
28-
Timer::after_millis(5_000).await;
29-
}
30-
}
19+
use stack_ripper::{gps, lora, spi};
3120

3221
#[main]
3322
async fn main(_spawner: Spawner) -> () {
3423
info!("Initializing");
3524

36-
let peripherals: Peripherals = Peripherals::take();
37-
let system = SystemControl::new(peripherals.SYSTEM);
38-
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock160MHz).freeze();
39-
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
40-
41-
esp_hal_embassy::init(&clocks, timg0);
25+
let peripherals: Peripherals = esp_hal::init(esp_hal::Config::default());
26+
let timg0 = TimerGroup::new(peripherals.TIMG0);
4227

43-
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
28+
esp_hal_embassy::init(timg0.timer0);
4429

4530
info!("Initializing compete");
4631

4732
// Setup UART for GPS
48-
let uart_pins = Some(TxRxPins::new_tx_rx(io.pins.gpio21, io.pins.gpio20));
49-
let uart_config = Config::default().baudrate(9200);
50-
let uart = Uart::new_async_with_config(peripherals.UART0, uart_config, uart_pins, &clocks);
33+
let rx_pin = peripherals.GPIO8.degrade();
34+
let tx_pin = peripherals.GPIO7.degrade();
5135

52-
let (_, rx) = uart.split();
36+
let uart_config = Config::default().baudrate(9600);
37+
let uart = Uart::new_with_config(peripherals.UART0, uart_config, rx_pin, tx_pin)
38+
.unwrap()
39+
.into_async();
40+
41+
let (rx, _) = uart.split();
5342

5443
// Note that this task now owns the UART RX line completely
5544
// UART is a 1:1 interface, so this is fine
5645
_spawner.spawn(gps::sample_uart(rx)).unwrap();
5746

5847
// Setup SPI bus
59-
let spi_clock = AnyPin::new(io.pins.gpio0);
60-
let spi_miso = AnyPin::new(io.pins.gpio1);
61-
let spi_mosi = AnyPin::new(io.pins.gpio2);
48+
let spi_clock = peripherals.GPIO20.degrade();
49+
let spi_miso = peripherals.GPIO21.degrade();
50+
let spi_mosi = peripherals.GPIO1.degrade();
6251

6352
let spi_bus = spi::init(
6453
peripherals.DMA,
6554
peripherals.SPI2,
66-
&clocks,
6755
spi_clock,
6856
spi_mosi,
6957
spi_miso,
7058
);
7159

72-
let lora_spi_csb = AnyOutput::new(io.pins.gpio3, Level::Low);
73-
let lora_spi_device = SpiDevice::new(spi_bus, lora_spi_csb);
60+
let lora_spi_csb = Output::new(peripherals.GPIO0.degrade(), Level::High);
61+
let lora_spi = SpiDevice::new(spi_bus, lora_spi_csb);
7462

75-
let lora_rst = AnyOutput::new(io.pins.gpio9, Level::High);
76-
let lora_irq = AnyInput::new(io.pins.gpio10, Pull::Up);
63+
let lora_rst = Output::new(peripherals.GPIO10.degrade(), Level::High);
64+
let lora_irq = Input::new(peripherals.GPIO2.degrade(), Pull::Up);
7765

7866
_spawner
79-
.spawn(lora::transmit(lora_spi_device, lora_irq, lora_rst))
67+
.spawn(lora::transmit(lora_spi, lora_irq, lora_rst))
8068
.ok();
81-
82-
// Finally set up the task to print state
83-
_spawner.spawn(print_state()).ok();
8469
}

0 commit comments

Comments
 (0)