diff --git a/common/tinyusb_debug.c b/common/tinyusb_debug.c deleted file mode 100644 index e6c2f5206..000000000 --- a/common/tinyusb_debug.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2022-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Tinyusb CDC debugger helper code. - */ - -#include "omv_boardconfig.h" - -#if OMV_TUSBDBG_ENABLE -#include "py/runtime.h" -#include "py/stream.h" -#include "py/mphal.h" -#include "py/ringbuf.h" -#include "pendsv.h" - -#include "tusb.h" -#include "usbdbg.h" -#include "tinyusb_debug.h" -#include "omv_common.h" -#include "cmsis_gcc.h" - -#define USBDBG_DATA_TIMEOUT (1000) -#define DEBUG_EP_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) - -typedef struct { - 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; - -static debug_context_t ctx; - -uint32_t usb_cdc_buf_len() { - return ringbuf_avail(&ctx.ringbuf); -} - -uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len) { - // Read all of the request bytes. - if (ringbuf_get_bytes(&ctx.ringbuf, buf, len) == 0) { - return len; - } - - // Try to read as much data as possible. - uint32_t bytes = 0; - for (; bytes < len; bytes++) { - int c = ringbuf_get(&ctx.ringbuf); - if (c == -1) { - break; - } - buf[bytes] = c; - } - - return bytes; -} - -void usb_cdc_reset_buffers(void) { - ctx.ringbuf.iget = 0; - ctx.ringbuf.iput = 0; -} - -void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *coding) { - usb_cdc_reset_buffers(); - - #if defined(MICROPY_BOARD_ENTER_BOOTLOADER) - if (coding->bit_rate == 1200) { - MICROPY_BOARD_ENTER_BOOTLOADER(0, 0); - } - #endif - - ctx.debug_mode = (coding->bit_rate == USBDBG_BAUDRATE_SLOW || - coding->bit_rate == USBDBG_BAUDRATE_FAST); -} - -// Wrapped MicroPython functions. -void __wrap_mp_usbd_task(void) { - extern void __real_mp_usbd_task(void); - - if (!tinyusb_debug_enabled()) { - __real_mp_usbd_task(); - } -} - -void __wrap_tud_cdc_rx_cb(uint8_t itf) { - extern void __real_tud_cdc_rx_cb(uint8_t itf); - - if (!tinyusb_debug_enabled()) { - __real_tud_cdc_rx_cb(itf); - } -} - -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()) { - return __real_mp_hal_stdio_poll(poll_flags); - } - return 0; -} - -mp_uint_t __wrap_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { - extern mp_uint_t __real_mp_hal_stdout_tx_strn(const char *str, mp_uint_t len); - - 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++) { - // On overflow, reset the ring buffer, if this string fits - // entirely in the buffer, to recover from broken strings. - if (ringbuf_put(&ctx.ringbuf, str[i]) == -1 && len <= ctx.ringbuf.size) { - usb_cdc_reset_buffers(); - ringbuf_put(&ctx.ringbuf, str[i]); - } - } - } - return 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) { - tud_task_ext(0, false); - - if (!tinyusb_debug_enabled() || !tud_cdc_connected()) { - return; - } - - if (!ctx.length && tud_cdc_available() >= USBDBG_HEADER_SIZE) { - uint8_t cmdbuf[USBDBG_HEADER_SIZE]; - tud_cdc_read(cmdbuf, sizeof(cmdbuf)); - - if (cmdbuf[0] == 0x30) { - ctx.opcode = cmdbuf[1]; - ctx.length = *((uint32_t *) (cmdbuf + 2)); - usbdbg_control(NULL, ctx.opcode, ctx.length); - } - - if (ctx.length > 0) { - ctx.timestamp = mp_hal_ticks_ms(); - } - } - - while (ctx.length) { - uint32_t bytes = 0; - - if (tud_task_event_ready()) { - tud_task_ext(0, false); - } - - if (ctx.opcode & 0x80) { - bytes = OMV_MIN(ctx.length, tud_cdc_write_available()); - if (bytes) { - ctx.length -= bytes; - usbdbg_data_in(bytes, tud_cdc_write); - } - if (bytes > 0 && bytes < DEBUG_EP_SIZE) { - tud_cdc_write_flush(); - } - } else { - bytes = OMV_MIN(ctx.length, tud_cdc_available()); - if (bytes) { - ctx.length -= bytes; - usbdbg_data_out(bytes, 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(); - } - } -} - -// For the mimxrt, and nrf ports this replaces the weak USB IRQ handlers. -// For the RP2 port, this handler is installed in main.c -void OMV_USB1_IRQ_HANDLER(void) { - dcd_int_handler(0); - // If there are any event to process, schedule a call to cdc loop. - if (tud_task_event_ready()) { - mp_sched_schedule_node(&ctx.sched_node, tinyusb_debug_task); - } -} - -#if defined(OMV_USB2_IRQ_HANDLER) -void OMV_USB2_IRQ_HANDLER(void) { - dcd_int_handler(1); - // If there are any event to process, schedule a call to cdc loop. - if (tud_task_event_ready()) { - mp_sched_schedule_node(&ctx.sched_node, tinyusb_debug_task); - } -} -#endif - -#endif //OMV_TINYUSB_DEBUG diff --git a/common/tinyusb_debug.h b/common/tinyusb_debug.h deleted file mode 100644 index d8c92a966..000000000 --- a/common/tinyusb_debug.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2022-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Tinyusb CDC debugger helper code. - */ -#ifndef __TUSBDBG_H__ -void USBD_IRQHandler(void); -int tinyusb_debug_init(void); -bool tinyusb_debug_enabled(void); -#endif // __TUSBDBG_H__ diff --git a/common/usbdbg.c b/common/usbdbg.c deleted file mode 100644 index a9d4eb4d0..000000000 --- a/common/usbdbg.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2013-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * USB debugger. - */ -#include -#include -#include "py/nlr.h" -#include "py/gc.h" -#include "py/mphal.h" -#include "py/obj.h" -#include "py/objstr.h" -#include "py/runtime.h" - -#include "imlib.h" -#if MICROPY_PY_CSI || MICROPY_PY_CSI_NG -#include "omv_i2c.h" -#include "omv_csi.h" -#endif -#include "framebuffer.h" -#include "usbdbg.h" -#include "tinyusb_debug.h" -#include "omv_boardconfig.h" -#include "py_image.h" - -static int xfer_offs; -static int xfer_size; -static enum usbdbg_cmd cmd; - -static volatile bool script_ready; -static volatile bool script_running; -static volatile bool irq_enabled; -static vstr_t script_buf; - -// These functions must be implemented by the stack. -extern uint32_t usb_cdc_buf_len(); -extern uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len); -extern void usb_cdc_reset_buffers(void); - -void usbdbg_init() { - cmd = USBDBG_NONE; - script_ready = false; - script_running = false; - irq_enabled = false; - vstr_init(&script_buf, 32); - #if OMV_TUSBDBG_ENABLE - tinyusb_debug_init(); - #endif - #if OMV_PROFILER_ENABLE - omv_profiler_init(); - #endif -} - -bool usbdbg_script_ready() { - return script_ready; -} - -vstr_t *usbdbg_get_script() { - return &script_buf; -} - -bool usbdbg_is_busy() { - return cmd != USBDBG_NONE; -} - -void usbdbg_set_script_running(bool running) { - script_running = running; -} - -inline void usbdbg_set_irq_enabled(bool enabled) { - if (enabled) { - NVIC_EnableIRQ(OMV_USB_IRQN); - } else { - NVIC_DisableIRQ(OMV_USB_IRQN); - } - __DSB(); __ISB(); - irq_enabled = enabled; -} - -static void usbdbg_interrupt_vm(bool ready) { - // Set script ready flag - script_ready = ready; - - // Set script running flag - script_running = ready; - - // Disable IDE IRQ (re-enabled by pyexec or in main). - usbdbg_set_irq_enabled(false); - - // Abort the VM. - mp_sched_vm_abort(); - - // When the VM runs again it will raise a KeyboardInterrupt. - mp_sched_keyboard_interrupt(); -} - -bool usbdbg_get_irq_enabled() { - return irq_enabled; -} - -void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) { - switch (cmd) { - case USBDBG_FW_VERSION: { - uint32_t buffer[3] = { - FIRMWARE_VERSION_MAJOR, - FIRMWARE_VERSION_MINOR, - FIRMWARE_VERSION_PATCH, - }; - cmd = USBDBG_NONE; - write_callback(&buffer, sizeof(buffer)); - break; - } - - case USBDBG_TX_BUF_LEN: { - uint32_t tx_buf_len = usb_cdc_buf_len(); - cmd = USBDBG_NONE; - write_callback(&tx_buf_len, sizeof(tx_buf_len)); - break; - } - - case USBDBG_SENSOR_ID: { - uint32_t buffer = 0xFF; - #if MICROPY_PY_CSI - omv_csi_t *csi = omv_csi_get(-1); - if (omv_csi_is_detected(csi) == true) { - buffer = omv_csi_get_id(csi); - } - #endif - cmd = USBDBG_NONE; - write_callback(&buffer, sizeof(buffer)); - break; - } - - case USBDBG_TX_BUF: { - uint8_t buffer[size]; - size = usb_cdc_get_buf(buffer, size); - xfer_offs += size; - if (xfer_offs == xfer_size) { - cmd = USBDBG_NONE; - } - if (size) { - write_callback(buffer, size); - } - break; - } - - case USBDBG_FRAME_SIZE: { - // Return 0 if FB is locked or not ready. - uint32_t buffer[3] = { 0 }; - // Try to lock FB. If header size == 0 frame is not ready - framebuffer_t *fb = framebuffer_get(FB_STREAM_ID); - if (mutex_try_lock(&fb->lock, MUTEX_TID_IDE)) { - // If header size == 0 frame is not ready - if (fb->size == 0) { - // unlock FB - mutex_unlock(&fb->lock, MUTEX_TID_IDE); - } else { - // Return header w, h and size/bpp - buffer[0] = fb->w; - buffer[1] = fb->h; - buffer[2] = fb->size; - } - } - cmd = USBDBG_NONE; - write_callback(&buffer, sizeof(buffer)); - break; - } - - case USBDBG_FRAME_DUMP: - if (xfer_offs < xfer_size) { - framebuffer_t *fb = framebuffer_get(FB_STREAM_ID); - write_callback(fb->raw_base + sizeof(framebuffer_header_t) + xfer_offs, size); - xfer_offs += size; - if (xfer_offs == xfer_size) { - cmd = USBDBG_NONE; - fb->w = 0; fb->h = 0; fb->size = 0; - mutex_unlock(&fb->lock, MUTEX_TID_IDE); - } - } - break; - - case USBDBG_ARCH_STR: { - uint8_t buffer[64]; - unsigned int uid[3] = { - #if (OMV_BOARD_UID_SIZE == 2) - 0U, - #else - *((unsigned int *) (OMV_BOARD_UID_ADDR + OMV_BOARD_UID_OFFSET * 2)), - #endif - *((unsigned int *) (OMV_BOARD_UID_ADDR + OMV_BOARD_UID_OFFSET * 1)), - *((unsigned int *) (OMV_BOARD_UID_ADDR + OMV_BOARD_UID_OFFSET * 0)), - }; - snprintf((char *) buffer, 64, "%s [%s:%08X%08X%08X]", - OMV_BOARD_ARCH, OMV_BOARD_TYPE, uid[0], uid[1], uid[2]); - cmd = USBDBG_NONE; - write_callback(&buffer, sizeof(buffer)); - break; - } - - case USBDBG_SCRIPT_RUNNING: { - cmd = USBDBG_NONE; - uint32_t buffer = script_running; - write_callback(&buffer, sizeof(buffer)); - break; - } - - case USBDBG_GET_STATE: { - // IDE will request 63/511 bytes of data to avoid ZLP packets. - // 64/512 packets still work too but generate ZLP packets. - size = OMV_MIN(size, 512); - uint8_t byte_buffer[size]; - memset(byte_buffer, 0, size); - uint32_t *buffer = (uint32_t *) byte_buffer; - static uint32_t last_update_ms = 0; - - // Set script running flag - if (script_running) { - buffer[0] |= USBDBG_FLAG_SCRIPT_RUNNING; - } - - // Set text buf valid flag. - uint32_t tx_buf_len = usb_cdc_buf_len(); - if (tx_buf_len) { - buffer[0] |= USBDBG_FLAG_TEXTBUF_NOTEMPTY; - } - - // Set code profiling flags - #if OMV_PROFILER_ENABLE - buffer[0] |= USBDBG_FLAG_PROFILE_ENABLED; - #if __PMU_PRESENT - buffer[0] |= USBDBG_FLAG_PROFILE_HAS_PMU; - #endif // __PMU_PRESENT - #endif // OMV_PROFILER_ENABLE - - // Limit the frames sent over USB to 20Hz. - framebuffer_t *fb = framebuffer_get(FB_STREAM_ID); - if (check_timeout_ms(last_update_ms, 50) && - mutex_try_lock_fair(&fb->lock, MUTEX_TID_IDE)) { - // If header size == 0 frame is not ready - if (fb->size == 0) { - // unlock FB - mutex_unlock(&fb->lock, MUTEX_TID_IDE); - } else { - // Set valid frame flag. - buffer[0] |= USBDBG_FLAG_FRAMEBUF_LOCKED; - - // Set frame width, height and size/bpp - buffer[1] = fb->w; - buffer[2] = fb->h; - buffer[3] = fb->size; - last_update_ms = mp_hal_ticks_ms(); - } - } - - // The rest of this packet is packed with text buffer. - if (tx_buf_len) { - const uint32_t hdr = 16; - tx_buf_len = OMV_MIN(tx_buf_len, (size - hdr - 1)); - usb_cdc_get_buf(byte_buffer + hdr, tx_buf_len); - byte_buffer[hdr + tx_buf_len] = 0; // Null-terminate - } - - cmd = USBDBG_NONE; - write_callback(&byte_buffer, size); - break; - } - - case USBDBG_PROFILE_SIZE: { - // Return 0 if the profiling data is locked. - uint32_t buffer[3] = { 0 }; - #if OMV_PROFILER_ENABLE - if (mutex_try_lock(omv_profiler_lock(), MUTEX_TID_IDE)) { - size_t size = omv_profiler_get_size(); - buffer[0] = size / sizeof(omv_profiler_data_t); - buffer[1] = sizeof(omv_profiler_data_t); - buffer[2] = __PMU_NUM_EVENTCNT; - } - #endif - cmd = USBDBG_NONE; - write_callback(&buffer, sizeof(buffer)); - break; - } - - #if OMV_PROFILER_ENABLE - case USBDBG_PROFILE_DUMP: - if (xfer_offs < xfer_size) { - const char *data = omv_profiler_get_data(); - write_callback(data + xfer_offs, size); - xfer_offs += size; - if (xfer_offs == xfer_size) { - cmd = USBDBG_NONE; - mutex_unlock(omv_profiler_lock(), MUTEX_TID_IDE); - } - } - break; - #endif - - default: /* error */ - break; - } -} - -void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback) { - switch (cmd) { - case USBDBG_FB_ENABLE: { - uint32_t enabled = 0; - framebuffer_t *fb = framebuffer_get(FB_STREAM_ID); - read_callback(&enabled, 4); - framebuffer_set_enabled(fb, enabled); - if (fb->enabled == 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(&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_offs will be less - // than the total size (xfer_size) and the script will Not be executed. - if (!script_running) { - nlr_buf_t nlr; - if (!gc_is_locked() && nlr_push(&nlr) == 0) { - char *buffer = vstr_add_len(&script_buf, size); - read_callback(buffer, size); - nlr_pop(); - } - xfer_offs += size; - if (xfer_offs == xfer_size) { - cmd = USBDBG_NONE; - // Schedule the IDE exception to interrupt the VM. - usbdbg_interrupt_vm(true); - } - } - break; - - case USBDBG_PROFILE_MODE: { - uint32_t buffer[1]; - read_callback(&buffer, sizeof(buffer)); - #if OMV_PROFILER_ENABLE - omv_profiler_set_mode(buffer[0]); - #endif - cmd = USBDBG_NONE; - break; - } - - case USBDBG_PROFILE_EVENT: { - uint32_t buffer[2]; - read_callback(&buffer, sizeof(buffer)); - #if OMV_PROFILER_ENABLE - omv_profiler_set_event(buffer[0], buffer[1]); - #endif - cmd = USBDBG_NONE; - break; - } - - default: /* error */ - size = OMV_MIN(size, 512); - uint8_t byte_buffer[size]; - read_callback(&byte_buffer, size); - break; - } -} - -void usbdbg_control(void *buffer, uint8_t request, uint32_t size) { - cmd = (enum usbdbg_cmd) request; - switch (cmd) { - case USBDBG_FW_VERSION: - case USBDBG_FRAME_SIZE: - case USBDBG_FRAME_DUMP: - 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: - case USBDBG_PROFILE_SIZE: - case USBDBG_PROFILE_DUMP: - case USBDBG_PROFILE_MODE: - case USBDBG_PROFILE_EVENT: - case USBDBG_SCRIPT_EXEC: - xfer_offs = 0; - xfer_size = size; - break; - - case USBDBG_PROFILE_RESET: { - #if OMV_PROFILER_ENABLE - omv_profiler_reset(); - #endif - cmd = USBDBG_NONE; - break; - } - - case USBDBG_SCRIPT_RUNNING: - vstr_reset(&script_buf); - xfer_offs = 0; - xfer_size = size; - break; - - case USBDBG_SCRIPT_STOP: - if (script_running) { - // Reset CDC buffers. - usb_cdc_reset_buffers(); - - // Schedule the IDE exception to interrupt the VM. - usbdbg_interrupt_vm(false); - } - cmd = USBDBG_NONE; - break; - - case USBDBG_SYS_RESET: - #if defined(OMV_BOARD_RESET) - OMV_BOARD_RESET(); - #else - NVIC_SystemReset(); - #endif - break; - - case USBDBG_SYS_RESET_TO_BL: { - #if defined(MICROPY_BOARD_ENTER_BOOTLOADER) - MICROPY_BOARD_ENTER_BOOTLOADER(0, 0); - #else - NVIC_SystemReset(); - #endif - break; - } - - default: /* error */ - cmd = USBDBG_NONE; - break; - } -} diff --git a/common/usbdbg.h b/common/usbdbg.h deleted file mode 100644 index 4a0895ffa..000000000 --- a/common/usbdbg.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2013-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * USB debug support. - */ -#ifndef __USBDBG_H__ -#define __USBDBG_H__ - -/** - * Firmware version (major, minor and patch numbers). - */ -#define FIRMWARE_VERSION_MAJOR (4) -#define FIRMWARE_VERSION_MINOR (7) -#define FIRMWARE_VERSION_PATCH (0) - -#define USBDBG_BAUDRATE_SLOW (921600) -#define USBDBG_BAUDRATE_FAST (12000000) -#define USBDBG_HEADER_SIZE (6) - -/** - * To add a new debugging command, increment the last command value used. - * Set the MSB of the value if the request has a device-to-host data phase. - * Add the command to usr/openmv.py using the same value. - * Handle the command control and data in/out (if any) phases in usbdbg.c. - * - * See usbdbg.c for examples. - */ -enum usbdbg_cmd { - USBDBG_NONE = 0x00, - USBDBG_FW_VERSION = 0x80, - USBDBG_FRAME_SIZE = 0x81, - USBDBG_FRAME_DUMP = 0x82, - USBDBG_ARCH_STR = 0x83, - USBDBG_SCRIPT_EXEC = 0x05, - USBDBG_SCRIPT_STOP = 0x06, - USBDBG_SCRIPT_RUNNING = 0x87, - USBDBG_SYS_RESET = 0x0C, - USBDBG_SYS_RESET_TO_BL = 0x0E, - USBDBG_FB_ENABLE = 0x0D, - USBDBG_TX_BUF_LEN = 0x8E, - USBDBG_TX_BUF = 0x8F, - USBDBG_SENSOR_ID = 0x90, - USBDBG_GET_STATE = 0x93, - USBDBG_PROFILE_SIZE = 0x94, - USBDBG_PROFILE_DUMP = 0x95, - USBDBG_PROFILE_MODE = 0x16, - USBDBG_PROFILE_EVENT = 0x17, - USBDBG_PROFILE_RESET = 0x18, -}; - -typedef enum { - USBDBG_FLAG_SCRIPT_RUNNING = (1 << 0), - USBDBG_FLAG_TEXTBUF_NOTEMPTY = (1 << 1), - USBDBG_FLAG_FRAMEBUF_LOCKED = (1 << 2), - USBDBG_FLAG_PROFILE_ENABLED = (1 << 3), - USBDBG_FLAG_PROFILE_HAS_PMU = (1 << 4), -} usbdbg_flags_t; - -typedef uint32_t (*usbdbg_read_callback_t) (void *buf, uint32_t len); -typedef uint32_t (*usbdbg_write_callback_t) (const void *buf, uint32_t len); - -void usbdbg_init(); -void usbdbg_wait_for_command(uint32_t timeout); -bool usbdbg_script_ready(); -vstr_t *usbdbg_get_script(); -bool usbdbg_is_busy(); -bool usbdbg_get_irq_enabled(); -void usbdbg_set_irq_enabled(bool enabled); -void usbdbg_set_script_running(bool running); -void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback); -void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback); -void usbdbg_control(void *buffer, uint8_t brequest, uint32_t wlength); - -#endif /* __USBDBG_H__ */