Skip to content

Commit 11727bd

Browse files
authored
Merge pull request #10727 from dhalbert/hack-club-sprig-board-spi
hack_club_sprig: add board.SPI() for display and SD card use
2 parents 1d13e30 + c5a28aa commit 11727bd

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

ports/raspberrypi/boards/hack_club_sprig/board.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "shared-bindings/fourwire/FourWire.h"
1111
#include "shared-module/displayio/__init__.h"
1212
#include "shared-module/displayio/mipi_constants.h"
13-
#include "supervisor/shared/board.h"
13+
#include "shared-bindings/board/__init__.h"
1414

1515

1616
// display init sequence from CircuitPython library https://github.com/adafruit/Adafruit_CircuitPython_ST7735R/blob/dfae353330cf051d1f31db9e4b681c8d70900cc5/adafruit_st7735r.py
@@ -57,17 +57,14 @@ uint8_t display_init_sequence[] = {
5757

5858

5959
void board_init(void) {
60+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
6061
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
61-
busio_spi_obj_t *spi = &bus->inline_bus;
62-
common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false);
63-
common_hal_busio_spi_never_reset(spi);
64-
6562
bus->base.type = &fourwire_fourwire_type;
6663
common_hal_fourwire_fourwire_construct(bus,
6764
spi,
68-
&pin_GPIO22, // DC
69-
&pin_GPIO20, // CS
70-
&pin_GPIO26, // RST
65+
CIRCUITPY_BOARD_TFT_DC,
66+
CIRCUITPY_BOARD_TFT_CS,
67+
CIRCUITPY_BOARD_TFT_RESET,
7168
30000000,
7269
0,
7370
0);
@@ -92,7 +89,7 @@ void board_init(void) {
9289
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
9390
display_init_sequence,
9491
sizeof(display_init_sequence),
95-
&pin_GPIO17, // backlight pin
92+
CIRCUITPY_BOARD_TFT_BACKLIGHT,
9693
NO_BRIGHTNESS_COMMAND,
9794
1.0f, // brightness
9895
false, // single_byte_bounds
@@ -104,4 +101,8 @@ void board_init(void) {
104101
50000); // backlight pwm frequency
105102
}
106103

104+
void board_deinit(void) {
105+
common_hal_displayio_release_displays();
106+
}
107+
107108
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/raspberrypi/boards/hack_club_sprig/mpconfigboard.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@
1010
#define MICROPY_HW_MCU_NAME "rp2040"
1111

1212
#define MICROPY_HW_LED_STATUS (&pin_GPIO4)
13+
14+
#define CIRCUITPY_BOARD_TFT_DC (&pin_GPIO22)
15+
#define CIRCUITPY_BOARD_TFT_CS (&pin_GPIO20)
16+
#define CIRCUITPY_BOARD_TFT_RESET (&pin_GPIO26)
17+
#define CIRCUITPY_BOARD_TFT_BACKLIGHT (&pin_GPIO17)
18+
19+
#define CIRCUITPY_BOARD_SPI (1)
20+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO19, .miso = &pin_GPIO16 }}

ports/raspberrypi/boards/hack_club_sprig/pins.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
6060
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
6161
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) },
6262

63-
6463
// Start Sprig-specific definitions
6564

6665
{ MP_ROM_QSTR(MP_QSTR_BLUE_LED), MP_ROM_PTR(&pin_GPIO4) },
@@ -79,18 +78,23 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
7978
{ MP_ROM_QSTR(MP_QSTR_BUTTON_K), MP_ROM_PTR(&pin_GPIO14) },
8079
{ MP_ROM_QSTR(MP_QSTR_BUTTON_L), MP_ROM_PTR(&pin_GPIO15) },
8180

82-
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO16) },
83-
{ MP_ROM_QSTR(MP_QSTR_TFT_LITE), MP_ROM_PTR(&pin_GPIO17) },
8481
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) },
8582
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO19) },
86-
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO20) },
83+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO16) },
84+
8785
{ MP_ROM_QSTR(MP_QSTR_CARD_CS), MP_ROM_PTR(&pin_GPIO21) },
88-
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO22) },
89-
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO23) },
86+
87+
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(CIRCUITPY_BOARD_TFT_DC) },
88+
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(CIRCUITPY_BOARD_TFT_CS) },
89+
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(CIRCUITPY_BOARD_TFT_RESET) },
90+
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(CIRCUITPY_BOARD_TFT_BACKLIGHT) },
91+
{ MP_ROM_QSTR(MP_QSTR_TFT_LITE), MP_ROM_PTR(CIRCUITPY_BOARD_TFT_BACKLIGHT) },
92+
9093

9194
{ MP_ROM_QSTR(MP_QSTR_WHITE_LED), MP_ROM_PTR(&pin_GPIO28) },
9295

9396
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
9497

98+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
9599
};
96100
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)