-
Notifications
You must be signed in to change notification settings - Fork 201
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
bbc1f60
commit bd3538f
Showing
30 changed files
with
1,068 additions
and
53 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
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,73 @@ | ||
//! This example shows a safe API to | ||
//! execute a memory-to-memory DMA transfer | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use defmt_rtt as _; | ||
use panic_probe as _; | ||
|
||
atsamd_hal::bind_interrupts!(struct Irqs { | ||
DMAC => atsamd_hal::dmac::InterruptHandler; | ||
}); | ||
|
||
use bsp::hal; | ||
use bsp::pac; | ||
use feather_m0 as bsp; | ||
use hal::{ | ||
clock::GenericClockController, | ||
dmac::{DmaController, PriorityLevel, TriggerAction, TriggerSource}, | ||
}; | ||
|
||
#[embassy_executor::main] | ||
async fn main(_s: embassy_executor::Spawner) { | ||
let mut peripherals = pac::Peripherals::take().unwrap(); | ||
let _core = pac::CorePeripherals::take().unwrap(); | ||
|
||
let _clocks = GenericClockController::with_external_32kosc( | ||
peripherals.GCLK, | ||
&mut peripherals.PM, | ||
&mut peripherals.SYSCTRL, | ||
&mut peripherals.NVMCTRL, | ||
); | ||
|
||
// Initialize DMA Controller | ||
let dmac = DmaController::init(peripherals.DMAC, &mut peripherals.PM); | ||
|
||
// Turn dmac into an async controller | ||
let mut dmac = dmac.into_future(crate::Irqs); | ||
// Get individual handles to DMA channels | ||
let channels = dmac.split(); | ||
|
||
// Initialize DMA Channel 0 | ||
let mut channel = channels.0.init(PriorityLevel::LVL0); | ||
|
||
let mut source = [0xff; 500]; | ||
let mut dest = [0x0; 500]; | ||
|
||
defmt::info!( | ||
"Launching a DMA transfer.\n\tSource: {}\n\tDestination: {}", | ||
&source, | ||
&dest | ||
); | ||
|
||
channel | ||
.transfer_future( | ||
&mut source, | ||
&mut dest, | ||
TriggerSource::DISABLE, | ||
TriggerAction::BLOCK, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
defmt::info!( | ||
"Finished DMA transfer.\n\tSource: {}\n\tDestination: {}", | ||
&source, | ||
&dest | ||
); | ||
|
||
loop { | ||
cortex_m::asm::wfi(); | ||
} | ||
} |
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,60 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use defmt_rtt as _; | ||
use panic_probe as _; | ||
|
||
use bsp::pac; | ||
use bsp::{hal, pin_alias}; | ||
use feather_m0 as bsp; | ||
use hal::{ | ||
clock::{enable_internal_32kosc, ClockGenId, ClockSource, GenericClockController}, | ||
ehal::digital::v2::ToggleableOutputPin, | ||
eic::{ | ||
pin::{ExtInt2, Sense}, | ||
EIC, | ||
}, | ||
gpio::{Pin, PullUpInterrupt}, | ||
}; | ||
|
||
atsamd_hal::bind_interrupts!(struct Irqs { | ||
EIC => atsamd_hal::eic::InterruptHandler; | ||
}); | ||
|
||
#[embassy_executor::main] | ||
async fn main(_s: embassy_executor::Spawner) { | ||
let mut peripherals = pac::Peripherals::take().unwrap(); | ||
let _core = pac::CorePeripherals::take().unwrap(); | ||
|
||
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 mut red_led: bsp::RedLed = pin_alias!(pins.red_led).into(); | ||
|
||
let _internal_clock = clocks | ||
.configure_gclk_divider_and_source(ClockGenId::GCLK2, 1, ClockSource::OSC32K, false) | ||
.unwrap(); | ||
clocks.configure_standby(ClockGenId::GCLK2, true); | ||
|
||
enable_internal_32kosc(&mut peripherals.SYSCTRL); | ||
|
||
// Configure a clock for the EIC peripheral | ||
let gclk2 = clocks.get_gclk(ClockGenId::GCLK2).unwrap(); | ||
let eic_clock = clocks.eic(&gclk2).unwrap(); | ||
|
||
let mut eic = EIC::init(&mut peripherals.PM, eic_clock, peripherals.EIC).into_future(Irqs); | ||
let button: Pin<_, PullUpInterrupt> = pins.d10.into(); | ||
let mut extint = ExtInt2::new(button, &mut eic); | ||
extint.enable_interrupt_wake(); | ||
|
||
loop { | ||
// Here we show straight falling edge detection without | ||
extint.wait(Sense::FALL).await; | ||
defmt::info!("Falling edge detected"); | ||
red_led.toggle().unwrap(); | ||
} | ||
} |
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,77 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use defmt_rtt as _; | ||
use panic_probe as _; | ||
|
||
use bsp::hal; | ||
use bsp::pac; | ||
use feather_m0 as bsp; | ||
use fugit::MillisDuration; | ||
use hal::{ | ||
clock::GenericClockController, | ||
dmac::{DmaController, PriorityLevel}, | ||
prelude::*, | ||
sercom::{i2c, Sercom3}, | ||
}; | ||
use rtic_monotonics::systick::Systick; | ||
|
||
atsamd_hal::bind_interrupts!(struct Irqs { | ||
SERCOM3 => atsamd_hal::sercom::i2c::InterruptHandler<Sercom3>; | ||
DMAC => atsamd_hal::dmac::InterruptHandler; | ||
}); | ||
|
||
#[embassy_executor::main] | ||
async fn main(_s: embassy_executor::Spawner) { | ||
let mut peripherals = pac::Peripherals::take().unwrap(); | ||
let _core = pac::CorePeripherals::take().unwrap(); | ||
|
||
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); | ||
|
||
// Take SDA and SCL | ||
let (sda, scl) = (pins.sda, pins.scl); | ||
|
||
// Initialize DMA Controller | ||
let dmac = DmaController::init(peripherals.DMAC, &mut peripherals.PM); | ||
|
||
// Turn dmac into an async controller | ||
let mut dmac = dmac.into_future(Irqs); | ||
// Get individual handles to DMA channels | ||
let channels = dmac.split(); | ||
|
||
// Initialize DMA Channel 0 | ||
let channel0 = channels.0.init(PriorityLevel::LVL0); | ||
|
||
let gclk0 = clocks.gclk0(); | ||
let sercom3_clock = &clocks.sercom3_core(&gclk0).unwrap(); | ||
let pads = i2c::Pads::new(sda, scl); | ||
let mut i2c = i2c::Config::new( | ||
&peripherals.PM, | ||
peripherals.SERCOM3, | ||
pads, | ||
sercom3_clock.freq(), | ||
) | ||
.baud(100.kHz()) | ||
.enable() | ||
.into_future(Irqs) | ||
.with_dma_channel(channel0); | ||
|
||
loop { | ||
defmt::info!("Sending 0x00 to I2C device..."); | ||
// 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 = [0xff; 4]; | ||
i2c.read(0x76, &mut buffer).await.unwrap(); | ||
defmt::info!("Read buffer: {:#x}", buffer); | ||
Systick::delay(MillisDuration::<u32>::from_ticks(500).convert()).await; | ||
} | ||
} |
Oops, something went wrong.