X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=megadrive.git;a=blobdiff_plain;f=teensy3%2Fusb_seremu.c;h=976a47b9939be92390f71a926d926601f226c235;hp=e4781e883e36715bd2af6305dac8d77eb4083501;hb=a773ac06cdc55be51ebc0bc61aa6066b54746c7d;hpb=f359b935ea6628421393610cf14f9fe6887b0d4c diff --git a/teensy3/usb_seremu.c b/teensy3/usb_seremu.c index e4781e8..976a47b 100644 --- a/teensy3/usb_seremu.c +++ b/teensy3/usb_seremu.c @@ -10,10 +10,10 @@ * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * - * 1. The above copyright notice and this permission notice shall be + * 1. The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * 2. If the Software is incorporated into a build system that allows + * 2. If the Software is incorporated into a build system that allows * selection among a list of target devices, then similar target * devices manufactured by PJRC.COM must be included in the list of * target devices and selectable in the same manner. @@ -28,7 +28,8 @@ * SOFTWARE. */ -//#include "mk20dx128.h" +#if F_CPU >= 20000000 + #include "usb_dev.h" #include "usb_seremu.h" #include "core_pins.h" // for yield() @@ -138,14 +139,23 @@ void usb_seremu_flush_input(void) // software. If it's too long, we stall the user's program when no software is running. #define TX_TIMEOUT_MSEC 30 -#if F_CPU == 96000000 +#if F_CPU == 168000000 + #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) +#elif F_CPU == 144000000 + #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) +#elif F_CPU == 120000000 + #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 764) +#elif F_CPU == 96000000 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) +#elif F_CPU == 72000000 + #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) #elif F_CPU == 48000000 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) #elif F_CPU == 24000000 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) #endif + // When we've suffered the transmit timeout, don't wait again until the computer // begins accepting data. If no software is running to receive, we'll just discard // data as rapidly as Serial.print() can generate it, until there's something to @@ -213,6 +223,24 @@ int usb_seremu_write(const void *buffer, uint32_t size) #endif } +int usb_seremu_write_buffer_free(void) +{ + uint32_t len; + + tx_noautoflush = 1; + if (!tx_packet) { + if (!usb_configuration || + usb_tx_packet_count(SEREMU_TX_ENDPOINT) >= TX_PACKET_LIMIT || + (tx_packet = usb_malloc()) == NULL) { + tx_noautoflush = 0; + return 0; + } + } + len = SEREMU_TX_SIZE - tx_packet->index; + tx_noautoflush = 0; + return len; +} + void usb_seremu_flush_output(void) { int i; @@ -247,3 +275,5 @@ void usb_seremu_flush_callback(void) } #endif // SEREMU_INTERFACE + +#endif // F_CPU >= 20 MHz