actually qwiic framework with hooks

qwiic_hud
Jack Humbert 6 years ago
parent d2856529ce
commit 636c5989de

@ -234,6 +234,8 @@ ifeq ($(strip $(LEADER_ENABLE)), yes)
OPT_DEFS += -DLEADER_ENABLE OPT_DEFS += -DLEADER_ENABLE
endif endif
include $(DRIVER_PATH)/qwiic/qwiic.mk
QUANTUM_SRC:= \ QUANTUM_SRC:= \
$(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/quantum.c \
$(QUANTUM_DIR)/keymap_common.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_vertical[2];
uint8_t joystiic_rx_button[1]; uint8_t joystiic_rx_button[1];
enum {
JOYSTIIC_LEFT,
JOYSTIIC_RIGHT,
JOYSTIIC_UP,
JOYSTIIC_DOWN,
JOYSTIIC_PRESS
};
bool joystiic_triggered[5] = {0}; bool joystiic_triggered[5] = {0};
void joystiic_init(void) { void joystiic_init(void) {
@ -54,27 +46,28 @@ void joystiic_update(uint16_t horizontal, uint16_t vertical, bool button) {
joystiic_update_user(horizontal, vertical, 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) { void joystiic_trigger(uint8_t trigger, bool active) {
joystiic_trigger_kb(trigger, active); joystiic_trigger_kb(trigger, active);
joystiic_trigger_user(trigger, active); joystiic_trigger_user(trigger, active);
} }
void joystiic_trigger_kb(uint8_t trigger, bool active) { __attribute__ ((weak))
switch (trigger) { void joystiic_trigger_kb(uint8_t trigger, bool active) { }
case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break;
}
}
void joystiic_trigger_user(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_task(void) { void joystiic_task(void) {
@ -90,29 +83,8 @@ void joystiic_task(void) {
joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1]; joystiic_horizontal = ((uint16_t)joystiic_rx_horizontal[0] << 8) | joystiic_rx_horizontal[1];
if (joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { joystiic_trigger_if_not(JOYSTIIC_LEFT, joystiic_horizontal > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
if (!joystiic_triggered[JOYSTIIC_LEFT]) { joystiic_trigger_if_not(JOYSTIIC_RIGHT, joystiic_horizontal < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
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);
}
}
// get vertical axis // get vertical axis
joystiic_tx[0] = JOYSTIIC_COMMAND_VERTICAL; 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]; joystiic_vertical = ((uint16_t)joystiic_rx_vertical[0] << 8) | joystiic_rx_vertical[1];
if (joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE)) { joystiic_trigger_if_not(JOYSTIIC_UP, joystiic_vertical > (JOYSTIIC_CENTER + JOYSTIIC_DEADZONE));
if (!joystiic_triggered[JOYSTIIC_UP]) { joystiic_trigger_if_not(JOYSTIIC_DOWN, joystiic_vertical < (JOYSTIIC_CENTER - JOYSTIIC_DEADZONE));
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);
}
}
// get button press // get button press
joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON; joystiic_tx[0] = JOYSTIIC_COMMAND_BUTTON;
@ -158,19 +109,9 @@ void joystiic_task(void) {
printf("error vert\n"); printf("error vert\n");
} }
joystiic_button = joystiic_rx_button[0]; joystiic_button = !joystiic_rx_button[0];
if (joystiic_button) { joystiic_trigger_if_not(JOYSTIIC_PRESS, 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_update(joystiic_horizontal, joystiic_vertical, joystiic_button); joystiic_update(joystiic_horizontal, joystiic_vertical, joystiic_button);

@ -15,7 +15,15 @@
*/ */
#pragma once #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_kb(uint16_t horizontal, uint16_t vertical, bool button);
void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button); void joystiic_update_user(uint16_t horizontal, uint16_t vertical, bool button);

@ -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
}

@ -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);

@ -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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "rev6.h" #include "rev6.h"
#include "qwiic/joystiic.h" #include "qwiic.h"
void matrix_init_kb(void) { void matrix_init_kb(void) {
matrix_init_user(); matrix_init_user();
joystiic_init();
} }
void matrix_scan_kb(void) { void matrix_scan_kb(void) {
matrix_scan_user(); 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 # project specific files
SRC = matrix.c qwiic/joystiic.c i2c_master.c SRC = matrix.c
LAYOUTS += ortho_4x12 LAYOUTS += ortho_4x12
## chip/board settings ## chip/board settings
@ -53,4 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover
CUSTOM_MATRIX = yes # Custom matrix file CUSTOM_MATRIX = yes # Custom matrix file
AUDIO_ENABLE = yes AUDIO_ENABLE = yes
RGBLIGHT_ENABLE = no RGBLIGHT_ENABLE = no
QWIIC_ENABLE += JOYSTIIC
# SERIAL_LINK_ENABLE = yes # SERIAL_LINK_ENABLE = yes

@ -72,6 +72,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef HD44780_ENABLE #ifdef HD44780_ENABLE
# include "hd44780.h" # include "hd44780.h"
#endif #endif
#ifdef QWIIC_ENABLE
# include "qwiic.h"
#endif
#ifdef MATRIX_HAS_GHOST #ifdef MATRIX_HAS_GHOST
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
@ -157,6 +160,9 @@ void keyboard_init(void) {
MCUCR |= _BV(JTD); MCUCR |= _BV(JTD);
#endif #endif
matrix_init(); matrix_init();
#ifdef QWIIC_ENABLE
qwiic_init();
#endif
#ifdef PS2_MOUSE_ENABLE #ifdef PS2_MOUSE_ENABLE
ps2_mouse_init(); ps2_mouse_init();
#endif #endif
@ -266,6 +272,10 @@ void keyboard_task(void)
MATRIX_LOOP_END: MATRIX_LOOP_END:
#ifdef QWIIC_ENABLE
qwiic_task();
#endif
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE
// mousekey repeat & acceleration // mousekey repeat & acceleration
mousekey_task(); mousekey_task();

Loading…
Cancel
Save