actually qwiic framework with hooks
This commit is contained in:
parent
d2856529ce
commit
636c5989de
9 changed files with 120 additions and 84 deletions
|
@ -234,6 +234,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 \
|
||||
|
|
|
@ -34,14 +34,6 @@ uint8_t joystiic_rx_horizontal[2];
|
|||
uint8_t joystiic_rx_vertical[2];
|
||||
uint8_t joystiic_rx_button[1];
|
||||
|
||||
enum {
|
||||
JOYSTIIC_LEFT,
|
||||
JOYSTIIC_RIGHT,
|
||||
JOYSTIIC_UP,
|
||||
JOYSTIIC_DOWN,
|
||||
JOYSTIIC_PRESS
|
||||
};
|
||||
|
||||
bool joystiic_triggered[5] = {0};
|
||||
|
||||
void joystiic_init(void) {
|
||||
|
@ -54,29 +46,30 @@ void joystiic_update(uint16_t horizontal, uint16_t vertical, bool button) {
|
|||
joystiic_update_user(horizontal, vertical, button);
|
||||
}
|
||||
|
||||
void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) {
|
||||
__attribute__ ((weak))
|
||||
void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button) { }
|
||||
|
||||
}
|
||||
|
||||
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) {
|
||||
|
||||
}
|
||||
__attribute__ ((weak))
|
||||
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button) { }
|
||||
|
||||
void joystiic_trigger(uint8_t trigger, bool active) {
|
||||
joystiic_trigger_kb(trigger, active);
|
||||
joystiic_trigger_user(trigger, active);
|
||||
}
|
||||
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active) {
|
||||
switch (trigger) {
|
||||
case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break;
|
||||
__attribute__ ((weak))
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active) { }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystiic_trigger_user(uint8_t trigger, bool active) { }
|
||||
|
||||
void joystiic_trigger_if_not(uint8_t trigger, bool active) {
|
||||
if (joystiic_triggered[trigger] != active) {
|
||||
joystiic_triggered[trigger] = active;
|
||||
joystiic_trigger(trigger, active);
|
||||
}
|
||||
}
|
||||
|
||||
void joystiic_trigger_user(uint8_t trigger, bool active) {
|
||||
|
||||
}
|
||||
|
||||
void joystiic_task(void) {
|
||||
// get horizontal axis
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_HORIZONTAL;
|
||||
|
@ -90,29 +83,8 @@ void joystiic_task(void) {
|
|||
|
||||
joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1];
|
||||
|
||||
if (joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) {
|
||||
if (!joystiic_triggered[JOYSTIIC_LEFT]) {
|
||||
joystiic_triggered[JOYSTIIC_LEFT] = true;
|
||||
joystiic_trigger(JOYSTIIC_LEFT, true);
|
||||
}
|
||||
} else {
|
||||
if (joystiic_triggered[JOYSTIIC_LEFT]) {
|
||||
joystiic_triggered[JOYSTIIC_LEFT] = false;
|
||||
joystiic_trigger(JOYSTIIC_LEFT, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) {
|
||||
if (!joystiic_triggered[JOYSTIIC_RIGHT]) {
|
||||
joystiic_triggered[JOYSTIIC_RIGHT] = true;
|
||||
joystiic_trigger(JOYSTIIC_RIGHT, true);
|
||||
}
|
||||
} else {
|
||||
if (joystiic_triggered[JOYSTIIC_RIGHT]) {
|
||||
joystiic_triggered[JOYSTIIC_RIGHT] = false;
|
||||
joystiic_trigger(JOYSTIIC_RIGHT, false);
|
||||
}
|
||||
}
|
||||
joystiic_trigger_if_not(JOYSTIIC_LEFT, joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
|
||||
joystiic_trigger_if_not(JOYSTIIC_RIGHT, joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
|
||||
|
||||
// get vertical axis
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_VERTICAL;
|
||||
|
@ -125,29 +97,8 @@ void joystiic_task(void) {
|
|||
|
||||
joystiic_vertical = ((uint16_t)joystiic_rx_vertical[0] << 8) | joystiic_rx_vertical[1];
|
||||
|
||||
if (joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) {
|
||||
if (!joystiic_triggered[JOYSTIIC_UP]) {
|
||||
joystiic_triggered[JOYSTIIC_UP] = true;
|
||||
joystiic_trigger(JOYSTIIC_UP, true);
|
||||
}
|
||||
} else {
|
||||
if (joystiic_triggered[JOYSTIIC_UP]) {
|
||||
joystiic_triggered[JOYSTIIC_UP] = false;
|
||||
joystiic_trigger(JOYSTIIC_UP, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE)) {
|
||||
if (!joystiic_triggered[JOYSTIIC_DOWN]) {
|
||||
joystiic_triggered[JOYSTIIC_DOWN] = true;
|
||||
joystiic_trigger(JOYSTIIC_DOWN, true);
|
||||
}
|
||||
} else {
|
||||
if (joystiic_triggered[JOYSTIIC_DOWN]) {
|
||||
joystiic_triggered[JOYSTIIC_DOWN] = false;
|
||||
joystiic_trigger(JOYSTIIC_DOWN, false);
|
||||
}
|
||||
}
|
||||
joystiic_trigger_if_not(JOYSTIIC_UP, joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
|
||||
joystiic_trigger_if_not(JOYSTIIC_DOWN, joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
|
||||
|
||||
// get button press
|
||||
joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON;
|
||||
|
@ -158,19 +109,9 @@ void joystiic_task(void) {
|
|||
printf("error vert\n");
|
||||
}
|
||||
|
||||
joystiic_button = joystiic_rx_button[0];
|
||||
joystiic_button = !joystiic_rx_button[0];
|
||||
|
||||
if (joystiic_button) {
|
||||
if (!joystiic_triggered[JOYSTIIC_PRESS]) {
|
||||
joystiic_triggered[JOYSTIIC_PRESS] = true;
|
||||
joystiic_trigger(JOYSTIIC_PRESS, true);
|
||||
}
|
||||
} else {
|
||||
if (joystiic_triggered[JOYSTIIC_PRESS]) {
|
||||
joystiic_triggered[JOYSTIIC_PRESS] = false;
|
||||
joystiic_trigger(JOYSTIIC_PRESS, false);
|
||||
}
|
||||
}
|
||||
joystiic_trigger_if_not(JOYSTIIC_PRESS, joystiic_button);
|
||||
|
||||
joystiic_update(joystiic_horizontal, joystiic_vertical, joystiic_button);
|
||||
|
||||
|
|
|
@ -15,7 +15,15 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "i2c_master.h"
|
||||
#include "qwiic.h"
|
||||
|
||||
enum {
|
||||
JOYSTIIC_LEFT,
|
||||
JOYSTIIC_RIGHT,
|
||||
JOYSTIIC_UP,
|
||||
JOYSTIIC_DOWN,
|
||||
JOYSTIIC_PRESS
|
||||
};
|
||||
|
||||
void joystiic_update_kb(uint16_t horizontal, uint16_t vertical, bool button);
|
||||
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button);
|
||||
|
|
28
drivers/qwiic/qwiic.c
Normal file
28
drivers/qwiic/qwiic.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* 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 "qwiic.h"
|
||||
|
||||
void qwiic_init(void) {
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
joystiic_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void qwiic_task(void) {
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
joystiic_task();
|
||||
#endif
|
||||
}
|
25
drivers/qwiic/qwiic.h
Normal file
25
drivers/qwiic/qwiic.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "i2c_master.h"
|
||||
|
||||
#ifdef QWIIC_JOYSTIIC_ENABLE
|
||||
#include "joystiic.h"
|
||||
#endif
|
||||
|
||||
void qwiic_init(void);
|
||||
void qwiic_task(void);
|
13
drivers/qwiic/qwiic.mk
Normal file
13
drivers/qwiic/qwiic.mk
Normal file
|
@ -0,0 +1,13 @@
|
|||
ifneq ($(strip $(QWIIC_ENABLE)),)
|
||||
COMMON_VPATH += $(DRIVER_PATH)/qwiic
|
||||
OPT_DEFS += -DQWIIC_ENABLE
|
||||
SRC += qwiic.c
|
||||
ifeq ($(filter "i2c_master.c", $(SRC)),)
|
||||
SRC += i2c_master.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(filter JOYSTIIC, $(QWIIC_ENABLE)),)
|
||||
OPT_DEFS += -DQWIIC_JOYSTIIC_ENABLE
|
||||
SRC += joystiic.c
|
||||
endif
|
|
@ -14,14 +14,22 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "rev6.h"
|
||||
#include "qwiic/joystiic.h"
|
||||
#include "qwiic.h"
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
matrix_init_user();
|
||||
joystiic_init();
|
||||
}
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
matrix_scan_user();
|
||||
joystiic_task();
|
||||
}
|
||||
|
||||
void joystiic_trigger_kb(uint8_t trigger, bool active) {
|
||||
switch (trigger) {
|
||||
case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break;
|
||||
case JOYSTIIC_RIGHT: active ? register_code(KC_R) : unregister_code(KC_R); break;
|
||||
case JOYSTIIC_UP: active ? register_code(KC_U) : unregister_code(KC_U); break;
|
||||
case JOYSTIIC_DOWN: active ? register_code(KC_D) : unregister_code(KC_D); break;
|
||||
case JOYSTIIC_PRESS: active ? register_code(KC_P) : unregister_code(KC_P); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# project specific files
|
||||
SRC = matrix.c qwiic/joystiic.c i2c_master.c
|
||||
SRC = matrix.c
|
||||
LAYOUTS += ortho_4x12
|
||||
|
||||
## chip/board settings
|
||||
|
@ -53,4 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover
|
|||
CUSTOM_MATRIX = yes # Custom matrix file
|
||||
AUDIO_ENABLE = yes
|
||||
RGBLIGHT_ENABLE = no
|
||||
QWIIC_ENABLE += JOYSTIIC
|
||||
# SERIAL_LINK_ENABLE = yes
|
||||
|
|
|
@ -72,6 +72,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifdef HD44780_ENABLE
|
||||
# include "hd44780.h"
|
||||
#endif
|
||||
#ifdef QWIIC_ENABLE
|
||||
# include "qwiic.h"
|
||||
#endif
|
||||
|
||||
#ifdef MATRIX_HAS_GHOST
|
||||
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
|
@ -157,6 +160,9 @@ void keyboard_init(void) {
|
|||
MCUCR |= _BV(JTD);
|
||||
#endif
|
||||
matrix_init();
|
||||
#ifdef QWIIC_ENABLE
|
||||
qwiic_init();
|
||||
#endif
|
||||
#ifdef PS2_MOUSE_ENABLE
|
||||
ps2_mouse_init();
|
||||
#endif
|
||||
|
@ -266,6 +272,10 @@ void keyboard_task(void)
|
|||
|
||||
MATRIX_LOOP_END:
|
||||
|
||||
#ifdef QWIIC_ENABLE
|
||||
qwiic_task();
|
||||
#endif
|
||||
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
// mousekey repeat & acceleration
|
||||
mousekey_task();
|
||||
|
|
Loading…
Reference in a new issue