]> mj.ucw.cz Git - home-hw.git/blobdiff - usb/Inc/usb.h
Aircon: Separate registers, temperatures in ddegC
[home-hw.git] / usb / Inc / usb.h
index 2aea056771dd35497642f44e313e4379364599c4..79b892c01bebb53a2d71a06b36c8e08920b47a06 100644 (file)
@@ -21,14 +21,17 @@ struct usb {
   PCD_HandleTypeDef *hpcd;
   byte state;                  // USB_STATE_xxx
   byte pre_suspend_state;
-  byte address;
-  byte config;
-  byte remote_wakeup;
+  byte address;                        // Device address assigned by the host (0=none)
+  byte config;                 // Selected configuration (0=none)
+  byte remote_wakeup;          // State of remote wakeup feature
+
+  // State of endpoint 00
   byte ep0_state;              // USB_EP0_xxx
   u16 ep0_setup_data_length;
   u16 ep0_remaining_length;
   u16 ep0_total_length;
   byte ep0_buf[USB_EP0_BUF_SIZE];
+
   // Descriptor data to be filled by the user during usb_dev_reset()
   const byte *desc_device;
   const byte *desc_config;
@@ -38,6 +41,9 @@ struct usb {
   u16 desc_config_len;
   u16 desc_string_items;
   u16 desc_languages_len;
+
+  // Internal use
+  u16 last_pma_alloc;
 };
 
 enum usb_device_state {
@@ -181,11 +187,15 @@ enum usb_ep_type {
 
 // Wrappers return HAL_OK / HAL_ERROR / HAL_BUSY / HAL_TIMEOUT
 
+// Call from configure callback
 static inline HAL_StatusTypeDef usb_ep_open(struct usb *usb, byte ep_addr, byte ep_type, byte ep_max_size)
 {
+  HAL_PCDEx_PMAConfig(usb->hpcd, ep_addr, PCD_SNG_BUF, usb->last_pma_alloc);
+  usb->last_pma_alloc += (ep_max_size + 7) & ~7U;
   return HAL_PCD_EP_Open(usb->hpcd, ep_addr, ep_max_size, ep_type);
 }
 
+// Call from unconfigure callback
 static inline HAL_StatusTypeDef usb_ep_close(struct usb *usb, byte ep_addr)
 {
   return HAL_PCD_EP_Close(usb->hpcd, ep_addr);