Skip to content
Snippets Groups Projects
Commit 22fc7de5 authored by moon2's avatar moon2 :speech_balloon:
Browse files

integrated new captouch driver

parent 600eae34
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,6 @@ static const char *TAG = "captouch"; ...@@ -34,7 +34,6 @@ static const char *TAG = "captouch";
static const struct ad714x_chip *chip_top; static const struct ad714x_chip *chip_top;
static const struct ad714x_chip *chip_bot; static const struct ad714x_chip *chip_bot;
void captouch_force_calibration(){}
struct ad714x_chip { struct ad714x_chip {
uint8_t addr; uint8_t addr;
...@@ -55,7 +54,7 @@ static const struct ad714x_chip chip_bot_rev5 = {.addr = AD7147_BASE_ADDR , . ...@@ -55,7 +54,7 @@ static const struct ad714x_chip chip_bot_rev5 = {.addr = AD7147_BASE_ADDR , .
static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offsets = {24, 12, 16, 33, 30, 28, 31, 27, 22, 24, 18, 19, }, .stages=top_stages}; static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offsets = {24, 12, 16, 33, 30, 28, 31, 27, 22, 24, 18, 19, }, .stages=top_stages};
static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = {3, 2, 1, 1 ,1, 1, 1, 1, 2, 3}, .stages=bottom_stages}; static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = {3, 2, 1, 1 ,1, 1, 1, 1, 2, 3}, .stages=bottom_stages};
*/ */
static void captouch_task(void* arg); //static void captouch_task(void* arg);
static esp_err_t ad714x_i2c_write(const struct ad714x_chip *chip, const uint16_t reg, const uint16_t data) static esp_err_t ad714x_i2c_write(const struct ad714x_chip *chip, const uint16_t reg, const uint16_t data)
{ {
...@@ -320,7 +319,7 @@ void captouch_init(void) ...@@ -320,7 +319,7 @@ void captouch_init(void)
TaskHandle_t handle; TaskHandle_t handle;
//xTaskCreatePinnedToCore(&captouch_task, "captouch", 4096, NULL, configMAX_PRIORITIES - 2, &handle, 1); //xTaskCreatePinnedToCore(&captouch_task, "captouch", 4096, NULL, configMAX_PRIORITIES - 2, &handle, 1);
xTaskCreate(&captouch_task, "captouch", 4096, NULL, configMAX_PRIORITIES - 2, &handle); //xTaskCreate(&captouch_task, "captouch", 4096, NULL, configMAX_PRIORITIES - 2, &handle);
} }
static void print_cdc(uint16_t *data) static void print_cdc(uint16_t *data)
...@@ -351,13 +350,21 @@ uint16_t cdc_ambient[2][12] = {0,}; ...@@ -351,13 +350,21 @@ uint16_t cdc_ambient[2][12] = {0,};
//extern void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot); //extern void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot);
static void captouch_task(void* arg) static uint8_t calib_cycles = 0;
{ void captouch_force_calibration(){
int cycle = 0; if(!calib_cycles){ //last calib has finished
calib_cycles = 16; //goal cycles, can be argument someday
}
// TODO: keep constant track of ambient or allow recalibration }
void captouch_read_cycle(){
static int cycle = 0;
static uint8_t calib_cycle = 0;
vTaskDelay(10 / portTICK_PERIOD_MS);
if(calib_cycles){
if(calib_cycle == 0){ // last cycle has finished
calib_cycle = calib_cycles;
}
uint32_t ambient_acc[2][12] = {{0,}, {0,}}; uint32_t ambient_acc[2][12] = {{0,}, {0,}};
for(int i = 0; i < 16; i++) { for(int i = 0; i < 16; i++) {
vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
...@@ -372,14 +379,15 @@ static void captouch_task(void* arg) ...@@ -372,14 +379,15 @@ static void captouch_task(void* arg)
} }
// TODO: use median instead of average // TODO: use median instead of average
calib_cycle--;
if(!calib_cycle){ //calib cycle is complete
for(int i=0;i<12;i++){ for(int i=0;i<12;i++){
cdc_ambient[0][i] = ambient_acc[0][i] / 16; cdc_ambient[0][i] = ambient_acc[0][i] / calib_cycles;
cdc_ambient[1][i] = ambient_acc[1][i] / 16; cdc_ambient[1][i] = ambient_acc[1][i] / calib_cycles;
} }
calib_cycles = 0;
}
while(true) { } else {
vTaskDelay(10 / portTICK_PERIOD_MS);
cycle++; cycle++;
ad714x_i2c_read(chip_top, 0xB, cdc_data[0], chip_top->stages); ad714x_i2c_read(chip_top, 0xB, cdc_data[0], chip_top->stages);
...@@ -396,7 +404,12 @@ static void captouch_task(void* arg) ...@@ -396,7 +404,12 @@ static void captouch_task(void* arg)
print_ambient(cdc_ambient[1]); print_ambient(cdc_ambient[1]);
print_cdc(cdc_data[1]); print_cdc(cdc_data[1]);
} }
//espan_handle_captouch(pressed_top, pressed_bot); }
}
static void captouch_task(void* arg)
{
while(true) {
} }
} }
......
...@@ -63,17 +63,13 @@ void os_app_main(void) ...@@ -63,17 +63,13 @@ void os_app_main(void)
captouch_init(); captouch_init();
vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(2000 / portTICK_PERIOD_MS);
set_global_vol_dB(0); //set_global_vol_dB(0);
captouch_force_calibration();
display_init(); display_init();
while(1) { while(1) {
manual_captouch_readout(1);
vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS);
manual_captouch_readout(0);
vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS);
update_button_state(); update_button_state();
vTaskDelay((CAPTOUCH_POLLING_PERIOD) / portTICK_PERIOD_MS); captouch_read_cycle();
//display_draw_scope();
} }
ESP_ERROR_CHECK(i2c_driver_delete(I2C_MASTER_NUM)); ESP_ERROR_CHECK(i2c_driver_delete(I2C_MASTER_NUM));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <stdint.h> #include <stdint.h>
void captouch_init(void); void captouch_init(void);
void captouch_read_cycle(void);
void captouch_print_debug_info(void); void captouch_print_debug_info(void);
void gpio_event_handler(void * arg); void gpio_event_handler(void * arg);
void manual_captouch_readout(uint8_t top); void manual_captouch_readout(uint8_t top);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment