Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
4cf5f374
Commit
4cf5f374
authored
Oct 04, 2015
by
devsaurus
Browse files
address SPI_CLKDIV_PRE requirements
* respect N-1 * avoid range overflow
parent
ac50f9c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/driver/spi.c
View file @
4cf5f374
...
...
@@ -112,10 +112,13 @@ void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databi
// SPI clock = CPU clock / clock_div
// the divider needs to be a multiple of 2 to get a proper waveform shape
if
((
clock_div
&
0x01
)
!=
0
)
{
// bump the divider to the nextN*2
// bump the divider to the next
N*2
clock_div
+=
0x02
;
}
clock_div
>>=
1
;
// clip to maximum possible CLKDIV_PRE
clock_div
=
clock_div
>
SPI_CLKDIV_PRE
?
SPI_CLKDIV_PRE
:
clock_div
-
1
;
WRITE_PERI_REG
(
SPI_CLOCK
(
spi_no
),
((
clock_div
&
SPI_CLKDIV_PRE
)
<<
SPI_CLKDIV_PRE_S
)
|
((
1
&
SPI_CLKCNT_N
)
<<
SPI_CLKCNT_N_S
)
|
...
...
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