newtx/usb/usb_dev.h

58 lines
1.9 KiB
C
Raw Permalink Normal View History

2023-12-01 09:17:09 +00:00
// USB device configuration and open
//
// Date: 2023-11-28
//
#pragma once
#include "buildconf.h"
#include "camtp.h"
#include "usb_gadget.h"
#include "../sdk/base/utils.h"
class usb_device : public refer
{
usb_gadget gadget_;
std::string dwc3_; // fe900000.dwc3
std::string udc_; // /opt/cfg/usb_gadget/g1/UDC
std::string pwd_; // password of login user
std::string ep_path_[EP_NB_OF_DESCRIPTORS];
ffs_strings ffs_strs_;
bool ffs_mode_ = true;
bool on_ = false;
2023-12-01 09:17:09 +00:00
size_t max_packet_ = 512;
void fill_if_descriptor(bool ffs_mode, usb_gadget * usbctx, struct usb_interface_descriptor * desc);
void fill_ep_descriptor(unsigned short max_packet, usb_gadget * usbctx, struct usb_endpoint_descriptor_no_audio * desc, int index, unsigned int flags);
int add_usb_string(usb_gadget * usbctx, int id, char * string);
void fill_config_descriptor(usb_gadget * usbctx,struct usb_config_descriptor * desc, int total_size, int hs);
void fill_dev_descriptor(usb_gadget * usbctx, struct usb_device_descriptor * desc);
void init_usb_camtp_gadget(bool ffs_mode);
void deinit_usb_camtp_gadget(void);
int config_device(bool ffs_mode);
int config_endpoint(int ep_ind);
public:
usb_device(const char* dwc3, const char* udc, const char* pwd);
static std::string endpoint_index_str(int epind);
protected:
virtual ~usb_device();
public:
int add_endpoint(const char* path, bool bulk/*true - bulk, false - int*/, bool in);
int open_device(const char* dev, bool ffs_mode, int* fd = nullptr);
int open_endpoint(int ep_ind, int* fd = nullptr);
int close_endpoint(int ep_ind);
int close_device(void);
int pull_up(std::string* msg = nullptr); // turn USB-pin on, so that the host can detect me
int pull_down(void);
int get_device_fd(void);
int get_endpoint_fd(int ep_ind);
size_t get_max_packet(void);
};