1
0
Fork 0

Remove sysex API (#14723)

This commit is contained in:
Ryan 2021-10-06 19:34:46 +11:00 committed by GitHub
parent a94c6fa620
commit d8f0c8783a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 7 additions and 425 deletions

View file

@ -46,14 +46,6 @@ else ifeq ($(strip $(DEBUG_MATRIX_SCAN_RATE_ENABLE)), api)
OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE
endif endif
ifeq ($(strip $(API_SYSEX_ENABLE)), yes)
OPT_DEFS += -DAPI_SYSEX_ENABLE
OPT_DEFS += -DAPI_ENABLE
MIDI_ENABLE=yes
SRC += $(QUANTUM_DIR)/api/api_sysex.c
SRC += $(QUANTUM_DIR)/api.c
endif
ifeq ($(strip $(COMMAND_ENABLE)), yes) ifeq ($(strip $(COMMAND_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/command.c SRC += $(QUANTUM_DIR)/command.c
OPT_DEFS += -DCOMMAND_ENABLE OPT_DEFS += -DCOMMAND_ENABLE

View file

@ -36,7 +36,7 @@ Size after:
can retry, loading that one can retry, loading that one
- Some of the options you might specify in your keyboard's Makefile - Some of the options you might specify in your keyboard's Makefile
consume extra memory; watch out for BOOTMAGIC_ENABLE, consume extra memory; watch out for BOOTMAGIC_ENABLE,
MOUSEKEY_ENABLE, EXTRAKEY_ENABLE, CONSOLE_ENABLE, API_SYSEX_ENABLE MOUSEKEY_ENABLE, EXTRAKEY_ENABLE, CONSOLE_ENABLE
- DFU tools do /not/ allow you to write into the bootloader (unless - DFU tools do /not/ allow you to write into the bootloader (unless
you throw in an extra fruit salad of options), so there is little risk you throw in an extra fruit salad of options), so there is little risk
there. there.

View file

@ -125,10 +125,6 @@ This allows you output audio on the C6 pin (needs abstracting). See the [audio p
Use this to debug changes to variable values, see the [tracing variables](unit_testing.md#tracing-variables) section of the Unit Testing page for more information. Use this to debug changes to variable values, see the [tracing variables](unit_testing.md#tracing-variables) section of the Unit Testing page for more information.
`API_SYSEX_ENABLE`
This enables using the Quantum SYSEX API to send strings (somewhere?)
`KEY_LOCK_ENABLE` `KEY_LOCK_ENABLE`
This enables [key lock](feature_key_lock.md). This enables [key lock](feature_key_lock.md).

View file

@ -85,11 +85,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
eeconfig_init(); eeconfig_init();
} }
break; break;
case 2:
if (record->event.pressed) { // For resetting EEPROM
api_send_unicode(0x0CA0);
}
break;
} }
return MACRO_NONE; return MACRO_NONE;
}; };

View file

