|
|
|
@ -14,13 +14,21 @@ static void handle_wheel(void *arg); |
|
|
|
|
void knob_init() { |
|
|
|
|
printf("Knob init\n"); |
|
|
|
|
|
|
|
|
|
gpio_config_t output = { |
|
|
|
|
.pin_bit_mask = (1<<pushPin) | (1 << wheelPin1) | (1 << wheelPin2), |
|
|
|
|
gpio_config_t cfgWheel = { |
|
|
|
|
.pin_bit_mask = (1 << wheelPin1) | (1 << wheelPin2), |
|
|
|
|
.mode = GPIO_MODE_INPUT, |
|
|
|
|
.pull_up_en = 1, |
|
|
|
|
.intr_type = GPIO_INTR_ANYEDGE, |
|
|
|
|
.intr_type = GPIO_INTR_NEGEDGE, // neg means active
|
|
|
|
|
}; |
|
|
|
|
gpio_config(&output); |
|
|
|
|
gpio_config(&cfgWheel); |
|
|
|
|
|
|
|
|
|
gpio_config_t cfgPush = { |
|
|
|
|
.pin_bit_mask = (1 << pushPin), |
|
|
|
|
.mode = GPIO_MODE_INPUT, |
|
|
|
|
.pull_up_en = 1, |
|
|
|
|
.intr_type = GPIO_INTR_ANYEDGE, // neg means active
|
|
|
|
|
}; |
|
|
|
|
gpio_config(&cfgPush); |
|
|
|
|
|
|
|
|
|
gpio_install_isr_service(0); |
|
|
|
|
gpio_intr_enable(pushPin); |
|
|
|
@ -96,6 +104,66 @@ const uint8_t switch_table[28] = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void handle_wheel(void *arg) { |
|
|
|
|
int dir = 0; |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
// Omron version
|
|
|
|
|
int which = (int)arg; |
|
|
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
|
|
|
|
|
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
|
|
|
|
|
bool b = 0 == (inputs & (1 << wheelPin2)); |
|
|
|
|
|
|
|
|
|
if (which == 0) { // itr from A
|
|
|
|
|
if (a) { |
|
|
|
|
if (b) { |
|
|
|
|
dir = -1; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
dir = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { // itr from B
|
|
|
|
|
if (b) { |
|
|
|
|
if (a) { |
|
|
|
|
dir = 1; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
dir = -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
// Naive version
|
|
|
|
|
int which = arg; |
|
|
|
|
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
|
|
|
|
|
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
|
|
|
|
|
bool b = 0 == (inputs & (1 << wheelPin2)); |
|
|
|
|
|
|
|
|
|
if (which == 0) { // itr from A
|
|
|
|
|
if (b) { |
|
|
|
|
dir = -1; |
|
|
|
|
} else { |
|
|
|
|
dir = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { // itr from B
|
|
|
|
|
if (a) { |
|
|
|
|
dir = 1; |
|
|
|
|
} else { |
|
|
|
|
dir = -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if 1 |
|
|
|
|
// More complex version
|
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
const uint8_t ab = |
|
|
|
|
(((inputs >> wheelPin2) & 1) << 1) | |
|
|
|
@ -109,15 +177,16 @@ static void handle_wheel(void *arg) { |
|
|
|
|
|
|
|
|
|
uint8_t next = switch_table[wheelState*4 + ab]; |
|
|
|
|
|
|
|
|
|
const bool forward = next & SW_FWD; |
|
|
|
|
const bool backward = next & SW_BCK; |
|
|
|
|
if (next & SW_FWD) dir = 1; |
|
|
|
|
if (next & SW_BCK) dir = -1; |
|
|
|
|
next &= ~(SW_FWD | SW_BCK); |
|
|
|
|
|
|
|
|
|
wheelState = next; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (forward || backward) { |
|
|
|
|
if (dir != 0) { |
|
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
|
xTaskNotifyFromISR(hGuiThread, forward | (backward << 1), eSetValueWithOverwrite, &higherWoken); |
|
|
|
|
xTaskNotifyFromISR(hGuiThread, dir == 1 ? 0b10 : 0b01, eSetBits, &higherWoken); |
|
|
|
|
if (higherWoken) { |
|
|
|
|
portYIELD_FROM_ISR(); |
|
|
|
|
} |
|
|
|
@ -126,11 +195,12 @@ static void handle_wheel(void *arg) { |
|
|
|
|
|
|
|
|
|
static void handle_pushbtn(void *arg) { |
|
|
|
|
const uint32_t inputs = gpio_input_get(); |
|
|
|
|
if ((inputs & (1 << pushPin)) == 0) { |
|
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
|
xTaskNotifyFromISR(hGuiThread, 0b100, eSetValueWithOverwrite, &higherWoken); |
|
|
|
|
if (higherWoken) { |
|
|
|
|
portYIELD_FROM_ISR(); |
|
|
|
|
} |
|
|
|
|
BaseType_t higherWoken = 0; |
|
|
|
|
|
|
|
|
|
bool pushed = (inputs & (1 << pushPin)) == 0; |
|
|
|
|
xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); |
|
|
|
|
|
|
|
|
|
if (higherWoken) { |
|
|
|
|
portYIELD_FROM_ISR(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|