extmod/machine_spi: Make SoftSPI configurable via macro option.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-09-02 12:39:28 +10:00
parent 122d901ef1
commit afe0634c98
7 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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