aboutsummaryrefslogtreecommitdiffstats
path: root/src/cirque.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-10-26 07:28:06 -0400
committerBrian Cully <bjc@kublai.com>2022-10-26 07:28:06 -0400
commit35cfff068047de01aab1213324fb423092c4289f (patch)
tree872136681a8e46f319b6fed12a2c69ccd7905481 /src/cirque.rs
parentc6e8f82fffa98283ebbae6e9cbcb028c7e72a0f5 (diff)
downloadluchie-35cfff068047de01aab1213324fb423092c4289f.tar.gz
luchie-35cfff068047de01aab1213324fb423092c4289f.zip
spi: use 1.5mhz, tweak some logging
Diffstat (limited to 'src/cirque.rs')
-rw-r--r--src/cirque.rs24
1 files changed, 14 insertions, 10 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();