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
577e2ea8
Commit
577e2ea8
authored
Jan 29, 2019
by
Javier Peletier
Committed by
Arnim Läuger
Jan 29, 2019
Browse files
uart: added uart.getconfig() (#2633)
parent
e38fc7ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
components/base_nodemcu/uart.c
View file @
577e2ea8
...
...
@@ -237,6 +237,24 @@ static int uart_start( lua_State* L )
return
1
;
}
static
int
uart_getconfig
(
lua_State
*
L
)
{
uint32_t
id
,
baud
,
databits
,
parity
,
stopbits
;
id
=
luaL_checkinteger
(
L
,
1
);
MOD_CHECK_ID
(
uart
,
id
);
int
err
=
platform_uart_get_config
(
id
,
&
baud
,
&
databits
,
&
parity
,
&
stopbits
);
if
(
err
)
{
luaL_error
(
L
,
"Error reading UART config"
);
}
lua_pushinteger
(
L
,
baud
);
lua_pushinteger
(
L
,
databits
);
lua_pushinteger
(
L
,
parity
);
lua_pushinteger
(
L
,
stopbits
);
return
4
;
}
// Module function map
static
const
LUA_REG_TYPE
uart_map
[]
=
{
{
LSTRKEY
(
"setup"
),
LFUNCVAL
(
uart_setup
)
},
...
...
@@ -245,6 +263,7 @@ static const LUA_REG_TYPE uart_map[] = {
{
LSTRKEY
(
"stop"
),
LFUNCVAL
(
uart_stop
)
},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
uart_on
)
},
{
LSTRKEY
(
"setmode"
),
LFUNCVAL
(
uart_setmode
)
},
{
LSTRKEY
(
"getconfig"
),
LFUNCVAL
(
uart_getconfig
)
},
{
LSTRKEY
(
"STOPBITS_1"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_1
)
},
{
LSTRKEY
(
"STOPBITS_1_5"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_1_5
)
},
{
LSTRKEY
(
"STOPBITS_2"
),
LNUMVAL
(
PLATFORM_UART_STOPBITS_2
)
},
...
...
components/platform/include/platform.h
View file @
577e2ea8
...
...
@@ -122,6 +122,7 @@ void platform_uart_send( unsigned id, uint8_t data );
void
platform_uart_flush
(
unsigned
id
);
int
platform_uart_start
(
unsigned
id
);
void
platform_uart_stop
(
unsigned
id
);
int
platform_uart_get_config
(
unsigned
id
,
uint32_t
*
baudp
,
uint32_t
*
databitsp
,
uint32_t
*
parityp
,
uint32_t
*
stopbitsp
);
// *****************************************************************************
...
...
components/platform/platform.c
View file @
577e2ea8
...
...
@@ -336,6 +336,43 @@ void platform_uart_stop( unsigned id )
}
}
int
platform_uart_get_config
(
unsigned
id
,
uint32_t
*
baudp
,
uint32_t
*
databitsp
,
uint32_t
*
parityp
,
uint32_t
*
stopbitsp
)
{
int
err
;
err
=
uart_get_baudrate
(
id
,
baudp
);
if
(
err
!=
ESP_OK
)
return
-
1
;
*
baudp
&=
0xFFFFFFFE
;
// round down
uint32_t
databits
;
err
=
uart_get_word_length
(
id
,
&
databits
);
if
(
err
!=
ESP_OK
)
return
-
1
;
switch
(
databits
)
{
case
UART_DATA_5_BITS
:
*
databitsp
=
5
;
break
;
case
UART_DATA_6_BITS
:
*
databitsp
=
6
;
break
;
case
UART_DATA_7_BITS
:
*
databitsp
=
7
;
break
;
case
UART_DATA_8_BITS
:
*
databitsp
=
8
;
break
;
default:
return
-
1
;
}
err
=
uart_get_parity
(
id
,
parityp
);
if
(
err
!=
ESP_OK
)
return
-
1
;
err
=
uart_get_stop_bits
(
id
,
stopbitsp
);
if
(
err
!=
ESP_OK
)
return
-
1
;
return
0
;
}
// *****************************************************************************
// Sigma-Delta platform interface
...
...
docs/modules/uart.md
View file @
577e2ea8
...
...
@@ -105,6 +105,30 @@ uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
uart
.
setup
(
2
,
115200
,
8
,
uart
.
PARITY_NONE
,
uart
.
STOPBITS_1
,
{
tx
=
16
,
rx
=
17
})
```
## uart.getconfig()
Returns the current configuration parameters of the UART.
#### Syntax
`uart.getconfig(id)`
#### Parameters
-
`id`
UART id (0 or 1).
#### Returns
Four values as follows:
-
`baud`
one of 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 256000, 460800, 921600, 1843200, 3686400
-
`databits`
one of 5, 6, 7, 8
-
`parity`
`uart.PARITY_NONE`
,
`uart.PARITY_ODD`
, or
`uart.PARITY_EVEN`
-
`stopbits`
`uart.STOPBITS_1`
,
`uart.STOPBITS_1_5`
, or
`uart.STOPBITS_2`
#### Example
```
lua
print
(
uart
.
getconfig
(
0
))
-- prints 9600 8 0 1 for 9600, 8N1
```
## uart.start()
Start the UART. You do not need to call
`start()`
on the console uart.
...
...
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