Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / src / stm / ao_usb_stm.c
index e484cd22f03c58ae0e9cb319e91a6d0bcb5d91fe..4e9d1f145cd98001e4378d3f8ea12050fc034e91 100644 (file)
 #define USB_DEBUG_DATA 0
 #define USB_ECHO       0
 
+#ifndef USE_USB_STDIO
+#define USE_USB_STDIO  1
+#endif
+
+#if USE_USB_STDIO
+#define AO_USB_OUT_SLEEP_ADDR  (&ao_stdin_ready)
+#else
+#define AO_USB_OUT_SLEEP_ADDR  (&ao_usb_out_avail)
+#endif
+
 #if USB_DEBUG
 #define debug(format, args...) printf(format, ## args);
 #else
@@ -107,9 +117,8 @@ static uint8_t      ao_usb_in_pending;
  * but not pulled to the shadow buffer.
  */
 static uint8_t ao_usb_out_avail;
-static uint8_t ao_usb_running;
+uint8_t                ao_usb_running;
 static uint8_t ao_usb_configuration;
-static uint8_t ueienx_0;
 
 #define AO_USB_EP0_GOT_RESET   1
 #define AO_USB_EP0_GOT_SETUP   2
@@ -303,7 +312,6 @@ ao_usb_init_ep(uint8_t ep, uint32_t addr, uint32_t type, uint32_t stat_rx, uint3
 static void
 ao_usb_set_ep0(void)
 {
-       uint32_t                epr;
        int                     e;
 
        ao_usb_sram_addr = 0;
@@ -346,8 +354,6 @@ ao_usb_set_ep0(void)
 static void
 ao_usb_set_configuration(void)
 {
-       uint32_t                epr;
-
        debug ("ao_usb_set_configuration\n");
 
        /* Set up the INT end point */
@@ -562,7 +568,7 @@ ao_usb_ep0_out_set(uint8_t *data, uint8_t len)
 }
 
 static void
-ao_usb_ep0_in_start(uint8_t max)
+ao_usb_ep0_in_start(uint16_t max)
 {
        /* Don't send more than asked for */
        if (ao_usb_ep0_in_len > max)
@@ -721,6 +727,9 @@ ao_usb_ep0_handle(uint8_t receive)
        if (receive & AO_USB_EP0_GOT_TX_ACK) {
                debug ("\tgot tx ack\n");
 
+#if HAS_FLIGHT && AO_USB_FORCE_IDLE
+               ao_flight_force_idle = 1;
+#endif
                /* Wait until the IN packet is received from addr 0
                 * before assigning our local address
                 */
@@ -770,7 +779,7 @@ stm_usb_lp_isr(void)
                                _rx_dbg1("RX ISR", epr);
                                ao_usb_out_avail = 1;
                                _rx_dbg0("out avail set");
-                               ao_wakeup(&ao_stdin_ready);
+                               ao_wakeup(AO_USB_OUT_SLEEP_ADDR);
                                _rx_dbg0("stdin awoken");
                        }
                        break;
@@ -936,7 +945,7 @@ ao_usb_getchar(void)
 
        ao_arch_block_interrupts();
        while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN)
-               ao_sleep(&ao_stdin_ready);
+               ao_sleep(AO_USB_OUT_SLEEP_ADDR);
        ao_arch_release_interrupts();
        return c;
 }
@@ -955,7 +964,7 @@ ao_usb_disable(void)
        stm_usb.cntr = (1 << STM_USB_CNTR_PDWN) | (1 << STM_USB_CNTR_FRES);
 
        /* Disable the interface */
-       stm_rcc.apb1enr &+ ~(1 << STM_RCC_APB1ENR_USBEN);
+       stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_USBEN);
        ao_arch_release_interrupts();
 }
 
@@ -1064,8 +1073,10 @@ ao_usb_init(void)
        ao_cmd_register(&ao_usb_cmds[0]);
 #endif
 #if !USB_ECHO
+#if USE_USB_STDIO
        ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush);
 #endif
+#endif
 }
 
 #if TX_DBG || RX_DBG