Skip to content

Commit

Permalink
bump hal to 0.16 for xiao_m0
Browse files Browse the repository at this point in the history
  • Loading branch information
fooker committed Dec 4, 2023
1 parent 7d7b21a commit 25e3532
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion boards/xiao_m0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = "0.7"
optional = true

[dependencies.atsamd-hal]
version = "0.14"
version = "0.16"
default-features = false

[dependencies.usb-device]
Expand Down
8 changes: 4 additions & 4 deletions boards/xiao_m0/examples/sercom_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions boards/xiao_m0/examples/shared_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions boards/xiao_m0/examples/ssd1306_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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,
Expand Down
31 changes: 18 additions & 13 deletions boards/xiao_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -154,25 +151,32 @@ pub fn uart(
.enable()
}

/// I2C master for the labelled SDA & SCL pins
pub type I2C = I2CMaster0<Sda, Scl>;
pub type I2cPads = i2c::Pads<Sercom0, Sda, Scl>;

/// 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<i2c::Config<I2cPads>>;

/// 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<Hertz>,
sercom0: pac::SERCOM0,
sercom: Sercom0,
pm: &mut pac::PM,
sda: impl Into<Sda>,
scl: impl Into<Scl>,
) -> 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
Expand All @@ -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)
Expand Down

0 comments on commit 25e3532

Please sign in to comment.