Fix softuart module setup function parameters (#3348)

This commit is contained in:
Lukáš Voborský 2020-12-16 12:56:55 +01:00 committed by GitHub
parent 432fe49612
commit f4ba635d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 19 deletions

View File

@ -194,6 +194,7 @@ static int softuart_init(softuart_t *s)
}
return platform_gpio_register_intr_hook(mask, softuart_intr_handler);
}
return 1;
}
@ -206,30 +207,27 @@ static int softuart_setup(lua_State *L)
NODE_DBG("[SoftUART]: setup called\n");
baudrate = (uint32_t)luaL_checkinteger(L, 1); // Get Baudrate from
luaL_argcheck(L, (baudrate > 0 && baudrate < 230400), 1, "Invalid baud rate");
lua_remove(L, 1); // Remove baudrate argument from stack
if (lua_gettop(L) == 2) { // 2 arguments: 1st can be nil
if (lua_isnil(L, 1)) {
tx_gpio_id = 0xFF;
} else {
tx_gpio_id = (uint8_t)luaL_checkinteger(L, 1);
luaL_argcheck(L, (platform_gpio_exists(tx_gpio_id) && tx_gpio_id != 0)
, 2, "Invalid SoftUART tx GPIO");
}
rx_gpio_id = (uint8_t)luaL_checkinteger(L, 2);
if (lua_isnoneornil(L, 2)) {
tx_gpio_id = 0xFF;
} else {
tx_gpio_id = (uint8_t)luaL_checkinteger(L, 2);
luaL_argcheck(L, (platform_gpio_exists(tx_gpio_id) && tx_gpio_id != 0)
, 2, "Invalid SoftUART tx GPIO");
}
if (lua_isnoneornil(L, 3)) {
rx_gpio_id = 0xFF;
} else {
rx_gpio_id = (uint8_t)luaL_checkinteger(L, 3);
luaL_argcheck(L, (platform_gpio_exists(rx_gpio_id) && rx_gpio_id != 0)
, 3, "Invalid SoftUART rx GPIO");
luaL_argcheck(L, softuart_gpio_instances[rx_gpio_id] == NULL
, 3, "SoftUART rx already configured on the pin");
}
} else if (lua_gettop(L) == 1) { // 1 argument: transmit part only
rx_gpio_id = 0xFF;
tx_gpio_id = (uint8_t)luaL_checkinteger(L, 1);
luaL_argcheck(L, (platform_gpio_exists(tx_gpio_id) && tx_gpio_id != 0)
, 2, "Invalid SoftUART tx GPIO");
} else {
// SoftUART object without receive and transmit part would be useless
return luaL_error(L, "Not enough arguments");
}
// SoftUART object without receive and transmit part would be useless
if ((rx_gpio_id == 0xFF) && (tx_gpio_id == 0xFF)) {return luaL_error(L, "Not enough arguments");}
softuart = (softuart_t*)lua_newuserdata(L, sizeof(softuart_t));
softuart->pin_rx = rx_gpio_id;