mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
common: Refactor TinyUSB debug interface implementation.
This commit refactors the TinyUSB debug interface with the following changes: - Handle disabled IRQs. - Replace global variables with centralized state. - Add timeout, and validation for more robust transfers (as much as possible given the protocol limits). - Remove obsolete/unsupported commands (attr read/write, script save etc..) Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
29f07312f8
commit
90bd11e937
@ -49,6 +49,12 @@
|
|||||||
#define OMV_ALIGN_DOWN(x, alignment) \
|
#define OMV_ALIGN_DOWN(x, alignment) \
|
||||||
((uintptr_t)(x) & ~((uintptr_t)(alignment) - 1))
|
((uintptr_t)(x) & ~((uintptr_t)(alignment) - 1))
|
||||||
|
|
||||||
|
#define check_timeout_ms(start_ms, timeout) \
|
||||||
|
((mp_hal_ticks_ms() - start_ms) > timeout)
|
||||||
|
|
||||||
|
#define check_timeout_us(start_us, timeout) \
|
||||||
|
((mp_hal_ticks_us() - start_us) > timeout)
|
||||||
|
|
||||||
#ifdef OMV_DEBUG_PRINTF
|
#ifdef OMV_DEBUG_PRINTF
|
||||||
#define debug_printf(fmt, ...) \
|
#define debug_printf(fmt, ...) \
|
||||||
do { printf("%s(): " fmt, __func__, ##__VA_ARGS__);} while (0)
|
do { printf("%s(): " fmt, __func__, ##__VA_ARGS__);} while (0)
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "omv_boardconfig.h"
|
#include "omv_boardconfig.h"
|
||||||
#if (OMV_TUSBDBG_ENABLE == 1)
|
|
||||||
|
#if OMV_TUSBDBG_ENABLE
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/stream.h"
|
#include "py/stream.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
@ -36,158 +37,174 @@
|
|||||||
#include "usbdbg.h"
|
#include "usbdbg.h"
|
||||||
#include "tinyusb_debug.h"
|
#include "tinyusb_debug.h"
|
||||||
#include "omv_common.h"
|
#include "omv_common.h"
|
||||||
|
#include "cmsis_gcc.h"
|
||||||
|
|
||||||
#define USBDBG_BAUDRATE_SLOW (921600)
|
#define USBDBG_DATA_TIMEOUT (1000)
|
||||||
#define USBDBG_BAUDRATE_FAST (12000000)
|
|
||||||
#define DEBUG_EP_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define DEBUG_EP_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
void NORETURN __fatal_error(const char *msg);
|
typedef struct {
|
||||||
static mp_sched_node_t tusb_debug_node;
|
uint32_t timestamp;
|
||||||
|
uint8_t opcode;
|
||||||
|
uint32_t length;
|
||||||
|
bool debug_mode;
|
||||||
|
mp_sched_node_t sched_node;
|
||||||
|
ringbuf_t ringbuf;
|
||||||
|
uint8_t rawbuf[OMV_TUSBDBG_BUFFER];
|
||||||
|
} debug_context_t;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) {
|
static debug_context_t ctx;
|
||||||
uint8_t cmd;
|
|
||||||
uint8_t request;
|
|
||||||
uint32_t xfer_length;
|
|
||||||
}
|
|
||||||
usbdbg_cmd_t;
|
|
||||||
|
|
||||||
static uint8_t tx_array[OMV_TUSBDBG_BUFFER];
|
|
||||||
static ringbuf_t tx_ringbuf = { tx_array, sizeof(tx_array) };
|
|
||||||
static volatile bool tinyusb_debug_mode = false;
|
|
||||||
|
|
||||||
uint32_t usb_cdc_buf_len() {
|
uint32_t usb_cdc_buf_len() {
|
||||||
return ringbuf_avail(&tx_ringbuf);
|
return ringbuf_avail(&ctx.ringbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len) {
|
uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len) {
|
||||||
// Read all of the request bytes.
|
// Read all of the request bytes.
|
||||||
if (ringbuf_get_bytes(&tx_ringbuf, buf, len) == 0) {
|
if (ringbuf_get_bytes(&ctx.ringbuf, buf, len) == 0) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to read as much data as possible.
|
// Try to read as much data as possible.
|
||||||
uint32_t bytes = 0;
|
uint32_t bytes = 0;
|
||||||
for (; bytes < len; bytes++) {
|
for (; bytes < len; bytes++) {
|
||||||
int c = ringbuf_get(&tx_ringbuf);
|
int c = ringbuf_get(&ctx.ringbuf);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf[bytes] = c;
|
buf[bytes] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_cdc_reset_buffers(void) {
|
void usb_cdc_reset_buffers(void) {
|
||||||
tx_ringbuf.iget = 0;
|
ctx.ringbuf.iget = 0;
|
||||||
tx_ringbuf.iput = 0;
|
ctx.ringbuf.iput = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding) {
|
void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding) {
|
||||||
tx_ringbuf.iget = 0;
|
usb_cdc_reset_buffers();
|
||||||
tx_ringbuf.iput = 0;
|
|
||||||
|
|
||||||
if (0) {
|
|
||||||
#if defined(MICROPY_BOARD_ENTER_BOOTLOADER)
|
#if defined(MICROPY_BOARD_ENTER_BOOTLOADER)
|
||||||
} else if (coding->bit_rate == 1200) {
|
if (coding->bit_rate == 1200) {
|
||||||
MICROPY_BOARD_ENTER_BOOTLOADER(0, 0);
|
MICROPY_BOARD_ENTER_BOOTLOADER(0, 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (coding->bit_rate == USBDBG_BAUDRATE_SLOW ||
|
|
||||||
coding->bit_rate == USBDBG_BAUDRATE_FAST) {
|
ctx.debug_mode = (coding->bit_rate == USBDBG_BAUDRATE_SLOW ||
|
||||||
tinyusb_debug_mode = true;
|
coding->bit_rate == USBDBG_BAUDRATE_FAST);
|
||||||
} else {
|
|
||||||
tinyusb_debug_mode = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tinyusb_debug_enabled(void) {
|
// Wrapped MicroPython functions.
|
||||||
return tinyusb_debug_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern void __real_mp_usbd_task(void);
|
|
||||||
void __wrap_mp_usbd_task(void) {
|
void __wrap_mp_usbd_task(void) {
|
||||||
|
extern void __real_mp_usbd_task(void);
|
||||||
|
|
||||||
if (!tinyusb_debug_enabled()) {
|
if (!tinyusb_debug_enabled()) {
|
||||||
__real_mp_usbd_task();
|
__real_mp_usbd_task();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void __real_tud_cdc_rx_cb(uint8_t itf);
|
|
||||||
void __wrap_tud_cdc_rx_cb(uint8_t itf) {
|
void __wrap_tud_cdc_rx_cb(uint8_t itf) {
|
||||||
|
extern void __real_tud_cdc_rx_cb(uint8_t itf);
|
||||||
|
|
||||||
if (!tinyusb_debug_enabled()) {
|
if (!tinyusb_debug_enabled()) {
|
||||||
__real_tud_cdc_rx_cb(itf);
|
__real_tud_cdc_rx_cb(itf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uintptr_t __real_mp_hal_stdio_poll(uintptr_t poll_flags);
|
|
||||||
uintptr_t __wrap_mp_hal_stdio_poll(uintptr_t poll_flags) {
|
uintptr_t __wrap_mp_hal_stdio_poll(uintptr_t poll_flags) {
|
||||||
|
extern uintptr_t __real_mp_hal_stdio_poll(uintptr_t poll_flags);
|
||||||
|
|
||||||
if (!tinyusb_debug_enabled()) {
|
if (!tinyusb_debug_enabled()) {
|
||||||
return __real_mp_hal_stdio_poll(poll_flags);
|
return __real_mp_hal_stdio_poll(poll_flags);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
|
||||||
mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||||
if (tinyusb_debug_enabled()) {
|
extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
|
||||||
if (tud_cdc_connected()) {
|
|
||||||
|
if (!tinyusb_debug_enabled()) {
|
||||||
|
return __real_mp_hal_stdout_tx_strn(str, len);
|
||||||
|
} else if (tud_cdc_connected()) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
// The ring buffer overflows occasionally, espcially when using a slow poll
|
// On overflow, reset the ring buffer, if this string fits
|
||||||
// rate and fast print rate. When this happens, reset the buffer and start
|
// entirely in the buffer, to recover from broken strings.
|
||||||
// over, if this string fits entirely in the buffer. This helps the ring buffer
|
if (ringbuf_put(&ctx.ringbuf, str[i]) == -1 && len <= ctx.ringbuf.size) {
|
||||||
// self-recover from broken strings.
|
usb_cdc_reset_buffers();
|
||||||
if (ringbuf_put(&tx_ringbuf, str[i]) == -1 && len <= tx_ringbuf.size) {
|
ringbuf_put(&ctx.ringbuf, str[i]);
|
||||||
tx_ringbuf.iget = 0;
|
|
||||||
tx_ringbuf.iput = 0;
|
|
||||||
ringbuf_put(&tx_ringbuf, str[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
} else {
|
|
||||||
return __real_mp_hal_stdout_tx_strn(str, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tinyusb_debug_init(void) {
|
||||||
|
ctx.opcode = 0;
|
||||||
|
ctx.length = 0;
|
||||||
|
if (!ctx.ringbuf.buf) {
|
||||||
|
ctx.ringbuf = (ringbuf_t) { ctx.rawbuf, sizeof(ctx.rawbuf), 0, 0 };
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tinyusb_debug_enabled(void) {
|
||||||
|
return ctx.debug_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tinyusb_debug_task(mp_sched_node_t *node) {
|
void tinyusb_debug_task(mp_sched_node_t *node) {
|
||||||
tud_task_ext(0, false);
|
tud_task_ext(0, false);
|
||||||
|
|
||||||
if (!tinyusb_debug_enabled() || !tud_cdc_connected() || tud_cdc_available() < 6) {
|
if (!tinyusb_debug_enabled() || !tud_cdc_connected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
usbdbg_cmd_t cmd;
|
if (!ctx.length && tud_cdc_available() >= USBDBG_HEADER_SIZE) {
|
||||||
tud_cdc_read(&cmd, sizeof(cmd));
|
uint8_t cmdbuf[USBDBG_HEADER_SIZE];
|
||||||
|
tud_cdc_read(cmdbuf, sizeof(cmdbuf));
|
||||||
|
|
||||||
if (cmd.cmd != 0x30) {
|
if (cmdbuf[0] == 0x30) {
|
||||||
// TODO: Try to recover from this state but for now, call __fatal_error.
|
ctx.opcode = cmdbuf[1];
|
||||||
__fatal_error("Invalid USB CMD received.");
|
ctx.length = *((uint32_t*)(cmdbuf+2));
|
||||||
|
usbdbg_control(NULL, ctx.opcode, ctx.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t request = cmd.request;
|
if (ctx.length > 0) {
|
||||||
uint32_t xfer_length = cmd.xfer_length;
|
ctx.timestamp = mp_hal_ticks_ms();
|
||||||
usbdbg_control(NULL, request, xfer_length);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (ctx.length) {
|
||||||
|
uint32_t bytes = 0;
|
||||||
|
|
||||||
while (xfer_length) {
|
|
||||||
// && tud_cdc_connected())
|
|
||||||
if (tud_task_event_ready()) {
|
if (tud_task_event_ready()) {
|
||||||
tud_task_ext(0, false);
|
tud_task_ext(0, false);
|
||||||
}
|
}
|
||||||
if (request & 0x80) {
|
|
||||||
// Device-to-host data phase
|
if (ctx.opcode & 0x80) {
|
||||||
int size = OMV_MIN(xfer_length, tud_cdc_write_available());
|
bytes = OMV_MIN(ctx.length, tud_cdc_write_available());
|
||||||
if (size) {
|
if (bytes) {
|
||||||
xfer_length -= size;
|
ctx.length -= bytes;
|
||||||
usbdbg_data_in(size, tud_cdc_write);
|
usbdbg_data_in(bytes, tud_cdc_write);
|
||||||
}
|
}
|
||||||
if (size > 0 && size < DEBUG_EP_SIZE) {
|
if (bytes > 0 && bytes < DEBUG_EP_SIZE) {
|
||||||
tud_cdc_write_flush();
|
tud_cdc_write_flush();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Host-to-device data phase
|
bytes = OMV_MIN(ctx.length, tud_cdc_available());
|
||||||
int size = OMV_MIN(xfer_length, tud_cdc_available());
|
if (bytes) {
|
||||||
if (size) {
|
ctx.length -= bytes;
|
||||||
xfer_length -= size;
|
usbdbg_data_out(bytes, tud_cdc_read);
|
||||||
usbdbg_data_out(size, tud_cdc_read);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bytes) {
|
||||||
|
ctx.timestamp = mp_hal_ticks_ms();
|
||||||
|
} else if (__get_PRIMASK() & 1) {
|
||||||
|
break;
|
||||||
|
} else if (check_timeout_ms(ctx.timestamp, USBDBG_DATA_TIMEOUT)) {
|
||||||
|
tinyusb_debug_init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +214,7 @@ void OMV_USB1_IRQ_HANDLER(void) {
|
|||||||
dcd_int_handler(0);
|
dcd_int_handler(0);
|
||||||
// If there are any event to process, schedule a call to cdc loop.
|
// If there are any event to process, schedule a call to cdc loop.
|
||||||
if (tud_task_event_ready()) {
|
if (tud_task_event_ready()) {
|
||||||
mp_sched_schedule_node(&tusb_debug_node, tinyusb_debug_task);
|
mp_sched_schedule_node(&ctx.sched_node, tinyusb_debug_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +223,7 @@ void OMV_USB2_IRQ_HANDLER(void) {
|
|||||||
dcd_int_handler(1);
|
dcd_int_handler(1);
|
||||||
// If there are any event to process, schedule a call to cdc loop.
|
// If there are any event to process, schedule a call to cdc loop.
|
||||||
if (tud_task_event_ready()) {
|
if (tud_task_event_ready()) {
|
||||||
mp_sched_schedule_node(&tusb_debug_node, tinyusb_debug_task);
|
mp_sched_schedule_node(&ctx.sched_node, tinyusb_debug_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -27,5 +27,4 @@
|
|||||||
void USBD_IRQHandler(void);
|
void USBD_IRQHandler(void);
|
||||||
int tinyusb_debug_init(void);
|
int tinyusb_debug_init(void);
|
||||||
bool tinyusb_debug_enabled(void);
|
bool tinyusb_debug_enabled(void);
|
||||||
void tinyusb_debug_tx_strn(const char *str, mp_uint_t len);
|
|
||||||
#endif // __TUSBDBG_H__
|
#endif // __TUSBDBG_H__
|
||||||
|
|||||||
178
common/usbdbg.c
178
common/usbdbg.c
@ -39,6 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "usbdbg.h"
|
#include "usbdbg.h"
|
||||||
|
#include "tinyusb_debug.h"
|
||||||
#include "omv_boardconfig.h"
|
#include "omv_boardconfig.h"
|
||||||
#include "py_image.h"
|
#include "py_image.h"
|
||||||
|
|
||||||
@ -62,8 +63,10 @@ void usbdbg_init() {
|
|||||||
script_ready = false;
|
script_ready = false;
|
||||||
script_running = false;
|
script_running = false;
|
||||||
irq_enabled = false;
|
irq_enabled = false;
|
||||||
|
|
||||||
vstr_init(&script_buf, 32);
|
vstr_init(&script_buf, 32);
|
||||||
|
#if OMV_TUSBDBG_ENABLE
|
||||||
|
tinyusb_debug_init();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usbdbg_script_ready() {
|
bool usbdbg_script_ready() {
|
||||||
@ -113,16 +116,6 @@ bool usbdbg_get_irq_enabled() {
|
|||||||
return irq_enabled;
|
return irq_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ticks_diff_ms(uint32_t start_ms) {
|
|
||||||
uint32_t current_ms = mp_hal_ticks_ms();
|
|
||||||
if (current_ms >= start_ms) {
|
|
||||||
return current_ms - start_ms;
|
|
||||||
} else {
|
|
||||||
// Handle wraparound
|
|
||||||
return (UINT32_MAX - start_ms) + current_ms + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case USBDBG_FW_VERSION: {
|
case USBDBG_FW_VERSION: {
|
||||||
@ -248,7 +241,7 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit the frames sent over USB to 20Hz.
|
// Limit the frames sent over USB to 20Hz.
|
||||||
if (ticks_diff_ms(last_update_ms) > 50 &&
|
if (check_timeout_ms(last_update_ms, 50) &&
|
||||||
mutex_try_lock_fair(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
|
mutex_try_lock_fair(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
|
||||||
// If header size == 0 frame is not ready
|
// If header size == 0 frame is not ready
|
||||||
if (JPEG_FB()->size == 0) {
|
if (JPEG_FB()->size == 0) {
|
||||||
@ -317,93 +310,6 @@ void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_TEMPLATE_SAVE: {
|
|
||||||
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
|
|
||||||
image_t image;
|
|
||||||
framebuffer_t *fb = framebuffer_get(0);
|
|
||||||
|
|
||||||
framebuffer_init_image(fb, &image);
|
|
||||||
|
|
||||||
size = MIN(128, size);
|
|
||||||
char buffer[size];
|
|
||||||
read_callback(buffer, size);
|
|
||||||
buffer[size - 1] = 0;
|
|
||||||
|
|
||||||
rectangle_t *roi = (rectangle_t *) buffer;
|
|
||||||
char *path = (char *) buffer + sizeof(rectangle_t);
|
|
||||||
|
|
||||||
imlib_save_image(&image, path, roi, 50);
|
|
||||||
#endif //IMLIB_ENABLE_IMAGE_FILE_IO
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case USBDBG_DESCRIPTOR_SAVE: {
|
|
||||||
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO) \
|
|
||||||
&& defined(IMLIB_ENABLE_KEYPOINTS)
|
|
||||||
image_t image;
|
|
||||||
framebuffer_t *fb = framebuffer_get(0);
|
|
||||||
|
|
||||||
framebuffer_init_image(fb, &image);
|
|
||||||
|
|
||||||
size = MIN(128, size);
|
|
||||||
char buffer[size];
|
|
||||||
read_callback(buffer, size);
|
|
||||||
buffer[size - 1] = 0;
|
|
||||||
|
|
||||||
rectangle_t *roi = (rectangle_t *) buffer;
|
|
||||||
char *path = (char *) buffer + sizeof(rectangle_t);
|
|
||||||
|
|
||||||
py_image_descriptor_from_roi(&image, path, roi);
|
|
||||||
#endif //IMLIB_ENABLE_IMAGE_FILE_IO && IMLIB_ENABLE_KEYPOINTS
|
|
||||||
cmd = USBDBG_NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case USBDBG_ATTR_WRITE: {
|
|
||||||
#if MICROPY_PY_CSI
|
|
||||||
struct {
|
|
||||||
int32_t name;
|
|
||||||
int32_t value;
|
|
||||||
} attr;
|
|
||||||
|
|
||||||
omv_csi_t *csi = omv_csi_get(-1);
|
|
||||||
|
|
||||||
read_callback(&attr, sizeof(attr));
|
|
||||||
|
|
||||||
switch (attr.name) {
|
|
||||||
case OMV_CSI_ATTR_CONTRAST:
|
|
||||||
omv_csi_set_contrast(csi, attr.value);
|
|
||||||
break;
|
|
||||||
case OMV_CSI_ATTR_BRIGHTNESS:
|
|
||||||
omv_csi_set_brightness(csi, attr.value);
|
|
||||||
break;
|
|
||||||
case OMV_CSI_ATTR_SATURATION:
|
|
||||||
omv_csi_set_saturation(csi, attr.value);
|
|
||||||
break;
|
|
||||||
case OMV_CSI_ATTR_GAINCEILING:
|
|
||||||
omv_csi_set_gainceiling(csi, attr.value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
cmd = USBDBG_NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case USBDBG_SET_TIME: {
|
|
||||||
// TODO implement
|
|
||||||
uint8_t buffer[32];
|
|
||||||
read_callback(&buffer, sizeof(buffer));
|
|
||||||
cmd = USBDBG_NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case USBDBG_TX_INPUT: {
|
|
||||||
// TODO implement
|
|
||||||
cmd = USBDBG_NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: /* error */
|
default: /* error */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -413,29 +319,23 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t size) {
|
|||||||
cmd = (enum usbdbg_cmd) request;
|
cmd = (enum usbdbg_cmd) request;
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case USBDBG_FW_VERSION:
|
case USBDBG_FW_VERSION:
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_FRAME_SIZE:
|
case USBDBG_FRAME_SIZE:
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_FRAME_DUMP:
|
case USBDBG_FRAME_DUMP:
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_ARCH_STR:
|
case USBDBG_ARCH_STR:
|
||||||
|
case USBDBG_FB_ENABLE:
|
||||||
|
case USBDBG_TX_BUF:
|
||||||
|
case USBDBG_TX_BUF_LEN:
|
||||||
|
case USBDBG_SENSOR_ID:
|
||||||
|
case USBDBG_GET_STATE:
|
||||||
xfer_offs = 0;
|
xfer_offs = 0;
|
||||||
xfer_size = size;
|
xfer_size = size;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USBDBG_SCRIPT_RUNNING:
|
||||||
|
vstr_reset(&script_buf);
|
||||||
case USBDBG_SCRIPT_EXEC:
|
case USBDBG_SCRIPT_EXEC:
|
||||||
xfer_offs = 0;
|
xfer_offs = 0;
|
||||||
xfer_size = size;
|
xfer_size = size;
|
||||||
vstr_reset(&script_buf);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SCRIPT_STOP:
|
case USBDBG_SCRIPT_STOP:
|
||||||
@ -449,28 +349,6 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t size) {
|
|||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SCRIPT_SAVE:
|
|
||||||
// TODO: save running script
|
|
||||||
cmd = USBDBG_NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_SCRIPT_RUNNING:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_TEMPLATE_SAVE:
|
|
||||||
case USBDBG_DESCRIPTOR_SAVE:
|
|
||||||
/* save template */
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_ATTR_WRITE:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_SYS_RESET:
|
case USBDBG_SYS_RESET:
|
||||||
#if defined(OMV_BOARD_RESET)
|
#if defined(OMV_BOARD_RESET)
|
||||||
OMV_BOARD_RESET();
|
OMV_BOARD_RESET();
|
||||||
@ -488,38 +366,6 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t size) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case USBDBG_FB_ENABLE: {
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case USBDBG_TX_BUF:
|
|
||||||
case USBDBG_TX_BUF_LEN:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_SENSOR_ID:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_SET_TIME:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_TX_INPUT:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USBDBG_GET_STATE:
|
|
||||||
xfer_offs = 0;
|
|
||||||
xfer_size = size;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: /* error */
|
default: /* error */
|
||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#define USBDBG_BAUDRATE_SLOW (921600)
|
#define USBDBG_BAUDRATE_SLOW (921600)
|
||||||
#define USBDBG_BAUDRATE_FAST (12000000)
|
#define USBDBG_BAUDRATE_FAST (12000000)
|
||||||
|
#define USBDBG_HEADER_SIZE (6)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To add a new debugging command, increment the last command value used.
|
* To add a new debugging command, increment the last command value used.
|
||||||
@ -52,20 +53,13 @@ enum usbdbg_cmd {
|
|||||||
USBDBG_ARCH_STR = 0x83,
|
USBDBG_ARCH_STR = 0x83,
|
||||||
USBDBG_SCRIPT_EXEC = 0x05,
|
USBDBG_SCRIPT_EXEC = 0x05,
|
||||||
USBDBG_SCRIPT_STOP = 0x06,
|
USBDBG_SCRIPT_STOP = 0x06,
|
||||||
USBDBG_SCRIPT_SAVE = 0x07,
|
|
||||||
USBDBG_SCRIPT_RUNNING = 0x87,
|
USBDBG_SCRIPT_RUNNING = 0x87,
|
||||||
USBDBG_TEMPLATE_SAVE = 0x08,
|
|
||||||
USBDBG_DESCRIPTOR_SAVE = 0x09,
|
|
||||||
USBDBG_ATTR_READ = 0x8A,
|
|
||||||
USBDBG_ATTR_WRITE = 0x0B,
|
|
||||||
USBDBG_SYS_RESET = 0x0C,
|
USBDBG_SYS_RESET = 0x0C,
|
||||||
USBDBG_SYS_RESET_TO_BL = 0x0E,
|
USBDBG_SYS_RESET_TO_BL = 0x0E,
|
||||||
USBDBG_FB_ENABLE = 0x0D,
|
USBDBG_FB_ENABLE = 0x0D,
|
||||||
USBDBG_TX_BUF_LEN = 0x8E,
|
USBDBG_TX_BUF_LEN = 0x8E,
|
||||||
USBDBG_TX_BUF = 0x8F,
|
USBDBG_TX_BUF = 0x8F,
|
||||||
USBDBG_SENSOR_ID = 0x90,
|
USBDBG_SENSOR_ID = 0x90,
|
||||||
USBDBG_TX_INPUT = 0x11,
|
|
||||||
USBDBG_SET_TIME = 0x12,
|
|
||||||
USBDBG_GET_STATE = 0x93,
|
USBDBG_GET_STATE = 0x93,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user