diff options
author | Damien George <damien.p.george@gmail.com> | 2016-10-04 13:51:30 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-10-04 13:51:30 +1100 |
commit | bd925b59c3177542fa69c3c95f9f1a40ced18039 (patch) | |
tree | 903a3a3a88ac50ef592c1a4c6eaf1b00b6493ea9 /stmhal | |
parent | b0eb0d6153d63cf823065792db35d2858fbb9406 (diff) | |
download | micropython-bd925b59c3177542fa69c3c95f9f1a40ced18039.tar.gz micropython-bd925b59c3177542fa69c3c95f9f1a40ced18039.zip |
stmhal/spi: Enable use of fast software SPI.
Diffstat (limited to 'stmhal')
-rw-r--r-- | stmhal/mpconfigport.h | 1 | ||||
-rw-r--r-- | stmhal/spi.c | 23 |
2 files changed, 18 insertions, 6 deletions
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 98d1e17e3d..aff13f329b 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -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) diff --git a/stmhal/spi.c b/stmhal/spi.c index 8ec6f86275..7f805709d6 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -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) { |