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
File renamed without changes.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Allow to set HSE bypass bit in `RCC` clock configuration register to use an external clock input on the `OSC_IN` pin
- support `embedded-hal-1.0`

## [v0.10.0] - 2022-12-12

Expand Down
21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,30 @@ default-target = "x86_64-unknown-linux-gnu"
[dependencies]
cortex-m = "0.7.6"
cortex-m-rt = "0.7.1"
nb = "1"
nb = "1.1"
stm32f1 = "0.15.1"
embedded-dma = "0.2.0"
bxcan = "0.7"
void = { default-features = false, version = "1.0.2" }
embedded-hal = { features = ["unproven"], version = "0.2.7" }
fugit = "0.3.6"
fugit = "0.3.7"
fugit-timer = "0.1.3"
rtic-monotonic = { version = "1.0", optional = true }
bitflags = "1.3.2"
vcell = "0.1.3"

[dependencies.embedded-hal-02]
package = "embedded-hal"
version = "0.2.7"
features = ["unproven"]

[dependencies.embedded-hal]
version = "1.0"

[dependencies.embedded-hal-nb]
version = "1.0"

[dependencies.embedded-io]
version = "0.6.1"

[dependencies.stm32-usbd]
version = "0.6.0"
Expand All @@ -45,7 +59,6 @@ heapless = "0.7.16"
mfrc522 = "0.3.0"
usb-device = "0.2.8"
usbd-serial = "0.1.1"
unwrap-infallible = "0.1.5"

