summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-05-12 14:12:23 +1000
committerjacqueline <me@jacqueline.id.au>2023-05-12 14:12:23 +1000
commitf3d0e8f98f2111ce41e076cfc927dce5705a6042 (patch)
tree7fb406cd3b34715f9b10d6aa38c74bf7eb20f9b9 /src
parent961c8014ada037712e8c72f23430362e9f14c1ec (diff)
downloadtangara-fw-f3d0e8f98f2111ce41e076cfc927dce5705a6042.tar.gz
Slightly improve touchwheel not-working-ness
It still doesn't work tho
Diffstat (limited to 'src')
-rw-r--r--src/drivers/include/touchwheel.hpp20
-rw-r--r--src/drivers/touchwheel.cpp22
2 files changed, 24 insertions, 18 deletions
diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp
index fae4b237..e55455be 100644
--- a/src/drivers/include/touchwheel.hpp
+++ b/src/drivers/include/touchwheel.hpp
@@ -31,16 +31,16 @@ class TouchWheel {
TouchWheelData data_;
enum Register {
- FIRMWARE_VERSION = 0x1,
- DETECTION_STATUS = 0x2,
- KEY_STATUS_A = 0x3,
- KEY_STATUS_B = 0x4,
- SLIDER_POSITION = 0x5,
- CALIBRATE = 0x6,
- RESET = 0x7,
- LOW_POWER = 0x8,
- SLIDER_OPTIONS = 0x14,
- CHARGE_TIME = 0x15,
+ FIRMWARE_VERSION = 1,
+ DETECTION_STATUS = 2,
+ KEY_STATUS_A = 3,
+ KEY_STATUS_B = 4,
+ SLIDER_POSITION = 5,
+ CALIBRATE = 6,
+ RESET = 7,
+ LOW_POWER = 8,
+ SLIDER_OPTIONS = 14,
+ CHARGE_TIME = 15,
};
void WriteRegister(uint8_t reg, uint8_t val);
diff --git a/src/drivers/touchwheel.cpp b/src/drivers/touchwheel.cpp
index d47b19a1..f807aaed 100644
--- a/src/drivers/touchwheel.cpp
+++ b/src/drivers/touchwheel.cpp
@@ -33,12 +33,13 @@ TouchWheel::TouchWheel() {
WriteRegister(Register::RESET, 1);
// TODO(daniel): do we need this? how long does reset take?
vTaskDelay(pdMS_TO_TICKS(1));
+ ReadRegister(Register::FIRMWARE_VERSION);
WriteRegister(Register::SLIDER_OPTIONS, 0b11000000);
- WriteRegister(Register::CALIBRATE, 1);
+ //WriteRegister(Register::CALIBRATE, 1);
// Confusingly-named; this sets to max-power max-response-time.
- WriteRegister(Register::LOW_POWER, 1);
+ //WriteRegister(Register::LOW_POWER, 1);
// TODO(jacqueline): Temp to debug touchwheel responsiveness.
- WriteRegister(Register::CHARGE_TIME, 8);
+ //WriteRegister(Register::CHARGE_TIME, 8);
}
TouchWheel::~TouchWheel() {}
@@ -63,9 +64,10 @@ uint8_t TouchWheel::ReadRegister(uint8_t reg) {
transaction.start()
.write_addr(kTouchWheelAddress, I2C_MASTER_WRITE)
.write_ack(reg)
+ .stop()
.start()
.write_addr(kTouchWheelAddress, I2C_MASTER_READ)
- .read(&res, I2C_MASTER_NACK)
+ .read(&res, I2C_MASTER_ACK)
.stop();
ESP_ERROR_CHECK(transaction.Execute());
return res;
@@ -73,13 +75,14 @@ uint8_t TouchWheel::ReadRegister(uint8_t reg) {
void TouchWheel::Update() {
// Read data from device into member struct
- bool has_data = !gpio_get_level(GPIO_NUM_25);
- if (!has_data) {
- return;
- }
+ //bool has_data = !gpio_get_level(GPIO_NUM_25);
+ //if (!has_data) {
+ // return;
+ //}
uint8_t status = ReadRegister(Register::DETECTION_STATUS);
if (status & 0b10000000) {
// Still calibrating.
+ ESP_LOGW(kTag, "awaiting calibration");
return;
}
if (status & 0b01000000) {
@@ -88,13 +91,16 @@ void TouchWheel::Update() {
}
if (status & 0b10) {
// Slider detect.
+ ESP_LOGW(kTag, "wheel changed");
data_.wheel_position = ReadRegister(Register::SLIDER_POSITION);
+ ESP_LOGW(kTag, "new pos: %d", data_.wheel_position);
}
if (status & 0b1) {
// Key detect.
// TODO(daniel): implement me
// Ensure we read all status registers -- even if we're not using them -- to
// ensure that INT can float high again.
+ ESP_LOGW(kTag, "button changed");
ReadRegister(Register::KEY_STATUS_A);
ReadRegister(Register::KEY_STATUS_B);
}