u16 cdc_rx(u8 *buf, u16 size){ // The first byte is a control byte. if(cdc_rx_size() <= size){ cdc_rx_need_skip = 1; } return usb_read(buf, size, CDC_DATA_EP_OUT); }
static void handle_data(){ u8 read_count; char buf[CDC_DATA_EP_OUT_PACKET_SIZE + 1]; buf[0] = 'D'; // debug while(read_count = min(((u8)cdc_rx_size()), sizeof(buf) - 1)){ cdc_rx(buf + 1, read_count); } }
void cdc_polling(){ static __xdata u8 previous_frame_num = 0; u8 current_frame_num = usb_frame_num & 0xF0; // per 16 frames u8 read_count; char buf[CDC_DATA_EP_OUT_PACKET_SIZE + 1]; buf[0] = 'D'; // debug while(read_count = min(((u8)cdc_rx_size()), sizeof(buf) - 1)){ cdc_rx(buf + 1, read_count); } if(previous_frame_num == current_frame_num){ return; } previous_frame_num = current_frame_num; cdc_tx(NULL, 0); // flush #ifndef CDC_IS_REPLACED_BY_FTDI /*{ // ResponseAvailable static const __code u8 buf[] = { 0xA1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; usb_write(buf, sizeof(buf), CDC_COM_EP_IN); }*/ { // SerialState static const __code u8 buf[] = { 0xA1, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00 }; usb_write(buf, sizeof(buf), CDC_COM_EP_IN); } #endif }