Skip to content

Commit

Permalink
INFRA - Use Rust procedural macros to reduce code duplication in boar…
Browse files Browse the repository at this point in the history
…d crates (#52)
  • Loading branch information
davidbeechey authored Nov 26, 2024
1 parent 9481fb1 commit 1fbfb77
Show file tree
Hide file tree
Showing 46 changed files with 638 additions and 243 deletions.
26 changes: 24 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[workspace]
members = [
"config",
"lib/*"
"lib/core",
"lib/io/*",
"lib/localisation",
"lib/sensors"
]
exclude = [
"boards/stm32l476rg",
Expand Down
5 changes: 4 additions & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[default.extend-words]
mosquitto = "mosquitto"
mosquitto = "mosquitto"

[files]
extend-exclude = ["telemetry/pnpm-lock.yaml"]
50 changes: 47 additions & 3 deletions boards/stm32f767zi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion boards/stm32f767zi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ critical-section = "1.1"
embedded-storage = "0.3.1"
static_cell = "2"

hyped_io = { path = "../../lib/io" }
hyped_sensors = { path = "../../lib/sensors" }

hyped_adc = { path = "../../lib/io/hyped_adc" }
hyped_adc_derive = { path = "../../lib/io/hyped_adc/hyped_adc_derive" }
hyped_i2c = { path = "../../lib/io/hyped_i2c" }
hyped_i2c_derive = { path = "../../lib/io/hyped_i2c/hyped_i2c_derive" }
hyped_gpio_input = { path = "../../lib/io/hyped_gpio_input" }
hyped_gpio_input_derive = { path = "../../lib/io/hyped_gpio_input/hyped_gpio_input_derive" }
4 changes: 2 additions & 2 deletions boards/stm32f767zi/src/bin/adc_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::adc::{Adc, AdcChannel};
use embassy_time::Timer;
use hyped_boards_stm32f767zi::io::adc::Stm32f767ziAdc;
use hyped_io::adc::HypedAdc;
use hyped_adc::HypedAdc;
use hyped_boards_stm32f767zi::io::Stm32f767ziAdc;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
Expand Down
29 changes: 26 additions & 3 deletions boards/stm32f767zi/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
pub mod adc;
pub mod gpio;
pub mod i2c;
use embassy_stm32::adc::{Adc, AnyAdcChannel, Instance};
use embassy_stm32::gpio::Input;
use embassy_stm32::{i2c::I2c, mode::Blocking};

use hyped_adc::HypedAdc;
use hyped_adc_derive::HypedAdc;
use hyped_gpio_input::HypedGpioInput;
use hyped_gpio_input_derive::HypedGpioInput;
use hyped_i2c::{HypedI2c, I2cError};
use hyped_i2c_derive::HypedI2c;

#[derive(HypedAdc)]
pub struct Stm32f767ziAdc<'d, T: Instance> {
adc: Adc<'d, T>,
channel: AnyAdcChannel<T>,
}

#[derive(HypedGpioInput)]
pub struct Stm32f767ziGpioInput {
pin: Input<'static>,
}

#[derive(HypedI2c)]
pub struct Stm32f767ziI2c<'d> {
i2c: I2c<'d, Blocking>,
}
21 changes: 0 additions & 21 deletions boards/stm32f767zi/src/io/adc.rs

This file was deleted.

20 changes: 0 additions & 20 deletions boards/stm32f767zi/src/io/gpio.rs

This file was deleted.

51 changes: 0 additions & 51 deletions boards/stm32f767zi/src/io/i2c.rs

This file was deleted.

4 changes: 2 additions & 2 deletions boards/stm32f767zi/src/tasks/keyence.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::io::gpio::Stm32f767ziGpio;
use crate::io::Stm32f767ziGpioInput;
use embassy_stm32::gpio::{Input, Pull};
use embassy_time::{Duration, Timer};
use hyped_sensors::keyence::Keyence;
Expand All @@ -7,7 +7,7 @@ use hyped_sensors::keyence::Keyence;
#[embassy_executor::task]
pub async fn read_keyence() -> ! {
let p = embassy_stm32::init(Default::default());
let mut keyence = Keyence::new(Stm32f767ziGpio::new(Input::new(p.PC13, Pull::Down)));
let mut keyence = Keyence::new(Stm32f767ziGpioInput::new(Input::new(p.PC13, Pull::Down)));

loop {
keyence.update_stripe_count();
Expand Down
2 changes: 1 addition & 1 deletion boards/stm32f767zi/src/tasks/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::io::i2c::Stm32f767ziI2c;
use crate::io::Stm32f767ziI2c;
use defmt_rtt as _;
use embassy_stm32::i2c::I2c;
use embassy_stm32::time::Hertz;
Expand Down
13 changes: 10 additions & 3 deletions boards/stm32l432kc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion boards/stm32l432kc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ critical-section = "1.1"
embedded-storage = "0.3.1"
static_cell = "2"

hyped_io = { path = "../../lib/io" }
hyped_sensors = { path = "../../lib/sensors" }
advanced-pid = { version = "0.2.2", default-features = false }
Loading

0 comments on commit 1fbfb77

Please sign in to comment.