More improvements to the incomplete BluetoothHost demo - add Disconnection Event...
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / BluetoothHost.c
index e492815..312d716 100644 (file)
   this software.\r
 */\r
 \r
-/*\r
-       Bluetooth Dongle host demo application.\r
-       \r
-       ** NOT CURRENTLY FUNCTIONAL - DO NOT USE **\r
-*/\r
+/** \file\r
+ *\r
+ *  Main source file for the BluetoothHost demo. This file contains the main tasks of\r
+ *  the demo and is responsible for the initial application hardware configuration.\r
+ */\r
 \r
 #include "BluetoothHost.h"\r
 \r
@@ -43,23 +43,26 @@ Bluetooth_Device_t Bluetooth_DeviceConfiguration =
                Name:    "LUFA Bluetooth Demo"\r
        };\r
 \r
-\r
+/** Main program entry point. This routine configures the hardware required by the application, then\r
+ *  enters a loop to run the application tasks in sequence.\r
+ */\r
 int main(void)\r
 {\r
        SetupHardware();\r
+\r
+       puts_P(PSTR(ESC_FG_CYAN "Bluetooth Host Demo running.\r\n" ESC_FG_WHITE));\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 \r
-       puts_P(PSTR(ESC_FG_CYAN "Bluetooth Host Demo running.\r\n" ESC_FG_WHITE));\r
-                  \r
        for (;;)\r
        {\r
                Bluetooth_Stack_Task();\r
-               Bluetooth_Management_Task();\r
+               Bluetooth_Host_Task();\r
                USB_USBTask();\r
        }\r
 }\r
 \r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
 void SetupHardware(void)\r
 {\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
@@ -75,26 +78,34 @@ void SetupHardware(void)
        USB_Init();\r
 }\r
 \r
+/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
+ *  starts the library USB task to begin the enumeration and USB management process.\r
+ */\r
 void EVENT_USB_Host_DeviceAttached(void)\r
 {\r
        puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));\r
-\r
        LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
 }\r
 \r
+/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
+ *  stops the library USB task management process.\r
+ */\r
 void EVENT_USB_Host_DeviceUnattached(void)\r
 {\r
        puts_P(PSTR(ESC_FG_GREEN "\r\nDevice Unattached.\r\n" ESC_FG_WHITE));\r
-\r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 }\r
 \r
+/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
+ *  enumerated by the host and is now ready to be used by the application.\r
+ */\r
 void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
 {\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
-void EVENT_USB_Host_HostError(uint8_t ErrorCode)\r
+/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
+void EVENT_USB_Host_HostError(const uint8_t ErrorCode)\r
 {\r
        USB_ShutDown();\r
 \r
@@ -105,7 +116,10 @@ void EVENT_USB_Host_HostError(uint8_t ErrorCode)
        for(;;);\r
 }\r
 \r
-void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)\r
+/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
+ *  enumerating an attached USB device.\r
+ */\r
+void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
 {\r
        printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"\r
                                 " -- Error Code %d\r\n"\r
@@ -115,7 +129,8 @@ void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorC
        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r
 \r
-void Bluetooth_Management_Task(void)\r
+/** Task to set the configuration of the attached device after it has been enumerated. */\r
+void Bluetooth_Host_Task(void)\r
 {\r
        uint8_t ErrorCode;\r
 \r
@@ -127,7 +142,7 @@ void Bluetooth_Management_Task(void)
                        /* Get and process the configuration descriptor data */\r
                        if ((ErrorCode = ProcessDeviceDescriptor()) != SuccessfulDeviceRead)\r
                        {\r
-                               if (ErrorCode == ControlErrorDuringDeviceRead)\r
+                               if (ErrorCode == DevControlError)\r
                                  puts_P(PSTR(ESC_FG_RED "Control Error (Get Device).\r\n"));\r
                                else\r
                                  puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));\r
@@ -163,7 +178,7 @@ void Bluetooth_Management_Task(void)
                        /* Get and process the configuration descriptor data */\r
                        if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)\r
                        {\r
-                               if (ErrorCode == ControlErrorDuringConfigRead)\r
+                               if (ErrorCode == ControlError)\r
                                  puts_P(PSTR(ESC_FG_RED "Control Error (Get Configuration).\r\n"));\r
                                else\r
                                  puts_P(PSTR(ESC_FG_RED "Invalid Device.\r\n"));\r