Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update feather_m4 bsp and examples to v2 as much as possible #487

Merged
merged 7 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/feather_m0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ pub fn i2c_master(
I2CMaster3::new(clock, baud, sercom3, pm, sda, scl)
}

/// UART pads for the labelled RX & TX pins
pub type UartPads = uart::Pads<Sercom0, UartRx, UartTx>;

/// UART device for the labelled RX & TX pins
Expand All @@ -291,6 +292,7 @@ pub fn uart(
}

#[cfg(feature = "usb")]
/// Convenience function for setting up USB
pub fn usb_allocator(
usb: pac::USB,
clocks: &mut GenericClockController,
Expand Down
6 changes: 3 additions & 3 deletions boards/feather_m4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ readme = "README.md"
documentation = "https://atsamd-rs.github.io/atsamd/atsamd51j/feather_m4/"

[dependencies]
cortex-m = "~0.6"
cortex-m = "0.7"
embedded-hal = "0.2.3"
nb = "0.1"

[dependencies.cortex-m-rt]
version = "0.6.12"
version = "0.7"
optional = true

[dependencies.atsamd-hal]
version = "0.13"
path = "../../hal"
default-features = false

[dependencies.usb-device]
Expand Down
6 changes: 3 additions & 3 deletions boards/feather_m4/examples/blinky_basic.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![no_std]
#![no_main]

use bsp::hal;
use feather_m4 as bsp;
#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
use panic_semihosting as _;

use bsp::entry;
use bsp::hal;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::pac::{CorePeripherals, Peripherals};
Expand All @@ -25,8 +25,8 @@ fn main() -> ! {
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output();
let mut delay = Delay::new(core.SYST, &mut clocks);
loop {
delay.delay_ms(2000u16);
Expand Down
4 changes: 2 additions & 2 deletions boards/feather_m4/examples/dmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use cortex_m::asm;
use feather_m4 as bsp;
use panic_halt as _;

use bsp::hal;
use hal::{
clock::GenericClockController,
entry,
pac::{CorePeripherals, Peripherals},
};

use hal::dmac::{DmaController, PriorityLevel, Transfer, TriggerAction, TriggerSource};

#[entry]
#[bsp::entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
Expand Down
5 changes: 3 additions & 2 deletions boards/feather_m4/examples/neopixel_rainbow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand Down Expand Up @@ -39,11 +40,11 @@ fn main() -> ! {
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = bsp::Pins::new(peripherals.PORT);
let pins = bsp::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);

// (Re-)configure PB3 as output
let ws_data_pin = pins.neopixel.into_push_pull_output(&mut pins.port);
let ws_data_pin = pins.neopixel.into_push_pull_output();
// Create a spin timer whoes period will be 9 x 120MHz clock cycles (75ns)
let timer = SpinTimer::new(9);
let mut neopixel = ws2812::Ws2812::new(timer, ws_data_pin);
Expand Down
5 changes: 3 additions & 2 deletions boards/feather_m4/examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand All @@ -33,8 +34,8 @@ fn main() -> ! {
);

let mut delay = Delay::new(core.SYST, &mut clocks);
let mut pins = bsp::Pins::new(peripherals.PORT);
let red_led = pins.d13.into_function_e(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let red_led: bsp::RedLedPwm = pins.d13.into();

let gclk0 = clocks.gclk0();
let mut pwm4 = Pwm4::new(
Expand Down
27 changes: 7 additions & 20 deletions boards/feather_m4/examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand All @@ -15,7 +16,6 @@ use hal::pac::gclk::genctrl::SRC_A;
use hal::pac::gclk::pchctrl::GEN_A;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
use hal::sercom::{PadPin, Sercom5Pad0, Sercom5Pad1, UART5};
use hal::time::Hertz;

#[entry]
Expand All @@ -30,31 +30,18 @@ fn main() -> ! {
&mut peripherals.NVMCTRL,
);
clocks.configure_gclk_divider_and_source(GEN_A::GCLK2, 1, SRC_A::DFLL, false);
let gclk2 = clocks
.get_gclk(GEN_A::GCLK2)
.expect("Could not get clock 2");

let mut pins = bsp::Pins::new(peripherals.PORT);
let pins = bsp::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);

let tx: Sercom5Pad0<_> = pins
.d1
.into_pull_down_input(&mut pins.port)
.into_pad(&mut pins.port);
let rx: Sercom5Pad1<_> = pins
.d0
.into_pull_down_input(&mut pins.port)
.into_pad(&mut pins.port);
let uart_clk = clocks
.sercom5_core(&gclk2)
.expect("Could not configure sercom5 clock");

let mut uart = UART5::new(
&uart_clk,
let (tx, rx) = (pins.d1, pins.d0);
let mut uart = bsp::uart(
&mut clocks,
Hertz(19200),
peripherals.SERCOM5,
&mut peripherals.MCLK,
(rx, tx),
rx,
tx,
);

loop {
Expand Down
5 changes: 3 additions & 2 deletions boards/feather_m4/examples/sleeping_timer_rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand Down Expand Up @@ -65,8 +66,8 @@ fn main() -> ! {
});

// Configure our red LED and blink forever, sleeping between!
let mut pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output();
loop {
red_led.set_low().unwrap();
sleeping_delay.delay_ms(1_000u32);
Expand Down
4 changes: 2 additions & 2 deletions boards/feather_m4/examples/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn main() -> ! {
&mut peripherals.NVMCTRL,
);
// Using the red LED as the feedback for this simple timer example.
let mut pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output();

// gclk0 represents a configured clock using the 120MHz oscillator.
let gclk0 = clocks.gclk0();
Expand Down
5 changes: 3 additions & 2 deletions boards/feather_m4/examples/trng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand All @@ -30,8 +31,8 @@ fn main() -> ! {
);
// We will use the red led and a delay in this simplest possible
// demonstration of the random number generator.
let mut pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output();
let mut delay = hal::delay::Delay::new(core.SYST, &mut clocks);

// Create a struct as a representation of the random number generator peripheral
Expand Down
29 changes: 8 additions & 21 deletions boards/feather_m4/examples/uart_poll_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand All @@ -22,7 +23,6 @@ use hal::pac::gclk::genctrl::SRC_A;
use hal::pac::gclk::pchctrl::GEN_A;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
use hal::sercom::{PadPin, Sercom5Pad0, Sercom5Pad1, UART5};
use hal::time::Hertz;

#[entry]
Expand All @@ -37,32 +37,19 @@ fn main() -> ! {
&mut peripherals.NVMCTRL,
);
clocks.configure_gclk_divider_and_source(GEN_A::GCLK2, 1, SRC_A::DFLL, false);
let gclk2 = clocks
.get_gclk(GEN_A::GCLK2)
.expect("Could not get clock 2");

let mut pins = bsp::Pins::new(peripherals.PORT);
let pins = bsp::Pins::new(peripherals.PORT);
let mut delay = Delay::new(core.SYST, &mut clocks);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);

let tx: Sercom5Pad0<_> = pins
.d1
.into_pull_down_input(&mut pins.port)
.into_pad(&mut pins.port);
let rx: Sercom5Pad1<_> = pins
.d0
.into_pull_down_input(&mut pins.port)
.into_pad(&mut pins.port);
let uart_clk = clocks
.sercom5_core(&gclk2)
.expect("Could not configure sercom5 clock");
let mut red_led = pins.d13.into_push_pull_output();

let mut uart = UART5::new(
&uart_clk,
let (tx, rx) = (pins.d1, pins.d0);
let mut uart = bsp::uart(
&mut clocks,
Hertz(19200),
peripherals.SERCOM5,
&mut peripherals.MCLK,
(rx, tx),
rx,
tx,
);

// Write out a message on start up
Expand Down
8 changes: 5 additions & 3 deletions boards/feather_m4/examples/usb_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use bsp::hal;
use feather_m4 as bsp;

#[cfg(not(feature = "use_semihosting"))]
use panic_halt as _;
#[cfg(feature = "use_semihosting")]
Expand All @@ -11,6 +12,7 @@ use panic_semihosting as _;
use bsp::entry;
use hal::clock::GenericClockController;
use hal::pac::{interrupt, CorePeripherals, Peripherals};
use hal::prelude::*;
use hal::usb::UsbBus;

use usb_device::bus::UsbBusAllocator;
Expand All @@ -31,8 +33,8 @@ fn main() -> ! {
&mut peripherals.OSCCTRL,
&mut peripherals.NVMCTRL,
);
let mut pins = bsp::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
let pins = bsp::Pins::new(peripherals.PORT);
let mut red_led: bsp::RedLed = pins.d13.into();

let bus_allocator = unsafe {
USB_ALLOCATOR = Some(bsp::usb_allocator(
Expand Down Expand Up @@ -68,7 +70,7 @@ fn main() -> ! {

loop {
cycle_delay(5 * 1024 * 1024);
red_led.toggle();
red_led.toggle().unwrap();
}
}

Expand Down
Loading