More improvements to the incomplete BluetoothHost demo - add Disconnection Event processing.

Remove unused macro in the host mode demos for the maximum Configuration Descriptor size.
This commit is contained in:
Dean Camera 2010-04-01 04:30:21 +00:00
parent a2e6d54336
commit fd96b28882
24 changed files with 229 additions and 187 deletions

View file

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