How do I use the ESP-IDF functions?

F1_lst
Posts: 1
Joined: Tue Apr 07, 2020 8:49 am

How do I use the ESP-IDF functions?

Postby F1_lst » Tue Apr 07, 2020 9:55 am

Hello,
I just recently started to work with the ESP-IDF, I know the ESP32 has two cores one for protocols and the other for user apps, both can run tasks with different priorities.

I'm using Visual Studio Code with PlatformIO extension and I was trying to configure the touch sensor module and found this example in the Espressif GitHub: https://github.com/espressif/esp-idf/bl ... ead_main.c

but I need to add "esp_err_t" in front of each function in order for it to work.

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_log.h"

#define TOUCH_THRESH_NO_USE (0)

void app_main(void)
{
  esp_err_t touch_pad_init();
  esp_err_t touch_pad_config(touch_pad_tTOUCH_PAD_NUM0, 1 );
  //esp_err_t touch_pad_filter_start(uint32_t filter_period_ms);
  //esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value);
}
I'm having trouble with the "touch_pad_config" function, it accepted the "touch_pad_tTOUCH_PAD_NUM0" as the first parameter but doesn't seem to accept anything as the second parameter.

Should I include the "touch_pad.h" header?
How do I use this function?


I'm sorry for asking such beginner stuff, I'm sure it must be quite simple but I'm having trouble understanding the ESP-IDF functions.
Thanks in advance!

They also have documented the functions here:
https://docs.espressif.com/projects/esp ... _pad_initv
The header file they used:

Code: Select all

https://github.com/espressif/esp-idf/blob/v4.0/components/driver/include/driver/touch_pad.h

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: How do I use the ESP-IDF functions?

Postby ESP_Dazz » Wed Apr 08, 2020 4:55 am

F1_lst wrote:Should I include the "touch_pad.h" header?
Yes. include by the following.
  1. #include "driver/touch_pad.h "
F1_lst wrote: I'm having trouble with the "touch_pad_config" function, it accepted the "touch_pad_tTOUCH_PAD_NUM0" as the first parameter but doesn't seem to accept anything as the second parameter.
Your code doesn't make any sense. You seem trying to declare the functions instead of using them. The correct usage of the two functions is shown below. I suggest you review your understanding of C syntax and usage.
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "freertos/queue.h"
  5. #include "esp_log.h"
  6. #include "driver/touch_pad.h"
  7.  
  8. #define TOUCH_THRESH_NO_USE (0)
  9.  
  10. void app_main(void)
  11. {
  12.     esp_err_t return_value;
  13.     return_value = touch_pad_init();
  14.     if (return_value != ESP_OK) {
  15.         printf("Touch pad init error\n");
  16.     }
  17.     return_value = touch_pad_config(TOUCH_PAD_NUM0, 1);
  18.     if (return_value != ESP_OK) {
  19.         printf("Touch pad config fail\n");
  20.     }
  21. }
Optionally, you can discard the return values of the functions
  1. touch_pad_init();
  2. touch_pad_config(TOUCH_PAD_NUM0, 1);

Who is online

Users browsing this forum: Timmeke_ and 124 guests