Permalink
Browse files

adding Hadron v3 keyboard, QWIIC devices support, haptic feedback sup…

…port (#4462)

* add initial support for hadron ver3

* add initial support for hadron ver3

* pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display

* initial work on OLED using qwiic driver

* early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality

* moved oled defines to config.h and added ifndef to micro_oled driver

* WORKING :D - note, still work in progress to get the start location correct on the 128x32 display.

* added equation to automatically calculate display offset based on screen width

* adding time-out timer to oled display

* changed read lock staus via read_led_state

* lock indications fixes

* Added scroll lock indication to oled

* add support for DRV2605 haptic driver

* Improve readabiity of DRV2605 driver.
-added typedef for waveform library
-added unions for registers

* Update keyboards/hadron/ver2/keymaps/default/config.h

Co-Authored-By: ishtob <ishtob@gmail.com>

* Update keyboards/hadron/ver2/keymaps/default/config.h

Co-Authored-By: ishtob <ishtob@gmail.com>

* Update keyboards/hadron/ver2/keymaps/default/config.h

Co-Authored-By: ishtob <ishtob@gmail.com>

* Update keyboards/hadron/ver2/keymaps/default/config.h

Co-Authored-By: ishtob <ishtob@gmail.com>

* Fixes for PR

* PR fixes

* fix old persistent layer function to use new set_single_persistent_default_layer

* fix issues with changing makefile defines that broken per-key haptic pulse

* Comment fixes

* Add definable parameter and auto-calibration based on motor choice
  • Loading branch information...
ishtob authored and drashna committed Dec 4, 2018
1 parent 4bb28d2 commit 4099536c0e7a099b181a80e483b4b95f389b5a7e
Showing with 5,532 additions and 296 deletions.
  1. +9 −0 common_features.mk
  2. +8 −4 drivers/arm/i2c_master.c
  3. +1 −0 drivers/arm/i2c_master.h
  4. +129 −0 drivers/haptic/DRV2605L.c
  5. +394 −0 drivers/haptic/DRV2605L.h
  6. +691 −0 drivers/qwiic/micro_oled.c
  7. +134 −0 drivers/qwiic/micro_oled.h
  8. +31 −0 drivers/qwiic/qwiic.c
  9. +28 −0 drivers/qwiic/qwiic.h
  10. +18 −0 drivers/qwiic/qwiic.mk
  11. +288 −0 drivers/qwiic/util/font5x7.h
  12. +127 −0 drivers/qwiic/util/font8x16.h
  13. +5 −5 keyboards/hadron/config.h
  14. +0 −24 keyboards/hadron/hadron.c
  15. +3 −1 keyboards/hadron/hadron.h
  16. +0 −20 keyboards/hadron/keymaps/default/config.h
  17. +0 −24 keyboards/hadron/keymaps/default/rules.mk
  18. +0 −20 keyboards/hadron/keymaps/side_numpad/config.h
  19. +2 −2 keyboards/hadron/readme.md
  20. +0 −73 keyboards/hadron/rules.mk
  21. +11 −0 keyboards/hadron/ver2/config.h
  22. +9 −0 keyboards/hadron/ver2/keymaps/default/config.h
  23. +29 −74 keyboards/hadron/{ → ver2}/keymaps/default/keymap.c
  24. 0 keyboards/hadron/{ → ver2}/keymaps/default/readme.md
  25. 0 keyboards/hadron/{ → ver2}/keymaps/readme.md
  26. +8 −0 keyboards/hadron/ver2/keymaps/side_numpad/config.h
  27. +1 −19 keyboards/hadron/{ → ver2}/keymaps/side_numpad/keymap.c
  28. 0 keyboards/hadron/{ → ver2}/keymaps/side_numpad/readme.md
  29. 0 keyboards/hadron/{ → ver2}/keymaps/side_numpad/rules.mk
  30. +76 −1 keyboards/hadron/ver2/rules.mk
  31. +26 −1 keyboards/hadron/ver2/ver2.c
  32. +126 −0 keyboards/hadron/ver3/boards/GENERIC_STM32_F303XC/board.c
  33. +1,187 −0 keyboards/hadron/ver3/boards/GENERIC_STM32_F303XC/board.h
  34. +5 −0 keyboards/hadron/ver3/boards/GENERIC_STM32_F303XC/board.mk
  35. +7 −0 keyboards/hadron/ver3/bootloader_defs.h
  36. +520 −0 keyboards/hadron/ver3/chconf.h
  37. +192 −0 keyboards/hadron/ver3/config.h
  38. +388 −0 keyboards/hadron/ver3/halconf.h
  39. +1 −0 keyboards/hadron/ver3/keymaps/default/config.h
  40. +295 −0 keyboards/hadron/ver3/keymaps/default/keymap.c
  41. +2 −0 keyboards/hadron/ver3/keymaps/default/readme.md
  42. +23 −0 keyboards/hadron/ver3/keymaps/readme.md
  43. +195 −0 keyboards/hadron/ver3/matrix.c
  44. +257 −0 keyboards/hadron/ver3/mcuconf.h
  45. +21 −0 keyboards/hadron/ver3/rev3.h
  46. +57 −0 keyboards/hadron/ver3/rules.mk
  47. +196 −0 keyboards/hadron/ver3/ver3.c
  48. +21 −0 keyboards/hadron/ver3/ver3.h
  49. +0 −25 keyboards/helix/rev1/keymaps/OLED_sample/rules.mk
  50. +1 −3 tmk_core/common/action_layer.h
  51. +10 −0 tmk_core/common/keyboard.c
@@ -225,6 +225,13 @@ ifeq ($(strip $(ENCODER_ENABLE)), yes)
OPT_DEFS += -DENCODER_ENABLE
endif
ifeq ($(strip $(HAPTIC_ENABLE)), DRV2605L)
COMMON_VPATH += $(DRIVER_PATH)/haptic
SRC += DRV2605L.c
SRC += i2c_master.c
OPT_DEFS += -DDRV2605L
endif
ifeq ($(strip $(HD44780_ENABLE)), yes)
SRC += drivers/avr/hd44780.c
OPT_DEFS += -DHD44780_ENABLE
@@ -240,6 +247,8 @@ ifeq ($(strip $(LEADER_ENABLE)), yes)
OPT_DEFS += -DLEADER_ENABLE
endif
include $(DRIVER_PATH)/qwiic/qwiic.mk
QUANTUM_SRC:= \
$(QUANTUM_DIR)/quantum.c \
$(QUANTUM_DIR)/keymap_common.c \
@@ -32,7 +32,7 @@
static uint8_t i2c_address;
// This configures the I2C clock to 400Mhz assuming a 72Mhz clock
// This configures the I2C clock to 400khz assuming a 72Mhz clock
// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
static const I2CConfig i2cconfig = {
STM32_TIMINGR_PRESC(15U) |
@@ -45,10 +45,14 @@ static const I2CConfig i2cconfig = {
__attribute__ ((weak))
void i2c_init(void)
{
setPinInput(B6); // Try releasing special pins for a short time
setPinInput(B7);
chThdSleepMilliseconds(10);
//palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT);
// Try releasing special pins for a short time
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT);
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
chThdSleepMilliseconds(10);
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
@@ -34,6 +34,7 @@ void i2c_init(void);
uint8_t i2c_start(uint8_t address);
uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length);
uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_readReg(uint8_t devaddr, uint8_t* regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_stop(uint16_t timeout);
@@ -0,0 +1,129 @@
/* Copyright 2018 ishtob
* Driver for DRV2605L written for QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DRV2605L.h"
#include "print.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
uint8_t DRV2605L_transfer_buffer[20];
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);
}
uint8_t DRV_read(uint8_t regaddress) {
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];
return DRV2605L_read_register;
}
void DRV_init(void)
{
i2c_init();
i2c_start(DRV2605L_BASE_ADDRESS);
/* 0x07 sets DRV2605 into calibration mode */
DRV_write(DRV_MODE,0x07);
// 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;
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;
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;
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;
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;
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);
//start autocalibration
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);
/* 0x06: LRA library */
DRV_write(DRV_WAVEFORM_SEQ_1, 0x01);
/* 0xB9: LRA, 4x brake factor, medium gain, 7.5x back EMF
* 0x39: ERM, 4x brake factor, medium gain, 1.365x back EMF */
/* TODO: setup auto-calibration as part of initiation */
}
void DRV_pulse(uint8_t sequence)
{
DRV_write(DRV_GO, 0x00);
DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
DRV_write(DRV_GO, 0x01);
}
Oops, something went wrong.

0 comments on commit 4099536

Please sign in to comment.