haptic.h (3589B)
1 /* Copyright 2019 ishtob 2 * Driver for haptic feedback written for QMK 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #pragma once 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 23 #include "compiler_support.h" 24 25 #ifndef HAPTIC_DEFAULT_FEEDBACK 26 # define HAPTIC_DEFAULT_FEEDBACK 0 27 #endif 28 #ifndef HAPTIC_DEFAULT_MODE 29 # define HAPTIC_DEFAULT_MODE DRV2605L_DEFAULT_MODE 30 #endif 31 32 /* EEPROM config settings */ 33 typedef union haptic_config_t { 34 uint32_t raw; 35 struct { 36 bool enable : 1; 37 uint8_t mode : 7; 38 bool buzz : 1; 39 uint8_t dwell : 7; 40 uint8_t amplitude : 8; 41 uint8_t feedback : 2; 42 bool cont : 1; 43 uint8_t reserved : 5; 44 }; 45 } haptic_config_t; 46 47 STATIC_ASSERT(sizeof(haptic_config_t) == sizeof(uint32_t), "Haptic EECONFIG out of spec."); 48 49 typedef enum HAPTIC_FEEDBACK { 50 KEY_PRESS, 51 KEY_PRESS_RELEASE, 52 KEY_RELEASE, 53 HAPTIC_FEEDBACK_MAX, 54 } HAPTIC_FEEDBACK; 55 56 void haptic_init(void); 57 void haptic_task(void); 58 void eeconfig_debug_haptic(void); 59 void haptic_enable(void); 60 void haptic_disable(void); 61 void haptic_toggle(void); 62 void haptic_feedback_toggle(void); 63 void haptic_mode_increase(void); 64 void haptic_mode_decrease(void); 65 void haptic_mode(uint8_t mode); 66 void haptic_reset(void); 67 void haptic_set_feedback(uint8_t feedback); 68 void haptic_set_mode(uint8_t mode); 69 void haptic_set_dwell(uint8_t dwell); 70 void haptic_set_buzz(uint8_t buzz); 71 void haptic_buzz_toggle(void); 72 uint8_t haptic_get_enable(void); 73 uint8_t haptic_get_mode(void); 74 uint8_t haptic_get_feedback(void); 75 void haptic_dwell_increase(void); 76 void haptic_dwell_decrease(void); 77 void haptic_toggle_continuous(void); 78 void haptic_cont_increase(void); 79 void haptic_cont_decrease(void); 80 81 void haptic_play(void); 82 void haptic_shutdown(void); 83 void haptic_notify_usb_device_state_change(void); 84 85 #ifdef HAPTIC_ENABLE_PIN_ACTIVE_LOW 86 # ifndef HAPTIC_ENABLE_PIN 87 # error HAPTIC_ENABLE_PIN not defined 88 # endif 89 # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN) 90 # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN) 91 #else 92 # define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN) 93 # define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN) 94 #endif 95 96 #ifdef HAPTIC_ENABLE_STATUS_LED_ACTIVE_LOW 97 # ifndef HAPTIC_ENABLE_STATUS_LED 98 # error HAPTIC_ENABLE_STATUS_LED not defined 99 # endif 100 # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED) 101 # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED) 102 #else 103 # define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED) 104 # define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED) 105 #endif 106 107 #ifndef HAPTIC_OFF_IN_LOW_POWER 108 # define HAPTIC_OFF_IN_LOW_POWER 0 109 #endif