Skip to content

Dotclock enhancements #8430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 27, 2023
Prev Previous commit
Next Next commit
Switch to i2c init string for espressif lcd ev, expose values via board
  • Loading branch information
jepler committed Sep 25, 2023
commit 6263f6af847c3035734b7790ccd16c37d1975936
3 changes: 1 addition & 2 deletions ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ MP_DEFINE_CONST_DICT(tft_dict, tft_table);
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

{ MP_ROM_QSTR(MP_QSTR_TFT), MP_ROM_PTR(&tft_dict) },
{ MP_ROM_QSTR(MP_QSTR_TFT_PINS), MP_ROM_PTR(&tft_dict) },
{ MP_ROM_QSTR(MP_QSTR_TFT_IO_EXPANDER), MP_ROM_PTR(&tft_io_expander_dict) },

{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(MICROPY_HW_NEOPIXEL) },

{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
Expand Down
34 changes: 17 additions & 17 deletions ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-module/displayio/__init__.h"
#include "boards/espressif_esp32s3_lcd_ev/board.h"

#define MP_DEFINE_BYTES_OBJ(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin}

static const uint8_t display_init_sequence[] = {
0xf0, 5, 0x55, 0xaa, 0x52, 0x08, 0x00,
Expand Down Expand Up @@ -80,8 +83,17 @@ static const uint8_t display_init_sequence[] = {
0x3a, 1, 0x66,
0x3a, 1, 0x66,
0x11, 0x80, 120,
0x29, 0x0
0x29, 0x0,
0, // trailing NUL for Python bytes() representation
};
MP_DEFINE_BYTES_OBJ(display_init_byte_obj, display_init_sequence);

static const char i2c_bus_init_sequence[] = {
2, 3, 0xf1, // set GPIO direction
2, 2, 0, // disable all output inversion
0, // trailing NUL for Python bytes() representation
};
MP_DEFINE_BYTES_OBJ(i2c_init_byte_obj, i2c_bus_init_sequence);

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

common_hal_busio_i2c_try_lock(&i2c);

{
uint8_t buf[2] = {3, 0xf1}; // set GPIO direction
common_hal_busio_i2c_write(&i2c, i2c_device_address, buf, sizeof(buf));
}

{
uint8_t buf[2] = {2, 0}; // set all output pins low initially
common_hal_busio_i2c_write(&i2c, i2c_device_address, buf, sizeof(buf));
}

common_hal_busio_i2c_unlock(&i2c);

dotclockframebuffer_ioexpander_spi_bus spibus = {
.bus = &i2c,
.i2c_device_address = i2c_device_address,
Expand All @@ -151,7 +149,9 @@ void board_init(void) {
.clk_mask = 0x100 << 2,
};

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

common_hal_busio_i2c_deinit(&i2c);
}
Expand Down
31 changes: 31 additions & 0 deletions ports/espressif/boards/espressif_esp32s3_lcd_ev/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2023 Jeff Epler for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#include "py/objstr.h"

extern mp_obj_str_t display_init_byte_obj, i2c_init_byte_obj;
15 changes: 15 additions & 0 deletions ports/espressif/boards/espressif_esp32s3_lcd_ev/pins.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#include "py/objtuple.h"
#include "boards/espressif_esp32s3_lcd_ev/board.h"
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"

STATIC const mp_rom_map_elem_t tft_io_expander_table[] = {
{ MP_ROM_QSTR(MP_QSTR_i2c_address), MP_ROM_INT(0x20)},
{ MP_ROM_QSTR(MP_QSTR_gpio_address), MP_ROM_INT(1)},
{ MP_ROM_QSTR(MP_QSTR_gpio_data_len), MP_ROM_INT(1)},
{ MP_ROM_QSTR(MP_QSTR_gpio_data), MP_ROM_INT(0xF1)},
{ MP_ROM_QSTR(MP_QSTR_cs_bit), MP_ROM_INT(1)},
{ MP_ROM_QSTR(MP_QSTR_mosi_bit), MP_ROM_INT(3)},
{ MP_ROM_QSTR(MP_QSTR_clk_bit), MP_ROM_INT(2)},
{ MP_ROM_QSTR(MP_QSTR_i2c_init_sequence), &i2c_init_byte_obj},
};
MP_DEFINE_CONST_DICT(tft_io_expander_dict, tft_io_expander_table);

STATIC const mp_rom_obj_tuple_t tft_r_pins = {
{&mp_type_tuple},
5,
Expand Down Expand Up @@ -73,6 +86,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {

{ MP_ROM_QSTR(MP_QSTR_TFT_PINS), MP_ROM_PTR(&tft_pins_dict) },
{ MP_ROM_QSTR(MP_QSTR_TFT_TIMINGS), MP_ROM_PTR(&tft_timings_dict) },
{ MP_ROM_QSTR(MP_QSTR_TFT_IO_EXPANDER), MP_ROM_PTR(&tft_io_expander_dict) },
{ MP_ROM_QSTR(MP_QSTR_TFT_INIT_SEQUENCE), &display_init_byte_obj},

{ MP_ROM_QSTR(MP_QSTR_I2S_SCK), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_I2S_MCLK), MP_ROM_PTR(&pin_GPIO5) },
Expand Down