# USB
[Core]

The USB subsystem provides access to USB Virtual Serial Port (CDC) functionality. More...

## Functions
int | Usb_SetActive (int state)
| Sets whether the Usb subsystem is active.
int | Usb_GetActive ()
| Read the active state of the Usb system.
int | Usb_Read (char *buffer, int length)
| Read from the USB port.
int | Usb_Write (char *buffer, int length)
| Write to the USB port.
int | Usb_SlipSend (char *buffer, int length)
| Write to the USB port using SLIP codes to packetize messages.
int | Usb_SlipReceive (char *buffer, int length)
| Read from the USB port using SLIP codes to de-packetize messages.

## Detailed Description

The USB subsystem provides access to USB Virtual Serial Port (CDC) functionality.

On OS X, the system USB CDC driver is used - no external drivers are needed. An entry in /dev is created - similar to /dev/cu.usbmodem.xxxx. It may be opened for reading and writing like a regular file using the standard POSIX open(), close(), read(), write() functions.

On Windows, the first time the device is seen, it needs to be pointed to a .INF file containing additional information - the make_controller_kit.inf in the same directory as this file. Once Windows sets this up, the device can be opened as a normal COM port. See also the mchelper codebase for code snippets.

Todo:
  expand usb support to include emulation of other kinds of USB device - mouse, keyboard, etc.

## Function Documentation

int Usb_GetActive | ( | void |  | ) |

Read the active state of the Usb system.

Returns:
  State - 1 (on) or 0 (off).

Definition at line 107 of file usb.c.

int Usb_Read | ( | char * | buffer,
|  | int | length |
| ) |  |  |

Read from the USB port.

Pass in a pointer to a char buffer to read into, and the number of characters requested to read. This function will return immediately with the number of characters read.

Parameters:

  | buffer | A pointer to a char buffer to read into
  | length | An integer specifying the number of characters to read

Returns:
  The number of characters successfully read.

Definition at line 121 of file usb.c.

int Usb_SetActive | ( | int | state | ) |

Sets whether the Usb subsystem is active.

Parameters:

  | state | An integer specifying the active state of the Usb system - 1 (on) or 0 (off).

Returns:
  Zero on success.

Definition at line 76 of file usb.c.

int Usb_SlipReceive | ( | char * | buffer,
|  | int | length |
| ) |  |  |

Read from the USB port using SLIP codes to de-packetize messages.

SLIP (Serial Line Internet Protocol) is a way to separate one "packet" from another on an open serial connection. This is the way OSC messages are sent over USB, for example. SLIP uses a simple start/end byte and an escape byte in case your data actually contains the start/end byte. This function will block until it has received a complete SLIP encoded message, and will pass back the original message with the SLIP codes removed.

Check the Wikipedia description of SLIP at http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol

Parameters:

  | buffer | A pointer to a char buffer to read into
  | length | An integer specifying the number of characters to read

Returns:
  The number of characters successfully written

Definition at line 255 of file usb.c.

int Usb_SlipSend | ( | char * | buffer,
|  | int | length |
| ) |  |  |

Write to the USB port using SLIP codes to packetize messages.

SLIP (Serial Line Internet Protocol) is a way to separate one "packet" from another on an open serial connection. This is the way OSC messages are sent over USB, for example. SLIP uses a simple start/end byte and an escape byte in case your data actually contains the start/end byte. Pass your normal buffer to this function to have the SLIP codes inserted and then write it out over USB.

Check the Wikipedia description of SLIP at http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol

Parameters:

  | buffer | A pointer to a char buffer to write from
  | length | An integer specifying the number of characters to write

Returns:
  The number of characters successfully written

Definition at line 203 of file usb.c.

int Usb_Write | ( | char * | buffer,
|  | int | length |
| ) |  |  |

Write to the USB port.

Pass in a pointer to a char buffer to from, and the number of characters requested to write.

Parameters:

  | buffer | A pointer to a char buffer to write from
  | length | An integer specifying the number of characters to write

Returns:
  The number of characters successfully written

Definition at line 158 of file usb.c.