Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft6x06 touch status fix and impoved report efficency #2060

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions capsules/src/ft6x06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ impl<'a> i2c::I2CClient for Ft6x06<'a> {
self.num_touches.set((buffer[1] & 0x0F) as usize);
self.touch_client.map(|client| {
if self.num_touches.get() <= 2 {
let status = match buffer[1] >> 6 {
let status = match buffer[2] >> 6 {
0x00 => TouchStatus::Pressed,
0x01 => TouchStatus::Released,
0x02 => TouchStatus::Moved,
_ => TouchStatus::Released,
};
let x = (((buffer[2] & 0x0F) as u16) << 8) + (buffer[3] as u16);
Expand Down Expand Up @@ -140,15 +141,17 @@ impl<'a> i2c::I2CClient for Ft6x06<'a> {
self.multi_touch_client.map(|client| {
if self.num_touches.get() <= 2 {
for touch_event in 0..self.num_touches.get() {
let status = match buffer[1] >> 6 {
let status = match buffer[touch_event * 8 + 2] >> 6 {
0x00 => TouchStatus::Pressed,
0x01 => TouchStatus::Released,
_ => TouchStatus::Released,
};
let x = (((buffer[2] & 0x0F) as u16) << 8) + (buffer[3] as u16);
let y = (((buffer[4] & 0x0F) as u16) << 8) + (buffer[5] as u16);
let pressure = Some(buffer[6] as u16);
let size = Some(buffer[7] as u16);
let x = (((buffer[touch_event * 8 + 2] & 0x0F) as u16) << 8)
+ (buffer[touch_event * 8 + 3] as u16);
let y = (((buffer[touch_event * 8 + 4] & 0x0F) as u16) << 8)
+ (buffer[touch_event * 8 + 5] as u16);
let pressure = Some(buffer[touch_event * 8 + 6] as u16);
let size = Some(buffer[touch_event * 8 + 7] as u16);
self.events.map(|buffer| {
buffer[touch_event] = TouchEvent {
status,
Expand Down Expand Up @@ -225,6 +228,7 @@ impl<'a> touch::MultiTouch<'a> for Ft6x06<'a> {
let status = match buffer[offset + 1] >> 6 {
0x00 => TouchStatus::Pressed,
0x01 => TouchStatus::Released,
0x02 => TouchStatus::Moved,
_ => TouchStatus::Released,
};
let x = (((buffer[offset + 2] & 0x0F) as u16) << 8) + (buffer[offset + 3] as u16);
Expand Down
70 changes: 48 additions & 22 deletions capsules/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//! ```

use core::mem;
// use kernel::debug;
use kernel::hil;
use kernel::hil::screen::ScreenRotation;
use kernel::hil::touch::{GestureEvent, TouchEvent, TouchStatus};
Expand All @@ -30,6 +29,9 @@ pub struct App {
events_buffer: Option<AppSlice<Shared, u8>>,
ack: bool,
dropped_events: usize,
x: u16,
y: u16,
status: usize,
}

impl Default for App {
Expand All @@ -41,6 +43,9 @@ impl Default for App {
events_buffer: None,
ack: true,
dropped_events: 0,
x: 0,
y: 0,
status: 3,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could status be changed to be a TouchStatus type, and an Unstarted variant added to TouchStatus? I find this initialization to 3 confusing and prone to breakage in the future if additional variants are added to TouchStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you for the tip.

}
}
}
Expand Down Expand Up @@ -157,24 +162,30 @@ impl<'a> hil::touch::TouchClient for Touch<'a> {
// );
for app in self.apps.iter() {
app.enter(|app, _| {
app.touch_callback.map(|mut callback| {
let event_id = match event.status {
TouchStatus::Released => 0,
TouchStatus::Pressed => 1,
};
let pressure_size = match event.pressure {
Some(pressure) => (pressure as usize) << 16,
None => 0,
} | match event.size {
Some(size) => size as usize,
None => 0,
};
callback.schedule(
event_id,
(event.x as usize) << 16 | event.y as usize,
pressure_size,
);
})
let event_status = match event.status {
TouchStatus::Released => 0,
TouchStatus::Pressed => 1,
TouchStatus::Moved => 2,
};
if app.x != event.x || app.y != event.y || app.status != event_status {
app.x = event.x;
app.y = event.y;
app.status = event_status;
app.touch_callback.map(|mut callback| {
let pressure_size = match event.pressure {
Some(pressure) => (pressure as usize) << 16,
None => 0,
} | match event.size {
Some(size) => size as usize,
None => 0,
};
callback.schedule(
event_status,
(event.x as usize) << 16 | event.y as usize,
pressure_size,
);
});
}
});
}
}
Expand Down Expand Up @@ -205,6 +216,7 @@ impl<'a> hil::touch::MultiTouchClient for Touch<'a> {
let event_status = match event.status {
TouchStatus::Released => 0,
TouchStatus::Pressed => 1,
TouchStatus::Moved => 2,
};
// debug!(
// " multitouch {:?} x {} y {} size {:?} pressure {:?}",
Expand Down Expand Up @@ -282,10 +294,10 @@ impl<'a> Driver for Touch<'a> {
// allow a buffer for the multi touch
// buffer data format
// 0 1 2 4 6 7 8 ...
// +---------+-----------+------------------+------------------+-----------+-------------+--------- ...
// +---------+-----------+------------------+------------------+-----------+---------------+--------- ...
// | id (u8) | type (u8) | x (u16) | y (u16) | size (u8) | pressure (u8) | ...
// +---------+-----------+------------------+------------------+-----------+-------------+--------- ...
// | Touch 0 | Touch 1 ...
// +---------+-----------+------------------+------------------+-----------+---------------+--------- ...
// | Touch 0 | Touch 1 ...
2 => {
if self.multi_touch.is_some() {
self.apps
Expand Down Expand Up @@ -358,6 +370,20 @@ impl<'a> Driver for Touch<'a> {
ReturnCode::SUCCESS
}

// number of touches
100 => {
let num_touches = if let Some(multi_touch) = self.multi_touch {
multi_touch.get_num_touches()
} else {
if self.touch.is_some() {
1
} else {
0
}
};
ReturnCode::SuccessWithValue { value: num_touches }
}

_ => ReturnCode::ENOSUPPORT,
}
}
Expand Down
1 change: 1 addition & 0 deletions kernel/src/hil/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::ReturnCode;
pub enum TouchStatus {
Pressed,
Released,
Moved,
}

/// Gesture event
Expand Down