From a4b22056bf7a26a04a45e62212f82836ecfac299 Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Mon, 4 Dec 2023 14:52:13 +0100 Subject: [PATCH] bump hal to 0.16 for xiao_m0 --- boards/xiao_m0/CHANGELOG.md | 2 ++ boards/xiao_m0/Cargo.toml | 2 +- boards/xiao_m0/examples/eic.rs | 2 +- boards/xiao_m0/examples/sercom_interrupt.rs | 8 +++--- boards/xiao_m0/examples/shared_i2c.rs | 4 +-- boards/xiao_m0/examples/ssd1306_i2c.rs | 4 +-- boards/xiao_m0/src/lib.rs | 31 ++++++++++++--------- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/boards/xiao_m0/CHANGELOG.md b/boards/xiao_m0/CHANGELOG.md index ba2210d0a806..1e8dea56366a 100644 --- a/boards/xiao_m0/CHANGELOG.md +++ b/boards/xiao_m0/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- Update atsamd-hal to 0.16 + # v0.12.1 - Updated to 2021 edition, updated dependencies, removed unused dependencies (#562) diff --git a/boards/xiao_m0/Cargo.toml b/boards/xiao_m0/Cargo.toml index de7e90cbc2c5..6d97980466e2 100644 --- a/boards/xiao_m0/Cargo.toml +++ b/boards/xiao_m0/Cargo.toml @@ -15,7 +15,7 @@ version = "0.7" optional = true [dependencies.atsamd-hal] -version = "0.14" +version = "0.16" default-features = false [dependencies.usb-device] diff --git a/boards/xiao_m0/examples/eic.rs b/boards/xiao_m0/examples/eic.rs index cec9b285726e..55c7d04044f6 100644 --- a/boards/xiao_m0/examples/eic.rs +++ b/boards/xiao_m0/examples/eic.rs @@ -20,7 +20,7 @@ use hal::{ pin::{ExtInt5, Sense}, EIC, }, - gpio::v2::{Pin, PullUpInterrupt}, + gpio::{Pin, PullUpInterrupt}, pac::{self, interrupt, CorePeripherals, Peripherals}, prelude::*, }; diff --git a/boards/xiao_m0/examples/sercom_interrupt.rs b/boards/xiao_m0/examples/sercom_interrupt.rs index feca6429d18f..7e203a6c7625 100644 --- a/boards/xiao_m0/examples/sercom_interrupt.rs +++ b/boards/xiao_m0/examples/sercom_interrupt.rs @@ -31,10 +31,10 @@ use bsp::hal::{ clock::GenericClockController, delay::Delay, ehal::blocking::delay::DelayMs, - gpio::v2::{Pin, PushPullOutput, PA17}, + gpio::{Pin, PushPullOutput, PA17}, pac::{self, interrupt, CorePeripherals, Peripherals}, prelude::*, - sercom::v2::{ + sercom::{ uart::{self, BaudMode, Oversampling}, Sercom0, }, @@ -86,7 +86,7 @@ fn main() -> ! { // custom sercom uart configuration let mut serial_sercom0 = uart0( &mut clocks, - Hertz(115200), + Hertz::Hz(115200), peripherals.SERCOM0, &mut peripherals.PM, pins.a5, @@ -96,7 +96,7 @@ fn main() -> ! { // labeled "default" uart let mut serial_sercom4 = bsp::uart( &mut clocks, - Hertz(115200), + Hertz::Hz(115200), peripherals.SERCOM4, &mut peripherals.PM, pins.a7, diff --git a/boards/xiao_m0/examples/shared_i2c.rs b/boards/xiao_m0/examples/shared_i2c.rs index 39f95016c38d..ef2cf6776ef9 100644 --- a/boards/xiao_m0/examples/shared_i2c.rs +++ b/boards/xiao_m0/examples/shared_i2c.rs @@ -5,7 +5,7 @@ extern crate panic_halt; use core::fmt::Write; -use hal::{clock::GenericClockController, delay::Delay, prelude::*, time::KiloHertz}; +use hal::{clock::GenericClockController, delay::Delay, prelude::*, time::Hertz}; use mpu6050::Mpu6050; use pac::{CorePeripherals, Peripherals}; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; @@ -27,7 +27,7 @@ fn main() -> ! { let mut delay = Delay::new(core.SYST, &mut clocks); let i2c = bsp::i2c_master( &mut clocks, - KiloHertz(400), + Hertz::kHz(400), peripherals.SERCOM0, &mut peripherals.PM, pins.a4, diff --git a/boards/xiao_m0/examples/ssd1306_i2c.rs b/boards/xiao_m0/examples/ssd1306_i2c.rs index c09d2cfeac8e..d92137da558a 100644 --- a/boards/xiao_m0/examples/ssd1306_i2c.rs +++ b/boards/xiao_m0/examples/ssd1306_i2c.rs @@ -8,7 +8,7 @@ use embedded_graphics::{ prelude::*, primitives::{Circle, PrimitiveStyleBuilder}, }; -use hal::{clock::GenericClockController, delay::Delay, prelude::*, time::KiloHertz}; +use hal::{clock::GenericClockController, delay::Delay, prelude::*, time::Hertz}; use pac::{CorePeripherals, Peripherals}; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; @@ -29,7 +29,7 @@ fn main() -> ! { let mut delay = Delay::new(core.SYST, &mut clocks); let i2c = bsp::i2c_master( &mut clocks, - KiloHertz(400), + Hertz::kHz(400), peripherals.SERCOM0, &mut peripherals.PM, pins.a4, diff --git a/boards/xiao_m0/src/lib.rs b/boards/xiao_m0/src/lib.rs index 4983529d941b..4a6be26b46f4 100644 --- a/boards/xiao_m0/src/lib.rs +++ b/boards/xiao_m0/src/lib.rs @@ -6,17 +6,14 @@ pub use cortex_m_rt::entry; use hal::clock::GenericClockController; pub use hal::ehal; pub use hal::pac; -use hal::sercom::{ - v2::{uart, Sercom0, Sercom4}, - I2CMaster0, -}; +use hal::sercom::{i2c, uart, Sercom0, Sercom4}; use hal::time::Hertz; #[cfg(feature = "usb")] use hal::usb::{usb_device::bus::UsbBusAllocator, UsbBus}; use spi::Pads; -use crate::hal::sercom::v2::spi; -use crate::hal::sercom::v2::uart::{BaudMode, Oversampling}; +use crate::hal::sercom::spi; +use crate::hal::sercom::uart::{BaudMode, Oversampling}; pub use pins::*; /// Definitions related to pins and pin aliases @@ -154,25 +151,32 @@ pub fn uart( .enable() } -/// I2C master for the labelled SDA & SCL pins -pub type I2C = I2CMaster0; +pub type I2cPads = i2c::Pads; + +/// I2C master for the labelled I2C peripheral +/// +/// This type implements [`Read`](ehal::blocking::i2c::Read), +/// [`Write`](ehal::blocking::i2c::Write) and +/// [`WriteRead`](ehal::blocking::i2c::WriteRead). +pub type I2c = i2c::I2c>; /// Convenience for setting up the labelled SDA, SCL pins to /// operate as an I2C master running at the specified frequency. pub fn i2c_master( clocks: &mut GenericClockController, baud: impl Into, - sercom0: pac::SERCOM0, + sercom: Sercom0, pm: &mut pac::PM, sda: impl Into, scl: impl Into, -) -> I2C { +) -> I2c { let gclk0 = clocks.gclk0(); let clock = &clocks.sercom0_core(&gclk0).unwrap(); + let freq = clock.freq(); let baud = baud.into(); - let sda = sda.into(); - let scl = scl.into(); - I2CMaster0::new(clock, baud, sercom0, pm, sda, scl) + let pads = i2c::Pads::new(sda.into(), scl.into()); + + i2c::Config::new(pm, sercom, pads, freq).baud(baud).enable() } /// SPI pads for the labelled SPI peripheral @@ -198,6 +202,7 @@ pub fn spi_master( let gclk0 = clocks.gclk0(); let clock = clocks.sercom4_core(&gclk0).unwrap(); let freq = clock.freq(); + let baud = baud.into(); let (miso, mosi, sclk) = (miso.into(), mosi.into(), sclk.into()); let pads = Pads::default().data_in(miso).data_out(mosi).sclk(sclk); spi::Config::new(pm, sercom0, pads, freq)