More Doxygen fixes - ensure no undocumented function parameters.
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / BluetoothHost.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /*
32 Bluetooth Dongle host demo application.
33
34 ** NOT CURRENTLY FUNCTIONAL - DO NOT USE **
35 */
36
37 #include "BluetoothHost.h"
38
39 Bluetooth_Device_t Bluetooth_DeviceConfiguration =
40 {
41 Class: (DEVICE_CLASS_SERVICE_CAPTURING | DEVICE_CLASS_MAJOR_COMPUTER | DEVICE_CLASS_MINOR_COMPUTER_PALM),
42 PINCode: "0000",
43 Name: "LUFA Bluetooth Demo"
44 };
45
46
47 int main(void)
48 {
49 SetupHardware();
50
51 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
52
53 /* Startup message */
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));
56
57 for (;;)
58 {
59 Bluetooth_Stack_Task();
60 Bluetooth_Management_Task();
61 USB_USBTask();
62 }
63 }
64
65 void SetupHardware(void)
66 {
67 /* Disable watchdog if enabled by bootloader/fuses */
68 MCUSR &= ~(1 << WDRF);
69 wdt_disable();
70
71 /* Disable clock division */
72 clock_prescale_set(clock_div_1);
73
74 /* Hardware Initialization */
75 SerialStream_Init(9600, false);
76 LEDs_Init();
77 USB_Init();
78 }
79
80 void EVENT_USB_DeviceAttached(void)
81 {
82 puts_P(PSTR("Device Attached.\r\n"));
83
84 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
85 }
86
87 void EVENT_USB_DeviceUnattached(void)
88 {
89 puts_P(PSTR("\r\nDevice Unattached.\r\n"));
90
91 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
92 }
93
94 void EVENT_USB_DeviceEnumerationComplete(void)
95 {
96 LEDs_SetAllLEDs(LEDMASK_USB_READY);
97 }
98
99 void EVENT_USB_HostError(uint8_t ErrorCode)
100 {
101 USB_ShutDown();
102
103 puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));
104 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
105
106 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
107 for(;;);
108 }
109
110 void EVENT_USB_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)
111 {
112 puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));
113 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
114 printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);
115
116 LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
117 }
118
119 void Bluetooth_Management_Task(void)
120 {
121 uint8_t ErrorCode;
122
123 switch (USB_HostState)
124 {
125 case HOST_STATE_Addressed:
126 puts_P(PSTR("Getting Device Data.\r\n"));
127
128 /* Get and process the configuration descriptor data */
129 if ((ErrorCode = ProcessDeviceDescriptor()) != SuccessfulDeviceRead)
130 {
131 if (ErrorCode == ControlErrorDuringDeviceRead)
132 puts_P(PSTR("Control Error (Get Device).\r\n"));
133 else
134 puts_P(PSTR("Invalid Device.\r\n"));
135
136 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
137
138 /* Indicate error via status LEDs */
139 LEDs_SetAllLEDs(LEDS_LED1);
140
141 /* Wait until USB device disconnected */
142 while (USB_IsConnected);
143 break;
144 }
145
146 puts_P(PSTR("Bluetooth Dongle Detected.\r\n"));
147
148 /* Standard request to set the device configuration to configuration 1 */
149 USB_ControlRequest = (USB_Request_Header_t)
150 {
151 bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
152 bRequest: REQ_SetConfiguration,
153 wValue: 1,
154 wIndex: 0,
155 wLength: 0,
156 };
157
158 /* Select the control pipe for the request transfer */
159 Pipe_SelectPipe(PIPE_CONTROLPIPE);
160
161 /* Send the request, display error and wait for device detatch if request fails */
162 if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
163 {
164 puts_P(PSTR("Control Error (Set Configuration).\r\n"));
165 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
166
167 /* Indicate error via status LEDs */
168 LEDs_SetAllLEDs(LEDS_LED1);
169
170 /* Wait until USB device disconnected */
171 while (USB_IsConnected);
172 break;
173 }
174
175 USB_HostState = HOST_STATE_Configured;
176 break;
177 case HOST_STATE_Configured:
178 puts_P(PSTR("Getting Config Data.\r\n"));
179
180 /* Get and process the configuration descriptor data */
181 if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
182 {
183 if (ErrorCode == ControlErrorDuringConfigRead)
184 puts_P(PSTR("Control Error (Get Configuration).\r\n"));
185 else
186 puts_P(PSTR("Invalid Device.\r\n"));
187
188 printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
189
190 /* Indicate error via status LEDs */
191 LEDs_SetAllLEDs(LEDS_LED1);
192
193 /* Wait until USB device disconnected */
194 while (USB_IsConnected);
195 break;
196 }
197
198 puts_P(PSTR("Bluetooth Dongle Enumerated.\r\n"));
199
200 USB_HostState = HOST_STATE_Ready;
201 break;
202 case HOST_STATE_Ready:
203 /* Do nothing, Bluetooth stack will take care of enumeration */
204
205 break;
206 }
207 }