haptic.h
3543 bytes
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#ifndef HAPTIC_DEFAULT_FEEDBACK
24# define HAPTIC_DEFAULT_FEEDBACK 0
25#endif
26#ifndef HAPTIC_DEFAULT_MODE
27# define HAPTIC_DEFAULT_MODE DRV2605L_DEFAULT_MODE
28#endif
29
30/* EEPROM config settings */
31typedef union {
32 uint32_t raw;
33 struct {
34 bool enable : 1;
35 uint8_t mode : 7;
36 bool buzz : 1;
37 uint8_t dwell : 7;
38 uint8_t amplitude : 8;
39 uint8_t feedback : 2;
40 bool cont : 1;
41 uint8_t reserved : 5;
42 };
43} haptic_config_t;
44
45_Static_assert(sizeof(haptic_config_t) == sizeof(uint32_t), "Haptic EECONFIG out of spec.");
46
47typedef enum HAPTIC_FEEDBACK {
48 KEY_PRESS,
49 KEY_PRESS_RELEASE,
50 KEY_RELEASE,
51 HAPTIC_FEEDBACK_MAX,
52} HAPTIC_FEEDBACK;
53
54void haptic_init(void);
55void haptic_task(void);
56void eeconfig_debug_haptic(void);
57void haptic_enable(void);
58void haptic_disable(void);
59void haptic_toggle(void);
60void haptic_feedback_toggle(void);
61void haptic_mode_increase(void);
62void haptic_mode_decrease(void);
63void haptic_mode(uint8_t mode);
64void haptic_reset(void);
65void haptic_set_feedback(uint8_t feedback);
66void haptic_set_mode(uint8_t mode);
67void haptic_set_dwell(uint8_t dwell);
68void haptic_set_buzz(uint8_t buzz);
69void haptic_buzz_toggle(void);
70uint8_t haptic_get_enable(void);
71uint8_t haptic_get_mode(void);
72uint8_t haptic_get_feedback(void);
73void haptic_dwell_increase(void);
74void haptic_dwell_decrease(void);
75void haptic_toggle_continuous(void);
76void haptic_cont_increase(void);
77void haptic_cont_decrease(void);
78
79void haptic_play(void);
80void haptic_shutdown(void);
81void haptic_notify_usb_device_state_change(void);
82
83#ifdef HAPTIC_ENABLE_PIN_ACTIVE_LOW
84# ifndef HAPTIC_ENABLE_PIN
85# error HAPTIC_ENABLE_PIN not defined
86# endif
87# define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
88# define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
89#else
90# define HAPTIC_ENABLE_PIN_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_PIN)
91# define HAPTIC_ENABLE_PIN_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_PIN)
92#endif
93
94#ifdef HAPTIC_ENABLE_STATUS_LED_ACTIVE_LOW
95# ifndef HAPTIC_ENABLE_STATUS_LED
96# error HAPTIC_ENABLE_STATUS_LED not defined
97# endif
98# define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
99# define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
100#else
101# define HAPTIC_ENABLE_STATUS_LED_WRITE_ACTIVE() gpio_write_pin_high(HAPTIC_ENABLE_STATUS_LED)
102# define HAPTIC_ENABLE_STATUS_LED_WRITE_INACTIVE() gpio_write_pin_low(HAPTIC_ENABLE_STATUS_LED)
103#endif
104
105#ifndef HAPTIC_OFF_IN_LOW_POWER
106# define HAPTIC_OFF_IN_LOW_POWER 0
107#endif