3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
32 Bluetooth Dongle host demo application.
34 ** NOT CURRENTLY FUNCTIONAL - DO NOT USE **
37 #include "BluetoothHost.h"
39 Bluetooth_Device_t Bluetooth_DeviceConfiguration
=
41 Class
: (DEVICE_CLASS_SERVICE_CAPTURING
| DEVICE_CLASS_MAJOR_COMPUTER
| DEVICE_CLASS_MINOR_COMPUTER_PALM
),
43 Name
: "LUFA Bluetooth Demo"
51 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
54 puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY
55 "Bluetooth Host Demo running.\r\n" ESC_INVERSE_OFF
));
59 Bluetooth_Stack_Task();
60 Bluetooth_Management_Task();
64 void SetupHardware(void)
66 /* Disable watchdog if enabled by bootloader/fuses */
67 MCUSR
&= ~(1 << WDRF
);
70 /* Disable clock division */
71 clock_prescale_set(clock_div_1
);
73 /* Hardware Initialization */
74 SerialStream_Init(9600, false);
79 void EVENT_USB_DeviceAttached(void)
81 puts_P(PSTR("Device Attached.\r\n"));
83 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
86 void EVENT_USB_DeviceUnattached(void)
88 puts_P(PSTR("\r\nDevice Unattached.\r\n"));
90 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
93 void EVENT_USB_DeviceEnumerationComplete(void)
95 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
98 void EVENT_USB_HostError(uint8_t ErrorCode
)
102 puts_P(PSTR(ESC_BG_RED
"Host Mode Error\r\n"));
103 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
105 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
109 void EVENT_USB_DeviceEnumerationFailed(uint8_t ErrorCode
, uint8_t SubErrorCode
)
111 puts_P(PSTR(ESC_BG_RED
"Dev Enum Error\r\n"));
112 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
113 printf_P(PSTR(" -- In State %d\r\n"), USB_HostState
);
115 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
118 void Bluetooth_Management_Task(void)
122 switch (USB_HostState
)
124 case HOST_STATE_Addressed
:
125 puts_P(PSTR("Getting Device Data.\r\n"));
127 /* Get and process the configuration descriptor data */
128 if ((ErrorCode
= ProcessDeviceDescriptor()) != SuccessfulDeviceRead
)
130 if (ErrorCode
== ControlErrorDuringDeviceRead
)
131 puts_P(PSTR("Control Error (Get Device).\r\n"));
133 puts_P(PSTR("Invalid Device.\r\n"));
135 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode
);
137 /* Indicate error via status LEDs */
138 LEDs_SetAllLEDs(LEDS_LED1
);
140 /* Wait until USB device disconnected */
141 while (USB_IsConnected
);
145 puts_P(PSTR("Bluetooth Dongle Detected.\r\n"));
147 /* Standard request to set the device configuration to configuration 1 */
148 USB_ControlRequest
= (USB_Request_Header_t
)
150 bmRequestType
: (REQDIR_HOSTTODEVICE
| REQTYPE_STANDARD
| REQREC_DEVICE
),
151 bRequest
: REQ_SetConfiguration
,
157 /* Select the control pipe for the request transfer */
158 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
160 /* Send the request, display error and wait for device detatch if request fails */
161 if ((ErrorCode
= USB_Host_SendControlRequest(NULL
)) != HOST_SENDCONTROL_Successful
)
163 puts_P(PSTR("Control Error (Set Configuration).\r\n"));
164 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode
);
166 /* Indicate error via status LEDs */
167 LEDs_SetAllLEDs(LEDS_LED1
);
169 /* Wait until USB device disconnected */
170 while (USB_IsConnected
);
174 USB_HostState
= HOST_STATE_Configured
;
176 case HOST_STATE_Configured
:
177 puts_P(PSTR("Getting Config Data.\r\n"));
179 /* Get and process the configuration descriptor data */
180 if ((ErrorCode
= ProcessConfigurationDescriptor()) != SuccessfulConfigRead
)
182 if (ErrorCode
== ControlErrorDuringConfigRead
)
183 puts_P(PSTR("Control Error (Get Configuration).\r\n"));
185 puts_P(PSTR("Invalid Device.\r\n"));
187 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode
);
189 /* Indicate error via status LEDs */
190 LEDs_SetAllLEDs(LEDS_LED1
);
192 /* Wait until USB device disconnected */
193 while (USB_IsConnected
);
197 puts_P(PSTR("Bluetooth Dongle Enumerated.\r\n"));
199 USB_HostState
= HOST_STATE_Ready
;
201 case HOST_STATE_Ready
:
202 /* Do nothing, Bluetooth stack will take care of enumeration */