diff --git a/board/Cargo.lock b/board/Cargo.lock index f8515db..e4727a4 100644 --- a/board/Cargo.lock +++ b/board/Cargo.lock @@ -28,25 +28,15 @@ dependencies = [ "cortex-m-rt", "datalogger", "embedded-alloc", - "embedded-hal", + "embedded-hal 1.0.0", "nb 1.1.0", "panic-abort", "rriv_board", "rriv_board_0_4_2", "rtt-target", - "stm32f1xx-hal", "unwrap-infallible", ] -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -59,15 +49,9 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" dependencies = [ - "rustc_version 0.2.3", + "rustc_version", ] -[[package]] -name = "bare-metal" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" - [[package]] name = "bitfield" version = "0.13.2" @@ -99,12 +83,12 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bxcan" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ac3d0c0a542d0ab5521211f873f62706a7136df415676f676d347e5a41dd80" +checksum = "3110c36f496cf7110ab17c48ad714225330862101ec30197a9898006cd3e2862" dependencies = [ "bitflags 1.3.2", - "embedded-hal", + "embedded-can", "nb 1.1.0", "vcell", ] @@ -145,10 +129,10 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" dependencies = [ - "bare-metal 0.2.5", + "bare-metal", "bitfield", "critical-section", - "embedded-hal", + "embedded-hal 0.2.7", "volatile-register", ] @@ -194,11 +178,11 @@ dependencies = [ [[package]] name = "ds323x" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5157c16c530fa971b40f2b591edd86b9ce300ec1e5c267a4d6df6ee7df890a6" +checksum = "fe0029db3520c604477b3155a860f7091e082df27210d63e9869e25dbd9eb0ca" dependencies = [ - "embedded-hal", + "embedded-hal 1.0.0", "rtcc", ] @@ -212,6 +196,15 @@ dependencies = [ "linked_list_allocator", ] +[[package]] +name = "embedded-can" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438" +dependencies = [ + "nb 1.1.0", +] + [[package]] name = "embedded-dma" version = "0.2.0" @@ -231,14 +224,47 @@ dependencies = [ "void", ] +[[package]] +name = "embedded-hal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" + +[[package]] +name = "embedded-hal-compat" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ecac72f6be75ad2d4809c9f07d45502e2e5c9a4e9579077f28d7135de81df3" +dependencies = [ + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "nb 1.1.0", +] + +[[package]] +name = "embedded-hal-nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605" +dependencies = [ + "embedded-hal 1.0.0", + "nb 1.1.0", +] + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "embedded-sdmmc" -version = "0.6.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3778099e48fedd6b81048e1d84f60db663124f5c6e22fcef495040b9d51fe06a" +checksum = "eb637331040ec9b35f6a8151904d1aca914cc349d14c91b9a3e92ba789b22f3f" dependencies = [ "byteorder", - "embedded-hal", + "embedded-hal 1.0.0", "heapless", "log", ] @@ -270,9 +296,9 @@ checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" [[package]] name = "hash32" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" dependencies = [ "byteorder", ] @@ -289,14 +315,11 @@ dependencies = [ [[package]] name = "heapless" -version = "0.7.17" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "atomic-polyfill", "hash32", - "rustc_version 0.4.1", - "spin", "stable_deref_trait", ] @@ -312,16 +335,6 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.22" @@ -352,6 +365,26 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -370,6 +403,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" +[[package]] +name = "portable-atomic" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -399,7 +438,9 @@ dependencies = [ "cortex-m", "cortex-m-rt", "ds323x", - "embedded-hal", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-compat", "embedded-sdmmc", "nb 1.1.0", "panic-halt", @@ -409,6 +450,7 @@ dependencies = [ "unwrap-infallible", "usb-device", "usbd-serial", + "usbd-storage", ] [[package]] @@ -436,16 +478,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver 1.0.24", + "semver", ] [[package]] @@ -454,12 +487,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "semver" version = "0.9.0" @@ -469,12 +496,6 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" - [[package]] name = "semver-parser" version = "0.7.0" @@ -512,15 +533,6 @@ dependencies = [ "serde", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -529,9 +541,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stm32-usbd" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c94998f166d66b210a164648a0b7866428d8f1e0740bf8a4c5edd89d4750c1" +checksum = "ef05e917d856a39278e80c50e0b2afcd5dcbcb62ffeeed1a0895d01e6a44ff0d" dependencies = [ "cortex-m", "usb-device", @@ -539,34 +551,38 @@ dependencies = [ ] [[package]] -name = "stm32f1" -version = "0.15.1" +name = "stm32f1-staging" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dc80735831c28fe85384e1e28428fb6d201f67c696e369a239ed9c5eba369d" +checksum = "721a765ed2f9632c7fec0cff287b65b89aba9facb987474be667c1c6a1ddf7ce" dependencies = [ - "bare-metal 1.0.0", "cortex-m", "cortex-m-rt", + "critical-section", + "portable-atomic", "vcell", ] [[package]] name = "stm32f1xx-hal" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30845662b9ce46a2ec04da97666a2b32458bee5032bb0452d0caf1536a96a542" +source = "git+https://github.com/stm32-rs/stm32f1xx-hal#6c5dc881b07dcad06ea57050fdc7c89d65ae6f5f" dependencies = [ "bitflags 1.3.2", "bxcan", "cortex-m", "cortex-m-rt", "embedded-dma", - "embedded-hal", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-nb", + "embedded-io", "fugit", "fugit-timer", "nb 1.1.0", "stm32-usbd", - "stm32f1", + "stm32f1-staging", + "vcell", "void", ] @@ -612,18 +628,32 @@ checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" [[package]] name = "usb-device" -version = "0.2.9" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" +checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6" +dependencies = [ + "heapless", + "portable-atomic", +] [[package]] name = "usbd-serial" -version = "0.1.1" +version = "0.2.2" +source = "git+https://github.com/nakajima/usbd-serial?rev=085c0bb#085c0bb9c11e46a38c783c7abec92e437cd02058" +dependencies = [ + "embedded-hal 1.0.0", + "embedded-io", + "nb 1.1.0", + "usb-device", +] + +[[package]] +name = "usbd-storage" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db75519b86287f12dcf0d171c7cf4ecc839149fe9f3b720ac4cfce52959e1dfe" +checksum = "ee23ab04c7d76b63c417cf2fa672d720477d2e71c6822ac6e5ceaf526f48f394" dependencies = [ - "embedded-hal", - "nb 0.1.3", + "num_enum", "usb-device", ] diff --git a/board/app/Cargo.toml b/board/app/Cargo.toml index 951a370..10bb8a5 100644 --- a/board/app/Cargo.toml +++ b/board/app/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0" nb = "1" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.3" @@ -21,6 +21,4 @@ rriv_board = { path = "../rriv_board" } rriv_board_0_4_2 = { path = "../rriv_board_0_4_2" } datalogger = { path = "../../src/datalogger" } -[dependencies.stm32f1xx-hal] -version = "0.10.0" -features = ["rt", "stm32f103", "high"] + diff --git a/board/rriv_board_0_4_2/Cargo.toml b/board/rriv_board_0_4_2/Cargo.toml index d18f7bc..ad92c9d 100644 --- a/board/rriv_board_0_4_2/Cargo.toml +++ b/board/rriv_board_0_4_2/Cargo.toml @@ -8,16 +8,19 @@ edition = "2021" [dependencies] rriv_board = { path = "../rriv_board" } -embedded-hal = "0.2.7" +embedded-hal-02 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"], optional = true } +embedded-hal = { package = "embedded-hal", version = "1.0" } +embedded-hal-compat = "0.13.0" +stm32f1xx-hal = { git="https://github.com/stm32-rs/stm32f1xx-hal", features = ["stm32f103", "high"] } nb = "1" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.3" # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives panic-halt = "0.2.0" unwrap-infallible = "0.1.5" -stm32f1xx-hal = { version = "0.10", features = ["rt", "stm32f103", "high"] } rtt-target = "0.4.0" -usb-device = "0.2.9" -usbd-serial = "0.1.1" -embedded-sdmmc = "0.6.0" -ds323x = "0.5.1" +usb-device = "0.3.2" +usbd-serial = { git="https://github.com/nakajima/usbd-serial", rev="085c0bb" } +embedded-sdmmc = "0.8" +ds323x = "0.6.0" +usbd-storage = { version = "1.0.0", features = ["bbb", "ufi"] } diff --git a/board/rriv_board_0_4_2/src/components/eeprom.rs b/board/rriv_board_0_4_2/src/components/eeprom.rs index d425f5a..64c4df7 100644 --- a/board/rriv_board_0_4_2/src/components/eeprom.rs +++ b/board/rriv_board_0_4_2/src/components/eeprom.rs @@ -1,8 +1,8 @@ -use embedded_hal::prelude::{ - _embedded_hal_blocking_i2c_Read, _embedded_hal_blocking_i2c_Write, - _embedded_hal_blocking_i2c_WriteRead, -}; +// use embedded_hal::prelude::{ +// _embedded_hal_blocking_i2c_Read, _embedded_hal_blocking_i2c_Write, +// _embedded_hal_blocking_i2c_WriteRead, +// }; use crate::Board; use rriv_board::RRIVBoard; use rtt_target::{rprint, rprintln}; diff --git a/board/rriv_board_0_4_2/src/components/internal_adc.rs b/board/rriv_board_0_4_2/src/components/internal_adc.rs index 6de0b5c..e48ba7c 100644 --- a/board/rriv_board_0_4_2/src/components/internal_adc.rs +++ b/board/rriv_board_0_4_2/src/components/internal_adc.rs @@ -3,92 +3,78 @@ use stm32f1xx_hal::adc; use stm32f1xx_hal::pac::ADC1; pub struct InternalAdcConfiguration { - pins: pin_groups::InternalAdcPins, - adc_device: ADC1, + pins: pin_groups::InternalAdcPins, + adc_device: ADC1, } pub struct InternalAdc { - pins: pin_groups::InternalAdcPins, - adc: adc::Adc, + pins: pin_groups::InternalAdcPins, + adc: adc::Adc, } pub enum AdcError { - NBError(nb::Error<()>), - NotConfigured, - ReadError, + NBError(nb::Error<()>), + NotConfigured, + ReadError, } impl InternalAdcConfiguration { - pub fn new(pins: pin_groups::InternalAdcPins, adc1: ADC1) -> Self { - return InternalAdcConfiguration { - pins, - adc_device: adc1, + pub fn new(pins: pin_groups::InternalAdcPins, adc1: ADC1) -> Self { + return InternalAdcConfiguration { + pins, + adc_device: adc1, + }; } - } - pub fn build(self, clocks: &Clocks) -> InternalAdc { - - let adc_device = self.adc_device; - let adc = adc::Adc::adc1(adc_device, *clocks); - return InternalAdc::new(self.pins, adc); - } + pub fn build(self, clocks: &Clocks) -> InternalAdc { + let adc_device = self.adc_device; + let adc = adc::Adc::adc1(adc_device, clocks); + return InternalAdc::new(self.pins, adc); + } } impl InternalAdc { - pub fn new(pins: pin_groups::InternalAdcPins, adc: adc::Adc) -> Self { - - return InternalAdc { - pins, - adc, + pub fn new(pins: pin_groups::InternalAdcPins, adc: adc::Adc) -> Self { + return InternalAdc { pins, adc }; } - } - - pub fn enable(&mut self, delay: &mut SysDelay) { - self.pins.enable_avdd.set_low(); - delay.delay_ms(100_u16); - } - - pub fn disable(&mut self){ - self.pins.enable_avdd.set_high(); - } - - - pub fn shutdown(mut self) -> InternalAdcConfiguration { - self.disable(); - let adc_device = self.adc.release(); - return InternalAdcConfiguration::new(self.pins, adc_device); - } - - pub fn read(&mut self, channel: u8) -> Result { + pub fn enable(&mut self, delay: &mut SysDelay) { + self.pins.enable_avdd.set_low(); + delay.delay_ms(100_u16); + } - let res: Result> = match channel { - 1 => self.adc.read(&mut self.pins.channel1), - 2 => self.adc.read(&mut self.pins.channel2), - 3 => self.adc.read(&mut self.pins.channel3), - 4 => self.adc.read(&mut self.pins.channel4), - 5 => self.adc.read(&mut self.pins.channel5), - _ => return Err(AdcError::ReadError) - }; + pub fn disable(&mut self) { + self.pins.enable_avdd.set_high(); + } - - match res { - Ok(value) => return Ok(value), - Err(error) => return Err(AdcError::NBError(error)), - } - - } + pub fn shutdown(mut self) -> InternalAdcConfiguration { + self.disable(); + let adc_device = self.adc.release(); + return InternalAdcConfiguration::new(self.pins, adc_device); + } - pub fn read_battery_level(&mut self) -> Result { - - let res = self.adc.read(&mut self.pins.vin_measure); - - match res { - Ok(value) => return Ok(value), - Err(error) => return Err(AdcError::NBError(error)), + pub fn read(&mut self, channel: u8) -> Result { + let res: Result> = match channel { + 1 => self.adc.read(&mut self.pins.channel1), + 2 => self.adc.read(&mut self.pins.channel2), + 3 => self.adc.read(&mut self.pins.channel3), + 4 => self.adc.read(&mut self.pins.channel4), + 5 => self.adc.read(&mut self.pins.channel5), + _ => return Err(AdcError::ReadError), + }; + + match res { + Ok(value) => return Ok(value), + Err(error) => return Err(AdcError::NBError(error)), + } } - - } + pub fn read_battery_level(&mut self) -> Result { + let res = self.adc.read(&mut self.pins.vin_measure); -} \ No newline at end of file + match res { + Ok(value) => return Ok(value), + Err(error) => return Err(AdcError::NBError(error)), + } + } +} diff --git a/board/rriv_board_0_4_2/src/components/storage.rs b/board/rriv_board_0_4_2/src/components/storage.rs index 9cce472..222e14e 100644 --- a/board/rriv_board_0_4_2/src/components/storage.rs +++ b/board/rriv_board_0_4_2/src/components/storage.rs @@ -1,63 +1,74 @@ - - use core::{ffi::CStr, time}; use alloc::format; use ds323x::{Datelike, Timelike}; -use embedded_hal::spi::{Mode, Phase, Polarity}; -use embedded_sdmmc::{Directory, File, SdCard, TimeSource, Timestamp, Volume, VolumeManager}; -use pac::SPI2; -use stm32f1xx_hal::spi::Spi2NoRemap; -// use embedded_sdmmc::{File, SdCard, TimeSource, Timestamp, Volume, VolumeManager}; +use embedded_hal::{ + delay::DelayNs, + spi::{Mode, Phase, Polarity}, +}; +use embedded_sdmmc::{ + BlockDevice, Directory, File, SdCard, TimeSource, Timestamp, Volume, VolumeManager, +}; +use pac::SPI2; use crate::*; pub const MODE: Mode = Mode { - phase: Phase::CaptureOnSecondTransition, - polarity: Polarity::IdleHigh, + polarity: Polarity::IdleHigh, + phase: Phase::CaptureOnSecondTransition, }; +pub fn build(pins: Spi2Pins, spi_dev: SPI2, clocks: Clocks, delay: D) -> Storage { + let spi2 = spi_dev.spi( + (Some(pins.sck), Some(pins.miso), Some(pins.mosi)), + MODE, + 1.MHz(), + &clocks, + ); + rprintln!("set up sdcard"); + // let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay).unwrap(); + // only one SPI device on this bus, can we avoid using embedded_hal_bus? - pub fn build(pins: Spi2Pins, spi_dev: SPI2, clocks: Clocks, delay: Delay) -> Storage { - - let spi2 = Spi::spi2( - spi_dev, - (pins.sck, pins.miso, pins.mosi), - MODE, - 1.MHz(), - clocks, -); - - rprintln!("set up sdcard"); - // let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay).unwrap(); - // only one SPI device on this bus, can we avoid using embedded_hal_bus? - - let sdcard = embedded_sdmmc::SdCard::new(spi2, pins.sd_card_chip_select, delay); - - rprintln!("set up sdcard"); + let sdcard = embedded_sdmmc::SdCard::new(spi2, delay); - return Storage::new(sdcard); + rprintln!("set up sdcard"); + // sdcard.read(blocks, start_block_idx, reason); + // sdcard.write(blocks, start_block_idx); + return Storage::new(sdcard); } +type RrivSdCard = SdCard< + Spi< + SPI2, + Spi2NoRemap, + ( + Pin<'B', 13, Alternate>, + Pin<'B', 14>, + Pin<'B', 15, Alternate>, + ), + u8, + >, + DelayNs, +>; + // type RrivSdCard = SdCard, Pin<'A', 6>, Pin<'A', 7, Alternate>), u8>, Pin<'C', 8, Output>, SysDelay>; -type RrivSdCard = SdCard, Pin<'B', 14>, Pin<'B', 15, Alternate>), u8>, Pin<'C', 8, Output>, Delay>; +// type RrivSdCard = SdCard, Pin<'B', 14>, Pin<'B', 15, Alternate>), u8>, Pin<'C', 8, Output>, Delay>; // SdCard, Pin<'B', 14>, Pin<'B', 15, Alternate>), u8>, Pin<'C', 8, Output>>; pub struct RrivTimeSource {} impl RrivTimeSource { - pub fn new () -> Self { - RrivTimeSource {} - } + pub fn new() -> Self { + RrivTimeSource {} + } } - // the Timesource trait below is a fraught way for us pass timestamps into the sd card library // this cloud be refactored in the library to allow the caller to simply pass the timestamp -// into each write call, from whatever source it wants to use for a timestmap. +// into each write call, from whatever source it wants to use for a timestmap. // for the time being, this static variable provides a way to transmit the timestamp into the library // Additinally, in the case of the RRIVBoard, we do not want to query the I2C RTC every time we write // therefore, this time should be coming form the internal RTC, which needs to be set to match that I2C RTC @@ -65,251 +76,248 @@ impl RrivTimeSource { static mut EPOCH_TIMESTAMP: i64 = 0; pub fn update_time_source(timestamp: i64) { - unsafe { - EPOCH_TIMESTAMP = timestamp; - } + unsafe { + EPOCH_TIMESTAMP = timestamp; + } } impl TimeSource for RrivTimeSource { fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { - - let mut naive = NaiveDateTime::default(); - unsafe { - naive = NaiveDateTime::from_timestamp(EPOCH_TIMESTAMP, 0); - } - let time = naive.time(); - let timestamp = embedded_sdmmc::Timestamp::from_calendar( - naive.year().try_into().unwrap(), - naive.month().try_into().unwrap(), - naive.day().try_into().unwrap(), - time.hour().try_into().unwrap(), - time.minute().try_into().unwrap(), - time.second().try_into().unwrap() - ); - match timestamp { - Ok(timestamp) => timestamp, - Err(err) => Timestamp::from_calendar(0, 0, 0, 0, 0, 0).unwrap() - } - + let mut naive = NaiveDateTime::default(); + unsafe { + naive = NaiveDateTime::from_timestamp(EPOCH_TIMESTAMP, 0); + } + let time = naive.time(); + let timestamp = embedded_sdmmc::Timestamp::from_calendar( + naive.year().try_into().unwrap(), + naive.month().try_into().unwrap(), + naive.day().try_into().unwrap(), + time.hour().try_into().unwrap(), + time.minute().try_into().unwrap(), + time.second().try_into().unwrap(), + ); + match timestamp { + Ok(timestamp) => timestamp, + Err(err) => Timestamp::from_calendar(0, 0, 0, 0, 0, 0).unwrap(), + } } } - pub trait OutputDevice { - fn write(data: &[u8]); + fn write(data: &[u8]); } const CACHE_SIZE: usize = 50; - pub struct Storage { - volume_manager: VolumeManager, - volume: Volume, - filename: [u8; 11], - file: Option, - root_dir: Directory, - cache: [u8; CACHE_SIZE], - next_position: usize, + volume_manager: VolumeManager, + // volume: Volume, + filename: [u8; 11], + // file: Option, + // root_dir: Directory, + cache: [u8; CACHE_SIZE], + next_position: usize, } - impl Storage { - - pub fn new(sd_card: RrivSdCard - // , time_source: impl TimeSource // a timesource passed in here could use unsafe access to internal RTC or i2c bus - ) -> Self { - - let time_source = RrivTimeSource::new(); // unsafe access to the board - // or global time var via interrupt - // or copy into a global variable at the top of the run loop - rprintln!("set up sdcard"); - - let mut volume_manager = embedded_sdmmc::VolumeManager::new(sd_card, time_source); - // Try and access Volume 0 (i.e. the first partition). - // The volume object holds information about the filesystem on that volume. - rprintln!("set up volume"); - let result = volume_manager.open_volume(embedded_sdmmc::VolumeIdx(0)); - let volume = match result { - Ok(volume0) => {rprintln!("Volume 0 Success: {:?}", volume0); volume0 }, - Err(error) => panic!("Volume 0 error: {:?}", error), - }; - - // let volume = volume_manager.open_volume(embedded_sdmmc::VolumeIdx(0)).unwrap(); - rprintln!("Volume 0 Success: {:?}", volume); - // Open the root directory (mutably borrows from the volume). - - // let mut filename_bytes: [u8; 20] = [b'\0'; 20]; - // let filename = format!("{}.csv", timestamp).as_bytes(); - // filename_bytes[0..filename.len()].clone_from_slice(filename); - // rprintln!("file: {:?}", filename); - - rprintln!("set up root dir"); - - let root_dir = volume_manager.open_root_dir(volume).unwrap(); - // This mutably borrows the directory. - rprintln!("Root Dir: {:?}", root_dir); - - - Storage { - volume_manager, - volume, - filename: [b'\0'; 11], - file: None, - root_dir: root_dir, - cache: [b'\0'; CACHE_SIZE], - next_position: 0 + pub fn new( + sd_card: RrivSdCard, // , time_source: impl TimeSource // a timesource passed in here could use unsafe access to internal RTC or i2c bus + ) -> Self { + let time_source = RrivTimeSource::new(); // unsafe access to the board + // or global time var via interrupt + // or copy into a global variable at the top of the run loop + rprintln!("set up sdcard"); + + let mut volume_manager: VolumeManager< + SdCard< + Spi< + SPI2, + Spi2NoRemap, + ( + Pin<'B', 13, Alternate>, + Pin<'B', 14>, + Pin<'B', 15, Alternate>, + ), + u8, + >, + _, + >, + RrivTimeSource, + > = embedded_sdmmc::VolumeManager::new(sd_card, time_source); + // Try and access Volume 0 (i.e. the first partition). + // The volume object holds information about the filesystem on that volume. + rprintln!("set up volume"); + let result = volume_manager.open_volume(embedded_sdmmc::VolumeIdx(0)); + let volume: Volume<'_, _, _, _, _, _> = match result { + Ok(volume0) => { + rprintln!("Volume 0 Success: {:?}", volume0); + volume0 + } + Err(error) => panic!("Volume 0 error: {:?}", error), + }; + + // let volume = volume_manager.open_volume(embedded_sdmmc::VolumeIdx(0)).unwrap(); + rprintln!("Volume 0 Success: {:?}", volume); + // Open the root directory (mutably borrows from the volume). + + // let mut filename_bytes: [u8; 20] = [b'\0'; 20]; + // let filename = format!("{}.csv", timestamp).as_bytes(); + // filename_bytes[0..filename.len()].clone_from_slice(filename); + // rprintln!("file: {:?}", filename); + + rprintln!("set up root dir"); + + let root_dir = volume_manager.open_root_dir(volume).unwrap(); + // This mutably borrows the directory. + rprintln!("Root Dir: {:?}", root_dir); + + Storage { + volume_manager, + // volume, + filename: [b'\0'; 11], + // file: None, + // root_dir: root_dir, + cache: [b'\0'; CACHE_SIZE], + next_position: 0, + } } - } - - pub fn reopen_file(&mut self){ - - let filename = match core::str::from_utf8(&self.filename) { - Ok(filename) => filename, - Err(err) => { - rprintln!("{:?}", err); - panic!(); - }, - }; - - rprintln!("Filename: {:?}", filename); - - let my_file = match self.volume_manager.open_file_in_dir( - self.root_dir, filename, embedded_sdmmc::Mode::ReadWriteCreateOrAppend){ - Ok(my_file) => my_file, - Err(error) => { - rprintln!("{:?}", error); - panic!(); - }, - }; - - - rprintln!("File: {:?}", my_file); - - self.file = Some(my_file); - - } - - - - // look at the c code to copy the structure of these calls - pub fn create_file(&mut self, timestamp: i64){ - - let timestamp = if timestamp > 9999999 { timestamp & 9999999 } else { timestamp }; - // let timestamp = timestamp > 1704067200 ? timestamp - 1704067200 : timestamp; // the RRIV epoch starts on Jan 1 2024, necessary to support short file names - let filename = format!("{:0>7}.csv", timestamp); - let filename = filename.as_bytes(); - rprintln!("file: {:?}", core::str::from_utf8(filename)); - let mut filename_bytes: [u8; 11] = [b'\0'; 11]; - filename_bytes[0..filename.len()].clone_from_slice(filename); - self.filename = filename_bytes; - - // let my_file = self.volume_manager.open_file_in_dir( - // root_dir, output.as_str(), embedded_sdmmc::Mode::ReadWriteCreateOrAppend).unwrap(); - - self.reopen_file(); - - } - - pub fn flush(&mut self) { - - if let Some(file) = self.file { - - let cache_data = &self.cache[0..self.next_position]; - match self.volume_manager.write(file, cache_data) { - Ok(ret) => rprintln!("Success: {:?}", ret), - Err(err) => rprintln!("Err: {:?}", err), - } - - self.volume_manager.close_file(file); - self.reopen_file(); - self.next_position = 0; + pub fn reopen_file(&mut self) { + let filename = match core::str::from_utf8(&self.filename) { + Ok(filename) => filename, + Err(err) => { + rprintln!("{:?}", err); + panic!(); + } + }; + + rprintln!("Filename: {:?}", filename); + + let my_file = match self.volume_manager.open_file_in_dir( + self.root_dir, + filename, + embedded_sdmmc::Mode::ReadWriteCreateOrAppend, + ) { + Ok(my_file) => my_file, + Err(error) => { + rprintln!("{:?}", error); + panic!(); + } + }; + + rprintln!("File: {:?}", my_file); + + self.file = Some(my_file); } - - } - - pub fn write(&mut self, data: &[u8], timestamp: i64) { //-> Result>{ - - unsafe { - EPOCH_TIMESTAMP = timestamp; // or function set_write_timestamp + // look at the c code to copy the structure of these calls + pub fn create_file(&mut self, timestamp: i64) { + let timestamp = if timestamp > 9999999 { + timestamp & 9999999 + } else { + timestamp + }; + // let timestamp = timestamp > 1704067200 ? timestamp - 1704067200 : timestamp; // the RRIV epoch starts on Jan 1 2024, necessary to support short file names + let filename = format!("{:0>7}.csv", timestamp); + let filename = filename.as_bytes(); + rprintln!("file: {:?}", core::str::from_utf8(filename)); + let mut filename_bytes: [u8; 11] = [b'\0'; 11]; + filename_bytes[0..filename.len()].clone_from_slice(filename); + self.filename = filename_bytes; + + // let my_file = self.volume_manager.open_file_in_dir( + // root_dir, output.as_str(), embedded_sdmmc::Mode::ReadWriteCreateOrAppend).unwrap(); + + self.reopen_file(); } - - if let Some(file) = self.file { - - if self.next_position + data.len() > CACHE_SIZE { - // flush cache - self.flush(); - } - self.cache[self.next_position..self.next_position+data.len()].copy_from_slice(data); - self.next_position = self.next_position+data.len(); + pub fn flush(&mut self) { + if let Some(file) = self.file { + let cache_data = &self.cache[0..self.next_position]; + match self.volume_manager.write(file, cache_data) { + Ok(ret) => rprintln!("Success: {:?}", ret), + Err(err) => rprintln!("Err: {:?}", err), + } + + self.volume_manager.close_file(file); + self.reopen_file(); + self.next_position = 0; + } + } - } else { - // return an error - rprintln!("File not open"); + pub fn write(&mut self, data: &[u8], timestamp: i64) { + //-> Result>{ + + unsafe { + EPOCH_TIMESTAMP = timestamp; // or function set_write_timestamp + } + + if let Some(file) = self.file { + if self.next_position + data.len() > CACHE_SIZE { + // flush cache + self.flush(); + } + + self.cache[self.next_position..self.next_position + data.len()].copy_from_slice(data); + self.next_position = self.next_position + data.len(); + } else { + // return an error + rprintln!("File not open"); + } } - - } - - - // pub fn write(&mut self, data: &[u8]){ - - // let root_dir = self.volume_manager.open_root_dir(self.volume).unwrap(); - - - - // let filename_str: &str = match core::str::from_utf8(&self.filename) { - // Ok(str) => str, - // Err(err) => { - // rprintln!("{:?}", err); - // panic!(); - // } - // }; - - // let my_file = match self.volume_manager.open_file_in_dir( - // root_dir, filename_str, embedded_sdmmc::Mode::ReadWriteCreateOrAppend){ - // Ok(my_file) => my_file, - // Err(error) => { - // rprintln!("{:?}", error); - // panic!(); - // }, - // }; - - - // match self.volume_manager.write(my_file, data.as_bytes()) { - // Ok(ret) => rprintln!("Success: {:?}", ret), - // Err(err) => rprintln!("Err: {:?}", err), - // } - - // self.volume_manager.close_file(my_file); // this is how you flush the file. - - - // // let mut volume_mgr = embedded_sdmmc::VolumeManager::new(self.sd_card, time_source); - // // // Try and access Volume 0 (i.e. the first partition). - // // // The volume object holds information about the filesystem on that volume. - // // let volume0 = volume_mgr.open_volume(embedded_sdmmc::VolumeIdx(0)).unwrap(); - // // rprintln!("Volume 0: {:?}", volume0); - // // // Open the root directory (mutably borrows from the volume). - // // let root_dir = volume_mgr.open_root_dir(volume0).unwrap(); - // // // Open a file called "MY_FILE.TXT" in the root directory - // // // This mutably borrows the directory. - // // rprintln!("Volume 0: {:?}", root_dir);root_dir - - // // let my_file = volume_mgr.open_file_in_dir( - // // root_dir, "MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly).unwrap(); - // // // let my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadWriteCreateOrAppend)?; - - // // rprintln!("Volume 0: {:?}", my_file); - - // // Print the contents of the file, assuming it's in ISO-8859-1 encoding - // // while !my_file.is_eof() { - // // let mut buffer = [0u8; 32]; - // // let num_read = my_file.read(&mut buffer)?; - // // for b in &buffer[0..num_read] { - // // rprintln!("{}", *b as char); - // // } - // // } - // } + // pub fn write(&mut self, data: &[u8]){ + + // let root_dir = self.volume_manager.open_root_dir(self.volume).unwrap(); + + // let filename_str: &str = match core::str::from_utf8(&self.filename) { + // Ok(str) => str, + // Err(err) => { + // rprintln!("{:?}", err); + // panic!(); + // } + // }; + + // let my_file = match self.volume_manager.open_file_in_dir( + // root_dir, filename_str, embedded_sdmmc::Mode::ReadWriteCreateOrAppend){ + // Ok(my_file) => my_file, + // Err(error) => { + // rprintln!("{:?}", error); + // panic!(); + // }, + // }; + + // match self.volume_manager.write(my_file, data.as_bytes()) { + // Ok(ret) => rprintln!("Success: {:?}", ret), + // Err(err) => rprintln!("Err: {:?}", err), + // } + + // self.volume_manager.close_file(my_file); // this is how you flush the file. + + // // let mut volume_mgr = embedded_sdmmc::VolumeManager::new(self.sd_card, time_source); + // // // Try and access Volume 0 (i.e. the first partition). + // // // The volume object holds information about the filesystem on that volume. + // // let volume0 = volume_mgr.open_volume(embedded_sdmmc::VolumeIdx(0)).unwrap(); + // // rprintln!("Volume 0: {:?}", volume0); + // // // Open the root directory (mutably borrows from the volume). + // // let root_dir = volume_mgr.open_root_dir(volume0).unwrap(); + // // // Open a file called "MY_FILE.TXT" in the root directory + // // // This mutably borrows the directory. + // // rprintln!("Volume 0: {:?}", root_dir);root_dir + + // // let my_file = volume_mgr.open_file_in_dir( + // // root_dir, "MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly).unwrap(); + // // // let my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadWriteCreateOrAppend)?; + + // // rprintln!("Volume 0: {:?}", my_file); + + // // Print the contents of the file, assuming it's in ISO-8859-1 encoding + // // while !my_file.is_eof() { + // // let mut buffer = [0u8; 32]; + // // let num_read = my_file.read(&mut buffer)?; + // // for b in &buffer[0..num_read] { + // // rprintln!("{}", *b as char); + // // } + // // } + // } } diff --git a/board/rriv_board_0_4_2/src/lib.rs b/board/rriv_board_0_4_2/src/lib.rs index 69e0eb1..543c54c 100644 --- a/board/rriv_board_0_4_2/src/lib.rs +++ b/board/rriv_board_0_4_2/src/lib.rs @@ -10,8 +10,9 @@ use core::{ concat, default::Default, format_args, + mem::MaybeUninit, ops::DerefMut, - option::{Option, Option::*}, + option::Option::{self, *}, result::Result::*, }; use core::{mem, result}; @@ -20,7 +21,7 @@ use cortex_m::{ interrupt::{CriticalSection, Mutex}, peripheral::NVIC, }; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use stm32f1xx_hal::afio::MAPR; use stm32f1xx_hal::flash::ACR; use stm32f1xx_hal::gpio::{Alternate, Pin}; @@ -43,6 +44,16 @@ use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType}; use usb_device::{bus::UsbBusAllocator, prelude::*}; use usbd_serial::{SerialPort, USB_CLASS_CDC}; +use usbd_storage::subclass::ufi::{Ufi, UfiCommand}; +use usbd_storage::subclass::Command; +use usbd_storage::transport::bbb::{BulkOnly, BulkOnlyError}; +use usbd_storage::transport::TransportError; + +static mut USB_TRANSPORT_BUF: MaybeUninit<[u8; 512]> = MaybeUninit::uninit(); + +const BLOCK_SIZE: usize = 512; +const USB_PACKET_SIZE: u16 = 64; // 8,16,32,64 + use rriv_board::{ ActuatorDriverServices, RRIVBoard, RRIVBoardBuilder, RXProcessor, SensorDriverServices, TelemetryDriverServices, @@ -76,8 +87,10 @@ pub struct Serial { } // type aliases to make things tenable -type BoardI2c1 = BlockingI2c; -type BoardI2c2 = BlockingI2c; +// type BoardI2c1 = BlockingI2c; +// type BoardI2c2 = BlockingI2c; +type BoardI2c1 = BlockingI2c; +type BoardI2c2 = BlockingI2c; pub struct Board { pub delay: SysDelay, @@ -93,7 +106,7 @@ pub struct Board { pub internal_rtc: Rtc, pub storage: Storage, pub debug: bool, - pub file_epoch: i64 + pub file_epoch: i64, } impl Board { @@ -108,7 +121,7 @@ impl Board { } impl RRIVBoard for Board { - fn run_loop_iteration(&mut self){ + fn run_loop_iteration(&mut self) { self.file_epoch = self.epoch_timestamp(); } @@ -158,8 +171,8 @@ impl RRIVBoard for Board { eeprom::write_datalogger_settings_to_eeprom(self, bytes); } - fn retrieve_datalogger_settings( // let timestamp: i64 = rriv_board::RRIVBoard::epoch_timestamp(self); - + fn retrieve_datalogger_settings( + // let timestamp: i64 = rriv_board::RRIVBoard::epoch_timestamp(self); &mut self, buffer: &mut [u8; rriv_board::EEPROM_DATALOGGER_SETTINGS_SIZE], ) { @@ -194,7 +207,7 @@ impl RRIVBoard for Board { fn set_epoch(&mut self, epoch: i64) { let i2c1 = mem::replace(&mut self.i2c1, None); - let mut ds3231 = Ds323x::new_ds3231( i2c1.unwrap()); + let mut ds3231 = Ds323x::new_ds3231(i2c1.unwrap()); let millis = epoch * 1000; // DateTime::from_timestamp_millis(micros); let datetime = NaiveDateTime::from_timestamp_millis(millis); @@ -202,17 +215,16 @@ impl RRIVBoard for Board { if let Some(datetime) = datetime { match ds3231.set_datetime(&datetime) { Ok(_) => {} - Err(err) => rprintln!("Error {:?}",err), + Err(err) => rprintln!("Error {:?}", err), } } let result = ds3231.datetime(); - self.i2c1 = Some(ds3231.destroy_ds3231()); + self.i2c1 = Some(ds3231.destroy_ds3231()); } fn epoch_timestamp(&mut self) -> i64 { - let i2c1 = mem::replace(&mut self.i2c1, None); - let mut ds3231 = Ds323x::new_ds3231( i2c1.unwrap()); + let mut ds3231 = Ds323x::new_ds3231(i2c1.unwrap()); let result = ds3231.datetime(); self.i2c1 = Some(ds3231.destroy_ds3231()); @@ -220,10 +232,10 @@ impl RRIVBoard for Board { Ok(date_time) => { // rprintln!("got DS3231 time {:?}", date_time.and_utc().timestamp()); date_time.and_utc().timestamp() - }, + } Err(err) => { rprintln!("DS3231 error {:?}", err); - return 0 // this could fail back to some other clock + return 0; // this could fail back to some other clock } } } @@ -231,8 +243,6 @@ impl RRIVBoard for Board { // crystal time, systick fn timestamp(&mut self) -> i64 { return self.internal_rtc.current_time().into(); // internal RTC - - } fn get_sensor_driver_services(&mut self) -> &mut dyn SensorDriverServices { @@ -246,9 +256,9 @@ impl RRIVBoard for Board { fn get_telemetry_driver_services(&mut self) -> &mut dyn TelemetryDriverServices { return self; } - + fn set_debug(&mut self, debug: bool) { - self.debug = debug; + self.debug = debug; } fn write_log_file(&mut self, data: &str) { @@ -311,7 +321,10 @@ impl SensorDriverServices for Board { // rprintln!(&format!("Problem reading I2C2 {}\n", addr)) // let error_msg = &format!("Problem reading I2C2 {}\n", addr); // rprintln!(error_msg); - rriv_board::RRIVBoard::serial_debug(self, &format!("Problem reading I2C2 {}\n", addr)); + rriv_board::RRIVBoard::serial_debug( + self, + &format!("Problem reading I2C2 {}\n", addr), + ); for i in 0..buffer.len() { buffer[i] = 0b11111111; // error value } @@ -325,7 +338,10 @@ impl SensorDriverServices for Board { Ok(_) => return Ok(()), Err(e) => { rprintln!("{:?}", e); - rriv_board::RRIVBoard::serial_debug(self, &format!("Problem writing I2C2 {}", addr)); + rriv_board::RRIVBoard::serial_debug( + self, + &format!("Problem writing I2C2 {}", addr), + ); return Err(()); } } @@ -445,7 +461,7 @@ pub struct BoardBuilder { pub i2c1: Option, pub i2c2: Option, pub internal_rtc: Option, - pub storage: Option + pub storage: Option, } impl BoardBuilder { @@ -462,7 +478,7 @@ impl BoardBuilder { rgb_led: None, oscillator_control: None, internal_rtc: None, - storage: None + storage: None, } } @@ -482,7 +498,7 @@ impl BoardBuilder { internal_rtc: self.internal_rtc.unwrap(), storage: self.storage.unwrap(), debug: true, - file_epoch: 0 + file_epoch: 0, } } @@ -517,17 +533,12 @@ impl BoardBuilder { clocks: &Clocks, ) { // rprintln!("initializing serial"); - - let mut serial = Hal_Serial::new( - usart, + rprintln!("serial rx.listen()"); + let mut serial = usart.serial( (pins.tx, pins.rx), - mapr, - Config::default().baudrate(57600.bps()), - &clocks, + Config::default().baudrate(115200.bps()), + clocks, ); - - rprintln!("serial rx.listen()"); - serial.rx.listen(); cortex_m::interrupt::free(|cs| { @@ -565,11 +576,21 @@ impl BoardBuilder { USB_SERIAL = Some(SerialPort::new(USB_BUS.as_ref().unwrap())); + let mut ufi = usbd_storage::subclass::ufi::Ufi::new( + USB_BUS.as_ref().unwrap(), + USB_PACKET_SIZE, + unsafe { USB_TRANSPORT_BUF.assume_init_mut().as_mut_slice() }, + ) + .unwrap(); + let usb_dev = UsbDeviceBuilder::new(USB_BUS.as_ref().unwrap(), UsbVidPid(0x0483, 0x29)) - .manufacturer("RRIV") - .product("RRIV Data Logger") - .serial_number("_rriv") .device_class(USB_CLASS_CDC) + .self_powered(false) + .strings(&[StringDescriptors::default() + .manufacturer("RRIV") + .product("RRIV Data Logger") + .serial_number("_rriv")]) + .unwrap() .build(); USB_DEVICE = Some(usb_dev); @@ -590,14 +611,13 @@ impl BoardBuilder { ) -> BoardI2c1 { let scl1 = pins.i2c1_scl.into_alternate_open_drain(&mut cr.gpiob_crl); // i2c let sda1 = pins.i2c1_sda.into_alternate_open_drain(&mut cr.gpiob_crl); // i2c - BlockingI2c::i2c1( + BlockingI2c::new( i2c1, (scl1, sda1), - mapr, Mode::Standard { - frequency: 100.kHz(), // slower to same some energy? + frequency: 100.kHz(), // slower to save some energy? }, - *clocks, + clocks, 1000, 10, 1000, @@ -613,13 +633,13 @@ impl BoardBuilder { ) -> BoardI2c2 { let scl2 = pins.i2c2_scl.into_alternate_open_drain(&mut cr.gpiob_crh); // i2c let sda2 = pins.i2c2_sda.into_alternate_open_drain(&mut cr.gpiob_crh); // i2c - let mut x = BlockingI2c::i2c2( + let mut x = BlockingI2c::new( i2c2, (scl2, sda2), Mode::Standard { frequency: 100.kHz(), // slower to same some energy? }, - *clocks, + clocks, 1000, 10, 1000, @@ -793,7 +813,7 @@ impl BoardBuilder { let delay2: DelayUs = device_peripherals.TIM2.delay(&clocks); // delay2.delay(2); rprintln!("{:?}", clocks); - + // let mut storage = storage::build( // spi1_pins, // device_peripherals.SPI1, @@ -802,15 +822,10 @@ impl BoardBuilder { // delay2, // ); - let mut storage = storage::build( - spi2_pins, - device_peripherals.SPI2, - clocks, - delay2, - ); + let mut storage = storage::build(spi2_pins, device_peripherals.SPI2, clocks, delay2); // for SPI SD https://github.com/rust-embedded-community/embedded-sdmmc-rs rprintln!("{:?}", clocks); - + self.storage = Some(storage); // // let spi_mode = Mode { diff --git a/board/rriv_board_0_4_2/src/pin_groups/mod.rs b/board/rriv_board_0_4_2/src/pin_groups/mod.rs index e702bc1..78fe9fc 100644 --- a/board/rriv_board_0_4_2/src/pin_groups/mod.rs +++ b/board/rriv_board_0_4_2/src/pin_groups/mod.rs @@ -7,7 +7,7 @@ pub use battery_level::*; mod dynamic_gpio; pub use dynamic_gpio::*; mod i2c1; -use embedded_hal::blocking::i2c; +use embedded_hal::i2c; pub use i2c1::*; mod i2c2; pub use i2c2::*;