Skip to content

Commit

Permalink
Fix stall when trying to i2c blocking read when INT is not high
Browse files Browse the repository at this point in the history
  • Loading branch information
tstellanova committed Apr 8, 2020
1 parent 6133d10 commit 29909b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
11 changes: 1 addition & 10 deletions examples/touchpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ fn main() -> ! {
// random number generator peripheral
let mut rng = dp.RNG.constrain();

// // pushbutton input GPIO: P0.13
// let mut _user_butt = port0.p0_13.into_floating_input().degrade();
// // must drive this pin high to enable pushbutton
// let mut _user_butt_en =
// port0.p0_15.into_push_pull_output(Level::High).degrade();
// vibration motor output: drive low to activate motor
// let mut vibe = port0.p0_16.into_push_pull_output(Level::Low).degrade();
// delay_source.delay_ms(100u8);
// let _ = vibe.set_high();

// internal i2c0 bus devices: BMA421 (accel), HRS3300 (hrs), CST816S (TouchPad)
// BMA421-INT: P0.08
Expand Down Expand Up @@ -140,7 +131,7 @@ fn main() -> ! {
draw_background(&mut display, &mut display_csn);

// setup touchpad external interrupt pin: P0.28/AIN4 (TP_INT)
let touch_int = port0.p0_28.into_floating_input().degrade();
let touch_int = port0.p0_28.into_pullup_input().degrade();
// setup touchpad reset pin: P0.10/NFC2 (TP_RESET)
let touch_rst = port0.p0_10.into_push_pull_output(Level::High).degrade();

Expand Down
28 changes: 17 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,23 @@ where
/// Reads events into the event buffer provided
pub fn read_one_touch_event(&mut self, ) -> Option<TouchEvent> {

if self.read_registers().is_ok() {
let gesture_id = self.blob_buf[Self::GESTURE_ID_OFF]; //TODO report gestures
let num_points = (self.blob_buf[Self::NUM_POINTS_OFF] & 0x0F) as usize;
for i in 0..num_points {
let evt_start: usize = (i * Self::RAW_TOUCH_EVENT_LEN) + Self::GESTURE_HEADER_LEN;
if let Some(mut evt) = Self::touch_event_from_data(
self.blob_buf[evt_start..evt_start + Self::RAW_TOUCH_EVENT_LEN].as_ref())
{
evt.gesture = gesture_id;
//TODO we only ever appear to get one event on the PineTime: handle more?
return Some(evt)
// the interrupt pin should be low if there is data available;
// otherwise, attempting to read i2c will cause a stall
if let Ok(data_available) = self.pin_int.is_low() {
if data_available {
if self.read_registers().is_ok() {
let gesture_id = self.blob_buf[Self::GESTURE_ID_OFF];
let num_points = (self.blob_buf[Self::NUM_POINTS_OFF] & 0x0F) as usize;
for i in 0..num_points {
let evt_start: usize = (i * Self::RAW_TOUCH_EVENT_LEN) + Self::GESTURE_HEADER_LEN;
if let Some(mut evt) = Self::touch_event_from_data(
self.blob_buf[evt_start..evt_start + Self::RAW_TOUCH_EVENT_LEN].as_ref())
{
evt.gesture = gesture_id;
//TODO we only ever appear to get one event on the PineTime: handle more?
return Some(evt)
}
}
}
}
}
Expand Down

0 comments on commit 29909b5

Please sign in to comment.