11
11
#include "lua.h"
12
12
#include "linput.h"
13
13
#include "platform.h"
14
- #include <string.h>
15
- #include <stdlib.h>
16
- #include <fcntl.h>
17
14
#include "sdkconfig.h"
18
15
#include "esp_system.h"
19
16
#include "esp_event.h"
20
17
#include "esp_spiffs.h"
21
18
#include "esp_netif.h"
22
- #include "esp_vfs_dev.h"
23
- #include "esp_vfs_cdcacm.h"
24
- #include "esp_vfs_usb_serial_jtag.h"
25
- #include "driver/usb_serial_jtag.h"
26
19
#include "nvs_flash.h"
27
20
28
21
#include "task/task.h"
29
- #include "sections.h"
30
22
#include "nodemcu_esp_event.h"
31
23
32
24
#include "freertos/FreeRTOS.h"
33
- #include "freertos/task.h"
34
- #include "freertos/queue.h"
35
-
36
- #define SIG_LUA 0
37
- #define SIG_UARTINPUT 1
38
-
39
- // Line ending config from Kconfig
40
- #if CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF
41
- # define RX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_CRLF
42
- #elif CONFIG_NEWLIB_STDIN_LINE_ENDING_CR
43
- # define RX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_CR
44
- #else
45
- # define RX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_LF
46
- #endif
47
-
48
- #if CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF
49
- # define TX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_CRLF
50
- #elif CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR
51
- # define TX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_CR
52
- #else
53
- # define TX_LINE_ENDINGS_CFG ESP_LINE_ENDINGS_LF
54
- #endif
25
+ #include "freertos/semphr.h"
55
26
56
27
57
28
// We don't get argument size data from the esp_event dispatch, so it's
@@ -71,8 +42,6 @@ typedef struct {
71
42
static task_handle_t relayed_event_task ;
72
43
static SemaphoreHandle_t relayed_event_handled ;
73
44
74
- static task_handle_t lua_feed_task ;
75
-
76
45
77
46
// This function runs in the context of the system default event loop RTOS task
78
47
static void relay_default_loop_events (
@@ -166,129 +135,10 @@ static void nodemcu_init(void)
166
135
}
167
136
168
137
169
- static bool have_console_on_data_cb (void )
170
- {
171
- #if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM
172
- return uart_has_on_data_cb (CONFIG_ESP_CONSOLE_UART_NUM );
173
- #else
174
- return false;
175
- #endif
176
- }
177
-
178
-
179
- static void console_nodemcu_task (task_param_t param , task_prio_t prio )
180
- {
181
- (void )prio ;
182
- char c = (char )param ;
183
-
184
- if (run_input )
185
- feed_lua_input (& c , 1 );
186
-
187
- #if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM
188
- if (have_console_on_data_cb ())
189
- uart_feed_data (CONFIG_ESP_CONSOLE_UART_NUM , & c , 1 );
190
- #endif
191
-
192
- // The IDF doesn't seem to honor setvbuf(stdout, NULL, _IONBF, 0) :(
193
- fsync (fileno (stdout ));
194
- }
195
-
196
-
197
- static void console_task (void * )
198
- {
199
- for (;;)
200
- {
201
- /* We can't use a large read buffer here as some console choices
202
- * (e.g. usb-serial-jtag) don't support read timeouts/partial reads,
203
- * which breaks the echo support and makes for a bad user experience.
204
- */
205
- char c ;
206
- ssize_t n = read (fileno (stdin ), & c , 1 );
207
- if (n > 0 && (run_input || have_console_on_data_cb ()))
208
- {
209
- if (!task_post_block_high (lua_feed_task , (task_param_t )c ))
210
- {
211
- NODE_ERR ("Lost console input data?!\n" );
212
- }
213
- }
214
- }
215
- }
216
-
217
-
218
- static void console_init (void )
219
- {
220
- fflush (stdout );
221
- fsync (fileno (stdout ));
222
-
223
- /* Disable buffering */
224
- setvbuf (stdin , NULL , _IONBF , 0 );
225
- setvbuf (stdout , NULL , _IONBF , 0 );
226
-
227
- /* Disable non-blocking mode */
228
- fcntl (fileno (stdin ), F_SETFL , 0 );
229
- fcntl (fileno (stdout ), F_SETFL , 0 );
230
-
231
- #if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM
232
- /* Based on console/advanced example */
233
-
234
- esp_vfs_dev_uart_port_set_rx_line_endings (
235
- CONFIG_ESP_CONSOLE_UART_NUM , RX_LINE_ENDINGS_CFG );
236
- esp_vfs_dev_uart_port_set_tx_line_endings (
237
- CONFIG_ESP_CONSOLE_UART_NUM , TX_LINE_ENDINGS_CFG );
238
-
239
- /* Configure UART. Note that REF_TICK is used so that the baud rate remains
240
- * correct while APB frequency is changing in light sleep mode.
241
- */
242
- const uart_config_t uart_config = {
243
- .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE ,
244
- .data_bits = UART_DATA_8_BITS ,
245
- .parity = UART_PARITY_DISABLE ,
246
- .stop_bits = UART_STOP_BITS_1 ,
247
- #if SOC_UART_SUPPORT_REF_TICK
248
- .source_clk = UART_SCLK_REF_TICK ,
249
- #elif SOC_UART_SUPPORT_XTAL_CLK
250
- .source_clk = UART_SCLK_XTAL ,
251
- #endif
252
- };
253
- /* Install UART driver for interrupt-driven reads and writes */
254
- uart_driver_install (CONFIG_ESP_CONSOLE_UART_NUM , 256 , 0 , 0 , NULL , 0 );
255
- uart_param_config (CONFIG_ESP_CONSOLE_UART_NUM , & uart_config );
256
-
257
- /* Tell VFS to use UART driver */
258
- esp_vfs_dev_uart_use_driver (CONFIG_ESP_CONSOLE_UART_NUM );
259
-
260
- #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
261
- /* Based on @pjsg's work */
262
-
263
- esp_vfs_dev_usb_serial_jtag_set_rx_line_endings (RX_LINE_ENDINGS_CFG );
264
- esp_vfs_dev_usb_serial_jtag_set_tx_line_endings (TX_LINE_ENDINGS_CFG );
265
-
266
- usb_serial_jtag_driver_config_t usb_serial_jtag_config =
267
- USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT ();
268
- /* Install USB-SERIAL-JTAG driver for interrupt-driven reads and write */
269
- usb_serial_jtag_driver_install (& usb_serial_jtag_config );
270
-
271
- esp_vfs_usb_serial_jtag_use_driver ();
272
- #elif CONFIG_ESP_CONSOLE_USB_CDC
273
- /* Based on console/advanced_usb_cdc */
274
-
275
- esp_vfs_dev_cdcacm_set_rx_line_endings (RX_LINE_ENDINGS_CFG );
276
- esp_vfs_dev_cdcacm_set_tx_line_endings (TX_LINE_ENDINGS_CFG );
277
- #else
278
- # error "Unsupported console type"
279
- #endif
280
-
281
- xTaskCreate (
282
- console_task , "console" , 1024 , NULL , ESP_TASK_MAIN_PRIO + 1 , NULL );
283
- }
284
-
285
-
286
138
void __attribute__((noreturn )) app_main (void )
287
139
{
288
140
task_init ();
289
141
290
- lua_feed_task = task_get_id (console_nodemcu_task );
291
-
292
142
relayed_event_handled = xSemaphoreCreateBinary ();
293
143
relayed_event_task = task_get_id (handle_default_loop_event );
294
144
@@ -304,8 +154,6 @@ void __attribute__((noreturn)) app_main(void)
304
154
nvs_flash_init ();
305
155
esp_netif_init ();
306
156
307
- console_init ();
308
-
309
157
start_lua ();
310
158
task_pump_messages ();
311
159
__builtin_unreachable ();
0 commit comments