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 4bf82c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 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
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::{uart, Sercom0, Sercom4, i2c};
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 4bf82c3

Please sign in to comment.