fix buffer size bug (#1747)

* fix buffer size bug

* faster file over usbcdc - wip

* minimal faster display tx
This commit is contained in:
Totoo 2024-01-09 18:30:43 +01:00 committed by GitHub
parent ad94ae05c1
commit 0e6f303eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -40,13 +40,15 @@
SerialUSBDriver SUSBD1; SerialUSBDriver SUSBD1;
uint8_t usbBulkBuffer[USBSERIAL_BUFFERS_SIZE];
void bulk_out_receive(void) { void bulk_out_receive(void) {
int ret; int ret;
do { do {
ret = usb_transfer_schedule( ret = usb_transfer_schedule(
&usb_endpoint_bulk_out, &usb_endpoint_bulk_out,
&usb_endpoint_bulk_out.buffer[0], &usbBulkBuffer[0],
32, USBSERIAL_BUFFERS_SIZE,
serial_bulk_transfer_complete, serial_bulk_transfer_complete,
NULL); NULL);
@ -61,7 +63,7 @@ void serial_bulk_transfer_complete(void* user_data, unsigned int bytes_transferr
for (unsigned int i = 0; i < bytes_transferred; i++) { for (unsigned int i = 0; i < bytes_transferred; i++) {
msg_t ret; msg_t ret;
do { do {
ret = chIQPutI(&SUSBD1.iqueue, usb_endpoint_bulk_out.buffer[i]); ret = chIQPutI(&SUSBD1.iqueue, usbBulkBuffer[i]);
if (ret == Q_FULL) if (ret == Q_FULL)
chThdSleepMilliseconds(1); chThdSleepMilliseconds(1);
@ -73,9 +75,9 @@ void serial_bulk_transfer_complete(void* user_data, unsigned int bytes_transferr
static void onotify(GenericQueue* qp) { static void onotify(GenericQueue* qp) {
SerialUSBDriver* sdp = chQGetLink(qp); SerialUSBDriver* sdp = chQGetLink(qp);
uint8_t buff[64]; uint8_t buff[USBSERIAL_BUFFERS_SIZE];
int n = chOQGetFullI(&sdp->oqueue); int n = chOQGetFullI(&sdp->oqueue);
if (n > 64) n = 64; // don't overflow if (n > USBSERIAL_BUFFERS_SIZE) n = USBSERIAL_BUFFERS_SIZE; // don't overflow
if (n > 0) { if (n > 0) {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
buff[i] = chOQGetI(&sdp->oqueue); buff[i] = chOQGetI(&sdp->oqueue);
@ -139,8 +141,8 @@ static const struct SerialUSBDriverVMT vmt = {
void init_serial_usb_driver(SerialUSBDriver* sdp) { void init_serial_usb_driver(SerialUSBDriver* sdp) {
sdp->vmt = &vmt; sdp->vmt = &vmt;
chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, NULL, sdp); chIQInit(&sdp->iqueue, sdp->ib, USBSERIAL_BUFFERS_SIZE, NULL, sdp);
chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp); chOQInit(&sdp->oqueue, sdp->ob, USBSERIAL_BUFFERS_SIZE, onotify, sdp);
} }
// queue handler from ch // queue handler from ch

View File

@ -24,6 +24,10 @@
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#ifndef USBSERIAL_BUFFERS_SIZE
#define USBSERIAL_BUFFERS_SIZE 400
#endif
struct SerialUSBDriverVMT { struct SerialUSBDriverVMT {
_base_asynchronous_channel_methods _base_asynchronous_channel_methods
}; };
@ -33,8 +37,8 @@ struct SerialUSBDriver {
const struct SerialUSBDriverVMT* vmt; const struct SerialUSBDriverVMT* vmt;
InputQueue iqueue; /* Output queue.*/ InputQueue iqueue; /* Output queue.*/
OutputQueue oqueue; /* Input circular buffer.*/ OutputQueue oqueue; /* Input circular buffer.*/
uint8_t ib[SERIAL_BUFFERS_SIZE]; /* Output circular buffer.*/ uint8_t ib[USBSERIAL_BUFFERS_SIZE]; /* Output circular buffer.*/
uint8_t ob[SERIAL_BUFFERS_SIZE]; uint8_t ob[USBSERIAL_BUFFERS_SIZE];
}; };
typedef struct SerialUSBDriver SerialUSBDriver; typedef struct SerialUSBDriver SerialUSBDriver;

View File

@ -241,18 +241,17 @@ static void cmd_screenframeshort(BaseSequentialStream* chp, int argc, char* argv
for (int y = 0; y < ui::screen_height; y++) { for (int y = 0; y < ui::screen_height; y++) {
std::array<ui::ColorRGB888, ui::screen_width> row; std::array<ui::ColorRGB888, ui::screen_width> row;
portapack::display.read_pixels({0, y, ui::screen_width, 1}, row); portapack::display.read_pixels({0, y, ui::screen_width, 1}, row);
for (int px = 0; px < ui::screen_width; px += 60) { char buffer[242];
char buffer[60]; for (int i = 0; i < 240; ++i) {
for (int i = 0; i < 60; ++i) { buffer[i] = getChrFromRgb(row[i].r, row[i].g, row[i].b);
buffer[i] = getChrFromRgb(row[px + i].r, row[px + i].g, row[px + i].b);
} }
fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, 60); buffer[240] = '\r';
} buffer[241] = '\n';
chprintf(chp, "\r\n"); fillOBuffer(&((SerialUSBDriver*)chp)->oqueue, (const uint8_t*)buffer, 242);
} }
evtd->exit_shell_working_mode(); evtd->exit_shell_working_mode();
chprintf(chp, "ok\r\n"); chprintf(chp, "\r\nok\r\n");
} }
static void cmd_write_memory(BaseSequentialStream* chp, int argc, char* argv[]) { static void cmd_write_memory(BaseSequentialStream* chp, int argc, char* argv[]) {