123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #pragma once
- #include <stdint.h>
- #include "usb.h"
- #include "usb_proto.h"
- #define USB_LOG_LEVEL 1
- #ifdef USB_LOG_LEVEL
- # define USB_LOG(lvl,...) if ((lvl) >= USB_LOG_LEVEL) printf(__VA_ARGS__)
- #else
- # define USB_LOG(lvl,...) do {} while(0)
- #endif
- #define USB_LOG_ERR(...) USB_LOG(1, __VA_ARGS__)
- struct usb_stack {
-
- const struct usb_stack_descriptors *stack_desc;
-
- enum usb_dev_state state;
- const struct usb_conf_desc *conf;
- uint32_t intf_alt;
-
- uint32_t tick;
-
- struct {
- enum {
- IDLE,
- DATA_IN,
- DATA_OUT,
- STATUS_DONE_OUT,
- STATUS_DONE_IN,
- STALL,
- } state;
- uint8_t buf[64];
- struct usb_xfer xfer;
- struct usb_ctrl_req req;
- } ctrl;
-
- struct usb_fn_drv *fnd;
- };
- extern struct usb_stack g_usb;
- void usb_data_write(unsigned int dst_ofs, const void *src, int len);
- void usb_data_read(void *dst, unsigned int src_ofs, int len);
- void usb_dispatch_sof(void);
- void usb_dipatch_bus_reset(void);
- void usb_dispatch_state_chg(enum usb_dev_state state);
- enum usb_fnd_resp usb_dispatch_ctrl_req(struct usb_ctrl_req *req, struct usb_xfer *xfer);
- enum usb_fnd_resp usb_dispatch_set_conf(const struct usb_conf_desc *desc);
- enum usb_fnd_resp usb_dispatch_set_intf(const struct usb_intf_desc *base, const struct usb_intf_desc *sel);
- enum usb_fnd_resp usb_dispatch_get_intf(const struct usb_intf_desc *base, uint8_t *sel);
- void usb_ep0_reset(void);
- void usb_ep0_poll(void);
- extern struct usb_fn_drv usb_ctrl_std_drv;
|