Skip to content

Commit

Permalink
parameter checking for touch
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Mar 6, 2024
1 parent acfa05c commit 27ef443
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/esp_lcd_panel_st7796.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C"
{
#endif

esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *config, esp_lcd_panel_handle_t *handle);
esp_err_t esp_lcd_new_panel_st7796(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *config, esp_lcd_panel_handle_t *handle);

#ifdef __cplusplus
}
Expand Down
18 changes: 14 additions & 4 deletions src/esp_lcd_touch_cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extern "C"
esp_err_t cst816s_reset(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
// Set RST active
Expand Down Expand Up @@ -109,6 +111,8 @@ extern "C"
esp_err_t cst816s_read_info(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
cst816s_info info;
Expand All @@ -128,6 +132,8 @@ extern "C"
esp_err_t cst816s_enter_sleep(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
const uint8_t data[] = {0x03}; // Sleep
Expand All @@ -140,6 +146,8 @@ extern "C"
esp_err_t cst816s_read_data(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
cst816s_touch_event buffer;
Expand Down Expand Up @@ -167,6 +175,8 @@ extern "C"
bool cst816s_get_xy(esp_lcd_touch_handle_t th, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
{
log_v("th:0x%08x, x:0x%08x, y:0x%08x, strength:0x%08x, point_num:0x%08x, max_point_num:%d", th, x, y, strength, point_num, max_point_num);
if (th == NULL || x == NULL || y == NULL || point_num == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand All @@ -187,6 +197,8 @@ extern "C"
esp_err_t cst816s_del(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);

Expand All @@ -211,10 +223,8 @@ extern "C"
esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("io:0x%08x, config:0x%08x, handle:0x%08x", io, config, handle);

assert(io != NULL);
assert(config != NULL);
assert(handle != NULL);
if (io == NULL || config == NULL || handle == NULL)
return ESP_ERR_INVALID_ARG;

if (config->int_gpio_num != GPIO_NUM_NC && !GPIO_IS_VALID_GPIO(config->int_gpio_num))
{
Expand Down
22 changes: 18 additions & 4 deletions src/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ extern "C"
esp_err_t gt911_reset(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
// Set RST active
Expand Down Expand Up @@ -130,6 +132,8 @@ extern "C"
esp_err_t gt911_read_info(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
gt911_info info;
Expand Down Expand Up @@ -164,6 +168,8 @@ extern "C"
esp_err_t gt911_enter_sleep(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
const uint8_t data[] = {0x05}; // Sleep
Expand All @@ -176,6 +182,8 @@ extern "C"
esp_err_t gt911_exit_sleep(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
if (th->config.int_gpio_num == GPIO_NUM_NC)
Expand Down Expand Up @@ -208,6 +216,8 @@ extern "C"
esp_err_t gt911_read_data(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
buffer_status_flags flags;
Expand Down Expand Up @@ -282,6 +292,8 @@ extern "C"
bool gt911_get_xy(esp_lcd_touch_handle_t th, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
{
log_v("th:0x%08x, x:0x%08x, y:0x%08x, strength:0x%08x, point_num:0x%08x, max_point_num:%d", th, x, y, strength, point_num, max_point_num);
if (th == NULL || x == NULL || y == NULL || point_num == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand All @@ -305,6 +317,8 @@ extern "C"
esp_err_t gt911_get_button_state(esp_lcd_touch_handle_t th, uint8_t n, uint8_t *state)
{
log_v("th:0x%08x, n:%d, state:0x%08x", th, n, state);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

if (n > th->data.buttons)
{
Expand All @@ -323,6 +337,8 @@ extern "C"
esp_err_t gt911_del(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);
// Remove gt911_info
Expand Down Expand Up @@ -350,10 +366,8 @@ extern "C"
esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("io:0x%08x, config:0x%08x, handle:0x%08x", io, config, handle);

assert(io != NULL);
assert(config != NULL);
assert(handle != NULL);
if (io == NULL || config == NULL || handle == NULL)
return ESP_ERR_INVALID_ARG;

if (config->int_gpio_num != GPIO_NUM_NC && !GPIO_IS_VALID_GPIO(config->int_gpio_num))
{
Expand Down
16 changes: 12 additions & 4 deletions src/esp_lcd_touch_xpt2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern "C"
esp_err_t xpt2046_enter_sleep(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
uint16_t discard;
Expand All @@ -50,6 +52,8 @@ extern "C"
esp_err_t xpt2046_exit_sleep(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
uint16_t discard;
Expand All @@ -65,6 +69,8 @@ extern "C"
esp_err_t xpt2046_read_data(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

esp_err_t res;
uint32_t x = 0, y = 0;
Expand Down Expand Up @@ -126,6 +132,8 @@ extern "C"
bool xpt2046_get_xy(esp_lcd_touch_handle_t th, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
{
log_v("th:0x%08x, x:0x%08x, y:0x%08x, strength:0x%08x, point_num:0x%08x, max_point_num:%d", th, x, y, strength, point_num, max_point_num);
if (th == NULL || x == NULL || y == NULL || point_num == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand All @@ -148,6 +156,8 @@ extern "C"
esp_err_t xpt2046_del(esp_lcd_touch_handle_t th)
{
log_v("th:0x%08x", th);
if (th == NULL)
return ESP_ERR_INVALID_ARG;

portENTER_CRITICAL(&th->data.lock);
// Remove interrupts and reset INT
Expand All @@ -167,10 +177,8 @@ extern "C"
esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("io:0x%08x, config:0x%08x, handle:0x%08x", io, config, handle);

assert(io != NULL);
assert(config != NULL);
assert(handle != NULL);
if (io == NULL || config == NULL || handle == NULL)
return ESP_ERR_INVALID_ARG;

if (config->int_gpio_num != GPIO_NUM_NC && !GPIO_IS_VALID_GPIO(config->int_gpio_num))
{
Expand Down

0 comments on commit 27ef443

Please sign in to comment.