ESP32-S3-Touch-LCD-4.3 > Eteindre Backlight dans loop

Bonjour,
J'ai la carte de waveshare avec le touch 4.3 ESP32-S3-Touch-LCD-4.3)
J'essaye d'éteindre le back light dans la boucle loop, il est initialisé dans le setup mais je n'arrive pas à l'éteindre dans une autre fonction :frowning:
Pourriez-vous m'aider à trouver comment interagir avec le back ligh(éteindre / allumer / régler l'intensité).
Voici le code du setup

/* Initialize IO expander */
    ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO);
    //ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000);
    expander->init();
    expander->begin();
    expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
    expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST | SD_CS, HIGH);

    // Turn off backlight
    //expander->digitalWrite(LCD_BL, OFF);
    expander->digitalWrite(USB_SEL, LOW);
   
    /* Add into panel */
    panel->addIOExpander(expander);

    /* Start panel */
    panel->begin();

Merci d'avance

Bonsoir

le schéma disponible ici montre dans la zone LCD Backlight Power que le signal nommé DISP permet d'activer ou désactiver le régulateur MP3302 qui alimente la ou les LED de rétroéclairage

image

un niveau bas de DISP coupe cette alimentation,

Un tableau indique que DISP est généré par la sortie EXIO2 du circuit intégré CH422 , expandeur d'E/S sur bus I2C
image

image

Dans le bout de code que tu montres on voit la mise à l'atat haut de plusieurs signaux , mais pas de signal nommé DISP .......Serait il renommé dans le code LCD_BL ? Ce n'est pas exclu :wink:

il suffirait alors de s'inspirer de cette commande d'initialisation

` expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST | SD_CS, HIGH);`

pour mettre à LOW le signal LCD_BL au lieu de le mettre à HIGH

Merci, concernant la valuer de LCD_BL j'ai des define

// Extend IO Pin define

#define TP_RST 1
#define LCD_BL 2
#define LCD_RST 3
#define SD_CS 4
#define USB_SEL 5

Mais sincèrement je ne sais comment interagir avec le backlight dans le setup j'ai essayé de décommenter //expander->digitalWrite(LCD_BL, OFF); et effectivement le backlight est éteint au démarrage mais comment l'activer (ou l'éteindre :wink: ) dans la boucle loop car quand je mets ce code en dehors du setup {} j'ai une erreur : 'expander' was not declared in this scope

Encore merci

ça pourrait probablement confirmer l'utilisation d'EXIO 2 pour le signal de commande du rétroéclairage, nommé DISP sur le schéma et LCD_BL dans le code :roll_eyes:

Pour le reste le petit bout de code que tu montres ne permet pas d'expliquer pourquoi la gestion du CH422 ne fonctionne pas dans loop() et comment y remédier

ceci dit rien ne t'empêche de piloter librement dans loop() le CH422 sans passer par la bibliothèque fournie par Waveshare , ce n'est qu'un composant I2C ...

voici le code complet et merci pour votre aide

#include <Arduino.h>
#include <lvgl.h>
#include <ESP_Panel_Library.h>
#include <ESP_IOExpander_Library.h>
#include "lv_conf.h"
#include <Wire.h>

//#include <demos/lv_demos.h>

//#define USE_UI
//#include "ui.h"

#include "events_init.h"
#include "gui_guider.h"
#include "custom.h"

// Extend IO Pin define
#define TP_RST 1
#define LCD_BL 2
#define LCD_RST 3
#define SD_CS 4
#define USB_SEL 5

// I²C Pin define (I²C touch screen)
#define I2C_MASTER_NUM 0
#define I2C_MASTER_SDA_IO 8
#define I2C_MASTER_SCL_IO 9
lv_ui guider_ui;

//I²C Configuration (I²C Slave)
#define I2C_numByte 21
#define I2C_numData 15

byte myData[I2C_numByte];
int I2C_rx_data [I2C_numData];

int I2C_time_out;

/* LVGL porting configurations */
#define LVGL_TICK_PERIOD_MS     (2)
#define LVGL_TASK_MAX_DELAY_MS  (500)
#define LVGL_TASK_MIN_DELAY_MS  (1)
#define LVGL_TASK_STACK_SIZE    (4 * 1024)
#define LVGL_TASK_PRIORITY      (2)
#define LVGL_BUF_SIZE           (ESP_PANEL_LCD_H_RES * 20)

ESP_Panel *panel = NULL;
SemaphoreHandle_t lvgl_mux = NULL;                  // LVGL mutex

#if ESP_PANEL_LCD_BUS_TYPE == ESP_PANEL_BUS_TYPE_RGB
/* Display flushing */
void lvgl_port_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
    panel->getLcd()->drawBitmap(area->x1, area->y1, area->x2 + 1, area->y2 + 1, color_p);
    lv_disp_flush_ready(disp);
}
#else
/* Display flushing */
void lvgl_port_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
    panel->getLcd()->drawBitmap(area->x1, area->y1, area->x2 + 1, area->y2 + 1, color_p);
}

bool notify_lvgl_flush_ready(void *user_ctx)
{
    lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
    lv_disp_flush_ready(disp_driver);
    return false;
}
#endif /* ESP_PANEL_LCD_BUS_TYPE */

