Skip to content

Commit 6263f6a

Browse files
committed
Switch to i2c init string for espressif lcd ev, expose values via board
1 parent 65310ab commit 6263f6a

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ MP_DEFINE_CONST_DICT(tft_dict, tft_table);
7373
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
7474
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
7575

76-
{ MP_ROM_QSTR(MP_QSTR_TFT), MP_ROM_PTR(&tft_dict) },
76+
{ MP_ROM_QSTR(MP_QSTR_TFT_PINS), MP_ROM_PTR(&tft_dict) },
7777
{ MP_ROM_QSTR(MP_QSTR_TFT_IO_EXPANDER), MP_ROM_PTR(&tft_io_expander_dict) },
78-
7978
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(MICROPY_HW_NEOPIXEL) },
8079

8180
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },

ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
3434
#include "shared-bindings/microcontroller/Pin.h"
3535
#include "shared-module/displayio/__init__.h"
36+
#include "boards/espressif_esp32s3_lcd_ev/board.h"
37+
38+
#define MP_DEFINE_BYTES_OBJ(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin}
3639

3740
static const uint8_t display_init_sequence[] = {
3841
0xf0, 5, 0x55, 0xaa, 0x52, 0x08, 0x00,
@@ -80,8 +83,17 @@ static const uint8_t display_init_sequence[] = {
8083
0x3a, 1, 0x66,
8184
0x3a, 1, 0x66,
8285
0x11, 0x80, 120,
83-
0x29, 0x0
86+
0x29, 0x0,
87+
0, // trailing NUL for Python bytes() representation
88+
};
89+
MP_DEFINE_BYTES_OBJ(display_init_byte_obj, display_init_sequence);
90+
91+
static const char i2c_bus_init_sequence[] = {
92+
2, 3, 0xf1, // set GPIO direction
93+
2, 2, 0, // disable all output inversion
94+
0, // trailing NUL for Python bytes() representation
8495
};
96+
MP_DEFINE_BYTES_OBJ(i2c_init_byte_obj, i2c_bus_init_sequence);
8597

8698
static const mcu_pin_obj_t *red_pins[] = {
8799
&pin_GPIO1, &pin_GPIO2, &pin_GPIO42, &pin_GPIO41, &pin_GPIO40
@@ -103,7 +115,7 @@ void board_init(void) {
103115
/* hsync */ &pin_GPIO46,
104116
/* dclk */ &pin_GPIO9,
105117
/* data */ red_pins, MP_ARRAY_SIZE(red_pins), green_pins, MP_ARRAY_SIZE(green_pins), blue_pins, MP_ARRAY_SIZE(blue_pins),
106-
/* frequency */ 6500000,
118+
/* frequency */ 12000000,
107119
/* width x height */ 480, 480,
108120
/* horizontal: pulse, back & front porch, idle */ 13, 20, 40, false,
109121
/* vertical: pulse, back & front porch, idle */ 15, 20, 40, false,
@@ -127,20 +139,6 @@ void board_init(void) {
127139
common_hal_busio_i2c_construct(&i2c, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 255);
128140
const int i2c_device_address = 32;
129141

130-
common_hal_busio_i2c_try_lock(&i2c);
131-
132-
{
133-
uint8_t buf[2] = {3, 0xf1}; // set GPIO direction
134-
common_hal_busio_i2c_write(&i2c, i2c_device_address, buf, sizeof(buf));
135-
}
136-
137-
{
138-
uint8_t buf[2] = {2, 0}; // set all output pins low initially
139-
common_hal_busio_i2c_write(&i2c, i2c_device_address, buf, sizeof(buf));
140-
}
141-
142-
common_hal_busio_i2c_unlock(&i2c);
143-
144142
dotclockframebuffer_ioexpander_spi_bus spibus = {
145143
.bus = &i2c,
146144
.i2c_device_address = i2c_device_address,
@@ -151,7 +149,9 @@ void board_init(void) {
151149
.clk_mask = 0x100 << 2,
152150
};
153151

154-
dotclockframebuffer_ioexpander_send_init_sequence(&spibus, display_init_sequence, sizeof(display_init_sequence));
152+
static const mp_buffer_info_t bufinfo_display_init = { (void *)display_init_sequence, sizeof(display_init_sequence) - 1 };
153+
static const mp_buffer_info_t bufinfo_i2c_bus_init = { (void *)i2c_bus_init_sequence, sizeof(i2c_bus_init_sequence) - 1 };
154+
dotclockframebuffer_ioexpander_send_init_sequence(&spibus, &bufinfo_i2c_bus_init, &bufinfo_display_init);
155155

156156
common_hal_busio_i2c_deinit(&i2c);
157157
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Jeff Epler 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+
#pragma once
28+
29+
#include "py/objstr.h"
30+
31+
extern mp_obj_str_t display_init_byte_obj, i2c_init_byte_obj;

ports/espressif/boards/espressif_esp32s3_lcd_ev/pins.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
#include "py/objtuple.h"
2+
#include "boards/espressif_esp32s3_lcd_ev/board.h"
23
#include "shared-bindings/board/__init__.h"
34
#include "shared-module/displayio/__init__.h"
45

6+
STATIC const mp_rom_map_elem_t tft_io_expander_table[] = {
7+
{ MP_ROM_QSTR(MP_QSTR_i2c_address), MP_ROM_INT(0x20)},
8+
{ MP_ROM_QSTR(MP_QSTR_gpio_address), MP_ROM_INT(1)},
9+
{ MP_ROM_QSTR(MP_QSTR_gpio_data_len), MP_ROM_INT(1)},
10+
{ MP_ROM_QSTR(MP_QSTR_gpio_data), MP_ROM_INT(0xF1)},
11+
{ MP_ROM_QSTR(MP_QSTR_cs_bit), MP_ROM_INT(1)},
12+
{ MP_ROM_QSTR(MP_QSTR_mosi_bit), MP_ROM_INT(3)},
13+
{ MP_ROM_QSTR(MP_QSTR_clk_bit), MP_ROM_INT(2)},
14+
{ MP_ROM_QSTR(MP_QSTR_i2c_init_sequence), &i2c_init_byte_obj},
15+
};
16+
MP_DEFINE_CONST_DICT(tft_io_expander_dict, tft_io_expander_table);
17+
518
STATIC const mp_rom_obj_tuple_t tft_r_pins = {
619
{&mp_type_tuple},
720
5,
@@ -73,6 +86,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
7386

7487
{ MP_ROM_QSTR(MP_QSTR_TFT_PINS), MP_ROM_PTR(&tft_pins_dict) },
7588
{ MP_ROM_QSTR(MP_QSTR_TFT_TIMINGS), MP_ROM_PTR(&tft_timings_dict) },
89+
{ MP_ROM_QSTR(MP_QSTR_TFT_IO_EXPANDER), MP_ROM_PTR(&tft_io_expander_dict) },
90+
{ MP_ROM_QSTR(MP_QSTR_TFT_INIT_SEQUENCE), &display_init_byte_obj},
7691

7792
{ MP_ROM_QSTR(MP_QSTR_I2S_SCK), MP_ROM_PTR(&pin_GPIO16) },
7893
{ MP_ROM_QSTR(MP_QSTR_I2S_MCLK), MP_ROM_PTR(&pin_GPIO5) },

0 commit comments

Comments
 (0)