4
4
//
5
5
// SPDX-License-Identifier: MIT
6
6
7
+ #include "board.h"
7
8
#include "keymap.h"
8
9
#include "supervisor/board.h"
9
10
#include "supervisor/shared/serial.h"
13
14
#include "shared-bindings/microcontroller/Pin.h"
14
15
#include "shared-module/displayio/__init__.h"
15
16
#include "shared-module/displayio/mipi_constants.h"
17
+ #include "shared-module/os/__init__.h"
16
18
#include "shared-bindings/board/__init__.h"
17
- #include "shared-bindings/keypad_demux/DemuxKeyMatrix.h"
18
19
#include "shared-bindings/keypad/EventQueue.h"
19
20
#include "shared-bindings/keypad/Event.h"
20
21
#include "supervisor/shared/reload.h"
23
24
#include "shared/runtime/interrupt_char.h"
24
25
25
26
keypad_demux_demuxkeymatrix_obj_t board_keyboard ;
27
+ bool board_keyboard_serial_enabled = false;
26
28
27
29
void update_keyboard (keypad_eventqueue_obj_t * queue );
28
30
void keyboard_seq (const char * seq );
@@ -123,7 +125,7 @@ void board_init(void) {
123
125
}
124
126
125
127
void board_serial_init () {
126
- ringbuf_init ( & keyqueue , ( uint8_t * ) keybuf , sizeof ( keybuf )) ;
128
+ board_keyboard . base . type = & keypad_demux_demuxkeymatrix_type ;
127
129
common_hal_keypad_demux_demuxkeymatrix_construct (
128
130
& board_keyboard , // self
129
131
3 , // num_row_addr_pins
@@ -135,16 +137,30 @@ void board_serial_init() {
135
137
2 // debounce_threshold
136
138
);
137
139
demuxkeymatrix_never_reset (& board_keyboard );
138
- common_hal_keypad_eventqueue_set_event_handler (board_keyboard .events , update_keyboard );
139
140
141
+ // Wire the keyboard input to serial input (sys.stdin)
142
+ // unless M5STACK_CARDPUTER_KEYBOARD_SERIAL=0 in /settings.toml
143
+ mp_int_t enable_keyboard_serial ;
144
+ os_getenv_err_t enable_keyboard_err = common_hal_os_getenv_int ("M5STACK_CARDPUTER_KEYBOARD_SERIAL" , & enable_keyboard_serial );
145
+ board_keyboard_serial_enabled = (enable_keyboard_err != GETENV_OK ) || enable_keyboard_serial > 0 ;
146
+ if (!board_keyboard_serial_enabled ) {
147
+ return ;
148
+ }
149
+
150
+ ringbuf_init (& keyqueue , (uint8_t * )keybuf , sizeof (keybuf ));
151
+ common_hal_keypad_eventqueue_set_event_handler (board_keyboard .events , update_keyboard );
140
152
}
141
153
142
154
bool board_serial_connected () {
143
- return true ;
155
+ return board_keyboard_serial_enabled ;
144
156
}
145
157
146
158
uint32_t board_serial_bytes_available () {
147
- return ringbuf_num_filled (& keyqueue );
159
+ if (board_keyboard_serial_enabled ) {
160
+ return ringbuf_num_filled (& keyqueue );
161
+ } else {
162
+ return 0 ;
163
+ }
148
164
}
149
165
150
166
void keyboard_seq (const char * seq ) {
@@ -219,7 +235,11 @@ void update_keyboard(keypad_eventqueue_obj_t *queue) {
219
235
}
220
236
221
237
char board_serial_read () {
222
- return ringbuf_get (& keyqueue );
238
+ if (board_keyboard_serial_enabled ) {
239
+ return ringbuf_get (& keyqueue );
240
+ } else {
241
+ return 0 ;
242
+ }
223
243
}
224
244
225
245
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
0 commit comments