Skip to content

Commit 8581ee3

Browse files
authored
Merge pull request #844 from matt-land/feature-default-spi-circuit-playground
Feature: 'default' SPI support for atmel-samd boards
2 parents 91db71e + c846f4b commit 8581ee3

File tree

37 files changed

+113
-4
lines changed

37 files changed

+113
-4
lines changed

ports/atmel-samd/board_busses.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include "shared-bindings/busio/I2C.h"
28+
#include "shared-bindings/busio/SPI.h"
2829
#include "shared-bindings/microcontroller/Pin.h"
2930
#include "mpconfigboard.h"
3031
#include "pins.h"
@@ -60,3 +61,30 @@
6061
#endif
6162

6263
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
64+
65+
#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
66+
STATIC mp_obj_t board_spi(void) {
67+
mp_raise_NotImplementedError("No default SPI bus");
68+
return NULL;
69+
}
70+
#else
71+
STATIC mp_obj_t spi_singleton = NULL;
72+
73+
STATIC mp_obj_t board_spi(void) {
74+
75+
if (spi_singleton == NULL) {
76+
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
77+
self->base.type = &busio_spi_type;
78+
assert_pin_free(DEFAULT_SPI_BUS_SCK);
79+
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
80+
assert_pin_free(DEFAULT_SPI_BUS_MISO);
81+
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
82+
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
83+
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
84+
common_hal_busio_spi_construct(self, clock, mosi, miso);
85+
spi_singleton = (mp_obj_t)self;
86+
}
87+
return spi_singleton;
88+
}
89+
#endif
90+
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);

ports/atmel-samd/board_busses.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@
3030
void board_i2c(void);
3131
extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
3232

33+
void board_spi(void);
34+
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
35+
3336
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H

ports/atmel-samd/boards/arduino_zero/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717

1818
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
1919
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
20+
21+
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
22+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
23+
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)

ports/atmel-samd/boards/arduino_zero/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
3333
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) },
3434
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) },
3535
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
36+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
3637
};
3738
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@
6161

6262
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
6363
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
64+
65+
#define DEFAULT_SPI_BUS_SCK (&pin_PA05)
66+
#define DEFAULT_SPI_BUS_MOSI (&pin_PA07)
67+
#define DEFAULT_SPI_BUS_MISO (&pin_PA06)

ports/atmel-samd/boards/circuitplayground_express/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
5858
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA07) },
5959
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) },
6060
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
61+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
6162
};
6263
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515

1616
#define DEFAULT_I2C_BUS_SCL (&pin_PA22)
1717
#define DEFAULT_I2C_BUS_SDA (&pin_PA23)
18+
19+
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
20+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
21+
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)

ports/atmel-samd/boards/feather_m0_adalogger/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
3232
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) },
3333
{ MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_PA17) },
3434
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
35+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
3536
};
3637
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616

1717
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
1818
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
19+
20+
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
21+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
22+
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)

ports/atmel-samd/boards/feather_m0_basic/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
2525
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) },
2626
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) },
2727
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
28+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
2829
};
2930
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

0 commit comments

Comments
 (0)