aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cirque.rs24
-rwxr-xr-xsrc/main.rs15
2 files changed, 26 insertions, 13 deletions
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<Word>: spi::FullDuplex<Word> {
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<S>(cs_pin: C, dr_pin: D, spi: &mut S, clocks: Clocks) -> nb::Result<Self, S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
let sysclk_speed = clocks.sysclk().raw();
let mut res = Self {
@@ -155,7 +159,7 @@ where
fn init<S>(&mut self, spi: &mut S) -> nb::Result<(), S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
self.cs_pin.set_high().ok();
self.clear_flags(spi)?;
@@ -174,7 +178,7 @@ where
fn clear_flags<S>(&mut self, spi: &mut S) -> nb::Result<(), S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
self.wr(spi, 0x02, 0x00)?;
@@ -185,7 +189,7 @@ where
pub fn poll<S>(&mut self, spi: &mut S) -> nb::Result<TouchData, S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
if self.dr_pin.is_high().unwrap_or(false) {
self.read_coords(spi)
@@ -196,7 +200,7 @@ where
fn read_coords<S>(&mut self, spi: &mut S) -> nb::Result<TouchData, S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
let mut buf: [u8; 6] = [0xfc; 6];
self.rd(spi, 0x12, &mut buf)?;
@@ -222,7 +226,7 @@ where
fn rd<S>(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> nb::Result<(), S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
let cmd = cmd | READ_MASK;
self.cs_pin.set_low().ok();
@@ -236,7 +240,7 @@ where
fn wr<S>(&mut self, spi: &mut S, addr: u8, data: u8) -> nb::Result<(), S::Error>
where
- S: embedded_hal::spi::FullDuplex<u8>,
+ S: spi::FullDuplex<u8>,
{
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!(".");