diff options
Diffstat (limited to 'app/src/dotstar.rs')
-rw-r--r-- | app/src/dotstar.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/src/dotstar.rs b/app/src/dotstar.rs new file mode 100644 index 0000000..8e930d0 --- /dev/null +++ b/app/src/dotstar.rs @@ -0,0 +1,42 @@ +use trinket_m0::{ + clock::GenericClockController, + gpio::{self, Floating, Input}, + prelude::*, + sercom::{self, PadPin, SPIMaster1}, + PM, SERCOM1, +}; + +use apa102_spi::Apa102; + +pub fn new( + sercom: SERCOM1, + miso: gpio::Pa31<Input<Floating>>, + mosi: gpio::Pa0<Input<Floating>>, + sck: gpio::Pa1<Input<Floating>>, + port: &mut gpio::Port, + pm: &mut PM, + clocks: &mut GenericClockController, +) -> Apa102< + SPIMaster1< + sercom::Sercom1Pad3<gpio::Pa31<gpio::PfD>>, + sercom::Sercom1Pad0<gpio::Pa0<gpio::PfD>>, + sercom::Sercom1Pad1<gpio::Pa1<gpio::PfD>>, + >, +> { + let gclk = clocks.gclk0(); + let miso = miso.into_pad(port); + let mosi = mosi.into_pad(port); + let sck = sck.into_pad(port); + let spi = SPIMaster1::new( + &clocks + .sercom1_core(&gclk) + .expect("setting up sercom1 clock"), + 3.mhz(), + apa102_spi::MODE, + sercom, + pm, + (miso, mosi, sck), + ); + + Apa102::new(spi) +} |