[features]
device-selected = []
Expand Down
2 changes: 1 addition & 1 deletion examples/delay-timer-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() -> ! {
loop {
// On for 1s, off for 3s.
led.set_high();
// Use `embedded_hal::DelayMs` trait
// Use `embedded_hal_02::DelayMs` trait
delay.delay_ms(1000_u32);
led.set_low();
// or use `fugit` duration units
Expand Down
2 changes: 1 addition & 1 deletion examples/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() -> ! {

loop {
led.set_high();
// Use `embedded_hal::DelayMs` trait
// Use `embedded_hal_02::DelayMs` trait
delay.delay_ms(1_000_u16);
led.set_low();
// or use `fugit` duration units
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nb::block;

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal_02::digital::v2::{InputPin, OutputPin};
use stm32f1xx_hal::{pac, prelude::*};

#[entry]
Expand Down
4 changes: 2 additions & 2 deletions examples/mfrc522.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use panic_itm as _;
use cortex_m::iprintln;

use cortex_m_rt::entry;
use embedded_hal::digital::v1_compat::OldOutputPin;
use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal_02::digital::v1_compat::OldOutputPin;
use embedded_hal_02::spi::{Mode, Phase, Polarity};
use mfrc522::Mfrc522;
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};
pub const MODE: Mode = Mode {
Expand Down
4 changes: 2 additions & 2 deletions examples/serial-interrupt-idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
// Set up the usart device. Takes ownership over the USART register and tx/rx pins. The rest of
// the registers are used to enable and configure the device.
let (mut tx, mut rx) =
Serial::new(p.USART1, (tx, rx), &mut afio.mapr, 115200.bps(), &clocks).split();
Serial::new(p.USART1, (tx, rx), &mut afio.mapr, 115_200.bps(), &clocks).split();
tx.listen();
rx.listen();
rx.listen_idle();

cortex_m::interrupt::free(|_| unsafe {
TX.replace(tx);

Check warning on line 54 in examples/serial-interrupt-idle.rs

View workflow job for this annotation

GitHub Actions / check (nightly, stm32f103, true)

creating a mutable reference to mutable static is discouraged
RX.replace(rx);

Check warning on line 55 in examples/serial-interrupt-idle.rs

View workflow job for this annotation

GitHub Actions / check (nightly, stm32f103, true)

creating a mutable reference to mutable static is discouraged
});
unsafe {
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::USART1);
Expand All @@ -67,15 +67,15 @@
static mut WIDX: usize = 0;

unsafe fn write(buf: &[u8]) {
if let Some(tx) = TX.as_mut() {

Check warning on line 70 in examples/serial-interrupt-idle.rs

View workflow job for this annotation

GitHub Actions / check (nightly, stm32f103, true)

creating a mutable reference to mutable static is discouraged
buf.iter()
.for_each(|w| if let Err(_err) = nb::block!(tx.write(*w)) {})
.for_each(|w| if let Err(_err) = nb::block!(tx.write_u8(*w)) {})
}
}
#[interrupt]
unsafe fn USART1() {
cortex_m::interrupt::free(|_| {
if let Some(rx) = RX.as_mut() {

Check warning on line 78 in examples/serial-interrupt-idle.rs

View workflow job for this annotation

GitHub Actions / check (nightly, stm32f103, true)

creating a mutable reference to mutable static is discouraged
if rx.is_rx_not_empty() {
if let Ok(w) = nb::block!(rx.read()) {
BUFFER[WIDX] = w;
Expand Down
5 changes: 2 additions & 3 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use stm32f1xx_hal::{
prelude::*,
serial::{Config, Serial},
};
use unwrap_infallible::UnwrapInfallible;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -71,7 +70,7 @@ fn main() -> ! {

// Loopback test. Write `X` and wait until the write is successful.
let sent = b'X';
block!(serial.tx.write(sent)).unwrap_infallible();
block!(serial.tx.write_u8(sent)).unwrap();

// Read the byte that was just sent. Blocks until the read is complete
let received = block!(serial.rx.read()).unwrap();
Expand All @@ -85,7 +84,7 @@ fn main() -> ! {
// You can also split the serial struct into a receiving and a transmitting part
let (mut tx, mut rx) = serial.split();
let sent = b'Y';
block!(tx.write(sent)).unwrap_infallible();
block!(tx.write_u8(sent)).unwrap();
let received = block!(rx.read()).unwrap();
assert_eq!(received, sent);
asm::bkpt();
Expand Down
16 changes: 7 additions & 9 deletions examples/serial_9bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
#![no_main]
#![no_std]

use core::convert::Infallible;
use cortex_m_rt::entry;
use nb::block;
use panic_halt as _;
use stm32f1xx_hal::{
pac,
prelude::*,
serial::{self, Config, Serial},
serial::{self, Config, Error, Serial},
};
use unwrap_infallible::UnwrapInfallible;

// The address of the slave device.
const SLAVE_ADDR: u8 = 123;
Expand All @@ -29,7 +27,7 @@ const MSG_MAX_LEN: usize = u8::MAX as usize;
// Receives a message addressed to the slave device. Returns the size of the received message.
fn receive_msg<RX>(serial_rx: &mut RX, buf: &mut [u8; MSG_MAX_LEN]) -> usize
where
RX: embedded_hal::serial::Read<u16, Error = serial::Error>,
RX: embedded_hal_02::serial::Read<u16, Error = serial::Error>,
{
enum RxPhase {
Start,
Expand Down Expand Up @@ -79,19 +77,19 @@ where
// Send message.
fn send_msg<TX>(serial_tx: &mut TX, msg: &[u8])
where
TX: embedded_hal::serial::Write<u8, Error = Infallible>
+ embedded_hal::serial::Write<u16, Error = Infallible>,
TX: embedded_hal_02::serial::Write<u8, Error = Error>
+ embedded_hal_02::serial::Write<u16, Error = Error>,
{
// Send address.
block!(serial_tx.write(SLAVE_ADDR as u16 | 0x100)).unwrap_infallible();
block!(serial_tx.write(SLAVE_ADDR as u16 | 0x100)).unwrap();

// Send message len.
assert!(msg.len() <= MSG_MAX_LEN);
block!(serial_tx.write(msg.len() as u8)).unwrap_infallible();
block!(serial_tx.write(msg.len() as u8)).unwrap();

// Send message.
for &b in msg {
block!(serial_tx.write(b)).unwrap_infallible();
block!(serial_tx.write(b)).unwrap();
}
}

Expand Down
5 changes: 2 additions & 3 deletions examples/serial_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use stm32f1xx_hal::{
prelude::*,
serial::{self, Serial},
};
use unwrap_infallible::UnwrapInfallible;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -75,8 +74,8 @@ fn main() -> ! {
let (mut tx, _rx) = serial.split();

let sent = b'U';
block!(tx.write(sent)).unwrap_infallible();
block!(tx.write(sent)).unwrap_infallible();
block!(tx.write_u8(sent)).unwrap();
block!(tx.write_u8(sent)).unwrap();

loop {}
}
5 changes: 2 additions & 3 deletions examples/serial_reconfigure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use stm32f1xx_hal::{
prelude::*,
serial::{self, Config, Serial},
};
use unwrap_infallible::UnwrapInfallible;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -71,7 +70,7 @@ fn main() -> ! {

// Loopback test. Write `X` and wait until the write is successful.
let sent = b'X';
block!(serial.tx.write(sent)).unwrap_infallible();
block!(serial.tx.write_u8(sent)).unwrap();

// Read the byte that was just sent. Blocks until the read is complete
let received = block!(serial.rx.read()).unwrap();
Expand All @@ -88,7 +87,7 @@ fn main() -> ! {

// Let's see if it works.'
let sent = b'Y';
block!(serial.tx.write(sent)).unwrap_infallible();
block!(serial.tx.write_u8(sent)).unwrap();
let received = block!(serial.rx.read()).unwrap();
assert_eq!(received, sent);
asm::bkpt();
Expand Down
2 changes: 1 addition & 1 deletion examples/spi-slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cortex_m_rt::entry;
use panic_halt as _;

use cortex_m::{asm, singleton};
use embedded_hal::spi::{Mode, Phase, Polarity};
use stm32f1xx_hal::spi::{Mode, Phase, Polarity};
pub const MODE: Mode = Mode {
phase: Phase::CaptureOnSecondTransition,
polarity: Polarity::IdleHigh,
Expand Down
2 changes: 1 addition & 1 deletion examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use cortex_m_rt::entry;
use panic_halt as _;

use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal_02::spi::{Mode, Phase, Polarity};
pub const MODE: Mode = Mode {
phase: Phase::CaptureOnSecondTransition,
polarity: Polarity::IdleHigh,
Expand Down
94 changes: 47 additions & 47 deletions src/adc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # API for the Analog to Digital converter

use core::marker::PhantomData;
use embedded_hal::adc::{Channel, OneShot};
use embedded_hal_02::adc::{Channel, OneShot};

#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
use crate::dma::dma2;
Expand Down Expand Up @@ -101,7 +101,7 @@
}

macro_rules! adc_pins {
($ADC:ty, $($pin:ty => $chan:expr),+ $(,)*) => {
($ADC:ty, $($pin:ty => $chan:literal),+ $(,)*) => {
$(
impl Channel<$ADC> for $pin {
type ID = u8;
Expand All @@ -113,59 +113,59 @@
}

adc_pins!(pac::ADC1,
gpio::PA0<Analog> => 0_u8,
gpio::PA1<Analog> => 1_u8,
gpio::PA2<Analog> => 2_u8,
gpio::PA3<Analog> => 3_u8,
gpio::PA4<Analog> => 4_u8,
gpio::PA5<Analog> => 5_u8,
gpio::PA6<Analog> => 6_u8,
gpio::PA7<Analog> => 7_u8,
gpio::PB0<Analog> => 8_u8,
gpio::PB1<Analog> => 9_u8,
gpio::PC0<Analog> => 10_u8,
gpio::PC1<Analog> => 11_u8,
gpio::PC2<Analog> => 12_u8,
gpio::PC3<Analog> => 13_u8,
gpio::PC4<Analog> => 14_u8,
gpio::PC5<Analog> => 15_u8,
gpio::PA0<Analog> => 0,
gpio::PA1<Analog> => 1,
gpio::PA2<Analog> => 2,
gpio::PA3<Analog> => 3,
gpio::PA4<Analog> => 4,
gpio::PA5<Analog> => 5,
gpio::PA6<Analog> => 6,
gpio::PA7<Analog> => 7,
gpio::PB0<Analog> => 8,
gpio::PB1<Analog> => 9,
gpio::PC0<Analog> => 10,
gpio::PC1<Analog> => 11,
gpio::PC2<Analog> => 12,
gpio::PC3<Analog> => 13,
gpio::PC4<Analog> => 14,
gpio::PC5<Analog> => 15,
);

#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
adc_pins!(pac::ADC2,
gpio::PA0<Analog> => 0_u8,
gpio::PA1<Analog> => 1_u8,
gpio::PA2<Analog> => 2_u8,
gpio::PA3<Analog> => 3_u8,
gpio::PA4<Analog> => 4_u8,
gpio::PA5<Analog> => 5_u8,
gpio::PA6<Analog> => 6_u8,
gpio::PA7<Analog> => 7_u8,
gpio::PB0<Analog> => 8_u8,
gpio::PB1<Analog> => 9_u8,
gpio::PC0<Analog> => 10_u8,
gpio::PC1<Analog> => 11_u8,
gpio::PC2<Analog> => 12_u8,
gpio::PC3<Analog> => 13_u8,
gpio::PC4<Analog> => 14_u8,
gpio::PC5<Analog> => 15_u8,
gpio::PA0<Analog> => 0,
gpio::PA1<Analog> => 1,
gpio::PA2<Analog> => 2,
gpio::PA3<Analog> => 3,
gpio::PA4<Analog> => 4,
gpio::PA5<Analog> => 5,
gpio::PA6<Analog> => 6,
gpio::PA7<Analog> => 7,
gpio::PB0<Analog> => 8,
gpio::PB1<Analog> => 9,
gpio::PC0<Analog> => 10,
gpio::PC1<Analog> => 11,
gpio::PC2<Analog> => 12,
gpio::PC3<Analog> => 13,
gpio::PC4<Analog> => 14,
gpio::PC5<Analog> => 15,
);

#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
adc_pins!(pac::ADC3,
gpio::PA0<Analog> => 0_u8,
gpio::PA1<Analog> => 1_u8,
gpio::PA2<Analog> => 2_u8,
gpio::PA3<Analog> => 3_u8,
gpio::PF6<Analog> => 4_u8,
gpio::PF7<Analog> => 5_u8,
gpio::PF8<Analog> => 6_u8,
gpio::PF9<Analog> => 7_u8,
gpio::PF10<Analog> => 8_u8,
gpio::PC0<Analog> => 10_u8,
gpio::PC1<Analog> => 11_u8,
gpio::PC2<Analog> => 12_u8,
gpio::PC3<Analog> => 13_u8,
gpio::PA0<Analog> => 0,
gpio::PA1<Analog> => 1,
gpio::PA2<Analog> => 2,
gpio::PA3<Analog> => 3,
gpio::PF6<Analog> => 4,
gpio::PF7<Analog> => 5,
gpio::PF8<Analog> => 6,
gpio::PF9<Analog> => 7,
gpio::PF10<Analog> => 8,
gpio::PC0<Analog> => 10,
gpio::PC1<Analog> => 11,
gpio::PC2<Analog> => 12,
gpio::PC3<Analog> => 13,
);

/// Stored ADC config can be restored using the `Adc::restore_cfg` method
Expand Down Expand Up @@ -246,7 +246,7 @@
/// Returns the largest possible sample value for the current settings
pub fn max_sample(&self) -> u16 {
match self.align {
Align::Left => u16::max_value(),

Check warning on line 249 in src/adc.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/adc.rs:249:45 | 249 | Align::Left => u16::max_value(), | ^^^^^^^^^^^ ... 545 | / adc_hal! { 546 | | pac::ADC2: (adc2), 547 | | } | |_- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: this warning originates in the macro `adc_hal` (in Nightly builds, run with -Z macro-backtrace for more info) help: use the associated constant instead | 249 | Align::Left => u16::MAX, | ~~~

Check warning on line 249 in src/adc.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/adc.rs:249:45 | 249 | Align::Left => u16::max_value(), | ^^^^^^^^^^^ ... 540 | / adc_hal! { 541 | | pac::ADC1: (adc1), 542 | | } | |_- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default = note: this warning originates in the macro `adc_hal` (in Nightly builds, run with -Z macro-backtrace for more info) help: use the associated constant instead | 249 | Align::Left => u16::MAX, | ~~~
Align::Right => (1 << 12) - 1,
}
}
Expand Down
Loading
Loading