-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1986: Touch Panel HIL and ft6x06 driver r=bradjc a=alexandruradovici ### Pull Request Overview This pull request adds: * a HIL for touch panels with optional multi touch and gestures * a driver for the ft6x06 touch panel ### Testing Strategy This pull request was tested using the STM32F412g Discovery Kit. ### TODO or Help Wanted This pull request still needs some feedback. Even tough the documentation for [ft6x06](http://www.tvielectronics.com/ocart/download/controller/FT6206.pdf) states that gestures should be recognized, my device does not seem to recognize them. I might be doing something wrong, any ideas would be helpful. The test setup is https://github.com/UPBIoT/tock/tree/touch. ### Documentation Updated - [x] no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Alexandru Radovici <msg4alex@gmail.com>
- Loading branch information
Showing
12 changed files
with
960 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//! Components for the Ft6x06 Touch Panel. | ||
//! | ||
//! Usage | ||
//! ----- | ||
//! ```rust | ||
//! let ft6x06 = components::ft6x06::Ft6x06Component::new() | ||
//! .finalize(components::ft6x06_i2c_component_helper!(mux_i2c)); | ||
//! ``` | ||
use capsules::ft6x06::Ft6x06; | ||
use capsules::virtual_i2c::I2CDevice; | ||
use core::mem::MaybeUninit; | ||
use kernel::component::Component; | ||
use kernel::hil::gpio; | ||
use kernel::static_init_half; | ||
|
||
// Setup static space for the objects. | ||
#[macro_export] | ||
macro_rules! ft6x06_i2c_component_helper { | ||
($i2c_mux: expr) => {{ | ||
use capsules::ft6x06::Ft6x06; | ||
use capsules::virtual_i2c::I2CDevice; | ||
use core::mem::MaybeUninit; | ||
let i2c = components::i2c::I2CComponent::new($i2c_mux, 0x38) | ||
.finalize(components::i2c_component_helper!()); | ||
static mut ft6x06: MaybeUninit<Ft6x06<'static>> = MaybeUninit::uninit(); | ||
(&i2c, &mut ft6x06) | ||
};}; | ||
} | ||
|
||
pub struct Ft6x06Component { | ||
interupt_pin: &'static dyn gpio::InterruptPin<'static>, | ||
} | ||
|
||
impl Ft6x06Component { | ||
pub fn new(pin: &'static dyn gpio::InterruptPin) -> Ft6x06Component { | ||
Ft6x06Component { interupt_pin: pin } | ||
} | ||
} | ||
|
||
impl Component for Ft6x06Component { | ||
type StaticInput = ( | ||
&'static I2CDevice<'static>, | ||
&'static mut MaybeUninit<Ft6x06<'static>>, | ||
); | ||
type Output = &'static Ft6x06<'static>; | ||
|
||
unsafe fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output { | ||
let ft6x06 = static_init_half!( | ||
static_buffer.1, | ||
Ft6x06<'static>, | ||
Ft6x06::new( | ||
static_buffer.0, | ||
self.interupt_pin, | ||
&mut capsules::ft6x06::BUFFER, | ||
&mut capsules::ft6x06::EVENTS_BUFFER | ||
) | ||
); | ||
static_buffer.0.set_client(ft6x06); | ||
self.interupt_pin.set_client(ft6x06); | ||
|
||
ft6x06 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//! Components for the Touch Panel. | ||
//! | ||
//! Usage | ||
//! ----- | ||
//! | ||
//! Touch | ||
//! | ||
//! ```rust | ||
//! // Just Touch | ||
//! let touch = | ||
//! components::touch::TouchComponent::new(board_kernel, ts, None, Some(screen)) | ||
//! .finalize(()); | ||
//! | ||
//! // With Gesture | ||
//! let touch = | ||
//! components::touch::TouchComponent::new(board_kernel, ts, Some(ts), Some(screen)) | ||
//! .finalize(()); | ||
//! ``` | ||
//! | ||
//! Multi Touch | ||
//! | ||
//! ```rust | ||
//! // Just Multi Touch | ||
//! let touch = | ||
//! components::touch::MultiTouchComponent::new(board_kernel, ts, None, Some(screen)) | ||
//! .finalize(()); | ||
//! | ||
//! // With Gesture | ||
//! let touch = | ||
//! components::touch::MultiTouchComponent::new(board_kernel, ts, Some(ts), Some(screen)) | ||
//! .finalize(()); | ||
//! ``` | ||
use kernel::capabilities; | ||
use kernel::component::Component; | ||
use kernel::create_capability; | ||
use kernel::static_init; | ||
|
||
pub struct TouchComponent { | ||
board_kernel: &'static kernel::Kernel, | ||
touch: &'static dyn kernel::hil::touch::Touch<'static>, | ||
gesture: Option<&'static dyn kernel::hil::touch::Gesture<'static>>, | ||
screen: Option<&'static dyn kernel::hil::screen::Screen>, | ||
} | ||
|
||
impl TouchComponent { | ||
pub fn new( | ||
board_kernel: &'static kernel::Kernel, | ||
touch: &'static dyn kernel::hil::touch::Touch<'static>, | ||
gesture: Option<&'static dyn kernel::hil::touch::Gesture<'static>>, | ||
screen: Option<&'static dyn kernel::hil::screen::Screen>, | ||
) -> TouchComponent { | ||
TouchComponent { | ||
board_kernel: board_kernel, | ||
touch: touch, | ||
gesture: gesture, | ||
screen: screen, | ||
} | ||
} | ||
} | ||
|
||
impl Component for TouchComponent { | ||
type StaticInput = (); | ||
type Output = &'static capsules::touch::Touch<'static>; | ||
|
||
unsafe fn finalize(self, _static_input: Self::StaticInput) -> Self::Output { | ||
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability); | ||
let grant_touch = self.board_kernel.create_grant(&grant_cap); | ||
|
||
let touch = static_init!( | ||
capsules::touch::Touch, | ||
capsules::touch::Touch::new(Some(self.touch), None, self.screen, grant_touch) | ||
); | ||
|
||
kernel::hil::touch::Touch::set_client(self.touch, touch); | ||
if let Some(gesture) = self.gesture { | ||
kernel::hil::touch::Gesture::set_client(gesture, touch); | ||
} | ||
|
||
touch | ||
} | ||
} | ||
|
||
pub struct MultiTouchComponent { | ||
board_kernel: &'static kernel::Kernel, | ||
multi_touch: &'static dyn kernel::hil::touch::MultiTouch<'static>, | ||
gesture: Option<&'static dyn kernel::hil::touch::Gesture<'static>>, | ||
screen: Option<&'static dyn kernel::hil::screen::Screen>, | ||
} | ||
|
||
impl MultiTouchComponent { | ||
pub fn new( | ||
board_kernel: &'static kernel::Kernel, | ||
multi_touch: &'static dyn kernel::hil::touch::MultiTouch<'static>, | ||
gesture: Option<&'static dyn kernel::hil::touch::Gesture<'static>>, | ||
screen: Option<&'static dyn kernel::hil::screen::Screen>, | ||
) -> MultiTouchComponent { | ||
MultiTouchComponent { | ||
board_kernel: board_kernel, | ||
multi_touch: multi_touch, | ||
gesture: gesture, | ||
screen: screen, | ||
} | ||
} | ||
} | ||
|
||
impl Component for MultiTouchComponent { | ||
type StaticInput = (); | ||
type Output = &'static capsules::touch::Touch<'static>; | ||
|
||
unsafe fn finalize(self, _static_input: Self::StaticInput) -> Self::Output { | ||
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability); | ||
let grant_touch = self.board_kernel.create_grant(&grant_cap); | ||
|
||
let touch = static_init!( | ||
capsules::touch::Touch, | ||
capsules::touch::Touch::new(None, Some(self.multi_touch), self.screen, grant_touch) | ||
); | ||
|
||
kernel::hil::touch::MultiTouch::set_client(self.multi_touch, touch); | ||
if let Some(gesture) = self.gesture { | ||
kernel::hil::touch::Gesture::set_client(gesture, touch); | ||
} | ||
|
||
touch | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.