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
70695597
Commit
70695597
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 done by generator.
parent
5deceb84
Branches
Branches containing commit
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
+29
-41
29 additions, 41 deletions
drivers/nrf24l01/nrf24l01.py
with
29 additions
and
41 deletions
drivers/nrf24l01/nrf24l01.py
+
29
−
41
View file @
70695597
"""
NRF24L01 driver for Micro Python
"""
NRF24L01 driver for Micro Python
Support for nonblocking send added. Minor fixes:
Timeout now uses pyb.elapsed_millis().
Channel numbers constrained to 125 as per datasheet.
Status register read with reg_read() - reg_read_ret_status() removed.
Default speed 250K for improved range/error rate.
"""
"""
import
pyb
import
pyb
...
@@ -145,7 +139,7 @@ class NRF24L01:
...
@@ -145,7 +139,7 @@ class NRF24L01:
self
.
reg_write
(
CONFIG
,
config
)
self
.
reg_write
(
CONFIG
,
config
)
def
set_channel
(
self
,
channel
):
def
set_channel
(
self
,
channel
):
self
.
reg_write
(
RF_CH
,
min
(
channel
,
125
))
# Changed from 127
self
.
reg_write
(
RF_CH
,
min
(
channel
,
125
))
# address should be a bytes object 5 bytes long
# address should be a bytes object 5 bytes long
def
open_tx_pipe
(
self
,
address
):
def
open_tx_pipe
(
self
,
address
):
...
@@ -207,20 +201,16 @@ class NRF24L01:
...
@@ -207,20 +201,16 @@ class NRF24L01:
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
=
send_nonblock
(
)
# 1 == success 2 == fail
result
=
next
(
send_nonblock
)
# 1 == success 2 == fail
if
result
==
2
:
if
result
==
2
:
raise
OSError
(
"
send failed
"
)
raise
OSError
(
"
send failed
"
)
def
send_nonblocking
(
self
,
buf
):
def
send_nonblocking
(
self
,
buf
):
'''
'''
Support for nonblocking transmission. Returns a
function
instance.
Support for nonblocking transmission. Returns a
generator
instance.
The first call to a function instanc
e sends the data and returns None.
First us
e sends the data and returns None.
Subsequently tests TX status
Subsequent calls test TX status
returning not ready None, ready 1, error 2.
returning not ready None, ready 1, error 2.
'''
'''
init
=
True
def
make_snb
():
nonlocal
init
if
init
:
# 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
)
...
@@ -237,14 +227,12 @@ class NRF24L01:
...
@@ -237,14 +227,12 @@ 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
()
init
=
False
yield
None
# Not ready
return
None
# Not ready
if
not
(
self
.
reg_read
(
STATUS
)
&
(
TX_DS
|
MAX_RT
)):
while
not
(
self
.
reg_read
(
STATUS
)
&
(
TX_DS
|
MAX_RT
)):
return
None
# Not ready
yield
None
# Not ready
# Either ready or failed: get and clear status flags, power down
# Either ready 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
)
return
1
if
status
&
TX_DS
else
2
yield
1
if
status
&
TX_DS
else
2
return
make_snb
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