add Comment for touchpad

This commit is contained in:
fuzhibo
2019-06-20 16:13:47 +08:00
parent fbb0687b97
commit 572084821b
43 changed files with 2780 additions and 1952 deletions

View File

@@ -12,17 +12,23 @@
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp_adc_cal.h"
#endif
#define DEFAULT_VREF 1100 //Use adc2_vref_to_gpio() to obtain a better estimate
#define NO_OF_SAMPLES 64 //Multisampling
#if CONFIG_IDF_TARGET_ESP32
static esp_adc_cal_characteristics_t *adc_chars;
static const adc_channel_t channel = ADC_CHANNEL_6; //GPIO34 if ADC1, GPIO14 if ADC2
#elif CONFIG_IDF_TARGET_ESP32S2BETA
static const adc_channel_t channel = ADC_CHANNEL_6; // GPIO7 if ADC1, GPIO17 if ADC2
#endif
static const adc_atten_t atten = ADC_ATTEN_DB_0;
static const adc_unit_t unit = ADC_UNIT_1;
#if CONFIG_IDF_TARGET_ESP32
static void check_efuse()
{
//Check TP is burned into eFuse
@@ -50,11 +56,14 @@ static void print_char_val_type(esp_adc_cal_value_t val_type)
printf("Characterized using Default Vref\n");
}
}
#endif
void app_main()
{
#if CONFIG_IDF_TARGET_ESP32
//Check if Two Point or Vref are burned into eFuse
check_efuse();
#endif
//Configure ADC
if (unit == ADC_UNIT_1) {
@@ -64,10 +73,12 @@ void app_main()
adc2_config_channel_atten((adc2_channel_t)channel, atten);
}
#if CONFIG_IDF_TARGET_ESP32
//Characterize ADC
adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
print_char_val_type(val_type);
#endif
//Continuously sample ADC1
while (1) {
@@ -83,49 +94,13 @@ void app_main()
}
}
adc_reading /= NO_OF_SAMPLES;
#if CONFIG_IDF_TARGET_ESP32
//Convert adc_reading to voltage in mV
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars);
printf("Raw: %d\tVoltage: %dmV\n", adc_reading, voltage);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
#elif CONFIG_IDF_TARGET_ESP32S2BETA
#define NO_OF_SAMPLES 64 //Multisampling
static const adc_channel_t channel = ADC_CHANNEL_6; // GPIO7 if ADC1, GPIO17 if ADC2
static const adc_atten_t atten = ADC_ATTEN_DB_11; // Detect 0 ~ 3.6v
static const adc_unit_t unit = ADC_UNIT_2;
static const adc_unit_t width = ADC_WIDTH_BIT_12;
void app_main()
{
//Configure ADC
if (unit == ADC_UNIT_1) {
adc1_config_width(width);
adc1_config_channel_atten(channel, atten);
} else {
adc2_config_channel_atten((adc2_channel_t)channel, atten);
}
//Continuously sample ADC1
while (1) {
uint32_t adc_reading = 0;
// Multisampling
for (int i = 0; i < NO_OF_SAMPLES; i++) {
if (unit == ADC_UNIT_1) {
adc_reading += adc1_get_raw((adc1_channel_t)channel);
} else {
int raw;
adc2_get_raw((adc2_channel_t)channel, width, &raw);
adc_reading += raw;
}
}
adc_reading /= NO_OF_SAMPLES;
printf("ADC%d CH%d Raw: %d\t\n", unit, channel, adc_reading);
#endif
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
#endif