Skip to content

Commit 1a4e1d1

Browse files
authored
Merge pull request #7916 from bablokb/badger_2040_w
Add support for Pimoroni Badger2040W
2 parents c5d3de2 + ec6fde9 commit 1a4e1d1

File tree

9 files changed

+468
-0
lines changed

9 files changed

+468
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,6 @@
335335
path = ports/raspberrypi/lib/PicoDVI
336336
url = https://github.com/circuitpython/PicoDVI.git
337337
branch = circuitpython
338+
[submodule "frozen/circuitpython-pcf85063a"]
339+
path = frozen/circuitpython-pcf85063a
340+
url = https://github.com/bablokb/circuitpython-pcf85063a

frozen/circuitpython-pcf85063a

Submodule circuitpython-pcf85063a added at 85aa931
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: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
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 "shared-bindings/board/__init__.h"
35+
#include "supervisor/shared/board.h"
36+
#include "badger-shared.h"
37+
38+
digitalio_digitalinout_obj_t enable_pin_obj;
39+
40+
#define DELAY 0x80
41+
42+
enum reg {
43+
PSR = 0x00,
44+
PWR = 0x01,
45+
POF = 0x02,
46+
PFS = 0x03,
47+
PON = 0x04,
48+
PMES = 0x05,
49+
BTST = 0x06,
50+
DSLP = 0x07,
51+
DTM1 = 0x10,
52+
DSP = 0x11,
53+
DRF = 0x12,
54+
DTM2 = 0x13,
55+
LUT_VCOM = 0x20,
56+
LUT_WW = 0x21,
57+
LUT_BW = 0x22,
58+
LUT_WB = 0x23,
59+
LUT_BB = 0x24,
60+
PLL = 0x30,
61+
TSC = 0x40,
62+
TSE = 0x41,
63+
TSR = 0x43,
64+
TSW = 0x42,
65+
CDI = 0x50,
66+
LPD = 0x51,
67+
TCON = 0x60,
68+
TRES = 0x61,
69+
REV = 0x70,
70+
FLG = 0x71,
71+
AMV = 0x80,
72+
VV = 0x81,
73+
VDCS = 0x82,
74+
PTL = 0x90,
75+
PTIN = 0x91,
76+
PTOU = 0x92,
77+
PGM = 0xa0,
78+
APG = 0xa1,
79+
ROTP = 0xa2,
80+
CCSET = 0xe0,
81+
PWS = 0xe3,
82+
TSSET = 0xe5
83+
};
84+
85+
enum PSR_FLAGS {
86+
RES_96x230 = 0b00000000,
87+
RES_96x252 = 0b01000000,
88+
RES_128x296 = 0b10000000,
89+
RES_160x296 = 0b11000000,
90+
91+
LUT_OTP = 0b00000000,
92+
LUT_REG = 0b00100000,
93+
94+
FORMAT_BWR = 0b00000000,
95+
FORMAT_BW = 0b00010000,
96+
97+
SCAN_DOWN = 0b00000000,
98+
SCAN_UP = 0b00001000,
99+
100+
SHIFT_LEFT = 0b00000000,
101+
SHIFT_RIGHT = 0b00000100,
102+
103+
BOOSTER_OFF = 0b00000000,
104+
BOOSTER_ON = 0b00000010,
105+
106+
RESET_SOFT = 0b00000000,
107+
RESET_NONE = 0b00000001
108+
};
109+
110+
enum PWR_FLAGS_1 {
111+
VDS_EXTERNAL = 0b00000000,
112+
VDS_INTERNAL = 0b00000010,
113+
114+
VDG_EXTERNAL = 0b00000000,
115+
VDG_INTERNAL = 0b00000001
116+
};
117+
118+
enum PWR_FLAGS_2 {
119+
VCOM_VD = 0b00000000,
120+
VCOM_VG = 0b00000100,
121+
122+
VGHL_16V = 0b00000000,
123+
VGHL_15V = 0b00000001,
124+
VGHL_14V = 0b00000010,
125+
VGHL_13V = 0b00000011
126+
};
127+
128+
enum BOOSTER_FLAGS {
129+
START_10MS = 0b00000000,
130+
START_20MS = 0b01000000,
131+
START_30MS = 0b10000000,
132+
START_40MS = 0b11000000,
133+
134+
STRENGTH_1 = 0b00000000,
135+
STRENGTH_2 = 0b00001000,
136+
STRENGTH_3 = 0b00010000,
137+
STRENGTH_4 = 0b00011000,
138+
STRENGTH_5 = 0b00100000,
139+
STRENGTH_6 = 0b00101000,
140+
STRENGTH_7 = 0b00110000,
141+
STRENGTH_8 = 0b00111000,
142+
143+
OFF_0_27US = 0b00000000,
144+
OFF_0_34US = 0b00000001,
145+
OFF_0_40US = 0b00000010,
146+
OFF_0_54US = 0b00000011,
147+
OFF_0_80US = 0b00000100,
148+
OFF_1_54US = 0b00000101,
149+
OFF_3_34US = 0b00000110,
150+
OFF_6_58US = 0b00000111
151+
};
152+
153+
enum PFS_FLAGS {
154+
FRAMES_1 = 0b00000000,
155+
FRAMES_2 = 0b00010000,
156+
FRAMES_3 = 0b00100000,
157+
FRAMES_4 = 0b00110000
158+
};
159+
160+
enum TSE_FLAGS {
161+
TEMP_INTERNAL = 0b00000000,
162+
TEMP_EXTERNAL = 0b10000000,
163+
164+
OFFSET_0 = 0b00000000,
165+
OFFSET_1 = 0b00000001,
166+
OFFSET_2 = 0b00000010,
167+
OFFSET_3 = 0b00000011,
168+
OFFSET_4 = 0b00000100,
169+
OFFSET_5 = 0b00000101,
170+
OFFSET_6 = 0b00000110,
171+
OFFSET_7 = 0b00000111,
172+
173+
OFFSET_MIN_8 = 0b00001000,
174+
OFFSET_MIN_7 = 0b00001001,
175+
OFFSET_MIN_6 = 0b00001010,
176+
OFFSET_MIN_5 = 0b00001011,
177+
OFFSET_MIN_4 = 0b00001100,
178+
OFFSET_MIN_3 = 0b00001101,
179+
OFFSET_MIN_2 = 0b00001110,
180+
OFFSET_MIN_1 = 0b00001111
181+
};
182+
183+
enum PLL_FLAGS {
184+
// other frequency options exist but there doesn't seem to be much
185+
// point in including them - this is a fair range of options...
186+
HZ_29 = 0b00111111,
187+
HZ_33 = 0b00111110,
188+
HZ_40 = 0b00111101,
189+
HZ_50 = 0b00111100,
190+
HZ_67 = 0b00111011,
191+
HZ_100 = 0b00111010,
192+
HZ_200 = 0b00111001
193+
};
194+
195+
// This is an UC8151 control chip. The display is a 2.9" grayscale EInk.
196+
const uint8_t display_start_sequence[] = {
197+
PWR, 5, VDS_INTERNAL | VDG_INTERNAL, VCOM_VD | VGHL_16V, 0b101011, 0b101011, 0b101011, // power setting
198+
PON, DELAY, 200, // power on and wait 200 ms
199+
BTST, 3, (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US),
200+
PSR, 1, (RES_128x296 | LUT_REG | FORMAT_BW | SCAN_UP | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE),
201+
PFS, 1, FRAMES_1,
202+
TSE, 1, TEMP_INTERNAL | OFFSET_0,
203+
TCON, 1, 0x22, // tcon setting
204+
CDI, 1, 0b01001100, // vcom and data interval
205+
PLL, 1, HZ_100, // PLL set to 100 Hz
206+
207+
// Look up tables for voltage sequence for pixel transition
208+
// Common voltage
209+
LUT_VCOM, 44,
210+
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
211+
0x00, 0x23, 0x23, 0x00, 0x00, 0x02,
212+
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
213+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
215+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
216+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217+
0x00, 0x00,
218+
219+
// White to white
220+
LUT_WW, 42,
221+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
222+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
223+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
224+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228+
229+
// Black to white
230+
LUT_BW, 42,
231+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
232+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
233+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
234+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238+
239+
// White to black
240+
LUT_WB, 42,
241+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
242+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
243+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
244+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248+
249+
// Black to black
250+
LUT_BB, 42,
251+
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
252+
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
253+
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
254+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258+
};
259+
260+
const uint8_t display_stop_sequence[] = {
261+
POF, 0x00 // Power off
262+
};
263+
264+
const uint8_t refresh_sequence[] = {
265+
DRF, 0x00
266+
};
267+
268+
void board_init(void) {
269+
// Drive the EN_3V3 pin high so the board stays awake on battery power
270+
enable_pin_obj.base.type = &digitalio_digitalinout_type;
271+
common_hal_digitalio_digitalinout_construct(&enable_pin_obj, &pin_GPIO10);
272+
common_hal_digitalio_digitalinout_switch_to_output(&enable_pin_obj, true, DRIVE_MODE_PUSH_PULL);
273+
274+
// Never reset
275+
common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj);
276+
277+
// Set up the SPI object used to control the display
278+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
279+
common_hal_busio_spi_never_reset(spi);
280+
281+
// Set up the DisplayIO pin object
282+
displayio_fourwire_obj_t *bus = &allocate_display_bus()->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 = &allocate_display()->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+
false); // address_little_endian
328+
}
329+
330+
void board_deinit(void) {
331+
displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display;
332+
if (display->base.type == &displayio_epaperdisplay_type) {
333+
while (common_hal_displayio_epaperdisplay_get_busy(display)) {
334+
RUN_BACKGROUND_TASKS;
335+
}
336+
}
337+
common_hal_displayio_release_displays();
338+
}
339+
340+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
firmware_size = 1532k;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#define MICROPY_HW_BOARD_NAME "Pimoroni Badger 2040 W"
2+
#define MICROPY_HW_MCU_NAME "rp2040"
3+
4+
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1)
5+
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1)
6+
7+
// Status LED
8+
#define MICROPY_HW_LED_STATUS (&pin_CYW0)
9+
10+
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)
11+
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
12+
13+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4)
14+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5)
15+
16+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO18)
17+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO19)
18+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO16)

0 commit comments

Comments
 (0)