Periodic interrupt timer to initiate frame drawing. More...
Data Structures | |
struct | display_frame_usb_phase_t |
Display frame counter and USB frame counter values at frame draw time. More... | |
Macros | |
#define | MS_PER_FRAME (1000/DEVICE_FPS) |
Time interval between frame displays expressed in milliseconds. | |
Frame timing tracking | |
void | new_sof_received (const uint16_t usb_frame_counter) |
Function to be called upon receival of a USB SOF token with the new USB frame counter value. | |
bool | get_display_frame_usb_phase (struct display_frame_usb_phase_t *usb_phase) |
Latest display frame counter phase. More... | |
bool | correct_display_frame_counter (const int16_t frame_diff) |
Correct the display frame counter. More... | |
void | correct_display_frame_phase (const int8_t ms_shift) |
Shift the frame display phase with respect to the USB frame counter. More... | |
Frame draw triggering | |
void | init_frame_timer () |
Initialise the frame timer. | |
bool | should_draw_frame () |
Whether a new frame should be displayed or if the device is allowed to idle. | |
void | clear_draw_frame () |
Acknowledge that a frame has been drawn. | |
Frame timer backend | |
void | init_frame_timer_backend (void(*timer_callback)()) |
Initialise the frame timer. More... | |
int8_t | get_counter_direction () |
Counter direction. More... | |
timer_count_t | get_counts_max () |
The maximum (roll-over/reset) value of the timer. | |
timer_count_t | get_counts_current () |
Get the current counter value of the timer. | |
void | correct_counts_max (timer_diff_t diff) |
Add diff to the current maximum value of the counter. More... | |
Periodic interrupt timer to initiate frame drawing.
Frame timing is split up in a platform independent interface (frame_timer.h) that should be used by other firmware modules, and the timer backend (frame_timer_backend.h) that is only used by the frame timer interface. All hardware specific details of the timer are implemented in this backend, so this is the only part that actually changes between implementation.
void correct_counts_max | ( | timer_diff_t | diff | ) |
Add diff to the current maximum value of the counter.
The new value will be applied after the counter has rolled over. Therefore, although possible, it doesn't really make sense to call this function more often than once per frame draw cycle.
bool correct_display_frame_counter | ( | const int16_t | frame_diff | ) |
Correct the display frame counter.
void correct_display_frame_phase | ( | const int8_t | ms_shift | ) |
Shift the frame display phase with respect to the USB frame counter.
The absolute value of ms_shift should be smaller than or equal to half the number of milliseconds per display frame interval. The provided ms shift can be performed only once per frame cycle, so if multiple calls are performed, only the last correction of the cycle will be used.
int8_t get_counter_direction | ( | ) |
Counter direction.
Differences between counter values have the same sign as the value returned by this function, except when the timer has rolled over.
bool get_display_frame_usb_phase | ( | struct display_frame_usb_phase_t * | usb_phase | ) |
Latest display frame counter phase.
Copy the latest display frame phase into the provided pointer.
void init_frame_timer_backend | ( | void(*)() | timer_callback | ) |
Initialise the frame timer.
timer_callback | The function to be called when the timer trips. |