mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-30 21:12:55 +08:00
9bbf8f43fb
RTOS driver evicted as it did not play nice with stdio etc. Implemented a minimal driver to fully support Lua console on UART0. Output on UART0 done via stdout (provided by the IDF). Input and setup handled via driver_console/console.c. In addition to the direct input function console_getc(), the driver also registers in the syscall tables to enable regular stdio input functions to work (yay!). The Lua VM is still using the direct interface since it's less overhead, but does also work when going through stdin/fd 0. Auto-bauding on the console is not yet functional; revisit when the UART docs are available. Module registration/linking/enabling moved over to be Kconfig based. See updates to base_nodemcu/include/module.h and base_nodemcu/Kconfig for details. The sdk-overrides directory/approach is no longer used. The IDF is simply too different to the old RTOS SDK - we need to adapt our code directly instead. Everything in app/ is now unused, and will need to be gradually migrated into components/ though it is probably better to migrate straight from the latest dev branch.
61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
#include "platform.h"
|
|
#include "driver/console.h"
|
|
#include <stdio.h>
|
|
|
|
int platform_init (void)
|
|
{
|
|
return PLATFORM_OK;
|
|
}
|
|
|
|
// ****************************************************************************
|
|
// UART
|
|
|
|
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
|
|
{
|
|
if (id == CONSOLE_UART)
|
|
{
|
|
ConsoleSetup_t cfg;
|
|
cfg.bit_rate = baud;
|
|
switch (databits)
|
|
{
|
|
case 5: cfg.data_bits = CONSOLE_NUM_BITS_5; break;
|
|
case 6: cfg.data_bits = CONSOLE_NUM_BITS_6; break;
|
|
case 7: cfg.data_bits = CONSOLE_NUM_BITS_7; break;
|
|
case 8: // fall-through
|
|
default: cfg.data_bits = CONSOLE_NUM_BITS_8; break;
|
|
}
|
|
switch (parity)
|
|
{
|
|
case PLATFORM_UART_PARITY_EVEN: cfg.parity = CONSOLE_PARITY_EVEN; break;
|
|
case PLATFORM_UART_PARITY_ODD: cfg.parity = CONSOLE_PARITY_ODD; break;
|
|
default: // fall-through
|
|
case PLATFORM_UART_PARITY_NONE: cfg.parity = CONSOLE_PARITY_NONE; break;
|
|
}
|
|
switch (stopbits)
|
|
{
|
|
default: // fall-through
|
|
case PLATFORM_UART_STOPBITS_1:
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_1; break;
|
|
case PLATFORM_UART_STOPBITS_1_5:
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_1_5; break;
|
|
case PLATFORM_UART_STOPBITS_2:
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_2; break;
|
|
}
|
|
cfg.auto_baud = false;
|
|
console_setup (&cfg);
|
|
return baud;
|
|
}
|
|
else
|
|
{
|
|
printf("UART1/UART2 not yet supported\n");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
void platform_uart_send( unsigned id, uint8_t data )
|
|
{
|
|
if (id == CONSOLE_UART)
|
|
putchar (data);
|
|
}
|