Merge pull request #2492 from openmv/usbdbg_fix
Some checks failed
🔎 Check Code Formatting / formatting-check (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_GIGA) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NANO_33_BLE_SENSE) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NANO_RP2040_CONNECT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NICLA_VISION) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_PORTENTA_H7) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV2) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV3) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV4) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV4P) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMVPT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV_RT1060) (push) Has been cancelled
🔥 Firmware Build / code-size-report (push) Has been cancelled
🔥 Firmware Build / stable-release (push) Has been cancelled
🔥 Firmware Build / development-release (push) Has been cancelled

misc: Limit IDE FPS to 20Hz.
This commit is contained in:
Ibrahim Abdelkader 2024-11-09 23:08:27 +02:00 committed by GitHub
commit 7d7338d7dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -113,6 +113,16 @@ bool usbdbg_get_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) {
switch (cmd) {
case USBDBG_FW_VERSION: {
@ -218,6 +228,7 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
case USBDBG_GET_STATE: {
uint32_t buffer[16] = { 0 };
static uint32_t last_update_ms = 0;
// Set script running flag
if (script_running) {
@ -230,8 +241,9 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
buffer[0] |= USBDBG_STATE_FLAGS_TEXT;
}
// Try to lock FB. If header size == 0 frame is not ready
if (mutex_try_lock_alternate(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
// Limit the frames sent over USB to 20Hz.
if (ticks_diff_ms(last_update_ms) > 50 &&
mutex_try_lock_alternate(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
// If header size == 0 frame is not ready
if (JPEG_FB()->size == 0) {
// unlock FB
@ -244,6 +256,7 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
buffer[1] = JPEG_FB()->w;
buffer[2] = JPEG_FB()->h;
buffer[3] = JPEG_FB()->size;
last_update_ms = mp_hal_ticks_ms();
}
}