USB device stack; Added getter method for terminal_connected;
Fork of USBDevice by
Example of use:
#include "mbed.h" #include "USBSerial.h" USBSerial pc; DigitalOut blue_led(P0_20); int main() { blue_led = 1; while(!pc.getTerminal_connected()); //Wait for serial terminal to connect... while(1) { blue_led = 0; wait(0.2); blue_led = 1; wait(0.2); } }
Diff: USBDevice/USBHAL_KL25Z.cpp
- Revision:
- 60:0e6b3f44926e
- Parent:
- 43:c0605f23f916
--- a/USBDevice/USBHAL_KL25Z.cpp Thu Aug 13 15:46:06 2015 +0100 +++ b/USBDevice/USBHAL_KL25Z.cpp Fri Jan 15 07:45:55 2016 +0000 @@ -228,21 +228,21 @@ handshake_flag = USB_ENDPT_EPHSHK_MASK; if (IN_EP(endpoint)) { if (endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)] == NULL) - endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)] = (uint8_t *) malloc (64*2); + endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)] = (uint8_t *) malloc (64); buf = &endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)][0]; } else { if (endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)] == NULL) - endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)] = (uint8_t *) malloc (64*2); + endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)] = (uint8_t *) malloc (64); buf = &endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)][0]; } } else { if (IN_EP(endpoint)) { if (endpoint_buffer_iso[2] == NULL) - endpoint_buffer_iso[2] = (uint8_t *) malloc (1023*2); + endpoint_buffer_iso[2] = (uint8_t *) malloc (1023); buf = &endpoint_buffer_iso[2][0]; } else { if (endpoint_buffer_iso[0] == NULL) - endpoint_buffer_iso[0] = (uint8_t *) malloc (1023*2); + endpoint_buffer_iso[0] = (uint8_t *) malloc (1023); buf = &endpoint_buffer_iso[0][0]; } } @@ -491,6 +491,7 @@ uint32_t num = (USB0->STAT >> 4) & 0x0F; uint32_t dir = (USB0->STAT >> 3) & 0x01; uint32_t ev_odd = (USB0->STAT >> 2) & 0x01; + int endpoint = (num << 1) | dir; // setup packet if ((num == 0) && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == SETUP_TOKEN)) { @@ -507,9 +508,9 @@ if (num == 0) EP0out(); else { - epComplete |= (1 << EP(num)); - if ((instance->*(epCallback[EP(num) - 2]))()) { - epComplete &= ~(1 << EP(num)); + epComplete |= EP(endpoint); + if ((instance->*(epCallback[endpoint - 2]))()) { + epComplete &= ~EP(endpoint); } } } @@ -524,9 +525,9 @@ } } else { - epComplete |= (1 << (EP(num) + 1)); - if ((instance->*(epCallback[EP(num) + 1 - 2]))()) { - epComplete &= ~(1 << (EP(num) + 1)); + epComplete |= EP(endpoint); + if ((instance->*(epCallback[endpoint - 2]))()) { + epComplete &= ~EP(endpoint); } } }