Add Support for USB programmable buttons (#12950)
This commit is contained in:
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "keycode.h"
|
||||
#include "keyboard.h"
|
||||
#include "mousekey.h"
|
||||
#include "programmable_button.h"
|
||||
#include "command.h"
|
||||
#include "led.h"
|
||||
#include "action_layer.h"
|
||||
@@ -988,6 +989,10 @@ void clear_keyboard_but_mods_and_keys() {
|
||||
mousekey_clear();
|
||||
mousekey_send();
|
||||
#endif
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
programmable_button_clear();
|
||||
programmable_button_send();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief Utilities for actions. (FIXME: Needs better description)
|
||||
|
@@ -76,6 +76,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
# include "process_joystick.h"
|
||||
#endif
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
# include "programmable_button.h"
|
||||
#endif
|
||||
#ifdef HD44780_ENABLE
|
||||
# include "hd44780.h"
|
||||
#endif
|
||||
@@ -542,6 +545,10 @@ MATRIX_LOOP_END:
|
||||
digitizer_task();
|
||||
#endif
|
||||
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
programmable_button_send();
|
||||
#endif
|
||||
|
||||
// update LED
|
||||
if (led_status != host_keyboard_leds()) {
|
||||
led_status = host_keyboard_leds();
|
||||
|
31
quantum/process_keycode/process_programmable_button.c
Normal file
31
quantum/process_keycode/process_programmable_button.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright 2021 Thomas Weißschuh <thomas@t-8ch.de>
|
||||
|
||||
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_programmable_button.h"
|
||||
#include "programmable_button.h"
|
||||
|
||||
bool process_programmable_button(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode >= PROGRAMMABLE_BUTTON_MIN && keycode <= PROGRAMMABLE_BUTTON_MAX) {
|
||||
uint8_t button = keycode - PROGRAMMABLE_BUTTON_MIN + 1;
|
||||
if (record->event.pressed) {
|
||||
programmable_button_on(button);
|
||||
} else {
|
||||
programmable_button_off(button);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
23
quantum/process_keycode/process_programmable_button.h
Normal file
23
quantum/process_keycode/process_programmable_button.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2021 Thomas Weißschuh <thomas@t-8ch.de>
|
||||
|
||||
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_programmable_button(uint16_t keycode, keyrecord_t *record);
|
37
quantum/programmable_button.c
Normal file
37
quantum/programmable_button.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2021 Thomas Weißschuh <thomas@t-8ch.de>
|
||||
|
||||
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 "programmable_button.h"
|
||||
#include "host.h"
|
||||
|
||||
#define REPORT_BIT(index) (((uint32_t)1) << (index - 1))
|
||||
|
||||
static uint32_t programmable_button_report = 0;
|
||||
|
||||
void programmable_button_clear(void) { programmable_button_report = 0; }
|
||||
|
||||
void programmable_button_send(void) { host_programmable_button_send(programmable_button_report); }
|
||||
|
||||
void programmable_button_on(uint8_t index) { programmable_button_report |= REPORT_BIT(index); }
|
||||
|
||||
void programmable_button_off(uint8_t index) { programmable_button_report &= ~REPORT_BIT(index); }
|
||||
|
||||
bool programmable_button_is_on(uint8_t index) { return !!(programmable_button_report & REPORT_BIT(index)); };
|
||||
|
||||
uint32_t programmable_button_get_report(void) { return programmable_button_report; };
|
||||
|
||||
void programmable_button_set_report(uint32_t report) { programmable_button_report = report; }
|
30
quantum/programmable_button.h
Normal file
30
quantum/programmable_button.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2021 Thomas Weißschuh <thomas@t-8ch.de>
|
||||
|
||||
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 <stdbool.h>
|
||||
#include "report.h"
|
||||
|
||||
void programmable_button_clear(void);
|
||||
void programmable_button_send(void);
|
||||
void programmable_button_on(uint8_t index);
|
||||
void programmable_button_off(uint8_t index);
|
||||
bool programmable_button_is_on(uint8_t index);
|
||||
uint32_t programmable_button_get_report(void);
|
||||
void programmable_button_set_report(uint32_t report);
|
@@ -295,6 +295,9 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
#endif
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
process_joystick(keycode, record) &&
|
||||
#endif
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
process_programmable_button(keycode, record) &&
|
||||
#endif
|
||||
true)) {
|
||||
return false;
|
||||
|
@@ -147,6 +147,10 @@ extern layer_state_t layer_state;
|
||||
# include "process_joystick.h"
|
||||
#endif
|
||||
|
||||
#ifdef PROGRAMMABLE_BUTTON_ENABLE
|
||||
# include "process_programmable_button.h"
|
||||
#endif
|
||||
|
||||
#ifdef GRAVE_ESC_ENABLE
|
||||
# include "process_grave_esc.h"
|
||||
#endif
|
||||
|
@@ -524,6 +524,40 @@ enum quantum_keycodes {
|
||||
// Additional magic key
|
||||
MAGIC_TOGGLE_GUI,
|
||||
|
||||
// Programmable Button
|
||||
PROGRAMMABLE_BUTTON_1,
|
||||
PROGRAMMABLE_BUTTON_2,
|
||||
PROGRAMMABLE_BUTTON_3,
|
||||
PROGRAMMABLE_BUTTON_4,
|
||||
PROGRAMMABLE_BUTTON_5,
|
||||
PROGRAMMABLE_BUTTON_6,
|
||||
PROGRAMMABLE_BUTTON_7,
|
||||
PROGRAMMABLE_BUTTON_8,
|
||||
PROGRAMMABLE_BUTTON_9,
|
||||
PROGRAMMABLE_BUTTON_10,
|
||||
PROGRAMMABLE_BUTTON_11,
|
||||
PROGRAMMABLE_BUTTON_12,
|
||||
PROGRAMMABLE_BUTTON_13,
|
||||
PROGRAMMABLE_BUTTON_14,
|
||||
PROGRAMMABLE_BUTTON_15,
|
||||
PROGRAMMABLE_BUTTON_16,
|
||||
PROGRAMMABLE_BUTTON_17,
|
||||
PROGRAMMABLE_BUTTON_18,
|
||||
PROGRAMMABLE_BUTTON_19,
|
||||
PROGRAMMABLE_BUTTON_20,
|
||||
PROGRAMMABLE_BUTTON_21,
|
||||
PROGRAMMABLE_BUTTON_22,
|
||||
PROGRAMMABLE_BUTTON_23,
|
||||
PROGRAMMABLE_BUTTON_24,
|
||||
PROGRAMMABLE_BUTTON_25,
|
||||
PROGRAMMABLE_BUTTON_26,
|
||||
PROGRAMMABLE_BUTTON_27,
|
||||
PROGRAMMABLE_BUTTON_28,
|
||||
PROGRAMMABLE_BUTTON_29,
|
||||
PROGRAMMABLE_BUTTON_30,
|
||||
PROGRAMMABLE_BUTTON_31,
|
||||
PROGRAMMABLE_BUTTON_32,
|
||||
|
||||
// Start of custom keycode range for keyboards and keymaps - always leave at the end
|
||||
SAFE_RANGE
|
||||
};
|
||||
@@ -854,3 +888,39 @@ enum quantum_keycodes {
|
||||
#define OS_TOGG ONESHOT_TOGGLE
|
||||
#define OS_ON ONESHOT_ENABLE
|
||||
#define OS_OFF ONESHOT_DISABLE
|
||||
|
||||
// Programmable Button aliases
|
||||
#define PB_1 PROGRAMMABLE_BUTTON_1
|
||||
#define PB_2 PROGRAMMABLE_BUTTON_2
|
||||
#define PB_3 PROGRAMMABLE_BUTTON_3
|
||||
#define PB_4 PROGRAMMABLE_BUTTON_4
|
||||
#define PB_5 PROGRAMMABLE_BUTTON_5
|
||||
#define PB_6 PROGRAMMABLE_BUTTON_6
|
||||
#define PB_7 PROGRAMMABLE_BUTTON_7
|
||||
#define PB_8 PROGRAMMABLE_BUTTON_8
|
||||
#define PB_9 PROGRAMMABLE_BUTTON_9
|
||||
#define PB_10 PROGRAMMABLE_BUTTON_10
|
||||
#define PB_11 PROGRAMMABLE_BUTTON_11
|
||||
#define PB_12 PROGRAMMABLE_BUTTON_12
|
||||
#define PB_13 PROGRAMMABLE_BUTTON_13
|
||||
#define PB_14 PROGRAMMABLE_BUTTON_14
|
||||
#define PB_15 PROGRAMMABLE_BUTTON_15
|
||||
#define PB_16 PROGRAMMABLE_BUTTON_16
|
||||
#define PB_17 PROGRAMMABLE_BUTTON_17
|
||||
#define PB_18 PROGRAMMABLE_BUTTON_18
|
||||
#define PB_19 PROGRAMMABLE_BUTTON_19
|
||||
#define PB_20 PROGRAMMABLE_BUTTON_20
|
||||
#define PB_21 PROGRAMMABLE_BUTTON_21
|
||||
#define PB_22 PROGRAMMABLE_BUTTON_22
|
||||
#define PB_23 PROGRAMMABLE_BUTTON_23
|
||||
#define PB_24 PROGRAMMABLE_BUTTON_24
|
||||
#define PB_25 PROGRAMMABLE_BUTTON_25
|
||||
#define PB_26 PROGRAMMABLE_BUTTON_26
|
||||
#define PB_27 PROGRAMMABLE_BUTTON_27
|
||||
#define PB_28 PROGRAMMABLE_BUTTON_28
|
||||
#define PB_29 PROGRAMMABLE_BUTTON_29
|
||||
#define PB_30 PROGRAMMABLE_BUTTON_30
|
||||
#define PB_31 PROGRAMMABLE_BUTTON_31
|
||||
#define PB_32 PROGRAMMABLE_BUTTON_32
|
||||
#define PROGRAMMABLE_BUTTON_MIN PROGRAMMABLE_BUTTON_1
|
||||
#define PROGRAMMABLE_BUTTON_MAX PROGRAMMABLE_BUTTON_32
|
||||
|
Reference in New Issue
Block a user