1
0
Fork 0

clang-format changes

This commit is contained in:
skullY 2019-08-30 11:19:03 -07:00 committed by skullydazed
parent 61af76a10d
commit b624f32f94
502 changed files with 32259 additions and 39062 deletions

View file

@ -20,110 +20,102 @@
#include <stdio.h>
#include <math.h>
uint8_t DRV2605L_transfer_buffer[2];
uint8_t DRV2605L_tx_register[0];
uint8_t DRV2605L_read_buffer[0];
uint8_t DRV2605L_read_register;
void DRV_write(uint8_t drv_register, uint8_t settings) {
DRV2605L_transfer_buffer[0] = drv_register;
DRV2605L_transfer_buffer[1] = settings;
i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100);
DRV2605L_transfer_buffer[0] = drv_register;
DRV2605L_transfer_buffer[1] = settings;
i2c_transmit(DRV2605L_BASE_ADDRESS << 1, DRV2605L_transfer_buffer, 2, 100);
}
uint8_t DRV_read(uint8_t regaddress) {
#ifdef __AVR__
i2c_readReg(DRV2605L_BASE_ADDRESS << 1,
regaddress, DRV2605L_read_buffer, 1, 100);
DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
i2c_readReg(DRV2605L_BASE_ADDRESS << 1, regaddress, DRV2605L_read_buffer, 1, 100);
DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
#else
DRV2605L_tx_register[0] = regaddress;
if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1,
DRV2605L_tx_register, 1,
DRV2605L_read_buffer, 1
)){
printf("err reading reg \n");
}
DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
DRV2605L_tx_register[0] = regaddress;
if (MSG_OK != i2c_transmit_receive(DRV2605L_BASE_ADDRESS << 1, DRV2605L_tx_register, 1, DRV2605L_read_buffer, 1)) {
printf("err reading reg \n");
}
DRV2605L_read_register = (uint8_t)DRV2605L_read_buffer[0];
#endif
return DRV2605L_read_register;
return DRV2605L_read_register;
}
void DRV_init(void)
{
i2c_init();
/* 0x07 sets DRV2605 into calibration mode */
DRV_write(DRV_MODE,0x07);
void DRV_init(void) {
i2c_init();
/* 0x07 sets DRV2605 into calibration mode */
DRV_write(DRV_MODE, 0x07);
// DRV_write(DRV_FEEDBACK_CTRL,0xB6);
#if FB_ERM_LRA == 0
// DRV_write(DRV_FEEDBACK_CTRL,0xB6);
#if FB_ERM_LRA == 0
/* ERM settings */
DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE/21.33)*1000);
#if ERM_OPEN_LOOP == 0
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK*(DRIVE_TIME+BLANKING_TIME+IDISS_TIME))/0.02133)/(DRIVE_TIME-0.0003)));
#elif ERM_OPEN_LOOP == 1
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
#endif
#elif FB_ERM_LRA == 1
DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150+(SAMPLE_TIME*50))*0.000001)) + 0.0003)* F_LRA)/0.02071)));
#if LRA_OPEN_LOOP == 0
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK/sqrt(1-(F_LRA*0.0008))/0.02133)));
#elif LRA_OPEN_LOOP == 1
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK/0.02196));
#endif
#endif
DRVREG_FBR FB_SET;
FB_SET.Bits.ERM_LRA = FB_ERM_LRA;
DRV_write(DRV_RATED_VOLT, (RATED_VOLTAGE / 21.33) * 1000);
# if ERM_OPEN_LOOP == 0
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (((V_PEAK * (DRIVE_TIME + BLANKING_TIME + IDISS_TIME)) / 0.02133) / (DRIVE_TIME - 0.0003)));
# elif ERM_OPEN_LOOP == 1
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196));
# endif
#elif FB_ERM_LRA == 1
DRV_write(DRV_RATED_VOLT, ((V_RMS * sqrt(1 - ((4 * ((150 + (SAMPLE_TIME * 50)) * 0.000001)) + 0.0003) * F_LRA) / 0.02071)));
# if LRA_OPEN_LOOP == 0
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, ((V_PEAK / sqrt(1 - (F_LRA * 0.0008)) / 0.02133)));
# elif LRA_OPEN_LOOP == 1
DRV_write(DRV_OVERDRIVE_CLAMP_VOLT, (V_PEAK / 0.02196));
# endif
#endif
DRVREG_FBR FB_SET;
FB_SET.Bits.ERM_LRA = FB_ERM_LRA;
FB_SET.Bits.BRAKE_FACTOR = FB_BRAKEFACTOR;
FB_SET.Bits.LOOP_GAIN =FB_LOOPGAIN;
FB_SET.Bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/
DRV_write(DRV_FEEDBACK_CTRL, (uint8_t) FB_SET.Byte);
DRVREG_CTRL1 C1_SET;
C1_SET.Bits.C1_DRIVE_TIME = DRIVE_TIME;
C1_SET.Bits.C1_AC_COUPLE = AC_COUPLE;
FB_SET.Bits.LOOP_GAIN = FB_LOOPGAIN;
FB_SET.Bits.BEMF_GAIN = 0; /* auto-calibration populates this field*/
DRV_write(DRV_FEEDBACK_CTRL, (uint8_t)FB_SET.Byte);
DRVREG_CTRL1 C1_SET;
C1_SET.Bits.C1_DRIVE_TIME = DRIVE_TIME;
C1_SET.Bits.C1_AC_COUPLE = AC_COUPLE;
C1_SET.Bits.C1_STARTUP_BOOST = STARTUP_BOOST;
DRV_write(DRV_CTRL_1, (uint8_t) C1_SET.Byte);
DRVREG_CTRL2 C2_SET;
C2_SET.Bits.C2_BIDIR_INPUT = BIDIR_INPUT;
C2_SET.Bits.C2_BRAKE_STAB = BRAKE_STAB;
C2_SET.Bits.C2_SAMPLE_TIME = SAMPLE_TIME;
DRV_write(DRV_CTRL_1, (uint8_t)C1_SET.Byte);
DRVREG_CTRL2 C2_SET;
C2_SET.Bits.C2_BIDIR_INPUT = BIDIR_INPUT;
C2_SET.Bits.C2_BRAKE_STAB = BRAKE_STAB;
C2_SET.Bits.C2_SAMPLE_TIME = SAMPLE_TIME;
C2_SET.Bits.C2_BLANKING_TIME = BLANKING_TIME;
C2_SET.Bits.C2_IDISS_TIME = IDISS_TIME;
DRV_write(DRV_CTRL_2, (uint8_t) C2_SET.Byte);
DRVREG_CTRL3 C3_SET;
C3_SET.Bits.C3_LRA_OPEN_LOOP = LRA_OPEN_LOOP;
C3_SET.Bits.C3_N_PWM_ANALOG = N_PWM_ANALOG;
C3_SET.Bits.C3_LRA_DRIVE_MODE = LRA_DRIVE_MODE;
C2_SET.Bits.C2_IDISS_TIME = IDISS_TIME;
DRV_write(DRV_CTRL_2, (uint8_t)C2_SET.Byte);
DRVREG_CTRL3 C3_SET;
C3_SET.Bits.C3_LRA_OPEN_LOOP = LRA_OPEN_LOOP;
C3_SET.Bits.C3_N_PWM_ANALOG = N_PWM_ANALOG;
C3_SET.Bits.C3_LRA_DRIVE_MODE = LRA_DRIVE_MODE;
C3_SET.Bits.C3_DATA_FORMAT_RTO = DATA_FORMAT_RTO;
C3_SET.Bits.C3_SUPPLY_COMP_DIS = SUPPLY_COMP_DIS;
C3_SET.Bits.C3_ERM_OPEN_LOOP = ERM_OPEN_LOOP;
C3_SET.Bits.C3_NG_THRESH = NG_THRESH;
DRV_write(DRV_CTRL_3, (uint8_t) C3_SET.Byte);
DRVREG_CTRL4 C4_SET;
C4_SET.Bits.C4_ZC_DET_TIME = ZC_DET_TIME;
C3_SET.Bits.C3_ERM_OPEN_LOOP = ERM_OPEN_LOOP;
C3_SET.Bits.C3_NG_THRESH = NG_THRESH;
DRV_write(DRV_CTRL_3, (uint8_t)C3_SET.Byte);
DRVREG_CTRL4 C4_SET;
C4_SET.Bits.C4_ZC_DET_TIME = ZC_DET_TIME;
C4_SET.Bits.C4_AUTO_CAL_TIME = AUTO_CAL_TIME;
DRV_write(DRV_CTRL_4, (uint8_t) C4_SET.Byte);
DRV_write(DRV_LIB_SELECTION,LIB_SELECTION);
DRV_write(DRV_CTRL_4, (uint8_t)C4_SET.Byte);
DRV_write(DRV_LIB_SELECTION, LIB_SELECTION);
DRV_write(DRV_GO, 0x01);
DRV_write(DRV_GO, 0x01);
/* 0x00 sets DRV2605 out of standby and to use internal trigger
* 0x01 sets DRV2605 out of standby and to use external trigger */
DRV_write(DRV_MODE,0x00);
/* 0x00 sets DRV2605 out of standby and to use internal trigger
* 0x01 sets DRV2605 out of standby and to use external trigger */
DRV_write(DRV_MODE, 0x00);
//Play greeting sequence
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
DRV_write(DRV_GO, 0x01);
// Play greeting sequence
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_WAVEFORM_SEQ_1, DRV_GREETING);
DRV_write(DRV_GO, 0x01);
}
void DRV_pulse(uint8_t sequence)
{
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
DRV_write(DRV_GO, 0x01);
void DRV_pulse(uint8_t sequence) {
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
DRV_write(DRV_GO, 0x01);
}

View file

@ -22,383 +22,383 @@
* Feedback Control Settings */
#ifndef FB_ERM_LRA
#define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/
# define FB_ERM_LRA 1 /* For ERM:0 or LRA:1*/
#endif
#ifndef FB_BRAKEFACTOR
#define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */
# define FB_BRAKEFACTOR 3 /* For 1x:0, 2x:1, 3x:2, 4x:3, 6x:4, 8x:5, 16x:6, Disable Braking:7 */
#endif
#ifndef FB_LOOPGAIN
#define FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */
# define FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */
#endif
/* LRA specific settings */
#if FB_ERM_LRA == 1
#ifndef V_RMS
#define V_RMS 2.0
#endif
#ifndef V_PEAK
#define V_PEAK 2.1
#endif
#ifndef F_LRA
#define F_LRA 205
#endif
#ifndef RATED_VOLTAGE
#define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
#endif
# ifndef V_RMS
# define V_RMS 2.0
# endif
# ifndef V_PEAK
# define V_PEAK 2.1
# endif
# ifndef F_LRA
# define F_LRA 205
# endif
# ifndef RATED_VOLTAGE
# define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
# endif
#endif
#ifndef RATED_VOLTAGE
#define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
# define RATED_VOLTAGE 2 /* 2v as safe range in case device voltage is not set */
#endif
#ifndef V_PEAK
#define V_PEAK 2.8
# define V_PEAK 2.8
#endif
/* Library Selection */
#ifndef LIB_SELECTION
#if FB_ERM_LRA == 1
#define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */
#else
#define LIB_SELECTION 1
#endif
# if FB_ERM_LRA == 1
# define LIB_SELECTION 6 /* For Empty:0' TS2200 library A to D:1-5, LRA Library: 6 */
# else
# define LIB_SELECTION 1
# endif
#endif
#ifndef DRV_GREETING
#define DRV_GREETING alert_750ms
# define DRV_GREETING alert_750ms
#endif
#ifndef DRV_MODE_DEFAULT
#define DRV_MODE_DEFAULT strong_click1
# define DRV_MODE_DEFAULT strong_click1
#endif
/* Control 1 register settings */
#ifndef DRIVE_TIME
#define DRIVE_TIME 25
# define DRIVE_TIME 25
#endif
#ifndef AC_COUPLE
#define AC_COUPLE 0
# define AC_COUPLE 0
#endif
#ifndef STARTUP_BOOST
#define STARTUP_BOOST 1
# define STARTUP_BOOST 1
#endif
/* Control 2 Settings */
#ifndef BIDIR_INPUT
#define BIDIR_INPUT 1
# define BIDIR_INPUT 1
#endif
#ifndef BRAKE_STAB
#define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */
# define BRAKE_STAB 1 /* Loopgain is reduced when braking is almost complete to improve stability */
#endif
#ifndef SAMPLE_TIME
#define SAMPLE_TIME 3
#ifndef SAMPLE_TIME
# define SAMPLE_TIME 3
#endif
#ifndef BLANKING_TIME
#define BLANKING_TIME 1
# define BLANKING_TIME 1
#endif
#ifndef IDISS_TIME
#define IDISS_TIME 1
# define IDISS_TIME 1
#endif
/* Control 3 settings */
#ifndef NG_THRESH
#define NG_THRESH 2
# define NG_THRESH 2
#endif
#ifndef ERM_OPEN_LOOP
#define ERM_OPEN_LOOP 1
# define ERM_OPEN_LOOP 1
#endif
#ifndef SUPPLY_COMP_DIS
#define SUPPLY_COMP_DIS 0
# define SUPPLY_COMP_DIS 0
#endif
#ifndef DATA_FORMAT_RTO
#define DATA_FORMAT_RTO 0
# define DATA_FORMAT_RTO 0
#endif
#ifndef LRA_DRIVE_MODE
#define LRA_DRIVE_MODE 0
# define LRA_DRIVE_MODE 0
#endif
#ifndef N_PWM_ANALOG
#define N_PWM_ANALOG 0
# define N_PWM_ANALOG 0
#endif
#ifndef LRA_OPEN_LOOP
#define LRA_OPEN_LOOP 0
# define LRA_OPEN_LOOP 0
#endif
/* Control 4 settings */
#ifndef ZC_DET_TIME
#define ZC_DET_TIME 0
# define ZC_DET_TIME 0
#endif
#ifndef AUTO_CAL_TIME
#define AUTO_CAL_TIME 3
# define AUTO_CAL_TIME 3
#endif
/* register defines -------------------------------------------------------- */
#define DRV2605L_BASE_ADDRESS 0x5A /* DRV2605L Base address */
#define DRV_STATUS 0x00
#define DRV_MODE 0x01
#define DRV_RTP_INPUT 0x02
#define DRV_LIB_SELECTION 0x03
#define DRV_WAVEFORM_SEQ_1 0x04
#define DRV_WAVEFORM_SEQ_2 0x05
#define DRV_WAVEFORM_SEQ_3 0x06
#define DRV_WAVEFORM_SEQ_4 0x07
#define DRV_WAVEFORM_SEQ_5 0x08
#define DRV_WAVEFORM_SEQ_6 0x09
#define DRV_WAVEFORM_SEQ_7 0x0A
#define DRV_WAVEFORM_SEQ_8 0x0B
#define DRV_GO 0x0C
#define DRV_OVERDRIVE_TIME_OFFSET 0x0D
#define DRV_SUSTAIN_TIME_OFFSET_P 0x0E
#define DRV_SUSTAIN_TIME_OFFSET_N 0x0F
#define DRV_BRAKE_TIME_OFFSET 0x10
#define DRV_AUDIO_2_VIBE_CTRL 0x11
#define DRV_AUDIO_2_VIBE_MIN_IN 0x12
#define DRV_AUDIO_2_VIBE_MAX_IN 0x13
#define DRV_AUDIO_2_VIBE_MIN_OUTDRV 0x14
#define DRV_AUDIO_2_VIBE_MAX_OUTDRV 0x15
#define DRV_RATED_VOLT 0x16
#define DRV_OVERDRIVE_CLAMP_VOLT 0x17
#define DRV_AUTO_CALIB_COMP_RESULT 0x18
#define DRV_AUTO_CALIB_BEMF_RESULT 0x19
#define DRV_FEEDBACK_CTRL 0x1A
#define DRV_CTRL_1 0x1B
#define DRV_CTRL_2 0x1C
#define DRV_CTRL_3 0x1D
#define DRV_CTRL_4 0x1E
#define DRV_CTRL_5 0x1F
#define DRV_OPEN_LOOP_PERIOD 0x20
#define DRV_VBAT_VOLT_MONITOR 0x21
#define DRV_LRA_RESONANCE_PERIOD 0x22
#define DRV2605L_BASE_ADDRESS 0x5A /* DRV2605L Base address */
#define DRV_STATUS 0x00
#define DRV_MODE 0x01
#define DRV_RTP_INPUT 0x02
#define DRV_LIB_SELECTION 0x03
#define DRV_WAVEFORM_SEQ_1 0x04
#define DRV_WAVEFORM_SEQ_2 0x05
#define DRV_WAVEFORM_SEQ_3 0x06
#define DRV_WAVEFORM_SEQ_4 0x07
#define DRV_WAVEFORM_SEQ_5 0x08
#define DRV_WAVEFORM_SEQ_6 0x09
#define DRV_WAVEFORM_SEQ_7 0x0A
#define DRV_WAVEFORM_SEQ_8 0x0B
#define DRV_GO 0x0C
#define DRV_OVERDRIVE_TIME_OFFSET 0x0D
#define DRV_SUSTAIN_TIME_OFFSET_P 0x0E
#define DRV_SUSTAIN_TIME_OFFSET_N 0x0F
#define DRV_BRAKE_TIME_OFFSET 0x10
#define DRV_AUDIO_2_VIBE_CTRL 0x11
#define DRV_AUDIO_2_VIBE_MIN_IN 0x12
#define DRV_AUDIO_2_VIBE_MAX_IN 0x13
#define DRV_AUDIO_2_VIBE_MIN_OUTDRV 0x14
#define DRV_AUDIO_2_VIBE_MAX_OUTDRV 0x15
#define DRV_RATED_VOLT 0x16
#define DRV_OVERDRIVE_CLAMP_VOLT 0x17
#define DRV_AUTO_CALIB_COMP_RESULT 0x18
#define DRV_AUTO_CALIB_BEMF_RESULT 0x19
#define DRV_FEEDBACK_CTRL 0x1A
#define DRV_CTRL_1 0x1B
#define DRV_CTRL_2 0x1C
#define DRV_CTRL_3 0x1D
#define DRV_CTRL_4 0x1E
#define DRV_CTRL_5 0x1F
#define DRV_OPEN_LOOP_PERIOD 0x20
#define DRV_VBAT_VOLT_MONITOR 0x21
#define DRV_LRA_RESONANCE_PERIOD 0x22
void DRV_init(void);
void DRV_write(const uint8_t drv_register, const uint8_t settings);
void DRV_init(void);
void DRV_write(const uint8_t drv_register, const uint8_t settings);
uint8_t DRV_read(const uint8_t regaddress);
void DRV_pulse(const uint8_t sequence);
void DRV_pulse(const uint8_t sequence);
typedef enum DRV_EFFECT{
clear_sequence = 0,
strong_click = 1,
strong_click_60 = 2,
strong_click_30 = 3,
sharp_click = 4,
sharp_click_60 = 5,
sharp_click_30 = 6,
soft_bump = 7,
soft_bump_60 = 8,
soft_bump_30 = 9,
dbl_click = 10,
dbl_click_60 = 11,
trp_click = 12,
soft_fuzz = 13,
strong_buzz = 14,
alert_750ms = 15,
alert_1000ms = 16,
strong_click1 = 17,
strong_click2_80 = 18,
strong_click3_60 = 19,
strong_click4_30 = 20,
medium_click1 = 21,
medium_click2_80 = 22,
medium_click3_60 = 23,
sharp_tick1 = 24,
sharp_tick2_80 = 25,
sharp_tick3_60 = 26,
sh_dblclick_str = 27,
sh_dblclick_str_80 = 28,
sh_dblclick_str_60 = 29,
sh_dblclick_str_30 = 30,
sh_dblclick_med = 31,
sh_dblclick_med_80 = 32,
sh_dblclick_med_60 = 33,
sh_dblsharp_tick = 34,
sh_dblsharp_tick_80 = 35,
sh_dblsharp_tick_60 = 36,
lg_dblclick_str = 37,
lg_dblclick_str_80 = 38,
lg_dblclick_str_60 = 39,
lg_dblclick_str_30 = 40,
lg_dblclick_med = 41,
lg_dblclick_med_80 = 42,
lg_dblclick_med_60 = 43,
lg_dblsharp_tick = 44,
lg_dblsharp_tick_80 = 45,
lg_dblsharp_tick_60 = 46,
buzz = 47,
buzz_80 = 48,
buzz_60 = 49,
buzz_40 = 50,
buzz_20 = 51,
pulsing_strong = 52,
pulsing_strong_80 = 53,
pulsing_medium = 54,
pulsing_medium_80 = 55,
pulsing_sharp = 56,
pulsing_sharp_80 = 57,
transition_click = 58,
transition_click_80 = 59,
transition_click_60 = 60,
transition_click_40 = 61,
transition_click_20 = 62,
transition_click_10 = 63,
transition_hum = 64,
transition_hum_80 = 65,
transition_hum_60 = 66,
transition_hum_40 = 67,
transition_hum_20 = 68,
transition_hum_10 = 69,
transition_rampdown_long_smooth1 = 70,
transition_rampdown_long_smooth2 = 71,
transition_rampdown_med_smooth1 = 72,
transition_rampdown_med_smooth2 = 73,
transition_rampdown_short_smooth1 = 74,
transition_rampdown_short_smooth2 = 75,
transition_rampdown_long_sharp1 = 76,
transition_rampdown_long_sharp2 = 77,
transition_rampdown_med_sharp1 = 78,
transition_rampdown_med_sharp2 = 79,
transition_rampdown_short_sharp1 = 80,
transition_rampdown_short_sharp2 = 81,
transition_rampup_long_smooth1 = 82,
transition_rampup_long_smooth2 = 83,
transition_rampup_med_smooth1 = 84,
transition_rampup_med_smooth2 = 85,
transition_rampup_short_smooth1 = 86,
transition_rampup_short_smooth2 = 87,
transition_rampup_long_sharp1 = 88,
transition_rampup_long_sharp2 = 89,
transition_rampup_med_sharp1 = 90,
transition_rampup_med_sharp2 = 91,
transition_rampup_short_sharp1 = 92,
transition_rampup_short_sharp2 = 93,
transition_rampdown_long_smooth1_50 = 94,
transition_rampdown_long_smooth2_50 = 95,
transition_rampdown_med_smooth1_50 = 96,
transition_rampdown_med_smooth2_50 = 97,
transition_rampdown_short_smooth1_50 = 98,
transition_rampdown_short_smooth2_50 = 99,
transition_rampdown_long_sharp1_50 = 100,
transition_rampdown_long_sharp2_50 = 101,
transition_rampdown_med_sharp1_50 = 102,
transition_rampdown_med_sharp2_50 = 103,
transition_rampdown_short_sharp1_50 = 104,
transition_rampdown_short_sharp2_50 = 105,
transition_rampup_long_smooth1_50 = 106,
transition_rampup_long_smooth2_50 = 107,
transition_rampup_med_smooth1_50 = 108,
transition_rampup_med_smooth2_50 = 109,
transition_rampup_short_smooth1_50 = 110,
transition_rampup_short_smooth2_50 = 111,
transition_rampup_long_sharp1_50 = 112,
transition_rampup_long_sharp2_50 = 113,
transition_rampup_med_sharp1_50 = 114,
transition_rampup_med_sharp2_50 = 115,
transition_rampup_short_sharp1_50 = 116,
transition_rampup_short_sharp2_50 = 117,
long_buzz_for_programmatic_stopping = 118,
smooth_hum1_50 = 119,
smooth_hum2_40 = 120,
smooth_hum3_30 = 121,
smooth_hum4_20 = 122,
smooth_hum5_10 = 123,
drv_effect_max = 124,
typedef enum DRV_EFFECT {
clear_sequence = 0,
strong_click = 1,
strong_click_60 = 2,
strong_click_30 = 3,
sharp_click = 4,
sharp_click_60 = 5,
sharp_click_30 = 6,
soft_bump = 7,
soft_bump_60 = 8,
soft_bump_30 = 9,
dbl_click = 10,
dbl_click_60 = 11,
trp_click = 12,
soft_fuzz = 13,
strong_buzz = 14,
alert_750ms = 15,
alert_1000ms = 16,
strong_click1 = 17,
strong_click2_80 = 18,
strong_click3_60 = 19,
strong_click4_30 = 20,
medium_click1 = 21,
medium_click2_80 = 22,
medium_click3_60 = 23,
sharp_tick1 = 24,
sharp_tick2_80 = 25,
sharp_tick3_60 = 26,
sh_dblclick_str = 27,
sh_dblclick_str_80 = 28,
sh_dblclick_str_60 = 29,
sh_dblclick_str_30 = 30,
sh_dblclick_med = 31,
sh_dblclick_med_80 = 32,
sh_dblclick_med_60 = 33,
sh_dblsharp_tick = 34,
sh_dblsharp_tick_80 = 35,
sh_dblsharp_tick_60 = 36,
lg_dblclick_str = 37,
lg_dblclick_str_80 = 38,
lg_dblclick_str_60 = 39,
lg_dblclick_str_30 = 40,
lg_dblclick_med = 41,
lg_dblclick_med_80 = 42,
lg_dblclick_med_60 = 43,
lg_dblsharp_tick = 44,
lg_dblsharp_tick_80 = 45,
lg_dblsharp_tick_60 = 46,
buzz = 47,
buzz_80 = 48,
buzz_60 = 49,
buzz_40 = 50,
buzz_20 = 51,
pulsing_strong = 52,
pulsing_strong_80 = 53,
pulsing_medium = 54,
pulsing_medium_80 = 55,
pulsing_sharp = 56,
pulsing_sharp_80 = 57,
transition_click = 58,
transition_click_80 = 59,
transition_click_60 = 60,
transition_click_40 = 61,
transition_click_20 = 62,
transition_click_10 = 63,
transition_hum = 64,
transition_hum_80 = 65,
transition_hum_60 = 66,
transition_hum_40 = 67,
transition_hum_20 = 68,
transition_hum_10 = 69,
transition_rampdown_long_smooth1 = 70,
transition_rampdown_long_smooth2 = 71,
transition_rampdown_med_smooth1 = 72,
transition_rampdown_med_smooth2 = 73,
transition_rampdown_short_smooth1 = 74,
transition_rampdown_short_smooth2 = 75,
transition_rampdown_long_sharp1 = 76,
transition_rampdown_long_sharp2 = 77,
transition_rampdown_med_sharp1 = 78,
transition_rampdown_med_sharp2 = 79,
transition_rampdown_short_sharp1 = 80,
transition_rampdown_short_sharp2 = 81,
transition_rampup_long_smooth1 = 82,
transition_rampup_long_smooth2 = 83,
transition_rampup_med_smooth1 = 84,
transition_rampup_med_smooth2 = 85,
transition_rampup_short_smooth1 = 86,
transition_rampup_short_smooth2 = 87,
transition_rampup_long_sharp1 = 88,
transition_rampup_long_sharp2 = 89,
transition_rampup_med_sharp1 = 90,
transition_rampup_med_sharp2 = 91,
transition_rampup_short_sharp1 = 92,
transition_rampup_short_sharp2 = 93,
transition_rampdown_long_smooth1_50 = 94,
transition_rampdown_long_smooth2_50 = 95,
transition_rampdown_med_smooth1_50 = 96,
transition_rampdown_med_smooth2_50 = 97,
transition_rampdown_short_smooth1_50 = 98,
transition_rampdown_short_smooth2_50 = 99,
transition_rampdown_long_sharp1_50 = 100,
transition_rampdown_long_sharp2_50 = 101,
transition_rampdown_med_sharp1_50 = 102,
transition_rampdown_med_sharp2_50 = 103,
transition_rampdown_short_sharp1_50 = 104,
transition_rampdown_short_sharp2_50 = 105,
transition_rampup_long_smooth1_50 = 106,
transition_rampup_long_smooth2_50 = 107,
transition_rampup_med_smooth1_50 = 108,
transition_rampup_med_smooth2_50 = 109,
transition_rampup_short_smooth1_50 = 110,
transition_rampup_short_smooth2_50 = 111,
transition_rampup_long_sharp1_50 = 112,
transition_rampup_long_sharp2_50 = 113,
transition_rampup_med_sharp1_50 = 114,
transition_rampup_med_sharp2_50 = 115,
transition_rampup_short_sharp1_50 = 116,
transition_rampup_short_sharp2_50 = 117,
long_buzz_for_programmatic_stopping = 118,
smooth_hum1_50 = 119,
smooth_hum2_40 = 120,
smooth_hum3_30 = 121,
smooth_hum4_20 = 122,
smooth_hum5_10 = 123,
drv_effect_max = 124,
} DRV_EFFECT;
/* Register bit array unions */
typedef union DRVREG_STATUS { /* register 0x00 */
uint8_t Byte;
struct {
uint8_t OC_DETECT :1; /* set to 1 when overcurrent event is detected */
uint8_t OVER_TEMP :1; /* set to 1 when device exceeds temp threshold */
uint8_t FB_STS :1; /* set to 1 when feedback controller has timed out */
/* auto-calibration routine and diagnostic result
* result | auto-calibation | diagnostic |
* 0 | passed | actuator func normal |
* 1 | failed | actuator func fault* |
* * actuator is not present or is shorted, timing out, or giving outof-range back-EMF */
uint8_t DIAG_RESULT :1;
uint8_t :1;
uint8_t DEVICE_ID :3; /* Device IDs 3: DRV2605 4: DRV2604 5: DRV2604L 6: DRV2605L */
} Bits;
uint8_t Byte;
struct {
uint8_t OC_DETECT : 1; /* set to 1 when overcurrent event is detected */
uint8_t OVER_TEMP : 1; /* set to 1 when device exceeds temp threshold */
uint8_t FB_STS : 1; /* set to 1 when feedback controller has timed out */
/* auto-calibration routine and diagnostic result
* result | auto-calibation | diagnostic |
* 0 | passed | actuator func normal |
* 1 | failed | actuator func fault* |
* * actuator is not present or is shorted, timing out, or giving outof-range back-EMF */
uint8_t DIAG_RESULT : 1;
uint8_t : 1;
uint8_t DEVICE_ID : 3; /* Device IDs 3: DRV2605 4: DRV2604 5: DRV2604L 6: DRV2605L */
} Bits;
} DRVREG_STATUS;
typedef union DRVREG_MODE { /* register 0x01 */
uint8_t Byte;
struct {
uint8_t MODE :3; /* Mode setting */
uint8_t :3;
uint8_t STANDBY :1; /* 0:standby 1:ready */
} Bits;
uint8_t Byte;
struct {
uint8_t MODE : 3; /* Mode setting */
uint8_t : 3;
uint8_t STANDBY : 1; /* 0:standby 1:ready */
} Bits;
} DRVREG_MODE;
typedef union DRVREG_WAIT {
uint8_t Byte;
struct {
uint8_t WAIT_MODE :1; /* Set to 1 to interpret as wait for next 7 bits x10ms */
uint8_t WAIT_TIME :7;
} Bits;
uint8_t Byte;
struct {
uint8_t WAIT_MODE : 1; /* Set to 1 to interpret as wait for next 7 bits x10ms */
uint8_t WAIT_TIME : 7;
} Bits;
} DRVREG_WAIT;
typedef union DRVREG_FBR{ /* register 0x1A */
uint8_t Byte;
struct {
uint8_t BEMF_GAIN :2;
uint8_t LOOP_GAIN :2;
uint8_t BRAKE_FACTOR :3;
uint8_t ERM_LRA :1;
} Bits;
typedef union DRVREG_FBR { /* register 0x1A */
uint8_t Byte;
struct {
uint8_t BEMF_GAIN : 2;
uint8_t LOOP_GAIN : 2;
uint8_t BRAKE_FACTOR : 3;
uint8_t ERM_LRA : 1;
} Bits;
} DRVREG_FBR;
typedef union DRVREG_CTRL1{ /* register 0x1B */
uint8_t Byte;
struct {
uint8_t C1_DRIVE_TIME :5;
uint8_t C1_AC_COUPLE :1;
uint8_t :1;
uint8_t C1_STARTUP_BOOST :1;
} Bits;
typedef union DRVREG_CTRL1 { /* register 0x1B */
uint8_t Byte;
struct {
uint8_t C1_DRIVE_TIME : 5;
uint8_t C1_AC_COUPLE : 1;
uint8_t : 1;
uint8_t C1_STARTUP_BOOST : 1;
} Bits;
} DRVREG_CTRL1;
typedef union DRVREG_CTRL2{ /* register 0x1C */
uint8_t Byte;
struct {
uint8_t C2_IDISS_TIME :2;
uint8_t C2_BLANKING_TIME :2;
uint8_t C2_SAMPLE_TIME :2;
uint8_t C2_BRAKE_STAB :1;
uint8_t C2_BIDIR_INPUT :1;
} Bits;
typedef union DRVREG_CTRL2 { /* register 0x1C */
uint8_t Byte;
struct {
uint8_t C2_IDISS_TIME : 2;
uint8_t C2_BLANKING_TIME : 2;
uint8_t C2_SAMPLE_TIME : 2;
uint8_t C2_BRAKE_STAB : 1;
uint8_t C2_BIDIR_INPUT : 1;
} Bits;
} DRVREG_CTRL2;
typedef union DRVREG_CTRL3{ /* register 0x1D */
uint8_t Byte;
struct {
uint8_t C3_LRA_OPEN_LOOP :1;
uint8_t C3_N_PWM_ANALOG :1;
uint8_t C3_LRA_DRIVE_MODE :1;
uint8_t C3_DATA_FORMAT_RTO :1;
uint8_t C3_SUPPLY_COMP_DIS :1;
uint8_t C3_ERM_OPEN_LOOP :1;
uint8_t C3_NG_THRESH :2;
} Bits;
typedef union DRVREG_CTRL3 { /* register 0x1D */
uint8_t Byte;
struct {
uint8_t C3_LRA_OPEN_LOOP : 1;
uint8_t C3_N_PWM_ANALOG : 1;
uint8_t C3_LRA_DRIVE_MODE : 1;
uint8_t C3_DATA_FORMAT_RTO : 1;
uint8_t C3_SUPPLY_COMP_DIS : 1;
uint8_t C3_ERM_OPEN_LOOP : 1;
uint8_t C3_NG_THRESH : 2;
} Bits;
} DRVREG_CTRL3;
typedef union DRVREG_CTRL4{ /* register 0x1E */
uint8_t Byte;
struct {
uint8_t C4_OTP_PROGRAM :1;
uint8_t :1;
uint8_t C4_OTP_STATUS :1;
uint8_t :1;
uint8_t C4_AUTO_CAL_TIME :2;
uint8_t C4_ZC_DET_TIME :2;
} Bits;
typedef union DRVREG_CTRL4 { /* register 0x1E */
uint8_t Byte;
struct {
uint8_t C4_OTP_PROGRAM : 1;
uint8_t : 1;
uint8_t C4_OTP_STATUS : 1;
uint8_t : 1;
uint8_t C4_AUTO_CAL_TIME : 2;
uint8_t C4_ZC_DET_TIME : 2;
} Bits;
} DRVREG_CTRL4;
typedef union DRVREG_CTRL5{ /* register 0x1F */
uint8_t Byte;
struct {
uint8_t C5_IDISS_TIME :2;
uint8_t C5_BLANKING_TIME :2;
uint8_t C5_PLAYBACK_INTERVAL :1;
uint8_t C5_LRA_AUTO_OPEN_LOOP :1;
uint8_t C5_AUTO_OL_CNT :2;
} Bits;
typedef union DRVREG_CTRL5 { /* register 0x1F */
uint8_t Byte;
struct {
uint8_t C5_IDISS_TIME : 2;
uint8_t C5_BLANKING_TIME : 2;
uint8_t C5_PLAYBACK_INTERVAL : 1;
uint8_t C5_LRA_AUTO_OPEN_LOOP : 1;
uint8_t C5_AUTO_OL_CNT : 2;
} Bits;
} DRVREG_CTRL5;

View file

@ -19,230 +19,248 @@
#include "progmem.h"
#include "debug.h"
#ifdef DRV2605L
#include "DRV2605L.h"
# include "DRV2605L.h"
#endif
#ifdef SOLENOID_ENABLE
#include "solenoid.h"
# include "solenoid.h"
#endif
haptic_config_t haptic_config;
void haptic_init(void) {
debug_enable = 1; //Debug is ON!
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
haptic_config.raw = eeconfig_read_haptic();
if (haptic_config.mode < 1){
haptic_config.mode = 1;
}
if (!haptic_config.mode){
dprintf("No haptic config found in eeprom, setting default configs\n");
haptic_reset();
}
#ifdef SOLENOID_ENABLE
debug_enable = 1; // Debug is ON!
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
haptic_config.raw = eeconfig_read_haptic();
if (haptic_config.mode < 1) {
haptic_config.mode = 1;
}
if (!haptic_config.mode) {
dprintf("No haptic config found in eeprom, setting default configs\n");
haptic_reset();
}
#ifdef SOLENOID_ENABLE
solenoid_setup();
dprintf("Solenoid driver initialized\n");
#endif
#ifdef DRV2605L
#endif
#ifdef DRV2605L
DRV_init();
dprintf("DRV2605 driver initialized\n");
#endif
eeconfig_debug_haptic();
#endif
eeconfig_debug_haptic();
}
void haptic_task(void) {
#ifdef SOLENOID_ENABLE
solenoid_check();
#endif
#ifdef SOLENOID_ENABLE
solenoid_check();
#endif
}
void eeconfig_debug_haptic(void) {
dprintf("haptic_config eprom\n");
dprintf("haptic_config.enable = %d\n", haptic_config.enable);
dprintf("haptic_config.mode = %d\n", haptic_config.mode);
dprintf("haptic_config eprom\n");
dprintf("haptic_config.enable = %d\n", haptic_config.enable);
dprintf("haptic_config.mode = %d\n", haptic_config.mode);
}
void haptic_enable(void) {
haptic_config.enable = 1;
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
haptic_config.enable = 1;
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
}
void haptic_disable(void) {
haptic_config.enable = 0;
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
haptic_config.enable = 0;
xprintf("haptic_config.enable = %u\n", haptic_config.enable);
eeconfig_update_haptic(haptic_config.raw);
}
void haptic_toggle(void) {
if (haptic_config.enable) {
haptic_disable();
} else {
haptic_enable();
}
eeconfig_update_haptic(haptic_config.raw);
if (haptic_config.enable) {
haptic_disable();
} else {
haptic_enable();
}
eeconfig_update_haptic(haptic_config.raw);
}
void haptic_feedback_toggle(void){
haptic_config.feedback++;
if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX)
haptic_config.feedback = KEY_PRESS;
xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
eeconfig_update_haptic(haptic_config.raw);
void haptic_feedback_toggle(void) {
haptic_config.feedback++;
if (haptic_config.feedback >= HAPTIC_FEEDBACK_MAX) haptic_config.feedback = KEY_PRESS;
xprintf("haptic_config.feedback = %u\n", !haptic_config.feedback);
eeconfig_update_haptic(haptic_config.raw);
}
void haptic_buzz_toggle(void) {
bool buzz_stat = !haptic_config.buzz;
haptic_config.buzz = buzz_stat;
haptic_set_buzz(buzz_stat);
bool buzz_stat = !haptic_config.buzz;
haptic_config.buzz = buzz_stat;
haptic_set_buzz(buzz_stat);
}
void haptic_mode_increase(void) {
uint8_t mode = haptic_config.mode + 1;
#ifdef DRV2605L
if (haptic_config.mode >= drv_effect_max) {
mode = 1;
}
#endif
uint8_t mode = haptic_config.mode + 1;
#ifdef DRV2605L
if (haptic_config.mode >= drv_effect_max) {
mode = 1;
}
#endif
haptic_set_mode(mode);
}
void haptic_mode_decrease(void) {
uint8_t mode = haptic_config.mode -1;
#ifdef DRV2605L
if (haptic_config.mode < 1) {
mode = (drv_effect_max - 1);
}
#endif
haptic_set_mode(mode);
uint8_t mode = haptic_config.mode - 1;
#ifdef DRV2605L
if (haptic_config.mode < 1) {
mode = (drv_effect_max - 1);
}
#endif
haptic_set_mode(mode);
}
void haptic_dwell_increase(void) {
uint8_t dwell = haptic_config.dwell + 1;
#ifdef SOLENOID_ENABLE
if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
dwell = 1;
}
solenoid_set_dwell(dwell);
#endif
haptic_set_dwell(dwell);
uint8_t dwell = haptic_config.dwell + 1;
#ifdef SOLENOID_ENABLE
if (haptic_config.dwell >= SOLENOID_MAX_DWELL) {
dwell = 1;
}
solenoid_set_dwell(dwell);
#endif
haptic_set_dwell(dwell);
}
void haptic_dwell_decrease(void) {
uint8_t dwell = haptic_config.dwell -1;
#ifdef SOLENOID_ENABLE
if (haptic_config.dwell < SOLENOID_MIN_DWELL) {
dwell = SOLENOID_MAX_DWELL;
}
solenoid_set_dwell(dwell);
#endif
haptic_set_dwell(dwell);
uint8_t dwell = haptic_config.dwell - 1;
#ifdef SOLENOID_ENABLE
if (haptic_config.dwell < SOLENOID_MIN_DWELL) {
dwell = SOLENOID_MAX_DWELL;
}
solenoid_set_dwell(dwell);
#endif
haptic_set_dwell(dwell);
}
void haptic_reset(void){
haptic_config.enable = true;
uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
haptic_config.feedback = feedback;
#ifdef DRV2605L
uint8_t mode = HAPTIC_MODE_DEFAULT;
void haptic_reset(void) {
haptic_config.enable = true;
uint8_t feedback = HAPTIC_FEEDBACK_DEFAULT;
haptic_config.feedback = feedback;
#ifdef DRV2605L
uint8_t mode = HAPTIC_MODE_DEFAULT;
haptic_config.mode = mode;
#endif
#ifdef SOLENOID_ENABLE
uint8_t dwell = SOLENOID_DEFAULT_DWELL;
#endif
#ifdef SOLENOID_ENABLE
uint8_t dwell = SOLENOID_DEFAULT_DWELL;
haptic_config.dwell = dwell;
#endif
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
#endif
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
}
void haptic_set_feedback(uint8_t feedback) {
haptic_config.feedback = feedback;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
haptic_config.feedback = feedback;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.feedback = %u\n", haptic_config.feedback);
}
void haptic_set_mode(uint8_t mode) {
haptic_config.mode = mode;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
haptic_config.mode = mode;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
}
void haptic_set_buzz(uint8_t buzz) {
haptic_config.buzz = buzz;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
haptic_config.buzz = buzz;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.buzz = %u\n", haptic_config.buzz);
}
void haptic_set_dwell(uint8_t dwell) {
haptic_config.dwell = dwell;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
haptic_config.dwell = dwell;
eeconfig_update_haptic(haptic_config.raw);
xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
}
uint8_t haptic_get_mode(void) {
if (!haptic_config.enable){
return false;
}
return haptic_config.mode;
if (!haptic_config.enable) {
return false;
}
return haptic_config.mode;
}
uint8_t haptic_get_feedback(void) {
if (!haptic_config.enable){
return false;
}
return haptic_config.feedback;
if (!haptic_config.enable) {
return false;
}
return haptic_config.feedback;
}
uint8_t haptic_get_dwell(void) {
if (!haptic_config.enable){
return false;
}
return haptic_config.dwell;
if (!haptic_config.enable) {
return false;
}
return haptic_config.dwell;
}
void haptic_play(void) {
#ifdef DRV2605L
uint8_t play_eff = 0;
play_eff = haptic_config.mode;
DRV_pulse(play_eff);
#endif
#ifdef SOLENOID_ENABLE
solenoid_fire();
#endif
#ifdef DRV2605L
uint8_t play_eff = 0;
play_eff = haptic_config.mode;
DRV_pulse(play_eff);
#endif
#ifdef SOLENOID_ENABLE
solenoid_fire();
#endif
}
bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (keycode == HPT_ON && record->event.pressed) { haptic_enable(); }
if (keycode == HPT_OFF && record->event.pressed) { haptic_disable(); }
if (keycode == HPT_TOG && record->event.pressed) { haptic_toggle(); }
if (keycode == HPT_RST && record->event.pressed) { haptic_reset(); }
if (keycode == HPT_FBK && record->event.pressed) { haptic_feedback_toggle(); }
if (keycode == HPT_BUZ && record->event.pressed) { haptic_buzz_toggle(); }
if (keycode == HPT_MODI && record->event.pressed) { haptic_mode_increase(); }
if (keycode == HPT_MODD && record->event.pressed) { haptic_mode_decrease(); }
if (keycode == HPT_DWLI && record->event.pressed) { haptic_dwell_increase(); }
if (keycode == HPT_DWLD && record->event.pressed) { haptic_dwell_decrease(); }
if (haptic_config.enable) {
if ( record->event.pressed ) {
// keypress
if (haptic_config.feedback < 2) {
haptic_play();
}
} else {
//keyrelease
if (haptic_config.feedback > 0) {
haptic_play();
}
if (keycode == HPT_ON && record->event.pressed) {
haptic_enable();
}
}
return true;
if (keycode == HPT_OFF && record->event.pressed) {
haptic_disable();
}
if (keycode == HPT_TOG && record->event.pressed) {
haptic_toggle();
}
if (keycode == HPT_RST && record->event.pressed) {
haptic_reset();
}
if (keycode == HPT_FBK && record->event.pressed) {
haptic_feedback_toggle();
}
if (keycode == HPT_BUZ && record->event.pressed) {
haptic_buzz_toggle();
}
if (keycode == HPT_MODI && record->event.pressed) {
haptic_mode_increase();
}
if (keycode == HPT_MODD && record->event.pressed) {
haptic_mode_decrease();
}
if (keycode == HPT_DWLI && record->event.pressed) {
haptic_dwell_increase();
}
if (keycode == HPT_DWLD && record->event.pressed) {
haptic_dwell_decrease();
}
if (haptic_config.enable) {
if (record->event.pressed) {
// keypress
if (haptic_config.feedback < 2) {
haptic_play();
}
} else {
// keyrelease
if (haptic_config.feedback > 0) {
haptic_play();
}
}
}
return true;
}
void haptic_shutdown(void) {
#ifdef SOLENOID_ENABLE
solenoid_shutdown();
#endif
#ifdef SOLENOID_ENABLE
solenoid_shutdown();
#endif
}

View file

@ -20,63 +20,57 @@
#include <stdbool.h>
#include "quantum.h"
#ifdef DRV2605L
#include "DRV2605L.h"
# include "DRV2605L.h"
#endif
#ifndef HAPTIC_FEEDBACK_DEFAULT
#define HAPTIC_FEEDBACK_DEFAULT 0
# define HAPTIC_FEEDBACK_DEFAULT 0
#endif
#ifndef HAPTIC_MODE_DEFAULT
#define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
# define HAPTIC_MODE_DEFAULT DRV_MODE_DEFAULT
#endif
/* EEPROM config settings */
typedef union {
uint32_t raw;
struct {
bool enable :1;
uint8_t feedback :2;
uint8_t mode :7;
bool buzz :1;
uint8_t dwell :7;
uint16_t reserved :16;
};
uint32_t raw;
struct {
bool enable : 1;
uint8_t feedback : 2;
uint8_t mode : 7;
bool buzz : 1;
uint8_t dwell : 7;
uint16_t reserved : 16;
};
} haptic_config_t;
typedef enum HAPTIC_FEEDBACK{
KEY_PRESS,
KEY_PRESS_RELEASE,
KEY_RELEASE,
HAPTIC_FEEDBACK_MAX,
typedef enum HAPTIC_FEEDBACK {
KEY_PRESS,
KEY_PRESS_RELEASE,
KEY_RELEASE,
HAPTIC_FEEDBACK_MAX,
} HAPTIC_FEEDBACK;
bool process_haptic(uint16_t keycode, keyrecord_t *record);
void haptic_init(void);
void haptic_task(void);
void eeconfig_debug_haptic(void);
void haptic_enable(void);
void haptic_disable(void);
void haptic_toggle(void);
void haptic_feedback_toggle(void);
void haptic_mode_increase(void);
void haptic_mode_decrease(void);
void haptic_mode(uint8_t mode);
void haptic_reset(void);
void haptic_set_feedback(uint8_t feedback);
void haptic_set_mode(uint8_t mode);
void haptic_set_dwell(uint8_t dwell);
void haptic_set_buzz(uint8_t buzz);
void haptic_buzz_toggle(void);
bool process_haptic(uint16_t keycode, keyrecord_t *record);
void haptic_init(void);
void haptic_task(void);
void eeconfig_debug_haptic(void);
void haptic_enable(void);
void haptic_disable(void);
void haptic_toggle(void);
void haptic_feedback_toggle(void);
void haptic_mode_increase(void);
void haptic_mode_decrease(void);
void haptic_mode(uint8_t mode);
void haptic_reset(void);
void haptic_set_feedback(uint8_t feedback);
void haptic_set_mode(uint8_t mode);
void haptic_set_dwell(uint8_t dwell);
void haptic_set_buzz(uint8_t buzz);
void haptic_buzz_toggle(void);
uint8_t haptic_get_mode(void);
uint8_t haptic_get_feedback(void);
void haptic_dwell_increase(void);
void haptic_dwell_decrease(void);
void haptic_dwell_increase(void);
void haptic_dwell_decrease(void);
void haptic_play(void);
void haptic_shutdown(void);

View file

@ -19,91 +19,77 @@
#include "solenoid.h"
#include "haptic.h"
bool solenoid_on = false;
bool solenoid_buzzing = false;
uint16_t solenoid_start = 0;
uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL;
bool solenoid_on = false;
bool solenoid_buzzing = false;
uint16_t solenoid_start = 0;
uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL;
extern haptic_config_t haptic_config;
void solenoid_buzz_on(void) { haptic_set_buzz(1); }
void solenoid_buzz_on(void) {
haptic_set_buzz(1);
}
void solenoid_buzz_off(void) {
haptic_set_buzz(0);
}
void solenoid_set_buzz(int buzz) {
haptic_set_buzz(buzz);
}
void solenoid_buzz_off(void) { haptic_set_buzz(0); }
void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); }
void solenoid_dwell_minus(uint8_t solenoid_dwell) {
if (solenoid_dwell > 0) solenoid_dwell--;
if (solenoid_dwell > 0) solenoid_dwell--;
}
void solenoid_dwell_plus(uint8_t solenoid_dwell) {
if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
}
void solenoid_set_dwell(uint8_t dwell) {
solenoid_dwell = dwell;
}
void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; }
void solenoid_stop(void) {
writePinLow(SOLENOID_PIN);
solenoid_on = false;
solenoid_buzzing = false;
writePinLow(SOLENOID_PIN);
solenoid_on = false;
solenoid_buzzing = false;
}
void solenoid_fire(void) {
if (!haptic_config.buzz && solenoid_on) return;
if (haptic_config.buzz && solenoid_buzzing) return;
if (!haptic_config.buzz && solenoid_on) return;
if (haptic_config.buzz && solenoid_buzzing) return;
solenoid_on = true;
solenoid_buzzing = true;
solenoid_start = timer_read();
writePinHigh(SOLENOID_PIN);
solenoid_on = true;
solenoid_buzzing = true;
solenoid_start = timer_read();
writePinHigh(SOLENOID_PIN);
}
void solenoid_check(void) {
uint16_t elapsed = 0;
uint16_t elapsed = 0;
if (!solenoid_on) return;
if (!solenoid_on) return;
elapsed = timer_elapsed(solenoid_start);
elapsed = timer_elapsed(solenoid_start);
//Check if it's time to finish this solenoid click cycle
if (elapsed > solenoid_dwell) {
solenoid_stop();
return;
}
//Check whether to buzz the solenoid on and off
if (haptic_config.buzz) {
if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){
if (!solenoid_buzzing) {
solenoid_buzzing = true;
writePinHigh(SOLENOID_PIN);
}
// Check if it's time to finish this solenoid click cycle
if (elapsed > solenoid_dwell) {
solenoid_stop();
return;
}
else {
if (solenoid_buzzing) {
solenoid_buzzing = false;
writePinLow(SOLENOID_PIN);
}
// Check whether to buzz the solenoid on and off
if (haptic_config.buzz) {
if (elapsed / SOLENOID_MIN_DWELL % 2 == 0) {
if (!solenoid_buzzing) {
solenoid_buzzing = true;
writePinHigh(SOLENOID_PIN);
}
} else {
if (solenoid_buzzing) {
solenoid_buzzing = false;
writePinLow(SOLENOID_PIN);
}
}
}
}
}
void solenoid_setup(void) {
setPinOutput(SOLENOID_PIN);
solenoid_fire();
setPinOutput(SOLENOID_PIN);
solenoid_fire();
}
void solenoid_shutdown(void) {
writePinLow(SOLENOID_PIN);
}
void solenoid_shutdown(void) { writePinLow(SOLENOID_PIN); }

View file

@ -18,23 +18,23 @@
#pragma once
#ifndef SOLENOID_DEFAULT_DWELL
#define SOLENOID_DEFAULT_DWELL 12
# define SOLENOID_DEFAULT_DWELL 12
#endif
#ifndef SOLENOID_MAX_DWELL
#define SOLENOID_MAX_DWELL 100
# define SOLENOID_MAX_DWELL 100
#endif
#ifndef SOLENOID_MIN_DWELL
#define SOLENOID_MIN_DWELL 4
# define SOLENOID_MIN_DWELL 4
#endif
#ifndef SOLENOID_ACTIVE
#define SOLENOID_ACTIVE false
# define SOLENOID_ACTIVE false
#endif
#ifndef SOLENOID_PIN
#define SOLENOID_PIN F6
# define SOLENOID_PIN F6
#endif
void solenoid_buzz_on(void);