|
|
|
@ -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) { |
|
|
|
|
// negedge
|
|
|
|
|
negedge_time = time; |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
|
bool pushed = (inputs & (1 << pushPin)) == 0; |
|
|
|
|
while (1) { |
|
|
|
|
// uint32_t value = 0;
|
|
|
|
|
// xTaskNotifyWait(0, ULONG_MAX, &value, pdMS_TO_TICKS(1));
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(1)); |
|
|
|
|
|
|
|
|
|
const uint32_t time = xTaskGetTickCount(); |
|
|
|
|
if (pushed) { |
|
|
|
|
negedge_time = time; |
|
|
|
|
} else { |
|
|
|
|
if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS)) { |
|
|
|
|
xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); |
|
|
|
|
uint32_t now = xTaskGetTickCount(); |
|
|
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
bool pushed = (inputs & (1 << pushPin)) == 0; |
|
|
|
|
|
|
|
|
|
if (pushed) { // event "PUSHED"
|
|
|
|
|
if (!push_state) { |
|
|
|
|
if (push_change_time == 0) { |
|
|
|
|
push_change_time = now; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
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();
|
|
|
|
|
} |
|
|
|
|