Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
f4ba635d
Unverified
Commit
f4ba635d
authored
Dec 16, 2020
by
Lukáš Voborský
Committed by
GitHub
Dec 16, 2020
Browse files
Fix softuart module setup function parameters (#3348)
parent
432fe496
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/softuart.c
View file @
f4ba635d
...
@@ -194,6 +194,7 @@ static int softuart_init(softuart_t *s)
...
@@ -194,6 +194,7 @@ static int softuart_init(softuart_t *s)
}
}
return
platform_gpio_register_intr_hook
(
mask
,
softuart_intr_handler
);
return
platform_gpio_register_intr_hook
(
mask
,
softuart_intr_handler
);
}
}
return
1
;
}
}
...
@@ -206,30 +207,27 @@ static int softuart_setup(lua_State *L)
...
@@ -206,30 +207,27 @@ static int softuart_setup(lua_State *L)
NODE_DBG
(
"[SoftUART]: setup called
\n
"
);
NODE_DBG
(
"[SoftUART]: setup called
\n
"
);
baudrate
=
(
uint32_t
)
luaL_checkinteger
(
L
,
1
);
// Get Baudrate from
baudrate
=
(
uint32_t
)
luaL_checkinteger
(
L
,
1
);
// Get Baudrate from
luaL_argcheck
(
L
,
(
baudrate
>
0
&&
baudrate
<
230400
),
1
,
"Invalid baud rate"
);
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_isnoneornil
(
L
,
2
))
{
if
(
lua_isnil
(
L
,
1
))
{
tx_gpio_id
=
0xFF
;
tx_gpio_id
=
0xFF
;
}
else
{
}
else
{
tx_gpio_id
=
(
uint8_t
)
luaL_checkinteger
(
L
,
2
);
tx_gpio_id
=
(
uint8_t
)
luaL_checkinteger
(
L
,
1
);
luaL_argcheck
(
L
,
(
platform_gpio_exists
(
tx_gpio_id
)
&&
tx_gpio_id
!=
0
)
luaL_argcheck
(
L
,
(
platform_gpio_exists
(
tx_gpio_id
)
&&
tx_gpio_id
!=
0
)
,
2
,
"Invalid SoftUART tx GPIO"
);
,
2
,
"Invalid SoftUART tx GPIO"
);
}
}
rx_gpio_id
=
(
uint8_t
)
luaL_checkinteger
(
L
,
2
);
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
)
luaL_argcheck
(
L
,
(
platform_gpio_exists
(
rx_gpio_id
)
&&
rx_gpio_id
!=
0
)
,
3
,
"Invalid SoftUART rx GPIO"
);
,
3
,
"Invalid SoftUART rx GPIO"
);
luaL_argcheck
(
L
,
softuart_gpio_instances
[
rx_gpio_id
]
==
NULL
luaL_argcheck
(
L
,
softuart_gpio_instances
[
rx_gpio_id
]
==
NULL
,
3
,
"SoftUART rx already configured on the pin"
);
,
3
,
"SoftUART rx already configured on the pin"
);
}
}
else
if
(
lua_gettop
(
L
)
==
1
)
{
// 1 argument: transmit part only
// SoftUART object without receive and transmit part would be useless
rx_gpio_id
=
0xFF
;
if
((
rx_gpio_id
==
0xFF
)
&&
(
tx_gpio_id
==
0xFF
))
{
return
luaL_error
(
L
,
"Not enough arguments"
);}
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
=
(
softuart_t
*
)
lua_newuserdata
(
L
,
sizeof
(
softuart_t
));
softuart
=
(
softuart_t
*
)
lua_newuserdata
(
L
,
sizeof
(
softuart_t
));
softuart
->
pin_rx
=
rx_gpio_id
;
softuart
->
pin_rx
=
rx_gpio_id
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment