mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
ports/nrf: Refactor omv_csi_init.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
c9ae439448
commit
bc37611dfc
@ -91,13 +91,19 @@
|
||||
#include "omv_csi.h"
|
||||
#include "mp_utils.h"
|
||||
|
||||
extern uint32_t _heap_start;
|
||||
extern uint32_t _heap_end;
|
||||
|
||||
uint32_t HAL_GetHalVersion() {
|
||||
// Hard-coded because it's not defined in SDK
|
||||
return ((2 << 24) | (0 << 16) | (0 << 8) | (0 << 0));
|
||||
}
|
||||
|
||||
extern uint32_t _heap_start;
|
||||
extern uint32_t _heap_end;
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||
static int vfs_mount_and_chdir(mp_obj_t bdev, mp_obj_t mount_point) {
|
||||
@ -142,6 +148,7 @@ soft_reset:
|
||||
machine_init();
|
||||
mp_init();
|
||||
readline_init0();
|
||||
pin_init0();
|
||||
#if MICROPY_PY_MACHINE_SPI
|
||||
spi_init0();
|
||||
#endif
|
||||
@ -163,13 +170,20 @@ soft_reset:
|
||||
#if MICROPY_PY_MACHINE_UART
|
||||
uart_init0();
|
||||
#endif
|
||||
pin_init0();
|
||||
|
||||
fb_alloc_init0();
|
||||
framebuffer_init0();
|
||||
#if MICROPY_PY_CSI
|
||||
omv_csi_init0();
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_CSI
|
||||
omv_csi_init();
|
||||
// Initialize the csi.
|
||||
if (first_soft_reset) {
|
||||
int ret = omv_csi_init();
|
||||
if (ret != 0 && ret != OMV_CSI_ERROR_ISC_UNDETECTED) {
|
||||
__fatal_error("Failed to init the CSI");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (MICROPY_PY_BLE_NUS == 0) && (MICROPY_HW_USB_CDC == 0)
|
||||
@ -372,7 +386,6 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void HardFault_Handler(void) {
|
||||
#if defined(NRF52_SERIES) || defined(NRF91_SERIES)
|
||||
static volatile uint32_t reg;
|
||||
@ -389,12 +402,6 @@ void HardFault_Handler(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void nlr_jump_fail(void *val) {
|
||||
printf("FATAL: uncaught exception %p\n", val);
|
||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t) val);
|
||||
|
||||
@ -206,60 +206,8 @@ static int nrf_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int omv_csi_init() {
|
||||
int init_ret = 0;
|
||||
static omv_i2c_t i2c;
|
||||
|
||||
#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
|
||||
|
||||
// Initialize the CSIs using this driver's ops as defaults,
|
||||
// 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];
|
||||
|
||||
memset(csi, 0, sizeof(omv_csi_t));
|
||||
csi->i2c = &i2c;
|
||||
csi->fb = framebuffer_get(-1);
|
||||
csi->abort = NULL;
|
||||
csi->config = nrf_csi_config;
|
||||
csi->snapshot = nrf_csi_snapshot;
|
||||
csi->color_palette = rainbow_table;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Initialize the camera bus.
|
||||
omv_i2c_init(&i2c, OMV_CSI_I2C_ID, OMV_CSI_I2C_SPEED);
|
||||
|
||||
// Detect and initialize the image sensor.
|
||||
if ((init_ret = omv_csi_probe(&i2c)) != 0) {
|
||||
// Sensor probe/init failed.
|
||||
return init_ret;
|
||||
}
|
||||
|
||||
// Configure the CSI interfaces.
|
||||
for (size_t i=0; i<OMV_CSI_MAX_DEVICES; i++) {
|
||||
omv_csi_t *csi = &csi_all[i];
|
||||
|
||||
if (omv_csi_config(csi, OMV_CSI_CONFIG_INIT) != 0) {
|
||||
return OMV_CSI_ERROR_CSI_INIT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear fb_enabled flag
|
||||
JPEG_FB()->enabled = 0;
|
||||
|
||||
int omv_csi_ops_init(omv_csi_t *csi) {
|
||||
csi->config = nrf_csi_config;
|
||||
csi->snapshot = nrf_csi_snapshot;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user