Merge pull request #1382 from openmv/systick_delay

Use mp_hal_delay_ms instead of systick_sleep.
This commit is contained in:
Ibrahim Abd Elkader 2021-06-29 17:19:48 +02:00 committed by GitHub
commit 9ca4a06776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 37 deletions

View File

@ -11,11 +11,11 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "extint.h"
#include "spi.h"
#include "softtimer.h"
#include "systick.h"
#include "py_helper.h"
#include "omv_boardconfig.h"
@ -346,29 +346,29 @@ int fir_lepton_init(cambus_t *bus, int *w, int *h, int *refresh, int *resolution
#if defined(OMV_FIR_LEPTON_PWDN_PIN_PRESENT)
OMV_FIR_LEPTON_PWDN_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
OMV_FIR_LEPTON_PWDN_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
#endif
#if defined(OMV_FIR_LEPTON_RST_PIN_PRESENT)
OMV_FIR_LEPTON_RST_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
OMV_FIR_LEPTON_RST_HIGH();
systick_sleep(1000);
mp_hal_delay_ms(1000);
#endif
LEP_RAD_ENABLE_E rad;
LEP_AGC_ROI_T roi;
for (uint32_t start = systick_current_millis();; systick_sleep(1)) {
for (uint32_t start = mp_hal_ticks_ms();; mp_hal_delay_ms(1)) {
if (LEP_OpenPort(bus, LEP_CCI_TWI, 0, &fir_lepton_handle) == LEP_OK) {
break;
}
if ((systick_current_millis() - start) >= 1000) {
if ((mp_hal_ticks_ms() - start) >= 1000) {
return -1;
}
}
@ -378,10 +378,10 @@ int fir_lepton_init(cambus_t *bus, int *w, int *h, int *refresh, int *resolution
return -2;
}
systick_sleep(1000);
mp_hal_delay_ms(1000);
#endif
for (uint32_t start = systick_current_millis();; systick_sleep(1)) {
for (uint32_t start = mp_hal_ticks_ms();; mp_hal_delay_ms(1)) {
LEP_SDK_BOOT_STATUS_E status;
if (LEP_GetCameraBootStatus(&fir_lepton_handle, &status) != LEP_OK) {
@ -392,12 +392,12 @@ int fir_lepton_init(cambus_t *bus, int *w, int *h, int *refresh, int *resolution
break;
}
if ((systick_current_millis() - start) >= 1000) {
if ((mp_hal_ticks_ms() - start) >= 1000) {
return -4;
}
}
for (uint32_t start = systick_current_millis();; systick_sleep(1)) {
for (uint32_t start = mp_hal_ticks_ms();; mp_hal_delay_ms(1)) {
LEP_UINT16 status;
if (LEP_DirectReadRegister(&fir_lepton_handle, LEP_I2C_STATUS_REG, &status) != LEP_OK) {
@ -408,7 +408,7 @@ int fir_lepton_init(cambus_t *bus, int *w, int *h, int *refresh, int *resolution
break;
}
if ((systick_current_millis() - start) >= 1000) {
if ((mp_hal_ticks_ms() - start) >= 1000) {
return -6;
}
}
@ -543,14 +543,14 @@ static const uint16_t *fir_lepton_get_frame(int timeout)
int sampled_framebuffer_tail = framebuffer_tail;
if (timeout >= 0) {
for (uint32_t start = systick_current_millis();;) {
for (uint32_t start = mp_hal_ticks_ms();;) {
sampled_framebuffer_tail = framebuffer_tail;
if (framebuffer_head != sampled_framebuffer_tail) {
break;
}
if ((systick_current_millis() - start) >= timeout) {
if ((mp_hal_ticks_ms() - start) >= timeout) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Timeout!"));
}
@ -712,7 +712,7 @@ void fir_lepton_trigger_ffc(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
int timeout = py_helper_keyword_int(n_args, args, 0, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_timeout), -1);
if (timeout >= 0) {
for (uint32_t start = systick_current_millis();;) {
for (uint32_t start = mp_hal_ticks_ms();;) {
LEP_SYS_STATUS_E status;
if (LEP_GetSysFFCStatus(&fir_lepton_handle, &status) != LEP_OK) {
@ -723,11 +723,11 @@ void fir_lepton_trigger_ffc(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
break;
}
if ((systick_current_millis() - start) >= timeout) {
if ((mp_hal_ticks_ms() - start) >= timeout) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Timeout!"));
}
systick_sleep(1);
mp_hal_delay_ms(1);
}
}
}

View File

@ -27,7 +27,6 @@
#include "hm01b0.h"
#include "paj6100.h"
#include "gc2145.h"
#include "systick.h"
#include "framebuffer.h"
#include "omv_boardconfig.h"
#include "unaligned_memcpy.h"
@ -199,10 +198,10 @@ int sensor_init()
/* Do a power cycle */
DCMI_PWDN_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
DCMI_PWDN_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
// Configure the sensor external clock (XCLK) to XCLK_FREQ.
//
@ -249,14 +248,14 @@ int sensor_init()
/* Reset the sensor */
DCMI_RESET_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
DCMI_RESET_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
// Initialize the camera bus.
cambus_init(&sensor.bus, ISC_I2C_ID, ISC_I2C_SPEED);
systick_sleep(10);
mp_hal_delay_ms(10);
/* Probe the sensor */
sensor.slv_addr = cambus_scan(&sensor.bus);
@ -267,7 +266,7 @@ int sensor_init()
/* Pull the sensor out of the reset state */
DCMI_RESET_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
/* Probe again to set the slave addr */
sensor.slv_addr = cambus_scan(&sensor.bus);
@ -275,14 +274,14 @@ int sensor_init()
sensor.pwdn_pol = ACTIVE_LOW;
DCMI_PWDN_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
sensor.slv_addr = cambus_scan(&sensor.bus);
if (sensor.slv_addr == 0) {
sensor.reset_pol = ACTIVE_HIGH;
DCMI_RESET_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
sensor.slv_addr = cambus_scan(&sensor.bus);
#ifndef OMV_ENABLE_NONI2CIS
@ -606,14 +605,14 @@ int sensor_reset()
// Hard-reset the sensor
if (sensor.reset_pol == ACTIVE_HIGH) {
DCMI_RESET_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
DCMI_RESET_LOW();
} else {
DCMI_RESET_LOW();
systick_sleep(10);
mp_hal_delay_ms(10);
DCMI_RESET_HIGH();
}
systick_sleep(20);
mp_hal_delay_ms(20);
// Call sensor-specific reset function
if (sensor.reset(&sensor) != 0) {
@ -720,7 +719,7 @@ int sensor_shutdown(int enable)
ret = sensor_dcmi_config(sensor.pixformat);
}
systick_sleep(10);
mp_hal_delay_ms(10);
return ret;
}
@ -783,7 +782,7 @@ int sensor_set_pixformat(pixformat_t pixformat)
return -1;
}
systick_sleep(100); // wait for the camera to settle
mp_hal_delay_ms(100); // wait for the camera to settle
// Set pixel format
sensor.pixformat = pixformat;
@ -817,7 +816,7 @@ int sensor_set_framesize(framesize_t framesize)
return -1;
}
systick_sleep(100); // wait for the camera to settle
mp_hal_delay_ms(100); // wait for the camera to settle
// Set framebuffer size
sensor.framesize = framesize;
@ -1037,7 +1036,7 @@ int sensor_set_hmirror(int enable)
return -1;
}
sensor.hmirror = enable;
systick_sleep(100); // wait for the camera to settle
mp_hal_delay_ms(100); // wait for the camera to settle
return 0;
}
@ -1062,7 +1061,7 @@ int sensor_set_vflip(int enable)
return -1;
}
sensor.vflip = enable;
systick_sleep(100); // wait for the camera to settle
mp_hal_delay_ms(100); // wait for the camera to settle
return 0;
}

View File

@ -37,13 +37,13 @@
#include <stdio.h>
#include <stdbool.h>
#include "systick.h"
#include "sensor.h"
#include "framebuffer.h"
#include "paj6100.h"
#include "paj6100_reg.h"
#include "pixspi.h"
#include "py/mphal.h"
#define CACHE_BANK
@ -358,7 +358,7 @@ static int sleep(sensor_t *sensor, int enable)
return -1;
}
// Sleep 30ms
systick_sleep(30);
mp_hal_delay_ms(30);
ret = read_regs_w_bank(BANK_1, REG_CMD_LPM_ENH, &val, 1);
if (ret) {
printf("Failed to read REG_CMD_SENSOR_MODE.\n");
@ -765,7 +765,7 @@ bool paj6100_detect(sensor_t *sensor)
uint8_t part_id_l, part_id_h;
DCMI_RESET_HIGH();
systick_sleep(10);
mp_hal_delay_ms(10);
if (!pixspi_init())
{