RP2: Move dcmi_config to pio file.

This commit is contained in:
iabdalkader 2021-06-21 22:41:38 +02:00
parent 012313b791
commit 68663f489d
2 changed files with 39 additions and 37 deletions

View File

@ -19,17 +19,17 @@
wait 1 gpio VSYNC ; Wait for VSYNC to go low wait 1 gpio VSYNC ; Wait for VSYNC to go low
wait 0 gpio VSYNC wait 0 gpio VSYNC
line_loop: HSYNC_LOOP:
mov x, osr ; Copy line width from OSR to X mov x, osr ; Copy line width from OSR to X
wait 0 gpio HSYNC ; Wait for HSYNC to go high wait 0 gpio HSYNC ; Wait for HSYNC to go high
wait 1 gpio HSYNC wait 1 gpio HSYNC
pixels_loop: PIXEL_LOOP:
wait 0 gpio PXCLK wait 0 gpio PXCLK
wait 1 gpio PXCLK wait 1 gpio PXCLK
in pins 8 in pins 8
jmp x-- pixels_loop ; Keep reading pixels while x != 0 jmp x-- PIXEL_LOOP ; Keep reading pixels while x != 0
jmp y-- line_loop ; Keep reading lines while y != 0 jmp y-- HSYNC_LOOP ; Keep reading lines while y != 0
.wrap .wrap
.program dcmi_odd_byte .program dcmi_odd_byte
@ -41,17 +41,48 @@ pixels_loop:
wait 1 gpio VSYNC ; Wait for VSYNC to go low wait 1 gpio VSYNC ; Wait for VSYNC to go low
wait 0 gpio VSYNC wait 0 gpio VSYNC
line_loop: HSYNC_LOOP:
mov x, osr ; Copy line width from OSR to X mov x, osr ; Copy line width from OSR to X
wait 0 gpio HSYNC ; Wait for HSYNC to go high wait 0 gpio HSYNC ; Wait for HSYNC to go high
wait 1 gpio HSYNC wait 1 gpio HSYNC
pixels_loop: PIXEL_LOOP:
wait 0 gpio PXCLK wait 0 gpio PXCLK
wait 1 gpio PXCLK wait 1 gpio PXCLK
in pins 8 in pins 8
wait 0 gpio PXCLK wait 0 gpio PXCLK
wait 1 gpio PXCLK wait 1 gpio PXCLK
jmp x-- pixels_loop ; Keep reading pixels while x != 0 jmp x-- PIXEL_LOOP ; Keep reading pixels while x != 0
jmp y-- line_loop ; Keep reading lines while y != 0 jmp y-- HSYNC_LOOP ; Keep reading lines while y != 0
.wrap .wrap
% c-sdk {
static inline int dcmi_config(uint32_t pixformat)
{
uint offset;
pio_sm_config config;
pio_sm_set_enabled(DCMI_PIO, DCMI_SM, false);
pio_sm_clear_fifos(DCMI_PIO, DCMI_SM);
for(uint i=DCMI_D0_PIN; i<DCMI_D0_PIN+8; i++) {
pio_gpio_init(DCMI_PIO, i);
}
pio_sm_set_consecutive_pindirs(DCMI_PIO, DCMI_SM, DCMI_D0_PIN, 8, false);
if (pixformat == PIXFORMAT_GRAYSCALE) {
offset = pio_add_program(DCMI_PIO, &dcmi_odd_byte_program);
config = dcmi_odd_byte_program_get_default_config(offset);
} else {
offset = pio_add_program(DCMI_PIO, &dcmi_default_program);
config = dcmi_default_program_get_default_config(offset);
}
sm_config_set_clkdiv(&config, 1);
sm_config_set_in_pins(&config, DCMI_D0_PIN);
sm_config_set_in_shift(&config, true, true, 32);
pio_sm_init(DCMI_PIO, DCMI_SM, offset, &config);
pio_sm_set_enabled(DCMI_PIO, DCMI_SM, true);
return 0;
}
%}

View File

@ -137,35 +137,6 @@ static void dma_config(int w, int h, int bpp, uint32_t *capture_buf, bool rev_by
dma_irqn_set_channel_enabled(DCMI_DMA, DCMI_DMA_CHANNEL, true); dma_irqn_set_channel_enabled(DCMI_DMA, DCMI_DMA_CHANNEL, true);
} }
static int dcmi_config(uint32_t pixformat)
{
uint offset;
pio_sm_config config;
pio_sm_set_enabled(DCMI_PIO, DCMI_SM, false);
pio_sm_clear_fifos(DCMI_PIO, DCMI_SM);
for(uint i=DCMI_D0_PIN; i<DCMI_D0_PIN+8; i++) {
pio_gpio_init(DCMI_PIO, i);
}
pio_sm_set_consecutive_pindirs(DCMI_PIO, DCMI_SM, DCMI_D0_PIN, 8, false);
if (pixformat == PIXFORMAT_GRAYSCALE) {
offset = pio_add_program(DCMI_PIO, &dcmi_odd_byte_program);
config = dcmi_odd_byte_program_get_default_config(offset);
} else {
offset = pio_add_program(DCMI_PIO, &dcmi_default_program);
config = dcmi_default_program_get_default_config(offset);
}
sm_config_set_clkdiv(&config, 1);
sm_config_set_in_pins(&config, DCMI_D0_PIN);
sm_config_set_in_shift(&config, true, true, 32);
pio_sm_init(DCMI_PIO, DCMI_SM, offset, &config);
pio_sm_set_enabled(DCMI_PIO, DCMI_SM, true);
return 0;
}
void dcmi_abort() void dcmi_abort()
{ {
// Disable DMA channel // Disable DMA channel