summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorJF <JF002@users.noreply.github.com>2021-11-28 13:59:09 +0100
committerGitHub <noreply@github.com>2021-11-28 13:59:09 +0100
commit583c7ee22fdf576490169643762240bf9bb6b375 (patch)
treec0bca6afa9b570bb2f78370c1096131acafd32d0 /src/drivers
parentf9613d28c06f96fbc93ccbc59a8f749bbc5f7fa5 (diff)
parent4257073a02215e3f182d993765e4c5edef2d9845 (diff)
Merge branch 'develop' into motionservice_fix_typo_in_include
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Bma421.cpp4
-rw-r--r--src/drivers/Cst816s.cpp69
-rw-r--r--src/drivers/Cst816s.h9
-rw-r--r--src/drivers/DebugPins.cpp2
-rw-r--r--src/drivers/Hrs3300.cpp2
-rw-r--r--src/drivers/Hrs3300.h2
-rw-r--r--src/drivers/InternalFlash.cpp2
-rw-r--r--src/drivers/PinMap.h1
-rw-r--r--src/drivers/Spi.cpp2
-rw-r--r--src/drivers/Spi.h2
-rw-r--r--src/drivers/SpiMaster.cpp2
-rw-r--r--src/drivers/SpiNorFlash.cpp4
-rw-r--r--src/drivers/St7789.cpp4
-rw-r--r--src/drivers/TwiMaster.cpp2
-rw-r--r--src/drivers/Watchdog.cpp2
15 files changed, 70 insertions, 39 deletions
diff --git a/src/drivers/Bma421.cpp b/src/drivers/Bma421.cpp
index dd284000..2f60f42f 100644
--- a/src/drivers/Bma421.cpp
+++ b/src/drivers/Bma421.cpp
@@ -1,7 +1,7 @@
+#include "drivers/Bma421.h"
#include <libraries/delay/nrf_delay.h>
#include <libraries/log/nrf_log.h>
-#include "Bma421.h"
-#include "TwiMaster.h"
+#include "drivers/TwiMaster.h"
#include <drivers/Bma421_C/bma423.h>
using namespace Pinetime::Drivers;
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index 7fc8eca4..e9573df1 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -1,4 +1,4 @@
-#include "Cst816s.h"
+#include "drivers/Cst816s.h"
#include <FreeRTOS.h>
#include <legacy/nrf_drv_gpiote.h>
#include <nrfx_log.h>
@@ -32,6 +32,12 @@ bool Cst816S::Init() {
twiMaster.Read(twiAddress, 0xa7, &dummy, 1);
vTaskDelay(5);
+ // TODO This function check that the device IDs from the controller are equal to the ones
+ // we expect. However, it seems to return false positive (probably in case of communication issue).
+ // Also, it seems that some users have pinetimes that works correctly but that report different device IDs
+ // Until we know more about this, we'll just read the IDs but not take any action in case they are not 'valid'
+ CheckDeviceIds();
+
/*
[2] EnConLR - Continuous operation can slide around
[1] EnConUD - Slide up and down to enable continuous operation
@@ -50,21 +56,7 @@ bool Cst816S::Init() {
static constexpr uint8_t irqCtl = 0b01110000;
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
- // There's mixed information about which register contains which information
- if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
- chipId = 0xFF;
- return false;
- }
- if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
- vendorId = 0xFF;
- return false;
- }
- if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
- fwVersion = 0xFF;
- return false;
- }
-
- return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
+ return true;
}
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
@@ -79,18 +71,33 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
// This can only be 0 or 1
uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
-
uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
uint8_t xLow = touchData[touchXLowIndex];
- info.x = (xHigh << 8) | xLow;
-
+ uint16_t x = (xHigh << 8) | xLow;
uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
uint8_t yLow = touchData[touchYLowIndex];
- info.y = (yHigh << 8) | yLow;
+ uint16_t y = (yHigh << 8) | yLow;
+ Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]);
+
+ // Validity check
+ if(x >= maxX || y >= maxY ||
+ (gesture != Gestures::None &&
+ gesture != Gestures::SlideDown &&
+ gesture != Gestures::SlideUp &&
+ gesture != Gestures::SlideLeft &&
+ gesture != Gestures::SlideRight &&
+ gesture != Gestures::SingleTap &&
+ gesture != Gestures::DoubleTap &&
+ gesture != Gestures::LongPress)) {
+ info.isValid = false;
+ return info;
+ }
+ info.x = x;
+ info.y = y;
info.touching = (nbTouchPoints > 0);
- info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
-
+ info.gesture = gesture;
+ info.isValid = true;
return info;
}
@@ -108,3 +115,21 @@ void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
}
+
+bool Cst816S::CheckDeviceIds() {
+ // There's mixed information about which register contains which information
+ if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ chipId = 0xFF;
+ return false;
+ }
+ if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ vendorId = 0xFF;
+ return false;
+ }
+ if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ fwVersion = 0xFF;
+ return false;
+ }
+
+ return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
+}
diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h
index 0fec8419..4a548d45 100644
--- a/src/drivers/Cst816s.h
+++ b/src/drivers/Cst816s.h
@@ -1,6 +1,6 @@
#pragma once
-#include "TwiMaster.h"
+#include "drivers/TwiMaster.h"
namespace Pinetime {
namespace Drivers {
@@ -21,7 +21,7 @@ namespace Pinetime {
uint16_t y = 0;
Gestures gesture = Gestures::None;
bool touching = false;
- bool isValid = true;
+ bool isValid = false;
};
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
@@ -45,6 +45,8 @@ namespace Pinetime {
return fwVersion;
}
private:
+ bool CheckDeviceIds();
+
// Unused/Unavailable commented out
static constexpr uint8_t gestureIndex = 1;
static constexpr uint8_t touchPointNumIndex = 2;
@@ -58,6 +60,9 @@ namespace Pinetime {
//static constexpr uint8_t touchXYIndex = 7;
//static constexpr uint8_t touchMiscIndex = 8;
+ static constexpr uint8_t maxX = 240;
+ static constexpr uint8_t maxY = 240;
+
TwiMaster& twiMaster;
uint8_t twiAddress;
diff --git a/src/drivers/DebugPins.cpp b/src/drivers/DebugPins.cpp
index 56fd1458..92091280 100644
--- a/src/drivers/DebugPins.cpp
+++ b/src/drivers/DebugPins.cpp
@@ -1,4 +1,4 @@
-#include "DebugPins.h"
+#include "drivers/DebugPins.h"
#include <hal/nrf_gpio.h>
#ifdef USE_DEBUG_PINS
diff --git a/src/drivers/Hrs3300.cpp b/src/drivers/Hrs3300.cpp
index edb9e81d..c14fe7aa 100644
--- a/src/drivers/Hrs3300.cpp
+++ b/src/drivers/Hrs3300.cpp
@@ -4,9 +4,9 @@
C++ port Copyright (C) 2021 Jean-François Milants
*/
+#include "drivers/Hrs3300.h"
#include <algorithm>
#include <nrf_gpio.h>
-#include "Hrs3300.h"
#include <FreeRTOS.h>
#include <task.h>
diff --git a/src/drivers/Hrs3300.h b/src/drivers/Hrs3300.h
index c4f28900..01310c62 100644
--- a/src/drivers/Hrs3300.h
+++ b/src/drivers/Hrs3300.h
@@ -1,6 +1,6 @@
#pragma once
-#include "TwiMaster.h"
+#include "drivers/TwiMaster.h"
namespace Pinetime {
namespace Drivers {
diff --git a/src/drivers/InternalFlash.cpp b/src/drivers/InternalFlash.cpp
index 0840c6e5..ec5885d5 100644
--- a/src/drivers/InternalFlash.cpp
+++ b/src/drivers/InternalFlash.cpp
@@ -1,4 +1,4 @@
-#include "InternalFlash.h"
+#include "drivers/InternalFlash.h"
#include <mdk/nrf.h>
using namespace Pinetime::Drivers;
diff --git a/src/drivers/PinMap.h b/src/drivers/PinMap.h
index 57964020..579bf38a 100644
--- a/src/drivers/PinMap.h
+++ b/src/drivers/PinMap.h
@@ -1,4 +1,5 @@
#pragma once
+#include <cstdint>
namespace Pinetime {
namespace PinMap {
diff --git a/src/drivers/Spi.cpp b/src/drivers/Spi.cpp
index a55d2888..e477622b 100644
--- a/src/drivers/Spi.cpp
+++ b/src/drivers/Spi.cpp
@@ -1,4 +1,4 @@
-#include "Spi.h"
+#include "drivers/Spi.h"
#include <hal/nrf_gpio.h>
#include <nrfx_log.h>
diff --git a/src/drivers/Spi.h b/src/drivers/Spi.h
index 6875710d..9b6a30f4 100644
--- a/src/drivers/Spi.h
+++ b/src/drivers/Spi.h
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <cstddef>
-#include "SpiMaster.h"
+#include "drivers/SpiMaster.h"
namespace Pinetime {
namespace Drivers {
diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp
index c45e1294..747dbc84 100644
--- a/src/drivers/SpiMaster.cpp
+++ b/src/drivers/SpiMaster.cpp
@@ -1,4 +1,4 @@
-#include "SpiMaster.h"
+#include "drivers/SpiMaster.h"
#include <hal/nrf_gpio.h>
#include <hal/nrf_spim.h>
#include <nrfx_log.h>
diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp
index 068d1d02..ebe3174c 100644
--- a/src/drivers/SpiNorFlash.cpp
+++ b/src/drivers/SpiNorFlash.cpp
@@ -1,8 +1,8 @@
-#include "SpiNorFlash.h"
+#include "drivers/SpiNorFlash.h"
#include <hal/nrf_gpio.h>
#include <libraries/delay/nrf_delay.h>
#include <libraries/log/nrf_log.h>
-#include "Spi.h"
+#include "drivers/Spi.h"
using namespace Pinetime::Drivers;
diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp
index 4d81cf27..fd1366f8 100644
--- a/src/drivers/St7789.cpp
+++ b/src/drivers/St7789.cpp
@@ -1,8 +1,8 @@
-#include "St7789.h"
+#include "drivers/St7789.h"
#include <hal/nrf_gpio.h>
#include <libraries/delay/nrf_delay.h>
#include <nrfx_log.h>
-#include "Spi.h"
+#include "drivers/Spi.h"
using namespace Pinetime::Drivers;
diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp
index 76009278..9b456d5f 100644
--- a/src/drivers/TwiMaster.cpp
+++ b/src/drivers/TwiMaster.cpp
@@ -1,4 +1,4 @@
-#include "TwiMaster.h"
+#include "drivers/TwiMaster.h"
#include <cstring>
#include <hal/nrf_gpio.h>
#include <nrfx_log.h>
diff --git a/src/drivers/Watchdog.cpp b/src/drivers/Watchdog.cpp
index a6ad263a..d0907a65 100644
--- a/src/drivers/Watchdog.cpp
+++ b/src/drivers/Watchdog.cpp
@@ -1,4 +1,4 @@
-#include "Watchdog.h"
+#include "drivers/Watchdog.h"
#include <mdk/nrf.h>
using namespace Pinetime::Drivers;