-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2010.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2010 OBinou (obconseil [at] gmail [dot] com)\r
- Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- *\r
- * Main source file for the RelayBoard program. This file contains the main tasks of\r
- * the project and is responsible for the initial application hardware configuration.\r
- */\r
-\r
-#include "RelayBoard.h"\r
-\r
-\r
-/** Main program entry point. This routine contains the overall program flow, including initial\r
- * setup of all components and the main program loop.\r
- */\r
-int main(void)\r
-{\r
- SetupHardware();\r
-\r
- for (;;)\r
- USB_USBTask();\r
-}\r
-\r
-/** Configures the board hardware and chip peripherals for the project's functionality. */\r
-void SetupHardware(void)\r
-{\r
- /* Disable watchdog if enabled by bootloader/fuses */\r
- MCUSR &= ~(1 << WDRF);\r
- wdt_disable();\r
-\r
- /* Disable clock division */\r
- clock_prescale_set(clock_div_1);\r
-\r
- /* Hardware Initialization */\r
- USB_Init();\r
-\r
- /* Initialize Relays */\r
- DDRC |= ALL_RELAYS;\r
- PORTC &= ~ALL_RELAYS;\r
-}\r
-\r
-\r
-/** Event handler for the library USB Configuration Changed event. */\r
-void EVENT_USB_Device_ConfigurationChanged(void)\r
-{\r
- USB_Device_EnableSOFEvents();\r
-}\r
-\r
-/** Event handler for the library USB Unhandled Control Packet event. */\r
-void EVENT_USB_Device_UnhandledControlRequest(void)\r
-{\r
- const uint8_t SerialNumber[5] = { 0, 0, 0, 0, 1 };\r
- uint8_t ControlData[2] = { 0, 0 };\r
-\r
- switch (USB_ControlRequest.bRequest)\r
- {\r
- case 0x09:\r
- if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
- {\r
- LEDs_ToggleLEDs(LEDS_LED1);\r
-\r
- Endpoint_ClearSETUP();\r
-\r
- Endpoint_Read_Control_Stream_LE(ControlData, sizeof(ControlData));\r
- Endpoint_ClearIN();\r
-\r
- switch (USB_ControlRequest.wValue)\r
- {\r
- case 0x303:\r
- if (ControlData[1]) PORTC &= ~RELAY1; else PORTC |= RELAY1;\r
- break;\r
- case 0x306:\r
- if (ControlData[1]) PORTC &= ~RELAY2; else PORTC |= RELAY2;\r
- break;\r
- case 0x309:\r
- if (ControlData[1]) PORTC &= ~RELAY3; else PORTC |= RELAY3;\r
- break;\r
- case 0x30c:\r
- if (ControlData[1]) PORTC &= ~RELAY4; else PORTC |= RELAY4;\r
- break;\r
- }\r
- }\r
- \r
- break;\r
- case 0x01:\r
- if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
- {\r
- LEDs_ToggleLEDs(LEDS_LED1);\r
-\r
- Endpoint_ClearSETUP();\r
-\r
- switch (USB_ControlRequest.wValue)\r
- {\r
- case 0x301:\r
- Endpoint_Write_Control_Stream_LE(SerialNumber, sizeof(SerialNumber));\r
- break;\r
- case 0x303:\r
- ControlData[1] = (PORTC & RELAY1) ? 2 : 3;\r
- break;\r
- case 0x306:\r
- ControlData[1] = (PORTC & RELAY2) ? 2 : 3;\r
- break;\r
- case 0x309:\r
- ControlData[1] = (PORTC & RELAY3) ? 2 : 3;\r
- break;\r
- case 0x30c:\r
- ControlData[1] = (PORTC & RELAY4) ? 2 : 3;\r
- break;\r
- }\r
- \r
- if (ControlData[1])\r
- Endpoint_Write_Control_Stream_LE(ControlData, sizeof(ControlData));\r
-\r
- Endpoint_ClearOUT();\r
- }\r
-\r
- break;\r
- }\r
-}\r
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2011.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2010 OBinou (obconseil [at] gmail [dot] com)
+ Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ *
+ * Main source file for the RelayBoard program. This file contains the main tasks of
+ * the project and is responsible for the initial application hardware configuration.
+ */
+
+#include "RelayBoard.h"
+
+
+/** Main program entry point. This routine contains the overall program flow, including initial
+ * setup of all components and the main program loop.
+ */
+int main(void)
+{
+ SetupHardware();
+
+ sei();
+
+ for (;;)
+ USB_USBTask();
+}
+
+/** Configures the board hardware and chip peripherals for the project's functionality. */
+void SetupHardware(void)
+{
+ /* Disable watchdog if enabled by bootloader/fuses */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ /* Disable clock division */
+ clock_prescale_set(clock_div_1);
+
+ /* Hardware Initialization */
+ USB_Init();
+
+ /* Initialize Relays */
+ DDRC |= ALL_RELAYS;
+ PORTC &= ~ALL_RELAYS;
+}
+
+/** Event handler for the library USB Control Request reception event. */
+void EVENT_USB_Device_ControlRequest(void)
+{
+ const uint8_t SerialNumber[5] = { 0, 0, 0, 0, 1 };
+ uint8_t ControlData[2] = { 0, 0 };
+
+ switch (USB_ControlRequest.bRequest)
+ {
+ case 0x09:
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
+ {
+ LEDs_ToggleLEDs(LEDS_LED1);
+
+ Endpoint_ClearSETUP();
+
+ Endpoint_Read_Control_Stream_LE(ControlData, sizeof(ControlData));
+ Endpoint_ClearIN();
+
+ switch (USB_ControlRequest.wValue)
+ {
+ case 0x303:
+ if (ControlData[1]) PORTC &= ~RELAY1; else PORTC |= RELAY1;
+ break;
+ case 0x306:
+ if (ControlData[1]) PORTC &= ~RELAY2; else PORTC |= RELAY2;
+ break;
+ case 0x309:
+ if (ControlData[1]) PORTC &= ~RELAY3; else PORTC |= RELAY3;
+ break;
+ case 0x30c:
+ if (ControlData[1]) PORTC &= ~RELAY4; else PORTC |= RELAY4;
+ break;
+ }
+ }
+
+ break;
+ case 0x01:
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
+ {
+ LEDs_ToggleLEDs(LEDS_LED1);
+
+ Endpoint_ClearSETUP();
+
+ switch (USB_ControlRequest.wValue)
+ {
+ case 0x301:
+ Endpoint_Write_Control_Stream_LE(SerialNumber, sizeof(SerialNumber));
+ break;
+ case 0x303:
+ ControlData[1] = (PORTC & RELAY1) ? 2 : 3;
+ break;
+ case 0x306:
+ ControlData[1] = (PORTC & RELAY2) ? 2 : 3;
+ break;
+ case 0x309:
+ ControlData[1] = (PORTC & RELAY3) ? 2 : 3;
+ break;
+ case 0x30c:
+ ControlData[1] = (PORTC & RELAY4) ? 2 : 3;
+ break;
+ }
+
+ if (ControlData[1])
+ Endpoint_Write_Control_Stream_LE(ControlData, sizeof(ControlData));
+
+ Endpoint_ClearOUT();
+ }
+
+ break;
+ }
+}
+