Skip to content

Commit

Permalink
Merge branch 'dev_xel' into 'dev'
Browse files Browse the repository at this point in the history
See merge request maix_sw/k230_canmv!296
  • Loading branch information
kendryte747 committed Jul 30, 2024
2 parents 832c399 + 83803b3 commit cbd58e0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions micropython/port/builtin_py/media/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def deinit(cls, force = False):
if not force:
return

dma_dev_deinit()
ret = vb_mgmt_deinit()
if ret:
raise RuntimeError(f"MediaManager, vb_mgmt_deinit failed({ret})")

ret = kd_mpi_vb_exit()
if ret:
raise RuntimeError(f"MediaManager, vb deinit failed({ret})")
Expand Down
22 changes: 14 additions & 8 deletions micropython/port/builtin_py/media/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,12 @@ def snapshot(self, chn = CAM_CHN_ID_0):
status = 0
frame_info = k_video_frame_info()
try:
old = os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
virt_addr = 0
ret = kd_mpi_vicap_dump_frame(self._dev_id, chn, VICAP_DUMP_YUV, frame_info, 1000)
self._imgs[chn].push_phys(frame_info.v_frame.phys_addr[0])
if ret:
os.exitpoint(old)
raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) failed({ret})")
status = 1
phys_addr = frame_info.v_frame.phys_addr[0]
Expand All @@ -371,6 +373,7 @@ def snapshot(self, chn = CAM_CHN_ID_0):
img_size = img_width * img_height * 3
img_fmt = image.RGBP888
else:
os.exitpoint(old)
raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) not support pixelformat({fmt})")
virt_addr = kd_mpi_sys_mmap_cached(phys_addr, img_size)
self._imgs[chn].push_virt(virt_addr, img_size)
Expand All @@ -384,8 +387,10 @@ def snapshot(self, chn = CAM_CHN_ID_0):
else:
img = image.Image(img_width, img_height, img_fmt, alloc=image.ALLOC_VB, phyaddr=phys_addr, virtaddr=virt_addr, poolid=frame_info.pool_id)
else:
os.exitpoint(old)
raise RuntimeError(f"sensor({self._dev_id}) snapshot chn({chn}) mmap failed")

os.exitpoint(old)
return img
except Exception as e:
raise e
Expand Down Expand Up @@ -871,17 +876,18 @@ def stop(self, is_del = False):
raise AssertionError("should call reset() first")

if not is_del and not self._is_started:
raise AssertionError("should call run() first")
print("warning: sensor not call run()")

ret = kd_mpi_vicap_stop_stream(self._dev_id)
if not is_del and ret:
raise RuntimeError(f"sensor({self._dev_id}) stop error, stop stream failed({ret})")
if self._is_started:
ret = kd_mpi_vicap_stop_stream(self._dev_id)
if not is_del and ret:
raise RuntimeError(f"sensor({self._dev_id}) stop error, stop stream failed({ret})")

ret = kd_mpi_vicap_deinit(self._dev_id)
if not is_del and ret:
raise RuntimeError(f"sensor({self._dev_id}) stop error, vicap deinit failed({ret})")
ret = kd_mpi_vicap_deinit(self._dev_id)
if not is_del and ret:
raise RuntimeError(f"sensor({self._dev_id}) stop error, vicap deinit failed({ret})")

vb_mgmt_vicap_dev_deinited(self._dev_id)
vb_mgmt_vicap_dev_deinited(self._dev_id)

self._dev_attr.dev_enable = False
self._release_all_chn_image()
Expand Down
3 changes: 3 additions & 0 deletions micropython/port/builtin_py/mpp_binding/vb_func_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ DEF_INT_FUNC_INT(kd_mpi_vb_exit_mod_common_pool)
DEF_INT_FUNC_INT_STRUCTPTR(kd_mpi_vb_set_mod_pool_config, k_vb_config)
DEF_INT_FUNC_INT_STRUCTPTR(kd_mpi_vb_get_mod_pool_config, k_vb_config)

DEF_INT_FUNC_VOID(vb_mgmt_deinit)
DEF_VOID_FUNC_VOID(dma_dev_deinit)

DEF_INT_FUNC_STRUCTPTR(vb_mgmt_get_block, vb_block_info)
DEF_INT_FUNC_STRUCTPTR(vb_mgmt_put_block, vb_block_info)

Expand Down
2 changes: 2 additions & 0 deletions micropython/port/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
// clear terminal
// mp_hal_stdout_tx_strn("\033[H\033[2J", 7);
do_repl();

is_repl_intr = false;
}
fprintf(stderr, "[mpy] exit, reset\n");
main_thread_exit:
Expand Down
3 changes: 3 additions & 0 deletions micropython/port/include/core/mpp_vb_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ typedef struct
k_u32 size; // self.size = size, user set
}vb_block_info;

// in ide_dbg.c
extern void dma_dev_deinit(void);

extern k_s32 vb_mgmt_init(void);

extern k_s32 vb_mgmt_deinit(void);
Expand Down
2 changes: 1 addition & 1 deletion micropython/port/omv/ide_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ int kd_mpi_vo_osd_rotation(int flag, k_video_frame_info *in, k_video_frame_info

if(false == _dma_dev_init_flag) {
printf("did't init dma_dev\n");
return -1;
dma_dev_init();
}

kd_mpi_dma_stop_chn(OSD_ROTATION_DMA_CHN);
Expand Down

0 comments on commit cbd58e0

Please sign in to comment.