; This file is part of the OpenMV project. ; ; Copyright (c) 2013-2021 Ibrahim Abdelkader ; Copyright (c) 2013-2021 Kwabena W. Agyeman ; ; This work is licensed under the MIT license, see the file LICENSE for details. ; Image Sensor PIO program. .define public PXCLK 11 .define public HSYNC 12 .define public VSYNC 13 .program dcmi_default .wrap_target pull block ; Read number of lines in OSR mov y, osr ; Copy OSR to Y pull block ; Read line width in bytes in OSR wait 1 gpio VSYNC ; Wait for VSYNC to go low wait 0 gpio VSYNC HSYNC_LOOP: mov x, osr ; Copy line width from OSR to X wait 0 gpio HSYNC ; Wait for HSYNC to go high wait 1 gpio HSYNC PIXEL_LOOP: wait 0 gpio PXCLK wait 1 gpio PXCLK in pins 8 jmp x-- PIXEL_LOOP ; Keep reading pixels while x != 0 jmp y-- HSYNC_LOOP ; Keep reading lines while y != 0 .wrap .program dcmi_odd_byte .wrap_target pull block ; Read number of lines in OSR mov y, osr ; Copy OSR to Y pull block ; Read line width in bytes in OSR wait 1 gpio VSYNC ; Wait for VSYNC to go low wait 0 gpio VSYNC HSYNC_LOOP: mov x, osr ; Copy line width from OSR to X wait 0 gpio HSYNC ; Wait for HSYNC to go high wait 1 gpio HSYNC PIXEL_LOOP: wait 0 gpio PXCLK wait 1 gpio PXCLK in pins 8 wait 0 gpio PXCLK wait 1 gpio PXCLK jmp x-- PIXEL_LOOP ; Keep reading pixels while x != 0 jmp y-- HSYNC_LOOP ; Keep reading lines while y != 0 .wrap % c-sdk { int omv_csi_config(omv_csi_t *csi, omv_csi_config_t config) { if (config == OMV_CSI_CONFIG_PIXFORMAT) { uint offset; pio_sm_config config; pio_sm_set_enabled(OMV_CSI_PIO, OMV_CSI_SM, false); pio_sm_clear_fifos(OMV_CSI_PIO, OMV_CSI_SM); for(uint i=OMV_CSI_D0_PIN; ipixformat == PIXFORMAT_GRAYSCALE) { offset = pio_add_program(OMV_CSI_PIO, &dcmi_odd_byte_program); config = dcmi_odd_byte_program_get_default_config(offset); } else { offset = pio_add_program(OMV_CSI_PIO, &dcmi_default_program); config = dcmi_default_program_get_default_config(offset); } sm_config_set_clkdiv(&config, 1); sm_config_set_in_pins(&config, OMV_CSI_D0_PIN); sm_config_set_in_shift(&config, true, true, 32); pio_sm_init(OMV_CSI_PIO, OMV_CSI_SM, offset, &config); pio_sm_set_enabled(OMV_CSI_PIO, OMV_CSI_SM, true); } return 0; } %}