|
|
@ -8,38 +8,46 @@ const int pushPin = 5; |
|
|
|
const int wheelPin1 = 18; |
|
|
|
const int wheelPin1 = 18; |
|
|
|
const int wheelPin2 = 23; |
|
|
|
const int wheelPin2 = 23; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DEBOUNCE_WHEEL_MS 6 |
|
|
|
|
|
|
|
#define DEBOUNCE_BTN_MS 20 |
|
|
|
|
|
|
|
|
|
|
|
static void handle_pushbtn(void *arg); |
|
|
|
static void handle_pushbtn(void *arg); |
|
|
|
static void handle_wheel(void *arg); |
|
|
|
static void handle_wheel(void *arg); |
|
|
|
|
|
|
|
|
|
|
|
void knob_init() { |
|
|
|
void knob_init() { |
|
|
|
printf("Knob init\n"); |
|
|
|
printf("Knob init\n"); |
|
|
|
|
|
|
|
|
|
|
|
gpio_config_t cfgWheel = { |
|
|
|
// gpio_config_t cfgWheel = {
|
|
|
|
.pin_bit_mask = (1 << wheelPin1) | (1 << wheelPin2), |
|
|
|
// .pin_bit_mask = (1 << wheelPin1) /*| (1 << wheelPin2)*/,
|
|
|
|
.mode = GPIO_MODE_INPUT, |
|
|
|
// .mode = GPIO_MODE_INPUT,
|
|
|
|
.pull_up_en = 1, |
|
|
|
// .pull_up_en = 1,
|
|
|
|
.intr_type = GPIO_INTR_NEGEDGE, // neg means active
|
|
|
|
// .intr_type = GPIO_INTR_NEGEDGE, // neg means active
|
|
|
|
}; |
|
|
|
// };
|
|
|
|
gpio_config(&cfgWheel); |
|
|
|
// gpio_config(&cfgWheel);
|
|
|
|
|
|
|
|
|
|
|
|
gpio_config_t cfgPush = { |
|
|
|
gpio_config_t cfgPush = { |
|
|
|
.pin_bit_mask = (1 << pushPin), |
|
|
|
.pin_bit_mask = (1 << pushPin) | (1 << wheelPin1), |
|
|
|
.mode = GPIO_MODE_INPUT, |
|
|
|
.mode = GPIO_MODE_INPUT, |
|
|
|
.pull_up_en = 1, |
|
|
|
.pull_up_en = 1, |
|
|
|
.intr_type = GPIO_INTR_ANYEDGE, // neg means active
|
|
|
|
.intr_type = GPIO_INTR_ANYEDGE, // neg means active
|
|
|
|
}; |
|
|
|
}; |
|
|
|
gpio_config(&cfgPush); |
|
|
|
gpio_config(&cfgPush); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cfgPush.intr_type = GPIO_INTR_DISABLE; |
|
|
|
|
|
|
|
cfgPush.pin_bit_mask = (1 << wheelPin2); |
|
|
|
|
|
|
|
gpio_config(&cfgPush); |
|
|
|
|
|
|
|
|
|
|
|
gpio_install_isr_service(0); |
|
|
|
gpio_install_isr_service(0); |
|
|
|
gpio_intr_enable(pushPin); |
|
|
|
gpio_intr_enable(pushPin); |
|
|
|
gpio_intr_enable(wheelPin1); |
|
|
|
gpio_intr_enable(wheelPin1); |
|
|
|
gpio_intr_enable(wheelPin2); |
|
|
|
// gpio_intr_enable(wheelPin2);
|
|
|
|
|
|
|
|
|
|
|
|
gpio_isr_handler_add(pushPin, handle_pushbtn, (void *)0); |
|
|
|
gpio_isr_handler_add(pushPin, handle_pushbtn, (void *)0); |
|
|
|
gpio_isr_handler_add(wheelPin1, handle_wheel, (void *)0); |
|
|
|
gpio_isr_handler_add(wheelPin1, handle_wheel, (void *)0); |
|
|
|
gpio_isr_handler_add(wheelPin2, handle_wheel, (void *)1); |
|
|
|
//gpio_isr_handler_add(wheelPin2, handle_wheel, (void *)1);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
enum state { |
|
|
|
enum state { |
|
|
|
S_11 = 0, |
|
|
|
S_11 = 0, |
|
|
|
|
|
|
|
|
|
|
@ -104,9 +112,37 @@ const uint8_t switch_table[28] = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static uint8_t OldEnc = 0b00; |
|
|
|
static uint8_t OldEnc = 0b00; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
static void handle_wheel(void *arg) { |
|
|
|
static void handle_wheel(void *arg) { |
|
|
|
|
|
|
|
static uint32_t negedge_time = 0; |
|
|
|
int dir = 0; |
|
|
|
int dir = 0; |
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
|
|
|
const bool a = 0 != (inputs & (1 << wheelPin1)); // neg = active
|
|
|
|
|
|
|
|
const bool b = 0 != (inputs & (1 << wheelPin2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint32_t time = xTaskGetTickCount(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!a) { |
|
|
|
|
|
|
|
// negedge
|
|
|
|
|
|
|
|
negedge_time = time; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// posedge
|
|
|
|
|
|
|
|
if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_WHEEL_MS)) { |
|
|
|
|
|
|
|
if (b) { |
|
|
|
|
|
|
|
dir = -1; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dir = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// reset the timer
|
|
|
|
|
|
|
|
negedge_time = time; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
@ -151,7 +187,7 @@ static void handle_wheel(void *arg) { |
|
|
|
}; // end if encoder value changed.
|
|
|
|
}; // end if encoder value changed.
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
#if 0 |
|
|
|
// Omron version
|
|
|
|
// Omron version
|
|
|
|
int which = (int)arg; |
|
|
|
int which = (int)arg; |
|
|
|
|
|
|
|
|
|
|
@ -232,20 +268,24 @@ static void handle_wheel(void *arg) { |
|
|
|
if (dir != 0) { |
|
|
|
if (dir != 0) { |
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
xTaskNotifyFromISR(hGuiThread, dir == 1 ? 0b10 : 0b01, eSetBits, &higherWoken); |
|
|
|
xTaskNotifyFromISR(hGuiThread, dir == 1 ? 0b10 : 0b01, eSetBits, &higherWoken); |
|
|
|
if (higherWoken) { |
|
|
|
if (higherWoken) portYIELD_FROM_ISR(); |
|
|
|
portYIELD_FROM_ISR(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void handle_pushbtn(void *arg) { |
|
|
|
static void handle_pushbtn(void *arg) { |
|
|
|
|
|
|
|
static uint32_t negedge_time = 0; |
|
|
|
|
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
|
|
|
|
|
|
|
|
bool pushed = (inputs & (1 << pushPin)) == 0; |
|
|
|
bool pushed = (inputs & (1 << pushPin)) == 0; |
|
|
|
xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (higherWoken) { |
|
|
|
const uint32_t time = xTaskGetTickCount(); |
|
|
|
portYIELD_FROM_ISR(); |
|
|
|
if (pushed) { |
|
|
|
|
|
|
|
negedge_time = time; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (time - negedge_time > pdMS_TO_TICKS(DEBOUNCE_BTN_MS)) { |
|
|
|
|
|
|
|
xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); |
|
|
|
|
|
|
|
if (higherWoken) portYIELD_FROM_ISR(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|