pin issue
This commit is contained in:
parent
fbb57f902d
commit
8d1d821876
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "mpconfigboard.h"
|
||||
#include "pins.h"
|
||||
@ -60,3 +61,30 @@
|
||||
#endif
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
|
||||
|
||||
#if !defined(DEFAULT_SPI_BUS_CLK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
|
||||
STATIC mp_obj_t board_spi(void) {
|
||||
mp_raise_NotImplementedError("No default SPI bus");
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
STATIC mp_obj_t spi_singleton = NULL;
|
||||
|
||||
STATIC mp_obj_t board_spi(void) {
|
||||
|
||||
if (spi_singleton == NULL) {
|
||||
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
|
||||
self->base.type = &busio_spi_type;
|
||||
assert_pin_free(DEFAULT_SPI_BUS_CLK);
|
||||
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
|
||||
assert_pin_free(DEFAULT_SPI_BUS_MISO);
|
||||
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_CLK);
|
||||
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
|
||||
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
|
||||
common_hal_busio_spi_construct(self, clock, mosi, miso);
|
||||
spi_singleton = (mp_obj_t)self;
|
||||
}
|
||||
return spi_singleton;
|
||||
}
|
||||
#endif
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
|
||||
|
@ -30,4 +30,7 @@
|
||||
void board_i2c(void);
|
||||
extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
|
||||
|
||||
void board_spi(void);
|
||||
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H
|
||||
|
@ -61,3 +61,7 @@
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
||||
|
||||
#define DEFAULT_SPI_BUS_CLK (&pin_PA21)
|
||||
#define DEFAULT_SPI_BUS_MISO (&pin_PA16)
|
||||
#define DEFAULT_SPI_BUS_MOSI (&pin_PA20)
|
||||
|
@ -58,5 +58,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
|
||||
|
Loading…
Reference in New Issue
Block a user