Skip to content

Commit c202211

Browse files
QMK for BLE Micro Pro v0.3.0
- works with bootloader v0.3.0 and newer revisions - New features: - New predefined custom keycode - BLE_SEL, USB_SEL, xKANA, xEISU, SAVE_EE, DEL_EE - Extended keycode - LTE: Layer Tap Extended - TLT: Tri Layer Tap - TDD: Tap Dance Double-tap - TDH: Tap Dance Hold - New matrix structure - LPME-IO: matrix scanner using IO expander - duplex: Duplex matrix (tentative)
1 parent 2ae534f commit c202211

28 files changed

+2072
-394
lines changed

keyboards/ble_micro_pro/keymaps/default/keymap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
#include QMK_KEYBOARD_H
1717
#include "bmp.h"
18+
#include "bmp_custom_keycode.h"
1819
#include "keycode_str_converter.h"
1920

2021
// Defines the keycodes used by our macros in process_record_user

keyboards/ble_micro_pro/ld/nrf52840_ao.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0xba000
99
/* RAM (rwx) : ORIGIN = 0x2000BC70, LENGTH = 0x34390 */
10-
RAM (rwx) : ORIGIN = 0x20016000, LENGTH = 0x2A000
10+
RAM (rwx) : ORIGIN = 0x20018000, LENGTH = 0x28000
1111
}
1212

1313
SECTIONS

quantum/template/base_nrf/keymaps/default/keymap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
#include QMK_KEYBOARD_H
1717
#include "bmp.h"
18+
#include "bmp_custom_keycode.h"
1819
#include "keycode_str_converter.h"
1920

2021
// Defines the keycodes used by our macros in process_record_user

tmk_core/protocol/nrf.mk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ PROTOCOL_DIR = protocol
22
NRF_DIR = $(PROTOCOL_DIR)/nrf
33

44
SRC += $(NRF_DIR)/matrix.c \
5-
$(NRF_DIR)/io_expander.c \
5+
$(NRF_DIR)/matrix_basic.c \
6+
$(NRF_DIR)/matrix_lpme.c \
7+
$(NRF_DIR)/matrix_duplex.c \
8+
$(NRF_DIR)/lpme.c \
69

710
SRC += \
811
$(NRF_DIR)/main_master.c \
@@ -16,6 +19,8 @@ NRF_DIR = $(PROTOCOL_DIR)/nrf
1619
$(NRF_DIR)/keycode_str_converter.c \
1720
$(NRF_DIR)/config_file_util.c \
1821
$(NRF_DIR)/bmp.c \
22+
$(NRF_DIR)/bmp_extended_keycode_converter.c \
23+
$(NRF_DIR)/bmp_process_extended_keycode.c \
1924

2025
VPATH += $(TMK_PATH)/$(NRF_DIR)/microshell/core
2126
VPATH += $(TMK_PATH)/$(NRF_DIR)/microshell/util

tmk_core/protocol/nrf/bmp.c

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
#include "bmp.h"
33
#include "bmp_encoder.h"
4+
#include "bmp_custom_keycode.h"
5+
#include "bmp_process_extended_keycode.h"
6+
#include "keycode_str_converter.h"
47

58
#include <stdint.h>
69
#include "quantum.h"
@@ -78,6 +81,12 @@
7881
#endif
7982

8083

84+
void bmp_action_exec(keyevent_t event)
85+
{
86+
bmp_action_exec_impl(event);
87+
action_exec(event);
88+
}
89+
8190
static int sleep_enter_counter = -1;
8291

8392
/** \brief Keyboard task: Do keyboard routine jobs
@@ -108,6 +117,8 @@ void bmp_keyboard_task(void)
108117
matrix_scan();
109118
#endif
110119

120+
// bmp_check_timeout_extended_keycode();
121+
111122
#ifdef BMP_ENCODER_ENABLE
112123
bmp_encoder_read();
113124
#endif
@@ -126,7 +137,7 @@ void bmp_keyboard_task(void)
126137
if (debug_matrix) matrix_print();
127138
for (uint8_t c = 0; c < config->matrix.cols; c++) {
128139
if (matrix_change & ((matrix_row_t)1<<c)) {
129-
action_exec((keyevent_t){
140+
bmp_action_exec((keyevent_t){
130141
.key = (keypos_t){ .row = r, .col = c },
131142
.pressed = (matrix_row & ((matrix_row_t)1<<c)),
132143
.time = (timer_read() | 1) /* time should not be 0 */
@@ -149,7 +160,7 @@ void bmp_keyboard_task(void)
149160
// we can get here with some keys processed now.
150161
if (!keys_processed)
151162
#endif
152-
action_exec(TICK);
163+
bmp_action_exec(TICK);
153164

