uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
USB CDC device driver implementation. More...
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include "lufa/LUFA/Drivers/USB/USB.h"
#include "leds.h"
#include "usb.h"
#include "usb_descriptors.h"
#include "system.h"
Functions | |
void | EVENT_USB_Device_Connect (void) |
Event handler for the library USB Connection event. More... | |
void | EVENT_USB_Device_Disconnect (void) |
Event handler for the library USB Disconnection event. More... | |
void | EVENT_USB_Device_ConfigurationChanged (void) |
Event handler for the library USB Configuration Changed event. More... | |
void | EVENT_USB_Device_ControlRequest (void) |
Event handler for the library USB Control Request reception event. More... | |
void | EVENT_CDC_Device_ControLineStateChanged (USB_ClassInfo_CDC_Device_t *const CDCInterfaceInfo) |
Callback for control line state changes. More... | |
static void | flush (void) |
Flushes the USB send buffer. More... | |
static void | send_string (const char *const string) |
Writes the given string to the USB send buffer and flushes it. More... | |
void | init_usb_module (void) |
Initializes the USB CDC module. More... | |
uint16_t | usb_bytes_received (void) |
Returns the number of unread bytes currently residing in the USB receive buffer. More... | |
int16_t | usb_getc (void) |
Reads one byte or character from the USB receive buffer. More... | |
void | usb_main_task (void) |
Main background task for USB CDC operation. More... | |
void | usb_printf (const char *const format,...) |
void | usb_printf_S (const char *const format,...) |
Does exactly what you would expect. ;-) More... | |
void | usb_putc (char c) |
Sends the given character over USB. More... | |
void | usb_puts (const char *const string) |
void | usb_puts_S (const char *const string) |
Sends the given string and a newline sequence over USB. More... | |
Variables | |
static USB_ClassInfo_CDC_Device_t | VirtualSerial_CDC_Interface |
LUFA CDC Class driver interface configuration and state information. More... | |
static bool | ok_to_send = 0 |
This flag indicates if the USB port is ready to send data. More... | |
USB CDC device driver implementation.
void EVENT_CDC_Device_ControLineStateChanged | ( | USB_ClassInfo_CDC_Device_t *const | CDCInterfaceInfo | ) |
Callback for control line state changes.
Sets / clears the ok_to_send flag.
void EVENT_USB_Device_ConfigurationChanged | ( | void | ) |
Event handler for the library USB Configuration Changed event.
Configures the endpoints or enters panic mode if something goes wrong.
void EVENT_USB_Device_Connect | ( | void | ) |
Event handler for the library USB Connection event.
Indicates device connection by flashing the red on-board LED.
void EVENT_USB_Device_ControlRequest | ( | void | ) |
Event handler for the library USB Control Request reception event.
void EVENT_USB_Device_Disconnect | ( | void | ) |
Event handler for the library USB Disconnection event.
Indicates device disconnection by flashing the red on-board LED.
|
static |
Flushes the USB send buffer.
Panics if something goes wrong!
void init_usb_module | ( | void | ) |
Initializes the USB CDC module.
Calls LUFA's USB_Init() function and enables interrupts.
|
static |
Writes the given string to the USB send buffer and flushes it.
Panics if something goes wrong!
uint16_t usb_bytes_received | ( | void | ) |
Returns the number of unread bytes currently residing in the USB receive buffer.
int16_t usb_getc | ( | void | ) |
Reads one byte or character from the USB receive buffer.
int16_t
or EOF
void usb_main_task | ( | void | ) |
Main background task for USB CDC operation.
Executes relevant LUFA tasks. This task should be included in the mid frequency background task queue. Depending on your application and requirements, it might also be reasonable to move this to either the slow or the fast queue - yielding lower resp. higher data transfer rates.
void usb_printf | ( | const char *const | format, |
... | |||
) |
void usb_printf_S | ( | const char * | format, |
... | |||
) |
Does exactly what you would expect. ;-)
Unlike the "real" printf
, this function does not return the number of written bytes, because it can not be guaranteed that the bytes really got sent over the bus. After writing the string to the send buffer, it is flushed. Also, strings formatted and printed with this function may not exceed a certain length, defined by USB_STRING_MAX_LENGTH. You should only rarely need this function. A possible use case is printing the contents of a modifiable string buffer without appending a newline sequence.
void usb_putc | ( | char | c | ) |
Sends the given character over USB.
Flushes the USB send buffer.
void usb_puts | ( | const char *const | string | ) |
void usb_puts_S | ( | const char * | string | ) |
Sends the given string and a newline sequence over USB.
Flushes the USB send buffer. You should only rarely need this function - namely when you have to modify or dynamically generate strings. Whenever you want to print a constant string you should place it in program space and use usb_puts instead.
|
static |
This flag indicates if the USB port is ready to send data.
The flag is set / cleared by a LUFA event callback.
|
static |
LUFA CDC Class driver interface configuration and state information.
This structure is passed to all CDC Class driver functions, so that multiple instances of the same class within a device can be differentiated from one another.