Skip to content

Commit 659e5b4

Browse files
committed
support for Pimoroni Badger2040W
1 parent 3c64b52 commit 659e5b4

File tree

9 files changed

+761
-0
lines changed

9 files changed

+761
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,6 @@
324324
path = ports/broadcom/peripherals
325325
url = https://github.com/adafruit/broadcom-peripherals.git
326326
branch = main-build
327+
[submodule "frozen/circuitpython-pcf85063a"]
328+
path = frozen/circuitpython-pcf85063a
329+
url = https://github.com/bablokb/circuitpython-pcf85063a

frozen/circuitpython-pcf85063a

Submodule circuitpython-pcf85063a added at 21baeb6
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef PIMORONI_BADGER2040W_SHARED
2+
#define PIMORONI_BADGER2040W_SHARED
3+
4+
#include "shared-bindings/digitalio/DigitalInOut.h"
5+
6+
extern digitalio_digitalinout_obj_t enable_pin_obj;
7+
8+
#endif // PIMORONI_BADGER2040W_SHARED
Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "supervisor/board.h"
28+
29+
#include "mpconfigboard.h"
30+
#include "shared-bindings/busio/SPI.h"
31+
#include "shared-bindings/displayio/FourWire.h"
32+
#include "shared-bindings/microcontroller/Pin.h"
33+
#include "shared-module/displayio/__init__.h"
34+
#include "supervisor/shared/board.h"
35+
#include "badger-shared.h"
36+
37+
digitalio_digitalinout_obj_t enable_pin_obj;
38+
39+
#define DELAY 0x80
40+
41+
enum reg {
42+
PSR = 0x00,
43+
PWR = 0x01,
44+
POF = 0x02,
45+
PFS = 0x03,
46+
PON = 0x04,
47+
PMES = 0x05,
48+
BTST = 0x06,
49+
DSLP = 0x07,
50+
DTM1 = 0x10,
51+
DSP = 0x11,
52+
DRF = 0x12,
53+
DTM2 = 0x13,
54+
LUT_VCOM = 0x20,
55+
LUT_WW = 0x21,
56+
LUT_BW = 0x22,
57+
LUT_WB = 0x23,
58+
LUT_BB = 0x24,
59+
PLL = 0x30,
60+
TSC = 0x40,
61+
TSE = 0x41,
62+
TSR = 0x43,
63+
TSW = 0x42,
64+
CDI = 0x50,
65+
LPD = 0x51,
66+
TCON = 0x60,
67+
TRES = 0x61,
68+
REV = 0x70,
69+
FLG = 0x71,
70+
AMV = 0x80,
71+
VV = 0x81,
72+
VDCS = 0x82,
73+
PTL = 0x90,
74+
PTIN = 0x91,
75+
PTOU = 0x92,
76+
PGM = 0xa0,
77+
APG = 0xa1,
78+
ROTP = 0xa2,
79+
CCSET = 0xe0,
80+
PWS = 0xe3,
81+
TSSET = 0xe5
82+
};
83+
84+
enum PSR_FLAGS {
85+
RES_96x230 = 0b00000000,
86+
RES_96x252 = 0b01000000,
87+
RES_128x296 = 0b10000000,
88+
RES_160x296 = 0b11000000,
89+
90+
LUT_OTP = 0b00000000,
91+
LUT_REG = 0b00100000,
92+
93+
FORMAT_BWR = 0b00000000,
94+
FORMAT_BW = 0b00010000,
95+
96+
SCAN_DOWN = 0b00000000,
97+
SCAN_UP = 0b00001000,
98+
99+
SHIFT_LEFT = 0b00000000,
100+
SHIFT_RIGHT = 0b00000100,
101+
102+
BOOSTER_OFF = 0b00000000,
103+
BOOSTER_ON = 0b00000010,
104+
105+
RESET_SOFT = 0b00000000,
106+
RESET_NONE = 0b00000001
107+
};
108+
109+
enum PWR_FLAGS_1 {
110+
VDS_EXTERNAL = 0b00000000,
111+
VDS_INTERNAL = 0b00000010,
112+
113+
VDG_EXTERNAL = 0b00000000,
114+
VDG_INTERNAL = 0b00000001
115+
};
116+
117+
enum PWR_FLAGS_2 {
118+
VCOM_VD = 0b00000000,
119+
VCOM_VG = 0b00000100,
120+
121+
VGHL_16V = 0b00000000,
122+
VGHL_15V = 0b00000001,
123+
VGHL_14V = 0b00000010,
124+
VGHL_13V = 0b00000011
125+
};
126+
127+
enum BOOSTER_FLAGS {
128+
START_10MS = 0b00000000,
129+
START_20MS = 0b01000000,
130+
START_30MS = 0b10000000,
131+
START_40MS = 0b11000000,
132+
133+
STRENGTH_1 = 0b00000000,
134+
STRENGTH_2 = 0b00001000,
135+
STRENGTH_3 = 0b00010000,
136+
STRENGTH_4 = 0b00011000,
137+
STRENGTH_5 = 0b00100000,
138+
STRENGTH_6 = 0b00101000,
139+
STRENGTH_7 = 0b00110000,
140+
STRENGTH_8 = 0b00111000,
141+
142+
OFF_0_27US = 0b00000000,
143+
OFF_0_34US = 0b00000001,
144+
OFF_0_40US = 0b00000010,
145+
OFF_0_54US = 0b00000011,
146+
OFF_0_80US = 0b00000100,
147+
OFF_1_54US = 0b00000101,
148+
OFF_3_34US = 0b00000110,
149+
OFF_6_58US = 0b00000111
150+
};
151+
152+
enum PFS_FLAGS {
153+
FRAMES_1 = 0b00000000,
154+
FRAMES_2 = 0b00010000,
155+
FRAMES_3 = 0b00100000,
156+
FRAMES_4 = 0b00110000
157+
};
158+
159+
enum TSE_FLAGS {
160+
TEMP_INTERNAL = 0b00000000,
161+
TEMP_EXTERNAL = 0b10000000,
162+
163+
OFFSET_0 = 0b00000000,
164+
OFFSET_1 = 0b00000001,
165+
OFFSET_2 = 0b00000010,
166+
OFFSET_3 = 0b00000011,
167+
OFFSET_4 = 0b00000100,
168+
OFFSET_5 = 0b00000101,
169+
OFFSET_6 = 0b00000110,
170+
OFFSET_7 = 0b00000111,
171+
172+
OFFSET_MIN_8 = 0b00001000,
173+
OFFSET_MIN_7 = 0b00001001,
174+
OFFSET_MIN_6 = 0b00001010,
175+
OFFSET_MIN_5 = 0b00001011,
176+
OFFSET_MIN_4 = 0b00001100,
177+
OFFSET_MIN_3 = 0b00001101,
178+
OFFSET_MIN_2 = 0b00001110,
179+
OFFSET_MIN_1 = 0b00001111
180+
};
181+
182+
enum PLL_FLAGS {
183+
// other frequency options exist but there doesn't seem to be much
184+
// point in including them - this is a fair range of options...
185+
HZ_29 = 0b00111111,
186+
HZ_33 = 0b00111110,
187+
HZ_40 = 0b00111101,
188+
HZ_50 = 0b00111100,
189+
HZ_67 = 0b00111011,
190+
HZ_100 = 0b00111010,
191+
HZ_200 = 0b00111001
192+
};
193+
194+
// This is an UC8151 control chip. The display is a 2.9" grayscale EInk.
195+
const uint8_t display_start_sequence[] = {
196+
PWR, 5, VDS_INTERNAL | VDG_INTERNAL, VCOM_VD | VGHL_16V, 0b101011, 0b101011, 0b101011, // power setting
197+
PON, DELAY, 200, // power on and wait 200 ms
198+
BTST, 3, (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US),
199+
PSR, 1, (RES_128x296 | LUT_REG | FORMAT_BW | SCAN_UP | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE),
200+
PFS, 1, FRAMES_1,
201+
TSE, 1, TEMP_INTERNAL | OFFSET_0,
202+
TCON, 1, 0x22, // tcon setting
203+
CDI, 1, 0b01001100, // vcom and data interval
204+
PLL, 1, HZ_100, // PLL set to 100 Hz
205+
206+
// Look up tables for voltage sequence for pixel transition
207+
// Common voltage
208+
LUT_VCOM, 44,
209+
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
210+
0x00, 0x23, 0x23, 0x00, 0x00, 0x02,
211+
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
212+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
213+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216+
0x00, 0x00,
217+
218+
// White to white
219+
LUT_WW, 42,
220+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
221+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
222+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
223+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227+
228+
// Black to white
229+
LUT_BW, 42,
230+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
231+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
232+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
233+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237+
238+
// White to black
239+
LUT_WB, 42,
240+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
241+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
242+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
243+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247+
248+
// Black to black
249+
LUT_BB, 42,
250+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
251+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
252+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
253+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257+
};
258+
259+
const uint8_t display_stop_sequence[] = {
260+
POF, 0x00 // Power off
261+
};
262+
263+
const uint8_t refresh_sequence[] = {
264+
DRF, 0x00
265+
};
266+
267+
void board_init(void) {
268+
// Drive the EN_3V3 pin high so the board stays awake on battery power
269+
enable_pin_obj.base.type = &digitalio_digitalinout_type;
270+
common_hal_digitalio_digitalinout_construct(&enable_pin_obj, &pin_GPIO10);
271+
common_hal_digitalio_digitalinout_switch_to_output(&enable_pin_obj, true, DRIVE_MODE_PUSH_PULL);
272+
273+
// Never reset
274+
common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj);
275+
276+
// Set up the SPI object used to control the display
277+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
278+
common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false);
279+
common_hal_busio_spi_never_reset(spi);
280+
281+
// Set up the DisplayIO pin object
282+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
283+
bus->base.type = &displayio_fourwire_type;
284+
common_hal_displayio_fourwire_construct(bus,
285+
spi,
286+
&pin_GPIO20, // EPD_DC Command or data
287+
&pin_GPIO17, // EPD_CS Chip select
288+
&pin_GPIO21, // EPD_RST Reset
289+
1200000, // Baudrate
290+
0, // Polarity
291+
0); // Phase
292+
293+
// Set up the DisplayIO epaper object
294+
displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display;
295+
display->base.type = &displayio_epaperdisplay_type;
296+
common_hal_displayio_epaperdisplay_construct(
297+
display,
298+
bus,
299+
display_start_sequence, sizeof(display_start_sequence),
300+
0, // start up time
301+
display_stop_sequence, sizeof(display_stop_sequence),
302+
296, // width
303+
128, // height
304+
160, // ram_width
305+
296, // ram_height
306+
0, // colstart
307+
0, // rowstart
308+
270, // rotation
309+
NO_COMMAND, // set_column_window_command
310+
NO_COMMAND, // set_row_window_command
311+
NO_COMMAND, // set_current_column_command
312+
NO_COMMAND, // set_current_row_command
313+
DTM2, // write_black_ram_command
314+
true, // black_bits_inverted
315+
DTM1, // write_color_ram_command
316+
false, // color_bits_inverted
317+
0x000000, // highlight_color
318+
refresh_sequence, sizeof(refresh_sequence), // refresh_display_command
319+
1.0, // refresh_time
320+
&pin_GPIO26, // busy_pin
321+
false, // busy_state
322+
2.0, // seconds_per_frame
323+
false, // always_toggle_chip_select
324+
false, // grayscale
325+
false, // acep
326+
false); // two_byte_sequence_length
327+
}
328+
329+
void board_deinit(void) {
330+
displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display;
331+
if (display->base.type == &displayio_epaperdisplay_type) {
332+
size_t i = 0;
333+
while (common_hal_displayio_epaperdisplay_get_busy(display)) {
334+
RUN_BACKGROUND_TASKS;
335+
i++;
336+
}
337+
}
338+
common_hal_displayio_release_displays();
339+
}
340+
341+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)