Skip to content

Commit 77eae28

Browse files
committed
Add PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION for callback when scanlines are available (non host only)
1 parent 2309d56 commit 77eae28

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/common/pico_scanvideo/include/pico/scanvideo/scanvideo_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ void scanvideo_end_scanline_generation(scanvideo_scanline_buffer_t *scanline_buf
265265

266266
typedef uint (*scanvideo_scanline_repeat_count_fn)(uint32_t scanline_id);
267267
void scanvideo_set_scanline_repeat_fn(scanvideo_scanline_repeat_count_fn fn);
268+
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
269+
typedef void (*scanvideo_scanline_release_fn)();
270+
void scanvideo_set_scanline_release_fn(scanvideo_scanline_release_fn fn);
271+
#endif
268272

269273
extern const scanvideo_timing_t vga_timing_640x480_60_default;
270274
extern const scanvideo_timing_t vga_timing_1280x1024_60_default;

src/rp2_common/pico_scanvideo_dpi/scanvideo.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ static bool video_timing_enabled = false;
341341
static bool display_enabled = true;
342342

343343
static scanvideo_scanline_repeat_count_fn _scanline_repeat_count_fn;
344+
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
345+
static scanvideo_scanline_release_fn _scanline_release_fn;
346+
#endif
344347

345348
inline static void list_prepend(full_scanline_buffer_t **phead, full_scanline_buffer_t *fsb) {
346349
scanline_assert(fsb);
@@ -466,6 +469,9 @@ inline static void free_local_free_list_irqs_enabled(full_scanline_buffer_t *loc
466469
spin_unlock(shared_state.free_list.lock, save);
467470
// note also this is useful for triggering scanvideo_wait_for_scanline_complete check
468471
__sev();
472+
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
473+
if (_scanline_release_fn) _scanline_release_fn();
474+
#endif
469475
}
470476
}
471477

@@ -872,7 +878,6 @@ static void __video_time_critical_func(prepare_for_vblank_scanline_irqs_enabled)
872878

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

878883
if (signal) {
@@ -1041,7 +1046,6 @@ extern bool scanvideo_in_vblank() {
10411046
return *(volatile bool *) &shared_state.scanline.in_vblank;
10421047
}
10431048

1044-
10451049
static uint default_scanvideo_scanline_repeat_count_fn(uint32_t scanline_id) {
10461050
return 1;
10471051
}
@@ -1254,6 +1258,13 @@ void scanvideo_set_scanline_repeat_fn(scanvideo_scanline_repeat_count_fn fn) {
12541258
_scanline_repeat_count_fn = fn ? fn : default_scanvideo_scanline_repeat_count_fn;
12551259
}
12561260

1261+
#if PICO_SCANVIDEO_SCANLINE_RELEASE_FUNCTION
1262+
void scanvideo_set_scanline_release_fn(scanvideo_scanline_release_fn fn) {
1263+
_scanline_release_fn = fn;
1264+
}
1265+
#endif
1266+
1267+
12571268
bool scanvideo_setup(const scanvideo_mode_t *mode) {
12581269
return scanvideo_setup_with_timing(mode, mode->default_timing);
12591270
}
@@ -1377,7 +1388,7 @@ bool scanvideo_setup_with_timing(const scanvideo_mode_t *mode, const scanvideo_t
13771388
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY
13781389
int program_wait_index = -1;
13791390
#endif
1380-
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY || PARAM_ASSERTIONS_ENABLED(SCANVIDEO_DBI)
1391+
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY || PARAM_ASSERTIONS_ENABLED(SCANVIDEO_DPI)
13811392
for (int i = 0; i < mode->pio_program->program->length; i++) {
13821393
if (instructions[i] == PIO_WAIT_IRQ4) {
13831394
#if PICO_SCANVIDEO_ENABLE_VIDEO_RECOVERY

0 commit comments

Comments
 (0)