summaryrefslogtreecommitdiff
path: root/src/drivers/Cst816s.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-07-19 20:30:44 +0200
committerJF <jf@codingfield.com>2020-07-19 20:30:44 +0200
commit6af5bbcbc87eecccf7613785a3c9540c07d2fd3b (patch)
tree77ea3c1c638321545c5d5f036134045ae112c6b3 /src/drivers/Cst816s.cpp
parent42d8a18fe74b060a84ea74b29aefca69f9471d5f (diff)
New implementation of the I²C/TWI driver.
Fix reset timing and add dummy reading in Cst816S to fix init error on some devices.
Diffstat (limited to 'src/drivers/Cst816s.cpp')
-rw-r--r--src/drivers/Cst816s.cpp54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index 61bce94c..60cd402c 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -13,51 +13,42 @@ using namespace Pinetime::Drivers;
* TODO : we need a complete datasheet and protocol reference!
* */
-void Pinetime::Drivers::Cst816S::Init() {
+Cst816S::Cst816S(TwiMaster &twiMaster, uint8_t twiAddress) : twiMaster{twiMaster}, twiAddress{twiAddress} {
+
+}
+
+void Cst816S::Init() {
nrf_gpio_cfg_output(pinReset);
+ nrf_gpio_pin_set(pinReset);
+ vTaskDelay(50);
nrf_gpio_pin_clear(pinReset);
- vTaskDelay(20);
+ vTaskDelay(5);
nrf_gpio_pin_set(pinReset);
- vTaskDelay(200);
-
- nrfx_twi_config_t config;
- config.frequency = NRF_TWI_FREQ_400K;
- config.scl = 7;
- config.sda = 6;
- config.interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY;
- config.hold_bus_uninit = NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT;
-
- // Configure TWI in blocking mode (event_handler = nullptr)
- auto ret = nrfx_twi_init(&twi, &config, nullptr, this);
- nrfx_twi_enable(&twi);
-}
+ vTaskDelay(50);
+ // Wake the touchpanel up
+ uint8_t dummy;
+ twiMaster.Read(twiAddress, 0x15, &dummy, 1);
+ vTaskDelay(5);
+ twiMaster.Read(twiAddress, 0xa7, &dummy, 1);
-void Cst816S::Probe() {
- nrfx_err_t ret;
- for(int i = 0; i < 127; i++) {
- uint8_t data;
- ret = nrfx_twi_rx(&twi, i, &data, 1);
- if(ret == NRFX_SUCCESS) {
- NRF_LOG_INFO("I2C device detected at address %d", i);
- }
- }
}
+
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
Cst816S::TouchInfos info;
- nrfx_twi_rx(&twi, address, touchData, 63);
+ twiMaster.Read(twiAddress, 0, touchData, 63);
auto nbTouchPoints = touchData[2] & 0x0f;
// uint8_t i = 0;
// NRF_LOG_INFO("#########################")
for(int i = 0; i < 1; i++) {
- uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
- if(nbTouchPoints == 0 && pointId == lastTouchId) return info;
+ uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
+ if(nbTouchPoints == 0 && pointId == lastTouchId) return info;
- // We fetch only the first touch point (the controller seems to handle only one anyway...)
- info.isTouch = true;
+ // We fetch only the first touch point (the controller seems to handle only one anyway...)
+ info.isTouch = true;
auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f;
@@ -106,11 +97,12 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
}
void Cst816S::Sleep() {
- nrfx_twi_disable(&twi);
+ // TODO re enable sleep mode
+ //twiMaster.Sleep();
nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7);
}
void Cst816S::Wakeup() {
Init();
-}
+} \ No newline at end of file