Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
84146a17
Commit
84146a17
authored
Apr 07, 2014
by
zephyrr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revamped write_payload() and read_payload()
Restructured based on needing or not needing blank padding
parent
afdb084d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
49 deletions
+47
-49
RF24.cpp
RF24.cpp
+47
-49
No files found.
RF24.cpp
View file @
84146a17
...
...
@@ -135,13 +135,12 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value)
/****************************************************************************/
uint8_t
RF24
::
write_payload
(
const
void
*
buf
,
uint8_t
len
)
uint8_t
RF24
::
write_payload
(
const
void
*
buf
,
uint8_t
data_
len
)
{
uint8_t
status
;
const
uint8_t
*
current
=
reinterpret_cast
<
const
uint8_t
*>
(
buf
);
uint8_t
data_len
=
min
(
len
,
payload_size
)
;
if
(
data_len
>
payload_size
)
data_len
=
payload_size
;
uint8_t
blank_len
=
dynamic_payloads_enabled
?
0
:
payload_size
-
data_len
;
//printf("[Writing %u bytes %u blanks]",data_len,blank_len);
...
...
@@ -150,33 +149,31 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len)
status
=
SPI
.
transfer
(
csn_pin
,
W_TX_PAYLOAD
,
SPI_CONTINUE
);
if
(
data_len
==
32
||
dynamic_payloads_enabled
){
while
(
data_len
--
>
1
){
SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
SPI
.
transfer
(
csn_pin
,
*
current
++
);
}
else
{
while
(
data_len
--
){
if
(
blank_len
){
while
(
data_len
--
){
SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
}
if
(
blank_len
){
while
(
blank_len
--
>
1
){
while
(
--
blank_len
){
SPI
.
transfer
(
csn_pin
,
0
,
SPI_CONTINUE
);
}
SPI
.
transfer
(
csn_pin
,
0
);
}
else
{
while
(
--
data_len
){
SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
SPI
.
transfer
(
csn_pin
,
*
current
);
}
#else
csn
(
LOW
);
status
=
SPI
.
transfer
(
W_TX_PAYLOAD
);
while
(
data_len
--
)
while
(
data_len
--
)
{
SPI
.
transfer
(
*
current
++
);
while
(
blank_len
--
)
}
while
(
blank_len
--
)
{
SPI
.
transfer
(
0
);
}
csn
(
HIGH
);
#endif
...
...
@@ -186,46 +183,47 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len)
/****************************************************************************/
uint8_t
RF24
::
read_payload
(
void
*
buf
,
uint8_t
len
)
uint8_t
RF24
::
read_payload
(
void
*
buf
,
uint8_t
data_
len
)
{
uint8_t
status
;
uint8_t
*
current
=
reinterpret_cast
<
uint8_t
*>
(
buf
);
uint8_t
data_len
=
min
(
len
,
payload_size
)
;
if
(
data_len
>
payload_size
)
data_len
=
payload_size
;
uint8_t
blank_len
=
dynamic_payloads_enabled
?
0
:
payload_size
-
data_len
;
//printf("[Reading %u bytes %u blanks]",data_len,blank_len);
#if defined (__arm__)
status
=
SPI
.
transfer
(
csn_pin
,
R_RX_PAYLOAD
,
SPI_CONTINUE
);
if
(
data_len
==
32
||
dynamic_payloads_enabled
){
while
(
data_len
--
>
1
){
*
current
++
=
SPI
.
transfer
(
csn_pin
,
0xff
,
SPI_CONTINUE
);
}
*
current
++
=
SPI
.
transfer
(
csn_pin
,
0xff
);
}
else
{
if
(
blank_len
){
while
(
data_len
--
){
*
current
++
=
SPI
.
transfer
(
csn_pin
,
0xff
,
SPI_CONTINUE
);
*
current
++
=
SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
while
(
--
blank_len
){
SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
if
(
blank_len
){
while
(
blank_len
--
){
SPI
.
transfer
(
csn_pin
,
0xff
,
SPI_CONTINUE
);
SPI
.
transfer
(
csn_pin
,
0xFF
);
}
else
{
while
(
--
data_len
){
*
current
++
=
SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
SPI
.
transfer
(
csn_pin
,
0xff
);
*
current
=
SPI
.
transfer
(
csn_pin
,
0xFF
);
}
#else
csn
(
LOW
);
status
=
SPI
.
transfer
(
R_RX_PAYLOAD
);
while
(
data_len
--
)
*
current
++
=
SPI
.
transfer
(
0xff
);
while
(
blank_len
--
)
while
(
data_len
--
)
{
*
current
++
=
SPI
.
transfer
(
0xFF
);
}
while
(
blank_len
--
)
{
SPI
.
transfer
(
0xff
);
}
csn
(
HIGH
);
#endif
...
...
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