uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Macros | Functions
usb.h File Reference

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"
Include dependency graph for usb.h:
This graph shows which files directly or indirectly include this file:

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...
 

Detailed Description

USB CDC device API.

This module uses the LUFA library to provide serial communication over USB. TODO: More details...

Macro Definition Documentation

◆ CDC_NOTIFICATION_EPADDR

#define CDC_NOTIFICATION_EPADDR   (ENDPOINT_DIR_IN | 2)

Endpoint address of the CDC device-to-host notification IN endpoint.

◆ CDC_RX_EPADDR

#define CDC_RX_EPADDR   (ENDPOINT_DIR_OUT | 4)

Endpoint address of the CDC host-to-device data OUT endpoint.

◆ CDC_TX_EPADDR

#define CDC_TX_EPADDR   (ENDPOINT_DIR_IN | 3)

Endpoint address of the CDC device-to-host data IN endpoint.

◆ USB_NEWLINE

#define USB_NEWLINE   "\r\n"

Newline character sequence.

◆ USB_STRING_MAX_LENGTH

#define USB_STRING_MAX_LENGTH   100

Maximum length for strings printed with the usb_printf() function.

See also
usb_printf

Function Documentation

◆ init_usb_module()

void init_usb_module ( void  )

Initializes the USB CDC module.

Calls LUFA's USB_Init() function and enables interrupts.

◆ usb_bytes_received()

uint16_t usb_bytes_received ( void  )

Returns the number of unread bytes currently residing in the USB receive buffer.

Returns
the number of pending bytes

◆ usb_getc()

int16_t usb_getc ( void  )

Reads one byte or character from the USB receive buffer.

Returns
the character read cast to an int16_t or EOF

◆ usb_main_task()

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.

◆ usb_printf()

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.

See also
man 3 printf
USB_STRING_MAX_LENGTH

◆ usb_printf_S()

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.

See also
man 3 printf
USB_STRING_MAX_LENGTH

◆ usb_putc()

void usb_putc ( char  c)

Sends the given character over USB.

Flushes the USB send buffer.

◆ usb_puts()

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.

See also
USB_NEWLINE
USB_STRING_MAX_LENGTH
usb_puts_S

◆ usb_puts_S()

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.

See also
USB_NEWLINE
usb_puts

◆ usb_set_echo()

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.

Parameters
echonew value for the flag