Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
bd925b59
Commit
bd925b59
authored
Oct 04, 2016
by
Damien George
Browse files
stmhal/spi: Enable use of fast software SPI.
parent
b0eb0d61
Changes
2
Hide whitespace changes
Inline
Side-by-side
stmhal/mpconfigport.h
View file @
bd925b59
...
...
@@ -94,6 +94,7 @@
#define MICROPY_PY_MACHINE (1)
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
...
...
stmhal/spi.c
View file @
bd925b59
...
...
@@ -944,17 +944,28 @@ STATIC MP_DEFINE_CONST_DICT(machine_spi_locals_dict, machine_spi_locals_dict_tab
/* code for soft implementation ***********************************************/
// for the software SPI implementation, this is roughly the max baudrate
#define MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
STATIC
uint32_t
baudrate_from_delay_half
(
uint32_t
delay_half
)
{
return
500000
/
delay_half
;
if
(
delay_half
==
MICROPY_PY_MACHINE_SPI_MIN_DELAY
)
{
return
MAX_BAUDRATE
;
}
else
{
return
500000
/
delay_half
;
}
}
STATIC
uint32_t
baudrate_to_delay_half
(
uint32_t
baudrate
)
{
uint32_t
delay_half
=
500000
/
baudrate
;
// round delay_half up so that: actual_baudrate <= requested_baudrate
if
(
500000
%
baudrate
!=
0
)
{
delay_half
+=
1
;
if
(
baudrate
>=
MAX_BAUDRATE
)
{
return
MICROPY_PY_MACHINE_SPI_MIN_DELAY
;
}
else
{
uint32_t
delay_half
=
500000
/
baudrate
;
// round delay_half up so that: actual_baudrate <= requested_baudrate
if
(
500000
%
baudrate
!=
0
)
{
delay_half
+=
1
;
}
return
delay_half
;
}
return
delay_half
;
}
STATIC
void
machine_soft_spi_print
(
const
mp_print_t
*
print
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
...
...
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