2021-10-06 09:24:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-01-21 16:55:44 +00:00
|
|
|
typedef struct FuriHalUsbInterface FuriHalUsbInterface;
|
2021-10-06 09:24:09 +00:00
|
|
|
|
2022-01-21 16:55:44 +00:00
|
|
|
struct FuriHalUsbInterface {
|
2022-03-23 13:35:25 +00:00
|
|
|
void (*init)(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
2022-01-05 16:10:18 +00:00
|
|
|
void (*deinit)(usbd_device* dev);
|
|
|
|
void (*wakeup)(usbd_device* dev);
|
|
|
|
void (*suspend)(usbd_device* dev);
|
2021-11-21 15:17:43 +00:00
|
|
|
|
|
|
|
struct usb_device_descriptor* dev_descr;
|
|
|
|
|
|
|
|
void* str_manuf_descr;
|
|
|
|
void* str_prod_descr;
|
|
|
|
void* str_serial_descr;
|
|
|
|
|
|
|
|
void* cfg_descr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** USB device interface modes */
|
2022-01-21 16:55:44 +00:00
|
|
|
extern FuriHalUsbInterface usb_cdc_single;
|
|
|
|
extern FuriHalUsbInterface usb_cdc_dual;
|
|
|
|
extern FuriHalUsbInterface usb_hid;
|
|
|
|
extern FuriHalUsbInterface usb_hid_u2f;
|
2023-09-21 09:09:00 +00:00
|
|
|
extern FuriHalUsbInterface usb_ccid;
|
2022-01-21 16:55:44 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FuriHalUsbStateEventReset,
|
|
|
|
FuriHalUsbStateEventWakeup,
|
|
|
|
FuriHalUsbStateEventSuspend,
|
|
|
|
FuriHalUsbStateEventDescriptorRequest,
|
|
|
|
} FuriHalUsbStateEvent;
|
|
|
|
|
|
|
|
typedef void (*FuriHalUsbStateCallback)(FuriHalUsbStateEvent state, void* context);
|
2021-10-06 09:24:09 +00:00
|
|
|
|
2021-10-13 16:38:24 +00:00
|
|
|
/** USB device low-level initialization
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_init(void);
|
2021-10-06 09:24:09 +00:00
|
|
|
|
2021-10-13 16:38:24 +00:00
|
|
|
/** Set USB device configuration
|
|
|
|
*
|
|
|
|
* @param mode new USB device mode
|
2022-03-23 13:35:25 +00:00
|
|
|
* @param ctx context passed to device mode init function
|
2022-03-24 15:45:03 +00:00
|
|
|
* @return true - mode switch started, false - mode switch is locked
|
2021-10-13 16:38:24 +00:00
|
|
|
*/
|
2022-03-24 15:45:03 +00:00
|
|
|
bool furi_hal_usb_set_config(FuriHalUsbInterface* new_if, void* ctx);
|
2021-10-06 09:24:09 +00:00
|
|
|
|
2021-10-13 16:38:24 +00:00
|
|
|
/** Get USB device configuration
|
|
|
|
*
|
|
|
|
* @return current USB device mode
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
FuriHalUsbInterface* furi_hal_usb_get_config(void);
|
2021-10-13 16:38:24 +00:00
|
|
|
|
2022-03-24 15:45:03 +00:00
|
|
|
/** Lock USB device mode switch
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_lock(void);
|
2022-03-24 15:45:03 +00:00
|
|
|
|
|
|
|
/** Unlock USB device mode switch
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_unlock(void);
|
2022-03-24 15:45:03 +00:00
|
|
|
|
|
|
|
/** Check if USB device mode switch locked
|
|
|
|
*
|
|
|
|
* @return lock state
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
bool furi_hal_usb_is_locked(void);
|
2022-03-24 15:45:03 +00:00
|
|
|
|
2021-10-13 16:38:24 +00:00
|
|
|
/** Disable USB device
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_disable(void);
|
2021-10-06 09:24:09 +00:00
|
|
|
|
2021-10-13 16:38:24 +00:00
|
|
|
/** Enable USB device
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_enable(void);
|
2022-01-21 16:55:44 +00:00
|
|
|
|
|
|
|
/** Set USB state callback
|
|
|
|
*/
|
|
|
|
void furi_hal_usb_set_state_callback(FuriHalUsbStateCallback cb, void* ctx);
|
|
|
|
|
|
|
|
/** Restart USB device
|
|
|
|
*/
|
2024-03-19 14:43:52 +00:00
|
|
|
void furi_hal_usb_reinit(void);
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|