Update debugging protocol to be more consistent.

* All commands now send a 6-bytes header followed by the payload in a separate packet.
This commit is contained in:
iabdalkader 2020-01-21 20:12:20 +02:00
parent 2962c0ce0c
commit 77b82d3b76
3 changed files with 50 additions and 34 deletions

View File

@ -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);
case USBDBG_ATTR_WRITE:
xfer_bytes = 0;
xfer_length =length;
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;
}
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;
}

View File

@ -128,7 +128,8 @@ def save_descriptor(x, y, w, h, path):
__serial.write(buf)
def set_attr(attr, value):
__serial.write(struct.pack("<BBIhh", __USBDBG_CMD, __USBDBG_ATTR_WRITE, 0, attr, value))
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_ATTR_WRITE, 8))
__serial.write(struct.pack("<II", attr, value))
def get_attr(attr):
__serial.write(struct.pack("<BBIh", __USBDBG_CMD, __USBDBG_ATTR_READ, 1, attr))
@ -163,7 +164,8 @@ def fw_version():
return struct.unpack("III", __serial.read(12))
def enable_fb(enable):
__serial.write(struct.pack("<BBIH", __USBDBG_CMD, __USBDBG_FB_ENABLE, 0, enable))
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FB_ENABLE, 4))
__serial.write(struct.pack("<I", enable))
def arch_str():
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_ARCH_STR, 64))

View File

@ -170,7 +170,8 @@ def save_descriptor(port, x, y, w, h, path):
def set_attr(port, attr, value):
try:
idx = __port.index(port)
__serial[idx].write(struct.pack("<BBIhh", __USBDBG_CMD, __USBDBG_ATTR_WRITE, 0, attr, value))
__serial[idx].write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_ATTR_WRITE, 8))
__serial[idx].write(struct.pack("<II", attr, value))
except:
pass
@ -246,7 +247,8 @@ def fw_version(port):
def enable_fb(port, enable):
try:
idx = __port.index(port)
__serial[idx].write(struct.pack("<BBIH", __USBDBG_CMD, __USBDBG_FB_ENABLE, 0, enable))
__serial[idx].write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_FB_ENABLE, 4))
__serial[idx].write(struct.pack("<I", enable))
except:
pass