hacky but working. wheel channel 1 uses 100n + 1k external PU for debounce now
This commit is contained in:
+27
-21
@@ -11,6 +11,8 @@ void gui_init() {
|
||||
printf("GUI init\n");
|
||||
LCD_setup();
|
||||
|
||||
LCD_setContrast(60);
|
||||
|
||||
LCD_clearDisplay(0);
|
||||
LCD_setStr("Hello World", 0, 0, 1);
|
||||
LCD_updateDisplay();
|
||||
@@ -21,24 +23,22 @@ void gui_init() {
|
||||
|
||||
static void __attribute__((noreturn)) gui_thread(void *arg) {
|
||||
uint32_t pos = 20;
|
||||
bool btn = 0;
|
||||
#define NMAX 60
|
||||
while (1) {
|
||||
uint32_t value;
|
||||
uint32_t value = 0;
|
||||
xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY);
|
||||
printf("Knob event 0x%02x ", value);
|
||||
// printf("Knob event 0x%02x ", value);
|
||||
|
||||
if (value & 0b1000) {
|
||||
printf("PUSH ");
|
||||
}
|
||||
if (value & 0b100) {
|
||||
printf("RELS ");
|
||||
// printf("PUSH ");
|
||||
btn = 1;
|
||||
} else if (value & 0b100) {
|
||||
btn = 0;
|
||||
}
|
||||
|
||||
if ((value & 0b11) == 0b11) {
|
||||
printf("BNCE ");
|
||||
} else {
|
||||
if (value & 0b01) {
|
||||
printf("FWD ");
|
||||
// printf("FWD ");
|
||||
if (pos == NMAX) {
|
||||
pos = 0;
|
||||
}
|
||||
@@ -46,8 +46,9 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (value & 0b10) {
|
||||
printf("BACK ");
|
||||
// printf("BACK ");
|
||||
if (pos == 0) {
|
||||
pos = NMAX;
|
||||
}
|
||||
@@ -55,16 +56,21 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf(">");
|
||||
for (int i=0; i<pos; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("#");
|
||||
for (int i=pos; i<NMAX; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("<\n");
|
||||
LCD_setRect(0, 15, 83, 35, 1, 1);
|
||||
char buf[10];
|
||||
sprintf(buf, "%3d %s", pos, btn?"BTN":"");
|
||||
LCD_setStr(buf, 2, 17, 0);
|
||||
LCD_updateDisplay();
|
||||
|
||||
// printf(">");
|
||||
// for (int i=0; i<pos; i++) {
|
||||
// printf(" ");
|
||||
// }
|
||||
// printf("#");
|
||||
// for (int i=pos; i<NMAX; i++) {
|
||||
// printf(" ");
|
||||
// }
|
||||
// printf("<\n");
|
||||
}
|
||||
}
|
||||
|
||||
+83
-20
@@ -8,12 +8,20 @@ const int pushPin = 5;
|
||||
const int wheelPin1 = 18;
|
||||
const int wheelPin2 = 23;
|
||||
|
||||
#define DEBOUNCE_WHEEL_MS 6
|
||||
#define DEBOUNCE_BTN_MS 20
|
||||
//const int sigPin1 = 12;
|
||||
//const int sigPin2 = 14;
|
||||
|
||||
#define DEBOUNCE_WHEEL_MS 3
|
||||
#define DEBOUNCE_BTN_MS 10
|
||||
|
||||
static void handle_pushbtn(void *arg);
|
||||
static void handle_wheel(void *arg);
|
||||
|
||||
|
||||
|
||||
static void debounce_service(void *arg);
|
||||
static TaskHandle_t hDebouncer;
|
||||
|
||||
void knob_init() {
|
||||
printf("Knob init\n");
|
||||
|
||||
@@ -33,10 +41,17 @@ void knob_init() {
|
||||
};
|
||||
gpio_config(&cfgPush);
|
||||
|
||||
// wheel2 without itr
|
||||
cfgPush.intr_type = GPIO_INTR_DISABLE;
|
||||
cfgPush.pin_bit_mask = (1 << wheelPin2);
|
||||
gpio_config(&cfgPush);
|
||||
|
||||
// gpio_config_t output = {
|
||||
// .pin_bit_mask = (1<<sigPin1)|(1<<sigPin2),
|
||||
// .mode = GPIO_MODE_OUTPUT
|
||||
// };
|
||||
// gpio_config(&output);
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
gpio_intr_enable(pushPin);
|
||||
gpio_intr_enable(wheelPin1);
|
||||
@@ -45,6 +60,10 @@ void knob_init() {
|
||||
gpio_isr_handler_add(pushPin, handle_pushbtn, (void *)0);
|
||||
gpio_isr_handler_add(wheelPin1, handle_wheel, (void *)0);
|
||||
//gpio_isr_handler_add(wheelPin2, handle_wheel, (void *)1);
|
||||
|
||||
|
||||
int rv = xTaskCreate(debounce_service, "debo", 2048, NULL, 6, &hDebouncer);
|
||||
assert (rv == pdPASS);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -116,35 +135,46 @@ static uint8_t OldEnc = 0b00;
|
||||
|
||||
static void handle_wheel(void *arg) {
|
||||
static uint32_t negedge_time = 0;
|
||||
int dir = 0;
|
||||
static uint32_t posedge_time = 0;
|
||||
static bool last_edge_level = 1;
|
||||
static bool flipflop = 0;
|
||||
|
||||
const uint32_t inputs = gpio_input_get();
|
||||
const bool a = 0 != (inputs & (1 << wheelPin1)); // neg = active
|
||||
const bool b = 0 != (inputs & (1 << wheelPin2));
|
||||
|
||||
// This discards "false rising edge" when we get triggered by a rising edge
|
||||
//
|
||||
if (a == last_edge_level) {
|
||||
return;
|
||||
}
|
||||
last_edge_level = a;
|
||||
|
||||
const uint32_t time = xTaskGetTickCount();
|
||||
|
||||
flipflop ^= 1;
|
||||
// gpio_set_level(sigPin2, flipflop);
|
||||
|
||||
int dir = 0;
|
||||
if (!a) {
|
||||
if ((time - posedge_time) > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) {
|
||||
// negedge
|
||||
negedge_time = time;
|
||||
// gpio_set_level(sigPin1, 0);
|
||||
}
|
||||
} else {
|
||||
// posedge
|
||||
if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) {
|
||||
if ((time - negedge_time) > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) {
|
||||
posedge_time = time;
|
||||
if (b) {
|
||||
dir = -1;
|
||||
} else {
|
||||
dir = 1;
|
||||
}
|
||||
} else {
|
||||
// reset the timer
|
||||
negedge_time = time;
|
||||
// gpio_set_level(sigPin1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
const uint32_t inputs = gpio_input_get();
|
||||
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
|
||||
@@ -272,20 +302,53 @@ static void handle_wheel(void *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_pushbtn(void *arg) {
|
||||
static uint32_t negedge_time = 0;
|
||||
static void __attribute__((noreturn)) debounce_service(void *arg) {
|
||||
bool push_state = 0;
|
||||
uint32_t push_change_time = 0;
|
||||
|
||||
while (1) {
|
||||
// uint32_t value = 0;
|
||||
// xTaskNotifyWait(0, ULONG_MAX, &value, pdMS_TO_TICKS(1));
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
|
||||
uint32_t now = xTaskGetTickCount();
|
||||
|
||||
const uint32_t inputs = gpio_input_get();
|
||||
BaseType_t higherWoken = 0;
|
||||
bool pushed = (inputs & (1 << pushPin)) == 0;
|
||||
|
||||
const uint32_t time = xTaskGetTickCount();
|
||||
if (pushed) {
|
||||
negedge_time = time;
|
||||
if (pushed) { // event "PUSHED"
|
||||
if (!push_state) {
|
||||
if (push_change_time == 0) {
|
||||
push_change_time = now;
|
||||
}
|
||||
} else {
|
||||
if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS)) {
|
||||
xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken);
|
||||
push_change_time = 0;
|
||||
}
|
||||
}
|
||||
else { // event "RELEASED"
|
||||
if (push_state) {
|
||||
if (push_change_time == 0) {
|
||||
push_change_time = now;
|
||||
}
|
||||
} else {
|
||||
push_change_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((push_change_time != 0) && (now - push_change_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS))) {
|
||||
push_state = !push_state;
|
||||
BaseType_t higherWoken = 0;
|
||||
xTaskNotifyFromISR(hGuiThread, 0b100<<push_state, eSetBits, &higherWoken);
|
||||
if (higherWoken) portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_pushbtn(void *arg) {
|
||||
// const uint32_t inputs = gpio_input_get();
|
||||
// bool pushed = (inputs & (1 << pushPin)) == 0;
|
||||
//
|
||||
// BaseType_t higherWoken = 0;
|
||||
// xTaskNotifyFromISR(hDebouncer, 1<<pushed, eSetBits, &higherWoken);
|
||||
// if (higherWoken) portYIELD_FROM_ISR();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user