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