2019-01-24 15:39:20 +00:00
|
|
|
/*
|
|
|
|
* Code generated from Atmel Start.
|
|
|
|
*
|
|
|
|
* This file will be overwritten when reconfiguring your Atmel Start project.
|
|
|
|
* Please copy examples or other code you want to keep to a separate file or main.c
|
|
|
|
* to avoid loosing it when reconfiguring.
|
|
|
|
*/
|
|
|
|
#include "atmel_start.h"
|
|
|
|
#include "usb_start.h"
|
|
|
|
|
|
|
|
#define CDCD_ECHO_BUF_SIZ CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ
|
|
|
|
|
|
|
|
/** Buffers to receive and echo the communication bytes. */
|
|
|
|
static uint32_t usbd_cdc_buffer[CDCD_ECHO_BUF_SIZ / 4];
|
|
|
|
|
|
|
|
/** Ctrl endpoint buffer */
|
|
|
|
static uint8_t ctrl_buffer[64];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Callback invoked when bulk OUT data received
|
|
|
|
*/
|
|
|
|
static bool usb_device_cb_bulk_out(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
|
|
|
|
{
|
|
|
|
cdcdf_acm_write((uint8_t *)usbd_cdc_buffer, count);
|
|
|
|
|
|
|
|
/* No error. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Callback invoked when bulk IN data received
|
|
|
|
*/
|
|
|
|
static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count)
|
|
|
|
{
|
|
|
|
/* Echo data. */
|
|
|
|
cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));
|
|
|
|
|
|
|
|
/* No error. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Callback invoked when Line State Change
|
|
|
|
*/
|
|
|
|
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
|
|
|
|
{
|
|
|
|
if (state.rs232.DTR) {
|
|
|
|
/* Callbacks must be registered after endpoint allocation */
|
|
|
|
cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out);
|
|
|
|
cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in);
|
|
|
|
/* Start Rx */
|
|
|
|
cdcdf_acm_read((uint8_t *)usbd_cdc_buffer, sizeof(usbd_cdc_buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No error. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-19 20:33:36 +00:00
|
|
|
extern const struct usbd_descriptors usb_descs[];
|
|
|
|
|
2019-01-24 15:39:20 +00:00
|
|
|
/**
|
|
|
|
* \brief CDC ACM Init
|
|
|
|
*/
|
|
|
|
void cdc_device_acm_init(void)
|
|
|
|
{
|
|
|
|
/* usb stack init */
|
|
|
|
usbdc_init(ctrl_buffer);
|
|
|
|
|
|
|
|
/* usbdc_register_funcion inside */
|
|
|
|
cdcdf_acm_init();
|
|
|
|
|
2019-04-19 20:33:36 +00:00
|
|
|
usbdc_start((struct usbd_descriptors *) usb_descs);
|
2019-01-24 15:39:20 +00:00
|
|
|
usbdc_attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-01-30 10:19:19 +00:00
|
|
|
* \brief Start USB stack
|
2019-01-24 15:39:20 +00:00
|
|
|
*/
|
2019-01-30 10:19:19 +00:00
|
|
|
void usb_start(void)
|
2019-01-24 15:39:20 +00:00
|
|
|
{
|
|
|
|
while (!cdcdf_acm_is_enabled()) {
|
|
|
|
// wait cdc acm to be installed
|
|
|
|
};
|
|
|
|
|
|
|
|
cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
cdc_device_acm_init();
|
2019-04-18 15:59:19 +00:00
|
|
|
ccid_df_init();
|
2019-01-24 15:39:20 +00:00
|
|
|
}
|