diff options
| author | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-11-28 12:02:18 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-28 12:02:18 -0800 |
| commit | c66df1664497546f32662409778731143e45a552 (patch) | |
| tree | da73a2d532a27685a31d932b3a44a707d4a3af81 /drivers/haptic | |
| parent | 15385d4113414d42bd062c60c9de5df797d3157f (diff) | |
| download | qmk_firmware-c66df1664497546f32662409778731143e45a552.tar.gz qmk_firmware-c66df1664497546f32662409778731143e45a552.zip | |
2020 November 28 Breaking Changes Update (#11053)
* Branch point for 2020 November 28 Breaking Change
* Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183)
* Add support for soft serial to ATmega32U2 (#10204)
* Change MIDI velocity implementation to allow direct control of velocity value (#9940)
* Add ability to build a subset of all keyboards based on platform.
* Actually use eeprom_driver_init().
* Make bootloader_jump weak for ChibiOS. (#10417)
* Joystick 16-bit support (#10439)
* Per-encoder resolutions (#10259)
* Share button state from mousekey to pointing_device (#10179)
* Add hotfix for chibios keyboards not wake (#10088)
* Add advanced/efficient RGB Matrix Indicators (#8564)
* Naming change.
* Support for STM32 GPIOF,G,H,I,J,K (#10206)
* Add milc as a dependency and remove the installed milc (#10563)
* ChibiOS upgrade: early init conversions (#10214)
* ChibiOS upgrade: configuration file migrator (#9952)
* Haptic and solenoid cleanup (#9700)
* XD75 cleanup (#10524)
* OLED display update interval support (#10388)
* Add definition based on currently-selected serial driver. (#10716)
* New feature: Retro Tapping per key (#10622)
* Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638)
* Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530)
* Rescale both ChibiOS and AVR backlighting.
* Reduce Helix keyboard build variation (#8669)
* Minor change to behavior allowing display updates to continue between task ticks (#10750)
* Some GPIO manipulations in matrix.c change to atomic. (#10491)
* qmk cformat (#10767)
* [Keyboard] Update the Speedo firmware for v3.0 (#10657)
* Maartenwut/Maarten namechange to evyd13/Evy (#10274)
* [quantum] combine repeated lines of code (#10837)
* Add step sequencer feature (#9703)
* aeboards/ext65 refactor (#10820)
* Refactor xelus/dawn60 for Rev2 later (#10584)
* add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824)
* [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549)
* update chibios os usb for the otg driver (#8893)
* Remove HD44780 References, Part 4 (#10735)
* [Keyboard] Add Valor FRL TKL (+refactor) (#10512)
* Fix cursor position bug in oled_write_raw functions (#10800)
* Fixup version.h writing when using SKIP_VERSION=yes (#10972)
* Allow for certain code in the codebase assuming length of string. (#10974)
* Add AT90USB support for serial.c (#10706)
* Auto shift: support repeats and early registration (#9826)
* Rename ledmatrix.h to match .c file (#7949)
* Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231)
* Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840)
* Merge point for 2020 Nov 28 Breaking Change
Diffstat (limited to 'drivers/haptic')
| -rw-r--r-- | drivers/haptic/haptic.c | 53 | ||||
| -rw-r--r-- | drivers/haptic/solenoid.c | 10 | ||||
| -rw-r--r-- | drivers/haptic/solenoid.h | 18 |
3 files changed, 56 insertions, 25 deletions
diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 2ce279b75..de3f40052 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c | |||
| @@ -33,11 +33,18 @@ void haptic_init(void) { | |||
| 33 | eeconfig_init(); | 33 | eeconfig_init(); |
| 34 | } | 34 | } |
| 35 | haptic_config.raw = eeconfig_read_haptic(); | 35 | haptic_config.raw = eeconfig_read_haptic(); |
| 36 | if (haptic_config.mode < 1) { | 36 | #ifdef SOLENOID_ENABLE |
| 37 | haptic_config.mode = 1; | 37 | solenoid_set_dwell(haptic_config.dwell); |
| 38 | } | 38 | #endif |
| 39 | if (!haptic_config.mode) { | 39 | if ((haptic_config.raw == 0) |
| 40 | dprintf("No haptic config found in eeprom, setting default configs\n"); | 40 | #ifdef SOLENOID_ENABLE |
| 41 | || (haptic_config.dwell == 0) | ||
| 42 | #endif | ||
| 43 | ) { | ||
| 44 | // this will be called, if the eeprom is not corrupt, | ||
| 45 | // but the previous firmware didn't have haptic enabled, | ||
| 46 | // or the previous firmware didn't have solenoid enabled, | ||
| 47 | // and the current one has solenoid enabled. | ||
| 41 | haptic_reset(); | 48 | haptic_reset(); |
| 42 | } | 49 | } |
| 43 | #ifdef SOLENOID_ENABLE | 50 | #ifdef SOLENOID_ENABLE |
| @@ -118,25 +125,37 @@ void haptic_mode_decrease(void) { | |||
| 118 | } | 125 | } |
| 119 | 126 | ||
| 120 | void haptic_dwell_increase(void) { | 127 | void haptic_dwell_increase(void) { |
| 121 | uint8_t dwell = haptic_config.dwell + 1; | ||
| 122 | #ifdef SOLENOID_ENABLE | 128 | #ifdef SOLENOID_ENABLE |
| 129 | int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE; | ||
| 123 | if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { | 130 | if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { |
| 124 | dwell = 1; | 131 | // if it's already at max, we wrap back to min |
| 132 | next_dwell = SOLENOID_MIN_DWELL; | ||
| 133 | } else if (next_dwell > SOLENOID_MAX_DWELL) { | ||
| 134 | // if we overshoot the max, then cap at max | ||
| 135 | next_dwell = SOLENOID_MAX_DWELL; | ||
| 125 | } | 136 | } |
| 126 | solenoid_set_dwell(dwell); | 137 | solenoid_set_dwell(next_dwell); |
| 138 | #else | ||
| 139 | int16_t next_dwell = ((int16_t)haptic_config.dwell) + 1; | ||
| 127 | #endif | 140 | #endif |
| 128 | haptic_set_dwell(dwell); | 141 | haptic_set_dwell(next_dwell); |
| 129 | } | 142 | } |
| 130 | 143 | ||
| 131 | void haptic_dwell_decrease(void) { | 144 | void haptic_dwell_decrease(void) { |
| 132 | uint8_t dwell = haptic_config.dwell - 1; | ||
| 133 | #ifdef SOLENOID_ENABLE | 145 | #ifdef SOLENOID_ENABLE |
| 134 | if (haptic_config.dwell < SOLENOID_MIN_DWELL) { | 146 | int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE; |
| 135 | dwell = SOLENOID_MAX_DWELL; | 147 | if (haptic_config.dwell <= SOLENOID_MIN_DWELL) { |
| 148 | // if it's already at min, we wrap to max | ||
| 149 | next_dwell = SOLENOID_MAX_DWELL; | ||
| 150 | } else if (next_dwell < SOLENOID_MIN_DWELL) { | ||
| 151 | // if we go below min, then we cap to min | ||
| 152 | next_dwell = SOLENOID_MIN_DWELL; | ||
| 136 | } | 153 | } |
| 137 | solenoid_set_dwell(dwell); | 154 | solenoid_set_dwell(next_dwell); |
| 155 | #else | ||
| 156 | int16_t next_dwell = ((int16_t)haptic_config.dwell) - 1; | ||
| 138 | #endif | 157 | #endif |
| 139 | haptic_set_dwell(dwell); | 158 | haptic_set_dwell(next_dwell); |
| 140 | } | 159 | } |
| 141 | 160 | ||
| 142 | void haptic_reset(void) { | 161 | void haptic_reset(void) { |
| @@ -150,6 +169,12 @@ void haptic_reset(void) { | |||
| 150 | #ifdef SOLENOID_ENABLE | 169 | #ifdef SOLENOID_ENABLE |
| 151 | uint8_t dwell = SOLENOID_DEFAULT_DWELL; | 170 | uint8_t dwell = SOLENOID_DEFAULT_DWELL; |
| 152 | haptic_config.dwell = dwell; | 171 | haptic_config.dwell = dwell; |
| 172 | haptic_config.buzz = SOLENOID_DEFAULT_BUZZ; | ||
| 173 | solenoid_set_dwell(dwell); | ||
| 174 | #else | ||
| 175 | // This is to trigger haptic_reset again, if solenoid is enabled in the future. | ||
| 176 | haptic_config.dwell = 0; | ||
| 177 | haptic_config.buzz = 0; | ||
| 153 | #endif | 178 | #endif |
| 154 | eeconfig_update_haptic(haptic_config.raw); | 179 | eeconfig_update_haptic(haptic_config.raw); |
| 155 | xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); | 180 | xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); |
diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index d645c379a..2975ef893 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c | |||
| @@ -32,14 +32,6 @@ void solenoid_buzz_off(void) { haptic_set_buzz(0); } | |||
| 32 | 32 | ||
| 33 | void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); } | 33 | void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); } |
| 34 | 34 | ||
| 35 | void solenoid_dwell_minus(uint8_t solenoid_dwell) { | ||
| 36 | if (solenoid_dwell > 0) solenoid_dwell--; | ||
| 37 | } | ||
| 38 | |||
| 39 | void solenoid_dwell_plus(uint8_t solenoid_dwell) { | ||
| 40 | if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++; | ||
| 41 | } | ||
| 42 | |||
| 43 | void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } | 35 | void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } |
| 44 | 36 | ||
| 45 | void solenoid_stop(void) { | 37 | void solenoid_stop(void) { |
| @@ -73,7 +65,7 @@ void solenoid_check(void) { | |||
| 73 | 65 | ||
| 74 | // Check whether to buzz the solenoid on and off | 66 | // Check whether to buzz the solenoid on and off |
| 75 | if (haptic_config.buzz) { | 67 | if (haptic_config.buzz) { |
| 76 | if (elapsed / SOLENOID_MIN_DWELL % 2 == 0) { | 68 | if ((elapsed % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) { |
| 77 | if (!solenoid_buzzing) { | 69 | if (!solenoid_buzzing) { |
| 78 | solenoid_buzzing = true; | 70 | solenoid_buzzing = true; |
| 79 | writePinHigh(SOLENOID_PIN); | 71 | writePinHigh(SOLENOID_PIN); |
diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index dd6ececa6..f2a3bc4c3 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h | |||
| @@ -29,6 +29,22 @@ | |||
| 29 | # define SOLENOID_MIN_DWELL 4 | 29 | # define SOLENOID_MIN_DWELL 4 |
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | #ifndef SOLENOID_DWELL_STEP_SIZE | ||
| 33 | # define SOLENOID_DWELL_STEP_SIZE 1 | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #ifndef SOLENOID_DEFAULT_BUZZ | ||
| 37 | # define SOLENOID_DEFAULT_BUZZ 0 | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifndef SOLENOID_BUZZ_ACTUATED | ||
| 41 | # define SOLENOID_BUZZ_ACTUATED SOLENOID_MIN_DWELL | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifndef SOLENOID_BUZZ_NONACTUATED | ||
| 45 | # define SOLENOID_BUZZ_NONACTUATED SOLENOID_MIN_DWELL | ||
| 46 | #endif | ||
| 47 | |||
| 32 | #ifndef SOLENOID_PIN | 48 | #ifndef SOLENOID_PIN |
| 33 | # error SOLENOID_PIN not defined | 49 | # error SOLENOID_PIN not defined |
| 34 | #endif | 50 | #endif |
| @@ -37,8 +53,6 @@ void solenoid_buzz_on(void); | |||
| 37 | void solenoid_buzz_off(void); | 53 | void solenoid_buzz_off(void); |
| 38 | void solenoid_set_buzz(int buzz); | 54 | void solenoid_set_buzz(int buzz); |
| 39 | 55 | ||
| 40 | void solenoid_dwell_minus(uint8_t solenoid_dwell); | ||
| 41 | void solenoid_dwell_plus(uint8_t solenoid_dwell); | ||
| 42 | void solenoid_set_dwell(uint8_t dwell); | 56 | void solenoid_set_dwell(uint8_t dwell); |
| 43 | 57 | ||
| 44 | void solenoid_stop(void); | 58 | void solenoid_stop(void); |
