Skip to content

Commit 8eee1fd

Browse files
committed
functional epd
1 parent 2098c62 commit 8eee1fd

File tree

1 file changed

+103
-0
lines changed
  • ports/espressif/boards/elecrow_crowpanel_4_2_epaper

1 file changed

+103
-0
lines changed

ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,108 @@
55
// SPDX-License-Identifier: MIT
66

77
#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+
// Init
19+
0x12, 0x80, 0x0a, // Soft reset
20+
0x01, 0x03, 0x2b, 0x01, 0x00, // Set MUX as 300
21+
0x21, 0x02, 0x40, 0x00, // Display update control
22+
0x3c, 0x01, 0x01, // Border waveform
23+
0x11, 0x01, 0x03, // X- mode
24+
0x44, 0x02, 0x00, 0x31, // Set RAM X Address Start/End Pos
25+
0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Address Start/End Pos
26+
0x4e, 0x01, 0x00, // Set RAM X Address counter
27+
0x4f, 0x02, 0x00, 0x00, // Set RAM Y Address counter
28+
};
29+
30+
const uint8_t display_stop_sequence[] = {
31+
0x10, 0x01, 0x32,
32+
};
33+
34+
const uint8_t refresh_sequence[] = {
35+
0x22, 0x01, 0xf7, // Display update sequence option
36+
0x20, 0x80, 0x0a, // Master activation
37+
};
38+
39+
void board_init(void) {
40+
41+
// Enable EPD with driver pin
42+
digitalio_digitalinout_obj_t epd_enable_pin_obj;
43+
epd_enable_pin_obj.base.type = &digitalio_digitalinout_type;
44+
common_hal_digitalio_digitalinout_construct(&epd_enable_pin_obj, &pin_GPIO7);
45+
common_hal_digitalio_digitalinout_switch_to_output(&epd_enable_pin_obj, true, DRIVE_MODE_PUSH_PULL);
46+
common_hal_digitalio_digitalinout_never_reset(&epd_enable_pin_obj);
47+
48+
// Set up the SPI object used to control the display
49+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
50+
busio_spi_obj_t *spi = &bus->inline_bus;
51+
common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false);
52+
common_hal_busio_spi_never_reset(spi);
53+
54+
// Set up the DisplayIO pin object
55+
bus->base.type = &fourwire_fourwire_type;
56+
common_hal_fourwire_fourwire_construct(bus,
57+
spi,
58+
&pin_GPIO46, // EPD_DC Command or data
59+
&pin_GPIO45, // EPD_CS Chip select
60+
&pin_GPIO47, // EPD_RST Reset
61+
1000000, // Baudrate
62+
0, // Polarity
63+
0); // Phase
64+
65+
// Set up the DisplayIO epaper object
66+
epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display;
67+
display->base.type = &epaperdisplay_epaperdisplay_type;
68+
common_hal_epaperdisplay_epaperdisplay_construct(
69+
display,
70+
bus,
71+
display_start_sequence, sizeof(display_start_sequence),
72+
1, // start up time
73+
display_stop_sequence, sizeof(display_stop_sequence),
74+
400, // width
75+
300, // height
76+
400, // ram_width
77+
300, // ram_height
78+
0, // colstart
79+
0, // rowstart
80+
0, // rotation
81+
NO_COMMAND, // set_column_window_command
82+
NO_COMMAND, // set_row_window_command
83+
NO_COMMAND, // set_current_column_command
84+
NO_COMMAND, // set_current_row_command
85+
0x24, // write_black_ram_command
86+
false, // black_bits_inverted
87+
0x26, // write_color_ram_command
88+
false, // color_bits_inverted
89+
0x000000, // highlight_color
90+
refresh_sequence, sizeof(refresh_sequence), // refresh_display_command
91+
1.0, // refresh_time
92+
&pin_GPIO48, // busy_pin
93+
true, // busy_state
94+
2.0, // seconds_per_frame
95+
false, // always_toggle_chip_select
96+
false, // grayscale
97+
false, // acep
98+
false, // two_byte_sequence_length
99+
false); // address_little_endian
100+
}
101+
102+
void board_deinit(void) {
103+
epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display;
104+
if (display->base.type == &epaperdisplay_epaperdisplay_type) {
105+
while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) {
106+
RUN_BACKGROUND_TASKS;
107+
}
108+
}
109+
common_hal_displayio_release_displays();
110+
}
8111

9112
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)