Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runner = 'probe-rs run --chip STM32F405RGTx'
target = "thumbv7em-none-eabi"

[env]
DEFMT_LOG = "trace"
DEFMT_LOG = "info"

[unstable]
build-std-features = ["panic_immediate_abort"]
Expand Down
48 changes: 25 additions & 23 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
name: Rust CI

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-latest

steps:
- name: Setup Rust
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build
run: cargo build --verbose --workspace --all --all-features
# - name: Test
# run: cargo test --verbose
- name: Clippy
run: cargo clippy --all-features --all --workspace
- name: Format
run: cargo fmt --verbose --all --check
steps:
- name: Clone repo
uses: actions/checkout@v6
with:
submodules: recursive
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo build --verbose --workspace --all --all-features
# - name: Test
# run: cargo test --verbose
- name: Clippy
run: cargo clippy --all-features --all --workspace
- name: Format
run: cargo fmt --verbose --all --check
55 changes: 22 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
[workspace]
members = ["msb-fw-rs","crates/*"]
resolver = "2"
resolver = "3"

[workspace.dependencies]
embassy-stm32 = { version = "0.1.0", features = ["defmt", "stm32f405rg", "unstable-pac", "memory-x", "time", "time-driver-any", "exti"] }
embassy-sync = { version = "0.6.1", features = ["defmt"] }
embassy-executor = { version = "0.7.0", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
embassy-time = { version = "0.4.0", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-embedded-hal = { version = "0.2.0", features = ["defmt"] }
embassy-futures = { version = "0.1.1", features = ["defmt"] }

defmt = "0.3.10"
defmt-rtt = "0.4.1"

cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.5"
embedded-hal = { version = "1.0.0", features = ["defmt-03"] }
embedded-hal-bus = { version = "0.2", features = ["async", "defmt-03"] }
embedded-io = { version = "0.6.1", features = ["defmt-03"] }
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
panic-probe = { version = "0.3.2", features = ["print-defmt", "defmt-error"] }
heapless = { version = "0.8.0", default-features = false }
static_cell = "2.1.0"
embassy-stm32 = { version = "0.6.0", features = ["defmt", "stm32f405rg", "unstable-pac", "memory-x", "time", "time-driver-any", "exti"] }
embassy-sync = { version = "0.8.0", features = ["defmt"] }
embassy-executor = { version = "0.10.0", features = ["executor-thread", "executor-interrupt", "defmt", "embassy-time-driver", "platform-cortex-m"] }
embassy-time = { version = "0.5.1", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-embedded-hal = { version = "0.6.0", features = ["defmt", "time"] }
embassy-futures = { version = "0.1.2", features = ["defmt"] }

defmt = "1"
defmt-rtt = "1"

cortex-m = { version = "0.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7"
embedded-hal = { version = "1", features = ["defmt-03"] }
embedded-hal-bus = { version = "0.3", features = ["async", "defmt-03"] }
embedded-io = { version = "0.7", features = ["defmt"] }
embedded-io-async = { version = "0.7", features = ["defmt"] }
panic-probe = { version = "1", features = ["print-defmt", "defmt-error"] }
heapless = { version = "0.9", default-features = false }
static_cell = "2.1"
#chrono = { version = "^0.4", default-features = false}
embedded-hal-async = {version = "1.0.0", features = ["defmt-03"] }
bitfield = "^0.17.0"


[patch.crates-io]
embassy-stm32 = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}
embassy-sync = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}
embassy-executor = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}
embassy-time = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}
embassy-embedded-hal = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}
embassy-futures = {git = "https://github.com/embassy-rs/embassy", rev = "b127ca9844a7e4e9079800be81d173e2725066c6"}


embedded-hal-async = {version = "1", features = ["defmt-03"] }
bitfield = "0.19"

[profile.release]
opt-level = "s"
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ To lint and check stuff, run `cargo clippy`.
### On car stuff

To run a RTT terminal dedicated:
`cargo embed --release --config rtt`
`cargo embed --release rtt`

To run a GDB terminal dedicated:
`cargo embed --release --config gdb`
`cargo embed --release gdb`

To flash and leave code:
`cargo embed --release --config `
`cargo embed --release`



Expand Down Expand Up @@ -56,3 +56,14 @@ This structure has multiple benefits, including:
- Shared `target` folder meaning a shared build cache for quicker and space-saving builds
- Other quirks, such as vscode `settings.json` and `config.toml`, are shared between projects


### Versioning

Updating versions is as follows

1. Update the rust-toolchain to the version found in embassy repo
2. Update all embassy versions to the versions found in the embassy repo, use x.y.z, in main Cargo.toml
3. Update all features, especially ones that say the version in them (ex. "defmt-03")
3. Update major package versions of other projects, use x.y, in main Cargo.toml
4. Update package versions of other projects, in individual Cargo.toml
4. Fix any build issues
4 changes: 1 addition & 3 deletions crates/lsm6dso-ner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[package]
name = "lsm6dso-ner"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
arrayref = "0.3.8"
embedded-hal-async.workspace = true


