Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
91eb0153
Commit
91eb0153
authored
8 years ago
by
marc hoffman
Committed by
Damien George
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
esp8266/uart: Add support for polling uart device.
parent
90ab191b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
esp8266/machine_uart.c
+16
-2
16 additions, 2 deletions
esp8266/machine_uart.c
esp8266/uart.c
+15
-0
15 additions, 0 deletions
esp8266/uart.c
esp8266/uart.h
+3
-0
3 additions, 0 deletions
esp8266/uart.h
with
34 additions
and
2 deletions
esp8266/machine_uart.c
+
16
−
2
View file @
91eb0153
...
...
@@ -255,8 +255,22 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
}
STATIC
mp_uint_t
pyb_uart_ioctl
(
mp_obj_t
self_in
,
mp_uint_t
request
,
mp_uint_t
arg
,
int
*
errcode
)
{
*
errcode
=
MP_EINVAL
;
return
MP_STREAM_ERROR
;
pyb_uart_obj_t
*
self
=
self_in
;
mp_uint_t
ret
;
if
(
request
==
MP_STREAM_POLL
)
{
mp_uint_t
flags
=
arg
;
ret
=
0
;
if
((
flags
&
MP_STREAM_POLL_RD
)
&&
uart_rx_any
(
self
->
uart_id
))
{
ret
|=
MP_STREAM_POLL_RD
;
}
if
((
flags
&
MP_STREAM_POLL_WR
)
&&
uart_tx_any_room
(
self
->
uart_id
))
{
ret
|=
MP_STREAM_POLL_WR
;
}
}
else
{
*
errcode
=
MP_EINVAL
;
ret
=
MP_STREAM_ERROR
;
}
return
ret
;
}
STATIC
const
mp_stream_p_t
uart_stream_p
=
{
...
...
This diff is collapsed.
Click to expand it.
esp8266/uart.c
+
15
−
0
View file @
91eb0153
...
...
@@ -200,6 +200,21 @@ bool uart_rx_wait(uint32_t timeout_us) {
}
}
int
uart_rx_any
(
uint8
uart
)
{
if
(
input_buf
.
iget
!=
input_buf
.
iput
)
{
return
true
;
// have at least 1 char ready for reading
}
return
false
;
}
int
uart_tx_any_room
(
uint8
uart
)
{
uint32_t
fifo_cnt
=
READ_PERI_REG
(
UART_STATUS
(
uart
))
&
(
UART_TXFIFO_CNT
<<
UART_TXFIFO_CNT_S
);
if
((
fifo_cnt
>>
UART_TXFIFO_CNT_S
&
UART_TXFIFO_CNT
)
>=
126
)
{
return
false
;
}
return
true
;
}
// Returns char from the input buffer, else -1 if buffer is empty.
int
uart_rx_char
(
void
)
{
return
ringbuf_get
(
&
input_buf
);
...
...
This diff is collapsed.
Click to expand it.
esp8266/uart.h
+
3
−
0
View file @
91eb0153
...
...
@@ -99,5 +99,8 @@ void uart_tx_one_char(uint8 uart, uint8 TxChar);
void
uart_flush
(
uint8
uart
);
void
uart_os_config
(
int
uart
);
void
uart_setup
(
uint8
uart
);
// check status of rx/tx
int
uart_rx_any
(
uint8
uart
);
int
uart_tx_any_room
(
uint8
uart
);
#endif // _INCLUDED_UART_H_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment