Skip to content

Commit b0861ec

Browse files
committed
Initial board declarations for Thumby
1 parent 31a1266 commit b0861ec

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Cooper Dalrymple
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
10+
#include "shared-bindings/busio/SPI.h"
11+
#include "shared-bindings/fourwire/FourWire.h"
12+
#include "shared-bindings/microcontroller/Pin.h"
13+
#include "shared-module/displayio/__init__.h"
14+
#include "shared-module/displayio/mipi_constants.h"
15+
#include "shared-bindings/board/__init__.h"
16+
17+
18+
uint8_t display_init_sequence[] = {
19+
/*
20+
0, 0xae, // display off
21+
0xd5, 0, 0x80, // set display clock div
22+
0, 0xd3, 0, 0x00, // set display offset
23+
0, 0x40, // set start line
24+
0, 0xa4, // display all on, resume
25+
0, 0xa6, // normal display
26+
0, 0x8d, 0, 0x14, // charge pump
27+
0, 0x20, 0, 0x00, // memory mode
28+
0, 0xa0, // segremap
29+
0, 0xc0, // com scan increment
30+
0, 0x81, 0, 0xff, // set contrast
31+
0, 0xd9, 0, 0xf1, // set precharge
32+
0, 0xd8, 0, 0x20, // set v com detect
33+
0, 0xa8, 0, 40-1, // set multiplex
34+
0, 0xda, 0, 0x12, // set com pins
35+
0, 0xad, 0, 0x30,
36+
0, 0xaf, // on
37+
*/
38+
39+
0xae, 0, // sleep
40+
0xd5, 1, 0x80, // fOsc divide by 2
41+
0xd3, 1, 0x00, // set display offset
42+
0x40, 1, 0x00, // set start line
43+
0xa4, 0, // display all on, resume
44+
0xa6, 0, // normal display
45+
0x8d, 1, 0x14, // charge pump
46+
0x20, 1, 0x00, // memory mode
47+
0xa0, 0, // segremap
48+
0xc0, 0, // com scan increment
49+
0x81, 1, 0xff, // set contrast
50+
0xd9, 1, 0xf1, // set precharge
51+
0xd8, 1, 0x20, // set v com detect
52+
0xa8, 1, 40-1, // set multiplex
53+
0xda, 1, 0x12, // set com pins
54+
0xad, 1, 0x30,
55+
0xaf, 0, // on
56+
};
57+
58+
void board_init(void) {
59+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
60+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
61+
bus->base.type = &fourwire_fourwire_type;
62+
common_hal_fourwire_fourwire_construct(bus,
63+
spi,
64+
CIRCUITPY_BOARD_OLED_DC, // Command or data
65+
CIRCUITPY_BOARD_OLED_CS, // Chip select
66+
CIRCUITPY_BOARD_OLED_RESET, // Reset
67+
10000000, // Baudrate
68+
0, // Polarity
69+
0); // Phase
70+
71+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
72+
display->base.type = &busdisplay_busdisplay_type;
73+
common_hal_busdisplay_busdisplay_construct(
74+
display,
75+
bus,
76+
72, // Width (after rotation)
77+
40, // Height (after rotation)
78+
28, // column start
79+
0, // row start
80+
0, // rotation
81+
1, // Color depth
82+
true, // grayscale
83+
false, // pixels in byte share row. only used for depth < 8
84+
1, // bytes per cell. Only valid for depths < 8
85+
false, // reverse_pixels_in_byte. Only valid for depths < 8
86+
true, // reverse_pixels_in_word
87+
0, // Set column command
88+
0, // Set row command
89+
0, // Write memory command
90+
display_init_sequence,
91+
sizeof(display_init_sequence),
92+
NULL, // backlight pin
93+
0x81,
94+
1.0f, // brightness
95+
true, // single_byte_bounds
96+
true, // data_as_commands
97+
true, // auto_refresh
98+
60, // native_frames_per_second
99+
true, // backlight_on_high
100+
true, // SH1107_addressing
101+
50000); // backlight pwm frequency
102+
}
103+
104+
void reset_board(void) {
105+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Cooper Dalrymple
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#define MICROPY_HW_BOARD_NAME "TinyCircuits Thumby"
10+
#define MICROPY_HW_MCU_NAME "rp2040"
11+
12+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO18)
13+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO19)
14+
15+
#define CIRCUITPY_BOARD_OLED_DC (&pin_GPIO17)
16+
#define CIRCUITPY_BOARD_OLED_CS (&pin_GPIO16)
17+
#define CIRCUITPY_BOARD_OLED_RESET (&pin_GPIO20)
18+
19+
#define CIRCUITPY_BOARD_SPI (1)
20+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = DEFAULT_SPI_BUS_SCK, .mosi = DEFAULT_SPI_BUS_MOSI, .miso = NULL }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
USB_VID = 0x1D6B
2+
USB_PID = 0x0003
3+
USB_PRODUCT = "Thumby"
4+
USB_MANUFACTURER = "TinyCircuits"
5+
6+
CHIP_VARIANT = RP2040
7+
CHIP_FAMILY = rp2
8+
9+
EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
10+
11+
CIRCUITPY_STAGE = 1
12+
CIRCUITPY_AUDIOIO = 1
13+
CIRCUITPY_AUDIOPWMIO = 1
14+
CIRCUITPY_KEYPAD = 1
15+
16+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_framebuf
17+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SSD1306
18+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DisplayIO_SSD1306
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Put board-specific pico-sdk definitions here. This file must exist.
10+
11+
// Allow extra time for xosc to start.
12+
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2025 Cooper Dalrymple
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/board/__init__.h"
8+
#include "shared-module/displayio/__init__.h"
9+
10+
static const mp_rom_map_elem_t board_module_globals_table[] = {
11+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
12+
13+
// Link Cable (ASR00074)
14+
{ MP_ROM_QSTR(MP_QSTR_EXT_TX), MP_ROM_PTR(&pin_GPIO0) },
15+
{ MP_ROM_QSTR(MP_QSTR_EXT), MP_ROM_PTR(&pin_GPIO1) },
16+
{ MP_ROM_QSTR(MP_QSTR_EXT_PU), MP_ROM_PTR(&pin_GPIO1) },
17+
18+
// 0.42 inch OLED AST1042
19+
{ MP_ROM_QSTR(MP_QSTR_OLED_CS), MP_ROM_PTR(&pin_GPIO16) },
20+
{ MP_ROM_QSTR(MP_QSTR_OLED_DC), MP_ROM_PTR(&pin_GPIO17) },
21+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) },
22+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO19) },
23+
{ MP_ROM_QSTR(MP_QSTR_OLED_RESET), MP_ROM_PTR(&pin_GPIO20) },
24+
25+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
26+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
27+
28+
// Buttons
29+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_LEFT), MP_ROM_PTR(&pin_GPIO3) },
30+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_UP), MP_ROM_PTR(&pin_GPIO4) },
31+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_RIGHT), MP_ROM_PTR(&pin_GPIO5) },
32+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_DOWN), MP_ROM_PTR(&pin_GPIO6) },
33+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_1), MP_ROM_PTR(&pin_GPIO24) },
34+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_2), MP_ROM_PTR(&pin_GPIO27) },
35+
36+
// Mono PWM Speaker
37+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO28) },
38+
39+
// Hardware revision ID pins
40+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ID3), MP_ROM_PTR(&pin_GPIO12) },
41+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ID2), MP_ROM_PTR(&pin_GPIO13) },
42+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ID1), MP_ROM_PTR(&pin_GPIO14) },
43+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ID0), MP_ROM_PTR(&pin_GPIO15) },
44+
45+
// Power pins
46+
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO26) }
47+
};
48+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)