From e39754ba105213c133407e2dacb5fd31f3873e4c Mon Sep 17 00:00:00 2001 From: Robin Howard Date: Fri, 19 Apr 2024 16:00:57 +1000 Subject: Fix DRV2065L register usage: we were accidentally setting control2 when we meant control3. --- src/drivers/include/haptics.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/haptics.hpp b/src/drivers/include/haptics.hpp index 6cfcbb0d..cf970977 100644 --- a/src/drivers/include/haptics.hpp +++ b/src/drivers/include/haptics.hpp @@ -214,7 +214,7 @@ class Haptics { }; struct ControlMask { - // Control1 + // FeedbackControl static constexpr uint8_t kNErmLra = 0b10000000; // Control3 static constexpr uint8_t kErmOpenLoop = 0b00100000; @@ -257,12 +257,12 @@ class Haptics { // A bunch of different options, not grouped // in any particular sensible way - kControl1 = 0x1A, - kControl2 = 0x1B, - kControl3 = 0x1C, - kControl4 = 0x1D, - kControl5 = 0x1E, - kControl6 = 0x1F, + kFeedbackControl = 0x1A, + kControl1 = 0x1B, + kControl2 = 0x1C, + kControl3 = 0x1D, + kControl4 = 0x1E, + kControl5 = 0x1F, kSupplyVoltageMonitor = 0x21, // "VBAT" kLraResonancePeriod = 0x22, @@ -295,12 +295,12 @@ class Haptics { kOverdriveClampVoltage = 0x8C, kAutoCalibrationCompensationResult = 0x0C, kAutoCalibrationBackEmfResult = 0x6C, - kControl1 = 0x36, - kControl2 = 0x93, - kControl3 = 0xF5, - kControl4 = 0xA0, - kControl5 = 0x20, - kControl6 = 0x80, + kFeedbackControl = 0x36, + kControl1 = 0x93, + kControl2 = 0xF5, + kControl3 = 0xA0, + kControl4 = 0x20, + kControl5 = 0x80, kSupplyVoltageMonitor = 0, kLraResonancePeriod = 0, }; -- cgit v1.2.3 From 7c075cf5b776feaed2065f936dff0c176635b89d Mon Sep 17 00:00:00 2001 From: Robin Howard Date: Fri, 19 Apr 2024 16:03:35 +1000 Subject: Adds LRA haptic support (open-loop only for now). --- src/drivers/include/haptics.hpp | 24 +++++++++++++++++++----- src/drivers/include/nvs.hpp | 6 ++++++ 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/drivers/include') 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 #include #include +#include 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& motor) + -> Haptics* { + return new Haptics(motor); + } + + Haptics(const std::variant& 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>) -> void; + auto HapticMotorIsErm() -> bool; + auto HapticMotorIsErm(bool) -> void; + // /Hardware Compatibility + auto PreferredBluetoothDevice() -> std::optional; auto PreferredBluetoothDevice(std::optional) -> void; @@ -130,6 +135,7 @@ class NvsStorage { Setting lock_polarity_; Setting display_cols_; Setting display_rows_; + Setting haptic_motor_type_; Setting brightness_; Setting sensitivity_; -- cgit v1.2.3