4 changes: 2 additions & 2 deletions crates/pca9539-ner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "pca9539-ner"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
embedded-hal-async.workspace = true
embedded-hal.workspace = true
embedded-hal.workspace = true
2 changes: 1 addition & 1 deletion crates/sht3x-ner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sht3x-ner"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
defmt.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/vl6180x-ner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "vl6180x-ner"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
embedded-hal-async.workspace = true
embedded-hal.workspace = true
int-enum = {version = "1.1.2", default-features = false}
#int-enum-impl = "0.5.0"
#int-enum-impl = "0.5.0"
4 changes: 2 additions & 2 deletions crates/vl6180x-ner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Config {
pub fn set_range_inter_measurement_period(&mut self, time_ms: u16) -> Result<(), Error<()>> {
let min_eq_val = ((self.range_max_convergence_time + 5) as f32 / 0.9) as u16;
let min = if 10 < min_eq_val { min_eq_val } else { 10 };
if time_ms % 10 != 0 || time_ms < min || time_ms > 2550 {
if !time_ms.is_multiple_of(10) || time_ms < min || time_ms > 2550 {
return Err(Error::InvalidConfigurationValue(time_ms));
}
self.range_inter_measurement_period = time_ms;
Expand Down Expand Up @@ -257,7 +257,7 @@ impl Config {
pub fn set_ambient_inter_measurement_period(&mut self, time_ms: u16) -> Result<(), Error<()>> {
let min_eq_val = ((self.ambient_integration_period as f32 * 1.1) / 0.9) as u16;
let min = if 10 < min_eq_val { min_eq_val } else { 10 };
if time_ms % 10 != 0 || time_ms < min || time_ms > 2560 {
if !time_ms.is_multiple_of(10) || time_ms < min || time_ms > 2560 {
return Err(Error::InvalidConfigurationValue(time_ms));
}
self.ambient_inter_measurement_period = time_ms;
Expand Down
8 changes: 4 additions & 4 deletions crates/vl6180x-ner/src/device_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ where

async fn wait_device_booted(&mut self) -> Result<(), E> {
loop {
if let Ok(result) = self.read_named_register(SYSTEM__FRESH_OUT_OF_RESET).await {
if result == 0x01 {
break;
}
if let Ok(result) = self.read_named_register(SYSTEM__FRESH_OUT_OF_RESET).await
&& result == 0x01
{
break;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/vl6180x-ner/src/i2c_interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use embedded_hal_async::i2c::I2c;

use super::*;
use crate::register::{Register16Bit, Register8Bit};
use crate::register::{Register8Bit, Register16Bit};

impl<MODE, I2C, E> VL6180X<MODE, I2C>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/vl6180x-ner/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use embedded_hal_async::i2c::I2c;

use super::VL6180X;
use crate::register::{
Register16Bit::*, Register8Bit::*, SysModeGpio1Polarity, SysModeGpio1Select,
AMBIENT_ANALOGUE_GAIN_CODE, RANGE_SCALAR_CODE,
AMBIENT_ANALOGUE_GAIN_CODE, RANGE_SCALAR_CODE, Register8Bit::*, Register16Bit::*,
SysModeGpio1Polarity, SysModeGpio1Select,
};

impl<MODE, I2C, E> VL6180X<MODE, I2C>
Expand Down
14 changes: 7 additions & 7 deletions crates/vl6180x-ner/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use embedded_hal_async::i2c::I2c;
pub use powered_off::*;
pub use ready::*;

use crate::error::Error;
use crate::VL6180X;
use crate::error::Error;

impl<MODE, I2C, E> VL6180X<MODE, I2C>
where
Expand Down Expand Up @@ -93,12 +93,12 @@ where
///
/// Does not return the result. To get the measured value the host has the following options:
/// 1. Check regularly to see if the result is ready with [`read_ambient_lux`](VL6180X::read_ambient_lux)
/// or [`read_ambient`](VL6180X::read_ambient)
/// or [`read_ambient`](VL6180X::read_ambient)
/// 2. Call [`read_ambient_lux_blocking`](VL6180X::read_ambient_lux_blocking) or
/// [`read_ambient_blocking`](VL6180X::read_ambient_blocking) to have the driver
/// perform the regular checks in a blocking way.
/// [`read_ambient_blocking`](VL6180X::read_ambient_blocking) to have the driver
/// perform the regular checks in a blocking way.
/// 3. Wait for the ambient interrupt to be triggered, indicating that the
/// new sample is ready, then call the methods listed in option 1.
/// new sample is ready, then call the methods listed in option 1.
pub async fn start_ambient_single(&mut self) -> Result<(), Error<E>> {
self.start_ambient_single_direct().await?;
Ok(())
Expand All @@ -115,9 +115,9 @@ where
/// Does not return the result. To get the measured value the host has the following options:
/// 1. Check regularly to see if the result is ready with [`read_range_mm()`](VL6180X::read_range_mm)
/// 2. Call [`read_range_mm_blocking()`](VL6180X::read_range_mm_blocking) to have the driver
/// perform the regular checks in a blocking way.
/// perform the regular checks in a blocking way.
/// 3. Wait for the range interrupt to be triggered, indicating that the
/// new sample is ready, then call [`read_range_mm()`](VL6180X::read_range_mm).
/// new sample is ready, then call [`read_range_mm()`](VL6180X::read_range_mm).
pub async fn start_range_single(&mut self) -> Result<(), Error<E>> {
self.start_range_single_direct().await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/vl6180x-ner/src/mode/continuous.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use embedded_hal_async::i2c::I2c;

use crate::{error::Error, AllowCommunication, VL6180X};
use crate::{AllowCommunication, VL6180X, error::Error};

use super::{AllowReadMeasurement, AllowStartAmbientSingle, AllowStartRangeSingle, ReadyMode};

Expand Down
4 changes: 2 additions & 2 deletions crates/vl6180x-ner/src/mode/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::error::{Error, Error2};
use crate::VL6180X;
use crate::error::{Error, Error2};
use OperatingMode::*;
use embedded_hal::digital::OutputPin;
use embedded_hal_async::i2c::I2c;
use OperatingMode::*;

/// A mode where the state is kept track of at runtime, instead of being
/// encoded into the type. Thus allowing you to change the mode often,
Expand Down
2 changes: 1 addition & 1 deletion crates/vl6180x-ner/src/mode/powered_off.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use embedded_hal::digital::OutputPin;
use embedded_hal_async::i2c::I2c;

use crate::{error::Error2, VL6180X};
use crate::{VL6180X, error::Error2};

use super::ReadyMode;

Expand Down
2 changes: 1 addition & 1 deletion crates/vl6180x-ner/src/mode/ready.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use embedded_hal_async::i2c::I2c;

use crate::{error::Error, Config};
use crate::{AllowCommunication, VL6180X};
use crate::{Config, error::Error};

use super::{
AllowReadMeasurement, AllowStartAmbientSingle, AllowStartRangeSingle, AmbientContinuousMode,
Expand Down
4 changes: 2 additions & 2 deletions crates/vl6180x-ner/src/read_measurements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use core::convert::TryFrom;
use embedded_hal_async::i2c::I2c;

use crate::{
VL6180X,
error::Error,
register::{
self, AmbientStatusErrorCode, RangeStatusErrorCode, Register16Bit, Register8Bit,
self, AmbientStatusErrorCode, RangeStatusErrorCode, Register8Bit, Register16Bit,
ResultInterruptStatusGpioCode,
},
VL6180X,
};

impl<MODE, I2C, E> VL6180X<MODE, I2C>
Expand Down
2 changes: 1 addition & 1 deletion crates/vl6180x-ner/src/start_stop_measurements.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use embedded_hal_async::i2c::I2c;

use crate::{
VL6180X,
error::Error,
register::{InterleavedModeEnableCode, Register8Bit, SysAmbientStartCode, SysRangeStartCode},
VL6180X,
};

impl<MODE, I2C, E> VL6180X<MODE, I2C>
Expand Down
4 changes: 2 additions & 2 deletions msb-fw-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
edition = "2021"
edition = "2024"
name = "msb-fw-rs"
version = "0.1.0"

Expand All @@ -24,4 +24,4 @@ vl6180x-ner = { version = "0.1.0", path = "../crates/vl6180x-ner", optional = tr
default = ["temp-sensor", "imu-sensor"]
tof-sensor = ["dep:vl6180x-ner"]
temp-sensor = ["dep:sht3x-ner"]
imu-sensor = ["dep:lsm6dso-ner"]
imu-sensor = ["dep:lsm6dso-ner"]
2 changes: 1 addition & 1 deletion msb-fw-rs/src/controllers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub async fn control_leds(
) {
let mut i = 0u8;
loop {
if i % 8 == 0 {
if i.is_multiple_of(8) {
match device_loc {
DeviceLocation::FrontLeft => {
led1.set_low();
Expand Down
3 changes: 1 addition & 2 deletions msb-fw-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(impl_trait_in_assoc_type)]

// declare all files in this project except main
pub mod can_handler;
Expand All @@ -12,7 +11,7 @@ pub mod readers;
// dont import anything in a lib.rs file, instead use fully resolved definitions
pub type SharedI2c3 = embassy_sync::mutex::Mutex<
embassy_sync::blocking_mutex::raw::NoopRawMutex,
embassy_stm32::i2c::I2c<'static, embassy_stm32::mode::Async>,
embassy_stm32::i2c::I2c<'static, embassy_stm32::mode::Async, embassy_stm32::i2c::Master>,
>;
#[derive(Clone, defmt::Format)]
pub enum DeviceLocation {
Expand Down
Loading