aboutsummaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorDamien George2016-10-04 13:43:02 +1100
committerDamien George2016-10-04 13:43:02 +1100
commitb932b2dd1faaf3091b13af7d213041a737e40fac (patch)
tree2428ebf68a48aebdb1d55ce800e557e37f45d13b /extmod
parent9f1e395c167648d1b7fef1175290b0047ee6e1f4 (diff)
extmod/machine_spi: Use delay_half, not baudrate, for internal timing.
The delay_half parameter must be specified by the port to set up the timing of the software SPI. This allows the port to adjust the timing value to better suit its timing characteristics, as well as provide a more accurate printing of the baudrate.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/machine_spi.c4
-rw-r--r--extmod/machine_spi.h2
2 files changed, 4 insertions, 2 deletions
diff --git a/extmod/machine_spi.c b/extmod/machine_spi.c
index 3a34b7fb0..b0bd76faf 100644
--- a/extmod/machine_spi.c
+++ b/extmod/machine_spi.c
@@ -34,8 +34,10 @@
void mp_machine_soft_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t*)self_in;
+ uint32_t delay_half = self->delay_half;
+
// only MSB transfer is implemented
- uint32_t delay_half = 500000 / self->baudrate + 1;
+
for (size_t i = 0; i < len; ++i) {
uint8_t data_out = src[i];
uint8_t data_in = 0;
diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h
index e1922c6e8..316d06646 100644
--- a/extmod/machine_spi.h
+++ b/extmod/machine_spi.h
@@ -37,7 +37,7 @@ typedef struct _mp_machine_spi_p_t {
typedef struct _mp_machine_soft_spi_obj_t {
mp_obj_base_t base;
- uint32_t baudrate;
+ uint32_t delay_half; // microsecond delay for half SCK period
uint8_t polarity;
uint8_t phase;
mp_hal_pin_obj_t sck;