altos/lpc: Clean up USB endpoint access functions
authorKeith Packard <keithp@keithp.com>
Fri, 6 Feb 2015 00:08:44 +0000 (16:08 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 6 Feb 2015 00:14:23 +0000 (16:14 -0800)
The USB device endpoints can have two pointers in them, but we use
only the first. Fix the access functions to take an index as to which
we want so that we can disable the other address registers with them
instead of requiring open-coded access.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lpc/ao_usb_lpc.c

index 12f5d8e6973013c5c5113bbe9d50a97d509d9fd3..78fbac3985ea848e3a519c2c977562c193ab3774 100644 (file)
@@ -234,15 +234,15 @@ ao_usb_ep0_in(void)
 }
 
 static inline vuint32_t *
 }
 
 static inline vuint32_t *
-ao_usb_epn_out(uint8_t n)
+ao_usb_epn_out(uint8_t n, uint8_t i)
 {
 {
-       return &lpc_usb_endpoint.epn[n-1].out[0];
+       return &lpc_usb_endpoint.epn[n-1].out[i];
 }
 
 static inline vuint32_t *
 }
 
 static inline vuint32_t *
-ao_usb_epn_in(uint8_t n)
+ao_usb_epn_in(uint8_t n, uint8_t i)
 {
 {
-       return &lpc_usb_endpoint.epn[n-1].in[0];
+       return &lpc_usb_endpoint.epn[n-1].in[i];
 }
 
 #if UNUSED
 }
 
 #if UNUSED
@@ -256,26 +256,26 @@ ao_usb_set_epn_in(uint8_t n, uint8_t *addr, uint16_t nbytes)
 static void
 ao_usb_set_epn_out(uint8_t n, uint8_t *addr, uint16_t nbytes)
 {
 static void
 ao_usb_set_epn_out(uint8_t n, uint8_t *addr, uint16_t nbytes)
 {
-       ao_usb_set_ep(ao_usb_epn_out(n), addr, nbytes);
+       ao_usb_set_ep(ao_usb_epn_out(n, 0), addr, nbytes);
 }
 
 static inline uint16_t
 ao_usb_epn_out_count(uint8_t n)
 {
 }
 
 static inline uint16_t
 ao_usb_epn_out_count(uint8_t n)
 {
-       return ao_usb_ep_count(ao_usb_epn_out(n));
+       return ao_usb_ep_count(ao_usb_epn_out(n, 0));
 }
 
 static inline uint16_t
 ao_usb_epn_in_count(uint8_t n)
 {
 }
 
 static inline uint16_t
 ao_usb_epn_in_count(uint8_t n)
 {
-       return ao_usb_ep_count(ao_usb_epn_in(n));
+       return ao_usb_ep_count(ao_usb_epn_in(n, 0));
 }
 
 static uint8_t *
 ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes)
 {
        uint8_t *addr = ao_usb_alloc_sram(nbytes);
 }
 
 static uint8_t *
 ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes)
 {
        uint8_t *addr = ao_usb_alloc_sram(nbytes);
-       
+
        ao_usb_set_ep(ep, addr, set_nbytes);
        return addr;
 }
        ao_usb_set_ep(ep, addr, set_nbytes);
        return addr;
 }
@@ -298,24 +298,24 @@ ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint8_t **out_addr, uint16_t in
 {
        uint8_t *addr;
 
 {
        uint8_t *addr;
 
-       addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_bytes);
+       addr = ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_bytes, out_bytes);
        if (out_addr)
                *out_addr = addr;
        if (out_addr)
                *out_addr = addr;
-       ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]);
+       ao_usb_disable_ep(ao_usb_epn_out(n, 1));
 
 
-       addr = ao_usb_enable_ep(ao_usb_epn_in(n), in_bytes, 0);
+       addr = ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_bytes, 0);
        if (in_addr)
                *in_addr = addr;
        if (in_addr)
                *in_addr = addr;
-       ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].in[1]);
+       ao_usb_disable_ep(ao_usb_epn_in(n, 1));
 }
 
 static void
 ao_usb_disable_epn(uint8_t n)
 {
 }
 
 static void
 ao_usb_disable_epn(uint8_t n)
 {
-       ao_usb_disable_ep(ao_usb_epn_out(n));
-       ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]);
-       ao_usb_disable_ep(ao_usb_epn_in(n));
-       ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].in[1]);
+       ao_usb_disable_ep(ao_usb_epn_out(n, 0));
+       ao_usb_disable_ep(ao_usb_epn_out(n, 1));
+       ao_usb_disable_ep(ao_usb_epn_in(n, 0));
+       ao_usb_disable_ep(ao_usb_epn_in(n, 1));
 }
 
 static void
 }
 
 static void
@@ -717,7 +717,7 @@ _ao_usb_in_send(void)
        if (ao_usb_tx_count != AO_USB_IN_SIZE)
                ao_usb_in_flushed = 1;
        memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count);
        if (ao_usb_tx_count != AO_USB_IN_SIZE)
                ao_usb_in_flushed = 1;
        memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count);
-       ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer, ao_usb_tx_count);
+       ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP, 0), ao_usb_in_tx_buffer, ao_usb_tx_count);
        ao_usb_tx_count = 0;
        _tx_dbg0("in_send end");
 }
        ao_usb_tx_count = 0;
        _tx_dbg0("in_send end");
 }
@@ -897,7 +897,7 @@ ao_usb_enable(void)
 
        /* Enable USB PHY */
        lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPAD_PD);
 
        /* Enable USB PHY */
        lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPAD_PD);
-       
+
        /* Turn on USB PLL */
        lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPLL_PD);
 
        /* Turn on USB PLL */
        lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPLL_PD);
 
@@ -1044,7 +1044,7 @@ static void _dbg(int line, char *msg, uint32_t value)
        dbg[dbg_i].primask = primask;
 #if TX_DBG
        dbg[dbg_i].in_count = in_count;
        dbg[dbg_i].primask = primask;
 #if TX_DBG
        dbg[dbg_i].in_count = in_count;
-       dbg[dbg_i].in_ep = *ao_usb_epn_in(AO_USB_IN_EP);
+       dbg[dbg_i].in_ep = *ao_usb_epn_in(AO_USB_IN_EP, 0);
        dbg[dbg_i].in_pending = ao_usb_in_pending;
        dbg[dbg_i].tx_count = ao_usb_tx_count;
        dbg[dbg_i].in_flushed = ao_usb_in_flushed;
        dbg[dbg_i].in_pending = ao_usb_in_pending;
        dbg[dbg_i].tx_count = ao_usb_tx_count;
        dbg[dbg_i].in_flushed = ao_usb_in_flushed;
@@ -1053,7 +1053,7 @@ static void _dbg(int line, char *msg, uint32_t value)
        dbg[dbg_i].rx_count = ao_usb_rx_count;
        dbg[dbg_i].rx_pos = ao_usb_rx_pos;
        dbg[dbg_i].out_avail = ao_usb_out_avail;
        dbg[dbg_i].rx_count = ao_usb_rx_count;
        dbg[dbg_i].rx_pos = ao_usb_rx_pos;
        dbg[dbg_i].out_avail = ao_usb_out_avail;
-       dbg[dbg_i].out_ep = *ao_usb_epn_out(AO_USB_OUT_EP);
+       dbg[dbg_i].out_ep = *ao_usb_epn_out(AO_USB_OUT_EP, 0);
 #endif
        if (++dbg_i == NUM_USB_DBG)
                dbg_i = 0;
 #endif
        if (++dbg_i == NUM_USB_DBG)
                dbg_i = 0;