80 lines
1.8 KiB
C
80 lines
1.8 KiB
C
#ifndef CORE_USB_USB
|
|
#define CORE_USB_USB
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "usb_device_types.h"
|
|
#include "usb_driver_common.h"
|
|
|
|
// --------------
|
|
|
|
/**
|
|
* Setup transfer state.
|
|
*/
|
|
typedef struct {
|
|
USB_SetupRequest setup_req; ///< Setup request
|
|
uint8_t next_stage; ///< Next expected stage
|
|
bool out_complete; ///< Signals if transfer's OUT direction is complete, no later data reception is expected
|
|
uint16_t fup_sz; ///< Some SETUP response IN data follows
|
|
const uint8_t * fup_data; ///< Pointer on follow-up data
|
|
} Usb_SetupTransferState;
|
|
|
|
// --------------
|
|
|
|
/** \cond 0 */
|
|
#ifndef USB_RX_BUF_SIZE
|
|
#define USB_RX_BUF_SIZE (512) ///< Receive buffer size FIXME
|
|
#endif
|
|
/** \endcond */
|
|
|
|
// --------------
|
|
|
|
/**
|
|
* Initialize USB core.
|
|
*
|
|
* @param drvIntf pointer to a mutable driver interface object
|
|
*/
|
|
void usbcore_init(UsbDrv_DrvIntf *drvIntf);
|
|
|
|
/**
|
|
* Reset USB core.
|
|
*/
|
|
void usbcore_reset();
|
|
|
|
/**
|
|
* Write data to an IN Endpoint.
|
|
*
|
|
* @param ep index of the Endpoint
|
|
* @param data pointer to data to be written
|
|
* @param size data length
|
|
* @return number of bytes written
|
|
*/
|
|
uint32_t usbcore_schedule_transmission(uint8_t ep, const uint8_t *data, uint16_t size);
|
|
|
|
/**
|
|
* Expect ingress data on an Endpoint.
|
|
*
|
|
* @param ep index of the Endpoint
|
|
* @param size expected reception length
|
|
* @return message length that the endpoint can support during next reception
|
|
*/
|
|
uint32_t usbcore_schedule_reception(uint8_t ep, uint16_t size);
|
|
|
|
/**
|
|
* Wake up an Endpoint.
|
|
*
|
|
* @param ep index of the Endpoint
|
|
* @param dir direction of the Endpoint
|
|
*/
|
|
void usbcore_wake_up_endpoint(uint8_t ep, uint8_t dir);
|
|
|
|
/**
|
|
* Register a callback for IN transmission completion.
|
|
*
|
|
* @param ep index of the Endpoint
|
|
* @param cb callback function
|
|
*/
|
|
void usbcore_register_IN_callback(uint8_t ep, UsbDrv_IN_cb cb);
|
|
|
|
#endif /* CORE_USB_USB */
|