Skip to content

Commit 2a0c7ba

Browse files
committed
working epd, proper pin definitions
1 parent 254f8ef commit 2a0c7ba

File tree

5 files changed

+274
-0
lines changed

5 files changed

+274
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
#include "shared-bindings/busio/SPI.h"
10+
#include "shared-bindings/fourwire/FourWire.h"
11+
#include "shared-bindings/microcontroller/Pin.h"
12+
#include "shared-module/displayio/__init__.h"
13+
#include "shared-module/displayio/mipi_constants.h"
14+
#include "shared-bindings/board/__init__.h"
15+
#include "shared-bindings/digitalio/DigitalInOut.h"
16+
17+
const uint8_t display_start_sequence[] = {
18+
0x04, 0x80, 0xc8, // power on
19+
0x00, 0x01, 0x1f, // panel setting
20+
0x50, 0x01, 0x97, // CDI setting
21+
22+
// common voltage
23+
0x20, 0x2a,
24+
0x00, 0x0A, 0x00, 0x00, 0x00, 0x01,
25+
0x60, 0x14, 0x14, 0x00, 0x00, 0x01,
26+
0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
27+
0x00, 0x13, 0x0A, 0x01, 0x00, 0x01,
28+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31+
// White to White
32+
0x21, 0x2a,
33+
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
34+
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
35+
0x10, 0x14, 0x0A, 0x00, 0x00, 0x01,
36+
0xA0, 0x13, 0x01, 0x00, 0x00, 0x01,
37+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40+
// Black to White
41+
0x22, 0x2a,
42+
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
43+
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
44+
0x00, 0x14, 0x0A, 0x00, 0x00, 0x01,
45+
0x99, 0x0B, 0x04, 0x04, 0x01, 0x01,
46+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49+
// White to Black
50+
0x23, 0x2a,
51+
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
52+
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
53+
0x00, 0x14, 0x0A, 0x00, 0x00, 0x01,
54+
0x99, 0x0C, 0x01, 0x03, 0x04, 0x01,
55+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58+
// Black to Black
59+
0x24, 0x2a,
60+
0x80, 0x0A, 0x00, 0x00, 0x00, 0x01,
61+
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
62+
0x20, 0x14, 0x0A, 0x00, 0x00, 0x01,
63+
0x50, 0x13, 0x01, 0x00, 0x00, 0x01,
64+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67+
};
68+
69+
const uint8_t display_stop_sequence[] = {
70+
0x50, 0x01, 0xf7,
71+
0x07, 0x01, 0xa5,
72+
};
73+
74+
const uint8_t refresh_sequence[] = {
75+
0x12,
76+
};
77+
78+
void board_init(void) {
79+
80+
// Set vext on (active low) to enable EPD
81+
digitalio_digitalinout_obj_t vext_pin_obj;
82+
vext_pin_obj.base.type = &digitalio_digitalinout_type;
83+
common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO45);
84+
common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, false, DRIVE_MODE_PUSH_PULL);
85+
common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj);
86+
87+
// Set up the SPI object used to control the display
88+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
89+
busio_spi_obj_t *spi = &bus->inline_bus;
90+
common_hal_busio_spi_construct(spi, &pin_GPIO3, &pin_GPIO2, NULL, false);
91+
common_hal_busio_spi_never_reset(spi);
92+
93+
// Set up the DisplayIO pin object
94+
bus->base.type = &fourwire_fourwire_type;
95+
common_hal_fourwire_fourwire_construct(bus,
96+
spi,
97+
&pin_GPIO5, // EPD_DC Command or data
98+
&pin_GPIO4, // EPD_CS Chip select
99+
&pin_GPIO6, // EPD_RST Reset
100+
1000000, // Baudrate
101+
0, // Polarity
102+
0); // Phase
103+
104+
// Set up the DisplayIO epaper object
105+
epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display;
106+
display->base.type = &epaperdisplay_epaperdisplay_type;
107+
common_hal_epaperdisplay_epaperdisplay_construct(
108+
display,
109+
bus,
110+
display_start_sequence, sizeof(display_start_sequence),
111+
0, // start up time
112+
display_stop_sequence, sizeof(display_stop_sequence),
113+
250, // width
114+
122, // height
115+
128, // ram_width
116+
296, // ram_height
117+
0, // colstart
118+
0, // rowstart
119+
270, // rotation
120+
NO_COMMAND, // set_column_window_command
121+
NO_COMMAND, // set_row_window_command
122+
NO_COMMAND, // set_current_column_command
123+
NO_COMMAND, // set_current_row_command
124+
0x13, // write_black_ram_command
125+
false, // black_bits_inverted
126+
0x10, // write_color_ram_command
127+
false, // color_bits_inverted
128+
0x000000, // highlight_color
129+
refresh_sequence, sizeof(refresh_sequence), // refresh_display_command
130+
1.0, // refresh_time
131+
&pin_GPIO7, // busy_pin
132+
false, // busy_state
133+
2.0, // seconds_per_frame
134+
false, // always_toggle_chip_select
135+
false, // grayscale
136+
false, // acep
137+
false, // two_byte_sequence_length
138+
false); // address_little_endian
139+
}
140+
141+
void board_deinit(void) {
142+
epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display;
143+
if (display->base.type == &epaperdisplay_epaperdisplay_type) {
144+
while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) {
145+
RUN_BACKGROUND_TASKS;
146+
}
147+
}
148+
common_hal_displayio_release_displays();
149+
}
150+
151+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "Heltec Wireless Paper"
12+
#define MICROPY_HW_MCU_NAME "ESP32S3"
13+
14+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
15+
16+
/*#define CIRCUITPY_BOARD_SPI (2)
17+
#define CIRCUITPY_BOARD_SPI_PIN { \
18+
{.clock = &pin_GPIO3, .mosi = &pin_GPIO2, .miso = NULL}, \
19+
{.clock = &pin_GPIO9, .mosi = &pin_GPIO11, .miso = &pin_GPIO11}, \
20+
}*/
21+
22+
// UART definition for UART connected to the CP210x
23+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
24+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
25+
26+
// Serial over UART
27+
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
28+
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Product URL: https://heltec.org/project/wifi-lora-32-v3/
2+
# Schematic: https://resource.heltec.cn/download/WiFi_LoRa32_V3/HTIT-WB32LA(F)_V3_Schematic_Diagram.pdf
3+
# Datasheet: https://resource.heltec.cn/download/WiFi_LoRa32_V3/HTIT-WB32LA_V3(Rev1.1).pdf
4+
# Pinout: https://resource.heltec.cn/download/WiFi_LoRa32_V3/HTIT-WB32LA(F)_V3.png
5+
6+
CIRCUITPY_CREATOR_ID = 0x148E173C
7+
CIRCUITPY_CREATION_ID = 0x00530002
8+
9+
USB_PRODUCT = "Heltec-Wireless-Paper"
10+
USB_MANUFACTURER = "Heltec"
11+
12+
IDF_TARGET = esp32s3
13+
14+
# This board doesn't have USB by default, it
15+
# instead uses a CP2102 USB-to-Serial chip
16+
CIRCUITPY_USB_DEVICE = 0
17+
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0
18+
19+
CIRCUITPY_ESP_FLASH_MODE = qio
20+
CIRCUITPY_ESP_FLASH_FREQ = 80m
21+
CIRCUITPY_ESP_FLASH_SIZE = 8MB
22+
23+
CIRCUITPY_ESPCAMERA = 0
24+
25+
CIRCUITPY_DISPLAYIO = 1
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
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+
// Sole programmable button
14+
{ MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO0) },
15+
16+
// LED
17+
{ MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_GPIO18) },
18+
19+
// ADC (When ADC_CTRL is low, VBAT is connected to ADC_IN with 10K/10K voltage divider)
20+
{ MP_ROM_QSTR(MP_QSTR_ADC_CTRL), MP_ROM_PTR(&pin_GPIO19) },
21+
{ MP_ROM_QSTR(MP_QSTR_ADC_IN), MP_ROM_PTR(&pin_GPIO20) },
22+
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO20) },
23+
24+
// VEXT powers epd and lora antenna boost when low
25+
{ MP_ROM_QSTR(MP_QSTR_VEXT_CTRL), MP_ROM_PTR(&pin_GPIO45) },
26+
27+
// UART that's connected to CP210x over USB
28+
{ MP_ROM_QSTR(MP_QSTR_DEBUG_TX), MP_ROM_PTR(&pin_GPIO43) },
29+
{ MP_ROM_QSTR(MP_QSTR_DEBUG_RX), MP_ROM_PTR(&pin_GPIO44) },
30+
31+
// LORA SPI, Reset, and More
32+
{ MP_ROM_QSTR(MP_QSTR_LORA_CS), MP_ROM_PTR(&pin_GPIO8) },
33+
{ MP_ROM_QSTR(MP_QSTR_LORA_SCK), MP_ROM_PTR(&pin_GPIO9) },
34+
{ MP_ROM_QSTR(MP_QSTR_LORA_MOSI), MP_ROM_PTR(&pin_GPIO10) },
35+
{ MP_ROM_QSTR(MP_QSTR_LORA_MISO), MP_ROM_PTR(&pin_GPIO11) },
36+
{ MP_ROM_QSTR(MP_QSTR_LORA_RESET), MP_ROM_PTR(&pin_GPIO12) },
37+
{ MP_ROM_QSTR(MP_QSTR_LORA_BUSY), MP_ROM_PTR(&pin_GPIO13) },
38+
{ MP_ROM_QSTR(MP_QSTR_LORA_DIO1), MP_ROM_PTR(&pin_GPIO14) },
39+
40+
// eInk Display
41+
{ MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO2) },
42+
{ MP_ROM_QSTR(MP_QSTR_EPD_SCK), MP_ROM_PTR(&pin_GPIO3) },
43+
{ MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO4) },
44+
{ MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO5) },
45+
{ MP_ROM_QSTR(MP_QSTR_EPD_RES), MP_ROM_PTR(&pin_GPIO6) },
46+
{ MP_ROM_QSTR(MP_QSTR_EPD_BUSY), MP_ROM_PTR(&pin_GPIO7) },
47+
48+
// objects
49+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
50+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
51+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)},
52+
53+
};
54+
55+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
CONFIG_ESP_PHY_ENABLE_USB=n
11+
# end of LWIP
12+
13+
# end of Component config
14+
15+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)