Author | Albert Faber, Copyright © 2008..2021, all rights reserved. |
Adapted-by | Matthew Schinkel, Rob Jansen |
Compiler | 2.5r5 |
USB Communication Device Class (CDC) code This USB library files contains the low level implementation to perform serial communication over a USB interface. The usage of this library requires detailed knowledge of the USB interface and requires that several configuration parameters are defined correctly. In order to make USB serial communication more accessible for the end user, I would highly recommend to use the usb_serial library
http://www.usb.org for USB specifications
No dependency found
var volatile byte cdc_rx_wr = 0
const byte USB_REQ_CLEAR_COMM_FEATURE = 0x04
var volatile byte cdc_tx_wr=0
var byte cdc_line_status = 0x00
const byte USB_REQ_SET_LINE_CODING = 0x20
var volatile byte cdc_rx_rd = 0
var volatile byte cdc_line_coding_parity at cdc_line_coding[5]
var volatile byte cdc_tx_rd=0
const byte USB_REQ_SET_CONTROL_LINE_STATE = 0x22
var volatile dword cdc_line_coding_dte_rate at cdc_line_coding[0]
var bit last_packet_is_full = false
const byte USB_REQ_GET_LINE_CODING = 0x21
const byte USB_REQ_SET_COMM_FEATURE = 0x02
const byte USB_REQ_SEND_BREAK = 0x23
var volatile byte cdc_line_coding_stop_bits at cdc_line_coding[4]
var volatile byte cdc_line_coding[7]
var volatile byte cdc_rx_free = USB_CDC_RX_BUFFER_SIZE
var volatile byte cdc_line_coding_data_bits at cdc_line_coding[6]
const byte USB_REQ_GET_ENCAPSULATED_RESPONSE = 0x01
const byte USB_REQ_SEND_ENCAPSULATED_COMMAND = 0x00
usb_handle_class_request_callback()
usb_handle_class_ctrl_read_callback()
usb_ep_data_out_callback(byte in end_point, word in buffer_addr, byte in byte_count)
usb_cdc_putc(byte in c)
usb_cdc_handle_tx()
usb_ep_data_in_callback(byte in end_point, word in buffer_addr, byte in byte_count)
usb_handle_class_ctrl_write_callback()
usb_sof_callback()
usb_cdc_setup()
usb_cdc_rx_avail() return bit
usb_cdc_line_status() return byte
usb_cdc_getc() return byte
usb_cdc_tx_empty() return byte
var volatile byte cdc_rx_wr = 0
Read and write pointer for the receive buffer.
const byte USB_REQ_CLEAR_COMM_FEATURE = 0x04
No documentation found
var volatile byte cdc_tx_wr=0
Read and write pointer for the transmit buffer.
var byte cdc_line_status = 0x00
No documentation found
const byte USB_REQ_SET_LINE_CODING = 0x20
No documentation found
var volatile byte cdc_rx_rd = 0
No documentation found
var volatile byte cdc_line_coding_parity at cdc_line_coding[5]
0=None, 1=Odd, 2=Even, 3=Mark, 4=Space
var volatile byte cdc_tx_rd=0
No documentation found
const byte USB_REQ_SET_CONTROL_LINE_STATE = 0x22
No documentation found
var volatile dword cdc_line_coding_dte_rate at cdc_line_coding[0]
data rate in bits per second
var bit last_packet_is_full = false
Variable used when transmitting data from the cdc_tx_buffer
const byte USB_REQ_GET_LINE_CODING = 0x21
No documentation found
const byte USB_REQ_SET_COMM_FEATURE = 0x02
No documentation found
const byte USB_REQ_SEND_BREAK = 0x23
No documentation found
var volatile byte cdc_line_coding_stop_bits at cdc_line_coding[4]
0=1 stop bit, 1=1.5 stop bits, 2=2 stop bits
var volatile byte cdc_line_coding[7]
No documentation found
var volatile byte cdc_rx_free = USB_CDC_RX_BUFFER_SIZE
No documentation found
var volatile byte cdc_line_coding_data_bits at cdc_line_coding[6]
5,6,7,8 or 16 bits
const byte USB_REQ_GET_ENCAPSULATED_RESPONSE = 0x01
No documentation found
const byte USB_REQ_SEND_ENCAPSULATED_COMMAND = 0x00
Class requests.
usb_handle_class_request_callback()
Handle the class request from the host.
usb_handle_class_ctrl_read_callback()
Handle the class read request from the Host. The only request handled is getting the line coding but we already sent that in usb_handle_class_request_callback()
usb_ep_data_out_callback(byte in end_point, word in buffer_addr, byte in byte_count)
This function is called when data can be received via the bulk interface Data in means that the Host is sending data to the device.
usb_cdc_putc(byte in c)
This usb_cdc_putc will transmit the specified character. Under normal conditions the character to be transmitted is placed into the fifo, so the call will be non blocking. This implies that buffer overruns can occur when the transmit FIFO is full. Therefore it is adviced to check the transmit FIFO state before calling this procedure to avoid buffer overruns. These buffer overrun issues have been addressed in the usb_serial library, therefore it is highly recommended to use this library instead of calling this low level procedure
usb_cdc_handle_tx()
This procedure will handle the transmission of the (bulk) data. The procedure check if there are pending characters in the tranmit FIFO. These character(s) are send in chunk(s), the chunk size is dependent on the configuration of the bulk interface endpoint determined by USB_CDC_BULK_IN_EP_SIZE.
usb_ep_data_in_callback(byte in end_point, word in buffer_addr, byte in byte_count)
This function is called when data can be transmitted via the bulk interface Data IN means that the device is sending data to the Host. Note: Only the parameter end_point is used.
usb_handle_class_ctrl_write_callback()
Handle the class write request from the Host. The only request handled is setting the line coding.
usb_sof_callback()
This procedure is called when the Start Of Frame interrupt flag is set. It starts the tranmission of any pending data (if present).
usb_cdc_setup()
This procedure will intialize the line status of the communicatin device class
usb_cdc_rx_avail() return bit
This function returns there has been a character received, function will return true if there is at least one pending receive character, false otherwise
usb_cdc_line_status() return byte
This function returns the line status. If on the host side the COM port has not been opened, the return status will be 0x00, otherwise it will be != 0
usb_cdc_getc() return byte
This usb_cdc_getc function wait (blocking) until a character has been received. The byte value of the received character is returned by this function
usb_cdc_tx_empty() return byte
This function returns the empty status of the transmit FIFO, it will return true if transmit FIFO is empty, false otherwise