Skip to content

Commit

Permalink
Add PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION for callback when scanli…
Browse files Browse the repository at this point in the history
…nes are available (non host only)
  • Loading branch information
kilograham committed Nov 1, 2021
1 parent 2309d56 commit 77eae28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ void scanvideo_end_scanline_generation(scanvideo_scanline_buffer_t *scanline_buf

typedef uint (*scanvideo_scanline_repeat_count_fn)(uint32_t scanline_id);
void scanvideo_set_scanline_repeat_fn(scanvideo_scanline_repeat_count_fn fn);
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
typedef void (*scanvideo_scanline_release_fn)();
void scanvideo_set_scanline_release_fn(scanvideo_scanline_release_fn fn);
#endif

extern const scanvideo_timing_t vga_timing_640x480_60_default;
extern const scanvideo_timing_t vga_timing_1280x1024_60_default;
Expand Down
17 changes: 14 additions & 3 deletions src/rp2_common/pico_scanvideo_dpi/scanvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ static bool video_timing_enabled = false;
static bool display_enabled = true;

static scanvideo_scanline_repeat_count_fn _scanline_repeat_count_fn;
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
static scanvideo_scanline_release_fn _scanline_release_fn;
#endif

inline static void list_prepend(full_scanline_buffer_t **phead, full_scanline_buffer_t *fsb) {
scanline_assert(fsb);
Expand Down Expand Up @@ -466,6 +469,9 @@ inline static void free_local_free_list_irqs_enabled(full_scanline_buffer_t *loc
spin_unlock(shared_state.free_list.lock, save);
// note also this is useful for triggering scanvideo_wait_for_scanline_complete check
__sev();
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
if (_scanline_release_fn) _scanline_release_fn();
#endif
}
}

Expand Down Expand Up @@ -872,7 +878,6 @@ static void __video_time_critical_func(prepare_for_vblank_scanline_irqs_enabled)

// because IRQs are enabled, we may obviously be pre-empted before or between either of these
release_scanline_irqs_enabled(buffers_to_free_count, &local_free_list);

free_local_free_list_irqs_enabled(local_free_list);

if (signal) {
Expand Down Expand Up @@ -1041,7 +1046,6 @@ extern bool scanvideo_in_vblank() {
return *(volatile bool *) &shared_state.scanline.in_vblank;
}


static uint default_scanvideo_scanline_repeat_count_fn(uint32_t scanline_id) {
return 1;
}
Expand Down Expand Up @@ -1254,6 +1258,13 @@ void scanvideo_set_scanline_repeat_fn(scanvideo_scanline_repeat_count_fn fn) {
_scanline_repeat_count_fn = fn ? fn : default_scanvideo_scanline_repeat_count_fn;
}

#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
void scanvideo_set_scanline_release_fn(scanvideo_scanline_release_fn fn) {
_scanline_release_fn = fn;
}
#endif


bool scanvideo_setup(const scanvideo_mode_t *mode) {
return scanvideo_setup_with_timing(mode, mode->default_timing);
}
Expand Down Expand Up @@ -1377,7 +1388,7 @@ bool scanvideo_setup_with_timing(const scanvideo_mode_t *mode, const scanvideo_t
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY
int program_wait_index = -1;
#endif
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY || PARAM_ASSERTIONS_ENABLED(SCANVIDEO_DBI)
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY || PARAM_ASSERTIONS_ENABLED(SCANVIDEO_DPI)
for (int i = 0; i < mode->pio_program->program->length; i++) {
if (instructions[i] == PIO_WAIT_IRQ4) {
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY
Expand Down

0 comments on commit 77eae28

Please sign in to comment.