Skip to content

Commit ac0a553

Browse files
authored
Merge pull request #9883 from ddrown/elecrow-crowpanel-3.5
add support for Elecrow Crowpanel 3.5"
2 parents 23a1c9a + 2238e64 commit ac0a553

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "supervisor/board.h"
2+
#include "mpconfigboard.h"
3+
#include "shared-bindings/busio/SPI.h"
4+
#include "shared-bindings/fourwire/FourWire.h"
5+
#include "shared-module/displayio/__init__.h"
6+
#include "shared-module/displayio/mipi_constants.h"
7+
8+
#include "common-hal/microcontroller/Pin.h"
9+
10+
// reference: lv_micropython ili9XXX.py
11+
// reference: ILI9488 datasheet
12+
13+
#define DELAY_FLAG 0x80
14+
15+
#define COLORMODE_BGR 0b00001000
16+
#define ROTATION_Y_FLIP 0b10000000
17+
#define ROTATION_X_FLIP 0b01000000
18+
#define ROTATION_MV 0b00100000
19+
20+
// DBI type C (SPI) only has 3bit and 18bit format support, 3bit = 2 pixels per byte, 18bit = one color per byte
21+
#define COLORFORMAT_3BIT 0b00000001
22+
#define COLORFORMAT_16BIT 0b00000101
23+
#define COLORFORMAT_18BIT 0b00000110
24+
#define COLORFORMAT_24BIT 0b00000111
25+
26+
static uint8_t display_init_sequence[] = {
27+
0x01, DELAY_FLAG | 0, 200, // Software Reset
28+
0x11, DELAY_FLAG | 0, 120, // Exit Sleep Mode
29+
0xE0, 15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F, // Positive Gamma Control
30+
0xE1, 15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F, // Negative Gamma Control
31+
0xC0, 2, 0x17, 0x15, // Power Control 1
32+
0xC1, 1, 0x41, // Power Control 2
33+
0xC2, 1, 0x44, // Power Control 3 / Normal Mode
34+
0xC5, 3, 0x00, 0x12, 0x80, // VCOM Control
35+
0x36, 1, ROTATION_Y_FLIP, // Colormode & Rotation
36+
0x3A, 1, COLORFORMAT_18BIT, // Interface pixel format
37+
0xB0, 1, 0x00, // Interface mode control
38+
0xB1, 1, 0xA0, // Frame Rate Control
39+
0xB4, 1, 0x02, // Display Inversion Control
40+
0xB6, 2, 0x02, 0x02, // Display Function Control
41+
0xE9, 1, 0x00, // Set Image Function
42+
0x53, 1, 0x28, // CTRL Display Value
43+
0x51, 1, 0x7F, // Display Brightness
44+
0xF7, 4, 0xA9, 0x51, 0x2C, 0x02, // Adjust Control 3
45+
0x29, DELAY_FLAG | 0, 25 // Display ON
46+
};
47+
48+
void board_init(void) {
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_GPIO14, &pin_GPIO13, NULL, false);
52+
common_hal_busio_spi_never_reset(spi);
53+
54+
bus->base.type = &fourwire_fourwire_type;
55+
common_hal_fourwire_fourwire_construct(bus,
56+
spi,
57+
&pin_GPIO2, // TFT_DC Command or data
58+
&pin_GPIO15, // TFT_CS Chip select
59+
NULL, // TFT_RST Reset
60+
20000000, // Baudrate
61+
0, // Polarity
62+
0); // Phase
63+
64+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
65+
display->base.type = &busdisplay_busdisplay_type;
66+
common_hal_busdisplay_busdisplay_construct(display,
67+
bus,
68+
320, // Width (after rotation)
69+
480, // Height (after rotation)
70+
0, // column start
71+
0, // row start
72+
0, // rotation
73+
24, // Color depth
74+
false, // grayscale
75+
false, // pixels in byte share row. only used for depth < 8
76+
1, // bytes per cell. Only valid for depths < 8
77+
false, // reverse_pixels_in_byte. Only valid for depths < 8
78+
true, // reverse_pixels_in_word
79+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
80+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
81+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
82+
display_init_sequence,
83+
sizeof(display_init_sequence),
84+
&pin_GPIO27, // backlight pin
85+
0x51, // cmd to write brightness
86+
0.5f, // brightness
87+
false, // single_byte_bounds
88+
false, // data_as_commands
89+
true, // auto_refresh
90+
60, // native_frames_per_second
91+
true, // backlight_on_high
92+
false, // SH1107_addressing
93+
50000); // backlight pwm frequency
94+
}
95+
96+
void board_deinit(void) {
97+
common_hal_displayio_release_displays();
98+
}
99+
100+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2024 Chris Drake, independently providing these changes.
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+
#define MICROPY_HW_BOARD_NAME "Elecrow CrowPanel"
28+
#define MICROPY_HW_MCU_NAME "ESP32"
29+
30+
#define CIRCUITPY_BOARD_I2C (1)
31+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}}
32+
33+
#define CIRCUITPY_BOARD_SPI (2)
34+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO19}, /* SD */ \
35+
{.clock = &pin_GPIO14, .mosi = &pin_GPIO13, .miso = &pin_GPIO12} /* LCD & touch */ }
36+
37+
// UART pins attached to the USB-serial converter chip
38+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
39+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
40+
41+
#define CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP (1)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CIRCUITPY_CREATOR_ID = 0xDD500000
2+
CIRCUITPY_CREATION_ID = 0x00320000
3+
4+
IDF_TARGET = esp32
5+
6+
# This board doesn't have USB by default, it
7+
# instead uses a CH340C USB-to-Serial chip
8+
CIRCUITPY_USB_DEVICE = 0
9+
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0
10+
11+
CIRCUITPY_ESP_FLASH_MODE = qio
12+
CIRCUITPY_ESP_FLASH_FREQ = 80m
13+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
14+
15+
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
16+
CIRCUITPY_ESP_PSRAM_MODE = qio
17+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "py/objtuple.h"
2+
#include "shared-bindings/board/__init__.h"
3+
#include "shared-module/displayio/__init__.h"
4+
5+
static const mp_rom_map_elem_t board_module_globals_table[] = {
6+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
7+
8+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO21) },
9+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO22) },
10+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
11+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
12+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
13+
14+
// TFT and Touch Panel share the same SPI bus
15+
{ MP_ROM_QSTR(MP_QSTR_TFT_MISO), MP_ROM_PTR(&pin_GPIO12) },
16+
{ MP_ROM_QSTR(MP_QSTR_TFT_MOSI), MP_ROM_PTR(&pin_GPIO13) },
17+
{ MP_ROM_QSTR(MP_QSTR_TFT_CLK), MP_ROM_PTR(&pin_GPIO14) },
18+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO15) },
19+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO2) },
20+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO27) },
21+
{ MP_ROM_QSTR(MP_QSTR_TP_CS), MP_ROM_PTR(&pin_GPIO33) },
22+
{ MP_ROM_QSTR(MP_QSTR_TP_IRQ), MP_ROM_PTR(&pin_GPIO36) },
23+
24+
// Version 2.2 hardware (Sep 2024) swaps MISO & touch CS pins
25+
{ MP_ROM_QSTR(MP_QSTR_TFT_MISO_ALT), MP_ROM_PTR(&pin_GPIO33) },
26+
{ MP_ROM_QSTR(MP_QSTR_TP_CS_ALT), MP_ROM_PTR(&pin_GPIO12) },
27+
28+
// SD card SPI bus
29+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO19) },
30+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO23) },
31+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) },
32+
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO5) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_GPIO1), MP_ROM_PTR(&pin_GPIO25) },
35+
{ MP_ROM_QSTR(MP_QSTR_GPIO2), MP_ROM_PTR(&pin_GPIO32) },
36+
37+
{ MP_ROM_QSTR(MP_QSTR_SPEAK), MP_ROM_PTR(&pin_GPIO26) },
38+
39+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
40+
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
41+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
42+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
43+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
44+
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
45+
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
46+
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
47+
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
48+
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
49+
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
50+
{ MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },
51+
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
52+
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
53+
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
54+
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
55+
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
56+
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
57+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
58+
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) },
59+
{ MP_ROM_QSTR(MP_QSTR_IO23), MP_ROM_PTR(&pin_GPIO23) },
60+
{ MP_ROM_QSTR(MP_QSTR_IO25), MP_ROM_PTR(&pin_GPIO25) },
61+
{ MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) },
62+
{ MP_ROM_QSTR(MP_QSTR_IO27), MP_ROM_PTR(&pin_GPIO27) },
63+
{ MP_ROM_QSTR(MP_QSTR_IO32), MP_ROM_PTR(&pin_GPIO32) },
64+
{ MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },
65+
{ MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) },
66+
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
67+
{ MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },
68+
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
69+
70+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
71+
};
72+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
#
6+
# Component config
7+
#
8+
#
9+
# Hardware Settings

0 commit comments

Comments
 (0)