Commit 5e6cb4d1 authored by Joo Aun Saw's avatar Joo Aun Saw Committed by Johny Mattsson
Browse files

uart: slight clean up of uart.setup

parent ddc770a6
...@@ -132,7 +132,7 @@ static int uart_on( lua_State* L ) ...@@ -132,7 +132,7 @@ static int uart_on( lua_State* L )
// Lua: actualbaud = setup( id, baud, databits, parity, stopbits, echo ) // Lua: actualbaud = setup( id, baud, databits, parity, stopbits, echo )
static int uart_setup( lua_State* L ) static int uart_setup( lua_State* L )
{ {
unsigned id, databits, parity, stopbits, echo = 1; unsigned id, databits, parity, stopbits;
uint32_t baud, res; uint32_t baud, res;
uart_pins_t pins; uart_pins_t pins;
uart_pins_t* pins_to_use = NULL; uart_pins_t* pins_to_use = NULL;
...@@ -144,13 +144,14 @@ static int uart_setup( lua_State* L ) ...@@ -144,13 +144,14 @@ static int uart_setup( lua_State* L )
databits = luaL_checkinteger( L, 3 ); databits = luaL_checkinteger( L, 3 );
parity = luaL_checkinteger( L, 4 ); parity = luaL_checkinteger( L, 4 );
stopbits = luaL_checkinteger( L, 5 ); stopbits = luaL_checkinteger( L, 5 );
if(id == CONFIG_ESP_CONSOLE_UART_NUM && lua_isnumber(L,6)){ if(id == CONFIG_ESP_CONSOLE_UART_NUM){
echo = lua_tointeger(L,6); if (!lua_isnoneornil(L, 6)) {
if(echo!=0) input_echo = luaL_checkinteger(L, 6) > 0;
input_echo = true; }
else } else {
input_echo = false; if (!lua_isnoneornil(L, 6)) {
} else if(id != CONFIG_ESP_CONSOLE_UART_NUM && lua_istable( L, 6 )) { luaL_checktable(L, 6);
lua_getfield (L, 6, "tx"); lua_getfield (L, 6, "tx");
pins.tx_pin = luaL_checkint(L, -1); pins.tx_pin = luaL_checkint(L, -1);
lua_getfield (L, 6, "rx"); lua_getfield (L, 6, "rx");
...@@ -173,6 +174,7 @@ static int uart_setup( lua_State* L ) ...@@ -173,6 +174,7 @@ static int uart_setup( lua_State* L )
pins.flow_control = luaL_optint(L, -1, PLATFORM_UART_FLOW_NONE); pins.flow_control = luaL_optint(L, -1, PLATFORM_UART_FLOW_NONE);
pins_to_use = &pins; pins_to_use = &pins;
}
} }
res = platform_uart_setup( id, baud, databits, parity, stopbits, pins_to_use ); res = platform_uart_setup( id, baud, databits, parity, stopbits, pins_to_use );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment