mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add sensor_snapshot timeout
This commit is contained in:
parent
6cc4509a30
commit
e3f41d674e
@ -27,7 +27,10 @@ static mp_obj_t py_sensor_reset() {
|
||||
|
||||
static mp_obj_t py_sensor_snapshot() {
|
||||
mp_obj_t image = py_image(0, 0, 0, 0);
|
||||
sensor_snapshot((struct image*) py_image_cobj(image));
|
||||
if (sensor_snapshot((struct image*) py_image_cobj(image))==-1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(&mp_type_RuntimeError, "Sensor Timeout!!"));
|
||||
return mp_const_false;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@ -291,6 +291,7 @@ int sensor_snapshot(struct image *image)
|
||||
{
|
||||
volatile uint32_t addr;
|
||||
volatile uint16_t length;
|
||||
uint32_t snapshot_start;
|
||||
|
||||
addr = (uint32_t) fb->pixels;
|
||||
|
||||
@ -303,13 +304,22 @@ int sensor_snapshot(struct image *image)
|
||||
/* Lock framebuffer mutex */
|
||||
mutex_lock(&fb->lock);
|
||||
|
||||
// Snapshot start tick
|
||||
snapshot_start = HAL_GetTick();
|
||||
|
||||
/* Start the DCMI */
|
||||
HAL_DCMI_Start_DMA(&DCMIHandle,
|
||||
DCMI_MODE_SNAPSHOT, addr, length);
|
||||
|
||||
/* Wait for frame */
|
||||
while ((DCMI->CR & DCMI_CR_CAPTURE) != 0) {
|
||||
|
||||
if (sys_tick_has_passed(snapshot_start, 1000)) {
|
||||
// Sensor timeout, most likely a HW issue.
|
||||
// unlock fb mutex and abort the DMA request
|
||||
mutex_unlock(&fb->lock);
|
||||
HAL_DMA_Abort(&DMAHandle);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sensor.pixformat == PIXFORMAT_GRAYSCALE) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user