summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extmod/machine_spi.c11
-rw-r--r--ports/esp32/mpconfigport.h1
-rw-r--r--ports/esp8266/mpconfigport.h1
-rw-r--r--ports/mimxrt/mpconfigport.h1
-rw-r--r--ports/rp2/mpconfigport.h1
-rw-r--r--ports/stm32/mpconfigport.h1
-rw-r--r--py/mpconfig.h5
7 files changed, 17 insertions, 4 deletions
diff --git a/extmod/machine_spi.c b/extmod/machine_spi.c
index c951a5137..ae5e6677d 100644
--- a/extmod/machine_spi.c
+++ b/extmod/machine_spi.c
@@ -30,8 +30,6 @@
#include "py/runtime.h"
#include "extmod/machine_spi.h"
-#if MICROPY_PY_MACHINE_SPI
-
// if a port didn't define MSB/LSB constants then provide them
#ifndef MICROPY_PY_MACHINE_SPI_MSB
#define MICROPY_PY_MACHINE_SPI_MSB (0)
@@ -41,6 +39,8 @@
/******************************************************************************/
// MicroPython bindings for generic machine.SPI
+#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI
+
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)s->type->protocol;
@@ -115,12 +115,15 @@ STATIC const mp_rom_map_elem_t machine_spi_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_MSB), MP_ROM_INT(MICROPY_PY_MACHINE_SPI_MSB) },
{ MP_ROM_QSTR(MP_QSTR_LSB), MP_ROM_INT(MICROPY_PY_MACHINE_SPI_LSB) },
};
-
MP_DEFINE_CONST_DICT(mp_machine_spi_locals_dict, machine_spi_locals_dict_table);
+#endif // MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI
+
/******************************************************************************/
// Implementation of soft SPI
+#if MICROPY_PY_MACHINE_SOFTSPI
+
STATIC uint32_t baudrate_from_delay_half(uint32_t delay_half) {
#ifdef MICROPY_HW_SOFTSPI_MIN_DELAY
if (delay_half == MICROPY_HW_SOFTSPI_MIN_DELAY) {
@@ -258,4 +261,4 @@ const mp_obj_type_t mp_machine_soft_spi_type = {
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
};
-#endif // MICROPY_PY_MACHINE_SPI
+#endif // MICROPY_PY_MACHINE_SOFTSPI
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index b9e133718..f8b26bfe8 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -163,6 +163,7 @@
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (0)
#define MICROPY_PY_MACHINE_SPI_LSB (1)
+#define MICROPY_PY_MACHINE_SOFTSPI (1)
#ifndef MICROPY_PY_MACHINE_DAC
#define MICROPY_PY_MACHINE_DAC (1)
#endif
diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h
index 4e234683b..5364dd58b 100644
--- a/ports/esp8266/mpconfigport.h
+++ b/ports/esp8266/mpconfigport.h
@@ -84,6 +84,7 @@
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SOFTI2C (1)
#define MICROPY_PY_MACHINE_SPI (1)
+#define MICROPY_PY_MACHINE_SOFTSPI (1)
#define MICROPY_PY_UWEBSOCKET (1)
#define MICROPY_PY_WEBREPL (1)
#define MICROPY_PY_WEBREPL_DELAY (20)
diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h
index 76716f705..88e1872cf 100644
--- a/ports/mimxrt/mpconfigport.h
+++ b/ports/mimxrt/mpconfigport.h
@@ -128,6 +128,7 @@ uint32_t trng_random_u32(void);
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_SOFTI2C (1)
#define MICROPY_PY_MACHINE_SPI (1)
+#define MICROPY_PY_MACHINE_SOFTSPI (1)
#define MICROPY_PY_FRAMEBUF (1)
// Use VfsLfs2's types for fileio/textio
diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h
index 04a2e4816..ad3de396b 100644
--- a/ports/rp2/mpconfigport.h
+++ b/ports/rp2/mpconfigport.h
@@ -136,6 +136,7 @@
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_MSB_FIRST)
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_LSB_FIRST)
+#define MICROPY_PY_MACHINE_SOFTSPI (1)
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_LFS2 (1)
diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h
index e2863f192..eff90cb25 100644
--- a/ports/stm32/mpconfigport.h
+++ b/ports/stm32/mpconfigport.h
@@ -205,6 +205,7 @@
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
+#define MICROPY_PY_MACHINE_SOFTSPI (1)
#endif
#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (HAL_RCC_GetSysClockFreq() / 48)
diff --git a/py/mpconfig.h b/py/mpconfig.h
index cc302c3cb..288b10537 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1494,6 +1494,11 @@ typedef double mp_float_t;
#define MICROPY_PY_MACHINE_SPI (0)
#endif
+// Whether to provide the "machine.SoftSPI" class
+#ifndef MICROPY_PY_MACHINE_SOFTSPI
+#define MICROPY_PY_MACHINE_SOFTSPI (0)
+#endif
+
#ifndef MICROPY_PY_USSL
#define MICROPY_PY_USSL (0)
// Whether to add finaliser code to ussl objects