format codes

This commit is contained in:
sakimisu
2022-02-08 11:44:46 +08:00
parent feb5a8fb52
commit 1edbae8e07
21 changed files with 7215 additions and 7215 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,138 +1,138 @@
/**
* @file usbd_core.h
*
* 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 _USBD_CORE_H
#define _USBD_CORE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "usb_util.h"
#include "usb_def.h"
#include "usb_dc.h"
enum usbd_event_type {
/** USB error reported by the controller */
USBD_EVENT_ERROR,
/** USB reset */
USBD_EVENT_RESET,
/** Start of Frame received */
USBD_EVENT_SOF,
/** USB connection established, hardware enumeration is completed */
USBD_EVENT_CONNECTED,
/** USB configuration done */
USBD_EVENT_CONFIGURED,
/** USB connection suspended by the HOST */
USBD_EVENT_SUSPEND,
/** USB connection lost */
USBD_EVENT_DISCONNECTED,
/** USB connection resumed by the HOST */
USBD_EVENT_RESUME,
/** USB interface selected */
USBD_EVENT_SET_INTERFACE,
/** USB interface selected */
USBD_EVENT_SET_REMOTE_WAKEUP,
/** USB interface selected */
USBD_EVENT_CLEAR_REMOTE_WAKEUP,
/** Set Feature ENDPOINT_HALT received */
USBD_EVENT_SET_HALT,
/** Clear Feature ENDPOINT_HALT received */
USBD_EVENT_CLEAR_HALT,
/** setup packet received */
USBD_EVENT_SETUP_NOTIFY,
/** ep0 in packet received */
USBD_EVENT_EP0_IN_NOTIFY,
/** ep0 out packet received */
USBD_EVENT_EP0_OUT_NOTIFY,
/** ep in packet except ep0 received */
USBD_EVENT_EP_IN_NOTIFY,
/** ep out packet except ep0 received */
USBD_EVENT_EP_OUT_NOTIFY,
/** Initial USB connection status */
USBD_EVENT_UNKNOWN
};
/**
* @brief Callback function signature for the USB Endpoint status
*/
typedef void (*usbd_endpoint_callback)(uint8_t ep);
/**
* @brief Callback function signature for class specific requests
*
* Function which handles Class specific requests corresponding to an
* interface number specified in the device descriptor table. For host
* to device direction the 'len' and 'payload_data' contain the length
* of the received data and the pointer to the received data respectively.
* For device to host class requests, 'len' and 'payload_data' should be
* set by the callback function with the length and the address of the
* data to be transmitted buffer respectively.
*/
typedef int (*usbd_request_handler)(struct usb_setup_packet *setup,
uint8_t **data, uint32_t *transfer_len);
/* callback function pointer structure for Application to handle events */
typedef void (*usbd_notify_handler)(uint8_t event, void *arg);
typedef struct usbd_endpoint {
usb_slist_t list;
uint8_t ep_addr;
usbd_endpoint_callback ep_cb;
} usbd_endpoint_t;
typedef struct usbd_interface {
usb_slist_t list;
/** Handler for USB Class specific commands*/
usbd_request_handler class_handler;
/** Handler for USB Vendor specific commands */
usbd_request_handler vendor_handler;
/** Handler for USB custom specific commands */
usbd_request_handler custom_handler;
/** Handler for USB event notify commands */
usbd_notify_handler notify_handler;
uint8_t intf_num;
usb_slist_t ep_list;
} usbd_interface_t;
typedef struct usbd_class {
usb_slist_t list;
const char *name;
usb_slist_t intf_list;
} usbd_class_t;
void usbd_event_notify_handler(uint8_t event, void *arg);
void usbd_desc_register(const uint8_t *desc);
void usbd_class_register(usbd_class_t *devclass);
void usbd_msosv1_desc_register(struct usb_msosv1_descriptor *desc);
void usbd_msosv2_desc_register(struct usb_msosv2_descriptor *desc);
void usbd_bos_desc_register(struct usb_bos_descriptor *desc);
void usbd_class_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
void usbd_interface_add_endpoint(usbd_interface_t *intf, usbd_endpoint_t *ep);
bool usb_device_is_configured(void);
#ifdef __cplusplus
}
#endif
#endif
/**
* @file usbd_core.h
*
* 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 _USBD_CORE_H
#define _USBD_CORE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "usb_util.h"
#include "usb_def.h"
#include "usb_dc.h"
enum usbd_event_type {
/** USB error reported by the controller */
USBD_EVENT_ERROR,
/** USB reset */
USBD_EVENT_RESET,
/** Start of Frame received */
USBD_EVENT_SOF,
/** USB connection established, hardware enumeration is completed */
USBD_EVENT_CONNECTED,
/** USB configuration done */
USBD_EVENT_CONFIGURED,
/** USB connection suspended by the HOST */
USBD_EVENT_SUSPEND,
/** USB connection lost */
USBD_EVENT_DISCONNECTED,
/** USB connection resumed by the HOST */
USBD_EVENT_RESUME,
/** USB interface selected */
USBD_EVENT_SET_INTERFACE,
/** USB interface selected */
USBD_EVENT_SET_REMOTE_WAKEUP,
/** USB interface selected */
USBD_EVENT_CLEAR_REMOTE_WAKEUP,
/** Set Feature ENDPOINT_HALT received */
USBD_EVENT_SET_HALT,
/** Clear Feature ENDPOINT_HALT received */
USBD_EVENT_CLEAR_HALT,
/** setup packet received */
USBD_EVENT_SETUP_NOTIFY,
/** ep0 in packet received */
USBD_EVENT_EP0_IN_NOTIFY,
/** ep0 out packet received */
USBD_EVENT_EP0_OUT_NOTIFY,
/** ep in packet except ep0 received */
USBD_EVENT_EP_IN_NOTIFY,
/** ep out packet except ep0 received */
USBD_EVENT_EP_OUT_NOTIFY,
/** Initial USB connection status */
USBD_EVENT_UNKNOWN
};
/**
* @brief Callback function signature for the USB Endpoint status
*/
typedef void (*usbd_endpoint_callback)(uint8_t ep);
/**
* @brief Callback function signature for class specific requests
*
* Function which handles Class specific requests corresponding to an
* interface number specified in the device descriptor table. For host
* to device direction the 'len' and 'payload_data' contain the length
* of the received data and the pointer to the received data respectively.
* For device to host class requests, 'len' and 'payload_data' should be
* set by the callback function with the length and the address of the
* data to be transmitted buffer respectively.
*/
typedef int (*usbd_request_handler)(struct usb_setup_packet *setup,
uint8_t **data, uint32_t *transfer_len);
/* callback function pointer structure for Application to handle events */
typedef void (*usbd_notify_handler)(uint8_t event, void *arg);
typedef struct usbd_endpoint {
usb_slist_t list;
uint8_t ep_addr;
usbd_endpoint_callback ep_cb;
} usbd_endpoint_t;
typedef struct usbd_interface {
usb_slist_t list;
/** Handler for USB Class specific commands*/
usbd_request_handler class_handler;
/** Handler for USB Vendor specific commands */
usbd_request_handler vendor_handler;
/** Handler for USB custom specific commands */
usbd_request_handler custom_handler;
/** Handler for USB event notify commands */
usbd_notify_handler notify_handler;
uint8_t intf_num;
usb_slist_t ep_list;
} usbd_interface_t;
typedef struct usbd_class {
usb_slist_t list;
const char *name;
usb_slist_t intf_list;
} usbd_class_t;
void usbd_event_notify_handler(uint8_t event, void *arg);
void usbd_desc_register(const uint8_t *desc);
void usbd_class_register(usbd_class_t *devclass);
void usbd_msosv1_desc_register(struct usb_msosv1_descriptor *desc);
void usbd_msosv2_desc_register(struct usb_msosv2_descriptor *desc);
void usbd_bos_desc_register(struct usb_bos_descriptor *desc);
void usbd_class_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
void usbd_interface_add_endpoint(usbd_interface_t *intf, usbd_endpoint_t *ep);
bool usb_device_is_configured(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,128 +1,128 @@
/**
* @file usbh_core.h
*
* 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 _USBH_CORE_H
#define _USBH_CORE_H
#include "usb_util.h"
#include "usb_def.h"
#include "usb_hc.h"
#include "usb_osal.h"
#include "usb_workq.h"
#include "usbh_hub.h"
#include "usb_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USBH_ROOT_HUB_INDEX 1 /* roothub index*/
#define USBH_EX_HUB_INDEX 2 /* external hub index */
#define USBH_HUB_PORT_START_INDEX 1 /* first hub port index */
#ifdef CONFIG_USBHOST_HUB
#define ROOTHUB(hport) ((hport)->parent == NULL)
#else
#define ROOTHUB(hport) true
#endif
#define CLASS_CONNECT(hport,i) ((hport)->config.intf[i].class_driver->connect(hport, i))
#define CLASS_DISCONNECT(hport,i) ((hport)->config.intf[i].class_driver->disconnect(hport, i))
enum usbh_event_type {
USBH_EVENT_ATTACHED,
USBH_EVENT_REMOVED,
};
struct usbh_class_info {
uint8_t class; /* Base device class code */
uint8_t subclass; /* Sub-class, depends on base class. Eg. */
uint8_t protocol; /* Protocol, depends on base class. Eg. */
uint16_t vid; /* Vendor ID (for vendor/product specific devices) */
uint16_t pid; /* Product ID (for vendor/product specific devices) */
const struct usbh_class_driver *class_driver;
};
struct usbh_hubport;
struct usbh_class_driver {
const char *driver_name;
int (*connect)(struct usbh_hubport *hport, uint8_t intf);
int (*disconnect)(struct usbh_hubport *hport, uint8_t intf);
};
typedef struct usbh_endpoint {
struct usb_endpoint_descriptor ep_desc;
} usbh_endpoint_t;
typedef struct usbh_interface {
struct usb_interface_descriptor intf_desc;
struct usbh_endpoint ep[CONFIG_USBHOST_EP_NUM];
struct usbh_class_driver *class_driver;
void *priv;
} usbh_interface_t;
typedef struct usbh_configuration {
struct usb_configuration_descriptor config_desc;
struct usbh_interface intf[CONFIG_USBHOST_INTF_NUM];
} usbh_configuration_t;
typedef struct usbh_hubport {
bool connected; /* True: device connected; false: disconnected */
bool port_change; /* True: port changed; false: port do not change */
uint8_t port; /* Hub port index */
uint8_t dev_addr; /* device address */
uint8_t speed; /* device speed */
usbh_epinfo_t ep0; /* control ep info */
struct usb_device_descriptor device_desc;
struct usbh_configuration config;
#if 0
uint8_t* config_desc;
#endif
struct usbh_hub *parent; /*if NULL, is roothub*/
} usbh_hubport_t;
typedef struct usbh_hub {
usb_slist_t list;
uint8_t index; /* Hub index */
uint8_t nports; /* Hub port number */
uint8_t dev_addr; /* Hub device address */
usbh_epinfo_t intin;
uint8_t *int_buffer;
struct usb_setup_packet *setup;
struct hub_port_status *port_status;
struct usb_hub_descriptor hub_desc;
struct usbh_hubport child[CONFIG_USBHOST_EHPORTS];
struct usbh_hubport *parent; /* Parent hub port */
struct usb_work work;
} usbh_hub_t;
void usbh_event_notify_handler(uint8_t event, uint8_t rhport);
int usbh_initialize(void);
int lsusb(int argc, char **argv);
struct usbh_hubport *usbh_get_hubport(uint8_t dev_addr);
void *usbh_get_class(uint8_t dev_addr, uint8_t intf);
#ifdef __cplusplus
}
#endif
#endif
/**
* @file usbh_core.h
*
* 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 _USBH_CORE_H
#define _USBH_CORE_H
#include "usb_util.h"
#include "usb_def.h"
#include "usb_hc.h"
#include "usb_osal.h"
#include "usb_workq.h"
#include "usbh_hub.h"
#include "usb_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USBH_ROOT_HUB_INDEX 1 /* roothub index*/
#define USBH_EX_HUB_INDEX 2 /* external hub index */
#define USBH_HUB_PORT_START_INDEX 1 /* first hub port index */
#ifdef CONFIG_USBHOST_HUB
#define ROOTHUB(hport) ((hport)->parent == NULL)
#else
#define ROOTHUB(hport) true
#endif
#define CLASS_CONNECT(hport,i) ((hport)->config.intf[i].class_driver->connect(hport, i))
#define CLASS_DISCONNECT(hport,i) ((hport)->config.intf[i].class_driver->disconnect(hport, i))
enum usbh_event_type {
USBH_EVENT_ATTACHED,
USBH_EVENT_REMOVED,
};
struct usbh_class_info {
uint8_t class; /* Base device class code */
uint8_t subclass; /* Sub-class, depends on base class. Eg. */
uint8_t protocol; /* Protocol, depends on base class. Eg. */
uint16_t vid; /* Vendor ID (for vendor/product specific devices) */
uint16_t pid; /* Product ID (for vendor/product specific devices) */
const struct usbh_class_driver *class_driver;
};
struct usbh_hubport;
struct usbh_class_driver {
const char *driver_name;
int (*connect)(struct usbh_hubport *hport, uint8_t intf);
int (*disconnect)(struct usbh_hubport *hport, uint8_t intf);
};
typedef struct usbh_endpoint {
struct usb_endpoint_descriptor ep_desc;
} usbh_endpoint_t;
typedef struct usbh_interface {
struct usb_interface_descriptor intf_desc;
struct usbh_endpoint ep[CONFIG_USBHOST_EP_NUM];
struct usbh_class_driver *class_driver;
void *priv;
} usbh_interface_t;
typedef struct usbh_configuration {
struct usb_configuration_descriptor config_desc;
struct usbh_interface intf[CONFIG_USBHOST_INTF_NUM];
} usbh_configuration_t;
typedef struct usbh_hubport {
bool connected; /* True: device connected; false: disconnected */
bool port_change; /* True: port changed; false: port do not change */
uint8_t port; /* Hub port index */
uint8_t dev_addr; /* device address */
uint8_t speed; /* device speed */
usbh_epinfo_t ep0; /* control ep info */
struct usb_device_descriptor device_desc;
struct usbh_configuration config;
#if 0
uint8_t* config_desc;
#endif
struct usbh_hub *parent; /*if NULL, is roothub*/
} usbh_hubport_t;
typedef struct usbh_hub {
usb_slist_t list;
uint8_t index; /* Hub index */
uint8_t nports; /* Hub port number */
uint8_t dev_addr; /* Hub device address */
usbh_epinfo_t intin;
uint8_t *int_buffer;
struct usb_setup_packet *setup;
struct hub_port_status *port_status;
struct usb_hub_descriptor hub_desc;
struct usbh_hubport child[CONFIG_USBHOST_EHPORTS];
struct usbh_hubport *parent; /* Parent hub port */
struct usb_work work;
} usbh_hub_t;
void usbh_event_notify_handler(uint8_t event, uint8_t rhport);
int usbh_initialize(void);
int lsusb(int argc, char **argv);
struct usbh_hubport *usbh_get_hubport(uint8_t dev_addr);
void *usbh_get_class(uint8_t dev_addr, uint8_t intf);
#ifdef __cplusplus
}
#endif
#endif