summaryrefslogtreecommitdiffhomepage
path: root/digital/dev2/src/usb_gpio/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/dev2/src/usb_gpio/main.c')
-rw-r--r--digital/dev2/src/usb_gpio/main.c33
1 files changed, 4 insertions, 29 deletions
diff --git a/digital/dev2/src/usb_gpio/main.c b/digital/dev2/src/usb_gpio/main.c
index 734e5198..4e251d93 100644
--- a/digital/dev2/src/usb_gpio/main.c
+++ b/digital/dev2/src/usb_gpio/main.c
@@ -30,6 +30,7 @@
#include <avr/wdt.h>
#include "descriptors.h"
+#include "common/gpio.h"
#include "common/select.h"
HANDLES_EVENT (USB_Connect);
@@ -39,35 +40,6 @@ HANDLES_EVENT (USB_UnhandledControlPacket);
volatile uint8_t usb_connected, usb_configured;
-void
-gpio_task (void)
-{
- Endpoint_SelectEndpoint (GPIO_RX_EPNUM);
- /* If data is available from USB: */
- if (Endpoint_ReadWriteAllowed ())
- {
- /* Read as much as possible, and clear endpoint. */
- do {
- Endpoint_Discard_Byte ();
- } while (Endpoint_ReadWriteAllowed ());
- Endpoint_ClearCurrentBank ();
- /* Now, print current GPIO state if possible. */
- Endpoint_SelectEndpoint (GPIO_TX_EPNUM);
- if (Endpoint_ReadWriteAllowed ())
- {
- uint8_t i, pin;
- pin = PIND;
- for (i = 0; i < 8; i++)
- {
- Endpoint_Write_Byte (pin & 0x80 ? '1' : '0');
- pin <<= 1;
- }
- Endpoint_Write_Byte ('\r');
- Endpoint_ClearCurrentBank ();
- }
- }
-}
-
int
main (void)
{
@@ -145,7 +117,10 @@ EVENT_HANDLER (USB_UnhandledControlPacket)
uint8_t output = Endpoint_Read_Byte ();
Endpoint_ClearSetupReceived ();
/* Select output. */
+ gpio_uninit ();
select_out (output);
+ if (select_active (output))
+ gpio_init ();
/* Send acknowledgement. */
Endpoint_ClearSetupIN ();
}