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
CST816 Touch driver support (IDFGH-10255) (BSP-328) #178
Comments
Hello, |
Thanks for quick reply. Is CST816 the same as CST816S? Because the driver that you linked is for CST816S. Regardless, I have tried to use this touch driver. My full function that initializes the LVGL Display:
The display itself works without any issues. I can display images and etc using LVGL. Lets have a look at functions I use to initialize touch display:
I get the following errors printed in the console:
It does not seem to be able to read the i2c device id:
|
Hello,
|
I found it on the schematics: https://github.com/Xinyuan-LilyGO/T-Display-S3/blob/main/schematic/T_Display_S3.pdf |
Yeah you are right. In the schematic it shows the following: but in the Readme.md it shows the following: Lets hope to hear from someone who managed to get it to work on the esp-idf. |
@Lzw655 please, could you help with this? I haven't got HW for CST816 touch. |
How is it going regarding the CST816 touch driver? Has there been any updates ? Highly appreciate! |
@krupis Sorry for being late. I have an LCD with CST816 touch in the home and I'll use it to test the driver tomorrow. Please wait another day. But we can do some tests first. You can run the below codes and check the I2C address of the touch.
|
Not a problem at all. Do you have a T-Display-S3 from Lilygo or some custom board? I have tried to run the command that you have suggested. I have a public repository for testing CST816 that here: I have a lvgl_setup function that is being called in main.c to initialise the whole display:
As you can see at the end of my lvgl_setup, I have added the following functions:
And when I flash my device, it does not seem to return any errors:
I am guessing that's a good sign. But when I try to call the functions to initialize CST816 driver:
I am getting errors:
If you want, you can try use my example project to get going from your side. The display seems to work fine (I can display images and other things on the display with that example project). It is just the Display that I am struggling with. |
Well, I only have a custom board. The given code is used to probe and print the I2C address of touch IC. But according to your results as below, there is no address (like 0x15) that can be found.
So I suspect that there is a problem with your I2C pins. You can try to swap the gpio of SDA and SCL, then run the given code again. If there is no address to be printed, maybe the hardware has some problems. Do you have another board to test? |
I have tried to swap the SDA and SCL pins around but the results are the same. It is most definately not the HW related issue since I can run the LilyGO provided example code based on Arduino IDE and the Touch works fine. Unfortunately, I do not prefer the Arduino IDE and I am hoping to get it working on the esp-idf. |
Hello, |
@krupis @C-basstien Get it. Let me take a look at the code in Arduino. |
@krupis Thanks for your patient test. I just notice that the And according to your results, I find an error in the source code. Line 71 should be placed to line 64. It may cause the level of esp-bsp/components/lcd_touch/esp_lcd_touch_cst816s/esp_lcd_touch_cst816s.c Lines 60 to 80 in 22aa831
Can you help me to verify it? If success, I'll fix it now. |
For this test, do you want me to remove the below from my code?
For the time being, i didint remove the above. Since I made changes in the managed component, I can no longer build the project
It tells me to copy the cst816s managed component and place it to my components folder. I just manually cloned the whole espressif__esp_lcd_touch_cst816s folder and moved it into my components folder. After building and flashing the device, It seems that it still does not work with the below esp_lcd_touch_config_t
|
There seems to be an issue with the rst pin. The below works without any issues
However, this one do not:
Keep in mind that I still have my:
at the beggining of the lvgl_setup I have updated the code in my repository. You can have a look for full source code there |
@krupis Please remove:
And try the code (.reset = 0):
|
I tried your suggestion. My lvgl_setup:
Unfortunately same results:
I dont think the esp_lcd_touch_new_i2c_cst816s pulls the RES pin high hence it does not work. I can try put a scope on that pin if I can |
@Lzw655 |
Yeah, of course! |
I managed to make it work. The issue is related to reset / init timing of the CST816 component.
Do not forget to configure an interrupt callback in the esp_lcd_touch_config_t structure and it should work. |
Nice work! I'll fix it according to your code. |
I am glad you guys have managed to find a fix but I still cannot get the touch to work properly (perhaps this time it is no longer the driver issue but my code issue?) After making a modification :
In my custom esl_lcd_touch_cst816s.c component (I cloned it from the managed component to make changes).
and using the following esp_lcd_touch_config_t: (Not sure why it does not work if I set .reset = 1. I must use .reset = 0.)
I have then added the following callback:
and the following functions at the bottom of my lvgl_setup:
The result:
I have updated my repository if you would like to view the full source code as usual. @C-basstien
Is configuring callback in esp_lcd_touch_config_t required for cst816? |
UPDATE So it turns out the touch funcionality actually works. I have added a debug printf statement inside touch callback:
and when I click on the display, the callback executes and prints the coordinates.
logs from popping up.
|
@krupis Oh, I get the same error logs as below. But the touch function works well, I can control my screen correctly. Can't you?
I think the error reason maybe is caused by the work mode (datasheet Page Four) of CST816. And its I2C can't work when not in dynamic mode. And I find a doc that also mentions that. So we should call |
Yeah I just figured out that the touch callback actually works but its constantly printing those i2c error messages. I have made an update at the same time you wrote your response :) Would you be able to show how to properly handle it in this case (only calling the get_coordinates upon the interrupt)? |
Yeah, let me try. |
Good news, I finish it. You can refer to the following steps (code): First, use a mutex for touch and create it before init touch:
Then, create a callback which used to send mutex and install it:
Finally, take mutex before read_data:
|
You can refer to this file or just simply replace them with |
Hi, |
@Lzw655 I have got it to work. The updated code for the Lilygo T-3 Display is on my repository. Just one quick question: Whenever I want to draw a widget, do I need to call |
@C-basstien Try my example code, perhaps that will help. It seems to be working on my side. The lvgl meter widget is displayed and I can touch the screen and get the coordinates. |
@krupis In any function that is not processed by the LVGL task (which runs |
Are you using |
@Lzw655 |
Yeah, thank you for helping us to test it! |
Should I close this issue for the time being and reopen it if having any other issues with the CST816S touch? |
Not necessary. It'll be closed when this PR is merged. |
Hello. I know this issue has been completed but I have been coming back to it and it haunts me. I hope you can clarify to me. Its been a while but you have helped me solve the issue with the touch callback. Current solution is as following: (pseudocode)
Question1As you can see from above, in Question2Lets say I have connected an I2C sensor to the same I2C bus that I2C touch and its collecting data in a seperate FreeRTOS task. |
Hi @krupis , hope the answers can be helpful. Answer 1LVGL will periodically call Answer 2Yes, you need to perform synchronization, and using the same semaphore is the correct approach. |
Thanks for a quick response Regarding Question1: Regarding Question2: Could you provide some pseudo code how could I synchronize it using the same semaphore My I2C sensor function that I use:
|
SemaphoreHandle_t i2c_mux;
static void bsp_touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
{
uint16_t touchpad_x[1] = {0};
uint16_t touchpad_y[1] = {0};
uint8_t touchpad_cnt = 0;
/* Read data from touch controller into memory */
if ((xSemaphoreTake(touch_mux, 0) == pdTRUE) && (xSemaphoreTake(i2c_mux, your_wait_time) == pdTRUE)) {
esp_lcd_touch_read_data(drv->user_data);
xSemaphoreGive(i2c_mux);
}
...
}
float ADS7828_Read_Current(enum ADS7828_channel_e channel,uint8_t device_address,uint8_t coeff){
//need to implement semaphore here
uint16_t read_adc = 0;
if (xSemaphoreTake(i2c_mux, your_wait_time) == pdTRUE ) {
I2C_read_ads7828(channel,device_address);
xSemaphoreGive(i2c_mux);
}
return read_adc ;
} |
@Lzw655 |
@Lzw655 Sorry to bring this back again after such a long time. My project was on hold for a while since I had some other urgent projects to develop. I have tried your suggestion regarding synchronizing multiple I2C devices on the same I2C bus and it does not seem to work as expected. In my Display component I have the following:
and in my other I2C temperature/humidity sensor I do the following:
As you can see from the SHT40_task, it should capture temperature and humidity readings every 100ms. I think the issue lies somewhere within touch_mux. Instead of taking a temperature reading every 100ms, it only captures a temperature/humidity reading every time I touch on the display. See the logs below:
Perhaps you have any ideas why that might happen and how to overcome this to ensure proper synchronization between multiple I2C devices? I really appreciate your help! My guess is that touch_mux is only given in touch_callback (whenever the touch is detected)
Since it is only given when touch is detected, in SHT40_task the condition:
is never going to be true because we cannot take the touch_mux semaphore unless it is given |
@krupis Yeah, your guess is right. The //SHT40_task is a free rtos task that is being created in my main.c.
void SHT40_task(void *argument)
{
for (;;)
{
if (xSemaphoreTake(i2c_mux, 100) == pdTRUE)
{
Measure_temp_humidity(SHT40_TEMP_HUMID_REG_HIGH_PREC);
xSemaphoreGive(i2c_mux);
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
} |
hii @Lzw655 I have same issue like picture bellow, Help me plss , I config like
|
Is your feature request related to a problem?
I have been using ST7789 display from the lilygo and it works flawlesly.
The only issue is that I believe the esp-idf does not currently support the touch driver (CST816) for this display.
https://www.lilygo.cc/products/t-display-s3
I think adding support for this touch driver would be very useful for developers such as myself.
Describe the solution you'd like.
Working touch display driver for CST816 and example project on how to get it going.
Describe alternatives you've considered.
Using different displays.
Additional context.
No response
The text was updated successfully, but these errors were encountered: