Remove trinket_m0 bsp crate

This commit is contained in:
Aode (Lion) 2022-02-10 11:19:34 -06:00
parent 0d9b3c8bcc
commit 10b98e1ad1
3 changed files with 43 additions and 18 deletions

View file

@ -8,7 +8,12 @@ build = "src/build.rs"
[dependencies]
apa102-spi = "0.3.2"
atsamd-hal = "0.14"
atsamd-hal = { version = "0.14", default-features = false, features = [
"samd21e",
"samd21e-rt",
"unproven",
"usb",
] }
bitbang-hal = "0.3.2"
cortex-m = "0.7.4"
cortex-m-rt = "0.7.1"
@ -17,7 +22,6 @@ embedded-hal = "0.2"
once_cell = { version = "1.7.2", default-features = false }
panic-halt = "0.2.0"
smart-leds = "0.3"
trinket_m0 = { version = "0.11.0", features = ["unproven", "usb"] }
usb-device = "0.2"
usbd-serial = "0.1"
streamdeck-common = { version = "0.1.0", path = "./streamdeck-common" }

View file

@ -1,8 +1,15 @@
use atsamd_hal::gpio::v2::{
Disabled, Floating, Input, Output, Pin, PullUp, PushPull, PA00, PA01, PA14,
};
use atsamd_hal::prelude::_embedded_hal_timer_CountDown as CountDown;
pub use atsamd_hal as hal;
pub use cortex_m_rt::entry;
use embedded_hal::timer::Periodic;
use hal::{
gpio::v2::{
Disabled, Floating, Input, Output, Pin, PullUp, PushPull, PA00, PA01, PA14, PA24, PA25,
},
prelude::_embedded_hal_timer_CountDown as CountDown,
usb::UsbBus,
};
use usb_device::class_prelude::UsbBusAllocator;
pub struct Dotstar {
pub ci: Pin<PA01, Disabled<Floating>>,
@ -10,6 +17,21 @@ pub struct Dotstar {
pub nc: Pin<PA14, Disabled<Floating>>,
}
pub fn usb_allocator(
usb: hal::pac::USB,
clocks: &mut hal::clock::GenericClockController,
pm: &mut hal::pac::PM,
dm: Pin<PA24, Disabled<Floating>>,
dp: Pin<PA25, Disabled<Floating>>,
) -> Option<UsbBusAllocator<UsbBus>> {
let gckl0 = clocks.gclk0();
let usb_clock = &clocks.usb(&gckl0)?;
Some(UsbBusAllocator::new(UsbBus::new(
usb_clock, pm, dm, dp, usb,
)))
}
pub type Spi<C> = bitbang_hal::spi::SPI<
Pin<PA14, Input<PullUp>>,
Pin<PA00, Output<PushPull>>,
@ -31,7 +53,7 @@ impl Dotstar {
}
}
atsamd_hal::bsp_pins! (
hal::bsp_pins! (
PA08 {
name: d0
aliases: {

View file

@ -8,21 +8,19 @@ use atsamd_hal::{
time::MegaHertz,
};
use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch panics
use trinket_m0 as hal;
use atsamd_hal::{
clock::GenericClockController,
pac::{interrupt, CorePeripherals, Peripherals},
prelude::_atsamd_hal_embedded_hal_digital_v2_OutputPin,
usb::UsbBus,
};
use core::cell::RefCell;
use cortex_m::{
asm::delay as cycle_delay,
interrupt::Mutex,
peripheral::{NVIC, SCB},
};
use hal::{
clock::GenericClockController,
entry,
pac::{interrupt, CorePeripherals, Peripherals},
prelude::_atsamd_hal_embedded_hal_digital_v2_OutputPin,
usb::UsbBus,
};
use once_cell::unsync::OnceCell;
use smart_leds::{SmartLedsWrite, RGB8};
use streamdeck_common::{handle_input, Handshake, UnsafeSync};
@ -32,7 +30,7 @@ use usbd_serial::{SerialPort, USB_CLASS_CDC};
mod bsp;
mod trinket_buttons;
use bsp::{Dotstar, Pins};
use bsp::{entry, Dotstar, Pins};
use trinket_buttons::Buttons;
static USB_ALLOCATOR: UnsafeSync<OnceCell<UsbBusAllocator<UsbBus>>> =
@ -74,13 +72,14 @@ fn main() -> ! {
let mut red_led = pins.d13.into_push_pull_output();
red_led.set_low().unwrap();
let usb_allocator = hal::usb_allocator(
let usb_allocator = bsp::usb_allocator(
peripherals.USB,
&mut clocks,
&mut peripherals.PM,
pins.usb_dm,
pins.usb_dp,
);
)
.unwrap();
// SAFETY: No interrupt will access USB_ALLOCATOR before this point, since it is only
// referenced from inside the USB_SERIAL mutex and the USB_BUS mutex, which have not been set