summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorailurux <me@dbyron.id.au>2023-03-13 15:14:32 +1100
committerailurux <me@dbyron.id.au>2023-03-13 15:14:32 +1100
commit78ec09c494faadf9e7d06dc7d3e04531c3a34ff7 (patch)
tree7f328e7236492f6bbcc66aea044b5e78fda620cc /src/drivers/include
parentb9a75cd55a11fd404a1977539acb64a6705f3809 (diff)
downloadtangara-fw-78ec09c494faadf9e7d06dc7d3e04531c3a34ff7.tar.gz
Touchwheel test
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/i2c.hpp2
-rw-r--r--src/drivers/include/touchwheel.hpp60
2 files changed, 61 insertions, 1 deletions
diff --git a/src/drivers/include/i2c.hpp b/src/drivers/include/i2c.hpp
index dbdd8a11..811c9333 100644
--- a/src/drivers/include/i2c.hpp
+++ b/src/drivers/include/i2c.hpp
@@ -35,7 +35,7 @@ class I2CTransaction {
* ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode.
* ESP_ERR_TIMEOUT Operation timeout because the bus is busy.
*/
- esp_err_t Execute();
+ esp_err_t Execute(uint8_t port = I2C_NUM_0);
/*
* Enqueues a start condition. May also be used for repeated start
diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp
new file mode 100644
index 00000000..14215acd
--- /dev/null
+++ b/src/drivers/include/touchwheel.hpp
@@ -0,0 +1,60 @@
+#pragma once
+
+
+#include <functional>
+#include <stdint.h>
+
+#include "esp_err.h"
+#include "result.hpp"
+
+#include "gpio_expander.hpp"
+
+namespace drivers {
+
+struct TouchWheelData {
+ bool is_touched = false;
+ uint8_t wheel_position = -1;
+};
+
+class TouchWheel {
+ public:
+ enum Error {
+ FAILED_TO_BOOT,
+ FAILED_TO_CONFIGURE,
+ };
+ static auto create(GpioExpander* expander)
+ -> cpp::result<std::unique_ptr<TouchWheel>, Error>;
+
+ TouchWheel(GpioExpander* gpio);
+ ~TouchWheel();
+
+ // Not copyable or movable.
+ TouchWheel(const TouchWheel&) = delete;
+ TouchWheel& operator=(const TouchWheel&) = delete;
+
+ auto Update() -> void;
+ auto GetTouchWheelData() const -> TouchWheelData;
+
+ private:
+ GpioExpander* gpio_;
+ 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,
+ };
+
+
+ void WriteRegister(uint8_t reg, uint8_t val);
+ void ReadRegister(uint8_t reg, uint8_t* data, uint8_t count);
+
+};
+
+} // namespace drivers