mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
ports/nrf: Add support for multiple CSIs.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
be6b3fa80d
commit
02f42b6837
@ -61,7 +61,7 @@ static const volatile uint32_t *_pclkPort;
|
|||||||
|
|
||||||
extern void __fatal_error(const char *msg);
|
extern void __fatal_error(const char *msg);
|
||||||
|
|
||||||
int omv_csi_config(omv_csi_config_t config) {
|
static int nrf_csi_config(omv_csi_t *csi, omv_csi_config_t config) {
|
||||||
if (config == OMV_CSI_CONFIG_INIT) {
|
if (config == OMV_CSI_CONFIG_INIT) {
|
||||||
uint32_t csi_pins[] = {
|
uint32_t csi_pins[] = {
|
||||||
OMV_CSI_D0_PIN,
|
OMV_CSI_D0_PIN,
|
||||||
@ -114,12 +114,12 @@ int omv_csi_set_clk_frequency(uint32_t frequency) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int omv_csi_set_windowing(int x, int y, int w, int h) {
|
int omv_csi_set_windowing(omv_csi_t *csi, int x, int y, int w, int h) {
|
||||||
return OMV_CSI_ERROR_CTL_UNSUPPORTED;
|
return OMV_CSI_ERROR_CTL_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the default snapshot function, which can be replaced in omv_csi_init functions.
|
// This is the default snapshot function, which can be replaced in omv_csi_init functions.
|
||||||
int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
static int nrf_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||||
framebuffer_t *fb = csi->fb;
|
framebuffer_t *fb = csi->fb;
|
||||||
|
|
||||||
// Compress the framebuffer for the IDE preview, only if it's not the first frame,
|
// Compress the framebuffer for the IDE preview, only if it's not the first frame,
|
||||||
@ -132,7 +132,7 @@ int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
|||||||
framebuffer_set_buffers(fb, 1);
|
framebuffer_set_buffers(fb, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (omv_csi_check_framebuffer_size(fb) != 0) {
|
if (omv_csi_check_framebuffer_size(csi) != 0) {
|
||||||
return OMV_CSI_ERROR_FRAMEBUFFER_OVERFLOW;
|
return OMV_CSI_ERROR_FRAMEBUFFER_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,8 +188,8 @@ int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
|||||||
interrupts();
|
interrupts();
|
||||||
|
|
||||||
// Not useful for the NRF but must call to keep API the same.
|
// Not useful for the NRF but must call to keep API the same.
|
||||||
if (csi->frame_callback) {
|
if (csi->frame_cb.fun) {
|
||||||
csi->frame_callback();
|
csi->frame_cb.fun(csi->frame_cb.arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set framebuffer pixel format.
|
// Set framebuffer pixel format.
|
||||||
@ -208,6 +208,7 @@ int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
|||||||
|
|
||||||
int omv_csi_init() {
|
int omv_csi_init() {
|
||||||
int init_ret = 0;
|
int init_ret = 0;
|
||||||
|
static omv_i2c_t i2c;
|
||||||
|
|
||||||
#if defined(OMV_CSI_POWER_PIN)
|
#if defined(OMV_CSI_POWER_PIN)
|
||||||
nrf_gpio_cfg_output(OMV_CSI_POWER_PIN);
|
nrf_gpio_cfg_output(OMV_CSI_POWER_PIN);
|
||||||
@ -219,17 +220,19 @@ int omv_csi_init() {
|
|||||||
nrf_gpio_pin_write(OMV_CSI_RESET_PIN, 1);
|
nrf_gpio_pin_write(OMV_CSI_RESET_PIN, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Reset the csi state
|
// Initialize the CSIs using this driver's ops as defaults,
|
||||||
memset(&csi, 0, sizeof(omv_csi_t));
|
// which can be overridden by sensor drivers during probe.
|
||||||
|
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) {
|
||||||
|
omv_csi_t *csi = &csi_all[i];
|
||||||
|
|
||||||
// Set default framebuffer
|
memset(csi, 0, sizeof(omv_csi_t));
|
||||||
csi.fb = framebuffer_get(0);
|
csi->i2c = &i2c;
|
||||||
|
csi->fb = framebuffer_get(-1);
|
||||||
// Set I2C bus
|
csi->abort = NULL;
|
||||||
csi.i2c = &csi_i2c;
|
csi->config = nrf_csi_config;
|
||||||
|
csi->snapshot = nrf_csi_snapshot;
|
||||||
// Set default snapshot function.
|
csi->color_palette = rainbow_table;
|
||||||
csi.snapshot = omv_csi_snapshot;
|
}
|
||||||
|
|
||||||
// Configure the csi external clock (XCLK).
|
// Configure the csi external clock (XCLK).
|
||||||
if (omv_csi_set_clk_frequency(OMV_CSI_CLK_FREQUENCY) != 0) {
|
if (omv_csi_set_clk_frequency(OMV_CSI_CLK_FREQUENCY) != 0) {
|
||||||
@ -237,30 +240,28 @@ int omv_csi_init() {
|
|||||||
return OMV_CSI_ERROR_TIM_INIT_FAILED;
|
return OMV_CSI_ERROR_TIM_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the camera bus.
|
||||||
|
omv_i2c_init(&i2c, OMV_CSI_I2C_ID, OMV_CSI_I2C_SPEED);
|
||||||
|
|
||||||
// Detect and initialize the image sensor.
|
// Detect and initialize the image sensor.
|
||||||
if ((init_ret = omv_csi_probe_init(OMV_CSI_I2C_ID, OMV_CSI_I2C_SPEED)) != 0) {
|
if ((init_ret = omv_csi_probe(&i2c)) != 0) {
|
||||||
// Sensor probe/init failed.
|
// Sensor probe/init failed.
|
||||||
return init_ret;
|
return init_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the CSI interface.
|
// Configure the CSI interfaces.
|
||||||
if (omv_csi_config(OMV_CSI_CONFIG_INIT) != 0) {
|
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) {
|
||||||
// CSI config failed
|
omv_csi_t *csi = &csi_all[i];
|
||||||
return OMV_CSI_ERROR_CSI_INIT_FAILED;
|
|
||||||
|
if (omv_csi_config(csi, OMV_CSI_CONFIG_INIT) != 0) {
|
||||||
|
return OMV_CSI_ERROR_CSI_INIT_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
csi->detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear fb_enabled flag
|
// Clear fb_enabled flag
|
||||||
// This is executed only once to initialize the FB enabled flag.
|
JPEG_FB()->enabled = 0;
|
||||||
//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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user