|
@@ -156,7 +156,7 @@ static uint16_t get_next_pma(uint16_t sz) {
|
|
|
return (_result < (0x020 + sz)) ? 0 : (_result - sz);
|
|
return (_result < (0x020 + sz)) ? 0 : (_result - sz);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-uint32_t getinfo(void) {
|
|
|
|
|
|
|
+static uint32_t getinfo(void) {
|
|
|
if (!(RCC->APB1ENR & RCC_APB1ENR_USBEN)) return STATUS_VAL(0);
|
|
if (!(RCC->APB1ENR & RCC_APB1ENR_USBEN)) return STATUS_VAL(0);
|
|
|
#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN)
|
|
#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN)
|
|
|
if (USBD_DP_PORT->IDR & _BV(USBD_DP_PIN)) return STATUS_VAL(USBD_HW_ENABLED | USBD_HW_SPEED_FS);
|
|
if (USBD_DP_PORT->IDR & _BV(USBD_DP_PIN)) return STATUS_VAL(USBD_HW_ENABLED | USBD_HW_SPEED_FS);
|
|
@@ -166,7 +166,7 @@ uint32_t getinfo(void) {
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ep_setstall(uint8_t ep, bool stall) {
|
|
|
|
|
|
|
+static void ep_setstall(uint8_t ep, bool stall) {
|
|
|
volatile uint16_t *reg = EPR(ep);
|
|
volatile uint16_t *reg = EPR(ep);
|
|
|
/* ISOCHRONOUS endpoint can't be stalled or unstalled */
|
|
/* ISOCHRONOUS endpoint can't be stalled or unstalled */
|
|
|
if (USB_EP_ISOCHRONOUS == (*reg & USB_EP_T_FIELD)) return;
|
|
if (USB_EP_ISOCHRONOUS == (*reg & USB_EP_T_FIELD)) return;
|
|
@@ -203,7 +203,7 @@ void ep_setstall(uint8_t ep, bool stall) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool ep_isstalled(uint8_t ep) {
|
|
|
|
|
|
|
+static bool ep_isstalled(uint8_t ep) {
|
|
|
if (ep & 0x80) {
|
|
if (ep & 0x80) {
|
|
|
return (USB_EP_TX_STALL == (USB_EPTX_STAT & *EPR(ep)));
|
|
return (USB_EP_TX_STALL == (USB_EPTX_STAT & *EPR(ep)));
|
|
|
} else {
|
|
} else {
|
|
@@ -211,7 +211,7 @@ bool ep_isstalled(uint8_t ep) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-uint8_t connect(bool connect) {
|
|
|
|
|
|
|
+static uint8_t connect(bool connect) {
|
|
|
#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN) && defined(STM32F3)
|
|
#if defined(USBD_DP_PORT) && defined(USBD_DP_PIN) && defined(STM32F3)
|
|
|
uint32_t _t = USBD_DP_PORT->MODER & ~(0x03 << (2 * USBD_DP_PIN));
|
|
uint32_t _t = USBD_DP_PORT->MODER & ~(0x03 << (2 * USBD_DP_PIN));
|
|
|
if (connect) {
|
|
if (connect) {
|
|
@@ -243,7 +243,7 @@ uint8_t connect(bool connect) {
|
|
|
return usbd_lane_unk;
|
|
return usbd_lane_unk;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void enable(bool enable) {
|
|
|
|
|
|
|
+static void enable(bool enable) {
|
|
|
if (enable) {
|
|
if (enable) {
|
|
|
set_gpiox();
|
|
set_gpiox();
|
|
|
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
|
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
|
@@ -262,11 +262,11 @@ void enable(bool enable) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void setaddr (uint8_t addr) {
|
|
|
|
|
|
|
+static void setaddr (uint8_t addr) {
|
|
|
USB->DADDR = USB_DADDR_EF | addr;
|
|
USB->DADDR = USB_DADDR_EF | addr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool ep_config(uint8_t ep, uint8_t eptype, uint16_t epsize) {
|
|
|
|
|
|
|
+static bool ep_config(uint8_t ep, uint8_t eptype, uint16_t epsize) {
|
|
|
volatile uint16_t *reg = EPR(ep);
|
|
volatile uint16_t *reg = EPR(ep);
|
|
|
pma_table *tbl = EPT(ep);
|
|
pma_table *tbl = EPT(ep);
|
|
|
/* epsize should be 16-bit aligned */
|
|
/* epsize should be 16-bit aligned */
|
|
@@ -337,7 +337,7 @@ bool ep_config(uint8_t ep, uint8_t eptype, uint16_t epsize) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ep_deconfig(uint8_t ep) {
|
|
|
|
|
|
|
+static void ep_deconfig(uint8_t ep) {
|
|
|
pma_table *ept = EPT(ep);
|
|
pma_table *ept = EPT(ep);
|
|
|
*EPR(ep) &= ~USB_EPREG_MASK;
|
|
*EPR(ep) &= ~USB_EPREG_MASK;
|
|
|
ept->rx.addr = 0;
|
|
ept->rx.addr = 0;
|
|
@@ -366,7 +366,7 @@ static uint16_t pma_read (uint8_t *buf, uint16_t blen, pma_rec *rx) {
|
|
|
return rxcnt;
|
|
return rxcnt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int32_t ep_read(uint8_t ep, void *buf, uint16_t blen) {
|
|
|
|
|
|
|
+static int32_t ep_read(uint8_t ep, void *buf, uint16_t blen) {
|
|
|
pma_table *tbl = EPT(ep);
|
|
pma_table *tbl = EPT(ep);
|
|
|
volatile uint16_t *reg = EPR(ep);
|
|
volatile uint16_t *reg = EPR(ep);
|
|
|
switch (*reg & (USB_EPRX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) {
|
|
switch (*reg & (USB_EPRX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) {
|
|
@@ -423,7 +423,7 @@ static void pma_write(const uint8_t *buf, uint16_t blen, pma_rec *tx) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int32_t ep_write(uint8_t ep, void *buf, uint16_t blen) {
|
|
|
|
|
|
|
+static int32_t ep_write(uint8_t ep, void *buf, uint16_t blen) {
|
|
|
pma_table *tbl = EPT(ep);
|
|
pma_table *tbl = EPT(ep);
|
|
|
volatile uint16_t *reg = EPR(ep);
|
|
volatile uint16_t *reg = EPR(ep);
|
|
|
switch (*reg & (USB_EPTX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) {
|
|
switch (*reg & (USB_EPTX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) {
|
|
@@ -458,11 +458,11 @@ int32_t ep_write(uint8_t ep, void *buf, uint16_t blen) {
|
|
|
return blen;
|
|
return blen;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-uint16_t get_frame (void) {
|
|
|
|
|
|
|
+static uint16_t get_frame (void) {
|
|
|
return USB->FNR & USB_FNR_FN;
|
|
return USB->FNR & USB_FNR_FN;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void evt_poll(usbd_device *dev, usbd_evt_callback callback) {
|
|
|
|
|
|
|
+static void evt_poll(usbd_device *dev, usbd_evt_callback callback) {
|
|
|
uint8_t _ev, _ep;
|
|
uint8_t _ev, _ep;
|
|
|
uint16_t _istr = USB->ISTR;
|
|
uint16_t _istr = USB->ISTR;
|
|
|
_ep = _istr & USB_ISTR_EP_ID;
|
|
_ep = _istr & USB_ISTR_EP_ID;
|
|
@@ -515,7 +515,7 @@ static uint32_t fnv1a32_turn (uint32_t fnv, uint32_t data ) {
|
|
|
return fnv;
|
|
return fnv;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-uint16_t get_serialno_desc(void *buffer) {
|
|
|
|
|
|
|
+static uint16_t get_serialno_desc(void *buffer) {
|
|
|
struct usb_string_descriptor *dsc = buffer;
|
|
struct usb_string_descriptor *dsc = buffer;
|
|
|
uint16_t *str = dsc->wString;
|
|
uint16_t *str = dsc->wString;
|
|
|
uint32_t fnv = 2166136261;
|
|
uint32_t fnv = 2166136261;
|