kopia lustrzana https://github.com/raspberrypi/pico-extras
default scanvideo to support 125mhz system clock for 640x480 - also means better compatibility as 25Mhz is better than 24Mhz when compared to 25.175Mhz
rodzic
cd49a86399
commit
89a69da242
|
@ -73,17 +73,16 @@ extern "C" {
|
|||
#define PICO_SCANVIDEO_PLANE3_FRAGMENT_DMA 1
|
||||
#endif
|
||||
|
||||
// todo these may be DPI only
|
||||
#ifndef PICO_SCANVIDEO_ENABLE_CLOCK_PIN
|
||||
#define PICO_SCANVIDEO_ENABLE_CLOCK_PIN 1
|
||||
#define PICO_SCANVIDEO_ENABLE_CLOCK_PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef PICO_SCANVIDEO_ENABLE_DEN_PIN
|
||||
#define PICO_SCANVIDEO_ENABLE_DEN_PIN 1
|
||||
#define PICO_SCANVIDEO_ENABLE_DEN_PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef PICO_SCANVIDEO_COLOR_PIN_BASE
|
||||
#define PICO_SCANVIDEO_COLOR_PIN_BASE 0
|
||||
#define PICO_SCANVIDEO_COLOR_PIN_BASE 1
|
||||
#endif
|
||||
|
||||
#ifndef PICO_SCANVIDEO_COLOR_PIN_COUNT
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// todo support for inverted-y (probably belongs in the scanline generators, as would inverted x)
|
||||
|
||||
extern const scanvideo_pio_program_t video_24mhz_composable;
|
||||
|
||||
#ifdef PICO_SCANVIDEO_48MHZ
|
||||
const scanvideo_timing_t vga_timing_640x480_60_default =
|
||||
{
|
||||
.clock_freq = 24000000,
|
||||
|
@ -124,7 +126,6 @@ const scanvideo_timing_t vga_timing_1280x1024_40_default =
|
|||
.enable_den = 0
|
||||
};
|
||||
|
||||
|
||||
const scanvideo_timing_t vga_timing_648x480_60_alt1 =
|
||||
{
|
||||
|
||||
|
@ -223,66 +224,6 @@ const scanvideo_timing_t vga_timing_648x480_50ish3 =
|
|||
|
||||
#define actual_vga_timing_50 vga_timing_648x480_50ish3
|
||||
|
||||
const scanvideo_mode_t vga_mode_160x120_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 160,
|
||||
.height = 120,
|
||||
.xscale = 4,
|
||||
.yscale = 4,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_213x160_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 213,
|
||||
.height = 160,
|
||||
.xscale = 3,
|
||||
.yscale = 3,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_320x240_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.xscale = 2,
|
||||
.yscale = 2,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_640x480_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 640,
|
||||
.height = 480,
|
||||
.xscale = 1,
|
||||
.yscale = 1,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_640x480_50 =
|
||||
{
|
||||
.default_timing = &actual_vga_timing_50,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 640,
|
||||
.height = 480,
|
||||
.xscale = 1,
|
||||
.yscale = 1,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_320x240_50 =
|
||||
{
|
||||
.default_timing = &actual_vga_timing_50,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.xscale = 2,
|
||||
.yscale = 2,
|
||||
};
|
||||
|
||||
/* this is 50 hz */
|
||||
const scanvideo_timing_t vga_timing_wide_480_50 =
|
||||
{
|
||||
|
@ -458,6 +399,90 @@ const scanvideo_mode_t vga_mode_1280x1024_40 =
|
|||
};
|
||||
|
||||
|
||||
const scanvideo_mode_t vga_mode_640x480_50 =
|
||||
{
|
||||
.default_timing = &actual_vga_timing_50,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 640,
|
||||
.height = 480,
|
||||
.xscale = 1,
|
||||
.yscale = 1,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_320x240_50 =
|
||||
{
|
||||
.default_timing = &actual_vga_timing_50,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.xscale = 2,
|
||||
.yscale = 2,
|
||||
};
|
||||
#else
|
||||
const scanvideo_timing_t vga_timing_640x480_60_default =
|
||||
{
|
||||
.clock_freq = 25000000,
|
||||
|
||||
.h_active = 640,
|
||||
.v_active = 480,
|
||||
|
||||
.h_front_porch = 16,
|
||||
.h_pulse = 64,
|
||||
.h_total = 800,
|
||||
.h_sync_polarity = 1,
|
||||
|
||||
.v_front_porch = 1,
|
||||
.v_pulse = 2,
|
||||
.v_total = 523,
|
||||
.v_sync_polarity = 1,
|
||||
|
||||
.enable_clock = 0,
|
||||
.clock_polarity = 0,
|
||||
|
||||
.enable_den = 0
|
||||
};
|
||||
#endif
|
||||
|
||||
const scanvideo_mode_t vga_mode_160x120_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 160,
|
||||
.height = 120,
|
||||
.xscale = 4,
|
||||
.yscale = 4,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_213x160_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 213,
|
||||
.height = 160,
|
||||
.xscale = 3,
|
||||
.yscale = 3,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_320x240_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.xscale = 2,
|
||||
.yscale = 2,
|
||||
};
|
||||
|
||||
const scanvideo_mode_t vga_mode_640x480_60 =
|
||||
{
|
||||
.default_timing = &vga_timing_640x480_60_default,
|
||||
.pio_program = &video_24mhz_composable,
|
||||
.width = 640,
|
||||
.height = 480,
|
||||
.xscale = 1,
|
||||
.yscale = 1,
|
||||
};
|
||||
|
||||
const scanvideo_timing_t vga_timing_1280x720_60_default =
|
||||
{
|
||||
.clock_freq = 74250000,
|
||||
|
|
|
@ -214,7 +214,7 @@ static uint32_t dma_states[DMA_STATE_COUNT];
|
|||
#define PICO_SCANVIDEO_ENABLE_VIDEO_CLOCK_DOWN 1
|
||||
|
||||
#if PICO_SCANVIDEO_ENABLE_VIDEO_CLOCK_DOWN
|
||||
static uint16_t video_clock_down;
|
||||
static uint16_t video_clock_down_times_2;
|
||||
#endif
|
||||
|
||||
semaphore_t vblank_begin;
|
||||
|
@ -992,7 +992,7 @@ void setup_sm(int sm, uint offset) {
|
|||
video_htiming_program_get_default_config(offset);
|
||||
|
||||
#if PICO_SCANVIDEO_ENABLE_VIDEO_CLOCK_DOWN
|
||||
sm_config_set_clkdiv_int_frac(&config, video_clock_down, 0);
|
||||
sm_config_set_clkdiv_int_frac(&config, video_clock_down_times_2 / 2, (video_clock_down_times_2 & 1u) << 7u);
|
||||
#endif
|
||||
|
||||
if (!is_scanline_sm(sm)) {
|
||||
|
@ -1316,37 +1316,43 @@ bool scanvideo_setup_with_timing(const scanvideo_mode_t *mode, const scanvideo_t
|
|||
// shared state init complete - probably overkill
|
||||
__mem_fence_release();
|
||||
|
||||
// todo this is incorrect
|
||||
// set first 18 pins to PIO for vga/dpi
|
||||
#if PICO_SCANVIDEO_ENABLE_DEN_PIN
|
||||
#define MAX_PIN 20
|
||||
bi_decl_if_func_used(bi_4pins_with_names(PICO_SCANVIDEO_SYNC_PIN_BASE, "HSync",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 1, "VSync",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 2, "Display Enable",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 3, "Pixel Clock"));
|
||||
#else
|
||||
#define MAX_PIN 19
|
||||
bi_local_decl(bi_3pins_with_names(PICO_SCANVIDEO_SYNC_PIN_BASE, "HSync",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 1, "VSync",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 2, "Pixel Clock"));
|
||||
#endif
|
||||
uint pin_mask = 3u << PICO_SCANVIDEO_SYNC_PIN_BASE;
|
||||
bi_decl_if_func_used(bi_2pins_with_names(PICO_SCANVIDEO_SYNC_PIN_BASE, "HSync",
|
||||
PICO_SCANVIDEO_SYNC_PIN_BASE + 1, "VSync"));
|
||||
|
||||
#if PICO_SCANVIDEO_ENABLE_DEN_PIN
|
||||
bi_decl_if_func_used(bi_1pin_with_name(PICO_SCANVIDEO_SYNC_PIN_BASE + 2, "Display Enable"));
|
||||
pin_mask |= 4u << PICO_SCANVIDEO_SYNC_PIN_BASE;
|
||||
#endif
|
||||
#if PICO_SCANVIDEO_ENABLE_CLOCK_PIN
|
||||
bi_decl_if_func_used(bi_1pin_with_name(PICO_SCANVIDEO_SYNC_PIN_BASE + 3, "Pixel Clock"));
|
||||
pin_mask |= 8u << PICO_SCANVIDEO_SYNC_PIN_BASE;
|
||||
#endif
|
||||
pin_mask |= 0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_RSHIFT);
|
||||
pin_mask |= 0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_GSHIFT);
|
||||
pin_mask |= 0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_BSHIFT);
|
||||
bi_decl_if_func_used(bi_pin_mask_with_name(0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_RSHIFT), "Red 0-4"));
|
||||
bi_decl_if_func_used(bi_pin_mask_with_name(0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_GSHIFT), "Green 0-4"));
|
||||
bi_decl_if_func_used(bi_pin_mask_with_name(0x1f << (PICO_SCANVIDEO_COLOR_PIN_BASE + PICO_SCANVIDEO_DPI_PIXEL_BSHIFT), "Blue 0-4"));
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < MAX_PIN; ++i)
|
||||
gpio_set_function(i, GPIO_FUNC_PIO0);
|
||||
for(uint8_t i = 0; pin_mask; i++, pin_mask>>=1u) {
|
||||
if (pin_mask & 1) gpio_set_function(i, GPIO_FUNC_PIO0);
|
||||
}
|
||||
|
||||
#if !PICO_SCANVIDEO_ENABLE_VIDEO_CLOCK_DOWN
|
||||
valid_params_if(SCANVIDEO_DPI, timing->clock_freq == video_clock_freq);
|
||||
#else
|
||||
uint sys_clk = clock_get_hz(clk_sys);
|
||||
video_clock_down = sys_clk / (2 * timing->clock_freq);
|
||||
if (2 * video_clock_down * timing->clock_freq != sys_clk) {
|
||||
video_clock_down_times_2 = sys_clk / timing->clock_freq;
|
||||
#if PICO_SCANVIDEO_ENABLE_CLOCK_PIN
|
||||
if (video_clock_down_times_2 * timing->clock_freq != sys_clk) {
|
||||
panic("System clock (%d) must be an integer multiple of 2 times the requested pixel clock (%d).", sys_clk, timing->clock_freq);
|
||||
}
|
||||
#else
|
||||
if (video_clock_down_times_2 * timing->clock_freq != sys_clk) {
|
||||
panic("System clock (%d) must be an integer multiple of the requested pixel clock (%d).", sys_clk, timing->clock_freq);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
valid_params_if(SCANVIDEO_DPI, mode->width * mode->xscale <= timing->h_active);
|
||||
|
|
Ładowanie…
Reference in New Issue