updated with requested changes

This commit is contained in:
sommersoft 2018-03-24 00:55:48 +00:00
parent f237657e5e
commit ef16109c5d

View File

@ -102,12 +102,13 @@ static void init_hardware(void) {
#endif #endif
} }
COMPILER_ALIGNED(4) uint8_t cdc_packet_buffer[64]; #define CDC_BULKOUT_SIZE CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ
COMPILER_ALIGNED(4) uint8_t cdc_packet_buffer[CDC_BULKOUT_SIZE];
static volatile bool pending_read; static volatile bool pending_read;
static int32_t start_read(void) { static int32_t start_read(void) {
pending_read = true; pending_read = true;
int32_t result = cdcdf_acm_read(cdc_packet_buffer, 64); int32_t result = cdcdf_acm_read(cdc_packet_buffer, CDC_BULKOUT_SIZE);
if (result != ERR_NONE) { if (result != ERR_NONE) {
pending_read = false; pending_read = false;
} }
@ -151,14 +152,6 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
} }
atomic_leave_critical(&flags); atomic_leave_critical(&flags);
// Trigger a follow up read if we have space.
/*if (usb_rx_count < USB_RX_BUF_SIZE - 64) {
int32_t result = start_read();
if (result != ERR_NONE) {
return true;
}
}*/
/* No error. */ /* No error. */
return false; return false;
} }
@ -247,7 +240,7 @@ static bool cdc_enabled(void) {
bool usb_bytes_available(void) { bool usb_bytes_available(void) {
// Check if the buffer has data, but not enough // Check if the buffer has data, but not enough
// space to hold another read. // space to hold another read.
if (usb_rx_count > 64) { if (usb_rx_count > CDC_BULKOUT_SIZE) {
return usb_rx_count > 0; return usb_rx_count > 0;
} }
// Buffer has enough room // Buffer has enough room
@ -277,11 +270,6 @@ int usb_read(void) {
} }
CRITICAL_SECTION_LEAVE(); CRITICAL_SECTION_LEAVE();
// Trigger a new read because we just cleared some space.
/*if (!pending_read && usb_rx_count == USB_RX_BUF_SIZE - 1) {
start_read();
}*/
return data; return data;
} }
@ -328,12 +316,10 @@ bool usb_connected(void) {
// Poll for input if keyboard interrupts are enabled, // Poll for input if keyboard interrupts are enabled,
// so that we can check for the interrupt char. read_complete() does the checking. // so that we can check for the interrupt char. read_complete() does the checking.
// also make sure we have enough room in the local buffer
void usb_cdc_background() { void usb_cdc_background() {
// //
if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read) { if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read && usb_rx_count < CDC_BULKOUT_SIZE) {
// Make sure we have space in the buffer
if (usb_rx_count < 64) {
start_read(); start_read();
} }
} }
}