From 35cfff068047de01aab1213324fb423092c4289f Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Wed, 26 Oct 2022 07:28:06 -0400 Subject: spi: use 1.5mhz, tweak some logging --- src/cirque.rs | 24 ++++++++++++++---------- src/main.rs | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/cirque.rs b/src/cirque.rs index af2ce6f..69f9903 100644 --- a/src/cirque.rs +++ b/src/cirque.rs @@ -69,6 +69,9 @@ enum RAPAddress { ProductID = 0x1f, } +// TODO: figure out how to use the +// embedded_hal::blocking::spi::{Transfer, Write} traits instead of +// doing it ourselves. trait SPIWriter: spi::FullDuplex { fn write(&mut self, buf: &[Word]) -> nb::Result<(), Self::Error>; fn transfer(&mut self, buf: &mut [Word]) -> nb::Result<(), Self::Error>; @@ -81,15 +84,16 @@ where { fn write(&mut self, buf: &[Word]) -> nb::Result<(), Self::Error> { for i in buf { - self.send(*i)?; + nb::block!(self.send(*i))?; + _ = nb::block!(self.read())?; } Ok(()) } fn transfer(&mut self, buf: &mut [Word]) -> nb::Result<(), Self::Error> { for i in buf.iter_mut() { - self.send(*i)?; - *i = self.read()?; + nb::block!(self.send(*i))?; + *i = nb::block!(self.read())?; } Ok(()) } @@ -141,7 +145,7 @@ where { pub fn new(cs_pin: C, dr_pin: D, spi: &mut S, clocks: Clocks) -> nb::Result where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { let sysclk_speed = clocks.sysclk().raw(); let mut res = Self { @@ -155,7 +159,7 @@ where fn init(&mut self, spi: &mut S) -> nb::Result<(), S::Error> where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { self.cs_pin.set_high().ok(); self.clear_flags(spi)?; @@ -174,7 +178,7 @@ where fn clear_flags(&mut self, spi: &mut S) -> nb::Result<(), S::Error> where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { self.wr(spi, 0x02, 0x00)?; @@ -185,7 +189,7 @@ where pub fn poll(&mut self, spi: &mut S) -> nb::Result where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { if self.dr_pin.is_high().unwrap_or(false) { self.read_coords(spi) @@ -196,7 +200,7 @@ where fn read_coords(&mut self, spi: &mut S) -> nb::Result where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { let mut buf: [u8; 6] = [0xfc; 6]; self.rd(spi, 0x12, &mut buf)?; @@ -222,7 +226,7 @@ where fn rd(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> nb::Result<(), S::Error> where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { let cmd = cmd | READ_MASK; self.cs_pin.set_low().ok(); @@ -236,7 +240,7 @@ where fn wr(&mut self, spi: &mut S, addr: u8, data: u8) -> nb::Result<(), S::Error> where - S: embedded_hal::spi::FullDuplex, + S: spi::FullDuplex, { let cmd = addr | WRITE_MASK; self.cs_pin.set_low().ok(); diff --git a/src/main.rs b/src/main.rs index 3c13e54..02812bd 100755 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn main() -> ! { log::init(tx); - logln!("luchie started!"); + logln!("luchie starting…"); // cirque spi connections to spi1: // @@ -75,6 +75,7 @@ fn main() -> ! { // pa6 - miso1 // pa7 - mosi1 + logln!("init trackpad"); let dr_pin = gpiob.pb0; let sck_pin = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); let miso_pin = gpioa.pa6; @@ -85,11 +86,18 @@ fn main() -> ! { (sck_pin, miso_pin, mosi_pin), &mut afio.mapr, spi::MODE_1, - 1.MHz(), + 1_500_000.Hz(), clocks, ); - let mut cirque = Cirque::new(cs_pin, dr_pin, &mut spi, clocks).expect("couldn't init touch pad"); + let mut cirque = match Cirque::new(cs_pin, dr_pin, &mut spi, clocks) { + Ok(c) => c, + Err(e) => { + logln!("err: {:?}", e); + panic!(); + } + }; + logln!("init usb"); // BluePill board has a pull-up resistor on the D+ line. // Pull the D+ pin down to send a RESET condition to the USB bus. // This forced reset is needed only for development, without it host @@ -116,6 +124,7 @@ fn main() -> ! { .device_class(USB_CLASS_CDC) .build(); + logln!("luchie started!"); loop { logln!("."); -- cgit v1.2.3