summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
authorRobin Howard <robin@rhoward.id.au>2024-04-19 16:03:35 +1000
committerRobin Howard <robin@rhoward.id.au>2024-04-19 16:03:53 +1000
commit7c075cf5b776feaed2065f936dff0c176635b89d (patch)
treed89dae49799dc684a9870361117789085b132854 /src/drivers/include
parente39754ba105213c133407e2dacb5fd31f3873e4c (diff)
downloadtangara-fw-7c075cf5b776feaed2065f936dff0c176635b89d.tar.gz
Adds LRA haptic support (open-loop only for now).
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/haptics.hpp24
-rw-r--r--src/drivers/include/nvs.hpp6
2 files changed, 25 insertions, 5 deletions
diff --git a/src/drivers/include/haptics.hpp b/src/drivers/include/haptics.hpp
index cf970977..940c3c6d 100644
--- a/src/drivers/include/haptics.hpp
+++ b/src/drivers/include/haptics.hpp
@@ -11,13 +11,24 @@
#include <mutex>
#include <optional>
#include <string>
+#include <variant>
namespace drivers {
+typedef std::monostate ErmMotor;
+struct LraMotor {
+ // TODO: fill out with calibration data from https://www.ti.com/lit/ds/symlink/drv2605l.pdf
+ bool hi;
+};
+
class Haptics {
public:
- static auto Create() -> Haptics* { return new Haptics(); }
- Haptics();
+ static auto Create(const std::variant<ErmMotor, LraMotor>& motor)
+ -> Haptics* {
+ return new Haptics(motor);
+ }
+
+ Haptics(const std::variant<ErmMotor, LraMotor>& motor);
~Haptics();
// Not copyable or movable.
@@ -169,11 +180,12 @@ class Haptics {
B = 2, // 3V, Rise: 40-60ms, Brake: 5-15ms
C = 3, // 3V, Rise: 60-80ms, Brake: 10-20ms
D = 4, // 3V, Rise: 100-140ms, Brake: 15-25ms
- E = 5 // 3V, Rise: >140ms, Brake: >30ms
- // 6 is LRA-only, 7 is 4.5V+
+ E = 5, // 3V, Rise: >140ms, Brake: >30ms
+ LRA = 6
+ // 7 is 4.5V+
};
- static constexpr Library kDefaultLibrary = Library::C;
+ static constexpr Library kDefaultErmLibrary = Library::C;
auto PowerDown() -> void;
auto Reset() -> void;
@@ -216,8 +228,10 @@ class Haptics {
struct ControlMask {
// FeedbackControl
static constexpr uint8_t kNErmLra = 0b10000000;
+
// Control3
static constexpr uint8_t kErmOpenLoop = 0b00100000;
+ static constexpr uint8_t kLraOpenLoop = 0b00000001;
};
// ยง8.6 Register Map
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
index 25396622..7c74ceb0 100644
--- a/src/drivers/include/nvs.hpp
+++ b/src/drivers/include/nvs.hpp
@@ -68,6 +68,7 @@ class NvsStorage {
auto Read() -> void;
auto Write() -> bool;
+ // Hardware Compatibility
auto LockPolarity() -> bool;
auto LockPolarity(bool) -> void;
@@ -76,6 +77,10 @@ class NvsStorage {
auto DisplaySize(std::pair<std::optional<uint16_t>, std::optional<uint16_t>>)
-> void;
+ auto HapticMotorIsErm() -> bool;
+ auto HapticMotorIsErm(bool) -> void;
+ // /Hardware Compatibility
+
auto PreferredBluetoothDevice() -> std::optional<bluetooth::MacAndName>;
auto PreferredBluetoothDevice(std::optional<bluetooth::MacAndName>) -> void;
@@ -130,6 +135,7 @@ class NvsStorage {
Setting<uint8_t> lock_polarity_;
Setting<uint16_t> display_cols_;
Setting<uint16_t> display_rows_;
+ Setting<uint8_t> haptic_motor_type_;
Setting<uint8_t> brightness_;
Setting<uint8_t> sensitivity_;