forked from atsamd-rs/atsamd
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2fb295
commit cec7f64
Showing
12 changed files
with
437 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![feature(type_alias_impl_trait)] | ||
|
||
use panic_probe as _; | ||
use defmt_rtt as _; | ||
|
||
#[rtic::app(device = bsp::pac, dispatchers = [I2S])] | ||
mod app { | ||
use bsp::{hal, pac, pin_alias}; | ||
use feather_m0 as bsp; | ||
use hal::{ | ||
prelude::*, | ||
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController}, | ||
ehal::digital::v2::ToggleableOutputPin, | ||
rtc::{Count32Mode, Rtc}, | ||
sercom::i2c::{self,Config, I2cFuture}, | ||
}; | ||
use fugit::MillisDuration; | ||
|
||
#[monotonic(binds = RTC, default = true)] | ||
type Monotonic = Rtc<Count32Mode>; | ||
|
||
#[shared] | ||
struct Shared {} | ||
|
||
#[local] | ||
struct Local { | ||
i2c: I2cFuture<Config<bsp::I2cPads>, bsp::pac::Interrupt>, | ||
red_led: bsp::RedLed, | ||
} | ||
|
||
#[init] | ||
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { | ||
let mut peripherals = cx.device; | ||
let _core = cx.core; | ||
|
||
let mut clocks = GenericClockController::with_external_32kosc( | ||
peripherals.GCLK, | ||
&mut peripherals.PM, | ||
&mut peripherals.SYSCTRL, | ||
&mut peripherals.NVMCTRL, | ||
); | ||
let pins = bsp::Pins::new(peripherals.PORT); | ||
let red_led: bsp::RedLed = pin_alias!(pins.red_led).into(); | ||
|
||
// Take SDA and SCL | ||
let (sda, scl) = (pins.sda, pins.scl); | ||
|
||
let sercom3_irq = cortex_m_interrupt::take_nvic_interrupt!(pac::Interrupt::SERCOM3, 2); | ||
// tc4_irq.set_priority(2); | ||
|
||
enable_internal_32kosc(&mut peripherals.SYSCTRL); | ||
let timer_clock = clocks | ||
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::OSC32K, false) | ||
.unwrap(); | ||
clocks.configure_standby(ClockGenId::GCLK2, true); | ||
|
||
// Setup RTC monotonic | ||
let rtc_clock = clocks.rtc(&timer_clock).unwrap(); | ||
let rtc = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM); | ||
|
||
let gclk0 = clocks.gclk0(); | ||
let sercom3_clock = &clocks.sercom3_core(&gclk0).unwrap(); | ||
let pads = i2c::Pads::new(sda, scl); | ||
let i2c = i2c::Config::new(&peripherals.PM, peripherals.SERCOM3, pads, sercom3_clock.freq()) | ||
.baud(100.khz()) | ||
.enable().into_async(sercom3_irq); | ||
|
||
|
||
async_task::spawn().ok(); | ||
|
||
(Shared {}, Local { i2c, red_led }, init::Monotonics(rtc)) | ||
} | ||
|
||
#[task(local = [i2c, red_led])] | ||
async fn async_task(cx: async_task::Context) { | ||
let i2c = cx.local.i2c; | ||
let red_led = cx.local.red_led; | ||
|
||
loop { | ||
defmt::info!("Sending 1 byte to I2C..."); | ||
// This test is based on the BMP388 barometer. Feel free to use any I2C peripheral | ||
// you have on hand. | ||
i2c.write(0x76, &[0x00]).await.unwrap(); | ||
|
||
let mut buffer = [0x00; 1]; | ||
defmt::info!("Reading 1 byte from I2C..."); | ||
i2c.read(0x76, &mut buffer).await.unwrap(); | ||
defmt::info!("Chip ID is: {:#x}", buffer[0]); | ||
red_led.toggle().unwrap(); | ||
crate::app::monotonics::delay(MillisDuration::<u32>::from_ticks(500).convert()).await; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
//! Async APIs | ||
#[cfg(feature = "samd11")] | ||
#[path = "irqs_samd11.rs"] | ||
mod irqs; | ||
// #[cfg(feature = "samd11")] | ||
// #[path = "irqs_samd11.rs"] | ||
// mod irqs; | ||
|
||
#[cfg(feature = "samd21")] | ||
#[path = "irqs_samd21.rs"] | ||
mod irqs; | ||
// #[cfg(feature = "samd21")] | ||
// #[path = "irqs_samd21.rs"] | ||
// mod irqs; | ||
|
||
#[cfg(feature = "samd51")] | ||
#[path = "irqs_thumbv7em.rs"] | ||
mod irqs; | ||
// #[cfg(feature = "samd51")] | ||
// #[path = "irqs_thumbv7em.rs"] | ||
// mod irqs; | ||
|
||
pub mod interrupt { | ||
pub use super::irqs::*; | ||
pub use cortex_m::interrupt::{CriticalSection, Mutex}; | ||
pub use embassy::interrupt::{declare, take, Interrupt}; | ||
// pub mod interrupt { | ||
// pub use super::irqs::*; | ||
// pub use cortex_m::interrupt::{CriticalSection, Mutex}; | ||
// pub use embassy::interrupt::{declare, take, Interrupt}; | ||
|
||
// TODO Priority2 seems to only be true for thumbv6m chips | ||
pub use embassy_hal_common::interrupt::Priority2 as Priority; | ||
} | ||
// // TODO Priority2 seems to only be true for thumbv6m chips | ||
// pub use embassy_hal_common::interrupt::Priority2 as Priority; | ||
// } | ||
|
||
pub mod timer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.