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
GitLab 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
e6e8ad8a
Commit
e6e8ad8a
authored
10 years ago
by
adminpete
Committed by
Damien George
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
drivers, nrf24: Nonblocking send now uses send_start and send_done.
parent
70695597
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
drivers/nrf24l01/nrf24l01.py
+14
-19
14 additions, 19 deletions
drivers/nrf24l01/nrf24l01.py
with
14 additions
and
19 deletions
drivers/nrf24l01/nrf24l01.py
+
14
−
19
View file @
e6e8ad8a
...
@@ -11,7 +11,6 @@ SETUP_RETR = const(0x04)
...
@@ -11,7 +11,6 @@ SETUP_RETR = const(0x04)
RF_CH
=
const
(
0x05
)
RF_CH
=
const
(
0x05
)
RF_SETUP
=
const
(
0x06
)
RF_SETUP
=
const
(
0x06
)
STATUS
=
const
(
0x07
)
STATUS
=
const
(
0x07
)
OBSERVE_TX
=
const
(
0x08
)
RX_ADDR_P0
=
const
(
0x0a
)
RX_ADDR_P0
=
const
(
0x0a
)
TX_ADDR
=
const
(
0x10
)
TX_ADDR
=
const
(
0x10
)
RX_PW_P0
=
const
(
0x11
)
RX_PW_P0
=
const
(
0x11
)
...
@@ -73,7 +72,7 @@ class NRF24L01:
...
@@ -73,7 +72,7 @@ class NRF24L01:
# set address width to 5 bytes and check for device present
# set address width to 5 bytes and check for device present
self
.
reg_write
(
SETUP_AW
,
0b11
)
self
.
reg_write
(
SETUP_AW
,
0b11
)
if
self
.
reg_read
(
SETUP_AW
)
!=
0b11
:
if
self
.
reg_read
(
SETUP_AW
)
!=
0b11
:
raise
OSError
(
"
nRF24
l
01+ Hardware not responding
"
)
raise
OSError
(
"
nRF24
L
01+ Hardware not responding
"
)
# disable dynamic payloads
# disable dynamic payloads
self
.
reg_write
(
DYNPD
,
0
)
self
.
reg_write
(
DYNPD
,
0
)
...
@@ -197,24 +196,19 @@ class NRF24L01:
...
@@ -197,24 +196,19 @@ class NRF24L01:
# blocking wait for tx complete
# blocking wait for tx complete
def
send
(
self
,
buf
,
timeout
=
500
):
def
send
(
self
,
buf
,
timeout
=
500
):
send_nonblock
=
self
.
send_
nonblocking
(
buf
)
send_nonblock
=
self
.
send_
start
(
buf
)
start
=
pyb
.
millis
()
start
=
pyb
.
millis
()
result
=
None
result
=
None
while
result
is
None
and
(
pyb
.
elapsed_millis
(
start
)
<
timeout
)
:
while
result
is
None
and
pyb
.
elapsed_millis
(
start
)
<
timeout
:
result
=
next
(
send_
n
on
block
)
# 1 == success 2 == fail
result
=
self
.
send_
d
on
e
(
)
# 1 == success
,
2 == fail
if
result
==
2
:
if
result
==
2
:
raise
OSError
(
"
send failed
"
)
raise
OSError
(
"
send failed
"
)
def
send_nonblocking
(
self
,
buf
):
# non-blocking tx
'''
def
send_start
(
self
,
buf
):
Support for nonblocking transmission. Returns a generator instance.
First use sends the data and returns None. Subsequently tests TX status
returning not ready None, ready 1, error 2.
'''
# power up
# power up
self
.
reg_write
(
CONFIG
,
(
self
.
reg_read
(
CONFIG
)
|
PWR_UP
)
&
~
PRIM_RX
)
self
.
reg_write
(
CONFIG
,
(
self
.
reg_read
(
CONFIG
)
|
PWR_UP
)
&
~
PRIM_RX
)
pyb
.
udelay
(
150
)
pyb
.
udelay
(
150
)
# send the data
# send the data
self
.
cs
.
low
()
self
.
cs
.
low
()
self
.
spi
.
send
(
W_TX_PAYLOAD
)
self
.
spi
.
send
(
W_TX_PAYLOAD
)
...
@@ -227,12 +221,13 @@ class NRF24L01:
...
@@ -227,12 +221,13 @@ class NRF24L01:
self
.
ce
.
high
()
self
.
ce
.
high
()
pyb
.
udelay
(
15
)
# needs to be >10us
pyb
.
udelay
(
15
)
# needs to be >10us
self
.
ce
.
low
()
self
.
ce
.
low
()
yield
None
# Not ready
while
not
(
self
.
reg_read
(
STATUS
)
&
(
TX_DS
|
MAX_RT
)):
# returns None if send still in progress, 1 for success, 2 for fail
yield
None
# Not ready
def
send_done
(
self
):
# Either ready or failed: get and clear status flags, power down
if
not
(
self
.
reg_read
(
STATUS
)
&
(
TX_DS
|
MAX_RT
)):
return
None
# tx not finished
# either finished or failed: get and clear status flags, power down
status
=
self
.
reg_write
(
STATUS
,
RX_DR
|
TX_DS
|
MAX_RT
)
status
=
self
.
reg_write
(
STATUS
,
RX_DR
|
TX_DS
|
MAX_RT
)
self
.
reg_write
(
CONFIG
,
self
.
reg_read
(
CONFIG
)
&
~
PWR_UP
)
self
.
reg_write
(
CONFIG
,
self
.
reg_read
(
CONFIG
)
&
~
PWR_UP
)
yield
1
if
status
&
TX_DS
else
2
return
1
if
status
&
TX_DS
else
2
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