get multiple touchpad working

This commit is contained in:
microDev 2020-11-22 18:54:18 +05:30
parent 2f14609044
commit 048ca2a570
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
1 changed files with 11 additions and 7 deletions

View File

@ -25,10 +25,12 @@
*/
#include "shared-bindings/touchio/TouchIn.h"
#include "py/runtime.h"
#include "py/runtime.h"
#include "driver/touch_pad.h"
bool touch_inited = false;
static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
uint32_t touch_value;
touch_pad_read_raw_data((touch_pad_t)self->pin->touch_channel, &touch_value);
@ -45,11 +47,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
}
claim_pin(pin);
touch_pad_init();
touch_pad_config((touch_pad_t)pin->touch_channel);
if (!touch_inited) {
touch_pad_init();
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_pad_fsm_start();
touch_inited = true;
}
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
touch_pad_fsm_start();
touch_pad_config((touch_pad_t)pin->touch_channel);
// wait for "raw data" to reset
mp_hal_delay_ms(10);
@ -79,8 +84,7 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
}
bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self) {
uint16_t reading = get_raw_reading(self);
return reading > self->threshold;
return get_raw_reading(self) > self->threshold;
}
uint16_t common_hal_touchio_touchin_get_raw_value(touchio_touchin_obj_t *self) {