Created
December 24, 2013 19:23
-
-
Save Arachnid/8116976 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Maps current state (index) to next state for a forward transition. | |
const int8 quadrature_states[] = {0x1, 0x3, 0x0, 0x2}; | |
CY_ISR(quadrature_event_isr) { | |
static int8 last_levels = 3; | |
static int8 count = 0; | |
int levels = Quadrature_Read(); | |
Quadrature_ClearInterrupt(); | |
if(quadrature_states[last_levels] == levels) { | |
count += 1; | |
last_levels = levels; | |
} else if(quadrature_states[levels] == last_levels) { | |
count -= 1; | |
last_levels = levels; | |
} | |
if(abs(count) >= 4) { | |
ui_event event = {.type = UI_EVENT_UPDOWN, .when = xTaskGetTickCountFromISR(), .int_arg = count / 4}; | |
xQueueSendToBackFromISR(ui_queue, &event, NULL); | |
count = count % 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment