mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-10-01 22:40:11 +02:00
Merge remote-tracking branch 'origin/develop' into xap
This commit is contained in:
+51
-49
@@ -293,19 +293,56 @@ void process_record_handler(keyrecord_t *record) {
|
||||
process_action(record, action);
|
||||
}
|
||||
|
||||
#if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
|
||||
void register_button(bool pressed, enum mouse_buttons button) {
|
||||
# ifdef PS2_MOUSE_ENABLE
|
||||
tp_buttons = pressed ? tp_buttons | button : tp_buttons & ~button;
|
||||
/**
|
||||
* @brief handles all the messy mouse stuff
|
||||
*
|
||||
* Handles all the edgecases and special stuff that is needed for coexistense
|
||||
* of the multiple mouse subsystems.
|
||||
*
|
||||
* @param mouse_keycode[in] uint8_t mouse keycode
|
||||
* @param pressed[in] bool
|
||||
*/
|
||||
|
||||
void register_mouse(uint8_t mouse_keycode, bool pressed) {
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
// if mousekeys is enabled, let it do the brunt of the work
|
||||
if (pressed) {
|
||||
mousekey_on(mouse_keycode);
|
||||
} else {
|
||||
mousekey_off(mouse_keycode);
|
||||
}
|
||||
// should mousekeys send report, or does something else handle this?
|
||||
switch (mouse_keycode) {
|
||||
# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
|
||||
case KC_MS_BTN1 ... KC_MS_BTN8:
|
||||
// let pointing device handle the buttons
|
||||
// expand if/when it handles more of the code
|
||||
# if defined(POINTING_DEVICE_ENABLE)
|
||||
pointing_device_keycode_handler(mouse_keycode, pressed);
|
||||
# endif
|
||||
break;
|
||||
# endif
|
||||
# ifdef POINTING_DEVICE_ENABLE
|
||||
report_mouse_t currentReport = pointing_device_get_report();
|
||||
currentReport.buttons = pressed ? currentReport.buttons | button : currentReport.buttons & ~button;
|
||||
pointing_device_set_report(currentReport);
|
||||
# endif
|
||||
}
|
||||
default:
|
||||
mousekey_send();
|
||||
break;
|
||||
}
|
||||
#elif defined(POINTING_DEVICE_ENABLE)
|
||||
// if mousekeys isn't enabled, and pointing device is enabled, then
|
||||
// let pointing device do all the heavy lifting, then
|
||||
if IS_MOUSEKEY (mouse_keycode) {
|
||||
pointing_device_keycode_handler(mouse_keycode, pressed);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PS2_MOUSE_ENABLE
|
||||
// make sure that ps2 mouse has button report synced
|
||||
if (KC_MS_BTN1 <= mouse_keycode && mouse_keycode <= KC_MS_BTN3) {
|
||||
uint8_t tmp_button_msk = MOUSE_BTN_MASK(mouse_keycode - KC_MS_BTN1);
|
||||
tp_buttons = pressed ? tp_buttons | tmp_button_msk : tp_buttons & ~tmp_button_msk;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief Take an action and processes it.
|
||||
*
|
||||
* FIXME: Needs documentation.
|
||||
@@ -506,30 +543,10 @@ void process_action(keyrecord_t *record, action_t action) {
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
/* Mouse key */
|
||||
case ACT_MOUSEKEY:
|
||||
if (event.pressed) {
|
||||
mousekey_on(action.key.code);
|
||||
} else {
|
||||
mousekey_off(action.key.code);
|
||||
}
|
||||
switch (action.key.code) {
|
||||
# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
|
||||
# ifdef POINTING_DEVICE_ENABLE
|
||||
case KC_MS_BTN1 ... KC_MS_BTN8:
|
||||
# else
|
||||
case KC_MS_BTN1 ... KC_MS_BTN3:
|
||||
# endif
|
||||
register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1));
|
||||
break;
|
||||
# endif
|
||||
default:
|
||||
mousekey_send();
|
||||
break;
|
||||
}
|
||||
register_mouse(action.key.code, event.pressed);
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_ACTION_LAYER
|
||||
case ACT_LAYER:
|
||||
if (action.layer_bitop.on == 0) {
|
||||
@@ -913,16 +930,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
|
||||
host_consumer_send(KEYCODE2CONSUMER(code));
|
||||
}
|
||||
#endif
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
else if IS_MOUSEKEY (code) {
|
||||
mousekey_on(code);
|
||||
mousekey_send();
|
||||
register_mouse(code, true);
|
||||
}
|
||||
#elif defined(POINTING_DEVICE_ENABLE)
|
||||
else if IS_MOUSEKEY (code) {
|
||||
pointing_device_keycode_handler(code, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief Utilities for actions. (FIXME: Needs better description)
|
||||
@@ -976,17 +986,9 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
|
||||
host_system_send(0);
|
||||
} else if IS_CONSUMER (code) {
|
||||
host_consumer_send(0);
|
||||
} else if IS_MOUSEKEY (code) {
|
||||
register_mouse(code, false);
|
||||
}
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
else if IS_MOUSEKEY (code) {
|
||||
mousekey_off(code);
|
||||
mousekey_send();
|
||||
}
|
||||
#elif defined(POINTING_DEVICE_ENABLE)
|
||||
else if IS_MOUSEKEY (code) {
|
||||
pointing_device_keycode_handler(code, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief Tap a keycode with a delay.
|
||||
|
||||
+15
-14
@@ -201,7 +201,7 @@ void dynamic_keymap_reset(void) {
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int column = 0; column < MATRIX_COLS; column++) {
|
||||
if (layer < keymap_layer_count()) {
|
||||
dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
|
||||
dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
|
||||
} else {
|
||||
dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
|
||||
}
|
||||
@@ -210,8 +210,8 @@ void dynamic_keymap_reset(void) {
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
|
||||
if (layer < encodermap_layer_count()) {
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
|
||||
} else {
|
||||
dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
|
||||
dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
|
||||
@@ -250,21 +250,22 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
|
||||
}
|
||||
}
|
||||
|
||||
// This overrides the one in quantum/keymap_common.c
|
||||
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
|
||||
if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
|
||||
return dynamic_keymap_get_keycode(layer, key.row, key.col);
|
||||
uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
|
||||
if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && row < MATRIX_ROWS && column < MATRIX_COLS) {
|
||||
return dynamic_keymap_get_keycode(layer_num, row, column);
|
||||
}
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
|
||||
return dynamic_keymap_get_encoder(layer, key.col, true);
|
||||
} else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
|
||||
return dynamic_keymap_get_encoder(layer, key.col, false);
|
||||
}
|
||||
#endif // ENCODER_MAP_ENABLE
|
||||
return KC_NO;
|
||||
}
|
||||
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
|
||||
if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && encoder_idx < NUM_ENCODERS) {
|
||||
return dynamic_keymap_get_encoder(layer_num, encoder_idx, clockwise);
|
||||
}
|
||||
return KC_NO;
|
||||
}
|
||||
#endif // ENCODER_MAP_ENABLE
|
||||
|
||||
uint8_t dynamic_keymap_macro_get_count(void) {
|
||||
return DYNAMIC_KEYMAP_MACRO_COUNT;
|
||||
}
|
||||
|
||||
+95
-3
@@ -1,5 +1,24 @@
|
||||
/* Copyright 2022
|
||||
*
|
||||
* 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 "joystick.h"
|
||||
|
||||
#include "analog.h"
|
||||
#include "wait.h"
|
||||
|
||||
// clang-format off
|
||||
joystick_t joystick_status = {
|
||||
.buttons = {0},
|
||||
@@ -15,12 +34,13 @@ joystick_t joystick_status = {
|
||||
// array defining the reading of analog values for each axis
|
||||
__attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {};
|
||||
|
||||
// to be implemented in the hid protocol library
|
||||
void send_joystick_packet(joystick_t *joystick);
|
||||
__attribute__((weak)) void joystick_task(void) {
|
||||
joystick_read_axes();
|
||||
}
|
||||
|
||||
void joystick_flush(void) {
|
||||
if ((joystick_status.status & JS_UPDATED) > 0) {
|
||||
send_joystick_packet(&joystick_status);
|
||||
host_joystick_send(&joystick_status);
|
||||
joystick_status.status &= ~JS_UPDATED;
|
||||
}
|
||||
}
|
||||
@@ -36,3 +56,75 @@ void unregister_joystick_button(uint8_t button) {
|
||||
joystick_status.status |= JS_UPDATED;
|
||||
joystick_flush();
|
||||
}
|
||||
|
||||
int16_t joystick_read_axis(uint8_t axis) {
|
||||
// disable pull-up resistor
|
||||
writePinLow(joystick_axes[axis].input_pin);
|
||||
|
||||
// if pin was a pull-up input, we need to uncharge it by turning it low
|
||||
// before making it a low input
|
||||
setPinOutput(joystick_axes[axis].input_pin);
|
||||
|
||||
wait_us(10);
|
||||
|
||||
if (joystick_axes[axis].output_pin != JS_VIRTUAL_AXIS) {
|
||||
setPinOutput(joystick_axes[axis].output_pin);
|
||||
writePinHigh(joystick_axes[axis].output_pin);
|
||||
}
|
||||
|
||||
if (joystick_axes[axis].ground_pin != JS_VIRTUAL_AXIS) {
|
||||
setPinOutput(joystick_axes[axis].ground_pin);
|
||||
writePinLow(joystick_axes[axis].ground_pin);
|
||||
}
|
||||
|
||||
wait_us(10);
|
||||
|
||||
setPinInput(joystick_axes[axis].input_pin);
|
||||
|
||||
wait_us(10);
|
||||
|
||||
#if defined(ANALOG_JOYSTICK_ENABLE) && (defined(__AVR__) || defined(PROTOCOL_CHIBIOS))
|
||||
int16_t axis_val = analogReadPin(joystick_axes[axis].input_pin);
|
||||
#else
|
||||
// default to resting position
|
||||
int16_t axis_val = joystick_axes[axis].mid_digit;
|
||||
#endif
|
||||
|
||||
// test the converted value against the lower range
|
||||
int32_t ref = joystick_axes[axis].mid_digit;
|
||||
int32_t range = joystick_axes[axis].min_digit;
|
||||
int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref);
|
||||
|
||||
if (ranged_val > 0) {
|
||||
// the value is in the higher range
|
||||
range = joystick_axes[axis].max_digit;
|
||||
ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref);
|
||||
}
|
||||
|
||||
// clamp the result in the valid range
|
||||
ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val;
|
||||
ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val;
|
||||
|
||||
return ranged_val;
|
||||
}
|
||||
|
||||
void joystick_read_axes() {
|
||||
#if JOYSTICK_AXES_COUNT > 0
|
||||
for (int i = 0; i < JOYSTICK_AXES_COUNT; ++i) {
|
||||
if (joystick_axes[i].input_pin == JS_VIRTUAL_AXIS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
joystick_set_axis(i, joystick_read_axis(i));
|
||||
}
|
||||
|
||||
joystick_flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
void joystick_set_axis(uint8_t axis, int16_t value) {
|
||||
if (value != joystick_status.axes[axis]) {
|
||||
joystick_status.axes[axis] = value;
|
||||
joystick_status.status |= JS_UPDATED;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-1
@@ -1,3 +1,19 @@
|
||||
/* Copyright 2022
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
@@ -54,7 +70,10 @@ typedef struct {
|
||||
|
||||
extern joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT];
|
||||
|
||||
enum joystick_status { JS_INITIALIZED = 1, JS_UPDATED = 2 };
|
||||
enum joystick_status {
|
||||
JS_INITIALIZED = 1,
|
||||
JS_UPDATED,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
|
||||
@@ -65,7 +84,14 @@ typedef struct {
|
||||
|
||||
extern joystick_t joystick_status;
|
||||
|
||||
void joystick_task(void);
|
||||
void joystick_flush(void);
|
||||
|
||||
void register_joystick_button(uint8_t button);
|
||||
void unregister_joystick_button(uint8_t button);
|
||||
|
||||
int16_t joystick_read_axis(uint8_t axis);
|
||||
void joystick_read_axes(void);
|
||||
void joystick_set_axis(uint8_t axis, int16_t value);
|
||||
|
||||
void host_joystick_send(joystick_t *joystick);
|
||||
|
||||
+7
-13
@@ -106,12 +106,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# include "split_util.h"
|
||||
#endif
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
# include "outputselect.h"
|
||||
# ifdef BLUETOOTH_BLUEFRUIT_LE
|
||||
# include "bluefruit_le.h"
|
||||
# elif BLUETOOTH_RN42
|
||||
# include "rn42.h"
|
||||
# endif
|
||||
# include "bluetooth.h"
|
||||
#endif
|
||||
#ifdef CAPS_WORD_ENABLE
|
||||
# include "caps_word.h"
|
||||
@@ -175,12 +170,11 @@ uint32_t get_matrix_scan_rate(void) {
|
||||
#endif
|
||||
|
||||
#ifdef MATRIX_HAS_GHOST
|
||||
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) {
|
||||
static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) {
|
||||
matrix_row_t out = 0;
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||
// read each key in the row data and check if the keymap defines it as a real key
|
||||
if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1 << col))) {
|
||||
if (keycode_at_keymap_location(0, row, col) && (rowdata & (1 << col))) {
|
||||
// this creates new row data, if a key is defined in the keymap, it will be set here
|
||||
out |= 1 << col;
|
||||
}
|
||||
@@ -412,8 +406,8 @@ void keyboard_init(void) {
|
||||
// init after split init
|
||||
pointing_device_init();
|
||||
#endif
|
||||
#if defined(BLUETOOTH_RN42)
|
||||
rn42_init();
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
bluetooth_init();
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
|
||||
@@ -675,8 +669,8 @@ void keyboard_task(void) {
|
||||
programmable_button_send();
|
||||
#endif
|
||||
|
||||
#ifdef BLUETOOTH_BLUEFRUIT_LE
|
||||
bluefruit_le_task();
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
bluetooth_task();
|
||||
#endif
|
||||
|
||||
led_task();
|
||||
|
||||
@@ -33,8 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// translates key to keycode
|
||||
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
|
||||
|
||||
extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
// Ensure we have a forward declaration for the encoder map
|
||||
# include "encoder.h"
|
||||
|
||||
@@ -65,11 +65,9 @@ action_t action_for_keycode(uint16_t keycode) {
|
||||
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
|
||||
break;
|
||||
#endif
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
case KC_MS_UP ... KC_MS_ACCEL2:
|
||||
action.code = ACTION_MOUSEKEY(keycode);
|
||||
break;
|
||||
#endif
|
||||
case KC_TRANSPARENT:
|
||||
action.code = ACTION_TRANSPARENT;
|
||||
break;
|
||||
@@ -147,13 +145,13 @@ action_t action_for_keycode(uint16_t keycode) {
|
||||
// translates key to keycode
|
||||
__attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
|
||||
if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
|
||||
return pgm_read_word(&keymaps[layer][key.row][key.col]);
|
||||
return keycode_at_keymap_location(layer, key.row, key.col);
|
||||
}
|
||||
#ifdef ENCODER_MAP_ENABLE
|
||||
else if (key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
|
||||
return pgm_read_word(&encoder_map[layer][key.col][0]);
|
||||
return keycode_at_encodermap_location(layer, key.col, true);
|
||||
} else if (key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
|
||||
return pgm_read_word(&encoder_map[layer][key.col][1]);
|
||||
return keycode_at_encodermap_location(layer, key.col, false);
|
||||
}
|
||||
#endif // ENCODER_MAP_ENABLE
|
||||
return KC_NO;
|
||||
|
||||
@@ -19,6 +19,17 @@ uint8_t keymap_layer_count(void) {
|
||||
|
||||
_Static_assert(NUM_KEYMAP_LAYERS <= MAX_LAYER, "Number of keymap layers exceeds maximum set by LAYER_STATE_(8|16|32)BIT");
|
||||
|
||||
uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column) {
|
||||
if (layer_num < NUM_KEYMAP_LAYERS && row < MATRIX_ROWS && column < MATRIX_COLS) {
|
||||
return pgm_read_word(&keymaps[layer_num][row][column]);
|
||||
}
|
||||
return KC_NO;
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
|
||||
return keycode_at_keymap_location_raw(layer_num, row, column);
|
||||
}
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
# define NUM_ENCODERMAP_LAYERS ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (2) * sizeof(uint16_t))))
|
||||
@@ -29,4 +40,15 @@ uint8_t encodermap_layer_count(void) {
|
||||
|
||||
_Static_assert(NUM_KEYMAP_LAYERS == NUM_ENCODERMAP_LAYERS, "Number of encoder_map layers doesn't match the number of keymap layers");
|
||||
|
||||
uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
|
||||
if (layer_num < NUM_ENCODERMAP_LAYERS && encoder_idx < NUM_ENCODERS) {
|
||||
return pgm_read_word(&encoder_map[layer_num][encoder_idx][clockwise ? 0 : 1]);
|
||||
}
|
||||
return KC_NO;
|
||||
}
|
||||
|
||||
__attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
|
||||
return keycode_at_encodermap_location_raw(layer_num, encoder_idx, clockwise);
|
||||
}
|
||||
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
@@ -7,9 +7,19 @@
|
||||
// Get the number of layers defined in the keymap
|
||||
uint8_t keymap_layer_count(void);
|
||||
|
||||
// Get the keycode for the keymap location, stored in firmware rather than any other persistent storage
|
||||
uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column);
|
||||
// Get the keycode for the keymap location, potentially stored dynamically
|
||||
uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column);
|
||||
|
||||
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
// Get the number of layers defined in the encoder map
|
||||
uint8_t encodermap_layer_count(void);
|
||||
|
||||
// Get the keycode for the encoder mapping location, stored in firmware rather than any other persistent storage
|
||||
uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise);
|
||||
// Get the keycode for the encoder mapping location, potentially stored dynamically
|
||||
uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise);
|
||||
|
||||
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
#include "joystick.h"
|
||||
/* Copyright 2022
|
||||
*
|
||||
* 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 "process_joystick.h"
|
||||
|
||||
#include "analog.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "joystick.h"
|
||||
|
||||
bool process_joystick(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
@@ -18,132 +29,3 @@ bool process_joystick(uint16_t keycode, keyrecord_t *record) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
__attribute__((weak)) void joystick_task(void) {
|
||||
if (process_joystick_analogread()) {
|
||||
joystick_flush();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t savePinState(pin_t pin) {
|
||||
#ifdef __AVR__
|
||||
uint8_t pinNumber = pin & 0xF;
|
||||
return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1);
|
||||
#elif defined(PROTOCOL_CHIBIOS)
|
||||
/*
|
||||
The pin configuration is backed up in the following format :
|
||||
bit 15 9 8 7 6 5 4 3 2 1 0
|
||||
|unused|ODR|IDR|PUPDR|OSPEEDR|OTYPER|MODER|
|
||||
*/
|
||||
return ((PAL_PORT(pin)->MODER >> (2 * PAL_PAD(pin))) & 0x3) | (((PAL_PORT(pin)->OTYPER >> (1 * PAL_PAD(pin))) & 0x1) << 2) | (((PAL_PORT(pin)->OSPEEDR >> (2 * PAL_PAD(pin))) & 0x3) << 3) | (((PAL_PORT(pin)->PUPDR >> (2 * PAL_PAD(pin))) & 0x3) << 5) | (((PAL_PORT(pin)->IDR >> (1 * PAL_PAD(pin))) & 0x1) << 7) | (((PAL_PORT(pin)->ODR >> (1 * PAL_PAD(pin))) & 0x1) << 8);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void restorePinState(pin_t pin, uint16_t restoreState) {
|
||||
#if defined(PROTOCOL_LUFA)
|
||||
uint8_t pinNumber = pin & 0xF;
|
||||
PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber);
|
||||
DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber);
|
||||
#elif defined(PROTOCOL_CHIBIOS)
|
||||
PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3 << (2 * PAL_PAD(pin)))) | (restoreState & 0x3) << (2 * PAL_PAD(pin));
|
||||
PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 2) & 0x1) << (1 * PAL_PAD(pin));
|
||||
PAL_PORT(pin)->OSPEEDR = (PAL_PORT(pin)->OSPEEDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 3) & 0x3) << (2 * PAL_PAD(pin));
|
||||
PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 5) & 0x3) << (2 * PAL_PAD(pin));
|
||||
PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 7) & 0x1) << (1 * PAL_PAD(pin));
|
||||
PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 8) & 0x1) << (1 * PAL_PAD(pin));
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((weak)) bool process_joystick_analogread() {
|
||||
return process_joystick_analogread_quantum();
|
||||
}
|
||||
|
||||
bool process_joystick_analogread_quantum() {
|
||||
#if JOYSTICK_AXES_COUNT > 0
|
||||
for (int axis_index = 0; axis_index < JOYSTICK_AXES_COUNT; ++axis_index) {
|
||||
if (joystick_axes[axis_index].input_pin == JS_VIRTUAL_AXIS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// save previous input pin status as well
|
||||
uint16_t inputSavedState = savePinState(joystick_axes[axis_index].input_pin);
|
||||
|
||||
// disable pull-up resistor
|
||||
writePinLow(joystick_axes[axis_index].input_pin);
|
||||
|
||||
// if pin was a pull-up input, we need to uncharge it by turning it low
|
||||
// before making it a low input
|
||||
setPinOutput(joystick_axes[axis_index].input_pin);
|
||||
|
||||
wait_us(10);
|
||||
|
||||
// save and apply output pin status
|
||||
uint16_t outputSavedState = 0;
|
||||
if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
|
||||
// save previous output pin status
|
||||
outputSavedState = savePinState(joystick_axes[axis_index].output_pin);
|
||||
|
||||
setPinOutput(joystick_axes[axis_index].output_pin);
|
||||
writePinHigh(joystick_axes[axis_index].output_pin);
|
||||
}
|
||||
|
||||
uint16_t groundSavedState = 0;
|
||||
if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
|
||||
// save previous output pin status
|
||||
groundSavedState = savePinState(joystick_axes[axis_index].ground_pin);
|
||||
|
||||
setPinOutput(joystick_axes[axis_index].ground_pin);
|
||||
writePinLow(joystick_axes[axis_index].ground_pin);
|
||||
}
|
||||
|
||||
wait_us(10);
|
||||
|
||||
setPinInput(joystick_axes[axis_index].input_pin);
|
||||
|
||||
wait_us(10);
|
||||
|
||||
# if defined(ANALOG_JOYSTICK_ENABLE) && (defined(__AVR__) || defined(PROTOCOL_CHIBIOS))
|
||||
int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin);
|
||||
# else
|
||||
// default to resting position
|
||||
int16_t axis_val = joystick_axes[axis_index].mid_digit;
|
||||
# endif
|
||||
|
||||
// test the converted value against the lower range
|
||||
int32_t ref = joystick_axes[axis_index].mid_digit;
|
||||
int32_t range = joystick_axes[axis_index].min_digit;
|
||||
int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref);
|
||||
|
||||
if (ranged_val > 0) {
|
||||
// the value is in the higher range
|
||||
range = joystick_axes[axis_index].max_digit;
|
||||
ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref);
|
||||
}
|
||||
|
||||
// clamp the result in the valid range
|
||||
ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val;
|
||||
ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val;
|
||||
|
||||
if (ranged_val != joystick_status.axes[axis_index]) {
|
||||
joystick_status.axes[axis_index] = ranged_val;
|
||||
joystick_status.status |= JS_UPDATED;
|
||||
}
|
||||
|
||||
// restore output, ground and input status
|
||||
if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
|
||||
restorePinState(joystick_axes[axis_index].output_pin, outputSavedState);
|
||||
}
|
||||
if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
|
||||
restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState);
|
||||
}
|
||||
|
||||
restorePinState(joystick_axes[axis_index].input_pin, inputSavedState);
|
||||
}
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
/* Copyright 2022
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include "quantum.h"
|
||||
|
||||
bool process_joystick(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
void joystick_task(void);
|
||||
|
||||
bool process_joystick_analogread(void);
|
||||
bool process_joystick_analogread_quantum(void);
|
||||
|
||||
@@ -523,10 +523,19 @@ void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) {
|
||||
|
||||
void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
|
||||
if (rgblight_config.enable) {
|
||||
#ifdef RGBLIGHT_SPLIT
|
||||
if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
|
||||
RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
|
||||
}
|
||||
#endif
|
||||
rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
|
||||
if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
|
||||
// same static color
|
||||
LED_TYPE tmp_led;
|
||||
#ifdef RGBLIGHT_LAYERS_RETAIN_VAL
|
||||
// needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val
|
||||
rgblight_config.val = val;
|
||||
#endif
|
||||
sethsv(hue, sat, val, &tmp_led);
|
||||
rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
|
||||
} else {
|
||||
@@ -568,15 +577,14 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
|
||||
dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
|
||||
sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
}
|
||||
# ifdef RGBLIGHT_LAYERS_RETAIN_VAL
|
||||
// needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val
|
||||
rgblight_config.val = val;
|
||||
# endif
|
||||
rgblight_set();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef RGBLIGHT_SPLIT
|
||||
if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
|
||||
RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
|
||||
}
|
||||
#endif
|
||||
rgblight_config.hue = hue;
|
||||
rgblight_config.sat = sat;
|
||||
rgblight_config.val = val;
|
||||
|
||||
Reference in New Issue
Block a user