Move Move dotstar timer init to dotstar init

This commit is contained in:
Aode (Lion) 2022-02-10 12:48:25 -06:00
parent 10b98e1ad1
commit d349148229
2 changed files with 14 additions and 9 deletions

View file

@ -7,6 +7,7 @@ use hal::{
Disabled, Floating, Input, Output, Pin, PullUp, PushPull, PA00, PA01, PA14, PA24, PA25,
},
prelude::_embedded_hal_timer_CountDown as CountDown,
time::MegaHertz,
usb::UsbBus,
};
use usb_device::class_prelude::UsbBusAllocator;
@ -40,7 +41,14 @@ pub type Spi<C> = bitbang_hal::spi::SPI<
>;
impl Dotstar {
pub fn init<C: CountDown + Periodic>(self, timer: C) -> apa102_spi::Apa102<Spi<C>> {
pub fn init<C>(self, mut timer: C) -> apa102_spi::Apa102<Spi<C>>
where
C: CountDown + Periodic,
C::Time: From<MegaHertz>,
{
// Adafruit Dotstar is always hardcoded to 8MHz
timer.start(MegaHertz(8));
let spi = bitbang_hal::spi::SPI::new(
apa102_spi::MODE,
self.nc.into(),

View file

@ -3,9 +3,8 @@
use atsamd_hal::{
clock::{ClockGenId, ClockSource},
prelude::_embedded_hal_timer_CountDown,
rtc::{Count32Mode, Rtc},
time::MegaHertz,
timer::TimerCounter,
};
use panic_halt as _; // you can put a breakpoint on `rust_begin_unwind` to catch panics
@ -61,6 +60,7 @@ fn is_handshake_complete() -> bool {
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let mut core = CorePeripherals::take().unwrap();
// initializes gclk0 at 48MHz and gclk1 at 32KHz
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.GCLK,
&mut peripherals.PM,
@ -124,12 +124,11 @@ fn main() -> ! {
}
.init();
// Use 32KHz clock for Rtc
let rtc_gclk = clocks
.configure_gclk_divider_and_source(ClockGenId::GCLK3, 32, ClockSource::OSC32K, true)
.unwrap();
clocks.configure_standby(ClockGenId::GCLK3, true);
let rtc_clock = clocks.rtc(&rtc_gclk).unwrap();
let mut counter = Rtc::count32_mode(peripherals.RTC, rtc_clock.freq(), &mut peripherals.PM);
counter.set_count32(0);
@ -138,12 +137,10 @@ fn main() -> ! {
*rtc.borrow_mut() = Some(counter);
});
// Use 48MHz clock for dotstar
let dotstar_gclk = clocks.gclk0();
let tc4_tc5 = &clocks.tc4_tc5(&dotstar_gclk).unwrap();
let mut timer =
atsamd_hal::timer::TimerCounter::tc4_(tc4_tc5, peripherals.TC4, &mut peripherals.PM);
timer.start(MegaHertz(8));
let timer = TimerCounter::tc4_(tc4_tc5, peripherals.TC4, &mut peripherals.PM);
let mut updated_at = 0;