Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-pico
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
arduino-pico
Commits
c3a3526a
Unverified
Commit
c3a3526a
authored
Dec 04, 2023
by
Earle F. Philhower, III
Committed by
GitHub
Dec 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SPI 16-bit transfers (#1882)
Fixes #1879 Fixes #1874
parent
280fc437
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
libraries/SPI/keywords.txt
libraries/SPI/keywords.txt
+1
-0
libraries/SPI/src/SPI.cpp
libraries/SPI/src/SPI.cpp
+5
-5
No files found.
libraries/SPI/keywords.txt
View file @
c3a3526a
...
...
@@ -18,6 +18,7 @@ beginTransaction KEYWORD2
endTransaction KEYWORD2
SPISettings KEYWORD2
transfer KEYWORD2
transfer16 KEYWORD2
setBitOrder KEYWORD2
setDataMode KEYWORD2
setClockDivider KEYWORD2
...
...
libraries/SPI/src/SPI.cpp
View file @
c3a3526a
...
...
@@ -111,6 +111,7 @@ byte SPIClassRP2040::transfer(uint8_t data) {
}
data
=
(
_spis
.
getBitOrder
()
==
MSBFIRST
)
?
data
:
reverseByte
(
data
);
DEBUGSPI
(
"SPI::transfer(%02x), cpol=%d, cpha=%d
\n
"
,
data
,
cpol
(),
cpha
());
hw_write_masked
(
&
spi_get_hw
(
_spi
)
->
cr0
,
(
8
-
1
)
<<
SPI_SSPCR0_DSS_LSB
,
SPI_SSPCR0_DSS_BITS
);
// Fast set to 8-bits
spi_write_read_blocking
(
_spi
,
&
data
,
&
ret
,
1
);
ret
=
(
_spis
.
getBitOrder
()
==
MSBFIRST
)
?
ret
:
reverseByte
(
ret
);
DEBUGSPI
(
"SPI: read back %02x
\n
"
,
ret
);
...
...
@@ -124,11 +125,8 @@ uint16_t SPIClassRP2040::transfer16(uint16_t data) {
}
data
=
(
_spis
.
getBitOrder
()
==
MSBFIRST
)
?
data
:
reverse16Bit
(
data
);
DEBUGSPI
(
"SPI::transfer16(%04x), cpol=%d, cpha=%d
\n
"
,
data
,
cpol
(),
cpha
());
uint8_t
d
[
2
];
d
[
0
]
=
(
data
>>
8
)
&
0xff
;
d
[
1
]
=
data
&
0xff
;
spi_write_read_blocking
(
_spi
,
d
,
d
,
2
);
ret
=
((
d
[
0
]
<<
8
)
|
(
d
[
1
]
&
0xff
))
&
0xffff
;
hw_write_masked
(
&
spi_get_hw
(
_spi
)
->
cr0
,
(
16
-
1
)
<<
SPI_SSPCR0_DSS_LSB
,
SPI_SSPCR0_DSS_BITS
);
// Fast set to 16-bits
spi_write16_read16_blocking
(
_spi
,
&
data
,
&
ret
,
1
);
ret
=
(
_spis
.
getBitOrder
()
==
MSBFIRST
)
?
ret
:
reverse16Bit
(
ret
);
DEBUGSPI
(
"SPI: read back %02x
\n
"
,
ret
);
return
ret
;
...
...
@@ -149,6 +147,8 @@ void SPIClassRP2040::transfer(const void *txbuf, void *rxbuf, size_t count) {
return
;
}
hw_write_masked
(
&
spi_get_hw
(
_spi
)
->
cr0
,
(
8
-
1
)
<<
SPI_SSPCR0_DSS_LSB
,
SPI_SSPCR0_DSS_BITS
);
// Fast set to 8-bits
DEBUGSPI
(
"SPI::transfer(%p, %p, %d)
\n
"
,
txbuf
,
rxbuf
,
count
);
const
uint8_t
*
txbuff
=
reinterpret_cast
<
const
uint8_t
*>
(
txbuf
);
uint8_t
*
rxbuff
=
reinterpret_cast
<
uint8_t
*>
(
rxbuf
);
...
...
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