mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
ports/nrf: Refactor CSI.
This commit is contained in:
parent
f1286053e9
commit
6cfd8dd82b
@ -61,62 +61,6 @@ static const volatile uint32_t *_pclkPort;
|
||||
|
||||
extern void __fatal_error(const char *msg);
|
||||
|
||||
int omv_csi_init() {
|
||||
int init_ret = 0;
|
||||
|
||||
#if defined(OMV_CSI_POWER_PIN)
|
||||
nrf_gpio_cfg_output(OMV_CSI_POWER_PIN);
|
||||
nrf_gpio_pin_write(OMV_CSI_POWER_PIN, 1);
|
||||
#endif
|
||||
|
||||
#if defined(OMV_CSI_RESET_PIN)
|
||||
nrf_gpio_cfg_output(OMV_CSI_RESET_PIN);
|
||||
nrf_gpio_pin_write(OMV_CSI_RESET_PIN, 1);
|
||||
#endif
|
||||
|
||||
// Reset the csi state
|
||||
memset(&csi, 0, sizeof(omv_csi_t));
|
||||
|
||||
// Set default framebuffer
|
||||
csi.fb = framebuffer_get(0);
|
||||
|
||||
// Set default snapshot function.
|
||||
csi.snapshot = omv_csi_snapshot;
|
||||
|
||||
// Configure the csi external clock (XCLK).
|
||||
if (omv_csi_set_clk_frequency(OMV_CSI_CLK_FREQUENCY) != 0) {
|
||||
// Failed to initialize the csi clock.
|
||||
return OMV_CSI_ERROR_TIM_INIT_FAILED;
|
||||
}
|
||||
|
||||
// Detect and initialize the image sensor.
|
||||
if ((init_ret = omv_csi_probe_init(OMV_CSI_I2C_ID, OMV_CSI_I2C_SPEED)) != 0) {
|
||||
// Sensor probe/init failed.
|
||||
return init_ret;
|
||||
}
|
||||
|
||||
// Configure the CSI interface.
|
||||
if (omv_csi_config(OMV_CSI_CONFIG_INIT) != 0) {
|
||||
// CSI config failed
|
||||
return OMV_CSI_ERROR_CSI_INIT_FAILED;
|
||||
}
|
||||
|
||||
// Clear fb_enabled flag
|
||||
// This is executed only once to initialize the FB enabled flag.
|
||||
//JPEG_FB()->enabled = 0;
|
||||
|
||||
// Set default color palette.
|
||||
csi.color_palette = rainbow_table;
|
||||
|
||||
csi.detected = true;
|
||||
|
||||
// Disable VSYNC IRQ and callback
|
||||
omv_csi_set_vsync_callback(NULL);
|
||||
|
||||
/* All good! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int omv_csi_config(omv_csi_config_t config) {
|
||||
if (config == OMV_CSI_CONFIG_INIT) {
|
||||
uint32_t csi_pins[] = {
|
||||
@ -150,7 +94,7 @@ int omv_csi_config(omv_csi_config_t config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t omv_csi_get_xclk_frequency() {
|
||||
uint32_t omv_csi_get_clk_frequency() {
|
||||
return OMV_CSI_CLK_FREQUENCY;
|
||||
}
|
||||
|
||||
@ -261,3 +205,59 @@ int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
framebuffer_init_image(fb, image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int omv_csi_init() {
|
||||
int init_ret = 0;
|
||||
|
||||
#if defined(OMV_CSI_POWER_PIN)
|
||||
nrf_gpio_cfg_output(OMV_CSI_POWER_PIN);
|
||||
nrf_gpio_pin_write(OMV_CSI_POWER_PIN, 1);
|
||||
#endif
|
||||
|
||||
#if defined(OMV_CSI_RESET_PIN)
|
||||
nrf_gpio_cfg_output(OMV_CSI_RESET_PIN);
|
||||
nrf_gpio_pin_write(OMV_CSI_RESET_PIN, 1);
|
||||
#endif
|
||||
|
||||
// Reset the csi state
|
||||
memset(&csi, 0, sizeof(omv_csi_t));
|
||||
|
||||
// Set default framebuffer
|
||||
csi.fb = framebuffer_get(0);
|
||||
|
||||
// Set default snapshot function.
|
||||
csi.snapshot = omv_csi_snapshot;
|
||||
|
||||
// Configure the csi external clock (XCLK).
|
||||
if (omv_csi_set_clk_frequency(OMV_CSI_CLK_FREQUENCY) != 0) {
|
||||
// Failed to initialize the csi clock.
|
||||
return OMV_CSI_ERROR_TIM_INIT_FAILED;
|
||||
}
|
||||
|
||||
// Detect and initialize the image sensor.
|
||||
if ((init_ret = omv_csi_probe_init(OMV_CSI_I2C_ID, OMV_CSI_I2C_SPEED)) != 0) {
|
||||
// Sensor probe/init failed.
|
||||
return init_ret;
|
||||
}
|
||||
|
||||
// Configure the CSI interface.
|
||||
if (omv_csi_config(OMV_CSI_CONFIG_INIT) != 0) {
|
||||
// CSI config failed
|
||||
return OMV_CSI_ERROR_CSI_INIT_FAILED;
|
||||
}
|
||||
|
||||
// Clear fb_enabled flag
|
||||
// This is executed only once to initialize the FB enabled flag.
|
||||
//JPEG_FB()->enabled = 0;
|
||||
|
||||
// Set default color palette.
|
||||
csi.color_palette = rainbow_table;
|
||||
|
||||
csi.detected = true;
|
||||
|
||||
// Disable VSYNC IRQ and callback
|
||||
omv_csi_set_vsync_callback(NULL);
|
||||
|
||||
/* All good! */
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user