Skip to content

Commit

Permalink
Fixed much of the cfg gating
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Dec 18, 2022
1 parent 7551687 commit 2ae21e1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions firmware/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ rustflags = [

[build]
# We compile without atomics, because its faster than using atomic trap handler
# target = "riscv32imc-unknown-none-elf"
target = "riscv32imc-unknown-none-elf"
# target = "thumbv7em-none-eabihf"
# target = "xtensa-esp32-none-elf"
target = "thumbv7em-none-eabihf"

[unstable]
build-std = ["core", "alloc"]
Expand Down
4 changes: 2 additions & 2 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ rust-version.workspace = true


[features]
# default = ["mcu-esp32c3", "imu-stubbed", "log-rtt", "net-wifi"]
default = ["mcu-nrf52840", "imu-stubbed", "log-usb-serial", "net-stubbed"]
default = ["mcu-esp32c3", "imu-stubbed", "log-rtt", "net-wifi"]
# default = ["mcu-nrf52840", "imu-stubbed", "log-uart", "net-stubbed"]
# default = ["mcu-esp32", "imu-stubbed", "log-uart", "net-wifi"]

# Supported microcontrollers
Expand Down
4 changes: 4 additions & 0 deletions firmware/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fn main() {
esp_xtensa: { any(feature = "mcu-esp32") },
esp_riscv: { any(feature = "mcu-esp32c3") },
esp: { any(esp_xtensa, esp_riscv) },
bbq: { all(
feature = "mcu-nrf52840",
any(feature = "log-uart", feature = "log-usb-serial")
)},
}

#[cfg(all(feature = "net-wifi", feature = "mcu-esp32c3"))]
Expand Down
7 changes: 4 additions & 3 deletions firmware/src/bbq_logger/embassy_uart.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use defmt::debug;
use defmt_bbq::DefmtConsumer;
use embassy_futures::yield_now;
use embassy_nrf::uarte::Error;

async fn logger_task(
pub async fn logger_task(
mut bbq: DefmtConsumer,
mut uart: crate::aliases::::UartConcrete<'static>,
) {
Expand All @@ -14,13 +15,13 @@ async fn logger_task(
continue;
};
let len = grant.buf().len();
uart.write(b"got data: ").await;
let _result = uart.write(b"got data: ").await;
match uart.write_from_ram(grant.buf()).await {
Err(Error::DMABufferNotInDataMemory) => {
// unreachable!("bbq should always be in RAM")
()
}
Err(Error::BufferZeroLength) | Err(Error::BufferTooLong) => (),
Err(Error::BufferTooLong) => (),
Ok(()) => (),
_ => (),
};
Expand Down
7 changes: 5 additions & 2 deletions firmware/src/bbq_logger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#[cfg(all(feature = "mcu-nrf52840", feature = "log-uart"))]
#[cfg(not(bbq))]
compile_error!("This module will only ever be compiled with the `bbq` feature");

#[cfg(all(feature = "log-uart"))]
#[path = "embassy_uart.rs"]
mod;

#[cfg(all(feature = "mcu-nrf52840", feature = "log-usb-serial"))]
#[cfg(all(bbq, feature = "log-usb-serial"))]
#[path = "embassy_usb.rs"]
mod;

Expand Down
14 changes: 7 additions & 7 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#![deny(unsafe_op_in_unsafe_fn)]

mod aliases;
mod bbq_logger;
mod globals;
mod imu;
mod networking;
mod peripherals;
mod utils;

#[cfg(bbq)]
mod bbq_logger;

use defmt::debug;
use embassy_executor::{task, Executor};
use embedded_hal::blocking::delay::DelayMs;
Expand All @@ -28,17 +30,15 @@ use xtensa_lx_rt::entry;

#[entry]
fn main() -> ! {
#[cfg(all(
feature = "defmt-bbq",
any(feature = "log-uart", feature = "log-usb-serial")
))]
#[cfg(bbq)]
let bbq = defmt_bbq::init().unwrap();

self::globals::setup();
debug!("Booted");
defmt::trace!("Trace");

let p = self::peripherals::::get_peripherals();
#[allow(unused)]
let (bbq_peripheral, mut p) = p.bbq_peripheral();

p.delay.delay_ms(500u32);
Expand All @@ -48,7 +48,7 @@ fn main() -> ! {
EXECUTOR.init(Executor::new()).run(move |spawner| {
spawner.spawn(network_task()).unwrap();
spawner.spawn(imu_task(p.i2c, p.delay)).unwrap();
#[cfg(feature = "defmt-bbq")]
#[cfg(bbq)]
spawner.spawn(logger_task(bbq, bbq_peripheral)).unwrap();
});
}
Expand All @@ -67,7 +67,7 @@ async fn imu_task(
crate::imu::imu_task(i2c, delay).await
}

#[cfg(feature = "defmt-bbq")]
#[cfg(bbq)]
#[task]
async fn logger_task(
bbq: defmt_bbq::DefmtConsumer,
Expand Down
10 changes: 7 additions & 3 deletions firmware/src/peripherals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<I2c, Delay, Uart, UsbDriver> Peripherals<I2c, Delay, Uart, UsbDriver> {

/// Type-level destructors for `Peripherals` which turn peripheral type into ().
impl<I2c, Delay, Uart, UsbDriver> Peripherals<I2c, Delay, Uart, UsbDriver> {
#[cfg(feature = "log-usb-serial")]
#[cfg(all(bbq, feature = "log-usb-serial"))]
pub fn bbq_peripheral(self) -> (UsbDriver, Peripherals<I2c, Delay, Uart, ()>) {
(
self.usb_driver,
Expand All @@ -85,8 +85,8 @@ impl<I2c, Delay, Uart, UsbDriver> Peripherals<I2c, Delay, Uart, UsbDriver> {
},
)
}
#[cfg(feature = "log-uart")]
pub fn bbq_peripheral(self) -> (UsbDriver, Peripherals<I2c, Delay, (), UsbDriver>) {
#[cfg(all(bbq, feature = "log-uart"))]
pub fn bbq_peripheral(self) -> (Uart, Peripherals<I2c, Delay, (), UsbDriver>) {
(
self.uart,
Peripherals {
Expand All @@ -97,4 +97,8 @@ impl<I2c, Delay, Uart, UsbDriver> Peripherals<I2c, Delay, Uart, UsbDriver> {
},
)
}
#[cfg(not(bbq))]
pub fn bbq_peripheral(self) -> ((), Peripherals<I2c, Delay, Uart, UsbDriver>) {
((), self)
}
}

0 comments on commit 2ae21e1

Please sign in to comment.