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"
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+
8190static 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
154165MATRIX_LOOP_END :
155166
@@ -239,6 +250,9 @@ char keymap_string[10*1024];
239250bmp_qmk_config_t bmp_qmk_config ;
240251char 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+
242256char * 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+
664739uint16_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; }
698773bool get_usb_enabled () { return usb_enabled ; }
699774void set_usb_enabled (bool enabled ) { usb_enabled = enabled ; }
700775
701-
702776bool 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+
0 commit comments