1 /* 2 * Copyright 2016 Google Inc. All Rights Reserved. 3 * Author: gkalsi@google.com (Gurjant Kalsi) 4 * 5 * Use of this source code is governed by a MIT-style 6 * license that can be found in the LICENSE file or at 7 * https://opensource.org/licenses/MIT 8 */ 9 10 #pragma once 11 12 #include <dev/usbc.h> 13 #include <kernel/event.h> 14 #include <sys/types.h> 15 16 typedef struct _cdcserial_channel_t cdcserial_channel_t; 17 typedef struct _cdcserial_channel_t { 18 int data_ep_addr; 19 int ctrl_ep_addr; 20 21 event_t txevt; 22 event_t rxevt; 23 24 volatile bool usb_online; 25 void (*online_cb)(cdcserial_channel_t *chan, bool online); 26 27 // A bitfield corresponding to the registered endpoints. When we get a 28 // USB_ONLINE event, these are the endpoints that we need to setup. 29 volatile uint16_t registered_bulk_eps_in; 30 volatile uint16_t registered_bulk_eps_out; 31 volatile uint16_t registered_intr_eps_in; 32 volatile uint16_t registered_intr_eps_out; 33 } cdcserial_channel_t; 34 35 void cdcserial_create_channel(cdcserial_channel_t *chan, int data_ep_addr, int ctrl_ep_addr); 36 37 // Write len bytes to the CDC Serial Virtual Com Port. 38 status_t cdcserial_write(cdcserial_channel_t *chan, size_t len, uint8_t *buf); 39 status_t cdcserial_write_async(cdcserial_channel_t *chan, usbc_transfer_t *transfer, ep_callback cb, 40 size_t len, uint8_t *buf); 41 42 // Read at most len bytes from the CDC Serial virtual Com Port. Returns the 43 // actual number of bytes read. 44 ssize_t cdcserial_read(cdcserial_channel_t *chan, size_t len, uint8_t *buf); 45 ssize_t cdcserial_read_async(cdcserial_channel_t *chan, usbc_transfer_t *transfer, ep_callback cb, 46 size_t len, uint8_t *buf); 47