209 lines
6.1 KiB
C
209 lines
6.1 KiB
C
/**
|
|
* @file usb_dc.h
|
|
* @brief
|
|
*
|
|
* Copyright (c) 2022 sakumisu
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership. The
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
*/
|
|
#ifndef _USB_DC_H
|
|
#define _USB_DC_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* @brief USB Endpoint Configuration.
|
|
*
|
|
* Structure containing the USB endpoint configuration.
|
|
*/
|
|
struct usbd_endpoint_cfg {
|
|
/** The number associated with the EP in the device
|
|
* configuration structure
|
|
* IN EP = 0x80 | \<endpoint number\>
|
|
* OUT EP = 0x00 | \<endpoint number\>
|
|
*/
|
|
uint8_t ep_addr;
|
|
/** Endpoint Transfer Type.
|
|
* May be Bulk, Interrupt, Control or Isochronous
|
|
*/
|
|
uint8_t ep_type;
|
|
/** Endpoint max packet size */
|
|
uint16_t ep_mps;
|
|
};
|
|
|
|
/**
|
|
* @brief USB Device Core Layer API
|
|
* @defgroup _usb_device_core_api USB Device Core API
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief init device controller registers.
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usb_dc_init(void);
|
|
|
|
/**
|
|
* @brief deinit device controller registers.
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usb_dc_deinit(void);
|
|
|
|
/**
|
|
* @brief Set USB device address
|
|
*
|
|
* @param[in] addr Device address
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_set_address(const uint8_t addr);
|
|
|
|
/**
|
|
* @brief configure and enable endpoint.
|
|
*
|
|
* This function sets endpoint configuration according to one specified in USB.
|
|
* endpoint descriptor and then enables it for data transfers.
|
|
*
|
|
* @param [in] ep_desc Endpoint descriptor byte array.
|
|
*
|
|
* @return true if successfully configured and enabled.
|
|
*/
|
|
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg);
|
|
|
|
/**
|
|
* @brief Disable the selected endpoint
|
|
*
|
|
* Function to disable the selected endpoint. Upon success interrupts are
|
|
* disabled for the corresponding endpoint and the endpoint is no longer able
|
|
* for transmitting/receiving data.
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_close(const uint8_t ep);
|
|
|
|
/**
|
|
* @brief Set stall condition for the selected endpoint
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_set_stall(const uint8_t ep);
|
|
|
|
/**
|
|
* @brief Clear stall condition for the selected endpoint
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_clear_stall(const uint8_t ep);
|
|
|
|
/**
|
|
* @brief Check if the selected endpoint is stalled
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
* @param[out] stalled Endpoint stall status
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled);
|
|
|
|
/**
|
|
* @brief Setup in ep transfer setting and start transfer.
|
|
*
|
|
* This function is asynchronous.
|
|
* This function is similar to uart with tx dma.
|
|
*
|
|
* This function is called to write data to the specified endpoint. The
|
|
* supplied usbd_endpoint_callback function will be called when data is transmitted
|
|
* out.
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
* @param[in] data Pointer to data to write
|
|
* @param[in] data_len Length of the data requested to write. This may
|
|
* be zero for a zero length status packet.
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len);
|
|
|
|
/**
|
|
* @brief Setup out ep transfer setting and start transfer.
|
|
*
|
|
* This function is asynchronous.
|
|
* This function is similar to uart with rx dma.
|
|
*
|
|
* This function is called to read data to the specified endpoint. The
|
|
* supplied usbd_endpoint_callback function will be called when data is received
|
|
* in.
|
|
*
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
* @param[in] data Pointer to data to read
|
|
* @param[in] data_len Max length of the data requested to read.
|
|
*
|
|
* @return 0 on success, negative errno code on fail.
|
|
*/
|
|
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len);
|
|
|
|
/* usb dcd irq callback */
|
|
|
|
/**
|
|
* @brief Usb reset irq callback.
|
|
*/
|
|
void usbd_event_reset_handler(void);
|
|
/**
|
|
* @brief Usb setup packet recv irq callback.
|
|
* @param[in] psetup setup packet.
|
|
*/
|
|
void usbd_event_ep0_setup_complete_handler(uint8_t *psetup);
|
|
/**
|
|
* @brief In ep transfer complete irq callback.
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
* @param[in] nbytes How many nbytes have transferred.
|
|
*/
|
|
void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes);
|
|
/**
|
|
* @brief Out ep transfer complete irq callback.
|
|
* @param[in] ep Endpoint address corresponding to the one
|
|
* listed in the device configuration table
|
|
* @param[in] nbytes How many nbytes have transferred.
|
|
*/
|
|
void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes);
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|