@ -1,182 +0,0 @@
/* Copyright 2016 Jack Humbert
*
* 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 "api.h"
#include "quantum.h"
void dword_to_bytes(uint32_t dword, uint8_t* bytes) {
bytes[0] = (dword >> 24) & 0xFF;
bytes[1] = (dword >> 16) & 0xFF;
bytes[2] = (dword >> 8) & 0xFF;
bytes[3] = (dword >> 0) & 0xFF;
}
uint32_t bytes_to_dword(uint8_t* bytes, uint8_t index) { return ((uint32_t)bytes[index + 0] << 24) | ((uint32_t)bytes[index + 1] << 16) | ((uint32_t)bytes[index + 2] << 8) | (uint32_t)bytes[index + 3]; }
__attribute__((weak)) bool process_api_quantum(uint8_t length, uint8_t* data) { return process_api_keyboard(length, data); }
__attribute__((weak)) bool process_api_keyboard(uint8_t length, uint8_t* data) { return process_api_user(length, data); }
__attribute__((weak)) bool process_api_user(uint8_t length, uint8_t* data) { return true; }
void process_api(uint16_t length, uint8_t* data) {
// SEND_STRING("\nRX: ");
// for (uint8_t i = 0; i < length; i++) {
// send_byte(data[i]);
// SEND_STRING(" ");
// }
if (!process_api_quantum(length, data)) return;
switch (data[0]) {
case MT_SET_DATA:
switch (data[1]) {
case DT_DEFAULT_LAYER: {
eeconfig_update_default_layer(data[2]);
default_layer_set((uint32_t)(data[2]));
break;
}
case DT_KEYMAP_OPTIONS: {
eeconfig_update_keymap(data[2]);
break;
}
case DT_RGBLIGHT: {
#ifdef RGBLIGHT_ENABLE
uint32_t rgblight = bytes_to_dword(data, 2);
eeconfig_update_rgblight(rgblight);
#endif
break;
}
}
case MT_GET_DATA:
switch (data[1]) {
case DT_HANDSHAKE: {
MT_GET_DATA_ACK(DT_HANDSHAKE, NULL, 0);
break;
}
case DT_DEBUG: {
uint8_t debug_bytes[1] = {eeprom_read_byte(EECONFIG_DEBUG)};
MT_GET_DATA_ACK(DT_DEBUG, debug_bytes, 1);
break;
}
case DT_DEFAULT_LAYER: {
uint8_t default_bytes[1] = {eeprom_read_byte(EECONFIG_DEFAULT_LAYER)};
MT_GET_DATA_ACK(DT_DEFAULT_LAYER, default_bytes, 1);
break;
}
case DT_CURRENT_LAYER: {
uint8_t layer_state_bytes[4];
dword_to_bytes(layer_state, layer_state_bytes);
MT_GET_DATA_ACK(DT_CURRENT_LAYER, layer_state_bytes, 4);
break;
}
case DT_AUDIO: {
#ifdef AUDIO_ENABLE
uint8_t audio_bytes[1] = {eeprom_read_byte(EECONFIG_AUDIO)};
MT_GET_DATA_ACK(DT_AUDIO, audio_bytes, 1);
#else
MT_GET_DATA_ACK(DT_AUDIO, NULL, 0);
#endif
break;
}
case DT_BACKLIGHT: {
#ifdef BACKLIGHT_ENABLE
uint8_t backlight_bytes[1] = {eeprom_read_byte(EECONFIG_BACKLIGHT)};
MT_GET_DATA_ACK(DT_BACKLIGHT, backlight_bytes, 1);
#else
MT_GET_DATA_ACK(DT_BACKLIGHT, NULL, 0);
#endif
break;
}
case DT_RGBLIGHT: {
#ifdef RGBLIGHT_ENABLE
uint8_t rgblight_bytes[4];
dword_to_bytes(eeconfig_read_rgblight(), rgblight_bytes);
MT_GET_DATA_ACK(DT_RGBLIGHT, rgblight_bytes, 4);
#else
MT_GET_DATA_ACK(DT_RGBLIGHT, NULL, 0);
#endif
break;
}
case DT_KEYMAP_OPTIONS: {
uint8_t keymap_bytes[1] = {eeconfig_read_keymap()};
MT_GET_DATA_ACK(DT_KEYMAP_OPTIONS, keymap_bytes, 1);
break;
}
case DT_KEYMAP_SIZE: {
uint8_t keymap_size[2] = {MATRIX_ROWS, MATRIX_COLS};
MT_GET_DATA_ACK(DT_KEYMAP_SIZE, keymap_size, 2);
break;
}
// This may be too much
// case DT_KEYMAP: {
// uint8_t keymap_data[MATRIX_ROWS * MATRIX_COLS * 4 + 3];
// keymap_data[0] = data[2];
// keymap_data[1] = MATRIX_ROWS;
// keymap_data[2] = MATRIX_COLS;
// for (int i = 0; i < MATRIX_ROWS; i++) {
// for (int j = 0; j < MATRIX_COLS; j++) {
// keymap_data[3 + (i*MATRIX_COLS*2) + (j*2)] = pgm_read_word(&keymaps[data[2]][i][j]) >> 8;
// keymap_data[3 + (i*MATRIX_COLS*2) + (j*2) + 1] = pgm_read_word(&keymaps[data[2]][i][j]) & 0xFF;
// }
// }
// MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, MATRIX_ROWS * MATRIX_COLS * 4 + 3);
// // uint8_t keymap_data[5];
// // keymap_data[0] = data[2];
// // keymap_data[1] = data[3];
// // keymap_data[2] = data[4];
// // keymap_data[3] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) >> 8;
// // keymap_data[4] = pgm_read_word(&keymaps[data[2]][data[3]][data[4]]) & 0xFF;
// // MT_GET_DATA_ACK(DT_KEYMAP, keymap_data, 5);
// break;
// }
default:
break;
}
break;
case MT_SET_DATA_ACK:
case MT_GET_DATA_ACK:
break;
case MT_SEND_DATA:
break;
case MT_SEND_DATA_ACK:
break;
case MT_EXE_ACTION:
break;
case MT_EXE_ACTION_ACK:
break;
case MT_TYPE_ERROR:
break;
default:; // command not recognised
SEND_BYTES(MT_TYPE_ERROR, DT_NONE, data, length);
break;
// #ifdef RGBLIGHT_ENABLE
// case 0x27: ; // RGB LED functions
// switch (*data++) {
// case 0x00: ; // Update HSV
// rgblight_sethsv((data[0] << 8 | data[1]) % 360, data[2], data[3]);
// break;
// case 0x01: ; // Update RGB
// break;
// case 0x02: ; // Update mode
// rgblight_mode(data[0]);
// break;
// }
// break;
// #endif
}
}

View file

@ -1,55 +0,0 @@
/* Copyright 2016 Jack Humbert
*
* 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
#ifdef __AVR__
# include "lufa.h"
#endif
enum MESSAGE_TYPE {
MT_GET_DATA = 0x10, // Get data from keyboard
MT_GET_DATA_ACK = 0x11, // returned data to process (ACK)
MT_SET_DATA = 0x20, // Set data on keyboard
MT_SET_DATA_ACK = 0x21, // returned data to confirm (ACK)
MT_SEND_DATA = 0x30, // Sending data/action from keyboard
MT_SEND_DATA_ACK = 0x31, // returned data/action confirmation (ACK)
MT_EXE_ACTION = 0x40, // executing actions on keyboard
MT_EXE_ACTION_ACK = 0x41, // return confirmation/value (ACK)
MT_TYPE_ERROR = 0x80 // type not recognised (ACK)
};
enum DATA_TYPE { DT_NONE = 0x00, DT_HANDSHAKE, DT_DEFAULT_LAYER, DT_CURRENT_LAYER, DT_KEYMAP_OPTIONS, DT_BACKLIGHT, DT_RGBLIGHT, DT_UNICODE, DT_DEBUG, DT_AUDIO, DT_QUANTUM_ACTION, DT_KEYBOARD_ACTION, DT_USER_ACTION, DT_KEYMAP_SIZE, DT_KEYMAP };
void dword_to_bytes(uint32_t dword, uint8_t* bytes);
uint32_t bytes_to_dword(uint8_t* bytes, uint8_t index);
#define MT_GET_DATA(data_type, data, length) SEND_BYTES(MT_GET_DATA, data_type, data, length)
#define MT_GET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_GET_DATA_ACK, data_type, data, length)
#define MT_SET_DATA(data_type, data, length) SEND_BYTES(MT_SET_DATA, data_type, data, length)
#define MT_SET_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SET_DATA_ACK, data_type, data, length)
#define MT_SEND_DATA(data_type, data, length) SEND_BYTES(MT_SEND_DATA, data_type, data, length)
#define MT_SEND_DATA_ACK(data_type, data, length) SEND_BYTES(MT_SEND_DATA_ACK, data_type, data, length)
#define MT_EXE_ACTION(data_type, data, length) SEND_BYTES(MT_EXE_ACTION, data_type, data, length)
#define MT_EXE_ACTION_ACK(data_type, data, length) SEND_BYTES(MT_EXE_ACTION_ACK, data_type, data, length)
void process_api(uint16_t length, uint8_t* data);
__attribute__((weak)) bool process_api_quantum(uint8_t length, uint8_t* data);
__attribute__((weak)) bool process_api_keyboard(uint8_t length, uint8_t* data);
__attribute__((weak)) bool process_api_user(uint8_t length, uint8_t* data);

View file

@ -1,72 +0,0 @@
/* Copyright 2016 Jack Humbert, Fred Sundvik
*
* 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 "api_sysex.h"
#include "sysex_tools.h"
#include "print.h"
#include "qmk_midi.h"
void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t* bytes, uint16_t length) {
// SEND_STRING("\nTX: ");
// for (uint8_t i = 0; i < length; i++) {
// send_byte(bytes[i]);
// SEND_STRING(" ");
// }
if (length > API_SYSEX_MAX_SIZE) {
xprintf("Sysex msg too big %d %d %d", message_type, data_type, length);
return;
}
// The buffer size required is calculated as the following
// API_SYSEX_MAX_SIZE is the maximum length
// In addition to that we have a two byte message header consisting of the message_type and data_type
// This has to be encoded with an additional overhead of one byte for every starting 7 bytes
// We just add one extra byte in case it's not divisible by 7
// Then we have an unencoded header consisting of 4 bytes
// Plus a one byte terminator
const unsigned message_header = 2;
const unsigned unencoded_message = API_SYSEX_MAX_SIZE + message_header;
const unsigned encoding_overhead = unencoded_message / 7 + 1;
const unsigned encoded_size = unencoded_message + encoding_overhead;
const unsigned unencoded_header = 4;
const unsigned terminator = 1;
const unsigned buffer_size = encoded_size + unencoded_header + terminator;
uint8_t buffer[encoded_size + unencoded_header + terminator];
// The unencoded header
buffer[0] = 0xF0;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;
// We copy the message to the end of the array, this way we can do an inplace encoding, using the same
// buffer for both input and output
const unsigned message_size = length + message_header;
uint8_t* unencoded_start = buffer + buffer_size - message_size;
uint8_t* ptr = unencoded_start;
*(ptr++) = message_type;
*(ptr++) = data_type;
memcpy(ptr, bytes, length);
unsigned encoded_length = sysex_encode(buffer + unencoded_header, unencoded_start, message_size);
unsigned final_size = unencoded_header + encoded_length + terminator;
buffer[final_size - 1] = 0xF7;
midi_send_array(&midi_device, final_size, buffer);
// SEND_STRING("\nTD: ");
// for (uint8_t i = 0; i < encoded_length + 5; i++) {
// send_byte(buffer[i]);
// SEND_STRING(" ");
// }
}

View file

@ -1,25 +0,0 @@
/* Copyright 2016 Jack Humbert
*
* 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 "api.h"
#define API_SYSEX_MAX_SIZE 32
void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t* bytes, uint16_t length);
#define SEND_BYTES(mt, dt, b, l) send_bytes_sysex(mt, dt, b, l)

View file

@ -25,10 +25,6 @@
# include "backlight.h" # include "backlight.h"
#endif #endif
#ifdef API_ENABLE
# include "api.h"
#endif
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
# include "process_midi.h" # include "process_midi.h"
#endif #endif
@ -145,12 +141,13 @@ void reset_keyboard(void) {
/* Convert record into usable keycode via the contained event. */ /* Convert record into usable keycode via the contained event. */
uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
#ifdef COMBO_ENABLE #ifdef COMBO_ENABLE
if (record->keycode) { return record->keycode; } if (record->keycode) {
return record->keycode;
}
#endif #endif
return get_event_keycode(record->event, update_layer_cache); return get_event_keycode(record->event, update_layer_cache);
} }
/* Convert event into usable keycode. Checks the layer cache to ensure that it /* Convert event into usable keycode. Checks the layer cache to ensure that it
* retains the correct keycode after a layer change, if the key is still pressed. * retains the correct keycode after a layer change, if the key is still pressed.
* "update_layer_cache" is to ensure that it only updates the layer cache when * "update_layer_cache" is to ensure that it only updates the layer cache when
@ -468,14 +465,6 @@ void matrix_scan_quantum() {
# include "hd44780.h" # include "hd44780.h"
#endif #endif
void api_send_unicode(uint32_t unicode) {
#ifdef API_ENABLE
uint8_t chunk[4];
dword_to_bytes(unicode, chunk);
MT_SEND_DATA(DT_UNICODE, chunk, 5);
#endif
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Override these functions in your keymap file to play different tunes on // Override these functions in your keymap file to play different tunes on
// different events such as startup and bootloader jump // different events such as startup and bootloader jump

View file

@ -237,5 +237,3 @@ void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led); void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state); bool led_update_user(led_t led_state);
bool led_update_kb(led_t led_state); bool led_update_kb(led_t led_state);
void api_send_unicode(uint32_t unicode);

View file

@ -40,7 +40,6 @@ OTHER_OPTION_NAMES = \
UCIS_ENABLE \ UCIS_ENABLE \
UNICODEMAP_ENABLE \ UNICODEMAP_ENABLE \
UNICODE_COMMON \ UNICODE_COMMON \
API_SYSEX_ENABLE \
AUTO_SHIFT_ENABLE \ AUTO_SHIFT_ENABLE \
AUTO_SHIFT_MODIFIERS \ AUTO_SHIFT_MODIFIERS \
COMBO_ENABLE \ COMBO_ENABLE \

View file

@ -56,14 +56,3 @@ extern host_driver_t lufa_driver;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#ifdef API_ENABLE
# include "api.h"
#endif
#ifdef API_SYSEX_ENABLE
# include "api_sysex.h"
// Allocate space for encoding overhead.
// The header and terminator are not stored to save a few bytes of precious ram
# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
#endif

View file

@ -4,9 +4,6 @@
#include "midi.h" #include "midi.h"
#include "usb_descriptor.h" #include "usb_descriptor.h"
#include "process_midi.h" #include "process_midi.h"
#if API_SYSEX_ENABLE
# include "api_sysex.h"
#endif
/******************************************************************************* /*******************************************************************************
* MIDI * MIDI
@ -124,41 +121,6 @@ static void cc_callback(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t v
// midi_send_cc(device, (chan + 1) % 16, num, val); // midi_send_cc(device, (chan + 1) % 16, num, val);
} }
#ifdef API_SYSEX_ENABLE
uint8_t midi_buffer[MIDI_SYSEX_BUFFER] = {0};
static void sysex_callback(MidiDevice* device, uint16_t start, uint8_t length, uint8_t* data) {
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
// Don't store the header
int16_t pos = start - 4;
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
if (pos >= 0) {
if (*data == 0xF7) {
// SEND_STRING("\nRD: ");
// for (uint8_t i = 0; i < start + place + 1; i++){
// send_byte(midi_buffer[i]);
// SEND_STRING(" ");
// }
const unsigned decoded_length = sysex_decoded_length(pos);
uint8_t decoded[API_SYSEX_MAX_SIZE];
sysex_decode(decoded, midi_buffer, pos);
process_api(decoded_length, decoded);
return;
} else if (pos >= MIDI_SYSEX_BUFFER) {
return;
}
midi_buffer[pos] = *data;
}
// SEND_STRING(" ");
data++;
pos++;
}
}
#endif
void midi_init(void); void midi_init(void);
void setup_midi(void) { void setup_midi(void) {
@ -170,7 +132,4 @@ void setup_midi(void) {
midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
midi_register_fallthrough_callback(&midi_device, fallthrough_callback); midi_register_fallthrough_callback(&midi_device, fallthrough_callback);
midi_register_cc_callback(&midi_device, cc_callback); midi_register_cc_callback(&midi_device, cc_callback);
#ifdef API_SYSEX_ENABLE
midi_register_sysex_callback(&midi_device, sysex_callback);
#endif
} }

View file

@ -25,7 +25,6 @@ UCIS_ENABLE = no
LTO_ENABLE = yes LTO_ENABLE = yes
# https://beta.docs.qmk.fm/developing-qmk/qmk-reference/getting_started_make_guide#rules-mk-options # https://beta.docs.qmk.fm/developing-qmk/qmk-reference/getting_started_make_guide#rules-mk-options
API_SYSEX_ENABLE = no
AUDIO_ENABLE = no AUDIO_ENABLE = no
BOOTMAGIC_ENABLE = no BOOTMAGIC_ENABLE = no
COMMAND_ENABLE = no COMMAND_ENABLE = no