154165
MATRIX_LOOP_END:
155166

@@ -239,6 +250,9 @@ char keymap_string[10*1024];
239250
bmp_qmk_config_t bmp_qmk_config;
240251
char qmk_config_string[1024];
241252

253+
bmp_ex_keycode_t bmp_ex_keycodes[BMP_EX_KC_LEN];
254+
uint32_t bmp_ex_keycode_num;
255+
242256
char *strnstr(const char *haystack, const char *needle, size_t len) {
243257
int i;
244258
size_t needle_len;
@@ -294,11 +308,18 @@ void parse_and_save_keymap(void)
294308
json_keymap_convert_inst_t inst;
295309
json_to_keymap_init(&inst, keymap, sizeof(keymap)/sizeof(keymap[0]));
296310
inst.locale = BMPAPI->app.get_config()->keymap.locale;
311+
inst.bmp_ek = bmp_ex_keycodes;
312+
memset(bmp_ex_keycodes, 0, sizeof(bmp_ex_keycodes));
313+
297314
if (json_to_keymap_conv(&inst, keymap_string) == 0)
298315
{
299316
xprintf("Update keymap. length:%d\r\n", inst.keymap_idx);
317+
xprintf("%d extended keycodes are found\r\n", inst.ek_num);
300318
BMPAPI->app.set_keymap(keymap, inst.keymap_idx);
319+
bmp_ex_keycode_num = inst.ek_num;
301320
BMPAPI->app.save_file(1);
321+
322+
save_ex_keycode_file();
302323
}
303324
else
304325
{
@@ -437,6 +458,8 @@ static inline void update_keymap_string(bmp_api_config_t const * config,
437458
keymap_to_json_init(&keymap_conv_inst, keymap_info->array, keymap_info->len);
438459
keymap_conv_inst.locale = config->keymap.locale;
439460
keymap_conv_inst.use_ascii = config->keymap.use_ascii;
461+
keymap_conv_inst.bmp_ek = bmp_ex_keycodes;
462+
440463
strcpy(str, "{\"layers\":\r\n");
441464
keymap_to_json_conv_layout(&keymap_conv_inst, str + 12,
442465
len-12, config->matrix.layout);
@@ -553,6 +576,7 @@ void bmp_init()
553576
BMPAPI->ble.set_nus_rcv_cb(nus_rcv_callback);
554577
}
555578

579+
load_ex_keycode_file(); // load exkc before tapping_term
556580
load_tapping_term_file();
557581
load_eeprom_emulation_file();
558582

@@ -589,6 +613,7 @@ int load_eeprom_emulation_file()
589613
BMPAPI->app.get_file(QMK_EE_RECORD, &eeprom_file, &eeprom_file_length);
590614
if (eeprom_file == NULL)
591615
{
616+
BMPAPI->app.save_file(QMK_EE_RECORD); // create eeprom file
592617
return 1;
593618
}
594619

@@ -635,6 +660,7 @@ int load_tapping_term_file()
635660
BMPAPI->app.get_file(QMK_RECORD, (uint8_t**)&p_qmk_config, &qmk_config_file_len);
636661
if (p_qmk_config == NULL)
637662
{
663+
BMPAPI->app.save_file(QMK_RECORD);
638664
bmp_qmk_config.tapping_term[0].qkc = KC_NO;
639665
bmp_qmk_config.tapping_term[0].tapping_term = TAPPING_TERM;
640666
return 1;
@@ -661,6 +687,55 @@ int save_tapping_term_file()
661687
return BMPAPI->app.save_file(QMK_RECORD);
662688
}
663689

690+
int load_ex_keycode_file()
691+
{
692+
bmp_ex_keycode_t *p_ex_keycode;
693+
uint32_t ex_keycode_len;
694+
695+
BMPAPI->app.get_file(BMP_EX_KEYCODE_RECORD,
696+
(uint8_t**)&p_ex_keycode, &ex_keycode_len);
697+
if (p_ex_keycode == NULL)
698+
{
699+
bmp_ex_keycodes[0].byte[0] = 0;
700+
return 1;
701+
}
702+
memcpy(&bmp_ex_keycodes[0], p_ex_keycode, sizeof(bmp_ex_keycodes));
703+
704+
for (bmp_ex_keycode_num=0;
705+
bmp_ex_keycode_num<sizeof(bmp_ex_keycodes)/sizeof(bmp_ex_keycodes[0]);
706+
bmp_ex_keycode_num++)
707+
{
708+
if (bmp_ex_keycodes[bmp_ex_keycode_num].byte[0] == 0)
709+
{
710+
break;
711+
}
712+
}
713+
714+
return 0;
715+
}
716+
717+
int save_ex_keycode_file()
718+
{
719+
bmp_ex_keycode_t *p_ex_keycode;
720+
uint32_t ex_keycode_len;
721+
722+
BMPAPI->app.get_file(BMP_EX_KEYCODE_RECORD,
723+
(uint8_t**)&p_ex_keycode, &ex_keycode_len);
724+
if (p_ex_keycode == NULL)
725+
{
726+
// create new file
727+
BMPAPI->app.save_file(BMP_EX_KEYCODE_RECORD);
728+
BMPAPI->app.get_file(BMP_EX_KEYCODE_RECORD,
729+
(uint8_t**)&p_ex_keycode, &ex_keycode_len);
730+
731+
if (p_ex_keycode == NULL) { return 1; }
732+
}
733+
734+
memcpy(p_ex_keycode, &bmp_ex_keycodes[0], ex_keycode_len);
735+
return BMPAPI->app.save_file(BMP_EX_KEYCODE_RECORD);
736+
}
737+
738+
664739
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
665740
{
666741
return BMPAPI->app.keymap_key_to_keycode(layer, (bmp_api_keypos_t*)&key);
@@ -698,10 +773,41 @@ void set_ble_enabled(bool enabled) { ble_enabled = enabled; }
698773
bool get_usb_enabled() { return usb_enabled; }
699774
void set_usb_enabled(bool enabled) { usb_enabled = enabled; }
700775

701-
702776
bool process_record_user_bmp(uint16_t keycode, keyrecord_t *record)
703777
{
704778
char str[16];
779+
780+
switch (keycode) {
781+
case xEISU:
782+
if (record->event.pressed) {
783+
if(keymap_config.swap_lalt_lgui==false){
784+
register_code(KC_LANG2);
785+
}else{
786+
SEND_STRING(SS_LALT("`"));
787+
}
788+
} else {
789+
unregister_code(KC_LANG2);
790+
}
791+
return false;
792+
break;
793+
794+
case xKANA:
795+
if (record->event.pressed) {
796+
if(keymap_config.swap_lalt_lgui==false){
797+
register_code(KC_LANG1);
798+
}else{
799+
SEND_STRING(SS_LALT("`"));
800+
}
801+
} else {
802+
unregister_code(KC_LANG1);
803+
}
804+
return false;
805+
break;
806+
807+
default:
808+
break;
809+
}
810+
705811
if (record->event.pressed) {
706812
switch (keycode) {
707813
case BLE_DIS:
@@ -716,6 +822,14 @@ bool process_record_user_bmp(uint16_t keycode, keyrecord_t *record)
716822
case USB_EN:
717823
set_usb_enabled(true);
718824
return false;
825+
case SEL_BLE:
826+
set_usb_enabled(false);
827+
set_ble_enabled(true);
828+
return false;
829+
case SEL_USB:
830+
set_ble_enabled(false);
831+
set_usb_enabled(true);
832+
return false;
719833
case ADV_ID0...ADV_ID7:
720834
BMPAPI->ble.advertise(keycode - ADV_ID0);
721835
return false;
@@ -738,6 +852,12 @@ bool process_record_user_bmp(uint16_t keycode, keyrecord_t *record)
738852
snprintf(str, sizeof(str), "%4dmV", BMPAPI->app.get_vcc_mv());
739853
send_string(str);
740854
return false;
855+
case SAVE_EE:
856+
save_eeprom_emulation_file();
857+
return false;
858+
case DEL_EE:
859+
BMPAPI->app.delete_file(QMK_EE_RECORD);
860+
return false;
741861
}
742862
}
743863
else if (!record->event.pressed) {
@@ -755,3 +875,4 @@ __attribute__((weak))uint32_t keymaps_len()
755875
{
756876
return 0;
757877
}
878+

tmk_core/protocol/nrf/bmp.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,6 @@
55
#include "action.h"
66
#include "quantum_keycodes.h"
77

8-
typedef struct {
9-
uint16_t start_kc;
10-
uint16_t end_kc;
11-
const char* key_strings;
12-
} key_string_map_t;
13-
14-
enum bmp_custom_keycodes {
15-
BLE_DIS = SAFE_RANGE, /* Disable BLE HID sending */
16-
BLE_EN, /* Enable BLE HID sending */
17-
USB_DIS, /* Disable USB HID sending */
18-
USB_EN, /* Enable USB HID sending */
19-
ADV_ID0, /* Start advertising to PeerID 0 */
20-
ADV_ID1, /* Start advertising to PeerID 1 */
21-
ADV_ID2, /* Start advertising to PeerID 2 */
22-
ADV_ID3, /* Start advertising to PeerID 3 */
23-
ADV_ID4, /* Start advertising to PeerID 4 */
24-
ADV_ID5, /* Start advertising to PeerID 5 */
25-
ADV_ID6, /* Start advertising to PeerID 6 */
26-
ADV_ID7, /* Start advertising to PeerID 7 */
27-
AD_WO_L, /* Start advertising without whitelist */
28-
DEL_ID0, /* Delete bonding of PeerID 0 */
29-
DEL_ID1, /* Delete bonding of PeerID 1 */
30-
DEL_ID2, /* Delete bonding of PeerID 2 */
31-
DEL_ID3, /* Delete bonding of PeerID 3 */
32-
DEL_ID4, /* Delete bonding of PeerID 4 */
33-
DEL_ID5, /* Delete bonding of PeerID 5 */
34-
DEL_ID6, /* Delete bonding of PeerID 6 */
35-
DEL_ID7, /* Delete bonding of PeerID 7 */
36-
DELBNDS, /* Delete all bonding */
37-
ENT_DFU, /* Start bootloader */
38-
ENT_WEB, /* Start web configurator */
39-
ENT_SLP, /* Deep sleep mode */
40-
BATT_LV, /* Display battery level in milli volts */
41-
BMP_SAFE_RANGE /* End of custom kecode */
42-
};
43-
448
void bmp_keyboard_task(void);
459
void bmp_init(void);
4610
bmp_error_t msc_write_callback(const uint8_t* dat, uint32_t len);
@@ -52,6 +16,9 @@ int save_eeprom_emulation_file();
5216
int load_tapping_term_file();
5317
int save_tapping_term_file();
5418

19+
int load_ex_keycode_file();
20+
int save_ex_keycode_file();
21+
5522
bool process_record_user_bmp(uint16_t keycode, keyrecord_t *record);
5623

5724
bool get_ble_enabled();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
#pragma once
3+
4+
#include "quantum_keycodes.h"
5+
6+
#define BMP_EX_KC_LEN 32
7+
enum bmp_custom_keycodes {
8+
BLE_DIS = SAFE_RANGE, /* Disable BLE HID sending */
9+
BLE_EN, /* Enable BLE HID sending */
10+
USB_DIS, /* Disable USB HID sending */
11+
USB_EN, /* Enable USB HID sending */
12+
SEL_BLE, /* Enable BLE and disable USB */
13+
SEL_USB, /* Enable USB and disable BLE */
14+
ADV_ID0, /* Start advertising to PeerID 0 */
15+
ADV_ID1, /* Start advertising to PeerID 1 */
16+
ADV_ID2, /* Start advertising to PeerID 2 */
17+
ADV_ID3, /* Start advertising to PeerID 3 */
18+
ADV_ID4, /* Start advertising to PeerID 4 */
19+
ADV_ID5, /* Start advertising to PeerID 5 */
20+
ADV_ID6, /* Start advertising to PeerID 6 */
21+
ADV_ID7, /* Start advertising to PeerID 7 */
22+
AD_WO_L, /* Start advertising without whitelist */
23+
DEL_ID0, /* Delete bonding of PeerID 0 */
24+
DEL_ID1, /* Delete bonding of PeerID 1 */
25+
DEL_ID2, /* Delete bonding of PeerID 2 */
26+
DEL_ID3, /* Delete bonding of PeerID 3 */
27+
DEL_ID4, /* Delete bonding of PeerID 4 */
28+
DEL_ID5, /* Delete bonding of PeerID 5 */
29+
DEL_ID6, /* Delete bonding of PeerID 6 */
30+
DEL_ID7, /* Delete bonding of PeerID 7 */
31+
DELBNDS, /* Delete all bonding */
32+
ENT_DFU, /* Start bootloader */
33+
ENT_WEB, /* Start web configurator */
34+
ENT_SLP, /* Deep sleep mode */
35+
BATT_LV, /* Display battery level in milli volts */
36+
SAVE_EE,
37+
DEL_EE,
38+
xEISU,
39+
xKANA,
40+
EXKC_START, /* Extended keycode START */
41+
EXKC_END = EXKC_START + BMP_EX_KC_LEN - 1,
42+
BMP_SAFE_RANGE /* End of custom kecode */
43+
};
44+

0 commit comments

Comments
 (0)