8000 Merge pull request #4949 from pewpew-game/macropad-oled · domdfcoding/circuitpython@826e259 · GitHub
[go: up one dir, main page]

Skip to content

Commit 826e259

Browse files
authored
Merge pull request adafruit#4949 from pewpew-game/macropad-oled
MacroPad RP2040: Add initialization for the OLED display
2 parents 176c5c5 + b8c4f7d commit 826e259

File tree

2 files changed

+78
-2
lines changed
8000

2 files changed

+78
-2
lines changed

ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,86 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "supervisor/board.h"
28-
27+
#include "shared-bindings/board/__init__.h"
28+
#include "shared-bindings/displayio/FourWire.h"
29+
#include "shared-module/displayio/__init__.h"
30+
#include "shared-module/displayio/mipi_constants.h"
31+
#include "shared-bindings/busio/SPI.h"
2932
#include "shared-bindings/microcontroller/Pin.h"
3033
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
3134
#include "supervisor/shared/board.h"
3235

36+
displayio_fourwire_obj_t board_display_obj;
37+
38+
#define DELAY 0x80
39+
40+
uint8_t display_init_sequence[] = {
41+
0xae, 0, // sleep
42+
0xd5, 1, 0x80, // fOsc divide by 2
43+
0xa8, 1, 0x3f, // multiplex 64
44+
0xd3, 1, 0x00, // offset 0
45+
0x40, 1, 0x00, // start line 0
46+
0xad, 1, 0x8b, // dc/dc on
47+
0xa1, 0, // segment remap = 0
48+
0xc8, 0, // scan incr
49+
0xda, 1, 0x12, // com pins
50+
0x81, 1, 0xff, // contrast 255
51+
0xd9, 1, 0x1f, // pre/dis-charge 2DCLKs/2CLKs
52+
0xdb, 1, 0x20, // VCOM deslect 0.770
53+
0x20, 1, 0x20,
54+
0x33, 0, // VPP 9V
55+
0xa6, 0, // not inverted
56+
0xa4, 0, // normal
57+
0xaf, 0, // on
58+
};
59+
3360
void board_init(void) {
61+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
62+
common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL);
63+
common_hal_busio_spi_never_reset(spi);
64+
65+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
66+
bus->base.type = &displayio_fourwire_type;
67+
common_hal_displayio_fourwire_construct(bus,
68+
spi,
69+
&pin_GPIO24, // Command or data
70+
&pin_GPIO22, // Chip select
71+
&pin_GPIO23, // Reset
72+
1000000, // Baudrate
73+
0, // Polarity
74+
0); // Phase
75+
76+
displayio_display_obj_t *display = &displays[0].display;
77+
display->base.type = &displayio_display_type;
78+
common_hal_displayio_display_construct(display,
79+
bus,
80+
128, // Width
81+
64, // Height
82+
2, // column start
83+
0, // row start
84+
0, // rotation
85+
1, // Color depth
86+
true, // grayscale
87+
false, // pixels in byte share row. Only used with depth < 8
88+
1, // bytes per cell. Only valid for depths < 8
89+
false, // reverse_pixels_in_byte. Only valid for depths < 8
90+
true, // reverse_pixels_in_word
91+
0, // Set column command
92+
0, // Set row command
93+
0, // Write memory command
94+
0xd3, // set vertical scroll command
95+
display_init_sequence,
96+
sizeof(display_init_sequence),
97+
NULL,
98+
0x81,
99+
1.0f, // brightness
100+
false, // auto_brightness
101+
true, // single_byte_bounds
102+
true, // data as commands
103+
true, // auto_refresh
104+
60, // native_frames_per_second
105+
true, // backlight_on_high
106+
true); // SH1107_addressing
34107
}
35108

36109
bool board_requests_safe_mode(void) {

ports/raspberrypi/boards/adafruit_macropad_rp2040/pins.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
23

34
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
45
{ MP_ROM_QSTR(MP_QSTR_KEY1), MP_ROM_PTR(&pin_GPIO1) },
@@ -43,5 +44,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
4344

4445
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
4546
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_i2c_obj) },
47+
48+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
4649
};
4750
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

0 commit comments

Comments
 (0)
0