#if ESP_PANEL_USE_LCD_TOUCH
/* Read the touchpad */
void lvgl_port_tp_read(lv_indev_drv_t * indev, lv_indev_data_t * data)
{
    panel->getLcdTouch()->readData();

    bool touched = panel->getLcdTouch()->getTouchState();
    if(!touched) {
        data->state = LV_INDEV_STATE_REL;
    } else {
        TouchPoint point = panel->getLcdTouch()->getPoint();

        data->state = LV_INDEV_STATE_PR;
        /*Set the coordinates*/
        data->point.x = point.x;
        data->point.y = point.y;

        Serial.printf("Touch point: x %d, y %d\n", point.x, point.y);
    }
}
#endif

void lvgl_port_lock(int timeout_ms)
{
    const TickType_t timeout_ticks = (timeout_ms < 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
    xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks);
}

void lvgl_port_unlock(void)
{
    xSemaphoreGiveRecursive(lvgl_mux);
}

void lvgl_port_task(void *arg)
{
    Serial.println("Starting LVGL task");

    uint32_t task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
    while (1) {
        // Lock the mutex due to the LVGL APIs are not thread-safe
        lvgl_port_lock(-1);
        task_delay_ms = lv_timer_handler();
        // Release the mutex
        lvgl_port_unlock();
        if (task_delay_ms > LVGL_TASK_MAX_DELAY_MS) {
            task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
        } else if (task_delay_ms < LVGL_TASK_MIN_DELAY_MS) {
            task_delay_ms = LVGL_TASK_MIN_DELAY_MS;
        }
        vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
    }
}

void setup()
{
    Serial.begin(115200); /* prepare for possible serial debug */

    String LVGL_Arduino = "";

    Serial.println(LVGL_Arduino);
    Serial.println("Prizer Ecosystem : Data Viewer & Configurator ID.01 BV.01 RV.00");

    panel = new ESP_Panel();

    /* Initialize LVGL core */
    lv_init();

    /* Initialize LVGL buffers */
    static lv_disp_draw_buf_t draw_buf;
    /* Using double buffers is more faster than single buffer */
    /* Using internal SRAM is more fast than PSRAM (Note: Memory allocated using `malloc` may be located in PSRAM.) */
    uint8_t *buf = (uint8_t *)heap_caps_calloc(1, LVGL_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_INTERNAL);
    assert(buf);
    lv_disp_draw_buf_init(&draw_buf, buf, NULL, LVGL_BUF_SIZE);

    /* Initialize the display device */
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    /* Change the following line to your display resolution */
    disp_drv.hor_res = ESP_PANEL_LCD_H_RES;
    disp_drv.ver_res = ESP_PANEL_LCD_V_RES;
    disp_drv.flush_cb = lvgl_port_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    lv_disp_drv_register(&disp_drv);

#if ESP_PANEL_USE_LCD_TOUCH
    /* Initialize the input device */
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = lvgl_port_tp_read;
    lv_indev_drv_register(&indev_drv);
#endif
    /* Initialize bus and device of panel */
    panel->init();
#if ESP_PANEL_LCD_BUS_TYPE != ESP_PANEL_BUS_TYPE_RGB
    /* Register a function to notify LVGL when the panel is ready to flush */
    /* This is useful for refreshing the screen using DMA transfers */
    panel->getLcd()->setCallback(notify_lvgl_flush_ready, &disp_drv);
#endif

    /* Require the use of an IO expander to configure the screen */
    Serial.println("Initialize IO expander");
    
    /* Initialize IO expander */
    ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO);
    //ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000);
    expander->init();
    expander->begin();
    expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
    expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST | SD_CS, HIGH);

    // Turn off backlight
    //expander->digitalWrite(LCD_BL, OFF);
    expander->digitalWrite(USB_SEL, LOW);
   
    /* Add into panel */
    panel->addIOExpander(expander);

    /* Start panel */
    panel->begin();
    
    /* Create a task to run the LVGL task periodically */
    lvgl_mux = xSemaphoreCreateRecursiveMutex();
    xTaskCreate(lvgl_port_task, "lvgl", LVGL_TASK_STACK_SIZE, NULL, LVGL_TASK_PRIORITY, NULL);

    /* Lock the mutex due to the LVGL APIs are not thread-safe */
    lvgl_port_lock(-1);

    /* Create simple label */
    lv_obj_t *label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, LVGL_Arduino.c_str());
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    /* Initilization of GUI */
    delay(200);
    
    lv_init();


    setup_ui(&guider_ui);
    //events_init(&guider_ui);
    //custom_init(&guider_ui);

    /* Release the mutex */
    lvgl_port_unlock();

    Serial.println("Setup done");

    // I²C Bus communication configuration 
    Wire1.setClock(4000000 / (2 * 100000)-1);   // I²C clock frequency
    Wire1.setPins(12,11);                       // I²C GPIO (SDA, SCL)
    Wire1.begin(0x12);                          // I²C Slave address
    Wire1.onReceive(I2C_RxHandler);             // I²C IRQ Data received

}

void loop()
{
  if (I2C_time_out > 5) {

    I2C_time_out = 0;

    // I²C Bus communication configuration & initialization
    Wire1.end();
    Wire1.setClock(4000000 / (2 * 100000)-1);   // I²C clock frequency
    Wire1.setPins(12,11);                       // I²C GPIO (SDA, SCL)
    Wire1.begin(0x12);                          // I²C Slave address
    Wire1.onReceive(I2C_RxHandler);             // I²C IRQ Data received
  
  }
  else I2C_time_out++;

  delay (1000);
  
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.