uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
USB CDC device API. More...
#include <stdarg.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "lufa/LUFA/Drivers/USB/USB.h"
Go to the source code of this file.
Macros | |
#define | CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) |
Endpoint address of the CDC device-to-host notification IN endpoint. More... | |
#define | CDC_TX_EPADDR (ENDPOINT_DIR_IN | 3) |
Endpoint address of the CDC device-to-host data IN endpoint. More... | |
#define | CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 4) |
Endpoint address of the CDC host-to-device data OUT endpoint. More... | |
#define | USB_NEWLINE "\r\n" |
Newline character sequence. More... | |
#define | USB_STRING_MAX_LENGTH 100 |
Maximum length for strings printed with the usb_printf() function. More... | |
Functions | |
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 (PGM_P format,...) |
Does exactly what you would expect. ;-) More... | |
void | usb_printf_S (const char *format,...) |
Does exactly what you would expect. ;-) More... | |
void | usb_putc (char c) |
Sends the given character over USB. More... | |
void | usb_puts (PGM_P string) |
Sends the given program space string and a newline sequence over USB. More... | |
void | usb_puts_S (const char *string) |
Sends the given string and a newline sequence over USB. More... | |
void | usb_set_echo (bool echo) |
Enables / disables terminal echo. More... | |
USB CDC device API.
This module uses the LUFA library to provide serial communication over USB. TODO: More details...
#define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2) |
Endpoint address of the CDC device-to-host notification IN endpoint.
#define CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 4) |
Endpoint address of the CDC host-to-device data OUT endpoint.
#define CDC_TX_EPADDR (ENDPOINT_DIR_IN | 3) |
Endpoint address of the CDC device-to-host data IN endpoint.
#define USB_NEWLINE "\r\n" |
Newline character sequence.
#define USB_STRING_MAX_LENGTH 100 |
Maximum length for strings printed with the usb_printf()
function.
void init_usb_module | ( | void | ) |
Initializes the USB CDC module.
Calls LUFA's USB_Init() function and enables interrupts.
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 | ( | PGM_P | 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.
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 | ( | PGM_P | string | ) |
Sends the given program space string and a newline sequence over USB.
Flushes the USB send buffer. Strings printed with this function may not be longer than USB_STRING_MAX_LENGTH.
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.
void usb_set_echo | ( | bool | echo | ) |
Enables / disables terminal echo.
When the echo is enabled, every character received over USB is immediately sent back to the source to provide a shell / terminal-like interactive experience. While this is cool and desirable for user interaction, it most certainly is not a good idea, when you want to transfer larger character streams or even binary data.
echo | new value for the flag |