fixed gcc compiling usb driver errors, update for including file position and adding macros

This commit is contained in:
sheltonyu 2023-02-27 14:59:47 +08:00 committed by Man, Jianting (Meco)
parent 26fab3e792
commit d6605e3f8b
23 changed files with 138 additions and 79 deletions

View File

@ -10,14 +10,14 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "usbd_int.h"
#include "drv_common.h"
#if defined(BSP_USING_USBD)
#include "usbd_int.h"
#include "drv_usbd.h"
#include "drv_config.h"
#if defined(BSP_USING_USBD)
static struct at32_usbd *p_usbd_instance = NULL;
static struct at32_usbd *p_usbd_instance = RT_NULL;
static struct ep_id endpoint_pool[] =
{
{0x0, USB_EP_ATTR_CONTROL, USB_DIR_INOUT, 64, ID_ASSIGNED },

View File

@ -14,6 +14,8 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_common.h"
#if defined(BSP_USING_USBD)
#include "usbd_core.h"
struct at32_usbd {
@ -21,7 +23,7 @@ struct at32_usbd {
usbd_core_type *p_usbd_core;
IRQn_Type irqn;
};
#endif
#endif /* __DRV_USBD_H__ */
/******************* end of file *******************/

View File

@ -14,6 +14,9 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_common.h"
#if defined(BSP_USING_HOST_USBFS1) || defined(BSP_USING_HOST_USBFS2) || \
defined(BSP_USING_DEVICE_USBFS1) || defined(BSP_USING_DEVICE_USBFS2)
#include "usb_core.h"
struct at32_usbfs {
@ -22,7 +25,7 @@ struct at32_usbfs {
otg_id_type id;
IRQn_Type irqn;
};
#endif
#endif /* __DRV_USBFS_H__ */
/******************* end of file *******************/

View File

@ -10,14 +10,14 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "usbd_int.h"
#include "drv_common.h"
#if defined(BSP_USING_DEVICE_USBFS1) || defined(BSP_USING_DEVICE_USBFS2)
#include "usbd_int.h"
#include "drv_usbfs.h"
#include "drv_config.h"
#if defined(BSP_USING_DEVICE_USBFS1) || defined(BSP_USING_DEVICE_USBFS2)
static struct at32_usbfs *p_usbfs_instance = NULL;
static struct at32_usbfs *p_usbfs_instance = RT_NULL;
static struct ep_id endpoint_pool[] =
{
{0x0, USB_EP_ATTR_CONTROL, USB_DIR_INOUT, 64, ID_ASSIGNED },
@ -196,7 +196,7 @@ static rt_size_t _ep_write(rt_uint8_t address, void *buffer, rt_size_t size)
static rt_err_t _ep0_send_status(void)
{
usbd_ept_send(&p_usbfs_instance->p_otg_core->dev, 0x00, NULL, 0);
usbd_ept_send(&p_usbfs_instance->p_otg_core->dev, 0x00, RT_NULL, 0);
return RT_EOK;
}

View File

@ -10,12 +10,12 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "usbh_int.h"
#include "drv_common.h"
#include "drv_usbfs.h"
#include "drv_config.h"
#if defined(BSP_USING_HOST_USBFS1) || defined(BSP_USING_HOST_USBFS2)
#include "usbh_int.h"
#include "drv_usbfs.h"
#include "drv_config.h"
//#define DRV_DEBUG
#define LOG_TAG "drv.usb"
@ -23,7 +23,7 @@
static struct rt_completion urb_completion;
static volatile rt_bool_t connect_status = RT_FALSE;
static struct at32_usbfs *p_usbfs_instance = NULL;
static struct at32_usbfs *p_usbfs_instance = RT_NULL;
enum
{

View File

@ -240,6 +240,16 @@ typedef struct
#define SWAPBYTE(addr) (uint16_t)(((uint16_t)(*((uint8_t *)(addr)))) + \
(((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) /*!< swap address */
/**
* @brief min and max define
*/
#ifndef MIN
#define MIN(a, b) (uint16_t)(((a) < (b)) ? (a) : (b)) /*!< min define*/
#endif
#ifndef MAX
#define MAX(a, b) (uint16_t)(((a) > (b)) ? (a) : (b)) /*!< max define*/
#endif
/**
* @brief low byte and high byte define
*/

View File

@ -40,6 +40,8 @@ extern "C" {
* @{
*/
#ifdef BSP_USING_USBD
/**
* @brief usb device event
*/
@ -164,6 +166,7 @@ void usbd_core_init(usbd_core_type *udev,
usb_reg_type *usb_reg,
uint8_t core_id);
#endif
/**
* @}

View File

@ -40,6 +40,9 @@ extern "C" {
/** @defgroup USBD_int_exported_functions
* @{
*/
#ifdef BSP_USING_USBD
void usbd_irq_handler(usbd_core_type *udev);
void usbd_ept_loop_handler(usbd_core_type *udev);
void usbd_eptn_handler(usbd_core_type *udev, usb_ept_number_type ept_num);
@ -57,6 +60,8 @@ void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num);
void usbd_connectCallback(usbd_core_type *udev);
void usbd_disconnectCallback(usbd_core_type *udev);
#endif
/**
* @}
*/

View File

@ -41,11 +41,14 @@ extern "C" {
* @{
*/
#ifdef BSP_USING_USBD
void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf);
usb_sts_type usbd_device_request(usbd_core_type *udev);
usb_sts_type usbd_interface_request(usbd_core_type *udev);
usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
#endif
/**
* @}

View File

@ -35,6 +35,8 @@
* @{
*/
#ifdef BSP_USING_USBD
/**
* @brief usb core in transfer complete handler
* @param udev: to the structure of usbd_core_type
@ -679,6 +681,8 @@ void usbd_core_init(usbd_core_type *udev,
usb_dev_init(udev->usb_reg);
}
#endif
/**
* @}
*/

View File

@ -33,6 +33,8 @@
* @{
*/
#ifdef BSP_USING_USBD
/**
* @brief usb device interrput request handler.
* @param udev: to the structure of usbd_core_type
@ -309,34 +311,36 @@ void usbd_wakeup_handler(usbd_core_type *udev)
/* user define wakeup event */
}
__weak void usbd_reset_callback(usbd_core_type *udev)
RT_WEAK void usbd_reset_callback(usbd_core_type *udev)
{
}
__weak void usbd_setup_phase_done_callback(usbd_core_type *udev)
RT_WEAK void usbd_setup_phase_done_callback(usbd_core_type *udev)
{
}
__weak void usbd_data_in_stage_callback(usbd_core_type *udev, uint32_t ept_num)
RT_WEAK void usbd_data_in_stage_callback(usbd_core_type *udev, uint32_t ept_num)
{
}
__weak void usbd_sof_callback(usbd_core_type *udev)
RT_WEAK void usbd_sof_callback(usbd_core_type *udev)
{
}
__weak void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num)
RT_WEAK void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num)
{
}
__weak void usbd_connectCallback(usbd_core_type *udev)
RT_WEAK void usbd_connectCallback(usbd_core_type *udev)
{
}
__weak void usbd_disconnectCallback(usbd_core_type *udev)
RT_WEAK void usbd_disconnectCallback(usbd_core_type *udev)
{
}
#endif
/**
* @}
*/

View File

@ -33,6 +33,8 @@
* @{
*/
#ifdef BSP_USING_USBD
static usb_sts_type usbd_get_descriptor(usbd_core_type *udev);
static usb_sts_type usbd_set_address(usbd_core_type *udev);
static usb_sts_type usbd_get_status(usbd_core_type *udev);
@ -66,10 +68,10 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
usb_sts_type ret = USB_OK;
uint16_t len = 0;
uint8_t desc_type = udev->setup.wValue >> 8;
usbd_desc_t *desc = NULL, usbd_desc =
usbd_desc_t *desc = RT_NULL, usbd_desc =
{
.length = 0xA,
.descriptor = NULL,
.descriptor = RT_NULL,
};
switch(desc_type)
@ -108,7 +110,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
return ret;
}
if(desc != NULL)
if(desc != RT_NULL)
{
if((desc->length != 0) && (udev->setup.wLength != 0))
{
@ -523,6 +525,8 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
return ret;
}
#endif
/**
* @}
*/

View File

@ -239,6 +239,16 @@ typedef struct
#define SWAPBYTE(addr) (uint16_t)(((uint16_t)(*((uint8_t *)(addr)))) + \
(((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) /*!< swap address */
/**
* @brief min and max define
*/
#ifndef MIN
#define MIN(a, b) (uint16_t)(((a) < (b)) ? (a) : (b)) /*!< min define*/
#endif
#ifndef MAX
#define MAX(a, b) (uint16_t)(((a) > (b)) ? (a) : (b)) /*!< max define*/
#endif
/**
* @brief low byte and high byte define
*/

View File

@ -34,8 +34,6 @@ extern "C" {
#include "usbd_core.h"
#include "usb_core.h"
#ifdef USE_OTG_DEVICE_MODE
/** @addtogroup USBD_drivers_int
* @{
*/
@ -44,6 +42,8 @@ extern "C" {
* @{
*/
#ifdef USE_OTG_DEVICE_MODE
void usbd_irq_handler(otg_core_type *udev);
void usbd_ept_handler(usbd_core_type *udev);
void usbd_reset_handler(usbd_core_type *udev);
@ -68,6 +68,8 @@ void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num);
void usbd_connectCallback(usbd_core_type *udev);
void usbd_disconnectCallback(usbd_core_type *udev);
#endif
/**
* @}
*/
@ -81,5 +83,3 @@ void usbd_disconnectCallback(usbd_core_type *udev);
#endif
#endif
#endif

View File

@ -33,8 +33,6 @@ extern "C" {
/* includes ------------------------------------------------------------------*/
#include "usb_core.h"
#ifdef USE_OTG_DEVICE_MODE
/** @addtogroup USBD_drivers_standard_request
* @{
*/
@ -43,11 +41,15 @@ extern "C" {
* @{
*/
#ifdef USE_OTG_DEVICE_MODE
void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf);
usb_sts_type usbd_device_request(usbd_core_type *udev);
usb_sts_type usbd_interface_request(usbd_core_type *udev);
usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
#endif
/**
* @}
*/
@ -61,5 +63,3 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
#endif
#endif
#endif

View File

@ -41,6 +41,8 @@ extern "C" {
* @{
*/
#ifdef USE_OTG_HOST_MODE
usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num);
usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer,
uint16_t length, uint16_t hc_num);
@ -83,6 +85,8 @@ usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t i
usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index);
usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num);
#endif
/**
* @}
*/

View File

@ -42,6 +42,8 @@ extern "C" {
* @{
*/
#ifdef USE_OTG_HOST_MODE
void usbh_irq_handler(otg_core_type *hdev);
void usbh_hch_handler(usbh_core_type *uhost);
void usbh_port_handler(usbh_core_type *uhost);
@ -55,6 +57,8 @@ void usbh_connect_callback(usbh_core_type *uhost);
void usbh_disconnect_callback(usbh_core_type *uhost);
void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum, urb_sts_type sts);
#endif
/**
* @}
*/

View File

@ -859,12 +859,12 @@ usb_sts_type usbd_core_init(usbd_core_type *udev,
}
/**
* @}
*/
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/

View File

@ -521,40 +521,40 @@ void usbd_wakeup_handler(usbd_core_type *udev)
udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT);
}
__weak void usbd_reset_callback(usbd_core_type *udev)
RT_WEAK void usbd_reset_callback(usbd_core_type *udev)
{
}
__weak void usbd_setup_phase_done_callback(usbd_core_type *udev)
RT_WEAK void usbd_setup_phase_done_callback(usbd_core_type *udev)
{
}
__weak void usbd_data_in_stage_callback(usbd_core_type *udev, uint32_t ept_num)
RT_WEAK void usbd_data_in_stage_callback(usbd_core_type *udev, uint32_t ept_num)
{
}
__weak void usbd_sof_callback(usbd_core_type *udev)
RT_WEAK void usbd_sof_callback(usbd_core_type *udev)
{
}
__weak void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num)
RT_WEAK void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num)
{
}
__weak void usbd_connectCallback(usbd_core_type *udev)
RT_WEAK void usbd_connectCallback(usbd_core_type *udev)
{
}
__weak void usbd_disconnectCallback(usbd_core_type *udev)
RT_WEAK void usbd_disconnectCallback(usbd_core_type *udev)
{
}
/**
* @}
*/
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/

View File

@ -23,21 +23,17 @@
*/
#include "usbd_sdr.h"
/** @addtogroup AT32F435_437_middlewares_usbd_drivers
* @{
*/
/** @defgroup USBD_drivers_standard_request
* @brief usb device standard_request
* @{
*/
#ifdef USE_OTG_DEVICE_MODE
/** @defgroup USBD_sdr_private_functions
* @{
*/
#ifdef USE_OTG_DEVICE_MODE
static usb_sts_type usbd_get_descriptor(usbd_core_type *udev);
static usb_sts_type usbd_set_address(usbd_core_type *udev);
static usb_sts_type usbd_get_status(usbd_core_type *udev);
@ -70,7 +66,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
{
usb_sts_type ret = USB_OK;
uint16_t len = 0;
usbd_desc_t *desc = NULL;
usbd_desc_t *desc = RT_NULL;
uint8_t desc_type = udev->setup.wValue >> 8;
switch(desc_type)
{
@ -120,7 +116,7 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
return ret;
}
if(desc != NULL)
if(desc != RT_NULL)
{
if((desc->length != 0) && (udev->setup.wLength != 0))
{
@ -520,16 +516,14 @@ usb_sts_type usbd_endpoint_request(usbd_core_type *udev)
}
return ret;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/

View File

@ -26,6 +26,8 @@
#include "usb_core.h"
#include "usbh_ctrl.h"
#ifdef USE_OTG_HOST_MODE
/** @defgroup USBH_drivers_core
* @brief usb host drivers core
* @{
@ -1105,7 +1107,7 @@ static void usbh_disconnect(usbh_core_type *uhost)
}
/* call class reset handler */
if(uhost->class_handler->reset_handler != NULL)
if(uhost->class_handler->reset_handler != RT_NULL)
{
uhost->class_handler->reset_handler(uhost);
}
@ -1220,3 +1222,4 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
* @}
*/
#endif

View File

@ -25,6 +25,8 @@
#include "usbh_core.h"
#include "usb_std.h"
#ifdef USE_OTG_HOST_MODE
/** @defgroup USBH_drivers_control
* @brief usb host drivers control
* @{
@ -956,3 +958,4 @@ usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint
* @}
*/
#endif

View File

@ -23,6 +23,8 @@
*/
#include "usbh_int.h"
#ifdef USE_OTG_HOST_MODE
/** @defgroup USBH_drivers_interrupt
* @brief usb host interrupt
* @{
@ -518,15 +520,15 @@ void usbh_port_handler(usbh_core_type *uhost)
usb_host->hprt = prt_0;
}
__weak void usbh_connect_callback(usbh_core_type *uhost)
RT_WEAK void usbh_connect_callback(usbh_core_type *uhost)
{
}
__weak void usbh_disconnect_callback(usbh_core_type *uhost)
RT_WEAK void usbh_disconnect_callback(usbh_core_type *uhost)
{
}
__weak void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum, urb_sts_type sts)
RT_WEAK void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum, urb_sts_type sts)
{
}
@ -538,3 +540,4 @@ __weak void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum,
* @}
*/
#endif