@@ -194,6 +194,7 @@ static int softuart_init(softuart_t *s)
194
194
}
195
195
return platform_gpio_register_intr_hook (mask , softuart_intr_handler );
196
196
}
197
+ return 1 ;
197
198
}
198
199
199
200
@@ -206,30 +207,27 @@ static int softuart_setup(lua_State *L)
206
207
NODE_DBG ("[SoftUART]: setup called\n" );
207
208
baudrate = (uint32_t )luaL_checkinteger (L , 1 ); // Get Baudrate from
208
209
luaL_argcheck (L , (baudrate > 0 && baudrate < 230400 ), 1 , "Invalid baud rate" );
209
- lua_remove (L , 1 ); // Remove baudrate argument from stack
210
- if (lua_gettop (L ) == 2 ) { // 2 arguments: 1st can be nil
211
- if (lua_isnil (L , 1 )) {
212
- tx_gpio_id = 0xFF ;
213
- } else {
214
- tx_gpio_id = (uint8_t )luaL_checkinteger (L , 1 );
215
- luaL_argcheck (L , (platform_gpio_exists (tx_gpio_id ) && tx_gpio_id != 0 )
216
- , 2 , "Invalid SoftUART tx GPIO" );
217
- }
218
- rx_gpio_id = (uint8_t )luaL_checkinteger (L , 2 );
210
+
211
+ if (lua_isnoneornil (L , 2 )) {
212
+ tx_gpio_id = 0xFF ;
213
+ } else {
214
+ tx_gpio_id = (uint8_t )luaL_checkinteger (L , 2 );
215
+ luaL_argcheck (L , (platform_gpio_exists (tx_gpio_id ) && tx_gpio_id != 0 )
216
+ , 2 , "Invalid SoftUART tx GPIO" );
217
+ }
218
+
219
+ if (lua_isnoneornil (L , 3 )) {
220
+ rx_gpio_id = 0xFF ;
221
+ } else {
222
+ rx_gpio_id = (uint8_t )luaL_checkinteger (L , 3 );
219
223
luaL_argcheck (L , (platform_gpio_exists (rx_gpio_id ) && rx_gpio_id != 0 )
220
224
, 3 , "Invalid SoftUART rx GPIO" );
221
225
luaL_argcheck (L , softuart_gpio_instances [rx_gpio_id ] == NULL
222
226
, 3 , "SoftUART rx already configured on the pin" );
227
+ }
223
228
224
- } else if (lua_gettop (L ) == 1 ) { // 1 argument: transmit part only
225
- rx_gpio_id = 0xFF ;
226
- tx_gpio_id = (uint8_t )luaL_checkinteger (L , 1 );
227
- luaL_argcheck (L , (platform_gpio_exists (tx_gpio_id ) && tx_gpio_id != 0 )
228
- , 2 , "Invalid SoftUART tx GPIO" );
229
- } else {
230
- // SoftUART object without receive and transmit part would be useless
231
- return luaL_error (L , "Not enough arguments" );
232
- }
229
+ // SoftUART object without receive and transmit part would be useless
230
+ if ((rx_gpio_id == 0xFF ) && (tx_gpio_id == 0xFF )) {return luaL_error (L , "Not enough arguments" );}
233
231
234
232
softuart = (softuart_t * )lua_newuserdata (L , sizeof (softuart_t ));
235
233
softuart -> pin_rx = rx_gpio_id ;
0 commit comments