From 77b82d3b7657eb771b0fbd12623d6c92362431ff Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 21 Jan 2020 20:12:20 +0200 Subject: [PATCH] Update debugging protocol to be more consistent. * All commands now send a 6-bytes header followed by the payload in a separate packet. --- src/omv/usbdbg.c | 72 ++++++++++++++++++++++++----------------- tools/pyopenmv.py | 6 ++-- tools/pyopenmv_multi.py | 6 ++-- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/omv/usbdbg.c b/src/omv/usbdbg.c index 3ef6f6e77..9a4ea2bdc 100644 --- a/src/omv/usbdbg.c +++ b/src/omv/usbdbg.c @@ -150,6 +150,18 @@ extern int py_image_descriptor_from_roi(image_t *image, const char *path, rectan void usbdbg_data_out(void *buffer, int length) { switch (cmd) { + case USBDBG_FB_ENABLE: { + uint32_t enable = *((int32_t*)buffer); + JPEG_FB()->enabled = enable; + if (enable == 0) { + // When disabling framebuffer, the IDE might still be holding FB lock. + // If the IDE is not the current lock owner, this operation is ignored. + mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE); + } + cmd = USBDBG_NONE; + break; + } + case USBDBG_SCRIPT_EXEC: // check if GC is locked before allocating memory for vstr. If GC was locked // at least once before the script is fully uploaded xfer_bytes will be less @@ -216,6 +228,31 @@ void usbdbg_data_out(void *buffer, int length) py_image_descriptor_from_roi(&image, path, roi); break; } + + case USBDBG_ATTR_WRITE: { + /* write sensor attribute */ + int32_t attr= *((int32_t*)buffer); + int32_t val = *((int32_t*)buffer+1); + switch (attr) { + case ATTR_CONTRAST: + sensor_set_contrast(val); + break; + case ATTR_BRIGHTNESS: + sensor_set_brightness(val); + break; + case ATTR_SATURATION: + sensor_set_saturation(val); + break; + case ATTR_GAINCEILING: + sensor_set_gainceiling(val); + break; + default: + break; + } + cmd = USBDBG_NONE; + break; + } + default: /* error */ break; } @@ -283,43 +320,18 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length) xfer_length =length; break; - case USBDBG_ATTR_WRITE: { - /* write sensor attribute */ - int16_t attr= *((int16_t*)buffer); - int16_t val = *((int16_t*)buffer+1); - switch (attr) { - case ATTR_CONTRAST: - sensor_set_contrast(val); - break; - case ATTR_BRIGHTNESS: - sensor_set_brightness(val); - break; - case ATTR_SATURATION: - sensor_set_saturation(val); - break; - case ATTR_GAINCEILING: - sensor_set_gainceiling(val); - break; - default: - break; - } - cmd = USBDBG_NONE; + case USBDBG_ATTR_WRITE: + xfer_bytes = 0; + xfer_length =length; break; - } case USBDBG_SYS_RESET: NVIC_SystemReset(); break; case USBDBG_FB_ENABLE: { - int16_t enable = *((int16_t*)buffer); - JPEG_FB()->enabled = enable; - if (enable == 0) { - // When disabling framebuffer, the IDE might still be holding FB lock. - // If the IDE is not the current lock owner, this operation is ignored. - mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE); - } - cmd = USBDBG_NONE; + xfer_bytes = 0; + xfer_length = length; break; } diff --git a/tools/pyopenmv.py b/tools/pyopenmv.py index e27368da3..e2108bd6b 100755 --- a/tools/pyopenmv.py +++ b/tools/pyopenmv.py @@ -128,7 +128,8 @@ def save_descriptor(x, y, w, h, path): __serial.write(buf) def set_attr(attr, value): - __serial.write(struct.pack("