diff --git a/_b_t_d_8cpp.html b/_b_t_d_8cpp.html index 68d9657d..965274a3 100644 --- a/_b_t_d_8cpp.html +++ b/_b_t_d_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTD.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for BTD.cpp: diff --git a/_b_t_d_8cpp_source.html b/_b_t_d_8cpp_source.html index b83d281a..85833835 100644 --- a/_b_t_d_8cpp_source.html +++ b/_b_t_d_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTD.cpp Source File @@ -31,7 +31,7 @@ - + @@ -127,1366 +127,1377 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
36 pollInterval(0),
37 bPollEnable(false) // Don't start polling before dongle is connected
38 {
-
39  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
39  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
40  btService[i] = NULL;
41 
-
42  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
+
42  Initialize(); // Set all variables, endpoint structs etc. to default values
43 
-
44  if (pUsb) // Register in USB subsystem
+
44  if(pUsb) // Register in USB subsystem
45  pUsb->RegisterDeviceClass(this); // Set devConfig[] entry
46 }
47 
48 uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
49  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
50  uint8_t buf[constBufSize];
-
51  uint8_t rcode;
-
52  UsbDevice *p = NULL;
-
53  EpInfo *oldep_ptr = NULL;
-
54 
-
55  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
-
56 
-
57  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
-
58 #ifdef EXTRADEBUG
-
59  Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80);
-
60 #endif
-
61 
-
62  if (bAddress) { // Check if address has already been assigned to an instance
-
63 #ifdef DEBUG_USB_HOST
-
64  Notify(PSTR("\r\nAddress in use"), 0x80);
-
65 #endif
-
66  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
67  }
-
68 
-
69  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
-
70  if (!p) {
-
71 #ifdef DEBUG_USB_HOST
-
72  Notify(PSTR("\r\nAddress not found"), 0x80);
-
73 #endif
-
74  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
75  }
-
76 
-
77  if (!p->epinfo) {
-
78 #ifdef DEBUG_USB_HOST
-
79  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
80 #endif
-
81  return USB_ERROR_EPINFO_IS_NULL;
-
82  }
-
83 
-
84  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
-
85  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
86  p->lowspeed = lowspeed;
-
87  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
88 
-
89  p->epinfo = oldep_ptr; // Restore p->epinfo
-
90 
-
91  if (rcode)
-
92  goto FailGetDevDescr;
-
93 
-
94  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
-
95 
-
96  if (!bAddress) {
-
97 #ifdef DEBUG_USB_HOST
-
98  Notify(PSTR("\r\nOut of address space"), 0x80);
-
99 #endif
-
100  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
101  }
-
102 
-
103  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
-
104  epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
-
105 
-
106  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
107  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
108 
-
109  return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
-
110 
-
111 FailGetDevDescr:
-
112 #ifdef DEBUG_USB_HOST
-
113  NotifyFailGetDevDescr(rcode);
-
114 #endif
-
115  if (rcode != hrJERR)
-
116  rcode = USB_ERROR_FailGetDevDescr;
-
117  Release();
-
118  return rcode;
-
119 };
-
120 
-
121 uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
-
122  uint8_t rcode;
-
123  uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
-
124  epInfo[1].epAddr = 0;
-
125 
-
126  AddressPool &addrPool = pUsb->GetAddressPool();
-
127 #ifdef EXTRADEBUG
-
128  Notify(PSTR("\r\nBTD Init"), 0x80);
-
129 #endif
-
130  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
131 
-
132  if (!p) {
-
133 #ifdef DEBUG_USB_HOST
-
134  Notify(PSTR("\r\nAddress not found"), 0x80);
-
135 #endif
-
136  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
137  }
-
138 
-
139  delay(300); // Assign new address to the device
-
140 
-
141  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
-
142  if (rcode) {
-
143 #ifdef DEBUG_USB_HOST
-
144  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
145  D_PrintHex<uint8_t > (rcode, 0x80);
-
146 #endif
-
147  p->lowspeed = false;
-
148  goto Fail;
-
149  }
-
150 #ifdef EXTRADEBUG
-
151  Notify(PSTR("\r\nAddr: "), 0x80);
-
152  D_PrintHex<uint8_t > (bAddress, 0x80);
-
153 #endif
-
154 
-
155  p->lowspeed = false;
-
156 
-
157  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
158  if (!p) {
-
159 #ifdef DEBUG_USB_HOST
-
160  Notify(PSTR("\r\nAddress not found"), 0x80);
-
161 #endif
-
162  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
163  }
-
164 
-
165  p->lowspeed = lowspeed;
-
166 
-
167  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
-
168  if (rcode)
-
169  goto FailSetDevTblEntry;
-
170 
-
171  if (VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
-
172  delay(100);
-
173  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device
-
174  if (rcode)
-
175  goto FailSetConfDescr;
-
176 
-
177 #ifdef DEBUG_USB_HOST
-
178  if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
-
179  if (PID == PS3_PID)
-
180  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
-
181  else // It must be a navigation controller
-
182  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
-
183  } else // It must be a Motion controller
-
184  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
-
185 #endif
-
186 
-
187  if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
-
188 #ifdef DEBUG_USB_HOST
-
189  Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\r\nor set the Bluetooth address in the constructor of the PS3BT class"), 0x80);
-
190 #endif
-
191  } else {
-
192  if (PID == PS3_PID || PID == PS3NAVIGATION_PID)
-
193  setBdaddr(my_bdaddr); // Set internal Bluetooth address
-
194  else
-
195  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
-
196 #ifdef DEBUG_USB_HOST
-
197  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
-
198  for (int8_t i = 5; i > 0; i--) {
-
199  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
-
200  Notify(PSTR(":"), 0x80);
-
201  }
-
202  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
-
203 #endif
-
204  }
-
205 
-
206  pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 0); // Reset configuration value
-
207  pUsb->setAddr(bAddress, 0, 0); // Reset address
-
208  Release(); // Release device
-
209  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return
-
210  } else {
-
211  // Check if attached device is a Bluetooth dongle and fill endpoint data structure
-
212  // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol
-
213  // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order
-
214  for (uint8_t i = 0; i < num_of_conf; i++) {
-
215  if (VID == IOGEAR_GBU521_VID && PID == IOGEAR_GBU521_PID) {
-
216  ConfigDescParser<USB_CLASS_VENDOR_SPECIFIC, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Needed for the IOGEAR GBU521
-
217  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
218  } else {
-
219  ConfigDescParser<USB_CLASS_WIRELESS_CTRL, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this);
-
220  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
221  }
-
222  if (rcode) // Check error code
-
223  goto FailGetConfDescr;
-
224  if (bNumEP >= BTD_MAX_ENDPOINTS) // All endpoints extracted
-
225  break;
-
226  }
-
227 
-
228  if (bNumEP < BTD_MAX_ENDPOINTS)
-
229  goto FailUnknownDevice;
-
230 
-
231  // Assign epInfo to epinfo pointer - this time all 3 endpoins
-
232  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
-
233  if (rcode)
-
234  goto FailSetDevTblEntry;
-
235 
-
236  // Set Configuration Value
-
237  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
-
238  if (rcode)
-
239  goto FailSetConfDescr;
-
240 
-
241  hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
-
242  hci_counter = 0;
-
243  hci_state = HCI_INIT_STATE;
-
244  watingForConnection = false;
-
245  bPollEnable = true;
-
246 
-
247 #ifdef DEBUG_USB_HOST
-
248  Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
-
249 #endif
-
250  }
-
251  return 0; // Successful configuration
-
252 
-
253  /* diagnostic messages */
-
254 FailGetDevDescr:
-
255 #ifdef DEBUG_USB_HOST
-
256  NotifyFailGetDevDescr();
-
257  goto Fail;
-
258 #endif
-
259 
-
260 FailSetDevTblEntry:
-
261 #ifdef DEBUG_USB_HOST
-
262  NotifyFailSetDevTblEntry();
-
263  goto Fail;
-
264 #endif
-
265 
-
266 FailGetConfDescr:
-
267 #ifdef DEBUG_USB_HOST
-
268  NotifyFailGetConfDescr();
-
269  goto Fail;
+
51  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
52  uint8_t rcode;
+
53  UsbDevice *p = NULL;
+
54  EpInfo *oldep_ptr = NULL;
+
55 
+
56  Initialize(); // Set all variables, endpoint structs etc. to default values
+
57 
+
58  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
+
59 #ifdef EXTRADEBUG
+
60  Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80);
+
61 #endif
+
62 
+
63  if(bAddress) { // Check if address has already been assigned to an instance
+
64 #ifdef DEBUG_USB_HOST
+
65  Notify(PSTR("\r\nAddress in use"), 0x80);
+
66 #endif
+
67  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
68  }
+
69 
+
70  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
+
71  if(!p) {
+
72 #ifdef DEBUG_USB_HOST
+
73  Notify(PSTR("\r\nAddress not found"), 0x80);
+
74 #endif
+
75  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
76  }
+
77 
+
78  if(!p->epinfo) {
+
79 #ifdef DEBUG_USB_HOST
+
80  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
81 #endif
+
82  return USB_ERROR_EPINFO_IS_NULL;
+
83  }
+
84 
+
85  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
+
86  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
87  p->lowspeed = lowspeed;
+
88  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
+
89 
+
90  p->epinfo = oldep_ptr; // Restore p->epinfo
+
91 
+
92  if(rcode)
+
93  goto FailGetDevDescr;
+
94 
+
95  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
+
96 
+
97  if(!bAddress) {
+
98 #ifdef DEBUG_USB_HOST
+
99  Notify(PSTR("\r\nOut of address space"), 0x80);
+
100 #endif
+
101  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
102  }
+
103 
+
104  epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
+
105  epInfo[1].epAddr = udd->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
+
106 
+
107  VID = udd->idVendor;
+
108  PID = udd->idProduct;
+
109 
+
110  return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
+
111 
+
112 FailGetDevDescr:
+
113 #ifdef DEBUG_USB_HOST
+
114  NotifyFailGetDevDescr(rcode);
+
115 #endif
+
116  if(rcode != hrJERR)
+
117  rcode = USB_ERROR_FailGetDevDescr;
+
118  Release();
+
119  return rcode;
+
120 };
+
121 
+
122 uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
+
123  uint8_t rcode;
+
124  uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
+
125  epInfo[1].epAddr = 0;
+
126 
+
127  AddressPool &addrPool = pUsb->GetAddressPool();
+
128 #ifdef EXTRADEBUG
+
129  Notify(PSTR("\r\nBTD Init"), 0x80);
+
130 #endif
+
131  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
132 
+
133  if(!p) {
+
134 #ifdef DEBUG_USB_HOST
+
135  Notify(PSTR("\r\nAddress not found"), 0x80);
+
136 #endif
+
137  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
138  }
+
139 
+
140  delay(300); // Assign new address to the device
+
141 
+
142  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
+
143  if(rcode) {
+
144 #ifdef DEBUG_USB_HOST
+
145  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
146  D_PrintHex<uint8_t > (rcode, 0x80);
+
147 #endif
+
148  p->lowspeed = false;
+
149  goto Fail;
+
150  }
+
151 #ifdef EXTRADEBUG
+
152  Notify(PSTR("\r\nAddr: "), 0x80);
+
153  D_PrintHex<uint8_t > (bAddress, 0x80);
+
154 #endif
+
155 
+
156  p->lowspeed = false;
+
157 
+
158  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
159  if(!p) {
+
160 #ifdef DEBUG_USB_HOST
+
161  Notify(PSTR("\r\nAddress not found"), 0x80);
+
162 #endif
+
163  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
164  }
+
165 
+
166  p->lowspeed = lowspeed;
+
167 
+
168  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
+
169  if(rcode)
+
170  goto FailSetDevTblEntry;
+
171 
+
172  if(VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
+
173  delay(100);
+
174  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device
+
175  if(rcode)
+
176  goto FailSetConfDescr;
+
177 
+
178 #ifdef DEBUG_USB_HOST
+
179  if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
+
180  if(PID == PS3_PID)
+
181  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
+
182  else // It must be a navigation controller
+
183  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
+
184  } else // It must be a Motion controller
+
185  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
+
186 #endif
+
187 
+
188  if(my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
+
189 #ifdef DEBUG_USB_HOST
+
190  Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\r\nor set the Bluetooth address in the constructor of the PS3BT class"), 0x80);
+
191 #endif
+
192  } else {
+
193  if(PID == PS3_PID || PID == PS3NAVIGATION_PID)
+
194  setBdaddr(my_bdaddr); // Set internal Bluetooth address
+
195  else
+
196  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
+
197 #ifdef DEBUG_USB_HOST
+
198  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
+
199  for(int8_t i = 5; i > 0; i--) {
+
200  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
+
201  Notify(PSTR(":"), 0x80);
+
202  }
+
203  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
+
204 #endif
+
205  }
+
206 
+
207  pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 0); // Reset configuration value
+
208  pUsb->setAddr(bAddress, 0, 0); // Reset address
+
209  Release(); // Release device
+
210  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return
+
211  } else {
+
212  // Check if attached device is a Bluetooth dongle and fill endpoint data structure
+
213  // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol
+
214  // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order
+
215  for(uint8_t i = 0; i < num_of_conf; i++) {
+
216  if(VID == IOGEAR_GBU521_VID && PID == IOGEAR_GBU521_PID) {
+
217  ConfigDescParser<USB_CLASS_VENDOR_SPECIFIC, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Needed for the IOGEAR GBU521
+
218  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
219  } else {
+
220  ConfigDescParser<USB_CLASS_WIRELESS_CTRL, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this);
+
221  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
222  }
+
223  if(rcode) // Check error code
+
224  goto FailGetConfDescr;
+
225  if(bNumEP >= BTD_MAX_ENDPOINTS) // All endpoints extracted
+
226  break;
+
227  }
+
228 
+
229  if(bNumEP < BTD_MAX_ENDPOINTS)
+
230  goto FailUnknownDevice;
+
231 
+
232  // Assign epInfo to epinfo pointer - this time all 3 endpoins
+
233  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
+
234  if(rcode)
+
235  goto FailSetDevTblEntry;
+
236 
+
237  // Set Configuration Value
+
238  rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
+
239  if(rcode)
+
240  goto FailSetConfDescr;
+
241 
+
242  hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
+
243  hci_counter = 0;
+
244  hci_state = HCI_INIT_STATE;
+
245  watingForConnection = false;
+
246  bPollEnable = true;
+
247 
+
248 #ifdef DEBUG_USB_HOST
+
249  Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
+
250 #endif
+
251  }
+
252  return 0; // Successful configuration
+
253 
+
254  /* Diagnostic messages */
+
255 FailSetDevTblEntry:
+
256 #ifdef DEBUG_USB_HOST
+
257  NotifyFailSetDevTblEntry();
+
258  goto Fail;
+
259 #endif
+
260 
+
261 FailGetConfDescr:
+
262 #ifdef DEBUG_USB_HOST
+
263  NotifyFailGetConfDescr();
+
264  goto Fail;
+
265 #endif
+
266 
+
267 FailSetConfDescr:
+
268 #ifdef DEBUG_USB_HOST
+
269  NotifyFailSetConfDescr();
270 #endif
-
271 
-
272 FailSetConfDescr:
-
273 #ifdef DEBUG_USB_HOST
-
274  NotifyFailSetConfDescr();
-
275 #endif
-
276  goto Fail;
-
277 
-
278 FailUnknownDevice:
-
279 #ifdef DEBUG_USB_HOST
-
280  NotifyFailUnknownDevice(VID, PID);
-
281 #endif
-
282  pUsb->setAddr(bAddress, 0, 0); // Reset address
-
283  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
284 Fail:
-
285 #ifdef DEBUG_USB_HOST
-
286  Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
-
287  NotifyFail(rcode);
-
288 #endif
-
289  Release();
-
290  return rcode;
-
291 }
-
292 
-
293 void BTD::clearAllVariables() {
-
294  uint8_t i;
-
295  for (i = 0; i < BTD_MAX_ENDPOINTS; i++) {
-
296  epInfo[i].epAddr = 0;
-
297  epInfo[i].maxPktSize = (i) ? 0 : 8;
-
298  epInfo[i].epAttribs = 0;
-
299  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
-
300  }
-
301  for (i = 0; i < BTD_NUMSERVICES; i++) {
-
302  if (btService[i])
-
303  btService[i]->Reset(); // Reset all Bluetooth services
-
304  }
-
305 
-
306  connectToWii = false;
-
307  incomingWii = false;
-
308  connectToHIDDevice = false;
-
309  incomingHIDDevice = false;
-
310  bAddress = 0; // Clear device address
-
311  bNumEP = 1; // Must have to be reset to 1
-
312  qNextPollTime = 0; // Reset next poll time
-
313  pollInterval = 0;
-
314  bPollEnable = false; // Don't start polling before dongle is connected
-
315 }
-
316 
-
317 /* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */
-
318 void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
-
319  //ErrorMessage<uint8_t>(PSTR("Conf.Val"),conf);
-
320  //ErrorMessage<uint8_t>(PSTR("Iface Num"),iface);
-
321  //ErrorMessage<uint8_t>(PSTR("Alt.Set"),alt);
-
322 
-
323  if (alt) // Wrong interface - by BT spec, no alt setting
-
324  return;
-
325 
-
326  bConfNum = conf;
-
327  uint8_t index;
-
328 
-
329  if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
-
330  index = BTD_EVENT_PIPE;
-
331  epInfo[index].bmNakPower = USB_NAK_NOWAIT;
-
332  } else {
-
333  if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found
-
334  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
-
335  else
-
336  return;
-
337  }
-
338 
-
339  // Fill the rest of endpoint data structure
-
340  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
-
341  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
-
342 #ifdef EXTRADEBUG
-
343  PrintEndpointDescriptor(pep);
-
344 #endif
-
345  if (pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
-
346  pollInterval = pep->bInterval;
-
347  bNumEP++;
-
348 }
-
349 
-
350 void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
-
351 #ifdef EXTRADEBUG
-
352  Notify(PSTR("\r\nEndpoint descriptor:"), 0x80);
-
353  Notify(PSTR("\r\nLength:\t\t"), 0x80);
-
354  D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
-
355  Notify(PSTR("\r\nType:\t\t"), 0x80);
-
356  D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
-
357  Notify(PSTR("\r\nAddress:\t"), 0x80);
-
358  D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
-
359  Notify(PSTR("\r\nAttributes:\t"), 0x80);
-
360  D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
-
361  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
-
362  D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
-
363  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
-
364  D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
-
365 #endif
-
366 }
-
367 
-
368 /* Performs a cleanup after failed Init() attempt */
-
369 uint8_t BTD::Release() {
-
370  clearAllVariables(); // Set all variables, endpoint structs etc. to default values
-
371  pUsb->GetAddressPool().FreeAddress(bAddress);
-
372  return 0;
-
373 }
-
374 
-
375 uint8_t BTD::Poll() {
-
376  if (!bPollEnable)
-
377  return 0;
-
378  if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
-
379  qNextPollTime = millis() + pollInterval; // Set new poll time
-
380  HCI_event_task(); // poll the HCI event pipe
-
381  ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected
-
382  }
-
383  return 0;
-
384 }
-
385 
-
386 void BTD::HCI_event_task() {
-
387  /* check the event pipe*/
-
388  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
-
389  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &MAX_BUFFER_SIZE, hcibuf); // input on endpoint 1
-
390  if (!rcode || rcode == hrNAK) // Check for errors
-
391  {
-
392  switch (hcibuf[0]) //switch on event type
-
393  {
-
394  case EV_COMMAND_COMPLETE:
-
395  if (!hcibuf[5]) { // Check if command succeeded
-
396  hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
-
397  if ((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // parameters from read local version information
-
398  hci_version = hcibuf[6]; // Used to check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
-
399  hci_event_flag |= HCI_FLAG_READ_VERSION;
-
400  } else if ((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address
-
401  for (uint8_t i = 0; i < 6; i++)
-
402  my_bdaddr[i] = hcibuf[6 + i];
-
403  hci_event_flag |= HCI_FLAG_READ_BDADDR;
-
404  }
-
405  }
-
406  break;
-
407 
-
408  case EV_COMMAND_STATUS:
-
409  if (hcibuf[2]) { // Show status on serial if not OK
-
410 #ifdef DEBUG_USB_HOST
-
411  Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
-
412  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
-
413 #endif
-
414  }
-
415  break;
-
416 
-
417  case EV_INQUIRY_COMPLETE:
-
418  if (inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
-
419  inquiry_counter = 0;
-
420 #ifdef DEBUG_USB_HOST
-
421  if (pairWithWii)
-
422  Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
-
423  else
-
424  Notify(PSTR("\r\nCouldn't find HID device"), 0x80);
-
425 #endif
-
426  connectToWii = false;
-
427  pairWithWii = false;
-
428  connectToHIDDevice = false;
-
429  pairWithHIDDevice = false;
-
430  hci_state = HCI_SCANNING_STATE;
-
431  }
-
432  inquiry_counter++;
-
433  break;
-
434 
-
435  case EV_INQUIRY_RESULT:
-
436  if (hcibuf[2]) { // Check that there is more than zero responses
-
437 #ifdef EXTRADEBUG
-
438  Notify(PSTR("\r\nNumber of responses: "), 0x80);
-
439  Notify(hcibuf[2], 0x80);
-
440 #endif
-
441  for (uint8_t i = 0; i < hcibuf[2]; i++) {
-
442  uint8_t offset = 8 * hcibuf[2] + 3 * i;
-
443  uint8_t classOfDevice[3];
-
444 
-
445  for (uint8_t j = 0; j < 3; j++)
-
446  classOfDevice[j] = hcibuf[j + 4 + offset];
+
271  goto Fail;
+
272 
+
273 FailUnknownDevice:
+
274 #ifdef DEBUG_USB_HOST
+
275  NotifyFailUnknownDevice(VID, PID);
+
276 #endif
+
277  pUsb->setAddr(bAddress, 0, 0); // Reset address
+
278  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
279 Fail:
+
280 #ifdef DEBUG_USB_HOST
+
281  Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
+
282  NotifyFail(rcode);
+
283 #endif
+
284  Release();
+
285  return rcode;
+
286 }
+
287 
+
288 void BTD::Initialize() {
+
289  uint8_t i;
+
290  for(i = 0; i < BTD_MAX_ENDPOINTS; i++) {
+
291  epInfo[i].epAddr = 0;
+
292  epInfo[i].maxPktSize = (i) ? 0 : 8;
+
293  epInfo[i].epAttribs = 0;
+
294  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
+
295  }
+
296  for(i = 0; i < BTD_NUMSERVICES; i++) {
+
297  if(btService[i])
+
298  btService[i]->Reset(); // Reset all Bluetooth services
+
299  }
+
300 
+
301  connectToWii = false;
+
302  incomingWii = false;
+
303  connectToHIDDevice = false;
+
304  incomingHIDDevice = false;
+
305  incomingPS4 = false;
+
306  bAddress = 0; // Clear device address
+
307  bNumEP = 1; // Must have to be reset to 1
+
308  qNextPollTime = 0; // Reset next poll time
+
309  pollInterval = 0;
+
310  bPollEnable = false; // Don't start polling before dongle is connected
+
311 }
+
312 
+
313 /* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */
+
314 void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
+
315  //ErrorMessage<uint8_t>(PSTR("Conf.Val"),conf);
+
316  //ErrorMessage<uint8_t>(PSTR("Iface Num"),iface);
+
317  //ErrorMessage<uint8_t>(PSTR("Alt.Set"),alt);
+
318 
+
319  if(alt) // Wrong interface - by BT spec, no alt setting
+
320  return;
+
321 
+
322  bConfNum = conf;
+
323  uint8_t index;
+
324 
+
325  if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
+
326  index = BTD_EVENT_PIPE;
+
327  epInfo[index].bmNakPower = USB_NAK_NOWAIT;
+
328  } else {
+
329  if((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found
+
330  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
+
331  else
+
332  return;
+
333  }
+
334 
+
335  // Fill the rest of endpoint data structure
+
336  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+
337  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+
338 #ifdef EXTRADEBUG
+
339  PrintEndpointDescriptor(pep);
+
340 #endif
+
341  if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
+
342  pollInterval = pep->bInterval;
+
343  bNumEP++;
+
344 }
+
345 
+
346 void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
+
347 #ifdef EXTRADEBUG
+
348  Notify(PSTR("\r\nEndpoint descriptor:"), 0x80);
+
349  Notify(PSTR("\r\nLength:\t\t"), 0x80);
+
350  D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
+
351  Notify(PSTR("\r\nType:\t\t"), 0x80);
+
352  D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
+
353  Notify(PSTR("\r\nAddress:\t"), 0x80);
+
354  D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
+
355  Notify(PSTR("\r\nAttributes:\t"), 0x80);
+
356  D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
+
357  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
+
358  D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
+
359  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
+
360  D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
+
361 #endif
+
362 }
+
363 
+
364 /* Performs a cleanup after failed Init() attempt */
+
365 uint8_t BTD::Release() {
+
366  Initialize(); // Set all variables, endpoint structs etc. to default values
+
367  pUsb->GetAddressPool().FreeAddress(bAddress);
+
368  return 0;
+
369 }
+
370 
+
371 uint8_t BTD::Poll() {
+
372  if(!bPollEnable)
+
373  return 0;
+
374  if(qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
+
375  qNextPollTime = millis() + pollInterval; // Set new poll time
+
376  HCI_event_task(); // Poll the HCI event pipe
+
377  HCI_task(); // HCI state machine
+
378  ACL_event_task(); // Poll the ACL input pipe too
+
379  }
+
380  return 0;
+
381 }
+
382 
+
383 void BTD::HCI_event_task() {
+
384  uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
+
385  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf); // Input on endpoint 1
+
386 
+
387  if(!rcode || rcode == hrNAK) { // Check for errors
+
388  switch(hcibuf[0]) { // Switch on event type
+
389  case EV_COMMAND_COMPLETE:
+
390  if(!hcibuf[5]) { // Check if command succeeded
+
391  hci_set_flag(HCI_FLAG_CMD_COMPLETE); // Set command complete flag
+
392  if((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // Parameters from read local version information
+
393  hci_version = hcibuf[6]; // Used to check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
+
394  hci_set_flag(HCI_FLAG_READ_VERSION);
+
395  } else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // Parameters from read local bluetooth address
+
396  for(uint8_t i = 0; i < 6; i++)
+
397  my_bdaddr[i] = hcibuf[6 + i];
+
398  hci_set_flag(HCI_FLAG_READ_BDADDR);
+
399  }
+
400  }
+
401  break;
+
402 
+
403  case EV_COMMAND_STATUS:
+
404  if(hcibuf[2]) { // Show status on serial if not OK
+
405 #ifdef DEBUG_USB_HOST
+
406  Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
+
407  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
+
408 #endif
+
409  }
+
410  break;
+
411 
+
412  case EV_INQUIRY_COMPLETE:
+
413  if(inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
+
414  inquiry_counter = 0;
+
415 #ifdef DEBUG_USB_HOST
+
416  if(pairWithWii)
+
417  Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
+
418  else
+
419  Notify(PSTR("\r\nCouldn't find HID device"), 0x80);
+
420 #endif
+
421  connectToWii = false;
+
422  pairWithWii = false;
+
423  connectToHIDDevice = false;
+
424  pairWithHIDDevice = false;
+
425  hci_state = HCI_SCANNING_STATE;
+
426  }
+
427  inquiry_counter++;
+
428  break;
+
429 
+
430  case EV_INQUIRY_RESULT:
+
431  if(hcibuf[2]) { // Check that there is more than zero responses
+
432 #ifdef EXTRADEBUG
+
433  Notify(PSTR("\r\nNumber of responses: "), 0x80);
+
434  Notify(hcibuf[2], 0x80);
+
435 #endif
+
436  for(uint8_t i = 0; i < hcibuf[2]; i++) {
+
437  uint8_t offset = 8 * hcibuf[2] + 3 * i;
+
438 
+
439  for(uint8_t j = 0; j < 3; j++)
+
440  classOfDevice[j] = hcibuf[j + 4 + offset];
+
441 
+
442  if(pairWithWii && classOfDevice[2] == 0x00 && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0x0C)) { // See http://wiibrew.org/wiki/Wiimote#SDP_information
+
443  if(classOfDevice[0] & 0x08) // Check if it's the new Wiimote with motion plus inside that was detected
+
444  motionPlusInside = true;
+
445  else
+
446  motionPlusInside = false;
447 
-
448  if (pairWithWii && classOfDevice[2] == 0x00 && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0x0C)) { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html and http://wiibrew.org/wiki/Wiimote#SDP_information
-
449  if (classOfDevice[0] & 0x08) // Check if it's the new Wiimote with motion plus inside that was detected
-
450  motionPlusInside = true;
-
451  else
-
452  motionPlusInside = false;
-
453 
-
454  for (uint8_t j = 0; j < 6; j++)
-
455  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
-
456 
-
457  hci_event_flag |= HCI_FLAG_DEVICE_FOUND;
-
458  break;
-
459  } else if (pairWithHIDDevice && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC0)) { // Check if it is a mouse or keyboard
-
460 #ifdef DEBUG_USB_HOST
-
461  if (classOfDevice[0] & 0x80)
-
462  Notify(PSTR("\r\nMouse found"), 0x80);
-
463  if (classOfDevice[0] & 0x40)
-
464  Notify(PSTR("\r\nKeyboard found"), 0x80);
-
465 #endif
-
466 
-
467  for (uint8_t j = 0; j < 6; j++)
-
468  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
-
469 
-
470  hci_event_flag |= HCI_FLAG_DEVICE_FOUND;
-
471  }
-
472 #ifdef EXTRADEBUG
-
473  else {
-
474  Notify(PSTR("\r\nClass of device: "), 0x80);
-
475  D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
-
476  Notify(PSTR(" "), 0x80);
-
477  D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
-
478  Notify(PSTR(" "), 0x80);
-
479  D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
-
480  }
-
481 #endif
-
482  }
-
483  }
-
484  break;
-
485 
-
486  case EV_CONNECT_COMPLETE:
-
487  hci_event_flag |= HCI_FLAG_CONNECT_EVENT;
-
488  if (!hcibuf[2]) { // check if connected OK
-
489 #ifdef EXTRADEBUG
-
490  Notify(PSTR("\r\nConnection established"), 0x80);
-
491 #endif
-
492  hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // store the handle for the ACL connection
-
493  hci_event_flag |= HCI_FLAG_CONN_COMPLETE; // set connection complete flag
-
494  } else {
-
495  hci_state = HCI_CHECK_DEVICE_SERVICE;
-
496 #ifdef DEBUG_USB_HOST
-
497  Notify(PSTR("\r\nConnection Failed: "), 0x80);
-
498  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
-
499 #endif
-
500  }
-
501  break;
-
502 
-
503  case EV_DISCONNECT_COMPLETE:
-
504  if (!hcibuf[2]) { // check if disconnected OK
-
505  hci_event_flag |= HCI_FLAG_DISCONN_COMPLETE; // set disconnect command complete flag
-
506  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE; // clear connection complete flag
-
507  }
-
508  break;
-
509 
-
510  case EV_REMOTE_NAME_COMPLETE:
-
511  if (!hcibuf[2]) { // check if reading is OK
-
512  for (uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++)
-
513  remote_name[i] = hcibuf[9 + i];
-
514  hci_event_flag |= HCI_FLAG_REMOTE_NAME_COMPLETE;
-
515  }
-
516  break;
-
517 
-
518  case EV_INCOMING_CONNECT:
-
519  for (uint8_t i = 0; i < 6; i++)
-
520  disc_bdaddr[i] = hcibuf[i + 2];
-
521 
-
522  if ((hcibuf[9] & 0x05) && (hcibuf[8] & 0xC0)) { // Check if it is a mouse or keyboard
-
523 #ifdef DEBUG_USB_HOST
-
524  if (hcibuf[8] & 0x80)
-
525  Notify(PSTR("\r\nMouse is connecting"), 0x80);
-
526  if (hcibuf[8] & 0x40)
-
527  Notify(PSTR("\r\nKeyboard is connecting"), 0x80);
-
528 #endif
-
529  incomingHIDDevice = true;
-
530  }
-
531 
-
532 #ifdef EXTRADEBUG
-
533  Notify(PSTR("\r\nClass of device: "), 0x80);
-
534  D_PrintHex<uint8_t > (hcibuf[10], 0x80);
-
535  Notify(PSTR(" "), 0x80);
-
536  D_PrintHex<uint8_t > (hcibuf[9], 0x80);
-
537  Notify(PSTR(" "), 0x80);
-
538  D_PrintHex<uint8_t > (hcibuf[8], 0x80);
-
539 #endif
-
540  hci_event_flag |= HCI_FLAG_INCOMING_REQUEST;
-
541  break;
-
542 
-
543  case EV_PIN_CODE_REQUEST:
-
544  if (pairWithWii) {
-
545 #ifdef DEBUG_USB_HOST
-
546  Notify(PSTR("\r\nPairing with wiimote"), 0x80);
-
547 #endif
-
548  hci_pin_code_request_reply();
-
549  } else if (btdPin != NULL) {
-
550 #ifdef DEBUG_USB_HOST
-
551  Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
-
552  NotifyStr(btdPin, 0x80);
-
553 #endif
-
554  hci_pin_code_request_reply();
-
555  } else {
-
556 #ifdef DEBUG_USB_HOST
-
557  Notify(PSTR("\r\nNo pin was set"), 0x80);
-
558 #endif
-
559  hci_pin_code_negative_request_reply();
-
560  }
-
561  break;
-
562 
-
563  case EV_LINK_KEY_REQUEST:
-
564 #ifdef DEBUG_USB_HOST
-
565  Notify(PSTR("\r\nReceived Key Request"), 0x80);
-
566 #endif
-
567  hci_link_key_request_negative_reply();
-
568  break;
-
569 
-
570  case EV_AUTHENTICATION_COMPLETE:
-
571  if (pairWithWii && !connectToWii) {
-
572 #ifdef DEBUG_USB_HOST
-
573  Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80);
-
574 #endif
-
575  connectToWii = true; // Only send the ACL data to the Wii service
-
576  } else if (pairWithHIDDevice && !connectToHIDDevice) {
-
577 #ifdef DEBUG_USB_HOST
-
578  Notify(PSTR("\r\nPairing successful with HID device"), 0x80);
-
579 #endif
-
580  connectToHIDDevice = true; // Only send the ACL data to the Wii service
-
581  }
-
582  break;
-
583  /* We will just ignore the following events */
-
584  case EV_NUM_COMPLETE_PKT:
-
585  case EV_ROLE_CHANGED:
-
586  case EV_PAGE_SCAN_REP_MODE:
-
587  case EV_LOOPBACK_COMMAND:
-
588  case EV_DATA_BUFFER_OVERFLOW:
-
589  case EV_CHANGE_CONNECTION_LINK:
-
590  case EV_MAX_SLOTS_CHANGE:
-
591  case EV_QOS_SETUP_COMPLETE:
-
592  case EV_LINK_KEY_NOTIFICATION:
-
593  case EV_ENCRYPTION_CHANGE:
-
594  case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
-
595  break;
-
596 #ifdef EXTRADEBUG
-
597  default:
-
598  if (hcibuf[0] != 0x00) {
-
599  Notify(PSTR("\r\nUnmanaged HCI Event: "), 0x80);
-
600  D_PrintHex<uint8_t > (hcibuf[0], 0x80);
-
601  }
-
602  break;
-
603 #endif
-
604  } // switch
-
605  }
-
606 #ifdef EXTRADEBUG
-
607  else {
-
608  Notify(PSTR("\r\nHCI event error: "), 0x80);
-
609  D_PrintHex<uint8_t > (rcode, 0x80);
-
610  }
-
611 #endif
-
612  HCI_task();
-
613 }
-
614 
-
615 /* Poll Bluetooth and print result */
-
616 void BTD::HCI_task() {
-
617  switch (hci_state) {
-
618  case HCI_INIT_STATE:
-
619  hci_counter++;
-
620  if (hci_counter > hci_num_reset_loops) { // wait until we have looped x times to clear any old events
-
621  hci_reset();
-
622  hci_state = HCI_RESET_STATE;
-
623  hci_counter = 0;
-
624  }
-
625  break;
-
626 
-
627  case HCI_RESET_STATE:
-
628  hci_counter++;
-
629  if (hci_cmd_complete) {
-
630  hci_counter = 0;
-
631 #ifdef DEBUG_USB_HOST
-
632  Notify(PSTR("\r\nHCI Reset complete"), 0x80);
-
633 #endif
-
634  hci_state = HCI_CLASS_STATE;
-
635  hci_write_class_of_device();
-
636  } else if (hci_counter > hci_num_reset_loops) {
-
637  hci_num_reset_loops *= 10;
-
638  if (hci_num_reset_loops > 2000)
-
639  hci_num_reset_loops = 2000;
-
640 #ifdef DEBUG_USB_HOST
-
641  Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
-
642 #endif
-
643  hci_state = HCI_INIT_STATE;
-
644  hci_counter = 0;
-
645  }
-
646  break;
-
647 
-
648  case HCI_CLASS_STATE:
-
649  if (hci_cmd_complete) {
-
650 #ifdef DEBUG_USB_HOST
-
651  Notify(PSTR("\r\nWrite class of device"), 0x80);
-
652 #endif
-
653  hci_state = HCI_BDADDR_STATE;
-
654  hci_read_bdaddr();
-
655  }
-
656  break;
-
657 
-
658  case HCI_BDADDR_STATE:
-
659  if (hci_read_bdaddr_complete) {
-
660 #ifdef DEBUG_USB_HOST
-
661  Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
-
662  for (int8_t i = 5; i > 0; i--) {
-
663  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
-
664  Notify(PSTR(":"), 0x80);
-
665  }
-
666  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
-
667 #endif
-
668  hci_read_local_version_information();
-
669  hci_state = HCI_LOCAL_VERSION_STATE;
-
670  }
-
671  break;
-
672 
-
673  case HCI_LOCAL_VERSION_STATE: // The local version is used by the PS3BT class
-
674  if (hci_read_version_complete) {
-
675  if (btdName != NULL) {
-
676  hci_set_local_name(btdName);
-
677  hci_state = HCI_SET_NAME_STATE;
-
678  } else
-
679  hci_state = HCI_CHECK_DEVICE_SERVICE;
-
680  }
-
681  break;
-
682 
-
683  case HCI_SET_NAME_STATE:
-
684  if (hci_cmd_complete) {
-
685 #ifdef DEBUG_USB_HOST
-
686  Notify(PSTR("\r\nThe name is set to: "), 0x80);
-
687  NotifyStr(btdName, 0x80);
-
688 #endif
-
689  hci_state = HCI_CHECK_DEVICE_SERVICE;
-
690  }
-
691  break;
-
692 
-
693  case HCI_CHECK_DEVICE_SERVICE:
-
694  if (pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a wiimote
-
695 #ifdef DEBUG_USB_HOST
-
696  if (pairWithWii)
-
697  Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
-
698  else
-
699  Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80);
-
700 #endif
-
701  hci_inquiry();
-
702  hci_state = HCI_INQUIRY_STATE;
-
703  } else
-
704  hci_state = HCI_SCANNING_STATE; // Don't try to connect to a Wiimote
-
705  break;
-
706 
-
707  case HCI_INQUIRY_STATE:
-
708  if (hci_device_found) {
-
709  hci_inquiry_cancel(); // Stop inquiry
-
710 #ifdef DEBUG_USB_HOST
-
711  if (pairWithWii)
-
712  Notify(PSTR("\r\nWiimote found"), 0x80);
-
713  else
-
714  Notify(PSTR("\r\nHID device found"), 0x80);
-
715 
-
716  Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
-
717  if (pairWithWii)
-
718  Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
-
719  else
-
720  Notify(PSTR("\r\nBTHID hid(&Btd);"), 0x80);
-
721 
-
722  Notify(PSTR("\r\nAnd then press any button on the "), 0x80);
-
723  if (pairWithWii)
-
724  Notify(PSTR("Wiimote"), 0x80);
-
725  else
-
726  Notify(PSTR("device"), 0x80);
-
727 #endif
-
728  if (motionPlusInside) {
-
729  hci_remote_name(); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller
-
730  hci_state = HCI_REMOTE_NAME_STATE;
-
731  } else
-
732  hci_state = HCI_CONNECT_DEVICE_STATE;
-
733  }
-
734  break;
-
735 
-
736  case HCI_CONNECT_DEVICE_STATE:
-
737  if (hci_cmd_complete) {
-
738 #ifdef DEBUG_USB_HOST
-
739  if (pairWithWii)
-
740  Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
-
741  else
-
742  Notify(PSTR("\r\nConnecting to HID device"), 0x80);
-
743 #endif
-
744  hci_connect();
-
745  hci_state = HCI_CONNECTED_DEVICE_STATE;
-
746  }
-
747  break;
-
748 
-
749  case HCI_CONNECTED_DEVICE_STATE:
-
750  if (hci_connect_event) {
-
751  if (hci_connect_complete) {
-
752 #ifdef DEBUG_USB_HOST
-
753  if (pairWithWii)
-
754  Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
-
755  else
-
756  Notify(PSTR("\r\nConnected to HID device"), 0x80);
-
757 #endif
-
758  hci_authentication_request(); // This will start the pairing with the wiimote
-
759  hci_state = HCI_SCANNING_STATE;
-
760  } else {
-
761 #ifdef DEBUG_USB_HOST
-
762  Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
-
763 #endif
-
764  hci_connect(); // Try to connect one more time
-
765  }
-
766  }
-
767  break;
-
768 
-
769  case HCI_SCANNING_STATE:
-
770  if (!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
-
771 #ifdef DEBUG_USB_HOST
-
772  Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
-
773 #endif
-
774  hci_write_scan_enable();
-
775  watingForConnection = true;
-
776  hci_state = HCI_CONNECT_IN_STATE;
-
777  }
-
778  break;
-
779 
-
780  case HCI_CONNECT_IN_STATE:
-
781  if (hci_incoming_connect_request) {
-
782  watingForConnection = false;
-
783 #ifdef DEBUG_USB_HOST
-
784  Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
-
785 #endif
-
786  hci_remote_name();
-
787  hci_state = HCI_REMOTE_NAME_STATE;
-
788  } else if (hci_disconnect_complete)
-
789  hci_state = HCI_DISCONNECT_STATE;
-
790  break;
-
791 
-
792  case HCI_REMOTE_NAME_STATE:
-
793  if (hci_remote_name_complete) {
-
794 #ifdef DEBUG_USB_HOST
-
795  Notify(PSTR("\r\nRemote Name: "), 0x80);
-
796  for (uint8_t i = 0; i < 30; i++) {
-
797  if (remote_name[i] == NULL)
-
798  break;
-
799  Notifyc(remote_name[i], 0x80);
-
800  }
-
801 #endif
-
802  if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
-
803  incomingWii = true;
-
804 #ifdef DEBUG_USB_HOST
-
805  Notify(PSTR("\r\nWiimote is connecting"), 0x80);
-
806 #endif
-
807  if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
-
808 #ifdef DEBUG_USB_HOST
-
809  Notify(PSTR(" with Motion Plus Inside"), 0x80);
-
810 #endif
-
811  motionPlusInside = true;
-
812  } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
-
813 #ifdef DEBUG_USB_HOST
-
814  Notify(PSTR(" - Wii U Pro Controller"), 0x80);
-
815 #endif
-
816  motionPlusInside = true;
-
817  wiiUProController = true;
-
818  } else {
-
819  motionPlusInside = false;
-
820  wiiUProController = false;
-
821  }
-
822  }
-
823  if (pairWithWii && motionPlusInside)
-
824  hci_state = HCI_CONNECT_DEVICE_STATE;
-
825  else {
-
826  hci_accept_connection();
-
827  hci_state = HCI_CONNECTED_STATE;
-
828  }
-
829  }
-
830  break;
-
831 
-
832  case HCI_CONNECTED_STATE:
-
833  if (hci_connect_complete) {
-
834 #ifdef DEBUG_USB_HOST
-
835  Notify(PSTR("\r\nConnected to Device: "), 0x80);
-
836  for (int8_t i = 5; i > 0; i--) {
-
837  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
-
838  Notify(PSTR(":"), 0x80);
-
839  }
-
840  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
-
841 #endif
-
842  // Clear these flags for a new connection
-
843  l2capConnectionClaimed = false;
-
844  sdpConnectionClaimed = false;
-
845  rfcommConnectionClaimed = false;
-
846 
-
847  hci_event_flag = 0;
-
848  hci_state = HCI_DONE_STATE;
-
849  }
-
850  break;
-
851 
-
852  case HCI_DONE_STATE:
-
853  hci_counter++;
-
854  if (hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
-
855  hci_counter = 0;
-
856  hci_state = HCI_SCANNING_STATE;
-
857  }
-
858  break;
-
859 
-
860  case HCI_DISCONNECT_STATE:
-
861  if (hci_disconnect_complete) {
-
862 #ifdef DEBUG_USB_HOST
-
863  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
-
864 #endif
-
865  hci_event_flag = 0; // Clear all flags
-
866 
-
867  // Reset all buffers
-
868  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
-
869  hcibuf[i] = 0;
-
870  for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)
-
871  l2capinbuf[i] = 0;
-
872 
-
873  connectToWii = false;
-
874  incomingWii = false;
-
875  pairWithWii = false;
-
876 
-
877  connectToHIDDevice = false;
-
878  incomingHIDDevice = false;
-
879  pairWithHIDDevice = false;
-
880 
-
881  hci_state = HCI_SCANNING_STATE;
-
882  }
-
883  break;
-
884  default:
-
885  break;
-
886  }
-
887 }
-
888 
-
889 void BTD::ACL_event_task() {
-
890  uint16_t MAX_BUFFER_SIZE = BULK_MAXPKTSIZE;
-
891  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &MAX_BUFFER_SIZE, l2capinbuf); // input on endpoint 2
-
892  if (!rcode) { // Check for errors
-
893  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
894  if (btService[i])
-
895  btService[i]->ACLData(l2capinbuf);
-
896  }
-
897 #ifdef EXTRADEBUG
-
898  else if (rcode != hrNAK) {
-
899  Notify(PSTR("\r\nACL data in error: "), 0x80);
-
900  D_PrintHex<uint8_t > (rcode, 0x80);
-
901  }
-
902 #endif
-
903  for (uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
904  if (btService[i])
-
905  btService[i]->Run();
-
906 }
-
907 
-
908 /************************************************************/
-
909 /* HCI Commands */
-
910 
-
911 /************************************************************/
-
912 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
-
913  hci_event_flag &= ~HCI_FLAG_CMD_COMPLETE;
-
914  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
-
915 }
-
916 
-
917 void BTD::hci_reset() {
-
918  hci_event_flag = 0; // Clear all the flags
-
919  hcibuf[0] = 0x03; // HCI OCF = 3
-
920  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
921  hcibuf[2] = 0x00;
-
922 
-
923  HCI_Command(hcibuf, 3);
-
924 }
-
925 
-
926 void BTD::hci_write_scan_enable() {
-
927  hci_event_flag &= ~HCI_FLAG_INCOMING_REQUEST;
-
928  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
929  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
930  hcibuf[2] = 0x01; // parameter length = 1
-
931  if (btdName != NULL)
-
932  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
-
933  else
-
934  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
+
448  for(uint8_t j = 0; j < 6; j++)
+
449  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
+
450 
+
451  hci_set_flag(HCI_FLAG_DEVICE_FOUND);
+
452  break;
+
453  } else if(pairWithHIDDevice && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC8)) { // Check if it is a mouse, keyboard or a gamepad - see: http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
+
454 #ifdef DEBUG_USB_HOST
+
455  if(classOfDevice[0] & 0x80)
+
456  Notify(PSTR("\r\nMouse found"), 0x80);
+
457  if(classOfDevice[0] & 0x40)
+
458  Notify(PSTR("\r\nKeyboard found"), 0x80);
+
459  if(classOfDevice[0] & 0x08)
+
460  Notify(PSTR("\r\nGamepad found"), 0x80);
+
461 #endif
+
462 
+
463  for(uint8_t j = 0; j < 6; j++)
+
464  disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
+
465 
+
466  hci_set_flag(HCI_FLAG_DEVICE_FOUND);
+
467  }
+
468 #ifdef EXTRADEBUG
+
469  else {
+
470  Notify(PSTR("\r\nClass of device: "), 0x80);
+
471  D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
+
472  Notify(PSTR(" "), 0x80);
+
473  D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
+
474  Notify(PSTR(" "), 0x80);
+
475  D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
+
476  }
+
477 #endif
+
478  }
+
479  }
+
480  break;
+
481 
+
482  case EV_CONNECT_COMPLETE:
+
483  hci_set_flag(HCI_FLAG_CONNECT_EVENT);
+
484  if(!hcibuf[2]) { // Check if connected OK
+
485 #ifdef EXTRADEBUG
+
486  Notify(PSTR("\r\nConnection established"), 0x80);
+
487 #endif
+
488  hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // Store the handle for the ACL connection
+
489  hci_set_flag(HCI_FLAG_CONNECT_COMPLETE); // Set connection complete flag
+
490  } else {
+
491  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
492 #ifdef DEBUG_USB_HOST
+
493  Notify(PSTR("\r\nConnection Failed: "), 0x80);
+
494  D_PrintHex<uint8_t > (hcibuf[2], 0x80);
+
495 #endif
+
496  }
+
497  break;
+
498 
+
499  case EV_DISCONNECT_COMPLETE:
+
500  if(!hcibuf[2]) { // Check if disconnected OK
+
501  hci_set_flag(HCI_FLAG_DISCONNECT_COMPLETE); // Set disconnect command complete flag
+
502  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE); // Clear connection complete flag
+
503  }
+
504  break;
+
505 
+
506  case EV_REMOTE_NAME_COMPLETE:
+
507  if(!hcibuf[2]) { // Check if reading is OK
+
508  for(uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++) {
+
509  remote_name[i] = hcibuf[9 + i];
+
510  if(remote_name[i] == '\0') // End of string
+
511  break;
+
512  }
+
513  hci_set_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
+
514  }
+
515  break;
+
516 
+
517  case EV_INCOMING_CONNECT:
+
518  for(uint8_t i = 0; i < 6; i++)
+
519  disc_bdaddr[i] = hcibuf[i + 2];
+
520 
+
521  for(uint8_t i = 0; i < 3; i++)
+
522  classOfDevice[i] = hcibuf[i + 8];
+
523 
+
524  if((classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC8)) { // Check if it is a mouse, keyboard or a gamepad
+
525 #ifdef DEBUG_USB_HOST
+
526  if(classOfDevice[0] & 0x80)
+
527  Notify(PSTR("\r\nMouse is connecting"), 0x80);
+
528  if(classOfDevice[0] & 0x40)
+
529  Notify(PSTR("\r\nKeyboard is connecting"), 0x80);
+
530  if(classOfDevice[0] & 0x08)
+
531  Notify(PSTR("\r\nGamepad is connecting"), 0x80);
+
532 #endif
+
533  incomingHIDDevice = true;
+
534  }
+
535 
+
536 #ifdef EXTRADEBUG
+
537  Notify(PSTR("\r\nClass of device: "), 0x80);
+
538  D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
+
539  Notify(PSTR(" "), 0x80);
+
540  D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
+
541  Notify(PSTR(" "), 0x80);
+
542  D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
+
543 #endif
+
544  hci_set_flag(HCI_FLAG_INCOMING_REQUEST);
+
545  break;
+
546 
+
547  case EV_PIN_CODE_REQUEST:
+
548  if(pairWithWii) {
+
549 #ifdef DEBUG_USB_HOST
+
550  Notify(PSTR("\r\nPairing with wiimote"), 0x80);
+
551 #endif
+
552  hci_pin_code_request_reply();
+
553  } else if(btdPin != NULL) {
+
554 #ifdef DEBUG_USB_HOST
+
555  Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
+
556  NotifyStr(btdPin, 0x80);
+
557 #endif
+
558  hci_pin_code_request_reply();
+
559  } else {
+
560 #ifdef DEBUG_USB_HOST
+
561  Notify(PSTR("\r\nNo pin was set"), 0x80);
+
562 #endif
+
563  hci_pin_code_negative_request_reply();
+
564  }
+
565  break;
+
566 
+
567  case EV_LINK_KEY_REQUEST:
+
568 #ifdef DEBUG_USB_HOST
+
569  Notify(PSTR("\r\nReceived Key Request"), 0x80);
+
570 #endif
+
571  hci_link_key_request_negative_reply();
+
572  break;
+
573 
+
574  case EV_AUTHENTICATION_COMPLETE:
+
575  if(pairWithWii && !connectToWii) {
+
576 #ifdef DEBUG_USB_HOST
+
577  Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80);
+
578 #endif
+
579  connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device
+
580  } else if(pairWithHIDDevice && !connectToHIDDevice) {
+
581 #ifdef DEBUG_USB_HOST
+
582  Notify(PSTR("\r\nPairing successful with HID device"), 0x80);
+
583 #endif
+
584  connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device
+
585  }
+
586  break;
+
587  /* We will just ignore the following events */
+
588  case EV_NUM_COMPLETE_PKT:
+
589  case EV_ROLE_CHANGED:
+
590  case EV_PAGE_SCAN_REP_MODE:
+
591  case EV_LOOPBACK_COMMAND:
+
592  case EV_DATA_BUFFER_OVERFLOW:
+
593  case EV_CHANGE_CONNECTION_LINK:
+
594  case EV_MAX_SLOTS_CHANGE:
+
595  case EV_QOS_SETUP_COMPLETE:
+
596  case EV_LINK_KEY_NOTIFICATION:
+
597  case EV_ENCRYPTION_CHANGE:
+
598  case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
+
599  break;
+
600 #ifdef EXTRADEBUG
+
601  default:
+
602  if(hcibuf[0] != 0x00) {
+
603  Notify(PSTR("\r\nUnmanaged HCI Event: "), 0x80);
+
604  D_PrintHex<uint8_t > (hcibuf[0], 0x80);
+
605  }
+
606  break;
+
607 #endif
+
608  } // Switch
+
609  }
+
610 #ifdef EXTRADEBUG
+
611  else {
+
612  Notify(PSTR("\r\nHCI event error: "), 0x80);
+
613  D_PrintHex<uint8_t > (rcode, 0x80);
+
614  }
+
615 #endif
+
616 }
+
617 
+
618 /* Poll Bluetooth and print result */
+
619 void BTD::HCI_task() {
+
620  switch(hci_state) {
+
621  case HCI_INIT_STATE:
+
622  hci_counter++;
+
623  if(hci_counter > hci_num_reset_loops) { // wait until we have looped x times to clear any old events
+
624  hci_reset();
+
625  hci_state = HCI_RESET_STATE;
+
626  hci_counter = 0;
+
627  }
+
628  break;
+
629 
+
630  case HCI_RESET_STATE:
+
631  hci_counter++;
+
632  if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
+
633  hci_counter = 0;
+
634 #ifdef DEBUG_USB_HOST
+
635  Notify(PSTR("\r\nHCI Reset complete"), 0x80);
+
636 #endif
+
637  hci_state = HCI_CLASS_STATE;
+
638  hci_write_class_of_device();
+
639  } else if(hci_counter > hci_num_reset_loops) {
+
640  hci_num_reset_loops *= 10;
+
641  if(hci_num_reset_loops > 2000)
+
642  hci_num_reset_loops = 2000;
+
643 #ifdef DEBUG_USB_HOST
+
644  Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
+
645 #endif
+
646  hci_state = HCI_INIT_STATE;
+
647  hci_counter = 0;
+
648  }
+
649  break;
+
650 
+
651  case HCI_CLASS_STATE:
+
652  if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
+
653 #ifdef DEBUG_USB_HOST
+
654  Notify(PSTR("\r\nWrite class of device"), 0x80);
+
655 #endif
+
656  hci_state = HCI_BDADDR_STATE;
+
657  hci_read_bdaddr();
+
658  }
+
659  break;
+
660 
+
661  case HCI_BDADDR_STATE:
+
662  if(hci_check_flag(HCI_FLAG_READ_BDADDR)) {
+
663 #ifdef DEBUG_USB_HOST
+
664  Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
+
665  for(int8_t i = 5; i > 0; i--) {
+
666  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
+
667  Notify(PSTR(":"), 0x80);
+
668  }
+
669  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
+
670 #endif
+
671  hci_read_local_version_information();
+
672  hci_state = HCI_LOCAL_VERSION_STATE;
+
673  }
+
674  break;
+
675 
+
676  case HCI_LOCAL_VERSION_STATE: // The local version is used by the PS3BT class
+
677  if(hci_check_flag(HCI_FLAG_READ_VERSION)) {
+
678  if(btdName != NULL) {
+
679  hci_set_local_name(btdName);
+
680  hci_state = HCI_SET_NAME_STATE;
+
681  } else
+
682  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
683  }
+
684  break;
+
685 
+
686  case HCI_SET_NAME_STATE:
+
687  if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
+
688 #ifdef DEBUG_USB_HOST
+
689  Notify(PSTR("\r\nThe name is set to: "), 0x80);
+
690  NotifyStr(btdName, 0x80);
+
691 #endif
+
692  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
693  }
+
694  break;
+
695 
+
696  case HCI_CHECK_DEVICE_SERVICE:
+
697  if(pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a Wiimote
+
698 #ifdef DEBUG_USB_HOST
+
699  if(pairWithWii)
+
700  Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
+
701  else
+
702  Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80);
+
703 #endif
+
704  hci_inquiry();
+
705  hci_state = HCI_INQUIRY_STATE;
+
706  } else
+
707  hci_state = HCI_SCANNING_STATE; // Don't try to connect to a Wiimote
+
708  break;
+
709 
+
710  case HCI_INQUIRY_STATE:
+
711  if(hci_check_flag(HCI_FLAG_DEVICE_FOUND)) {
+
712  hci_inquiry_cancel(); // Stop inquiry
+
713 #ifdef DEBUG_USB_HOST
+
714  if(pairWithWii)
+
715  Notify(PSTR("\r\nWiimote found"), 0x80);
+
716  else
+
717  Notify(PSTR("\r\nHID device found"), 0x80);
+
718 
+
719  Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
+
720  if(pairWithWii)
+
721  Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
+
722  else
+
723  Notify(PSTR("\r\nBTHID hid(&Btd);"), 0x80);
+
724 
+
725  Notify(PSTR("\r\nAnd then press any button on the "), 0x80);
+
726  if(pairWithWii)
+
727  Notify(PSTR("Wiimote"), 0x80);
+
728  else
+
729  Notify(PSTR("device"), 0x80);
+
730 #endif
+
731  if(motionPlusInside) {
+
732  hci_remote_name(); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller
+
733  hci_state = HCI_REMOTE_NAME_STATE;
+
734  } else
+
735  hci_state = HCI_CONNECT_DEVICE_STATE;
+
736  }
+
737  break;
+
738 
+
739  case HCI_CONNECT_DEVICE_STATE:
+
740  if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
+
741 #ifdef DEBUG_USB_HOST
+
742  if(pairWithWii)
+
743  Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
+
744  else
+
745  Notify(PSTR("\r\nConnecting to HID device"), 0x80);
+
746 #endif
+
747  hci_connect();
+
748  hci_state = HCI_CONNECTED_DEVICE_STATE;
+
749  }
+
750  break;
+
751 
+
752  case HCI_CONNECTED_DEVICE_STATE:
+
753  if(hci_check_flag(HCI_FLAG_CONNECT_EVENT)) {
+
754  if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
+
755 #ifdef DEBUG_USB_HOST
+
756  if(pairWithWii)
+
757  Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
+
758  else
+
759  Notify(PSTR("\r\nConnected to HID device"), 0x80);
+
760 #endif
+
761  hci_authentication_request(); // This will start the pairing with the Wiimote
+
762  hci_state = HCI_SCANNING_STATE;
+
763  } else {
+
764 #ifdef DEBUG_USB_HOST
+
765  Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
+
766 #endif
+
767  hci_connect(); // Try to connect one more time
+
768  }
+
769  }
+
770  break;
+
771 
+
772  case HCI_SCANNING_STATE:
+
773  if(!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
+
774 #ifdef DEBUG_USB_HOST
+
775  Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
+
776 #endif
+
777  hci_write_scan_enable();
+
778  watingForConnection = true;
+
779  hci_state = HCI_CONNECT_IN_STATE;
+
780  }
+
781  break;
+
782 
+
783  case HCI_CONNECT_IN_STATE:
+
784  if(hci_check_flag(HCI_FLAG_INCOMING_REQUEST)) {
+
785  watingForConnection = false;
+
786 #ifdef DEBUG_USB_HOST
+
787  Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
+
788 #endif
+
789  hci_remote_name();
+
790  hci_state = HCI_REMOTE_NAME_STATE;
+
791  } else if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE))
+
792  hci_state = HCI_DISCONNECT_STATE;
+
793  break;
+
794 
+
795  case HCI_REMOTE_NAME_STATE:
+
796  if(hci_check_flag(HCI_FLAG_REMOTE_NAME_COMPLETE)) {
+
797 #ifdef DEBUG_USB_HOST
+
798  Notify(PSTR("\r\nRemote Name: "), 0x80);
+
799  for(uint8_t i = 0; i < 30; i++) {
+
800  if(remote_name[i] == '\0') // End of string
+
801  break;
+
802  Notifyc(remote_name[i], 0x80);
+
803  }
+
804 #endif
+
805  if(strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
+
806  incomingWii = true;
+
807 #ifdef DEBUG_USB_HOST
+
808  Notify(PSTR("\r\nWiimote is connecting"), 0x80);
+
809 #endif
+
810  if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
+
811 #ifdef DEBUG_USB_HOST
+
812  Notify(PSTR(" with Motion Plus Inside"), 0x80);
+
813 #endif
+
814  motionPlusInside = true;
+
815  } else if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
+
816 #ifdef DEBUG_USB_HOST
+
817  Notify(PSTR(" - Wii U Pro Controller"), 0x80);
+
818 #endif
+
819  motionPlusInside = true;
+
820  wiiUProController = true;
+
821  } else {
+
822  motionPlusInside = false;
+
823  wiiUProController = false;
+
824  }
+
825  }
+
826  if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 && strncmp((const char*)remote_name, "Wireless Controller", 19) == 0) {
+
827 #ifdef DEBUG_USB_HOST
+
828  Notify(PSTR("\r\nPS4 controller is connecting"), 0x80);
+
829 #endif
+
830  incomingPS4 = true;
+
831  }
+
832  if(pairWithWii && motionPlusInside)
+
833  hci_state = HCI_CONNECT_DEVICE_STATE;
+
834  else {
+
835  hci_accept_connection();
+
836  hci_state = HCI_CONNECTED_STATE;
+
837  }
+
838  }
+
839  break;
+
840 
+
841  case HCI_CONNECTED_STATE:
+
842  if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
+
843 #ifdef DEBUG_USB_HOST
+
844  Notify(PSTR("\r\nConnected to Device: "), 0x80);
+
845  for(int8_t i = 5; i > 0; i--) {
+
846  D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
+
847  Notify(PSTR(":"), 0x80);
+
848  }
+
849  D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
+
850 #endif
+
851  if(incomingPS4)
+
852  connectToHIDDevice = true; // We should always connect to the PS4 controller
+
853 
+
854  // Clear these flags for a new connection
+
855  l2capConnectionClaimed = false;
+
856  sdpConnectionClaimed = false;
+
857  rfcommConnectionClaimed = false;
+
858 
+
859  hci_event_flag = 0;
+
860  hci_state = HCI_DONE_STATE;
+
861  }
+
862  break;
+
863 
+
864  case HCI_DONE_STATE:
+
865  hci_counter++;
+
866  if(hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
+
867  hci_counter = 0;
+
868  hci_state = HCI_SCANNING_STATE;
+
869  }
+
870  break;
+
871 
+
872  case HCI_DISCONNECT_STATE:
+
873  if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE)) {
+
874 #ifdef DEBUG_USB_HOST
+
875  Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
+
876 #endif
+
877  hci_event_flag = 0; // Clear all flags
+
878 
+
879  // Reset all buffers
+
880  memset(hcibuf, 0, BULK_MAXPKTSIZE);
+
881  memset(l2capinbuf, 0, BULK_MAXPKTSIZE);
+
882 
+
883  connectToWii = incomingWii = pairWithWii = false;
+
884  connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false;
+
885  incomingPS4 = false;
+
886 
+
887  hci_state = HCI_SCANNING_STATE;
+
888  }
+
889  break;
+
890  default:
+
891  break;
+
892  }
+
893 }
+
894 
+
895 void BTD::ACL_event_task() {
+
896  uint16_t length = BULK_MAXPKTSIZE;
+
897  uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2
+
898 
+
899  if(!rcode) { // Check for errors
+
900  if(length > 0) { // Check if any data was read
+
901  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
+
902  if(btService[i])
+
903  btService[i]->ACLData(l2capinbuf);
+
904  }
+
905  }
+
906  }
+
907 #ifdef EXTRADEBUG
+
908  else if(rcode != hrNAK) {
+
909  Notify(PSTR("\r\nACL data in error: "), 0x80);
+
910  D_PrintHex<uint8_t > (rcode, 0x80);
+
911  }
+
912 #endif
+
913  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
914  if(btService[i])
+
915  btService[i]->Run();
+
916 }
+
917 
+
918 /************************************************************/
+
919 /* HCI Commands */
+
920 
+
921 /************************************************************/
+
922 void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
+
923  hci_clear_flag(HCI_FLAG_CMD_COMPLETE);
+
924  pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
+
925 }
+
926 
+
927 void BTD::hci_reset() {
+
928  hci_event_flag = 0; // Clear all the flags
+
929  hcibuf[0] = 0x03; // HCI OCF = 3
+
930  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
931  hcibuf[2] = 0x00;
+
932 
+
933  HCI_Command(hcibuf, 3);
+
934 }
935 
-
936  HCI_Command(hcibuf, 4);
-
937 }
-
938 
-
939 void BTD::hci_write_scan_disable() {
-
940  hcibuf[0] = 0x1A; // HCI OCF = 1A
-
941  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
942  hcibuf[2] = 0x01; // parameter length = 1
-
943  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
-
944 
-
945  HCI_Command(hcibuf, 4);
-
946 }
-
947 
-
948 void BTD::hci_read_bdaddr() {
-
949  hcibuf[0] = 0x09; // HCI OCF = 9
-
950  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
951  hcibuf[2] = 0x00;
-
952 
-
953  HCI_Command(hcibuf, 3);
-
954 }
-
955 
-
956 void BTD::hci_read_local_version_information() {
-
957  hcibuf[0] = 0x01; // HCI OCF = 1
-
958  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
-
959  hcibuf[2] = 0x00;
-
960 
-
961  HCI_Command(hcibuf, 3);
-
962 }
+
936 void BTD::hci_write_scan_enable() {
+
937  hci_clear_flag(HCI_FLAG_INCOMING_REQUEST);
+
938  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
939  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
940  hcibuf[2] = 0x01; // parameter length = 1
+
941  if(btdName != NULL)
+
942  hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
+
943  else
+
944  hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
+
945 
+
946  HCI_Command(hcibuf, 4);
+
947 }
+
948 
+
949 void BTD::hci_write_scan_disable() {
+
950  hcibuf[0] = 0x1A; // HCI OCF = 1A
+
951  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
952  hcibuf[2] = 0x01; // parameter length = 1
+
953  hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
+
954 
+
955  HCI_Command(hcibuf, 4);
+
956 }
+
957 
+
958 void BTD::hci_read_bdaddr() {
+
959  hci_clear_flag(HCI_FLAG_READ_BDADDR);
+
960  hcibuf[0] = 0x09; // HCI OCF = 9
+
961  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
962  hcibuf[2] = 0x00;
963 
-
964 void BTD::hci_accept_connection() {
-
965  hci_event_flag &= ~HCI_FLAG_CONN_COMPLETE;
-
966  hcibuf[0] = 0x09; // HCI OCF = 9
-
967  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
968  hcibuf[2] = 0x07; // parameter length 7
-
969  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
970  hcibuf[4] = disc_bdaddr[1];
-
971  hcibuf[5] = disc_bdaddr[2];
-
972  hcibuf[6] = disc_bdaddr[3];
-
973  hcibuf[7] = disc_bdaddr[4];
-
974  hcibuf[8] = disc_bdaddr[5];
-
975  hcibuf[9] = 0x00; //switch role to master
-
976 
-
977  HCI_Command(hcibuf, 10);
-
978 }
-
979 
-
980 void BTD::hci_remote_name() {
-
981  hci_event_flag &= ~HCI_FLAG_REMOTE_NAME_COMPLETE;
-
982  hcibuf[0] = 0x19; // HCI OCF = 19
-
983  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
984  hcibuf[2] = 0x0A; // parameter length = 10
-
985  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
986  hcibuf[4] = disc_bdaddr[1];
-
987  hcibuf[5] = disc_bdaddr[2];
-
988  hcibuf[6] = disc_bdaddr[3];
-
989  hcibuf[7] = disc_bdaddr[4];
-
990  hcibuf[8] = disc_bdaddr[5];
-
991  hcibuf[9] = 0x01; //Page Scan Repetition Mode
-
992  hcibuf[10] = 0x00; //Reserved
-
993  hcibuf[11] = 0x00; //Clock offset - low byte
-
994  hcibuf[12] = 0x00; //Clock offset - high byte
-
995 
-
996  HCI_Command(hcibuf, 13);
-
997 }
-
998 
-
999 void BTD::hci_set_local_name(const char* name) {
-
1000  hcibuf[0] = 0x13; // HCI OCF = 13
-
1001  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
1002  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
-
1003  uint8_t i;
-
1004  for (i = 0; i < strlen(name); i++)
-
1005  hcibuf[i + 3] = name[i];
-
1006  hcibuf[i + 3] = 0x00; // End of string
+
964  HCI_Command(hcibuf, 3);
+
965 }
+
966 
+
967 void BTD::hci_read_local_version_information() {
+
968  hci_clear_flag(HCI_FLAG_READ_VERSION);
+
969  hcibuf[0] = 0x01; // HCI OCF = 1
+
970  hcibuf[1] = 0x04 << 2; // HCI OGF = 4
+
971  hcibuf[2] = 0x00;
+
972 
+
973  HCI_Command(hcibuf, 3);
+
974 }
+
975 
+
976 void BTD::hci_accept_connection() {
+
977  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE);
+
978  hcibuf[0] = 0x09; // HCI OCF = 9
+
979  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
980  hcibuf[2] = 0x07; // parameter length 7
+
981  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
982  hcibuf[4] = disc_bdaddr[1];
+
983  hcibuf[5] = disc_bdaddr[2];
+
984  hcibuf[6] = disc_bdaddr[3];
+
985  hcibuf[7] = disc_bdaddr[4];
+
986  hcibuf[8] = disc_bdaddr[5];
+
987  hcibuf[9] = 0x00; // Switch role to master
+
988 
+
989  HCI_Command(hcibuf, 10);
+
990 }
+
991 
+
992 void BTD::hci_remote_name() {
+
993  hci_clear_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
+
994  hcibuf[0] = 0x19; // HCI OCF = 19
+
995  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
996  hcibuf[2] = 0x0A; // parameter length = 10
+
997  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
998  hcibuf[4] = disc_bdaddr[1];
+
999  hcibuf[5] = disc_bdaddr[2];
+
1000  hcibuf[6] = disc_bdaddr[3];
+
1001  hcibuf[7] = disc_bdaddr[4];
+
1002  hcibuf[8] = disc_bdaddr[5];
+
1003  hcibuf[9] = 0x01; // Page Scan Repetition Mode
+
1004  hcibuf[10] = 0x00; // Reserved
+
1005  hcibuf[11] = 0x00; // Clock offset - low byte
+
1006  hcibuf[12] = 0x00; // Clock offset - high byte
1007 
-
1008  HCI_Command(hcibuf, 4 + strlen(name));
+
1008  HCI_Command(hcibuf, 13);
1009 }
1010 
-
1011 void BTD::hci_inquiry() {
-
1012  hci_event_flag &= ~HCI_FLAG_DEVICE_FOUND;
-
1013  hcibuf[0] = 0x01;
-
1014  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1015  hcibuf[2] = 0x05; // Parameter Total Length = 5
-
1016  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
-
1017  hcibuf[4] = 0x8B;
-
1018  hcibuf[5] = 0x9E;
-
1019  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
-
1020  hcibuf[7] = 0x0A; // 10 number of responses
-
1021 
-
1022  HCI_Command(hcibuf, 8);
-
1023 }
-
1024 
-
1025 void BTD::hci_inquiry_cancel() {
-
1026  hcibuf[0] = 0x02;
-
1027  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1028  hcibuf[2] = 0x00; // Parameter Total Length = 0
-
1029 
-
1030  HCI_Command(hcibuf, 3);
-
1031 }
-
1032 
-
1033 void BTD::hci_connect() {
-
1034  hci_connect(disc_bdaddr); // Use last discovered device
+
1011 void BTD::hci_set_local_name(const char* name) {
+
1012  hcibuf[0] = 0x13; // HCI OCF = 13
+
1013  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1014  hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
+
1015  uint8_t i;
+
1016  for(i = 0; i < strlen(name); i++)
+
1017  hcibuf[i + 3] = name[i];
+
1018  hcibuf[i + 3] = 0x00; // End of string
+
1019 
+
1020  HCI_Command(hcibuf, 4 + strlen(name));
+
1021 }
+
1022 
+
1023 void BTD::hci_inquiry() {
+
1024  hci_clear_flag(HCI_FLAG_DEVICE_FOUND);
+
1025  hcibuf[0] = 0x01;
+
1026  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1027  hcibuf[2] = 0x05; // Parameter Total Length = 5
+
1028  hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
+
1029  hcibuf[4] = 0x8B;
+
1030  hcibuf[5] = 0x9E;
+
1031  hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
+
1032  hcibuf[7] = 0x0A; // 10 number of responses
+
1033 
+
1034  HCI_Command(hcibuf, 8);
1035 }
1036 
-
1037 void BTD::hci_connect(uint8_t *bdaddr) {
-
1038  hci_event_flag &= ~(HCI_FLAG_CONN_COMPLETE | HCI_FLAG_CONNECT_EVENT);
-
1039  hcibuf[0] = 0x05;
-
1040  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1041  hcibuf[2] = 0x0D; // parameter Total Length = 13
-
1042  hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
-
1043  hcibuf[4] = bdaddr[1];
-
1044  hcibuf[5] = bdaddr[2];
-
1045  hcibuf[6] = bdaddr[3];
-
1046  hcibuf[7] = bdaddr[4];
-
1047  hcibuf[8] = bdaddr[5];
-
1048  hcibuf[9] = 0x18; // DM1 or DH1 may be used
-
1049  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
-
1050  hcibuf[11] = 0x01; // Page repetition mode R1
-
1051  hcibuf[12] = 0x00; // Reserved
-
1052  hcibuf[13] = 0x00; // Clock offset
-
1053  hcibuf[14] = 0x00; // Invalid clock offset
-
1054  hcibuf[15] = 0x00; // Do not allow role switch
-
1055 
-
1056  HCI_Command(hcibuf, 16);
-
1057 }
-
1058 
-
1059 void BTD::hci_pin_code_request_reply() {
-
1060  hcibuf[0] = 0x0D; // HCI OCF = 0D
-
1061  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1062  hcibuf[2] = 0x17; // parameter length 23
-
1063  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1064  hcibuf[4] = disc_bdaddr[1];
-
1065  hcibuf[5] = disc_bdaddr[2];
-
1066  hcibuf[6] = disc_bdaddr[3];
-
1067  hcibuf[7] = disc_bdaddr[4];
-
1068  hcibuf[8] = disc_bdaddr[5];
-
1069  if (pairWithWii) {
-
1070  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
-
1071  if (wiiUProController) {
-
1072 #ifdef DEBUG_USB_HOST
-
1073  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
-
1074 #endif
-
1075  for (uint8_t i = 0; i < 6; i++)
-
1076  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
-
1077  } else {
-
1078  for (uint8_t i = 0; i < 6; i++)
-
1079  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
-
1080  }
-
1081  for (uint8_t i = 16; i < 26; i++)
-
1082  hcibuf[i] = 0x00; // The rest should be 0
-
1083  } else {
-
1084  hcibuf[9] = strlen(btdPin); // Length of pin
-
1085  uint8_t i;
-
1086  for (i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
-
1087  hcibuf[i + 10] = btdPin[i];
-
1088  for (; i < 16; i++)
-
1089  hcibuf[i + 10] = 0x00; // The rest should be 0
-
1090  }
-
1091 
-
1092  HCI_Command(hcibuf, 26);
-
1093 }
-
1094 
-
1095 void BTD::hci_pin_code_negative_request_reply() {
-
1096  hcibuf[0] = 0x0E; // HCI OCF = 0E
-
1097  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1098  hcibuf[2] = 0x06; // parameter length 6
-
1099  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1100  hcibuf[4] = disc_bdaddr[1];
-
1101  hcibuf[5] = disc_bdaddr[2];
-
1102  hcibuf[6] = disc_bdaddr[3];
-
1103  hcibuf[7] = disc_bdaddr[4];
-
1104  hcibuf[8] = disc_bdaddr[5];
-
1105 
-
1106  HCI_Command(hcibuf, 9);
-
1107 }
-
1108 
-
1109 void BTD::hci_link_key_request_negative_reply() {
-
1110  hcibuf[0] = 0x0C; // HCI OCF = 0C
-
1111  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1112  hcibuf[2] = 0x06; // parameter length 6
-
1113  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
-
1114  hcibuf[4] = disc_bdaddr[1];
-
1115  hcibuf[5] = disc_bdaddr[2];
-
1116  hcibuf[6] = disc_bdaddr[3];
-
1117  hcibuf[7] = disc_bdaddr[4];
-
1118  hcibuf[8] = disc_bdaddr[5];
-
1119 
-
1120  HCI_Command(hcibuf, 9);
-
1121 }
-
1122 
-
1123 void BTD::hci_authentication_request() {
-
1124  hcibuf[0] = 0x11; // HCI OCF = 11
-
1125  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1126  hcibuf[2] = 0x02; // parameter length = 2
-
1127  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
-
1128  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
-
1129 
-
1130  HCI_Command(hcibuf, 5);
-
1131 }
-
1132 
-
1133 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
-
1134  hci_event_flag &= ~HCI_FLAG_DISCONN_COMPLETE;
-
1135  hcibuf[0] = 0x06; // HCI OCF = 6
-
1136  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
-
1137  hcibuf[2] = 0x03; // parameter length = 3
-
1138  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
-
1139  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
-
1140  hcibuf[5] = 0x13; // reason
+
1037 void BTD::hci_inquiry_cancel() {
+
1038  hcibuf[0] = 0x02;
+
1039  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1040  hcibuf[2] = 0x00; // Parameter Total Length = 0
+
1041 
+
1042  HCI_Command(hcibuf, 3);
+
1043 }
+
1044 
+
1045 void BTD::hci_connect() {
+
1046  hci_connect(disc_bdaddr); // Use last discovered device
+
1047 }
+
1048 
+
1049 void BTD::hci_connect(uint8_t *bdaddr) {
+
1050  hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE | HCI_FLAG_CONNECT_EVENT);
+
1051  hcibuf[0] = 0x05;
+
1052  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1053  hcibuf[2] = 0x0D; // parameter Total Length = 13
+
1054  hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
+
1055  hcibuf[4] = bdaddr[1];
+
1056  hcibuf[5] = bdaddr[2];
+
1057  hcibuf[6] = bdaddr[3];
+
1058  hcibuf[7] = bdaddr[4];
+
1059  hcibuf[8] = bdaddr[5];
+
1060  hcibuf[9] = 0x18; // DM1 or DH1 may be used
+
1061  hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
+
1062  hcibuf[11] = 0x01; // Page repetition mode R1
+
1063  hcibuf[12] = 0x00; // Reserved
+
1064  hcibuf[13] = 0x00; // Clock offset
+
1065  hcibuf[14] = 0x00; // Invalid clock offset
+
1066  hcibuf[15] = 0x00; // Do not allow role switch
+
1067 
+
1068  HCI_Command(hcibuf, 16);
+
1069 }
+
1070 
+
1071 void BTD::hci_pin_code_request_reply() {
+
1072  hcibuf[0] = 0x0D; // HCI OCF = 0D
+
1073  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1074  hcibuf[2] = 0x17; // parameter length 23
+
1075  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1076  hcibuf[4] = disc_bdaddr[1];
+
1077  hcibuf[5] = disc_bdaddr[2];
+
1078  hcibuf[6] = disc_bdaddr[3];
+
1079  hcibuf[7] = disc_bdaddr[4];
+
1080  hcibuf[8] = disc_bdaddr[5];
+
1081  if(pairWithWii) {
+
1082  hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
+
1083  if(wiiUProController) {
+
1084 #ifdef DEBUG_USB_HOST
+
1085  Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
+
1086 #endif
+
1087  for(uint8_t i = 0; i < 6; i++)
+
1088  hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
+
1089  } else {
+
1090  for(uint8_t i = 0; i < 6; i++)
+
1091  hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
+
1092  }
+
1093  for(uint8_t i = 16; i < 26; i++)
+
1094  hcibuf[i] = 0x00; // The rest should be 0
+
1095  } else {
+
1096  hcibuf[9] = strlen(btdPin); // Length of pin
+
1097  uint8_t i;
+
1098  for(i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
+
1099  hcibuf[i + 10] = btdPin[i];
+
1100  for(; i < 16; i++)
+
1101  hcibuf[i + 10] = 0x00; // The rest should be 0
+
1102  }
+
1103 
+
1104  HCI_Command(hcibuf, 26);
+
1105 }
+
1106 
+
1107 void BTD::hci_pin_code_negative_request_reply() {
+
1108  hcibuf[0] = 0x0E; // HCI OCF = 0E
+
1109  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1110  hcibuf[2] = 0x06; // parameter length 6
+
1111  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1112  hcibuf[4] = disc_bdaddr[1];
+
1113  hcibuf[5] = disc_bdaddr[2];
+
1114  hcibuf[6] = disc_bdaddr[3];
+
1115  hcibuf[7] = disc_bdaddr[4];
+
1116  hcibuf[8] = disc_bdaddr[5];
+
1117 
+
1118  HCI_Command(hcibuf, 9);
+
1119 }
+
1120 
+
1121 void BTD::hci_link_key_request_negative_reply() {
+
1122  hcibuf[0] = 0x0C; // HCI OCF = 0C
+
1123  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1124  hcibuf[2] = 0x06; // parameter length 6
+
1125  hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
+
1126  hcibuf[4] = disc_bdaddr[1];
+
1127  hcibuf[5] = disc_bdaddr[2];
+
1128  hcibuf[6] = disc_bdaddr[3];
+
1129  hcibuf[7] = disc_bdaddr[4];
+
1130  hcibuf[8] = disc_bdaddr[5];
+
1131 
+
1132  HCI_Command(hcibuf, 9);
+
1133 }
+
1134 
+
1135 void BTD::hci_authentication_request() {
+
1136  hcibuf[0] = 0x11; // HCI OCF = 11
+
1137  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1138  hcibuf[2] = 0x02; // parameter length = 2
+
1139  hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
+
1140  hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
1141 
-
1142  HCI_Command(hcibuf, 6);
+
1142  HCI_Command(hcibuf, 5);
1143 }
1144 
-
1145 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
-
1146  hcibuf[0] = 0x24; // HCI OCF = 24
-
1147  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
-
1148  hcibuf[2] = 0x03; // parameter length = 3
-
1149  hcibuf[3] = 0x04; // Robot
-
1150  hcibuf[4] = 0x08; // Toy
-
1151  hcibuf[5] = 0x00;
-
1152 
-
1153  HCI_Command(hcibuf, 6);
-
1154 }
-
1155 /*******************************************************************
-
1156  * *
-
1157  * HCI ACL Data Packet *
-
1158  * *
-
1159  * buf[0] buf[1] buf[2] buf[3]
-
1160  * 0 4 8 11 12 16 24 31 MSB
-
1161  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1162  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
-
1163  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1164  *
-
1165  * buf[4] buf[5] buf[6] buf[7]
-
1166  * 0 8 16 31 MSB
-
1167  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1168  * | Length | Channel ID | Basic L2CAP header
-
1169  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1170  *
-
1171  * buf[8] buf[9] buf[10] buf[11]
-
1172  * 0 8 16 31 MSB
-
1173  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
-
1174  * | Code | Identifier | Length | Control frame (C-frame)
-
1175  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
-
1176  */
-
1177 /************************************************************/
-
1178 /* L2CAP Commands */
-
1179 
-
1180 /************************************************************/
-
1181 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
-
1182  uint8_t buf[8 + nbytes];
-
1183  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
-
1184  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
-
1185  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
-
1186  buf[3] = (uint8_t)((4 + nbytes) >> 8);
-
1187  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
-
1188  buf[5] = (uint8_t)(nbytes >> 8);
-
1189  buf[6] = channelLow;
-
1190  buf[7] = channelHigh;
+
1145 void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
+
1146  hci_clear_flag(HCI_FLAG_DISCONNECT_COMPLETE);
+
1147  hcibuf[0] = 0x06; // HCI OCF = 6
+
1148  hcibuf[1] = 0x01 << 2; // HCI OGF = 1
+
1149  hcibuf[2] = 0x03; // parameter length = 3
+
1150  hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
+
1151  hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
+
1152  hcibuf[5] = 0x13; // reason
+
1153 
+
1154  HCI_Command(hcibuf, 6);
+
1155 }
+
1156 
+
1157 void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
+
1158  hcibuf[0] = 0x24; // HCI OCF = 24
+
1159  hcibuf[1] = 0x03 << 2; // HCI OGF = 3
+
1160  hcibuf[2] = 0x03; // parameter length = 3
+
1161  hcibuf[3] = 0x04; // Robot
+
1162  hcibuf[4] = 0x08; // Toy
+
1163  hcibuf[5] = 0x00;
+
1164 
+
1165  HCI_Command(hcibuf, 6);
+
1166 }
+
1167 /*******************************************************************
+
1168  * *
+
1169  * HCI ACL Data Packet *
+
1170  * *
+
1171  * buf[0] buf[1] buf[2] buf[3]
+
1172  * 0 4 8 11 12 16 24 31 MSB
+
1173  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1174  * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
+
1175  * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1176  *
+
1177  * buf[4] buf[5] buf[6] buf[7]
+
1178  * 0 8 16 31 MSB
+
1179  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1180  * | Length | Channel ID | Basic L2CAP header
+
1181  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1182  *
+
1183  * buf[8] buf[9] buf[10] buf[11]
+
1184  * 0 8 16 31 MSB
+
1185  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
+
1186  * | Code | Identifier | Length | Control frame (C-frame)
+
1187  * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
+
1188  */
+
1189 /************************************************************/
+
1190 /* L2CAP Commands */
1191 
-
1192  for (uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
-
1193  buf[8 + i] = data[i];
-
1194 
-
1195  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
-
1196  if (rcode) {
-
1197  delay(100); // This small delay prevents it from overflowing if it fails
-
1198 #ifdef DEBUG_USB_HOST
-
1199  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
-
1200  D_PrintHex<uint8_t > (rcode, 0x80);
-
1201  Notify(PSTR(" - Channel ID: "), 0x80);
-
1202  D_PrintHex<uint8_t > (channelHigh, 0x80);
-
1203  Notify(PSTR(" "), 0x80);
-
1204  D_PrintHex<uint8_t > (channelLow, 0x80);
-
1205 #endif
-
1206  }
-
1207 }
-
1208 
-
1209 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
-
1210  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
-
1211  l2capoutbuf[1] = rxid; // Identifier
-
1212  l2capoutbuf[2] = 0x04; // Length
-
1213  l2capoutbuf[3] = 0x00;
-
1214  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
-
1215  l2capoutbuf[5] = (uint8_t)(psm >> 8);
-
1216  l2capoutbuf[6] = scid[0]; // Source CID
-
1217  l2capoutbuf[7] = scid[1];
-
1218 
-
1219  L2CAP_Command(handle, l2capoutbuf, 8);
-
1220 }
-
1221 
-
1222 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
-
1223  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
-
1224  l2capoutbuf[1] = rxid; // Identifier
-
1225  l2capoutbuf[2] = 0x08; // Length
-
1226  l2capoutbuf[3] = 0x00;
-
1227  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1228  l2capoutbuf[5] = dcid[1];
-
1229  l2capoutbuf[6] = scid[0]; // Source CID
-
1230  l2capoutbuf[7] = scid[1];
-
1231  l2capoutbuf[8] = result; // Result: Pending or Success
-
1232  l2capoutbuf[9] = 0x00;
-
1233  l2capoutbuf[10] = 0x00; // No further information
-
1234  l2capoutbuf[11] = 0x00;
-
1235 
-
1236  L2CAP_Command(handle, l2capoutbuf, 12);
-
1237 }
-
1238 
-
1239 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
-
1240  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
-
1241  l2capoutbuf[1] = rxid; // Identifier
-
1242  l2capoutbuf[2] = 0x08; // Length
-
1243  l2capoutbuf[3] = 0x00;
-
1244  l2capoutbuf[4] = dcid[0]; // Destination CID
-
1245  l2capoutbuf[5] = dcid[1];
-
1246  l2capoutbuf[6] = 0x00; // Flags
-
1247  l2capoutbuf[7] = 0x00;
-
1248  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
-
1249  l2capoutbuf[9] = 0x02; // Config Opt: length
-
1250  l2capoutbuf[10] = 0xFF; // MTU
-
1251  l2capoutbuf[11] = 0xFF;
-
1252 
-
1253  L2CAP_Command(handle, l2capoutbuf, 12);
-
1254 }
-
1255 
-
1256 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
-
1257  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
-
1258  l2capoutbuf[1] = rxid; // Identifier
-
1259  l2capoutbuf[2] = 0x0A; // Length
-
1260  l2capoutbuf[3] = 0x00;
-
1261  l2capoutbuf[4] = scid[0]; // Source CID
-
1262  l2capoutbuf[5] = scid[1];
-
1263  l2capoutbuf[6] = 0x00; // Flag
-
1264  l2capoutbuf[7] = 0x00;
-
1265  l2capoutbuf[8] = 0x00; // Result
-
1266  l2capoutbuf[9] = 0x00;
-
1267  l2capoutbuf[10] = 0x01; // Config
-
1268  l2capoutbuf[11] = 0x02;
-
1269  l2capoutbuf[12] = 0xA0;
-
1270  l2capoutbuf[13] = 0x02;
-
1271 
-
1272  L2CAP_Command(handle, l2capoutbuf, 14);
-
1273 }
-
1274 
-
1275 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1276  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
-
1277  l2capoutbuf[1] = rxid; // Identifier
-
1278  l2capoutbuf[2] = 0x04; // Length
-
1279  l2capoutbuf[3] = 0x00;
-
1280  l2capoutbuf[4] = dcid[0];
-
1281  l2capoutbuf[5] = dcid[1];
-
1282  l2capoutbuf[6] = scid[0];
-
1283  l2capoutbuf[7] = scid[1];
-
1284 
-
1285  L2CAP_Command(handle, l2capoutbuf, 8);
-
1286 }
-
1287 
-
1288 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
-
1289  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
-
1290  l2capoutbuf[1] = rxid; // Identifier
-
1291  l2capoutbuf[2] = 0x04; // Length
-
1292  l2capoutbuf[3] = 0x00;
-
1293  l2capoutbuf[4] = dcid[0];
-
1294  l2capoutbuf[5] = dcid[1];
-
1295  l2capoutbuf[6] = scid[0];
-
1296  l2capoutbuf[7] = scid[1];
-
1297 
-
1298  L2CAP_Command(handle, l2capoutbuf, 8);
-
1299 }
-
1300 
-
1301 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
-
1302  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
-
1303  l2capoutbuf[1] = rxid; // Identifier
-
1304  l2capoutbuf[2] = 0x08; // Length
-
1305  l2capoutbuf[3] = 0x00;
-
1306  l2capoutbuf[4] = infoTypeLow;
-
1307  l2capoutbuf[5] = infoTypeHigh;
-
1308  l2capoutbuf[6] = 0x00; // Result = success
-
1309  l2capoutbuf[7] = 0x00; // Result = success
-
1310  l2capoutbuf[8] = 0x00;
-
1311  l2capoutbuf[9] = 0x00;
-
1312  l2capoutbuf[10] = 0x00;
-
1313  l2capoutbuf[11] = 0x00;
-
1314 
-
1315  L2CAP_Command(handle, l2capoutbuf, 12);
-
1316 }
-
1317 
-
1318 /* PS3 Commands - only set Bluetooth address is implemented in this library */
-
1319 void BTD::setBdaddr(uint8_t* bdaddr) {
-
1320  /* Set the internal Bluetooth address */
-
1321  uint8_t buf[8];
-
1322  buf[0] = 0x01;
-
1323  buf[1] = 0x00;
-
1324 
-
1325  for (uint8_t i = 0; i < 6; i++)
-
1326  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
-
1327 
-
1328  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
1329  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
-
1330 }
-
1331 
-
1332 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
-
1333  /* Set the internal Bluetooth address */
-
1334  uint8_t buf[11];
-
1335  buf[0] = 0x05;
-
1336  buf[7] = 0x10;
-
1337  buf[8] = 0x01;
-
1338  buf[9] = 0x02;
-
1339  buf[10] = 0x12;
-
1340 
-
1341  for (uint8_t i = 0; i < 6; i++)
-
1342  buf[i + 1] = bdaddr[i];
+
1192 /************************************************************/
+
1193 void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
+
1194  uint8_t buf[8 + nbytes];
+
1195  buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
+
1196  buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
+
1197  buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
+
1198  buf[3] = (uint8_t)((4 + nbytes) >> 8);
+
1199  buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
+
1200  buf[5] = (uint8_t)(nbytes >> 8);
+
1201  buf[6] = channelLow;
+
1202  buf[7] = channelHigh;
+
1203 
+
1204  for(uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
+
1205  buf[8 + i] = data[i];
+
1206 
+
1207  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
+
1208  if(rcode) {
+
1209  delay(100); // This small delay prevents it from overflowing if it fails
+
1210 #ifdef DEBUG_USB_HOST
+
1211  Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
+
1212  D_PrintHex<uint8_t > (rcode, 0x80);
+
1213  Notify(PSTR(" - Channel ID: "), 0x80);
+
1214  D_PrintHex<uint8_t > (channelHigh, 0x80);
+
1215  Notify(PSTR(" "), 0x80);
+
1216  D_PrintHex<uint8_t > (channelLow, 0x80);
+
1217 #endif
+
1218  }
+
1219 }
+
1220 
+
1221 void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
+
1222  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
+
1223  l2capoutbuf[1] = rxid; // Identifier
+
1224  l2capoutbuf[2] = 0x04; // Length
+
1225  l2capoutbuf[3] = 0x00;
+
1226  l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
+
1227  l2capoutbuf[5] = (uint8_t)(psm >> 8);
+
1228  l2capoutbuf[6] = scid[0]; // Source CID
+
1229  l2capoutbuf[7] = scid[1];
+
1230 
+
1231  L2CAP_Command(handle, l2capoutbuf, 8);
+
1232 }
+
1233 
+
1234 void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
+
1235  l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
+
1236  l2capoutbuf[1] = rxid; // Identifier
+
1237  l2capoutbuf[2] = 0x08; // Length
+
1238  l2capoutbuf[3] = 0x00;
+
1239  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1240  l2capoutbuf[5] = dcid[1];
+
1241  l2capoutbuf[6] = scid[0]; // Source CID
+
1242  l2capoutbuf[7] = scid[1];
+
1243  l2capoutbuf[8] = result; // Result: Pending or Success
+
1244  l2capoutbuf[9] = 0x00;
+
1245  l2capoutbuf[10] = 0x00; // No further information
+
1246  l2capoutbuf[11] = 0x00;
+
1247 
+
1248  L2CAP_Command(handle, l2capoutbuf, 12);
+
1249 }
+
1250 
+
1251 void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
+
1252  l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
+
1253  l2capoutbuf[1] = rxid; // Identifier
+
1254  l2capoutbuf[2] = 0x08; // Length
+
1255  l2capoutbuf[3] = 0x00;
+
1256  l2capoutbuf[4] = dcid[0]; // Destination CID
+
1257  l2capoutbuf[5] = dcid[1];
+
1258  l2capoutbuf[6] = 0x00; // Flags
+
1259  l2capoutbuf[7] = 0x00;
+
1260  l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
+
1261  l2capoutbuf[9] = 0x02; // Config Opt: length
+
1262  l2capoutbuf[10] = 0xFF; // MTU
+
1263  l2capoutbuf[11] = 0xFF;
+
1264 
+
1265  L2CAP_Command(handle, l2capoutbuf, 12);
+
1266 }
+
1267 
+
1268 void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
+
1269  l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
+
1270  l2capoutbuf[1] = rxid; // Identifier
+
1271  l2capoutbuf[2] = 0x0A; // Length
+
1272  l2capoutbuf[3] = 0x00;
+
1273  l2capoutbuf[4] = scid[0]; // Source CID
+
1274  l2capoutbuf[5] = scid[1];
+
1275  l2capoutbuf[6] = 0x00; // Flag
+
1276  l2capoutbuf[7] = 0x00;
+
1277  l2capoutbuf[8] = 0x00; // Result
+
1278  l2capoutbuf[9] = 0x00;
+
1279  l2capoutbuf[10] = 0x01; // Config
+
1280  l2capoutbuf[11] = 0x02;
+
1281  l2capoutbuf[12] = 0xA0;
+
1282  l2capoutbuf[13] = 0x02;
+
1283 
+
1284  L2CAP_Command(handle, l2capoutbuf, 14);
+
1285 }
+
1286 
+
1287 void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1288  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
+
1289  l2capoutbuf[1] = rxid; // Identifier
+
1290  l2capoutbuf[2] = 0x04; // Length
+
1291  l2capoutbuf[3] = 0x00;
+
1292  l2capoutbuf[4] = dcid[0];
+
1293  l2capoutbuf[5] = dcid[1];
+
1294  l2capoutbuf[6] = scid[0];
+
1295  l2capoutbuf[7] = scid[1];
+
1296 
+
1297  L2CAP_Command(handle, l2capoutbuf, 8);
+
1298 }
+
1299 
+
1300 void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
+
1301  l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
+
1302  l2capoutbuf[1] = rxid; // Identifier
+
1303  l2capoutbuf[2] = 0x04; // Length
+
1304  l2capoutbuf[3] = 0x00;
+
1305  l2capoutbuf[4] = dcid[0];
+
1306  l2capoutbuf[5] = dcid[1];
+
1307  l2capoutbuf[6] = scid[0];
+
1308  l2capoutbuf[7] = scid[1];
+
1309 
+
1310  L2CAP_Command(handle, l2capoutbuf, 8);
+
1311 }
+
1312 
+
1313 void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
+
1314  l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
+
1315  l2capoutbuf[1] = rxid; // Identifier
+
1316  l2capoutbuf[2] = 0x08; // Length
+
1317  l2capoutbuf[3] = 0x00;
+
1318  l2capoutbuf[4] = infoTypeLow;
+
1319  l2capoutbuf[5] = infoTypeHigh;
+
1320  l2capoutbuf[6] = 0x00; // Result = success
+
1321  l2capoutbuf[7] = 0x00; // Result = success
+
1322  l2capoutbuf[8] = 0x00;
+
1323  l2capoutbuf[9] = 0x00;
+
1324  l2capoutbuf[10] = 0x00;
+
1325  l2capoutbuf[11] = 0x00;
+
1326 
+
1327  L2CAP_Command(handle, l2capoutbuf, 12);
+
1328 }
+
1329 
+
1330 /* PS3 Commands - only set Bluetooth address is implemented in this library */
+
1331 void BTD::setBdaddr(uint8_t* bdaddr) {
+
1332  /* Set the internal Bluetooth address */
+
1333  uint8_t buf[8];
+
1334  buf[0] = 0x01;
+
1335  buf[1] = 0x00;
+
1336 
+
1337  for(uint8_t i = 0; i < 6; i++)
+
1338  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
+
1339 
+
1340  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
1341  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
+
1342 }
1343 
-
1344  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
1345  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
-
1346 }
-
BTD::BTD_DATAOUT_PIPE
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:482
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
-
BTD::incomingWii
bool incomingWii
Definition: BTD.h:432
+
1344 void BTD::setMoveBdaddr(uint8_t* bdaddr) {
+
1345  /* Set the internal Bluetooth address */
+
1346  uint8_t buf[11];
+
1347  buf[0] = 0x05;
+
1348  buf[7] = 0x10;
+
1349  buf[8] = 0x01;
+
1350  buf[9] = 0x02;
+
1351  buf[10] = 0x12;
+
1352 
+
1353  for(uint8_t i = 0; i < 6; i++)
+
1354  buf[i + 1] = bdaddr[i];
+
1355 
+
1356  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
1357  pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
+
1358 }
+
BTD::BTD_DATAOUT_PIPE
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:557
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
+
BTD::incomingWii
bool incomingWii
Definition: BTD.h:507
AddressPool
Definition: address.h:83
-
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1033
-
BTD::bNumEP
uint8_t bNumEP
Definition: BTD.h:471
+
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1045
+
BTD::bNumEP
uint8_t bNumEP
Definition: BTD.h:546
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
BTD::btdName
const char * btdName
Definition: BTD.h:405
-
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:917
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
+
BTD::btdName
const char * btdName
Definition: BTD.h:480
+
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:927
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
HCI_SCANNING_STATE
#define HCI_SCANNING_STATE
Definition: BTD.h:54
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
-
EV_COMMAND_STATUS
#define EV_COMMAND_STATUS
Definition: BTD.h:104
-
EV_REMOTE_NAME_COMPLETE
#define EV_REMOTE_NAME_COMPLETE
Definition: BTD.h:91
+
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
EV_COMMAND_STATUS
#define EV_COMMAND_STATUS
Definition: BTD.h:98
+
EV_REMOTE_NAME_COMPLETE
#define EV_REMOTE_NAME_COMPLETE
Definition: BTD.h:85
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
-
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:400
+
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:475
bmREQ_HCI_OUT
#define bmREQ_HCI_OUT
Definition: BTD.h:36
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
UsbDevice
Definition: address.h:75
-
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:402
-
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:422
-
EV_INQUIRY_COMPLETE
#define EV_INQUIRY_COMPLETE
Definition: BTD.h:85
-
hci_read_bdaddr_complete
#define hci_read_bdaddr_complete
Definition: BTD.h:79
-
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1011
-
BTD::BTD_EVENT_PIPE
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:478
+
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:477
+
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:497
+
USB_DEVICE_DESCRIPTOR::idVendor
uint16_t idVendor
Definition: usb_ch9.h:106
+
EV_INQUIRY_COMPLETE
#define EV_INQUIRY_COMPLETE
Definition: BTD.h:79
+
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1023
+
BTD::BTD_EVENT_PIPE
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:553
PS3MOVE_PID
#define PS3MOVE_PID
Definition: BTD.h:27
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
USB_ENDPOINT_DESCRIPTOR::bInterval
uint8_t bInterval
Definition: usb_ch9.h:147
-
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:434
+
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:509
USB_ENDPOINT_DESCRIPTOR::bLength
uint8_t bLength
Definition: usb_ch9.h:142
-
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:939
+
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
+
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:949
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
HCI_SET_NAME_STATE
#define HCI_SET_NAME_STATE
Definition: BTD.h:47
-
BTD::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:318
-
HCI_FLAG_CONN_COMPLETE
#define HCI_FLAG_CONN_COMPLETE
Definition: BTD.h:64
-
EV_LINK_KEY_REQUEST
#define EV_LINK_KEY_REQUEST
Definition: BTD.h:97
+
BTD::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:314
+
EV_LINK_KEY_REQUEST
#define EV_LINK_KEY_REQUEST
Definition: BTD.h:91
HCI_DONE_STATE
#define HCI_DONE_STATE
Definition: BTD.h:59
-
hci_incoming_connect_request
#define hci_incoming_connect_request
Definition: BTD.h:78
-
EV_DATA_BUFFER_OVERFLOW
#define EV_DATA_BUFFER_OVERFLOW
Definition: BTD.h:99
+
EV_DATA_BUFFER_OVERFLOW
#define EV_DATA_BUFFER_OVERFLOW
Definition: BTD.h:93
HCI_DISCONNECT_STATE
#define HCI_DISCONNECT_STATE
Definition: BTD.h:60
-
hci_device_found
#define hci_device_found
Definition: BTD.h:81
-
EV_PIN_CODE_REQUEST
#define EV_PIN_CODE_REQUEST
Definition: BTD.h:96
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
BTD::btdPin
const char * btdPin
Definition: BTD.h:407
-
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:436
-
EV_AUTHENTICATION_COMPLETE
#define EV_AUTHENTICATION_COMPLETE
Definition: BTD.h:90
-
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:980
-
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:416
-
HCI_FLAG_DISCONN_COMPLETE
#define HCI_FLAG_DISCONN_COMPLETE
Definition: BTD.h:65
+
HCI_FLAG_CONNECT_COMPLETE
#define HCI_FLAG_CONNECT_COMPLETE
Definition: BTD.h:64
+
EV_PIN_CODE_REQUEST
#define EV_PIN_CODE_REQUEST
Definition: BTD.h:90
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
BTD::btdPin
const char * btdPin
Definition: BTD.h:482
+
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:511
+
EV_AUTHENTICATION_COMPLETE
#define EV_AUTHENTICATION_COMPLETE
Definition: BTD.h:84
+
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:992
+
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:491
HCI_FLAG_CONNECT_EVENT
#define HCI_FLAG_CONNECT_EVENT
Definition: BTD.h:71
+
HCI_FLAG_DISCONNECT_COMPLETE
#define HCI_FLAG_DISCONNECT_COMPLETE
Definition: BTD.h:65
HCI_REMOTE_NAME_STATE
#define HCI_REMOTE_NAME_STATE
Definition: BTD.h:56
USB_ERROR_FailGetDevDescr
#define USB_ERROR_FailGetDevDescr
Definition: UsbCore.h:73
HCI_FLAG_CMD_COMPLETE
#define HCI_FLAG_CMD_COMPLETE
Definition: BTD.h:63
@@ -1496,144 +1507,143 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
hrJERR
#define hrJERR
Definition: max3421e.h:225
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
BluetoothService::Reset
virtual void Reset()
-
EV_MAX_SLOTS_CHANGE
#define EV_MAX_SLOTS_CHANGE
Definition: BTD.h:100
-
BTD::BTD_DATAIN_PIPE
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:480
-
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:999
-
EV_QOS_SETUP_COMPLETE
#define EV_QOS_SETUP_COMPLETE
Definition: BTD.h:102
-
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:926
-
BTD::Release
virtual uint8_t Release()
Definition: BTD.cpp:369
+
EV_MAX_SLOTS_CHANGE
#define EV_MAX_SLOTS_CHANGE
Definition: BTD.h:94
+
BTD::BTD_DATAIN_PIPE
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:555
+
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1011
+
EV_QOS_SETUP_COMPLETE
#define EV_QOS_SETUP_COMPLETE
Definition: BTD.h:96
+
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:936
+
BTD::Release
virtual uint8_t Release()
Definition: BTD.cpp:365
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
-
BTD::watingForConnection
bool watingForConnection
Definition: BTD.h:396
+
BTD::watingForConnection
bool watingForConnection
Definition: BTD.h:471
HCI_BDADDR_STATE
#define HCI_BDADDR_STATE
Definition: BTD.h:45
HCI_CONNECT_DEVICE_STATE
#define HCI_CONNECT_DEVICE_STATE
Definition: BTD.h:51
Notify
#define Notify(...)
Definition: message.h:44
-
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:444
+
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:519
USB_ENDPOINT_DESCRIPTOR::bmAttributes
uint8_t bmAttributes
Definition: usb_ch9.h:145
-
ConfigDescParser
Definition: confdescparser.h:39
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
-
BTD::bAddress
uint8_t bAddress
Definition: BTD.h:464
+
ConfigDescParser
Definition: confdescparser.h:38
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
+
BTD::bAddress
uint8_t bAddress
Definition: BTD.h:539
NotifyFailGetConfDescr
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
-
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:448
+
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:523
NotifyFailUnknownDevice
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
-
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:450
-
hci_remote_name_complete
#define hci_remote_name_complete
Definition: BTD.h:77
-
BTD::qNextPollTime
uint32_t qNextPollTime
Definition: BTD.h:473
+
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:525
+
BTD::qNextPollTime
uint32_t qNextPollTime
Definition: BTD.h:548
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
EV_CONNECT_COMPLETE
#define EV_CONNECT_COMPLETE
Definition: BTD.h:87
-
BTD::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:350
-
EV_DISCONNECT_COMPLETE
#define EV_DISCONNECT_COMPLETE
Definition: BTD.h:89
+
EV_CONNECT_COMPLETE
#define EV_CONNECT_COMPLETE
Definition: BTD.h:81
+
BTD::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:346
+
EV_DISCONNECT_COMPLETE
#define EV_DISCONNECT_COMPLETE
Definition: BTD.h:83
HCI_FLAG_READ_BDADDR
#define HCI_FLAG_READ_BDADDR
Definition: BTD.h:68
-
hci_read_version_complete
#define hci_read_version_complete
Definition: BTD.h:80
IOGEAR_GBU521_PID
#define IOGEAR_GBU521_PID
Definition: BTD.h:30
-
BTD::connectToWii
bool connectToWii
Definition: BTD.h:428
+
BTD::connectToWii
bool connectToWii
Definition: BTD.h:503
BTD::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:48
HCI_LOCAL_VERSION_STATE
#define HCI_LOCAL_VERSION_STATE
Definition: BTD.h:46
-
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:438
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
-
BTD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:121
+
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:513
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
+
BTD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:122
Notifyc
#define Notifyc(...)
Definition: message.h:46
EpInfo
Definition: address.h:32
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
HCI_RESET_STATE
#define HCI_RESET_STATE
Definition: BTD.h:43
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
hrNAK
#define hrNAK
Definition: max3421e.h:216
-
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:948
-
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1025
-
L2CAP_CMD_INFORMATION_RESPONSE
#define L2CAP_CMD_INFORMATION_RESPONSE
Definition: BTD.h:117
+
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:958
+
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1037
+
L2CAP_CMD_INFORMATION_RESPONSE
#define L2CAP_CMD_INFORMATION_RESPONSE
Definition: BTD.h:173
USB_ENDPOINT_DESCRIPTOR::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
-
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:410
+
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:485
HID_REQUEST_SET_REPORT
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
-
EV_INCOMING_CONNECT
#define EV_INCOMING_CONNECT
Definition: BTD.h:88
+
EV_INCOMING_CONNECT
#define EV_INCOMING_CONNECT
Definition: BTD.h:82
HCI_CONNECT_IN_STATE
#define HCI_CONNECT_IN_STATE
Definition: BTD.h:55
HCI_INQUIRY_STATE
#define HCI_INQUIRY_STATE
Definition: BTD.h:50
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
USB_ENDPOINT_DESCRIPTOR::bEndpointAddress
uint8_t bEndpointAddress
Definition: usb_ch9.h:144
HCI_CONNECTED_STATE
#define HCI_CONNECTED_STATE
Definition: BTD.h:57
-
EV_INQUIRY_RESULT
#define EV_INQUIRY_RESULT
Definition: BTD.h:86
+
EV_INQUIRY_RESULT
#define EV_INQUIRY_RESULT
Definition: BTD.h:80
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
BTD::Poll
virtual uint8_t Poll()
Definition: BTD.cpp:375
-
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
BTD::BTD_CONTROL_PIPE
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:476
+
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:168
+
BTD::Poll
virtual uint8_t Poll()
Definition: BTD.cpp:371
+
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:170
+
BTD::BTD_CONTROL_PIPE
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:551
USB_ENDPOINT_DESCRIPTOR::bDescriptorType
uint8_t bDescriptorType
Definition: usb_ch9.h:143
-
hci_cmd_complete
#define hci_cmd_complete
Definition: BTD.h:74
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
HCI_FLAG_READ_VERSION
#define HCI_FLAG_READ_VERSION
Definition: BTD.h:69
-
BTD::disc_bdaddr
uint8_t disc_bdaddr[6]
Definition: BTD.h:414
-
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:398
+
BTD::disc_bdaddr
uint8_t disc_bdaddr[6]
Definition: BTD.h:489
+
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:473
USB_NAK_NOWAIT
#define USB_NAK_NOWAIT
Definition: address.h:29
HCI_FLAG_INCOMING_REQUEST
#define HCI_FLAG_INCOMING_REQUEST
Definition: BTD.h:67
-
EV_NUM_COMPLETE_PKT
#define EV_NUM_COMPLETE_PKT
Definition: BTD.h:95
+
EV_NUM_COMPLETE_PKT
#define EV_NUM_COMPLETE_PKT
Definition: BTD.h:89
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
-
BTD::epInfo
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:466
+
BTD::epInfo
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:541
IOGEAR_GBU521_VID
#define IOGEAR_GBU521_VID
Definition: BTD.h:29
BluetoothService::ACLData
virtual void ACLData(uint8_t *ACLData)
PS3_PID
#define PS3_PID
Definition: BTD.h:25
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
-
BTD_MAX_ENDPOINTS
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:133
+
BTD_MAX_ENDPOINTS
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:189
PS3NAVIGATION_PID
#define PS3NAVIGATION_PID
Definition: BTD.h:26
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
-
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:115
-
EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
#define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
Definition: BTD.h:101
-
EV_COMMAND_COMPLETE
#define EV_COMMAND_COMPLETE
Definition: BTD.h:103
-
hci_connect_event
#define hci_connect_event
Definition: BTD.h:82
-
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1301
-
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:111
-
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1145
+
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
+
EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
#define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE
Definition: BTD.h:95
+
EV_COMMAND_COMPLETE
#define EV_COMMAND_COMPLETE
Definition: BTD.h:97
+
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1313
+
USB_DEVICE_DESCRIPTOR::idProduct
uint16_t idProduct
Definition: usb_ch9.h:107
+
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:167
+
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
+
hci_set_flag
#define hci_set_flag(flag)
Definition: BTD.h:75
+
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1157
HCI_CONNECTED_DEVICE_STATE
#define HCI_CONNECTED_DEVICE_STATE
Definition: BTD.h:52
HCI_INIT_STATE
#define HCI_INIT_STATE
Definition: BTD.h:42
bmREQ_HID_OUT
#define bmREQ_HID_OUT
Definition: BTD.h:38
-
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1095
-
EV_CHANGE_CONNECTION_LINK
#define EV_CHANGE_CONNECTION_LINK
Definition: BTD.h:93
+
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1107
+
EV_CHANGE_CONNECTION_LINK
#define EV_CHANGE_CONNECTION_LINK
Definition: BTD.h:87
+
USB_DEVICE_DESCRIPTOR::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:112
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
-
EV_ROLE_CHANGED
#define EV_ROLE_CHANGED
Definition: BTD.h:94
+
hci_check_flag
#define hci_check_flag(flag)
Definition: BTD.h:74
+
EV_ROLE_CHANGED
#define EV_ROLE_CHANGED
Definition: BTD.h:88
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
HCI_CHECK_DEVICE_SERVICE
#define HCI_CHECK_DEVICE_SERVICE
Definition: BTD.h:48
-
USB
Definition: UsbCore.h:152
+
USB
Definition: UsbCore.h:176
BluetoothService::Run
virtual void Run()
-
BTD::bConfNum
uint8_t bConfNum
Definition: BTD.h:469
-
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1109
-
hci_connect_complete
#define hci_connect_complete
Definition: BTD.h:75
-
EV_LOOPBACK_COMMAND
#define EV_LOOPBACK_COMMAND
Definition: BTD.h:105
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD_NUMSERVICES
#define BTD_NUMSERVICES
Definition: BTD.h:134
-
EV_LINK_KEY_NOTIFICATION
#define EV_LINK_KEY_NOTIFICATION
Definition: BTD.h:98
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1059
-
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
+
BTD::bConfNum
uint8_t bConfNum
Definition: BTD.h:544
+
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1121
+
EV_LOOPBACK_COMMAND
#define EV_LOOPBACK_COMMAND
Definition: BTD.h:99
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD_NUMSERVICES
#define BTD_NUMSERVICES
Definition: BTD.h:190
+
EV_LINK_KEY_NOTIFICATION
#define EV_LINK_KEY_NOTIFICATION
Definition: BTD.h:92
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1071
+
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
BTD.h
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
-
EV_ENCRYPTION_CHANGE
#define EV_ENCRYPTION_CHANGE
Definition: BTD.h:92
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
+
EV_ENCRYPTION_CHANGE
#define EV_ENCRYPTION_CHANGE
Definition: BTD.h:86
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
BTD::pUsb
USB * pUsb
Definition: BTD.h:458
+
hci_clear_flag
#define hci_clear_flag(flag)
Definition: BTD.h:76
+
BTD::pUsb
USB * pUsb
Definition: BTD.h:533
NotifyStr
#define NotifyStr(...)
Definition: message.h:45
-
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1123
-
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:956
+
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1135
+
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:967
HCI_FLAG_REMOTE_NAME_COMPLETE
#define HCI_FLAG_REMOTE_NAME_COMPLETE
Definition: BTD.h:66
-
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:964
-
EV_PAGE_SCAN_REP_MODE
#define EV_PAGE_SCAN_REP_MODE
Definition: BTD.h:106
-
hci_disconnect_complete
#define hci_disconnect_complete
Definition: BTD.h:76
+
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:976
+
EV_PAGE_SCAN_REP_MODE
#define EV_PAGE_SCAN_REP_MODE
Definition: BTD.h:100
HCI_FLAG_DEVICE_FOUND
#define HCI_FLAG_DEVICE_FOUND
Definition: BTD.h:70
HCI_CLASS_STATE
#define HCI_CLASS_STATE
Definition: BTD.h:44
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
-
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:912
+
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:922
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/_b_t_d_8h.html b/_b_t_d_8h.html index a3726579..7e8ccfbd 100644 --- a/_b_t_d_8h.html +++ b/_b_t_d_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTD.h File Reference @@ -31,7 +31,7 @@ - + @@ -105,7 +105,7 @@ This graph shows which files directly or indirectly include this file:
- +

Go to the source code of this file.

@@ -175,10 +175,10 @@ Macros   #define HCI_FLAG_CMD_COMPLETE   0x01   -#define HCI_FLAG_CONN_COMPLETE   0x02 -  -#define HCI_FLAG_DISCONN_COMPLETE   0x04 -  +#define HCI_FLAG_CONNECT_COMPLETE   0x02 +  +#define HCI_FLAG_DISCONNECT_COMPLETE   0x04 +  #define HCI_FLAG_REMOTE_NAME_COMPLETE   0x08   #define HCI_FLAG_INCOMING_REQUEST   0x10 @@ -191,24 +191,12 @@ Macros   #define HCI_FLAG_CONNECT_EVENT   0x100   -#define hci_cmd_complete   (hci_event_flag & HCI_FLAG_CMD_COMPLETE) -  -#define hci_connect_complete   (hci_event_flag & HCI_FLAG_CONN_COMPLETE) -  -#define hci_disconnect_complete   (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE) -  -#define hci_remote_name_complete   (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE) -  -#define hci_incoming_connect_request   (hci_event_flag & HCI_FLAG_INCOMING_REQUEST) -  -#define hci_read_bdaddr_complete   (hci_event_flag & HCI_FLAG_READ_BDADDR) -  -#define hci_read_version_complete   (hci_event_flag & HCI_FLAG_READ_VERSION) -  -#define hci_device_found   (hci_event_flag & HCI_FLAG_DEVICE_FOUND) -  -#define hci_connect_event   (hci_event_flag & HCI_FLAG_CONNECT_EVENT) -  +#define hci_check_flag(flag)   (hci_event_flag & (flag)) +  +#define hci_set_flag(flag)   (hci_event_flag |= (flag)) +  +#define hci_clear_flag(flag)   (hci_event_flag &= ~(flag)) +  #define EV_INQUIRY_COMPLETE   0x01   #define EV_INQUIRY_RESULT   0x02 @@ -253,6 +241,82 @@ Macros   #define EV_PAGE_SCAN_REP_MODE   0x20   +#define L2CAP_WAIT   0 +  +#define L2CAP_DONE   1 +  +#define L2CAP_CONTROL_CONNECT_REQUEST   2 +  +#define L2CAP_CONTROL_CONFIG_REQUEST   3 +  +#define L2CAP_CONTROL_SUCCESS   4 +  +#define L2CAP_CONTROL_DISCONNECT   5 +  +#define L2CAP_INTERRUPT_SETUP   6 +  +#define L2CAP_INTERRUPT_CONNECT_REQUEST   7 +  +#define L2CAP_INTERRUPT_CONFIG_REQUEST   8 +  +#define L2CAP_INTERRUPT_DISCONNECT   9 +  +#define L2CAP_SDP_WAIT   10 +  +#define L2CAP_SDP_SUCCESS   11 +  +#define L2CAP_RFCOMM_WAIT   12 +  +#define L2CAP_RFCOMM_SUCCESS   13 +  +#define L2CAP_DISCONNECT_RESPONSE   14 +  +#define TURN_ON_LED   17 +  +#define PS3_ENABLE_SIXAXIS   18 +  +#define WII_CHECK_MOTION_PLUS_STATE   19 +  +#define WII_CHECK_EXTENSION_STATE   20 +  +#define WII_INIT_MOTION_PLUS_STATE   21 +  +#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x00000001 +  +#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x00000002 +  +#define L2CAP_FLAG_CONTROL_CONNECTED   0x00000004 +  +#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x00000008 +  +#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x00000010 +  +#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x00000020 +  +#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x00000040 +  +#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x00000080 +  +#define L2CAP_FLAG_CONNECTION_SDP_REQUEST   0x00000100 +  +#define L2CAP_FLAG_CONFIG_SDP_SUCCESS   0x00000200 +  +#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST   0x00000400 +  +#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST   0x00000800 +  +#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS   0x00001000 +  +#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST   0x00002000 +  +#define L2CAP_FLAG_DISCONNECT_RESPONSE   0x00004000 +  +#define l2cap_check_flag(flag)   (l2cap_event_flag & (flag)) +  +#define l2cap_set_flag(flag)   (l2cap_event_flag |= (flag)) +  +#define l2cap_clear_flag(flag)   (l2cap_event_flag &= ~(flag)) +  #define L2CAP_CMD_COMMAND_REJECT   0x01   #define L2CAP_CMD_CONNECTION_REQUEST   0x02 @@ -293,6 +357,8 @@ Macros   #define PAIR   1   +#define UHS_ACL_HANDLE_OK(x, y)   ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20))) + 

Macro Definition Documentation

@@ -687,12 +753,12 @@ Macros - +
- +
#define HCI_FLAG_CONN_COMPLETE   0x02#define HCI_FLAG_CONNECT_COMPLETE   0x02
@@ -701,12 +767,12 @@ Macros
- +
- +
#define HCI_FLAG_DISCONN_COMPLETE   0x04#define HCI_FLAG_DISCONNECT_COMPLETE   0x04
@@ -799,12 +865,16 @@ Macros
- +
- + + + + +
#define hci_cmd_complete   (hci_event_flag & HCI_FLAG_CMD_COMPLETE)#define hci_check_flag( flag)   (hci_event_flag & (flag))
@@ -813,12 +883,16 @@ Macros
- +
- + + + + +
#define hci_connect_complete   (hci_event_flag & HCI_FLAG_CONN_COMPLETE)#define hci_set_flag( flag)   (hci_event_flag |= (flag))
@@ -827,102 +901,22 @@ Macros
- +
- + + + + +
#define hci_disconnect_complete   (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)#define hci_clear_flag( flag)   (hci_event_flag &= ~(flag))

Definition at line 76 of file BTD.h.

-
-
- -
-
- - - - -
#define hci_remote_name_complete   (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
-
- -

Definition at line 77 of file BTD.h.

- -
-
- -
-
- - - - -
#define hci_incoming_connect_request   (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
-
- -

Definition at line 78 of file BTD.h.

- -
-
- -
-
- - - - -
#define hci_read_bdaddr_complete   (hci_event_flag & HCI_FLAG_READ_BDADDR)
-
- -

Definition at line 79 of file BTD.h.

- -
-
- -
-
- - - - -
#define hci_read_version_complete   (hci_event_flag & HCI_FLAG_READ_VERSION)
-
- -

Definition at line 80 of file BTD.h.

- -
-
- -
-
- - - - -
#define hci_device_found   (hci_event_flag & HCI_FLAG_DEVICE_FOUND)
-
- -

Definition at line 81 of file BTD.h.

- -
-
- -
-
- - - - -
#define hci_connect_event   (hci_event_flag & HCI_FLAG_CONNECT_EVENT)
-
- -

Definition at line 82 of file BTD.h.

-
@@ -935,7 +929,7 @@ Macros
-

Definition at line 85 of file BTD.h.

+

Definition at line 79 of file BTD.h.

@@ -949,7 +943,7 @@ Macros
-

Definition at line 86 of file BTD.h.

+

Definition at line 80 of file BTD.h.

@@ -963,7 +957,7 @@ Macros
-

Definition at line 87 of file BTD.h.

+

Definition at line 81 of file BTD.h.

@@ -977,7 +971,7 @@ Macros
-

Definition at line 88 of file BTD.h.

+

Definition at line 82 of file BTD.h.

@@ -991,7 +985,7 @@ Macros
-

Definition at line 89 of file BTD.h.

+

Definition at line 83 of file BTD.h.

@@ -1005,7 +999,7 @@ Macros
-

Definition at line 90 of file BTD.h.

+

Definition at line 84 of file BTD.h.

@@ -1019,7 +1013,7 @@ Macros
-

Definition at line 91 of file BTD.h.

+

Definition at line 85 of file BTD.h.

@@ -1033,7 +1027,7 @@ Macros
-

Definition at line 92 of file BTD.h.

+

Definition at line 86 of file BTD.h.

@@ -1047,7 +1041,7 @@ Macros
-

Definition at line 93 of file BTD.h.

+

Definition at line 87 of file BTD.h.

@@ -1061,7 +1055,7 @@ Macros
-

Definition at line 94 of file BTD.h.

+

Definition at line 88 of file BTD.h.

@@ -1075,7 +1069,7 @@ Macros
-

Definition at line 95 of file BTD.h.

+

Definition at line 89 of file BTD.h.

@@ -1089,7 +1083,7 @@ Macros
-

Definition at line 96 of file BTD.h.

+

Definition at line 90 of file BTD.h.

@@ -1103,7 +1097,7 @@ Macros
-

Definition at line 97 of file BTD.h.

+

Definition at line 91 of file BTD.h.

@@ -1117,7 +1111,7 @@ Macros
-

Definition at line 98 of file BTD.h.

+

Definition at line 92 of file BTD.h.

@@ -1131,7 +1125,7 @@ Macros
-

Definition at line 99 of file BTD.h.

+

Definition at line 93 of file BTD.h.

@@ -1145,7 +1139,7 @@ Macros
-

Definition at line 100 of file BTD.h.

+

Definition at line 94 of file BTD.h.

@@ -1159,7 +1153,7 @@ Macros
-

Definition at line 101 of file BTD.h.

+

Definition at line 95 of file BTD.h.

@@ -1173,7 +1167,7 @@ Macros
-

Definition at line 102 of file BTD.h.

+

Definition at line 96 of file BTD.h.

@@ -1187,7 +1181,7 @@ Macros
-

Definition at line 103 of file BTD.h.

+

Definition at line 97 of file BTD.h.

@@ -1201,7 +1195,7 @@ Macros
-

Definition at line 104 of file BTD.h.

+

Definition at line 98 of file BTD.h.

@@ -1215,7 +1209,7 @@ Macros
-

Definition at line 105 of file BTD.h.

+

Definition at line 99 of file BTD.h.

@@ -1229,7 +1223,551 @@ Macros
-

Definition at line 106 of file BTD.h.

+

Definition at line 100 of file BTD.h.

+ +
+ + +
+
+ + + + +
#define L2CAP_WAIT   0
+
+ +

Definition at line 103 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_DONE   1
+
+ +

Definition at line 104 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_CONTROL_CONNECT_REQUEST   2
+
+ +

Definition at line 107 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_CONTROL_CONFIG_REQUEST   3
+
+ +

Definition at line 108 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_CONTROL_SUCCESS   4
+
+ +

Definition at line 109 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_CONTROL_DISCONNECT   5
+
+ +

Definition at line 110 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_INTERRUPT_SETUP   6
+
+ +

Definition at line 113 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_INTERRUPT_CONNECT_REQUEST   7
+
+ +

Definition at line 114 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_INTERRUPT_CONFIG_REQUEST   8
+
+ +

Definition at line 115 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_INTERRUPT_DISCONNECT   9
+
+ +

Definition at line 116 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_SDP_WAIT   10
+
+ +

Definition at line 119 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_SDP_SUCCESS   11
+
+ +

Definition at line 120 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_RFCOMM_WAIT   12
+
+ +

Definition at line 123 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_RFCOMM_SUCCESS   13
+
+ +

Definition at line 124 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_DISCONNECT_RESPONSE   14
+
+ +

Definition at line 126 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define TURN_ON_LED   17
+
+ +

Definition at line 129 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define PS3_ENABLE_SIXAXIS   18
+
+ +

Definition at line 130 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define WII_CHECK_MOTION_PLUS_STATE   19
+
+ +

Definition at line 131 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define WII_CHECK_EXTENSION_STATE   20
+
+ +

Definition at line 132 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define WII_INIT_MOTION_PLUS_STATE   21
+
+ +

Definition at line 133 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x00000001
+
+ +

Definition at line 136 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x00000002
+
+ +

Definition at line 137 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONTROL_CONNECTED   0x00000004
+
+ +

Definition at line 138 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x00000008
+
+ +

Definition at line 139 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x00000010
+
+ +

Definition at line 142 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x00000020
+
+ +

Definition at line 143 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x00000040
+
+ +

Definition at line 144 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x00000080
+
+ +

Definition at line 145 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST   0x00000100
+
+ +

Definition at line 148 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS   0x00000200
+
+ +

Definition at line 149 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST   0x00000400
+
+ +

Definition at line 150 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST   0x00000800
+
+ +

Definition at line 153 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS   0x00001000
+
+ +

Definition at line 154 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST   0x00002000
+
+ +

Definition at line 155 of file BTD.h.

+ +
+
+ +
+
+ + + + +
#define L2CAP_FLAG_DISCONNECT_RESPONSE   0x00004000
+
+ +

Definition at line 157 of file BTD.h.

+ +
+
+ +
+
+ + + + + + + + +
#define l2cap_check_flag( flag)   (l2cap_event_flag & (flag))
+
+ +

Definition at line 160 of file BTD.h.

+ +
+
+ +
+
+ + + + + + + + +
#define l2cap_set_flag( flag)   (l2cap_event_flag |= (flag))
+
+ +

Definition at line 161 of file BTD.h.

+ +
+
+ +
+
+ + + + + + + + +
#define l2cap_clear_flag( flag)   (l2cap_event_flag &= ~(flag))
+
+ +

Definition at line 162 of file BTD.h.

@@ -1243,7 +1781,7 @@ Macros
-

Definition at line 109 of file BTD.h.

+

Definition at line 165 of file BTD.h.

@@ -1257,7 +1795,7 @@ Macros
-

Definition at line 110 of file BTD.h.

+

Definition at line 166 of file BTD.h.

@@ -1271,7 +1809,7 @@ Macros
-

Definition at line 111 of file BTD.h.

+

Definition at line 167 of file BTD.h.

@@ -1285,7 +1823,7 @@ Macros
-

Definition at line 112 of file BTD.h.

+

Definition at line 168 of file BTD.h.

@@ -1299,7 +1837,7 @@ Macros
-

Definition at line 113 of file BTD.h.

+

Definition at line 169 of file BTD.h.

@@ -1313,7 +1851,7 @@ Macros
-

Definition at line 114 of file BTD.h.

+

Definition at line 170 of file BTD.h.

@@ -1327,7 +1865,7 @@ Macros
-

Definition at line 115 of file BTD.h.

+

Definition at line 171 of file BTD.h.

@@ -1341,7 +1879,7 @@ Macros
-

Definition at line 116 of file BTD.h.

+

Definition at line 172 of file BTD.h.

@@ -1355,7 +1893,7 @@ Macros
-

Definition at line 117 of file BTD.h.

+

Definition at line 173 of file BTD.h.

@@ -1369,7 +1907,7 @@ Macros
-

Definition at line 120 of file BTD.h.

+

Definition at line 176 of file BTD.h.

@@ -1383,7 +1921,7 @@ Macros
-

Definition at line 121 of file BTD.h.

+

Definition at line 177 of file BTD.h.

@@ -1397,7 +1935,7 @@ Macros
-

Definition at line 124 of file BTD.h.

+

Definition at line 180 of file BTD.h.

@@ -1411,7 +1949,7 @@ Macros
-

Definition at line 125 of file BTD.h.

+

Definition at line 181 of file BTD.h.

@@ -1425,7 +1963,7 @@ Macros
-

Definition at line 126 of file BTD.h.

+

Definition at line 182 of file BTD.h.

@@ -1439,7 +1977,7 @@ Macros
-

Definition at line 127 of file BTD.h.

+

Definition at line 183 of file BTD.h.

@@ -1453,7 +1991,7 @@ Macros
-

Definition at line 130 of file BTD.h.

+

Definition at line 186 of file BTD.h.

@@ -1467,7 +2005,7 @@ Macros
-

Definition at line 131 of file BTD.h.

+

Definition at line 187 of file BTD.h.

@@ -1481,7 +2019,7 @@ Macros
-

Definition at line 133 of file BTD.h.

+

Definition at line 189 of file BTD.h.

@@ -1495,7 +2033,7 @@ Macros
-

Definition at line 134 of file BTD.h.

+

Definition at line 190 of file BTD.h.

@@ -1509,7 +2047,35 @@ Macros
-

Definition at line 136 of file BTD.h.

+

Definition at line 192 of file BTD.h.

+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + +
#define UHS_ACL_HANDLE_OK( x,
 
)   ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20)))
+
+ +

Definition at line 207 of file BTD.h.

@@ -1518,7 +2084,7 @@ Macros diff --git a/_b_t_d_8h__dep__incl.map b/_b_t_d_8h__dep__incl.map index 4800756d..792f0e4d 100644 --- a/_b_t_d_8h__dep__incl.map +++ b/_b_t_d_8h__dep__incl.map @@ -1,11 +1,13 @@ - - - - - - - - - + + + + + + + + + + + diff --git a/_b_t_d_8h__dep__incl.md5 b/_b_t_d_8h__dep__incl.md5 index 9aa56dc0..01d32675 100644 --- a/_b_t_d_8h__dep__incl.md5 +++ b/_b_t_d_8h__dep__incl.md5 @@ -1 +1 @@ -733ffa9984cd5bf95cd4137ba4b743af \ No newline at end of file +359d0fb9802ea91c25ab343278928ac0 \ No newline at end of file diff --git a/_b_t_d_8h__dep__incl.png b/_b_t_d_8h__dep__incl.png index 816ed240..7b28b330 100644 Binary files a/_b_t_d_8h__dep__incl.png and b/_b_t_d_8h__dep__incl.png differ diff --git a/_b_t_d_8h_source.html b/_b_t_d_8h_source.html index 325ef5f2..c6e00629 100644 --- a/_b_t_d_8h_source.html +++ b/_b_t_d_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTD.h Source File @@ -31,7 +31,7 @@ - + @@ -121,7 +121,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
30 #define IOGEAR_GBU521_PID 0x21E8
31 
32 /* Bluetooth dongle data taken from descriptors */
-
33 #define BULK_MAXPKTSIZE 64 // max size for ACL data
+
33 #define BULK_MAXPKTSIZE 64 // Max size for ACL data
34 
35 // Used in control endpoint header for HCI Commands
36 #define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
@@ -138,7 +138,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
47 #define HCI_SET_NAME_STATE 5
48 #define HCI_CHECK_DEVICE_SERVICE 6
49 
-
50 #define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a Wii controller
+
50 #define HCI_INQUIRY_STATE 7 // These three states are only used if it should pair and connect to a device
51 #define HCI_CONNECT_DEVICE_STATE 8
52 #define HCI_CONNECTED_DEVICE_STATE 9
53 
@@ -152,8 +152,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
61 
62 /* HCI event flags*/
63 #define HCI_FLAG_CMD_COMPLETE 0x01
-
64 #define HCI_FLAG_CONN_COMPLETE 0x02
-
65 #define HCI_FLAG_DISCONN_COMPLETE 0x04
+
64 #define HCI_FLAG_CONNECT_COMPLETE 0x02
+
65 #define HCI_FLAG_DISCONNECT_COMPLETE 0x04
66 #define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08
67 #define HCI_FLAG_INCOMING_REQUEST 0x10
68 #define HCI_FLAG_READ_BDADDR 0x20
@@ -161,332 +161,410 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
70 #define HCI_FLAG_DEVICE_FOUND 0x80
71 #define HCI_FLAG_CONNECT_EVENT 0x100
72 
-
73 /*Macros for HCI event flag tests */
-
74 #define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE)
-
75 #define hci_connect_complete (hci_event_flag & HCI_FLAG_CONN_COMPLETE)
-
76 #define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)
-
77 #define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
-
78 #define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
-
79 #define hci_read_bdaddr_complete (hci_event_flag & HCI_FLAG_READ_BDADDR)
-
80 #define hci_read_version_complete (hci_event_flag & HCI_FLAG_READ_VERSION)
-
81 #define hci_device_found (hci_event_flag & HCI_FLAG_DEVICE_FOUND)
-
82 #define hci_connect_event (hci_event_flag & HCI_FLAG_CONNECT_EVENT)
-
83 
-
84 /* HCI Events managed */
-
85 #define EV_INQUIRY_COMPLETE 0x01
-
86 #define EV_INQUIRY_RESULT 0x02
-
87 #define EV_CONNECT_COMPLETE 0x03
-
88 #define EV_INCOMING_CONNECT 0x04
-
89 #define EV_DISCONNECT_COMPLETE 0x05
-
90 #define EV_AUTHENTICATION_COMPLETE 0x06
-
91 #define EV_REMOTE_NAME_COMPLETE 0x07
-
92 #define EV_ENCRYPTION_CHANGE 0x08
-
93 #define EV_CHANGE_CONNECTION_LINK 0x09
-
94 #define EV_ROLE_CHANGED 0x12
-
95 #define EV_NUM_COMPLETE_PKT 0x13
-
96 #define EV_PIN_CODE_REQUEST 0x16
-
97 #define EV_LINK_KEY_REQUEST 0x17
-
98 #define EV_LINK_KEY_NOTIFICATION 0x18
-
99 #define EV_DATA_BUFFER_OVERFLOW 0x1A
-
100 #define EV_MAX_SLOTS_CHANGE 0x1B
-
101 #define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
-
102 #define EV_QOS_SETUP_COMPLETE 0x0D
-
103 #define EV_COMMAND_COMPLETE 0x0E
-
104 #define EV_COMMAND_STATUS 0x0F
-
105 #define EV_LOOPBACK_COMMAND 0x19
-
106 #define EV_PAGE_SCAN_REP_MODE 0x20
-
107 
-
108 /* L2CAP signaling commands */
-
109 #define L2CAP_CMD_COMMAND_REJECT 0x01
-
110 #define L2CAP_CMD_CONNECTION_REQUEST 0x02
-
111 #define L2CAP_CMD_CONNECTION_RESPONSE 0x03
-
112 #define L2CAP_CMD_CONFIG_REQUEST 0x04
-
113 #define L2CAP_CMD_CONFIG_RESPONSE 0x05
-
114 #define L2CAP_CMD_DISCONNECT_REQUEST 0x06
-
115 #define L2CAP_CMD_DISCONNECT_RESPONSE 0x07
-
116 #define L2CAP_CMD_INFORMATION_REQUEST 0x0A
-
117 #define L2CAP_CMD_INFORMATION_RESPONSE 0x0B
-
118 
-
119 // Used For Connection Response - Remember to Include High Byte
-
120 #define PENDING 0x01
-
121 #define SUCCESSFUL 0x00
-
122 
-
123 /* Bluetooth L2CAP PSM - see http://www.bluetooth.org/Technical/AssignedNumbers/logical_link.htm */
-
124 #define SDP_PSM 0x01 // Service Discovery Protocol PSM Value
-
125 #define RFCOMM_PSM 0x03 // RFCOMM PSM Value
-
126 #define HID_CTRL_PSM 0x11 // HID_Control PSM Value
-
127 #define HID_INTR_PSM 0x13 // HID_Interrupt PSM Value
-
128 
-
129 // Used to determine if it is a Bluetooth dongle
-
130 #define WI_SUBCLASS_RF 0x01 // RF Controller
-
131 #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
-
132 
-
133 #define BTD_MAX_ENDPOINTS 4
-
134 #define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than four simply increase this number
-
135 
-
136 #define PAIR 1
-
137 
-
139 class BluetoothService {
-
140 public:
-
145  virtual void ACLData(uint8_t* ACLData);
-
147  virtual void Run();
-
149  virtual void Reset();
-
151  virtual void disconnect();
-
152 };
-
153 
-
158 class BTD : public USBDeviceConfig, public UsbConfigXtracter {
-
159 public:
-
164  BTD(USB *p);
-
165 
-
174  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
-
182  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
-
187  virtual uint8_t Release();
-
192  virtual uint8_t Poll();
-
193 
-
198  virtual uint8_t GetAddress() {
-
199  return bAddress;
-
200  };
-
201 
-
206  virtual bool isReady() {
-
207  return bPollEnable;
-
208  };
-
214  virtual boolean DEVCLASSOK(uint8_t klass) { return (klass == USB_CLASS_WIRELESS_CTRL); }
-
215 
-
223  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
-
224  if (vid == IOGEAR_GBU521_VID && pid == IOGEAR_GBU521_PID)
-
225  return true;
-
226  if (my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) { // Check if Bluetooth address is set
-
227  if (vid == PS3_VID && (pid == PS3_PID || pid == PS3NAVIGATION_PID || pid == PS3MOVE_PID))
-
228  return true;
-
229  }
-
230  return false;
-
231  };
-
243  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
-
247  void disconnect() {
-
248  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
-
249  if(btService[i])
-
250  btService[i]->disconnect();
-
251  };
-
252 
-
258  int8_t registerServiceClass(BluetoothService *pService) {
-
259  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
-
260  if(!btService[i]) {
-
261  btService[i] = pService;
-
262  return i; // Return ID
-
263  }
-
264  }
-
265  return -1; // ErrorregisterServiceClass
-
266  };
-
267 
-
274  void HCI_Command(uint8_t* data, uint16_t nbytes);
-
276  void hci_reset();
-
278  void hci_read_bdaddr();
-
280  void hci_read_local_version_information();
-
285  void hci_set_local_name(const char* name);
-
287  void hci_write_scan_enable();
-
289  void hci_write_scan_disable();
-
291  void hci_remote_name();
-
293  void hci_accept_connection();
-
298  void hci_disconnect(uint16_t handle);
-
304  void hci_pin_code_request_reply();
-
306  void hci_pin_code_negative_request_reply();
-
311  void hci_link_key_request_negative_reply();
-
313  void hci_authentication_request();
-
315  void hci_inquiry();
-
317  void hci_inquiry_cancel();
-
319  void hci_connect();
-
324  void hci_connect(uint8_t *bdaddr);
-
326  void hci_write_class_of_device();
-
338  void L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00);
-
346  void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm);
-
355  void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result);
-
362  void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid);
-
369  void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid);
-
377  void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
-
385  void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
-
392  void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh);
-
396  bool watingForConnection;
-
398  bool l2capConnectionClaimed;
-
400  bool sdpConnectionClaimed;
-
402  bool rfcommConnectionClaimed;
-
403 
-
405  const char* btdName;
-
407  const char* btdPin;
-
408 
-
410  uint8_t my_bdaddr[6];
-
412  uint16_t hci_handle;
-
414  uint8_t disc_bdaddr[6];
-
416  uint8_t remote_name[30];
-
422  uint8_t hci_version;
-
423 
-
425  void pairWithWiimote() {
-
426  pairWithWii = true;
-
427  hci_state = HCI_CHECK_DEVICE_SERVICE;
-
428  };
-
430  bool connectToWii;
-
432  bool incomingWii;
-
434  bool pairWithWii;
-
436  bool motionPlusInside;
-
438  bool wiiUProController;
-
439 
-
441  void pairWithHID() {
-
442  pairWithHIDDevice = true;
-
443  hci_state = HCI_CHECK_DEVICE_SERVICE;
-
444  };
-
446  bool connectToHIDDevice;
-
448  bool incomingHIDDevice;
-
450  bool pairWithHIDDevice;
-
451 
-
456  uint8_t readPollInterval() {
-
457  return pollInterval;
-
458  };
-
459 
-
460 protected:
-
462  USB *pUsb;
-
464  uint8_t bAddress;
-
466  EpInfo epInfo[BTD_MAX_ENDPOINTS];
-
467 
-
469  uint8_t bConfNum;
-
471  uint8_t bNumEP;
-
473  uint32_t qNextPollTime;
-
474 
-
476  static const uint8_t BTD_CONTROL_PIPE;
-
478  static const uint8_t BTD_EVENT_PIPE;
-
480  static const uint8_t BTD_DATAIN_PIPE;
-
482  static const uint8_t BTD_DATAOUT_PIPE;
+
73 /* Macros for HCI event flag tests */
+
74 #define hci_check_flag(flag) (hci_event_flag & (flag))
+
75 #define hci_set_flag(flag) (hci_event_flag |= (flag))
+
76 #define hci_clear_flag(flag) (hci_event_flag &= ~(flag))
+
77 
+
78 /* HCI Events managed */
+
79 #define EV_INQUIRY_COMPLETE 0x01
+
80 #define EV_INQUIRY_RESULT 0x02
+
81 #define EV_CONNECT_COMPLETE 0x03
+
82 #define EV_INCOMING_CONNECT 0x04
+
83 #define EV_DISCONNECT_COMPLETE 0x05
+
84 #define EV_AUTHENTICATION_COMPLETE 0x06
+
85 #define EV_REMOTE_NAME_COMPLETE 0x07
+
86 #define EV_ENCRYPTION_CHANGE 0x08
+
87 #define EV_CHANGE_CONNECTION_LINK 0x09
+
88 #define EV_ROLE_CHANGED 0x12
+
89 #define EV_NUM_COMPLETE_PKT 0x13
+
90 #define EV_PIN_CODE_REQUEST 0x16
+
91 #define EV_LINK_KEY_REQUEST 0x17
+
92 #define EV_LINK_KEY_NOTIFICATION 0x18
+
93 #define EV_DATA_BUFFER_OVERFLOW 0x1A
+
94 #define EV_MAX_SLOTS_CHANGE 0x1B
+
95 #define EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
+
96 #define EV_QOS_SETUP_COMPLETE 0x0D
+
97 #define EV_COMMAND_COMPLETE 0x0E
+
98 #define EV_COMMAND_STATUS 0x0F
+
99 #define EV_LOOPBACK_COMMAND 0x19
+
100 #define EV_PAGE_SCAN_REP_MODE 0x20
+
101 
+
102 /* Bluetooth states for the different Bluetooth drivers */
+
103 #define L2CAP_WAIT 0
+
104 #define L2CAP_DONE 1
+
105 
+
106 /* Used for HID Control channel */
+
107 #define L2CAP_CONTROL_CONNECT_REQUEST 2
+
108 #define L2CAP_CONTROL_CONFIG_REQUEST 3
+
109 #define L2CAP_CONTROL_SUCCESS 4
+
110 #define L2CAP_CONTROL_DISCONNECT 5
+
111 
+
112 /* Used for HID Interrupt channel */
+
113 #define L2CAP_INTERRUPT_SETUP 6
+
114 #define L2CAP_INTERRUPT_CONNECT_REQUEST 7
+
115 #define L2CAP_INTERRUPT_CONFIG_REQUEST 8
+
116 #define L2CAP_INTERRUPT_DISCONNECT 9
+
117 
+
118 /* Used for SDP channel */
+
119 #define L2CAP_SDP_WAIT 10
+
120 #define L2CAP_SDP_SUCCESS 11
+
121 
+
122 /* Used for RFCOMM channel */
+
123 #define L2CAP_RFCOMM_WAIT 12
+
124 #define L2CAP_RFCOMM_SUCCESS 13
+
125 
+
126 #define L2CAP_DISCONNECT_RESPONSE 14 // Used for both SDP and RFCOMM channel
+
127 
+
128 /* Bluetooth states used by some drivers */
+
129 #define TURN_ON_LED 17
+
130 #define PS3_ENABLE_SIXAXIS 18
+
131 #define WII_CHECK_MOTION_PLUS_STATE 19
+
132 #define WII_CHECK_EXTENSION_STATE 20
+
133 #define WII_INIT_MOTION_PLUS_STATE 21
+
134 
+
135 /* L2CAP event flags for HID Control channel */
+
136 #define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x00000001
+
137 #define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS 0x00000002
+
138 #define L2CAP_FLAG_CONTROL_CONNECTED 0x00000004
+
139 #define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE 0x00000008
+
140 
+
141 /* L2CAP event flags for HID Interrupt channel */
+
142 #define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST 0x00000010
+
143 #define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS 0x00000020
+
144 #define L2CAP_FLAG_INTERRUPT_CONNECTED 0x00000040
+
145 #define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE 0x00000080
+
146 
+
147 /* L2CAP event flags for SDP channel */
+
148 #define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x00000100
+
149 #define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x00000200
+
150 #define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x00000400
+
151 
+
152 /* L2CAP event flags for RFCOMM channel */
+
153 #define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x00000800
+
154 #define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x00001000
+
155 #define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x00002000
+
156 
+
157 #define L2CAP_FLAG_DISCONNECT_RESPONSE 0x00004000
+
158 
+
159 /* Macros for L2CAP event flag tests */
+
160 #define l2cap_check_flag(flag) (l2cap_event_flag & (flag))
+
161 #define l2cap_set_flag(flag) (l2cap_event_flag |= (flag))
+
162 #define l2cap_clear_flag(flag) (l2cap_event_flag &= ~(flag))
+
163 
+
164 /* L2CAP signaling commands */
+
165 #define L2CAP_CMD_COMMAND_REJECT 0x01
+
166 #define L2CAP_CMD_CONNECTION_REQUEST 0x02
+
167 #define L2CAP_CMD_CONNECTION_RESPONSE 0x03
+
168 #define L2CAP_CMD_CONFIG_REQUEST 0x04
+
169 #define L2CAP_CMD_CONFIG_RESPONSE 0x05
+
170 #define L2CAP_CMD_DISCONNECT_REQUEST 0x06
+
171 #define L2CAP_CMD_DISCONNECT_RESPONSE 0x07
+
172 #define L2CAP_CMD_INFORMATION_REQUEST 0x0A
+
173 #define L2CAP_CMD_INFORMATION_RESPONSE 0x0B
+
174 
+
175 // Used For Connection Response - Remember to Include High Byte
+
176 #define PENDING 0x01
+
177 #define SUCCESSFUL 0x00
+
178 
+
179 /* Bluetooth L2CAP PSM - see http://www.bluetooth.org/Technical/AssignedNumbers/logical_link.htm */
+
180 #define SDP_PSM 0x01 // Service Discovery Protocol PSM Value
+
181 #define RFCOMM_PSM 0x03 // RFCOMM PSM Value
+
182 #define HID_CTRL_PSM 0x11 // HID_Control PSM Value
+
183 #define HID_INTR_PSM 0x13 // HID_Interrupt PSM Value
+
184 
+
185 // Used to determine if it is a Bluetooth dongle
+
186 #define WI_SUBCLASS_RF 0x01 // RF Controller
+
187 #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
+
188 
+
189 #define BTD_MAX_ENDPOINTS 4
+
190 #define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
+
191 
+
192 #define PAIR 1
+
193 
+
194 /* acl_handle_ok or it's a new connection */
+
195 #if 0
+
196 #define UHS_ACL_HANDLE_OK(x, y) ((uint16_t)(x[0]) | (uint16_t)(x[1] << 8)) == (y | 0x2000U)
+
197 #else
+
198 /*
+
199  * Better implementation.
+
200  * o One place for this code, it is reused four times in the source.
+
201  * Perhaps it is better as a function.
+
202  * o This should be faster since the && operation can early exit, this means
+
203  * the shift would only be performed if the first byte matches.
+
204  * o Casting is eliminated.
+
205  * o How does this compare in code size? No difference. It is a free optimization.
+
206  */
+
207 #define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20)))
+
208 #endif
+
209 
+
211 class BluetoothService {
+
212 public:
+
217  virtual void ACLData(uint8_t* ACLData);
+
219  virtual void Run();
+
221  virtual void Reset();
+
223  virtual void disconnect();
+
224 };
+
225 
+
230 class BTD : public USBDeviceConfig, public UsbConfigXtracter {
+
231 public:
+
236  BTD(USB *p);
+
237 
+
246  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
+
254  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
+
259  virtual uint8_t Release();
+
264  virtual uint8_t Poll();
+
265 
+
270  virtual uint8_t GetAddress() {
+
271  return bAddress;
+
272  };
+
273 
+
278  virtual bool isReady() {
+
279  return bPollEnable;
+
280  };
+
281 
+
287  virtual boolean DEVCLASSOK(uint8_t klass) {
+
288  return (klass == USB_CLASS_WIRELESS_CTRL);
+
289  };
+
290 
+
298  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
+
299  if(vid == IOGEAR_GBU521_VID && pid == IOGEAR_GBU521_PID)
+
300  return true;
+
301  if(my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) { // Check if Bluetooth address is set
+
302  if(vid == PS3_VID && (pid == PS3_PID || pid == PS3NAVIGATION_PID || pid == PS3MOVE_PID))
+
303  return true;
+
304  }
+
305  return false;
+
306  };
+
318  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
+
322  void disconnect() {
+
323  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
+
324  if(btService[i])
+
325  btService[i]->disconnect();
+
326  };
+
327 
+
333  int8_t registerServiceClass(BluetoothService *pService) {
+
334  for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
+
335  if(!btService[i]) {
+
336  btService[i] = pService;
+
337  return i; // Return ID
+
338  }
+
339  }
+
340  return -1; // ErrorregisterServiceClass
+
341  };
+
342 
+
349  void HCI_Command(uint8_t* data, uint16_t nbytes);
+
351  void hci_reset();
+
353  void hci_read_bdaddr();
+
355  void hci_read_local_version_information();
+
360  void hci_set_local_name(const char* name);
+
362  void hci_write_scan_enable();
+
364  void hci_write_scan_disable();
+
366  void hci_remote_name();
+
368  void hci_accept_connection();
+
373  void hci_disconnect(uint16_t handle);
+
379  void hci_pin_code_request_reply();
+
381  void hci_pin_code_negative_request_reply();
+
386  void hci_link_key_request_negative_reply();
+
388  void hci_authentication_request();
+
390  void hci_inquiry();
+
392  void hci_inquiry_cancel();
+
394  void hci_connect();
+
399  void hci_connect(uint8_t *bdaddr);
+
401  void hci_write_class_of_device();
+
413  void L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00);
+
421  void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm);
+
430  void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result);
+
437  void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid);
+
444  void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid);
+
452  void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
+
460  void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid);
+
467  void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh);
+
471  bool watingForConnection;
+
473  bool l2capConnectionClaimed;
+
475  bool sdpConnectionClaimed;
+
477  bool rfcommConnectionClaimed;
+
478 
+
480  const char* btdName;
+
482  const char* btdPin;
483 
-
488  void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
-
489 
-
490 private:
-
491  void clearAllVariables(); // Set all variables, endpoint structs etc. to default values
-
492  BluetoothService* btService[BTD_NUMSERVICES];
-
493 
-
494  uint16_t PID, VID; // PID and VID of device connected
-
495 
-
496  bool bPollEnable;
-
497  uint8_t pollInterval;
+
485  uint8_t my_bdaddr[6];
+
487  uint16_t hci_handle;
+
489  uint8_t disc_bdaddr[6];
+
491  uint8_t remote_name[30];
+
497  uint8_t hci_version;
498 
-
499  /* Variables used by high level HCI task */
-
500  uint8_t hci_state; //current state of bluetooth hci connection
-
501  uint16_t hci_counter; // counter used for bluetooth hci reset loops
-
502  uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
-
503  uint16_t hci_event_flag; // hci flags of received bluetooth events
-
504  uint8_t inquiry_counter;
-
505 
-
506  uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
-
507  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
-
508  uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
-
509 
-
510  /* State machines */
-
511  void HCI_event_task(); // Poll the HCI event pipe
-
512  void HCI_task(); // HCI state machine
-
513  void ACL_event_task(); // ACL input pipe
+
500  void pairWithWiimote() {
+
501  pairWithWii = true;
+
502  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
503  };
+
505  bool connectToWii;
+
507  bool incomingWii;
+
509  bool pairWithWii;
+
511  bool motionPlusInside;
+
513  bool wiiUProController;
514 
-
515  /* Used to set the Bluetooth Address internally to the PS3 Controllers */
-
516  void setBdaddr(uint8_t* BDADDR);
-
517  void setMoveBdaddr(uint8_t* BDADDR);
-
518 };
-
519 #endif
-
BTD::BTD_DATAOUT_PIPE
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:482
-
BTD::incomingWii
bool incomingWii
Definition: BTD.h:432
-
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1033
-
BTD::bNumEP
uint8_t bNumEP
Definition: BTD.h:471
-
BTD::btdName
const char * btdName
Definition: BTD.h:405
-
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:917
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
-
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
-
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:400
-
BTD
Definition: BTD.h:158
-
BTD::DEVCLASSOK
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: BTD.h:214
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
-
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:402
-
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:422
-
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1011
-
BTD::BTD_EVENT_PIPE
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:478
+
516  void pairWithHID() {
+
517  pairWithHIDDevice = true;
+
518  hci_state = HCI_CHECK_DEVICE_SERVICE;
+
519  };
+
521  bool connectToHIDDevice;
+
523  bool incomingHIDDevice;
+
525  bool pairWithHIDDevice;
+
526 
+
531  uint8_t readPollInterval() {
+
532  return pollInterval;
+
533  };
+
534 
+
535 protected:
+
537  USB *pUsb;
+
539  uint8_t bAddress;
+
541  EpInfo epInfo[BTD_MAX_ENDPOINTS];
+
542 
+
544  uint8_t bConfNum;
+
546  uint8_t bNumEP;
+
548  uint32_t qNextPollTime;
+
549 
+
551  static const uint8_t BTD_CONTROL_PIPE;
+
553  static const uint8_t BTD_EVENT_PIPE;
+
555  static const uint8_t BTD_DATAIN_PIPE;
+
557  static const uint8_t BTD_DATAOUT_PIPE;
+
558 
+
563  void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
+
564 
+
565 private:
+
566  void Initialize(); // Set all variables, endpoint structs etc. to default values
+
567  BluetoothService* btService[BTD_NUMSERVICES];
+
568 
+
569  uint16_t PID, VID; // PID and VID of device connected
+
570 
+
571  uint8_t pollInterval;
+
572  bool bPollEnable;
+
573 
+
574  bool incomingPS4; // True if a PS4 controller is connecting
+
575  uint8_t classOfDevice[3]; // Class of device of last device
+
576 
+
577  /* Variables used by high level HCI task */
+
578  uint8_t hci_state; //current state of bluetooth hci connection
+
579  uint16_t hci_counter; // counter used for bluetooth hci reset loops
+
580  uint16_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
+
581  uint16_t hci_event_flag; // hci flags of received bluetooth events
+
582  uint8_t inquiry_counter;
+
583 
+
584  uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
+
585  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
+
586  uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
+
587 
+
588  /* State machines */
+
589  void HCI_event_task(); // Poll the HCI event pipe
+
590  void HCI_task(); // HCI state machine
+
591  void ACL_event_task(); // ACL input pipe
+
592 
+
593  /* Used to set the Bluetooth Address internally to the PS3 Controllers */
+
594  void setBdaddr(uint8_t* BDADDR);
+
595  void setMoveBdaddr(uint8_t* BDADDR);
+
596 };
+
597 #endif
+
BTD::BTD_DATAOUT_PIPE
static const uint8_t BTD_DATAOUT_PIPE
Definition: BTD.h:557
+
BTD::incomingWii
bool incomingWii
Definition: BTD.h:507
+
BTD::hci_connect
void hci_connect()
Definition: BTD.cpp:1045
+
BTD::bNumEP
uint8_t bNumEP
Definition: BTD.h:546
+
BTD::btdName
const char * btdName
Definition: BTD.h:480
+
BTD::hci_reset
void hci_reset()
Definition: BTD.cpp:927
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:475
+
BTD
Definition: BTD.h:230
+
BTD::DEVCLASSOK
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: BTD.h:287
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:477
+
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:497
+
BTD::hci_inquiry
void hci_inquiry()
Definition: BTD.cpp:1023
+
BTD::BTD_EVENT_PIPE
static const uint8_t BTD_EVENT_PIPE
Definition: BTD.h:553
PS3MOVE_PID
#define PS3MOVE_PID
Definition: BTD.h:27
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
-
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:434
-
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:939
-
BTD::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:318
-
BTD::GetAddress
virtual uint8_t GetAddress()
Definition: BTD.h:198
-
BTD::btdPin
const char * btdPin
Definition: BTD.h:407
-
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:436
-
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:980
-
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:416
+
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:509
+
BTD::hci_write_scan_disable
void hci_write_scan_disable()
Definition: BTD.cpp:949
+
BTD::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: BTD.cpp:314
+
BTD::GetAddress
virtual uint8_t GetAddress()
Definition: BTD.h:270
+
BTD::btdPin
const char * btdPin
Definition: BTD.h:482
+
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:511
+
BTD::hci_remote_name
void hci_remote_name()
Definition: BTD.cpp:992
+
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:491
USBDeviceConfig
Definition: UsbCore.h:105
Usb.h
PS3_VID
#define PS3_VID
Definition: BTD.h:24
BTD::BTD
BTD(USB *p)
Definition: BTD.cpp:27
-
BTD::readPollInterval
uint8_t readPollInterval()
Definition: BTD.h:456
+
BTD::readPollInterval
uint8_t readPollInterval()
Definition: BTD.h:531
BluetoothService::Reset
virtual void Reset()
-
BTD::BTD_DATAIN_PIPE
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:480
-
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:999
-
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:926
-
BTD::Release
virtual uint8_t Release()
Definition: BTD.cpp:369
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
+
BTD::BTD_DATAIN_PIPE
static const uint8_t BTD_DATAIN_PIPE
Definition: BTD.h:555
+
BTD::hci_set_local_name
void hci_set_local_name(const char *name)
Definition: BTD.cpp:1011
+
BTD::hci_write_scan_enable
void hci_write_scan_enable()
Definition: BTD.cpp:936
+
BTD::Release
virtual uint8_t Release()
Definition: BTD.cpp:365
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
USB_CLASS_WIRELESS_CTRL
#define USB_CLASS_WIRELESS_CTRL
Definition: UsbCore.h:55
-
BTD::watingForConnection
bool watingForConnection
Definition: BTD.h:396
-
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:444
-
BTD::bAddress
uint8_t bAddress
Definition: BTD.h:464
-
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:448
-
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:450
-
BTD::qNextPollTime
uint32_t qNextPollTime
Definition: BTD.h:473
-
BTD::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:350
+
BTD::watingForConnection
bool watingForConnection
Definition: BTD.h:471
+
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:519
+
BTD::bAddress
uint8_t bAddress
Definition: BTD.h:539
+
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:523
+
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:525
+
BTD::qNextPollTime
uint32_t qNextPollTime
Definition: BTD.h:548
+
BTD::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: BTD.cpp:346
IOGEAR_GBU521_PID
#define IOGEAR_GBU521_PID
Definition: BTD.h:30
-
BTD::connectToWii
bool connectToWii
Definition: BTD.h:428
+
BTD::connectToWii
bool connectToWii
Definition: BTD.h:503
BTD::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:48
-
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:438
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
-
BTD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:121
+
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:513
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
+
BTD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: BTD.cpp:122
EpInfo
Definition: address.h:32
-
BTD::pairWithHID
void pairWithHID()
Definition: BTD.h:441
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
-
BluetoothService
Definition: BTD.h:139
-
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:948
-
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1025
-
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:410
-
BTD::Poll
virtual uint8_t Poll()
Definition: BTD.cpp:375
-
BTD::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: BTD.h:223
-
BTD::BTD_CONTROL_PIPE
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:476
-
UsbConfigXtracter
Definition: confdescparser.h:24
+
BTD::pairWithHID
void pairWithHID()
Definition: BTD.h:516
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
BluetoothService
Definition: BTD.h:211
+
BTD::hci_read_bdaddr
void hci_read_bdaddr()
Definition: BTD.cpp:958
+
BTD::hci_inquiry_cancel
void hci_inquiry_cancel()
Definition: BTD.cpp:1037
+
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:485
+
BTD::Poll
virtual uint8_t Poll()
Definition: BTD.cpp:371
+
BTD::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: BTD.h:298
+
BTD::BTD_CONTROL_PIPE
static const uint8_t BTD_CONTROL_PIPE
Definition: BTD.h:551
+
UsbConfigXtracter
Definition: confdescparser.h:23
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
-
BTD::disconnect
void disconnect()
Definition: BTD.h:247
-
BTD::disc_bdaddr
uint8_t disc_bdaddr[6]
Definition: BTD.h:414
-
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
-
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:398
-
BTD::epInfo
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:466
+
BTD::disconnect
void disconnect()
Definition: BTD.h:322
+
BTD::disc_bdaddr
uint8_t disc_bdaddr[6]
Definition: BTD.h:489
+
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:333
+
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:473
+
BTD::epInfo
EpInfo epInfo[BTD_MAX_ENDPOINTS]
Definition: BTD.h:541
IOGEAR_GBU521_VID
#define IOGEAR_GBU521_VID
Definition: BTD.h:29
BluetoothService::ACLData
virtual void ACLData(uint8_t *ACLData)
PS3_PID
#define PS3_PID
Definition: BTD.h:25
-
BTD_MAX_ENDPOINTS
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:133
+
BTD_MAX_ENDPOINTS
#define BTD_MAX_ENDPOINTS
Definition: BTD.h:189
PS3NAVIGATION_PID
#define PS3NAVIGATION_PID
Definition: BTD.h:26
-
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1301
-
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1145
-
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1095
+
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1313
+
BTD::hci_write_class_of_device
void hci_write_class_of_device()
Definition: BTD.cpp:1157
+
BTD::hci_pin_code_negative_request_reply
void hci_pin_code_negative_request_reply()
Definition: BTD.cpp:1107
HCI_CHECK_DEVICE_SERVICE
#define HCI_CHECK_DEVICE_SERVICE
Definition: BTD.h:48
-
USB
Definition: UsbCore.h:152
+
USB
Definition: UsbCore.h:176
BluetoothService::Run
virtual void Run()
-
BTD::bConfNum
uint8_t bConfNum
Definition: BTD.h:469
-
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1109
-
BTD::pairWithWiimote
void pairWithWiimote()
Definition: BTD.h:425
-
BTD::isReady
virtual bool isReady()
Definition: BTD.h:206
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD_NUMSERVICES
#define BTD_NUMSERVICES
Definition: BTD.h:134
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1059
+
BTD::bConfNum
uint8_t bConfNum
Definition: BTD.h:544
+
BTD::hci_link_key_request_negative_reply
void hci_link_key_request_negative_reply()
Definition: BTD.cpp:1121
+
BTD::pairWithWiimote
void pairWithWiimote()
Definition: BTD.h:500
+
BTD::isReady
virtual bool isReady()
Definition: BTD.h:278
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD_NUMSERVICES
#define BTD_NUMSERVICES
Definition: BTD.h:190
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
BTD::hci_pin_code_request_reply
void hci_pin_code_request_reply()
Definition: BTD.cpp:1071
BluetoothService::disconnect
virtual void disconnect()
-
BTD::pUsb
USB * pUsb
Definition: BTD.h:458
-
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1123
-
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:956
-
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:964
-
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:912
+
BTD::pUsb
USB * pUsb
Definition: BTD.h:533
+
BTD::hci_authentication_request
void hci_authentication_request()
Definition: BTD.cpp:1135
+
BTD::hci_read_local_version_information
void hci_read_local_version_information()
Definition: BTD.cpp:967
+
BTD::hci_accept_connection
void hci_accept_connection()
Definition: BTD.cpp:976
+
BTD::HCI_Command
void HCI_Command(uint8_t *data, uint16_t nbytes)
Definition: BTD.cpp:922
diff --git a/_b_t_h_i_d_8cpp.html b/_b_t_h_i_d_8cpp.html index 7f34cc87..59ea6bce 100644 --- a/_b_t_h_i_d_8cpp.html +++ b/_b_t_h_i_d_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTHID.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -95,7 +95,7 @@ Include dependency graph for BTHID.cpp:
- +

Go to the source code of this file.

@@ -104,7 +104,7 @@ Include dependency graph for BTHID.cpp: diff --git a/_b_t_h_i_d_8cpp__incl.map b/_b_t_h_i_d_8cpp__incl.map index cf2b810d..d86777cd 100644 --- a/_b_t_h_i_d_8cpp__incl.map +++ b/_b_t_h_i_d_8cpp__incl.map @@ -1,9 +1,8 @@ - - - - - - - + + + + + + diff --git a/_b_t_h_i_d_8cpp__incl.md5 b/_b_t_h_i_d_8cpp__incl.md5 index 286113a3..ec5d712c 100644 --- a/_b_t_h_i_d_8cpp__incl.md5 +++ b/_b_t_h_i_d_8cpp__incl.md5 @@ -1 +1 @@ -72bf7a4ac7922d4cdc4dd2d2a3e314c4 \ No newline at end of file +3325b0ff5c79ca7ff5822cbf27f33902 \ No newline at end of file diff --git a/_b_t_h_i_d_8cpp__incl.png b/_b_t_h_i_d_8cpp__incl.png index bcb9b0f7..b2a12176 100644 Binary files a/_b_t_h_i_d_8cpp__incl.png and b/_b_t_h_i_d_8cpp__incl.png differ diff --git a/_b_t_h_i_d_8cpp_source.html b/_b_t_h_i_d_8cpp_source.html index 772b0cfa..66e6069f 100644 --- a/_b_t_h_i_d_8cpp_source.html +++ b/_b_t_h_i_d_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTHID.cpp Source File @@ -31,7 +31,7 @@ - + @@ -111,334 +111,334 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
20 //#define EXTRADEBUG // Uncomment to get even more debugging data
21 //#define PRINTREPORT // Uncomment to print the report send by the HID device
22 
-
23 BTHID::BTHID(BTD *p, bool pair, const char *pin) :
+
23 BTHID::BTHID(BTD *p, bool pair, const char *pin) :
24 pBtd(p), // pointer to USB class instance - mandatory
-
25 protocolMode(HID_BOOT_PROTOCOL)
-
26 {
-
27  for(uint8_t i = 0; i < epMUL; i++)
-
28  pRptParser[i] = NULL;
-
29 
-
30  if (pBtd)
-
31  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
-
32 
-
33  pBtd->pairWithHIDDevice = pair;
+
25 protocolMode(HID_BOOT_PROTOCOL) {
+
26  for(uint8_t i = 0; i < NUM_PARSERS; i++)
+
27  pRptParser[i] = NULL;
+
28 
+
29  if(pBtd)
+
30  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
+
31 
+
32  pBtd->pairWithHIDDevice = pair;
+
33  pBtd->btdPin = pin;
34 
-
35  if (pair)
-
36  pBtd->btdPin= pin;
-
37 
-
38  /* Set device cid for the control and intterrupt channelse - LSB */
-
39  control_dcid[0] = 0x70; // 0x0070
-
40  control_dcid[1] = 0x00;
-
41  interrupt_dcid[0] = 0x71; // 0x0071
-
42  interrupt_dcid[1] = 0x00;
+
35  /* Set device cid for the control and intterrupt channelse - LSB */
+
36  control_dcid[0] = 0x70; // 0x0070
+
37  control_dcid[1] = 0x00;
+
38  interrupt_dcid[0] = 0x71; // 0x0071
+
39  interrupt_dcid[1] = 0x00;
+
40 
+
41  Reset();
+
42 }
43 
-
44  Reset();
-
45 }
-
46 
-
47 void BTHID::Reset() {
-
48  connected = false;
-
49  activeConnection = false;
-
50  l2cap_event_flag = 0; // Reset flags
-
51  l2cap_state = L2CAP_WAIT;
-
52 }
-
53 
-
54 void BTHID::disconnect() { // Use this void to disconnect any of the controllers
-
55  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
-
56  pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
-
57  Reset();
-
58  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
-
59 }
-
60 
-
61 void BTHID::ACLData(uint8_t* l2capinbuf) {
-
62  if (!pBtd->l2capConnectionClaimed && pBtd->incomingHIDDevice && !connected && !activeConnection) {
-
63  if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
64  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
-
65  pBtd->incomingHIDDevice = false;
-
66  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
-
67  activeConnection = true;
-
68  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
69  l2cap_state = L2CAP_WAIT;
-
70  }
-
71  }
-
72  }
-
73  if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
-
74  if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
-
75  if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
-
76 #ifdef DEBUG_USB_HOST
-
77  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
-
78  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
44 void BTHID::Reset() {
+
45  connected = false;
+
46  activeConnection = false;
+
47  l2cap_event_flag = 0; // Reset flags
+
48  l2cap_state = L2CAP_WAIT;
+
49 }
+
50 
+
51 void BTHID::disconnect() { // Use this void to disconnect the device
+
52  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
+
53  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
+
54  Reset();
+
55  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
+
56 }
+
57 
+
58 void BTHID::ACLData(uint8_t* l2capinbuf) {
+
59  if(!pBtd->l2capConnectionClaimed && pBtd->incomingHIDDevice && !connected && !activeConnection) {
+
60  if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
61  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
62  pBtd->incomingHIDDevice = false;
+
63  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
+
64  activeConnection = true;
+
65  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
+
66  l2cap_state = L2CAP_WAIT;
+
67  }
+
68  }
+
69  }
+
70  //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
+
71  if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
+
72  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
+
73  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
+
74 #ifdef DEBUG_USB_HOST
+
75  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
+
76  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
77  Notify(PSTR(" "), 0x80);
+
78  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
79  Notify(PSTR(" "), 0x80);
-
80  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
80  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
81  Notify(PSTR(" "), 0x80);
-
82  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
+
82  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
83  Notify(PSTR(" "), 0x80);
-
84  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
+
84  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
85  Notify(PSTR(" "), 0x80);
-
86  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
87  Notify(PSTR(" "), 0x80);
-
88  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
89 #endif
-
90  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
-
91  if (((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
-
92  if (l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) { // Success
-
93  //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
-
94  identifier = l2capinbuf[9];
-
95  control_scid[0] = l2capinbuf[12];
-
96  control_scid[1] = l2capinbuf[13];
-
97  l2cap_event_flag |= L2CAP_FLAG_CONTROL_CONNECTED;
-
98  } else if (l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
-
99  //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
-
100  identifier = l2capinbuf[9];
-
101  interrupt_scid[0] = l2capinbuf[12];
-
102  interrupt_scid[1] = l2capinbuf[13];
-
103  l2cap_event_flag |= L2CAP_FLAG_INTERRUPT_CONNECTED;
-
104  }
-
105  }
-
106  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
107 #ifdef EXTRADEBUG
-
108  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
-
109  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
110  Notify(PSTR(" "), 0x80);
-
111  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
112  Notify(PSTR(" SCID: "), 0x80);
-
113  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
114  Notify(PSTR(" "), 0x80);
-
115  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
116  Notify(PSTR(" Identifier: "), 0x80);
-
117  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
118 #endif
-
119  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
-
120  identifier = l2capinbuf[9];
-
121  control_scid[0] = l2capinbuf[14];
-
122  control_scid[1] = l2capinbuf[15];
-
123  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_CONTROL_REQUEST;
-
124  } else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
-
125  identifier = l2capinbuf[9];
-
126  interrupt_scid[0] = l2capinbuf[14];
-
127  interrupt_scid[1] = l2capinbuf[15];
-
128  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST;
-
129  }
-
130  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
-
131  if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
-
132  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
133  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
-
134  identifier = l2capinbuf[9];
-
135  l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS;
-
136  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
137  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
-
138  identifier = l2capinbuf[9];
-
139  l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS;
-
140  }
-
141  }
-
142  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
-
143  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
144  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
-
145  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
-
146  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
147  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
-
148  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
-
149  }
-
150  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
-
151  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
152 #ifdef DEBUG_USB_HOST
-
153  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
-
154 #endif
-
155  identifier = l2capinbuf[9];
-
156  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
-
157  Reset();
-
158  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
159 #ifdef DEBUG_USB_HOST
-
160  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
-
161 #endif
-
162  identifier = l2capinbuf[9];
-
163  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
-
164  Reset();
-
165  }
-
166  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
-
167  if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
-
168  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
-
169  identifier = l2capinbuf[9];
-
170  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE;
-
171  } else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
-
172  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
-
173  identifier = l2capinbuf[9];
-
174  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE;
-
175  }
-
176  }
-
177 #ifdef EXTRADEBUG
-
178  else {
-
179  identifier = l2capinbuf[9];
-
180  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
-
181  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
182  }
-
183 #endif
-
184  } else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
-
185  //Notify(PSTR("\r\n\r\nL2CAP Interrupt: "), 0x80);
-
186 #ifdef PRINTREPORT
-
187  Notify(PSTR("\r\n"), 0x80);
-
188  for (uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
-
189  D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
-
190  Notifyc(' ', 0x80);
-
191  }
-
192 #endif
-
193  if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
-
194  switch (l2capinbuf[9]) {
-
195  case 0x01: // Keyboard events
-
196  if (pRptParser[KEYBOARD_PARSER_ID]) {
-
197  uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
-
198  pRptParser[KEYBOARD_PARSER_ID]->Parse((HID*)this, 0, (uint8_t) length, &l2capinbuf[10]);
-
199  }
-
200  break;
-
201 
-
202  case 0x02: // Mouse events
-
203  case 0x1A:
-
204  if (pRptParser[MOUSE_PARSER_ID]) {
-
205  uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
-
206  pRptParser[MOUSE_PARSER_ID]->Parse((HID*)this, 0, (uint8_t) length, &l2capinbuf[10]);
-
207  }
-
208  break;
-
209  case 0x03:
-
210 #ifdef EXTRADEBUG
-
211  Notify(PSTR("\r\nChange mode event: "), 0x80);
-
212  D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
-
213 #endif
-
214  break;
-
215 #ifdef DEBUG_USB_HOST
-
216  default:
-
217  Notify(PSTR("\r\nUnknown Report type: "), 0x80);
-
218  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
219  break;
+
86  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
87 #endif
+
88  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
+
89  if(((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
+
90  if(l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) {
+
91  //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
+
92  identifier = l2capinbuf[9];
+
93  control_scid[0] = l2capinbuf[12];
+
94  control_scid[1] = l2capinbuf[13];
+
95  l2cap_set_flag(L2CAP_FLAG_CONTROL_CONNECTED);
+
96  } else if(l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
+
97  //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
+
98  identifier = l2capinbuf[9];
+
99  interrupt_scid[0] = l2capinbuf[12];
+
100  interrupt_scid[1] = l2capinbuf[13];
+
101  l2cap_set_flag(L2CAP_FLAG_INTERRUPT_CONNECTED);
+
102  }
+
103  }
+
104  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
105 #ifdef EXTRADEBUG
+
106  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
+
107  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
108  Notify(PSTR(" "), 0x80);
+
109  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
110  Notify(PSTR(" SCID: "), 0x80);
+
111  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
112  Notify(PSTR(" "), 0x80);
+
113  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
114  Notify(PSTR(" Identifier: "), 0x80);
+
115  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
116 #endif
+
117  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
118  identifier = l2capinbuf[9];
+
119  control_scid[0] = l2capinbuf[14];
+
120  control_scid[1] = l2capinbuf[15];
+
121  l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
+
122  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
+
123  identifier = l2capinbuf[9];
+
124  interrupt_scid[0] = l2capinbuf[14];
+
125  interrupt_scid[1] = l2capinbuf[15];
+
126  l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
+
127  }
+
128  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
+
129  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
+
130  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
131  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
+
132  identifier = l2capinbuf[9];
+
133  l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
+
134  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
135  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
+
136  identifier = l2capinbuf[9];
+
137  l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
+
138  }
+
139  }
+
140  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
+
141  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
142  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
+
143  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
+
144  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
145  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
+
146  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
+
147  }
+
148  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
+
149  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
150 #ifdef DEBUG_USB_HOST
+
151  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
+
152 #endif
+
153  identifier = l2capinbuf[9];
+
154  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
+
155  Reset();
+
156  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
157 #ifdef DEBUG_USB_HOST
+
158  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
+
159 #endif
+
160  identifier = l2capinbuf[9];
+
161  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
+
162  Reset();
+
163  }
+
164  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
+
165  if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
+
166  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
+
167  identifier = l2capinbuf[9];
+
168  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
+
169  } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
+
170  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
+
171  identifier = l2capinbuf[9];
+
172  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
+
173  }
+
174  }
+
175 #ifdef EXTRADEBUG
+
176  else {
+
177  identifier = l2capinbuf[9];
+
178  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
+
179  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
180  }
+
181 #endif
+
182  } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
+
183 #ifdef PRINTREPORT
+
184  Notify(PSTR("\r\nL2CAP Interrupt: "), 0x80);
+
185  for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
+
186  D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
+
187  Notify(PSTR(" "), 0x80);
+
188  }
+
189 #endif
+
190  if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
+
191  switch(l2capinbuf[9]) {
+
192  case 0x01: // Keyboard events
+
193  if(pRptParser[KEYBOARD_PARSER_ID]) {
+
194  uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
+
195  pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
+
196  }
+
197  break;
+
198 
+
199  case 0x02: // Mouse events
+
200  if(pRptParser[MOUSE_PARSER_ID]) {
+
201  uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
+
202  pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<HID *>(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
+
203  }
+
204  break;
+
205 #ifdef DEBUG_USB_HOST
+
206  default:
+
207  Notify(PSTR("\r\nUnknown Report type: "), 0x80);
+
208  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
209  break;
+
210 #endif
+
211  }
+
212  }
+
213  } else if(l2capinbuf[6] == control_dcid[0] && l2capinbuf[7] == control_dcid[1]) { // l2cap_control
+
214 #ifdef PRINTREPORT
+
215  Notify(PSTR("\r\nL2CAP Control: "), 0x80);
+
216  for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
+
217  D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
+
218  Notify(PSTR(" "), 0x80);
+
219  }
220 #endif
-
221  }
-
222  }
-
223  }
-
224 #ifdef EXTRADEBUG
-
225  else {
-
226  Notify(PSTR("\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
-
227  D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
-
228  Notify(PSTR(" "), 0x80);
-
229  D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);
-
230 
-
231  Notify(PSTR("\r\nData: "), 0x80);
-
232  Notify(PSTR("\r\n"), 0x80);
-
233  for (uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
-
234  D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
-
235  Notifyc(' ', 0x80);
-
236  }
-
237  }
-
238 #endif
-
239  L2CAP_task();
-
240  }
-
241 }
-
242 
-
243 void BTHID::L2CAP_task() {
-
244  switch (l2cap_state) {
-
245  /* These states are used if the HID device is the host */
-
246  case L2CAP_CONTROL_SUCCESS:
-
247  if (l2cap_config_success_control_flag) {
-
248 #ifdef DEBUG_USB_HOST
-
249  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
-
250 #endif
-
251  l2cap_state = L2CAP_INTERRUPT_SETUP;
-
252  }
-
253  break;
-
254 
-
255  case L2CAP_INTERRUPT_SETUP:
-
256  if (l2cap_connection_request_interrupt_flag) {
-
257 #ifdef DEBUG_USB_HOST
-
258  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
-
259 #endif
-
260  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
-
261  delay(1);
-
262  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
-
263  identifier++;
-
264  delay(1);
-
265  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
266 
-
267  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
-
268  }
-
269  break;
-
270 
-
271  /* These states are used if the Arduino is the host */
-
272  case L2CAP_CONTROL_CONNECT_REQUEST:
-
273  if (l2cap_connected_control_flag) {
-
274 #ifdef DEBUG_USB_HOST
-
275  Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
-
276 #endif
-
277  identifier++;
-
278  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
279  l2cap_state = L2CAP_CONTROL_CONFIG_REQUEST;
-
280  }
-
281  break;
-
282 
-
283  case L2CAP_CONTROL_CONFIG_REQUEST:
-
284  if (l2cap_config_success_control_flag) {
-
285 #ifdef DEBUG_USB_HOST
-
286  Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
-
287 #endif
-
288  identifier++;
-
289  pBtd->l2cap_connection_request(hci_handle, identifier, interrupt_dcid, HID_INTR_PSM);
-
290  l2cap_state = L2CAP_INTERRUPT_CONNECT_REQUEST;
-
291  }
-
292  break;
-
293 
-
294  case L2CAP_INTERRUPT_CONNECT_REQUEST:
-
295  if (l2cap_connected_interrupt_flag) {
-
296 #ifdef DEBUG_USB_HOST
-
297  Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
-
298 #endif
-
299  identifier++;
-
300  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
301  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
-
302  }
-
303  break;
-
304 
-
305  case L2CAP_INTERRUPT_CONFIG_REQUEST:
-
306  if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established
-
307 #ifdef DEBUG_USB_HOST
-
308  Notify(PSTR("\r\nHID Channels Established"), 0x80);
-
309 #endif
-
310  pBtd->connectToHIDDevice = false;
-
311  pBtd->pairWithHIDDevice = false;
-
312  connected = true;
-
313  setProtocol();
+
221  }
+
222 #ifdef EXTRADEBUG
+
223  else {
+
224  Notify(PSTR("\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
+
225  D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
+
226  Notify(PSTR(" "), 0x80);
+
227  D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);
+
228 
+
229  Notify(PSTR("\r\nData: "), 0x80);
+
230  Notify(PSTR("\r\n"), 0x80);
+
231  for(uint16_t i = 0; i < ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); i++) {
+
232  D_PrintHex<uint8_t > (l2capinbuf[i + 8], 0x80);
+
233  Notify(PSTR(" "), 0x80);
+
234  }
+
235  }
+
236 #endif
+
237  L2CAP_task();
+
238  }
+
239 }
+
240 
+
241 void BTHID::L2CAP_task() {
+
242  switch(l2cap_state) {
+
243  /* These states are used if the HID device is the host */
+
244  case L2CAP_CONTROL_SUCCESS:
+
245  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
246 #ifdef DEBUG_USB_HOST
+
247  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
+
248 #endif
+
249  setProtocol(); // Set protocol before establishing HID interrupt channel
+
250  l2cap_state = L2CAP_INTERRUPT_SETUP;
+
251  }
+
252  break;
+
253 
+
254  case L2CAP_INTERRUPT_SETUP:
+
255  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
+
256 #ifdef DEBUG_USB_HOST
+
257  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
+
258 #endif
+
259  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
+
260  delay(1);
+
261  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
+
262  identifier++;
+
263  delay(1);
+
264  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
265 
+
266  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
+
267  }
+
268  break;
+
269 
+
270  /* These states are used if the Arduino is the host */
+
271  case L2CAP_CONTROL_CONNECT_REQUEST:
+
272  if(l2cap_check_flag(L2CAP_FLAG_CONTROL_CONNECTED)) {
+
273 #ifdef DEBUG_USB_HOST
+
274  Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
+
275 #endif
+
276  identifier++;
+
277  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
+
278  l2cap_state = L2CAP_CONTROL_CONFIG_REQUEST;
+
279  }
+
280  break;
+
281 
+
282  case L2CAP_CONTROL_CONFIG_REQUEST:
+
283  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
284  setProtocol(); // Set protocol before establishing HID interrupt channel
+
285  delay(1); // Short delay between commands - just to be sure
+
286 #ifdef DEBUG_USB_HOST
+
287  Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
+
288 #endif
+
289  identifier++;
+
290  pBtd->l2cap_connection_request(hci_handle, identifier, interrupt_dcid, HID_INTR_PSM);
+
291  l2cap_state = L2CAP_INTERRUPT_CONNECT_REQUEST;
+
292  }
+
293  break;
+
294 
+
295  case L2CAP_INTERRUPT_CONNECT_REQUEST:
+
296  if(l2cap_check_flag(L2CAP_FLAG_INTERRUPT_CONNECTED)) {
+
297 #ifdef DEBUG_USB_HOST
+
298  Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
+
299 #endif
+
300  identifier++;
+
301  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
302  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
+
303  }
+
304  break;
+
305 
+
306  case L2CAP_INTERRUPT_CONFIG_REQUEST:
+
307  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
+
308 #ifdef DEBUG_USB_HOST
+
309  Notify(PSTR("\r\nHID Channels Established"), 0x80);
+
310 #endif
+
311  pBtd->connectToHIDDevice = false;
+
312  pBtd->pairWithHIDDevice = false;
+
313  connected = true;
314  onInit();
-
315  l2cap_state = L2CAP_DONE;
+
315  l2cap_state = L2CAP_DONE;
316  }
317  break;
318 
-
319  case L2CAP_DONE:
+
319  case L2CAP_DONE:
320  break;
321 
-
322  case L2CAP_INTERRUPT_DISCONNECT:
-
323  if (l2cap_disconnect_response_interrupt_flag) {
+
322  case L2CAP_INTERRUPT_DISCONNECT:
+
323  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)) {
324 #ifdef DEBUG_USB_HOST
325  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
326 #endif
327  identifier++;
328  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
-
329  l2cap_state = L2CAP_CONTROL_DISCONNECT;
+
329  l2cap_state = L2CAP_CONTROL_DISCONNECT;
330  }
331  break;
332 
-
333  case L2CAP_CONTROL_DISCONNECT:
-
334  if (l2cap_disconnect_response_control_flag) {
+
333  case L2CAP_CONTROL_DISCONNECT:
+
334  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
335 #ifdef DEBUG_USB_HOST
336  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
337 #endif
338  pBtd->hci_disconnect(hci_handle);
339  hci_handle = -1; // Reset handle
340  l2cap_event_flag = 0; // Reset flags
-
341  l2cap_state = L2CAP_WAIT;
+
341  l2cap_state = L2CAP_WAIT;
342  }
343  break;
344  }
345 }
346 
347 void BTHID::Run() {
-
348  switch (l2cap_state) {
-
349  case L2CAP_WAIT:
-
350  if (pBtd->connectToHIDDevice && !pBtd->l2capConnectionClaimed && !connected && !activeConnection) {
+
348  switch(l2cap_state) {
+
349  case L2CAP_WAIT:
+
350  if(pBtd->connectToHIDDevice && !pBtd->l2capConnectionClaimed && !connected && !activeConnection) {
351  pBtd->l2capConnectionClaimed = true;
352  activeConnection = true;
353 #ifdef DEBUG_USB_HOST
@@ -448,8 +448,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
357  l2cap_event_flag = 0; // Reset flags
358  identifier = 0;
359  pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM);
-
360  l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
-
361  } else if (l2cap_connection_request_control_flag) {
+
360  l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
+
361  } else if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)) {
362 #ifdef DEBUG_USB_HOST
363  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
364 #endif
@@ -459,7 +459,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
368  identifier++;
369  delay(1);
370  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
371  l2cap_state = L2CAP_CONTROL_SUCCESS;
+
371  l2cap_state = L2CAP_CONTROL_SUCCESS;
372  }
373  break;
374  }
@@ -467,86 +467,100 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
376 
377 /************************************************************/
378 /* HID Commands */
-
379 /************************************************************/
-
380 void BTHID::setProtocol() {
-
381  uint8_t command = 0x70 | protocolMode; // Set Protocol, see HID specs page 33
-
382  pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);
-
383 }
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
-
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:121
-
BTHID::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:61
-
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
-
L2CAP_CONTROL_CONFIG_REQUEST
#define L2CAP_CONTROL_CONFIG_REQUEST
Definition: BTHID.h:34
-
BTD
Definition: BTD.h:158
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
-
l2cap_disconnect_response_interrupt_flag
#define l2cap_disconnect_response_interrupt_flag
Definition: BTHID.h:59
-
BTHID::connected
bool connected
Definition: BTHID.h:103
+
379 
+
380 /************************************************************/
+
381 void BTHID::setProtocol() {
+
382 #ifdef DEBUG_USB_HOST
+
383  Notify(PSTR("\r\nSet protocol mode: "), 0x80);
+
384  D_PrintHex<uint8_t > (protocolMode, 0x80);
+
385 #endif
+
386  if (protocolMode != HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) {
+
387 #ifdef DEBUG_USB_HOST
+
388  Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80);
+
389 #endif
+
390  protocolMode = HID_BOOT_PROTOCOL; // Use Boot Protocol by default
+
391  }
+
392  uint8_t command = 0x70 | protocolMode; // Set Protocol, see Bluetooth HID specs page 33
+
393  pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);
+
394 }
+
395 
+
396 void BTHID::setLeds(uint8_t data) {
+
397  uint8_t buf[3];
+
398  buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
399  buf[1] = 0x01; // Report ID
+
400  buf[2] = data;
+
401  pBtd->L2CAP_Command(hci_handle, buf, 3, interrupt_scid[0], interrupt_scid[1]);
+
402 }
+
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTD.h:139
+
UHS_ACL_HANDLE_OK
#define UHS_ACL_HANDLE_OK(x, y)
Definition: BTD.h:207
+
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTD.h:143
+
L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTD.h:115
+
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTD.h:113
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:177
+
BTHID::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:58
+
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTD.h:142
+
HID_RPT_PROTOCOL
#define HID_RPT_PROTOCOL
Definition: hid.h:83
+
BTD
Definition: BTD.h:230
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
BTHID::connected
bool connected
Definition: BTHID.h:93
BTHID::Run
virtual void Run()
Definition: BTHID.cpp:347
-
BTD::btdPin
const char * btdPin
Definition: BTD.h:407
-
BTHID::Reset
virtual void Reset()
Definition: BTHID.cpp:47
-
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTHID.h:47
-
l2cap_connection_request_control_flag
#define l2cap_connection_request_control_flag
Definition: BTHID.h:60
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
-
L2CAP_FLAG_INTERRUPT_CONNECTED
#define L2CAP_FLAG_INTERRUPT_CONNECTED
Definition: BTHID.h:45
+
BTD::btdPin
const char * btdPin
Definition: BTD.h:482
+
L2CAP_DONE
#define L2CAP_DONE
Definition: BTD.h:104
+
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTD.h:109
+
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTD.h:103
+
BTHID::Reset
virtual void Reset()
Definition: BTHID.cpp:44
+
L2CAP_CONTROL_CONFIG_REQUEST
#define L2CAP_CONTROL_CONFIG_REQUEST
Definition: BTD.h:108
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
Notify
#define Notify(...)
Definition: message.h:44
-
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTHID.h:26
-
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:444
-
HID_BOOT_PROTOCOL
#define HID_BOOT_PROTOCOL
Definition: hid.h:79
-
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTHID.h:49
-
l2cap_connection_request_interrupt_flag
#define l2cap_connection_request_interrupt_flag
Definition: BTHID.h:61
-
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:126
-
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:448
-
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:450
-
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTHID.h:40
-
MOUSE_PARSER_ID
#define MOUSE_PARSER_ID
Definition: BTHID.h:64
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
-
Notifyc
#define Notifyc(...)
Definition: message.h:46
+
BTD::connectToHIDDevice
bool connectToHIDDevice
Definition: BTD.h:519
+
HID_BOOT_PROTOCOL
#define HID_BOOT_PROTOCOL
Definition: hid.h:82
+
L2CAP_CONTROL_CONNECT_REQUEST
#define L2CAP_CONTROL_CONNECT_REQUEST
Definition: BTD.h:107
+
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:182
+
BTD::incomingHIDDevice
bool incomingHIDDevice
Definition: BTD.h:523
+
BTD::pairWithHIDDevice
bool pairWithHIDDevice
Definition: BTD.h:525
+
MOUSE_PARSER_ID
#define MOUSE_PARSER_ID
Definition: BTHID.h:25
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
BTHID.h
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
-
BTHID::disconnect
virtual void disconnect()
Definition: BTHID.cpp:54
-
L2CAP_CONTROL_CONNECT_REQUEST
#define L2CAP_CONTROL_CONNECT_REQUEST
Definition: BTHID.h:33
-
HID
Definition: hid.h:143
-
L2CAP_DONE
#define L2CAP_DONE
Definition: BTHID.h:38
-
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTHID.h:30
-
l2cap_disconnect_response_control_flag
#define l2cap_disconnect_response_control_flag
Definition: BTHID.h:58
-
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTHID.h:51
-
epMUL
#define epMUL
Definition: BTHID.h:65
-
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTHID.h:50
-
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:127
-
L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_CONNECT_REQUEST
Definition: BTHID.h:35
-
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
-
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:398
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTD.h:145
+
BTHID::disconnect
virtual void disconnect()
Definition: BTHID.cpp:51
+
BTHID::setLeds
void setLeds(uint8_t data)
Definition: BTHID.cpp:396
+
l2cap_check_flag
#define l2cap_check_flag(flag)
Definition: BTD.h:160
+
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:168
+
L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_FLAG_CONTROL_CONNECTED
Definition: BTD.h:138
+
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:170
+
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTD.h:110
+
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTD.h:136
+
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:183
+
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:333
+
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:473
HIDReportParser::Parse
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)=0
-
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:115
-
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:111
-
l2cap_connected_interrupt_flag
#define l2cap_connected_interrupt_flag
Definition: BTHID.h:55
-
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_FLAG_CONTROL_CONNECTED
Definition: BTHID.h:44
-
l2cap_config_success_control_flag
#define l2cap_config_success_control_flag
Definition: BTHID.h:56
-
l2cap_config_success_interrupt_flag
#define l2cap_config_success_interrupt_flag
Definition: BTHID.h:57
-
KEYBOARD_PARSER_ID
#define KEYBOARD_PARSER_ID
Definition: BTHID.h:63
-
l2cap_connected_control_flag
#define l2cap_connected_control_flag
Definition: BTHID.h:54
-
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTHID.h:29
-
BTHID::BTHID
BTHID(BTD *p, bool pair=false, const char *pin="1234")
Definition: BTHID.cpp:23
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
PENDING
#define PENDING
Definition: BTD.h:120
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTHID.h:37
-
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
-
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTHID.h:41
-
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTHID.h:48
-
BTHID::pair
void pair(void)
Definition: BTHID.h:109
-
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTHID.h:46
-
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:109
+
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
+
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:167
+
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
+
NUM_PARSERS
#define NUM_PARSERS
Definition: BTHID.h:26
+
KEYBOARD_PARSER_ID
#define KEYBOARD_PARSER_ID
Definition: BTHID.h:24
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
PENDING
#define PENDING
Definition: BTD.h:176
+
L2CAP_FLAG_INTERRUPT_CONNECTED
#define L2CAP_FLAG_INTERRUPT_CONNECTED
Definition: BTD.h:144
+
l2cap_set_flag
#define l2cap_set_flag(flag)
Definition: BTD.h:161
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTD.h:137
+
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
+
BTHID::BTHID
BTHID(BTD *p, bool pair=false, const char *pin="0000")
Definition: BTHID.cpp:23
+
L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_CONNECT_REQUEST
Definition: BTD.h:114
+
BTHID::pair
void pair(void)
Definition: BTHID.h:96
+
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTD.h:116
+
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:165
diff --git a/_b_t_h_i_d_8h.html b/_b_t_h_i_d_8h.html index e2513294..e2c94944 100644 --- a/_b_t_h_i_d_8h.html +++ b/_b_t_h_i_d_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTHID.h File Reference @@ -31,7 +31,7 @@ - + @@ -93,21 +93,20 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
#include "BTD.h"
-#include "controllerEnums.h"
#include "hidboot.h"
Include dependency graph for BTHID.h:
- +
This graph shows which files directly or indirectly include this file:
- +

Go to the source code of this file.

@@ -119,430 +118,14 @@ Classes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +

Macros

#define L2CAP_WAIT   0
 
#define L2CAP_CONTROL_SUCCESS   1
 
#define L2CAP_INTERRUPT_SETUP   2
 
#define L2CAP_CONTROL_CONNECT_REQUEST   3
 
#define L2CAP_CONTROL_CONFIG_REQUEST   4
 
#define L2CAP_INTERRUPT_CONNECT_REQUEST   5
 
#define L2CAP_INTERRUPT_CONFIG_REQUEST   6
 
#define L2CAP_DONE   7
 
#define L2CAP_INTERRUPT_DISCONNECT   8
 
#define L2CAP_CONTROL_DISCONNECT   9
 
#define L2CAP_FLAG_CONTROL_CONNECTED   0x01
 
#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x02
 
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x04
 
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x08
 
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x10
 
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x20
 
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x40
 
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x80
 
#define l2cap_connected_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
 
#define l2cap_connected_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
 
#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
 
#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
 
#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
 
#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
 
#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
 
#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
 
#define KEYBOARD_PARSER_ID   0
 
#define MOUSE_PARSER_ID   1
 
#define epMUL   2
 
#define NUM_PARSERS   2
 

Macro Definition Documentation

- -
-
- - - - -
#define L2CAP_WAIT   0
-
- -

Definition at line 26 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_SUCCESS   1
-
- -

Definition at line 29 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_SETUP   2
-
- -

Definition at line 30 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_CONNECT_REQUEST   3
-
- -

Definition at line 33 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_CONFIG_REQUEST   4
-
- -

Definition at line 34 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_CONNECT_REQUEST   5
-
- -

Definition at line 35 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_CONFIG_REQUEST   6
-
- -

Definition at line 37 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_DONE   7
-
- -

Definition at line 38 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_DISCONNECT   8
-
- -

Definition at line 40 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_DISCONNECT   9
-
- -

Definition at line 41 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONTROL_CONNECTED   0x01
-
- -

Definition at line 44 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x02
-
- -

Definition at line 45 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x04
-
- -

Definition at line 46 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x08
-
- -

Definition at line 47 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x10
-
- -

Definition at line 48 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x20
-
- -

Definition at line 49 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x40
-
- -

Definition at line 50 of file BTHID.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x80
-
- -

Definition at line 51 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_connected_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
-
- -

Definition at line 54 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_connected_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
-
- -

Definition at line 55 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
- -

Definition at line 56 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
- -

Definition at line 57 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
- -

Definition at line 58 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
- -

Definition at line 59 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
- -

Definition at line 60 of file BTHID.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
- -

Definition at line 61 of file BTHID.h.

- -
-
@@ -553,7 +136,7 @@ Macros
-

Definition at line 63 of file BTHID.h.

+

Definition at line 24 of file BTHID.h.

@@ -567,21 +150,21 @@ Macros
-

Definition at line 64 of file BTHID.h.

+

Definition at line 25 of file BTHID.h.

- +
- +
#define epMUL   2#define NUM_PARSERS   2
-

Definition at line 65 of file BTHID.h.

+

Definition at line 26 of file BTHID.h.

@@ -590,7 +173,7 @@ Macros diff --git a/_b_t_h_i_d_8h__dep__incl.map b/_b_t_h_i_d_8h__dep__incl.map index 07165275..81735ccb 100644 --- a/_b_t_h_i_d_8h__dep__incl.map +++ b/_b_t_h_i_d_8h__dep__incl.map @@ -1,3 +1,5 @@ + + diff --git a/_b_t_h_i_d_8h__dep__incl.md5 b/_b_t_h_i_d_8h__dep__incl.md5 index 7a89812c..3c0c2208 100644 --- a/_b_t_h_i_d_8h__dep__incl.md5 +++ b/_b_t_h_i_d_8h__dep__incl.md5 @@ -1 +1 @@ -b3540e7b4b9e3a2df110f82ca3e6f24e \ No newline at end of file +f8f7a945eda22215fd32dc14b58fcae7 \ No newline at end of file diff --git a/_b_t_h_i_d_8h__dep__incl.png b/_b_t_h_i_d_8h__dep__incl.png index 3ae84761..ec9f42f9 100644 Binary files a/_b_t_h_i_d_8h__dep__incl.png and b/_b_t_h_i_d_8h__dep__incl.png differ diff --git a/_b_t_h_i_d_8h__incl.map b/_b_t_h_i_d_8h__incl.map index 151695cf..1bcd73e5 100644 --- a/_b_t_h_i_d_8h__incl.map +++ b/_b_t_h_i_d_8h__incl.map @@ -1,8 +1,7 @@ - - - - - - + + + + + diff --git a/_b_t_h_i_d_8h__incl.md5 b/_b_t_h_i_d_8h__incl.md5 index 9569d8d9..f98ecfbe 100644 --- a/_b_t_h_i_d_8h__incl.md5 +++ b/_b_t_h_i_d_8h__incl.md5 @@ -1 +1 @@ -037c2f7eb5bb2a91683242d6c47805c2 \ No newline at end of file +50c98864be761896492416679dad01a4 \ No newline at end of file diff --git a/_b_t_h_i_d_8h__incl.png b/_b_t_h_i_d_8h__incl.png index d53716bc..60567abb 100644 Binary files a/_b_t_h_i_d_8h__incl.png and b/_b_t_h_i_d_8h__incl.png differ diff --git a/_b_t_h_i_d_8h_source.html b/_b_t_h_i_d_8h_source.html index de09f221..207607cf 100644 --- a/_b_t_h_i_d_8h_source.html +++ b/_b_t_h_i_d_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTHID.h Source File @@ -31,7 +31,7 @@ - + @@ -110,144 +110,109 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
19 #define _bthid_h_
20 
21 #include "BTD.h"
-
22 #include "controllerEnums.h"
-
23 #include "hidboot.h"
-
24 
-
25 /* Bluetooth L2CAP states for L2CAP_task() */
-
26 #define L2CAP_WAIT 0
+
22 #include "hidboot.h"
+
23 
+
24 #define KEYBOARD_PARSER_ID 0
+
25 #define MOUSE_PARSER_ID 1
+
26 #define NUM_PARSERS 2
27 
-
28 // These states are used if the device is the host
-
29 #define L2CAP_CONTROL_SUCCESS 1
-
30 #define L2CAP_INTERRUPT_SETUP 2
-
31 
-
32 // These states are used if the Arduino is the host
-
33 #define L2CAP_CONTROL_CONNECT_REQUEST 3
-
34 #define L2CAP_CONTROL_CONFIG_REQUEST 4
-
35 #define L2CAP_INTERRUPT_CONNECT_REQUEST 5
-
36 
-
37 #define L2CAP_INTERRUPT_CONFIG_REQUEST 6
-
38 #define L2CAP_DONE 7
-
39 
-
40 #define L2CAP_INTERRUPT_DISCONNECT 8
-
41 #define L2CAP_CONTROL_DISCONNECT 9
-
42 
-
43 /* L2CAP event flags */
-
44 #define L2CAP_FLAG_CONTROL_CONNECTED 0x01
-
45 #define L2CAP_FLAG_INTERRUPT_CONNECTED 0x02
-
46 #define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS 0x04
-
47 #define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS 0x08
-
48 #define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE 0x10
-
49 #define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE 0x20
-
50 #define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x40
-
51 #define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST 0x80
-
52 
-
53 /* Macros for L2CAP event flag tests */
-
54 #define l2cap_connected_control_flag (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
-
55 #define l2cap_connected_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
-
56 #define l2cap_config_success_control_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
57 #define l2cap_config_success_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
58 #define l2cap_disconnect_response_control_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
59 #define l2cap_disconnect_response_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
60 #define l2cap_connection_request_control_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
61 #define l2cap_connection_request_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
62 
-
63 #define KEYBOARD_PARSER_ID 0
-
64 #define MOUSE_PARSER_ID 1
-
65 #define epMUL 2
-
66 
-
68 class BTHID : public BluetoothService {
-
69 public:
-
76  BTHID(BTD *p, bool pair = false, const char *pin = "1234");
+
29 class BTHID : public BluetoothService {
+
30 public:
+
37  BTHID(BTD *p, bool pair = false, const char *pin = "0000");
+
38 
+
44  virtual void ACLData(uint8_t* ACLData);
+
46  virtual void Run();
+
48  virtual void Reset();
+
50  virtual void disconnect();
+
51 
+
59  HIDReportParser *GetReportParser(uint8_t id) {
+
60  if (id >= NUM_PARSERS)
+
61  return NULL;
+
62  return pRptParser[id];
+
63  };
+
64 
+
71  bool SetReportParser(uint8_t id, HIDReportParser *prs) {
+
72  if (id >= NUM_PARSERS)
+
73  return false;
+
74  pRptParser[id] = prs;
+
75  return true;
+
76  };
77 
-
83  virtual void ACLData(uint8_t* ACLData);
-
85  virtual void Run();
-
87  virtual void Reset();
-
89  virtual void disconnect();
-
92  HIDReportParser *GetReportParser(uint8_t id) {
-
93  return pRptParser[id];
-
94  };
-
95 
-
96  bool SetReportParser(uint8_t id, HIDReportParser *prs) {
-
97  pRptParser[id] = prs;
-
98  return true;
+
82  void setProtocolMode(uint8_t mode) {
+
83  protocolMode = mode;
+
84  };
+
85 
+
90  void setLeds(uint8_t data);
+
91 
+
93  bool connected;
+
94 
+
96  void pair(void) {
+
97  if(pBtd)
+
98  pBtd->pairWithHID();
99  };
100 
-
101  void setProtocolMode(uint8_t mode) {
-
102  protocolMode = mode;
-
103  };
-
104 
-
106  bool connected;
-
107 
-
109  void pair(void) {
-
110  if (pBtd)
-
111  pBtd->pairWithHID();
-
112  };
+
105  void attachOnInit(void (*funcOnInit)(void)) {
+
106  pFuncOnInit = funcOnInit;
+
107  };
+
108 
+
109 private:
+
110  BTD *pBtd; // Pointer to BTD instance
+
111 
+
112  HIDReportParser *pRptParser[NUM_PARSERS]; // Pointer to HIDReportParsers.
113 
-
118  void attachOnInit(void (*funcOnInit)(void)) {
-
119  pFuncOnInit = funcOnInit;
-
120  };
-
121 
-
122 private:
-
123  BTD *pBtd; // Pointer to BTD instance
-
124 
-
125  HIDReportParser *pRptParser[epMUL];
-
126 
-
128  void setProtocol();
-
129  uint8_t protocolMode;
+
115  void setProtocol();
+
116  uint8_t protocolMode;
+
117 
+
123  void onInit() {
+
124  if(pFuncOnInit)
+
125  pFuncOnInit(); // Call the user function
+
126  };
+
127  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
128 
+
129  void L2CAP_task(); // L2CAP state machine
130 
-
136  void onInit() {
-
137  if (pFuncOnInit)
-
138  pFuncOnInit(); // Call the user function
-
139  }
-
140  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
-
141 
-
142  void L2CAP_task(); // L2CAP state machine
-
143 
-
144  /* Variables filled from HCI event management */
-
145  uint16_t hci_handle;
-
146  bool activeConnection; // Used to indicate if it's already has established a connection
-
147 
-
148  /* Variables used by high level L2CAP task */
-
149  uint8_t l2cap_state;
-
150  uint8_t l2cap_event_flag; // l2cap flags of received Bluetooth events
-
151 
-
152  uint8_t ButtonState, OldButtonState, ButtonClickState;
-
153  int16_t xAxis, yAxis, scroll;
-
154 
-
155  /* L2CAP Channels */
-
156  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
-
157  uint8_t control_dcid[2]; // 0x0070
-
158  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
-
159  uint8_t interrupt_dcid[2]; // 0x0071
-
160  uint8_t identifier; // Identifier for connection
-
161 };
-
162 #endif
+
131  /* Variables filled from HCI event management */
+
132  uint16_t hci_handle;
+
133  bool activeConnection; // Used to indicate if it already has established a connection
+
134 
+
135  /* Variables used by high level L2CAP task */
+
136  uint8_t l2cap_state;
+
137  uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events
+
138 
+
139  /* L2CAP Channels */
+
140  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
+
141  uint8_t control_dcid[2]; // 0x0070
+
142  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
+
143  uint8_t interrupt_dcid[2]; // 0x0071
+
144  uint8_t identifier; // Identifier for connection
+
145 };
+
146 #endif
hidboot.h
-
BTHID::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:61
-
BTD
Definition: BTD.h:158
-
BTHID::connected
bool connected
Definition: BTHID.h:103
+
BTHID::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:58
+
BTD
Definition: BTD.h:230
+
BTHID::connected
bool connected
Definition: BTHID.h:93
BTHID::Run
virtual void Run()
Definition: BTHID.cpp:347
-
BTHID::Reset
virtual void Reset()
Definition: BTHID.cpp:47
-
controllerEnums.h
-
BTHID::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: BTHID.h:118
-
BTD::pairWithHID
void pairWithHID()
Definition: BTD.h:441
-
BluetoothService
Definition: BTD.h:139
-
BTHID::disconnect
virtual void disconnect()
Definition: BTHID.cpp:54
-
BTHID::GetReportParser
HIDReportParser * GetReportParser(uint8_t id)
Definition: BTHID.h:92
-
epMUL
#define epMUL
Definition: BTHID.h:65
-
HIDReportParser
Definition: hid.h:135
-
BTHID::BTHID
BTHID(BTD *p, bool pair=false, const char *pin="1234")
Definition: BTHID.cpp:23
-
BTHID
Definition: BTHID.h:68
+
BTHID::Reset
virtual void Reset()
Definition: BTHID.cpp:44
+
BTHID::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: BTHID.h:105
+
BTD::pairWithHID
void pairWithHID()
Definition: BTD.h:516
+
BluetoothService
Definition: BTD.h:211
+
BTHID::disconnect
virtual void disconnect()
Definition: BTHID.cpp:51
+
BTHID::GetReportParser
HIDReportParser * GetReportParser(uint8_t id)
Definition: BTHID.h:59
+
BTHID::setLeds
void setLeds(uint8_t data)
Definition: BTHID.cpp:396
+
NUM_PARSERS
#define NUM_PARSERS
Definition: BTHID.h:26
+
HIDReportParser
Definition: hid.h:138
+
BTHID
Definition: BTHID.h:29
BTD.h
-
BTHID::setProtocolMode
void setProtocolMode(uint8_t mode)
Definition: BTHID.h:101
-
BTHID::pair
void pair(void)
Definition: BTHID.h:109
-
BTHID::SetReportParser
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:96
+
BTHID::setProtocolMode
void setProtocolMode(uint8_t mode)
Definition: BTHID.h:82
+
BTHID::BTHID
BTHID(BTD *p, bool pair=false, const char *pin="0000")
Definition: BTHID.cpp:23
+
BTHID::pair
void pair(void)
Definition: BTHID.h:96
+
BTHID::SetReportParser
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:71
diff --git a/_p_s3_b_t_8cpp.html b/_p_s3_b_t_8cpp.html index ca81baa9..4fb4c2ad 100644 --- a/_p_s3_b_t_8cpp.html +++ b/_p_s3_b_t_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3BT.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for PS3BT.cpp: diff --git a/_p_s3_b_t_8cpp_source.html b/_p_s3_b_t_8cpp_source.html index 38fc88f1..3403e036 100644 --- a/_p_s3_b_t_8cpp_source.html +++ b/_p_s3_b_t_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3BT.cpp Source File @@ -31,7 +31,7 @@ - + @@ -114,7 +114,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
23 PS3BT::PS3BT(BTD *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) :
24 pBtd(p) // pointer to USB class instance - mandatory
25 {
-
26  if (pBtd)
+
26  if(pBtd)
27  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
28 
29  pBtd->my_bdaddr[5] = btadr5; // Change to your dongle's Bluetooth address instead
@@ -140,35 +140,35 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
49  Reset();
50 }
51 
-
52 bool PS3BT::getButtonPress(Button b) {
-
53  return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
+
52 bool PS3BT::getButtonPress(ButtonEnum b) {
+
53  return (ButtonState & pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]));
54 }
55 
-
56 bool PS3BT::getButtonClick(Button b) {
-
57  uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
+
56 bool PS3BT::getButtonClick(ButtonEnum b) {
+
57  uint32_t button = pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]);
58  bool click = (ButtonClickState & button);
59  ButtonClickState &= ~button; // Clear "click" event
60  return click;
61 }
62 
-
63 uint8_t PS3BT::getAnalogButton(Button a) {
-
64  return (uint8_t)(l2capinbuf[pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a])]);
+
63 uint8_t PS3BT::getAnalogButton(ButtonEnum a) {
+
64  return (uint8_t)(l2capinbuf[pgm_read_byte(&PS3_ANALOG_BUTTONS[(uint8_t)a])]);
65 }
66 
-
67 uint8_t PS3BT::getAnalogHat(AnalogHat a) {
+
67 uint8_t PS3BT::getAnalogHat(AnalogHatEnum a) {
68  return (uint8_t)(l2capinbuf[(uint8_t)a + 15]);
69 }
70 
-
71 int16_t PS3BT::getSensor(Sensor a) {
-
72  if (PS3Connected) {
-
73  if (a == aX || a == aY || a == aZ || a == gZ)
+
71 int16_t PS3BT::getSensor(SensorEnum a) {
+
72  if(PS3Connected) {
+
73  if(a == aX || a == aY || a == aZ || a == gZ)
74  return ((l2capinbuf[(uint16_t)a] << 8) | l2capinbuf[(uint16_t)a + 1]);
75  else
76  return 0;
-
77  } else if (PS3MoveConnected) {
-
78  if (a == mXmove || a == mYmove) // These are all 12-bits long
+
77  } else if(PS3MoveConnected) {
+
78  if(a == mXmove || a == mYmove) // These are all 12-bits long
79  return (((l2capinbuf[(uint16_t)a] & 0x0F) << 8) | (l2capinbuf[(uint16_t)a + 1]));
-
80  else if (a == mZmove || a == tempMove) // The tempearature is also 12 bits long
+
80  else if(a == mZmove || a == tempMove) // The tempearature is also 12 bits long
81  return ((l2capinbuf[(uint16_t)a] << 4) | ((l2capinbuf[(uint16_t)a + 1] & 0xF0) >> 4));
82  else // aXmove, aYmove, aZmove, gXmove, gYmove and gZmove
83  return (l2capinbuf[(uint16_t)a] | (l2capinbuf[(uint16_t)a + 1] << 8));
@@ -176,55 +176,55 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
85  return 0;
86 }
87 
-
88 double PS3BT::getAngle(Angle a) {
+
88 double PS3BT::getAngle(AngleEnum a) {
89  double accXval, accYval, accZval;
90 
-
91  if (PS3Connected) {
+
91  if(PS3Connected) {
92  // Data for the Kionix KXPC4 used in the DualShock 3
93  const double zeroG = 511.5; // 1.65/3.3*1023 (1.65V)
-
94  accXval = -((double)getSensor(aX) - zeroG);
-
95  accYval = -((double)getSensor(aY) - zeroG);
-
96  accZval = -((double)getSensor(aZ) - zeroG);
-
97  } else if (PS3MoveConnected) {
+
94  accXval = -((double)getSensor(aX) - zeroG);
+
95  accYval = -((double)getSensor(aY) - zeroG);
+
96  accZval = -((double)getSensor(aZ) - zeroG);
+
97  } else if(PS3MoveConnected) {
98  // It's a Kionix KXSC4 inside the Motion controller
99  const uint16_t zeroG = 0x8000;
-
100  accXval = -(int16_t)(getSensor(aXmove) - zeroG);
-
101  accYval = (int16_t)(getSensor(aYmove) - zeroG);
-
102  accZval = (int16_t)(getSensor(aZmove) - zeroG);
+
100  accXval = -(int16_t)(getSensor(aXmove) - zeroG);
+
101  accYval = (int16_t)(getSensor(aYmove) - zeroG);
+
102  accZval = (int16_t)(getSensor(aZmove) - zeroG);
103  } else
104  return 0;
105 
106  // Convert to 360 degrees resolution
107  // atan2 outputs the value of -Ï€ to Ï€ (radians)
108  // We are then converting it to 0 to 2Ï€ and then to degrees
-
109  if (a == Pitch)
+
109  if(a == Pitch)
110  return (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
111  else
112  return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
113 }
114 
-
115 double PS3BT::get9DOFValues(Sensor a) { // Thanks to Manfred Piendl
-
116  if (!PS3MoveConnected)
+
115 double PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl
+
116  if(!PS3MoveConnected)
117  return 0;
-
118  int16_t value = getSensor(a);
-
119  if (a == mXmove || a == mYmove || a == mZmove) {
-
120  if (value > 2047)
+
118  int16_t value = getSensor(a);
+
119  if(a == mXmove || a == mYmove || a == mZmove) {
+
120  if(value > 2047)
121  value -= 0x1000;
122  return (double)value / 3.2; // unit: muT = 10^(-6) Tesla
-
123  } else if (a == aXmove || a == aYmove || a == aZmove) {
-
124  if (value < 0)
+
123  } else if(a == aXmove || a == aYmove || a == aZmove) {
+
124  if(value < 0)
125  value += 0x8000;
126  else
127  value -= 0x8000;
128  return (double)value / 442.0; // unit: m/(s^2)
-
129  } else if (a == gXmove || a == gYmove || a == gZmove) {
-
130  if (value < 0)
+
129  } else if(a == gXmove || a == gYmove || a == gZmove) {
+
130  if(value < 0)
131  value += 0x8000;
132  else
133  value -= 0x8000;
-
134  if (a == gXmove)
+
134  if(a == gXmove)
135  return (double)value / 11.6; // unit: deg/s
-
136  else if (a == gYmove)
+
136  else if(a == gYmove)
137  return (double)value / 11.2; // unit: deg/s
138  else // gZmove
139  return (double)value / 9.6; // unit: deg/s
@@ -233,12 +233,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
142 }
143 
144 String PS3BT::getTemperature() {
-
145  if (PS3MoveConnected) {
-
146  int16_t input = getSensor(tempMove);
+
145  if(PS3MoveConnected) {
+
146  int16_t input = getSensor(tempMove);
147 
148  String output = String(input / 100);
149  output += ".";
-
150  if (input % 100 < 10)
+
150  if(input % 100 < 10)
151  output += "0";
152  output += String(input % 100);
153 
@@ -247,645 +247,619 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
156  return "Error";
157 }
158 
-
159 bool PS3BT::getStatus(Status c) {
+
159 bool PS3BT::getStatus(StatusEnum c) {
160  return (l2capinbuf[(uint16_t)c >> 8] == ((uint8_t)c & 0xff));
161 }
162 
-
163 String PS3BT::getStatusString() {
-
164  if (PS3Connected || PS3NavigationConnected) {
-
165  char statusOutput[100];
-
166 
-
167  strcpy(statusOutput, "ConnectionStatus: ");
-
168 
-
169  if (getStatus(Plugged)) strcat(statusOutput, "Plugged");
-
170  else if (getStatus(Unplugged)) strcat(statusOutput, "Unplugged");
-
171  else strcat(statusOutput, "Error");
-
172 
+
163 void PS3BT::printStatusString() {
+
164  char statusOutput[100]; // Max string length plus null character
+
165  if(PS3Connected || PS3NavigationConnected) {
+
166  strcpy_P(statusOutput, PSTR("ConnectionStatus: "));
+
167 
+
168  if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged"));
+
169  else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged"));
+
170  else strcat_P(statusOutput, PSTR("Error"));
+
171 
+
172  strcat_P(statusOutput, PSTR(" - PowerRating: "));
173 
-
174  strcat(statusOutput, " - PowerRating: ");
-
175  if (getStatus(Charging)) strcat(statusOutput, "Charging");
-
176  else if (getStatus(NotCharging)) strcat(statusOutput, "Not Charging");
-
177  else if (getStatus(Shutdown)) strcat(statusOutput, "Shutdown");
-
178  else if (getStatus(Dying)) strcat(statusOutput, "Dying");
-
179  else if (getStatus(Low)) strcat(statusOutput, "Low");
-
180  else if (getStatus(High)) strcat(statusOutput, "High");
-
181  else if (getStatus(Full)) strcat(statusOutput, "Full");
-
182  else strcat(statusOutput, "Error");
-
183 
-
184  strcat(statusOutput, " - WirelessStatus: ");
-
185 
-
186  if (getStatus(CableRumble)) strcat(statusOutput, "Cable - Rumble is on");
-
187  else if (getStatus(Cable)) strcat(statusOutput, "Cable - Rumble is off");
-
188  else if (getStatus(BluetoothRumble)) strcat(statusOutput, "Bluetooth - Rumble is on");
-
189  else if (getStatus(Bluetooth)) strcat(statusOutput, "Bluetooth - Rumble is off");
-
190  else strcat(statusOutput, "Error");
-
191 
-
192  return statusOutput;
-
193 
-
194  } else if (PS3MoveConnected) {
-
195  char statusOutput[50];
-
196 
-
197  strcpy(statusOutput, "PowerRating: ");
-
198 
-
199  if (getStatus(MoveCharging)) strcat(statusOutput, "Charging");
-
200  else if (getStatus(MoveNotCharging)) strcat(statusOutput, "Not Charging");
-
201  else if (getStatus(MoveShutdown)) strcat(statusOutput, "Shutdown");
-
202  else if (getStatus(MoveDying)) strcat(statusOutput, "Dying");
-
203  else if (getStatus(MoveLow)) strcat(statusOutput, "Low");
-
204  else if (getStatus(MoveHigh)) strcat(statusOutput, "High");
-
205  else if (getStatus(MoveFull)) strcat(statusOutput, "Full");
-
206  else strcat(statusOutput, "Error");
-
207 
-
208  return statusOutput;
-
209  } else
-
210  return "Error";
-
211 }
-
212 
-
213 void PS3BT::Reset() {
-
214  PS3Connected = false;
-
215  PS3MoveConnected = false;
-
216  PS3NavigationConnected = false;
-
217  activeConnection = false;
-
218  l2cap_event_flag = 0; // Reset flags
-
219  l2cap_state = L2CAP_WAIT;
-
220 
-
221  // Needed for PS3 Dualshock Controller commands to work via bluetooth
-
222  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
-
223  HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
-
224 }
-
225 
-
226 void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
-
227  //First the HID interrupt channel has to be disconencted, then the HID control channel and finally the HCI connection
-
228  pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
-
229  Reset();
-
230  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
-
231 }
-
232 
-
233 void PS3BT::ACLData(uint8_t* ACLData) {
-
234  if (!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected && !activeConnection && !pBtd->connectToWii && !pBtd->incomingWii && !pBtd->pairWithWii) {
-
235  if (ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
236  if ((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) {
-
237  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
-
238  activeConnection = true;
-
239  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
240  l2cap_state = L2CAP_WAIT;
-
241  for (uint8_t i = 0; i < 30; i++)
-
242  remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection
-
243 #ifdef DEBUG_USB_HOST
-
244  if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle
-
245  Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
-
246  Notify(pBtd->hci_version, 0x80);
-
247  Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80);
-
248  }
-
249 #endif
-
250  }
-
251  }
-
252  }
-
253  if (((ACLData[0] | (ACLData[1] << 8)) == (hci_handle | 0x2000))) { //acl_handle_ok
-
254  memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
-
255  if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
-
256  if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
-
257 #ifdef DEBUG_USB_HOST
-
258  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
-
259  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
260  Notify(PSTR(" "), 0x80);
-
261  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
262  Notify(PSTR(" Data: "), 0x80);
-
263  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
-
264  Notify(PSTR(" "), 0x80);
-
265  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
-
266  Notify(PSTR(" "), 0x80);
-
267  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
268  Notify(PSTR(" "), 0x80);
-
269  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
270 #endif
-
271  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
272 #ifdef EXTRADEBUG
-
273  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
-
274  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
275  Notify(PSTR(" "), 0x80);
-
276  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
277  Notify(PSTR(" SCID: "), 0x80);
-
278  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
279  Notify(PSTR(" "), 0x80);
-
280  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
281  Notify(PSTR(" Identifier: "), 0x80);
-
282  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
283 #endif
-
284  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
174  if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging"));
+
175  else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
+
176  else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
+
177  else if(getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying"));
+
178  else if(getStatus(Low)) strcat_P(statusOutput, PSTR("Low"));
+
179  else if(getStatus(High)) strcat_P(statusOutput, PSTR("High"));
+
180  else if(getStatus(Full)) strcat_P(statusOutput, PSTR("Full"));
+
181  else strcat_P(statusOutput, PSTR("Error"));
+
182 
+
183  strcat_P(statusOutput, PSTR(" - WirelessStatus: "));
+
184 
+
185  if(getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on"));
+
186  else if(getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off"));
+
187  else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on"));
+
188  else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off"));
+
189  else strcat_P(statusOutput, PSTR("Error"));
+
190  } else if(PS3MoveConnected) {
+
191  strcpy_P(statusOutput, PSTR("PowerRating: "));
+
192 
+
193  if(getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging"));
+
194  else if(getStatus(MoveNotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
+
195  else if(getStatus(MoveShutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
+
196  else if(getStatus(MoveDying)) strcat_P(statusOutput, PSTR("Dying"));
+
197  else if(getStatus(MoveLow)) strcat_P(statusOutput, PSTR("Low"));
+
198  else if(getStatus(MoveHigh)) strcat_P(statusOutput, PSTR("High"));
+
199  else if(getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full"));
+
200  else strcat_P(statusOutput, PSTR("Error"));
+
201  } else
+
202  strcpy_P(statusOutput, PSTR("Error"));
+
203 
+
204  USB_HOST_SERIAL.write((uint8_t*)statusOutput, strlen(statusOutput));
+
205 }
+
206 
+
207 void PS3BT::Reset() {
+
208  PS3Connected = false;
+
209  PS3MoveConnected = false;
+
210  PS3NavigationConnected = false;
+
211  activeConnection = false;
+
212  l2cap_event_flag = 0; // Reset flags
+
213  l2cap_state = L2CAP_WAIT;
+
214 
+
215  // Needed for PS3 Dualshock Controller commands to work via Bluetooth
+
216  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
+
217  HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
+
218 }
+
219 
+
220 void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
+
221  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
+
222  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
+
223  Reset();
+
224  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
+
225 }
+
226 
+
227 void PS3BT::ACLData(uint8_t* ACLData) {
+
228  if(!pBtd->l2capConnectionClaimed && !PS3Connected && !PS3MoveConnected && !PS3NavigationConnected && !activeConnection && !pBtd->connectToWii && !pBtd->incomingWii && !pBtd->pairWithWii) {
+
229  if(ACLData[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
230  if((ACLData[12] | (ACLData[13] << 8)) == HID_CTRL_PSM) {
+
231  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
+
232  activeConnection = true;
+
233  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
+
234  l2cap_state = L2CAP_WAIT;
+
235  for(uint8_t i = 0; i < 30; i++)
+
236  remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection
+
237 #ifdef DEBUG_USB_HOST
+
238  if(pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle
+
239  Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
+
240  Notify(pBtd->hci_version, 0x80);
+
241  Notify(PSTR("\r\nBut should be at least 3\r\nThis means that it doesn't support Bluetooth Version 2.0+EDR"), 0x80);
+
242  }
+
243 #endif
+
244  }
+
245  }
+
246  }
+
247  //if((ACLData[0] | (uint16_t)ACLData[1] << 8) == (hci_handle | 0x2000U)) { //acl_handle_ok
+
248  if(UHS_ACL_HANDLE_OK(ACLData, hci_handle)) { //acl_handle_ok
+
249  memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
+
250  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
+
251  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
+
252 #ifdef DEBUG_USB_HOST
+
253  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
+
254  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
255  Notify(PSTR(" "), 0x80);
+
256  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
257  Notify(PSTR(" Data: "), 0x80);
+
258  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
+
259  Notify(PSTR(" "), 0x80);
+
260  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
+
261  Notify(PSTR(" "), 0x80);
+
262  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
263  Notify(PSTR(" "), 0x80);
+
264  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
265 #endif
+
266  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
267 #ifdef EXTRADEBUG
+
268  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
+
269  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
270  Notify(PSTR(" "), 0x80);
+
271  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
272  Notify(PSTR(" SCID: "), 0x80);
+
273  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
274  Notify(PSTR(" "), 0x80);
+
275  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
276  Notify(PSTR(" Identifier: "), 0x80);
+
277  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
278 #endif
+
279  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
280  identifier = l2capinbuf[9];
+
281  control_scid[0] = l2capinbuf[14];
+
282  control_scid[1] = l2capinbuf[15];
+
283  l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
+
284  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
285  identifier = l2capinbuf[9];
-
286  control_scid[0] = l2capinbuf[14];
-
287  control_scid[1] = l2capinbuf[15];
-
288  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_CONTROL_REQUEST;
-
289  } else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
-
290  identifier = l2capinbuf[9];
-
291  interrupt_scid[0] = l2capinbuf[14];
-
292  interrupt_scid[1] = l2capinbuf[15];
-
293  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST;
-
294  }
-
295  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
-
296  if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
-
297  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
298  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
-
299  l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS;
-
300  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
301  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
-
302  l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS;
-
303  }
-
304  }
-
305  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
-
306  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
307  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
-
308  identifier = l2capinbuf[9];
-
309  l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_REQUEST;
-
310  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
311  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
-
312  identifier = l2capinbuf[9];
-
313  l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST;
-
314  }
-
315  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
-
316  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
286  interrupt_scid[0] = l2capinbuf[14];
+
287  interrupt_scid[1] = l2capinbuf[15];
+
288  l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
+
289  }
+
290  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
+
291  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
+
292  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
293  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
+
294  l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
+
295  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
296  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
+
297  l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
+
298  }
+
299  }
+
300  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
+
301  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
302  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
+
303  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
+
304  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
305  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
+
306  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
+
307  }
+
308  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
+
309  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
310 #ifdef DEBUG_USB_HOST
+
311  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
+
312 #endif
+
313  identifier = l2capinbuf[9];
+
314  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
+
315  Reset();
+
316  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
317 #ifdef DEBUG_USB_HOST
-
318  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
+
318  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
319 #endif
320  identifier = l2capinbuf[9];
-
321  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
+
321  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
322  Reset();
-
323  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
324 #ifdef DEBUG_USB_HOST
-
325  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
-
326 #endif
-
327  identifier = l2capinbuf[9];
-
328  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
-
329  Reset();
-
330  }
-
331  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
-
332  if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
-
333  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
-
334  identifier = l2capinbuf[9];
-
335  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE;
-
336  } else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
-
337  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
-
338  identifier = l2capinbuf[9];
-
339  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE;
-
340  }
-
341  }
-
342 #ifdef EXTRADEBUG
-
343  else {
-
344  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
-
345  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
346  }
-
347 #endif
-
348  } else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
-
349  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
-
350  if (PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
-
351  /* Read Report */
-
352  if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
-
353  if (PS3Connected || PS3NavigationConnected)
-
354  ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
-
355  else if (PS3MoveConnected)
-
356  ButtonState = (uint32_t)(l2capinbuf[10] | ((uint16_t)l2capinbuf[11] << 8) | ((uint32_t)l2capinbuf[12] << 16));
-
357 
-
358  //Notify(PSTR("\r\nButtonState", 0x80);
-
359  //PrintHex<uint32_t>(ButtonState, 0x80);
-
360 
-
361  if (ButtonState != OldButtonState) {
-
362  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
-
363  OldButtonState = ButtonState;
-
364  }
-
365 
-
366 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
-
367  for (uint8_t i = 10; i < 58; i++) {
-
368  D_PrintHex<uint8_t > (l2capinbuf[i], 0x80);
-
369  Notify(PSTR(" "), 0x80);
-
370  }
-
371  Notify(PSTR("\r\n"), 0x80);
-
372 #endif
-
373  }
-
374  }
-
375  }
-
376  L2CAP_task();
-
377  }
-
378 }
-
379 
-
380 void PS3BT::L2CAP_task() {
-
381  switch (l2cap_state) {
-
382  case L2CAP_WAIT:
-
383  if (l2cap_connection_request_control_flag) {
-
384 #ifdef DEBUG_USB_HOST
-
385  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
-
386 #endif
-
387  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
-
388  delay(1);
-
389  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
-
390  identifier++;
-
391  delay(1);
-
392  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
393  l2cap_state = L2CAP_CONTROL_REQUEST;
-
394  }
-
395  break;
-
396  case L2CAP_CONTROL_REQUEST:
-
397  if (l2cap_config_request_control_flag) {
-
398 #ifdef DEBUG_USB_HOST
-
399  Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
-
400 #endif
-
401  pBtd->l2cap_config_response(hci_handle, identifier, control_scid);
-
402  l2cap_state = L2CAP_CONTROL_SUCCESS;
-
403  }
-
404  break;
-
405 
-
406  case L2CAP_CONTROL_SUCCESS:
-
407  if (l2cap_config_success_control_flag) {
-
408 #ifdef DEBUG_USB_HOST
-
409  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
-
410 #endif
-
411  l2cap_state = L2CAP_INTERRUPT_SETUP;
+
323  }
+
324  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
+
325  if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
+
326  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
+
327  identifier = l2capinbuf[9];
+
328  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
+
329  } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
+
330  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
+
331  identifier = l2capinbuf[9];
+
332  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
+
333  }
+
334  }
+
335 #ifdef EXTRADEBUG
+
336  else {
+
337  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
+
338  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
339  }
+
340 #endif
+
341  } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
+
342  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
+
343  if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
+
344  /* Read Report */
+
345  if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
+
346  if(PS3Connected || PS3NavigationConnected)
+
347  ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
+
348  else if(PS3MoveConnected)
+
349  ButtonState = (uint32_t)(l2capinbuf[10] | ((uint16_t)l2capinbuf[11] << 8) | ((uint32_t)l2capinbuf[12] << 16));
+
350 
+
351  //Notify(PSTR("\r\nButtonState", 0x80);
+
352  //PrintHex<uint32_t>(ButtonState, 0x80);
+
353 
+
354  if(ButtonState != OldButtonState) {
+
355  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
+
356  OldButtonState = ButtonState;
+
357  }
+
358 
+
359 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
+
360  for(uint8_t i = 10; i < 58; i++) {
+
361  D_PrintHex<uint8_t > (l2capinbuf[i], 0x80);
+
362  Notify(PSTR(" "), 0x80);
+
363  }
+
364  Notify(PSTR("\r\n"), 0x80);
+
365 #endif
+
366  }
+
367  }
+
368  }
+
369  L2CAP_task();
+
370  }
+
371 }
+
372 
+
373 void PS3BT::L2CAP_task() {
+
374  switch(l2cap_state) {
+
375  case L2CAP_WAIT:
+
376  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)) {
+
377 #ifdef DEBUG_USB_HOST
+
378  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
+
379 #endif
+
380  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
+
381  delay(1);
+
382  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
+
383  identifier++;
+
384  delay(1);
+
385  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
+
386  l2cap_state = L2CAP_CONTROL_SUCCESS;
+
387  }
+
388  break;
+
389 
+
390  case L2CAP_CONTROL_SUCCESS:
+
391  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
392 #ifdef DEBUG_USB_HOST
+
393  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
+
394 #endif
+
395  l2cap_state = L2CAP_INTERRUPT_SETUP;
+
396  }
+
397  break;
+
398 
+
399  case L2CAP_INTERRUPT_SETUP:
+
400  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
+
401 #ifdef DEBUG_USB_HOST
+
402  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
+
403 #endif
+
404  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
+
405  delay(1);
+
406  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
+
407  identifier++;
+
408  delay(1);
+
409  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
410 
+
411  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
412  }
413  break;
-
414  case L2CAP_INTERRUPT_SETUP:
-
415  if (l2cap_connection_request_interrupt_flag) {
-
416 #ifdef DEBUG_USB_HOST
-
417  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
-
418 #endif
-
419  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
-
420  delay(1);
-
421  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
-
422  identifier++;
-
423  delay(1);
-
424  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
425 
-
426  l2cap_state = L2CAP_INTERRUPT_REQUEST;
-
427  }
-
428  break;
-
429  case L2CAP_INTERRUPT_REQUEST:
-
430  if (l2cap_config_request_interrupt_flag) {
-
431 #ifdef DEBUG_USB_HOST
-
432  Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
-
433 #endif
-
434  pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid);
-
435  l2cap_state = L2CAP_INTERRUPT_SUCCESS;
-
436  }
-
437  break;
-
438  case L2CAP_INTERRUPT_SUCCESS:
-
439  if (l2cap_config_success_interrupt_flag) {
-
440 #ifdef DEBUG_USB_HOST
-
441  Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80);
-
442 #endif
-
443  if (remote_name[0] == 'M') { // First letter in Motion Controller ('M')
-
444  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
-
445  l2cap_state = L2CAP_HID_PS3_LED;
-
446  } else
-
447  l2cap_state = L2CAP_HID_ENABLE_SIXAXIS;
-
448  timer = millis();
-
449  }
-
450  break;
-
451 
-
452  /* These states are handled in Run() */
-
453 
-
454  case L2CAP_INTERRUPT_DISCONNECT:
-
455  if (l2cap_disconnect_response_interrupt_flag) {
-
456 #ifdef DEBUG_USB_HOST
-
457  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
-
458 #endif
-
459  identifier++;
-
460  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
-
461  l2cap_state = L2CAP_CONTROL_DISCONNECT;
-
462  }
-
463  break;
-
464 
-
465  case L2CAP_CONTROL_DISCONNECT:
-
466  if (l2cap_disconnect_response_control_flag) {
-
467 #ifdef DEBUG_USB_HOST
-
468  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
-
469 #endif
-
470  pBtd->hci_disconnect(hci_handle);
-
471  hci_handle = -1; // Reset handle
-
472  l2cap_event_flag = 0; // Reset flags
-
473  l2cap_state = L2CAP_WAIT;
-
474  }
-
475  break;
-
476  }
-
477 }
-
478 
-
479 void PS3BT::Run() {
-
480  switch (l2cap_state) {
-
481  case L2CAP_HID_ENABLE_SIXAXIS:
-
482  if (millis() - timer > 1000) { // loop 1 second before sending the command
-
483  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
-
484  for (uint8_t i = 15; i < 19; i++)
-
485  l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
-
486  enable_sixaxis();
-
487  l2cap_state = L2CAP_HID_PS3_LED;
-
488  timer = millis();
-
489  }
-
490  break;
+
414 
+
415  case L2CAP_INTERRUPT_CONFIG_REQUEST:
+
416  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
+
417 #ifdef DEBUG_USB_HOST
+
418  Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80);
+
419 #endif
+
420  if(remote_name[0] == 'M') { // First letter in Motion Controller ('M')
+
421  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
+
422  l2cap_state = TURN_ON_LED;
+
423  } else
+
424  l2cap_state = PS3_ENABLE_SIXAXIS;
+
425  timer = millis();
+
426  }
+
427  break;
+
428 
+
429  /* These states are handled in Run() */
+
430 
+
431  case L2CAP_INTERRUPT_DISCONNECT:
+
432  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)) {
+
433 #ifdef DEBUG_USB_HOST
+
434  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
+
435 #endif
+
436  identifier++;
+
437  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
+
438  l2cap_state = L2CAP_CONTROL_DISCONNECT;
+
439  }
+
440  break;
+
441 
+
442  case L2CAP_CONTROL_DISCONNECT:
+
443  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
+
444 #ifdef DEBUG_USB_HOST
+
445  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
+
446 #endif
+
447  pBtd->hci_disconnect(hci_handle);
+
448  hci_handle = -1; // Reset handle
+
449  l2cap_event_flag = 0; // Reset flags
+
450  l2cap_state = L2CAP_WAIT;
+
451  }
+
452  break;
+
453  }
+
454 }
+
455 
+
456 void PS3BT::Run() {
+
457  switch(l2cap_state) {
+
458  case PS3_ENABLE_SIXAXIS:
+
459  if(millis() - timer > 1000) { // loop 1 second before sending the command
+
460  memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed
+
461  for(uint8_t i = 15; i < 19; i++)
+
462  l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
+
463  enable_sixaxis();
+
464  l2cap_state = TURN_ON_LED;
+
465  timer = millis();
+
466  }
+
467  break;
+
468 
+
469  case TURN_ON_LED:
+
470  if(millis() - timer > 1000) { // loop 1 second before sending the command
+
471  if(remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
+
472 #ifdef DEBUG_USB_HOST
+
473  Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
+
474 #endif
+
475  PS3Connected = true;
+
476  } else if(remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
+
477 #ifdef DEBUG_USB_HOST
+
478  Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
+
479 #endif
+
480  PS3NavigationConnected = true;
+
481  } else if(remote_name[0] == 'M') { // First letter in Motion Controller ('M')
+
482  timerBulbRumble = millis();
+
483 #ifdef DEBUG_USB_HOST
+
484  Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
+
485 #endif
+
486  PS3MoveConnected = true;
+
487  }
+
488  ButtonState = 0; // Clear all values
+
489  OldButtonState = 0;
+
490  ButtonClickState = 0;
491 
-
492  case L2CAP_HID_PS3_LED:
-
493  if (millis() - timer > 1000) { // loop 1 second before sending the command
-
494  if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
-
495 #ifdef DEBUG_USB_HOST
-
496  Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
-
497 #endif
-
498  PS3Connected = true;
-
499  } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
-
500 #ifdef DEBUG_USB_HOST
-
501  Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
-
502 #endif
-
503  PS3NavigationConnected = true;
-
504  } else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M')
-
505  timerBulbRumble = millis();
-
506 #ifdef DEBUG_USB_HOST
-
507  Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
-
508 #endif
-
509  PS3MoveConnected = true;
-
510  }
-
511  ButtonState = 0; // Clear all values
-
512  OldButtonState = 0;
-
513  ButtonClickState = 0;
-
514 
-
515  onInit(); // Turn on the LED on the controller
-
516  l2cap_state = L2CAP_DONE;
-
517  }
-
518  break;
-
519 
-
520  case L2CAP_DONE:
-
521  if (PS3MoveConnected) { // The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on
-
522  if (millis() - timerBulbRumble > 4000) { // Send at least every 4th second
-
523  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
-
524  timerBulbRumble = millis();
-
525  }
-
526  }
-
527  break;
-
528  }
-
529 }
-
530 
-
531 /************************************************************/
-
532 /* HID Commands */
-
533 /************************************************************/
-
534 
-
535 // Playstation Sixaxis Dualshock and Navigation Controller commands
-
536 
-
537 void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) {
-
538  if (millis() - timerHID <= 150) // Check if is has been more than 150ms since last command
-
539  delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands
-
540  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel
-
541  timerHID = millis();
-
542 }
-
543 
-
544 void PS3BT::setAllOff() {
-
545  HIDBuffer[3] = 0x00; // Rumble bytes
-
546  HIDBuffer[4] = 0x00;
-
547  HIDBuffer[5] = 0x00;
-
548  HIDBuffer[6] = 0x00;
+
492  onInit(); // Turn on the LED on the controller
+
493  l2cap_state = L2CAP_DONE;
+
494  }
+
495  break;
+
496 
+
497  case L2CAP_DONE:
+
498  if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on
+
499  if(millis() - timerBulbRumble > 4000) { // Send at least every 4th second
+
500  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
+
501  timerBulbRumble = millis();
+
502  }
+
503  }
+
504  break;
+
505  }
+
506 }
+
507 
+
508 /************************************************************/
+
509 /* HID Commands */
+
510 /************************************************************/
+
511 
+
512 // Playstation Sixaxis Dualshock and Navigation Controller commands
+
513 
+
514 void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) {
+
515  if(millis() - timerHID <= 150) // Check if is has been more than 150ms since last command
+
516  delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands
+
517  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel
+
518  timerHID = millis();
+
519 }
+
520 
+
521 void PS3BT::setAllOff() {
+
522  HIDBuffer[3] = 0x00; // Rumble bytes
+
523  HIDBuffer[4] = 0x00;
+
524  HIDBuffer[5] = 0x00;
+
525  HIDBuffer[6] = 0x00;
+
526 
+
527  HIDBuffer[11] = 0x00; // LED byte
+
528 
+
529  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
530 }
+
531 
+
532 void PS3BT::setRumbleOff() {
+
533  HIDBuffer[3] = 0x00;
+
534  HIDBuffer[4] = 0x00;
+
535  HIDBuffer[5] = 0x00;
+
536  HIDBuffer[6] = 0x00;
+
537 
+
538  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
539 }
+
540 
+
541 void PS3BT::setRumbleOn(RumbleEnum mode) {
+
542  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
+
543  if(mode == RumbleHigh) {
+
544  power[0] = 0x00;
+
545  power[1] = 0xff;
+
546  }
+
547  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
+
548 }
549 
-
550  HIDBuffer[11] = 0x00; // LED byte
-
551 
-
552  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
553 }
-
554 
-
555 void PS3BT::setRumbleOff() {
-
556  HIDBuffer[3] = 0x00;
-
557  HIDBuffer[4] = 0x00;
-
558  HIDBuffer[5] = 0x00;
-
559  HIDBuffer[6] = 0x00;
-
560 
-
561  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
562 }
-
563 
-
564 void PS3BT::setRumbleOn(Rumble mode) {
-
565  uint8_t power[2] = { 0xff, 0x00 }; // Defaults to RumbleLow
-
566  if (mode == RumbleHigh) {
-
567  power[0] = 0x00;
-
568  power[1] = 0xff;
-
569  }
-
570  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
-
571 }
-
572 
-
573 void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
-
574  HIDBuffer[3] = rightDuration;
-
575  HIDBuffer[4] = rightPower;
-
576  HIDBuffer[5] = leftDuration;
-
577  HIDBuffer[6] = leftPower;
-
578  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
579 }
-
580 
-
581 void PS3BT::setLedRaw(uint8_t value) {
-
582  HIDBuffer[11] = value << 1;
-
583  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
584 }
-
585 
-
586 void PS3BT::setLedOff(LED a) {
-
587  HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
-
588  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
589 }
+
550 void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
+
551  HIDBuffer[3] = rightDuration;
+
552  HIDBuffer[4] = rightPower;
+
553  HIDBuffer[5] = leftDuration;
+
554  HIDBuffer[6] = leftPower;
+
555  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
556 }
+
557 
+
558 void PS3BT::setLedRaw(uint8_t value) {
+
559  HIDBuffer[11] = value << 1;
+
560  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
561 }
+
562 
+
563 void PS3BT::setLedOff(LEDEnum a) {
+
564  HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1));
+
565  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
566 }
+
567 
+
568 void PS3BT::setLedOn(LEDEnum a) {
+
569  if(a == OFF)
+
570  setLedRaw(0);
+
571  else {
+
572  HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
573  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
574  }
+
575 }
+
576 
+
577 void PS3BT::setLedToggle(LEDEnum a) {
+
578  HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
579  HID_Command(HIDBuffer, HID_BUFFERSIZE);
+
580 }
+
581 
+
582 void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
+
583  uint8_t cmd_buf[6];
+
584  cmd_buf[0] = 0x53; // HID BT Set_report (0x50) | Report Type (Feature 0x03)
+
585  cmd_buf[1] = 0xF4; // Report ID
+
586  cmd_buf[2] = 0x42; // Special PS3 Controller enable commands
+
587  cmd_buf[3] = 0x03;
+
588  cmd_buf[4] = 0x00;
+
589  cmd_buf[5] = 0x00;
590 
-
591 void PS3BT::setLedOn(LED a) {
-
592  HIDBuffer[11] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
-
593  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
594 }
+
591  HID_Command(cmd_buf, 6);
+
592 }
+
593 
+
594 // Playstation Move Controller commands
595 
-
596 void PS3BT::setLedToggle(LED a) {
-
597  HIDBuffer[11] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
-
598  HID_Command(HIDBuffer, HID_BUFFERSIZE);
-
599 }
-
600 
-
601 void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
-
602  uint8_t cmd_buf[6];
-
603  cmd_buf[0] = 0x53; // HID BT Set_report (0x50) | Report Type (Feature 0x03)
-
604  cmd_buf[1] = 0xF4; // Report ID
-
605  cmd_buf[2] = 0x42; // Special PS3 Controller enable commands
-
606  cmd_buf[3] = 0x03;
-
607  cmd_buf[4] = 0x00;
-
608  cmd_buf[5] = 0x00;
-
609 
-
610  HID_Command(cmd_buf, 6);
-
611 }
-
612 
-
613 // Playstation Move Controller commands
-
614 
-
615 void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) {
-
616  if (millis() - timerHID <= 150)// Check if is has been less than 150ms since last command
-
617  delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands
-
618  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel
-
619  timerHID = millis();
-
620 }
-
621 
-
622 void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { //Use this to set the Color using RGB values
-
623  // Set the Bulb's values into the write buffer
-
624  HIDMoveBuffer[3] = r;
-
625  HIDMoveBuffer[4] = g;
-
626  HIDMoveBuffer[5] = b;
-
627 
-
628  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
-
629 }
-
630 
-
631 void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the predefined colors in enum
-
632  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
-
633 }
-
634 
-
635 void PS3BT::moveSetRumble(uint8_t rumble) {
-
636 #ifdef DEBUG_USB_HOST
-
637  if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
-
638  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
-
639 #endif
-
640  // Set the rumble value into the write buffer
-
641  HIDMoveBuffer[7] = rumble;
-
642 
-
643  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
-
644 }
-
645 
-
646 void PS3BT::onInit() {
-
647  if (pFuncOnInit)
-
648  pFuncOnInit(); // Call the user function
-
649  else {
-
650  if (PS3MoveConnected)
-
651  moveSetBulb(Red);
-
652  else // Dualshock 3 or Navigation controller
-
653  setLedOn(LED1);
-
654  }
-
655 }
-
MoveLow
Definition: PS3Enums.h:200
-
BTD::incomingWii
bool incomingWii
Definition: BTD.h:432
-
L2CAP_FLAG_CONFIG_CONTROL_REQUEST
#define L2CAP_FLAG_CONFIG_CONTROL_REQUEST
Definition: PS3BT.h:41
-
NotCharging
Definition: PS3Enums.h:189
-
PS3BT::getAnalogHat
uint8_t getAnalogHat(AnalogHat a)
Definition: PS3BT.cpp:67
-
Cable
Definition: PS3Enums.h:205
-
PS3BT::getButtonClick
bool getButtonClick(Button b)
Definition: PS3BT.cpp:56
-
PS3BT::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3BT.h:229
-
Red
Definition: PS3Enums.h:117
-
gYmove
Definition: PS3Enums.h:163
-
LED1
Definition: controllerEnums.h:28
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
-
PS3BT::getStatusString
String getStatusString()
Definition: PS3BT.cpp:163
-
PS3BT::Run
virtual void Run()
Definition: PS3BT.cpp:479
-
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:121
-
BTD
Definition: BTD.h:158
-
mZmove
Definition: PS3Enums.h:171
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
-
l2cap_config_request_interrupt_flag
#define l2cap_config_request_interrupt_flag
Definition: PS3BT.h:54
-
Low
Definition: PS3Enums.h:192
-
l2cap_disconnect_response_interrupt_flag
#define l2cap_disconnect_response_interrupt_flag
Definition: BTHID.h:59
-
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:422
-
Sensor
Sensor
Definition: PS3Enums.h:141
-
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:434
-
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[]
Definition: PS3Enums.h:24
+
596 void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) {
+
597  if(millis() - timerHID <= 150)// Check if is has been less than 150ms since last command
+
598  delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands
+
599  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel
+
600  timerHID = millis();
+
601 }
+
602 
+
603 void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
+
604  // Set the Bulb's values into the write buffer
+
605  HIDMoveBuffer[3] = r;
+
606  HIDMoveBuffer[4] = g;
+
607  HIDMoveBuffer[5] = b;
+
608 
+
609  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
+
610 }
+
611 
+
612 void PS3BT::moveSetBulb(ColorsEnum color) { // Use this to set the Color using the predefined colors in enum
+
613  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
+
614 }
+
615 
+
616 void PS3BT::moveSetRumble(uint8_t rumble) {
+
617 #ifdef DEBUG_USB_HOST
+
618  if(rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
+
619  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
+
620 #endif
+
621  // Set the rumble value into the write buffer
+
622  HIDMoveBuffer[7] = rumble;
+
623 
+
624  HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
+
625 }
+
626 
+
627 void PS3BT::onInit() {
+
628  if(pFuncOnInit)
+
629  pFuncOnInit(); // Call the user function
+
630  else {
+
631  if(PS3MoveConnected)
+
632  moveSetBulb(Red);
+
633  else // Dualshock 3 or Navigation controller
+
634  setLedOn(LED1);
+
635  }
+
636 }
+
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTD.h:139
+
BTD::incomingWii
bool incomingWii
Definition: BTD.h:507
+
RumbleEnum
RumbleEnum
Definition: PS3Enums.h:211
+
UHS_ACL_HANDLE_OK
#define UHS_ACL_HANDLE_OK(x, y)
Definition: BTD.h:207
+
High
Definition: PS3Enums.h:194
+
Unplugged
Definition: PS3Enums.h:187
+
aZ
Definition: PS3Enums.h:148
+
PS3BT::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3BT.h:196
+
MoveLow
Definition: PS3Enums.h:201
+
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTD.h:143
+
L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTD.h:115
+
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTD.h:113
+
PS3BT::getStatus
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
PS3BT::Run
virtual void Run()
Definition: PS3BT.cpp:456
+
aY
Definition: PS3Enums.h:146
+
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:177
+
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTD.h:142
+
BTD
Definition: BTD.h:230
+
LED1
Definition: controllerEnums.h:29
+
PS3BT::setLedOn
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:568
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
gZ
Definition: PS3Enums.h:150
+
MoveCharging
Definition: PS3Enums.h:197
+
CableRumble
Definition: PS3Enums.h:205
+
BTD::hci_version
uint8_t hci_version
Definition: BTD.h:497
+
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:509
+
Bluetooth
Definition: PS3Enums.h:208
PS3BT::getTemperature
String getTemperature()
Definition: PS3BT.cpp:144
-
High
Definition: PS3Enums.h:193
-
Charging
Definition: PS3Enums.h:188
-
RumbleHigh
Definition: PS3Enums.h:211
-
Bluetooth
Definition: PS3Enums.h:207
-
L2CAP_INTERRUPT_REQUEST
#define L2CAP_INTERRUPT_REQUEST
Definition: PS3BT.h:31
-
PS3BT::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:635
-
Full
Definition: PS3Enums.h:194
-
LEDS
const uint8_t LEDS[]
Definition: PS3Enums.h:43
-
ANALOGBUTTONS
const uint8_t ANALOGBUTTONS[]
Definition: PS3Enums.h:93
-
PS3BT::setAllOff
void setAllOff()
Definition: PS3BT.cpp:544
-
MoveCharging
Definition: PS3Enums.h:196
-
MoveDying
Definition: PS3Enums.h:199
-
tempMove
Definition: PS3Enums.h:166
-
PS3BT::getSensor
int16_t getSensor(Sensor a)
Definition: PS3BT.cpp:71
-
PS3BT::get9DOFValues
double get9DOFValues(Sensor a)
Definition: PS3BT.cpp:115
-
mXmove
Definition: PS3Enums.h:169
-
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:416
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
PS3BT::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:616
+
TURN_ON_LED
#define TURN_ON_LED
Definition: BTD.h:129
+
PS3BT::printStatusString
void printStatusString()
Definition: PS3BT.cpp:163
+
PS3BT::setAllOff
void setAllOff()
Definition: PS3BT.cpp:521
+
Pitch
Definition: PS3Enums.h:179
+
L2CAP_DONE
#define L2CAP_DONE
Definition: BTD.h:104
+
Shutdown
Definition: PS3Enums.h:191
+
Charging
Definition: PS3Enums.h:189
+
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTD.h:109
+
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTD.h:103
+
BTD::remote_name
uint8_t remote_name[30]
Definition: BTD.h:491
+
StatusEnum
StatusEnum
Definition: PS3Enums.h:183
HID_BUFFERSIZE
#define HID_BUFFERSIZE
Definition: PS3BT.h:24
-
PS3BT::Reset
virtual void Reset()
Definition: PS3BT.cpp:213
-
L2CAP_INTERRUPT_SUCCESS
#define L2CAP_INTERRUPT_SUCCESS
Definition: PS3BT.h:32
-
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTHID.h:47
-
l2cap_config_request_control_flag
#define l2cap_config_request_control_flag
Definition: PS3BT.h:51
-
LED
LED
Definition: controllerEnums.h:27
-
l2cap_connection_request_control_flag
#define l2cap_connection_request_control_flag
Definition: BTHID.h:60
-
PS3BT::getAngle
double getAngle(Angle a)
Definition: PS3BT.cpp:88
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
-
L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST
Definition: PS3BT.h:44
+
PS3BT::Reset
virtual void Reset()
Definition: PS3BT.cpp:207
+
PS3_BUTTONS
const uint32_t PS3_BUTTONS[]
Definition: PS3Enums.h:63
+
PS3BT::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: PS3BT.cpp:52
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
+
PS3BT::getSensor
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:71
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
Notify
#define Notify(...)
Definition: message.h:44
-
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTHID.h:26
-
L2CAP_CONTROL_REQUEST
#define L2CAP_CONTROL_REQUEST
Definition: PS3BT.h:28
-
Dying
Definition: PS3Enums.h:191
-
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTHID.h:49
-
l2cap_connection_request_interrupt_flag
#define l2cap_connection_request_interrupt_flag
Definition: BTHID.h:61
-
Unplugged
Definition: PS3Enums.h:186
-
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:126
-
aZ
Definition: PS3Enums.h:147
-
Status
Status
Definition: PS3Enums.h:182
-
Colors
Colors
Definition: PS3Enums.h:115
-
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTHID.h:40
-
Shutdown
Definition: PS3Enums.h:190
-
Rumble
Rumble
Definition: PS3Enums.h:210
-
BTD::connectToWii
bool connectToWii
Definition: BTD.h:428
+
PS3BT::getAngle
double getAngle(AngleEnum a)
Definition: PS3BT.cpp:88
+
USB_HOST_SERIAL
#define USB_HOST_SERIAL
Definition: settings.h:24
+
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:182
+
Dying
Definition: PS3Enums.h:192
+
Low
Definition: PS3Enums.h:193
+
aZmove
Definition: PS3Enums.h:155
+
BTD::connectToWii
bool connectToWii
Definition: BTD.h:503
+
Red
Definition: PS3Enums.h:118
+
gZmove
Definition: PS3Enums.h:162
PS3BT.h
-
MoveFull
Definition: PS3Enums.h:202
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
-
PS3BT::PS3Connected
bool PS3Connected
Definition: PS3BT.h:221
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
-
aZmove
Definition: PS3Enums.h:154
-
PS3BT::setLedToggle
void setLedToggle(LED a)
Definition: PS3BT.cpp:596
-
PS3BT::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:622
-
PS3BT::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3BT.h:227
-
L2CAP_DONE
#define L2CAP_DONE
Definition: BTHID.h:38
-
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:410
-
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTHID.h:30
-
MoveNotCharging
Definition: PS3Enums.h:197
-
l2cap_disconnect_response_control_flag
#define l2cap_disconnect_response_control_flag
Definition: BTHID.h:58
-
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTHID.h:51
-
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTHID.h:50
-
Pitch
Definition: PS3Enums.h:178
-
MoveHigh
Definition: PS3Enums.h:201
-
MoveShutdown
Definition: PS3Enums.h:198
-
aX
Definition: PS3Enums.h:143
-
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
Angle
Angle
Definition: PS3Enums.h:177
-
PS3BT::setLedOn
void setLedOn(LED a)
Definition: PS3BT.cpp:591
-
mYmove
Definition: PS3Enums.h:173
+
PS3BT::getAnalogHat
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
+
PS3BT::PS3Connected
bool PS3Connected
Definition: PS3BT.h:188
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTD.h:145
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
PS3BT::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:603
+
PS3BT::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3BT.h:194
+
aYmove
Definition: PS3Enums.h:157
+
BTD::my_bdaddr
uint8_t my_bdaddr[6]
Definition: BTD.h:485
+
AngleEnum
AngleEnum
Definition: PS3Enums.h:178
+
PS3BT::setRumbleOn
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:541
+
PS3_LEDS
const uint8_t PS3_LEDS[]
Definition: PS3Enums.h:43
+
l2cap_check_flag
#define l2cap_check_flag(flag)
Definition: BTD.h:160
+
SensorEnum
SensorEnum
Definition: PS3Enums.h:142
+
MoveFull
Definition: PS3Enums.h:203
+
Plugged
Definition: PS3Enums.h:186
+
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:168
+
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:170
+
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTD.h:110
+
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTD.h:136
+
mYmove
Definition: PS3Enums.h:174
+
gYmove
Definition: PS3Enums.h:164
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
-
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:127
-
gZ
Definition: PS3Enums.h:149
-
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
-
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:398
-
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:115
-
aXmove
Definition: PS3Enums.h:152
-
gXmove
Definition: PS3Enums.h:159
-
PS3BT::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:233
-
Plugged
Definition: PS3Enums.h:185
-
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
L2CAP_HID_ENABLE_SIXAXIS
#define L2CAP_HID_ENABLE_SIXAXIS
Definition: PS3BT.h:33
-
gZmove
Definition: PS3Enums.h:161
-
l2cap_config_success_control_flag
#define l2cap_config_success_control_flag
Definition: BTHID.h:56
-
l2cap_config_success_interrupt_flag
#define l2cap_config_success_interrupt_flag
Definition: BTHID.h:57
-
PS3BT::setLedOff
void setLedOff()
Definition: PS3BT.h:180
-
L2CAP_HID_PS3_LED
#define L2CAP_HID_PS3_LED
Definition: PS3BT.h:34
-
Button
Button
Definition: controllerEnums.h:44
-
PS3BT::getStatus
bool getStatus(Status c)
Definition: PS3BT.cpp:159
-
aYmove
Definition: PS3Enums.h:156
-
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTHID.h:29
-
PS3BT::setRumbleOn
void setRumbleOn(Rumble mode)
Definition: PS3BT.cpp:564
-
PS3_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:37
-
BluetoothRumble
Definition: PS3Enums.h:206
-
PS3BT::disconnect
virtual void disconnect()
Definition: PS3BT.cpp:226
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
PENDING
#define PENDING
Definition: BTD.h:120
-
CableRumble
Definition: PS3Enums.h:204
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
-
PS3BT::getAnalogButton
uint8_t getAnalogButton(Button a)
Definition: PS3BT.cpp:63
-
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTHID.h:41
-
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTHID.h:48
-
PS3BT::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:581
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
+
ColorsEnum
ColorsEnum
Definition: PS3Enums.h:116
+
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:183
+
PS3_ANALOG_BUTTONS
const uint8_t PS3_ANALOG_BUTTONS[]
Definition: PS3Enums.h:94
+
OFF
Definition: controllerEnums.h:28
+
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:333
+
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:473
+
mZmove
Definition: PS3Enums.h:172
+
aX
Definition: PS3Enums.h:144
+
PS3_ENABLE_SIXAXIS
#define PS3_ENABLE_SIXAXIS
Definition: BTD.h:130
+
MoveShutdown
Definition: PS3Enums.h:199
+
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
+
Cable
Definition: PS3Enums.h:206
+
MoveHigh
Definition: PS3Enums.h:202
+
PS3BT::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
+
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
+
BluetoothRumble
Definition: PS3Enums.h:207
+
gXmove
Definition: PS3Enums.h:160
+
mXmove
Definition: PS3Enums.h:170
+
NotCharging
Definition: PS3Enums.h:190
+
PS3BT::setLedOff
void setLedOff()
Definition: PS3BT.h:147
+
aXmove
Definition: PS3Enums.h:153
+
PS3BT::setLedToggle
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:577
+
RumbleHigh
Definition: PS3Enums.h:212
+
PS3_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:24
+
MoveDying
Definition: PS3Enums.h:200
+
PS3BT::disconnect
virtual void disconnect()
Definition: PS3BT.cpp:220
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
PENDING
#define PENDING
Definition: BTD.h:176
+
l2cap_set_flag
#define l2cap_set_flag(flag)
Definition: BTD.h:161
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTD.h:137
+
MoveNotCharging
Definition: PS3Enums.h:198
+
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
+
PS3BT::get9DOFValues
double get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:115
+
PS3BT::getAnalogButton
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:63
+
PS3BT::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:558
PS3BT::PS3BT
PS3BT(BTD *pBtd, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
Definition: PS3BT.cpp:23
-
BUTTONS
const uint32_t BUTTONS[]
Definition: PS3Enums.h:62
-
aY
Definition: PS3Enums.h:145
-
PS3BT::getButtonPress
bool getButtonPress(Button b)
Definition: PS3BT.cpp:52
-
PS3BT::setRumbleOff
void setRumbleOff()
Definition: PS3BT.cpp:555
-
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTHID.h:46
-
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:109
+
tempMove
Definition: PS3Enums.h:167
+
Full
Definition: PS3Enums.h:195
+
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTD.h:116
+
PS3BT::setRumbleOff
void setRumbleOff()
Definition: PS3BT.cpp:532
+
PS3BT::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:56
+
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
Definition: PS3Enums.h:27
+
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:165
diff --git a/_p_s3_b_t_8h.html b/_p_s3_b_t_8h.html index c66750ba..f817c166 100644 --- a/_p_s3_b_t_8h.html +++ b/_p_s3_b_t_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3BT.h File Reference @@ -31,7 +31,7 @@ - + @@ -120,60 +120,6 @@ Classes Macros #define HID_BUFFERSIZE   50   -#define L2CAP_WAIT   0 -  -#define L2CAP_CONTROL_REQUEST   1 -  -#define L2CAP_CONTROL_SUCCESS   2 -  -#define L2CAP_INTERRUPT_SETUP   3 -  -#define L2CAP_INTERRUPT_REQUEST   4 -  -#define L2CAP_INTERRUPT_SUCCESS   5 -  -#define L2CAP_HID_ENABLE_SIXAXIS   6 -  -#define L2CAP_HID_PS3_LED   7 -  -#define L2CAP_DONE   8 -  -#define L2CAP_INTERRUPT_DISCONNECT   9 -  -#define L2CAP_CONTROL_DISCONNECT   10 -  -#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x01 -  -#define L2CAP_FLAG_CONFIG_CONTROL_REQUEST   0x02 -  -#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x04 -  -#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x08 -  -#define L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST   0x10 -  -#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x20 -  -#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x40 -  -#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x80 -  -#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST) -  -#define l2cap_config_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_REQUEST) -  -#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS) -  -#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST) -  -#define l2cap_config_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST) -  -#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS) -  -#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE) -  -#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) - 

Macro Definition Documentation

@@ -188,384 +134,6 @@ Macros

Definition at line 24 of file PS3BT.h.

- - - -
-
- - - - -
#define L2CAP_WAIT   0
-
- -

Definition at line 27 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_REQUEST   1
-
- -

Definition at line 28 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_SUCCESS   2
-
- -

Definition at line 29 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_SETUP   3
-
- -

Definition at line 30 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_REQUEST   4
-
- -

Definition at line 31 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_SUCCESS   5
-
- -

Definition at line 32 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_HID_ENABLE_SIXAXIS   6
-
- -

Definition at line 33 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_HID_PS3_LED   7
-
- -

Definition at line 34 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_DONE   8
-
- -

Definition at line 35 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_DISCONNECT   9
-
- -

Definition at line 36 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_DISCONNECT   10
-
- -

Definition at line 37 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x01
-
- -

Definition at line 40 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_CONTROL_REQUEST   0x02
-
- -

Definition at line 41 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x04
-
- -

Definition at line 42 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x08
-
- -

Definition at line 43 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST   0x10
-
- -

Definition at line 44 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x20
-
- -

Definition at line 45 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x40
-
- -

Definition at line 46 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x80
-
- -

Definition at line 47 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
- -

Definition at line 50 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_config_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_REQUEST)
-
- -

Definition at line 51 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
- -

Definition at line 52 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
- -

Definition at line 53 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_config_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST)
-
- -

Definition at line 54 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
- -

Definition at line 55 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
- -

Definition at line 56 of file PS3BT.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
- -

Definition at line 57 of file PS3BT.h.

-
@@ -573,7 +141,7 @@ Macros diff --git a/_p_s3_b_t_8h_source.html b/_p_s3_b_t_8h_source.html index 470720b1..2081a7d7 100644 --- a/_p_s3_b_t_8h_source.html +++ b/_p_s3_b_t_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3BT.h Source File @@ -31,7 +31,7 @@ - + @@ -112,177 +112,145 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
21 #include "BTD.h"
22 #include "PS3Enums.h"
23 
-
24 #define HID_BUFFERSIZE 50 // Size of the buffer for the Playstation Motion Controller
+
24 #define HID_BUFFERSIZE 50 // Size of the buffer for the Playstation Motion Controller
25 
-
26 /* Bluetooth L2CAP states for L2CAP_task() */
-
27 #define L2CAP_WAIT 0
-
28 #define L2CAP_CONTROL_REQUEST 1
-
29 #define L2CAP_CONTROL_SUCCESS 2
-
30 #define L2CAP_INTERRUPT_SETUP 3
-
31 #define L2CAP_INTERRUPT_REQUEST 4
-
32 #define L2CAP_INTERRUPT_SUCCESS 5
-
33 #define L2CAP_HID_ENABLE_SIXAXIS 6
-
34 #define L2CAP_HID_PS3_LED 7
-
35 #define L2CAP_DONE 8
-
36 #define L2CAP_INTERRUPT_DISCONNECT 9
-
37 #define L2CAP_CONTROL_DISCONNECT 10
-
38 
-
39 /* L2CAP event flags */
-
40 #define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x01
-
41 #define L2CAP_FLAG_CONFIG_CONTROL_REQUEST 0x02
-
42 #define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS 0x04
-
43 #define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST 0x08
-
44 #define L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST 0x10
-
45 #define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS 0x20
-
46 #define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE 0x40
-
47 #define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE 0x80
-
48 
-
49 /*Macros for L2CAP event flag tests */
-
50 #define l2cap_connection_request_control_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
51 #define l2cap_config_request_control_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_REQUEST)
-
52 #define l2cap_config_success_control_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
53 #define l2cap_connection_request_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
54 #define l2cap_config_request_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_REQUEST)
-
55 #define l2cap_config_success_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
56 #define l2cap_disconnect_response_control_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
57 #define l2cap_disconnect_response_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
58 
-
65 class PS3BT : public BluetoothService {
-
66 public:
-
74  PS3BT(BTD *pBtd, uint8_t btadr5 = 0, uint8_t btadr4 = 0, uint8_t btadr3 = 0, uint8_t btadr2 = 0, uint8_t btadr1 = 0, uint8_t btadr0 = 0);
-
75 
-
81  virtual void ACLData(uint8_t* ACLData);
-
83  virtual void Run();
-
85  virtual void Reset();
-
87  virtual void disconnect();
-
99  bool getButtonPress(Button b);
-
100  bool getButtonClick(Button b);
-
111  uint8_t getAnalogButton(Button a);
-
117  uint8_t getAnalogHat(AnalogHat a);
-
126  int16_t getSensor(Sensor a);
-
132  double getAngle(Angle a);
-
138  double get9DOFValues(Sensor a);
-
144  bool getStatus(Status c);
-
149  String getStatusString();
-
154  String getTemperature();
-
155 
-
157  void setAllOff();
-
159  void setRumbleOff();
-
164  void setRumbleOn(Rumble mode);
-
172  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
-
173 
-
178  void setLedRaw(uint8_t value);
-
180  void setLedOff() {
-
181  setLedRaw(0);
-
182  }
-
187  void setLedOff(LED a);
-
192  void setLedOn(LED a);
-
197  void setLedToggle(LED a);
-
198 
-
203  void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
-
208  void moveSetBulb(Colors color);
-
213  void moveSetRumble(uint8_t rumble);
-
214 
-
219  void attachOnInit(void (*funcOnInit)(void)) {
-
220  pFuncOnInit = funcOnInit;
-
221  };
-
225  bool PS3Connected;
-
227  bool PS3MoveConnected;
-
229  bool PS3NavigationConnected;
-
230 
-
231 private:
-
232  /* Mandatory members */
-
233  BTD *pBtd;
-
234 
-
240  void onInit();
-
241  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
-
242 
-
243  void L2CAP_task(); // L2CAP state machine
-
244 
-
245  /* Variables filled from HCI event management */
-
246  int16_t hci_handle;
-
247  uint8_t remote_name[30]; // First 30 chars of remote name
-
248  bool activeConnection; // Used to indicate if it's already has established a connection
-
249 
-
250  /* variables used by high level L2CAP task */
-
251  uint8_t l2cap_state;
-
252  uint16_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
-
253 
-
254  unsigned long timer;
-
255 
-
256  uint32_t ButtonState;
-
257  uint32_t OldButtonState;
-
258  uint32_t ButtonClickState;
-
259 
-
260  uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command
-
261  uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values
-
262 
-
263  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
-
264  uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands
-
265  uint8_t HIDMoveBuffer[HID_BUFFERSIZE]; // Used to store HID commands for the Move controller
-
266 
-
267  /* L2CAP Channels */
-
268  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
-
269  uint8_t control_dcid[2]; // 0x0040
-
270  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
-
271  uint8_t interrupt_dcid[2]; // 0x0041
-
272  uint8_t identifier; // Identifier for connection
-
273 
-
274  /* HID Commands */
-
275  void HID_Command(uint8_t* data, uint8_t nbytes);
-
276  void HIDMove_Command(uint8_t* data, uint8_t nbytes);
-
277  void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
-
278 };
-
279 #endif
-
PS3BT::getAnalogHat
uint8_t getAnalogHat(AnalogHat a)
Definition: PS3BT.cpp:67
-
PS3BT::getButtonClick
bool getButtonClick(Button b)
Definition: PS3BT.cpp:56
-
PS3BT::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3BT.h:229
-
PS3BT::getStatusString
String getStatusString()
Definition: PS3BT.cpp:163
-
PS3BT::Run
virtual void Run()
Definition: PS3BT.cpp:479
-
BTD
Definition: BTD.h:158
-
Sensor
Sensor
Definition: PS3Enums.h:141
+
32 class PS3BT : public BluetoothService {
+
33 public:
+
41  PS3BT(BTD *pBtd, uint8_t btadr5 = 0, uint8_t btadr4 = 0, uint8_t btadr3 = 0, uint8_t btadr2 = 0, uint8_t btadr1 = 0, uint8_t btadr0 = 0);
+
42 
+
48  virtual void ACLData(uint8_t* ACLData);
+
50  virtual void Run();
+
52  virtual void Reset();
+
54  virtual void disconnect();
+
68  bool getButtonPress(ButtonEnum b);
+
69  bool getButtonClick(ButtonEnum b);
+
80  uint8_t getAnalogButton(ButtonEnum a);
+
86  uint8_t getAnalogHat(AnalogHatEnum a);
+
95  int16_t getSensor(SensorEnum a);
+
101  double getAngle(AngleEnum a);
+
107  double get9DOFValues(SensorEnum a);
+
113  bool getStatus(StatusEnum c);
+
115  void printStatusString();
+
120  String getTemperature();
+
121 
+
123  void setAllOff();
+
125  void setRumbleOff();
+
130  void setRumbleOn(RumbleEnum mode);
+
138  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
+
139 
+
144  void setLedRaw(uint8_t value);
+
145 
+
147  void setLedOff() {
+
148  setLedRaw(0);
+
149  };
+
154  void setLedOff(LEDEnum a);
+
159  void setLedOn(LEDEnum a);
+
164  void setLedToggle(LEDEnum a);
+
165 
+
170  void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
+
175  void moveSetBulb(ColorsEnum color);
+
180  void moveSetRumble(uint8_t rumble);
+
181 
+
186  void attachOnInit(void (*funcOnInit)(void)) {
+
187  pFuncOnInit = funcOnInit;
+
188  };
+
192  bool PS3Connected;
+
194  bool PS3MoveConnected;
+
196  bool PS3NavigationConnected;
+
197 
+
198 private:
+
199  /* Mandatory members */
+
200  BTD *pBtd;
+
201 
+
207  void onInit();
+
208  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
209 
+
210  void L2CAP_task(); // L2CAP state machine
+
211 
+
212  /* Variables filled from HCI event management */
+
213  int16_t hci_handle;
+
214  uint8_t remote_name[30]; // First 30 chars of remote name
+
215  bool activeConnection; // Used to indicate if it's already has established a connection
+
216 
+
217  /* variables used by high level L2CAP task */
+
218  uint8_t l2cap_state;
+
219  uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
+
220 
+
221  unsigned long timer;
+
222 
+
223  uint32_t ButtonState;
+
224  uint32_t OldButtonState;
+
225  uint32_t ButtonClickState;
+
226 
+
227  uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command
+
228  uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values
+
229 
+
230  uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
+
231  uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands
+
232  uint8_t HIDMoveBuffer[HID_BUFFERSIZE]; // Used to store HID commands for the Move controller
+
233 
+
234  /* L2CAP Channels */
+
235  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
+
236  uint8_t control_dcid[2]; // 0x0040
+
237  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
+
238  uint8_t interrupt_dcid[2]; // 0x0041
+
239  uint8_t identifier; // Identifier for connection
+
240 
+
241  /* HID Commands */
+
242  void HID_Command(uint8_t* data, uint8_t nbytes);
+
243  void HIDMove_Command(uint8_t* data, uint8_t nbytes);
+
244  void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
+
245 };
+
246 #endif
+
RumbleEnum
RumbleEnum
Definition: PS3Enums.h:211
+
PS3BT::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3BT.h:196
+
PS3BT::getStatus
bool getStatus(StatusEnum c)
Definition: PS3BT.cpp:159
+
PS3BT::Run
virtual void Run()
Definition: PS3BT.cpp:456
+
BTD
Definition: BTD.h:230
+
PS3BT::setLedOn
void setLedOn(LEDEnum a)
Definition: PS3BT.cpp:568
PS3BT::getTemperature
String getTemperature()
Definition: PS3BT.cpp:144
-
PS3BT::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:635
-
PS3BT::setAllOff
void setAllOff()
Definition: PS3BT.cpp:544
-
PS3BT::getSensor
int16_t getSensor(Sensor a)
Definition: PS3BT.cpp:71
-
PS3BT::get9DOFValues
double get9DOFValues(Sensor a)
Definition: PS3BT.cpp:115
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
PS3BT::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3BT.cpp:616
+
PS3BT::printStatusString
void printStatusString()
Definition: PS3BT.cpp:163
+
PS3BT::setAllOff
void setAllOff()
Definition: PS3BT.cpp:521
+
StatusEnum
StatusEnum
Definition: PS3Enums.h:183
HID_BUFFERSIZE
#define HID_BUFFERSIZE
Definition: PS3BT.h:24
-
PS3BT::Reset
virtual void Reset()
Definition: PS3BT.cpp:213
-
LED
LED
Definition: controllerEnums.h:27
-
PS3BT::getAngle
double getAngle(Angle a)
Definition: PS3BT.cpp:88
+
PS3BT::Reset
virtual void Reset()
Definition: PS3BT.cpp:207
+
PS3BT::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: PS3BT.cpp:52
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
+
PS3BT::getSensor
int16_t getSensor(SensorEnum a)
Definition: PS3BT.cpp:71
PS3Enums.h
-
PS3BT
Definition: PS3BT.h:65
-
Status
Status
Definition: PS3Enums.h:182
-
Colors
Colors
Definition: PS3Enums.h:115
-
PS3BT::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: PS3BT.h:219
-
Rumble
Rumble
Definition: PS3Enums.h:210
-
PS3BT::PS3Connected
bool PS3Connected
Definition: PS3BT.h:221
-
BluetoothService
Definition: BTD.h:139
-
PS3BT::setLedToggle
void setLedToggle(LED a)
Definition: PS3BT.cpp:596
-
PS3BT::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:622
-
PS3BT::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3BT.h:227
-
Angle
Angle
Definition: PS3Enums.h:177
-
PS3BT::setLedOn
void setLedOn(LED a)
Definition: PS3BT.cpp:591
+
PS3BT::getAngle
double getAngle(AngleEnum a)
Definition: PS3BT.cpp:88
+
PS3BT
Definition: PS3BT.h:32
+
PS3BT::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: PS3BT.h:186
+
PS3BT::getAnalogHat
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3BT.cpp:67
+
PS3BT::PS3Connected
bool PS3Connected
Definition: PS3BT.h:188
+
BluetoothService
Definition: BTD.h:211
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
PS3BT::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3BT.cpp:603
+
PS3BT::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3BT.h:194
+
AngleEnum
AngleEnum
Definition: PS3Enums.h:178
+
PS3BT::setRumbleOn
void setRumbleOn(RumbleEnum mode)
Definition: PS3BT.cpp:541
+
SensorEnum
SensorEnum
Definition: PS3Enums.h:142
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
-
PS3BT::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:233
-
PS3BT::setLedOff
void setLedOff()
Definition: PS3BT.h:180
-
Button
Button
Definition: controllerEnums.h:44
-
PS3BT::getStatus
bool getStatus(Status c)
Definition: PS3BT.cpp:159
-
PS3BT::setRumbleOn
void setRumbleOn(Rumble mode)
Definition: PS3BT.cpp:564
-
PS3BT::disconnect
virtual void disconnect()
Definition: PS3BT.cpp:226
+
ColorsEnum
ColorsEnum
Definition: PS3Enums.h:116
+
PS3BT::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: PS3BT.cpp:227
+
PS3BT::setLedOff
void setLedOff()
Definition: PS3BT.h:147
+
PS3BT::setLedToggle
void setLedToggle(LEDEnum a)
Definition: PS3BT.cpp:577
+
PS3BT::disconnect
virtual void disconnect()
Definition: PS3BT.cpp:220
BTD.h
-
PS3BT::getAnalogButton
uint8_t getAnalogButton(Button a)
Definition: PS3BT.cpp:63
-
PS3BT::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:581
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
+
PS3BT::get9DOFValues
double get9DOFValues(SensorEnum a)
Definition: PS3BT.cpp:115
+
PS3BT::getAnalogButton
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3BT.cpp:63
+
PS3BT::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3BT.cpp:558
PS3BT::PS3BT
PS3BT(BTD *pBtd, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
Definition: PS3BT.cpp:23
-
PS3BT::getButtonPress
bool getButtonPress(Button b)
Definition: PS3BT.cpp:52
-
PS3BT::setRumbleOff
void setRumbleOff()
Definition: PS3BT.cpp:555
+
PS3BT::setRumbleOff
void setRumbleOff()
Definition: PS3BT.cpp:532
+
PS3BT::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: PS3BT.cpp:56
diff --git a/_p_s3_enums_8h.html b/_p_s3_enums_8h.html index 0a6dcd2e..ff5d3105 100644 --- a/_p_s3_enums_8h.html +++ b/_p_s3_enums_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3Enums.h File Reference @@ -31,7 +31,7 @@ - + @@ -106,7 +106,7 @@ This graph shows which files directly or indirectly include this file:
- +

Go to the source code of this file.

@@ -120,87 +120,87 @@ Macros - - - + - - + - - + - - + - +

Enumerations

enum  Colors {
-  Red = 0xFF0000, -Green = 0xFF00, -Blue = 0xFF, -Yellow = 0xFFEB04, +
enum  ColorsEnum {
+  Red = 0xFF0000, +Green = 0xFF00, +Blue = 0xFF, +Yellow = 0xFFEB04,
-  Lightblue = 0xFFFF, -Purble = 0xFF00FF, -White = 0xFFFFFF, -Off = 0x00 +  Lightblue = 0xFFFF, +Purble = 0xFF00FF, +White = 0xFFFFFF, +Off = 0x00
}
 
enum  Sensor {
-  aX = 50, -aY = 52, -aZ = 54, -gZ = 56, +
 
enum  SensorEnum {
+  aX = 50, +aY = 52, +aZ = 54, +gZ = 56,
-  aXmove = 28, -aZmove = 30, -aYmove = 32, -gXmove = 40, +  aXmove = 28, +aZmove = 30, +aYmove = 32, +gXmove = 40,
-  gZmove = 42, -gYmove = 44, -tempMove = 46, -mXmove = 47, +  gZmove = 42, +gYmove = 44, +tempMove = 46, +mXmove = 47,
-  mZmove = 49, -mYmove = 50 +  mZmove = 49, +mYmove = 50
}
 
enum  Angle { Pitch = 0x01, -Roll = 0x02 +
 
enum  AngleEnum { Pitch = 0x01, +Roll = 0x02 }
 
enum  Status {
-  Plugged = (38 << 8) | 0x02, -Unplugged = (38 << 8) | 0x03, -Charging = (39 << 8) | 0xEE, -NotCharging = (39 << 8) | 0xF1, +
 
enum  StatusEnum {
+  Plugged = (38 << 8) | 0x02, +Unplugged = (38 << 8) | 0x03, +Charging = (39 << 8) | 0xEE, +NotCharging = (39 << 8) | 0xF1,
-  Shutdown = (39 << 8) | 0x01, -Dying = (39 << 8) | 0x02, -Low = (39 << 8) | 0x03, -High = (39 << 8) | 0x04, +  Shutdown = (39 << 8) | 0x01, +Dying = (39 << 8) | 0x02, +Low = (39 << 8) | 0x03, +High = (39 << 8) | 0x04,
-  Full = (39 << 8) | 0x05, -MoveCharging = (21 << 8) | 0xEE, -MoveNotCharging = (21 << 8) | 0xF1, -MoveShutdown = (21 << 8) | 0x01, +  Full = (39 << 8) | 0x05, +MoveCharging = (21 << 8) | 0xEE, +MoveNotCharging = (21 << 8) | 0xF1, +MoveShutdown = (21 << 8) | 0x01,
-  MoveDying = (21 << 8) | 0x02, -MoveLow = (21 << 8) | 0x03, -MoveHigh = (21 << 8) | 0x04, -MoveFull = (21 << 8) | 0x05, +  MoveDying = (21 << 8) | 0x02, +MoveLow = (21 << 8) | 0x03, +MoveHigh = (21 << 8) | 0x04, +MoveFull = (21 << 8) | 0x05,
-  CableRumble = (40 << 8) | 0x10, -Cable = (40 << 8) | 0x12, -BluetoothRumble = (40 << 8) | 0x14, -Bluetooth = (40 << 8) | 0x16 +  CableRumble = (40 << 8) | 0x10, +Cable = (40 << 8) | 0x12, +BluetoothRumble = (40 << 8) | 0x14, +Bluetooth = (40 << 8) | 0x16
}
 
enum  Rumble { RumbleHigh = 0x10, -RumbleLow = 0x20 +
 
enum  RumbleEnum { RumbleHigh = 0x10, +RumbleLow = 0x20 }
 
 
- - - - - - - - + + + + + + + +

Variables

const uint8_t PS3_REPORT_BUFFER []
 
const uint8_t LEDS []
 
const uint32_t BUTTONS []
 
const uint8_t ANALOGBUTTONS []
 
const uint8_t PS3_REPORT_BUFFER [PS3_REPORT_BUFFER_SIZE]
 
const uint8_t PS3_LEDS []
 
const uint32_t PS3_BUTTONS []
 
const uint8_t PS3_ANALOG_BUTTONS []
 

Macro Definition Documentation

@@ -214,7 +214,7 @@ Variables

Size of the output report buffer for the Dualshock and Navigation controllers

-

Definition at line 37 of file PS3Enums.h.

+

Definition at line 24 of file PS3Enums.h.

@@ -234,211 +234,211 @@ Variables

Enumeration Type Documentation

- +
- +
enum Colorsenum ColorsEnum

Used to set the colors of the move controller.

- - - - - - - -
Enumerator
Red  +
Enumerator
Red 

r = 255, g = 0, b = 0

Green  +
Green 

r = 0, g = 255, b = 0

Blue  +
Blue 

r = 0, g = 0, b = 255

Yellow  +
Yellow 

r = 255, g = 235, b = 4

Lightblue  +
Lightblue 

r = 0, g = 255, b = 255

Purble  +
Purble 

r = 255, g = 0, b = 255

White  +
White 

r = 255, g = 255, b = 255

Off  +
Off 

r = 0, g = 0, b = 0

-

Definition at line 115 of file PS3Enums.h.

+

Definition at line 116 of file PS3Enums.h.

- +
- +
enum Sensorenum SensorEnum

Sensors inside the Sixaxis Dualshock 3 and Move controller.

-

Note: that the location is shiftet 9 when it's connected via USB.

+

Note: that the location is shifted 9 when it's connected via USB.

- - - - - - - - - - - - - -
Enumerator
aX  +
Enumerator
aX 

Accelerometer x-axis

aY  +
aY 

Accelerometer y-axis

aZ  +
aZ 

Accelerometer z-axis

gZ  +
gZ 

Gyro z-axis

aXmove  +
aXmove 

Accelerometer x-axis

aZmove  +
aZmove 

Accelerometer z-axis

aYmove  +
aYmove 

Accelerometer y-axis

gXmove  +
gXmove 

Gyro x-axis

gZmove  +
gZmove 

Gyro z-axis

gYmove  +
gYmove 

Gyro y-axis

tempMove  +
tempMove 

Temperature sensor

mXmove  +
mXmove 

Magnetometer x-axis

mZmove  +
mZmove 

Magnetometer z-axis

mYmove  +
mYmove 

Magnetometer y-axis

-

Definition at line 141 of file PS3Enums.h.

+

Definition at line 142 of file PS3Enums.h.

- +
- +
enum Angleenum AngleEnum

Used to get the angle calculated using the accelerometer.

- -
Enumerator
Pitch  +
Enumerator
Pitch 
Roll  +
Roll 
-

Definition at line 177 of file PS3Enums.h.

+

Definition at line 178 of file PS3Enums.h.

- +
- +
enum Statusenum StatusEnum
- - - - - - - - - - - - - - - - - - - -
Enumerator
Plugged  +
Enumerator
Plugged 
Unplugged  +
Unplugged 
Charging  +
Charging 
NotCharging  +
NotCharging 
Shutdown  +
Shutdown 
Dying  +
Dying 
Low  +
Low 
High  +
High 
Full  +
Full 
MoveCharging  +
MoveCharging 
MoveNotCharging  +
MoveNotCharging 
MoveShutdown  +
MoveShutdown 
MoveDying  +
MoveDying 
MoveLow  +
MoveLow 
MoveHigh  +
MoveHigh 
MoveFull  +
MoveFull 
CableRumble  +
CableRumble 
Cable  +
Cable 
BluetoothRumble  +
BluetoothRumble 
Bluetooth  +
Bluetooth 
-

Definition at line 182 of file PS3Enums.h.

+

Definition at line 183 of file PS3Enums.h.

- +
- +
enum Rumbleenum RumbleEnum
- -
Enumerator
RumbleHigh  +
Enumerator
RumbleHigh 
RumbleLow  +
RumbleLow 
-

Definition at line 210 of file PS3Enums.h.

+

Definition at line 211 of file PS3Enums.h.

Variable Documentation

- +
- +
const uint8_t PS3_REPORT_BUFFER[]const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
@@ -455,20 +455,21 @@ Variables
}

Report buffer for all PS3 commands

-

Definition at line 24 of file PS3Enums.h.

+

Definition at line 27 of file PS3Enums.h.

- +
- +
const uint8_t LEDS[]const uint8_t PS3_LEDS[]
Initial value:
= {
+
0x00,
0x01,
0x02,
0x04,
@@ -479,7 +480,7 @@ Variables
0x0C,
0x0D,
0x0E,
-
0x0F
+
0x0F,
}

Used to set the LEDs on the controllers

@@ -487,12 +488,12 @@ Variables
- +
- +
const uint32_t BUTTONS[]const uint32_t PS3_BUTTONS[]
@@ -519,21 +520,21 @@ Variables
0x010000,
0x080000,
-
0x100000
+
0x100000,
}

Buttons on the controllers

-

Note: that the location is shiftet 9 when it's connected via USB.

+

Note: that the location is shifted 9 when it's connected via USB.

-

Definition at line 62 of file PS3Enums.h.

+

Definition at line 63 of file PS3Enums.h.

- +
- +
const uint8_t ANALOGBUTTONS[]const uint8_t PS3_ANALOG_BUTTONS[]
@@ -555,12 +556,12 @@ Variables
0, 0,
-
15
+
15,
}

Analog buttons on the controllers

-

Note: that the location is shiftet 9 when it's connected via USB.

+

Note: that the location is shifted 9 when it's connected via USB.

-

Definition at line 93 of file PS3Enums.h.

+

Definition at line 94 of file PS3Enums.h.

@@ -569,7 +570,7 @@ Variables diff --git a/_p_s3_enums_8h__dep__incl.map b/_p_s3_enums_8h__dep__incl.map index 4f915e72..2d94994d 100644 --- a/_p_s3_enums_8h__dep__incl.map +++ b/_p_s3_enums_8h__dep__incl.map @@ -1,6 +1,8 @@ - - + + + + diff --git a/_p_s3_enums_8h__dep__incl.md5 b/_p_s3_enums_8h__dep__incl.md5 index 1a523eaa..c9a9c9a1 100644 --- a/_p_s3_enums_8h__dep__incl.md5 +++ b/_p_s3_enums_8h__dep__incl.md5 @@ -1 +1 @@ -632aeb814444892cb4235318575b2052 \ No newline at end of file +33a889bb2dd64e4ad2739cccaf1b7d9c \ No newline at end of file diff --git a/_p_s3_enums_8h__dep__incl.png b/_p_s3_enums_8h__dep__incl.png index efe757ad..2ea866e7 100644 Binary files a/_p_s3_enums_8h__dep__incl.png and b/_p_s3_enums_8h__dep__incl.png differ diff --git a/_p_s3_enums_8h_source.html b/_p_s3_enums_8h_source.html index eeec7613..265a4712 100644 --- a/_p_s3_enums_8h_source.html +++ b/_p_s3_enums_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3Enums.h Source File @@ -31,7 +31,7 @@ - + @@ -111,218 +111,220 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
20 
21 #include "controllerEnums.h"
22 
-
24 const uint8_t PS3_REPORT_BUFFER[] PROGMEM = {
-
25  0x00, 0x00, 0x00, 0x00, 0x00,
-
26  0x00, 0x00, 0x00, 0x00, 0x00,
-
27  0xff, 0x27, 0x10, 0x00, 0x32,
-
28  0xff, 0x27, 0x10, 0x00, 0x32,
-
29  0xff, 0x27, 0x10, 0x00, 0x32,
+
24 #define PS3_REPORT_BUFFER_SIZE 48
+
25 
+
27 const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE] PROGMEM = {
+
28  0x00, 0x00, 0x00, 0x00, 0x00,
+
29  0x00, 0x00, 0x00, 0x00, 0x00,
30  0xff, 0x27, 0x10, 0x00, 0x32,
-
31  0x00, 0x00, 0x00, 0x00, 0x00,
-
32  0x00, 0x00, 0x00, 0x00, 0x00,
-
33  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-
34 };
-
35 
-
37 #define PS3_REPORT_BUFFER_SIZE 48
-
38 
+
31  0xff, 0x27, 0x10, 0x00, 0x32,
+
32  0xff, 0x27, 0x10, 0x00, 0x32,
+
33  0xff, 0x27, 0x10, 0x00, 0x32,
+
34  0x00, 0x00, 0x00, 0x00, 0x00,
+
35  0x00, 0x00, 0x00, 0x00, 0x00,
+
36  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+
37 };
+
38 
40 #define MOVE_REPORT_BUFFER_SIZE 7
41 
-
43 const uint8_t LEDS[] PROGMEM = {
-
44  0x01, // LED1
-
45  0x02, // LED2
-
46  0x04, // LED3
-
47  0x08, // LED4
-
48 
-
49  0x09, // LED5
-
50  0x0A, // LED6
-
51  0x0C, // LED7
-
52  0x0D, // LED8
-
53  0x0E, // LED9
-
54  0x0F // LED10
-
55 };
-
56 
-
62 const uint32_t BUTTONS[] PROGMEM = {
-
63  0x10, // UP
-
64  0x20, // RIGHT
-
65  0x40, // DOWN
-
66  0x80, // LEFT
-
67 
-
68  0x01, // SELECT
-
69  0x08, // START
-
70  0x02, // L3
-
71  0x04, // R3
-
72 
-
73  0x0100, // L2
-
74  0x0200, // R2
-
75  0x0400, // L1
-
76  0x0800, // R1
-
77 
-
78  0x1000, // TRIANGLE
-
79  0x2000, // CIRCLE
-
80  0x4000, // CROSS
-
81  0x8000, // SQUARE
-
82 
-
83  0x010000, // PS
-
84  0x080000, // MOVE - covers 12 bits - we only need to read the top 8
-
85  0x100000 // T - covers 12 bits - we only need to read the top 8
-
86 };
-
87 
-
93 const uint8_t ANALOGBUTTONS[] PROGMEM = {
-
94  23, // UP_ANALOG
-
95  24, // RIGHT_ANALOG
-
96  25, // DOWN_ANALOG
-
97  26, // LEFT_ANALOG
-
98  0, 0, 0, 0, // Skip SELECT, L3, R3 and START
-
99 
-
100  27, // L2_ANALOG
-
101  28, // R2_ANALOG
-
102  29, // L1_ANALOG
-
103  30, // R1_ANALOG
-
104  31, // TRIANGLE_ANALOG
-
105  32, // CIRCLE_ANALOG
-
106  33, // CROSS_ANALOG
-
107  34, // SQUARE_ANALOG
-
108  0, 0, // Skip PS and MOVE
-
109 
-
110  // Playstation Move Controller
-
111  15 // T_ANALOG - Both at byte 14 (last reading) and byte 15 (current reading)
-
112 };
-
113 
-
115 enum Colors {
-
117  Red = 0xFF0000,
-
119  Green = 0xFF00,
-
121  Blue = 0xFF,
-
122 
-
124  Yellow = 0xFFEB04,
-
126  Lightblue = 0xFFFF,
-
128  Purble = 0xFF00FF,
-
129 
-
131  White = 0xFFFFFF,
-
133  Off = 0x00,
-
134 };
-
135 
-
141 enum Sensor {
-
143  aX = 50,
-
145  aY = 52,
-
147  aZ = 54,
-
149  gZ = 56,
-
150 
-
152  aXmove = 28,
-
154  aZmove = 30,
-
156  aYmove = 32,
-
157 
-
159  gXmove = 40,
-
161  gZmove = 42,
-
163  gYmove = 44,
-
164 
-
166  tempMove = 46,
-
167 
-
169  mXmove = 47,
-
171  mZmove = 49,
-
173  mYmove = 50,
-
174 };
-
175 
-
177 enum Angle {
-
178  Pitch = 0x01,
-
179  Roll = 0x02,
-
180 };
-
181 
-
182 enum Status {
-
183  // Note that the location is shiftet 9 when it's connected via USB
-
184  // Byte location | bit location
-
185  Plugged = (38 << 8) | 0x02,
-
186  Unplugged = (38 << 8) | 0x03,
-
187 
-
188  Charging = (39 << 8) | 0xEE,
-
189  NotCharging = (39 << 8) | 0xF1,
-
190  Shutdown = (39 << 8) | 0x01,
-
191  Dying = (39 << 8) | 0x02,
-
192  Low = (39 << 8) | 0x03,
-
193  High = (39 << 8) | 0x04,
-
194  Full = (39 << 8) | 0x05,
-
195 
-
196  MoveCharging = (21 << 8) | 0xEE,
-
197  MoveNotCharging = (21 << 8) | 0xF1,
-
198  MoveShutdown = (21 << 8) | 0x01,
-
199  MoveDying = (21 << 8) | 0x02,
-
200  MoveLow = (21 << 8) | 0x03,
-
201  MoveHigh = (21 << 8) | 0x04,
-
202  MoveFull = (21 << 8) | 0x05,
-
203 
-
204  CableRumble = (40 << 8) | 0x10, //Opperating by USB and rumble is turned on
-
205  Cable = (40 << 8) | 0x12, //Opperating by USB and rumble is turned off
-
206  BluetoothRumble = (40 << 8) | 0x14, //Opperating by bluetooth and rumble is turned on
-
207  Bluetooth = (40 << 8) | 0x16, //Opperating by bluetooth and rumble is turned off
-
208 };
-
209 
-
210 enum Rumble {
-
211  RumbleHigh = 0x10,
-
212  RumbleLow = 0x20,
-
213 };
-
214 
-
215 #endif
-
MoveLow
Definition: PS3Enums.h:200
-
NotCharging
Definition: PS3Enums.h:189
-
Cable
Definition: PS3Enums.h:205
-
Red
Definition: PS3Enums.h:117
-
gYmove
Definition: PS3Enums.h:163
-
Roll
Definition: PS3Enums.h:179
-
mZmove
Definition: PS3Enums.h:171
-
Low
Definition: PS3Enums.h:192
-
Sensor
Sensor
Definition: PS3Enums.h:141
-
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[]
Definition: PS3Enums.h:24
-
High
Definition: PS3Enums.h:193
-
Charging
Definition: PS3Enums.h:188
-
RumbleHigh
Definition: PS3Enums.h:211
-
Bluetooth
Definition: PS3Enums.h:207
-
Full
Definition: PS3Enums.h:194
-
LEDS
const uint8_t LEDS[]
Definition: PS3Enums.h:43
-
ANALOGBUTTONS
const uint8_t ANALOGBUTTONS[]
Definition: PS3Enums.h:93
-
MoveCharging
Definition: PS3Enums.h:196
-
MoveDying
Definition: PS3Enums.h:199
-
tempMove
Definition: PS3Enums.h:166
-
mXmove
Definition: PS3Enums.h:169
-
Lightblue
Definition: PS3Enums.h:126
+
43 const uint8_t PS3_LEDS[] PROGMEM = {
+
44  0x00, // OFF
+
45  0x01, // LED1
+
46  0x02, // LED2
+
47  0x04, // LED3
+
48  0x08, // LED4
+
49 
+
50  0x09, // LED5
+
51  0x0A, // LED6
+
52  0x0C, // LED7
+
53  0x0D, // LED8
+
54  0x0E, // LED9
+
55  0x0F, // LED10
+
56 };
+
57 
+
63 const uint32_t PS3_BUTTONS[] PROGMEM = {
+
64  0x10, // UP
+
65  0x20, // RIGHT
+
66  0x40, // DOWN
+
67  0x80, // LEFT
+
68 
+
69  0x01, // SELECT
+
70  0x08, // START
+
71  0x02, // L3
+
72  0x04, // R3
+
73 
+
74  0x0100, // L2
+
75  0x0200, // R2
+
76  0x0400, // L1
+
77  0x0800, // R1
+
78 
+
79  0x1000, // TRIANGLE
+
80  0x2000, // CIRCLE
+
81  0x4000, // CROSS
+
82  0x8000, // SQUARE
+
83 
+
84  0x010000, // PS
+
85  0x080000, // MOVE - covers 12 bits - we only need to read the top 8
+
86  0x100000, // T - covers 12 bits - we only need to read the top 8
+
87 };
+
88 
+
94 const uint8_t PS3_ANALOG_BUTTONS[] PROGMEM = {
+
95  23, // UP_ANALOG
+
96  24, // RIGHT_ANALOG
+
97  25, // DOWN_ANALOG
+
98  26, // LEFT_ANALOG
+
99  0, 0, 0, 0, // Skip SELECT, L3, R3 and START
+
100 
+
101  27, // L2_ANALOG
+
102  28, // R2_ANALOG
+
103  29, // L1_ANALOG
+
104  30, // R1_ANALOG
+
105  31, // TRIANGLE_ANALOG
+
106  32, // CIRCLE_ANALOG
+
107  33, // CROSS_ANALOG
+
108  34, // SQUARE_ANALOG
+
109  0, 0, // Skip PS and MOVE
+
110 
+
111  // Playstation Move Controller
+
112  15, // T_ANALOG - Both at byte 14 (last reading) and byte 15 (current reading)
+
113 };
+
114 
+
116 enum ColorsEnum {
+
118  Red = 0xFF0000,
+
120  Green = 0xFF00,
+
122  Blue = 0xFF,
+
123 
+
125  Yellow = 0xFFEB04,
+
127  Lightblue = 0xFFFF,
+
129  Purble = 0xFF00FF,
+
130 
+
132  White = 0xFFFFFF,
+
134  Off = 0x00,
+
135 };
+
136 
+
142 enum SensorEnum {
+
144  aX = 50,
+
146  aY = 52,
+
148  aZ = 54,
+
150  gZ = 56,
+
151 
+
153  aXmove = 28,
+
155  aZmove = 30,
+
157  aYmove = 32,
+
158 
+
160  gXmove = 40,
+
162  gZmove = 42,
+
164  gYmove = 44,
+
165 
+
167  tempMove = 46,
+
168 
+
170  mXmove = 47,
+
172  mZmove = 49,
+
174  mYmove = 50,
+
175 };
+
176 
+
178 enum AngleEnum {
+
179  Pitch = 0x01,
+
180  Roll = 0x02,
+
181 };
+
182 
+
183 enum StatusEnum {
+
184  // Note that the location is shifted 9 when it's connected via USB
+
185  // Byte location | bit location
+
186  Plugged = (38 << 8) | 0x02,
+
187  Unplugged = (38 << 8) | 0x03,
+
188 
+
189  Charging = (39 << 8) | 0xEE,
+
190  NotCharging = (39 << 8) | 0xF1,
+
191  Shutdown = (39 << 8) | 0x01,
+
192  Dying = (39 << 8) | 0x02,
+
193  Low = (39 << 8) | 0x03,
+
194  High = (39 << 8) | 0x04,
+
195  Full = (39 << 8) | 0x05,
+
196 
+
197  MoveCharging = (21 << 8) | 0xEE,
+
198  MoveNotCharging = (21 << 8) | 0xF1,
+
199  MoveShutdown = (21 << 8) | 0x01,
+
200  MoveDying = (21 << 8) | 0x02,
+
201  MoveLow = (21 << 8) | 0x03,
+
202  MoveHigh = (21 << 8) | 0x04,
+
203  MoveFull = (21 << 8) | 0x05,
+
204 
+
205  CableRumble = (40 << 8) | 0x10, // Operating by USB and rumble is turned on
+
206  Cable = (40 << 8) | 0x12, // Operating by USB and rumble is turned off
+
207  BluetoothRumble = (40 << 8) | 0x14, // Operating by Bluetooth and rumble is turned on
+
208  Bluetooth = (40 << 8) | 0x16, // Operating by Bluetooth and rumble is turned off
+
209 };
+
210 
+
211 enum RumbleEnum {
+
212  RumbleHigh = 0x10,
+
213  RumbleLow = 0x20,
+
214 };
+
215 
+
216 #endif
+
RumbleEnum
RumbleEnum
Definition: PS3Enums.h:211
+
High
Definition: PS3Enums.h:194
+
Unplugged
Definition: PS3Enums.h:187
+
aZ
Definition: PS3Enums.h:148
+
MoveLow
Definition: PS3Enums.h:201
+
aY
Definition: PS3Enums.h:146
+
RumbleLow
Definition: PS3Enums.h:213
+
gZ
Definition: PS3Enums.h:150
+
MoveCharging
Definition: PS3Enums.h:197
+
CableRumble
Definition: PS3Enums.h:205
+
Bluetooth
Definition: PS3Enums.h:208
+
Lightblue
Definition: PS3Enums.h:127
+
Yellow
Definition: PS3Enums.h:125
+
Pitch
Definition: PS3Enums.h:179
+
Shutdown
Definition: PS3Enums.h:191
+
Charging
Definition: PS3Enums.h:189
+
StatusEnum
StatusEnum
Definition: PS3Enums.h:183
+
PS3_BUTTONS
const uint32_t PS3_BUTTONS[]
Definition: PS3Enums.h:63
controllerEnums.h
-
Dying
Definition: PS3Enums.h:191
-
Unplugged
Definition: PS3Enums.h:186
-
Yellow
Definition: PS3Enums.h:124
-
aZ
Definition: PS3Enums.h:147
-
Status
Status
Definition: PS3Enums.h:182
-
Colors
Colors
Definition: PS3Enums.h:115
-
Green
Definition: PS3Enums.h:119
-
Shutdown
Definition: PS3Enums.h:190
-
Rumble
Rumble
Definition: PS3Enums.h:210
-
RumbleLow
Definition: PS3Enums.h:212
-
MoveFull
Definition: PS3Enums.h:202
-
aZmove
Definition: PS3Enums.h:154
-
MoveNotCharging
Definition: PS3Enums.h:197
-
Pitch
Definition: PS3Enums.h:178
-
MoveHigh
Definition: PS3Enums.h:201
-
MoveShutdown
Definition: PS3Enums.h:198
-
aX
Definition: PS3Enums.h:143
-
Angle
Angle
Definition: PS3Enums.h:177
-
mYmove
Definition: PS3Enums.h:173
-
White
Definition: PS3Enums.h:131
-
gZ
Definition: PS3Enums.h:149
-
aXmove
Definition: PS3Enums.h:152
-
gXmove
Definition: PS3Enums.h:159
-
Plugged
Definition: PS3Enums.h:185
-
gZmove
Definition: PS3Enums.h:161
-
Off
Definition: PS3Enums.h:133
-
aYmove
Definition: PS3Enums.h:156
-
Purble
Definition: PS3Enums.h:128
-
BluetoothRumble
Definition: PS3Enums.h:206
-
Blue
Definition: PS3Enums.h:121
-
CableRumble
Definition: PS3Enums.h:204
-
BUTTONS
const uint32_t BUTTONS[]
Definition: PS3Enums.h:62
-
aY
Definition: PS3Enums.h:145
+
Purble
Definition: PS3Enums.h:129
+
Dying
Definition: PS3Enums.h:192
+
Low
Definition: PS3Enums.h:193
+
aZmove
Definition: PS3Enums.h:155
+
Red
Definition: PS3Enums.h:118
+
gZmove
Definition: PS3Enums.h:162
+
Green
Definition: PS3Enums.h:120
+
aYmove
Definition: PS3Enums.h:157
+
AngleEnum
AngleEnum
Definition: PS3Enums.h:178
+
PS3_LEDS
const uint8_t PS3_LEDS[]
Definition: PS3Enums.h:43
+
SensorEnum
SensorEnum
Definition: PS3Enums.h:142
+
MoveFull
Definition: PS3Enums.h:203
+
Plugged
Definition: PS3Enums.h:186
+
White
Definition: PS3Enums.h:132
+
mYmove
Definition: PS3Enums.h:174
+
gYmove
Definition: PS3Enums.h:164
+
ColorsEnum
ColorsEnum
Definition: PS3Enums.h:116
+
PS3_ANALOG_BUTTONS
const uint8_t PS3_ANALOG_BUTTONS[]
Definition: PS3Enums.h:94
+
mZmove
Definition: PS3Enums.h:172
+
aX
Definition: PS3Enums.h:144
+
MoveShutdown
Definition: PS3Enums.h:199
+
Cable
Definition: PS3Enums.h:206
+
MoveHigh
Definition: PS3Enums.h:202
+
BluetoothRumble
Definition: PS3Enums.h:207
+
gXmove
Definition: PS3Enums.h:160
+
mXmove
Definition: PS3Enums.h:170
+
NotCharging
Definition: PS3Enums.h:190
+
Off
Definition: PS3Enums.h:134
+
aXmove
Definition: PS3Enums.h:153
+
Blue
Definition: PS3Enums.h:122
+
RumbleHigh
Definition: PS3Enums.h:212
+
PS3_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:24
+
MoveDying
Definition: PS3Enums.h:200
+
MoveNotCharging
Definition: PS3Enums.h:198
+
Roll
Definition: PS3Enums.h:180
+
tempMove
Definition: PS3Enums.h:167
+
Full
Definition: PS3Enums.h:195
+
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
Definition: PS3Enums.h:27
diff --git a/_p_s3_u_s_b_8cpp.html b/_p_s3_u_s_b_8cpp.html index f5d084d1..09080bbf 100644 --- a/_p_s3_u_s_b_8cpp.html +++ b/_p_s3_u_s_b_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3USB.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for PS3USB.cpp: diff --git a/_p_s3_u_s_b_8cpp_source.html b/_p_s3_u_s_b_8cpp_source.html index 6eec5910..41455788 100644 --- a/_p_s3_u_s_b_8cpp_source.html +++ b/_p_s3_u_s_b_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3USB.cpp Source File @@ -31,7 +31,7 @@ - + @@ -116,14 +116,14 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
25 bAddress(0), // device address - mandatory
26 bPollEnable(false) // don't start polling before dongle is connected
27 {
-
28  for (uint8_t i = 0; i < PS3_MAX_ENDPOINTS; i++) {
+
28  for(uint8_t i = 0; i < PS3_MAX_ENDPOINTS; i++) {
29  epInfo[i].epAddr = 0;
30  epInfo[i].maxPktSize = (i) ? 0 : 8;
31  epInfo[i].epAttribs = 0;
32  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
33  }
34 
-
35  if (pUsb) // register in USB subsystem
+
35  if(pUsb) // register in USB subsystem
36  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
37 
38  my_bdaddr[5] = btadr5; // Change to your dongle's Bluetooth address instead
@@ -136,653 +136,658 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
45 
46 uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
47  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
-
48  uint8_t rcode;
-
49  UsbDevice *p = NULL;
-
50  EpInfo *oldep_ptr = NULL;
-
51  uint16_t PID;
-
52  uint16_t VID;
-
53 
-
54  // get memory address of USB device address pool
-
55  AddressPool &addrPool = pUsb->GetAddressPool();
-
56 #ifdef EXTRADEBUG
-
57  Notify(PSTR("\r\nPS3USB Init"), 0x80);
-
58 #endif
-
59  // check if address has already been assigned to an instance
-
60  if (bAddress) {
-
61 #ifdef DEBUG_USB_HOST
-
62  Notify(PSTR("\r\nAddress in use"), 0x80);
-
63 #endif
-
64  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
65  }
-
66 
-
67  // Get pointer to pseudo device with address 0 assigned
-
68  p = addrPool.GetUsbDevicePtr(0);
-
69 
-
70  if (!p) {
-
71 #ifdef DEBUG_USB_HOST
-
72  Notify(PSTR("\r\nAddress not found"), 0x80);
-
73 #endif
-
74  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
75  }
-
76 
-
77  if (!p->epinfo) {
-
78 #ifdef DEBUG_USB_HOST
-
79  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
80 #endif
-
81  return USB_ERROR_EPINFO_IS_NULL;
-
82  }
-
83 
-
84  // Save old pointer to EP_RECORD of address 0
-
85  oldep_ptr = p->epinfo;
-
86 
-
87  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
88  p->epinfo = epInfo;
-
89 
-
90  p->lowspeed = lowspeed;
-
91 
-
92  // Get device descriptor
-
93  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
94  // Restore p->epinfo
-
95  p->epinfo = oldep_ptr;
-
96 
-
97  if (rcode)
-
98  goto FailGetDevDescr;
-
99 
-
100  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
101  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
102 
-
103  if (VID != PS3_VID || (PID != PS3_PID && PID != PS3NAVIGATION_PID && PID != PS3MOVE_PID))
-
104  goto FailUnknownDevice;
-
105 
-
106  // Allocate new address according to device class
-
107  bAddress = addrPool.AllocAddress(parent, false, port);
-
108 
-
109  if (!bAddress)
-
110  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
111 
-
112  // Extract Max Packet Size from device descriptor
-
113  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
114 
-
115  // Assign new address to the device
-
116  rcode = pUsb->setAddr(0, 0, bAddress);
-
117  if (rcode) {
-
118  p->lowspeed = false;
-
119  addrPool.FreeAddress(bAddress);
-
120  bAddress = 0;
-
121 #ifdef DEBUG_USB_HOST
-
122  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
123  D_PrintHex<uint8_t > (rcode, 0x80);
-
124 #endif
-
125  return rcode;
-
126  }
-
127 #ifdef EXTRADEBUG
-
128  Notify(PSTR("\r\nAddr: "), 0x80);
-
129  D_PrintHex<uint8_t > (bAddress, 0x80);
-
130 #endif
-
131  delay(300); // Spec says you should wait at least 200ms
-
132 
-
133  p->lowspeed = false;
-
134 
-
135  //get pointer to assigned address record
-
136  p = addrPool.GetUsbDevicePtr(bAddress);
-
137  if (!p)
-
138  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
139 
-
140  p->lowspeed = lowspeed;
-
141 
-
142  // Assign epInfo to epinfo pointer - only EP0 is known
-
143  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
144  if (rcode)
-
145  goto FailSetDevTblEntry;
-
146 
+
48  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
49  uint8_t rcode;
+
50  UsbDevice *p = NULL;
+
51  EpInfo *oldep_ptr = NULL;
+
52  uint16_t PID;
+
53  uint16_t VID;
+
54 
+
55  // get memory address of USB device address pool
+
56  AddressPool &addrPool = pUsb->GetAddressPool();
+
57 #ifdef EXTRADEBUG
+
58  Notify(PSTR("\r\nPS3USB Init"), 0x80);
+
59 #endif
+
60  // check if address has already been assigned to an instance
+
61  if(bAddress) {
+
62 #ifdef DEBUG_USB_HOST
+
63  Notify(PSTR("\r\nAddress in use"), 0x80);
+
64 #endif
+
65  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
66  }
+
67 
+
68  // Get pointer to pseudo device with address 0 assigned
+
69  p = addrPool.GetUsbDevicePtr(0);
+
70 
+
71  if(!p) {
+
72 #ifdef DEBUG_USB_HOST
+
73  Notify(PSTR("\r\nAddress not found"), 0x80);
+
74 #endif
+
75  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
76  }
+
77 
+
78  if(!p->epinfo) {
+
79 #ifdef DEBUG_USB_HOST
+
80  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
81 #endif
+
82  return USB_ERROR_EPINFO_IS_NULL;
+
83  }
+
84 
+
85  // Save old pointer to EP_RECORD of address 0
+
86  oldep_ptr = p->epinfo;
+
87 
+
88  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
89  p->epinfo = epInfo;
+
90 
+
91  p->lowspeed = lowspeed;
+
92 
+
93  // Get device descriptor
+
94  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
+
95  // Restore p->epinfo
+
96  p->epinfo = oldep_ptr;
+
97 
+
98  if(rcode)
+
99  goto FailGetDevDescr;
+
100 
+
101  VID = udd->idVendor;
+
102  PID = udd->idProduct;
+
103 
+
104  if(VID != PS3_VID || (PID != PS3_PID && PID != PS3NAVIGATION_PID && PID != PS3MOVE_PID))
+
105  goto FailUnknownDevice;
+
106 
+
107  // Allocate new address according to device class
+
108  bAddress = addrPool.AllocAddress(parent, false, port);
+
109 
+
110  if(!bAddress)
+
111  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
112 
+
113  // Extract Max Packet Size from device descriptor
+
114  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
115 
+
116  // Assign new address to the device
+
117  rcode = pUsb->setAddr(0, 0, bAddress);
+
118  if(rcode) {
+
119  p->lowspeed = false;
+
120  addrPool.FreeAddress(bAddress);
+
121  bAddress = 0;
+
122 #ifdef DEBUG_USB_HOST
+
123  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
124  D_PrintHex<uint8_t > (rcode, 0x80);
+
125 #endif
+
126  return rcode;
+
127  }
+
128 #ifdef EXTRADEBUG
+
129  Notify(PSTR("\r\nAddr: "), 0x80);
+
130  D_PrintHex<uint8_t > (bAddress, 0x80);
+
131 #endif
+
132  //delay(300); // Spec says you should wait at least 200ms
+
133 
+
134  p->lowspeed = false;
+
135 
+
136  //get pointer to assigned address record
+
137  p = addrPool.GetUsbDevicePtr(bAddress);
+
138  if(!p)
+
139  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
140 
+
141  p->lowspeed = lowspeed;
+
142 
+
143  // Assign epInfo to epinfo pointer - only EP0 is known
+
144  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
145  if(rcode)
+
146  goto FailSetDevTblEntry;
147 
-
148  /* The application will work in reduced host mode, so we can save program and data
-
149  memory space. After verifying the PID and VID we will use known values for the
-
150  configuration values for device, interface, endpoints and HID for the PS3 Controllers */
-
151 
-
152  /* Initialize data structures for endpoints of device */
-
153  epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint
-
154  epInfo[ PS3_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
155  epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
156  epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
157  epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
158  epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
159  epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint
-
160  epInfo[ PS3_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
161  epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
162  epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
163  epInfo[ PS3_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
164  epInfo[ PS3_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
165 
-
166  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
-
167  if (rcode)
-
168  goto FailSetDevTblEntry;
-
169 
-
170  delay(200); //Give time for address change
-
171 
-
172  rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1);
-
173  if (rcode)
-
174  goto FailSetConfDescr;
-
175 
-
176  if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
-
177  if (PID == PS3_PID) {
-
178 #ifdef DEBUG_USB_HOST
-
179  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
-
180 #endif
-
181  PS3Connected = true;
-
182  } else { // must be a navigation controller
-
183 #ifdef DEBUG_USB_HOST
-
184  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
-
185 #endif
-
186  PS3NavigationConnected = true;
-
187  }
-
188  enable_sixaxis(); // The PS3 controller needs a special command before it starts sending data
-
189 
-
190  // Needed for PS3 Dualshock and Navigation commands to work
-
191  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
-
192  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]);
-
193 
-
194  for (uint8_t i = 6; i < 10; i++)
-
195  readBuf[i] = 0x7F; // Set the analog joystick values to center position
-
196  } else { // must be a Motion controller
-
197 #ifdef DEBUG_USB_HOST
-
198  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
-
199 #endif
-
200  PS3MoveConnected = true;
-
201  writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
-
202  }
-
203  if (my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) {
-
204  if (PS3MoveConnected)
-
205  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
-
206  else
-
207  setBdaddr(my_bdaddr); // Set internal Bluetooth address
-
208 
-
209 #ifdef DEBUG_USB_HOST
-
210  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
-
211  for (int8_t i = 5; i > 0; i--) {
-
212  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
-
213  Notify(PSTR(":"), 0x80);
-
214  }
-
215  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
-
216 #endif
-
217  }
-
218  onInit();
-
219 
-
220  bPollEnable = true;
-
221  Notify(PSTR("\r\n"), 0x80);
-
222  timer = millis();
-
223  return 0; // successful configuration
-
224 
-
225  /* diagnostic messages */
-
226 FailGetDevDescr:
-
227 #ifdef DEBUG_USB_HOST
-
228  NotifyFailGetDevDescr();
-
229  goto Fail;
-
230 #endif
-
231 FailSetDevTblEntry:
-
232 #ifdef DEBUG_USB_HOST
-
233  NotifyFailSetDevTblEntry();
-
234  goto Fail;
-
235 #endif
-
236 
-
237 FailSetConfDescr:
-
238 #ifdef DEBUG_USB_HOST
-
239  NotifyFailSetConfDescr();
-
240 #endif
-
241  goto Fail;
-
242 FailUnknownDevice:
-
243 #ifdef DEBUG_USB_HOST
-
244  NotifyFailUnknownDevice(VID, PID);
-
245 #endif
-
246  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
247 Fail:
-
248 
-
249 #ifdef DEBUG_USB_HOST
-
250  Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80);
-
251  NotifyFail(rcode);
-
252 #endif
-
253  Release();
-
254  return rcode;
-
255 }
-
256 
-
257 /* Performs a cleanup after failed Init() attempt */
-
258 uint8_t PS3USB::Release() {
-
259  PS3Connected = false;
-
260  PS3MoveConnected = false;
-
261  PS3NavigationConnected = false;
-
262  pUsb->GetAddressPool().FreeAddress(bAddress);
-
263  bAddress = 0;
-
264  bPollEnable = false;
-
265  return 0;
-
266 }
-
267 
-
268 uint8_t PS3USB::Poll() {
-
269  if (!bPollEnable)
-
270  return 0;
-
271 
-
272  if (PS3Connected || PS3NavigationConnected) {
-
273  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
-
274  pUsb->inTransfer(bAddress, epInfo[ PS3_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
-
275  if (millis() - timer > 100) { // Loop 100ms before processing data
-
276  readReport();
-
277 #ifdef PRINTREPORT
-
278  printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
-
279 #endif
-
280  }
-
281  } else if (PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB
-
282  if (millis() - timer > 4000) { // Send at least every 4th second
-
283  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
-
284  timer = millis();
-
285  }
-
286  }
-
287  return 0;
-
288 }
-
289 
-
290 void PS3USB::readReport() {
-
291  ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
+
148 
+
149  /* The application will work in reduced host mode, so we can save program and data
+
150  memory space. After verifying the PID and VID we will use known values for the
+
151  configuration values for device, interface, endpoints and HID for the PS3 Controllers */
+
152 
+
153  /* Initialize data structures for endpoints of device */
+
154  epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint
+
155  epInfo[ PS3_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
156  epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
157  epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
158  epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = 0;
+
159  epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = 0;
+
160  epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint
+
161  epInfo[ PS3_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
162  epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
163  epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
164  epInfo[ PS3_INPUT_PIPE ].bmSndToggle = 0;
+
165  epInfo[ PS3_INPUT_PIPE ].bmRcvToggle = 0;
+
166 
+
167  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
+
168  if(rcode)
+
169  goto FailSetDevTblEntry;
+
170 
+
171  delay(200); //Give time for address change
+
172 
+
173  rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1);
+
174  if(rcode)
+
175  goto FailSetConfDescr;
+
176 
+
177  if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
+
178  if(PID == PS3_PID) {
+
179 #ifdef DEBUG_USB_HOST
+
180  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
+
181 #endif
+
182  PS3Connected = true;
+
183  } else { // must be a navigation controller
+
184 #ifdef DEBUG_USB_HOST
+
185  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
+
186 #endif
+
187  PS3NavigationConnected = true;
+
188  }
+
189  enable_sixaxis(); // The PS3 controller needs a special command before it starts sending data
+
190 
+
191  // Needed for PS3 Dualshock and Navigation commands to work
+
192  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
+
193  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]);
+
194 
+
195  for(uint8_t i = 6; i < 10; i++)
+
196  readBuf[i] = 0x7F; // Set the analog joystick values to center position
+
197  } else { // must be a Motion controller
+
198 #ifdef DEBUG_USB_HOST
+
199  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
+
200 #endif
+
201  PS3MoveConnected = true;
+
202  writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
+
203  }
+
204  if(my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) {
+
205  if(PS3MoveConnected)
+
206  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
+
207  else
+
208  setBdaddr(my_bdaddr); // Set internal Bluetooth address
+
209 
+
210 #ifdef DEBUG_USB_HOST
+
211  Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
+
212  for(int8_t i = 5; i > 0; i--) {
+
213  D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
+
214  Notify(PSTR(":"), 0x80);
+
215  }
+
216  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
+
217 #endif
+
218  }
+
219  onInit();
+
220 
+
221  bPollEnable = true;
+
222  Notify(PSTR("\r\n"), 0x80);
+
223  timer = millis();
+
224  return 0; // Successful configuration
+
225 
+
226  /* Diagnostic messages */
+
227 FailGetDevDescr:
+
228 #ifdef DEBUG_USB_HOST
+
229  NotifyFailGetDevDescr();
+
230  goto Fail;
+
231 #endif
+
232 
+
233 FailSetDevTblEntry:
+
234 #ifdef DEBUG_USB_HOST
+
235  NotifyFailSetDevTblEntry();
+
236  goto Fail;
+
237 #endif
+
238 
+
239 FailSetConfDescr:
+
240 #ifdef DEBUG_USB_HOST
+
241  NotifyFailSetConfDescr();
+
242 #endif
+
243  goto Fail;
+
244 
+
245 FailUnknownDevice:
+
246 #ifdef DEBUG_USB_HOST
+
247  NotifyFailUnknownDevice(VID, PID);
+
248 #endif
+
249  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
250 
+
251 Fail:
+
252 #ifdef DEBUG_USB_HOST
+
253  Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80);
+
254  NotifyFail(rcode);
+
255 #endif
+
256  Release();
+
257  return rcode;
+
258 }
+
259 
+
260 /* Performs a cleanup after failed Init() attempt */
+
261 uint8_t PS3USB::Release() {
+
262  PS3Connected = false;
+
263  PS3MoveConnected = false;
+
264  PS3NavigationConnected = false;
+
265  pUsb->GetAddressPool().FreeAddress(bAddress);
+
266  bAddress = 0;
+
267  bPollEnable = false;
+
268  return 0;
+
269 }
+
270 
+
271 uint8_t PS3USB::Poll() {
+
272  if(!bPollEnable)
+
273  return 0;
+
274 
+
275  if(PS3Connected || PS3NavigationConnected) {
+
276  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
+
277  pUsb->inTransfer(bAddress, epInfo[ PS3_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
+
278  if(millis() - timer > 100) { // Loop 100ms before processing data
+
279  readReport();
+
280 #ifdef PRINTREPORT
+
281  printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
+
282 #endif
+
283  }
+
284  } else if(PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB
+
285  if(millis() - timer > 4000) { // Send at least every 4th second
+
286  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
+
287  timer = millis();
+
288  }
+
289  }
+
290  return 0;
+
291 }
292 
-
293  //Notify(PSTR("\r\nButtonState", 0x80);
-
294  //PrintHex<uint32_t>(ButtonState, 0x80);
+
293 void PS3USB::readReport() {
+
294  ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
295 
-
296  if (ButtonState != OldButtonState) {
-
297  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
-
298  OldButtonState = ButtonState;
-
299  }
-
300 }
-
301 
-
302 void PS3USB::printReport() { // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
-
303 #ifdef PRINTREPORT
-
304  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) {
-
305  D_PrintHex<uint8_t > (readBuf[i], 0x80);
-
306  Notify(PSTR(" "), 0x80);
-
307  }
-
308  Notify(PSTR("\r\n"), 0x80);
-
309 #endif
-
310 }
-
311 
-
312 bool PS3USB::getButtonPress(Button b) {
-
313  return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
-
314 }
-
315 
-
316 bool PS3USB::getButtonClick(Button b) {
-
317  uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
-
318  bool click = (ButtonClickState & button);
-
319  ButtonClickState &= ~button; // Clear "click" event
-
320  return click;
-
321 }
-
322 
-
323 uint8_t PS3USB::getAnalogButton(Button a) {
-
324  return (uint8_t)(readBuf[(pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a])) - 9]);
-
325 }
-
326 
-
327 uint8_t PS3USB::getAnalogHat(AnalogHat a) {
-
328  return (uint8_t)(readBuf[((uint8_t)a + 6)]);
-
329 }
-
330 
-
331 uint16_t PS3USB::getSensor(Sensor a) {
-
332  return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
-
333 }
-
334 
-
335 double PS3USB::getAngle(Angle a) {
-
336  if (PS3Connected) {
-
337  double accXval;
-
338  double accYval;
-
339  double accZval;
-
340 
-
341  // Data for the Kionix KXPC4 used in the DualShock 3
-
342  const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
-
343  accXval = -((double)getSensor(aX) - zeroG);
-
344  accYval = -((double)getSensor(aY) - zeroG);
-
345  accZval = -((double)getSensor(aZ) - zeroG);
-
346 
-
347  // Convert to 360 degrees resolution
-
348  // atan2 outputs the value of -Ï€ to Ï€ (radians)
-
349  // We are then converting it to 0 to 2Ï€ and then to degrees
-
350  if (a == Pitch)
-
351  return (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
-
352  else
-
353  return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
-
354  } else
-
355  return 0;
-
356 }
-
357 
-
358 bool PS3USB::getStatus(Status c) {
-
359  return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
-
360 }
-
361 
-
362 String PS3USB::getStatusString() {
-
363  if (PS3Connected || PS3NavigationConnected) {
-
364  char statusOutput[100];
-
365 
-
366  strcpy(statusOutput, "ConnectionStatus: ");
-
367 
-
368  if (getStatus(Plugged)) strcat(statusOutput, "Plugged");
-
369  else if (getStatus(Unplugged)) strcat(statusOutput, "Unplugged");
-
370  else strcat(statusOutput, "Error");
-
371 
-
372 
-
373  strcat(statusOutput, " - PowerRating: ");
-
374 
-
375  if (getStatus(Charging)) strcat(statusOutput, "Charging");
-
376  else if (getStatus(NotCharging)) strcat(statusOutput, "Not Charging");
-
377  else if (getStatus(Shutdown)) strcat(statusOutput, "Shutdown");
-
378  else if (getStatus(Dying)) strcat(statusOutput, "Dying");
-
379  else if (getStatus(Low)) strcat(statusOutput, "Low");
-
380  else if (getStatus(High)) strcat(statusOutput, "High");
-
381  else if (getStatus(Full)) strcat(statusOutput, "Full");
-
382  else strcat(statusOutput, "Error");
-
383 
-
384  strcat(statusOutput, " - WirelessStatus: ");
-
385 
-
386  if (getStatus(CableRumble)) strcat(statusOutput, "Cable - Rumble is on");
-
387  else if (getStatus(Cable)) strcat(statusOutput, "Cable - Rumble is off");
-
388  else if (getStatus(BluetoothRumble)) strcat(statusOutput, "Bluetooth - Rumble is on");
-
389  else if (getStatus(Bluetooth)) strcat(statusOutput, "Bluetooth - Rumble is off");
-
390  else strcat(statusOutput, "Error");
-
391 
-
392  return statusOutput;
-
393  } else
-
394  return "Error";
-
395 }
-
396 
-
397 /* Playstation Sixaxis Dualshock and Navigation Controller commands */
-
398 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
-
399  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x01), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
-
400  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
-
401 }
-
402 
-
403 void PS3USB::setAllOff() {
-
404  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
-
405  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // Reset buffer
-
406 
-
407  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
408 }
-
409 
-
410 void PS3USB::setRumbleOff() {
-
411  writeBuf[1] = 0x00;
-
412  writeBuf[2] = 0x00; // Low mode off
-
413  writeBuf[3] = 0x00;
-
414  writeBuf[4] = 0x00; // High mode off
-
415 
-
416  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
417 }
-
418 
-
419 void PS3USB::setRumbleOn(Rumble mode) {
-
420  if ((mode & 0x30) > 0x00) {
-
421  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
-
422  if (mode == RumbleHigh) {
-
423  power[0] = 0x00;
-
424  power[1] = 0xff;
-
425  }
-
426  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
-
427  }
-
428 }
-
429 
-
430 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
-
431  writeBuf[1] = rightDuration;
-
432  writeBuf[2] = rightPower;
-
433  writeBuf[3] = leftDuration;
-
434  writeBuf[4] = leftPower;
-
435  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
436 }
-
437 
-
438 void PS3USB::setLedRaw(uint8_t value) {
-
439  writeBuf[9] = value << 1;
-
440  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
441 }
-
442 
-
443 void PS3USB::setLedOff(LED a) {
-
444  writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
-
445  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
446 }
-
447 
-
448 void PS3USB::setLedOn(LED a) {
-
449  writeBuf[9] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
-
450  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
-
451 }
-
452 
-
453 void PS3USB::setLedToggle(LED a) {
-
454  writeBuf[9] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
-
455  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
296  //Notify(PSTR("\r\nButtonState", 0x80);
+
297  //PrintHex<uint32_t>(ButtonState, 0x80);
+
298 
+
299  if(ButtonState != OldButtonState) {
+
300  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
+
301  OldButtonState = ButtonState;
+
302  }
+
303 }
+
304 
+
305 void PS3USB::printReport() { // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
+
306 #ifdef PRINTREPORT
+
307  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) {
+
308  D_PrintHex<uint8_t > (readBuf[i], 0x80);
+
309  Notify(PSTR(" "), 0x80);
+
310  }
+
311  Notify(PSTR("\r\n"), 0x80);
+
312 #endif
+
313 }
+
314 
+
315 bool PS3USB::getButtonPress(ButtonEnum b) {
+
316  return (ButtonState & pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]));
+
317 }
+
318 
+
319 bool PS3USB::getButtonClick(ButtonEnum b) {
+
320  uint32_t button = pgm_read_dword(&PS3_BUTTONS[(uint8_t)b]);
+
321  bool click = (ButtonClickState & button);
+
322  ButtonClickState &= ~button; // Clear "click" event
+
323  return click;
+
324 }
+
325 
+
326 uint8_t PS3USB::getAnalogButton(ButtonEnum a) {
+
327  return (uint8_t)(readBuf[(pgm_read_byte(&PS3_ANALOG_BUTTONS[(uint8_t)a])) - 9]);
+
328 }
+
329 
+
330 uint8_t PS3USB::getAnalogHat(AnalogHatEnum a) {
+
331  return (uint8_t)(readBuf[((uint8_t)a + 6)]);
+
332 }
+
333 
+
334 uint16_t PS3USB::getSensor(SensorEnum a) {
+
335  return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
+
336 }
+
337 
+
338 double PS3USB::getAngle(AngleEnum a) {
+
339  if(PS3Connected) {
+
340  double accXval;
+
341  double accYval;
+
342  double accZval;
+
343 
+
344  // Data for the Kionix KXPC4 used in the DualShock 3
+
345  const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
+
346  accXval = -((double)getSensor(aX) - zeroG);
+
347  accYval = -((double)getSensor(aY) - zeroG);
+
348  accZval = -((double)getSensor(aZ) - zeroG);
+
349 
+
350  // Convert to 360 degrees resolution
+
351  // atan2 outputs the value of -Ï€ to Ï€ (radians)
+
352  // We are then converting it to 0 to 2Ï€ and then to degrees
+
353  if(a == Pitch)
+
354  return (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
+
355  else
+
356  return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
+
357  } else
+
358  return 0;
+
359 }
+
360 
+
361 bool PS3USB::getStatus(StatusEnum c) {
+
362  return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
+
363 }
+
364 
+
365 void PS3USB::printStatusString() {
+
366  char statusOutput[100]; // Max string length plus null character
+
367  if(PS3Connected || PS3NavigationConnected) {
+
368  strcpy_P(statusOutput, PSTR("ConnectionStatus: "));
+
369 
+
370  if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged"));
+
371  else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged"));
+
372  else strcat_P(statusOutput, PSTR("Error"));
+
373 
+
374  strcat_P(statusOutput, PSTR(" - PowerRating: "));
+
375 
+
376  if(getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging"));
+
377  else if(getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
+
378  else if(getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
+
379  else if(getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying"));
+
380  else if(getStatus(Low)) strcat_P(statusOutput, PSTR("Low"));
+
381  else if(getStatus(High)) strcat_P(statusOutput, PSTR("High"));
+
382  else if(getStatus(Full)) strcat_P(statusOutput, PSTR("Full"));
+
383  else strcat_P(statusOutput, PSTR("Error"));
+
384 
+
385  strcat_P(statusOutput, PSTR(" - WirelessStatus: "));
+
386 
+
387  if(getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on"));
+
388  else if(getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off"));
+
389  else if(getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on"));
+
390  else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off"));
+
391  else strcat_P(statusOutput, PSTR("Error"));
+
392  } else
+
393  strcpy_P(statusOutput, PSTR("Error"));
+
394 
+
395  USB_HOST_SERIAL.write((uint8_t*)statusOutput, strlen(statusOutput));
+
396 }
+
397 
+
398 /* Playstation Sixaxis Dualshock and Navigation Controller commands */
+
399 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
+
400  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x01), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
+
401  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
+
402 }
+
403 
+
404 void PS3USB::setAllOff() {
+
405  for(uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
+
406  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // Reset buffer
+
407 
+
408  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
409 }
+
410 
+
411 void PS3USB::setRumbleOff() {
+
412  writeBuf[1] = 0x00;
+
413  writeBuf[2] = 0x00; // Low mode off
+
414  writeBuf[3] = 0x00;
+
415  writeBuf[4] = 0x00; // High mode off
+
416 
+
417  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
418 }
+
419 
+
420 void PS3USB::setRumbleOn(RumbleEnum mode) {
+
421  if((mode & 0x30) > 0x00) {
+
422  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
+
423  if(mode == RumbleHigh) {
+
424  power[0] = 0x00;
+
425  power[1] = 0xff;
+
426  }
+
427  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
+
428  }
+
429 }
+
430 
+
431 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
+
432  writeBuf[1] = rightDuration;
+
433  writeBuf[2] = rightPower;
+
434  writeBuf[3] = leftDuration;
+
435  writeBuf[4] = leftPower;
+
436  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
437 }
+
438 
+
439 void PS3USB::setLedRaw(uint8_t value) {
+
440  writeBuf[9] = value << 1;
+
441  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
442 }
+
443 
+
444 void PS3USB::setLedOff(LEDEnum a) {
+
445  writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1));
+
446  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
447 }
+
448 
+
449 void PS3USB::setLedOn(LEDEnum a) {
+
450  if(a == OFF)
+
451  setLedRaw(0);
+
452  else {
+
453  writeBuf[9] |= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
454  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
455  }
456 }
457 
-
458 void PS3USB::setBdaddr(uint8_t *bdaddr) {
-
459  /* Set the internal Bluetooth address */
-
460  uint8_t buf[8];
-
461  buf[0] = 0x01;
-
462  buf[1] = 0x00;
-
463 
-
464  for (uint8_t i = 0; i < 6; i++)
-
465  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
-
466 
-
467  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
468  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
-
469 }
-
470 
-
471 void PS3USB::getBdaddr(uint8_t *bdaddr) {
-
472  uint8_t buf[8];
-
473 
-
474  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
475  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
-
476 
-
477  for (uint8_t i = 0; i < 6; i++)
-
478  bdaddr[5 - i] = buf[i + 2]; // Copy into buffer reversed, so it is LSB first
-
479 }
-
480 
-
481 void PS3USB::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via USB
-
482  uint8_t cmd_buf[4];
-
483  cmd_buf[0] = 0x42; // Special PS3 Controller enable commands
-
484  cmd_buf[1] = 0x0c;
-
485  cmd_buf[2] = 0x00;
-
486  cmd_buf[3] = 0x00;
-
487 
-
488  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF4), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data)
-
489  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
-
490 }
-
491 
-
492 /* Playstation Move Controller commands */
-
493 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
-
494  pUsb->outTransfer(bAddress, epInfo[ PS3_OUTPUT_PIPE ].epAddr, nbytes, data);
+
458 void PS3USB::setLedToggle(LEDEnum a) {
+
459  writeBuf[9] ^= (uint8_t)((pgm_read_byte(&PS3_LEDS[(uint8_t)a]) & 0x0f) << 1);
+
460  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
+
461 }
+
462 
+
463 void PS3USB::setBdaddr(uint8_t *bdaddr) {
+
464  /* Set the internal Bluetooth address */
+
465  uint8_t buf[8];
+
466  buf[0] = 0x01;
+
467  buf[1] = 0x00;
+
468 
+
469  for(uint8_t i = 0; i < 6; i++)
+
470  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
+
471 
+
472  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
473  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
+
474 }
+
475 
+
476 void PS3USB::getBdaddr(uint8_t *bdaddr) {
+
477  uint8_t buf[8];
+
478 
+
479  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
480  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
+
481 
+
482  for(uint8_t i = 0; i < 6; i++)
+
483  bdaddr[5 - i] = buf[i + 2]; // Copy into buffer reversed, so it is LSB first
+
484 }
+
485 
+
486 void PS3USB::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via USB
+
487  uint8_t cmd_buf[4];
+
488  cmd_buf[0] = 0x42; // Special PS3 Controller enable commands
+
489  cmd_buf[1] = 0x0c;
+
490  cmd_buf[2] = 0x00;
+
491  cmd_buf[3] = 0x00;
+
492 
+
493  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF4), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data)
+
494  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
495 }
496 
-
497 void PS3USB::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
-
498  // Set the Bulb's values into the write buffer
-
499  writeBuf[2] = r;
-
500  writeBuf[3] = g;
-
501  writeBuf[4] = b;
-
502 
-
503  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
-
504 }
-
505 
-
506 void PS3USB::moveSetBulb(Colors color) { // Use this to set the Color using the predefined colors in "enums.h"
-
507  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
-
508 }
-
509 
-
510 void PS3USB::moveSetRumble(uint8_t rumble) {
-
511 #ifdef DEBUG_USB_HOST
-
512  if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
-
513  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
-
514 #endif
-
515  writeBuf[6] = rumble; // Set the rumble value into the write buffer
-
516 
-
517  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
-
518 }
-
519 
-
520 void PS3USB::setMoveBdaddr(uint8_t *bdaddr) {
-
521  /* Set the internal Bluetooth address */
-
522  uint8_t buf[11];
-
523  buf[0] = 0x05;
-
524  buf[7] = 0x10;
-
525  buf[8] = 0x01;
-
526  buf[9] = 0x02;
-
527  buf[10] = 0x12;
-
528 
-
529  for (uint8_t i = 0; i < 6; i++)
-
530  buf[i + 1] = bdaddr[i];
-
531 
-
532  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
533  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
-
534 }
-
535 
-
536 void PS3USB::getMoveBdaddr(uint8_t *bdaddr) {
-
537  uint8_t buf[16];
-
538 
-
539  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x04), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
540  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
-
541 
-
542  for (uint8_t i = 0; i < 6; i++)
-
543  bdaddr[i] = buf[10 + i];
-
544 }
-
545 
-
546 void PS3USB::getMoveCalibration(uint8_t *data) {
-
547  uint8_t buf[49];
-
548 
-
549  for (uint8_t i = 0; i < 3; i++) {
-
550  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x10), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
-
551  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
-
552 
-
553  for (byte j = 0; j < 49; j++)
-
554  data[49 * i + j] = buf[j];
-
555  }
-
556 }
+
497 /* Playstation Move Controller commands */
+
498 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
+
499  pUsb->outTransfer(bAddress, epInfo[ PS3_OUTPUT_PIPE ].epAddr, nbytes, data);
+
500 }
+
501 
+
502 void PS3USB::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
+
503  // Set the Bulb's values into the write buffer
+
504  writeBuf[2] = r;
+
505  writeBuf[3] = g;
+
506  writeBuf[4] = b;
+
507 
+
508  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
+
509 }
+
510 
+
511 void PS3USB::moveSetBulb(ColorsEnum color) { // Use this to set the Color using the predefined colors in "enums.h"
+
512  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
+
513 }
+
514 
+
515 void PS3USB::moveSetRumble(uint8_t rumble) {
+
516 #ifdef DEBUG_USB_HOST
+
517  if(rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
+
518  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
+
519 #endif
+
520  writeBuf[6] = rumble; // Set the rumble value into the write buffer
+
521 
+
522  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
+
523 }
+
524 
+
525 void PS3USB::setMoveBdaddr(uint8_t *bdaddr) {
+
526  /* Set the internal Bluetooth address */
+
527  uint8_t buf[11];
+
528  buf[0] = 0x05;
+
529  buf[7] = 0x10;
+
530  buf[8] = 0x01;
+
531  buf[9] = 0x02;
+
532  buf[10] = 0x12;
+
533 
+
534  for(uint8_t i = 0; i < 6; i++)
+
535  buf[i + 1] = bdaddr[i];
+
536 
+
537  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
538  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
+
539 }
+
540 
+
541 void PS3USB::getMoveBdaddr(uint8_t *bdaddr) {
+
542  uint8_t buf[16];
+
543 
+
544  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x04), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
545  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
+
546 
+
547  for(uint8_t i = 0; i < 6; i++)
+
548  bdaddr[i] = buf[10 + i];
+
549 }
+
550 
+
551 void PS3USB::getMoveCalibration(uint8_t *data) {
+
552  uint8_t buf[49];
+
553 
+
554  for(uint8_t i = 0; i < 3; i++) {
+
555  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x10), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
+
556  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
557 
-
558 void PS3USB::onInit() {
-
559  if (pFuncOnInit)
-
560  pFuncOnInit(); // Call the user function
-
561  else {
-
562  if (PS3MoveConnected)
-
563  moveSetBulb(Red);
-
564  else // Dualshock 3 or Navigation controller
-
565  setLedOn(LED1);
-
566  }
-
567 }
+
558  for(byte j = 0; j < 49; j++)
+
559  data[49 * i + j] = buf[j];
+
560  }
+
561 }
+
562 
+
563 void PS3USB::onInit() {
+
564  if(pFuncOnInit)
+
565  pFuncOnInit(); // Call the user function
+
566  else {
+
567  if(PS3MoveConnected)
+
568  moveSetBulb(Red);
+
569  else // Dualshock 3 or Navigation controller
+
570  setLedOn(LED1);
+
571  }
+
572 }
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:41
+
RumbleEnum
RumbleEnum
Definition: PS3Enums.h:211
+
High
Definition: PS3Enums.h:194
AddressPool
Definition: address.h:83
-
PS3USB::getSensor
uint16_t getSensor(Sensor a)
Definition: PS3USB.cpp:331
-
NotCharging
Definition: PS3Enums.h:189
-
PS3USB::getBdaddr
void getBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:471
-
Cable
Definition: PS3Enums.h:205
-
Red
Definition: PS3Enums.h:117
+
PS3USB::getBdaddr
void getBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:476
+
Unplugged
Definition: PS3Enums.h:187
+
aZ
Definition: PS3Enums.h:148
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
LED1
Definition: controllerEnums.h:28
+
aY
Definition: PS3Enums.h:146
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
-
PS3USB::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3USB.cpp:438
+
PS3USB::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3USB.cpp:439
PS3USB::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3USB.h:273
PS3USB::setLedOff
void setLedOff()
Definition: PS3USB.h:224
PS3_INPUT_PIPE
#define PS3_INPUT_PIPE
Definition: PS3USB.h:33
-
Low
Definition: PS3Enums.h:192
+
LED1
Definition: controllerEnums.h:29
UsbDevice
Definition: address.h:75
-
Sensor
Sensor
Definition: PS3Enums.h:141
+
CableRumble
Definition: PS3Enums.h:205
PS3MOVE_PID
#define PS3MOVE_PID
Definition: BTD.h:27
-
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[]
Definition: PS3Enums.h:24
-
PS3USB::setBdaddr
void setBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:458
-
PS3USB::Release
virtual uint8_t Release()
Definition: PS3USB.cpp:258
+
PS3USB::setBdaddr
void setBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:463
+
PS3USB::Release
virtual uint8_t Release()
Definition: PS3USB.cpp:261
+
Bluetooth
Definition: PS3Enums.h:208
+
PS3USB::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: PS3USB.cpp:315
PS3USB.h
PS3_OUTPUT_PIPE
#define PS3_OUTPUT_PIPE
Definition: PS3USB.h:32
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
PS3USB::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3USB.h:271
-
High
Definition: PS3Enums.h:193
-
Charging
Definition: PS3Enums.h:188
-
RumbleHigh
Definition: PS3Enums.h:211
-
Bluetooth
Definition: PS3Enums.h:207
-
Full
Definition: PS3Enums.h:194
-
LEDS
const uint8_t LEDS[]
Definition: PS3Enums.h:43
-
ANALOGBUTTONS
const uint8_t ANALOGBUTTONS[]
Definition: PS3Enums.h:93
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
PS3USB::getAnalogButton
uint8_t getAnalogButton(Button a)
Definition: PS3USB.cpp:323
-
PS3USB::getMoveBdaddr
void getMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:536
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
Pitch
Definition: PS3Enums.h:179
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
Shutdown
Definition: PS3Enums.h:191
+
Charging
Definition: PS3Enums.h:189
+
StatusEnum
StatusEnum
Definition: PS3Enums.h:183
+
PS3USB::getMoveBdaddr
void getMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:541
PS3_VID
#define PS3_VID
Definition: BTD.h:24
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
+
PS3USB::getAnalogButton
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3USB.cpp:326
+
PS3USB::getSensor
uint16_t getSensor(SensorEnum a)
Definition: PS3USB.cpp:334
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
PS3USB::setRumbleOff
void setRumbleOff()
Definition: PS3USB.cpp:410
-
LED
LED
Definition: controllerEnums.h:27
+
PS3USB::setRumbleOff
void setRumbleOff()
Definition: PS3USB.cpp:411
+
PS3_BUTTONS
const uint32_t PS3_BUTTONS[]
Definition: PS3Enums.h:63
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
PS3USB::PS3Connected
bool PS3Connected
Definition: PS3USB.h:265
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
-
PS3USB::getStatusString
String getStatusString()
Definition: PS3USB.cpp:362
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
-
PS3USB::getStatus
bool getStatus(Status c)
Definition: PS3USB.cpp:358
-
PS3USB::getButtonClick
bool getButtonClick(Button b)
Definition: PS3USB.cpp:316
Notify
#define Notify(...)
Definition: message.h:44
PS3_CONTROL_PIPE
#define PS3_CONTROL_PIPE
Definition: PS3USB.h:31
-
Dying
Definition: PS3Enums.h:191
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
-
PS3USB::setRumbleOn
void setRumbleOn(Rumble mode)
Definition: PS3USB.cpp:419
-
Unplugged
Definition: PS3Enums.h:186
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
+
USB_HOST_SERIAL
#define USB_HOST_SERIAL
Definition: settings.h:24
+
PS3USB::setLedToggle
void setLedToggle(LEDEnum a)
Definition: PS3USB.cpp:458
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
-
aZ
Definition: PS3Enums.h:147
NotifyFailUnknownDevice
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
-
Status
Status
Definition: PS3Enums.h:182
-
Colors
Colors
Definition: PS3Enums.h:115
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
PS3USB::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3USB.cpp:497
-
Shutdown
Definition: PS3Enums.h:190
-
PS3USB::setLedToggle
void setLedToggle(LED a)
Definition: PS3USB.cpp:453
-
Rumble
Rumble
Definition: PS3Enums.h:210
+
PS3USB::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3USB.cpp:502
+
Dying
Definition: PS3Enums.h:192
+
Low
Definition: PS3Enums.h:193
PS3USB::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: PS3USB.cpp:46
+
Red
Definition: PS3Enums.h:118
EP_INTERRUPT
#define EP_INTERRUPT
Definition: PS3USB.h:28
EpInfo
Definition: address.h:32
MOVE_REPORT_BUFFER_SIZE
#define MOVE_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:40
-
PS3USB::setAllOff
void setAllOff()
Definition: PS3USB.cpp:403
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
PS3USB::printStatusString
void printStatusString()
Definition: PS3USB.cpp:365
+
PS3USB::setAllOff
void setAllOff()
Definition: PS3USB.cpp:404
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
HID_REQUEST_SET_REPORT
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
-
HID_REQUEST_GET_REPORT
#define HID_REQUEST_GET_REPORT
Definition: hid.h:66
-
Pitch
Definition: PS3Enums.h:178
+
AngleEnum
AngleEnum
Definition: PS3Enums.h:178
+
HID_REQUEST_GET_REPORT
#define HID_REQUEST_GET_REPORT
Definition: hid.h:69
+
PS3_LEDS
const uint8_t PS3_LEDS[]
Definition: PS3Enums.h:43
+
SensorEnum
SensorEnum
Definition: PS3Enums.h:142
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
+
Plugged
Definition: PS3Enums.h:186
EpInfo::bmSndToggle
uint8_t bmSndToggle
Definition: address.h:40
-
aX
Definition: PS3Enums.h:143
+
PS3USB::getAnalogHat
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3USB.cpp:330
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
Angle
Angle
Definition: PS3Enums.h:177
PS3USB::pUsb
USB * pUsb
Definition: PS3USB.h:277
+
ColorsEnum
ColorsEnum
Definition: PS3Enums.h:116
+
PS3_ANALOG_BUTTONS
const uint8_t PS3_ANALOG_BUTTONS[]
Definition: PS3Enums.h:94
+
OFF
Definition: controllerEnums.h:28
USB_NAK_NOWAIT
#define USB_NAK_NOWAIT
Definition: address.h:29
+
PS3USB::getAngle
double getAngle(AngleEnum a)
Definition: PS3USB.cpp:338
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
+
aX
Definition: PS3Enums.h:144
PS3_PID
#define PS3_PID
Definition: BTD.h:25
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
PS3NAVIGATION_PID
#define PS3NAVIGATION_PID
Definition: BTD.h:26
-
PS3USB::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3USB.cpp:510
-
PS3USB::Poll
virtual uint8_t Poll()
Definition: PS3USB.cpp:268
+
PS3USB::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3USB.cpp:515
+
PS3USB::Poll
virtual uint8_t Poll()
Definition: PS3USB.cpp:271
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
+
Cable
Definition: PS3Enums.h:206
PS3_MAX_ENDPOINTS
#define PS3_MAX_ENDPOINTS
Definition: PS3USB.h:48
PS3USB::epInfo
EpInfo epInfo[PS3_MAX_ENDPOINTS]
Definition: PS3USB.h:281
-
Plugged
Definition: PS3Enums.h:185
-
bmRCVTOG0
#define bmRCVTOG0
Definition: max3421e.h:185
+
PS3USB::setRumbleOn
void setRumbleOn(RumbleEnum mode)
Definition: PS3USB.cpp:420
+
BluetoothRumble
Definition: PS3Enums.h:207
bmREQ_HID_OUT
#define bmREQ_HID_OUT
Definition: BTD.h:38
bmREQ_HID_IN
#define bmREQ_HID_IN
Definition: PS3USB.h:43
+
NotCharging
Definition: PS3Enums.h:190
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
-
Button
Button
Definition: controllerEnums.h:44
-
bmSNDTOG0
#define bmSNDTOG0
Definition: max3421e.h:187
+
PS3USB::setLedOn
void setLedOn(LEDEnum a)
Definition: PS3USB.cpp:449
+
RumbleHigh
Definition: PS3Enums.h:212
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
PS3USB::bAddress
uint8_t bAddress
Definition: PS3USB.h:279
-
PS3USB::setMoveBdaddr
void setMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:520
-
PS3_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:37
-
BluetoothRumble
Definition: PS3Enums.h:206
-
USB
Definition: UsbCore.h:152
-
PS3USB::getAnalogHat
uint8_t getAnalogHat(AnalogHat a)
Definition: PS3USB.cpp:327
-
PS3USB::getAngle
double getAngle(Angle a)
Definition: PS3USB.cpp:335
-
PS3USB::setLedOn
void setLedOn(LED a)
Definition: PS3USB.cpp:448
-
CableRumble
Definition: PS3Enums.h:204
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
PS3USB::setMoveBdaddr
void setMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:525
+
PS3_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:24
+
USB
Definition: UsbCore.h:176
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
PS3USB::getButtonPress
bool getButtonPress(Button b)
Definition: PS3USB.cpp:312
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
BUTTONS
const uint32_t BUTTONS[]
Definition: PS3Enums.h:62
PS3USB::PS3USB
PS3USB(USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
Definition: PS3USB.cpp:23
-
PS3USB::getMoveCalibration
void getMoveCalibration(uint8_t *data)
Definition: PS3USB.cpp:546
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
-
aY
Definition: PS3Enums.h:145
+
PS3USB::getMoveCalibration
void getMoveCalibration(uint8_t *data)
Definition: PS3USB.cpp:551
+
Full
Definition: PS3Enums.h:195
+
PS3USB::getStatus
bool getStatus(StatusEnum c)
Definition: PS3USB.cpp:361
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
+
PS3_REPORT_BUFFER
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
Definition: PS3Enums.h:27
+
PS3USB::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: PS3USB.cpp:319
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/_p_s3_u_s_b_8h.html b/_p_s3_u_s_b_8h.html index 58d6a13b..35438333 100644 --- a/_p_s3_u_s_b_8h.html +++ b/_p_s3_u_s_b_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3USB.h File Reference @@ -31,7 +31,7 @@ - + @@ -349,7 +349,7 @@ Macros diff --git a/_p_s3_u_s_b_8h_source.html b/_p_s3_u_s_b_8h_source.html index 007364bc..4033ed50 100644 --- a/_p_s3_u_s_b_8h_source.html +++ b/_p_s3_u_s_b_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: PS3USB.h Source File @@ -31,7 +31,7 @@ - + @@ -164,30 +164,31 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
140  void getMoveBdaddr(uint8_t *bdaddr);
145  void getMoveCalibration(uint8_t *data);
146 
-
156  bool getButtonPress(Button b);
-
157  bool getButtonClick(Button b);
-
168  uint8_t getAnalogButton(Button a);
-
174  uint8_t getAnalogHat(AnalogHat a);
-
181  uint16_t getSensor(Sensor a);
-
187  double getAngle(Angle a);
-
193  bool getStatus(Status c);
-
198  String getStatusString();
-
199 
-
201  void setAllOff();
-
203  void setRumbleOff();
-
208  void setRumbleOn(Rumble mode);
-
216  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
-
217 
-
222  void setLedRaw(uint8_t value);
+
158  bool getButtonPress(ButtonEnum b);
+
159  bool getButtonClick(ButtonEnum b);
+
170  uint8_t getAnalogButton(ButtonEnum a);
+
176  uint8_t getAnalogHat(AnalogHatEnum a);
+
183  uint16_t getSensor(SensorEnum a);
+
189  double getAngle(AngleEnum a);
+
195  bool getStatus(StatusEnum c);
+
197  void printStatusString();
+
198 
+
200  void setAllOff();
+
202  void setRumbleOff();
+
207  void setRumbleOn(RumbleEnum mode);
+
215  void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
+
216 
+
221  void setLedRaw(uint8_t value);
+
222 
224  void setLedOff() {
225  setLedRaw(0);
226  }
-
231  void setLedOff(LED a);
-
236  void setLedOn(LED a);
-
241  void setLedToggle(LED a);
+
231  void setLedOff(LEDEnum a);
+
236  void setLedOn(LEDEnum a);
+
241  void setLedToggle(LEDEnum a);
242 
247  void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
-
252  void moveSetBulb(Colors color);
+
252  void moveSetBulb(ColorsEnum color);
257  void moveSetRumble(uint8_t rumble);
258 
263  void attachOnInit(void (*funcOnInit)(void)) {
@@ -227,68 +228,68 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
310  void Move_Command(uint8_t *data, uint16_t nbytes);
311 };
312 #endif
-
PS3USB::getSensor
uint16_t getSensor(Sensor a)
Definition: PS3USB.cpp:331
-
PS3USB::getBdaddr
void getBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:471
+
RumbleEnum
RumbleEnum
Definition: PS3Enums.h:211
+
PS3USB::getBdaddr
void getBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:476
PS3USB
Definition: PS3USB.h:58
-
PS3USB::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3USB.cpp:438
+
PS3USB::setLedRaw
void setLedRaw(uint8_t value)
Definition: PS3USB.cpp:439
PS3USB::PS3NavigationConnected
bool PS3NavigationConnected
Definition: PS3USB.h:273
PS3USB::setLedOff
void setLedOff()
Definition: PS3USB.h:224
-
Sensor
Sensor
Definition: PS3Enums.h:141
-
PS3USB::setBdaddr
void setBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:458
-
PS3USB::Release
virtual uint8_t Release()
Definition: PS3USB.cpp:258
+
PS3USB::setBdaddr
void setBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:463
+
PS3USB::Release
virtual uint8_t Release()
Definition: PS3USB.cpp:261
+
PS3USB::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: PS3USB.cpp:315
PS3USB::PS3MoveConnected
bool PS3MoveConnected
Definition: PS3USB.h:271
-
PS3USB::getAnalogButton
uint8_t getAnalogButton(Button a)
Definition: PS3USB.cpp:323
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
StatusEnum
StatusEnum
Definition: PS3Enums.h:183
USBDeviceConfig
Definition: UsbCore.h:105
-
PS3USB::getMoveBdaddr
void getMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:536
+
PS3USB::getMoveBdaddr
void getMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:541
Usb.h
-
PS3USB::setRumbleOff
void setRumbleOff()
Definition: PS3USB.cpp:410
-
LED
LED
Definition: controllerEnums.h:27
+
PS3USB::getAnalogButton
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS3USB.cpp:326
+
PS3USB::getSensor
uint16_t getSensor(SensorEnum a)
Definition: PS3USB.cpp:334
+
PS3USB::setRumbleOff
void setRumbleOff()
Definition: PS3USB.cpp:411
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
PS3USB::PS3Connected
bool PS3Connected
Definition: PS3USB.h:265
-
PS3USB::getStatusString
String getStatusString()
Definition: PS3USB.cpp:362
-
PS3USB::getStatus
bool getStatus(Status c)
Definition: PS3USB.cpp:358
-
PS3USB::getButtonClick
bool getButtonClick(Button b)
Definition: PS3USB.cpp:316
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
PS3Enums.h
PS3USB::GetAddress
virtual uint8_t GetAddress()
Definition: PS3USB.h:93
-
PS3USB::setRumbleOn
void setRumbleOn(Rumble mode)
Definition: PS3USB.cpp:419
PS3USB::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: PS3USB.h:263
-
Status
Status
Definition: PS3Enums.h:182
-
Colors
Colors
Definition: PS3Enums.h:115
-
PS3USB::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3USB.cpp:497
-
PS3USB::setLedToggle
void setLedToggle(LED a)
Definition: PS3USB.cpp:453
-
Rumble
Rumble
Definition: PS3Enums.h:210
+
PS3USB::setLedToggle
void setLedToggle(LEDEnum a)
Definition: PS3USB.cpp:458
+
PS3USB::moveSetBulb
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3USB.cpp:502
PS3USB::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: PS3USB.cpp:46
EpInfo
Definition: address.h:32
-
PS3USB::setAllOff
void setAllOff()
Definition: PS3USB.cpp:403
+
PS3USB::printStatusString
void printStatusString()
Definition: PS3USB.cpp:365
+
PS3USB::setAllOff
void setAllOff()
Definition: PS3USB.cpp:404
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
AngleEnum
AngleEnum
Definition: PS3Enums.h:178
PS3_PID
#define PS3_PID
Definition: PS3USB.h:37
-
Angle
Angle
Definition: PS3Enums.h:177
+
SensorEnum
SensorEnum
Definition: PS3Enums.h:142
+
PS3USB::getAnalogHat
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS3USB.cpp:330
PS3USB::pUsb
USB * pUsb
Definition: PS3USB.h:277
-
PS3USB::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3USB.cpp:510
-
PS3USB::Poll
virtual uint8_t Poll()
Definition: PS3USB.cpp:268
+
ColorsEnum
ColorsEnum
Definition: PS3Enums.h:116
+
PS3USB::getAngle
double getAngle(AngleEnum a)
Definition: PS3USB.cpp:338
+
PS3USB::moveSetRumble
void moveSetRumble(uint8_t rumble)
Definition: PS3USB.cpp:515
+
PS3USB::Poll
virtual uint8_t Poll()
Definition: PS3USB.cpp:271
PS3MOVE_PID
#define PS3MOVE_PID
Definition: PS3USB.h:39
PS3_MAX_ENDPOINTS
#define PS3_MAX_ENDPOINTS
Definition: PS3USB.h:48
PS3USB::epInfo
EpInfo epInfo[PS3_MAX_ENDPOINTS]
Definition: PS3USB.h:281
+
PS3USB::setRumbleOn
void setRumbleOn(RumbleEnum mode)
Definition: PS3USB.cpp:420
PS3USB::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: PS3USB.h:111
-
Button
Button
Definition: controllerEnums.h:44
+
PS3USB::setLedOn
void setLedOn(LEDEnum a)
Definition: PS3USB.cpp:449
PS3NAVIGATION_PID
#define PS3NAVIGATION_PID
Definition: PS3USB.h:38
PS3_VID
#define PS3_VID
Definition: PS3USB.h:36
PS3USB::bAddress
uint8_t bAddress
Definition: PS3USB.h:279
-
PS3USB::setMoveBdaddr
void setMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:520
-
USB
Definition: UsbCore.h:152
-
PS3USB::getAnalogHat
uint8_t getAnalogHat(AnalogHat a)
Definition: PS3USB.cpp:327
-
PS3USB::getAngle
double getAngle(Angle a)
Definition: PS3USB.cpp:335
-
PS3USB::setLedOn
void setLedOn(LED a)
Definition: PS3USB.cpp:448
-
PS3USB::getButtonPress
bool getButtonPress(Button b)
Definition: PS3USB.cpp:312
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
+
PS3USB::setMoveBdaddr
void setMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:525
+
USB
Definition: UsbCore.h:176
PS3USB::PS3USB
PS3USB(USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
Definition: PS3USB.cpp:23
-
PS3USB::getMoveCalibration
void getMoveCalibration(uint8_t *data)
Definition: PS3USB.cpp:546
+
PS3USB::getMoveCalibration
void getMoveCalibration(uint8_t *data)
Definition: PS3USB.cpp:551
+
PS3USB::getStatus
bool getStatus(StatusEnum c)
Definition: PS3USB.cpp:361
PS3USB::isReady
virtual bool isReady()
Definition: PS3USB.h:101
+
PS3USB::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: PS3USB.cpp:319
diff --git a/_p_s4_b_t_8cpp.html b/_p_s4_b_t_8cpp.html new file mode 100644 index 00000000..002a6918 --- /dev/null +++ b/_p_s4_b_t_8cpp.html @@ -0,0 +1,184 @@ + + + + + + +USB Host Shield 2.0: PS4BT.cpp File Reference + + + + + + + + + + +
+
+ + + + + + +
+
USB Host Shield 2.0 +
+
+
+ + + + + + +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
+ + +
+ +
+ + +
+
+
+Variables
+
+
PS4BT.cpp File Reference
+
+
+
#include "PS4BT.h"
+
+Include dependency graph for PS4BT.cpp:
+
+
+ + +
+
+

Go to the source code of this file.

+ + + + + + +

+Variables

const uint8_t PS4_BUTTONS []
 
const uint8_t PS4_ANALOG_BUTTONS []
 
+

Variable Documentation

+ +
+
+ + + + +
const uint8_t PS4_BUTTONS[]
+
+Initial value:
= {
+ + + + +
+
0x0C,
+
0x0D,
+
0x0E,
+
0x0F,
+
+
0x0A,
+
0x0B,
+
0x08,
+
0x09,
+
+
0x07,
+
0x06,
+
0x05,
+
0x04,
+
+
0x10,
+
0x11,
+
}
+ + + +
Definition: PS4BT.h:25
+

Buttons on the controller

+ +

Definition at line 24 of file PS4BT.cpp.

+ +
+
+ +
+
+ + + + +
const uint8_t PS4_ANALOG_BUTTONS[]
+
+Initial value:
= {
+
0, 0, 0, 0, 0, 0, 0, 0,
+
0,
+
1,
+
}
+

Analog buttons on the controller

+ +

Definition at line 50 of file PS4BT.cpp.

+ +
+
+
+ + + + diff --git a/_p_s4_b_t_8cpp__incl.map b/_p_s4_b_t_8cpp__incl.map new file mode 100644 index 00000000..1b48006a --- /dev/null +++ b/_p_s4_b_t_8cpp__incl.map @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/_p_s4_b_t_8cpp__incl.md5 b/_p_s4_b_t_8cpp__incl.md5 new file mode 100644 index 00000000..3e7dd121 --- /dev/null +++ b/_p_s4_b_t_8cpp__incl.md5 @@ -0,0 +1 @@ +de3836781e278adb9d496ef43b7194ea \ No newline at end of file diff --git a/_p_s4_b_t_8cpp__incl.png b/_p_s4_b_t_8cpp__incl.png new file mode 100644 index 00000000..122dfb82 Binary files /dev/null and b/_p_s4_b_t_8cpp__incl.png differ diff --git a/_p_s4_b_t_8cpp_source.html b/_p_s4_b_t_8cpp_source.html new file mode 100644 index 00000000..3df04ff2 --- /dev/null +++ b/_p_s4_b_t_8cpp_source.html @@ -0,0 +1,240 @@ + + + + + + +USB Host Shield 2.0: PS4BT.cpp Source File + + + + + + + + + + +
+
+ + + + + + +
+
USB Host Shield 2.0 +
+
+
+ + + + + + +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
+ + +
+ +
+ + +
+
+
+
PS4BT.cpp
+
+
+Go to the documentation of this file.
1 /* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. All rights reserved.
+
2 
+
3  This software may be distributed and modified under the terms of the GNU
+
4  General Public License version 2 (GPL2) as published by the Free Software
+
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
+
6  this file. Please note that GPL2 Section 2[b] requires that all works based
+
7  on this software must also be made publicly available under the terms of
+
8  the GPL2 ("Copyleft").
+
9 
+
10  Contact information
+
11  -------------------
+
12 
+
13  Kristian Lauszus, TKJ Electronics
+
14  Web : http://www.tkjelectronics.com
+
15  e-mail : kristianl@tkjelectronics.com
+
16  */
+
17 
+
18 #include "PS4BT.h"
+
19 
+
20 // To enable serial debugging see "settings.h"
+
21 //#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller
+
22 
+
24 const uint8_t PS4_BUTTONS[] PROGMEM = {
+
25  DPAD_UP, // UP
+
26  DPAD_RIGHT, // RIGHT
+
27  DPAD_DOWN, // DOWN
+
28  DPAD_LEFT, // LEFT
+
29 
+
30  0x0C, // SHARE
+
31  0x0D, // OPTIONS
+
32  0x0E, // L3
+
33  0x0F, // R3
+
34 
+
35  0x0A, // L2
+
36  0x0B, // R2
+
37  0x08, // L1
+
38  0x09, // R1
+
39 
+
40  0x07, // TRIANGLE
+
41  0x06, // CIRCLE
+
42  0x05, // CROSS
+
43  0x04, // SQUARE
+
44 
+
45  0x10, // PS
+
46  0x11, // KEYPAD
+
47 };
+
48 
+
50 const uint8_t PS4_ANALOG_BUTTONS[] PROGMEM = {
+
51  0, 0, 0, 0, 0, 0, 0, 0, // Skip UP_ANALOG, RIGHT_ANALOG, DOWN_ANALOG, LEFT_ANALOG, SELECT, L3, R3 and START
+
52  0, // L2_ANALOG
+
53  1, // R2_ANALOG
+
54 };
+
55 
+
56 bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) {
+
57  return ps4Buttons.dpad == b;
+
58 }
+
59 
+ +
61  uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
+
62  if (b < 4) // Dpad
+
63  return checkDpad(ps4Data.btn, (DPADEnum)button);
+
64  else {
+
65  uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
+
66  uint8_t mask = (1 << (button - 8 * index));
+
67  return ps4Data.btn.val[index] & mask;
+
68  }
+
69 }
+
70 
+ +
72  uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
+
73  if (b < 4) { // Dpad
+
74  if (checkDpad(buttonClickState, (DPADEnum)button)) {
+
75  buttonClickState.dpad = DPAD_OFF;
+
76  return true;
+
77  }
+
78  return false;
+
79  } else {
+
80  uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
+
81  uint8_t mask = (1 << (button - 8 * index));
+
82 
+
83  bool click = buttonClickState.val[index] & mask;
+
84  buttonClickState.val[index] &= ~mask; // Clear "click" event
+
85  return click;
+
86  }
+
87 }
+
88 
+ +
90  return (uint8_t)(ps4Data.trigger[pgm_read_byte(&PS4_ANALOG_BUTTONS[(uint8_t)a])]);
+
91 }
+
92 
+ +
94  return ps4Data.hatValue[(uint8_t)a];
+
95 }
+
96 
+
97 void PS4BT::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
+
98  if (len == sizeof(PS4Data) && buf) {
+
99  memcpy(&ps4Data, buf, len);
+
100 
+
101  for (uint8_t i = 0; i < sizeof(ps4Data.btn); i++) {
+
102  if (ps4Data.btn.val[i] != oldButtonState.val[i]) {
+
103  buttonClickState.val[i] = ps4Data.btn.val[i] & ~oldButtonState.val[i]; // Update click state variable
+
104  oldButtonState.val[i] = ps4Data.btn.val[i];
+
105  if (i == 0)
+
106  buttonClickState.dpad = ps4Data.btn.dpad; // The DPAD buttons does not set the different bits, but set a value corresponding to the buttons pressed
+
107  }
+
108  }
+
109 #ifdef PRINTREPORT
+
110  for (uint8_t i = 0; i < len; i++) {
+
111  D_PrintHex<uint8_t > (buf[i], 0x80);
+
112  Notify(PSTR(" "), 0x80);
+
113  }
+
114  Notify(PSTR("\r\n"), 0x80);
+
115 #endif
+
116  }
+
117 }
+
Definition: PS4BT.h:33
+
uint8_t hatValue[4]
Definition: PS4BT.h:61
+
Definition: PS4BT.h:60
+
const uint8_t PS4_ANALOG_BUTTONS[]
Definition: PS4BT.cpp:50
+
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: PS4BT.cpp:97
+
AnalogHatEnum
+ +
#define Notify(...)
Definition: message.h:44
+
const uint8_t PS4_BUTTONS[]
Definition: PS4BT.cpp:24
+
bool getButtonPress(ButtonEnum b)
Definition: PS4BT.cpp:60
+
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS4BT.cpp:93
+
uint8_t val[3]
Definition: PS4BT.h:57
+
uint8_t trigger[2]
Definition: PS4BT.h:63
+
ButtonEnum
+
Definition: hid.h:143
+ + +
uint8_t dpad
Definition: PS4BT.h:38
+ +
Definition: PS4BT.h:25
+
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS4BT.cpp:89
+ +
PS4Buttons btn
Definition: PS4BT.h:62
+
bool getButtonClick(ButtonEnum b)
Definition: PS4BT.cpp:71
+
DPADEnum
Definition: PS4BT.h:24
+
+ + + + diff --git a/_p_s4_b_t_8h.html b/_p_s4_b_t_8h.html new file mode 100644 index 00000000..d016c2e8 --- /dev/null +++ b/_p_s4_b_t_8h.html @@ -0,0 +1,184 @@ + + + + + + +USB Host Shield 2.0: PS4BT.h File Reference + + + + + + + + + + +
+
+ + + + + + +
+
USB Host Shield 2.0 +
+
+
+ + + + + + +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
+ + +
+ +
+ + +
+
+
+Classes | +Enumerations
+
+
PS4BT.h File Reference
+
+
+
#include "BTHID.h"
+#include "PS3Enums.h"
+
+Include dependency graph for PS4BT.h:
+
+
+ + +
+
+This graph shows which files directly or indirectly include this file:
+
+
+ + +
+
+

Go to the source code of this file.

+ + + + + + + + +

+Classes

union  PS4Buttons
 
struct  PS4Data
 
class  PS4BT
 
+ + + +

+Enumerations

enum  DPADEnum {
+  DPAD_UP = 0x0, +DPAD_UP_RIGHT = 0x1, +DPAD_RIGHT = 0x2, +DPAD_RIGHT_DOWN = 0x3, +
+  DPAD_DOWN = 0x4, +DPAD_DOWN_LEFT = 0x5, +DPAD_LEFT = 0x6, +DPAD_LEFT_UP = 0x7, +
+  DPAD_OFF = 0x8 +
+ }
 
+

Enumeration Type Documentation

+ +
+
+ + + + +
enum DPADEnum
+
+ + + + + + + + + + +
Enumerator
DPAD_UP  +
DPAD_UP_RIGHT  +
DPAD_RIGHT  +
DPAD_RIGHT_DOWN  +
DPAD_DOWN  +
DPAD_DOWN_LEFT  +
DPAD_LEFT  +
DPAD_LEFT_UP  +
DPAD_OFF  +
+ +

Definition at line 24 of file PS4BT.h.

+ +
+
+
+ + + + diff --git a/_p_s4_b_t_8h__dep__incl.map b/_p_s4_b_t_8h__dep__incl.map new file mode 100644 index 00000000..e8501bf1 --- /dev/null +++ b/_p_s4_b_t_8h__dep__incl.map @@ -0,0 +1,3 @@ + + + diff --git a/_p_s4_b_t_8h__dep__incl.md5 b/_p_s4_b_t_8h__dep__incl.md5 new file mode 100644 index 00000000..fb600911 --- /dev/null +++ b/_p_s4_b_t_8h__dep__incl.md5 @@ -0,0 +1 @@ +82347198cb38622e6ed67d96408c604d \ No newline at end of file diff --git a/_p_s4_b_t_8h__dep__incl.png b/_p_s4_b_t_8h__dep__incl.png new file mode 100644 index 00000000..9385c53b Binary files /dev/null and b/_p_s4_b_t_8h__dep__incl.png differ diff --git a/_p_s4_b_t_8h__incl.map b/_p_s4_b_t_8h__incl.map new file mode 100644 index 00000000..a70d190d --- /dev/null +++ b/_p_s4_b_t_8h__incl.map @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/_p_s4_b_t_8h__incl.md5 b/_p_s4_b_t_8h__incl.md5 new file mode 100644 index 00000000..27191060 --- /dev/null +++ b/_p_s4_b_t_8h__incl.md5 @@ -0,0 +1 @@ +99e5f1ed9603881ee572c3d90866b742 \ No newline at end of file diff --git a/_p_s4_b_t_8h__incl.png b/_p_s4_b_t_8h__incl.png new file mode 100644 index 00000000..4a655fcc Binary files /dev/null and b/_p_s4_b_t_8h__incl.png differ diff --git a/_p_s4_b_t_8h_source.html b/_p_s4_b_t_8h_source.html new file mode 100644 index 00000000..004d1971 --- /dev/null +++ b/_p_s4_b_t_8h_source.html @@ -0,0 +1,287 @@ + + + + + + +USB Host Shield 2.0: PS4BT.h Source File + + + + + + + + + + +
+
+ + + + + + +
+
USB Host Shield 2.0 +
+
+
+ + + + + + +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
+ + +
+ +
+ + +
+
+
+
PS4BT.h
+
+
+Go to the documentation of this file.
1 /* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. All rights reserved.
+
2 
+
3  This software may be distributed and modified under the terms of the GNU
+
4  General Public License version 2 (GPL2) as published by the Free Software
+
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
+
6  this file. Please note that GPL2 Section 2[b] requires that all works based
+
7  on this software must also be made publicly available under the terms of
+
8  the GPL2 ("Copyleft").
+
9 
+
10  Contact information
+
11  -------------------
+
12 
+
13  Kristian Lauszus, TKJ Electronics
+
14  Web : http://www.tkjelectronics.com
+
15  e-mail : kristianl@tkjelectronics.com
+
16  */
+
17 
+
18 #ifndef _ps4bt_h_
+
19 #define _ps4bt_h_
+
20 
+
21 #include "BTHID.h"
+
22 #include "PS3Enums.h"
+
23 
+
24 enum DPADEnum {
+
25  DPAD_UP = 0x0,
+ +
27  DPAD_RIGHT = 0x2,
+ +
29  DPAD_DOWN = 0x4,
+ +
31  DPAD_LEFT = 0x6,
+
32  DPAD_LEFT_UP = 0x7,
+
33  DPAD_OFF = 0x8,
+
34 };
+
35 
+
36 union PS4Buttons {
+
37  struct {
+
38  uint8_t dpad : 4;
+
39  uint8_t square : 1;
+
40  uint8_t cross : 1;
+
41  uint8_t circle : 1;
+
42  uint8_t triangle : 1;
+
43 
+
44  uint8_t l1 : 1;
+
45  uint8_t r1 : 1;
+
46  uint8_t l2 : 1;
+
47  uint8_t r2 : 1;
+
48  uint8_t share : 1;
+
49  uint8_t options : 1;
+
50  uint8_t l3 : 1;
+
51  uint8_t r3 : 1;
+
52 
+
53  uint8_t ps : 1;
+
54  uint8_t keypad : 1;
+
55  uint8_t dummy : 6;
+
56  };
+
57  uint8_t val[3];
+
58 };
+
59 
+
60 struct PS4Data {
+
61  uint8_t hatValue[4];
+ +
63  uint8_t trigger[2];
+
64 };
+
65 
+
67 class PS4BT : public HIDReportParser {
+
68 public:
+
73  PS4BT(BTHID *p) :
+
74  pBthid(p) {
+
75  pBthid->SetReportParser(KEYBOARD_PARSER_ID, this);
+
76  Reset();
+
77  };
+
78 
+
79  virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
+
80 
+
92  bool getButtonPress(ButtonEnum b);
+
93  bool getButtonClick(ButtonEnum b);
+
104  uint8_t getAnalogButton(ButtonEnum a);
+
105 
+
111  uint8_t getAnalogHat(AnalogHatEnum a);
+
115  bool connected() {
+
116  if (pBthid)
+
117  return pBthid->connected;
+
118  return false;
+
119  };
+
120 
+
122  void disconnect() {
+
123  if (pBthid)
+
124  pBthid->disconnect();
+
125  };
+
126 
+
128  void pair(void) {
+
129  if (pBthid)
+
130  pBthid->pair();
+
131  };
+
132 
+
133  void Reset() {
+
134  uint8_t i;
+
135  for (0; i < sizeof(ps4Data.hatValue); i++)
+
136  ps4Data.hatValue[i] = 127;
+
137  for (0; i < sizeof(PS4Buttons); i++) {
+
138  ps4Data.btn.val[i] = 0;
+
139  oldButtonState.val[i] = 0;
+
140  }
+
141  for (0; i < sizeof(ps4Data.trigger); i++)
+
142  ps4Data.trigger[i] = 0;
+
143 
+
144  ps4Data.btn.dpad = DPAD_OFF;
+
145  oldButtonState.dpad = DPAD_OFF;
+
146  buttonClickState.dpad = DPAD_OFF;
+
147  };
+
148 
+
153  void attachOnInit(void (*funcOnInit)(void)) {
+
154  pFuncOnInit = funcOnInit;
+
155  };
+
156 
+
157 private:
+
163  void onInit() {
+
164  Reset();
+
165  if(pFuncOnInit)
+
166  pFuncOnInit(); // Call the user function
+
167  };
+
168  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
169 
+
170  bool checkDpad(PS4Buttons ps4Buttons, DPADEnum b); // Used to check PS4 DPAD buttons
+
171 
+
172  BTHID *pBthid; // Pointer to BTHID instance
+
173  PS4Data ps4Data;
+
174  PS4Buttons oldButtonState, buttonClickState;
+
175 };
+
176 #endif
+
Definition: PS4BT.h:33
+
uint8_t hatValue[4]
Definition: PS4BT.h:61
+
Definition: PS4BT.h:60
+
uint8_t r1
Definition: PS4BT.h:45
+
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: PS4BT.cpp:97
+
bool connected()
Definition: PS4BT.h:115
+
AnalogHatEnum
+
bool connected
Definition: BTHID.h:93
+
uint8_t share
Definition: PS4BT.h:48
+
void attachOnInit(void(*funcOnInit)(void))
Definition: PS4BT.h:153
+ + +
uint8_t cross
Definition: PS4BT.h:40
+
uint8_t l2
Definition: PS4BT.h:46
+ +
uint8_t square
Definition: PS4BT.h:39
+
bool getButtonPress(ButtonEnum b)
Definition: PS4BT.cpp:60
+
uint8_t ps
Definition: PS4BT.h:53
+
uint8_t getAnalogHat(AnalogHatEnum a)
Definition: PS4BT.cpp:93
+
uint8_t val[3]
Definition: PS4BT.h:57
+
uint8_t trigger[2]
Definition: PS4BT.h:63
+ + +
virtual void disconnect()
Definition: BTHID.cpp:51
+
ButtonEnum
+
Definition: hid.h:143
+
void pair(void)
Definition: PS4BT.h:128
+
uint8_t l1
Definition: PS4BT.h:44
+ + +
uint8_t r3
Definition: PS4BT.h:51
+ +
uint8_t dpad
Definition: PS4BT.h:38
+
uint8_t keypad
Definition: PS4BT.h:54
+ +
Definition: PS4BT.h:25
+
uint8_t dummy
Definition: PS4BT.h:55
+
void disconnect()
Definition: PS4BT.h:122
+
uint8_t getAnalogButton(ButtonEnum a)
Definition: PS4BT.cpp:89
+
uint8_t triangle
Definition: PS4BT.h:42
+
uint8_t r2
Definition: PS4BT.h:47
+
uint8_t options
Definition: PS4BT.h:49
+
void Reset()
Definition: PS4BT.h:133
+
#define KEYBOARD_PARSER_ID
Definition: BTHID.h:24
+ + +
PS4BT(BTHID *p)
Definition: PS4BT.h:73
+
uint8_t l3
Definition: PS4BT.h:50
+
PS4Buttons btn
Definition: PS4BT.h:62
+
bool getButtonClick(ButtonEnum b)
Definition: PS4BT.cpp:71
+
Definition: BTHID.h:29
+
DPADEnum
Definition: PS4BT.h:24
+
uint8_t circle
Definition: PS4BT.h:41
+
void pair(void)
Definition: BTHID.h:96
+
Definition: PS4BT.h:67
+
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:71
+
+ + + + diff --git a/_r_e_a_d_m_e_8md.html b/_r_e_a_d_m_e_8md.html index 021b6e1b..5ecda0dd 100644 --- a/_r_e_a_d_m_e_8md.html +++ b/_r_e_a_d_m_e_8md.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: README.md File Reference @@ -31,7 +31,7 @@ - + @@ -92,7 +92,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/_r_e_a_d_m_e_8md_source.html b/_r_e_a_d_m_e_8md_source.html index 8e5e825d..4adf8087 100644 --- a/_r_e_a_d_m_e_8md_source.html +++ b/_r_e_a_d_m_e_8md_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: README.md Source File @@ -31,7 +31,7 @@ - + @@ -154,160 +154,168 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
67 
68 * All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.)
69 * Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, and Teensy 3.0)
-
70 * Balanduino
-
71 * Sanguino
-
72 * Black Widdow
-
73 
-
74 The following boards need to be activated manually in [settings.h](settings.h):
-
75 
-
76 * Arduino Mega ADK
-
77  * If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega ADK manually
-
78 * Black Widdow
-
79 
-
80 Simply set the corresponding value to 1 instead of 0.
-
81 
-
82 ### [Bluetooth libraries](BTD.cpp)
-
83 
-
84 The [BTD library](BTD.cpp) is a general purpose library for an ordinary Bluetooth dongle.
-
85 This library make it easy to add support for different Bluetooth services like a PS3 or a Wii controller or SPP which is a virtual serial port via Bluetooth.
-
86 Some different examples can be found in the [example directory](examples/Bluetooth).
-
87 
-
88 The BTD library will also make it possible to use multiple services at once, the following example sketch is an example of this:
-
89 <https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3SPP/PS3SPP.ino>.
-
90 
-
91 ### [BTHID library](BTHID.cpp)
-
92 
-
93 The [Bluetooth HID library](BTHID.cpp) allows you to connect HID devices via Bluetooth to the USB Host Shield.
-
94 
-
95 Currently HID mice and keyboards are supported.
-
96 
-
97 It uses the standard Boot protocol by default, but it is also able to use the Report protocol as well. You would simply have to call ```setProtocolMode()``` and then parse ```HID_RPT_PROTOCOL``` as an argument. You will then have to modify the parser for your device. See the example: <https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/BTHID/BTHID.ino> for more information.
-
98 
-
99 ### [SPP library](SPP.cpp)
-
100 
-
101 SPP stands for "Serial Port Profile" and is a Bluetooth protocol that implements a virtual comport which allows you to send data back and forth from your computer/phone to your Arduino via Bluetooth.
-
102 It has been tested successfully on Windows, Mac OS X, Linux, and Android.
-
103 
-
104 More information can be found at these blog posts:
-
105 
-
106 * <http://www.circuitsathome.com/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released>
-
107 * <http://blog.tkjelectronics.dk/2012/07/rfcommspp-library-for-arduino/>
+
70  * Note if you are using the Teensy 3.0 you should download this SPI library as well: <https://github.com/xxxajk/spi4teensy3>. You should then add ```#include <spi4teensy3.h>``` to your .ino file.
+
71 * Balanduino
+
72 * Sanguino
+
73 * Black Widdow
+
74 
+
75 The following boards need to be activated manually in [settings.h](settings.h):
+
76 
+
77 * Arduino Mega ADK
+
78  * If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega ADK manually
+
79 * Black Widdow
+
80 
+
81 Simply set the corresponding value to 1 instead of 0.
+
82 
+
83 ### [Bluetooth libraries](BTD.cpp)
+
84 
+
85 The [BTD library](BTD.cpp) is a general purpose library for an ordinary Bluetooth dongle.
+
86 This library make it easy to add support for different Bluetooth services like a PS3 or a Wii controller or SPP which is a virtual serial port via Bluetooth.
+
87 Some different examples can be found in the [example directory](examples/Bluetooth).
+
88 
+
89 The BTD library also makes it possible to use multiple services at once, the following example sketch is an example of this:
+
90 [PS3SPP.ino](examples/Bluetooth/PS3SPP/PS3SPP.ino).
+
91 
+
92 ### [BTHID library](BTHID.cpp)
+
93 
+
94 The [Bluetooth HID library](BTHID.cpp) allows you to connect HID devices via Bluetooth to the USB Host Shield.
+
95 
+
96 Currently HID mice and keyboards are supported.
+
97 
+
98 It uses the standard Boot protocol by default, but it is also able to use the Report protocol as well. You would simply have to call ```setProtocolMode()``` and then parse ```HID_RPT_PROTOCOL``` as an argument. You will then have to modify the parser for your device. See the example: [BTHID.ino](examples/Bluetooth/BTHID/BTHID.ino) for more information.
+
99 
+
100 ### [SPP library](SPP.cpp)
+
101 
+
102 SPP stands for "Serial Port Profile" and is a Bluetooth protocol that implements a virtual comport which allows you to send data back and forth from your computer/phone to your Arduino via Bluetooth.
+
103 It has been tested successfully on Windows, Mac OS X, Linux, and Android.
+
104 
+
105 Take a look at the [SPP.ino](examples/Bluetooth/SPP/SPP.ino) example for more information.
+
106 
+
107 More information can be found at these blog posts:
108 
-
109 To implement the SPP protocol I used a Bluetooth sniffing tool called [PacketLogger](http://www.tkjelectronics.com/uploads/PacketLogger.zip) developed by Apple.
-
110 It enables me to see the Bluetooth communication between my Mac and any device.
+
109 * <http://www.circuitsathome.com/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released>
+
110 * <http://blog.tkjelectronics.dk/2012/07/rfcommspp-library-for-arduino/>
111 
-
112 ### PS3 Library
-
113 
-
114 These libraries consist of the [PS3BT](PS3BT.cpp) and [PS3USB](PS3USB.cpp). These libraries allows you to use a Dualshock 3, Navigation or a Motion controller with the USB Host Shield both via Bluetooth and USB.
-
115 
-
116 In order to use your Playstation controller via Bluetooth you have to set the Bluetooth address of the dongle internally to your PS3 Controller. This can be achieved by plugging the controller in via USB and letting the library set it automatically.
-
117 
-
118 __Note:__ To obtain the address you have to plug in the Bluetooth dongle before connecting the controller, or alternatively you could set it in code like so: <https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino#L15>.
-
119 
-
120 For more information about the PS3 protocol see the official wiki: <https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information>.
-
121 
-
122 Also take a look at the blog posts:
-
123 
-
124 * <http://blog.tkjelectronics.dk/2012/01/ps3-controller-bt-library-for-arduino/>
-
125 * <http://www.circuitsathome.com/mcu/sony-ps3-controller-support-added-to-usb-host-library>
-
126 * <http://www.circuitsathome.com/mcu/arduino/interfacing-ps3-controllers-via-usb>
-
127 
-
128 A special thanks go to the following people:
-
129 
-
130 1. _Richard Ibbotson_ who made this excellent guide: <http://www.circuitsathome.com/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part>
-
131 2. _Tomoyuki Tanaka_ for releasing his code for the Arduino USB Host shield connected to the wiimote: <http://www.circuitsathome.com/mcu/rc-car-controlled-by-wii-remote-on-arduino>
+
112 To implement the SPP protocol I used a Bluetooth sniffing tool called [PacketLogger](http://www.tkjelectronics.com/uploads/PacketLogger.zip) developed by Apple.
+
113 It enables me to see the Bluetooth communication between my Mac and any device.
+
114 
+
115 ### PS3 Library
+
116 
+
117 These libraries consist of the [PS3BT](PS3BT.cpp) and [PS3USB](PS3USB.cpp). These libraries allows you to use a Dualshock 3, Navigation or a Motion controller with the USB Host Shield both via Bluetooth and USB.
+
118 
+
119 In order to use your Playstation controller via Bluetooth you have to set the Bluetooth address of the dongle internally to your PS3 Controller. This can be achieved by plugging the controller in via USB and letting the library set it automatically.
+
120 
+
121 __Note:__ To obtain the address you have to plug in the Bluetooth dongle before connecting the controller, or alternatively you could set it in code like so: [PS3BT.ino#L20](examples/Bluetooth/PS3BT/PS3BT.ino#L20).
+
122 
+
123 For more information about the PS3 protocol see the official wiki: <https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information>.
+
124 
+
125 Also take a look at the blog posts:
+
126 
+
127 * <http://blog.tkjelectronics.dk/2012/01/ps3-controller-bt-library-for-arduino/>
+
128 * <http://www.circuitsathome.com/mcu/sony-ps3-controller-support-added-to-usb-host-library>
+
129 * <http://www.circuitsathome.com/mcu/arduino/interfacing-ps3-controllers-via-usb>
+
130 
+
131 A special thanks go to the following people:
132 
-
133 Also a big thanks all the people behind these sites about the Motion controller:
-
134 
-
135 * <http://thp.io/2010/psmove/>
-
136 * <http://www.copenhagengamecollective.org/unimove/>
-
137 * <https://github.com/thp/psmoveapi>
-
138 * <http://code.google.com/p/moveonpc/>
-
139 
-
140 ### Xbox Libraries
-
141 
-
142 The library supports both the original Xbox controller via USB and the Xbox 360 controller both via USB and wirelessly.
-
143 
-
144 #### Xbox library
-
145 
-
146 The [XBOXOLD](XBOXOLD.cpp) class implements support for the original Xbox controller via USB.
-
147 
-
148 All the information are from the following sites:
-
149 
-
150 * <https://github.com/torvalds/linux/blob/master/Documentation/input/xpad.txt>
-
151 * <https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c>
-
152 * <http://euc.jp/periphs/xbox-controller.ja.html>
-
153 * <https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L15>
-
154 
-
155 #### Xbox 360 Library
-
156 
-
157 The library support one Xbox 360 via USB or up to four Xbox 360 controllers wirelessly by using a [Xbox 360 wireless receiver](http://blog.tkjelectronics.dk/wp-content/uploads/xbox360-wireless-receiver.jpg).
-
158 
-
159 To use it via USB use the [XBOXUSB](XBOXUSB.cpp) library or to use it wirelessly use the [XBOXRECV](XBOXRECV.cpp) library.
-
160 
-
161 __Note that a Wireless controller can NOT be used via USB!__
-
162 
-
163 Examples code can be found in the [examples directory](examples/Xbox).
-
164 
-
165 Also see the following blog posts:
-
166 
-
167 * <http://www.circuitsathome.com/mcu/xbox360-controller-support-added-to-usb-host-shield-2-0-library>
-
168 * <http://blog.tkjelectronics.dk/2012/07/xbox-360-controller-support-added-to-the-usb-host-library/>
-
169 * <http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/>
-
170 
-
171 All the information regarding the Xbox 360 controller protocol are form these sites:
-
172 
-
173 * <http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo>
-
174 * <http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo>
-
175 * <https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL>
-
176 
-
177 ### [Wii library](Wii.cpp)
-
178 
-
179 The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller is also supported via Bluetooth.
-
180 
-
181 First you have to pair with the controller, this is done automatically by the library if you create the instance like so:
-
182 
-
183 ```
-
184 WII Wii(&Btd,PAIR);
-
185 ```
-
186 
-
187 And then press 1 & 2 at once on the Wiimote or press sync if you are using a Wii U Pro Controller.
-
188 
-
189 After that you can simply create the instance like so:
-
190 
-
191 ```
-
192 WII Wii(&Btd);
-
193 ```
-
194 
-
195 Then just press any button on the Wiimote and it will then connect to the dongle.
-
196 
-
197 Take a look at the example for more information: <https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/Wii/Wii.ino>.
-
198 
-
199 Also take a look at the blog post:
-
200 
-
201 * <http://blog.tkjelectronics.dk/2012/08/wiimote-added-to-usb-host-library/>
-
202 
-
203 All the information about the Wii controllers are from these sites:
-
204 
-
205 * <http://wiibrew.org/wiki/Wiimote>
-
206 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers>
-
207 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck>
-
208 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus>
-
209 * The old library created by _Tomoyuki Tanaka_: <https://github.com/moyuchin/WiiRemote_on_Arduino> also helped a lot.
+
133 1. _Richard Ibbotson_ who made this excellent guide: <http://www.circuitsathome.com/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part>
+
134 2. _Tomoyuki Tanaka_ for releasing his code for the Arduino USB Host shield connected to the wiimote: <http://www.circuitsathome.com/mcu/rc-car-controlled-by-wii-remote-on-arduino>
+
135 
+
136 Also a big thanks all the people behind these sites about the Motion controller:
+
137 
+
138 * <http://thp.io/2010/psmove/>
+
139 * <http://www.copenhagengamecollective.org/unimove/>
+
140 * <https://github.com/thp/psmoveapi>
+
141 * <http://code.google.com/p/moveonpc/>
+
142 
+
143 ### Xbox Libraries
+
144 
+
145 The library supports both the original Xbox controller via USB and the Xbox 360 controller both via USB and wirelessly.
+
146 
+
147 #### Xbox library
+
148 
+
149 The [XBOXOLD](XBOXOLD.cpp) class implements support for the original Xbox controller via USB.
+
150 
+
151 All the information are from the following sites:
+
152 
+
153 * <https://github.com/torvalds/linux/blob/master/Documentation/input/xpad.txt>
+
154 * <https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c>
+
155 * <http://euc.jp/periphs/xbox-controller.ja.html>
+
156 * <https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L15>
+
157 
+
158 #### Xbox 360 Library
+
159 
+
160 The library support one Xbox 360 via USB or up to four Xbox 360 controllers wirelessly by using a [Xbox 360 wireless receiver](http://blog.tkjelectronics.dk/wp-content/uploads/xbox360-wireless-receiver.jpg).
+
161 
+
162 To use it via USB use the [XBOXUSB](XBOXUSB.cpp) library or to use it wirelessly use the [XBOXRECV](XBOXRECV.cpp) library.
+
163 
+
164 __Note that a Wireless controller can NOT be used via USB!__
+
165 
+
166 Examples code can be found in the [examples directory](examples/Xbox).
+
167 
+
168 Also see the following blog posts:
+
169 
+
170 * <http://www.circuitsathome.com/mcu/xbox360-controller-support-added-to-usb-host-shield-2-0-library>
+
171 * <http://blog.tkjelectronics.dk/2012/07/xbox-360-controller-support-added-to-the-usb-host-library/>
+
172 * <http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/>
+
173 
+
174 All the information regarding the Xbox 360 controller protocol are form these sites:
+
175 
+
176 * <http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo>
+
177 * <http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo>
+
178 * <https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL>
+
179 
+
180 ### [Wii library](Wii.cpp)
+
181 
+
182 The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller is also supported via Bluetooth.
+
183 
+
184 First you have to pair with the controller, this is done automatically by the library if you create the instance like so:
+
185 
+
186 ```
+
187 WII Wii(&Btd,PAIR);
+
188 ```
+
189 
+
190 And then press 1 & 2 at once on the Wiimote or press sync if you are using a Wii U Pro Controller.
+
191 
+
192 After that you can simply create the instance like so:
+
193 
+
194 ```
+
195 WII Wii(&Btd);
+
196 ```
+
197 
+
198 Then just press any button on the Wiimote and it will then connect to the dongle.
+
199 
+
200 Take a look at the example for more information: [Wii.ino](examples/Bluetooth/Wii/Wii.ino).
+
201 
+
202 Also take a look at the blog post:
+
203 
+
204 * <http://blog.tkjelectronics.dk/2012/08/wiimote-added-to-usb-host-library/>
+
205 
+
206 The Wii IR camera can also be used, but you will have to activate the code for it manually as it is quite large. Simply set ```ENABLE_WII_IR_CAMERA``` to 1 in [settings.h](settings.h).
+
207 
+
208 The [WiiIRCamera.ino](examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino) example shows how it can be used.
+
209 
210 
-
211 # FAQ
+
211 All the information about the Wii controllers are from these sites:
212 
-
213 > When I plug my device into the USB connector nothing happens?
-
214 
-
215 Try to connect a external power supply to the Arduino - this solves the problem in most cases.
+
213 * <http://wiibrew.org/wiki/Wiimote>
+
214 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers>
+
215 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck>
+
216 * <http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus>
+
217 * The old library created by _Tomoyuki Tanaka_: <https://github.com/moyuchin/WiiRemote_on_Arduino> also helped a lot.
+
218 
+
219 # FAQ
+
220 
+
221 > When I plug my device into the USB connector nothing happens?
+
222 
+
223 Try to connect a external power supply to the Arduino - this solves the problem in most cases.
MAX3421e
Definition: usbhost.h:81
-
USB
Definition: UsbCore.h:152
+
USB
Definition: UsbCore.h:176
diff --git a/_s_p_p_8cpp.html b/_s_p_p_8cpp.html index ff5b9019..b160c1b8 100644 --- a/_s_p_p_8cpp.html +++ b/_s_p_p_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: SPP.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -145,7 +145,7 @@ Variables diff --git a/_s_p_p_8cpp_source.html b/_s_p_p_8cpp_source.html index 2192e640..d0166489 100644 --- a/_s_p_p_8cpp_source.html +++ b/_s_p_p_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: SPP.cpp Source File @@ -31,7 +31,7 @@ - + @@ -133,10 +133,10 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
42  0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF
43 };
44 
-
45 SPP::SPP(BTD *p, const char* name, const char* pin) :
+
45 SPP::SPP(BTD *p, const char* name, const char* pin) :
46 pBtd(p) // Pointer to BTD class instance - mandatory
47 {
-
48  if (pBtd)
+
48  if(pBtd)
49  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
50 
51  pBtd->btdName = name;
@@ -156,862 +156,834 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
65  RFCOMMConnected = false;
66  SDPConnected = false;
67  waitForLastCommand = false;
-
68  l2cap_sdp_state = L2CAP_SDP_WAIT;
-
69  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
+
68  l2cap_sdp_state = L2CAP_SDP_WAIT;
+
69  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
70  l2cap_event_flag = 0;
71  sppIndex = 0;
72 }
73 
74 void SPP::disconnect() {
75  connected = false;
-
76  // First the two L2CAP channels has to be disconencted and then the HCI connection
-
77  if (RFCOMMConnected)
-
78  pBtd->l2cap_disconnection_request(hci_handle, 0x0A, rfcomm_scid, rfcomm_dcid);
-
79  if (RFCOMMConnected && SDPConnected)
+
76  // First the two L2CAP channels has to be disconnected and then the HCI connection
+
77  if(RFCOMMConnected)
+
78  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, rfcomm_scid, rfcomm_dcid);
+
79  if(RFCOMMConnected && SDPConnected)
80  delay(1); // Add delay between commands
-
81  if (SDPConnected)
-
82  pBtd->l2cap_disconnection_request(hci_handle, 0x0B, sdp_scid, sdp_dcid);
-
83  l2cap_sdp_state = L2CAP_DISCONNECT_RESPONSE;
+
81  if(SDPConnected)
+
82  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, sdp_scid, sdp_dcid);
+
83  l2cap_sdp_state = L2CAP_DISCONNECT_RESPONSE;
84 }
85 
86 void SPP::ACLData(uint8_t* l2capinbuf) {
-
87  if (!connected) {
-
88  if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
89  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == SDP_PSM && !pBtd->sdpConnectionClaimed) {
+
87  if(!connected) {
+
88  if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
89  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == SDP_PSM && !pBtd->sdpConnectionClaimed) {
90  pBtd->sdpConnectionClaimed = true;
91  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
92  l2cap_sdp_state = L2CAP_SDP_WAIT; // Reset state
-
93  } else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == RFCOMM_PSM && !pBtd->rfcommConnectionClaimed) {
+
92  l2cap_sdp_state = L2CAP_SDP_WAIT; // Reset state
+
93  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == RFCOMM_PSM && !pBtd->rfcommConnectionClaimed) {
94  pBtd->rfcommConnectionClaimed = true;
95  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
96  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT; // Reset state
+
96  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT; // Reset state
97  }
98  }
99  }
-
100  if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok
-
101  if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
-
102  if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
-
103 #ifdef DEBUG_USB_HOST
-
104  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
-
105  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
106  Notify(PSTR(" "), 0x80);
-
107  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
108  Notify(PSTR(" Data: "), 0x80);
-
109  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
-
110  Notify(PSTR(" "), 0x80);
-
111  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
-
112  Notify(PSTR(" "), 0x80);
-
113  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
114  Notify(PSTR(" "), 0x80);
-
115  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
116 #endif
-
117  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
118 #ifdef EXTRADEBUG
-
119  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
-
120  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
121  Notify(PSTR(" "), 0x80);
-
122  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
123  Notify(PSTR(" SCID: "), 0x80);
-
124  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
125  Notify(PSTR(" "), 0x80);
-
126  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
127  Notify(PSTR(" Identifier: "), 0x80);
-
128  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
129 #endif
-
130  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == SDP_PSM) { // It doesn't matter if it receives another reqeust, since it waits for the channel to disconnect in the L2CAP_SDP_DONE state, and the l2cap_event_flag will be cleared if so
-
131  identifier = l2capinbuf[9];
-
132  sdp_scid[0] = l2capinbuf[14];
-
133  sdp_scid[1] = l2capinbuf[15];
-
134  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_SDP_REQUEST;
-
135  } else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == RFCOMM_PSM) { // ----- || -----
-
136  identifier = l2capinbuf[9];
-
137  rfcomm_scid[0] = l2capinbuf[14];
-
138  rfcomm_scid[1] = l2capinbuf[15];
-
139  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST;
-
140  }
-
141  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
-
142  if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
-
143  if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
-
144  //Notify(PSTR("\r\nSDP Configuration Complete"), 0x80);
-
145  l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_SUCCESS;
-
146  } else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
-
147  //Notify(PSTR("\r\nRFCOMM Configuration Complete"), 0x80);
-
148  l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS;
-
149  }
-
150  }
-
151  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
-
152  if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
-
153  //Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
-
154  identifier = l2capinbuf[9];
-
155  l2cap_event_flag |= L2CAP_FLAG_CONFIG_SDP_REQUEST;
-
156  } else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
+
100  //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok
+
101  if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok
+
102  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
+
103  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
+
104 #ifdef DEBUG_USB_HOST
+
105  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
+
106  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
107  Notify(PSTR(" "), 0x80);
+
108  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
109  Notify(PSTR(" Data: "), 0x80);
+
110  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
+
111  Notify(PSTR(" "), 0x80);
+
112  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
+
113  Notify(PSTR(" "), 0x80);
+
114  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
115  Notify(PSTR(" "), 0x80);
+
116  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
117 #endif
+
118  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
119 #ifdef EXTRADEBUG
+
120  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
+
121  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
122  Notify(PSTR(" "), 0x80);
+
123  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
124  Notify(PSTR(" SCID: "), 0x80);
+
125  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
126  Notify(PSTR(" "), 0x80);
+
127  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
128  Notify(PSTR(" Identifier: "), 0x80);
+
129  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
130 #endif
+
131  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == SDP_PSM) { // It doesn't matter if it receives another reqeust, since it waits for the channel to disconnect in the L2CAP_SDP_DONE state, and the l2cap_event_flag will be cleared if so
+
132  identifier = l2capinbuf[9];
+
133  sdp_scid[0] = l2capinbuf[14];
+
134  sdp_scid[1] = l2capinbuf[15];
+
135  l2cap_set_flag(L2CAP_FLAG_CONNECTION_SDP_REQUEST);
+
136  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == RFCOMM_PSM) { // ----- || -----
+
137  identifier = l2capinbuf[9];
+
138  rfcomm_scid[0] = l2capinbuf[14];
+
139  rfcomm_scid[1] = l2capinbuf[15];
+
140  l2cap_set_flag(L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST);
+
141  }
+
142  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
+
143  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
+
144  if(l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
+
145  //Notify(PSTR("\r\nSDP Configuration Complete"), 0x80);
+
146  l2cap_set_flag(L2CAP_FLAG_CONFIG_SDP_SUCCESS);
+
147  } else if(l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
+
148  //Notify(PSTR("\r\nRFCOMM Configuration Complete"), 0x80);
+
149  l2cap_set_flag(L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS);
+
150  }
+
151  }
+
152  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
+
153  if(l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
+
154  //Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
+
155  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], sdp_scid);
+
156  } else if(l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
157  //Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
-
158  identifier = l2capinbuf[9];
-
159  l2cap_event_flag |= L2CAP_FLAG_CONFIG_RFCOMM_REQUEST;
-
160  }
-
161  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
-
162  if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
-
163  //Notify(PSTR("\r\nDisconnect Request: SDP Channel"), 0x80);
-
164  identifier = l2capinbuf[9];
-
165  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_SDP_REQUEST;
-
166  } else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
-
167  //Notify(PSTR("\r\nDisconnect Request: RFCOMM Channel"), 0x80);
-
168  identifier = l2capinbuf[9];
-
169  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST;
-
170  }
-
171  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
-
172  if (l2capinbuf[12] == sdp_scid[0] && l2capinbuf[13] == sdp_scid[1]) {
-
173  //Notify(PSTR("\r\nDisconnect Response: SDP Channel"), 0x80);
-
174  identifier = l2capinbuf[9];
-
175  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE;
-
176  } else if (l2capinbuf[12] == rfcomm_scid[0] && l2capinbuf[13] == rfcomm_scid[1]) {
-
177  //Notify(PSTR("\r\nDisconnect Response: RFCOMM Channel"), 0x80);
-
178  identifier = l2capinbuf[9];
-
179  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE;
-
180  }
-
181  } else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) {
-
182 #ifdef DEBUG_USB_HOST
-
183  Notify(PSTR("\r\nInformation request"), 0x80);
-
184 #endif
-
185  identifier = l2capinbuf[9];
-
186  pBtd->l2cap_information_response(hci_handle, identifier, l2capinbuf[12], l2capinbuf[13]);
-
187  }
-
188 #ifdef EXTRADEBUG
-
189  else {
-
190  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
-
191  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
192  }
-
193 #endif
-
194  } else if (l2capinbuf[6] == sdp_dcid[0] && l2capinbuf[7] == sdp_dcid[1]) { // SDP
-
195  if (l2capinbuf[8] == SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU) {
-
196  if (((l2capinbuf[16] << 8 | l2capinbuf[17]) == SERIALPORT_UUID) || ((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000 && (l2capinbuf[18] << 8 | l2capinbuf[19]) == SERIALPORT_UUID)) { // Check if it's sending the full UUID, see: https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm, we will just check the first four bytes
-
197  if (firstMessage) {
-
198  serialPortResponse1(l2capinbuf[9], l2capinbuf[10]);
-
199  firstMessage = false;
-
200  } else {
-
201  serialPortResponse2(l2capinbuf[9], l2capinbuf[10]); // Serialport continuation state
-
202  firstMessage = true;
-
203  }
-
204  } else if (((l2capinbuf[16] << 8 | l2capinbuf[17]) == L2CAP_UUID) || ((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000 && (l2capinbuf[18] << 8 | l2capinbuf[19]) == L2CAP_UUID)) {
-
205  if (firstMessage) {
-
206  l2capResponse1(l2capinbuf[9], l2capinbuf[10]);
-
207  firstMessage = false;
-
208  } else {
-
209  l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state
-
210  firstMessage = true;
-
211  }
-
212  } else
-
213  serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported
-
214 #ifdef EXTRADEBUG
-
215  Notify(PSTR("\r\nUUID: "), 0x80);
-
216  uint16_t uuid;
-
217  if((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000) // Check if it's sending the UUID as a 128-bit UUID
-
218  uuid = (l2capinbuf[18] << 8 | l2capinbuf[19]);
-
219  else // Short UUID
-
220  uuid = (l2capinbuf[16] << 8 | l2capinbuf[17]);
-
221  D_PrintHex<uint16_t> (uuid, 0x80);
-
222 
-
223  Notify(PSTR("\r\nLength: "), 0x80);
-
224  uint16_t length = l2capinbuf[11] << 8 | l2capinbuf[12];
-
225  D_PrintHex<uint16_t> (length, 0x80);
-
226  Notify(PSTR("\r\nData: "), 0x80);
-
227  for (uint8_t i = 0; i < length; i++) {
-
228  D_PrintHex<uint8_t> (l2capinbuf[13+i], 0x80);
-
229  Notify(PSTR(" "), 0x80);
-
230  }
-
231 #endif
-
232  }
-
233 #ifdef EXTRADEBUG
-
234  else {
-
235  Notify(PSTR("\r\nUnknown PDU: "), 0x80);
-
236  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
237  }
-
238 #endif
-
239  } else if (l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM
-
240  rfcommChannel = l2capinbuf[8] & 0xF8;
-
241  rfcommDirection = l2capinbuf[8] & 0x04;
-
242  rfcommCommandResponse = l2capinbuf[8] & 0x02;
-
243  rfcommChannelType = l2capinbuf[9] & 0xEF;
-
244  rfcommPfBit = l2capinbuf[9] & 0x10;
-
245 
-
246  if (rfcommChannel >> 3 != 0x00)
-
247  rfcommChannelConnection = rfcommChannel;
-
248 
-
249 #ifdef EXTRADEBUG
-
250  Notify(PSTR("\r\nRFCOMM Channel: "), 0x80);
-
251  D_PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
-
252  Notify(PSTR(" Direction: "), 0x80);
-
253  D_PrintHex<uint8_t > (rfcommDirection >> 2, 0x80);
-
254  Notify(PSTR(" CommandResponse: "), 0x80);
-
255  D_PrintHex<uint8_t > (rfcommCommandResponse >> 1, 0x80);
-
256  Notify(PSTR(" ChannelType: "), 0x80);
-
257  D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
-
258  Notify(PSTR(" PF_BIT: "), 0x80);
-
259  D_PrintHex<uint8_t > (rfcommPfBit, 0x80);
-
260 #endif
-
261  if (rfcommChannelType == RFCOMM_DISC) {
-
262 #ifdef DEBUG_USB_HOST
-
263  Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80);
-
264  D_PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
-
265 #endif
-
266  connected = false;
-
267  sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
-
268  }
-
269  if (connected) {
-
270  /* Read the incoming message */
-
271  if (rfcommChannelType == RFCOMM_UIH && rfcommChannel == rfcommChannelConnection) {
-
272  uint8_t length = l2capinbuf[10] >> 1; // Get length
-
273  uint8_t offset = l2capinbuf[4] - length - 4; // Check if there is credit
-
274  if (checkFcs(&l2capinbuf[8], l2capinbuf[11 + length + offset])) {
-
275  uint8_t i = 0;
-
276  for (; i < length; i++) {
-
277  if (rfcommAvailable + i >= sizeof (rfcommDataBuffer)) {
-
278 #ifdef DEBUG_USB_HOST
-
279  Notify(PSTR("\r\nWarning: Buffer is full!"), 0x80);
-
280 #endif
-
281  break;
-
282  }
-
283  rfcommDataBuffer[rfcommAvailable + i] = l2capinbuf[11 + i + offset];
-
284  }
-
285  rfcommAvailable += i;
-
286 #ifdef EXTRADEBUG
-
287  Notify(PSTR("\r\nRFCOMM Data Available: "), 0x80);
-
288  Notify(rfcommAvailable, 0x80);
-
289  if (offset) {
-
290  Notify(PSTR(" - Credit: 0x"), 0x80);
-
291  D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
-
292  }
-
293 #endif
-
294  }
-
295 #ifdef DEBUG_USB_HOST
-
296  else
-
297  Notify(PSTR("\r\nError in FCS checksum!"), 0x80);
-
298 #endif
-
299 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send to the Arduino via Bluetooth
-
300  for (uint8_t i = 0; i < length; i++)
-
301  Notifyc(l2capinbuf[i + 11 + offset], 0x80);
-
302 #endif
-
303  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
-
304 #ifdef DEBUG_USB_HOST
-
305  Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
-
306 #endif
-
307  rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
-
308  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
-
309  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
-
310  rfcommbuf[3] = l2capinbuf[14]; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
-
311  rfcommbuf[4] = l2capinbuf[15]; // Priority
-
312  rfcommbuf[5] = l2capinbuf[16]; // Timer
-
313  rfcommbuf[6] = l2capinbuf[17]; // Max Fram Size LSB
-
314  rfcommbuf[7] = l2capinbuf[18]; // Max Fram Size MSB
-
315  rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm.
-
316  rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
-
317  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
-
318  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
-
319 #ifdef DEBUG_USB_HOST
-
320  Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
-
321 #endif
-
322  rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
-
323  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
-
324  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
-
325  rfcommbuf[3] = l2capinbuf[14];
-
326  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
-
327  }
-
328  } else {
-
329  if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish
-
330 #ifdef DEBUG_USB_HOST
-
331  Notify(PSTR("\r\nReceived SABM Command"), 0x80);
-
332 #endif
-
333  sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
-
334  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command
-
335 #ifdef DEBUG_USB_HOST
-
336  Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80);
-
337 #endif
-
338  rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response
-
339  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
-
340  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
-
341  rfcommbuf[3] = 0xE0; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
-
342  rfcommbuf[4] = 0x00; // Priority
-
343  rfcommbuf[5] = 0x00; // Timer
-
344  rfcommbuf[6] = BULK_MAXPKTSIZE - 14; // Max Fram Size LSB - set to the size of received data (50)
-
345  rfcommbuf[7] = 0x00; // Max Fram Size MSB
-
346  rfcommbuf[8] = 0x00; // MaxRatransm.
-
347  rfcommbuf[9] = 0x00; // Number of Frames
-
348  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A);
-
349  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
-
350 #ifdef DEBUG_USB_HOST
-
351  Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
-
352 #endif
-
353  rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
-
354  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
-
355  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
-
356  rfcommbuf[3] = l2capinbuf[14];
-
357  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
-
358 
-
359  delay(1);
-
360 #ifdef DEBUG_USB_HOST
-
361  Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80);
-
362 #endif
-
363  rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command
-
364  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
-
365  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
-
366  rfcommbuf[3] = 0x8D; // Can receive frames (YES), Ready to Communicate (YES), Ready to Receive (YES), Incomig Call (NO), Data is Value (YES)
-
367 
-
368  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
-
369  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response
-
370  if (!creditSent) {
-
371 #ifdef DEBUG_USB_HOST
-
372  Notify(PSTR("\r\nSend UIH Command with credit"), 0x80);
-
373 #endif
-
374  sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit
-
375  creditSent = true;
-
376  timer = millis();
-
377  waitForLastCommand = true;
-
378  }
-
379  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit
-
380 #ifdef DEBUG_USB_HOST
-
381  Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80);
-
382 #endif
-
383  } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
-
384 #ifdef DEBUG_USB_HOST
-
385  Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
-
386 #endif
-
387  rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
-
388  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
-
389  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
-
390  rfcommbuf[3] = l2capinbuf[14]; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
-
391  rfcommbuf[4] = l2capinbuf[15]; // Priority
-
392  rfcommbuf[5] = l2capinbuf[16]; // Timer
-
393  rfcommbuf[6] = l2capinbuf[17]; // Max Fram Size LSB
-
394  rfcommbuf[7] = l2capinbuf[18]; // Max Fram Size MSB
-
395  rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm.
-
396  rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
-
397  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
-
398 #ifdef DEBUG_USB_HOST
-
399  Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80);
-
400 #endif
-
401  waitForLastCommand = false;
-
402  creditSent = false;
-
403  connected = true; // The RFCOMM channel is now established
-
404  sppIndex = 0;
-
405  }
-
406 #ifdef DEBUG_USB_HOST
-
407  else if (rfcommChannelType != RFCOMM_DISC) {
-
408  Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80);
-
409  D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
-
410  Notify(PSTR(" Command: "), 0x80);
-
411  D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
-
412  }
-
413 #endif
-
414  }
-
415  }
-
416 #ifdef EXTRADEBUG
-
417  else {
-
418  Notify(PSTR("\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
-
419  D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
-
420  Notify(PSTR(" "), 0x80);
-
421  D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);
-
422  }
-
423 #endif
-
424  SDP_task();
-
425  RFCOMM_task();
-
426  }
-
427 }
-
428 
-
429 void SPP::Run() {
-
430  if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it
-
431 #ifdef DEBUG_USB_HOST
-
432  Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80);
-
433 #endif
-
434  creditSent = false;
-
435  waitForLastCommand = false;
-
436  connected = true; // The RFCOMM channel is now established
-
437  sppIndex = 0;
-
438  }
-
439  send(); // Send all bytes currently in the buffer
-
440 }
-
441 
-
442 void SPP::SDP_task() {
-
443  switch (l2cap_sdp_state) {
-
444  case L2CAP_SDP_WAIT:
-
445  if (l2cap_connection_request_sdp_flag) {
-
446  l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag
-
447 #ifdef DEBUG_USB_HOST
-
448  Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80);
-
449 #endif
-
450  pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING);
-
451  delay(1);
-
452  pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, SUCCESSFUL);
-
453  identifier++;
-
454  delay(1);
-
455  pBtd->l2cap_config_request(hci_handle, identifier, sdp_scid);
-
456  l2cap_sdp_state = L2CAP_SDP_REQUEST;
-
457  }
-
458  break;
-
459  case L2CAP_SDP_REQUEST:
-
460  if (l2cap_config_request_sdp_flag) {
-
461  l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag
-
462 #ifdef DEBUG_USB_HOST
-
463  Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
-
464 #endif
-
465  pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid);
-
466  l2cap_sdp_state = L2CAP_SDP_SUCCESS;
-
467  }
-
468  break;
-
469  case L2CAP_SDP_SUCCESS:
-
470  if (l2cap_config_success_sdp_flag) {
-
471  l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag
-
472 #ifdef DEBUG_USB_HOST
-
473  Notify(PSTR("\r\nSDP Successfully Configured"), 0x80);
-
474 #endif
-
475  firstMessage = true; // Reset bool
-
476  SDPConnected = true;
-
477  l2cap_sdp_state = L2CAP_SDP_DONE;
-
478  }
-
479  break;
-
480  case L2CAP_SDP_DONE:
-
481  if (l2cap_disconnect_request_sdp_flag) {
-
482  l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag
-
483  SDPConnected = false;
-
484 #ifdef DEBUG_USB_HOST
-
485  Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80);
-
486 #endif
-
487  pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid);
-
488  l2cap_sdp_state = L2CAP_SDP_WAIT;
-
489  } else if (l2cap_connection_request_sdp_flag)
-
490  l2cap_rfcomm_state = L2CAP_SDP_WAIT;
-
491  break;
-
492  case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected
-
493  if (l2cap_disconnect_response_flag) {
-
494 #ifdef DEBUG_USB_HOST
-
495  Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80);
-
496 #endif
-
497  RFCOMMConnected = false;
-
498  SDPConnected = false;
-
499  pBtd->hci_disconnect(hci_handle);
-
500  hci_handle = -1; // Reset handle
-
501  l2cap_event_flag = 0; // Reset flags
-
502  l2cap_sdp_state = L2CAP_SDP_WAIT;
-
503  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
-
504  }
-
505  break;
-
506  }
-
507 }
-
508 
-
509 void SPP::RFCOMM_task() {
-
510  switch (l2cap_rfcomm_state) {
-
511  case L2CAP_RFCOMM_WAIT:
-
512  if (l2cap_connection_request_rfcomm_flag) {
-
513  l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag
-
514 #ifdef DEBUG_USB_HOST
-
515  Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80);
-
516 #endif
-
517  pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING);
-
518  delay(1);
-
519  pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, SUCCESSFUL);
-
520  identifier++;
-
521  delay(1);
-
522  pBtd->l2cap_config_request(hci_handle, identifier, rfcomm_scid);
-
523  l2cap_rfcomm_state = L2CAP_RFCOMM_REQUEST;
-
524  }
-
525  break;
-
526  case L2CAP_RFCOMM_REQUEST:
-
527  if (l2cap_config_request_rfcomm_flag) {
-
528  l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag
-
529 #ifdef DEBUG_USB_HOST
-
530  Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
-
531 #endif
-
532  pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid);
-
533  l2cap_rfcomm_state = L2CAP_RFCOMM_SUCCESS;
-
534  }
-
535  break;
-
536  case L2CAP_RFCOMM_SUCCESS:
-
537  if (l2cap_config_success_rfcomm_flag) {
-
538  l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag
-
539 #ifdef DEBUG_USB_HOST
-
540  Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80);
-
541 #endif
-
542  rfcommAvailable = 0; // Reset number of bytes available
-
543  bytesRead = 0; // Reset number of bytes received
-
544  RFCOMMConnected = true;
-
545  l2cap_rfcomm_state = L2CAP_RFCOMM_DONE;
-
546  }
-
547  break;
-
548  case L2CAP_RFCOMM_DONE:
-
549  if (l2cap_disconnect_request_rfcomm_flag) {
-
550  l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag
-
551  RFCOMMConnected = false;
-
552  connected = false;
-
553 #ifdef DEBUG_USB_HOST
-
554  Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80);
-
555 #endif
-
556  pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid);
-
557  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
-
558  } else if (l2cap_connection_request_rfcomm_flag)
-
559  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
-
560  break;
-
561  }
-
562 }
-
563 /************************************************************/
-
564 /* SDP Commands */
-
565 
-
566 /************************************************************/
-
567 void SPP::SDP_Command(uint8_t* data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
-
568  pBtd->L2CAP_Command(hci_handle, data, nbytes, sdp_scid[0], sdp_scid[1]);
-
569 }
-
570 
-
571 void SPP::serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow) { // See page 235 in the Bluetooth specs
-
572  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
-
573  l2capoutbuf[1] = transactionIDHigh;
-
574  l2capoutbuf[2] = transactionIDLow;
-
575  l2capoutbuf[3] = 0x00; // Parameter Length
-
576  l2capoutbuf[4] = 0x05; // Parameter Length
-
577  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
-
578  l2capoutbuf[6] = 0x02; // AttributeListsByteCount
-
579 
-
580  /* Attribute ID/Value Sequence: */
-
581  l2capoutbuf[7] = 0x35;
-
582  l2capoutbuf[8] = 0x00;
-
583  l2capoutbuf[9] = 0x00;
-
584 
-
585  SDP_Command(l2capoutbuf, 10);
-
586 }
-
587 
-
588 void SPP::serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
-
589  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
-
590  l2capoutbuf[1] = transactionIDHigh;
-
591  l2capoutbuf[2] = transactionIDLow;
-
592  l2capoutbuf[3] = 0x00; // Parameter Length
-
593  l2capoutbuf[4] = 0x2B; // Parameter Length
-
594  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
-
595  l2capoutbuf[6] = 0x26; // AttributeListsByteCount
-
596 
-
597  /* Attribute ID/Value Sequence: */
-
598  l2capoutbuf[7] = 0x36;
-
599  l2capoutbuf[8] = 0x00;
-
600  l2capoutbuf[9] = 0x3C;
-
601  l2capoutbuf[10] = 0x36;
-
602  l2capoutbuf[11] = 0x00;
+
158  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], rfcomm_scid);
+
159  }
+
160  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
+
161  if(l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
+
162  //Notify(PSTR("\r\nDisconnect Request: SDP Channel"), 0x80);
+
163  identifier = l2capinbuf[9];
+
164  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST);
+
165  } else if(l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
+
166  //Notify(PSTR("\r\nDisconnect Request: RFCOMM Channel"), 0x80);
+
167  identifier = l2capinbuf[9];
+
168  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST);
+
169  }
+
170  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
+
171  if(l2capinbuf[12] == sdp_scid[0] && l2capinbuf[13] == sdp_scid[1]) {
+
172  //Notify(PSTR("\r\nDisconnect Response: SDP Channel"), 0x80);
+
173  identifier = l2capinbuf[9];
+
174  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_RESPONSE);
+
175  } else if(l2capinbuf[12] == rfcomm_scid[0] && l2capinbuf[13] == rfcomm_scid[1]) {
+
176  //Notify(PSTR("\r\nDisconnect Response: RFCOMM Channel"), 0x80);
+
177  identifier = l2capinbuf[9];
+
178  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_RESPONSE);
+
179  }
+
180  } else if(l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) {
+
181 #ifdef DEBUG_USB_HOST
+
182  Notify(PSTR("\r\nInformation request"), 0x80);
+
183 #endif
+
184  identifier = l2capinbuf[9];
+
185  pBtd->l2cap_information_response(hci_handle, identifier, l2capinbuf[12], l2capinbuf[13]);
+
186  }
+
187 #ifdef EXTRADEBUG
+
188  else {
+
189  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
+
190  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
191  }
+
192 #endif
+
193  } else if(l2capinbuf[6] == sdp_dcid[0] && l2capinbuf[7] == sdp_dcid[1]) { // SDP
+
194  if(l2capinbuf[8] == SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU) {
+
195  if(((l2capinbuf[16] << 8 | l2capinbuf[17]) == SERIALPORT_UUID) || ((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000 && (l2capinbuf[18] << 8 | l2capinbuf[19]) == SERIALPORT_UUID)) { // Check if it's sending the full UUID, see: https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm, we will just check the first four bytes
+
196  if(firstMessage) {
+
197  serialPortResponse1(l2capinbuf[9], l2capinbuf[10]);
+
198  firstMessage = false;
+
199  } else {
+
200  serialPortResponse2(l2capinbuf[9], l2capinbuf[10]); // Serialport continuation state
+
201  firstMessage = true;
+
202  }
+
203  } else if(((l2capinbuf[16] << 8 | l2capinbuf[17]) == L2CAP_UUID) || ((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000 && (l2capinbuf[18] << 8 | l2capinbuf[19]) == L2CAP_UUID)) {
+
204  if(firstMessage) {
+
205  l2capResponse1(l2capinbuf[9], l2capinbuf[10]);
+
206  firstMessage = false;
+
207  } else {
+
208  l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state
+
209  firstMessage = true;
+
210  }
+
211  } else
+
212  serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported
+
213 #ifdef EXTRADEBUG
+
214  Notify(PSTR("\r\nUUID: "), 0x80);
+
215  uint16_t uuid;
+
216  if((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000) // Check if it's sending the UUID as a 128-bit UUID
+
217  uuid = (l2capinbuf[18] << 8 | l2capinbuf[19]);
+
218  else // Short UUID
+
219  uuid = (l2capinbuf[16] << 8 | l2capinbuf[17]);
+
220  D_PrintHex<uint16_t > (uuid, 0x80);
+
221 
+
222  Notify(PSTR("\r\nLength: "), 0x80);
+
223  uint16_t length = l2capinbuf[11] << 8 | l2capinbuf[12];
+
224  D_PrintHex<uint16_t > (length, 0x80);
+
225  Notify(PSTR("\r\nData: "), 0x80);
+
226  for(uint8_t i = 0; i < length; i++) {
+
227  D_PrintHex<uint8_t > (l2capinbuf[13 + i], 0x80);
+
228  Notify(PSTR(" "), 0x80);
+
229  }
+
230 #endif
+
231  }
+
232 #ifdef EXTRADEBUG
+
233  else {
+
234  Notify(PSTR("\r\nUnknown PDU: "), 0x80);
+
235  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
236  }
+
237 #endif
+
238  } else if(l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM
+
239  rfcommChannel = l2capinbuf[8] & 0xF8;
+
240  rfcommDirection = l2capinbuf[8] & 0x04;
+
241  rfcommCommandResponse = l2capinbuf[8] & 0x02;
+
242  rfcommChannelType = l2capinbuf[9] & 0xEF;
+
243  rfcommPfBit = l2capinbuf[9] & 0x10;
+
244 
+
245  if(rfcommChannel >> 3 != 0x00)
+
246  rfcommChannelConnection = rfcommChannel;
+
247 
+
248 #ifdef EXTRADEBUG
+
249  Notify(PSTR("\r\nRFCOMM Channel: "), 0x80);
+
250  D_PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
+
251  Notify(PSTR(" Direction: "), 0x80);
+
252  D_PrintHex<uint8_t > (rfcommDirection >> 2, 0x80);
+
253  Notify(PSTR(" CommandResponse: "), 0x80);
+
254  D_PrintHex<uint8_t > (rfcommCommandResponse >> 1, 0x80);
+
255  Notify(PSTR(" ChannelType: "), 0x80);
+
256  D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
+
257  Notify(PSTR(" PF_BIT: "), 0x80);
+
258  D_PrintHex<uint8_t > (rfcommPfBit, 0x80);
+
259 #endif
+
260  if(rfcommChannelType == RFCOMM_DISC) {
+
261 #ifdef DEBUG_USB_HOST
+
262  Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80);
+
263  D_PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
+
264 #endif
+
265  connected = false;
+
266  sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
+
267  }
+
268  if(connected) {
+
269  /* Read the incoming message */
+
270  if(rfcommChannelType == RFCOMM_UIH && rfcommChannel == rfcommChannelConnection) {
+
271  uint8_t length = l2capinbuf[10] >> 1; // Get length
+
272  uint8_t offset = l2capinbuf[4] - length - 4; // Check if there is credit
+
273  if(checkFcs(&l2capinbuf[8], l2capinbuf[11 + length + offset])) {
+
274  uint8_t i = 0;
+
275  for(; i < length; i++) {
+
276  if(rfcommAvailable + i >= sizeof (rfcommDataBuffer)) {
+
277 #ifdef DEBUG_USB_HOST
+
278  Notify(PSTR("\r\nWarning: Buffer is full!"), 0x80);
+
279 #endif
+
280  break;
+
281  }
+
282  rfcommDataBuffer[rfcommAvailable + i] = l2capinbuf[11 + i + offset];
+
283  }
+
284  rfcommAvailable += i;
+
285 #ifdef EXTRADEBUG
+
286  Notify(PSTR("\r\nRFCOMM Data Available: "), 0x80);
+
287  Notify(rfcommAvailable, 0x80);
+
288  if(offset) {
+
289  Notify(PSTR(" - Credit: 0x"), 0x80);
+
290  D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
+
291  }
+
292 #endif
+
293  }
+
294 #ifdef DEBUG_USB_HOST
+
295  else
+
296  Notify(PSTR("\r\nError in FCS checksum!"), 0x80);
+
297 #endif
+
298 #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send to the Arduino via Bluetooth
+
299  for(uint8_t i = 0; i < length; i++)
+
300  Notifyc(l2capinbuf[i + 11 + offset], 0x80);
+
301 #endif
+
302  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
+
303 #ifdef DEBUG_USB_HOST
+
304  Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
+
305 #endif
+
306  rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
+
307  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
+
308  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
+
309  rfcommbuf[3] = l2capinbuf[14]; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
+
310  rfcommbuf[4] = l2capinbuf[15]; // Priority
+
311  rfcommbuf[5] = l2capinbuf[16]; // Timer
+
312  rfcommbuf[6] = l2capinbuf[17]; // Max Fram Size LSB
+
313  rfcommbuf[7] = l2capinbuf[18]; // Max Fram Size MSB
+
314  rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm.
+
315  rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
+
316  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
+
317  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
+
318 #ifdef DEBUG_USB_HOST
+
319  Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
+
320 #endif
+
321  rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
+
322  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
+
323  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
+
324  rfcommbuf[3] = l2capinbuf[14];
+
325  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
+
326  }
+
327  } else {
+
328  if(rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish
+
329 #ifdef DEBUG_USB_HOST
+
330  Notify(PSTR("\r\nReceived SABM Command"), 0x80);
+
331 #endif
+
332  sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
+
333  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command
+
334 #ifdef DEBUG_USB_HOST
+
335  Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80);
+
336 #endif
+
337  rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response
+
338  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
+
339  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
+
340  rfcommbuf[3] = 0xE0; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
+
341  rfcommbuf[4] = 0x00; // Priority
+
342  rfcommbuf[5] = 0x00; // Timer
+
343  rfcommbuf[6] = BULK_MAXPKTSIZE - 14; // Max Fram Size LSB - set to the size of received data (50)
+
344  rfcommbuf[7] = 0x00; // Max Fram Size MSB
+
345  rfcommbuf[8] = 0x00; // MaxRatransm.
+
346  rfcommbuf[9] = 0x00; // Number of Frames
+
347  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A);
+
348  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
+
349 #ifdef DEBUG_USB_HOST
+
350  Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
+
351 #endif
+
352  rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
+
353  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
+
354  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
+
355  rfcommbuf[3] = l2capinbuf[14];
+
356  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
+
357 
+
358  delay(1);
+
359 #ifdef DEBUG_USB_HOST
+
360  Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80);
+
361 #endif
+
362  rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command
+
363  rfcommbuf[1] = 2 << 1 | 1; // Length and shiftet like so: length << 1 | 1
+
364  rfcommbuf[2] = l2capinbuf[13]; // Channel: (1 << 0) | (1 << 1) | (0 << 2) | (channel << 3)
+
365  rfcommbuf[3] = 0x8D; // Can receive frames (YES), Ready to Communicate (YES), Ready to Receive (YES), Incomig Call (NO), Data is Value (YES)
+
366 
+
367  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
+
368  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response
+
369  if(!creditSent) {
+
370 #ifdef DEBUG_USB_HOST
+
371  Notify(PSTR("\r\nSend UIH Command with credit"), 0x80);
+
372 #endif
+
373  sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit
+
374  creditSent = true;
+
375  timer = millis();
+
376  waitForLastCommand = true;
+
377  }
+
378  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit
+
379 #ifdef DEBUG_USB_HOST
+
380  Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80);
+
381 #endif
+
382  } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
+
383 #ifdef DEBUG_USB_HOST
+
384  Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
+
385 #endif
+
386  rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
+
387  rfcommbuf[1] = l2capinbuf[12]; // Length and shiftet like so: length << 1 | 1
+
388  rfcommbuf[2] = l2capinbuf[13]; // Channel: channel << 1 | 1
+
389  rfcommbuf[3] = l2capinbuf[14]; // Pre difined for Bluetooth, see 5.5.3 of TS 07.10 Adaption for RFCOMM
+
390  rfcommbuf[4] = l2capinbuf[15]; // Priority
+
391  rfcommbuf[5] = l2capinbuf[16]; // Timer
+
392  rfcommbuf[6] = l2capinbuf[17]; // Max Fram Size LSB
+
393  rfcommbuf[7] = l2capinbuf[18]; // Max Fram Size MSB
+
394  rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm.
+
395  rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
+
396  sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
+
397 #ifdef DEBUG_USB_HOST
+
398  Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80);
+
399 #endif
+
400  waitForLastCommand = false;
+
401  creditSent = false;
+
402  connected = true; // The RFCOMM channel is now established
+
403  sppIndex = 0;
+
404  }
+
405 #ifdef EXTRADEBUG
+
406  else if(rfcommChannelType != RFCOMM_DISC) {
+
407  Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80);
+
408  D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
+
409  Notify(PSTR(" Command: "), 0x80);
+
410  D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
+
411  }
+
412 #endif
+
413  }
+
414  }
+
415 #ifdef EXTRADEBUG
+
416  else {
+
417  Notify(PSTR("\r\nUnsupported L2CAP Data - Channel ID: "), 0x80);
+
418  D_PrintHex<uint8_t > (l2capinbuf[7], 0x80);
+
419  Notify(PSTR(" "), 0x80);
+
420  D_PrintHex<uint8_t > (l2capinbuf[6], 0x80);
+
421  }
+
422 #endif
+
423  SDP_task();
+
424  RFCOMM_task();
+
425  }
+
426 }
+
427 
+
428 void SPP::Run() {
+
429  if(waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it
+
430 #ifdef DEBUG_USB_HOST
+
431  Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80);
+
432 #endif
+
433  creditSent = false;
+
434  waitForLastCommand = false;
+
435  connected = true; // The RFCOMM channel is now established
+
436  sppIndex = 0;
+
437  }
+
438  send(); // Send all bytes currently in the buffer
+
439 }
+
440 
+
441 void SPP::SDP_task() {
+
442  switch(l2cap_sdp_state) {
+
443  case L2CAP_SDP_WAIT:
+
444  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_SDP_REQUEST)) {
+
445  l2cap_clear_flag(L2CAP_FLAG_CONNECTION_SDP_REQUEST); // Clear flag
+
446 #ifdef DEBUG_USB_HOST
+
447  Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80);
+
448 #endif
+
449  pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING);
+
450  delay(1);
+
451  pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, SUCCESSFUL);
+
452  identifier++;
+
453  delay(1);
+
454  pBtd->l2cap_config_request(hci_handle, identifier, sdp_scid);
+
455  l2cap_sdp_state = L2CAP_SDP_SUCCESS;
+
456  } else if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST)) {
+
457  l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST); // Clear flag
+
458  SDPConnected = false;
+
459 #ifdef DEBUG_USB_HOST
+
460  Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80);
+
461 #endif
+
462  pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid);
+
463  }
+
464  break;
+
465  case L2CAP_SDP_SUCCESS:
+
466  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_SDP_SUCCESS)) {
+
467  l2cap_clear_flag(L2CAP_FLAG_CONFIG_SDP_SUCCESS); // Clear flag
+
468 #ifdef DEBUG_USB_HOST
+
469  Notify(PSTR("\r\nSDP Successfully Configured"), 0x80);
+
470 #endif
+
471  firstMessage = true; // Reset bool
+
472  SDPConnected = true;
+
473  l2cap_sdp_state = L2CAP_SDP_WAIT;
+
474  }
+
475  break;
+
476 
+
477  case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected
+
478  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RESPONSE)) {
+
479 #ifdef DEBUG_USB_HOST
+
480  Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80);
+
481 #endif
+
482  pBtd->hci_disconnect(hci_handle);
+
483  hci_handle = -1; // Reset handle
+
484  Reset();
+
485  }
+
486  break;
+
487  }
+
488 }
+
489 
+
490 void SPP::RFCOMM_task() {
+
491  switch(l2cap_rfcomm_state) {
+
492  case L2CAP_RFCOMM_WAIT:
+
493  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)) {
+
494  l2cap_clear_flag(L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST); // Clear flag
+
495 #ifdef DEBUG_USB_HOST
+
496  Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80);
+
497 #endif
+
498  pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING);
+
499  delay(1);
+
500  pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, SUCCESSFUL);
+
501  identifier++;
+
502  delay(1);
+
503  pBtd->l2cap_config_request(hci_handle, identifier, rfcomm_scid);
+
504  l2cap_rfcomm_state = L2CAP_RFCOMM_SUCCESS;
+
505  } else if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)) {
+
506  l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST); // Clear flag
+
507  RFCOMMConnected = false;
+
508  connected = false;
+
509 #ifdef DEBUG_USB_HOST
+
510  Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80);
+
511 #endif
+
512  pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid);
+
513  }
+
514  break;
+
515  case L2CAP_RFCOMM_SUCCESS:
+
516  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS)) {
+
517  l2cap_clear_flag(L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS); // Clear flag
+
518 #ifdef DEBUG_USB_HOST
+
519  Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80);
+
520 #endif
+
521  rfcommAvailable = 0; // Reset number of bytes available
+
522  bytesRead = 0; // Reset number of bytes received
+
523  RFCOMMConnected = true;
+
524  l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
+
525  }
+
526  break;
+
527  }
+
528 }
+
529 /************************************************************/
+
530 /* SDP Commands */
+
531 
+
532 /************************************************************/
+
533 void SPP::SDP_Command(uint8_t* data, uint8_t nbytes) { // See page 223 in the Bluetooth specs
+
534  pBtd->L2CAP_Command(hci_handle, data, nbytes, sdp_scid[0], sdp_scid[1]);
+
535 }
+
536 
+
537 void SPP::serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow) { // See page 235 in the Bluetooth specs
+
538  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
+
539  l2capoutbuf[1] = transactionIDHigh;
+
540  l2capoutbuf[2] = transactionIDLow;
+
541  l2capoutbuf[3] = 0x00; // Parameter Length
+
542  l2capoutbuf[4] = 0x05; // Parameter Length
+
543  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
+
544  l2capoutbuf[6] = 0x02; // AttributeListsByteCount
+
545 
+
546  /* Attribute ID/Value Sequence: */
+
547  l2capoutbuf[7] = 0x35;
+
548  l2capoutbuf[8] = 0x00;
+
549  l2capoutbuf[9] = 0x00;
+
550 
+
551  SDP_Command(l2capoutbuf, 10);
+
552 }
+
553 
+
554 void SPP::serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
+
555  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
+
556  l2capoutbuf[1] = transactionIDHigh;
+
557  l2capoutbuf[2] = transactionIDLow;
+
558  l2capoutbuf[3] = 0x00; // Parameter Length
+
559  l2capoutbuf[4] = 0x2B; // Parameter Length
+
560  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
+
561  l2capoutbuf[6] = 0x26; // AttributeListsByteCount
+
562 
+
563  /* Attribute ID/Value Sequence: */
+
564  l2capoutbuf[7] = 0x36;
+
565  l2capoutbuf[8] = 0x00;
+
566  l2capoutbuf[9] = 0x3C;
+
567  l2capoutbuf[10] = 0x36;
+
568  l2capoutbuf[11] = 0x00;
+
569 
+
570  l2capoutbuf[12] = 0x39;
+
571  l2capoutbuf[13] = 0x09;
+
572  l2capoutbuf[14] = 0x00;
+
573  l2capoutbuf[15] = 0x00;
+
574  l2capoutbuf[16] = 0x0A;
+
575  l2capoutbuf[17] = 0x00;
+
576  l2capoutbuf[18] = 0x01;
+
577  l2capoutbuf[19] = 0x00;
+
578  l2capoutbuf[20] = 0x06;
+
579  l2capoutbuf[21] = 0x09;
+
580  l2capoutbuf[22] = 0x00;
+
581  l2capoutbuf[23] = 0x01;
+
582  l2capoutbuf[24] = 0x35;
+
583  l2capoutbuf[25] = 0x03;
+
584  l2capoutbuf[26] = 0x19;
+
585  l2capoutbuf[27] = 0x11;
+
586 
+
587  l2capoutbuf[28] = 0x01;
+
588  l2capoutbuf[29] = 0x09;
+
589  l2capoutbuf[30] = 0x00;
+
590  l2capoutbuf[31] = 0x04;
+
591  l2capoutbuf[32] = 0x35;
+
592  l2capoutbuf[33] = 0x0C;
+
593  l2capoutbuf[34] = 0x35;
+
594  l2capoutbuf[35] = 0x03;
+
595  l2capoutbuf[36] = 0x19;
+
596  l2capoutbuf[37] = 0x01;
+
597  l2capoutbuf[38] = 0x00;
+
598  l2capoutbuf[39] = 0x35;
+
599  l2capoutbuf[40] = 0x05;
+
600  l2capoutbuf[41] = 0x19;
+
601  l2capoutbuf[42] = 0x00;
+
602  l2capoutbuf[43] = 0x03;
603 
-
604  l2capoutbuf[12] = 0x39;
-
605  l2capoutbuf[13] = 0x09;
-
606  l2capoutbuf[14] = 0x00;
-
607  l2capoutbuf[15] = 0x00;
-
608  l2capoutbuf[16] = 0x0A;
-
609  l2capoutbuf[17] = 0x00;
-
610  l2capoutbuf[18] = 0x01;
-
611  l2capoutbuf[19] = 0x00;
-
612  l2capoutbuf[20] = 0x06;
-
613  l2capoutbuf[21] = 0x09;
-
614  l2capoutbuf[22] = 0x00;
-
615  l2capoutbuf[23] = 0x01;
-
616  l2capoutbuf[24] = 0x35;
-
617  l2capoutbuf[25] = 0x03;
-
618  l2capoutbuf[26] = 0x19;
-
619  l2capoutbuf[27] = 0x11;
+
604  l2capoutbuf[44] = 0x08;
+
605  l2capoutbuf[45] = 0x02; // Two extra bytes
+
606  l2capoutbuf[46] = 0x00; // 25 (0x19) more bytes to come
+
607  l2capoutbuf[47] = 0x19;
+
608 
+
609  SDP_Command(l2capoutbuf, 48);
+
610 }
+
611 
+
612 void SPP::serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
+
613  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
+
614  l2capoutbuf[1] = transactionIDHigh;
+
615  l2capoutbuf[2] = transactionIDLow;
+
616  l2capoutbuf[3] = 0x00; // Parameter Length
+
617  l2capoutbuf[4] = 0x1C; // Parameter Length
+
618  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
+
619  l2capoutbuf[6] = 0x19; // AttributeListsByteCount
620 
-
621  l2capoutbuf[28] = 0x01;
-
622  l2capoutbuf[29] = 0x09;
-
623  l2capoutbuf[30] = 0x00;
-
624  l2capoutbuf[31] = 0x04;
-
625  l2capoutbuf[32] = 0x35;
-
626  l2capoutbuf[33] = 0x0C;
-
627  l2capoutbuf[34] = 0x35;
-
628  l2capoutbuf[35] = 0x03;
-
629  l2capoutbuf[36] = 0x19;
-
630  l2capoutbuf[37] = 0x01;
-
631  l2capoutbuf[38] = 0x00;
-
632  l2capoutbuf[39] = 0x35;
-
633  l2capoutbuf[40] = 0x05;
-
634  l2capoutbuf[41] = 0x19;
-
635  l2capoutbuf[42] = 0x00;
-
636  l2capoutbuf[43] = 0x03;
-
637 
-
638  l2capoutbuf[44] = 0x08;
-
639  l2capoutbuf[45] = 0x02; // Two extra bytes
-
640  l2capoutbuf[46] = 0x00; // 25 (0x19) more bytes to come
-
641  l2capoutbuf[47] = 0x19;
+
621  /* Attribute ID/Value Sequence: */
+
622  l2capoutbuf[7] = 0x01;
+
623  l2capoutbuf[8] = 0x09;
+
624  l2capoutbuf[9] = 0x00;
+
625  l2capoutbuf[10] = 0x06;
+
626  l2capoutbuf[11] = 0x35;
+
627 
+
628  l2capoutbuf[12] = 0x09;
+
629  l2capoutbuf[13] = 0x09;
+
630  l2capoutbuf[14] = 0x65;
+
631  l2capoutbuf[15] = 0x6E;
+
632  l2capoutbuf[16] = 0x09;
+
633  l2capoutbuf[17] = 0x00;
+
634  l2capoutbuf[18] = 0x6A;
+
635  l2capoutbuf[19] = 0x09;
+
636  l2capoutbuf[20] = 0x01;
+
637  l2capoutbuf[21] = 0x00;
+
638  l2capoutbuf[22] = 0x09;
+
639  l2capoutbuf[23] = 0x01;
+
640  l2capoutbuf[24] = 0x00;
+
641  l2capoutbuf[25] = 0x25;
642 
-
643  SDP_Command(l2capoutbuf, 48);
-
644 }
-
645 
-
646 void SPP::serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
-
647  l2capoutbuf[0] = SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU;
-
648  l2capoutbuf[1] = transactionIDHigh;
-
649  l2capoutbuf[2] = transactionIDLow;
-
650  l2capoutbuf[3] = 0x00; // Parameter Length
-
651  l2capoutbuf[4] = 0x1C; // Parameter Length
-
652  l2capoutbuf[5] = 0x00; // AttributeListsByteCount
-
653  l2capoutbuf[6] = 0x19; // AttributeListsByteCount
-
654 
-
655  /* Attribute ID/Value Sequence: */
-
656  l2capoutbuf[7] = 0x01;
-
657  l2capoutbuf[8] = 0x09;
-
658  l2capoutbuf[9] = 0x00;
-
659  l2capoutbuf[10] = 0x06;
-
660  l2capoutbuf[11] = 0x35;
-
661 
-
662  l2capoutbuf[12] = 0x09;
-
663  l2capoutbuf[13] = 0x09;
-
664  l2capoutbuf[14] = 0x65;
-
665  l2capoutbuf[15] = 0x6E;
-
666  l2capoutbuf[16] = 0x09;
-
667  l2capoutbuf[17] = 0x00;
-
668  l2capoutbuf[18] = 0x6A;
-
669  l2capoutbuf[19] = 0x09;
-
670  l2capoutbuf[20] = 0x01;
-
671  l2capoutbuf[21] = 0x00;
-
672  l2capoutbuf[22] = 0x09;
-
673  l2capoutbuf[23] = 0x01;
-
674  l2capoutbuf[24] = 0x00;
-
675  l2capoutbuf[25] = 0x25;
-
676 
-
677  l2capoutbuf[26] = 0x05; // Name length
-
678  l2capoutbuf[27] = 'T';
-
679  l2capoutbuf[28] = 'K';
-
680  l2capoutbuf[29] = 'J';
-
681  l2capoutbuf[30] = 'S';
-
682  l2capoutbuf[31] = 'P';
-
683  l2capoutbuf[32] = 0x00; // No more data
-
684 
-
685  SDP_Command(l2capoutbuf, 33);
-
686 }
-
687 
-
688 void SPP::l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
-
689  serialPortResponse1(transactionIDHigh, transactionIDLow); // These has to send all the supported functions, since it only supports virtual serialport it just sends the message again
-
690 }
-
691 
-
692 void SPP::l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
-
693  serialPortResponse2(transactionIDHigh, transactionIDLow); // Same data as serialPortResponse2
-
694 }
-
695 /************************************************************/
-
696 /* RFCOMM Commands */
-
697 
-
698 /************************************************************/
-
699 void SPP::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
-
700  pBtd->L2CAP_Command(hci_handle, data, nbytes, rfcomm_scid[0], rfcomm_scid[1]);
+
643  l2capoutbuf[26] = 0x05; // Name length
+
644  l2capoutbuf[27] = 'T';
+
645  l2capoutbuf[28] = 'K';
+
646  l2capoutbuf[29] = 'J';
+
647  l2capoutbuf[30] = 'S';
+
648  l2capoutbuf[31] = 'P';
+
649  l2capoutbuf[32] = 0x00; // No more data
+
650 
+
651  SDP_Command(l2capoutbuf, 33);
+
652 }
+
653 
+
654 void SPP::l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
+
655  serialPortResponse1(transactionIDHigh, transactionIDLow); // These has to send all the supported functions, since it only supports virtual serialport it just sends the message again
+
656 }
+
657 
+
658 void SPP::l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow) {
+
659  serialPortResponse2(transactionIDHigh, transactionIDLow); // Same data as serialPortResponse2
+
660 }
+
661 /************************************************************/
+
662 /* RFCOMM Commands */
+
663 
+
664 /************************************************************/
+
665 void SPP::RFCOMM_Command(uint8_t* data, uint8_t nbytes) {
+
666  pBtd->L2CAP_Command(hci_handle, data, nbytes, rfcomm_scid[0], rfcomm_scid[1]);
+
667 }
+
668 
+
669 void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length) {
+
670  l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address
+
671  l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control
+
672  l2capoutbuf[2] = length << 1 | 0x01; // Length and format (always 0x01 bytes format)
+
673  uint8_t i = 0;
+
674  for(; i < length; i++)
+
675  l2capoutbuf[i + 3] = data[i];
+
676  l2capoutbuf[i + 3] = calcFcs(l2capoutbuf);
+
677 #ifdef EXTRADEBUG
+
678  Notify(PSTR(" - RFCOMM Data: "), 0x80);
+
679  for(i = 0; i < length + 4; i++) {
+
680  D_PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
+
681  Notify(PSTR(" "), 0x80);
+
682  }
+
683 #endif
+
684  RFCOMM_Command(l2capoutbuf, length + 4);
+
685 }
+
686 
+
687 void SPP::sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t credit) {
+
688  l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address
+
689  l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control
+
690  l2capoutbuf[2] = 0x01; // Length = 0
+
691  l2capoutbuf[3] = credit; // Credit
+
692  l2capoutbuf[4] = calcFcs(l2capoutbuf);
+
693 #ifdef EXTRADEBUG
+
694  Notify(PSTR(" - RFCOMM Credit Data: "), 0x80);
+
695  for(uint8_t i = 0; i < 5; i++) {
+
696  D_PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
+
697  Notify(PSTR(" "), 0x80);
+
698  }
+
699 #endif
+
700  RFCOMM_Command(l2capoutbuf, 5);
701 }
702 
-
703 void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length) {
-
704  l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address
-
705  l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control
-
706  l2capoutbuf[2] = length << 1 | 0x01; // Length and format (always 0x01 bytes format)
-
707  uint8_t i = 0;
-
708  for (; i < length; i++)
-
709  l2capoutbuf[i + 3] = data[i];
-
710  l2capoutbuf[i + 3] = calcFcs(l2capoutbuf);
-
711 #ifdef EXTRADEBUG
-
712  Notify(PSTR(" - RFCOMM Data: "), 0x80);
-
713  for (i = 0; i < length + 4; i++) {
-
714  D_PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
-
715  Notify(PSTR(" "), 0x80);
-
716  }
-
717 #endif
-
718  RFCOMM_Command(l2capoutbuf, length + 4);
-
719 }
-
720 
-
721 void SPP::sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t credit) {
-
722  l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address
-
723  l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control
-
724  l2capoutbuf[2] = 0x01; // Length = 0
-
725  l2capoutbuf[3] = credit; // Credit
-
726  l2capoutbuf[4] = calcFcs(l2capoutbuf);
-
727 #ifdef EXTRADEBUG
-
728  Notify(PSTR(" - RFCOMM Credit Data: "), 0x80);
-
729  for (uint8_t i = 0; i < 5; i++) {
-
730  D_PrintHex<uint8_t > (l2capoutbuf[i], 0x80);
-
731  Notify(PSTR(" "), 0x80);
-
732  }
-
733 #endif
-
734  RFCOMM_Command(l2capoutbuf, 5);
+
703 /* CRC on 2 bytes */
+
704 uint8_t SPP::crc(uint8_t *data) {
+
705  return (pgm_read_byte(&rfcomm_crc_table[pgm_read_byte(&rfcomm_crc_table[0xFF ^ data[0]]) ^ data[1]]));
+
706 }
+
707 
+
708 /* Calculate FCS */
+
709 uint8_t SPP::calcFcs(uint8_t *data) {
+
710  uint8_t temp = crc(data);
+
711  if((data[1] & 0xEF) == RFCOMM_UIH)
+
712  return (0xFF - temp); // FCS on 2 bytes
+
713  else
+
714  return (0xFF - pgm_read_byte(&rfcomm_crc_table[temp ^ data[2]])); // FCS on 3 bytes
+
715 }
+
716 
+
717 /* Check FCS */
+
718 bool SPP::checkFcs(uint8_t *data, uint8_t fcs) {
+
719  uint8_t temp = crc(data);
+
720  if((data[1] & 0xEF) != RFCOMM_UIH)
+
721  temp = pgm_read_byte(&rfcomm_crc_table[temp ^ data[2]]); // FCS on 3 bytes
+
722  return (pgm_read_byte(&rfcomm_crc_table[temp ^ fcs]) == 0xCF);
+
723 }
+
724 
+
725 /* Serial commands */
+
726 #if defined(ARDUINO) && ARDUINO >=100
+
727 
+
728 size_t SPP::write(uint8_t data) {
+
729  return write(&data, 1);
+
730 }
+
731 #else
+
732 
+
733 void SPP::write(uint8_t data) {
+
734  write(&data, 1);
735 }
-
736 
-
737 /* CRC on 2 bytes */
-
738 uint8_t SPP::crc(uint8_t *data) {
-
739  return (pgm_read_byte(&rfcomm_crc_table[pgm_read_byte(&rfcomm_crc_table[0xFF ^ data[0]]) ^ data[1]]));
-
740 }
-
741 
-
742 /* Calculate FCS */
-
743 uint8_t SPP::calcFcs(uint8_t *data) {
-
744  if ((data[1] & 0xEF) == RFCOMM_UIH)
-
745  return (0xFF - crc(data)); // FCS on 2 bytes
-
746  else
-
747  return (0xFF - pgm_read_byte(&rfcomm_crc_table[crc(data) ^ data[2]])); // FCS on 3 bytes
-
748 }
-
749 
-
750 /* Check FCS */
-
751 bool SPP::checkFcs(uint8_t *data, uint8_t fcs) {
-
752  uint8_t temp = crc(data);
-
753  if ((data[1] & 0xEF) != RFCOMM_UIH)
-
754  temp = pgm_read_byte(&rfcomm_crc_table[temp ^ data[2]]); // FCS on 3 bytes
-
755  return (pgm_read_byte(&rfcomm_crc_table[temp ^ fcs]) == 0xCF);
-
756 }
-
757 
-
758 /* Serial commands */
-
759 size_t SPP::write(uint8_t data) {
-
760  return write(&data,1);
-
761 }
-
762 
-
763 size_t SPP::write(const uint8_t *data, size_t size) {
-
764  for(uint8_t i = 0; i < size; i++) {
-
765  if(sppIndex >= sizeof(sppOutputBuffer)/sizeof(sppOutputBuffer[0]))
-
766  send(); // Send the current data in the buffer
-
767  sppOutputBuffer[sppIndex++] = data[i]; // All the bytes are put into a buffer and then send using the send() function
-
768  }
-
769  return size;
-
770 }
-
771 
-
772 void SPP::send() {
-
773  if (!connected || !sppIndex)
-
774  return;
-
775  uint8_t length; // This is the length of the string we are sending
-
776  uint8_t offset = 0; // This is used to keep track of where we are in the string
+
736 #endif
+
737 
+
738 #if defined(ARDUINO) && ARDUINO >=100
+
739 
+
740 size_t SPP::write(const uint8_t *data, size_t size) {
+
741 #else
+
742 
+
743 void SPP::write(const uint8_t *data, size_t size) {
+
744 #endif
+
745  for(uint8_t i = 0; i < size; i++) {
+
746  if(sppIndex >= sizeof (sppOutputBuffer) / sizeof (sppOutputBuffer[0]))
+
747  send(); // Send the current data in the buffer
+
748  sppOutputBuffer[sppIndex++] = data[i]; // All the bytes are put into a buffer and then send using the send() function
+
749  }
+
750 #if defined(ARDUINO) && ARDUINO >=100
+
751  return size;
+
752 #endif
+
753 }
+
754 
+
755 void SPP::send() {
+
756  if(!connected || !sppIndex)
+
757  return;
+
758  uint8_t length; // This is the length of the string we are sending
+
759  uint8_t offset = 0; // This is used to keep track of where we are in the string
+
760 
+
761  l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address
+
762  l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
+
763 
+
764  while(sppIndex) { // We will run this while loop until this variable is 0
+
765  if(sppIndex > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger than the outgoing buffer
+
766  length = sizeof (l2capoutbuf) - 4;
+
767  else
+
768  length = sppIndex;
+
769 
+
770  l2capoutbuf[2] = length << 1 | 1; // Length
+
771  uint8_t i = 0;
+
772  for(; i < length; i++)
+
773  l2capoutbuf[i + 3] = sppOutputBuffer[i + offset];
+
774  l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
+
775 
+
776  RFCOMM_Command(l2capoutbuf, length + 4);
777 
-
778  l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address
-
779  l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control
-
780 
-
781  while (sppIndex) { // We will run this while loop until this variable is 0
-
782  if (sppIndex > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger than the outgoing buffer
-
783  length = sizeof (l2capoutbuf) - 4;
-
784  else
-
785  length = sppIndex;
+
778  sppIndex -= length;
+
779  offset += length; // Increment the offset
+
780  }
+
781 }
+
782 
+
783 int SPP::available(void) {
+
784  return rfcommAvailable;
+
785 };
786 
-
787  l2capoutbuf[2] = length << 1 | 1; // Length
-
788  uint8_t i = 0;
-
789  for (; i < length; i++)
-
790  l2capoutbuf[i + 3] = sppOutputBuffer[i + offset];
-
791  l2capoutbuf[i + 3] = calcFcs(l2capoutbuf); // Calculate checksum
-
792 
-
793  RFCOMM_Command(l2capoutbuf, length + 4);
-
794 
-
795  sppIndex -= length;
-
796  offset += length; // Increment the offset
-
797  }
-
798 }
-
799 
-
800 int SPP::available(void) {
-
801  return rfcommAvailable;
-
802 };
-
803 
-
804 void SPP::flush(void) {
-
805  rfcommAvailable = 0;
-
806 }
-
807 
-
808 int SPP::peek(void) {
-
809  if (rfcommAvailable == 0) // Don't read if there is nothing in the buffer
-
810  return -1;
-
811  return rfcommDataBuffer[0];
-
812 }
-
813 
-
814 int SPP::read(void) {
-
815  if (rfcommAvailable == 0) // Don't read if there is nothing in the buffer
-
816  return -1;
-
817  uint8_t output = rfcommDataBuffer[0];
-
818  for (uint8_t i = 1; i < rfcommAvailable; i++)
-
819  rfcommDataBuffer[i - 1] = rfcommDataBuffer[i]; // Shift the buffer one left
-
820  rfcommAvailable--;
-
821  bytesRead++;
-
822  if (bytesRead > (sizeof (rfcommDataBuffer) - 5)) { // We will send the command just before it runs out of credit
-
823  bytesRead = 0;
-
824  sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send more credit
-
825 #ifdef EXTRADEBUG
-
826  Notify(PSTR("\r\nSent "), 0x80);
-
827  Notify((uint8_t)sizeof (rfcommDataBuffer), 0x80);
-
828  Notify(PSTR(" more credit"), 0x80);
-
829 #endif
-
830  }
-
831  return output;
-
832 }
-
SPP::write
virtual size_t write(uint8_t data)
Definition: SPP.cpp:759
-
BTD::btdName
const char * btdName
Definition: BTD.h:405
-
BT_RFCOMM_RPN_RSP
#define BT_RFCOMM_RPN_RSP
Definition: SPP.h:79
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
-
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:121
-
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:400
-
L2CAP_FLAG_CONFIG_SDP_REQUEST
#define L2CAP_FLAG_CONFIG_SDP_REQUEST
Definition: SPP.h:39
-
RFCOMM_PSM
#define RFCOMM_PSM
Definition: BTD.h:125
-
BTD
Definition: BTD.h:158
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
-
RFCOMM_SABM
#define RFCOMM_SABM
Definition: SPP.h:65
-
L2CAP_UUID
#define L2CAP_UUID
Definition: SPP.h:62
+
787 void SPP::discard(void) {
+
788  rfcommAvailable = 0;
+
789 }
+
790 
+
791 int SPP::peek(void) {
+
792  if(rfcommAvailable == 0) // Don't read if there is nothing in the buffer
+
793  return -1;
+
794  return rfcommDataBuffer[0];
+
795 }
+
796 
+
797 int SPP::read(void) {
+
798  if(rfcommAvailable == 0) // Don't read if there is nothing in the buffer
+
799  return -1;
+
800  uint8_t output = rfcommDataBuffer[0];
+
801  for(uint8_t i = 1; i < rfcommAvailable; i++)
+
802  rfcommDataBuffer[i - 1] = rfcommDataBuffer[i]; // Shift the buffer one left
+
803  rfcommAvailable--;
+
804  bytesRead++;
+
805  if(bytesRead > (sizeof (rfcommDataBuffer) - 5)) { // We will send the command just before it runs out of credit
+
806  bytesRead = 0;
+
807  sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send more credit
+
808 #ifdef EXTRADEBUG
+
809  Notify(PSTR("\r\nSent "), 0x80);
+
810  Notify((uint8_t)sizeof (rfcommDataBuffer), 0x80);
+
811  Notify(PSTR(" more credit"), 0x80);
+
812 #endif
+
813  }
+
814  return output;
+
815 }
+
UHS_ACL_HANDLE_OK
#define UHS_ACL_HANDLE_OK(x, y)
Definition: BTD.h:207
+
SPP::write
virtual size_t write(uint8_t data)
Definition: SPP.cpp:728
+
BTD::btdName
const char * btdName
Definition: BTD.h:480
+
BT_RFCOMM_RPN_RSP
#define BT_RFCOMM_RPN_RSP
Definition: SPP.h:44
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:177
+
BTD::sdpConnectionClaimed
bool sdpConnectionClaimed
Definition: BTD.h:475
+
RFCOMM_PSM
#define RFCOMM_PSM
Definition: BTD.h:181
+
SPP::SPP
SPP(BTD *p, const char *name="Arduino", const char *pin="0000")
Definition: SPP.cpp:45
+
BTD
Definition: BTD.h:230
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
RFCOMM_SABM
#define RFCOMM_SABM
Definition: SPP.h:30
+
L2CAP_UUID
#define L2CAP_UUID
Definition: SPP.h:27
rfcomm_crc_table
const uint8_t rfcomm_crc_table[256]
Definition: SPP.cpp:26
-
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:402
-
SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU
#define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU
Definition: SPP.h:60
-
l2cap_connection_request_sdp_flag
#define l2cap_connection_request_sdp_flag
Definition: SPP.h:48
-
L2CAP_FLAG_CONNECTION_SDP_REQUEST
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST
Definition: SPP.h:37
-
l2cap_disconnect_response_flag
#define l2cap_disconnect_response_flag
Definition: SPP.h:56
-
RFCOMM_DISC
#define RFCOMM_DISC
Definition: SPP.h:69
-
L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS
Definition: SPP.h:42
-
SERIALPORT_UUID
#define SERIALPORT_UUID
Definition: SPP.h:61
-
L2CAP_SDP_DONE
#define L2CAP_SDP_DONE
Definition: SPP.h:27
-
SPP::flush
virtual void flush(void)
Definition: SPP.cpp:804
-
L2CAP_DISCONNECT_RESPONSE
#define L2CAP_DISCONNECT_RESPONSE
Definition: SPP.h:28
-
BTD::btdPin
const char * btdPin
Definition: BTD.h:407
-
SPP::connected
bool connected
Definition: SPP.h:111
-
L2CAP_FLAG_CONFIG_RFCOMM_REQUEST
#define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST
Definition: SPP.h:40
-
L2CAP_CMD_INFORMATION_REQUEST
#define L2CAP_CMD_INFORMATION_REQUEST
Definition: BTD.h:116
-
l2cap_config_request_sdp_flag
#define l2cap_config_request_sdp_flag
Definition: SPP.h:50
-
SDP_PSM
#define SDP_PSM
Definition: BTD.h:124
-
SPP::read
virtual int read(void)
Definition: SPP.cpp:814
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
-
extendAddress
#define extendAddress
Definition: SPP.h:71
-
L2CAP_SDP_REQUEST
#define L2CAP_SDP_REQUEST
Definition: SPP.h:25
+
BTD::rfcommConnectionClaimed
bool rfcommConnectionClaimed
Definition: BTD.h:477
+
SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU
#define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU
Definition: SPP.h:25
+
L2CAP_FLAG_CONFIG_SDP_SUCCESS
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS
Definition: BTD.h:149
+
RFCOMM_DISC
#define RFCOMM_DISC
Definition: SPP.h:34
+
SERIALPORT_UUID
#define SERIALPORT_UUID
Definition: SPP.h:26
+
L2CAP_SDP_SUCCESS
#define L2CAP_SDP_SUCCESS
Definition: BTD.h:120
+
BTD::btdPin
const char * btdPin
Definition: BTD.h:482
+
SPP::connected
bool connected
Definition: SPP.h:79
+
L2CAP_CMD_INFORMATION_REQUEST
#define L2CAP_CMD_INFORMATION_REQUEST
Definition: BTD.h:172
+
SDP_PSM
#define SDP_PSM
Definition: BTD.h:180
+
SPP::read
virtual int read(void)
Definition: SPP.cpp:797
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
+
extendAddress
#define extendAddress
Definition: SPP.h:36
+
L2CAP_RFCOMM_WAIT
#define L2CAP_RFCOMM_WAIT
Definition: BTD.h:123
Notify
#define Notify(...)
Definition: message.h:44
-
l2cap_connection_request_rfcomm_flag
#define l2cap_connection_request_rfcomm_flag
Definition: SPP.h:49
-
L2CAP_FLAG_CONFIG_SDP_SUCCESS
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS
Definition: SPP.h:41
-
SPP::Run
virtual void Run()
Definition: SPP.cpp:429
-
L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST
Definition: SPP.h:44
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
+
SPP::Run
virtual void Run()
Definition: SPP.cpp:428
+
L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST
Definition: BTD.h:153
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
Notifyc
#define Notifyc(...)
Definition: message.h:46
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
SPP::Reset
virtual void Reset()
Definition: SPP.cpp:63
-
l2cap_config_success_rfcomm_flag
#define l2cap_config_success_rfcomm_flag
Definition: SPP.h:53
-
SPP::SPP
SPP(BTD *p, const char *name="Arduino", const char *pin="1234")
Definition: SPP.cpp:45
-
RFCOMM_UIH
#define RFCOMM_UIH
Definition: SPP.h:67
-
SPP::available
virtual int available(void)
Definition: SPP.cpp:800
-
l2cap_disconnect_request_rfcomm_flag
#define l2cap_disconnect_request_rfcomm_flag
Definition: SPP.h:55
-
L2CAP_SDP_SUCCESS
#define L2CAP_SDP_SUCCESS
Definition: SPP.h:26
-
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
L2CAP_FLAG_DISCONNECT_SDP_REQUEST
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST
Definition: SPP.h:43
-
L2CAP_RFCOMM_DONE
#define L2CAP_RFCOMM_DONE
Definition: SPP.h:34
+
L2CAP_FLAG_DISCONNECT_SDP_REQUEST
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST
Definition: BTD.h:150
+
RFCOMM_UIH
#define RFCOMM_UIH
Definition: SPP.h:32
+
SPP::available
virtual int available(void)
Definition: SPP.cpp:783
+
l2cap_check_flag
#define l2cap_check_flag(flag)
Definition: BTD.h:160
+
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:168
+
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:170
+
SPP::discard
void discard(void)
Definition: SPP.cpp:787
+
L2CAP_SDP_WAIT
#define L2CAP_SDP_WAIT
Definition: BTD.h:119
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
-
BT_RFCOMM_RPN_CMD
#define BT_RFCOMM_RPN_CMD
Definition: SPP.h:78
-
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
+
L2CAP_RFCOMM_SUCCESS
#define L2CAP_RFCOMM_SUCCESS
Definition: BTD.h:124
+
BT_RFCOMM_RPN_CMD
#define BT_RFCOMM_RPN_CMD
Definition: SPP.h:43
+
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:333
+
L2CAP_FLAG_DISCONNECT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_RESPONSE
Definition: BTD.h:157
+
L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS
Definition: BTD.h:154
SPP::disconnect
virtual void disconnect()
Definition: SPP.cpp:74
-
BT_RFCOMM_MSC_CMD
#define BT_RFCOMM_MSC_CMD
Definition: SPP.h:76
-
SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU
#define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU
Definition: SPP.h:59
-
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:115
-
RFCOMM_UA
#define RFCOMM_UA
Definition: SPP.h:66
-
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1301
-
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST
Definition: SPP.h:38
-
L2CAP_RFCOMM_SUCCESS
#define L2CAP_RFCOMM_SUCCESS
Definition: SPP.h:33
-
BT_RFCOMM_PN_CMD
#define BT_RFCOMM_PN_CMD
Definition: SPP.h:74
-
BT_RFCOMM_MSC_RSP
#define BT_RFCOMM_MSC_RSP
Definition: SPP.h:77
-
L2CAP_RFCOMM_REQUEST
#define L2CAP_RFCOMM_REQUEST
Definition: SPP.h:32
-
L2CAP_SDP_WAIT
#define L2CAP_SDP_WAIT
Definition: SPP.h:24
-
L2CAP_RFCOMM_WAIT
#define L2CAP_RFCOMM_WAIT
Definition: SPP.h:31
-
SPP::send
void send(void)
Definition: SPP.cpp:772
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
PENDING
#define PENDING
Definition: BTD.h:120
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
l2cap_config_request_rfcomm_flag
#define l2cap_config_request_rfcomm_flag
Definition: SPP.h:51
-
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
-
BT_RFCOMM_PN_RSP
#define BT_RFCOMM_PN_RSP
Definition: SPP.h:75
-
l2cap_config_success_sdp_flag
#define l2cap_config_success_sdp_flag
Definition: SPP.h:52
-
l2cap_disconnect_request_sdp_flag
#define l2cap_disconnect_request_sdp_flag
Definition: SPP.h:54
+
BT_RFCOMM_MSC_CMD
#define BT_RFCOMM_MSC_CMD
Definition: SPP.h:41
+
SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU
#define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU
Definition: SPP.h:24
+
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
+
RFCOMM_UA
#define RFCOMM_UA
Definition: SPP.h:31
+
BTD::l2cap_information_response
void l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh)
Definition: BTD.cpp:1313
+
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
+
BT_RFCOMM_PN_CMD
#define BT_RFCOMM_PN_CMD
Definition: SPP.h:39
+
BT_RFCOMM_MSC_RSP
#define BT_RFCOMM_MSC_RSP
Definition: SPP.h:42
+
L2CAP_FLAG_CONNECTION_SDP_REQUEST
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST
Definition: BTD.h:148
+
l2cap_clear_flag
#define l2cap_clear_flag(flag)
Definition: BTD.h:162
+
L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST
Definition: BTD.h:155
+
L2CAP_DISCONNECT_RESPONSE
#define L2CAP_DISCONNECT_RESPONSE
Definition: BTD.h:126
+
SPP::send
void send(void)
Definition: SPP.cpp:755
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
PENDING
#define PENDING
Definition: BTD.h:176
+
l2cap_set_flag
#define l2cap_set_flag(flag)
Definition: BTD.h:161
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
+
BT_RFCOMM_PN_RSP
#define BT_RFCOMM_PN_RSP
Definition: SPP.h:40
SPP::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: SPP.cpp:86
-
SPP::peek
virtual int peek(void)
Definition: SPP.cpp:808
+
SPP::peek
virtual int peek(void)
Definition: SPP.cpp:791
SPP.h
-
L2CAP_FLAG_DISCONNECT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_RESPONSE
Definition: SPP.h:45
-
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:109
+
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:165
diff --git a/_s_p_p_8h.html b/_s_p_p_8h.html index 179ce679..9d6be5ab 100644 --- a/_s_p_p_8h.html +++ b/_s_p_p_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: SPP.h File Reference @@ -31,7 +31,7 @@ - + @@ -117,60 +117,6 @@ Classes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -203,384 +149,6 @@ Macros

Macros

#define L2CAP_SDP_WAIT   0
 
#define L2CAP_SDP_REQUEST   1
 
#define L2CAP_SDP_SUCCESS   2
 
#define L2CAP_SDP_DONE   3
 
#define L2CAP_DISCONNECT_RESPONSE   4
 
#define L2CAP_RFCOMM_WAIT   0
 
#define L2CAP_RFCOMM_REQUEST   1
 
#define L2CAP_RFCOMM_SUCCESS   2
 
#define L2CAP_RFCOMM_DONE   3
 
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST   0x001
 
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST   0x002
 
#define L2CAP_FLAG_CONFIG_SDP_REQUEST   0x004
 
#define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST   0x008
 
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS   0x010
 
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS   0x020
 
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST   0x040
 
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST   0x080
 
#define L2CAP_FLAG_DISCONNECT_RESPONSE   0x100
 
#define l2cap_connection_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_SDP_REQUEST)
 
#define l2cap_connection_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)
 
#define l2cap_config_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_REQUEST)
 
#define l2cap_config_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_REQUEST)
 
#define l2cap_config_success_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_SUCCESS)
 
#define l2cap_config_success_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS)
 
#define l2cap_disconnect_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_SDP_REQUEST)
 
#define l2cap_disconnect_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)
 
#define l2cap_disconnect_response_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RESPONSE)
 
#define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU   0x06
 
#define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU   0x07
 

Macro Definition Documentation

- -
-
- - - - -
#define L2CAP_SDP_WAIT   0
-
- -

Definition at line 24 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_SDP_REQUEST   1
-
- -

Definition at line 25 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_SDP_SUCCESS   2
-
- -

Definition at line 26 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_SDP_DONE   3
-
- -

Definition at line 27 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_DISCONNECT_RESPONSE   4
-
- -

Definition at line 28 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_RFCOMM_WAIT   0
-
- -

Definition at line 31 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_RFCOMM_REQUEST   1
-
- -

Definition at line 32 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_RFCOMM_SUCCESS   2
-
- -

Definition at line 33 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_RFCOMM_DONE   3
-
- -

Definition at line 34 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST   0x001
-
- -

Definition at line 37 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST   0x002
-
- -

Definition at line 38 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_SDP_REQUEST   0x004
-
- -

Definition at line 39 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST   0x008
-
- -

Definition at line 40 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS   0x010
-
- -

Definition at line 41 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS   0x020
-
- -

Definition at line 42 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST   0x040
-
- -

Definition at line 43 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST   0x080
-
- -

Definition at line 44 of file SPP.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_RESPONSE   0x100
-
- -

Definition at line 45 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_SDP_REQUEST)
-
- -

Definition at line 48 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)
-
- -

Definition at line 49 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_config_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_REQUEST)
-
- -

Definition at line 50 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_config_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_REQUEST)
-
- -

Definition at line 51 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_SUCCESS)
-
- -

Definition at line 52 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS)
-
- -

Definition at line 53 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_request_sdp_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_SDP_REQUEST)
-
- -

Definition at line 54 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_request_rfcomm_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)
-
- -

Definition at line 55 of file SPP.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RESPONSE)
-
- -

Definition at line 56 of file SPP.h.

- -
-
@@ -591,7 +159,7 @@ Macros
-

Definition at line 59 of file SPP.h.

+

Definition at line 24 of file SPP.h.

@@ -605,7 +173,7 @@ Macros
-

Definition at line 60 of file SPP.h.

+

Definition at line 25 of file SPP.h.

@@ -619,7 +187,7 @@ Macros
-

Definition at line 61 of file SPP.h.

+

Definition at line 26 of file SPP.h.

@@ -633,7 +201,7 @@ Macros
-

Definition at line 62 of file SPP.h.

+

Definition at line 27 of file SPP.h.

@@ -647,7 +215,7 @@ Macros
-

Definition at line 65 of file SPP.h.

+

Definition at line 30 of file SPP.h.

@@ -661,7 +229,7 @@ Macros
-

Definition at line 66 of file SPP.h.

+

Definition at line 31 of file SPP.h.

@@ -675,7 +243,7 @@ Macros
-

Definition at line 67 of file SPP.h.

+

Definition at line 32 of file SPP.h.

@@ -689,7 +257,7 @@ Macros
-

Definition at line 69 of file SPP.h.

+

Definition at line 34 of file SPP.h.

@@ -703,7 +271,7 @@ Macros
-

Definition at line 71 of file SPP.h.

+

Definition at line 36 of file SPP.h.

@@ -717,7 +285,7 @@ Macros
-

Definition at line 74 of file SPP.h.

+

Definition at line 39 of file SPP.h.

@@ -731,7 +299,7 @@ Macros
-

Definition at line 75 of file SPP.h.

+

Definition at line 40 of file SPP.h.

@@ -745,7 +313,7 @@ Macros
-

Definition at line 76 of file SPP.h.

+

Definition at line 41 of file SPP.h.

@@ -759,7 +327,7 @@ Macros
-

Definition at line 77 of file SPP.h.

+

Definition at line 42 of file SPP.h.

@@ -773,7 +341,7 @@ Macros
-

Definition at line 78 of file SPP.h.

+

Definition at line 43 of file SPP.h.

@@ -787,7 +355,7 @@ Macros
-

Definition at line 79 of file SPP.h.

+

Definition at line 44 of file SPP.h.

@@ -796,7 +364,7 @@ Macros diff --git a/_s_p_p_8h_source.html b/_s_p_p_8h_source.html index 587ee385..b4c29572 100644 --- a/_s_p_p_8h_source.html +++ b/_s_p_p_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: SPP.h Source File @@ -31,7 +31,7 @@ - + @@ -111,185 +111,164 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
20 
21 #include "BTD.h"
22 
-
23 /* Bluetooth L2CAP states for SDP_task() */
-
24 #define L2CAP_SDP_WAIT 0
-
25 #define L2CAP_SDP_REQUEST 1
-
26 #define L2CAP_SDP_SUCCESS 2
-
27 #define L2CAP_SDP_DONE 3
-
28 #define L2CAP_DISCONNECT_RESPONSE 4
-
29 
-
30 /* Bluetooth L2CAP states for RFCOMM_task() */
-
31 #define L2CAP_RFCOMM_WAIT 0
-
32 #define L2CAP_RFCOMM_REQUEST 1
-
33 #define L2CAP_RFCOMM_SUCCESS 2
-
34 #define L2CAP_RFCOMM_DONE 3
+
23 /* Used for SDP */
+
24 #define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU 0x06 // See the RFCOMM specs
+
25 #define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU 0x07 // See the RFCOMM specs
+
26 #define SERIALPORT_UUID 0x1101 // See http://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
+
27 #define L2CAP_UUID 0x0100
+
28 
+
29 /* Used for RFCOMM */
+
30 #define RFCOMM_SABM 0x2F
+
31 #define RFCOMM_UA 0x63
+
32 #define RFCOMM_UIH 0xEF
+
33 //#define RFCOMM_DM 0x0F
+
34 #define RFCOMM_DISC 0x43
35 
-
36 /* L2CAP event flags */
-
37 #define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x001
-
38 #define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x002
-
39 #define L2CAP_FLAG_CONFIG_SDP_REQUEST 0x004
-
40 #define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST 0x008
-
41 #define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x010
-
42 #define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x020
-
43 #define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x040
-
44 #define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x080
-
45 #define L2CAP_FLAG_DISCONNECT_RESPONSE 0x100
-
46 
-
47 /* Macros for L2CAP event flag tests */
-
48 #define l2cap_connection_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_SDP_REQUEST)
-
49 #define l2cap_connection_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST)
-
50 #define l2cap_config_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_REQUEST)
-
51 #define l2cap_config_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_REQUEST)
-
52 #define l2cap_config_success_sdp_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_SDP_SUCCESS)
-
53 #define l2cap_config_success_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS)
-
54 #define l2cap_disconnect_request_sdp_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_SDP_REQUEST)
-
55 #define l2cap_disconnect_request_rfcomm_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)
-
56 #define l2cap_disconnect_response_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_RESPONSE)
-
57 
-
58 /* Used for SDP */
-
59 #define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU 0x06 // See the RFCOMM specs
-
60 #define SDP_SERVICE_SEARCH_ATTRIBUTE_RESPONSE_PDU 0x07 // See the RFCOMM specs
-
61 #define SERIALPORT_UUID 0x1101 // See http://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
-
62 #define L2CAP_UUID 0x0100
-
63 
-
64 /* Used for RFCOMM */
-
65 #define RFCOMM_SABM 0x2F
-
66 #define RFCOMM_UA 0x63
-
67 #define RFCOMM_UIH 0xEF
-
68 //#define RFCOMM_DM 0x0F
-
69 #define RFCOMM_DISC 0x43
-
70 
-
71 #define extendAddress 0x01 // Always 1
-
72 
-
73 // Multiplexer message types
-
74 #define BT_RFCOMM_PN_CMD 0x83
-
75 #define BT_RFCOMM_PN_RSP 0x81
-
76 #define BT_RFCOMM_MSC_CMD 0xE3
-
77 #define BT_RFCOMM_MSC_RSP 0xE1
-
78 #define BT_RFCOMM_RPN_CMD 0x93
-
79 #define BT_RFCOMM_RPN_RSP 0x91
-
80 /*
-
81 #define BT_RFCOMM_TEST_CMD 0x23
-
82 #define BT_RFCOMM_TEST_RSP 0x21
-
83 #define BT_RFCOMM_FCON_CMD 0xA3
-
84 #define BT_RFCOMM_FCON_RSP 0xA1
-
85 #define BT_RFCOMM_FCOFF_CMD 0x63
-
86 #define BT_RFCOMM_FCOFF_RSP 0x61
-
87 #define BT_RFCOMM_RLS_CMD 0x53
-
88 #define BT_RFCOMM_RLS_RSP 0x51
-
89 #define BT_RFCOMM_NSC_RSP 0x11
-
90  */
-
91 
-
93 class SPP : public BluetoothService, public Stream {
-
94 public:
-
101  SPP(BTD *p, const char* name = "Arduino", const char* pin = "1234");
-
102 
-
107  operator bool() {
-
108  return connected;
-
109  }
-
111  bool connected;
-
112 
-
118  virtual void ACLData(uint8_t* ACLData);
-
120  virtual void Run();
-
122  virtual void Reset();
-
124  virtual void disconnect();
-
132  virtual int available(void);
-
134  virtual void flush(void);
-
139  virtual int peek(void);
-
144  virtual int read(void);
-
150  virtual size_t write(uint8_t data);
-
157  virtual size_t write(const uint8_t* data, size_t size);
-
159  using Print::write;
-
165  void send(void);
-
168 private:
-
169  /* Bluetooth dongle library pointer */
-
170  BTD *pBtd;
+
36 #define extendAddress 0x01 // Always 1
+
37 
+
38 // Multiplexer message types
+
39 #define BT_RFCOMM_PN_CMD 0x83
+
40 #define BT_RFCOMM_PN_RSP 0x81
+
41 #define BT_RFCOMM_MSC_CMD 0xE3
+
42 #define BT_RFCOMM_MSC_RSP 0xE1
+
43 #define BT_RFCOMM_RPN_CMD 0x93
+
44 #define BT_RFCOMM_RPN_RSP 0x91
+
45 /*
+
46 #define BT_RFCOMM_TEST_CMD 0x23
+
47 #define BT_RFCOMM_TEST_RSP 0x21
+
48 #define BT_RFCOMM_FCON_CMD 0xA3
+
49 #define BT_RFCOMM_FCON_RSP 0xA1
+
50 #define BT_RFCOMM_FCOFF_CMD 0x63
+
51 #define BT_RFCOMM_FCOFF_RSP 0x61
+
52 #define BT_RFCOMM_RLS_CMD 0x53
+
53 #define BT_RFCOMM_RLS_RSP 0x51
+
54 #define BT_RFCOMM_NSC_RSP 0x11
+
55  */
+
56 
+
61 class SPP : public BluetoothService, public Stream {
+
62 public:
+
69  SPP(BTD *p, const char *name = "Arduino", const char *pin = "0000");
+
70 
+
75  operator bool() {
+
76  return connected;
+
77  }
+
79  bool connected;
+
80 
+
86  virtual void ACLData(uint8_t* ACLData);
+
88  virtual void Run();
+
90  virtual void Reset();
+
92  virtual void disconnect();
+
100  virtual int available(void);
+
101 
+
103  virtual void flush(void) {
+
104  send();
+
105  };
+
110  virtual int peek(void);
+
115  virtual int read(void);
+
116 
+
117 #if defined(ARDUINO) && ARDUINO >=100
+
118 
+
123  virtual size_t write(uint8_t data);
+
130  virtual size_t write(const uint8_t* data, size_t size);
+
132  using Print::write;
+
133 #else
+
134 
+
138  virtual void write(uint8_t data);
+
144  virtual void write(const uint8_t* data, size_t size);
+
145 #endif
+
146 
+
148  void discard(void);
+
154  void send(void);
+
157 private:
+
158  /* Bluetooth dongle library pointer */
+
159  BTD *pBtd;
+
160 
+
161  /* Set true when a channel is created */
+
162  bool SDPConnected;
+
163  bool RFCOMMConnected;
+
164 
+
165  uint16_t hci_handle; // The HCI Handle for the connection
+
166 
+
167  /* Variables used by L2CAP state machines */
+
168  uint8_t l2cap_sdp_state;
+
169  uint8_t l2cap_rfcomm_state;
+
170  uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events
171 
-
172  /* Set true when a channel is created */
-
173  bool SDPConnected;
-
174  bool RFCOMMConnected;
-
175 
-
176  uint16_t hci_handle; // The HCI Handle for the connection
-
177 
-
178  /* Variables used by L2CAP state machines */
-
179  uint8_t l2cap_sdp_state;
-
180  uint8_t l2cap_rfcomm_state;
-
181  uint16_t l2cap_event_flag; // l2cap flags of received Bluetooth events
-
182 
-
183  uint8_t l2capoutbuf[BULK_MAXPKTSIZE]; // General purpose buffer for l2cap out data
-
184  uint8_t rfcommbuf[10]; // Buffer for RFCOMM Commands
-
185 
-
186  /* L2CAP Channels */
-
187  uint8_t sdp_scid[2]; // L2CAP source CID for SDP
-
188  uint8_t sdp_dcid[2]; // 0x0050
-
189  uint8_t rfcomm_scid[2]; // L2CAP source CID for RFCOMM
-
190  uint8_t rfcomm_dcid[2]; // 0x0051
-
191  uint8_t identifier; // Identifier for command
-
192 
-
193  /* RFCOMM Variables */
-
194  uint8_t rfcommChannel;
-
195  uint8_t rfcommChannelConnection; // This is the channel the SPP channel will be running at
-
196  uint8_t rfcommDirection;
-
197  uint8_t rfcommCommandResponse;
-
198  uint8_t rfcommChannelType;
-
199  uint8_t rfcommPfBit;
-
200 
-
201  unsigned long timer;
-
202  bool waitForLastCommand;
-
203  bool creditSent;
-
204 
-
205  uint8_t rfcommDataBuffer[100]; // Create a 100 sized buffer for incoming data
-
206  uint8_t sppOutputBuffer[100]; // Create a 100 sized buffer for outgoing SPP data
-
207  uint8_t sppIndex;
-
208  uint8_t rfcommAvailable;
-
209 
-
210  bool firstMessage; // Used to see if it's the first SDP request received
-
211  uint8_t bytesRead; // Counter to see when it's time to send more credit
-
212 
-
213  /* State machines */
-
214  void SDP_task(); // SDP state machine
-
215  void RFCOMM_task(); // RFCOMM state machine
-
216 
-
217  /* SDP Commands */
-
218  void SDP_Command(uint8_t *data, uint8_t nbytes);
-
219  void serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow);
-
220  void serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
-
221  void serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
-
222  void l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
-
223  void l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
-
224 
-
225  /* RFCOMM Commands */
-
226  void RFCOMM_Command(uint8_t *data, uint8_t nbytes);
-
227  void sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t *data, uint8_t length);
-
228  void sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t credit);
-
229  uint8_t calcFcs(uint8_t *data);
-
230  bool checkFcs(uint8_t *data, uint8_t fcs);
-
231  uint8_t crc(uint8_t *data);
-
232 };
-
233 #endif
-
SPP::write
virtual size_t write(uint8_t data)
Definition: SPP.cpp:759
-
BTD
Definition: BTD.h:158
-
SPP::flush
virtual void flush(void)
Definition: SPP.cpp:804
-
SPP::connected
bool connected
Definition: SPP.h:111
-
SPP::read
virtual int read(void)
Definition: SPP.cpp:814
-
SPP::Run
virtual void Run()
Definition: SPP.cpp:429
-
BluetoothService
Definition: BTD.h:139
+
172  uint8_t l2capoutbuf[BULK_MAXPKTSIZE]; // General purpose buffer for l2cap out data
+
173  uint8_t rfcommbuf[10]; // Buffer for RFCOMM Commands
+
174 
+
175  /* L2CAP Channels */
+
176  uint8_t sdp_scid[2]; // L2CAP source CID for SDP
+
177  uint8_t sdp_dcid[2]; // 0x0050
+
178  uint8_t rfcomm_scid[2]; // L2CAP source CID for RFCOMM
+
179  uint8_t rfcomm_dcid[2]; // 0x0051
+
180  uint8_t identifier; // Identifier for command
+
181 
+
182  /* RFCOMM Variables */
+
183  uint8_t rfcommChannel;
+
184  uint8_t rfcommChannelConnection; // This is the channel the SPP channel will be running at
+
185  uint8_t rfcommDirection;
+
186  uint8_t rfcommCommandResponse;
+
187  uint8_t rfcommChannelType;
+
188  uint8_t rfcommPfBit;
+
189 
+
190  unsigned long timer;
+
191  bool waitForLastCommand;
+
192  bool creditSent;
+
193 
+
194  uint8_t rfcommDataBuffer[100]; // Create a 100 sized buffer for incoming data
+
195  uint8_t sppOutputBuffer[100]; // Create a 100 sized buffer for outgoing SPP data
+
196  uint8_t sppIndex;
+
197  uint8_t rfcommAvailable;
+
198 
+
199  bool firstMessage; // Used to see if it's the first SDP request received
+
200  uint8_t bytesRead; // Counter to see when it's time to send more credit
+
201 
+
202  /* State machines */
+
203  void SDP_task(); // SDP state machine
+
204  void RFCOMM_task(); // RFCOMM state machine
+
205 
+
206  /* SDP Commands */
+
207  void SDP_Command(uint8_t *data, uint8_t nbytes);
+
208  void serviceNotSupported(uint8_t transactionIDHigh, uint8_t transactionIDLow);
+
209  void serialPortResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
+
210  void serialPortResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
+
211  void l2capResponse1(uint8_t transactionIDHigh, uint8_t transactionIDLow);
+
212  void l2capResponse2(uint8_t transactionIDHigh, uint8_t transactionIDLow);
+
213 
+
214  /* RFCOMM Commands */
+
215  void RFCOMM_Command(uint8_t *data, uint8_t nbytes);
+
216  void sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t *data, uint8_t length);
+
217  void sendRfcommCredit(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t credit);
+
218  uint8_t calcFcs(uint8_t *data);
+
219  bool checkFcs(uint8_t *data, uint8_t fcs);
+
220  uint8_t crc(uint8_t *data);
+
221 };
+
222 #endif
+
SPP::write
virtual size_t write(uint8_t data)
Definition: SPP.cpp:728
+
SPP::SPP
SPP(BTD *p, const char *name="Arduino", const char *pin="0000")
Definition: SPP.cpp:45
+
BTD
Definition: BTD.h:230
+
SPP::connected
bool connected
Definition: SPP.h:79
+
SPP::read
virtual int read(void)
Definition: SPP.cpp:797
+
SPP::Run
virtual void Run()
Definition: SPP.cpp:428
+
BluetoothService
Definition: BTD.h:211
SPP::Reset
virtual void Reset()
Definition: SPP.cpp:63
-
SPP::SPP
SPP(BTD *p, const char *name="Arduino", const char *pin="1234")
Definition: SPP.cpp:45
-
SPP::available
virtual int available(void)
Definition: SPP.cpp:800
+
SPP::flush
virtual void flush(void)
Definition: SPP.h:103
+
SPP::available
virtual int available(void)
Definition: SPP.cpp:783
+
SPP::discard
void discard(void)
Definition: SPP.cpp:787
BULK_MAXPKTSIZE
#define BULK_MAXPKTSIZE
Definition: BTD.h:33
SPP::disconnect
virtual void disconnect()
Definition: SPP.cpp:74
-
SPP
Definition: SPP.h:93
-
SPP::send
void send(void)
Definition: SPP.cpp:772
+
SPP
Definition: SPP.h:61
+
SPP::send
void send(void)
Definition: SPP.cpp:755
BTD.h
SPP::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: SPP.cpp:86
-
SPP::peek
virtual int peek(void)
Definition: SPP.cpp:808
+
SPP::peek
virtual int peek(void)
Definition: SPP.cpp:791
diff --git a/_usb_8cpp.html b/_usb_8cpp.html index 3729a798..bfc7c240 100644 --- a/_usb_8cpp.html +++ b/_usb_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Usb.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for Usb.cpp: diff --git a/_usb_8cpp_source.html b/_usb_8cpp_source.html index c4346347..56b97046 100644 --- a/_usb_8cpp_source.html +++ b/_usb_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Usb.cpp Source File @@ -31,7 +31,7 @@ - + @@ -135,13 +135,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
44 EpInfo* USB::getEpInfoEntry(uint8_t addr, uint8_t ep) {
45  UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
46 
-
47  if (!p || !p->epinfo)
+
47  if(!p || !p->epinfo)
48  return NULL;
49 
50  EpInfo *pep = p->epinfo;
51 
-
52  for (uint8_t i = 0; i < p->epcount; i++) {
-
53  if ((pep)->epAddr == ep)
+
52  for(uint8_t i = 0; i < p->epcount; i++) {
+
53  if((pep)->epAddr == ep)
54  return pep;
55 
56  pep++;
@@ -153,15 +153,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
62 
63 /* each device is different and has different number of endpoints. This function plugs endpoint record structure, defined in application, to devtable */
64 uint8_t USB::setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr) {
-
65  if (!eprecord_ptr)
+
65  if(!eprecord_ptr)
66  return USB_ERROR_INVALID_ARGUMENT;
67 
68  UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
69 
-
70  if (!p)
+
70  if(!p)
71  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
72 
-
73  p->address = addr;
+
73  p->address.devAddress = addr;
74  p->epinfo = eprecord_ptr;
75  p->epcount = epcount;
76 
@@ -171,15 +171,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
80 uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t &nak_limit) {
81  UsbDevice *p = addrPool.GetUsbDevicePtr(addr);
82 
-
83  if (!p)
+
83  if(!p)
84  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
85 
-
86  if (!p->epinfo)
+
86  if(!p->epinfo)
87  return USB_ERROR_EPINFO_IS_NULL;
88 
89  *ppep = getEpInfoEntry(addr, ep);
90 
-
91  if (!*ppep)
+
91  if(!*ppep)
92  return USB_ERROR_EP_NOT_FOUND_IN_TBL;
93 
94  nak_limit = (0x0001UL << (((*ppep)->bmNakPower > USB_NAK_MAX_POWER) ? USB_NAK_MAX_POWER : (*ppep)->bmNakPower));
@@ -191,9 +191,9 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
100  USBTRACE2(" NAK Limit: ", nak_limit);
101  USBTRACE("\r\n");
102  */
-
103  regWr(rPERADDR, addr); //set peripheral address
+
103  regWr(rPERADDR, addr); //set peripheral address
104 
-
105  uint8_t mode = regRd(rMODE);
+
105  uint8_t mode = regRd(rMODE);
106 
107  //Serial.print("\r\nMode: ");
108  //Serial.println( mode, HEX);
@@ -203,7 +203,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
112 
113 
114  // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise
-
115  regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED));
+
115  regWr(rMODE, (p->lowspeed) ? mode | bmLOWSPEED | bmHubPre : mode & ~(bmHUBPRE | bmLOWSPEED));
116 
117  return 0;
118 }
@@ -225,56 +225,56 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
134 
135  rcode = SetAddress(addr, ep, &pep, nak_limit);
136 
-
137  if (rcode)
+
137  if(rcode)
138  return rcode;
139 
140  direction = ((bmReqType & 0x80) > 0);
141 
142  /* fill in setup packet */
-
143  setup_pkt.ReqType_u.bmRequestType = bmReqType;
+
143  setup_pkt.ReqType_u.bmRequestType = bmReqType;
144  setup_pkt.bRequest = bRequest;
-
145  setup_pkt.wVal_u.wValueLo = wValLo;
-
146  setup_pkt.wVal_u.wValueHi = wValHi;
+
145  setup_pkt.wVal_u.wValueLo = wValLo;
+
146  setup_pkt.wVal_u.wValueHi = wValHi;
147  setup_pkt.wIndex = wInd;
148  setup_pkt.wLength = total;
149 
-
150  bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); //transfer to setup packet FIFO
+
150  bytesWr(rSUDFIFO, 8, (uint8_t*) & setup_pkt); //transfer to setup packet FIFO
151 
152  rcode = dispatchPkt(tokSETUP, ep, nak_limit); //dispatch packet
153 
-
154  if (rcode) //return HRSLT if not zero
+
154  if(rcode) //return HRSLT if not zero
155  return ( rcode);
156 
-
157  if (dataptr != NULL) //data stage, if present
+
157  if(dataptr != NULL) //data stage, if present
158  {
-
159  if (direction) //IN transfer
+
159  if(direction) //IN transfer
160  {
161  uint16_t left = total;
162 
163  pep->bmRcvToggle = 1; //bmRCVTOG1;
164 
-
165  while (left) {
+
165  while(left) {
166  // Bytes read into buffer
167  uint16_t read = nbytes;
168  //uint16_t read = (left<nbytes) ? left : nbytes;
169 
170  rcode = InTransfer(pep, nak_limit, &read, dataptr);
-
171  if (rcode == hrTOGERR) {
+
171  if(rcode == hrTOGERR) {
172  // yes, we flip it wrong here so that next time it is actually correct!
-
173  pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
+
173  pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
174  continue;
175  }
176 
-
177  if (rcode)
+
177  if(rcode)
178  return rcode;
179 
180  // Invoke callback function if inTransfer completed successfully and callback function pointer is specified
-
181  if (!rcode && p)
+
181  if(!rcode && p)
182  ((USBReadParser*)p)->Parse(read, dataptr, total - left);
183 
184  left -= read;
185 
-
186  if (read < nbytes)
+
186  if(read < nbytes)
187  break;
188  }
189  } else //OUT transfer
@@ -282,7 +282,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
191  pep->bmSndToggle = 1; //bmSNDTOG1;
192  rcode = OutTransfer(pep, nak_limit, nbytes, dataptr);
193  }
-
194  if (rcode) //return error
+
194  if(rcode) //return error
195  return ( rcode);
196  }
197  // Status stage
@@ -300,602 +300,608 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
209 
210  uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
211 
-
212  if (rcode) {
-
213  //printf("SetAddress Failed");
-
214  return rcode;
-
215  }
-
216  return InTransfer(pep, nak_limit, nbytesptr, data);
-
217 }
-
218 
-
219 uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data) {
-
220  uint8_t rcode = 0;
-
221  uint8_t pktsize;
-
222 
-
223  uint16_t nbytes = *nbytesptr;
-
224  //printf("Requesting %i bytes ", nbytes);
-
225  uint8_t maxpktsize = pep->maxPktSize;
-
226 
-
227  *nbytesptr = 0;
-
228  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
-
229 
-
230  while (1) // use a 'return' to exit this loop
-
231  {
-
232  rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS.
-
233  if (rcode == hrTOGERR) {
-
234  // yes, we flip it wrong here so that next time it is actually correct!
-
235  pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
-
236  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
-
237  continue;
-
238  }
-
239  if (rcode) {
-
240  //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
-
241  break; //should be 0, indicating ACK. Else return error code.
-
242  }
-
243  /* check for RCVDAVIRQ and generate error if not present */
-
244  /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
-
245  if ((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
-
246  //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
-
247  rcode = 0xf0; //receive error
-
248  break;
-
249  }
-
250  pktsize = regRd(rRCVBC); //number of received bytes
-
251  //printf("Got %i bytes \r\n", pktsize);
-
252  // This would be OK, but...
-
253  //assert(pktsize <= nbytes);
-
254  if (pktsize > nbytes) {
-
255  // This can happen. Use of assert on Arduino locks up the Arduino.
-
256  // So I will trim the value, and hope for the best.
-
257  //printf(">>>>>>>> Problem! Wanted %i bytes but got %i.\r\n", nbytes, pktsize);
-
258  pktsize = nbytes;
-
259  }
-
260 
-
261  int16_t mem_left = (int16_t)nbytes - *((int16_t*)nbytesptr);
+
212  if(rcode) {
+
213  USBTRACE3("(USB::InTransfer) SetAddress Failed ", rcode, 0x81);
+
214  USBTRACE3("(USB::InTransfer) addr requested ", addr, 0x81);
+
215  USBTRACE3("(USB::InTransfer) ep requested ", ep, 0x81);
+
216  return rcode;
+
217  }
+
218  return InTransfer(pep, nak_limit, nbytesptr, data);
+
219 }
+
220 
+
221 uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data) {
+
222  uint8_t rcode = 0;
+
223  uint8_t pktsize;
+
224 
+
225  uint16_t nbytes = *nbytesptr;
+
226  //printf("Requesting %i bytes ", nbytes);
+
227  uint8_t maxpktsize = pep->maxPktSize;
+
228 
+
229  *nbytesptr = 0;
+
230  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
+
231 
+
232  // use a 'break' to exit this loop
+
233  while(1) {
+
234  rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS.
+
235  if(rcode == hrTOGERR) {
+
236  // yes, we flip it wrong here so that next time it is actually correct!
+
237  pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
+
238  regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value
+
239  continue;
+
240  }
+
241  if(rcode) {
+
242  //printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
+
243  break; //should be 0, indicating ACK. Else return error code.
+
244  }
+
245  /* check for RCVDAVIRQ and generate error if not present */
+
246  /* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
+
247  if((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
+
248  //printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
+
249  rcode = 0xf0; //receive error
+
250  break;
+
251  }
+
252  pktsize = regRd(rRCVBC); //number of received bytes
+
253  //printf("Got %i bytes \r\n", pktsize);
+
254  // This would be OK, but...
+
255  //assert(pktsize <= nbytes);
+
256  if(pktsize > nbytes) {
+
257  // This can happen. Use of assert on Arduino locks up the Arduino.
+
258  // So I will trim the value, and hope for the best.
+
259  //printf(">>>>>>>> Problem! Wanted %i bytes but got %i.\r\n", nbytes, pktsize);
+
260  pktsize = nbytes;
+
261  }
262 
-
263  if (mem_left < 0)
-
264  mem_left = 0;
-
265 
-
266  data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data);
+
263  int16_t mem_left = (int16_t)nbytes - *((int16_t*)nbytesptr);
+
264 
+
265  if(mem_left < 0)
+
266  mem_left = 0;
267 
-
268  regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer
-
269  *nbytesptr += pktsize; // add this packet's byte count to total transfer length
-
270 
-
271  /* The transfer is complete under two conditions: */
-
272  /* 1. The device sent a short packet (L.T. maxPacketSize) */
-
273  /* 2. 'nbytes' have been transferred. */
-
274  if ((pktsize < maxpktsize) || (*nbytesptr >= nbytes)) // have we transferred 'nbytes' bytes?
-
275  {
-
276  // Save toggle value
-
277  pep->bmRcvToggle = ((regRd(rHRSL) & bmRCVTOGRD)) ? 1 : 0;
-
278  //printf("\r\n");
-
279  rcode = 0;
-
280  break;
-
281  } // if
-
282  } //while( 1 )
-
283  return ( rcode);
-
284 }
-
285 
-
286 /* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */
-
287 /* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */
-
288 
-
289 /* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */
-
290 uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
-
291  EpInfo *pep = NULL;
-
292  uint16_t nak_limit = 0;
-
293 
-
294  uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
+
268  data = bytesRd(rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data);
+
269 
+
270  regWr(rHIRQ, bmRCVDAVIRQ); // Clear the IRQ & free the buffer
+
271  *nbytesptr += pktsize; // add this packet's byte count to total transfer length
+
272 
+
273  /* The transfer is complete under two conditions: */
+
274  /* 1. The device sent a short packet (L.T. maxPacketSize) */
+
275  /* 2. 'nbytes' have been transferred. */
+
276  if((pktsize < maxpktsize) || (*nbytesptr >= nbytes)) // have we transferred 'nbytes' bytes?
+
277  {
+
278  // Save toggle value
+
279  pep->bmRcvToggle = ((regRd(rHRSL) & bmRCVTOGRD)) ? 1 : 0;
+
280  //printf("\r\n");
+
281  rcode = 0;
+
282  break;
+
283  } // if
+
284  } //while( 1 )
+
285  return ( rcode);
+
286 }
+
287 
+
288 /* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */
+
289 /* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */
+
290 
+
291 /* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */
+
292 uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
+
293  EpInfo *pep = NULL;
+
294  uint16_t nak_limit = 0;
295 
-
296  if (rcode)
-
297  return rcode;
-
298 
-
299  return OutTransfer(pep, nak_limit, nbytes, data);
-
300 }
-
301 
-
302 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) {
-
303  uint8_t rcode = hrSUCCESS, retry_count;
-
304  uint8_t *data_p = data; //local copy of the data pointer
-
305  uint16_t bytes_tosend, nak_count;
-
306  uint16_t bytes_left = nbytes;
-
307 
-
308  uint8_t maxpktsize = pep->maxPktSize;
+
296  uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
+
297 
+
298  if(rcode)
+
299  return rcode;
+
300 
+
301  return OutTransfer(pep, nak_limit, nbytes, data);
+
302 }
+
303 
+
304 uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data) {
+
305  uint8_t rcode = hrSUCCESS, retry_count;
+
306  uint8_t *data_p = data; //local copy of the data pointer
+
307  uint16_t bytes_tosend, nak_count;
+
308  uint16_t bytes_left = nbytes;
309 
-
310  if (maxpktsize < 1 || maxpktsize > 64)
-
311  return USB_ERROR_INVALID_MAX_PKT_SIZE;
-
312 
-
313  unsigned long timeout = millis() + USB_XFER_TIMEOUT;
+
310  uint8_t maxpktsize = pep->maxPktSize;
+
311 
+
312  if(maxpktsize < 1 || maxpktsize > 64)
+
313  return USB_ERROR_INVALID_MAX_PKT_SIZE;
314 
-
315  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
+
315  unsigned long timeout = millis() + USB_XFER_TIMEOUT;
316 
-
317  while (bytes_left) {
-
318  retry_count = 0;
-
319  nak_count = 0;
-
320  bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
-
321  bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
-
322  regWr(rSNDBC, bytes_tosend); //set number of bytes
-
323  regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
-
324  while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
-
325  regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
-
326  rcode = (regRd(rHRSL) & 0x0f);
-
327 
-
328  while (rcode && (timeout > millis())) {
-
329  switch (rcode) {
-
330  case hrNAK:
-
331  nak_count++;
-
332  if (nak_limit && (nak_count == nak_limit))
-
333  goto breakout;
-
334  //return ( rcode);
-
335  break;
-
336  case hrTIMEOUT:
-
337  retry_count++;
-
338  if (retry_count == USB_RETRY_LIMIT)
-
339  goto breakout;
-
340  //return ( rcode);
-
341  break;
-
342  case hrTOGERR:
-
343  // yes, we flip it wrong here so that next time it is actually correct!
-
344  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
-
345  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
-
346  break;
-
347  default:
-
348  goto breakout;
-
349  }//switch( rcode
-
350 
-
351  /* process NAK according to Host out NAK bug */
-
352  regWr(rSNDBC, 0);
-
353  regWr(rSNDFIFO, *data_p);
-
354  regWr(rSNDBC, bytes_tosend);
-
355  regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
-
356  while (!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
-
357  regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
-
358  rcode = (regRd(rHRSL) & 0x0f);
-
359  }//while( rcode && ....
-
360  bytes_left -= bytes_tosend;
-
361  data_p += bytes_tosend;
-
362  }//while( bytes_left...
-
363 breakout:
-
364 
-
365  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; //bmSNDTOG1 : bmSNDTOG0; //update toggle
-
366  return ( rcode); //should be 0 in all cases
-
367 }
-
368 /* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty */
-
369 /* If NAK, tries to re-send up to nak_limit times */
-
370 /* If nak_limit == 0, do not count NAKs, exit after timeout */
-
371 /* If bus timeout, re-sends up to USB_RETRY_LIMIT times */
-
372 
-
373 /* return codes 0x00-0x0f are HRSLT( 0x00 being success ), 0xff means timeout */
-
374 uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
-
375  unsigned long timeout = millis() + USB_XFER_TIMEOUT;
-
376  uint8_t tmpdata;
-
377  uint8_t rcode = hrSUCCESS;
-
378  uint8_t retry_count = 0;
-
379  uint16_t nak_count = 0;
-
380 
-
381  while (timeout > millis()) {
-
382  regWr(rHXFR, (token | ep)); //launch the transfer
-
383  rcode = USB_ERROR_TRANSFER_TIMEOUT;
-
384 
-
385  while (timeout > millis()) //wait for transfer completion
-
386  {
-
387  tmpdata = regRd(rHIRQ);
-
388 
-
389  if (tmpdata & bmHXFRDNIRQ) {
-
390  regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt
-
391  rcode = 0x00;
-
392  break;
-
393  }//if( tmpdata & bmHXFRDNIRQ
-
394 
-
395  }//while ( millis() < timeout
+
317  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
+
318 
+
319  while(bytes_left) {
+
320  retry_count = 0;
+
321  nak_count = 0;
+
322  bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
+
323  bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
+
324  regWr(rSNDBC, bytes_tosend); //set number of bytes
+
325  regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
+
326  while(!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
+
327  regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
+
328  rcode = (regRd(rHRSL) & 0x0f);
+
329 
+
330  while(rcode && (timeout > millis())) {
+
331  switch(rcode) {
+
332  case hrNAK:
+
333  nak_count++;
+
334  if(nak_limit && (nak_count == nak_limit))
+
335  goto breakout;
+
336  //return ( rcode);
+
337  break;
+
338  case hrTIMEOUT:
+
339  retry_count++;
+
340  if(retry_count == USB_RETRY_LIMIT)
+
341  goto breakout;
+
342  //return ( rcode);
+
343  break;
+
344  case hrTOGERR:
+
345  // yes, we flip it wrong here so that next time it is actually correct!
+
346  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1;
+
347  regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
+
348  break;
+
349  default:
+
350  goto breakout;
+
351  }//switch( rcode
+
352 
+
353  /* process NAK according to Host out NAK bug */
+
354  regWr(rSNDBC, 0);
+
355  regWr(rSNDFIFO, *data_p);
+
356  regWr(rSNDBC, bytes_tosend);
+
357  regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
+
358  while(!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
+
359  regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
+
360  rcode = (regRd(rHRSL) & 0x0f);
+
361  }//while( rcode && ....
+
362  bytes_left -= bytes_tosend;
+
363  data_p += bytes_tosend;
+
364  }//while( bytes_left...
+
365 breakout:
+
366 
+
367  pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 1 : 0; //bmSNDTOG1 : bmSNDTOG0; //update toggle
+
368  return ( rcode); //should be 0 in all cases
+
369 }
+
370 /* dispatch USB packet. Assumes peripheral address is set and relevant buffer is loaded/empty */
+
371 /* If NAK, tries to re-send up to nak_limit times */
+
372 /* If nak_limit == 0, do not count NAKs, exit after timeout */
+
373 /* If bus timeout, re-sends up to USB_RETRY_LIMIT times */
+
374 
+
375 /* return codes 0x00-0x0f are HRSLT( 0x00 being success ), 0xff means timeout */
+
376 uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
+
377  unsigned long timeout = millis() + USB_XFER_TIMEOUT;
+
378  uint8_t tmpdata;
+
379  uint8_t rcode = hrSUCCESS;
+
380  uint8_t retry_count = 0;
+
381  uint16_t nak_count = 0;
+
382 
+
383  while(timeout > millis()) {
+
384  regWr(rHXFR, (token | ep)); //launch the transfer
+
385  rcode = USB_ERROR_TRANSFER_TIMEOUT;
+
386 
+
387  while(timeout > millis()) //wait for transfer completion
+
388  {
+
389  tmpdata = regRd(rHIRQ);
+
390 
+
391  if(tmpdata & bmHXFRDNIRQ) {
+
392  regWr(rHIRQ, bmHXFRDNIRQ); //clear the interrupt
+
393  rcode = 0x00;
+
394  break;
+
395  }//if( tmpdata & bmHXFRDNIRQ
396 
-
397  //if (rcode != 0x00) //exit if timeout
-
398  // return ( rcode);
-
399 
-
400  rcode = (regRd(rHRSL) & 0x0f); //analyze transfer result
+
397  }//while ( millis() < timeout
+
398 
+
399  //if (rcode != 0x00) //exit if timeout
+
400  // return ( rcode);
401 
-
402  switch (rcode) {
-
403  case hrNAK:
-
404  nak_count++;
-
405  if (nak_limit && (nak_count == nak_limit))
-
406  return (rcode);
-
407  break;
-
408  case hrTIMEOUT:
-
409  retry_count++;
-
410  if (retry_count == USB_RETRY_LIMIT)
-
411  return (rcode);
-
412  break;
-
413  default:
-
414  return (rcode);
-
415  }//switch( rcode
-
416 
-
417  }//while( timeout > millis()
-
418  return ( rcode);
-
419 }
-
420 
-
421 /* USB main task. Performs enumeration/cleanup */
-
422 void USB::Task(void) //USB state machine
-
423 {
-
424  uint8_t rcode;
-
425  uint8_t tmpdata;
-
426  static unsigned long delay = 0;
-
427  //USB_DEVICE_DESCRIPTOR buf;
-
428  bool lowspeed = false;
-
429 
-
430  MAX3421E::Task();
+
402  rcode = (regRd(rHRSL) & 0x0f); //analyze transfer result
+
403 
+
404  switch(rcode) {
+
405  case hrNAK:
+
406  nak_count++;
+
407  if(nak_limit && (nak_count == nak_limit))
+
408  return (rcode);
+
409  break;
+
410  case hrTIMEOUT:
+
411  retry_count++;
+
412  if(retry_count == USB_RETRY_LIMIT)
+
413  return (rcode);
+
414  break;
+
415  default:
+
416  return (rcode);
+
417  }//switch( rcode
+
418 
+
419  }//while( timeout > millis()
+
420  return ( rcode);
+
421 }
+
422 
+
423 /* USB main task. Performs enumeration/cleanup */
+
424 void USB::Task(void) //USB state machine
+
425 {
+
426  uint8_t rcode;
+
427  uint8_t tmpdata;
+
428  static unsigned long delay = 0;
+
429  //USB_DEVICE_DESCRIPTOR buf;
+
430  bool lowspeed = false;
431 
-
432  tmpdata = getVbusState();
+
432  MAX3421E::Task();
433 
-
434  /* modify USB task state if Vbus changed */
-
435  switch (tmpdata) {
-
436  case SE1: //illegal state
-
437  usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL;
-
438  lowspeed = false;
-
439  break;
-
440  case SE0: //disconnected
-
441  if ((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED)
-
442  usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;
-
443  lowspeed = false;
-
444  break;
-
445  case LSHOST:
-
446 
-
447  lowspeed = true;
-
448  //intentional fallthrough
-
449  case FSHOST: //attached
-
450  if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
-
451  delay = millis() + USB_SETTLE_DELAY;
-
452  usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
-
453  }
-
454  break;
-
455  }// switch( tmpdata
-
456 
-
457  for (uint8_t i = 0; i < USB_NUMDEVICES; i++)
-
458  if (devConfig[i])
-
459  rcode = devConfig[i]->Poll();
-
460 
-
461  switch (usb_task_state) {
-
462  case USB_DETACHED_SUBSTATE_INITIALIZE:
-
463  init();
-
464 
-
465  for (uint8_t i = 0; i < USB_NUMDEVICES; i++)
-
466  if (devConfig[i])
-
467  rcode = devConfig[i]->Release();
-
468 
-
469  usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE;
-
470  break;
-
471  case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here
+
434  tmpdata = getVbusState();
+
435 
+
436  /* modify USB task state if Vbus changed */
+
437  switch(tmpdata) {
+
438  case SE1: //illegal state
+
439  usb_task_state = USB_DETACHED_SUBSTATE_ILLEGAL;
+
440  lowspeed = false;
+
441  break;
+
442  case SE0: //disconnected
+
443  if((usb_task_state & USB_STATE_MASK) != USB_STATE_DETACHED)
+
444  usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE;
+
445  lowspeed = false;
+
446  break;
+
447  case LSHOST:
+
448 
+
449  lowspeed = true;
+
450  //intentional fallthrough
+
451  case FSHOST: //attached
+
452  if((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
+
453  delay = millis() + USB_SETTLE_DELAY;
+
454  usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
+
455  }
+
456  break;
+
457  }// switch( tmpdata
+
458 
+
459  for(uint8_t i = 0; i < USB_NUMDEVICES; i++)
+
460  if(devConfig[i])
+
461  rcode = devConfig[i]->Poll();
+
462 
+
463  switch(usb_task_state) {
+
464  case USB_DETACHED_SUBSTATE_INITIALIZE:
+
465  init();
+
466 
+
467  for(uint8_t i = 0; i < USB_NUMDEVICES; i++)
+
468  if(devConfig[i])
+
469  rcode = devConfig[i]->Release();
+
470 
+
471  usb_task_state = USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE;
472  break;
-
473  case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
+
473  case USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE: //just sit here
474  break;
-
475  case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device
-
476  if (delay < millis())
-
477  usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
-
478  else break; // don't fall through
-
479  case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
-
480  regWr(rHCTL, bmBUSRST); //issue bus reset
-
481  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE;
-
482  break;
-
483  case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
-
484  if ((regRd(rHCTL) & bmBUSRST) == 0) {
-
485  tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
-
486  regWr(rMODE, tmpdata);
-
487  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
-
488  //delay = millis() + 20; //20ms wait after reset per USB spec
-
489  }
-
490  break;
-
491  case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
-
492  if (regRd(rHIRQ) & bmFRAMEIRQ) {
-
493  //when first SOF received _and_ 20ms has passed we can continue
-
494  /*
-
495  if (delay < millis()) //20ms passed
-
496  usb_task_state = USB_STATE_CONFIGURING;
-
497  */
-
498  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
-
499  delay = millis() + 20;
-
500  }
-
501  break;
-
502  case USB_ATTACHED_SUBSTATE_WAIT_RESET:
-
503  if (delay < millis()) usb_task_state = USB_STATE_CONFIGURING;
-
504  else break; // don't fall through
-
505  case USB_STATE_CONFIGURING:
-
506 
-
507  //Serial.print("\r\nConf.LS: ");
-
508  //Serial.println(lowspeed, HEX);
-
509 
-
510  rcode = Configuring(0, 0, lowspeed);
+
475  case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
+
476  break;
+
477  case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device
+
478  if(delay < millis())
+
479  usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
+
480  else break; // don't fall through
+
481  case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
+
482  regWr(rHCTL, bmBUSRST); //issue bus reset
+
483  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE;
+
484  break;
+
485  case USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE:
+
486  if((regRd(rHCTL) & bmBUSRST) == 0) {
+
487  tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
+
488  regWr(rMODE, tmpdata);
+
489  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
+
490  //delay = millis() + 20; //20ms wait after reset per USB spec
+
491  }
+
492  break;
+
493  case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
+
494  if(regRd(rHIRQ) & bmFRAMEIRQ) {
+
495  //when first SOF received _and_ 20ms has passed we can continue
+
496  /*
+
497  if (delay < millis()) //20ms passed
+
498  usb_task_state = USB_STATE_CONFIGURING;
+
499  */
+
500  usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
+
501  delay = millis() + 20;
+
502  }
+
503  break;
+
504  case USB_ATTACHED_SUBSTATE_WAIT_RESET:
+
505  if(delay < millis()) usb_task_state = USB_STATE_CONFIGURING;
+
506  else break; // don't fall through
+
507  case USB_STATE_CONFIGURING:
+
508 
+
509  //Serial.print("\r\nConf.LS: ");
+
510  //Serial.println(lowspeed, HEX);
511 
-
512  if (rcode) {
-
513  if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) {
-
514  usb_error = rcode;
-
515  usb_task_state = USB_STATE_ERROR;
-
516  }
-
517  } else
-
518  usb_task_state = USB_STATE_RUNNING;
-
519  break;
-
520  case USB_STATE_RUNNING:
+
512  rcode = Configuring(0, 0, lowspeed);
+
513 
+
514  if(rcode) {
+
515  if(rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE) {
+
516  usb_error = rcode;
+
517  usb_task_state = USB_STATE_ERROR;
+
518  }
+
519  } else
+
520  usb_task_state = USB_STATE_RUNNING;
521  break;
-
522  case USB_STATE_ERROR:
-
523  //MAX3421E::Init();
-
524  break;
-
525  } // switch( usb_task_state )
-
526 }
-
527 
-
528 uint8_t USB::DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed) {
-
529  //uint8_t buf[12];
-
530  uint8_t rcode;
-
531  UsbDevice *p0 = NULL, *p = NULL;
-
532 
-
533  // Get pointer to pseudo device with address 0 assigned
-
534  p0 = addrPool.GetUsbDevicePtr(0);
-
535 
-
536  if (!p0)
-
537  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
538 
-
539  if (!p0->epinfo)
-
540  return USB_ERROR_EPINFO_IS_NULL;
-
541 
-
542  p0->lowspeed = (lowspeed) ? true : false;
+
522  case USB_STATE_RUNNING:
+
523  break;
+
524  case USB_STATE_ERROR:
+
525  //MAX3421E::Init();
+
526  break;
+
527  } // switch( usb_task_state )
+
528 }
+
529 
+
530 uint8_t USB::DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed) {
+
531  //uint8_t buf[12];
+
532  uint8_t rcode;
+
533  UsbDevice *p0 = NULL, *p = NULL;
+
534 
+
535  // Get pointer to pseudo device with address 0 assigned
+
536  p0 = addrPool.GetUsbDevicePtr(0);
+
537 
+
538  if(!p0)
+
539  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
540 
+
541  if(!p0->epinfo)
+
542  return USB_ERROR_EPINFO_IS_NULL;
543 
-
544  // Allocate new address according to device class
-
545  uint8_t bAddress = addrPool.AllocAddress(parent, false, port);
-
546 
-
547  if (!bAddress)
-
548  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
549 
-
550  p = addrPool.GetUsbDevicePtr(bAddress);
+
544  p0->lowspeed = (lowspeed) ? true : false;
+
545 
+
546  // Allocate new address according to device class
+
547  uint8_t bAddress = addrPool.AllocAddress(parent, false, port);
+
548 
+
549  if(!bAddress)
+
550  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
551 
-
552  if (!p)
-
553  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
554 
-
555  p->lowspeed = lowspeed;
+
552  p = addrPool.GetUsbDevicePtr(bAddress);
+
553 
+
554  if(!p)
+
555  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
556 
-
557  // Assign new address to the device
-
558  rcode = setAddr(0, 0, bAddress);
-
559 
-
560  if (rcode) {
-
561  addrPool.FreeAddress(bAddress);
-
562  bAddress = 0;
-
563  return rcode;
-
564  }
-
565  return 0;
-
566 };
-
567 
-
568 uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed) {
-
569  //printf("AttemptConfig: parent = %i, port = %i\r\n", parent, port);
-
570  uint8_t retries = 0;
-
571 
-
572 again:
-
573  uint8_t rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed);
-
574  if (rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
-
575  if (parent == 0) {
-
576  // Send a bus reset on the root interface.
-
577  regWr(rHCTL, bmBUSRST); //issue bus reset
-
578  delay(102); // delay 102ms, compensate for clock inaccuracy.
-
579  } else {
-
580  // reset parent port
-
581  devConfig[parent]->ResetHubPort(port);
-
582  }
-
583  } else if (rcode == hrJERR && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works
-
584  delay(100);
-
585  retries++;
-
586  goto again;
-
587  } else if (rcode)
-
588  return rcode;
-
589 
-
590  rcode = devConfig[driver]->Init(parent, port, lowspeed);
-
591  if (rcode == hrJERR && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works
-
592  delay(100);
-
593  retries++;
-
594  goto again;
-
595  }
-
596  if (rcode) {
-
597  // Issue a bus reset, because the device may be in a limbo state
-
598  if (parent == 0) {
-
599  // Send a bus reset on the root interface.
-
600  regWr(rHCTL, bmBUSRST); //issue bus reset
-
601  delay(102); // delay 102ms, compensate for clock inaccuracy.
-
602  } else {
-
603  // reset parent port
-
604  devConfig[parent]->ResetHubPort(port);
-
605  }
-
606  }
-
607  return rcode;
-
608 }
-
609 
-
610 /*
-
611  * This is broken. We need to enumerate differently.
-
612  * It causes major problems with several devices if detected in an unexpected order.
-
613  *
-
614  *
-
615  * Oleg - I wouldn't do anything before the newly connected device is considered sane.
-
616  * i.e.(delays are not indicated for brevity):
-
617  * 1. reset
-
618  * 2. GetDevDescr();
-
619  * 3a. If ACK, continue with allocating address, addressing, etc.
-
620  * 3b. Else reset again, count resets, stop at some number (5?).
-
621  * 4. When max.number of resets is reached, toggle power/fail
-
622  * If desired, this could be modified by performing two resets with GetDevDescr() in the middle - however, from my experience, if a device answers to GDD()
-
623  * it doesn't need to be reset again
-
624  * New steps proposal:
-
625  * 1: get address pool instance. exit on fail
-
626  * 2: pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf). exit on fail.
-
627  * 3: bus reset, 100ms delay
-
628  * 4: set address
-
629  * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail
-
630  * 6: while (configurations) {
-
631  * for(each configuration) {
-
632  * for (each driver) {
-
633  * 6a: Ask device if it likes configuration. Returns 0 on OK.
-
634  * If successful, the driver configured device.
-
635  * The driver now owns the endpoints, and takes over managing them.
-
636  * The following will need codes:
-
637  * Everything went well, instance consumed, exit with success.
-
638  * Instance already in use, ignore it, try next driver.
-
639  * Not a supported device, ignore it, try next driver.
-
640  * Not a supported configuration for this device, ignore it, try next driver.
-
641  * Could not configure device, fatal, exit with fail.
-
642  * }
-
643  * }
-
644  * }
-
645  * 7: for(each driver) {
-
646  * 7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID
-
647  * 8: if we get here, no driver likes the device plugged in, so exit failure.
-
648  *
-
649  */
-
650 uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
-
651  //uint8_t bAddress = 0;
-
652  //printf("Configuring: parent = %i, port = %i\r\n", parent, port);
-
653  uint8_t devConfigIndex;
-
654  uint8_t rcode = 0;
-
655  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
-
656  UsbDevice *p = NULL;
-
657  EpInfo *oldep_ptr = NULL;
-
658  EpInfo epInfo;
-
659 
-
660  epInfo.epAddr = 0;
-
661  epInfo.maxPktSize = 8;
-
662  epInfo.epAttribs = 0;
-
663  epInfo.bmNakPower = USB_NAK_MAX_POWER;
-
664 
-
665  //delay(2000);
-
666  AddressPool &addrPool = GetAddressPool();
-
667  // Get pointer to pseudo device with address 0 assigned
-
668  p = addrPool.GetUsbDevicePtr(0);
-
669  if (!p) {
-
670  //printf("Configuring error: USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL\r\n");
-
671  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
672  }
-
673 
-
674  // Save old pointer to EP_RECORD of address 0
-
675  oldep_ptr = p->epinfo;
+
557  p->lowspeed = lowspeed;
+
558 
+
559  // Assign new address to the device
+
560  rcode = setAddr(0, 0, bAddress);
+
561 
+
562  if(rcode) {
+
563  addrPool.FreeAddress(bAddress);
+
564  bAddress = 0;
+
565  return rcode;
+
566  }
+
567  return 0;
+
568 };
+
569 
+
570 uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed) {
+
571  //printf("AttemptConfig: parent = %i, port = %i\r\n", parent, port);
+
572  uint8_t retries = 0;
+
573 
+
574 again:
+
575  uint8_t rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed);
+
576  if(rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
+
577  if(parent == 0) {
+
578  // Send a bus reset on the root interface.
+
579  regWr(rHCTL, bmBUSRST); //issue bus reset
+
580  delay(102); // delay 102ms, compensate for clock inaccuracy.
+
581  } else {
+
582  // reset parent port
+
583  devConfig[parent]->ResetHubPort(port);
+
584  }
+
585  } else if(rcode == hrJERR && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works
+
586  delay(100);
+
587  retries++;
+
588  goto again;
+
589  } else if(rcode)
+
590  return rcode;
+
591 
+
592  rcode = devConfig[driver]->Init(parent, port, lowspeed);
+
593  if(rcode == hrJERR && retries < 3) { // Some devices returns this when plugged in - trying to initialize the device again usually works
+
594  delay(100);
+
595  retries++;
+
596  goto again;
+
597  }
+
598  if(rcode) {
+
599  // Issue a bus reset, because the device may be in a limbo state
+
600  if(parent == 0) {
+
601  // Send a bus reset on the root interface.
+
602  regWr(rHCTL, bmBUSRST); //issue bus reset
+
603  delay(102); // delay 102ms, compensate for clock inaccuracy.
+
604  } else {
+
605  // reset parent port
+
606  devConfig[parent]->ResetHubPort(port);
+
607  }
+
608  }
+
609  return rcode;
+
610 }
+
611 
+
612 /*
+
613  * This is broken. We need to enumerate differently.
+
614  * It causes major problems with several devices if detected in an unexpected order.
+
615  *
+
616  *
+
617  * Oleg - I wouldn't do anything before the newly connected device is considered sane.
+
618  * i.e.(delays are not indicated for brevity):
+
619  * 1. reset
+
620  * 2. GetDevDescr();
+
621  * 3a. If ACK, continue with allocating address, addressing, etc.
+
622  * 3b. Else reset again, count resets, stop at some number (5?).
+
623  * 4. When max.number of resets is reached, toggle power/fail
+
624  * If desired, this could be modified by performing two resets with GetDevDescr() in the middle - however, from my experience, if a device answers to GDD()
+
625  * it doesn't need to be reset again
+
626  * New steps proposal:
+
627  * 1: get address pool instance. exit on fail
+
628  * 2: pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf). exit on fail.
+
629  * 3: bus reset, 100ms delay
+
630  * 4: set address
+
631  * 5: pUsb->setEpInfoEntry(bAddress, 1, epInfo), exit on fail
+
632  * 6: while (configurations) {
+
633  * for(each configuration) {
+
634  * for (each driver) {
+
635  * 6a: Ask device if it likes configuration. Returns 0 on OK.
+
636  * If successful, the driver configured device.
+
637  * The driver now owns the endpoints, and takes over managing them.
+
638  * The following will need codes:
+
639  * Everything went well, instance consumed, exit with success.
+
640  * Instance already in use, ignore it, try next driver.
+
641  * Not a supported device, ignore it, try next driver.
+
642  * Not a supported configuration for this device, ignore it, try next driver.
+
643  * Could not configure device, fatal, exit with fail.
+
644  * }
+
645  * }
+
646  * }
+
647  * 7: for(each driver) {
+
648  * 7a: Ask device if it knows this VID/PID. Acts exactly like 6a, but using VID/PID
+
649  * 8: if we get here, no driver likes the device plugged in, so exit failure.
+
650  *
+
651  */
+
652 uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
+
653  //uint8_t bAddress = 0;
+
654  //printf("Configuring: parent = %i, port = %i\r\n", parent, port);
+
655  uint8_t devConfigIndex;
+
656  uint8_t rcode = 0;
+
657  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
+
658  USB_DEVICE_DESCRIPTOR *udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR *>(buf);
+
659  UsbDevice *p = NULL;
+
660  EpInfo *oldep_ptr = NULL;
+
661  EpInfo epInfo;
+
662 
+
663  epInfo.epAddr = 0;
+
664  epInfo.maxPktSize = 8;
+
665  epInfo.epAttribs = 0;
+
666  epInfo.bmNakPower = USB_NAK_MAX_POWER;
+
667 
+
668  //delay(2000);
+
669  AddressPool &addrPool = GetAddressPool();
+
670  // Get pointer to pseudo device with address 0 assigned
+
671  p = addrPool.GetUsbDevicePtr(0);
+
672  if(!p) {
+
673  //printf("Configuring error: USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL\r\n");
+
674  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
675  }
676 
-
677  // Temporary assign new pointer to epInfo to p->epinfo in order to
-
678  // avoid toggle inconsistence
+
677  // Save old pointer to EP_RECORD of address 0
+
678  oldep_ptr = p->epinfo;
679 
-
680  p->epinfo = &epInfo;
-
681 
-
682  p->lowspeed = lowspeed;
-
683  // Get device descriptor
-
684  rcode = getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
-
685 
-
686  // Restore p->epinfo
-
687  p->epinfo = oldep_ptr;
+
680  // Temporary assign new pointer to epInfo to p->epinfo in order to
+
681  // avoid toggle inconsistence
+
682 
+
683  p->epinfo = &epInfo;
+
684 
+
685  p->lowspeed = lowspeed;
+
686  // Get device descriptor
+
687  rcode = getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
688 
-
689  if (rcode) {
-
690  //printf("Configuring error: Can't get USB_DEVICE_DESCRIPTOR\r\n");
-
691  return rcode;
-
692  }
-
693 
-
694  // to-do?
-
695  // Allocate new address according to device class
-
696  //bAddress = addrPool.AllocAddress(parent, false, port);
-
697 
-
698  //if (!bAddress)
-
699  // return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
689  // Restore p->epinfo
+
690  p->epinfo = oldep_ptr;
+
691 
+
692  if(rcode) {
+
693  //printf("Configuring error: Can't get USB_DEVICE_DESCRIPTOR\r\n");
+
694  return rcode;
+
695  }
+
696 
+
697  // to-do?
+
698  // Allocate new address according to device class
+
699  //bAddress = addrPool.AllocAddress(parent, false, port);
700 
-
701  uint16_t vid = (uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
702  uint16_t pid = (uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
703  uint8_t klass = ((USB_DEVICE_DESCRIPTOR*)buf)->bDeviceClass;
-
704 
-
705  // Attempt to configure if VID/PID or device class matches with a driver
-
706  for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
-
707  if (!devConfig[devConfigIndex]) continue; // no driver
-
708  if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
-
709  if (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) {
-
710  rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
-
711  if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED)
-
712  break;
-
713  }
-
714  }
-
715 
-
716  if (devConfigIndex < USB_NUMDEVICES) {
-
717  return rcode;
-
718  }
-
719 
-
720 
-
721  // blindly attempt to configure
-
722  for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
-
723  if (!devConfig[devConfigIndex]) continue;
-
724  if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
-
725  if (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above
-
726  rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
-
727 
-
728  //printf("ERROR ENUMERATING %2.2x\r\n", rcode);
-
729  if (!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) {
-
730  // in case of an error dev_index should be reset to 0
-
731  // in order to start from the very beginning the
-
732  // next time the program gets here
-
733  //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE)
-
734  // devConfigIndex = 0;
-
735  return rcode;
-
736  }
-
737  }
-
738  // if we get here that means that the device class is not supported by any of registered classes
-
739  rcode = DefaultAddressing(parent, port, lowspeed);
-
740 
-
741  return rcode;
-
742 }
-
743 
-
744 uint8_t USB::ReleaseDevice(uint8_t addr) {
-
745  if (!addr)
-
746  return 0;
-
747 
-
748  for (uint8_t i = 0; i < USB_NUMDEVICES; i++) {
-
749  if(!devConfig[i]) continue;
-
750  if (devConfig[i]->GetAddress() == addr)
-
751  return devConfig[i]->Release();
-
752  }
-
753  return 0;
-
754 }
-
755 
-
756 #if 1
-
757 //get device descriptor
-
758 
-
759 uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
-
760  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, NULL));
-
761 }
-
762 //get configuration descriptor
-
763 
-
764 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
-
765  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, NULL));
-
766 }
-
767 
-
768 /* Requests Configuration Descriptor. Sends two Get Conf Descr requests. The first one gets the total length of all descriptors, then the second one requests this
-
769  total length. The length of the first request can be shorter ( 4 bytes ), however, there are devices which won't work unless this length is set to 9 */
-
770 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) {
-
771  const uint8_t bufSize = 64;
-
772  uint8_t buf[bufSize];
-
773 
-
774  uint8_t ret = getConfDescr(addr, ep, 9, conf, buf);
-
775 
-
776  if (ret)
-
777  return ret;
+
701  //if (!bAddress)
+
702  // return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
703  uint16_t vid = udd->idVendor;
+
704  uint16_t pid = udd->idProduct;
+
705  uint8_t klass = udd->bDeviceClass;
+
706 
+
707  // Attempt to configure if VID/PID or device class matches with a driver
+
708  for(devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
+
709  if(!devConfig[devConfigIndex]) continue; // no driver
+
710  if(devConfig[devConfigIndex]->GetAddress()) continue; // consumed
+
711  if(devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) {
+
712  rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
+
713  if(rcode != USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED)
+
714  break;
+
715  }
+
716  }
+
717 
+
718  if(devConfigIndex < USB_NUMDEVICES) {
+
719  return rcode;
+
720  }
+
721 
+
722 
+
723  // blindly attempt to configure
+
724  for(devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
+
725  if(!devConfig[devConfigIndex]) continue;
+
726  if(devConfig[devConfigIndex]->GetAddress()) continue; // consumed
+
727  if(devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above
+
728  rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
+
729 
+
730  //printf("ERROR ENUMERATING %2.2x\r\n", rcode);
+
731  if(!(rcode == USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED || rcode == USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE)) {
+
732  // in case of an error dev_index should be reset to 0
+
733  // in order to start from the very beginning the
+
734  // next time the program gets here
+
735  //if (rcode != USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE)
+
736  // devConfigIndex = 0;
+
737  return rcode;
+
738  }
+
739  }
+
740  // if we get here that means that the device class is not supported by any of registered classes
+
741  rcode = DefaultAddressing(parent, port, lowspeed);
+
742 
+
743  return rcode;
+
744 }
+
745 
+
746 uint8_t USB::ReleaseDevice(uint8_t addr) {
+
747  if(!addr)
+
748  return 0;
+
749 
+
750  for(uint8_t i = 0; i < USB_NUMDEVICES; i++) {
+
751  if(!devConfig[i]) continue;
+
752  if(devConfig[i]->GetAddress() == addr)
+
753  return devConfig[i]->Release();
+
754  }
+
755  return 0;
+
756 }
+
757 
+
758 #if 1
+
759 //get device descriptor
+
760 
+
761 uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
+
762  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, nbytes, dataptr, NULL));
+
763 }
+
764 //get configuration descriptor
+
765 
+
766 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
+
767  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, nbytes, dataptr, NULL));
+
768 }
+
769 
+
770 /* Requests Configuration Descriptor. Sends two Get Conf Descr requests. The first one gets the total length of all descriptors, then the second one requests this
+
771  total length. The length of the first request can be shorter ( 4 bytes ), however, there are devices which won't work unless this length is set to 9 */
+
772 uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p) {
+
773  const uint8_t bufSize = 64;
+
774  uint8_t buf[bufSize];
+
775  USB_CONFIGURATION_DESCRIPTOR *ucd = reinterpret_cast<USB_CONFIGURATION_DESCRIPTOR *>(buf);
+
776 
+
777  uint8_t ret = getConfDescr(addr, ep, 9, conf, buf);
778 
-
779  uint16_t total = ((USB_CONFIGURATION_DESCRIPTOR*)buf)->wTotalLength;
-
780 
-
781  //USBTRACE2("\r\ntotal conf.size:", total);
-
782 
-
783  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p));
-
784 }
+
779  if(ret)
+
780  return ret;
+
781 
+
782  uint16_t total = ucd->wTotalLength;
+
783 
+
784  //USBTRACE2("\r\ntotal conf.size:", total);
785 
-
786 //get string descriptor
-
787 
-
788 uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) {
-
789  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, NULL));
-
790 }
-
791 //set address
-
792 
-
793 uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
-
794  return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
-
795 }
-
796 //set configuration
-
797 
-
798 uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
-
799  return ( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
-
800 }
-
801 
-
802 #endif // defined(USB_METHODS_INLINE)
-
803 
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
786  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, total, bufSize, buf, p));
+
787 }
+
788 
+
789 //get string descriptor
+
790 
+
791 uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, uint16_t langid, uint8_t* dataptr) {
+
792  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, ns, ns, dataptr, NULL));
+
793 }
+
794 //set address
+
795 
+
796 uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
+
797  uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL);
+
798  //delay(2); //per USB 2.0 sect.9.2.6.3
+
799  delay(300); // Older spec says you should wait at least 200ms
+
800  return rcode;
+
801  //return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
+
802 }
+
803 //set configuration
+
804 
+
805 uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
+
806  return ( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
+
807 }
+
808 
+
809 #endif // defined(USB_METHODS_INLINE)
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:41
AddressPool
Definition: address.h:83
-
USBDeviceConfig::Poll
virtual uint8_t Poll()
Definition: UsbCore.h:110
+
USBDeviceConfig::Poll
virtual uint8_t Poll()
Definition: UsbCore.h:120
USB_ERROR_EP_NOT_FOUND_IN_TBL
#define USB_ERROR_EP_NOT_FOUND_IN_TBL
Definition: UsbCore.h:71
bmHUBPRE
#define bmHUBPRE
Definition: max3421e.h:170
USB_ATTACHED_SUBSTATE_WAIT_RESET
#define USB_ATTACHED_SUBSTATE_WAIT_RESET
Definition: UsbCore.h:98
@@ -905,14 +911,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
+
USB_CONFIGURATION_DESCRIPTOR::wTotalLength
uint16_t wTotalLength
Definition: usb_ch9.h:119
USB::getEpInfoEntry
EpInfo * getEpInfoEntry(uint8_t addr, uint8_t ep)
Definition: Usb.cpp:44
UsbDevice
Definition: address.h:75
bmSOFKAENAB
#define bmSOFKAENAB
Definition: max3421e.h:171
USB_DESCRIPTOR_STRING
#define USB_DESCRIPTOR_STRING
Definition: usb_ch9.h:65
-
SETUP_PKT::wLength
uint16_t wLength
Definition: UsbCore.h:140
+
SETUP_PKT::wLength
uint16_t wLength
Definition: UsbCore.h:164
USB_SETTLE_DELAY
#define USB_SETTLE_DELAY
Definition: UsbCore.h:81
USB_ATTACHED_SUBSTATE_SETTLE
#define USB_ATTACHED_SUBSTATE_SETTLE
Definition: UsbCore.h:94
-
MAX3421e::regWr
void regWr(uint8_t reg, uint8_t data)
Definition: usbhost.h:125
+
MAX3421e::getVbusState
uint8_t getVbusState(void)
Definition: usbhost.h:100
bmRCVTOGRD
#define bmRCVTOGRD
Definition: max3421e.h:204
USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE
#define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE
Definition: UsbCore.h:62
USB_RETRY_LIMIT
#define USB_RETRY_LIMIT
Definition: UsbCore.h:80
@@ -920,32 +927,35 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
USB_DESCRIPTOR_DEVICE
#define USB_DESCRIPTOR_DEVICE
Definition: usb_ch9.h:63
bmRCVTOG1
#define bmRCVTOG1
Definition: max3421e.h:186
USB_ERROR_INVALID_MAX_PKT_SIZE
#define USB_ERROR_INVALID_MAX_PKT_SIZE
Definition: UsbCore.h:70
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
USB_STATE_DETACHED
#define USB_STATE_DETACHED
Definition: UsbCore.h:90
USB_NUMDEVICES
#define USB_NUMDEVICES
Definition: UsbCore.h:83
Usb.h
+
SETUP_PKT::ReqType_u
union SETUP_PKT::@24 ReqType_u
rRCVBC
#define rRCVBC
Definition: max3421e.h:45
hrJERR
#define hrJERR
Definition: max3421e.h:225
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
USBDeviceConfig::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:108
+
USBDeviceConfig::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:112
+
MAX3421e::Task
uint8_t Task()
Definition: usbhost.h:380
hrSUCCESS
#define hrSUCCESS
Definition: max3421e.h:212
USB_STATE_ERROR
#define USB_STATE_ERROR
Definition: UsbCore.h:103
-
SETUP_PKT::bmRequestType
uint8_t bmRequestType
Definition: UsbCore.h:121
+
SETUP_PKT::bmRequestType
uint8_t bmRequestType
Definition: UsbCore.h:145
bmSNDTOGRD
#define bmSNDTOGRD
Definition: max3421e.h:205
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
USB_DESCRIPTOR_CONFIGURATION
#define USB_DESCRIPTOR_CONFIGURATION
Definition: usb_ch9.h:64
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
bmHXFRDNIRQ
#define bmHXFRDNIRQ
Definition: max3421e.h:151
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
USB::USB
USB(void)
Definition: Usb.cpp:25
USB_STATE_RUNNING
#define USB_STATE_RUNNING
Definition: UsbCore.h:102
USB_CONFIGURATION_DESCRIPTOR
Definition: usb_ch9.h:116
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
rRCVFIFO
#define rRCVFIFO
Definition: max3421e.h:42
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
AddressPoolImpl::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)
Definition: address.h:174
-
SETUP_PKT::wIndex
uint16_t wIndex
Definition: UsbCore.h:139
+
AddressPoolImpl::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)
Definition: address.h:180
+
SETUP_PKT::wVal_u
union SETUP_PKT::@25 wVal_u
+
SETUP_PKT::wIndex
uint16_t wIndex
Definition: UsbCore.h:163
bmBUSRST
#define bmBUSRST
Definition: max3421e.h:181
tokOUT
#define tokOUT
Definition: max3421e.h:195
tokIN
#define tokIN
Definition: max3421e.h:194
@@ -954,86 +964,84 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
EpInfo
Definition: address.h:32
rMODE
#define rMODE
Definition: max3421e.h:165
USB::setUsbTaskState
void setUsbTaskState(uint8_t state)
Definition: Usb.cpp:40
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
hrNAK
#define hrNAK
Definition: max3421e.h:216
bmREQ_GET_DESCR
#define bmREQ_GET_DESCR
Definition: UsbCore.h:31
rSNDBC
#define rSNDBC
Definition: max3421e.h:46
rHRSL
#define rHRSL
Definition: max3421e.h:201
USB_ATTACHED_SUBSTATE_RESET_DEVICE
#define USB_ATTACHED_SUBSTATE_RESET_DEVICE
Definition: UsbCore.h:95
+
MAX3421e::bytesRd
uint8_t * bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
Definition: usbhost.h:204
tokINHS
#define tokINHS
Definition: max3421e.h:196
bmLOWSPEED
#define bmLOWSPEED
Definition: max3421e.h:169
-
USBDeviceConfig::ResetHubPort
virtual void ResetHubPort(uint8_t port)
Definition: UsbCore.h:112
-
USB::getStrDescr
uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t *dataptr)
Definition: Usb.cpp:788
+
USBDeviceConfig::ResetHubPort
virtual void ResetHubPort(uint8_t port)
Definition: UsbCore.h:128
+
MAX3421e::bytesWr
uint8_t * bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
Definition: usbhost.h:147
+
USB::getStrDescr
uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t *dataptr)
Definition: Usb.cpp:791
USB_REQUEST_SET_ADDRESS
#define USB_REQUEST_SET_ADDRESS
Definition: usb_ch9.h:36
-
SETUP_PKT::ReqType_u
union SETUP_PKT::@22 ReqType_u
tokSETUP
#define tokSETUP
Definition: max3421e.h:193
-
MAX3421e::Task
uint8_t Task()
Definition: usbhost.h:379
rHXFR
#define rHXFR
Definition: max3421e.h:190
rHIRQ
#define rHIRQ
Definition: max3421e.h:142
EpInfo::bmSndToggle
uint8_t bmSndToggle
Definition: address.h:40
rSNDFIFO
#define rSNDFIFO
Definition: max3421e.h:43
-
USBReadParser
Definition: UsbCore.h:147
+
USBReadParser
Definition: UsbCore.h:171
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
SETUP_PKT
Definition: UsbCore.h:118
-
MAX3421e::bytesWr
uint8_t * bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
Definition: usbhost.h:147
+
UsbDeviceAddress::devAddress
uint8_t devAddress
Definition: address.h:67
+
SETUP_PKT
Definition: UsbCore.h:142
tokOUTHS
#define tokOUTHS
Definition: max3421e.h:197
USB::getUsbTaskState
uint8_t getUsbTaskState(void)
Definition: Usb.cpp:36
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
USB_STATE_MASK
#define USB_STATE_MASK
Definition: UsbCore.h:88
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
-
USB::Task
void Task(void)
Definition: Usb.cpp:422
+
USB::Task
void Task(void)
Definition: Usb.cpp:424
USB_DETACHED_SUBSTATE_ILLEGAL
#define USB_DETACHED_SUBSTATE_ILLEGAL
Definition: UsbCore.h:93
hrTIMEOUT
#define hrTIMEOUT
Definition: max3421e.h:226
rPERADDR
#define rPERADDR
Definition: max3421e.h:177
bmRCVDAVIRQ
#define bmRCVDAVIRQ
Definition: max3421e.h:146
USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE
#define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE
Definition: UsbCore.h:96
+
MAX3421e::regWr
void regWr(uint8_t reg, uint8_t data)
Definition: usbhost.h:125
bmRCVTOG0
#define bmRCVTOG0
Definition: max3421e.h:185
-
USBDeviceConfig::DEVCLASSOK
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: UsbCore.h:114
UsbDevice::epcount
uint8_t epcount
Definition: address.h:78
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
USB_STATE_CONFIGURING
#define USB_STATE_CONFIGURING
Definition: UsbCore.h:101
-
USB::dispatchPkt
uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit)
Definition: Usb.cpp:374
-
USBDeviceConfig::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:107
+
USB::dispatchPkt
uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit)
Definition: Usb.cpp:376
+
USBDeviceConfig::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:108
bmSNDTOG0
#define bmSNDTOG0
Definition: max3421e.h:187
+
MAX3421e::regRd
uint8_t regRd(uint8_t reg)
Definition: usbhost.h:182
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
USB_ERROR_INVALID_ARGUMENT
#define USB_ERROR_INVALID_ARGUMENT
Definition: UsbCore.h:68
-
USB::Configuring
uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:650
-
UsbDevice::address
uint8_t address
Definition: address.h:77
-
MAX3421e::bytesRd
uint8_t * bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
Definition: usbhost.h:203
-
SETUP_PKT::bRequest
uint8_t bRequest
Definition: UsbCore.h:129
+
USB::Configuring
uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:652
+
USBTRACE3
#define USBTRACE3(s, r, l)
Definition: macros.h:68
+
SETUP_PKT::bRequest
uint8_t bRequest
Definition: UsbCore.h:153
SE0
#define SE0
Definition: max3421e.h:33
-
AddressPoolImpl::FreeAddress
virtual void FreeAddress(uint8_t addr)
Definition: address.h:246
-
USBDeviceConfig::Release
virtual uint8_t Release()
Definition: UsbCore.h:109
+
AddressPoolImpl::FreeAddress
virtual void FreeAddress(uint8_t addr)
Definition: address.h:254
+
USBDeviceConfig::Release
virtual uint8_t Release()
Definition: UsbCore.h:116
bmFRAMEIRQ
#define bmFRAMEIRQ
Definition: max3421e.h:150
hrTOGERR
#define hrTOGERR
Definition: max3421e.h:218
SE1
#define SE1
Definition: max3421e.h:34
rSUDFIFO
#define rSUDFIFO
Definition: max3421e.h:44
-
AddressPoolImpl::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
Definition: address.h:195
+
AddressPoolImpl::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
Definition: address.h:202
bmREQ_SET
#define bmREQ_SET
Definition: UsbCore.h:32
+
UsbDevice::address
UsbDeviceAddress address
Definition: address.h:77
USB_REQUEST_SET_CONFIGURATION
#define USB_REQUEST_SET_CONFIGURATION
Definition: usb_ch9.h:40
-
SETUP_PKT::wVal_u
union SETUP_PKT::@23 wVal_u
USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE
#define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE
Definition: UsbCore.h:92
-
SETUP_PKT::wValueHi
uint8_t wValueHi
Definition: UsbCore.h:136
-
USB::DefaultAddressing
uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:528
+
SETUP_PKT::wValueHi
uint8_t wValueHi
Definition: UsbCore.h:160
+
USB::DefaultAddressing
uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:530
USB_DETACHED_SUBSTATE_INITIALIZE
#define USB_DETACHED_SUBSTATE_INITIALIZE
Definition: UsbCore.h:91
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
USB_ATTACHED_SUBSTATE_WAIT_SOF
#define USB_ATTACHED_SUBSTATE_WAIT_SOF
Definition: UsbCore.h:97
-
SETUP_PKT::wValueLo
uint8_t wValueLo
Definition: UsbCore.h:135
+
SETUP_PKT::wValueLo
uint8_t wValueLo
Definition: UsbCore.h:159
bmSNDTOG1
#define bmSNDTOG1
Definition: max3421e.h:188
-
USB::ReleaseDevice
uint8_t ReleaseDevice(uint8_t addr)
Definition: Usb.cpp:744
+
USB::ReleaseDevice
uint8_t ReleaseDevice(uint8_t addr)
Definition: Usb.cpp:746
USB_ERROR_TRANSFER_TIMEOUT
#define USB_ERROR_TRANSFER_TIMEOUT
Definition: UsbCore.h:76
USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
-
MAX3421e::getVbusState
uint8_t getVbusState(void)
Definition: usbhost.h:100
-
MAX3421e::regRd
uint8_t regRd(uint8_t reg)
Definition: usbhost.h:181
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/_usb_8h.html b/_usb_8h.html index 688770f7..a975e0e9 100644 --- a/_usb_8h.html +++ b/_usb_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Usb.h File Reference @@ -31,7 +31,7 @@ - + @@ -94,7 +94,7 @@ This graph shows which files directly or indirectly include this file:
- +

Go to the source code of this file.

@@ -103,7 +103,7 @@ This graph shows which files directly or indirectly include this file: diff --git a/_usb_8h__dep__incl.map b/_usb_8h__dep__incl.map index bbbeede4..0fe84f9e 100644 --- a/_usb_8h__dep__incl.map +++ b/_usb_8h__dep__incl.map @@ -1,45 +1,49 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/_usb_8h__dep__incl.md5 b/_usb_8h__dep__incl.md5 index ac47aae8..ca81b93f 100644 --- a/_usb_8h__dep__incl.md5 +++ b/_usb_8h__dep__incl.md5 @@ -1 +1 @@ -19d142dcf235fa4191381f3fc2835694 \ No newline at end of file +5b8072c50adde9c54ed53b728fbb5f15 \ No newline at end of file diff --git a/_usb_8h__dep__incl.png b/_usb_8h__dep__incl.png index d2a2136b..87fdd56e 100644 Binary files a/_usb_8h__dep__incl.png and b/_usb_8h__dep__incl.png differ diff --git a/_usb_8h_source.html b/_usb_8h_source.html index 42856f49..d1b4a855 100644 --- a/_usb_8h_source.html +++ b/_usb_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Usb.h Source File @@ -31,7 +31,7 @@ - + @@ -119,16 +119,17 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
28 #include "printhex.h"
29 #include "message.h"
30 #include "hexdump.h"
-
31 #include "max3421e.h"
-
32 #include "address.h"
-
33 #include "avrpins.h"
-
34 #include "usb_ch9.h"
-
35 #include "usbhost.h"
-
36 #include "UsbCore.h"
-
37 #include "parsetools.h"
-
38 #include "confdescparser.h"
-
39 
-
40 #endif //_usb_h_
+
31 #include "sink_parser.h"
+
32 #include "max3421e.h"
+
33 #include "address.h"
+
34 #include "avrpins.h"
+
35 #include "usb_ch9.h"
+
36 #include "usbhost.h"
+
37 #include "UsbCore.h"
+
38 #include "parsetools.h"
+
39 #include "confdescparser.h"
+
40 
+
41 #endif //_usb_h_
UsbCore.h
parsetools.h
message.h
@@ -139,6 +140,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
max3421e.h
settings.h
confdescparser.h
+
sink_parser.h
printhex.h
hexdump.h
@@ -146,7 +148,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/_usb_core_8h.html b/_usb_core_8h.html index ed66af96..f6fbd19e 100644 --- a/_usb_core_8h.html +++ b/_usb_core_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: UsbCore.h File Reference @@ -31,7 +31,7 @@ - + @@ -1078,7 +1078,7 @@ Typedefs diff --git a/_usb_core_8h_source.html b/_usb_core_8h_source.html index 15087457..af1c3234 100644 --- a/_usb_core_8h_source.html +++ b/_usb_core_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: UsbCore.h Source File @@ -31,7 +31,7 @@ - + @@ -195,222 +195,245 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
104 
105 class USBDeviceConfig {
106 public:
-
107  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; }
-
108  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {return 0; }
-
109  virtual uint8_t Release() { return 0; }
-
110  virtual uint8_t Poll() { return 0; }
-
111  virtual uint8_t GetAddress() { return 0; }
-
112  virtual void ResetHubPort(uint8_t port) { return; } // Note used for hubs only!
-
113  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) { return false; }
-
114  virtual boolean DEVCLASSOK(uint8_t klass) { return false; }
-
115 };
-
116 
-
117 /* USB Setup Packet Structure */
-
118 typedef struct {
+
107 
+
108  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed) {
+
109  return 0;
+
110  }
+
111 
+
112  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
+
113  return 0;
+
114  }
+
115 
+
116  virtual uint8_t Release() {
+
117  return 0;
+
118  }
119 
-
120  union { // offset description
-
121  uint8_t bmRequestType; // 0 Bit-map of request type
-
122 
-
123  struct {
-
124  uint8_t recipient : 5; // Recipient of the request
-
125  uint8_t type : 2; // Type of request
-
126  uint8_t direction : 1; // Direction of data X-fer
-
127  } __attribute__((packed));
-
128  } ReqType_u;
-
129  uint8_t bRequest; // 1 Request
-
130 
-
131  union {
-
132  uint16_t wValue; // 2 Depends on bRequest
-
133 
-
134  struct {
-
135  uint8_t wValueLo;
-
136  uint8_t wValueHi;
-
137  } __attribute__((packed));
-
138  } wVal_u;
-
139  uint16_t wIndex; // 4 Depends on bRequest
-
140  uint16_t wLength; // 6 Depends on bRequest
-
141 }__attribute__((packed)) SETUP_PKT, *PSETUP_PKT;
-
142 
+
120  virtual uint8_t Poll() {
+
121  return 0;
+
122  }
+
123 
+
124  virtual uint8_t GetAddress() {
+
125  return 0;
+
126  }
+
127 
+
128  virtual void ResetHubPort(uint8_t port) {
+
129  return;
+
130  } // Note used for hubs only!
+
131 
+
132  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
+
133  return false;
+
134  }
+
135 
+
136  virtual boolean DEVCLASSOK(uint8_t klass) {
+
137  return false;
+
138  }
+
139 };
+
140 
+
141 /* USB Setup Packet Structure */
+
142 typedef struct {
143 
-
144 
-
145 // Base class for incoming data parser
+
144  union { // offset description
+
145  uint8_t bmRequestType; // 0 Bit-map of request type
146 
-
147 class USBReadParser {
-
148 public:
-
149  virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset) = 0;
-
150 };
-
151 
-
152 class USB : public MAX3421E {
-
153  AddressPoolImpl<USB_NUMDEVICES> addrPool;
-
154  USBDeviceConfig* devConfig[USB_NUMDEVICES];
-
155  uint8_t bmHubPre;
-
156 
-
157 public:
-
158  USB(void);
-
159 
-
160  void SetHubPreMask() {
-
161  bmHubPre |= bmHUBPRE;
-
162  };
-
163 
-
164  void ResetHubPreMask() {
-
165  bmHubPre &= (~bmHUBPRE);
-
166  };
+
147  struct {
+
148  uint8_t recipient : 5; // Recipient of the request
+
149  uint8_t type : 2; // Type of request
+
150  uint8_t direction : 1; // Direction of data X-fer
+
151  } __attribute__((packed));
+
152  } ReqType_u;
+
153  uint8_t bRequest; // 1 Request
+
154 
+
155  union {
+
156  uint16_t wValue; // 2 Depends on bRequest
+
157 
+
158  struct {
+
159  uint8_t wValueLo;
+
160  uint8_t wValueHi;
+
161  } __attribute__((packed));
+
162  } wVal_u;
+
163  uint16_t wIndex; // 4 Depends on bRequest
+
164  uint16_t wLength; // 6 Depends on bRequest
+
165 } __attribute__((packed)) SETUP_PKT, *PSETUP_PKT;
+
166 
167 
-
168  AddressPool& GetAddressPool() {
-
169  return(AddressPool&) addrPool;
-
170  };
-
171 
-
172  uint8_t RegisterDeviceClass(USBDeviceConfig *pdev) {
-
173  for(uint8_t i = 0; i < USB_NUMDEVICES; i++) {
-
174  if(!devConfig[i]) {
-
175  devConfig[i] = pdev;
-
176  return 0;
-
177  }
-
178  }
-
179  return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS;
-
180  };
-
181 
-
182  void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
-
183  addrPool.ForEachUsbDevice(pfunc);
-
184  };
-
185  uint8_t getUsbTaskState(void);
-
186  void setUsbTaskState(uint8_t state);
+
168 
+
169 // Base class for incoming data parser
+
170 
+
171 class USBReadParser {
+
172 public:
+
173  virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset) = 0;
+
174 };
+
175 
+
176 class USB : public MAX3421E {
+
177  AddressPoolImpl<USB_NUMDEVICES> addrPool;
+
178  USBDeviceConfig* devConfig[USB_NUMDEVICES];
+
179  uint8_t bmHubPre;
+
180 
+
181 public:
+
182  USB(void);
+
183 
+
184  void SetHubPreMask() {
+
185  bmHubPre |= bmHUBPRE;
+
186  };
187 
-
188  EpInfo* getEpInfoEntry(uint8_t addr, uint8_t ep);
-
189  uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr);
-
190 
-
191  /* Control requests */
-
192  uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr);
-
193  uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr);
-
194 
-
195  uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p);
-
196 
-
197  uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t* dataptr);
-
198  uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr);
-
199  uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value);
-
200 
-
201  uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr, boolean direction);
-
202  uint8_t ctrlStatus(uint8_t ep, boolean direction, uint16_t nak_limit);
-
203  uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data);
-
204  uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data);
-
205  uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit);
-
206 
-
207  void Task(void);
-
208 
-
209  uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed);
-
210  uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed);
-
211  uint8_t ReleaseDevice(uint8_t addr);
-
212 
-
213  uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
-
214  uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p);
-
215 
-
216 private:
-
217  void init();
-
218  uint8_t SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t &nak_limit);
-
219  uint8_t OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data);
-
220  uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data);
-
221  uint8_t AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed);
-
222 };
-
223 
-
224 #if 0 //defined(USB_METHODS_INLINE)
-
225 //get device descriptor
-
226 
-
227 inline uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
-
228  return( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, dataptr));
-
229 }
-
230 //get configuration descriptor
-
231 
-
232 inline uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
-
233  return( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, dataptr));
-
234 }
-
235 //get string descriptor
+
188  void ResetHubPreMask() {
+
189  bmHubPre &= (~bmHUBPRE);
+
190  };
+
191 
+
192  AddressPool& GetAddressPool() {
+
193  return (AddressPool&)addrPool;
+
194  };
+
195 
+
196  uint8_t RegisterDeviceClass(USBDeviceConfig *pdev) {
+
197  for(uint8_t i = 0; i < USB_NUMDEVICES; i++) {
+
198  if(!devConfig[i]) {
+
199  devConfig[i] = pdev;
+
200  return 0;
+
201  }
+
202  }
+
203  return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS;
+
204  };
+
205 
+
206  void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
+
207  addrPool.ForEachUsbDevice(pfunc);
+
208  };
+
209  uint8_t getUsbTaskState(void);
+
210  void setUsbTaskState(uint8_t state);
+
211 
+
212  EpInfo* getEpInfoEntry(uint8_t addr, uint8_t ep);
+
213  uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr);
+
214 
+
215  /* Control requests */
+
216  uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr);
+
217  uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr);
+
218 
+
219  uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser *p);
+
220 
+
221  uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t* dataptr);
+
222  uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr);
+
223  uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value);
+
224 
+
225  uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr, boolean direction);
+
226  uint8_t ctrlStatus(uint8_t ep, boolean direction, uint16_t nak_limit);
+
227  uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data);
+
228  uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data);
+
229  uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit);
+
230 
+
231  void Task(void);
+
232 
+
233  uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed);
+
234  uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed);
+
235  uint8_t ReleaseDevice(uint8_t addr);
236 
-
237 inline uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t nuint8_ts, uint8_t index, uint16_t langid, uint8_t* dataptr) {
-
238  return( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, nuint8_ts, dataptr));
-
239 }
-
240 //set address
-
241 
-
242 inline uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
-
243  return( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, NULL));
-
244 }
-
245 //set configuration
-
246 
-
247 inline uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
-
248  return( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, NULL));
-
249 }
+
237  uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
+
238  uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBReadParser *p);
+
239 
+
240 private:
+
241  void init();
+
242  uint8_t SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t &nak_limit);
+
243  uint8_t OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data);
+
244  uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data);
+
245  uint8_t AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed);
+
246 };
+
247 
+
248 #if 0 //defined(USB_METHODS_INLINE)
+
249 //get device descriptor
250 
-
251 #endif // defined(USB_METHODS_INLINE)
-
252 
-
253 #endif /* USBCORE_H */
-
254 
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
251 inline uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
+
252  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, USB_DESCRIPTOR_DEVICE, 0x0000, nbytes, dataptr));
+
253 }
+
254 //get configuration descriptor
+
255 
+
256 inline uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
+
257  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, conf, USB_DESCRIPTOR_CONFIGURATION, 0x0000, nbytes, dataptr));
+
258 }
+
259 //get string descriptor
+
260 
+
261 inline uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t nuint8_ts, uint8_t index, uint16_t langid, uint8_t* dataptr) {
+
262  return ( ctrlReq(addr, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, index, USB_DESCRIPTOR_STRING, langid, nuint8_ts, dataptr));
+
263 }
+
264 //set address
+
265 
+
266 inline uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
+
267  return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, NULL));
+
268 }
+
269 //set configuration
+
270 
+
271 inline uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
+
272  return ( ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, NULL));
+
273 }
+
274 
+
275 #endif // defined(USB_METHODS_INLINE)
+
276 
+
277 #endif /* USBCORE_H */
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
AddressPool
Definition: address.h:83
-
SETUP_PKT::wValue
uint16_t wValue
Definition: UsbCore.h:132
-
USBDeviceConfig::Poll
virtual uint8_t Poll()
Definition: UsbCore.h:110
+
SETUP_PKT::wValue
uint16_t wValue
Definition: UsbCore.h:156
+
USBDeviceConfig::Poll
virtual uint8_t Poll()
Definition: UsbCore.h:120
bmHUBPRE
#define bmHUBPRE
Definition: max3421e.h:170
-
USBDeviceConfig::GetAddress
virtual uint8_t GetAddress()
Definition: UsbCore.h:111
+
USBDeviceConfig::GetAddress
virtual uint8_t GetAddress()
Definition: UsbCore.h:124
USB::getEpInfoEntry
EpInfo * getEpInfoEntry(uint8_t addr, uint8_t ep)
Definition: Usb.cpp:44
USB_DESCRIPTOR_STRING
#define USB_DESCRIPTOR_STRING
Definition: usb_ch9.h:65
-
SETUP_PKT::wLength
uint16_t wLength
Definition: UsbCore.h:140
+
SETUP_PKT::wLength
uint16_t wLength
Definition: UsbCore.h:164
MAX3421e
Definition: usbhost.h:81
USB_REQUEST_GET_DESCRIPTOR
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb_ch9.h:37
USB_DESCRIPTOR_DEVICE
#define USB_DESCRIPTOR_DEVICE
Definition: usb_ch9.h:63
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
USB_NUMDEVICES
#define USB_NUMDEVICES
Definition: UsbCore.h:83
USBDeviceConfig
Definition: UsbCore.h:105
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
USBDeviceConfig::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:108
-
SETUP_PKT::bmRequestType
uint8_t bmRequestType
Definition: UsbCore.h:121
+
USBDeviceConfig::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:112
+
SETUP_PKT::bmRequestType
uint8_t bmRequestType
Definition: UsbCore.h:145
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
USB_DESCRIPTOR_CONFIGURATION
#define USB_DESCRIPTOR_CONFIGURATION
Definition: usb_ch9.h:64
-
USB::ResetHubPreMask
void ResetHubPreMask()
Definition: UsbCore.h:164
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
USB::ResetHubPreMask
void ResetHubPreMask()
Definition: UsbCore.h:188
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
USB::ctrlStatus
uint8_t ctrlStatus(uint8_t ep, boolean direction, uint16_t nak_limit)
USB::USB
USB(void)
Definition: Usb.cpp:25
UsbDeviceHandleFunc
void(* UsbDeviceHandleFunc)(UsbDevice *pdev)
Definition: address.h:90
-
SETUP_PKT::wIndex
uint16_t wIndex
Definition: UsbCore.h:139
-
USB::SetHubPreMask
void SetHubPreMask()
Definition: UsbCore.h:160
+
SETUP_PKT::wIndex
uint16_t wIndex
Definition: UsbCore.h:163
+
USB::SetHubPreMask
void SetHubPreMask()
Definition: UsbCore.h:184
EpInfo
Definition: address.h:32
USB::setUsbTaskState
void setUsbTaskState(uint8_t state)
Definition: Usb.cpp:40
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
bmREQ_GET_DESCR
#define bmREQ_GET_DESCR
Definition: UsbCore.h:31
-
USBDeviceConfig::ResetHubPort
virtual void ResetHubPort(uint8_t port)
Definition: UsbCore.h:112
+
USBDeviceConfig::ResetHubPort
virtual void ResetHubPort(uint8_t port)
Definition: UsbCore.h:128
USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS
#define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS
Definition: UsbCore.h:63
-
USB::getStrDescr
uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t *dataptr)
Definition: Usb.cpp:788
+
USB::getStrDescr
uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t *dataptr)
Definition: Usb.cpp:791
USB_REQUEST_SET_ADDRESS
#define USB_REQUEST_SET_ADDRESS
Definition: usb_ch9.h:36
MAX3421E
MAX3421e< P10, P9 > MAX3421E
Definition: UsbCore.h:27
-
USBReadParser
Definition: UsbCore.h:147
-
SETUP_PKT
Definition: UsbCore.h:118
+
USBReadParser
Definition: UsbCore.h:171
+
SETUP_PKT
Definition: UsbCore.h:142
USB::getUsbTaskState
uint8_t getUsbTaskState(void)
Definition: Usb.cpp:36
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
-
USB::Task
void Task(void)
Definition: Usb.cpp:422
+
USB::Task
void Task(void)
Definition: Usb.cpp:424
AddressPoolImpl< USB_NUMDEVICES >
-
USBDeviceConfig::DEVCLASSOK
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: UsbCore.h:114
-
AddressPoolImpl::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: address.h:185
+
USBDeviceConfig::DEVCLASSOK
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: UsbCore.h:136
+
AddressPoolImpl::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: address.h:191
USB::ctrlData
uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr, boolean direction)
-
USB::dispatchPkt
uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit)
Definition: Usb.cpp:374
-
USBDeviceConfig::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:107
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB::Configuring
uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:650
-
USB
Definition: UsbCore.h:152
-
USBDeviceConfig::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: UsbCore.h:113
-
SETUP_PKT::bRequest
uint8_t bRequest
Definition: UsbCore.h:129
-
USBDeviceConfig::Release
virtual uint8_t Release()
Definition: UsbCore.h:109
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
USB::dispatchPkt
uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit)
Definition: Usb.cpp:376
+
USBDeviceConfig::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: UsbCore.h:108
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB::Configuring
uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:652
+
USB
Definition: UsbCore.h:176
+
USBDeviceConfig::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: UsbCore.h:132
+
SETUP_PKT::bRequest
uint8_t bRequest
Definition: UsbCore.h:153
+
USBDeviceConfig::Release
virtual uint8_t Release()
Definition: UsbCore.h:116
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
bmREQ_SET
#define bmREQ_SET
Definition: UsbCore.h:32
-
USB::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: UsbCore.h:182
+
USB::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: UsbCore.h:206
USB_REQUEST_SET_CONFIGURATION
#define USB_REQUEST_SET_CONFIGURATION
Definition: usb_ch9.h:40
-
SETUP_PKT::wValueHi
uint8_t wValueHi
Definition: UsbCore.h:136
-
USB::DefaultAddressing
uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:528
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
-
SETUP_PKT::wValueLo
uint8_t wValueLo
Definition: UsbCore.h:135
-
USB::ReleaseDevice
uint8_t ReleaseDevice(uint8_t addr)
Definition: Usb.cpp:744
+
SETUP_PKT::wValueHi
uint8_t wValueHi
Definition: UsbCore.h:160
+
USB::DefaultAddressing
uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed)
Definition: Usb.cpp:530
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
+
SETUP_PKT::wValueLo
uint8_t wValueLo
Definition: UsbCore.h:159
+
USB::ReleaseDevice
uint8_t ReleaseDevice(uint8_t addr)
Definition: Usb.cpp:746
diff --git a/_wii_8cpp.html b/_wii_8cpp.html index b2d8b346..47e873f2 100644 --- a/_wii_8cpp.html +++ b/_wii_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Wii.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,24 +104,25 @@ Include dependency graph for Wii.cpp: - - - - - - + + + + + +

Variables

const uint8_t LEDS []
 
const uint32_t BUTTONS []
 
const uint32_t PROCONTROLLERBUTTONS []
 
const uint8_t WII_LEDS []
 
const uint32_t WII_BUTTONS []
 
const uint32_t WII_PROCONTROLLER_BUTTONS []
 

Variable Documentation

- +
- +
const uint8_t LEDS[]const uint8_t WII_LEDS[]
Initial value:
= {
+
0x00,
0x10,
0x20,
0x40,
@@ -132,19 +133,19 @@ Variables
0xC0,
0xD0,
0xE0,
-
0xF0
+
0xF0,
}

Definition at line 25 of file Wii.cpp.

- +
- +
const uint32_t BUTTONS[]const uint32_t WII_BUTTONS[]
@@ -165,19 +166,19 @@ Variables
0x20000,
0x00400,
-
0x00800
+
0x00800,
}
-

Definition at line 39 of file Wii.cpp.

+

Definition at line 40 of file Wii.cpp.

- +
- +
const uint32_t PROCONTROLLERBUTTONS[]const uint32_t WII_PROCONTROLLER_BUTTONS[]
@@ -204,10 +205,10 @@ Variables
0x00020,
0x00002,
0x08000,
-
0x00400
+
0x00400,
}
-

Definition at line 58 of file Wii.cpp.

+

Definition at line 59 of file Wii.cpp.

@@ -216,7 +217,7 @@ Variables diff --git a/_wii_8cpp_source.html b/_wii_8cpp_source.html index 5bd7b8b5..175abfe1 100644 --- a/_wii_8cpp_source.html +++ b/_wii_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Wii.cpp Source File @@ -31,7 +31,7 @@ - + @@ -113,1308 +113,1312 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
22 //#define EXTRADEBUG // Uncomment to get even more debugging data
23 //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers
24 
-
25 const uint8_t LEDS[] PROGMEM = {
-
26  0x10, // LED1
-
27  0x20, // LED2
-
28  0x40, // LED3
-
29  0x80, // LED4
-
30 
-
31  0x90, // LED5
-
32  0xA0, // LED6
-
33  0xC0, // LED7
-
34  0xD0, // LED8
-
35  0xE0, // LED9
-
36  0xF0 // LED10
-
37 };
-
38 
-
39 const uint32_t BUTTONS[] PROGMEM = {
-
40  0x00008, // UP
-
41  0x00002, // RIGHT
-
42  0x00004, // DOWN
-
43  0x00001, // LEFT
-
44 
-
45  0, // Skip
-
46  0x00010, // PLUS
-
47  0x00100, // TWO
-
48  0x00200, // ONE
-
49 
-
50  0x01000, // MINUS
-
51  0x08000, // HOME
-
52  0x10000, // Z
-
53  0x20000, // C
-
54 
-
55  0x00400, // B
-
56  0x00800 // A
-
57 };
-
58 const uint32_t PROCONTROLLERBUTTONS[] PROGMEM = {
-
59  0x00100, // UP
-
60  0x00080, // RIGHT
-
61  0x00040, // DOWN
-
62  0x00200, // LEFT
-
63 
-
64  0, // Skip
-
65  0x00004, // PLUS
-
66  0x20000, // L3
-
67  0x10000, // R3
-
68 
-
69  0x00010, // MINUS
-
70  0x00008, // HOME
-
71  0, 0, // Skip
-
72 
-
73  0x04000, // B
-
74  0x01000, // A
-
75  0x00800, // X
-
76  0x02000, // Y
-
77 
-
78  0x00020, // L
-
79  0x00002, // R
-
80  0x08000, // ZL
-
81  0x00400 // ZR
-
82 };
-
83 
-
84 WII::WII(BTD *p, bool pair) :
-
85 pBtd(p) // pointer to USB class instance - mandatory
-
86 {
-
87  if (pBtd)
-
88  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
-
89 
-
90  pBtd->pairWithWii = pair;
-
91 
-
92  HIDBuffer[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
93 
-
94  /* Set device cid for the control and intterrupt channelse - LSB */
-
95  control_dcid[0] = 0x60; //0x0060
-
96  control_dcid[1] = 0x00;
-
97  interrupt_dcid[0] = 0x61; //0x0061
-
98  interrupt_dcid[1] = 0x00;
-
99 
-
100  Reset();
-
101 }
-
102 
-
103 void WII::Reset() {
-
104  wiimoteConnected = false;
-
105  nunchuckConnected = false;
-
106  motionPlusConnected = false;
-
107  activateNunchuck = false;
-
108  motionValuesReset = false;
-
109  activeConnection = false;
-
110  motionPlusInside = false;
-
111  pBtd->wiiUProController = false;
-
112  wiiUProControllerConnected = false;
-
113  l2cap_event_flag = 0; // Reset flags
-
114  l2cap_state = L2CAP_WAIT;
-
115 }
-
116 
-
117 void WII::disconnect() { // Use this void to disconnect any of the controllers
-
118  if (!motionPlusInside) { // The old Wiimote needs a delay after the first command or it will automatically reconnect
-
119  if (motionPlusConnected) {
-
120 #ifdef DEBUG_USB_HOST
-
121  Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80);
-
122 #endif
-
123  initExtension1(); // This will disable the Motion Plus extension
-
124  }
-
125  timer = millis() + 1000; // We have to wait for the message before the rest of the channels can be deactivated
-
126  } else
-
127  timer = millis(); // Don't wait
-
128  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
-
129  pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
-
130  Reset();
-
131  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
-
132 }
-
133 
-
134 void WII::ACLData(uint8_t* l2capinbuf) {
-
135  if (!pBtd->l2capConnectionClaimed && pBtd->incomingWii && !wiimoteConnected && !activeConnection) {
-
136  if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
137  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
-
138  motionPlusInside = pBtd->motionPlusInside;
-
139  pBtd->incomingWii = false;
-
140  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
-
141  activeConnection = true;
-
142  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
143  l2cap_state = L2CAP_WAIT;
-
144  }
-
145  }
-
146  }
-
147  if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
-
148  if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
-
149  if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
-
150 #ifdef DEBUG_USB_HOST
-
151  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
-
152  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
153  Notify(PSTR(" "), 0x80);
-
154  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
25 const uint8_t WII_LEDS[] PROGMEM = {
+
26  0x00, // OFF
+
27  0x10, // LED1
+
28  0x20, // LED2
+
29  0x40, // LED3
+
30  0x80, // LED4
+
31 
+
32  0x90, // LED5
+
33  0xA0, // LED6
+
34  0xC0, // LED7
+
35  0xD0, // LED8
+
36  0xE0, // LED9
+
37  0xF0, // LED10
+
38 };
+
39 
+
40 const uint32_t WII_BUTTONS[] PROGMEM = {
+
41  0x00008, // UP
+
42  0x00002, // RIGHT
+
43  0x00004, // DOWN
+
44  0x00001, // LEFT
+
45 
+
46  0, // Skip
+
47  0x00010, // PLUS
+
48  0x00100, // TWO
+
49  0x00200, // ONE
+
50 
+
51  0x01000, // MINUS
+
52  0x08000, // HOME
+
53  0x10000, // Z
+
54  0x20000, // C
+
55 
+
56  0x00400, // B
+
57  0x00800, // A
+
58 };
+
59 const uint32_t WII_PROCONTROLLER_BUTTONS[] PROGMEM = {
+
60  0x00100, // UP
+
61  0x00080, // RIGHT
+
62  0x00040, // DOWN
+
63  0x00200, // LEFT
+
64 
+
65  0, // Skip
+
66  0x00004, // PLUS
+
67  0x20000, // L3
+
68  0x10000, // R3
+
69 
+
70  0x00010, // MINUS
+
71  0x00008, // HOME
+
72  0, 0, // Skip
+
73 
+
74  0x04000, // B
+
75  0x01000, // A
+
76  0x00800, // X
+
77  0x02000, // Y
+
78 
+
79  0x00020, // L
+
80  0x00002, // R
+
81  0x08000, // ZL
+
82  0x00400, // ZR
+
83 };
+
84 
+
85 WII::WII(BTD *p, bool pair) :
+
86 pBtd(p) // pointer to USB class instance - mandatory
+
87 {
+
88  if(pBtd)
+
89  pBtd->registerServiceClass(this); // Register it as a Bluetooth service
+
90 
+
91  pBtd->pairWithWii = pair;
+
92 
+
93  HIDBuffer[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
94 
+
95  /* Set device cid for the control and intterrupt channelse - LSB */
+
96  control_dcid[0] = 0x60; //0x0060
+
97  control_dcid[1] = 0x00;
+
98  interrupt_dcid[0] = 0x61; //0x0061
+
99  interrupt_dcid[1] = 0x00;
+
100 
+
101  Reset();
+
102 }
+
103 
+
104 void WII::Reset() {
+
105  wiimoteConnected = false;
+
106  nunchuckConnected = false;
+
107  motionPlusConnected = false;
+
108  activateNunchuck = false;
+
109  motionValuesReset = false;
+
110  activeConnection = false;
+
111  motionPlusInside = false;
+
112  pBtd->wiiUProController = false;
+
113  wiiUProControllerConnected = false;
+
114  l2cap_event_flag = 0; // Reset flags
+
115  l2cap_state = L2CAP_WAIT;
+
116 }
+
117 
+
118 void WII::disconnect() { // Use this void to disconnect any of the controllers
+
119  if(!motionPlusInside) { // The old Wiimote needs a delay after the first command or it will automatically reconnect
+
120  if(motionPlusConnected) {
+
121 #ifdef DEBUG_USB_HOST
+
122  Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80);
+
123 #endif
+
124  initExtension1(); // This will disable the Motion Plus extension
+
125  }
+
126  timer = millis() + 1000; // We have to wait for the message before the rest of the channels can be deactivated
+
127  } else
+
128  timer = millis(); // Don't wait
+
129  // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
+
130  pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
+
131  Reset();
+
132  l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
+
133 }
+
134 
+
135 void WII::ACLData(uint8_t* l2capinbuf) {
+
136  if(!pBtd->l2capConnectionClaimed && pBtd->incomingWii && !wiimoteConnected && !activeConnection) {
+
137  if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
138  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
139  motionPlusInside = pBtd->motionPlusInside;
+
140  pBtd->incomingWii = false;
+
141  pBtd->l2capConnectionClaimed = true; // Claim that the incoming connection belongs to this service
+
142  activeConnection = true;
+
143  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
+
144  l2cap_state = L2CAP_WAIT;
+
145  }
+
146  }
+
147  }
+
148  //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
+
149  if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
+
150  if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
+
151  if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
+
152 #ifdef DEBUG_USB_HOST
+
153  Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
+
154  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
155  Notify(PSTR(" "), 0x80);
-
156  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
+
156  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
157  Notify(PSTR(" "), 0x80);
-
158  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
+
158  D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
159  Notify(PSTR(" "), 0x80);
-
160  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
160  D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
161  Notify(PSTR(" "), 0x80);
-
162  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
163 #endif
-
164  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
-
165  if (((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
-
166  if (l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) { // Success
-
167  //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
-
168  identifier = l2capinbuf[9];
-
169  control_scid[0] = l2capinbuf[12];
-
170  control_scid[1] = l2capinbuf[13];
-
171  l2cap_event_flag |= L2CAP_FLAG_CONTROL_CONNECTED;
-
172  } else if (l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
-
173  //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
-
174  identifier = l2capinbuf[9];
-
175  interrupt_scid[0] = l2capinbuf[12];
-
176  interrupt_scid[1] = l2capinbuf[13];
-
177  l2cap_event_flag |= L2CAP_FLAG_INTERRUPT_CONNECTED;
-
178  }
-
179  }
-
180  } else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
-
181 #ifdef EXTRADEBUG
-
182  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
-
183  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
184  Notify(PSTR(" "), 0x80);
-
185  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
186  Notify(PSTR(" SCID: "), 0x80);
-
187  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
-
188  Notify(PSTR(" "), 0x80);
-
189  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
190  Notify(PSTR(" Identifier: "), 0x80);
-
191  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
192 #endif
-
193  if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
-
194  identifier = l2capinbuf[9];
-
195  control_scid[0] = l2capinbuf[14];
-
196  control_scid[1] = l2capinbuf[15];
-
197  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_CONTROL_REQUEST;
-
198  } else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
-
199  identifier = l2capinbuf[9];
-
200  interrupt_scid[0] = l2capinbuf[14];
-
201  interrupt_scid[1] = l2capinbuf[15];
-
202  l2cap_event_flag |= L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST;
-
203  }
-
204  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
-
205  if ((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
-
206  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
207  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
-
208  identifier = l2capinbuf[9];
-
209  l2cap_event_flag |= L2CAP_FLAG_CONFIG_CONTROL_SUCCESS;
-
210  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
211  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
-
212  identifier = l2capinbuf[9];
-
213  l2cap_event_flag |= L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS;
-
214  }
-
215  }
-
216  } else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
-
217  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
218  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
-
219  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
-
220  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
221  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
-
222  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
-
223  }
-
224  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
-
225  if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
-
226 #ifdef DEBUG_USB_HOST
-
227  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
-
228 #endif
-
229  identifier = l2capinbuf[9];
-
230  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
-
231  Reset();
-
232  } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
-
233 #ifdef DEBUG_USB_HOST
-
234  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
-
235 #endif
-
236  identifier = l2capinbuf[9];
-
237  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
-
238  Reset();
-
239  }
-
240  } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
-
241  if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
-
242  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
-
243  identifier = l2capinbuf[9];
-
244  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE;
-
245  } else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
-
246  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
-
247  identifier = l2capinbuf[9];
-
248  l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE;
-
249  }
-
250  }
-
251 #ifdef EXTRADEBUG
-
252  else {
-
253  identifier = l2capinbuf[9];
-
254  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
-
255  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
-
256  }
-
257 #endif
-
258  } else if (l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
-
259  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
-
260  if (l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
-
261  if ((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || (l2capinbuf[9] >= 0x30 && l2capinbuf[9] <= 0x37) || l2capinbuf[9] == 0x3e || l2capinbuf[9] == 0x3f) { // These reports include the buttons
-
262  if ((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33) // These reports have no extensions bytes
-
263  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
-
264  else if (wiiUProControllerConnected)
-
265  ButtonState = (uint32_t)(((~l2capinbuf[23]) & 0xFE) | ((uint16_t)(~l2capinbuf[24]) << 8) | ((uint32_t)((~l2capinbuf[25]) & 0x03) << 16));
-
266  else if (motionPlusConnected) {
-
267  if (l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus
-
268  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
-
269  else if (nunchuckConnected) // Update if it's a report from the Nunchuck
-
270  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14));
-
271  //else if(classicControllerConnected) // Update if it's a report from the Classic Controller
-
272  } else if (nunchuckConnected) // The Nunchuck is directly connected
-
273  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x03) << 16));
-
274  //else if(classicControllerConnected) // The Classic Controller is directly connected
-
275  else if (!unknownExtensionConnected)
-
276  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
-
277 #ifdef PRINTREPORT
-
278  Notify(PSTR("ButtonState: "), 0x80);
-
279  D_PrintHex<uint32_t > (ButtonState, 0x80);
-
280  Notify(PSTR("\r\n"), 0x80);
-
281 #endif
-
282  if (ButtonState != OldButtonState) {
-
283  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
-
284  OldButtonState = ButtonState;
-
285  }
-
286  }
-
287  if (l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33 || l2capinbuf[9] == 0x35 || l2capinbuf[9] == 0x37) { // Read the accelerometer
-
288  accXwiimote = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5)) - 500;
-
289  accYwiimote = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4)) - 500;
-
290  accZwiimote = ((l2capinbuf[14] << 2) | (l2capinbuf[11] & 0x40 >> 5)) - 500;
-
291  }
-
292  switch (l2capinbuf[9]) {
-
293  case 0x20: // Status Information - (a1) 20 BB BB LF 00 00 VV
-
294 #ifdef EXTRADEBUG
-
295  Notify(PSTR("\r\nStatus report was received"), 0x80);
-
296 #endif
-
297  wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4)
-
298  batteryLevel = l2capinbuf[15]; // Update battery level
-
299 #ifdef DEBUG_USB_HOST
-
300  if (l2capinbuf[12] & 0x01)
-
301  Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80);
-
302 #endif
-
303  if (checkExtension) { // If this is false it means that the user must have called getBatteryLevel()
-
304  if (l2capinbuf[12] & 0x02) { // Check if a extension is connected
-
305 #ifdef DEBUG_USB_HOST
-
306  if (!unknownExtensionConnected)
-
307  Notify(PSTR("\r\nExtension connected"), 0x80);
-
308 #endif
-
309  unknownExtensionConnected = true;
-
310 #ifdef WIICAMERA
-
311  if (!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
-
312 #endif
-
313  setReportMode(false, 0x35); // Also read the extension
-
314  } else {
-
315 #ifdef DEBUG_USB_HOST
-
316  Notify(PSTR("\r\nExtension disconnected"), 0x80);
-
317 #endif
-
318  if (motionPlusConnected) {
-
319 #ifdef DEBUG_USB_HOST
-
320  Notify(PSTR(" - from Motion Plus"), 0x80);
-
321 #endif
-
322  l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED;
-
323  if (!activateNunchuck) // If it's already trying to initialize the Nunchuck don't set it to false
-
324  nunchuckConnected = false;
-
325  //else if(classicControllerConnected)
-
326  } else if (nunchuckConnected) {
-
327 #ifdef DEBUG_USB_HOST
-
328  Notify(PSTR(" - Nunchuck"), 0x80);
-
329 #endif
-
330  nunchuckConnected = false; // It must be the Nunchuck controller then
-
331  l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED;
-
332  onInit();
-
333  setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer
-
334  } else
+
162  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
163  Notify(PSTR(" "), 0x80);
+
164  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
165 #endif
+
166  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_RESPONSE) {
+
167  if(((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) == SUCCESSFUL)) { // Success
+
168  if(l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) {
+
169  //Notify(PSTR("\r\nHID Control Connection Complete"), 0x80);
+
170  identifier = l2capinbuf[9];
+
171  control_scid[0] = l2capinbuf[12];
+
172  control_scid[1] = l2capinbuf[13];
+
173  l2cap_set_flag(L2CAP_FLAG_CONTROL_CONNECTED);
+
174  } else if(l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
+
175  //Notify(PSTR("\r\nHID Interrupt Connection Complete"), 0x80);
+
176  identifier = l2capinbuf[9];
+
177  interrupt_scid[0] = l2capinbuf[12];
+
178  interrupt_scid[1] = l2capinbuf[13];
+
179  l2cap_set_flag(L2CAP_FLAG_INTERRUPT_CONNECTED);
+
180  }
+
181  }
+
182  } else if(l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) {
+
183 #ifdef EXTRADEBUG
+
184  Notify(PSTR("\r\nL2CAP Connection Request - PSM: "), 0x80);
+
185  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
186  Notify(PSTR(" "), 0x80);
+
187  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
188  Notify(PSTR(" SCID: "), 0x80);
+
189  D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
+
190  Notify(PSTR(" "), 0x80);
+
191  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
192  Notify(PSTR(" Identifier: "), 0x80);
+
193  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
194 #endif
+
195  if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_CTRL_PSM) {
+
196  identifier = l2capinbuf[9];
+
197  control_scid[0] = l2capinbuf[14];
+
198  control_scid[1] = l2capinbuf[15];
+
199  l2cap_set_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST);
+
200  } else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) == HID_INTR_PSM) {
+
201  identifier = l2capinbuf[9];
+
202  interrupt_scid[0] = l2capinbuf[14];
+
203  interrupt_scid[1] = l2capinbuf[15];
+
204  l2cap_set_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST);
+
205  }
+
206  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_RESPONSE) {
+
207  if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) { // Success
+
208  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
209  //Notify(PSTR("\r\nHID Control Configuration Complete"), 0x80);
+
210  identifier = l2capinbuf[9];
+
211  l2cap_set_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS);
+
212  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
213  //Notify(PSTR("\r\nHID Interrupt Configuration Complete"), 0x80);
+
214  identifier = l2capinbuf[9];
+
215  l2cap_set_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS);
+
216  }
+
217  }
+
218  } else if(l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
+
219  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
220  //Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
+
221  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], control_scid);
+
222  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
223  //Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
+
224  pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], interrupt_scid);
+
225  }
+
226  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
+
227  if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
+
228 #ifdef DEBUG_USB_HOST
+
229  Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
+
230 #endif
+
231  identifier = l2capinbuf[9];
+
232  pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
+
233  Reset();
+
234  } else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
+
235 #ifdef DEBUG_USB_HOST
+
236  Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
+
237 #endif
+
238  identifier = l2capinbuf[9];
+
239  pBtd->l2cap_disconnection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid);
+
240  Reset();
+
241  }
+
242  } else if(l2capinbuf[8] == L2CAP_CMD_DISCONNECT_RESPONSE) {
+
243  if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
+
244  //Notify(PSTR("\r\nDisconnect Response: Control Channel"), 0x80);
+
245  identifier = l2capinbuf[9];
+
246  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE);
+
247  } else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
+
248  //Notify(PSTR("\r\nDisconnect Response: Interrupt Channel"), 0x80);
+
249  identifier = l2capinbuf[9];
+
250  l2cap_set_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE);
+
251  }
+
252  }
+
253 #ifdef EXTRADEBUG
+
254  else {
+
255  identifier = l2capinbuf[9];
+
256  Notify(PSTR("\r\nL2CAP Unknown Signaling Command: "), 0x80);
+
257  D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
+
258  }
+
259 #endif
+
260  } else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) { // l2cap_interrupt
+
261  //Notify(PSTR("\r\nL2CAP Interrupt"), 0x80);
+
262  if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
+
263  if((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || (l2capinbuf[9] >= 0x30 && l2capinbuf[9] <= 0x37) || l2capinbuf[9] == 0x3e || l2capinbuf[9] == 0x3f) { // These reports include the buttons
+
264  if((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33) // These reports have no extensions bytes
+
265  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
+
266  else if(wiiUProControllerConnected)
+
267  ButtonState = (uint32_t)(((~l2capinbuf[23]) & 0xFE) | ((uint16_t)(~l2capinbuf[24]) << 8) | ((uint32_t)((~l2capinbuf[25]) & 0x03) << 16));
+
268  else if(motionPlusConnected) {
+
269  if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus
+
270  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
+
271  else if(nunchuckConnected) // Update if it's a report from the Nunchuck
+
272  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14));
+
273  //else if(classicControllerConnected) // Update if it's a report from the Classic Controller
+
274  } else if(nunchuckConnected) // The Nunchuck is directly connected
+
275  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x03) << 16));
+
276  //else if(classicControllerConnected) // The Classic Controller is directly connected
+
277  else if(!unknownExtensionConnected)
+
278  ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
+
279 #ifdef PRINTREPORT
+
280  Notify(PSTR("ButtonState: "), 0x80);
+
281  D_PrintHex<uint32_t > (ButtonState, 0x80);
+
282  Notify(PSTR("\r\n"), 0x80);
+
283 #endif
+
284  if(ButtonState != OldButtonState) {
+
285  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
+
286  OldButtonState = ButtonState;
+
287  }
+
288  }
+
289  if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33 || l2capinbuf[9] == 0x35 || l2capinbuf[9] == 0x37) { // Read the accelerometer
+
290  accXwiimote = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5)) - 500;
+
291  accYwiimote = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4)) - 500;
+
292  accZwiimote = ((l2capinbuf[14] << 2) | (l2capinbuf[11] & 0x40 >> 5)) - 500;
+
293  }
+
294  switch(l2capinbuf[9]) {
+
295  case 0x20: // Status Information - (a1) 20 BB BB LF 00 00 VV
+
296 #ifdef EXTRADEBUG
+
297  Notify(PSTR("\r\nStatus report was received"), 0x80);
+
298 #endif
+
299  wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4)
+
300  batteryLevel = l2capinbuf[15]; // Update battery level
+
301 #ifdef DEBUG_USB_HOST
+
302  if(l2capinbuf[12] & 0x01)
+
303  Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80);
+
304 #endif
+
305  if(checkExtension) { // If this is false it means that the user must have called getBatteryLevel()
+
306  if(l2capinbuf[12] & 0x02) { // Check if a extension is connected
+
307 #ifdef DEBUG_USB_HOST
+
308  if(!unknownExtensionConnected)
+
309  Notify(PSTR("\r\nExtension connected"), 0x80);
+
310 #endif
+
311  unknownExtensionConnected = true;
+
312 #ifdef WIICAMERA
+
313  if(!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
+
314 #endif
+
315  setReportMode(false, 0x35); // Also read the extension
+
316  } else {
+
317 #ifdef DEBUG_USB_HOST
+
318  Notify(PSTR("\r\nExtension disconnected"), 0x80);
+
319 #endif
+
320  if(motionPlusConnected) {
+
321 #ifdef DEBUG_USB_HOST
+
322  Notify(PSTR(" - from Motion Plus"), 0x80);
+
323 #endif
+
324  wii_clear_flag(WII_FLAG_NUNCHUCK_CONNECTED);
+
325  if(!activateNunchuck) // If it's already trying to initialize the Nunchuck don't set it to false
+
326  nunchuckConnected = false;
+
327  //else if(classicControllerConnected)
+
328  } else if(nunchuckConnected) {
+
329 #ifdef DEBUG_USB_HOST
+
330  Notify(PSTR(" - Nunchuck"), 0x80);
+
331 #endif
+
332  nunchuckConnected = false; // It must be the Nunchuck controller then
+
333  wii_clear_flag(WII_FLAG_NUNCHUCK_CONNECTED);
+
334  onInit();
335  setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer
-
336  }
-
337  } else
-
338  checkExtension = true; // Check for extensions by default
-
339  break;
-
340  case 0x21: // Read Memory Data
-
341  if ((l2capinbuf[12] & 0x0F) == 0) { // No error
-
342  // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers
-
343  if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) {
-
344 #ifdef DEBUG_USB_HOST
-
345  Notify(PSTR("\r\nNunchuck connected"), 0x80);
-
346 #endif
-
347  l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED;
-
348  } else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) {
-
349 #ifdef DEBUG_USB_HOST
-
350  Notify(PSTR("\r\nMotion Plus connected"), 0x80);
-
351 #endif
-
352  l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED;
-
353  } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) {
-
354 #ifdef DEBUG_USB_HOST
-
355  Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80);
-
356 #endif
-
357  motionPlusConnected = true;
-
358 #ifdef WIICAMERA
-
359  if (!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
-
360 #endif
-
361  setReportMode(false, 0x35); // Also read the extension
-
362  } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) {
-
363 #ifdef DEBUG_USB_HOST
-
364  Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80);
-
365 #endif
-
366  activateNunchuck = false;
-
367  motionPlusConnected = true;
-
368  nunchuckConnected = true;
-
369 #ifdef WIICAMERA
-
370  if (!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
-
371 #endif
-
372  setReportMode(false, 0x35); // Also read the extension
-
373  } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) {
-
374 #ifdef DEBUG_USB_HOST
-
375  Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80);
-
376  Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80);
-
377 #endif
-
378  stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE"
-
379  } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) {
-
380 #ifdef DEBUG_USB_HOST
-
381  Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80);
-
382 #endif
-
383  wiiUProControllerConnected = true;
-
384  }
-
385 #ifdef DEBUG_USB_HOST
-
386  else {
-
387  Notify(PSTR("\r\nUnknown Device: "), 0x80);
-
388  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
389  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
390  Notify(PSTR("\r\nData: "), 0x80);
-
391  for (uint8_t i = 0; i < ((l2capinbuf[12] >> 4) + 1); i++) { // bit 4-7 is the length-1
-
392  D_PrintHex<uint8_t > (l2capinbuf[15 + i], 0x80);
-
393  Notify(PSTR(" "), 0x80);
-
394  }
-
395  }
-
396 #endif
-
397  }
-
398 #ifdef EXTRADEBUG
-
399  else {
-
400  Notify(PSTR("\r\nReport Error: "), 0x80);
-
401  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
-
402  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
-
403  }
-
404 #endif
-
405  break;
-
406  case 0x22: // Acknowledge output report, return function result
-
407 #ifdef DEBUG_USB_HOST
-
408  if (l2capinbuf[13] != 0x00) { // Check if there is an error
-
409  Notify(PSTR("\r\nCommand failed: "), 0x80);
-
410  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
-
411  }
-
412 #endif
-
413  break;
-
414  case 0x30: // Core buttons - (a1) 30 BB BB
-
415  break;
-
416  case 0x31: // Core Buttons and Accelerometer - (a1) 31 BB BB AA AA AA
+
336  } else
+
337  setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer
+
338  }
+
339  } else
+
340  checkExtension = true; // Check for extensions by default
+
341  break;
+
342  case 0x21: // Read Memory Data
+
343  if((l2capinbuf[12] & 0x0F) == 0) { // No error
+
344  // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers
+
345  if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) {
+
346 #ifdef DEBUG_USB_HOST
+
347  Notify(PSTR("\r\nNunchuck connected"), 0x80);
+
348 #endif
+
349  wii_set_flag(WII_FLAG_NUNCHUCK_CONNECTED);
+
350  } else if(l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) {
+
351 #ifdef DEBUG_USB_HOST
+
352  Notify(PSTR("\r\nMotion Plus connected"), 0x80);
+
353 #endif
+
354  wii_set_flag(WII_FLAG_MOTION_PLUS_CONNECTED);
+
355  } else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) {
+
356 #ifdef DEBUG_USB_HOST
+
357  Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80);
+
358 #endif
+
359  motionPlusConnected = true;
+
360 #ifdef WIICAMERA
+
361  if(!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
+
362 #endif
+
363  setReportMode(false, 0x35); // Also read the extension
+
364  } else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) {
+
365 #ifdef DEBUG_USB_HOST
+
366  Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80);
+
367 #endif
+
368  activateNunchuck = false;
+
369  motionPlusConnected = true;
+
370  nunchuckConnected = true;
+
371 #ifdef WIICAMERA
+
372  if(!isIRCameraEnabled()) // Don't activate the Motion Plus if we are trying to initialize the IR camera
+
373 #endif
+
374  setReportMode(false, 0x35); // Also read the extension
+
375  } else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) {
+
376 #ifdef DEBUG_USB_HOST
+
377  Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80);
+
378  Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80);
+
379 #endif
+
380  stateCounter = 300; // Skip the rest in "WII_CHECK_MOTION_PLUS_STATE"
+
381  } else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) {
+
382 #ifdef DEBUG_USB_HOST
+
383  Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80);
+
384 #endif
+
385  wiiUProControllerConnected = true;
+
386  }
+
387 #ifdef DEBUG_USB_HOST
+
388  else {
+
389  Notify(PSTR("\r\nUnknown Device: "), 0x80);
+
390  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
391  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
392  Notify(PSTR("\r\nData: "), 0x80);
+
393  for(uint8_t i = 0; i < ((l2capinbuf[12] >> 4) + 1); i++) { // bit 4-7 is the length-1
+
394  D_PrintHex<uint8_t > (l2capinbuf[15 + i], 0x80);
+
395  Notify(PSTR(" "), 0x80);
+
396  }
+
397  }
+
398 #endif
+
399  }
+
400 #ifdef EXTRADEBUG
+
401  else {
+
402  Notify(PSTR("\r\nReport Error: "), 0x80);
+
403  D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
+
404  D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
+
405  }
+
406 #endif
+
407  break;
+
408  case 0x22: // Acknowledge output report, return function result
+
409 #ifdef DEBUG_USB_HOST
+
410  if(l2capinbuf[13] != 0x00) { // Check if there is an error
+
411  Notify(PSTR("\r\nCommand failed: "), 0x80);
+
412  D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
+
413  }
+
414 #endif
+
415  break;
+
416  case 0x30: // Core buttons - (a1) 30 BB BB
417  break;
-
418  case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE
+
418  case 0x31: // Core Buttons and Accelerometer - (a1) 31 BB BB AA AA AA
419  break;
-
420  case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II
-
421 #ifdef WIICAMERA
-
422  // Read the IR data
-
423  IR_object_x1 = (l2capinbuf[15] | ((uint16_t)(l2capinbuf[17] & 0x30) << 4)); // x position
-
424  IR_object_y1 = (l2capinbuf[16] | ((uint16_t)(l2capinbuf[17] & 0xC0) << 2)); // y position
-
425  IR_object_s1 = (l2capinbuf[17] & 0x0F); // size value, 0-15
-
426 
-
427  IR_object_x2 = (l2capinbuf[18] | ((uint16_t)(l2capinbuf[20] & 0x30) << 4));
-
428  IR_object_y2 = (l2capinbuf[19] | ((uint16_t)(l2capinbuf[20] & 0xC0) << 2));
-
429  IR_object_s2 = (l2capinbuf[20] & 0x0F);
-
430 
-
431  IR_object_x3 = (l2capinbuf[21] | ((uint16_t)(l2capinbuf[23] & 0x30) << 4));
-
432  IR_object_y3 = (l2capinbuf[22] | ((uint16_t)(l2capinbuf[23] & 0xC0) << 2));
-
433  IR_object_s3 = (l2capinbuf[23] & 0x0F);
-
434 
-
435  IR_object_x4 = (l2capinbuf[24] | ((uint16_t)(l2capinbuf[26] & 0x30) << 4));
-
436  IR_object_y4 = (l2capinbuf[25] | ((uint16_t)(l2capinbuf[26] & 0xC0) << 2));
-
437  IR_object_s4 = (l2capinbuf[26] & 0x0F);
-
438 #endif
-
439  break;
-
440  case 0x34: // Core Buttons with 19 Extension bytes - (a1) 34 BB BB EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
-
441  break;
-
442  /* 0x3e and 0x3f both give unknown report types when report mode is 0x3e or 0x3f with mode number 0x05 */
-
443  case 0x3E: // Core Buttons with Accelerometer and 32 IR bytes
-
444  // (a1) 31 BB BB AA AA AA II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II
-
445  // corresponds to output report mode 0x3e
-
446 
-
447  /**** for reading in full mode: DOES NOT WORK YET ****/
-
448  /* When it works it will also have intensity and bounding box data */
-
449  /*
-
450  IR_object_x1 = (l2capinbuf[13] | ((uint16_t)(l2capinbuf[15] & 0x30) << 4));
-
451  IR_object_y1 = (l2capinbuf[14] | ((uint16_t)(l2capinbuf[15] & 0xC0) << 2));
-
452  IR_object_s1 = (l2capinbuf[15] & 0x0F);
-
453  */
-
454  break;
-
455  case 0x3F:
-
456  /*
-
457  IR_object_x1 = (l2capinbuf[13] | ((uint16_t)(l2capinbuf[15] & 0x30) << 4));
-
458  IR_object_y1 = (l2capinbuf[14] | ((uint16_t)(l2capinbuf[15] & 0xC0) << 2));
-
459  IR_object_s1 = (l2capinbuf[15] & 0x0F);
-
460  */
-
461  break;
-
462  case 0x35: // Core Buttons and Accelerometer with 16 Extension Bytes
-
463  // (a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
-
464  if (motionPlusConnected) {
-
465  if (l2capinbuf[20] & 0x02) { // Check if it's a report from the Motion controller or the extension
-
466  if (motionValuesReset) { // We will only use the values when the gyro value has been set
-
467  gyroYawRaw = ((l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)) - gyroYawZero);
-
468  gyroRollRaw = ((l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6)) - gyroRollZero);
-
469  gyroPitchRaw = ((l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6)) - gyroPitchZero);
-
470 
-
471  yawGyroSpeed = (double)gyroYawRaw / ((double)gyroYawZero / yawGyroScale);
-
472  rollGyroSpeed = -(double)gyroRollRaw / ((double)gyroRollZero / rollGyroScale); // We invert these values so they will fit the acc values
-
473  pitchGyroSpeed = (double)gyroPitchRaw / ((double)gyroPitchZero / pitchGyroScale);
-
474 
-
475  /* The onboard gyro has two ranges for slow and fast mode */
-
476  if (!(l2capinbuf[18] & 0x02)) // Check if fast mode is used
-
477  yawGyroSpeed *= 4.545;
-
478  if (!(l2capinbuf[18] & 0x01)) // Check if fast mode is used
-
479  pitchGyroSpeed *= 4.545;
-
480  if (!(l2capinbuf[19] & 0x02)) // Check if fast mode is used
-
481  rollGyroSpeed *= 4.545;
-
482 
-
483  compPitch = (0.93 * (compPitch + (pitchGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimotePitch()); // Use a complimentary filter to calculate the angle
-
484  compRoll = (0.93 * (compRoll + (rollGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimoteRoll());
-
485 
-
486  gyroYaw += (yawGyroSpeed * ((double)(micros() - timer) / 1000000));
-
487  gyroRoll += (rollGyroSpeed * ((double)(micros() - timer) / 1000000));
-
488  gyroPitch += (pitchGyroSpeed * ((double)(micros() - timer) / 1000000));
-
489  timer = micros();
-
490  /*
-
491  // Uncomment these lines to tune the gyro scale variabels
-
492  Notify(PSTR("\r\ngyroYaw: "), 0x80);
-
493  Notify(gyroYaw, 0x80);
-
494  Notify(PSTR("\tgyroRoll: "), 0x80);
-
495  Notify(gyroRoll, 0x80);
-
496  Notify(PSTR("\tgyroPitch: "), 0x80);
-
497  Notify(gyroPitch, 0x80);
-
498  */
-
499  /*
-
500  Notify(PSTR("\twiimoteRoll: "), 0x80);
-
501  Notify(wiimoteRoll, 0x80);
-
502  Notify(PSTR("\twiimotePitch: "), 0x80);
-
503  Notify(wiimotePitch, 0x80);
-
504  */
-
505  } else {
-
506  if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values
-
507 #ifdef DEBUG_USB_HOST
-
508  Notify(PSTR("\r\nThe gyro values has been reset"), 0x80);
-
509 #endif
-
510  gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6));
-
511  gyroRollZero = (l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6));
-
512  gyroPitchZero = (l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6));
-
513 
-
514  rollGyroScale = 500; // You might need to adjust these
-
515  pitchGyroScale = 400;
-
516  yawGyroScale = 415;
-
517 
-
518  gyroYaw = 0;
-
519  gyroRoll = 0;
-
520  gyroPitch = 0;
-
521 
-
522  motionValuesReset = true;
-
523  timer = micros();
-
524  }
-
525  }
-
526  } else {
-
527  if (nunchuckConnected) {
-
528  hatValues[HatX] = l2capinbuf[15];
-
529  hatValues[HatY] = l2capinbuf[16];
-
530  accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x10 >> 3)) - 416;
-
531  accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x20 >> 4)) - 416;
-
532  accZnunchuck = (((l2capinbuf[19] & 0xFE) << 2) | (l2capinbuf[20] & 0xC0 >> 5)) - 416;
-
533  }
-
534  //else if(classicControllerConnected) { }
-
535  }
-
536  if (l2capinbuf[19] & 0x01) {
-
537  if (!extensionConnected) {
-
538  extensionConnected = true;
-
539  unknownExtensionConnected = true;
-
540 #ifdef DEBUG_USB_HOST
-
541  Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80);
-
542 #endif
-
543  }
-
544  } else {
-
545  if (extensionConnected && !unknownExtensionConnected) {
-
546  extensionConnected = false;
-
547  unknownExtensionConnected = true;
-
548 #ifdef DEBUG_USB_HOST
-
549  Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80);
-
550 #endif
-
551  nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent
-
552  }
-
553  }
-
554 
-
555  } else if (nunchuckConnected) {
-
556  hatValues[HatX] = l2capinbuf[15];
-
557  hatValues[HatY] = l2capinbuf[16];
-
558  accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x0C >> 2)) - 416;
-
559  accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x30 >> 4)) - 416;
-
560  accZnunchuck = ((l2capinbuf[19] << 2) | (l2capinbuf[20] & 0xC0 >> 6)) - 416;
-
561  } else if (wiiUProControllerConnected) {
-
562  hatValues[LeftHatX] = (l2capinbuf[15] | l2capinbuf[16] << 8);
-
563  hatValues[RightHatX] = (l2capinbuf[17] | l2capinbuf[18] << 8);
-
564  hatValues[LeftHatY] = (l2capinbuf[19] | l2capinbuf[20] << 8);
-
565  hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8);
-
566  }
-
567  break;
-
568 #ifdef DEBUG_USB_HOST
-
569  default:
-
570  Notify(PSTR("\r\nUnknown Report type: "), 0x80);
-
571  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
-
572  break;
-
573 #endif
-
574  }
-
575  }
-
576  }
-
577  L2CAP_task();
-
578  }
-
579 }
-
580 
-
581 void WII::L2CAP_task() {
-
582  switch (l2cap_state) {
-
583  /* These states are used if the Wiimote is the host */
-
584  case L2CAP_CONTROL_SUCCESS:
-
585  if (l2cap_config_success_control_flag) {
-
586 #ifdef DEBUG_USB_HOST
-
587  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
-
588 #endif
-
589  l2cap_state = L2CAP_INTERRUPT_SETUP;
-
590  }
-
591  break;
-
592 
-
593  case L2CAP_INTERRUPT_SETUP:
-
594  if (l2cap_connection_request_interrupt_flag) {
-
595 #ifdef DEBUG_USB_HOST
-
596  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
-
597 #endif
-
598  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
-
599  delay(1);
-
600  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
-
601  identifier++;
-
602  delay(1);
-
603  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
604 
-
605  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
-
606  }
-
607  break;
-
608 
-
609  /* These states are used if the Arduino is the host */
-
610  case L2CAP_CONTROL_CONNECT_REQUEST:
-
611  if (l2cap_connected_control_flag) {
-
612 #ifdef DEBUG_USB_HOST
-
613  Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
-
614 #endif
-
615  identifier++;
-
616  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
617  l2cap_state = L2CAP_CONTROL_CONFIG_REQUEST;
-
618  }
-
619  break;
-
620 
-
621  case L2CAP_CONTROL_CONFIG_REQUEST:
-
622  if (l2cap_config_success_control_flag) {
-
623 #ifdef DEBUG_USB_HOST
-
624  Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
-
625 #endif
-
626  identifier++;
-
627  pBtd->l2cap_connection_request(hci_handle, identifier, interrupt_dcid, HID_INTR_PSM);
-
628  l2cap_state = L2CAP_INTERRUPT_CONNECT_REQUEST;
-
629  }
-
630  break;
-
631 
-
632  case L2CAP_INTERRUPT_CONNECT_REQUEST:
-
633  if (l2cap_connected_interrupt_flag) {
-
634 #ifdef DEBUG_USB_HOST
-
635  Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
-
636 #endif
-
637  identifier++;
-
638  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
-
639  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
-
640  }
-
641  break;
-
642 
-
643  case L2CAP_INTERRUPT_CONFIG_REQUEST:
-
644  if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established
-
645 #ifdef DEBUG_USB_HOST
-
646  Notify(PSTR("\r\nHID Channels Established"), 0x80);
-
647 #endif
-
648  pBtd->connectToWii = false;
-
649  pBtd->pairWithWii = false;
-
650  stateCounter = 0;
-
651  l2cap_state = L2CAP_CHECK_MOTION_PLUS_STATE;
-
652  }
-
653  break;
-
654 
-
655  /* The next states are in run() */
+
420  case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE
+
421  break;
+
422  case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II
+
423 #ifdef WIICAMERA
+
424  // Read the IR data
+
425  IR_object_x1 = (l2capinbuf[15] | ((uint16_t)(l2capinbuf[17] & 0x30) << 4)); // x position
+
426  IR_object_y1 = (l2capinbuf[16] | ((uint16_t)(l2capinbuf[17] & 0xC0) << 2)); // y position
+
427  IR_object_s1 = (l2capinbuf[17] & 0x0F); // size value, 0-15
+
428 
+
429  IR_object_x2 = (l2capinbuf[18] | ((uint16_t)(l2capinbuf[20] & 0x30) << 4));
+
430  IR_object_y2 = (l2capinbuf[19] | ((uint16_t)(l2capinbuf[20] & 0xC0) << 2));
+
431  IR_object_s2 = (l2capinbuf[20] & 0x0F);
+
432 
+
433  IR_object_x3 = (l2capinbuf[21] | ((uint16_t)(l2capinbuf[23] & 0x30) << 4));
+
434  IR_object_y3 = (l2capinbuf[22] | ((uint16_t)(l2capinbuf[23] & 0xC0) << 2));
+
435  IR_object_s3 = (l2capinbuf[23] & 0x0F);
+
436 
+
437  IR_object_x4 = (l2capinbuf[24] | ((uint16_t)(l2capinbuf[26] & 0x30) << 4));
+
438  IR_object_y4 = (l2capinbuf[25] | ((uint16_t)(l2capinbuf[26] & 0xC0) << 2));
+
439  IR_object_s4 = (l2capinbuf[26] & 0x0F);
+
440 #endif
+
441  break;
+
442  case 0x34: // Core Buttons with 19 Extension bytes - (a1) 34 BB BB EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
+
443  break;
+
444  /* 0x3e and 0x3f both give unknown report types when report mode is 0x3e or 0x3f with mode number 0x05 */
+
445  case 0x3E: // Core Buttons with Accelerometer and 32 IR bytes
+
446  // (a1) 31 BB BB AA AA AA II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II
+
447  // corresponds to output report mode 0x3e
+
448 
+
449  /**** for reading in full mode: DOES NOT WORK YET ****/
+
450  /* When it works it will also have intensity and bounding box data */
+
451  /*
+
452  IR_object_x1 = (l2capinbuf[13] | ((uint16_t)(l2capinbuf[15] & 0x30) << 4));
+
453  IR_object_y1 = (l2capinbuf[14] | ((uint16_t)(l2capinbuf[15] & 0xC0) << 2));
+
454  IR_object_s1 = (l2capinbuf[15] & 0x0F);
+
455  */
+
456  break;
+
457  case 0x3F:
+
458  /*
+
459  IR_object_x1 = (l2capinbuf[13] | ((uint16_t)(l2capinbuf[15] & 0x30) << 4));
+
460  IR_object_y1 = (l2capinbuf[14] | ((uint16_t)(l2capinbuf[15] & 0xC0) << 2));
+
461  IR_object_s1 = (l2capinbuf[15] & 0x0F);
+
462  */
+
463  break;
+
464  case 0x35: // Core Buttons and Accelerometer with 16 Extension Bytes
+
465  // (a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
+
466  if(motionPlusConnected) {
+
467  if(l2capinbuf[20] & 0x02) { // Check if it's a report from the Motion controller or the extension
+
468  if(motionValuesReset) { // We will only use the values when the gyro value has been set
+
469  gyroYawRaw = ((l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)) - gyroYawZero);
+
470  gyroRollRaw = ((l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6)) - gyroRollZero);
+
471  gyroPitchRaw = ((l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6)) - gyroPitchZero);
+
472 
+
473  yawGyroSpeed = (double)gyroYawRaw / ((double)gyroYawZero / yawGyroScale);
+
474  rollGyroSpeed = -(double)gyroRollRaw / ((double)gyroRollZero / rollGyroScale); // We invert these values so they will fit the acc values
+
475  pitchGyroSpeed = (double)gyroPitchRaw / ((double)gyroPitchZero / pitchGyroScale);
+
476 
+
477  /* The onboard gyro has two ranges for slow and fast mode */
+
478  if(!(l2capinbuf[18] & 0x02)) // Check if fast mode is used
+
479  yawGyroSpeed *= 4.545;
+
480  if(!(l2capinbuf[18] & 0x01)) // Check if fast mode is used
+
481  pitchGyroSpeed *= 4.545;
+
482  if(!(l2capinbuf[19] & 0x02)) // Check if fast mode is used
+
483  rollGyroSpeed *= 4.545;
+
484 
+
485  compPitch = (0.93 * (compPitch + (pitchGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimotePitch()); // Use a complimentary filter to calculate the angle
+
486  compRoll = (0.93 * (compRoll + (rollGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimoteRoll());
+
487 
+
488  gyroYaw += (yawGyroSpeed * ((double)(micros() - timer) / 1000000));
+
489  gyroRoll += (rollGyroSpeed * ((double)(micros() - timer) / 1000000));
+
490  gyroPitch += (pitchGyroSpeed * ((double)(micros() - timer) / 1000000));
+
491  timer = micros();
+
492  /*
+
493  // Uncomment these lines to tune the gyro scale variabels
+
494  Notify(PSTR("\r\ngyroYaw: "), 0x80);
+
495  Notify(gyroYaw, 0x80);
+
496  Notify(PSTR("\tgyroRoll: "), 0x80);
+
497  Notify(gyroRoll, 0x80);
+
498  Notify(PSTR("\tgyroPitch: "), 0x80);
+
499  Notify(gyroPitch, 0x80);
+
500  */
+
501  /*
+
502  Notify(PSTR("\twiimoteRoll: "), 0x80);
+
503  Notify(wiimoteRoll, 0x80);
+
504  Notify(PSTR("\twiimotePitch: "), 0x80);
+
505  Notify(wiimotePitch, 0x80);
+
506  */
+
507  } else {
+
508  if((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values
+
509 #ifdef DEBUG_USB_HOST
+
510  Notify(PSTR("\r\nThe gyro values has been reset"), 0x80);
+
511 #endif
+
512  gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6));
+
513  gyroRollZero = (l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6));
+
514  gyroPitchZero = (l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6));
+
515 
+
516  rollGyroScale = 500; // You might need to adjust these
+
517  pitchGyroScale = 400;
+
518  yawGyroScale = 415;
+
519 
+
520  gyroYaw = 0;
+
521  gyroRoll = 0;
+
522  gyroPitch = 0;
+
523 
+
524  motionValuesReset = true;
+
525  timer = micros();
+
526  }
+
527  }
+
528  } else {
+
529  if(nunchuckConnected) {
+
530  hatValues[HatX] = l2capinbuf[15];
+
531  hatValues[HatY] = l2capinbuf[16];
+
532  accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x10 >> 3)) - 416;
+
533  accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x20 >> 4)) - 416;
+
534  accZnunchuck = (((l2capinbuf[19] & 0xFE) << 2) | (l2capinbuf[20] & 0xC0 >> 5)) - 416;
+
535  }
+
536  //else if(classicControllerConnected) { }
+
537  }
+
538  if(l2capinbuf[19] & 0x01) {
+
539  if(!extensionConnected) {
+
540  extensionConnected = true;
+
541  unknownExtensionConnected = true;
+
542 #ifdef DEBUG_USB_HOST
+
543  Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80);
+
544 #endif
+
545  }
+
546  } else {
+
547  if(extensionConnected && !unknownExtensionConnected) {
+
548  extensionConnected = false;
+
549  unknownExtensionConnected = true;
+
550 #ifdef DEBUG_USB_HOST
+
551  Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80);
+
552 #endif
+
553  nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent
+
554  }
+
555  }
+
556 
+
557  } else if(nunchuckConnected) {
+
558  hatValues[HatX] = l2capinbuf[15];
+
559  hatValues[HatY] = l2capinbuf[16];
+
560  accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x0C >> 2)) - 416;
+
561  accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x30 >> 4)) - 416;
+
562  accZnunchuck = ((l2capinbuf[19] << 2) | (l2capinbuf[20] & 0xC0 >> 6)) - 416;
+
563  } else if(wiiUProControllerConnected) {
+
564  hatValues[LeftHatX] = (l2capinbuf[15] | l2capinbuf[16] << 8);
+
565  hatValues[RightHatX] = (l2capinbuf[17] | l2capinbuf[18] << 8);
+
566  hatValues[LeftHatY] = (l2capinbuf[19] | l2capinbuf[20] << 8);
+
567  hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8);
+
568  }
+
569  break;
+
570 #ifdef DEBUG_USB_HOST
+
571  default:
+
572  Notify(PSTR("\r\nUnknown Report type: "), 0x80);
+
573  D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
+
574  break;
+
575 #endif
+
576  }
+
577  }
+
578  }
+
579  L2CAP_task();
+
580  }
+
581 }
+
582 
+
583 void WII::L2CAP_task() {
+
584  switch(l2cap_state) {
+
585  /* These states are used if the Wiimote is the host */
+
586  case L2CAP_CONTROL_SUCCESS:
+
587  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
588 #ifdef DEBUG_USB_HOST
+
589  Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
+
590 #endif
+
591  l2cap_state = L2CAP_INTERRUPT_SETUP;
+
592  }
+
593  break;
+
594 
+
595  case L2CAP_INTERRUPT_SETUP:
+
596  if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)) {
+
597 #ifdef DEBUG_USB_HOST
+
598  Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
+
599 #endif
+
600  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
+
601  delay(1);
+
602  pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, SUCCESSFUL);
+
603  identifier++;
+
604  delay(1);
+
605  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
606 
+
607  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
+
608  }
+
609  break;
+
610 
+
611  /* These states are used if the Arduino is the host */
+
612  case L2CAP_CONTROL_CONNECT_REQUEST:
+
613  if(l2cap_check_flag(L2CAP_FLAG_CONTROL_CONNECTED)) {
+
614 #ifdef DEBUG_USB_HOST
+
615  Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
+
616 #endif
+
617  identifier++;
+
618  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
+
619  l2cap_state = L2CAP_CONTROL_CONFIG_REQUEST;
+
620  }
+
621  break;
+
622 
+
623  case L2CAP_CONTROL_CONFIG_REQUEST:
+
624  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)) {
+
625 #ifdef DEBUG_USB_HOST
+
626  Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
+
627 #endif
+
628  identifier++;
+
629  pBtd->l2cap_connection_request(hci_handle, identifier, interrupt_dcid, HID_INTR_PSM);
+
630  l2cap_state = L2CAP_INTERRUPT_CONNECT_REQUEST;
+
631  }
+
632  break;
+
633 
+
634  case L2CAP_INTERRUPT_CONNECT_REQUEST:
+
635  if(l2cap_check_flag(L2CAP_FLAG_INTERRUPT_CONNECTED)) {
+
636 #ifdef DEBUG_USB_HOST
+
637  Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
+
638 #endif
+
639  identifier++;
+
640  pBtd->l2cap_config_request(hci_handle, identifier, interrupt_scid);
+
641  l2cap_state = L2CAP_INTERRUPT_CONFIG_REQUEST;
+
642  }
+
643  break;
+
644 
+
645  case L2CAP_INTERRUPT_CONFIG_REQUEST:
+
646  if(l2cap_check_flag(L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)) { // Now the HID channels is established
+
647 #ifdef DEBUG_USB_HOST
+
648  Notify(PSTR("\r\nHID Channels Established"), 0x80);
+
649 #endif
+
650  pBtd->connectToWii = false;
+
651  pBtd->pairWithWii = false;
+
652  stateCounter = 0;
+
653  l2cap_state = WII_CHECK_MOTION_PLUS_STATE;
+
654  }
+
655  break;
656 
-
657  case L2CAP_INTERRUPT_DISCONNECT:
-
658  if (l2cap_disconnect_response_interrupt_flag && millis() > timer) {
-
659 #ifdef DEBUG_USB_HOST
-
660  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
-
661 #endif
-
662  identifier++;
-
663  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
-
664  l2cap_state = L2CAP_CONTROL_DISCONNECT;
-
665  }
-
666  break;
-
667 
-
668  case L2CAP_CONTROL_DISCONNECT:
-
669  if (l2cap_disconnect_response_control_flag) {
-
670 #ifdef DEBUG_USB_HOST
-
671  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
-
672 #endif
-
673  pBtd->hci_disconnect(hci_handle);
-
674  hci_handle = -1; // Reset handle
-
675  l2cap_event_flag = 0; // Reset flags
-
676  l2cap_state = L2CAP_WAIT;
-
677  }
-
678  break;
-
679  }
-
680 }
-
681 
-
682 void WII::Run() {
-
683  if (l2cap_state == L2CAP_INTERRUPT_DISCONNECT && millis() > timer)
-
684  L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough
-
685 
-
686  switch (l2cap_state) {
-
687  case L2CAP_WAIT:
-
688  if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) {
-
689  pBtd->l2capConnectionClaimed = true;
-
690  activeConnection = true;
-
691  motionPlusInside = pBtd->motionPlusInside;
-
692 #ifdef DEBUG_USB_HOST
-
693  Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80);
-
694 #endif
-
695  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
-
696  l2cap_event_flag = 0; // Reset flags
-
697  identifier = 0;
-
698  pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM);
-
699  l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
-
700  } else if (l2cap_connection_request_control_flag) {
-
701 #ifdef DEBUG_USB_HOST
-
702  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
-
703 #endif
-
704  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
-
705  delay(1);
-
706  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
-
707  identifier++;
-
708  delay(1);
-
709  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
-
710  l2cap_state = L2CAP_CONTROL_SUCCESS;
-
711  }
-
712  break;
-
713 
-
714  case L2CAP_CHECK_MOTION_PLUS_STATE:
-
715 #ifdef DEBUG_USB_HOST
-
716  if (stateCounter == 0) // Only print onnce
-
717  Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80);
-
718 #endif
-
719  stateCounter++;
-
720  if (stateCounter % 200 == 0)
-
721  checkMotionPresent(); // Check if there is a motion plus connected
-
722  if (motion_plus_connected_flag) {
-
723  stateCounter = 0;
-
724  l2cap_state = L2CAP_INIT_MOTION_PLUS_STATE;
-
725  timer = micros();
-
726 
-
727  if (unknownExtensionConnected) {
-
728 #ifdef DEBUG_USB_HOST
-
729  Notify(PSTR("\r\nA extension is also connected"), 0x80);
-
730 #endif
-
731  activateNunchuck = true; // For we will just set this to true as this the only extension supported so far
-
732  }
-
733 
-
734  } else if (stateCounter == 601) { // We will try three times to check for the motion plus
-
735 #ifdef DEBUG_USB_HOST
-
736  Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80);
-
737 #endif
-
738  stateCounter = 0;
-
739  l2cap_state = L2CAP_CHECK_EXTENSION_STATE;
-
740  }
-
741  break;
-
742 
-
743  case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port
-
744 #ifdef DEBUG_USB_HOST
-
745  if (stateCounter == 0) // Only print onnce
-
746  Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80);
-
747 #endif
-
748  stateCounter++; // We use this counter as there has to be a short delay between the commands
-
749  if (stateCounter == 1)
-
750  statusRequest(); // See if a new device has connected
-
751  if (stateCounter == 100) {
-
752  if (unknownExtensionConnected) // Check if there is a extension is connected to the port
-
753  initExtension1();
-
754  else
-
755  stateCounter = 399;
-
756  } else if (stateCounter == 200)
-
757  initExtension2();
-
758  else if (stateCounter == 300) {
-
759  readExtensionType();
-
760  unknownExtensionConnected = false;
-
761  } else if (stateCounter == 400) {
-
762  stateCounter = 0;
-
763  l2cap_state = L2CAP_LED_STATE;
-
764  }
-
765  break;
-
766 
-
767  case L2CAP_INIT_MOTION_PLUS_STATE:
-
768  stateCounter++;
-
769  if (stateCounter == 1)
-
770  initMotionPlus();
-
771  else if (stateCounter == 100)
-
772  activateMotionPlus();
-
773  else if (stateCounter == 200)
-
774  readExtensionType(); // Check if it has been activated
-
775  else if (stateCounter == 300) {
-
776  stateCounter = 0;
-
777  unknownExtensionConnected = false; // The motion plus will send a status report when it's activated, we will set this to false so it doesn't reinitialize the Motion Plus
-
778  l2cap_state = L2CAP_LED_STATE;
-
779  }
-
780  break;
-
781 
-
782  case L2CAP_LED_STATE:
-
783  if (nunchuck_connected_flag)
-
784  nunchuckConnected = true;
-
785  wiimoteConnected = true;
-
786  onInit();
-
787  l2cap_state = L2CAP_DONE;
-
788  break;
-
789 
-
790  case L2CAP_DONE:
-
791  if (unknownExtensionConnected) {
-
792 #ifdef DEBUG_USB_HOST
-
793  if (stateCounter == 0) // Only print once
-
794  Notify(PSTR("\r\nChecking extension port"), 0x80);
-
795 #endif
-
796  stateCounter++; // We will use this counter as there has to be a short delay between the commands
-
797  if (stateCounter == 50)
-
798  statusRequest();
-
799  else if (stateCounter == 100)
-
800  initExtension1();
-
801  else if (stateCounter == 150)
-
802  if ((extensionConnected && motionPlusConnected) || (unknownExtensionConnected && !motionPlusConnected))
-
803  initExtension2();
-
804  else
-
805  stateCounter = 299; // There is no extension connected
-
806  else if (stateCounter == 200)
-
807  readExtensionType();
-
808  else if (stateCounter == 250) {
-
809  if (nunchuck_connected_flag) {
-
810 #ifdef DEBUG_USB_HOST
-
811  Notify(PSTR("\r\nNunchuck was reconnected"), 0x80);
-
812 #endif
-
813  activateNunchuck = true;
-
814  nunchuckConnected = true;
-
815  }
-
816  if (!motionPlusConnected)
-
817  stateCounter = 449;
-
818  } else if (stateCounter == 300) {
-
819  if (motionPlusConnected) {
-
820 #ifdef DEBUG_USB_HOST
-
821  Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80);
-
822 #endif
-
823  initMotionPlus();
-
824  } else
-
825  stateCounter = 449;
-
826  } else if (stateCounter == 350)
-
827  activateMotionPlus();
-
828  else if (stateCounter == 400)
-
829  readExtensionType(); // Check if it has been activated
-
830  else if (stateCounter == 450) {
-
831  onInit();
-
832  stateCounter = 0;
-
833  unknownExtensionConnected = false;
-
834  }
-
835  } else
-
836  stateCounter = 0;
-
837  break;
-
838  }
-
839 }
-
840 
-
841 /************************************************************/
-
842 /* HID Commands */
-
843 
-
844 /************************************************************/
-
845 void WII::HID_Command(uint8_t* data, uint8_t nbytes) {
-
846  if (motionPlusInside)
-
847  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // It's the new wiimote with the Motion Plus Inside
-
848  else
-
849  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]);
-
850 }
-
851 
-
852 void WII::setAllOff() {
-
853  HIDBuffer[1] = 0x11;
-
854  HIDBuffer[2] = 0x00;
-
855  HID_Command(HIDBuffer, 3);
-
856 }
-
857 
-
858 void WII::setRumbleOff() {
-
859  HIDBuffer[1] = 0x11;
-
860  HIDBuffer[2] &= ~0x01; // Bit 0 control the rumble
-
861  HID_Command(HIDBuffer, 3);
-
862 }
-
863 
-
864 void WII::setRumbleOn() {
-
865  HIDBuffer[1] = 0x11;
-
866  HIDBuffer[2] |= 0x01; // Bit 0 control the rumble
-
867  HID_Command(HIDBuffer, 3);
-
868 }
-
869 
-
870 void WII::setRumbleToggle() {
-
871  HIDBuffer[1] = 0x11;
-
872  HIDBuffer[2] ^= 0x01; // Bit 0 control the rumble
-
873  HID_Command(HIDBuffer, 3);
-
874 }
-
875 
-
876 void WII::setLedRaw(uint8_t value) {
-
877  HIDBuffer[1] = 0x11;
-
878  HIDBuffer[2] = value | (HIDBuffer[2] & 0x01); // Keep the rumble bit
-
879  HID_Command(HIDBuffer, 3);
-
880 }
-
881 void WII::setLedOff(LED a) {
-
882  HIDBuffer[1] = 0x11;
-
883  HIDBuffer[2] &= ~(pgm_read_byte(&LEDS[(uint8_t)a]));
-
884  HID_Command(HIDBuffer, 3);
-
885 }
-
886 
-
887 void WII::setLedOn(LED a) {
-
888  HIDBuffer[1] = 0x11;
-
889  HIDBuffer[2] |= pgm_read_byte(&LEDS[(uint8_t)a]);
-
890  HID_Command(HIDBuffer, 3);
-
891 }
-
892 
-
893 void WII::setLedToggle(LED a) {
-
894  HIDBuffer[1] = 0x11;
-
895  HIDBuffer[2] ^= pgm_read_byte(&LEDS[(uint8_t)a]);
-
896  HID_Command(HIDBuffer, 3);
-
897 }
-
898 
-
899 void WII::setLedStatus() {
-
900  HIDBuffer[1] = 0x11;
-
901  HIDBuffer[2] = (HIDBuffer[2] & 0x01); // Keep the rumble bit
-
902  if (wiimoteConnected)
-
903  HIDBuffer[2] |= 0x10; // If it's connected LED1 will light up
-
904  if (motionPlusConnected)
-
905  HIDBuffer[2] |= 0x20; // If it's connected LED2 will light up
-
906  if (nunchuckConnected)
-
907  HIDBuffer[2] |= 0x40; // If it's connected LED3 will light up
-
908 
-
909  HID_Command(HIDBuffer, 3);
-
910 }
-
911 
-
912 uint8_t WII::getBatteryLevel() {
-
913  checkExtension = false; // This is needed so the library knows that the status response is a response to this function
-
914  statusRequest(); // This will update the battery level
-
915  return batteryLevel;
-
916 };
-
917 
-
918 void WII::setReportMode(bool continuous, uint8_t mode) {
-
919  uint8_t cmd_buf[4];
-
920  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
921  cmd_buf[1] = 0x12;
-
922  if (continuous)
-
923  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit
-
924  else
-
925  cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01); // Keep the rumble bit
-
926  cmd_buf[3] = mode;
-
927  HID_Command(cmd_buf, 4);
-
928 }
-
929 
-
930 void WII::statusRequest() {
-
931  uint8_t cmd_buf[3];
-
932  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
933  cmd_buf[1] = 0x15;
-
934  cmd_buf[2] = (HIDBuffer[2] & 0x01); // Keep the rumble bit
-
935  HID_Command(cmd_buf, 3);
-
936 }
-
937 
-
938 /************************************************************/
-
939 /* Memmory Commands */
-
940 
-
941 /************************************************************/
-
942 void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) {
-
943  uint8_t cmd_buf[23];
-
944  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
945  cmd_buf[1] = 0x16; // Write data
-
946  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Write to memory, clear bit 2 to write to EEPROM
-
947  cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
-
948  cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
-
949  cmd_buf[5] = (uint8_t)(offset & 0xFF);
-
950  cmd_buf[6] = size;
-
951  uint8_t i = 0;
-
952  for (; i < size; i++)
-
953  cmd_buf[7 + i] = data[i];
-
954  for (; i < 16; i++) // Set the rest to zero
-
955  cmd_buf[7 + i] = 0x00;
-
956  HID_Command(cmd_buf, 23);
-
957 }
-
958 
-
959 void WII::initExtension1() {
-
960  uint8_t buf[1];
-
961  buf[0] = 0x55;
-
962  writeData(0xA400F0, 1, buf);
-
963 }
-
964 
-
965 void WII::initExtension2() {
-
966  uint8_t buf[1];
-
967  buf[0] = 0x00;
-
968  writeData(0xA400FB, 1, buf);
-
969 }
-
970 
-
971 void WII::initMotionPlus() {
-
972  uint8_t buf[1];
-
973  buf[0] = 0x55;
-
974  writeData(0xA600F0, 1, buf);
-
975 }
-
976 
-
977 void WII::activateMotionPlus() {
-
978  uint8_t buf[1];
-
979  if (pBtd->wiiUProController) {
-
980 #ifdef DEBUG_USB_HOST
-
981  Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80);
-
982 #endif
-
983  buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07
-
984  } else if (activateNunchuck) {
-
985 #ifdef DEBUG_USB_HOST
-
986  Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80);
-
987 #endif
-
988  buf[0] = 0x05; // Activate nunchuck pass-through mode
-
989  } //else if(classicControllerConnected && extensionConnected)
-
990  //buf[0] = 0x07;
-
991  else {
+
657  /* The next states are in run() */
+
658 
+
659  case L2CAP_INTERRUPT_DISCONNECT:
+
660  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && millis() > timer) {
+
661 #ifdef DEBUG_USB_HOST
+
662  Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
+
663 #endif
+
664  identifier++;
+
665  pBtd->l2cap_disconnection_request(hci_handle, identifier, control_scid, control_dcid);
+
666  l2cap_state = L2CAP_CONTROL_DISCONNECT;
+
667  }
+
668  break;
+
669 
+
670  case L2CAP_CONTROL_DISCONNECT:
+
671  if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)) {
+
672 #ifdef DEBUG_USB_HOST
+
673  Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
+
674 #endif
+
675  pBtd->hci_disconnect(hci_handle);
+
676  hci_handle = -1; // Reset handle
+
677  l2cap_event_flag = 0; // Reset flags
+
678  l2cap_state = L2CAP_WAIT;
+
679  }
+
680  break;
+
681  }
+
682 }
+
683 
+
684 void WII::Run() {
+
685  if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && millis() > timer)
+
686  L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough
+
687 
+
688  switch(l2cap_state) {
+
689  case L2CAP_WAIT:
+
690  if(pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) {
+
691  pBtd->l2capConnectionClaimed = true;
+
692  activeConnection = true;
+
693  motionPlusInside = pBtd->motionPlusInside;
+
694 #ifdef DEBUG_USB_HOST
+
695  Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80);
+
696 #endif
+
697  hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
+
698  l2cap_event_flag = 0; // Reset flags
+
699  identifier = 0;
+
700  pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM);
+
701  l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
+
702  } else if(l2cap_check_flag(L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)) {
+
703 #ifdef DEBUG_USB_HOST
+
704  Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
+
705 #endif
+
706  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
+
707  delay(1);
+
708  pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, SUCCESSFUL);
+
709  identifier++;
+
710  delay(1);
+
711  pBtd->l2cap_config_request(hci_handle, identifier, control_scid);
+
712  l2cap_state = L2CAP_CONTROL_SUCCESS;
+
713  }
+
714  break;
+
715 
+
716  case WII_CHECK_MOTION_PLUS_STATE:
+
717 #ifdef DEBUG_USB_HOST
+
718  if(stateCounter == 0) // Only print onnce
+
719  Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80);
+
720 #endif
+
721  stateCounter++;
+
722  if(stateCounter % 200 == 0)
+
723  checkMotionPresent(); // Check if there is a motion plus connected
+
724  if(wii_check_flag(WII_FLAG_MOTION_PLUS_CONNECTED)) {
+
725  stateCounter = 0;
+
726  l2cap_state = WII_INIT_MOTION_PLUS_STATE;
+
727  timer = micros();
+
728 
+
729  if(unknownExtensionConnected) {
+
730 #ifdef DEBUG_USB_HOST
+
731  Notify(PSTR("\r\nA extension is also connected"), 0x80);
+
732 #endif
+
733  activateNunchuck = true; // For we will just set this to true as this the only extension supported so far
+
734  }
+
735 
+
736  } else if(stateCounter == 601) { // We will try three times to check for the motion plus
+
737 #ifdef DEBUG_USB_HOST
+
738  Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80);
+
739 #endif
+
740  stateCounter = 0;
+
741  l2cap_state = WII_CHECK_EXTENSION_STATE;
+
742  }
+
743  break;
+
744 
+
745  case WII_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port
+
746 #ifdef DEBUG_USB_HOST
+
747  if(stateCounter == 0) // Only print onnce
+
748  Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80);
+
749 #endif
+
750  stateCounter++; // We use this counter as there has to be a short delay between the commands
+
751  if(stateCounter == 1)
+
752  statusRequest(); // See if a new device has connected
+
753  if(stateCounter == 100) {
+
754  if(unknownExtensionConnected) // Check if there is a extension is connected to the port
+
755  initExtension1();
+
756  else
+
757  stateCounter = 399;
+
758  } else if(stateCounter == 200)
+
759  initExtension2();
+
760  else if(stateCounter == 300) {
+
761  readExtensionType();
+
762  unknownExtensionConnected = false;
+
763  } else if(stateCounter == 400) {
+
764  stateCounter = 0;
+
765  l2cap_state = TURN_ON_LED;
+
766  }
+
767  break;
+
768 
+
769  case WII_INIT_MOTION_PLUS_STATE:
+
770  stateCounter++;
+
771  if(stateCounter == 1)
+
772  initMotionPlus();
+
773  else if(stateCounter == 100)
+
774  activateMotionPlus();
+
775  else if(stateCounter == 200)
+
776  readExtensionType(); // Check if it has been activated
+
777  else if(stateCounter == 300) {
+
778  stateCounter = 0;
+
779  unknownExtensionConnected = false; // The motion plus will send a status report when it's activated, we will set this to false so it doesn't reinitialize the Motion Plus
+
780  l2cap_state = TURN_ON_LED;
+
781  }
+
782  break;
+
783 
+
784  case TURN_ON_LED:
+
785  if(wii_check_flag(WII_FLAG_NUNCHUCK_CONNECTED))
+
786  nunchuckConnected = true;
+
787  wiimoteConnected = true;
+
788  onInit();
+
789  l2cap_state = L2CAP_DONE;
+
790  break;
+
791 
+
792  case L2CAP_DONE:
+
793  if(unknownExtensionConnected) {
+
794 #ifdef DEBUG_USB_HOST
+
795  if(stateCounter == 0) // Only print once
+
796  Notify(PSTR("\r\nChecking extension port"), 0x80);
+
797 #endif
+
798  stateCounter++; // We will use this counter as there has to be a short delay between the commands
+
799  if(stateCounter == 50)
+
800  statusRequest();
+
801  else if(stateCounter == 100)
+
802  initExtension1();
+
803  else if(stateCounter == 150)
+
804  if((extensionConnected && motionPlusConnected) || (unknownExtensionConnected && !motionPlusConnected))
+
805  initExtension2();
+
806  else
+
807  stateCounter = 299; // There is no extension connected
+
808  else if(stateCounter == 200)
+
809  readExtensionType();
+
810  else if(stateCounter == 250) {
+
811  if(wii_check_flag(WII_FLAG_NUNCHUCK_CONNECTED)) {
+
812 #ifdef DEBUG_USB_HOST
+
813  Notify(PSTR("\r\nNunchuck was reconnected"), 0x80);
+
814 #endif
+
815  activateNunchuck = true;
+
816  nunchuckConnected = true;
+
817  }
+
818  if(!motionPlusConnected)
+
819  stateCounter = 449;
+
820  } else if(stateCounter == 300) {
+
821  if(motionPlusConnected) {
+
822 #ifdef DEBUG_USB_HOST
+
823  Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80);
+
824 #endif
+
825  initMotionPlus();
+
826  } else
+
827  stateCounter = 449;
+
828  } else if(stateCounter == 350)
+
829  activateMotionPlus();
+
830  else if(stateCounter == 400)
+
831  readExtensionType(); // Check if it has been activated
+
832  else if(stateCounter == 450) {
+
833  onInit();
+
834  stateCounter = 0;
+
835  unknownExtensionConnected = false;
+
836  }
+
837  } else
+
838  stateCounter = 0;
+
839  break;
+
840  }
+
841 }
+
842 
+
843 /************************************************************/
+
844 /* HID Commands */
+
845 
+
846 /************************************************************/
+
847 void WII::HID_Command(uint8_t* data, uint8_t nbytes) {
+
848  if(motionPlusInside)
+
849  pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // It's the new Wiimote with the Motion Plus Inside or Wii U Pro controller
+
850  else
+
851  pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]);
+
852 }
+
853 
+
854 void WII::setAllOff() {
+
855  HIDBuffer[1] = 0x11;
+
856  HIDBuffer[2] = 0x00;
+
857  HID_Command(HIDBuffer, 3);
+
858 }
+
859 
+
860 void WII::setRumbleOff() {
+
861  HIDBuffer[1] = 0x11;
+
862  HIDBuffer[2] &= ~0x01; // Bit 0 control the rumble
+
863  HID_Command(HIDBuffer, 3);
+
864 }
+
865 
+
866 void WII::setRumbleOn() {
+
867  HIDBuffer[1] = 0x11;
+
868  HIDBuffer[2] |= 0x01; // Bit 0 control the rumble
+
869  HID_Command(HIDBuffer, 3);
+
870 }
+
871 
+
872 void WII::setRumbleToggle() {
+
873  HIDBuffer[1] = 0x11;
+
874  HIDBuffer[2] ^= 0x01; // Bit 0 control the rumble
+
875  HID_Command(HIDBuffer, 3);
+
876 }
+
877 
+
878 void WII::setLedRaw(uint8_t value) {
+
879  HIDBuffer[1] = 0x11;
+
880  HIDBuffer[2] = value | (HIDBuffer[2] & 0x01); // Keep the rumble bit
+
881  HID_Command(HIDBuffer, 3);
+
882 }
+
883 
+
884 void WII::setLedOff(LEDEnum a) {
+
885  HIDBuffer[1] = 0x11;
+
886  HIDBuffer[2] &= ~(pgm_read_byte(&WII_LEDS[(uint8_t)a]));
+
887  HID_Command(HIDBuffer, 3);
+
888 }
+
889 
+
890 void WII::setLedOn(LEDEnum a) {
+
891  if(a == OFF)
+
892  setLedRaw(0);
+
893  else {
+
894  HIDBuffer[1] = 0x11;
+
895  HIDBuffer[2] |= pgm_read_byte(&WII_LEDS[(uint8_t)a]);
+
896  HID_Command(HIDBuffer, 3);
+
897  }
+
898 }
+
899 
+
900 void WII::setLedToggle(LEDEnum a) {
+
901  HIDBuffer[1] = 0x11;
+
902  HIDBuffer[2] ^= pgm_read_byte(&WII_LEDS[(uint8_t)a]);
+
903  HID_Command(HIDBuffer, 3);
+
904 }
+
905 
+
906 void WII::setLedStatus() {
+
907  HIDBuffer[1] = 0x11;
+
908  HIDBuffer[2] = (HIDBuffer[2] & 0x01); // Keep the rumble bit
+
909  if(wiimoteConnected)
+
910  HIDBuffer[2] |= 0x10; // If it's connected LED1 will light up
+
911  if(motionPlusConnected)
+
912  HIDBuffer[2] |= 0x20; // If it's connected LED2 will light up
+
913  if(nunchuckConnected)
+
914  HIDBuffer[2] |= 0x40; // If it's connected LED3 will light up
+
915 
+
916  HID_Command(HIDBuffer, 3);
+
917 }
+
918 
+
919 uint8_t WII::getBatteryLevel() {
+
920  checkExtension = false; // This is needed so the library knows that the status response is a response to this function
+
921  statusRequest(); // This will update the battery level
+
922  return batteryLevel;
+
923 };
+
924 
+
925 void WII::setReportMode(bool continuous, uint8_t mode) {
+
926  uint8_t cmd_buf[4];
+
927  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
928  cmd_buf[1] = 0x12;
+
929  if(continuous)
+
930  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit
+
931  else
+
932  cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01); // Keep the rumble bit
+
933  cmd_buf[3] = mode;
+
934  HID_Command(cmd_buf, 4);
+
935 }
+
936 
+
937 void WII::statusRequest() {
+
938  uint8_t cmd_buf[3];
+
939  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
940  cmd_buf[1] = 0x15;
+
941  cmd_buf[2] = (HIDBuffer[2] & 0x01); // Keep the rumble bit
+
942  HID_Command(cmd_buf, 3);
+
943 }
+
944 
+
945 /************************************************************/
+
946 /* Memmory Commands */
+
947 
+
948 /************************************************************/
+
949 void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) {
+
950  uint8_t cmd_buf[23];
+
951  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
952  cmd_buf[1] = 0x16; // Write data
+
953  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Write to memory, clear bit 2 to write to EEPROM
+
954  cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
+
955  cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
+
956  cmd_buf[5] = (uint8_t)(offset & 0xFF);
+
957  cmd_buf[6] = size;
+
958  uint8_t i = 0;
+
959  for(; i < size; i++)
+
960  cmd_buf[7 + i] = data[i];
+
961  for(; i < 16; i++) // Set the rest to zero
+
962  cmd_buf[7 + i] = 0x00;
+
963  HID_Command(cmd_buf, 23);
+
964 }
+
965 
+
966 void WII::initExtension1() {
+
967  uint8_t buf[1];
+
968  buf[0] = 0x55;
+
969  writeData(0xA400F0, 1, buf);
+
970 }
+
971 
+
972 void WII::initExtension2() {
+
973  uint8_t buf[1];
+
974  buf[0] = 0x00;
+
975  writeData(0xA400FB, 1, buf);
+
976 }
+
977 
+
978 void WII::initMotionPlus() {
+
979  uint8_t buf[1];
+
980  buf[0] = 0x55;
+
981  writeData(0xA600F0, 1, buf);
+
982 }
+
983 
+
984 void WII::activateMotionPlus() {
+
985  uint8_t buf[1];
+
986  if(pBtd->wiiUProController) {
+
987 #ifdef DEBUG_USB_HOST
+
988  Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80);
+
989 #endif
+
990  buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07
+
991  } else if(activateNunchuck) {
992 #ifdef DEBUG_USB_HOST
-
993  Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80);
+
993  Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80);
994 #endif
-
995  buf[0] = 0x04; // Don't use any extension
-
996  }
-
997  writeData(0xA600FE, 1, buf);
-
998 }
-
999 
-
1000 void WII::readData(uint32_t offset, uint16_t size, bool EEPROM) {
-
1001  uint8_t cmd_buf[8];
-
1002  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
1003  cmd_buf[1] = 0x17; // Read data
-
1004  if (EEPROM)
-
1005  cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01); // Read from EEPROM
-
1006  else
-
1007  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Read from memory
-
1008  cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
-
1009  cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
-
1010  cmd_buf[5] = (uint8_t)(offset & 0xFF);
-
1011  cmd_buf[6] = (uint8_t)((size & 0xFF00) >> 8);
-
1012  cmd_buf[7] = (uint8_t)(size & 0xFF);
-
1013 
-
1014  HID_Command(cmd_buf, 8);
-
1015 }
-
1016 
-
1017 void WII::readExtensionType() {
-
1018  readData(0xA400FA, 6, false);
-
1019 }
+
995  buf[0] = 0x05; // Activate nunchuck pass-through mode
+
996  }//else if(classicControllerConnected && extensionConnected)
+
997  //buf[0] = 0x07;
+
998  else {
+
999 #ifdef DEBUG_USB_HOST
+
1000  Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80);
+
1001 #endif
+
1002  buf[0] = 0x04; // Don't use any extension
+
1003  }
+
1004  writeData(0xA600FE, 1, buf);
+
1005 }
+
1006 
+
1007 void WII::readData(uint32_t offset, uint16_t size, bool EEPROM) {
+
1008  uint8_t cmd_buf[8];
+
1009  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
1010  cmd_buf[1] = 0x17; // Read data
+
1011  if(EEPROM)
+
1012  cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01); // Read from EEPROM
+
1013  else
+
1014  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Read from memory
+
1015  cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
+
1016  cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
+
1017  cmd_buf[5] = (uint8_t)(offset & 0xFF);
+
1018  cmd_buf[6] = (uint8_t)((size & 0xFF00) >> 8);
+
1019  cmd_buf[7] = (uint8_t)(size & 0xFF);
1020 
-
1021 void WII::readCalData() {
-
1022  readData(0x0016, 8, true);
-
1023 }
-
1024 
-
1025 void WII::checkMotionPresent() {
-
1026  readData(0xA600FA, 6, false);
-
1027 }
-
1028 
-
1029 /************************************************************/
-
1030 /* WII Commands */
+
1021  HID_Command(cmd_buf, 8);
+
1022 }
+
1023 
+
1024 void WII::readExtensionType() {
+
1025  readData(0xA400FA, 6, false);
+
1026 }
+
1027 
+
1028 void WII::readCalData() {
+
1029  readData(0x0016, 8, true);
+
1030 }
1031 
-
1032 /************************************************************/
-
1033 
-
1034 bool WII::getButtonPress(Button b) { // Return true when a button is pressed
-
1035  if (wiiUProControllerConnected)
-
1036  return (ButtonState & pgm_read_dword(&PROCONTROLLERBUTTONS[(uint8_t)b]));
-
1037  else
-
1038  return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
-
1039 }
+
1032 void WII::checkMotionPresent() {
+
1033  readData(0xA600FA, 6, false);
+
1034 }
+
1035 
+
1036 /************************************************************/
+
1037 /* WII Commands */
+
1038 
+
1039 /************************************************************/
1040 
-
1041 bool WII::getButtonClick(Button b) { // Only return true when a button is clicked
-
1042  uint32_t button;
-
1043  if (wiiUProControllerConnected)
-
1044  button = pgm_read_dword(&PROCONTROLLERBUTTONS[(uint8_t)b]);
-
1045  else
-
1046  button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
-
1047  bool click = (ButtonClickState & button);
-
1048  ButtonClickState &= ~button; // clear "click" event
-
1049  return click;
-
1050 }
-
1051 
-
1052 uint8_t WII::getAnalogHat(Hat a) {
-
1053  if (!nunchuckConnected)
-
1054  return 127; // Return center position
-
1055  else {
-
1056  uint8_t output = hatValues[(uint8_t)a];
-
1057  if (output == 0xFF || output == 0x00) // The joystick will only read 255 or 0 when the cable is unplugged or initializing, so we will just return the center position
-
1058  return 127;
-
1059  else
-
1060  return output;
-
1061  }
-
1062 }
-
1063 
-
1064 uint16_t WII::getAnalogHat(AnalogHat a) {
-
1065  if (!wiiUProControllerConnected)
-
1066  return 2000;
-
1067  else {
-
1068  uint16_t output = hatValues[(uint8_t)a];
-
1069  if (output == 0x00) // The joystick will only read 0 when it is first initializing, so we will just return the center position
-
1070  return 2000;
-
1071  else
-
1072  return output;
-
1073  }
-
1074 }
-
1075 
-
1076 void WII::onInit() {
-
1077  if (pFuncOnInit)
-
1078  pFuncOnInit(); // Call the user function
-
1079  else
-
1080  setLedStatus();
+
1041 bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed
+
1042  if(wiiUProControllerConnected)
+
1043  return (ButtonState & pgm_read_dword(&WII_PROCONTROLLER_BUTTONS[(uint8_t)b]));
+
1044  else
+
1045  return (ButtonState & pgm_read_dword(&WII_BUTTONS[(uint8_t)b]));
+
1046 }
+
1047 
+
1048 bool WII::getButtonClick(ButtonEnum b) { // Only return true when a button is clicked
+
1049  uint32_t button;
+
1050  if(wiiUProControllerConnected)
+
1051  button = pgm_read_dword(&WII_PROCONTROLLER_BUTTONS[(uint8_t)b]);
+
1052  else
+
1053  button = pgm_read_dword(&WII_BUTTONS[(uint8_t)b]);
+
1054  bool click = (ButtonClickState & button);
+
1055  ButtonClickState &= ~button; // clear "click" event
+
1056  return click;
+
1057 }
+
1058 
+
1059 uint8_t WII::getAnalogHat(HatEnum a) {
+
1060  if(!nunchuckConnected)
+
1061  return 127; // Return center position
+
1062  else {
+
1063  uint8_t output = hatValues[(uint8_t)a];
+
1064  if(output == 0xFF || output == 0x00) // The joystick will only read 255 or 0 when the cable is unplugged or initializing, so we will just return the center position
+
1065  return 127;
+
1066  else
+
1067  return output;
+
1068  }
+
1069 }
+
1070 
+
1071 uint16_t WII::getAnalogHat(AnalogHatEnum a) {
+
1072  if(!wiiUProControllerConnected)
+
1073  return 2000;
+
1074  else {
+
1075  uint16_t output = hatValues[(uint8_t)a];
+
1076  if(output == 0x00) // The joystick will only read 0 when it is first initializing, so we will just return the center position
+
1077  return 2000;
+
1078  else
+
1079  return output;
+
1080  }
1081 }
1082 
-
1083 /************************************************************/
-
1084 /* The following functions are for the IR camera */
-
1085 /************************************************************/
-
1086 
-
1087 #ifdef WIICAMERA
-
1088 
-
1089 void WII::IRinitialize() { // Turns on and initialises the IR camera
-
1090 
-
1091  enableIRCamera1();
-
1092 #ifdef DEBUG_USB_HOST
-
1093  Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80);
-
1094 #endif
-
1095  delay(80);
-
1096 
-
1097  enableIRCamera2();
-
1098 #ifdef DEBUG_USB_HOST
-
1099  Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80);
-
1100 #endif
-
1101  delay(80);
-
1102 
-
1103  write0x08Value();
-
1104 #ifdef DEBUG_USB_HOST
-
1105  Notify(PSTR("\r\nWrote hex number 0x08"), 0x80);
-
1106 #endif
-
1107  delay(80);
-
1108 
-
1109  writeSensitivityBlock1();
-
1110 #ifdef DEBUG_USB_HOST
-
1111  Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80);
-
1112 #endif
-
1113  delay(80);
-
1114 
-
1115  writeSensitivityBlock2();
-
1116 #ifdef DEBUG_USB_HOST
-
1117  Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80);
-
1118 #endif
-
1119  delay(80);
-
1120 
-
1121  uint8_t mode_num = 0x03;
-
1122  setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05
+
1083 void WII::onInit() {
+
1084  if(pFuncOnInit)
+
1085  pFuncOnInit(); // Call the user function
+
1086  else
+
1087  setLedStatus();
+
1088 }
+
1089 
+
1090 /************************************************************/
+
1091 /* The following functions are for the IR camera */
+
1092 /************************************************************/
+
1093 
+
1094 #ifdef WIICAMERA
+
1095 
+
1096 void WII::IRinitialize() { // Turns on and initialises the IR camera
+
1097 
+
1098  enableIRCamera1();
+
1099 #ifdef DEBUG_USB_HOST
+
1100  Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80);
+
1101 #endif
+
1102  delay(80);
+
1103 
+
1104  enableIRCamera2();
+
1105 #ifdef DEBUG_USB_HOST
+
1106  Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80);
+
1107 #endif
+
1108  delay(80);
+
1109 
+
1110  write0x08Value();
+
1111 #ifdef DEBUG_USB_HOST
+
1112  Notify(PSTR("\r\nWrote hex number 0x08"), 0x80);
+
1113 #endif
+
1114  delay(80);
+
1115 
+
1116  writeSensitivityBlock1();
+
1117 #ifdef DEBUG_USB_HOST
+
1118  Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80);
+
1119 #endif
+
1120  delay(80);
+
1121 
+
1122  writeSensitivityBlock2();
1123 #ifdef DEBUG_USB_HOST
-
1124  Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80);
-
1125  D_PrintHex<uint8_t > (mode_num, 0x80);
-
1126 #endif
-
1127  delay(80);
-
1128 
-
1129  write0x08Value();
+
1124  Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80);
+
1125 #endif
+
1126  delay(80);
+
1127 
+
1128  uint8_t mode_num = 0x03;
+
1129  setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05
1130 #ifdef DEBUG_USB_HOST
-
1131  Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80);
-
1132 #endif
-
1133  delay(80);
-
1134 
-
1135  setReportMode(false, 0x33);
-
1136  //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet
+
1131  Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80);
+
1132  D_PrintHex<uint8_t > (mode_num, 0x80);
+
1133 #endif
+
1134  delay(80);
+
1135 
+
1136  write0x08Value();
1137 #ifdef DEBUG_USB_HOST
-
1138  Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80);
+
1138  Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80);
1139 #endif
1140  delay(80);
1141 
-
1142  statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked
-
1143 #ifdef DEBUG_USB_HOST
-
1144  Notify(PSTR("\r\nIR Initialized"), 0x80);
-
1145 #endif
-
1146 }
-
1147 
-
1148 void WII::enableIRCamera1() {
-
1149  uint8_t cmd_buf[3];
-
1150  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
1151  cmd_buf[1] = 0x13; // Output report 13
-
1152  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit and sets bit 2
-
1153  HID_Command(cmd_buf, 3);
-
1154 }
-
1155 
-
1156 void WII::enableIRCamera2() {
-
1157  uint8_t cmd_buf[3];
-
1158  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
-
1159  cmd_buf[1] = 0x1A; // Output report 1A
-
1160  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit and sets bit 2
-
1161  HID_Command(cmd_buf, 3);
-
1162 }
-
1163 
-
1164 void WII::writeSensitivityBlock1() {
-
1165  uint8_t buf[9];
-
1166  buf[0] = 0x00;
-
1167  buf[1] = 0x00;
-
1168  buf[2] = 0x00;
-
1169  buf[3] = 0x00;
-
1170  buf[4] = 0x00;
-
1171  buf[5] = 0x00;
-
1172  buf[6] = 0x90;
-
1173  buf[7] = 0x00;
-
1174  buf[8] = 0x41;
-
1175 
-
1176  writeData(0xB00000, 9, buf);
-
1177 }
-
1178 
-
1179 void WII::writeSensitivityBlock2() {
-
1180  uint8_t buf[2];
-
1181  buf[0] = 0x40;
-
1182  buf[1] = 0x00;
-
1183 
-
1184  writeData(0xB0001A, 2, buf);
-
1185 }
-
1186 
-
1187 void WII::write0x08Value() {
-
1188  uint8_t cmd = 0x08;
-
1189  writeData(0xb00030, 1, &cmd);
-
1190 }
-
1191 
-
1192 void WII::setWiiModeNumber(uint8_t mode_number) { // mode_number in hex i.e. 0x03 for extended mode
-
1193  writeData(0xb00033, 1, &mode_number);
-
1194 }
-
1195 #endif
-
WII::wiimoteConnected
bool wiimoteConnected
Definition: Wii.h:239
-
BTD::incomingWii
bool incomingWii
Definition: BTD.h:432
-
WII::gyroPitchRaw
int16_t gyroPitchRaw
Definition: Wii.h:307
-
nunchuck_connected_flag
#define nunchuck_connected_flag
Definition: Wii.h:77
-
WII::rollGyroScale
uint16_t rollGyroScale
Definition: Wii.h:299
-
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1222
-
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:121
-
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1209
-
L2CAP_CONTROL_CONFIG_REQUEST
#define L2CAP_CONTROL_CONFIG_REQUEST
Definition: BTHID.h:34
-
WII::setLedRaw
void setLedRaw(uint8_t value)
Definition: Wii.cpp:876
-
WII::yawGyroScale
uint16_t yawGyroScale
Definition: Wii.h:300
-
BTD
Definition: BTD.h:158
-
HatX
Definition: Wii.h:82
-
WII_FLAG_NUNCHUCK_CONNECTED
#define WII_FLAG_NUNCHUCK_CONNECTED
Definition: Wii.h:74
-
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1275
-
WII::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: Wii.cpp:134
-
l2cap_disconnect_response_interrupt_flag
#define l2cap_disconnect_response_interrupt_flag
Definition: BTHID.h:59
-
motion_plus_connected_flag
#define motion_plus_connected_flag
Definition: Wii.h:76
-
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:434
-
WII::gyroRoll
double gyroRoll
Definition: Wii.h:285
-
WII::setLedToggle
void setLedToggle(LED a)
Definition: Wii.cpp:893
-
WII::setRumbleOn
void setRumbleOn()
Definition: Wii.cpp:864
-
WII::Reset
virtual void Reset()
Definition: Wii.cpp:103
-
LeftHatY
Definition: controllerEnums.h:113
-
WII::accZnunchuck
int16_t accZnunchuck
Definition: Wii.h:278
-
L2CAP_LED_STATE
#define L2CAP_LED_STATE
Definition: Wii.h:46
-
LEDS
const uint8_t LEDS[]
Definition: PS3Enums.h:43
-
WII::getBatteryLevel
uint8_t getBatteryLevel()
Definition: Wii.cpp:912
-
WII::disconnect
virtual void disconnect()
Definition: Wii.cpp:117
-
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:436
-
RightHatX
Definition: controllerEnums.h:115
-
WII::accXnunchuck
int16_t accXnunchuck
Definition: Wii.h:278
-
WII::getButtonClick
bool getButtonClick(Button b)
Definition: Wii.cpp:1041
-
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTHID.h:47
-
LED
LED
Definition: controllerEnums.h:27
-
l2cap_connection_request_control_flag
#define l2cap_connection_request_control_flag
Definition: BTHID.h:60
-
WII::gyroRollRaw
int16_t gyroRollRaw
Definition: Wii.h:306
-
PROCONTROLLERBUTTONS
const uint32_t PROCONTROLLERBUTTONS[]
Definition: Wii.cpp:58
+
1142  setReportMode(false, 0x33);
+
1143  //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet
+
1144 #ifdef DEBUG_USB_HOST
+
1145  Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80);
+
1146 #endif
+
1147  delay(80);
+
1148 
+
1149  statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked
+
1150 #ifdef DEBUG_USB_HOST
+
1151  Notify(PSTR("\r\nIR Initialized"), 0x80);
+
1152 #endif
+
1153 }
+
1154 
+
1155 void WII::enableIRCamera1() {
+
1156  uint8_t cmd_buf[3];
+
1157  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
1158  cmd_buf[1] = 0x13; // Output report 13
+
1159  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit and sets bit 2
+
1160  HID_Command(cmd_buf, 3);
+
1161 }
+
1162 
+
1163 void WII::enableIRCamera2() {
+
1164  uint8_t cmd_buf[3];
+
1165  cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
+
1166  cmd_buf[1] = 0x1A; // Output report 1A
+
1167  cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01); // Keep the rumble bit and sets bit 2
+
1168  HID_Command(cmd_buf, 3);
+
1169 }
+
1170 
+
1171 void WII::writeSensitivityBlock1() {
+
1172  uint8_t buf[9];
+
1173  buf[0] = 0x00;
+
1174  buf[1] = 0x00;
+
1175  buf[2] = 0x00;
+
1176  buf[3] = 0x00;
+
1177  buf[4] = 0x00;
+
1178  buf[5] = 0x00;
+
1179  buf[6] = 0x90;
+
1180  buf[7] = 0x00;
+
1181  buf[8] = 0x41;
+
1182 
+
1183  writeData(0xB00000, 9, buf);
+
1184 }
+
1185 
+
1186 void WII::writeSensitivityBlock2() {
+
1187  uint8_t buf[2];
+
1188  buf[0] = 0x40;
+
1189  buf[1] = 0x00;
+
1190 
+
1191  writeData(0xB0001A, 2, buf);
+
1192 }
+
1193 
+
1194 void WII::write0x08Value() {
+
1195  uint8_t cmd = 0x08;
+
1196  writeData(0xb00030, 1, &cmd);
+
1197 }
+
1198 
+
1199 void WII::setWiiModeNumber(uint8_t mode_number) { // mode_number in hex i.e. 0x03 for extended mode
+
1200  writeData(0xb00033, 1, &mode_number);
+
1201 }
+
1202 #endif
+
WII::wiimoteConnected
bool wiimoteConnected
Definition: Wii.h:199
+
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTD.h:139
+
BTD::incomingWii
bool incomingWii
Definition: BTD.h:507
+
UHS_ACL_HANDLE_OK
#define UHS_ACL_HANDLE_OK(x, y)
Definition: BTD.h:207
+
RightHatX
Definition: controllerEnums.h:122
+
WII::gyroPitchRaw
int16_t gyroPitchRaw
Definition: Wii.h:271
+
wii_clear_flag
#define wii_clear_flag(flag)
Definition: Wii.h:32
+
L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
Definition: BTD.h:143
+
L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTD.h:115
+
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTD.h:113
+
WII::rollGyroScale
uint16_t rollGyroScale
Definition: Wii.h:263
+
BTD::l2cap_connection_response
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
Definition: BTD.cpp:1234
+
SUCCESSFUL
#define SUCCESSFUL
Definition: BTD.h:177
+
BTD::l2cap_connection_request
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
Definition: BTD.cpp:1221
+
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTD.h:142
+
WII::setLedToggle
void setLedToggle(LEDEnum a)
Definition: Wii.cpp:900
+
WII::setLedRaw
void setLedRaw(uint8_t value)
Definition: Wii.cpp:878
+
WII::getAnalogHat
uint8_t getAnalogHat(HatEnum a)
Definition: Wii.cpp:1059
+
WII::yawGyroScale
uint16_t yawGyroScale
Definition: Wii.h:264
+
HatY
Definition: Wii.h:39
+
BTD
Definition: BTD.h:230
+
WII_FLAG_NUNCHUCK_CONNECTED
#define WII_FLAG_NUNCHUCK_CONNECTED
Definition: Wii.h:28
+
BTD::l2cap_disconnection_request
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1287
+
WII::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: Wii.cpp:135
+
BTD::pairWithWii
bool pairWithWii
Definition: BTD.h:509
+
WII::gyroRoll
double gyroRoll
Definition: Wii.h:249
+
WII::setRumbleOn
void setRumbleOn()
Definition: Wii.cpp:866
+
WII::Reset
virtual void Reset()
Definition: Wii.cpp:104
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
TURN_ON_LED
#define TURN_ON_LED
Definition: BTD.h:129
+
WII::accZnunchuck
int16_t accZnunchuck
Definition: Wii.h:242
+
WII::getBatteryLevel
uint8_t getBatteryLevel()
Definition: Wii.cpp:919
+
WII::disconnect
virtual void disconnect()
Definition: Wii.cpp:118
+
BTD::motionPlusInside
bool motionPlusInside
Definition: BTD.h:511
+
L2CAP_DONE
#define L2CAP_DONE
Definition: BTD.h:104
+
wii_set_flag
#define wii_set_flag(flag)
Definition: Wii.h:31
+
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTD.h:109
+
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTD.h:103
+
WII::accXnunchuck
int16_t accXnunchuck
Definition: Wii.h:242
+
L2CAP_CONTROL_CONFIG_REQUEST
#define L2CAP_CONTROL_CONFIG_REQUEST
Definition: BTD.h:108
+
WII::gyroRollRaw
int16_t gyroRollRaw
Definition: Wii.h:270
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
Wii.h
-
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1288
-
WII::IRinitialize
void IRinitialize()
Definition: Wii.cpp:1089
-
L2CAP_FLAG_INTERRUPT_CONNECTED
#define L2CAP_FLAG_INTERRUPT_CONNECTED
Definition: BTHID.h:45
-
HatY
Definition: Wii.h:84
+
BTD::l2cap_disconnection_response
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
Definition: BTD.cpp:1300
+
WII::IRinitialize
void IRinitialize()
Definition: Wii.cpp:1096
+
HatX
Definition: Wii.h:37
Notify
#define Notify(...)
Definition: message.h:44
-
L2CAP_WAIT
#define L2CAP_WAIT
Definition: BTHID.h:26
-
WII::setRumbleToggle
void setRumbleToggle()
Definition: Wii.cpp:870
-
WII::gyroPitchZero
int16_t gyroPitchZero
Definition: Wii.h:314
-
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTHID.h:49
-
WII::pitchGyroScale
uint16_t pitchGyroScale
Definition: Wii.h:298
-
l2cap_connection_request_interrupt_flag
#define l2cap_connection_request_interrupt_flag
Definition: BTHID.h:61
-
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:126
-
WII::getWiimoteRoll
double getWiimoteRoll()
Definition: Wii.h:260
-
WII::WII
WII(BTD *p, bool pair=false)
Definition: Wii.cpp:84
-
WII::rollGyroSpeed
double rollGyroSpeed
Definition: Wii.h:292
-
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTHID.h:40
-
BTD::connectToWii
bool connectToWii
Definition: BTD.h:428
-
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:438
-
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:412
-
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1133
-
WII::setLedStatus
void setLedStatus()
Definition: Wii.cpp:899
-
LeftHatX
Definition: controllerEnums.h:111
-
WII_FLAG_MOTION_PLUS_CONNECTED
#define WII_FLAG_MOTION_PLUS_CONNECTED
Definition: Wii.h:73
-
L2CAP_CONTROL_CONNECT_REQUEST
#define L2CAP_CONTROL_CONNECT_REQUEST
Definition: BTHID.h:33
-
WII::setLedOn
void setLedOn(LED a)
Definition: Wii.cpp:887
-
WII::accYwiimote
int16_t accYwiimote
Definition: Wii.h:272
-
L2CAP_DONE
#define L2CAP_DONE
Definition: BTHID.h:38
-
WII::wiiUProControllerConnected
bool wiiUProControllerConnected
Definition: Wii.h:250
-
L2CAP_INTERRUPT_SETUP
#define L2CAP_INTERRUPT_SETUP
Definition: BTHID.h:30
-
l2cap_disconnect_response_control_flag
#define l2cap_disconnect_response_control_flag
Definition: BTHID.h:58
-
L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
Definition: BTHID.h:51
-
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTHID.h:50
-
L2CAP_CHECK_EXTENSION_STATE
#define L2CAP_CHECK_EXTENSION_STATE
Definition: Wii.h:44
-
WII::setRumbleOff
void setRumbleOff()
Definition: Wii.cpp:858
-
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:112
-
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:114
-
WII::setAllOff
void setAllOff()
Definition: Wii.cpp:852
-
WII::setLedOff
void setLedOff()
Definition: Wii.h:193
-
WII::gyroYaw
double gyroYaw
Definition: Wii.h:287
-
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:127
-
L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_CONNECT_REQUEST
Definition: BTHID.h:35
-
WII::nunchuckConnected
bool nunchuckConnected
Definition: Wii.h:246
-
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:258
-
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:398
-
WII::gyroYawRaw
int16_t gyroYawRaw
Definition: Wii.h:305
-
WII::getButtonPress
bool getButtonPress(Button b)
Definition: Wii.cpp:1034
-
WII::isIRCameraEnabled
bool isIRCameraEnabled()
Definition: Wii.h:425
-
Hat
Hat
Definition: Wii.h:80
-
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:115
-
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:111
-
l2cap_connected_interrupt_flag
#define l2cap_connected_interrupt_flag
Definition: BTHID.h:55
-
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:113
-
L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_FLAG_CONTROL_CONNECTED
Definition: BTHID.h:44
-
WII::getWiimotePitch
double getWiimotePitch()
Definition: Wii.h:257
-
WII::pair
void pair(void)
Definition: Wii.h:131
-
l2cap_config_success_control_flag
#define l2cap_config_success_control_flag
Definition: BTHID.h:56
-
l2cap_config_success_interrupt_flag
#define l2cap_config_success_interrupt_flag
Definition: BTHID.h:57
-
l2cap_connected_control_flag
#define l2cap_connected_control_flag
Definition: BTHID.h:54
-
L2CAP_CHECK_MOTION_PLUS_STATE
#define L2CAP_CHECK_MOTION_PLUS_STATE
Definition: Wii.h:43
-
Button
Button
Definition: controllerEnums.h:44
-
WII::yawGyroSpeed
double yawGyroSpeed
Definition: Wii.h:293
-
WII::accYnunchuck
int16_t accYnunchuck
Definition: Wii.h:278
-
WII::gyroYawZero
int16_t gyroYawZero
Definition: Wii.h:312
-
L2CAP_CONTROL_SUCCESS
#define L2CAP_CONTROL_SUCCESS
Definition: BTHID.h:29
-
WII::pitchGyroSpeed
double pitchGyroSpeed
Definition: Wii.h:291
-
WII::gyroPitch
double gyroPitch
Definition: Wii.h:283
-
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1181
-
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1256
-
PENDING
#define PENDING
Definition: BTD.h:120
-
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1239
-
L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_CONFIG_REQUEST
Definition: BTHID.h:37
-
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:110
-
WII::motionPlusConnected
bool motionPlusConnected
Definition: Wii.h:248
-
WII::gyroRollZero
int16_t gyroRollZero
Definition: Wii.h:313
-
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTHID.h:41
-
L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
Definition: BTHID.h:48
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
RightHatY
Definition: controllerEnums.h:117
-
BUTTONS
const uint32_t BUTTONS[]
Definition: PS3Enums.h:62
-
L2CAP_INIT_MOTION_PLUS_STATE
#define L2CAP_INIT_MOTION_PLUS_STATE
Definition: Wii.h:45
-
WII::Run
virtual void Run()
Definition: Wii.cpp:682
-
WII::accXwiimote
int16_t accXwiimote
Definition: Wii.h:272
-
WII::getAnalogHat
uint8_t getAnalogHat(Hat a)
Definition: Wii.cpp:1052
-
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTHID.h:46
-
WII::accZwiimote
int16_t accZwiimote
Definition: Wii.h:272
-
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:109
+
WII::setRumbleToggle
void setRumbleToggle()
Definition: Wii.cpp:872
+
WII::gyroPitchZero
int16_t gyroPitchZero
Definition: Wii.h:278
+
WII::pitchGyroScale
uint16_t pitchGyroScale
Definition: Wii.h:262
+
L2CAP_CONTROL_CONNECT_REQUEST
#define L2CAP_CONTROL_CONNECT_REQUEST
Definition: BTD.h:107
+
HID_CTRL_PSM
#define HID_CTRL_PSM
Definition: BTD.h:182
+
WII::getWiimoteRoll
double getWiimoteRoll()
Definition: Wii.h:222
+
WII::WII
WII(BTD *p, bool pair=false)
Definition: Wii.cpp:85
+
WII::rollGyroSpeed
double rollGyroSpeed
Definition: Wii.h:256
+
WII_CHECK_EXTENSION_STATE
#define WII_CHECK_EXTENSION_STATE
Definition: BTD.h:132
+
RightHatY
Definition: controllerEnums.h:124
+
BTD::connectToWii
bool connectToWii
Definition: BTD.h:503
+
BTD::wiiUProController
bool wiiUProController
Definition: BTD.h:513
+
BTD::hci_handle
uint16_t hci_handle
Definition: BTD.h:487
+
BTD::hci_disconnect
void hci_disconnect(uint16_t handle)
Definition: BTD.cpp:1145
+
WII::setLedStatus
void setLedStatus()
Definition: Wii.cpp:906
+
L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
Definition: BTD.h:145
+
WII_FLAG_MOTION_PLUS_CONNECTED
#define WII_FLAG_MOTION_PLUS_CONNECTED
Definition: Wii.h:27
+
WII_LEDS
const uint8_t WII_LEDS[]
Definition: Wii.cpp:25
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
WII::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: Wii.cpp:1048
+
WII::accYwiimote
int16_t accYwiimote
Definition: Wii.h:236
+
WII::wiiUProControllerConnected
bool wiiUProControllerConnected
Definition: Wii.h:210
+
l2cap_check_flag
#define l2cap_check_flag(flag)
Definition: BTD.h:160
+
WII::setRumbleOff
void setRumbleOff()
Definition: Wii.cpp:860
+
L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_CMD_CONFIG_REQUEST
Definition: BTD.h:168
+
L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_FLAG_CONTROL_CONNECTED
Definition: BTD.h:138
+
L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CMD_DISCONNECT_REQUEST
Definition: BTD.h:170
+
WII::setAllOff
void setAllOff()
Definition: Wii.cpp:854
+
L2CAP_CONTROL_DISCONNECT
#define L2CAP_CONTROL_DISCONNECT
Definition: BTD.h:110
+
WII_BUTTONS
const uint32_t WII_BUTTONS[]
Definition: Wii.cpp:40
+
L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
Definition: BTD.h:136
+
WII::setLedOff
void setLedOff()
Definition: Wii.h:152
+
WII_CHECK_MOTION_PLUS_STATE
#define WII_CHECK_MOTION_PLUS_STATE
Definition: BTD.h:131
+
WII::gyroYaw
double gyroYaw
Definition: Wii.h:251
+
HID_INTR_PSM
#define HID_INTR_PSM
Definition: BTD.h:183
+
WII::nunchuckConnected
bool nunchuckConnected
Definition: Wii.h:206
+
OFF
Definition: controllerEnums.h:28
+
BTD::registerServiceClass
int8_t registerServiceClass(BluetoothService *pService)
Definition: BTD.h:333
+
BTD::l2capConnectionClaimed
bool l2capConnectionClaimed
Definition: BTD.h:473
+
WII::gyroYawRaw
int16_t gyroYawRaw
Definition: Wii.h:269
+
WII::isIRCameraEnabled
bool isIRCameraEnabled()
Definition: Wii.h:389
+
WII_PROCONTROLLER_BUTTONS
const uint32_t WII_PROCONTROLLER_BUTTONS[]
Definition: Wii.cpp:59
+
L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_DISCONNECT_RESPONSE
Definition: BTD.h:171
+
L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
Definition: BTD.h:167
+
L2CAP_CMD_CONFIG_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
Definition: BTD.h:169
+
WII::getWiimotePitch
double getWiimotePitch()
Definition: Wii.h:218
+
WII::pair
void pair(void)
Definition: Wii.h:89
+
WII::setLedOn
void setLedOn(LEDEnum a)
Definition: Wii.cpp:890
+
WII::yawGyroSpeed
double yawGyroSpeed
Definition: Wii.h:257
+
HatEnum
HatEnum
Definition: Wii.h:35
+
WII::accYnunchuck
int16_t accYnunchuck
Definition: Wii.h:242
+
WII::gyroYawZero
int16_t gyroYawZero
Definition: Wii.h:276
+
wii_check_flag
#define wii_check_flag(flag)
Definition: Wii.h:30
+
WII::pitchGyroSpeed
double pitchGyroSpeed
Definition: Wii.h:255
+
WII::gyroPitch
double gyroPitch
Definition: Wii.h:247
+
WII_INIT_MOTION_PLUS_STATE
#define WII_INIT_MOTION_PLUS_STATE
Definition: BTD.h:133
+
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1193
+
BTD::l2cap_config_response
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
Definition: BTD.cpp:1268
+
PENDING
#define PENDING
Definition: BTD.h:176
+
L2CAP_FLAG_INTERRUPT_CONNECTED
#define L2CAP_FLAG_INTERRUPT_CONNECTED
Definition: BTD.h:144
+
l2cap_set_flag
#define l2cap_set_flag(flag)
Definition: BTD.h:161
+
BTD::l2cap_config_request
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
Definition: BTD.cpp:1251
+
LeftHatY
Definition: controllerEnums.h:120
+
WII::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: Wii.cpp:1041
+
L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
Definition: BTD.h:137
+
LeftHatX
Definition: controllerEnums.h:118
+
L2CAP_CMD_CONNECTION_REQUEST
#define L2CAP_CMD_CONNECTION_REQUEST
Definition: BTD.h:166
+
WII::motionPlusConnected
bool motionPlusConnected
Definition: Wii.h:208
+
WII::gyroRollZero
int16_t gyroRollZero
Definition: Wii.h:277
+
L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_CONNECT_REQUEST
Definition: BTD.h:114
+
WII::Run
virtual void Run()
Definition: Wii.cpp:684
+
L2CAP_INTERRUPT_DISCONNECT
#define L2CAP_INTERRUPT_DISCONNECT
Definition: BTD.h:116
+
WII::accXwiimote
int16_t accXwiimote
Definition: Wii.h:236
+
WII::accZwiimote
int16_t accZwiimote
Definition: Wii.h:236
+
L2CAP_CMD_COMMAND_REJECT
#define L2CAP_CMD_COMMAND_REJECT
Definition: BTD.h:165
diff --git a/_wii_8h.html b/_wii_8h.html index 325b9b25..0effd198 100644 --- a/_wii_8h.html +++ b/_wii_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Wii.h File Reference @@ -31,7 +31,7 @@ - + @@ -119,531 +119,36 @@ Classes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - + + + + + +

Macros

#define WIICAMERA
 
#define L2CAP_WAIT   0
 
#define L2CAP_CONTROL_SUCCESS   1
 
#define L2CAP_INTERRUPT_SETUP   2
 
#define L2CAP_CONTROL_CONNECT_REQUEST   3
 
#define L2CAP_CONTROL_CONFIG_REQUEST   4
 
#define L2CAP_INTERRUPT_CONNECT_REQUEST   5
 
#define L2CAP_INTERRUPT_CONFIG_REQUEST   6
 
#define L2CAP_CHECK_MOTION_PLUS_STATE   7
 
#define L2CAP_CHECK_EXTENSION_STATE   8
 
#define L2CAP_INIT_MOTION_PLUS_STATE   9
 
#define L2CAP_LED_STATE   10
 
#define L2CAP_DONE   11
 
#define L2CAP_INTERRUPT_DISCONNECT   12
 
#define L2CAP_CONTROL_DISCONNECT   13
 
#define L2CAP_FLAG_CONTROL_CONNECTED   0x001
 
#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x002
 
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x004
 
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x008
 
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x040
 
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x080
 
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x100
 
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x200
 
#define l2cap_connected_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
 
#define l2cap_connected_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
 
#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
 
#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
 
#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
 
#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
 
#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
 
#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
 
#define WII_FLAG_MOTION_PLUS_CONNECTED   0x400
#define WII_FLAG_MOTION_PLUS_CONNECTED   0x01
 
#define WII_FLAG_NUNCHUCK_CONNECTED   0x800
#define WII_FLAG_NUNCHUCK_CONNECTED   0x02
 
#define motion_plus_connected_flag   (l2cap_event_flag & WII_FLAG_MOTION_PLUS_CONNECTED)
 
#define nunchuck_connected_flag   (l2cap_event_flag & WII_FLAG_NUNCHUCK_CONNECTED)
 
#define wii_check_flag(flag)   (wii_event_flag & (flag))
 
#define wii_set_flag(flag)   (wii_event_flag |= (flag))
 
#define wii_clear_flag(flag)   (wii_event_flag &= ~(flag))
 
- - +

Enumerations

enum  Hat { HatX = 0, -HatY = 1 +
enum  HatEnum { HatX = 0, +HatY = 1 }
 
 

Macro Definition Documentation

- -
-
- - - - -
#define WIICAMERA
-
-

You will have to uncomment this to use the IR camera

- -

Definition at line 27 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_WAIT   0
-
- -

Definition at line 30 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_SUCCESS   1
-
- -

Definition at line 33 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_SETUP   2
-
- -

Definition at line 34 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_CONNECT_REQUEST   3
-
- -

Definition at line 37 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_CONFIG_REQUEST   4
-
- -

Definition at line 38 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_CONNECT_REQUEST   5
-
- -

Definition at line 39 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_CONFIG_REQUEST   6
-
- -

Definition at line 41 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CHECK_MOTION_PLUS_STATE   7
-
- -

Definition at line 43 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CHECK_EXTENSION_STATE   8
-
- -

Definition at line 44 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_INIT_MOTION_PLUS_STATE   9
-
- -

Definition at line 45 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_LED_STATE   10
-
- -

Definition at line 46 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_DONE   11
-
- -

Definition at line 47 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_INTERRUPT_DISCONNECT   12
-
- -

Definition at line 49 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_CONTROL_DISCONNECT   13
-
- -

Definition at line 50 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONTROL_CONNECTED   0x001
-
- -

Definition at line 53 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_INTERRUPT_CONNECTED   0x002
-
- -

Definition at line 54 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS   0x004
-
- -

Definition at line 55 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS   0x008
-
- -

Definition at line 56 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE   0x040
-
- -

Definition at line 57 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE   0x080
-
- -

Definition at line 58 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST   0x100
-
- -

Definition at line 59 of file Wii.h.

- -
-
- -
-
- - - - -
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST   0x200
-
- -

Definition at line 60 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_connected_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
-
- -

Definition at line 63 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_connected_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
-
- -

Definition at line 64 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
- -

Definition at line 65 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_config_success_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
- -

Definition at line 66 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_control_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
- -

Definition at line 67 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_disconnect_response_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
- -

Definition at line 68 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_control_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
- -

Definition at line 69 of file Wii.h.

- -
-
- -
-
- - - - -
#define l2cap_connection_request_interrupt_flag   (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
- -

Definition at line 70 of file Wii.h.

- -
-
- +
#define WII_FLAG_MOTION_PLUS_CONNECTED   0x400#define WII_FLAG_MOTION_PLUS_CONNECTED   0x01
-

Definition at line 73 of file Wii.h.

+

Definition at line 27 of file Wii.h.

@@ -652,64 +157,90 @@ Enumerations
- +
#define WII_FLAG_NUNCHUCK_CONNECTED   0x800#define WII_FLAG_NUNCHUCK_CONNECTED   0x02
-

Definition at line 74 of file Wii.h.

+

Definition at line 28 of file Wii.h.

- +
- + + + + +
#define motion_plus_connected_flag   (l2cap_event_flag & WII_FLAG_MOTION_PLUS_CONNECTED)#define wii_check_flag( flag)   (wii_event_flag & (flag))
-

Definition at line 76 of file Wii.h.

+

Definition at line 30 of file Wii.h.

- +
- + + + + +
#define nunchuck_connected_flag   (l2cap_event_flag & WII_FLAG_NUNCHUCK_CONNECTED)#define wii_set_flag( flag)   (wii_event_flag |= (flag))
-

Definition at line 77 of file Wii.h.

+

Definition at line 31 of file Wii.h.

+ +
+
+ +
+
+ + + + + + + + +
#define wii_clear_flag( flag)   (wii_event_flag &= ~(flag))
+
+ +

Definition at line 32 of file Wii.h.

Enumeration Type Documentation

- +
- +
enum Hatenum HatEnum

Enum used to read the joystick on the Nunchuck.

- -
Enumerator
HatX  +
Enumerator
HatX 

Read the x-axis on the Nunchuck joystick.

HatY  +
HatY 

Read the y-axis on the Nunchuck joystick.

-

Definition at line 80 of file Wii.h.

+

Definition at line 35 of file Wii.h.

@@ -718,7 +249,7 @@ Enumerations diff --git a/_wii_8h_source.html b/_wii_8h_source.html index 45b7f868..343e8ffd 100644 --- a/_wii_8h_source.html +++ b/_wii_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Wii.h Source File @@ -31,7 +31,7 @@ - + @@ -114,385 +114,346 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
23 #include "BTD.h"
24 #include "controllerEnums.h"
25 
-
27 #define WIICAMERA
-
28 
-
29 /* Bluetooth L2CAP states for L2CAP_task() */
-
30 #define L2CAP_WAIT 0
-
31 
-
32 // These states are used if the Wiimote is the host
-
33 #define L2CAP_CONTROL_SUCCESS 1
-
34 #define L2CAP_INTERRUPT_SETUP 2
-
35 
-
36 // These states are used if the Arduino is the host
-
37 #define L2CAP_CONTROL_CONNECT_REQUEST 3
-
38 #define L2CAP_CONTROL_CONFIG_REQUEST 4
-
39 #define L2CAP_INTERRUPT_CONNECT_REQUEST 5
-
40 
-
41 #define L2CAP_INTERRUPT_CONFIG_REQUEST 6
-
42 
-
43 #define L2CAP_CHECK_MOTION_PLUS_STATE 7
-
44 #define L2CAP_CHECK_EXTENSION_STATE 8
-
45 #define L2CAP_INIT_MOTION_PLUS_STATE 9
-
46 #define L2CAP_LED_STATE 10
-
47 #define L2CAP_DONE 11
-
48 
-
49 #define L2CAP_INTERRUPT_DISCONNECT 12
-
50 #define L2CAP_CONTROL_DISCONNECT 13
-
51 
-
52 /* L2CAP event flags */
-
53 #define L2CAP_FLAG_CONTROL_CONNECTED 0x001
-
54 #define L2CAP_FLAG_INTERRUPT_CONNECTED 0x002
-
55 #define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS 0x004
-
56 #define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS 0x008
-
57 #define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE 0x040
-
58 #define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE 0x080
-
59 #define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x100
-
60 #define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST 0x200
-
61 
-
62 /* Macros for L2CAP event flag tests */
-
63 #define l2cap_connected_control_flag (l2cap_event_flag & L2CAP_FLAG_CONTROL_CONNECTED)
-
64 #define l2cap_connected_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_INTERRUPT_CONNECTED)
-
65 #define l2cap_config_success_control_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_CONTROL_SUCCESS)
-
66 #define l2cap_config_success_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS)
-
67 #define l2cap_disconnect_response_control_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE)
-
68 #define l2cap_disconnect_response_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE)
-
69 #define l2cap_connection_request_control_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_CONTROL_REQUEST)
-
70 #define l2cap_connection_request_interrupt_flag (l2cap_event_flag & L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST)
-
71 
-
72 /* Wii event flags */
-
73 #define WII_FLAG_MOTION_PLUS_CONNECTED 0x400
-
74 #define WII_FLAG_NUNCHUCK_CONNECTED 0x800
-
75 
-
76 #define motion_plus_connected_flag (l2cap_event_flag & WII_FLAG_MOTION_PLUS_CONNECTED)
-
77 #define nunchuck_connected_flag (l2cap_event_flag & WII_FLAG_NUNCHUCK_CONNECTED)
-
78 
-
80 enum Hat {
-
82  HatX = 0,
-
84  HatY = 1,
-
85 };
-
86 
-
92 class WII : public BluetoothService {
-
93 public:
-
100  WII(BTD *p, bool pair = false);
-
101 
-
107  virtual void ACLData(uint8_t* ACLData);
-
109  virtual void Run();
-
111  virtual void Reset();
-
113  virtual void disconnect();
-
125  bool getButtonPress(Button b);
-
126  bool getButtonClick(Button b);
-
131  void pair(void) {
-
132  if(pBtd)
-
133  pBtd->pairWithWiimote();
-
134  }
-
140  uint8_t getAnalogHat(Hat a);
-
146  uint16_t getAnalogHat(AnalogHat a);
-
147 
-
152  double getPitch() {
-
153  if (motionPlusConnected)
-
154  return compPitch;
-
155  return getWiimotePitch();
-
156  };
-
157 
-
162  double getRoll() {
-
163  if (motionPlusConnected)
-
164  return compRoll;
-
165  return getWiimoteRoll();
-
166  };
-
167 
-
174  double getYaw() {
-
175  return gyroYaw;
-
176  };
-
177 
-
179  void setAllOff();
-
181  void setRumbleOff();
-
183  void setRumbleOn();
-
185  void setRumbleToggle();
-
186 
-
191  void setLedRaw(uint8_t value);
-
193  void setLedOff() {
-
194  setLedRaw(0);
-
195  }
-
200  void setLedOff(LED a);
-
205  void setLedOn(LED a);
-
210  void setLedToggle(LED a);
-
218  void setLedStatus();
-
219 
-
224  uint8_t getBatteryLevel();
-
229  uint8_t getWiiState() {
-
230  return wiiState;
-
231  };
-
232 
-
237  void attachOnInit(void (*funcOnInit)(void)) {
-
238  pFuncOnInit = funcOnInit;
-
239  };
-
244  bool wiimoteConnected;
-
246  bool nunchuckConnected;
-
248  bool motionPlusConnected;
-
250  bool wiiUProControllerConnected;
-
253  /* IMU Data, might be usefull if you need to do something more advanced than just calculating the angle */
-
254 
-
257  double getWiimotePitch() {
-
258  return (atan2(accYwiimote, accZwiimote) + PI) * RAD_TO_DEG;
-
259  };
-
260  double getWiimoteRoll() {
-
261  return (atan2(accXwiimote, accZwiimote) + PI) * RAD_TO_DEG;
-
262  };
-
267  double getNunchuckPitch() {
-
268  return (atan2(accYnunchuck, accZnunchuck) + PI) * RAD_TO_DEG;
-
269  };
-
270  double getNunchuckRoll() {
-
271  return (atan2(accXnunchuck, accZnunchuck) + PI) * RAD_TO_DEG;
-
272  };
-
277  int16_t accXwiimote, accYwiimote, accZwiimote;
-
278  int16_t accXnunchuck, accYnunchuck, accZnunchuck;
-
281  /* Variables for the gyro inside the Motion Plus */
-
283  double gyroPitch;
-
285  double gyroRoll;
-
287  double gyroYaw;
-
288 
-
291  double pitchGyroSpeed;
-
292  double rollGyroSpeed;
-
293  double yawGyroSpeed;
-
298  uint16_t pitchGyroScale;
-
299  uint16_t rollGyroScale;
-
300  uint16_t yawGyroScale;
-
305  int16_t gyroYawRaw;
-
306  int16_t gyroRollRaw;
-
307  int16_t gyroPitchRaw;
-
312  int16_t gyroYawZero;
-
313  int16_t gyroRollZero;
-
314  int16_t gyroPitchZero;
-
317 #ifdef WIICAMERA
-
318 
-
322  void IRinitialize();
-
323 
-
328  uint16_t getIRx1() {
-
329  return IR_object_x1;
-
330  };
-
331 
-
336  uint16_t getIRy1() {
-
337  return IR_object_y1;
-
338  };
-
339 
-
344  uint8_t getIRs1() {
-
345  return IR_object_s1;
-
346  };
-
347 
-
352  uint16_t getIRx2() {
-
353  return IR_object_x2;
-
354  };
-
355 
-
360  uint16_t getIRy2() {
-
361  return IR_object_y2;
-
362  };
-
363 
-
368  uint8_t getIRs2() {
-
369  return IR_object_s2;
-
370  };
-
371 
-
376  uint16_t getIRx3() {
-
377  return IR_object_x3;
-
378  };
-
379 
-
384  uint16_t getIRy3() {
-
385  return IR_object_y3;
-
386  };
-
387 
-
392  uint8_t getIRs3() {
-
393  return IR_object_s3;
-
394  };
-
395 
-
400  uint16_t getIRx4() {
-
401  return IR_object_x4;
-
402  };
-
403 
-
408  uint16_t getIRy4() {
-
409  return IR_object_y4;
-
410  };
+
26 /* Wii event flags */
+
27 #define WII_FLAG_MOTION_PLUS_CONNECTED 0x01
+
28 #define WII_FLAG_NUNCHUCK_CONNECTED 0x02
+
29 
+
30 #define wii_check_flag(flag) (wii_event_flag & (flag))
+
31 #define wii_set_flag(flag) (wii_event_flag |= (flag))
+
32 #define wii_clear_flag(flag) (wii_event_flag &= ~(flag))
+
33 
+
35 enum HatEnum {
+
37  HatX = 0,
+
39  HatY = 1,
+
40 };
+
41 
+
47 class WII : public BluetoothService {
+
48 public:
+
55  WII(BTD *p, bool pair = false);
+
56 
+
62  virtual void ACLData(uint8_t* ACLData);
+
64  virtual void Run();
+
66  virtual void Reset();
+
68  virtual void disconnect();
+
82  bool getButtonPress(ButtonEnum b);
+
83  bool getButtonClick(ButtonEnum b);
+
89  void pair(void) {
+
90  if(pBtd)
+
91  pBtd->pairWithWiimote();
+
92  };
+
98  uint8_t getAnalogHat(HatEnum a);
+
104  uint16_t getAnalogHat(AnalogHatEnum a);
+
105 
+
110  double getPitch() {
+
111  if(motionPlusConnected)
+
112  return compPitch;
+
113  return getWiimotePitch();
+
114  };
+
115 
+
120  double getRoll() {
+
121  if(motionPlusConnected)
+
122  return compRoll;
+
123  return getWiimoteRoll();
+
124  };
+
125 
+
132  double getYaw() {
+
133  return gyroYaw;
+
134  };
+
135 
+
137  void setAllOff();
+
139  void setRumbleOff();
+
141  void setRumbleOn();
+
143  void setRumbleToggle();
+
144 
+
149  void setLedRaw(uint8_t value);
+
150 
+
152  void setLedOff() {
+
153  setLedRaw(0);
+
154  };
+
159  void setLedOff(LEDEnum a);
+
164  void setLedOn(LEDEnum a);
+
169  void setLedToggle(LEDEnum a);
+
177  void setLedStatus();
+
178 
+
183  uint8_t getBatteryLevel();
+
184 
+
189  uint8_t getWiiState() {
+
190  return wiiState;
+
191  };
+
192 
+
197  void attachOnInit(void (*funcOnInit)(void)) {
+
198  pFuncOnInit = funcOnInit;
+
199  };
+
204  bool wiimoteConnected;
+
206  bool nunchuckConnected;
+
208  bool motionPlusConnected;
+
210  bool wiiUProControllerConnected;
+
213  /* IMU Data, might be usefull if you need to do something more advanced than just calculating the angle */
+
214 
+
218  double getWiimotePitch() {
+
219  return (atan2(accYwiimote, accZwiimote) + PI) * RAD_TO_DEG;
+
220  };
+
221 
+
222  double getWiimoteRoll() {
+
223  return (atan2(accXwiimote, accZwiimote) + PI) * RAD_TO_DEG;
+
224  };
+
230  double getNunchuckPitch() {
+
231  return (atan2(accYnunchuck, accZnunchuck) + PI) * RAD_TO_DEG;
+
232  };
+
233 
+
234  double getNunchuckRoll() {
+
235  return (atan2(accXnunchuck, accZnunchuck) + PI) * RAD_TO_DEG;
+
236  };
+
241  int16_t accXwiimote, accYwiimote, accZwiimote;
+
242  int16_t accXnunchuck, accYnunchuck, accZnunchuck;
+
245  /* Variables for the gyro inside the Motion Plus */
+
247  double gyroPitch;
+
249  double gyroRoll;
+
251  double gyroYaw;
+
252 
+
255  double pitchGyroSpeed;
+
256  double rollGyroSpeed;
+
257  double yawGyroSpeed;
+
262  uint16_t pitchGyroScale;
+
263  uint16_t rollGyroScale;
+
264  uint16_t yawGyroScale;
+
269  int16_t gyroYawRaw;
+
270  int16_t gyroRollRaw;
+
271  int16_t gyroPitchRaw;
+
276  int16_t gyroYawZero;
+
277  int16_t gyroRollZero;
+
278  int16_t gyroPitchZero;
+
281 #ifdef WIICAMERA
+
282 
+
286  void IRinitialize();
+
287 
+
292  uint16_t getIRx1() {
+
293  return IR_object_x1;
+
294  };
+
295 
+
300  uint16_t getIRy1() {
+
301  return IR_object_y1;
+
302  };
+
303 
+
308  uint8_t getIRs1() {
+
309  return IR_object_s1;
+
310  };
+
311 
+
316  uint16_t getIRx2() {
+
317  return IR_object_x2;
+
318  };
+
319 
+
324  uint16_t getIRy2() {
+
325  return IR_object_y2;
+
326  };
+
327 
+
332  uint8_t getIRs2() {
+
333  return IR_object_s2;
+
334  };
+
335 
+
340  uint16_t getIRx3() {
+
341  return IR_object_x3;
+
342  };
+
343 
+
348  uint16_t getIRy3() {
+
349  return IR_object_y3;
+
350  };
+
351 
+
356  uint8_t getIRs3() {
+
357  return IR_object_s3;
+
358  };
+
359 
+
364  uint16_t getIRx4() {
+
365  return IR_object_x4;
+
366  };
+
367 
+
372  uint16_t getIRy4() {
+
373  return IR_object_y4;
+
374  };
+
375 
+
380  uint8_t getIRs4() {
+
381  return IR_object_s4;
+
382  };
+
383 
+
389  bool isIRCameraEnabled() {
+
390  return (wiiState & 0x08);
+
391  };
+
393 #endif
+
394 
+
395 private:
+
396  BTD *pBtd; // Pointer to BTD instance
+
397 
+
403  void onInit();
+
404  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
405 
+
406  void L2CAP_task(); // L2CAP state machine
+
407 
+
408  /* Variables filled from HCI event management */
+
409  uint16_t hci_handle;
+
410  bool activeConnection; // Used to indicate if it's already has established a connection
411 
-
416  uint8_t getIRs4() {
-
417  return IR_object_s4;
-
418  };
-
419 
-
425  bool isIRCameraEnabled() {
-
426  return(wiiState & 0x08);
-
427  };
-
429 #endif
-
430 
-
431 private:
-
432  BTD *pBtd; // Pointer to BTD instance
-
433 
-
439  void onInit();
-
440  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
-
441 
-
442  void L2CAP_task(); // L2CAP state machine
-
443 
-
444  /* Variables filled from HCI event management */
-
445  uint16_t hci_handle;
-
446  bool activeConnection; // Used to indicate if it's already has established a connection
-
447 
-
448  /* Variables used by high level L2CAP task */
-
449  uint8_t l2cap_state;
-
450  uint16_t l2cap_event_flag; // l2cap flags of received Bluetooth events
-
451 
-
452  uint32_t ButtonState;
-
453  uint32_t OldButtonState;
-
454  uint32_t ButtonClickState;
-
455  uint16_t hatValues[4];
-
456 
-
457  uint8_t HIDBuffer[3]; // Used to store HID commands
-
458 
-
459  uint16_t stateCounter;
-
460  bool unknownExtensionConnected;
-
461  bool extensionConnected;
-
462  bool checkExtension; // Set to false when getBatteryLevel() is called otherwise if should be true
-
463  bool motionPlusInside; // True if it's a new Wiimote with the Motion Plus extension build into it
+
412  /* Variables used by high level L2CAP task */
+
413  uint8_t l2cap_state;
+
414  uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
+
415  uint8_t wii_event_flag; // Used for Wii flags
+
416 
+
417  uint32_t ButtonState;
+
418  uint32_t OldButtonState;
+
419  uint32_t ButtonClickState;
+
420  uint16_t hatValues[4];
+
421 
+
422  uint8_t HIDBuffer[3]; // Used to store HID commands
+
423 
+
424  uint16_t stateCounter;
+
425  bool unknownExtensionConnected;
+
426  bool extensionConnected;
+
427  bool checkExtension; // Set to false when getBatteryLevel() is called otherwise if should be true
+
428  bool motionPlusInside; // True if it's a new Wiimote with the Motion Plus extension build into it
+
429 
+
430  /* L2CAP Channels */
+
431  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
+
432  uint8_t control_dcid[2]; // 0x0060
+
433  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
+
434  uint8_t interrupt_dcid[2]; // 0x0061
+
435  uint8_t identifier; // Identifier for connection
+
436 
+
437  /* HID Commands */
+
438  void HID_Command(uint8_t* data, uint8_t nbytes);
+
439  void setReportMode(bool continuous, uint8_t mode);
+
440 
+
441  void writeData(uint32_t offset, uint8_t size, uint8_t* data);
+
442  void initExtension1();
+
443  void initExtension2();
+
444 
+
445  void statusRequest(); // Used to update the Wiimote state and battery level
+
446 
+
447  void readData(uint32_t offset, uint16_t size, bool EEPROM);
+
448  void readExtensionType();
+
449  void readCalData();
+
450 
+
451  void checkMotionPresent(); // Used to see if a Motion Plus is connected to the Wiimote
+
452  void initMotionPlus();
+
453  void activateMotionPlus();
+
454 
+
455  double compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected
+
456  double compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected
+
457 
+
458  bool activateNunchuck;
+
459  bool motionValuesReset; // This bool is true when the gyro values has been reset
+
460  unsigned long timer;
+
461 
+
462  uint8_t wiiState; // Stores the value in l2capinbuf[12] - (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4)
+
463  uint8_t batteryLevel;
464 
-
465  /* L2CAP Channels */
-
466  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
-
467  uint8_t control_dcid[2]; // 0x0060
-
468  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
-
469  uint8_t interrupt_dcid[2]; // 0x0061
-
470  uint8_t identifier; // Identifier for connection
-
471 
-
472  /* HID Commands */
-
473  void HID_Command(uint8_t* data, uint8_t nbytes);
-
474  void setReportMode(bool continuous, uint8_t mode);
-
475 
-
476  void writeData(uint32_t offset, uint8_t size, uint8_t* data);
-
477  void initExtension1();
-
478  void initExtension2();
-
479 
-
480  void statusRequest(); // Used to update the Wiimote state and battery level
-
481 
-
482  void readData(uint32_t offset, uint16_t size, bool EEPROM);
-
483  void readExtensionType();
-
484  void readCalData();
-
485 
-
486  void checkMotionPresent(); // Used to see if a Motion Plus is connected to the Wiimote
-
487  void initMotionPlus();
-
488  void activateMotionPlus();
-
489 
-
490  double compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected
-
491  double compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected
-
492 
-
493  bool activateNunchuck;
-
494  bool motionValuesReset; // This bool is true when the gyro values has been reset
-
495  unsigned long timer;
-
496 
-
497  uint8_t wiiState; // Stores the value in l2capinbuf[12] - (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4)
-
498  uint8_t batteryLevel;
-
499 
-
500 #ifdef WIICAMERA
-
501  /* Private function and variables for the readings from the IR Camera */
-
502  void enableIRCamera1(); // Sets bit 2 of output report 13
-
503  void enableIRCamera2(); // Sets bit 2 of output report 1A
-
504  void writeSensitivityBlock1();
-
505  void writeSensitivityBlock2();
-
506  void write0x08Value();
-
507  void setWiiModeNumber(uint8_t mode_number);
-
508 
-
509  uint16_t IR_object_x1; // IR x position 10 bits
-
510  uint16_t IR_object_y1; // IR y position 10 bits
-
511  uint8_t IR_object_s1; // IR size value
-
512  uint16_t IR_object_x2;
-
513  uint16_t IR_object_y2;
-
514  uint8_t IR_object_s2;
-
515  uint16_t IR_object_x3; // IR x position 10 bits
-
516  uint16_t IR_object_y3; // IR y position 10 bits
-
517  uint8_t IR_object_s3; // IR size value
-
518  uint16_t IR_object_x4;
-
519  uint16_t IR_object_y4;
-
520  uint8_t IR_object_s4;
-
521 #endif
-
522 };
-
523 #endif
-
WII::wiimoteConnected
bool wiimoteConnected
Definition: Wii.h:239
-
WII::gyroPitchRaw
int16_t gyroPitchRaw
Definition: Wii.h:307
-
WII::rollGyroScale
uint16_t rollGyroScale
Definition: Wii.h:299
-
WII::getNunchuckPitch
double getNunchuckPitch()
Definition: Wii.h:267
-
WII::setLedRaw
void setLedRaw(uint8_t value)
Definition: Wii.cpp:876
-
WII::yawGyroScale
uint16_t yawGyroScale
Definition: Wii.h:300
-
BTD
Definition: BTD.h:158
-
WII::getIRs1
uint8_t getIRs1()
Definition: Wii.h:344
-
HatX
Definition: Wii.h:82
-
WII::getIRs3
uint8_t getIRs3()
Definition: Wii.h:392
-
WII::getNunchuckRoll
double getNunchuckRoll()
Definition: Wii.h:270
-
WII::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: Wii.cpp:134
-
WII::gyroRoll
double gyroRoll
Definition: Wii.h:285
-
WII::getIRx4
uint16_t getIRx4()
Definition: Wii.h:400
-
WII::setLedToggle
void setLedToggle(LED a)
Definition: Wii.cpp:893
-
WII::setRumbleOn
void setRumbleOn()
Definition: Wii.cpp:864
-
WII::Reset
virtual void Reset()
Definition: Wii.cpp:103
-
WII::getRoll
double getRoll()
Definition: Wii.h:162
-
WII::accZnunchuck
int16_t accZnunchuck
Definition: Wii.h:278
-
WII::getBatteryLevel
uint8_t getBatteryLevel()
Definition: Wii.cpp:912
-
WII::disconnect
virtual void disconnect()
Definition: Wii.cpp:117
-
WII::getPitch
double getPitch()
Definition: Wii.h:152
-
WII::accXnunchuck
int16_t accXnunchuck
Definition: Wii.h:278
-
WII::getButtonClick
bool getButtonClick(Button b)
Definition: Wii.cpp:1041
-
WII::getWiiState
uint8_t getWiiState()
Definition: Wii.h:229
-
LED
LED
Definition: controllerEnums.h:27
-
WII::getIRy2
uint16_t getIRy2()
Definition: Wii.h:360
-
WII::gyroRollRaw
int16_t gyroRollRaw
Definition: Wii.h:306
-
WII::IRinitialize
void IRinitialize()
Definition: Wii.cpp:1089
-
HatY
Definition: Wii.h:84
+
465 #ifdef WIICAMERA
+
466  /* Private function and variables for the readings from the IR Camera */
+
467  void enableIRCamera1(); // Sets bit 2 of output report 13
+
468  void enableIRCamera2(); // Sets bit 2 of output report 1A
+
469  void writeSensitivityBlock1();
+
470  void writeSensitivityBlock2();
+
471  void write0x08Value();
+
472  void setWiiModeNumber(uint8_t mode_number);
+
473 
+
474  uint16_t IR_object_x1; // IR x position 10 bits
+
475  uint16_t IR_object_y1; // IR y position 10 bits
+
476  uint8_t IR_object_s1; // IR size value
+
477  uint16_t IR_object_x2;
+
478  uint16_t IR_object_y2;
+
479  uint8_t IR_object_s2;
+
480  uint16_t IR_object_x3; // IR x position 10 bits
+
481  uint16_t IR_object_y3; // IR y position 10 bits
+
482  uint8_t IR_object_s3; // IR size value
+
483  uint16_t IR_object_x4;
+
484  uint16_t IR_object_y4;
+
485  uint8_t IR_object_s4;
+
486 #endif
+
487 };
+
488 #endif
+
WII::wiimoteConnected
bool wiimoteConnected
Definition: Wii.h:199
+
WII::gyroPitchRaw
int16_t gyroPitchRaw
Definition: Wii.h:271
+
WII::rollGyroScale
uint16_t rollGyroScale
Definition: Wii.h:263
+
WII::getNunchuckPitch
double getNunchuckPitch()
Definition: Wii.h:230
+
WII::setLedToggle
void setLedToggle(LEDEnum a)
Definition: Wii.cpp:900
+
WII::setLedRaw
void setLedRaw(uint8_t value)
Definition: Wii.cpp:878
+
WII::getAnalogHat
uint8_t getAnalogHat(HatEnum a)
Definition: Wii.cpp:1059
+
WII::yawGyroScale
uint16_t yawGyroScale
Definition: Wii.h:264
+
HatY
Definition: Wii.h:39
+
BTD
Definition: BTD.h:230
+
WII::getIRs1
uint8_t getIRs1()
Definition: Wii.h:308
+
WII::getIRs3
uint8_t getIRs3()
Definition: Wii.h:356
+
WII::getNunchuckRoll
double getNunchuckRoll()
Definition: Wii.h:234
+
WII::ACLData
virtual void ACLData(uint8_t *ACLData)
Definition: Wii.cpp:135
+
WII::gyroRoll
double gyroRoll
Definition: Wii.h:249
+
WII::getIRx4
uint16_t getIRx4()
Definition: Wii.h:364
+
WII::setRumbleOn
void setRumbleOn()
Definition: Wii.cpp:866
+
WII::Reset
virtual void Reset()
Definition: Wii.cpp:104
+
WII::getRoll
double getRoll()
Definition: Wii.h:120
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
WII::accZnunchuck
int16_t accZnunchuck
Definition: Wii.h:242
+
WII::getBatteryLevel
uint8_t getBatteryLevel()
Definition: Wii.cpp:919
+
WII::disconnect
virtual void disconnect()
Definition: Wii.cpp:118
+
WII::getPitch
double getPitch()
Definition: Wii.h:110
+
WII::accXnunchuck
int16_t accXnunchuck
Definition: Wii.h:242
+
WII::getWiiState
uint8_t getWiiState()
Definition: Wii.h:189
+
WII::getIRy2
uint16_t getIRy2()
Definition: Wii.h:324
+
WII::gyroRollRaw
int16_t gyroRollRaw
Definition: Wii.h:270
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
+
WII::IRinitialize
void IRinitialize()
Definition: Wii.cpp:1096
+
HatX
Definition: Wii.h:37
controllerEnums.h
-
WII::getIRx2
uint16_t getIRx2()
Definition: Wii.h:352
-
WII::getIRx1
uint16_t getIRx1()
Definition: Wii.h:328
-
WII::setRumbleToggle
void setRumbleToggle()
Definition: Wii.cpp:870
-
WII::gyroPitchZero
int16_t gyroPitchZero
Definition: Wii.h:314
-
WII::pitchGyroScale
uint16_t pitchGyroScale
Definition: Wii.h:298
-
WII::getWiimoteRoll
double getWiimoteRoll()
Definition: Wii.h:260
-
WII::WII
WII(BTD *p, bool pair=false)
Definition: Wii.cpp:84
-
WII::rollGyroSpeed
double rollGyroSpeed
Definition: Wii.h:292
-
WII::getIRs4
uint8_t getIRs4()
Definition: Wii.h:416
-
WII::getIRy3
uint16_t getIRy3()
Definition: Wii.h:384
-
BluetoothService
Definition: BTD.h:139
-
WII::setLedStatus
void setLedStatus()
Definition: Wii.cpp:899
-
WII::setLedOn
void setLedOn(LED a)
Definition: Wii.cpp:887
-
WII::accYwiimote
int16_t accYwiimote
Definition: Wii.h:272
-
WII::wiiUProControllerConnected
bool wiiUProControllerConnected
Definition: Wii.h:250
-
WII::setRumbleOff
void setRumbleOff()
Definition: Wii.cpp:858
-
WII::setAllOff
void setAllOff()
Definition: Wii.cpp:852
-
WII::setLedOff
void setLedOff()
Definition: Wii.h:193
-
WII::getIRy1
uint16_t getIRy1()
Definition: Wii.h:336
-
WII::getIRx3
uint16_t getIRx3()
Definition: Wii.h:376
-
WII::gyroYaw
double gyroYaw
Definition: Wii.h:287
-
WII::nunchuckConnected
bool nunchuckConnected
Definition: Wii.h:246
-
WII::getIRy4
uint16_t getIRy4()
Definition: Wii.h:408
-
WII::gyroYawRaw
int16_t gyroYawRaw
Definition: Wii.h:305
-
WII::getButtonPress
bool getButtonPress(Button b)
Definition: Wii.cpp:1034
-
WII::isIRCameraEnabled
bool isIRCameraEnabled()
Definition: Wii.h:425
-
Hat
Hat
Definition: Wii.h:80
-
WII::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: Wii.h:237
-
WII::getYaw
double getYaw()
Definition: Wii.h:174
-
WII::getWiimotePitch
double getWiimotePitch()
Definition: Wii.h:257
-
WII::pair
void pair(void)
Definition: Wii.h:131
-
Button
Button
Definition: controllerEnums.h:44
-
WII::yawGyroSpeed
double yawGyroSpeed
Definition: Wii.h:293
-
WII::accYnunchuck
int16_t accYnunchuck
Definition: Wii.h:278
-
WII::gyroYawZero
int16_t gyroYawZero
Definition: Wii.h:312
-
WII::pitchGyroSpeed
double pitchGyroSpeed
Definition: Wii.h:291
-
BTD::pairWithWiimote
void pairWithWiimote()
Definition: BTD.h:425
-
WII::getIRs2
uint8_t getIRs2()
Definition: Wii.h:368
-
WII::gyroPitch
double gyroPitch
Definition: Wii.h:283
-
WII
Definition: Wii.h:92
+
WII::getIRx2
uint16_t getIRx2()
Definition: Wii.h:316
+
WII::getIRx1
uint16_t getIRx1()
Definition: Wii.h:292
+
WII::setRumbleToggle
void setRumbleToggle()
Definition: Wii.cpp:872
+
WII::gyroPitchZero
int16_t gyroPitchZero
Definition: Wii.h:278
+
WII::pitchGyroScale
uint16_t pitchGyroScale
Definition: Wii.h:262
+
WII::getWiimoteRoll
double getWiimoteRoll()
Definition: Wii.h:222
+
WII::WII
WII(BTD *p, bool pair=false)
Definition: Wii.cpp:85
+
WII::rollGyroSpeed
double rollGyroSpeed
Definition: Wii.h:256
+
WII::getIRs4
uint8_t getIRs4()
Definition: Wii.h:380
+
WII::getIRy3
uint16_t getIRy3()
Definition: Wii.h:348
+
BluetoothService
Definition: BTD.h:211
+
WII::setLedStatus
void setLedStatus()
Definition: Wii.cpp:906
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
WII::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: Wii.cpp:1048
+
WII::accYwiimote
int16_t accYwiimote
Definition: Wii.h:236
+
WII::wiiUProControllerConnected
bool wiiUProControllerConnected
Definition: Wii.h:210
+
WII::setRumbleOff
void setRumbleOff()
Definition: Wii.cpp:860
+
WII::setAllOff
void setAllOff()
Definition: Wii.cpp:854
+
WII::setLedOff
void setLedOff()
Definition: Wii.h:152
+
WII::getIRy1
uint16_t getIRy1()
Definition: Wii.h:300
+
WII::getIRx3
uint16_t getIRx3()
Definition: Wii.h:340
+
WII::gyroYaw
double gyroYaw
Definition: Wii.h:251
+
WII::nunchuckConnected
bool nunchuckConnected
Definition: Wii.h:206
+
WII::getIRy4
uint16_t getIRy4()
Definition: Wii.h:372
+
WII::gyroYawRaw
int16_t gyroYawRaw
Definition: Wii.h:269
+
WII::isIRCameraEnabled
bool isIRCameraEnabled()
Definition: Wii.h:389
+
WII::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: Wii.h:197
+
WII::getYaw
double getYaw()
Definition: Wii.h:132
+
WII::getWiimotePitch
double getWiimotePitch()
Definition: Wii.h:218
+
WII::pair
void pair(void)
Definition: Wii.h:89
+
WII::setLedOn
void setLedOn(LEDEnum a)
Definition: Wii.cpp:890
+
WII::yawGyroSpeed
double yawGyroSpeed
Definition: Wii.h:257
+
HatEnum
HatEnum
Definition: Wii.h:35
+
WII::accYnunchuck
int16_t accYnunchuck
Definition: Wii.h:242
+
WII::gyroYawZero
int16_t gyroYawZero
Definition: Wii.h:276
+
WII::pitchGyroSpeed
double pitchGyroSpeed
Definition: Wii.h:255
+
BTD::pairWithWiimote
void pairWithWiimote()
Definition: BTD.h:500
+
WII::getIRs2
uint8_t getIRs2()
Definition: Wii.h:332
+
WII::gyroPitch
double gyroPitch
Definition: Wii.h:247
+
WII
Definition: Wii.h:47
+
WII::getButtonPress
bool getButtonPress(ButtonEnum b)
Definition: Wii.cpp:1041
BTD.h
-
WII::motionPlusConnected
bool motionPlusConnected
Definition: Wii.h:248
-
WII::gyroRollZero
int16_t gyroRollZero
Definition: Wii.h:313
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
WII::Run
virtual void Run()
Definition: Wii.cpp:682
-
WII::accXwiimote
int16_t accXwiimote
Definition: Wii.h:272
-
WII::getAnalogHat
uint8_t getAnalogHat(Hat a)
Definition: Wii.cpp:1052
-
WII::accZwiimote
int16_t accZwiimote
Definition: Wii.h:272
+
WII::motionPlusConnected
bool motionPlusConnected
Definition: Wii.h:208
+
WII::gyroRollZero
int16_t gyroRollZero
Definition: Wii.h:277
+
WII::Run
virtual void Run()
Definition: Wii.cpp:684
+
WII::accXwiimote
int16_t accXwiimote
Definition: Wii.h:236
+
WII::accZwiimote
int16_t accZwiimote
Definition: Wii.h:236
diff --git a/_wii_camera_readme_8md.html b/_wii_camera_readme_8md.html index 0f792621..2eba6dd0 100644 --- a/_wii_camera_readme_8md.html +++ b/_wii_camera_readme_8md.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: WiiCameraReadme.md File Reference @@ -31,7 +31,7 @@ - + @@ -92,7 +92,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/_wii_camera_readme_8md_source.html b/_wii_camera_readme_8md_source.html index 9bf45477..ebd03437 100644 --- a/_wii_camera_readme_8md_source.html +++ b/_wii_camera_readme_8md_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: WiiCameraReadme.md Source File @@ -31,7 +31,7 @@ - + @@ -89,23 +89,23 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
2 
3 This library is large, if you run into memory problems when uploading to the Arduino, disable serial debugging.
4 
-
5 To enable the IR camera code, uncomment \#define WIICAMERA in Wii.h.
+
5 To enable the IR camera code, simply set ```ENABLE_WII_IR_CAMERA``` to 1 in [settings.h](settings.h).
6 
7 This library implements the following settings:
8 
9 * Report sensitivity mode: 00 00 00 00 00 00 90 00 41 40 00 Suggested by inio (high sensitivity)
-
10 * Data Format: Extended mode (0x03). Full mode is not working yet. The output reports 0x3e and 0x3f need tampering with
+
10 * Data Format: Extended mode (0x03). Full mode is not working yet. The output reports 0x3e and 0x3f need tampering with
11  * In this mode the camera outputs x and y coordinates and a size dimension for the 4 brightest points.
12 
13 Again, read through <http://wiibrew.org/wiki/Wiimote#IR_Camera> to get an understanding of the camera and its settings.
-
Full
Definition: PS3Enums.h:194
-
WIICAMERA
#define WIICAMERA
Definition: Wii.h:27
+
ENABLE_WII_IR_CAMERA
#define ENABLE_WII_IR_CAMERA
Definition: settings.h:45
+
Full
Definition: PS3Enums.h:195
diff --git a/_x_b_o_x_o_l_d_8cpp.html b/_x_b_o_x_o_l_d_8cpp.html index 3329058e..cd338b35 100644 --- a/_x_b_o_x_o_l_d_8cpp.html +++ b/_x_b_o_x_o_l_d_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXOLD.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,16 +104,16 @@ Include dependency graph for XBOXOLD.cpp: - - + +

Variables

const uint8_t XBOXOLDBUTTONS []
 
const uint8_t XBOXOLD_BUTTONS []
 

Variable Documentation

- +
- +
const uint8_t XBOXOLDBUTTONS[]const uint8_t XBOXOLD_BUTTONS[]
@@ -150,7 +150,7 @@ Variables diff --git a/_x_b_o_x_o_l_d_8cpp_source.html b/_x_b_o_x_o_l_d_8cpp_source.html index aa9d6374..47fa05bc 100644 --- a/_x_b_o_x_o_l_d_8cpp_source.html +++ b/_x_b_o_x_o_l_d_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXOLD.cpp Source File @@ -31,7 +31,7 @@
- + @@ -111,7 +111,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
20 //#define EXTRADEBUG // Uncomment to get even more debugging data
21 //#define PRINTREPORT // Uncomment to print the report send by the Xbox controller
22 
-
24 const uint8_t XBOXOLDBUTTONS[] PROGMEM = {
+
24 const uint8_t XBOXOLD_BUTTONS[] PROGMEM = {
25  0x01, // UP
26  0x08, // RIGHT
27  0x02, // DOWN
@@ -138,379 +138,379 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
48 pUsb(p), // pointer to USB class instance - mandatory
49 bAddress(0), // device address - mandatory
50 bPollEnable(false) { // don't start polling before dongle is connected
-
51  for (uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
+
51  for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
52  epInfo[i].epAddr = 0;
53  epInfo[i].maxPktSize = (i) ? 0 : 8;
54  epInfo[i].epAttribs = 0;
55  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
56  }
57 
-
58  if (pUsb) // register in USB subsystem
+
58  if(pUsb) // register in USB subsystem
59  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
60 }
61 
62 uint8_t XBOXOLD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
63  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
-
64  uint8_t rcode;
-
65  UsbDevice *p = NULL;
-
66  EpInfo *oldep_ptr = NULL;
-
67  uint16_t PID;
-
68  uint16_t VID;
-
69 
-
70  // get memory address of USB device address pool
-
71  AddressPool &addrPool = pUsb->GetAddressPool();
-
72 #ifdef EXTRADEBUG
-
73  Notify(PSTR("\r\nXBOXUSB Init"), 0x80);
-
74 #endif
-
75  // check if address has already been assigned to an instance
-
76  if (bAddress) {
-
77 #ifdef DEBUG_USB_HOST
-
78  Notify(PSTR("\r\nAddress in use"), 0x80);
-
79 #endif
-
80  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
81  }
-
82 
-
83  // Get pointer to pseudo device with address 0 assigned
-
84  p = addrPool.GetUsbDevicePtr(0);
-
85 
-
86  if (!p) {
-
87 #ifdef DEBUG_USB_HOST
-
88  Notify(PSTR("\r\nAddress not found"), 0x80);
-
89 #endif
-
90  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
91  }
-
92 
-
93  if (!p->epinfo) {
-
94 #ifdef DEBUG_USB_HOST
-
95  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
96 #endif
-
97  return USB_ERROR_EPINFO_IS_NULL;
-
98  }
-
99 
-
100  // Save old pointer to EP_RECORD of address 0
-
101  oldep_ptr = p->epinfo;
-
102 
-
103  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
104  p->epinfo = epInfo;
-
105 
-
106  p->lowspeed = lowspeed;
-
107 
-
108  // Get device descriptor
-
109  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
110  // Restore p->epinfo
-
111  p->epinfo = oldep_ptr;
-
112 
-
113  if (rcode)
-
114  goto FailGetDevDescr;
-
115 
-
116  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
117  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
118 
-
119  if ((VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) || (PID != XBOX_OLD_PID1 && PID != XBOX_OLD_PID2 && PID != XBOX_OLD_PID3 && PID != XBOX_OLD_PID4)) // Check if VID and PID match
-
120  goto FailUnknownDevice;
-
121 
-
122  // Allocate new address according to device class
-
123  bAddress = addrPool.AllocAddress(parent, false, port);
-
124 
-
125  if (!bAddress)
-
126  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
127 
-
128  // Extract Max Packet Size from device descriptor
-
129  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
130 
-
131  // Assign new address to the device
-
132  rcode = pUsb->setAddr(0, 0, bAddress);
-
133  if (rcode) {
-
134  p->lowspeed = false;
-
135  addrPool.FreeAddress(bAddress);
-
136  bAddress = 0;
-
137 #ifdef DEBUG_USB_HOST
-
138  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
139  D_PrintHex<uint8_t > (rcode, 0x80);
-
140 #endif
-
141  return rcode;
-
142  }
-
143 #ifdef EXTRADEBUG
-
144  Notify(PSTR("\r\nAddr: "), 0x80);
-
145  D_PrintHex<uint8_t > (bAddress, 0x80);
-
146 #endif
-
147  delay(300); // Spec says you should wait at least 200ms
-
148 
-
149  p->lowspeed = false;
-
150 
-
151  //get pointer to assigned address record
-
152  p = addrPool.GetUsbDevicePtr(bAddress);
-
153  if (!p)
-
154  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
155 
-
156  p->lowspeed = lowspeed;
-
157 
-
158  // Assign epInfo to epinfo pointer - only EP0 is known
-
159  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
160  if (rcode)
-
161  goto FailSetDevTblEntry;
-
162 
-
163  /* The application will work in reduced host mode, so we can save program and data
-
164  memory space. After verifying the VID we will use known values for the
-
165  configuration values for device, interface, endpoints and HID for the XBOX controllers */
-
166 
-
167  /* Initialize data structures for endpoints of device */
-
168  epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX report endpoint
-
169  epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
170  epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
171  epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
172  epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
173  epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
174  epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX output endpoint
-
175  epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
176  epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
177  epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
178  epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
179  epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
180 
-
181  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
-
182  if (rcode)
-
183  goto FailSetDevTblEntry;
-
184 
-
185  delay(200); // Give time for address change
-
186 
-
187  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
-
188  if (rcode)
-
189  goto FailSetConfDescr;
-
190 
-
191 #ifdef DEBUG_USB_HOST
-
192  Notify(PSTR("\r\nXbox Controller Connected\r\n"), 0x80);
-
193 #endif
-
194  if (pFuncOnInit)
-
195  pFuncOnInit(); // Call the user function
-
196  XboxConnected = true;
-
197  bPollEnable = true;
-
198  return 0; // Successful configuration
-
199 
-
200  /* Diagnostic messages */
-
201 FailGetDevDescr:
-
202 #ifdef DEBUG_USB_HOST
-
203  NotifyFailGetDevDescr();
-
204  goto Fail;
-
205 #endif
-
206 
-
207 FailSetDevTblEntry:
-
208 #ifdef DEBUG_USB_HOST
-
209  NotifyFailSetDevTblEntry();
-
210  goto Fail;
-
211 #endif
-
212 
-
213 FailSetConfDescr:
-
214 #ifdef DEBUG_USB_HOST
-
215  NotifyFailSetConfDescr();
-
216  goto Fail;
+
64  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
65  uint8_t rcode;
+
66  UsbDevice *p = NULL;
+
67  EpInfo *oldep_ptr = NULL;
+
68  uint16_t PID;
+
69  uint16_t VID;
+
70 
+
71  // get memory address of USB device address pool
+
72  AddressPool &addrPool = pUsb->GetAddressPool();
+
73 #ifdef EXTRADEBUG
+
74  Notify(PSTR("\r\nXBOXUSB Init"), 0x80);
+
75 #endif
+
76  // check if address has already been assigned to an instance
+
77  if(bAddress) {
+
78 #ifdef DEBUG_USB_HOST
+
79  Notify(PSTR("\r\nAddress in use"), 0x80);
+
80 #endif
+
81  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
82  }
+
83 
+
84  // Get pointer to pseudo device with address 0 assigned
+
85  p = addrPool.GetUsbDevicePtr(0);
+
86 
+
87  if(!p) {
+
88 #ifdef DEBUG_USB_HOST
+
89  Notify(PSTR("\r\nAddress not found"), 0x80);
+
90 #endif
+
91  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
92  }
+
93 
+
94  if(!p->epinfo) {
+
95 #ifdef DEBUG_USB_HOST
+
96  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
97 #endif
+
98  return USB_ERROR_EPINFO_IS_NULL;
+
99  }
+
100 
+
101  // Save old pointer to EP_RECORD of address 0
+
102  oldep_ptr = p->epinfo;
+
103 
+
104  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
105  p->epinfo = epInfo;
+
106 
+
107  p->lowspeed = lowspeed;
+
108 
+
109  // Get device descriptor
+
110  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
+
111  // Restore p->epinfo
+
112  p->epinfo = oldep_ptr;
+
113 
+
114  if(rcode)
+
115  goto FailGetDevDescr;
+
116 
+
117  VID = udd->idVendor;
+
118  PID = udd->idProduct;
+
119 
+
120  if((VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) || (PID != XBOX_OLD_PID1 && PID != XBOX_OLD_PID2 && PID != XBOX_OLD_PID3 && PID != XBOX_OLD_PID4)) // Check if VID and PID match
+
121  goto FailUnknownDevice;
+
122 
+
123  // Allocate new address according to device class
+
124  bAddress = addrPool.AllocAddress(parent, false, port);
+
125 
+
126  if(!bAddress)
+
127  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
128 
+
129  // Extract Max Packet Size from device descriptor
+
130  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
131 
+
132  // Assign new address to the device
+
133  rcode = pUsb->setAddr(0, 0, bAddress);
+
134  if(rcode) {
+
135  p->lowspeed = false;
+
136  addrPool.FreeAddress(bAddress);
+
137  bAddress = 0;
+
138 #ifdef DEBUG_USB_HOST
+
139  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
140  D_PrintHex<uint8_t > (rcode, 0x80);
+
141 #endif
+
142  return rcode;
+
143  }
+
144 #ifdef EXTRADEBUG
+
145  Notify(PSTR("\r\nAddr: "), 0x80);
+
146  D_PrintHex<uint8_t > (bAddress, 0x80);
+
147 #endif
+
148  //delay(300); // Spec says you should wait at least 200ms
+
149 
+
150  p->lowspeed = false;
+
151 
+
152  //get pointer to assigned address record
+
153  p = addrPool.GetUsbDevicePtr(bAddress);
+
154  if(!p)
+
155  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
156 
+
157  p->lowspeed = lowspeed;
+
158 
+
159  // Assign epInfo to epinfo pointer - only EP0 is known
+
160  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
161  if(rcode)
+
162  goto FailSetDevTblEntry;
+
163 
+
164  /* The application will work in reduced host mode, so we can save program and data
+
165  memory space. After verifying the VID we will use known values for the
+
166  configuration values for device, interface, endpoints and HID for the XBOX controllers */
+
167 
+
168  /* Initialize data structures for endpoints of device */
+
169  epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX report endpoint
+
170  epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
171  epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
172  epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
173  epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = 0;
+
174  epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = 0;
+
175  epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX output endpoint
+
176  epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
177  epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
178  epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
179  epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = 0;
+
180  epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = 0;
+
181 
+
182  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
+
183  if(rcode)
+
184  goto FailSetDevTblEntry;
+
185 
+
186  delay(200); // Give time for address change
+
187 
+
188  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
+
189  if(rcode)
+
190  goto FailSetConfDescr;
+
191 
+
192 #ifdef DEBUG_USB_HOST
+
193  Notify(PSTR("\r\nXbox Controller Connected\r\n"), 0x80);
+
194 #endif
+
195  if(pFuncOnInit)
+
196  pFuncOnInit(); // Call the user function
+
197  XboxConnected = true;
+
198  bPollEnable = true;
+
199  return 0; // Successful configuration
+
200 
+
201  /* Diagnostic messages */
+
202 FailGetDevDescr:
+
203 #ifdef DEBUG_USB_HOST
+
204  NotifyFailGetDevDescr();
+
205  goto Fail;
+
206 #endif
+
207 
+
208 FailSetDevTblEntry:
+
209 #ifdef DEBUG_USB_HOST
+
210  NotifyFailSetDevTblEntry();
+
211  goto Fail;
+
212 #endif
+
213 
+
214 FailSetConfDescr:
+
215 #ifdef DEBUG_USB_HOST
+
216  NotifyFailSetConfDescr();
217 #endif
-
218 FailUnknownDevice:
-
219 #ifdef DEBUG_USB_HOST
-
220  NotifyFailUnknownDevice(VID, PID);
-
221 #endif
-
222  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
223 
-
224 Fail:
-
225 #ifdef DEBUG_USB_HOST
-
226  Notify(PSTR("\r\nXbox Init Failed, error code: "), 0x80);
-
227  NotifyFail(rcode);
-
228 #endif
-
229  Release();
-
230  return rcode;
-
231 }
-
232 
-
233 /* Performs a cleanup after failed Init() attempt */
-
234 uint8_t XBOXOLD::Release() {
-
235  XboxConnected = false;
-
236  pUsb->GetAddressPool().FreeAddress(bAddress);
-
237  bAddress = 0;
-
238  bPollEnable = false;
-
239  return 0;
-
240 }
-
241 
-
242 uint8_t XBOXOLD::Poll() {
-
243  if (!bPollEnable)
-
244  return 0;
-
245  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
-
246  pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
-
247  readReport();
-
248 #ifdef PRINTREPORT
-
249  printReport(BUFFER_SIZE); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox controller
-
250 #endif
-
251  return 0;
-
252 }
-
253 
-
254 void XBOXOLD::readReport() {
-
255  ButtonState = readBuf[2];
-
256 
-
257  for (uint8_t i = 0; i < sizeof(buttonValues); i++)
-
258  buttonValues[i] = readBuf[i + 4]; // A, B, X, Y, BLACK, WHITE, L1, and R1
-
259 
-
260  hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[12] << 8) | readBuf[13]);
-
261  hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[14] << 8) | readBuf[15]);
-
262  hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[16] << 8) | readBuf[17]);
-
263  hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[18] << 8) | readBuf[19]);
-
264 
-
265  //Notify(PSTR("\r\nButtonState"), 0x80);
-
266  //PrintHex<uint8_t>(ButtonState, 0x80);
-
267 
-
268  if (ButtonState != OldButtonState || memcmp(buttonValues, oldButtonValues, sizeof(buttonValues)) != 0) {
-
269  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
-
270  OldButtonState = ButtonState;
-
271 
-
272  for (uint8_t i = 0; i < sizeof(buttonValues); i++) {
-
273  if (oldButtonValues[i] == 0 && buttonValues[i] != 0)
-
274  buttonClicked[i] = true; // Update A, B, X, Y, BLACK, WHITE, L1, and R1 click state
-
275  oldButtonValues[i] = buttonValues[i];
-
276  }
-
277  }
-
278 }
-
279 
-
280 void XBOXOLD::printReport(uint16_t length) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox controller
-
281 #ifdef PRINTREPORT
-
282  if (readBuf == NULL)
-
283  return;
-
284  for (uint8_t i = 0; i < length; i++) {
-
285  D_PrintHex<uint8_t > (readBuf[i], 0x80);
-
286  Notify(PSTR(" "), 0x80);
-
287  }
-
288  Notify(PSTR("\r\n"), 0x80);
-
289 #endif
-
290 }
-
291 
-
292 uint8_t XBOXOLD::getButtonPress(Button b) {
-
293  uint8_t button = pgm_read_byte(&XBOXOLDBUTTONS[(uint8_t)b]);
-
294  if (b == A || b == B || b == X || b == Y || b == BLACK || b == WHITE || b == L1 || b == R1) // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
-
295  return buttonValues[button]; // Analog buttons
-
296  return (ButtonState & button); // Digital buttons
-
297 }
-
298 
-
299 bool XBOXOLD::getButtonClick(Button b) {
-
300  uint8_t button = pgm_read_byte(&XBOXOLDBUTTONS[(uint8_t)b]);
-
301  if (b == A || b == B || b == X || b == Y || b == BLACK || b == WHITE || b == L1 || b == R1) { // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
-
302  if (buttonClicked[button]) {
-
303  buttonClicked[button] = false;
-
304  return true;
-
305  }
-
306  return false;
-
307  }
-
308 
-
309  bool click = (ButtonClickState & button);
-
310  ButtonClickState &= ~button; // clear "click" event
-
311  return click;
-
312 }
-
313 
-
314 int16_t XBOXOLD::getAnalogHat(AnalogHat a) {
-
315  return hatValue[a];
-
316 }
-
317 
-
318 /* Xbox Controller commands */
-
319 void XBOXOLD::XboxCommand(uint8_t* data, uint16_t nbytes) {
-
320  //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
-
321  pUsb->ctrlReq(bAddress, epInfo[XBOX_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
-
322 }
-
323 
-
324 void XBOXOLD::setRumbleOn(uint8_t lValue, uint8_t rValue) {
-
325  uint8_t writeBuf[6];
-
326 
-
327  writeBuf[0] = 0x00;
-
328  writeBuf[1] = 0x06;
-
329  writeBuf[2] = 0x00;
-
330  writeBuf[3] = rValue; // small weight
-
331  writeBuf[4] = 0x00;
-
332  writeBuf[5] = lValue; // big weight
-
333 
-
334  XboxCommand(writeBuf, 6);
-
335 }
+
218  goto Fail;
+
219 
+
220 FailUnknownDevice:
+
221 #ifdef DEBUG_USB_HOST
+
222  NotifyFailUnknownDevice(VID, PID);
+
223 #endif
+
224  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
225 
+
226 Fail:
+
227 #ifdef DEBUG_USB_HOST
+
228  Notify(PSTR("\r\nXbox Init Failed, error code: "), 0x80);
+
229  NotifyFail(rcode);
+
230 #endif
+
231  Release();
+
232  return rcode;
+
233 }
+
234 
+
235 /* Performs a cleanup after failed Init() attempt */
+
236 uint8_t XBOXOLD::Release() {
+
237  XboxConnected = false;
+
238  pUsb->GetAddressPool().FreeAddress(bAddress);
+
239  bAddress = 0;
+
240  bPollEnable = false;
+
241  return 0;
+
242 }
+
243 
+
244 uint8_t XBOXOLD::Poll() {
+
245  if(!bPollEnable)
+
246  return 0;
+
247  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
+
248  pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
+
249  readReport();
+
250 #ifdef PRINTREPORT
+
251  printReport(BUFFER_SIZE); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox controller
+
252 #endif
+
253  return 0;
+
254 }
+
255 
+
256 void XBOXOLD::readReport() {
+
257  ButtonState = readBuf[2];
+
258 
+
259  for(uint8_t i = 0; i < sizeof (buttonValues); i++)
+
260  buttonValues[i] = readBuf[i + 4]; // A, B, X, Y, BLACK, WHITE, L1, and R1
+
261 
+
262  hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[12] << 8) | readBuf[13]);
+
263  hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[14] << 8) | readBuf[15]);
+
264  hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[16] << 8) | readBuf[17]);
+
265  hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[18] << 8) | readBuf[19]);
+
266 
+
267  //Notify(PSTR("\r\nButtonState"), 0x80);
+
268  //PrintHex<uint8_t>(ButtonState, 0x80);
+
269 
+
270  if(ButtonState != OldButtonState || memcmp(buttonValues, oldButtonValues, sizeof (buttonValues)) != 0) {
+
271  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
+
272  OldButtonState = ButtonState;
+
273 
+
274  for(uint8_t i = 0; i < sizeof (buttonValues); i++) {
+
275  if(oldButtonValues[i] == 0 && buttonValues[i] != 0)
+
276  buttonClicked[i] = true; // Update A, B, X, Y, BLACK, WHITE, L1, and R1 click state
+
277  oldButtonValues[i] = buttonValues[i];
+
278  }
+
279  }
+
280 }
+
281 
+
282 void XBOXOLD::printReport(uint16_t length) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox controller
+
283 #ifdef PRINTREPORT
+
284  if(readBuf == NULL)
+
285  return;
+
286  for(uint8_t i = 0; i < length; i++) {
+
287  D_PrintHex<uint8_t > (readBuf[i], 0x80);
+
288  Notify(PSTR(" "), 0x80);
+
289  }
+
290  Notify(PSTR("\r\n"), 0x80);
+
291 #endif
+
292 }
+
293 
+
294 uint8_t XBOXOLD::getButtonPress(ButtonEnum b) {
+
295  uint8_t button = pgm_read_byte(&XBOXOLD_BUTTONS[(uint8_t)b]);
+
296  if(b == A || b == B || b == X || b == Y || b == BLACK || b == WHITE || b == L1 || b == R1) // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
+
297  return buttonValues[button]; // Analog buttons
+
298  return (ButtonState & button); // Digital buttons
+
299 }
+
300 
+
301 bool XBOXOLD::getButtonClick(ButtonEnum b) {
+
302  uint8_t button = pgm_read_byte(&XBOXOLD_BUTTONS[(uint8_t)b]);
+
303  if(b == A || b == B || b == X || b == Y || b == BLACK || b == WHITE || b == L1 || b == R1) { // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons
+
304  if(buttonClicked[button]) {
+
305  buttonClicked[button] = false;
+
306  return true;
+
307  }
+
308  return false;
+
309  }
+
310 
+
311  bool click = (ButtonClickState & button);
+
312  ButtonClickState &= ~button; // clear "click" event
+
313  return click;
+
314 }
+
315 
+
316 int16_t XBOXOLD::getAnalogHat(AnalogHatEnum a) {
+
317  return hatValue[a];
+
318 }
+
319 
+
320 /* Xbox Controller commands */
+
321 void XBOXOLD::XboxCommand(uint8_t* data, uint16_t nbytes) {
+
322  //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
+
323  pUsb->ctrlReq(bAddress, epInfo[XBOX_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
+
324 }
+
325 
+
326 void XBOXOLD::setRumbleOn(uint8_t lValue, uint8_t rValue) {
+
327  uint8_t writeBuf[6];
+
328 
+
329  writeBuf[0] = 0x00;
+
330  writeBuf[1] = 0x06;
+
331  writeBuf[2] = 0x00;
+
332  writeBuf[3] = rValue; // small weight
+
333  writeBuf[4] = 0x00;
+
334  writeBuf[5] = lValue; // big weight
+
335 
+
336  XboxCommand(writeBuf, 6);
+
337 }
uint8_t bmRcvToggle
Definition: address.h:41
Definition: address.h:83
+
EpInfo * epinfo
Definition: address.h:76
bool lowspeed
Definition: address.h:79
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
uint8_t bmNakPower
Definition: address.h:42
Definition: address.h:75
-
virtual uint8_t Release()
Definition: XBOXOLD.cpp:234
-
-
+
virtual uint8_t Release()
Definition: XBOXOLD.cpp:236
#define NotifyFail(...)
Definition: message.h:55
-
const uint8_t XBOXOLDBUTTONS[]
Definition: XBOXOLD.cpp:24
-
-
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
-
-
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:324
+
+
AnalogHatEnum
+
+
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:326
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
+
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
#define XBOX_OLD_PID4
Definition: XBOXOLD.h:43
-
-
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:160
+
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:159
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
virtual void FreeAddress(uint8_t addr)=0
uint8_t epAttribs
Definition: address.h:37
+
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
+
const uint8_t XBOXOLD_BUTTONS[]
Definition: XBOXOLD.cpp:24
#define Notify(...)
Definition: message.h:44
-
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
+
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
+
uint8_t epAddr
Definition: address.h:33
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
+
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
+
int16_t getAnalogHat(AnalogHatEnum a)
Definition: XBOXOLD.cpp:316
#define XBOX_VID
Definition: XBOXOLD.h:36
#define XBOX_INPUT_PIPE
Definition: XBOXOLD.h:32
+
XBOXOLD(USB *pUsb)
Definition: XBOXOLD.cpp:47
#define EP_INTERRUPT
Definition: PS3USB.h:28
#define XBOX_OLD_PID1
Definition: XBOXOLD.h:40
Definition: address.h:32
-
+
ButtonEnum
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
#define JOYTECH_VID
Definition: XBOXOLD.h:38
-
-
uint8_t getButtonPress(Button b)
Definition: XBOXOLD.cpp:292
-
USB * pUsb
Definition: XBOXOLD.h:156
+
USB * pUsb
Definition: XBOXOLD.h:155
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
uint8_t bmSndToggle
Definition: address.h:40
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
int16_t getAnalogHat(AnalogHat a)
Definition: XBOXOLD.cpp:314
-
virtual uint8_t Poll()
Definition: XBOXOLD.cpp:242
+
virtual uint8_t Poll()
Definition: XBOXOLD.cpp:244
#define XBOX_OLD_PID2
Definition: XBOXOLD.h:41
#define MADCATZ_VID
Definition: XBOXOLD.h:37
#define XBOX_OUTPUT_PIPE
Definition: XBOXOLD.h:33
#define USB_NAK_NOWAIT
Definition: address.h:29
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
+
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXOLD.cpp:62
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:49
-
#define bmRCVTOG0
Definition: max3421e.h:185
-
bool getButtonClick(Button b)
Definition: XBOXOLD.cpp:299
#define XBOX_OLD_PID3
Definition: XBOXOLD.h:42
#define bmREQ_HID_OUT
Definition: BTD.h:38
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
-
Button
-
bool XboxConnected
Definition: XBOXOLD.h:148
-
#define bmSNDTOG0
Definition: max3421e.h:187
+
bool XboxConnected
Definition: XBOXOLD.h:147
uint8_t maxPktSize
Definition: address.h:34
-
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
Definition: UsbCore.h:152
-
+
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
Definition: UsbCore.h:176
+
bool getButtonClick(ButtonEnum b)
Definition: XBOXOLD.cpp:301
+
uint8_t getButtonPress(ButtonEnum b)
Definition: XBOXOLD.cpp:294
#define XBOX_CONTROL_PIPE
Definition: XBOXOLD.h:31
-
uint8_t bAddress
Definition: XBOXOLD.h:158
-
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
uint8_t bAddress
Definition: XBOXOLD.h:157
+
+
+
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
AnalogHat
-
-
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
-
Definition: usb_ch9.h:98
diff --git a/_x_b_o_x_o_l_d_8h.html b/_x_b_o_x_o_l_d_8h.html index 01bf2c45..89852a20 100644 --- a/_x_b_o_x_o_l_d_8h.html +++ b/_x_b_o_x_o_l_d_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXOLD.h File Reference @@ -31,7 +31,7 @@ - + @@ -365,7 +365,7 @@ Macros diff --git a/_x_b_o_x_o_l_d_8h_source.html b/_x_b_o_x_o_l_d_8h_source.html index bafe098e..1a9ce1e4 100644 --- a/_x_b_o_x_o_l_d_8h_source.html +++ b/_x_b_o_x_o_l_d_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXOLD.h Source File @@ -31,7 +31,7 @@ - + @@ -158,91 +158,91 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
102  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
103  return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID) && (pid == XBOX_OLD_PID1 || pid == XBOX_OLD_PID2 || pid == XBOX_OLD_PID3 || pid == XBOX_OLD_PID4));
104  };
-
119  uint8_t getButtonPress(Button b);
-
120  bool getButtonClick(Button b);
-
129  int16_t getAnalogHat(AnalogHat a);
-
130 
-
132  void setRumbleOff() {
-
133  setRumbleOn(0, 0);
-
134  };
-
140  void setRumbleOn(uint8_t lValue, uint8_t rValue);
-
141 
-
146  void attachOnInit(void (*funcOnInit)(void)) {
-
147  pFuncOnInit = funcOnInit;
-
148  };
-
152  bool XboxConnected;
-
153 
-
154 protected:
-
156  USB *pUsb;
-
158  uint8_t bAddress;
-
160  EpInfo epInfo[XBOX_MAX_ENDPOINTS];
-
161 
-
162 private:
-
168  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
-
169 
-
170  bool bPollEnable;
-
171 
-
172  /* Variables to store the digital buttons */
-
173  uint8_t ButtonState;
-
174  uint8_t OldButtonState;
-
175  uint8_t ButtonClickState;
-
176 
-
177  /* Variables to store the analog buttons */
-
178  uint8_t buttonValues[8]; // A, B, X, Y, BLACK, WHITE, L1, and R1
-
179  uint8_t oldButtonValues[8];
-
180  bool buttonClicked[8];
-
181 
-
182  int16_t hatValue[4]; // Joystick values
-
183 
-
184  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
-
185 
-
186  void readReport(); // Read incoming data
-
187  void printReport(uint16_t length); // Print incoming date
-
188 
-
189  /* Private commands */
-
190  void XboxCommand(uint8_t* data, uint16_t nbytes);
-
191 };
-
192 #endif
-
XBOXOLD::Release
virtual uint8_t Release()
Definition: XBOXOLD.cpp:234
-
XBOXOLD::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXOLD.h:146
+
118  uint8_t getButtonPress(ButtonEnum b);
+
119  bool getButtonClick(ButtonEnum b);
+
128  int16_t getAnalogHat(AnalogHatEnum a);
+
129 
+
131  void setRumbleOff() {
+
132  setRumbleOn(0, 0);
+
133  };
+
139  void setRumbleOn(uint8_t lValue, uint8_t rValue);
+
140 
+
145  void attachOnInit(void (*funcOnInit)(void)) {
+
146  pFuncOnInit = funcOnInit;
+
147  };
+
151  bool XboxConnected;
+
152 
+
153 protected:
+
155  USB *pUsb;
+
157  uint8_t bAddress;
+
159  EpInfo epInfo[XBOX_MAX_ENDPOINTS];
+
160 
+
161 private:
+
167  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
168 
+
169  bool bPollEnable;
+
170 
+
171  /* Variables to store the digital buttons */
+
172  uint8_t ButtonState;
+
173  uint8_t OldButtonState;
+
174  uint8_t ButtonClickState;
+
175 
+
176  /* Variables to store the analog buttons */
+
177  uint8_t buttonValues[8]; // A, B, X, Y, BLACK, WHITE, L1, and R1
+
178  uint8_t oldButtonValues[8];
+
179  bool buttonClicked[8];
+
180 
+
181  int16_t hatValue[4]; // Joystick values
+
182 
+
183  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
+
184 
+
185  void readReport(); // Read incoming data
+
186  void printReport(uint16_t length); // Print incoming date
+
187 
+
188  /* Private commands */
+
189  void XboxCommand(uint8_t* data, uint16_t nbytes);
+
190 };
+
191 #endif
+
XBOXOLD::Release
virtual uint8_t Release()
Definition: XBOXOLD.cpp:236
+
XBOXOLD::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXOLD.h:145
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
XBOXOLD::GetAddress
virtual uint8_t GetAddress()
Definition: XBOXOLD.h:84
USBDeviceConfig
Definition: UsbCore.h:105
Usb.h
XBOXOLD
Definition: XBOXOLD.h:52
-
XBOXOLD::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:324
+
XBOXOLD::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:326
XBOXOLD::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXOLD.h:102
XBOX_OLD_PID4
#define XBOX_OLD_PID4
Definition: XBOXOLD.h:43
XBOXOLD::isReady
virtual bool isReady()
Definition: XBOXOLD.h:92
-
XBOXOLD::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:160
+
XBOXOLD::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:159
controllerEnums.h
+
XBOXOLD::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a)
Definition: XBOXOLD.cpp:316
XBOX_VID
#define XBOX_VID
Definition: XBOXOLD.h:36
XBOXOLD::XBOXOLD
XBOXOLD(USB *pUsb)
Definition: XBOXOLD.cpp:47
XBOX_OLD_PID1
#define XBOX_OLD_PID1
Definition: XBOXOLD.h:40
EpInfo
Definition: address.h:32
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXOLD.h:38
-
XBOXOLD::getButtonPress
uint8_t getButtonPress(Button b)
Definition: XBOXOLD.cpp:292
-
XBOXOLD::pUsb
USB * pUsb
Definition: XBOXOLD.h:156
-
XBOXOLD::getAnalogHat
int16_t getAnalogHat(AnalogHat a)
Definition: XBOXOLD.cpp:314
-
XBOXOLD::Poll
virtual uint8_t Poll()
Definition: XBOXOLD.cpp:242
+
XBOXOLD::pUsb
USB * pUsb
Definition: XBOXOLD.h:155
+
XBOXOLD::Poll
virtual uint8_t Poll()
Definition: XBOXOLD.cpp:244
XBOX_OLD_PID2
#define XBOX_OLD_PID2
Definition: XBOXOLD.h:41
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXOLD.h:37
XBOXOLD::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXOLD.cpp:62
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:49
-
XBOXOLD::getButtonClick
bool getButtonClick(Button b)
Definition: XBOXOLD.cpp:299
XBOX_OLD_PID3
#define XBOX_OLD_PID3
Definition: XBOXOLD.h:42
-
Button
Button
Definition: controllerEnums.h:44
-
XBOXOLD::XboxConnected
bool XboxConnected
Definition: XBOXOLD.h:148
-
USB
Definition: UsbCore.h:152
-
XBOXOLD::setRumbleOff
void setRumbleOff()
Definition: XBOXOLD.h:132
-
XBOXOLD::bAddress
uint8_t bAddress
Definition: XBOXOLD.h:158
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
+
XBOXOLD::XboxConnected
bool XboxConnected
Definition: XBOXOLD.h:147
+
USB
Definition: UsbCore.h:176
+
XBOXOLD::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: XBOXOLD.cpp:301
+
XBOXOLD::setRumbleOff
void setRumbleOff()
Definition: XBOXOLD.h:131
+
XBOXOLD::getButtonPress
uint8_t getButtonPress(ButtonEnum b)
Definition: XBOXOLD.cpp:294
+
XBOXOLD::bAddress
uint8_t bAddress
Definition: XBOXOLD.h:157
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: XBOXOLD.h:25
diff --git a/_x_b_o_x_r_e_c_v_8cpp.html b/_x_b_o_x_r_e_c_v_8cpp.html index 32ae5cca..35773474 100644 --- a/_x_b_o_x_r_e_c_v_8cpp.html +++ b/_x_b_o_x_r_e_c_v_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXRECV.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for XBOXRECV.cpp: diff --git a/_x_b_o_x_r_e_c_v_8cpp_source.html b/_x_b_o_x_r_e_c_v_8cpp_source.html index f088749e..7d87b985 100644 --- a/_x_b_o_x_r_e_c_v_8cpp_source.html +++ b/_x_b_o_x_r_e_c_v_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXRECV.cpp Source File @@ -31,7 +31,7 @@ - + @@ -117,85 +117,85 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
26 pUsb(p), // pointer to USB class instance - mandatory
27 bAddress(0), // device address - mandatory
28 bPollEnable(false) { // don't start polling before dongle is connected
-
29  for (uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
+
29  for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
30  epInfo[i].epAddr = 0;
31  epInfo[i].maxPktSize = (i) ? 0 : 8;
32  epInfo[i].epAttribs = 0;
33  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
34  }
35 
-
36  if (pUsb) // register in USB subsystem
+
36  if(pUsb) // register in USB subsystem
37  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
38 }
39 
40 uint8_t XBOXRECV::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
41  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
42  uint8_t buf[constBufSize];
-
43  uint8_t rcode;
-
44  UsbDevice *p = NULL;
-
45  EpInfo *oldep_ptr = NULL;
-
46  uint16_t PID, VID;
-
47 
-
48  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
-
49 #ifdef EXTRADEBUG
-
50  Notify(PSTR("\r\nXBOXRECV Init"), 0x80);
-
51 #endif
-
52 
-
53  if (bAddress) { // Check if address has already been assigned to an instance
-
54 #ifdef DEBUG_USB_HOST
-
55  Notify(PSTR("\r\nAddress in use"), 0x80);
-
56 #endif
-
57  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
58  }
-
59 
-
60  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
-
61 
-
62  if (!p) {
-
63 #ifdef DEBUG_USB_HOST
-
64  Notify(PSTR("\r\nAddress not found"), 0x80);
-
65 #endif
-
66  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
67  }
-
68 
-
69  if (!p->epinfo) {
-
70 #ifdef DEBUG_USB_HOST
-
71  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
72 #endif
-
73  return USB_ERROR_EPINFO_IS_NULL;
-
74  }
-
75 
-
76  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
-
77  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
78  p->lowspeed = lowspeed;
-
79 
-
80  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
81 
-
82  p->epinfo = oldep_ptr; // Restore p->epinfo
-
83 
-
84  if (rcode)
-
85  goto FailGetDevDescr;
-
86 
-
87  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
88  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
89 
-
90  if ((VID != XBOX_VID && VID != MADCATZ_VID) || (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID)) { // Check if it's a Xbox receiver using the Vendor ID and Product ID
-
91 #ifdef DEBUG_USB_HOST
-
92  Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
-
93 #endif
-
94  goto FailUnknownDevice;
-
95  }
-
96 
-
97  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
-
98 
-
99  if (!bAddress) {
-
100 #ifdef DEBUG_USB_HOST
-
101  Notify(PSTR("\r\nOut of address space"), 0x80);
-
102 #endif
-
103  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
104  }
-
105 
-
106  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
-
107  epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
+
43  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
44  uint8_t rcode;
+
45  UsbDevice *p = NULL;
+
46  EpInfo *oldep_ptr = NULL;
+
47  uint16_t PID, VID;
+
48 
+
49  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
+
50 #ifdef EXTRADEBUG
+
51  Notify(PSTR("\r\nXBOXRECV Init"), 0x80);
+
52 #endif
+
53 
+
54  if(bAddress) { // Check if address has already been assigned to an instance
+
55 #ifdef DEBUG_USB_HOST
+
56  Notify(PSTR("\r\nAddress in use"), 0x80);
+
57 #endif
+
58  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
59  }
+
60 
+
61  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
+
62 
+
63  if(!p) {
+
64 #ifdef DEBUG_USB_HOST
+
65  Notify(PSTR("\r\nAddress not found"), 0x80);
+
66 #endif
+
67  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
68  }
+
69 
+
70  if(!p->epinfo) {
+
71 #ifdef DEBUG_USB_HOST
+
72  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
73 #endif
+
74  return USB_ERROR_EPINFO_IS_NULL;
+
75  }
+
76 
+
77  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
+
78  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
79  p->lowspeed = lowspeed;
+
80 
+
81  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
+
82 
+
83  p->epinfo = oldep_ptr; // Restore p->epinfo
+
84 
+
85  if(rcode)
+
86  goto FailGetDevDescr;
+
87 
+
88  VID = udd->idVendor;
+
89  PID = udd->idProduct;
+
90 
+
91  if((VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) || (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID)) { // Check if it's a Xbox receiver using the Vendor ID and Product ID
+
92 #ifdef DEBUG_USB_HOST
+
93  Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
+
94 #endif
+
95  goto FailUnknownDevice;
+
96  }
+
97 
+
98  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
+
99 
+
100  if(!bAddress) {
+
101 #ifdef DEBUG_USB_HOST
+
102  Notify(PSTR("\r\nOut of address space"), 0x80);
+
103 #endif
+
104  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
105  }
+
106 
+
107  epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
108 
109  delay(20); // Wait a little before resetting device
110 
@@ -206,13 +206,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
115 #ifdef DEBUG_USB_HOST
116  NotifyFailGetDevDescr(rcode);
117 #endif
-
118  if (rcode != hrJERR)
+
118  if(rcode != hrJERR)
119  rcode = USB_ERROR_FailGetDevDescr;
120  goto Fail;
121 
122 FailUnknownDevice:
123 #ifdef DEBUG_USB_HOST
-
124  NotifyFailUnknownDevice(VID,PID);
+
124  NotifyFailUnknownDevice(VID, PID);
125 #endif
126  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
127 
@@ -227,360 +227,360 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
136 
137 uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
138  uint8_t rcode;
-
139  uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
-
140  epInfo[1].epAddr = 0;
-
141 
-
142  AddressPool &addrPool = pUsb->GetAddressPool();
-
143 #ifdef EXTRADEBUG
-
144  Notify(PSTR("\r\nBTD Init"), 0x80);
-
145 #endif
-
146  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
147 
-
148  if (!p) {
-
149 #ifdef DEBUG_USB_HOST
-
150  Notify(PSTR("\r\nAddress not found"), 0x80);
-
151 #endif
-
152  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
153  }
+
139 
+
140  AddressPool &addrPool = pUsb->GetAddressPool();
+
141 #ifdef EXTRADEBUG
+
142  Notify(PSTR("\r\nBTD Init"), 0x80);
+
143 #endif
+
144  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
145 
+
146  if(!p) {
+
147 #ifdef DEBUG_USB_HOST
+
148  Notify(PSTR("\r\nAddress not found"), 0x80);
+
149 #endif
+
150  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
151  }
+
152 
+
153  delay(300); // Assign new address to the device
154 
-
155  delay(300); // Assign new address to the device
-
156 
-
157  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
-
158  if (rcode) {
-
159 #ifdef DEBUG_USB_HOST
-
160  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
161  D_PrintHex<uint8_t > (rcode, 0x80);
-
162 #endif
-
163  p->lowspeed = false;
-
164  goto Fail;
-
165  }
-
166 #ifdef EXTRADEBUG
-
167  Notify(PSTR("\r\nAddr: "), 0x80);
-
168  D_PrintHex<uint8_t > (bAddress, 0x80);
-
169 #endif
-
170 
-
171  p->lowspeed = false;
-
172 
-
173  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
-
174  if (!p) {
-
175 #ifdef DEBUG_USB_HOST
-
176  Notify(PSTR("\r\nAddress not found"), 0x80);
-
177 #endif
-
178  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
179  }
+
155  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
+
156  if(rcode) {
+
157 #ifdef DEBUG_USB_HOST
+
158  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
159  D_PrintHex<uint8_t > (rcode, 0x80);
+
160 #endif
+
161  p->lowspeed = false;
+
162  goto Fail;
+
163  }
+
164 #ifdef EXTRADEBUG
+
165  Notify(PSTR("\r\nAddr: "), 0x80);
+
166  D_PrintHex<uint8_t > (bAddress, 0x80);
+
167 #endif
+
168 
+
169  p->lowspeed = false;
+
170 
+
171  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
+
172  if(!p) {
+
173 #ifdef DEBUG_USB_HOST
+
174  Notify(PSTR("\r\nAddress not found"), 0x80);
+
175 #endif
+
176  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
177  }
+
178 
+
179  p->lowspeed = lowspeed;
180 
-
181  p->lowspeed = lowspeed;
-
182 
-
183  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
-
184  if (rcode)
-
185  goto FailSetDevTblEntry;
-
186 
-
187  /* The application will work in reduced host mode, so we can save program and data
-
188  memory space. After verifying the VID we will use known values for the
-
189  configuration values for device, interface, endpoints and HID for the XBOX360 Wireless receiver */
-
190 
-
191  /* Initialize data structures for endpoints of device */
-
192  epInfo[ XBOX_INPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 report endpoint - poll interval 1ms
-
193  epInfo[ XBOX_INPUT_PIPE_1 ].epAttribs = EP_INTERRUPT;
-
194  epInfo[ XBOX_INPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
195  epInfo[ XBOX_INPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE;
-
196  epInfo[ XBOX_INPUT_PIPE_1 ].bmSndToggle = bmSNDTOG0;
-
197  epInfo[ XBOX_INPUT_PIPE_1 ].bmRcvToggle = bmRCVTOG0;
-
198  epInfo[ XBOX_OUTPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 output endpoint - poll interval 8ms
-
199  epInfo[ XBOX_OUTPUT_PIPE_1 ].epAttribs = EP_INTERRUPT;
-
200  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
201  epInfo[ XBOX_OUTPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE;
-
202  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmSndToggle = bmSNDTOG0;
-
203  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmRcvToggle = bmRCVTOG0;
-
204 
-
205  epInfo[ XBOX_INPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 report endpoint - poll interval 1ms
-
206  epInfo[ XBOX_INPUT_PIPE_2 ].epAttribs = EP_INTERRUPT;
-
207  epInfo[ XBOX_INPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
208  epInfo[ XBOX_INPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE;
-
209  epInfo[ XBOX_INPUT_PIPE_2 ].bmSndToggle = bmSNDTOG0;
-
210  epInfo[ XBOX_INPUT_PIPE_2 ].bmRcvToggle = bmRCVTOG0;
-
211  epInfo[ XBOX_OUTPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 output endpoint - poll interval 8ms
-
212  epInfo[ XBOX_OUTPUT_PIPE_2 ].epAttribs = EP_INTERRUPT;
-
213  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
214  epInfo[ XBOX_OUTPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE;
-
215  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmSndToggle = bmSNDTOG0;
-
216  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmRcvToggle = bmRCVTOG0;
-
217 
-
218  epInfo[ XBOX_INPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 report endpoint - poll interval 1ms
-
219  epInfo[ XBOX_INPUT_PIPE_3 ].epAttribs = EP_INTERRUPT;
-
220  epInfo[ XBOX_INPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
221  epInfo[ XBOX_INPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE;
-
222  epInfo[ XBOX_INPUT_PIPE_3 ].bmSndToggle = bmSNDTOG0;
-
223  epInfo[ XBOX_INPUT_PIPE_3 ].bmRcvToggle = bmRCVTOG0;
-
224  epInfo[ XBOX_OUTPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 output endpoint - poll interval 8ms
-
225  epInfo[ XBOX_OUTPUT_PIPE_3 ].epAttribs = EP_INTERRUPT;
-
226  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
227  epInfo[ XBOX_OUTPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE;
-
228  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmSndToggle = bmSNDTOG0;
-
229  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmRcvToggle = bmRCVTOG0;
-
230 
-
231  epInfo[ XBOX_INPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 report endpoint - poll interval 1ms
-
232  epInfo[ XBOX_INPUT_PIPE_4 ].epAttribs = EP_INTERRUPT;
-
233  epInfo[ XBOX_INPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
234  epInfo[ XBOX_INPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE;
-
235  epInfo[ XBOX_INPUT_PIPE_4 ].bmSndToggle = bmSNDTOG0;
-
236  epInfo[ XBOX_INPUT_PIPE_4 ].bmRcvToggle = bmRCVTOG0;
-
237  epInfo[ XBOX_OUTPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 output endpoint - poll interval 8ms
-
238  epInfo[ XBOX_OUTPUT_PIPE_4 ].epAttribs = EP_INTERRUPT;
-
239  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
240  epInfo[ XBOX_OUTPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE;
-
241  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmSndToggle = bmSNDTOG0;
-
242  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmRcvToggle = bmRCVTOG0;
-
243 
-
244  rcode = pUsb->setEpInfoEntry(bAddress, 9, epInfo);
-
245  if (rcode)
-
246  goto FailSetDevTblEntry;
+
181  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
+
182  if(rcode)
+
183  goto FailSetDevTblEntry;
+
184 
+
185  /* The application will work in reduced host mode, so we can save program and data
+
186  memory space. After verifying the VID we will use known values for the
+
187  configuration values for device, interface, endpoints and HID for the XBOX360 Wireless receiver */
+
188 
+
189  /* Initialize data structures for endpoints of device */
+
190  epInfo[ XBOX_INPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 report endpoint - poll interval 1ms
+
191  epInfo[ XBOX_INPUT_PIPE_1 ].epAttribs = EP_INTERRUPT;
+
192  epInfo[ XBOX_INPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
193  epInfo[ XBOX_INPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE;
+
194  epInfo[ XBOX_INPUT_PIPE_1 ].bmSndToggle = 0;
+
195  epInfo[ XBOX_INPUT_PIPE_1 ].bmRcvToggle = 0;
+
196  epInfo[ XBOX_OUTPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 output endpoint - poll interval 8ms
+
197  epInfo[ XBOX_OUTPUT_PIPE_1 ].epAttribs = EP_INTERRUPT;
+
198  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
199  epInfo[ XBOX_OUTPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE;
+
200  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmSndToggle = 0;
+
201  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmRcvToggle = 0;
+
202 
+
203  epInfo[ XBOX_INPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 report endpoint - poll interval 1ms
+
204  epInfo[ XBOX_INPUT_PIPE_2 ].epAttribs = EP_INTERRUPT;
+
205  epInfo[ XBOX_INPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
206  epInfo[ XBOX_INPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE;
+
207  epInfo[ XBOX_INPUT_PIPE_2 ].bmSndToggle = 0;
+
208  epInfo[ XBOX_INPUT_PIPE_2 ].bmRcvToggle = 0;
+
209  epInfo[ XBOX_OUTPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 output endpoint - poll interval 8ms
+
210  epInfo[ XBOX_OUTPUT_PIPE_2 ].epAttribs = EP_INTERRUPT;
+
211  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
212  epInfo[ XBOX_OUTPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE;
+
213  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmSndToggle = 0;
+
214  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmRcvToggle = 0;
+
215 
+
216  epInfo[ XBOX_INPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 report endpoint - poll interval 1ms
+
217  epInfo[ XBOX_INPUT_PIPE_3 ].epAttribs = EP_INTERRUPT;
+
218  epInfo[ XBOX_INPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
219  epInfo[ XBOX_INPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE;
+
220  epInfo[ XBOX_INPUT_PIPE_3 ].bmSndToggle = 0;
+
221  epInfo[ XBOX_INPUT_PIPE_3 ].bmRcvToggle = 0;
+
222  epInfo[ XBOX_OUTPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 output endpoint - poll interval 8ms
+
223  epInfo[ XBOX_OUTPUT_PIPE_3 ].epAttribs = EP_INTERRUPT;
+
224  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
225  epInfo[ XBOX_OUTPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE;
+
226  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmSndToggle = 0;
+
227  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmRcvToggle = 0;
+
228 
+
229  epInfo[ XBOX_INPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 report endpoint - poll interval 1ms
+
230  epInfo[ XBOX_INPUT_PIPE_4 ].epAttribs = EP_INTERRUPT;
+
231  epInfo[ XBOX_INPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
232  epInfo[ XBOX_INPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE;
+
233  epInfo[ XBOX_INPUT_PIPE_4 ].bmSndToggle = 0;
+
234  epInfo[ XBOX_INPUT_PIPE_4 ].bmRcvToggle = 0;
+
235  epInfo[ XBOX_OUTPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 output endpoint - poll interval 8ms
+
236  epInfo[ XBOX_OUTPUT_PIPE_4 ].epAttribs = EP_INTERRUPT;
+
237  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
238  epInfo[ XBOX_OUTPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE;
+
239  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmSndToggle = 0;
+
240  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmRcvToggle = 0;
+
241 
+
242  rcode = pUsb->setEpInfoEntry(bAddress, 9, epInfo);
+
243  if(rcode)
+
244  goto FailSetDevTblEntry;
+
245 
+
246  delay(200); //Give time for address change
247 
-
248  delay(200); //Give time for address change
-
249 
-
250  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
-
251  if (rcode)
-
252  goto FailSetConfDescr;
-
253 
-
254 #ifdef DEBUG_USB_HOST
-
255  Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
-
256 #endif
-
257  XboxReceiverConnected = true;
-
258  bPollEnable = true;
-
259  checkStatusTimer = 0; // Reset timer
-
260  return 0; // Successful configuration
-
261 
-
262  /* Diagnostic messages */
-
263 FailGetDevDescr:
-
264 #ifdef DEBUG_USB_HOST
-
265  NotifyFailGetDevDescr();
-
266  goto Fail;
-
267 #endif
-
268 
-
269 FailSetDevTblEntry:
-
270 #ifdef DEBUG_USB_HOST
-
271  NotifyFailSetDevTblEntry();
-
272  goto Fail;
-
273 #endif
-
274 
-
275 FailSetConfDescr:
-
276 #ifdef DEBUG_USB_HOST
-
277  NotifyFailSetConfDescr();
-
278 #endif
-
279  goto Fail;
+
248  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
+
249  if(rcode)
+
250  goto FailSetConfDescr;
+
251 
+
252 #ifdef DEBUG_USB_HOST
+
253  Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
+
254 #endif
+
255  XboxReceiverConnected = true;
+
256  bPollEnable = true;
+
257  checkStatusTimer = 0; // Reset timer
+
258  return 0; // Successful configuration
+
259 
+
260  /* Diagnostic messages */
+
261 FailSetDevTblEntry:
+
262 #ifdef DEBUG_USB_HOST
+
263  NotifyFailSetDevTblEntry();
+
264  goto Fail;
+
265 #endif
+
266 
+
267 FailSetConfDescr:
+
268 #ifdef DEBUG_USB_HOST
+
269  NotifyFailSetConfDescr();
+
270 #endif
+
271 
+
272 Fail:
+
273 #ifdef DEBUG_USB_HOST
+
274  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
+
275  NotifyFail(rcode);
+
276 #endif
+
277  Release();
+
278  return rcode;
+
279 }
280 
-
281 Fail:
-
282 #ifdef DEBUG_USB_HOST
-
283  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
-
284  NotifyFail(rcode);
-
285 #endif
-
286  Release();
-
287  return rcode;
-
288 }
-
289 
-
290 /* Performs a cleanup after failed Init() attempt */
-
291 uint8_t XBOXRECV::Release() {
-
292  XboxReceiverConnected = false;
-
293  for (uint8_t i = 0; i < 4; i++)
-
294  Xbox360Connected[i] = 0x00;
-
295  pUsb->GetAddressPool().FreeAddress(bAddress);
-
296  bAddress = 0;
-
297  bPollEnable = false;
-
298  return 0;
-
299 }
-
300 
-
301 uint8_t XBOXRECV::Poll() {
-
302  if (!bPollEnable)
-
303  return 0;
-
304  if (!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds
-
305  checkStatusTimer = millis();
-
306  checkStatus();
-
307  }
-
308 
-
309  uint8_t inputPipe;
-
310  uint16_t bufferSize;
-
311  for (uint8_t i = 0; i < 4; i++) {
-
312  if (i == 0)
-
313  inputPipe = XBOX_INPUT_PIPE_1;
-
314  else if (i == 1)
-
315  inputPipe = XBOX_INPUT_PIPE_2;
-
316  else if (i == 2)
-
317  inputPipe = XBOX_INPUT_PIPE_3;
-
318  else
-
319  inputPipe = XBOX_INPUT_PIPE_4;
-
320 
-
321  bufferSize = EP_MAXPKTSIZE; // This is the maximum number of bytes we want to receive
-
322  pUsb->inTransfer(bAddress, epInfo[ inputPipe ].epAddr, &bufferSize, readBuf);
-
323  if (bufferSize > 0) { // The number of received bytes
-
324 #ifdef EXTRADEBUG
-
325  Notify(PSTR("Bytes Received: "), 0x80);
-
326  D_PrintHex<uint16_t > (bufferSize, 0x80);
-
327  Notify(PSTR("\r\n"), 0x80);
-
328 #endif
-
329  readReport(i);
-
330 #ifdef PRINTREPORT
-
331  printReport(i, bufferSize); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
-
332 #endif
-
333  }
-
334  }
-
335  return 0;
-
336 }
-
337 
-
338 void XBOXRECV::readReport(uint8_t controller) {
-
339  if (readBuf == NULL)
-
340  return;
-
341  // This report is send when a controller is connected and disconnected
-
342  if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) {
-
343  Xbox360Connected[controller] = readBuf[1];
-
344 #ifdef DEBUG_USB_HOST
-
345  Notify(PSTR("Controller "), 0x80);
-
346  Notify(controller, 0x80);
-
347 #endif
-
348  if (Xbox360Connected[controller]) {
-
349 #ifdef DEBUG_USB_HOST
-
350  const char* str = 0;
-
351  switch (readBuf[1]) {
-
352  case 0x80: str = PSTR(" as controller\r\n");
-
353  break;
-
354  case 0x40: str = PSTR(" as headset\r\n");
-
355  break;
-
356  case 0xC0: str = PSTR(" as controller+headset\r\n");
-
357  break;
-
358  }
-
359  Notify(PSTR(": connected"), 0x80);
-
360  Notify(str, 0x80);
-
361 #endif
-
362  onInit(controller);
-
363  }
-
364 #ifdef DEBUG_USB_HOST
-
365  else
-
366  Notify(PSTR(": disconnected\r\n"), 0x80);
-
367 #endif
-
368  return;
-
369  }
-
370  // Controller status report
-
371  if (readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
-
372  controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
-
373  return;
-
374  }
-
375  if (readBuf[1] != 0x01) // Check if it's the correct report - the receiver also sends different status reports
-
376  return;
-
377 
-
378  // A controller must be connected if it's sending data
-
379  if (!Xbox360Connected[controller])
-
380  Xbox360Connected[controller] |= 0x80;
-
381 
-
382  ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
-
383 
-
384  hatValue[controller][LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
-
385  hatValue[controller][LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
-
386  hatValue[controller][RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
-
387  hatValue[controller][RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
-
388 
-
389  //Notify(PSTR("\r\nButtonState: "), 0x80);
-
390  //PrintHex<uint32_t>(ButtonState[controller], 0x80);
-
391 
-
392  if (ButtonState[controller] != OldButtonState[controller]) {
-
393  buttonStateChanged[controller] = true;
-
394  ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
-
395  if (((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
-
396  R2Clicked[controller] = true;
-
397  if ((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
-
398  L2Clicked[controller] = true;
-
399  OldButtonState[controller] = ButtonState[controller];
-
400  }
-
401 }
-
402 
-
403 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
-
404 #ifdef PRINTREPORT
-
405  if (readBuf == NULL)
-
406  return;
-
407  Notify(PSTR("Controller "), 0x80);
-
408  Notify(controller, 0x80);
-
409  Notify(PSTR(": "), 0x80);
-
410  for (uint8_t i = 0; i < nBytes; i++) {
-
411  D_PrintHex<uint8_t > (readBuf[i], 0x80);
-
412  Notify(PSTR(" "), 0x80);
-
413  }
-
414  Notify(PSTR("\r\n"), 0x80);
-
415 #endif
-
416 }
-
417 
-
418 uint8_t XBOXRECV::getButtonPress(Button b, uint8_t controller) {
-
419  if (b == L2) // These are analog buttons
-
420  return (uint8_t)(ButtonState[controller] >> 8);
-
421  else if (b == R2)
-
422  return (uint8_t)ButtonState[controller];
-
423  return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16));
-
424 }
-
425 
-
426 bool XBOXRECV::getButtonClick(Button b, uint8_t controller) {
-
427  if (b == L2) {
-
428  if (L2Clicked[controller]) {
-
429  L2Clicked[controller] = false;
-
430  return true;
-
431  }
-
432  return false;
-
433  } else if (b == R2) {
-
434  if (R2Clicked[controller]) {
-
435  R2Clicked[controller] = false;
-
436  return true;
-
437  }
-
438  return false;
-
439  }
-
440  uint16_t button = pgm_read_word(&XBOXBUTTONS[(uint8_t)b]);
-
441  bool click = (ButtonClickState[controller] & button);
-
442  ButtonClickState[controller] &= ~button; // clear "click" event
-
443  return click;
-
444 }
-
445 
-
446 int16_t XBOXRECV::getAnalogHat(AnalogHat a, uint8_t controller) {
-
447  return hatValue[controller][a];
-
448 }
-
449 
-
450 bool XBOXRECV::buttonChanged(uint8_t controller) {
-
451  bool state = buttonStateChanged[controller];
-
452  buttonStateChanged[controller] = false;
-
453  return state;
-
454 }
-
455 
-
456 /*
-
457 ControllerStatus Breakdown
-
458 ControllerStatus[controller] & 0x0001 // 0
-
459 ControllerStatus[controller] & 0x0002 // normal batteries, no rechargeable battery pack
-
460 ControllerStatus[controller] & 0x0004 // controller starting up / settling
-
461 ControllerStatus[controller] & 0x0008 // headset adapter plugged in, but no headphones connected (mute?)
-
462 ControllerStatus[controller] & 0x0010 // 0
-
463 ControllerStatus[controller] & 0x0020 // 1
-
464 ControllerStatus[controller] & 0x0040 // battery level (high bit)
-
465 ControllerStatus[controller] & 0x0080 // battery level (low bit)
-
466 ControllerStatus[controller] & 0x0100 // 1
-
467 ControllerStatus[controller] & 0x0200 // 1
-
468 ControllerStatus[controller] & 0x0400 // headset adapter plugged in
-
469 ControllerStatus[controller] & 0x0800 // 0
-
470 ControllerStatus[controller] & 0x1000 // 1
-
471 ControllerStatus[controller] & 0x2000 // 0
-
472 ControllerStatus[controller] & 0x4000 // 0
-
473 ControllerStatus[controller] & 0x8000 // 0
-
474  */
-
475 uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
-
476  return ((controllerStatus[controller] & 0x00C0) >> 6);
-
477 }
-
478 
-
479 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
-
480  uint8_t outputPipe;
-
481  if (controller == 0)
-
482  outputPipe = XBOX_OUTPUT_PIPE_1;
-
483  else if (controller == 1)
-
484  outputPipe = XBOX_OUTPUT_PIPE_2;
-
485  else if (controller == 2)
-
486  outputPipe = XBOX_OUTPUT_PIPE_3;
-
487  else
-
488  outputPipe = XBOX_OUTPUT_PIPE_4;
-
489 
-
490  uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ outputPipe ].epAddr, nbytes, data);
+
281 /* Performs a cleanup after failed Init() attempt */
+
282 uint8_t XBOXRECV::Release() {
+
283  XboxReceiverConnected = false;
+
284  for(uint8_t i = 0; i < 4; i++)
+
285  Xbox360Connected[i] = 0x00;
+
286  pUsb->GetAddressPool().FreeAddress(bAddress);
+
287  bAddress = 0;
+
288  bPollEnable = false;
+
289  return 0;
+
290 }
+
291 
+
292 uint8_t XBOXRECV::Poll() {
+
293  if(!bPollEnable)
+
294  return 0;
+
295  if(!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds
+
296  checkStatusTimer = millis();
+
297  checkStatus();
+
298  }
+
299 
+
300  uint8_t inputPipe;
+
301  uint16_t bufferSize;
+
302  for(uint8_t i = 0; i < 4; i++) {
+
303  if(i == 0)
+
304  inputPipe = XBOX_INPUT_PIPE_1;
+
305  else if(i == 1)
+
306  inputPipe = XBOX_INPUT_PIPE_2;
+
307  else if(i == 2)
+
308  inputPipe = XBOX_INPUT_PIPE_3;
+
309  else
+
310  inputPipe = XBOX_INPUT_PIPE_4;
+
311 
+
312  bufferSize = EP_MAXPKTSIZE; // This is the maximum number of bytes we want to receive
+
313  pUsb->inTransfer(bAddress, epInfo[ inputPipe ].epAddr, &bufferSize, readBuf);
+
314  if(bufferSize > 0) { // The number of received bytes
+
315 #ifdef EXTRADEBUG
+
316  Notify(PSTR("Bytes Received: "), 0x80);
+
317  D_PrintHex<uint16_t > (bufferSize, 0x80);
+
318  Notify(PSTR("\r\n"), 0x80);
+
319 #endif
+
320  readReport(i);
+
321 #ifdef PRINTREPORT
+
322  printReport(i, bufferSize); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
+
323 #endif
+
324  }
+
325  }
+
326  return 0;
+
327 }
+
328 
+
329 void XBOXRECV::readReport(uint8_t controller) {
+
330  if(readBuf == NULL)
+
331  return;
+
332  // This report is send when a controller is connected and disconnected
+
333  if(readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) {
+
334  Xbox360Connected[controller] = readBuf[1];
+
335 #ifdef DEBUG_USB_HOST
+
336  Notify(PSTR("Controller "), 0x80);
+
337  Notify(controller, 0x80);
+
338 #endif
+
339  if(Xbox360Connected[controller]) {
+
340 #ifdef DEBUG_USB_HOST
+
341  const char* str = 0;
+
342  switch(readBuf[1]) {
+
343  case 0x80: str = PSTR(" as controller\r\n");
+
344  break;
+
345  case 0x40: str = PSTR(" as headset\r\n");
+
346  break;
+
347  case 0xC0: str = PSTR(" as controller+headset\r\n");
+
348  break;
+
349  }
+
350  Notify(PSTR(": connected"), 0x80);
+
351  Notify(str, 0x80);
+
352 #endif
+
353  onInit(controller);
+
354  }
+
355 #ifdef DEBUG_USB_HOST
+
356  else
+
357  Notify(PSTR(": disconnected\r\n"), 0x80);
+
358 #endif
+
359  return;
+
360  }
+
361  // Controller status report
+
362  if(readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
+
363  controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
+
364  return;
+
365  }
+
366  if(readBuf[1] != 0x01) // Check if it's the correct report - the receiver also sends different status reports
+
367  return;
+
368 
+
369  // A controller must be connected if it's sending data
+
370  if(!Xbox360Connected[controller])
+
371  Xbox360Connected[controller] |= 0x80;
+
372 
+
373  ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
+
374 
+
375  hatValue[controller][LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
+
376  hatValue[controller][LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
+
377  hatValue[controller][RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
+
378  hatValue[controller][RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
+
379 
+
380  //Notify(PSTR("\r\nButtonState: "), 0x80);
+
381  //PrintHex<uint32_t>(ButtonState[controller], 0x80);
+
382 
+
383  if(ButtonState[controller] != OldButtonState[controller]) {
+
384  buttonStateChanged[controller] = true;
+
385  ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
+
386  if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
+
387  R2Clicked[controller] = true;
+
388  if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
+
389  L2Clicked[controller] = true;
+
390  OldButtonState[controller] = ButtonState[controller];
+
391  }
+
392 }
+
393 
+
394 void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
+
395 #ifdef PRINTREPORT
+
396  if(readBuf == NULL)
+
397  return;
+
398  Notify(PSTR("Controller "), 0x80);
+
399  Notify(controller, 0x80);
+
400  Notify(PSTR(": "), 0x80);
+
401  for(uint8_t i = 0; i < nBytes; i++) {
+
402  D_PrintHex<uint8_t > (readBuf[i], 0x80);
+
403  Notify(PSTR(" "), 0x80);
+
404  }
+
405  Notify(PSTR("\r\n"), 0x80);
+
406 #endif
+
407 }
+
408 
+
409 uint8_t XBOXRECV::getButtonPress(ButtonEnum b, uint8_t controller) {
+
410  if(b == L2) // These are analog buttons
+
411  return (uint8_t)(ButtonState[controller] >> 8);
+
412  else if(b == R2)
+
413  return (uint8_t)ButtonState[controller];
+
414  return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]) << 16));
+
415 }
+
416 
+
417 bool XBOXRECV::getButtonClick(ButtonEnum b, uint8_t controller) {
+
418  if(b == L2) {
+
419  if(L2Clicked[controller]) {
+
420  L2Clicked[controller] = false;
+
421  return true;
+
422  }
+
423  return false;
+
424  } else if(b == R2) {
+
425  if(R2Clicked[controller]) {
+
426  R2Clicked[controller] = false;
+
427  return true;
+
428  }
+
429  return false;
+
430  }
+
431  uint16_t button = pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]);
+
432  bool click = (ButtonClickState[controller] & button);
+
433  ButtonClickState[controller] &= ~button; // clear "click" event
+
434  return click;
+
435 }
+
436 
+
437 int16_t XBOXRECV::getAnalogHat(AnalogHatEnum a, uint8_t controller) {
+
438  return hatValue[controller][a];
+
439 }
+
440 
+
441 bool XBOXRECV::buttonChanged(uint8_t controller) {
+
442  bool state = buttonStateChanged[controller];
+
443  buttonStateChanged[controller] = false;
+
444  return state;
+
445 }
+
446 
+
447 /*
+
448 ControllerStatus Breakdown
+
449 ControllerStatus[controller] & 0x0001 // 0
+
450 ControllerStatus[controller] & 0x0002 // normal batteries, no rechargeable battery pack
+
451 ControllerStatus[controller] & 0x0004 // controller starting up / settling
+
452 ControllerStatus[controller] & 0x0008 // headset adapter plugged in, but no headphones connected (mute?)
+
453 ControllerStatus[controller] & 0x0010 // 0
+
454 ControllerStatus[controller] & 0x0020 // 1
+
455 ControllerStatus[controller] & 0x0040 // battery level (high bit)
+
456 ControllerStatus[controller] & 0x0080 // battery level (low bit)
+
457 ControllerStatus[controller] & 0x0100 // 1
+
458 ControllerStatus[controller] & 0x0200 // 1
+
459 ControllerStatus[controller] & 0x0400 // headset adapter plugged in
+
460 ControllerStatus[controller] & 0x0800 // 0
+
461 ControllerStatus[controller] & 0x1000 // 1
+
462 ControllerStatus[controller] & 0x2000 // 0
+
463 ControllerStatus[controller] & 0x4000 // 0
+
464 ControllerStatus[controller] & 0x8000 // 0
+
465  */
+
466 uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
+
467  return ((controllerStatus[controller] & 0x00C0) >> 6);
+
468 }
+
469 
+
470 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
+
471 #ifdef EXTRADEBUG
+
472  uint8_t rcode;
+
473 #endif
+
474  uint8_t outputPipe;
+
475  switch(controller) {
+
476  case 0: outputPipe = XBOX_OUTPUT_PIPE_1;
+
477  break;
+
478  case 1: outputPipe = XBOX_OUTPUT_PIPE_2;
+
479  break;
+
480  case 2: outputPipe = XBOX_OUTPUT_PIPE_3;
+
481  break;
+
482  case 3: outputPipe = XBOX_OUTPUT_PIPE_4;
+
483  break;
+
484  default:
+
485  return;
+
486  }
+
487 #ifdef EXTRADEBUG
+
488  rcode =
+
489 #endif
+
490  pUsb->outTransfer(bAddress, epInfo[ outputPipe ].epAddr, nbytes, data);
491 #ifdef EXTRADEBUG
-
492  if (rcode)
+
492  if(rcode)
493  Notify(PSTR("Error sending Xbox message\r\n"), 0x80);
494 #endif
495 }
@@ -603,167 +603,172 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
512  XboxCommand(controller, writeBuf, 4);
513 }
514 
-
515 void XBOXRECV::setLedOn(LED led, uint8_t controller) {
-
516  if (led != ALL) // All LEDs can't be on a the same time
-
517  setLedRaw(pgm_read_byte(&XBOXLEDS[(uint8_t)led]) + 4, controller);
-
518 }
-
519 
-
520 void XBOXRECV::setLedBlink(LED led, uint8_t controller) {
-
521  setLedRaw(pgm_read_byte(&XBOXLEDS[(uint8_t)led]), controller);
-
522 }
-
523 
-
524 void XBOXRECV::setLedMode(LEDMode ledMode, uint8_t controller) { // This function is used to do some speciel LED stuff the controller supports
-
525  setLedRaw((uint8_t)ledMode, controller);
-
526 }
-
527 
-
528 /* PC runs this at interval of approx 2 seconds
-
529 Thanks to BusHound from Perisoft.net for the Windows USB Analysis output
-
530 Found by timstamp.co.uk
-
531  */
-
532 void XBOXRECV::checkStatus() {
-
533  if (!bPollEnable)
-
534  return;
-
535  // Get controller info
-
536  writeBuf[0] = 0x08;
-
537  writeBuf[1] = 0x00;
-
538  writeBuf[2] = 0x0f;
-
539  writeBuf[3] = 0xc0;
-
540  for (uint8_t i = 0; i < 4; i++) {
-
541  XboxCommand(i, writeBuf, 4);
-
542  }
-
543  // Get battery status
-
544  writeBuf[0] = 0x00;
-
545  writeBuf[1] = 0x00;
-
546  writeBuf[2] = 0x00;
-
547  writeBuf[3] = 0x40;
-
548  for (uint8_t i = 0; i < 4; i++) {
-
549  if (Xbox360Connected[i])
-
550  XboxCommand(i, writeBuf, 4);
-
551  }
-
552 }
-
553 
-
554 void XBOXRECV::setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller) {
-
555  writeBuf[0] = 0x00;
-
556  writeBuf[1] = 0x01;
-
557  writeBuf[2] = 0x0f;
-
558  writeBuf[3] = 0xc0;
-
559  writeBuf[4] = 0x00;
-
560  writeBuf[5] = lValue; // big weight
-
561  writeBuf[6] = rValue; // small weight
-
562 
-
563  XboxCommand(controller, writeBuf, 7);
-
564 }
-
565 
-
566 void XBOXRECV::onInit(uint8_t controller) {
-
567  if (pFuncOnInit)
-
568  pFuncOnInit(); // Call the user function
-
569  else {
-
570  LED led;
-
571  if (controller == 0)
-
572  led = LED1;
-
573  else if (controller == 1)
-
574  led = LED2;
-
575  else if (controller == 2)
-
576  led = LED3;
-
577  else
-
578  led = LED4;
-
579  setLedOn(led, controller);
-
580  }
-
581 }
+
515 void XBOXRECV::setLedOn(LEDEnum led, uint8_t controller) {
+
516  if(led == OFF)
+
517  setLedRaw(0);
+
518  else if(led != ALL) // All LEDs can't be on a the same time
+
519  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4);
+
520 }
+
521 
+
522 void XBOXRECV::setLedBlink(LEDEnum led, uint8_t controller) {
+
523  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]), controller);
+
524 }
+
525 
+
526 void XBOXRECV::setLedMode(LEDModeEnum ledMode, uint8_t controller) { // This function is used to do some speciel LED stuff the controller supports
+
527  setLedRaw((uint8_t)ledMode, controller);
+
528 }
+
529 
+
530 /* PC runs this at interval of approx 2 seconds
+
531 Thanks to BusHound from Perisoft.net for the Windows USB Analysis output
+
532 Found by timstamp.co.uk
+
533  */
+
534 void XBOXRECV::checkStatus() {
+
535  if(!bPollEnable)
+
536  return;
+
537  // Get controller info
+
538  writeBuf[0] = 0x08;
+
539  writeBuf[1] = 0x00;
+
540  writeBuf[2] = 0x0f;
+
541  writeBuf[3] = 0xc0;
+
542  for(uint8_t i = 0; i < 4; i++) {
+
543  XboxCommand(i, writeBuf, 4);
+
544  }
+
545  // Get battery status
+
546  writeBuf[0] = 0x00;
+
547  writeBuf[1] = 0x00;
+
548  writeBuf[2] = 0x00;
+
549  writeBuf[3] = 0x40;
+
550  for(uint8_t i = 0; i < 4; i++) {
+
551  if(Xbox360Connected[i])
+
552  XboxCommand(i, writeBuf, 4);
+
553  }
+
554 }
+
555 
+
556 void XBOXRECV::setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller) {
+
557  writeBuf[0] = 0x00;
+
558  writeBuf[1] = 0x01;
+
559  writeBuf[2] = 0x0f;
+
560  writeBuf[3] = 0xc0;
+
561  writeBuf[4] = 0x00;
+
562  writeBuf[5] = lValue; // big weight
+
563  writeBuf[6] = rValue; // small weight
+
564 
+
565  XboxCommand(controller, writeBuf, 7);
+
566 }
+
567 
+
568 void XBOXRECV::onInit(uint8_t controller) {
+
569  if(pFuncOnInit)
+
570  pFuncOnInit(); // Call the user function
+
571  else {
+
572  LEDEnum led;
+
573  if(controller == 0)
+
574  led = LED1;
+
575  else if(controller == 1)
+
576  led = LED2;
+
577  else if(controller == 2)
+
578  led = LED3;
+
579  else
+
580  led = LED4;
+
581  setLedOn(led, controller);
+
582  }
+
583 }
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:41
-
LED3
Definition: controllerEnums.h:30
AddressPool
Definition: address.h:83
XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
Definition: XBOXRECV.h:49
-
XBOXRECV::getButtonClick
bool getButtonClick(Button b, uint8_t controller=0)
Definition: XBOXRECV.cpp:426
+
RightHatX
Definition: controllerEnums.h:122
+
LEDModeEnum
LEDModeEnum
Definition: xboxEnums.h:24
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
LED1
Definition: controllerEnums.h:28
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
XBOXRECV::Poll
virtual uint8_t Poll()
Definition: XBOXRECV.cpp:301
-
XBOXRECV::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
Definition: XBOXRECV.cpp:554
+
XBOXRECV::Poll
virtual uint8_t Poll()
Definition: XBOXRECV.cpp:292
+
XBOXRECV::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
Definition: XBOXRECV.cpp:556
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
XBOX_WIRELESS_RECEIVER_PID
#define XBOX_WIRELESS_RECEIVER_PID
Definition: XBOXRECV.h:48
-
XBOXRECV::bAddress
uint8_t bAddress
Definition: XBOXRECV.h:241
+
LED1
Definition: controllerEnums.h:29
+
XBOXRECV::bAddress
uint8_t bAddress
Definition: XBOXRECV.h:240
UsbDevice
Definition: address.h:75
+
USB_DEVICE_DESCRIPTOR::idVendor
uint16_t idVendor
Definition: usb_ch9.h:106
XBOXRECV.h
+
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
-
XBOXRECV::Xbox360Connected
uint8_t Xbox360Connected[4]
Definition: XBOXRECV.h:235
-
LeftHatY
Definition: controllerEnums.h:113
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
XBOXRECV::buttonChanged
bool buttonChanged(uint8_t controller=0)
Definition: XBOXRECV.cpp:450
-
ALL
Definition: controllerEnums.h:40
-
RightHatX
Definition: controllerEnums.h:115
+
XBOXRECV::Xbox360Connected
uint8_t Xbox360Connected[4]
Definition: XBOXRECV.h:234
+
XBOXRECV::setLedMode
void setLedMode(LEDModeEnum lm, uint8_t controller=0)
Definition: XBOXRECV.cpp:526
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
XBOXRECV::buttonChanged
bool buttonChanged(uint8_t controller=0)
Definition: XBOXRECV.cpp:441
XBOX_OUTPUT_PIPE_3
#define XBOX_OUTPUT_PIPE_3
Definition: XBOXRECV.h:39
XBOXRECV::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:40
USB_ERROR_FailGetDevDescr
#define USB_ERROR_FailGetDevDescr
Definition: UsbCore.h:73
-
LED4
Definition: controllerEnums.h:31
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
-
XBOXBUTTONS
const uint16_t XBOXBUTTONS[]
Definition: xboxEnums.h:40
hrJERR
#define hrJERR
Definition: max3421e.h:225
-
XBOXLEDS
const uint8_t XBOXLEDS[]
Definition: xboxEnums.h:32
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
LED
LED
Definition: controllerEnums.h:27
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
-
R2
Definition: controllerEnums.h:82
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
Notify
#define Notify(...)
Definition: message.h:44
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
XBOX_INPUT_PIPE_2
#define XBOX_INPUT_PIPE_2
Definition: XBOXRECV.h:36
NotifyFailUnknownDevice
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
LED2
Definition: controllerEnums.h:29
+
LED2
Definition: controllerEnums.h:30
XBOX_VID
#define XBOX_VID
Definition: XBOXOLD.h:36
-
XBOXRECV::Release
virtual uint8_t Release()
Definition: XBOXRECV.cpp:291
+
RightHatY
Definition: controllerEnums.h:124
+
XBOXRECV::Release
virtual uint8_t Release()
Definition: XBOXRECV.cpp:282
EP_INTERRUPT
#define EP_INTERRUPT
Definition: PS3USB.h:28
EpInfo
Definition: address.h:32
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
-
LeftHatX
Definition: controllerEnums.h:111
-
XBOXRECV::XboxReceiverConnected
bool XboxReceiverConnected
Definition: XBOXRECV.h:229
-
XBOXRECV::setLedBlink
void setLedBlink(LED l, uint8_t controller=0)
Definition: XBOXRECV.cpp:520
-
L2
Definition: controllerEnums.h:81
-
XBOXRECV::setLedOn
void setLedOn(LED l, uint8_t controller=0)
Definition: XBOXRECV.cpp:515
-
XBOXRECV::getBatteryLevel
uint8_t getBatteryLevel(uint8_t controller=0)
Definition: XBOXRECV.cpp:475
+
XBOXRECV::getButtonClick
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:417
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
+
XBOXRECV::setLedOn
void setLedOn(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:515
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
XBOXRECV::getButtonPress
uint8_t getButtonPress(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:409
+
XBOXRECV::XboxReceiverConnected
bool XboxReceiverConnected
Definition: XBOXRECV.h:228
+
L2
Definition: controllerEnums.h:82
+
LED4
Definition: controllerEnums.h:32
+
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXOLD.h:38
+
ALL
Definition: controllerEnums.h:41
+
XBOXRECV::getBatteryLevel
uint8_t getBatteryLevel(uint8_t controller=0)
Definition: XBOXRECV.cpp:466
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
XBOX_OUTPUT_PIPE_1
#define XBOX_OUTPUT_PIPE_1
Definition: XBOXRECV.h:35
-
LEDMode
LEDMode
Definition: xboxEnums.h:24
EpInfo::bmSndToggle
uint8_t bmSndToggle
Definition: address.h:40
+
XBOXRECV::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller=0)
Definition: XBOXRECV.cpp:437
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
XBOXRECV::XBOXRECV
XBOXRECV(USB *pUsb)
Definition: XBOXRECV.cpp:25
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXOLD.h:37
XBOX_INPUT_PIPE_1
#define XBOX_INPUT_PIPE_1
Definition: XBOXRECV.h:34
+
XBOXRECV::setLedBlink
void setLedBlink(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:522
+
OFF
Definition: controllerEnums.h:28
USB_NAK_NOWAIT
#define USB_NAK_NOWAIT
Definition: address.h:29
-
XBOXRECV::setLedMode
void setLedMode(LEDMode lm, uint8_t controller=0)
Definition: XBOXRECV.cpp:524
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
XBOXRECV::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:137
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
XBOXRECV::setLedRaw
void setLedRaw(uint8_t value, uint8_t controller=0)
Definition: XBOXRECV.cpp:506
+
XBOX_LEDS
const uint8_t XBOX_LEDS[]
Definition: xboxEnums.h:32
+
USB_DEVICE_DESCRIPTOR::idProduct
uint16_t idProduct
Definition: usb_ch9.h:107
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:49
-
bmRCVTOG0
#define bmRCVTOG0
Definition: max3421e.h:185
-
XBOXRECV::getAnalogHat
int16_t getAnalogHat(AnalogHat a, uint8_t controller=0)
Definition: XBOXRECV.cpp:446
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
-
Button
Button
Definition: controllerEnums.h:44
-
bmSNDTOG0
#define bmSNDTOG0
Definition: max3421e.h:187
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB
Definition: UsbCore.h:152
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB
Definition: UsbCore.h:176
+
LED3
Definition: controllerEnums.h:31
XBOX_INPUT_PIPE_3
#define XBOX_INPUT_PIPE_3
Definition: XBOXRECV.h:38
XBOX_CONTROL_PIPE
#define XBOX_CONTROL_PIPE
Definition: XBOXOLD.h:31
-
XBOXRECV::getButtonPress
uint8_t getButtonPress(Button b, uint8_t controller=0)
Definition: XBOXRECV.cpp:418
+
LeftHatY
Definition: controllerEnums.h:120
+
LeftHatX
Definition: controllerEnums.h:118
+
R2
Definition: controllerEnums.h:83
XBOX_INPUT_PIPE_4
#define XBOX_INPUT_PIPE_4
Definition: XBOXRECV.h:40
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
XBOX_BUTTONS
const uint16_t XBOX_BUTTONS[]
Definition: xboxEnums.h:41
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
XBOXRECV::disconnect
void disconnect(uint8_t controller=0)
Definition: XBOXRECV.cpp:497
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
RightHatY
Definition: controllerEnums.h:117
XBOX_OUTPUT_PIPE_4
#define XBOX_OUTPUT_PIPE_4
Definition: XBOXRECV.h:41
-
XBOXRECV::pUsb
USB * pUsb
Definition: XBOXRECV.h:239
+
XBOXRECV::pUsb
USB * pUsb
Definition: XBOXRECV.h:238
XBOX_OUTPUT_PIPE_2
#define XBOX_OUTPUT_PIPE_2
Definition: XBOXRECV.h:37
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
-
XBOXRECV::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXRECV.h:243
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
+
XBOXRECV::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXRECV.h:242
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
@@ -772,7 +777,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/_x_b_o_x_r_e_c_v_8h.html b/_x_b_o_x_r_e_c_v_8h.html index b7856c37..4ca7f36e 100644 --- a/_x_b_o_x_r_e_c_v_8h.html +++ b/_x_b_o_x_r_e_c_v_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXRECV.h File Reference @@ -31,7 +31,7 @@ - + @@ -397,7 +397,7 @@ Macros diff --git a/_x_b_o_x_r_e_c_v_8h_source.html b/_x_b_o_x_r_e_c_v_8h_source.html index 2da4845f..c47d3df6 100644 --- a/_x_b_o_x_r_e_c_v_8h_source.html +++ b/_x_b_o_x_r_e_c_v_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXRECV.h Source File @@ -31,7 +31,7 @@ - + @@ -161,124 +161,124 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
116  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
117  return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID) && (pid == XBOX_WIRELESS_RECEIVER_PID || pid == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID));
118  };
-
134  uint8_t getButtonPress(Button b, uint8_t controller = 0);
-
135  bool getButtonClick(Button b, uint8_t controller = 0);
-
145  int16_t getAnalogHat(AnalogHat a, uint8_t controller = 0);
-
146 
-
151  void disconnect(uint8_t controller = 0);
-
152 
-
157  void setAllOff(uint8_t controller = 0) {
-
158  setRumbleOn(0, 0, controller);
-
159  setLedOff(controller);
-
160  };
-
161 
-
166  void setRumbleOff(uint8_t controller = 0) {
-
167  setRumbleOn(0, 0, controller);
-
168  };
-
175  void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller = 0);
-
183  void setLedRaw(uint8_t value, uint8_t controller = 0);
-
184 
-
189  void setLedOff(uint8_t controller = 0) {
-
190  setLedRaw(0, controller);
-
191  };
-
197  void setLedOn(LED l, uint8_t controller = 0);
-
203  void setLedBlink(LED l, uint8_t controller = 0);
-
209  void setLedMode(LEDMode lm, uint8_t controller = 0);
-
215  uint8_t getBatteryLevel(uint8_t controller = 0);
-
221  bool buttonChanged(uint8_t controller = 0);
-
222 
-
227  void attachOnInit(void (*funcOnInit)(void)) {
-
228  pFuncOnInit = funcOnInit;
-
229  };
-
233  bool XboxReceiverConnected;
-
235  uint8_t Xbox360Connected[4];
-
236 
-
237 protected:
-
239  USB *pUsb;
-
241  uint8_t bAddress;
-
243  EpInfo epInfo[XBOX_MAX_ENDPOINTS];
-
244 
-
245 private:
-
252  void onInit(uint8_t controller);
-
253  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
-
254 
-
255  bool bPollEnable;
-
256 
-
257  /* Variables to store the buttons */
-
258  uint32_t ButtonState[4];
-
259  uint32_t OldButtonState[4];
-
260  uint16_t ButtonClickState[4];
-
261  int16_t hatValue[4][4];
-
262  uint16_t controllerStatus[4];
-
263  bool buttonStateChanged[4]; // True if a button has changed
-
264 
-
265  bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
-
266  bool R2Clicked[4];
-
267 
-
268  uint32_t checkStatusTimer; // Timing for checkStatus() signals
-
269 
-
270  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
-
271  uint8_t writeBuf[7]; // General purpose buffer for output data
-
272 
-
273  void readReport(uint8_t controller); // read incoming data
-
274  void printReport(uint8_t controller, uint8_t nBytes); // print incoming date - Uncomment for debugging
-
275 
-
276  /* Private commands */
-
277  void XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes);
-
278  void checkStatus();
-
279 };
-
280 #endif
+
133  uint8_t getButtonPress(ButtonEnum b, uint8_t controller = 0);
+
134  bool getButtonClick(ButtonEnum b, uint8_t controller = 0);
+
144  int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller = 0);
+
145 
+
150  void disconnect(uint8_t controller = 0);
+
151 
+
156  void setAllOff(uint8_t controller = 0) {
+
157  setRumbleOn(0, 0, controller);
+
158  setLedOff(controller);
+
159  };
+
160 
+
165  void setRumbleOff(uint8_t controller = 0) {
+
166  setRumbleOn(0, 0, controller);
+
167  };
+
174  void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller = 0);
+
182  void setLedRaw(uint8_t value, uint8_t controller = 0);
+
183 
+
188  void setLedOff(uint8_t controller = 0) {
+
189  setLedRaw(0, controller);
+
190  };
+
196  void setLedOn(LEDEnum l, uint8_t controller = 0);
+
202  void setLedBlink(LEDEnum l, uint8_t controller = 0);
+
208  void setLedMode(LEDModeEnum lm, uint8_t controller = 0);
+
214  uint8_t getBatteryLevel(uint8_t controller = 0);
+
220  bool buttonChanged(uint8_t controller = 0);
+
221 
+
226  void attachOnInit(void (*funcOnInit)(void)) {
+
227  pFuncOnInit = funcOnInit;
+
228  };
+
232  bool XboxReceiverConnected;
+
234  uint8_t Xbox360Connected[4];
+
235 
+
236 protected:
+
238  USB *pUsb;
+
240  uint8_t bAddress;
+
242  EpInfo epInfo[XBOX_MAX_ENDPOINTS];
+
243 
+
244 private:
+
251  void onInit(uint8_t controller);
+
252  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
+
253 
+
254  bool bPollEnable;
+
255 
+
256  /* Variables to store the buttons */
+
257  uint32_t ButtonState[4];
+
258  uint32_t OldButtonState[4];
+
259  uint16_t ButtonClickState[4];
+
260  int16_t hatValue[4][4];
+
261  uint16_t controllerStatus[4];
+
262  bool buttonStateChanged[4]; // True if a button has changed
+
263 
+
264  bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
+
265  bool R2Clicked[4];
+
266 
+
267  uint32_t checkStatusTimer; // Timing for checkStatus() signals
+
268 
+
269  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
+
270  uint8_t writeBuf[7]; // General purpose buffer for output data
+
271 
+
272  void readReport(uint8_t controller); // read incoming data
+
273  void printReport(uint8_t controller, uint8_t nBytes); // print incoming date - Uncomment for debugging
+
274 
+
275  /* Private commands */
+
276  void XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes);
+
277  void checkStatus();
+
278 };
+
279 #endif
XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
Definition: XBOXRECV.h:49
-
XBOXRECV::getButtonClick
bool getButtonClick(Button b, uint8_t controller=0)
Definition: XBOXRECV.cpp:426
-
XBOXRECV::Poll
virtual uint8_t Poll()
Definition: XBOXRECV.cpp:301
-
XBOXRECV::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
Definition: XBOXRECV.cpp:554
+
LEDModeEnum
LEDModeEnum
Definition: xboxEnums.h:24
+
XBOXRECV::Poll
virtual uint8_t Poll()
Definition: XBOXRECV.cpp:292
+
XBOXRECV::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
Definition: XBOXRECV.cpp:556
XBOX_WIRELESS_RECEIVER_PID
#define XBOX_WIRELESS_RECEIVER_PID
Definition: XBOXRECV.h:48
-
XBOXRECV::bAddress
uint8_t bAddress
Definition: XBOXRECV.h:241
-
XBOXRECV::setLedOff
void setLedOff(uint8_t controller=0)
Definition: XBOXRECV.h:189
+
XBOXRECV::bAddress
uint8_t bAddress
Definition: XBOXRECV.h:240
+
XBOXRECV::setLedOff
void setLedOff(uint8_t controller=0)
Definition: XBOXRECV.h:188
xboxEnums.h
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: XBOXRECV.h:27
XBOXRECV::GetAddress
virtual uint8_t GetAddress()
Definition: XBOXRECV.h:98
-
XBOXRECV::Xbox360Connected
uint8_t Xbox360Connected[4]
Definition: XBOXRECV.h:235
-
XBOXRECV::buttonChanged
bool buttonChanged(uint8_t controller=0)
Definition: XBOXRECV.cpp:450
-
XBOXRECV::setRumbleOff
void setRumbleOff(uint8_t controller=0)
Definition: XBOXRECV.h:166
+
XBOXRECV::Xbox360Connected
uint8_t Xbox360Connected[4]
Definition: XBOXRECV.h:234
+
XBOXRECV::setLedMode
void setLedMode(LEDModeEnum lm, uint8_t controller=0)
Definition: XBOXRECV.cpp:526
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
+
XBOXRECV::buttonChanged
bool buttonChanged(uint8_t controller=0)
Definition: XBOXRECV.cpp:441
+
XBOXRECV::setRumbleOff
void setRumbleOff(uint8_t controller=0)
Definition: XBOXRECV.h:165
XBOXRECV::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:40
USBDeviceConfig
Definition: UsbCore.h:105
Usb.h
XBOXRECV::isReady
virtual bool isReady()
Definition: XBOXRECV.h:106
-
LED
LED
Definition: controllerEnums.h:27
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
XBOX_VID
#define XBOX_VID
Definition: XBOXRECV.h:44
-
XBOXRECV::setAllOff
void setAllOff(uint8_t controller=0)
Definition: XBOXRECV.h:157
-
XBOXRECV::Release
virtual uint8_t Release()
Definition: XBOXRECV.cpp:291
+
XBOXRECV::setAllOff
void setAllOff(uint8_t controller=0)
Definition: XBOXRECV.h:156
+
XBOXRECV::Release
virtual uint8_t Release()
Definition: XBOXRECV.cpp:282
EpInfo
Definition: address.h:32
-
XBOXRECV::XboxReceiverConnected
bool XboxReceiverConnected
Definition: XBOXRECV.h:229
-
XBOXRECV::setLedBlink
void setLedBlink(LED l, uint8_t controller=0)
Definition: XBOXRECV.cpp:520
-
XBOXRECV::setLedOn
void setLedOn(LED l, uint8_t controller=0)
Definition: XBOXRECV.cpp:515
-
XBOXRECV::getBatteryLevel
uint8_t getBatteryLevel(uint8_t controller=0)
Definition: XBOXRECV.cpp:475
-
LEDMode
LEDMode
Definition: xboxEnums.h:24
+
XBOXRECV::getButtonClick
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:417
+
XBOXRECV::setLedOn
void setLedOn(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:515
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
+
XBOXRECV::getButtonPress
uint8_t getButtonPress(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:409
+
XBOXRECV::XboxReceiverConnected
bool XboxReceiverConnected
Definition: XBOXRECV.h:228
+
XBOXRECV::getBatteryLevel
uint8_t getBatteryLevel(uint8_t controller=0)
Definition: XBOXRECV.cpp:466
+
XBOXRECV::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller=0)
Definition: XBOXRECV.cpp:437
XBOXRECV::XBOXRECV
XBOXRECV(USB *pUsb)
Definition: XBOXRECV.cpp:25
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXRECV.h:46
-
XBOXRECV::setLedMode
void setLedMode(LEDMode lm, uint8_t controller=0)
Definition: XBOXRECV.cpp:524
+
XBOXRECV::setLedBlink
void setLedBlink(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:522
XBOXRECV::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:137
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXRECV.h:45
XBOXRECV::setLedRaw
void setLedRaw(uint8_t value, uint8_t controller=0)
Definition: XBOXRECV.cpp:506
XBOXRECV::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXRECV.h:116
-
XBOXRECV::getAnalogHat
int16_t getAnalogHat(AnalogHat a, uint8_t controller=0)
Definition: XBOXRECV.cpp:446
-
Button
Button
Definition: controllerEnums.h:44
-
USB
Definition: UsbCore.h:152
-
XBOXRECV::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXRECV.h:227
-
XBOXRECV::getButtonPress
uint8_t getButtonPress(Button b, uint8_t controller=0)
Definition: XBOXRECV.cpp:418
+
USB
Definition: UsbCore.h:176
+
XBOXRECV::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXRECV.h:226
XBOXRECV::disconnect
void disconnect(uint8_t controller=0)
Definition: XBOXRECV.cpp:497
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
XBOXRECV
Definition: XBOXRECV.h:58
-
XBOXRECV::pUsb
USB * pUsb
Definition: XBOXRECV.h:239
-
XBOXRECV::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXRECV.h:243
+
XBOXRECV::pUsb
USB * pUsb
Definition: XBOXRECV.h:238
+
XBOXRECV::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXRECV.h:242
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXRECV.h:51
diff --git a/_x_b_o_x_u_s_b_8cpp.html b/_x_b_o_x_u_s_b_8cpp.html index e7ca9ca8..a6068163 100644 --- a/_x_b_o_x_u_s_b_8cpp.html +++ b/_x_b_o_x_u_s_b_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXUSB.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for XBOXUSB.cpp: diff --git a/_x_b_o_x_u_s_b_8cpp_source.html b/_x_b_o_x_u_s_b_8cpp_source.html index d084eeaa..998d430d 100644 --- a/_x_b_o_x_u_s_b_8cpp_source.html +++ b/_x_b_o_x_u_s_b_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXUSB.cpp Source File @@ -31,7 +31,7 @@ - + @@ -115,431 +115,435 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
24 pUsb(p), // pointer to USB class instance - mandatory
25 bAddress(0), // device address - mandatory
26 bPollEnable(false) { // don't start polling before dongle is connected
-
27  for (uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
+
27  for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
28  epInfo[i].epAddr = 0;
29  epInfo[i].maxPktSize = (i) ? 0 : 8;
30  epInfo[i].epAttribs = 0;
31  epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
32  }
33 
-
34  if (pUsb) // register in USB subsystem
+
34  if(pUsb) // register in USB subsystem
35  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
36 }
37 
38 uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
39  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
-
40  uint8_t rcode;
-
41  UsbDevice *p = NULL;
-
42  EpInfo *oldep_ptr = NULL;
-
43  uint16_t PID;
-
44  uint16_t VID;
-
45 
-
46  // get memory address of USB device address pool
-
47  AddressPool &addrPool = pUsb->GetAddressPool();
-
48 #ifdef EXTRADEBUG
-
49  Notify(PSTR("\r\nXBOXUSB Init"), 0x80);
-
50 #endif
-
51  // check if address has already been assigned to an instance
-
52  if (bAddress) {
-
53 #ifdef DEBUG_USB_HOST
-
54  Notify(PSTR("\r\nAddress in use"), 0x80);
-
55 #endif
-
56  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
57  }
-
58 
-
59  // Get pointer to pseudo device with address 0 assigned
-
60  p = addrPool.GetUsbDevicePtr(0);
-
61 
-
62  if (!p) {
-
63 #ifdef DEBUG_USB_HOST
-
64  Notify(PSTR("\r\nAddress not found"), 0x80);
-
65 #endif
-
66  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
67  }
-
68 
-
69  if (!p->epinfo) {
-
70 #ifdef DEBUG_USB_HOST
-
71  Notify(PSTR("\r\nepinfo is null"), 0x80);
-
72 #endif
-
73  return USB_ERROR_EPINFO_IS_NULL;
-
74  }
-
75 
-
76  // Save old pointer to EP_RECORD of address 0
-
77  oldep_ptr = p->epinfo;
-
78 
-
79  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
80  p->epinfo = epInfo;
-
81 
-
82  p->lowspeed = lowspeed;
-
83 
-
84  // Get device descriptor
-
85  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
-
86  // Restore p->epinfo
-
87  p->epinfo = oldep_ptr;
-
88 
-
89  if (rcode)
-
90  goto FailGetDevDescr;
-
91 
-
92  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
-
93  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
-
94 
-
95  if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID && VID != GAMESTOP_VID) // Check VID
-
96  goto FailUnknownDevice;
-
97  if (PID == XBOX_WIRELESS_PID) {
-
98 #ifdef DEBUG_USB_HOST
-
99  Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
-
100 #endif
-
101  goto FailUnknownDevice;
-
102  } else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
-
103 #ifdef DEBUG_USB_HOST
-
104  Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
-
105 #endif
-
106  goto FailUnknownDevice;
-
107  } else if (PID != XBOX_WIRED_PID && PID != GAMESTOP_WIRED_PID) // Check PID
-
108  goto FailUnknownDevice;
-
109 
-
110  // Allocate new address according to device class
-
111  bAddress = addrPool.AllocAddress(parent, false, port);
-
112 
-
113  if (!bAddress)
-
114  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
115 
-
116  // Extract Max Packet Size from device descriptor
-
117  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
118 
-
119  // Assign new address to the device
-
120  rcode = pUsb->setAddr(0, 0, bAddress);
-
121  if (rcode) {
-
122  p->lowspeed = false;
-
123  addrPool.FreeAddress(bAddress);
-
124  bAddress = 0;
-
125 #ifdef DEBUG_USB_HOST
-
126  Notify(PSTR("\r\nsetAddr: "), 0x80);
-
127  D_PrintHex<uint8_t > (rcode, 0x80);
-
128 #endif
-
129  return rcode;
-
130  }
-
131 #ifdef EXTRADEBUG
-
132  Notify(PSTR("\r\nAddr: "), 0x80);
-
133  D_PrintHex<uint8_t > (bAddress, 0x80);
-
134 #endif
-
135  delay(300); // Spec says you should wait at least 200ms
-
136 
-
137  p->lowspeed = false;
-
138 
-
139  //get pointer to assigned address record
-
140  p = addrPool.GetUsbDevicePtr(bAddress);
-
141  if (!p)
-
142  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
143 
-
144  p->lowspeed = lowspeed;
-
145 
-
146  // Assign epInfo to epinfo pointer - only EP0 is known
-
147  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
148  if (rcode)
-
149  goto FailSetDevTblEntry;
-
150 
-
151  /* The application will work in reduced host mode, so we can save program and data
-
152  memory space. After verifying the VID we will use known values for the
-
153  configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */
-
154 
-
155  /* Initialize data structures for endpoints of device */
-
156  epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX 360 report endpoint
-
157  epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
158  epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
159  epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
160  epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
161  epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
162  epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX 360 output endpoint
-
163  epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
-
164  epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
-
165  epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
-
166  epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
-
167  epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
-
168 
-
169  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
-
170  if (rcode)
-
171  goto FailSetDevTblEntry;
-
172 
-
173  delay(200); // Give time for address change
-
174 
-
175  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
-
176  if (rcode)
-
177  goto FailSetConfDescr;
-
178 
-
179 #ifdef DEBUG_USB_HOST
-
180  Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80);
-
181 #endif
-
182  onInit();
-
183  Xbox360Connected = true;
-
184  bPollEnable = true;
-
185  return 0; // Successful configuration
-
186 
-
187  /* Diagnostic messages */
-
188 FailGetDevDescr:
-
189 #ifdef DEBUG_USB_HOST
-
190  NotifyFailGetDevDescr();
-
191  goto Fail;
-
192 #endif
-
193 
-
194 FailSetDevTblEntry:
-
195 #ifdef DEBUG_USB_HOST
-
196  NotifyFailSetDevTblEntry();
-
197  goto Fail;
-
198 #endif
-
199 
-
200 FailSetConfDescr:
-
201 #ifdef DEBUG_USB_HOST
-
202  NotifyFailSetConfDescr();
-
203  goto Fail;
+
40  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
41  uint8_t rcode;
+
42  UsbDevice *p = NULL;
+
43  EpInfo *oldep_ptr = NULL;
+
44  uint16_t PID;
+
45  uint16_t VID;
+
46 
+
47  // get memory address of USB device address pool
+
48  AddressPool &addrPool = pUsb->GetAddressPool();
+
49 #ifdef EXTRADEBUG
+
50  Notify(PSTR("\r\nXBOXUSB Init"), 0x80);
+
51 #endif
+
52  // check if address has already been assigned to an instance
+
53  if(bAddress) {
+
54 #ifdef DEBUG_USB_HOST
+
55  Notify(PSTR("\r\nAddress in use"), 0x80);
+
56 #endif
+
57  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
58  }
+
59 
+
60  // Get pointer to pseudo device with address 0 assigned
+
61  p = addrPool.GetUsbDevicePtr(0);
+
62 
+
63  if(!p) {
+
64 #ifdef DEBUG_USB_HOST
+
65  Notify(PSTR("\r\nAddress not found"), 0x80);
+
66 #endif
+
67  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
68  }
+
69 
+
70  if(!p->epinfo) {
+
71 #ifdef DEBUG_USB_HOST
+
72  Notify(PSTR("\r\nepinfo is null"), 0x80);
+
73 #endif
+
74  return USB_ERROR_EPINFO_IS_NULL;
+
75  }
+
76 
+
77  // Save old pointer to EP_RECORD of address 0
+
78  oldep_ptr = p->epinfo;
+
79 
+
80  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
81  p->epinfo = epInfo;
+
82 
+
83  p->lowspeed = lowspeed;
+
84 
+
85  // Get device descriptor
+
86  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
+
87  // Restore p->epinfo
+
88  p->epinfo = oldep_ptr;
+
89 
+
90  if(rcode)
+
91  goto FailGetDevDescr;
+
92 
+
93  VID = udd->idVendor;
+
94  PID = udd->idProduct;
+
95 
+
96  if(VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID && VID != GAMESTOP_VID) // Check VID
+
97  goto FailUnknownDevice;
+
98  if(PID == XBOX_WIRELESS_PID) {
+
99 #ifdef DEBUG_USB_HOST
+
100  Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
+
101 #endif
+
102  goto FailUnknownDevice;
+
103  } else if(PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
+
104 #ifdef DEBUG_USB_HOST
+
105  Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
+
106 #endif
+
107  goto FailUnknownDevice;
+
108  } else if(PID != XBOX_WIRED_PID && PID != MADCATZ_WIRED_PID && PID != GAMESTOP_WIRED_PID) // Check PID
+
109  goto FailUnknownDevice;
+
110 
+
111  // Allocate new address according to device class
+
112  bAddress = addrPool.AllocAddress(parent, false, port);
+
113 
+
114  if(!bAddress)
+
115  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
116 
+
117  // Extract Max Packet Size from device descriptor
+
118  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
119 
+
120  // Assign new address to the device
+
121  rcode = pUsb->setAddr(0, 0, bAddress);
+
122  if(rcode) {
+
123  p->lowspeed = false;
+
124  addrPool.FreeAddress(bAddress);
+
125  bAddress = 0;
+
126 #ifdef DEBUG_USB_HOST
+
127  Notify(PSTR("\r\nsetAddr: "), 0x80);
+
128  D_PrintHex<uint8_t > (rcode, 0x80);
+
129 #endif
+
130  return rcode;
+
131  }
+
132 #ifdef EXTRADEBUG
+
133  Notify(PSTR("\r\nAddr: "), 0x80);
+
134  D_PrintHex<uint8_t > (bAddress, 0x80);
+
135 #endif
+
136  //delay(300); // Spec says you should wait at least 200ms
+
137 
+
138  p->lowspeed = false;
+
139 
+
140  //get pointer to assigned address record
+
141  p = addrPool.GetUsbDevicePtr(bAddress);
+
142  if(!p)
+
143  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
144 
+
145  p->lowspeed = lowspeed;
+
146 
+
147  // Assign epInfo to epinfo pointer - only EP0 is known
+
148  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
149  if(rcode)
+
150  goto FailSetDevTblEntry;
+
151 
+
152  /* The application will work in reduced host mode, so we can save program and data
+
153  memory space. After verifying the VID we will use known values for the
+
154  configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */
+
155 
+
156  /* Initialize data structures for endpoints of device */
+
157  epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX 360 report endpoint
+
158  epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
159  epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
160  epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
161  epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = 0;
+
162  epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = 0;
+
163  epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX 360 output endpoint
+
164  epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
+
165  epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
+
166  epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
+
167  epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = 0;
+
168  epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = 0;
+
169 
+
170  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
+
171  if(rcode)
+
172  goto FailSetDevTblEntry;
+
173 
+
174  delay(200); // Give time for address change
+
175 
+
176  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
+
177  if(rcode)
+
178  goto FailSetConfDescr;
+
179 
+
180 #ifdef DEBUG_USB_HOST
+
181  Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80);
+
182 #endif
+
183  onInit();
+
184  Xbox360Connected = true;
+
185  bPollEnable = true;
+
186  return 0; // Successful configuration
+
187 
+
188  /* Diagnostic messages */
+
189 FailGetDevDescr:
+
190 #ifdef DEBUG_USB_HOST
+
191  NotifyFailGetDevDescr();
+
192  goto Fail;
+
193 #endif
+
194 
+
195 FailSetDevTblEntry:
+
196 #ifdef DEBUG_USB_HOST
+
197  NotifyFailSetDevTblEntry();
+
198  goto Fail;
+
199 #endif
+
200 
+
201 FailSetConfDescr:
+
202 #ifdef DEBUG_USB_HOST
+
203  NotifyFailSetConfDescr();
204 #endif
-
205 FailUnknownDevice:
-
206 #ifdef DEBUG_USB_HOST
-
207  NotifyFailUnknownDevice(VID, PID);
-
208 #endif
-
209  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
210 
-
211 Fail:
-
212 #ifdef DEBUG_USB_HOST
-
213  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
-
214  NotifyFail(rcode);
-
215 #endif
-
216  Release();
-
217  return rcode;
-
218 }
-
219 
-
220 /* Performs a cleanup after failed Init() attempt */
-
221 uint8_t XBOXUSB::Release() {
-
222  Xbox360Connected = false;
-
223  pUsb->GetAddressPool().FreeAddress(bAddress);
-
224  bAddress = 0;
-
225  bPollEnable = false;
-
226  return 0;
-
227 }
-
228 
-
229 uint8_t XBOXUSB::Poll() {
-
230  if (!bPollEnable)
-
231  return 0;
-
232  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
-
233  pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
-
234  readReport();
-
235 #ifdef PRINTREPORT
-
236  printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
-
237 #endif
-
238  return 0;
-
239 }
-
240 
-
241 void XBOXUSB::readReport() {
-
242  if (readBuf == NULL)
-
243  return;
-
244  if (readBuf[0] != 0x00 || readBuf[1] != 0x14) { // Check if it's the correct report - the controller also sends different status reports
+
205  goto Fail;
+
206 
+
207 FailUnknownDevice:
+
208 #ifdef DEBUG_USB_HOST
+
209  NotifyFailUnknownDevice(VID, PID);
+
210 #endif
+
211  rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
212 
+
213 Fail:
+
214 #ifdef DEBUG_USB_HOST
+
215  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
+
216  NotifyFail(rcode);
+
217 #endif
+
218  Release();
+
219  return rcode;
+
220 }
+
221 
+
222 /* Performs a cleanup after failed Init() attempt */
+
223 uint8_t XBOXUSB::Release() {
+
224  Xbox360Connected = false;
+
225  pUsb->GetAddressPool().FreeAddress(bAddress);
+
226  bAddress = 0;
+
227  bPollEnable = false;
+
228  return 0;
+
229 }
+
230 
+
231 uint8_t XBOXUSB::Poll() {
+
232  if(!bPollEnable)
+
233  return 0;
+
234  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
+
235  pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
+
236  readReport();
+
237 #ifdef PRINTREPORT
+
238  printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
+
239 #endif
+
240  return 0;
+
241 }
+
242 
+
243 void XBOXUSB::readReport() {
+
244  if(readBuf == NULL)
245  return;
-
246  }
-
247 
-
248  ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
+
246  if(readBuf[0] != 0x00 || readBuf[1] != 0x14) { // Check if it's the correct report - the controller also sends different status reports
+
247  return;
+
248  }
249 
-
250  hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
-
251  hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
-
252  hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
-
253  hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
-
254 
-
255  //Notify(PSTR("\r\nButtonState"), 0x80);
-
256  //PrintHex<uint32_t>(ButtonState, 0x80);
-
257 
-
258  if (ButtonState != OldButtonState) {
-
259  ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
-
260  if (((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0) // The L2 and R2 buttons are special as they are analog buttons
-
261  R2Clicked = true;
-
262  if ((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
-
263  L2Clicked = true;
-
264  OldButtonState = ButtonState;
-
265  }
-
266 }
-
267 
-
268 void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
-
269 #ifdef PRINTREPORT
-
270  if (readBuf == NULL)
-
271  return;
-
272  for (uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) {
-
273  D_PrintHex<uint8_t > (readBuf[i], 0x80);
-
274  Notify(PSTR(" "), 0x80);
-
275  }
-
276  Notify(PSTR("\r\n"), 0x80);
-
277 #endif
-
278 }
-
279 
-
280 uint8_t XBOXUSB::getButtonPress(Button b) {
-
281  if (b == L2) // These are analog buttons
-
282  return (uint8_t)(ButtonState >> 8);
-
283  else if (b == R2)
-
284  return (uint8_t)ButtonState;
-
285  return (bool)(ButtonState & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16));
-
286 }
-
287 
-
288 bool XBOXUSB::getButtonClick(Button b) {
-
289  if (b == L2) {
-
290  if (L2Clicked) {
-
291  L2Clicked = false;
-
292  return true;
-
293  }
-
294  return false;
-
295  } else if (b == R2) {
-
296  if (R2Clicked) {
-
297  R2Clicked = false;
-
298  return true;
-
299  }
-
300  return false;
-
301  }
-
302  uint16_t button = pgm_read_word(&XBOXBUTTONS[(uint8_t)b]);
-
303  bool click = (ButtonClickState & button);
-
304  ButtonClickState &= ~button; // clear "click" event
-
305  return click;
-
306 }
-
307 
-
308 int16_t XBOXUSB::getAnalogHat(AnalogHat a) {
-
309  return hatValue[a];
-
310 }
-
311 
-
312 /* Xbox Controller commands */
-
313 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
-
314  //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
-
315  pUsb->ctrlReq(bAddress, epInfo[XBOX_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
-
316 }
-
317 
-
318 void XBOXUSB::setLedRaw(uint8_t value) {
-
319  writeBuf[0] = 0x01;
-
320  writeBuf[1] = 0x03;
-
321  writeBuf[2] = value;
-
322 
-
323  XboxCommand(writeBuf, 3);
-
324 }
-
325 
-
326 void XBOXUSB::setLedOn(LED led) {
-
327  if (led != ALL) // All LEDs can't be on a the same time
-
328  setLedRaw((pgm_read_byte(&XBOXLEDS[(uint8_t)led])) + 4);
-
329 }
-
330 
-
331 void XBOXUSB::setLedBlink(LED led) {
-
332  setLedRaw(pgm_read_byte(&XBOXLEDS[(uint8_t)led]));
+
250  ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
+
251 
+
252  hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
+
253  hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
+
254  hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
+
255  hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
+
256 
+
257  //Notify(PSTR("\r\nButtonState"), 0x80);
+
258  //PrintHex<uint32_t>(ButtonState, 0x80);
+
259 
+
260  if(ButtonState != OldButtonState) {
+
261  ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
+
262  if(((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0) // The L2 and R2 buttons are special as they are analog buttons
+
263  R2Clicked = true;
+
264  if((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
+
265  L2Clicked = true;
+
266  OldButtonState = ButtonState;
+
267  }
+
268 }
+
269 
+
270 void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
+
271 #ifdef PRINTREPORT
+
272  if(readBuf == NULL)
+
273  return;
+
274  for(uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) {
+
275  D_PrintHex<uint8_t > (readBuf[i], 0x80);
+
276  Notify(PSTR(" "), 0x80);
+
277  }
+
278  Notify(PSTR("\r\n"), 0x80);
+
279 #endif
+
280 }
+
281 
+
282 uint8_t XBOXUSB::getButtonPress(ButtonEnum b) {
+
283  if(b == L2) // These are analog buttons
+
284  return (uint8_t)(ButtonState >> 8);
+
285  else if(b == R2)
+
286  return (uint8_t)ButtonState;
+
287  return (bool)(ButtonState & ((uint32_t)pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]) << 16));
+
288 }
+
289 
+
290 bool XBOXUSB::getButtonClick(ButtonEnum b) {
+
291  if(b == L2) {
+
292  if(L2Clicked) {
+
293  L2Clicked = false;
+
294  return true;
+
295  }
+
296  return false;
+
297  } else if(b == R2) {
+
298  if(R2Clicked) {
+
299  R2Clicked = false;
+
300  return true;
+
301  }
+
302  return false;
+
303  }
+
304  uint16_t button = pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]);
+
305  bool click = (ButtonClickState & button);
+
306  ButtonClickState &= ~button; // clear "click" event
+
307  return click;
+
308 }
+
309 
+
310 int16_t XBOXUSB::getAnalogHat(AnalogHatEnum a) {
+
311  return hatValue[a];
+
312 }
+
313 
+
314 /* Xbox Controller commands */
+
315 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
+
316  //bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
+
317  pUsb->ctrlReq(bAddress, epInfo[XBOX_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
+
318 }
+
319 
+
320 void XBOXUSB::setLedRaw(uint8_t value) {
+
321  writeBuf[0] = 0x01;
+
322  writeBuf[1] = 0x03;
+
323  writeBuf[2] = value;
+
324 
+
325  XboxCommand(writeBuf, 3);
+
326 }
+
327 
+
328 void XBOXUSB::setLedOn(LEDEnum led) {
+
329  if(led == OFF)
+
330  setLedRaw(0);
+
331  else if(led != ALL) // All LEDs can't be on a the same time
+
332  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4);
333 }
334 
-
335 void XBOXUSB::setLedMode(LEDMode ledMode) { // This function is used to do some speciel LED stuff the controller supports
-
336  setLedRaw((uint8_t)ledMode);
+
335 void XBOXUSB::setLedBlink(LEDEnum led) {
+
336  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]));
337 }
338 
-
339 void XBOXUSB::setRumbleOn(uint8_t lValue, uint8_t rValue) {
-
340  writeBuf[0] = 0x00;
-
341  writeBuf[1] = 0x08;
-
342  writeBuf[2] = 0x00;
-
343  writeBuf[3] = lValue; // big weight
-
344  writeBuf[4] = rValue; // small weight
-
345  writeBuf[5] = 0x00;
-
346  writeBuf[6] = 0x00;
-
347  writeBuf[7] = 0x00;
-
348 
-
349  XboxCommand(writeBuf, 8);
-
350 }
-
351 
-
352 void XBOXUSB::onInit() {
-
353  if (pFuncOnInit)
-
354  pFuncOnInit(); // Call the user function
-
355  else
-
356  setLedOn(LED1);
-
357 }
+
339 void XBOXUSB::setLedMode(LEDModeEnum ledMode) { // This function is used to do some special LED stuff the controller supports
+
340  setLedRaw((uint8_t)ledMode);
+
341 }
+
342 
+
343 void XBOXUSB::setRumbleOn(uint8_t lValue, uint8_t rValue) {
+
344  writeBuf[0] = 0x00;
+
345  writeBuf[1] = 0x08;
+
346  writeBuf[2] = 0x00;
+
347  writeBuf[3] = lValue; // big weight
+
348  writeBuf[4] = rValue; // small weight
+
349  writeBuf[5] = 0x00;
+
350  writeBuf[6] = 0x00;
+
351  writeBuf[7] = 0x00;
+
352 
+
353  XboxCommand(writeBuf, 8);
+
354 }
+
355 
+
356 void XBOXUSB::onInit() {
+
357  if(pFuncOnInit)
+
358  pFuncOnInit(); // Call the user function
+
359  else
+
360  setLedOn(LED1);
+
361 }
XBOX_WIRED_PID
#define XBOX_WIRED_PID
Definition: XBOXUSB.h:41
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:41
AddressPool
Definition: address.h:83
XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
Definition: XBOXRECV.h:49
+
RightHatX
Definition: controllerEnums.h:122
+
LEDModeEnum
LEDModeEnum
Definition: xboxEnums.h:24
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
LED1
Definition: controllerEnums.h:28
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
XBOX_WIRELESS_RECEIVER_PID
#define XBOX_WIRELESS_RECEIVER_PID
Definition: XBOXRECV.h:48
+
XBOXUSB::setLedOn
void setLedOn(LEDEnum l)
Definition: XBOXUSB.cpp:328
+
LED1
Definition: controllerEnums.h:29
UsbDevice
Definition: address.h:75
-
XBOXUSB::setLedMode
void setLedMode(LEDMode lm)
Definition: XBOXUSB.cpp:335
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
-
LeftHatY
Definition: controllerEnums.h:113
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
XBOXUSB::pUsb
USB * pUsb
Definition: XBOXUSB.h:193
-
XBOX_REPORT_BUFFER_SIZE
#define XBOX_REPORT_BUFFER_SIZE
Definition: XBOXUSB.h:47
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
ALL
Definition: controllerEnums.h:40
-
RightHatX
Definition: controllerEnums.h:115
+
XBOX_REPORT_BUFFER_SIZE
#define XBOX_REPORT_BUFFER_SIZE
Definition: XBOXUSB.h:48
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
XBOXUSB::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXUSB.cpp:38
-
XBOXUSB::getButtonPress
uint8_t getButtonPress(Button b)
Definition: XBOXUSB.cpp:280
+
XBOXUSB::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a)
Definition: XBOXUSB.cpp:310
+
XBOXUSB::setLedBlink
void setLedBlink(LEDEnum l)
Definition: XBOXUSB.cpp:335
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
-
XBOXBUTTONS
const uint16_t XBOXBUTTONS[]
Definition: xboxEnums.h:40
-
XBOXLEDS
const uint8_t XBOXLEDS[]
Definition: xboxEnums.h:32
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
LED
LED
Definition: controllerEnums.h:27
-
XBOXUSB::getButtonClick
bool getButtonClick(Button b)
Definition: XBOXUSB.cpp:288
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
-
R2
Definition: controllerEnums.h:82
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
Notify
#define Notify(...)
Definition: message.h:44
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
NotifyFailUnknownDevice
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
XBOX_VID
#define XBOX_VID
Definition: XBOXOLD.h:36
-
XBOXUSB::getAnalogHat
int16_t getAnalogHat(AnalogHat a)
Definition: XBOXUSB.cpp:308
XBOX_INPUT_PIPE
#define XBOX_INPUT_PIPE
Definition: XBOXOLD.h:32
+
RightHatY
Definition: controllerEnums.h:124
XBOXUSB::bAddress
uint8_t bAddress
Definition: XBOXUSB.h:195
+
XBOXUSB::getButtonPress
uint8_t getButtonPress(ButtonEnum b)
Definition: XBOXUSB.cpp:282
EP_INTERRUPT
#define EP_INTERRUPT
Definition: PS3USB.h:28
EpInfo
Definition: address.h:32
XBOX_WIRELESS_PID
#define XBOX_WIRELESS_PID
Definition: XBOXUSB.h:42
-
LeftHatX
Definition: controllerEnums.h:111
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
XBOXUSB::Xbox360Connected
bool Xbox360Connected
Definition: XBOXUSB.h:185
XBOXUSB.h
-
L2
Definition: controllerEnums.h:81
+
L2
Definition: controllerEnums.h:82
HID_REQUEST_SET_REPORT
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXOLD.h:38
+
ALL
Definition: controllerEnums.h:41
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
-
LEDMode
LEDMode
Definition: xboxEnums.h:24
EpInfo::bmSndToggle
uint8_t bmSndToggle
Definition: address.h:40
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
XBOXUSB::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXUSB.cpp:339
+
XBOXUSB::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXUSB.cpp:343
XBOXUSB::XBOXUSB
XBOXUSB(USB *pUsb)
Definition: XBOXUSB.cpp:23
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXOLD.h:37
+
OFF
Definition: controllerEnums.h:28
XBOX_OUTPUT_PIPE
#define XBOX_OUTPUT_PIPE
Definition: XBOXOLD.h:33
USB_NAK_NOWAIT
#define USB_NAK_NOWAIT
Definition: address.h:29
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
GAMESTOP_VID
#define GAMESTOP_VID
Definition: XBOXUSB.h:39
-
XBOXUSB::setLedBlink
void setLedBlink(LED l)
Definition: XBOXUSB.cpp:331
+
XBOX_LEDS
const uint8_t XBOX_LEDS[]
Definition: xboxEnums.h:32
+
XBOXUSB::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: XBOXUSB.cpp:290
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:49
-
XBOXUSB::setLedOn
void setLedOn(LED l)
Definition: XBOXUSB.cpp:326
-
bmRCVTOG0
#define bmRCVTOG0
Definition: max3421e.h:185
bmREQ_HID_OUT
#define bmREQ_HID_OUT
Definition: BTD.h:38
-
XBOXUSB::setLedRaw
void setLedRaw(uint8_t value)
Definition: XBOXUSB.cpp:318
+
XBOXUSB::setLedRaw
void setLedRaw(uint8_t value)
Definition: XBOXUSB.cpp:320
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
-
Button
Button
Definition: controllerEnums.h:44
-
bmSNDTOG0
#define bmSNDTOG0
Definition: max3421e.h:187
+
XBOXUSB::setLedMode
void setLedMode(LEDModeEnum lm)
Definition: XBOXUSB.cpp:339
+
MADCATZ_WIRED_PID
#define MADCATZ_WIRED_PID
Definition: XBOXUSB.h:45
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB
Definition: UsbCore.h:152
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB
Definition: UsbCore.h:176
XBOX_CONTROL_PIPE
#define XBOX_CONTROL_PIPE
Definition: XBOXOLD.h:31
-
XBOXUSB::Release
virtual uint8_t Release()
Definition: XBOXUSB.cpp:221
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
LeftHatY
Definition: controllerEnums.h:120
+
LeftHatX
Definition: controllerEnums.h:118
+
R2
Definition: controllerEnums.h:83
+
XBOXUSB::Release
virtual uint8_t Release()
Definition: XBOXUSB.cpp:223
+
XBOX_BUTTONS
const uint16_t XBOX_BUTTONS[]
Definition: xboxEnums.h:41
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
RightHatY
Definition: controllerEnums.h:117
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
-
XBOXUSB::Poll
virtual uint8_t Poll()
Definition: XBOXUSB.cpp:229
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
+
XBOXUSB::Poll
virtual uint8_t Poll()
Definition: XBOXUSB.cpp:231
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
XBOXUSB::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXUSB.h:197
-
GAMESTOP_WIRED_PID
#define GAMESTOP_WIRED_PID
Definition: XBOXUSB.h:45
+
GAMESTOP_WIRED_PID
#define GAMESTOP_WIRED_PID
Definition: XBOXUSB.h:46
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/_x_b_o_x_u_s_b_8h.html b/_x_b_o_x_u_s_b_8h.html index 1cfaafea..3024c726 100644 --- a/_x_b_o_x_u_s_b_8h.html +++ b/_x_b_o_x_u_s_b_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXUSB.h File Reference @@ -31,7 +31,7 @@ - + @@ -144,6 +144,8 @@ Macros   #define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID   0x0291   +#define MADCATZ_WIRED_PID   0xF016 +  #define GAMESTOP_WIRED_PID   0x0401   #define XBOX_REPORT_BUFFER_SIZE   14 @@ -336,6 +338,20 @@ Macros

Definition at line 44 of file XBOXUSB.h.

+ + + +
+
+ + + + +
#define MADCATZ_WIRED_PID   0xF016
+
+ +

Definition at line 45 of file XBOXUSB.h.

+
@@ -348,7 +364,7 @@ Macros
-

Definition at line 45 of file XBOXUSB.h.

+

Definition at line 46 of file XBOXUSB.h.

@@ -362,7 +378,7 @@ Macros
-

Definition at line 47 of file XBOXUSB.h.

+

Definition at line 48 of file XBOXUSB.h.

@@ -376,7 +392,7 @@ Macros
-

Definition at line 50 of file XBOXUSB.h.

+

Definition at line 51 of file XBOXUSB.h.

@@ -390,7 +406,7 @@ Macros
-

Definition at line 51 of file XBOXUSB.h.

+

Definition at line 52 of file XBOXUSB.h.

@@ -404,7 +420,7 @@ Macros
-

Definition at line 53 of file XBOXUSB.h.

+

Definition at line 54 of file XBOXUSB.h.

@@ -413,7 +429,7 @@ Macros diff --git a/_x_b_o_x_u_s_b_8h_source.html b/_x_b_o_x_u_s_b_8h_source.html index f63fe8cb..1ba31dfa 100644 --- a/_x_b_o_x_u_s_b_8h_source.html +++ b/_x_b_o_x_u_s_b_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: XBOXUSB.h Source File @@ -31,7 +31,7 @@ - + @@ -133,38 +133,39 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
42 #define XBOX_WIRELESS_PID 0x028F // Wireless controller only support charging
43 #define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver
44 #define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver
-
45 #define GAMESTOP_WIRED_PID 0x0401 // Gamestop wired controller
-
46 
-
47 #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer
-
48 
-
49 // Used in control endpoint header for HID Commands
-
50 #define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
-
51 #define HID_REQUEST_SET_REPORT 0x09
-
52 
-
53 #define XBOX_MAX_ENDPOINTS 3
-
54 
-
56 class XBOXUSB : public USBDeviceConfig {
-
57 public:
-
62  XBOXUSB(USB *pUsb);
-
63 
-
72  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
-
77  virtual uint8_t Release();
-
82  virtual uint8_t Poll();
-
83 
-
88  virtual uint8_t GetAddress() {
-
89  return bAddress;
-
90  };
-
91 
-
96  virtual bool isReady() {
-
97  return bPollEnable;
-
98  };
-
99 
-
106  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
-
107  return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == GAMESTOP_VID) && (pid == XBOX_WIRED_PID || pid == GAMESTOP_WIRED_PID));
-
108  };
-
123  uint8_t getButtonPress(Button b);
-
124  bool getButtonClick(Button b);
-
133  int16_t getAnalogHat(AnalogHat a);
+
45 #define MADCATZ_WIRED_PID 0xF016 // Mad Catz wired controller
+
46 #define GAMESTOP_WIRED_PID 0x0401 // Gamestop wired controller
+
47 
+
48 #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer
+
49 
+
50 // Used in control endpoint header for HID Commands
+
51 #define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
+
52 #define HID_REQUEST_SET_REPORT 0x09
+
53 
+
54 #define XBOX_MAX_ENDPOINTS 3
+
55 
+
57 class XBOXUSB : public USBDeviceConfig {
+
58 public:
+
63  XBOXUSB(USB *pUsb);
+
64 
+
73  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
+
78  virtual uint8_t Release();
+
83  virtual uint8_t Poll();
+
84 
+
89  virtual uint8_t GetAddress() {
+
90  return bAddress;
+
91  };
+
92 
+
97  virtual bool isReady() {
+
98  return bPollEnable;
+
99  };
+
100 
+
107  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
+
108  return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == GAMESTOP_VID) && (pid == XBOX_WIRED_PID || pid == MADCATZ_WIRED_PID || pid == GAMESTOP_WIRED_PID));
+
109  };
+
123  uint8_t getButtonPress(ButtonEnum b);
+
124  bool getButtonClick(ButtonEnum b);
+
133  int16_t getAnalogHat(AnalogHatEnum a);
134 
136  void setAllOff() {
137  setRumbleOn(0, 0);
@@ -180,9 +181,9 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
160  void setLedOff() {
161  setLedRaw(0);
162  };
-
167  void setLedOn(LED l);
-
172  void setLedBlink(LED l);
-
177  void setLedMode(LEDMode lm);
+
167  void setLedOn(LEDEnum l);
+
172  void setLedBlink(LEDEnum l);
+
177  void setLedMode(LEDModeEnum lm);
178 
183  void attachOnInit(void (*funcOnInit)(void)) {
184  pFuncOnInit = funcOnInit;
@@ -221,52 +222,53 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
228 };
229 #endif
XBOX_WIRED_PID
#define XBOX_WIRED_PID
Definition: XBOXUSB.h:41
+
LEDModeEnum
LEDModeEnum
Definition: xboxEnums.h:24
+
XBOXUSB::setLedOn
void setLedOn(LEDEnum l)
Definition: XBOXUSB.cpp:328
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXUSB.h:37
-
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXUSB.h:53
+
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXUSB.h:54
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXUSB.h:38
xboxEnums.h
-
XBOXUSB::setLedMode
void setLedMode(LEDMode lm)
Definition: XBOXUSB.cpp:335
+
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:116
XBOXUSB::pUsb
USB * pUsb
Definition: XBOXUSB.h:193
XBOXUSB::setLedOff
void setLedOff()
Definition: XBOXUSB.h:160
XBOXUSB::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXUSB.cpp:38
-
XBOXUSB::getButtonPress
uint8_t getButtonPress(Button b)
Definition: XBOXUSB.cpp:280
USBDeviceConfig
Definition: UsbCore.h:105
+
XBOXUSB::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a)
Definition: XBOXUSB.cpp:310
Usb.h
-
XBOXUSB::isReady
virtual bool isReady()
Definition: XBOXUSB.h:96
-
LED
LED
Definition: controllerEnums.h:27
-
XBOXUSB::getButtonClick
bool getButtonClick(Button b)
Definition: XBOXUSB.cpp:288
+
XBOXUSB::setLedBlink
void setLedBlink(LEDEnum l)
Definition: XBOXUSB.cpp:335
+
XBOXUSB::isReady
virtual bool isReady()
Definition: XBOXUSB.h:97
+
LEDEnum
LEDEnum
Definition: controllerEnums.h:27
XBOXUSB::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXUSB.h:183
-
XBOXUSB::getAnalogHat
int16_t getAnalogHat(AnalogHat a)
Definition: XBOXUSB.cpp:308
XBOXUSB::bAddress
uint8_t bAddress
Definition: XBOXUSB.h:195
+
XBOXUSB::getButtonPress
uint8_t getButtonPress(ButtonEnum b)
Definition: XBOXUSB.cpp:282
EpInfo
Definition: address.h:32
+
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:45
XBOXUSB::Xbox360Connected
bool Xbox360Connected
Definition: XBOXUSB.h:185
-
LEDMode
LEDMode
Definition: xboxEnums.h:24
XBOX_VID
#define XBOX_VID
Definition: XBOXUSB.h:36
-
XBOXUSB::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXUSB.cpp:339
+
XBOXUSB::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXUSB.cpp:343
XBOXUSB::XBOXUSB
XBOXUSB(USB *pUsb)
Definition: XBOXUSB.cpp:23
-
XBOXUSB::GetAddress
virtual uint8_t GetAddress()
Definition: XBOXUSB.h:88
+
XBOXUSB::GetAddress
virtual uint8_t GetAddress()
Definition: XBOXUSB.h:89
GAMESTOP_VID
#define GAMESTOP_VID
Definition: XBOXUSB.h:39
-
XBOXUSB::setLedBlink
void setLedBlink(LED l)
Definition: XBOXUSB.cpp:331
+
XBOXUSB::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: XBOXUSB.cpp:290
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: XBOXUSB.h:25
-
XBOXUSB::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXUSB.h:106
+
XBOXUSB::VIDPIDOK
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXUSB.h:107
XBOXUSB::setRumbleOff
void setRumbleOff()
Definition: XBOXUSB.h:142
-
XBOXUSB::setLedOn
void setLedOn(LED l)
Definition: XBOXUSB.cpp:326
-
XBOXUSB::setLedRaw
void setLedRaw(uint8_t value)
Definition: XBOXUSB.cpp:318
-
Button
Button
Definition: controllerEnums.h:44
-
XBOXUSB
Definition: XBOXUSB.h:56
-
USB
Definition: UsbCore.h:152
+
XBOXUSB::setLedRaw
void setLedRaw(uint8_t value)
Definition: XBOXUSB.cpp:320
+
XBOXUSB::setLedMode
void setLedMode(LEDModeEnum lm)
Definition: XBOXUSB.cpp:339
+
MADCATZ_WIRED_PID
#define MADCATZ_WIRED_PID
Definition: XBOXUSB.h:45
+
XBOXUSB
Definition: XBOXUSB.h:57
+
USB
Definition: UsbCore.h:176
XBOXUSB::setAllOff
void setAllOff()
Definition: XBOXUSB.h:136
-
XBOXUSB::Release
virtual uint8_t Release()
Definition: XBOXUSB.cpp:221
-
AnalogHat
AnalogHat
Definition: controllerEnums.h:109
-
XBOXUSB::Poll
virtual uint8_t Poll()
Definition: XBOXUSB.cpp:229
+
XBOXUSB::Release
virtual uint8_t Release()
Definition: XBOXUSB.cpp:223
+
XBOXUSB::Poll
virtual uint8_t Poll()
Definition: XBOXUSB.cpp:231
XBOXUSB::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXUSB.h:197
-
GAMESTOP_WIRED_PID
#define GAMESTOP_WIRED_PID
Definition: XBOXUSB.h:45
+
GAMESTOP_WIRED_PID
#define GAMESTOP_WIRED_PID
Definition: XBOXUSB.h:46
diff --git a/address_8h.html b/address_8h.html index 90b4f233..e138f297 100644 --- a/address_8h.html +++ b/address_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: address.h File Reference @@ -31,7 +31,7 @@ - + @@ -282,7 +282,7 @@ Typedefs diff --git a/address_8h_source.html b/address_8h_source.html index 31db7a11..491dbd3a 100644 --- a/address_8h_source.html +++ b/address_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: address.h Source File @@ -31,7 +31,7 @@ - + @@ -153,7 +153,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
62  uint8_t bmAddress : 3; // device address/port number
63  uint8_t bmParent : 3; // parent hub address
64  uint8_t bmHub : 1; // hub flag
-
65  uint8_t bmReserved : 1; // reserved, must be zerro
+
65  uint8_t bmReserved : 1; // reserved, must be zero
66  } __attribute__((packed));
67  uint8_t devAddress;
68  };
@@ -165,7 +165,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
74 
75 struct UsbDevice {
76  EpInfo *epinfo; // endpoint info pointer
-
77  uint8_t address; // address
+
77  UsbDeviceAddress address;
78  uint8_t epcount; // number of endpoints
79  bool lowspeed; // indicates if a device is the low speed one
80  // uint8_t devclass; // device class
@@ -195,187 +195,196 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
104  // Initializes address pool entry
105 
106  void InitEntry(uint8_t index) {
-
107  thePool[index].address = 0;
+
107  thePool[index].address.devAddress = 0;
108  thePool[index].epcount = 1;
109  thePool[index].lowspeed = 0;
110  thePool[index].epinfo = &dev0ep;
111  };
-
112  // Returns thePool index for a given address
-
113 
-
114  uint8_t FindAddressIndex(uint8_t address = 0) {
-
115  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
-
116  if(thePool[i].address == address)
-
117  return i;
-
118  }
-
119  return 0;
-
120  };
-
121  // Returns thePool child index for a given parent
+
112 
+
113  // Returns thePool index for a given address
+
114 
+
115  uint8_t FindAddressIndex(uint8_t address = 0) {
+
116  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
+
117  if(thePool[i].address.devAddress == address)
+
118  return i;
+
119  }
+
120  return 0;
+
121  };
122 
-
123  uint8_t FindChildIndex(UsbDeviceAddress addr, uint8_t start = 1) {
-
124  for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
-
125  if(((UsbDeviceAddress*) & thePool[i].address)->bmParent == addr.bmAddress)
-
126  return i;
-
127  }
-
128  return 0;
-
129  };
-
130  // Frees address entry specified by index parameter
-
131 
-
132  void FreeAddressByIndex(uint8_t index) {
-
133  // Zerro field is reserved and should not be affected
-
134  if(index == 0)
-
135  return;
-
136 
-
137  // If a hub was switched off all port addresses should be freed
-
138  if(((UsbDeviceAddress*) & thePool[index].address)->bmHub == 1) {
-
139  for(uint8_t i = 1; (i = FindChildIndex(*((UsbDeviceAddress*) & thePool[index].address), i));)
-
140  FreeAddressByIndex(i);
-
141 
-
142  // If the hub had the last allocated address, hubCounter should be decremented
-
143  if(hubCounter == ((UsbDeviceAddress*) & thePool[index].address)->bmAddress)
-
144  hubCounter--;
-
145  }
-
146  InitEntry(index);
-
147  }
-
148  // Initializes the whole address pool at once
-
149 
-
150  void InitAllAddresses() {
-
151  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
-
152  InitEntry(i);
-
153 
-
154  hubCounter = 0;
-
155  };
-
156 
-
157 public:
+
123  // Returns thePool child index for a given parent
+
124 
+
125  uint8_t FindChildIndex(UsbDeviceAddress addr, uint8_t start = 1) {
+
126  for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
+
127  if(thePool[i].address.bmParent == addr.bmAddress)
+
128  return i;
+
129  }
+
130  return 0;
+
131  };
+
132 
+
133  // Frees address entry specified by index parameter
+
134 
+
135  void FreeAddressByIndex(uint8_t index) {
+
136  // Zero field is reserved and should not be affected
+
137  if(index == 0)
+
138  return;
+
139 
+
140  UsbDeviceAddress uda = thePool[index].address;
+
141  // If a hub was switched off all port addresses should be freed
+
142  if(uda.bmHub == 1) {
+
143  for(uint8_t i = 1; (i = FindChildIndex(uda, i));)
+
144  FreeAddressByIndex(i);
+
145 
+
146  // If the hub had the last allocated address, hubCounter should be decremented
+
147  if(hubCounter == uda.bmAddress)
+
148  hubCounter--;
+
149  }
+
150  InitEntry(index);
+
151  }
+
152 
+
153  // Initializes the whole address pool at once
+
154 
+
155  void InitAllAddresses() {
+
156  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
+
157  InitEntry(i);
158 
-
159  AddressPoolImpl() : hubCounter(0) {
-
160  // Zero address is reserved
-
161  InitEntry(0);
-
162 
-
163  thePool[0].address = 0;
-
164  thePool[0].epinfo = &dev0ep;
-
165  dev0ep.epAddr = 0;
-
166  dev0ep.maxPktSize = 8;
-
167  dev0ep.epAttribs = 0; //set DATA0/1 toggles to 0
-
168  dev0ep.bmNakPower = USB_NAK_MAX_POWER;
-
169 
-
170  InitAllAddresses();
-
171  };
-
172  // Returns a pointer to a specified address entry
-
173 
-
174  virtual UsbDevice* GetUsbDevicePtr(uint8_t addr) {
-
175  if(!addr)
-
176  return thePool;
+
159  hubCounter = 0;
+
160  };
+
161 
+
162 public:
+
163 
+
164  AddressPoolImpl() : hubCounter(0) {
+
165  // Zero address is reserved
+
166  InitEntry(0);
+
167 
+
168  thePool[0].address.devAddress = 0;
+
169  thePool[0].epinfo = &dev0ep;
+
170  dev0ep.epAddr = 0;
+
171  dev0ep.maxPktSize = 8;
+
172  dev0ep.epAttribs = 0; //set DATA0/1 toggles to 0
+
173  dev0ep.bmNakPower = USB_NAK_MAX_POWER;
+
174 
+
175  InitAllAddresses();
+
176  };
177 
-
178  uint8_t index = FindAddressIndex(addr);
+
178  // Returns a pointer to a specified address entry
179 
-
180  return(!index) ? NULL : thePool + index;
-
181  };
-
182 
-
183  // Performs an operation specified by pfunc for each addressed device
-
184 
-
185  void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
-
186  if(!pfunc)
-
187  return;
+
180  virtual UsbDevice* GetUsbDevicePtr(uint8_t addr) {
+
181  if(!addr)
+
182  return thePool;
+
183 
+
184  uint8_t index = FindAddressIndex(addr);
+
185 
+
186  return (!index) ? NULL : thePool + index;
+
187  };
188 
-
189  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
-
190  if(thePool[i].address)
-
191  pfunc(thePool + i);
-
192  };
-
193  // Allocates new address
+
189  // Performs an operation specified by pfunc for each addressed device
+
190 
+
191  void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
+
192  if(!pfunc)
+
193  return;
194 
-
195  virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) {
-
196  /* if (parent != 0 && port == 0)
-
197  USB_HOST_SERIAL.println("PRT:0"); */
-
198 
-
199  if(parent > 127 || port > 7)
-
200  return 0;
+
195  for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
+
196  if(thePool[i].address.devAddress)
+
197  pfunc(thePool + i);
+
198  };
+
199 
+
200  // Allocates new address
201 
-
202  if(is_hub && hubCounter == 7)
-
203  return 0;
-
204 
-
205  // finds first empty address entry starting from one
-
206  uint8_t index = FindAddressIndex(0);
-
207 
-
208  if(!index) // if empty entry is not found
+
202  virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) {
+
203  /* if (parent != 0 && port == 0)
+
204  USB_HOST_SERIAL.println("PRT:0"); */
+
205  UsbDeviceAddress _parent;
+
206  _parent.devAddress = parent;
+
207  if(_parent.bmReserved || port > 7)
+
208  //if(parent > 127 || port > 7)
209  return 0;
210 
-
211  if(parent == 0) {
-
212  if(is_hub) {
-
213  thePool[index].address = 0x41;
-
214  hubCounter++;
-
215  } else
-
216  thePool[index].address = 1;
-
217 
-
218  return thePool[index].address;
-
219  }
-
220 
-
221  UsbDeviceAddress addr;
-
222  addr.devAddress = 0; // Ensure all bits are zero
-
223 
-
224  addr.bmParent = ((UsbDeviceAddress*) & parent)->bmAddress;
-
225 
-
226  if(is_hub) {
-
227  addr.bmHub = 1;
-
228  addr.bmAddress = ++hubCounter;
-
229  } else {
-
230  addr.bmHub = 0;
-
231  addr.bmAddress = port;
-
232  }
-
233  thePool[index].address = *((uint8_t*) & addr);
-
234  /*
-
235  USB_HOST_SERIAL.print("Addr:");
-
236  USB_HOST_SERIAL.print(addr.bmHub, HEX);
-
237  USB_HOST_SERIAL.print(".");
-
238  USB_HOST_SERIAL.print(addr.bmParent, HEX);
-
239  USB_HOST_SERIAL.print(".");
-
240  USB_HOST_SERIAL.println(addr.bmAddress, HEX);
-
241  */
-
242  return thePool[index].address;
-
243  };
-
244  // Empties pool entry
-
245 
-
246  virtual void FreeAddress(uint8_t addr) {
-
247  // if the root hub is disconnected all the addresses should be initialized
-
248  if(addr == 0x41) {
-
249  InitAllAddresses();
-
250  return;
-
251  }
-
252  uint8_t index = FindAddressIndex(addr);
-
253  FreeAddressByIndex(index);
-
254  };
-
255  // Returns number of hubs attached
-
256  // It can be rather helpfull to find out if there are hubs attached than getting the exact number of hubs.
-
257  //uint8_t GetNumHubs()
-
258  //{
-
259  // return hubCounter;
-
260  //};
-
261  //uint8_t GetNumDevices()
-
262  //{
-
263  // uint8_t counter = 0;
-
264 
-
265  // for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
-
266  // if (thePool[i].address != 0);
-
267  // counter ++;
-
268 
-
269  // return counter;
-
270  //};
-
271 };
-
272 
-
273 #endif // __ADDRESS_H__
+
211  if(is_hub && hubCounter == 7)
+
212  return 0;
+
213 
+
214  // finds first empty address entry starting from one
+
215  uint8_t index = FindAddressIndex(0);
+
216 
+
217  if(!index) // if empty entry is not found
+
218  return 0;
+
219 
+
220  if(_parent.devAddress == 0) {
+
221  if(is_hub) {
+
222  thePool[index].address.devAddress = 0x41;
+
223  hubCounter++;
+
224  } else
+
225  thePool[index].address.devAddress = 1;
+
226 
+
227  return thePool[index].address.devAddress;
+
228  }
+
229 
+
230  UsbDeviceAddress addr;
+
231  addr.devAddress = 0; // Ensure all bits are zero
+
232  addr.bmParent = _parent.bmAddress;
+
233  if(is_hub) {
+
234  addr.bmHub = 1;
+
235  addr.bmAddress = ++hubCounter;
+
236  } else {
+
237  addr.bmHub = 0;
+
238  addr.bmAddress = port;
+
239  }
+
240  thePool[index].address = addr;
+
241  /*
+
242  USB_HOST_SERIAL.print("Addr:");
+
243  USB_HOST_SERIAL.print(addr.bmHub, HEX);
+
244  USB_HOST_SERIAL.print(".");
+
245  USB_HOST_SERIAL.print(addr.bmParent, HEX);
+
246  USB_HOST_SERIAL.print(".");
+
247  USB_HOST_SERIAL.println(addr.bmAddress, HEX);
+
248  */
+
249  return thePool[index].address.devAddress;
+
250  };
+
251 
+
252  // Empties pool entry
+
253 
+
254  virtual void FreeAddress(uint8_t addr) {
+
255  // if the root hub is disconnected all the addresses should be initialized
+
256  if(addr == 0x41) {
+
257  InitAllAddresses();
+
258  return;
+
259  }
+
260  uint8_t index = FindAddressIndex(addr);
+
261  FreeAddressByIndex(index);
+
262  };
+
263 
+
264  // Returns number of hubs attached
+
265  // It can be rather helpfull to find out if there are hubs attached than getting the exact number of hubs.
+
266  //uint8_t GetNumHubs()
+
267  //{
+
268  // return hubCounter;
+
269  //};
+
270  //uint8_t GetNumDevices()
+
271  //{
+
272  // uint8_t counter = 0;
+
273 
+
274  // for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
+
275  // if (thePool[i].address != 0);
+
276  // counter ++;
+
277 
+
278  // return counter;
+
279  //};
+
280 };
+
281 
+
282 #endif // __ADDRESS_H__
EpInfo::bmRcvToggle
uint8_t bmRcvToggle
Definition: address.h:41
AddressPool
Definition: address.h:83
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
UsbDevice
Definition: address.h:75
-
AddressPoolImpl::AddressPoolImpl
AddressPoolImpl()
Definition: address.h:159
+
AddressPoolImpl::AddressPoolImpl
AddressPoolImpl()
Definition: address.h:164
UsbDeviceAddress::bmReserved
uint8_t bmReserved
Definition: address.h:65
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
AddressPoolImpl::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)
Definition: address.h:174
+
AddressPoolImpl::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)
Definition: address.h:180
UsbDeviceHandleFunc
void(* UsbDeviceHandleFunc)(UsbDevice *pdev)
Definition: address.h:90
EpInfo
Definition: address.h:32
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
@@ -385,19 +394,19 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
UsbDeviceAddress::bmParent
uint8_t bmParent
Definition: address.h:63
AddressPoolImpl
Definition: address.h:96
UsbDevice::epcount
uint8_t epcount
Definition: address.h:78
-
AddressPoolImpl::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: address.h:185
+
AddressPoolImpl::ForEachUsbDevice
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
Definition: address.h:191
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
UsbDevice::address
uint8_t address
Definition: address.h:77
-
AddressPoolImpl::FreeAddress
virtual void FreeAddress(uint8_t addr)
Definition: address.h:246
+
AddressPoolImpl::FreeAddress
virtual void FreeAddress(uint8_t addr)
Definition: address.h:254
UsbDeviceAddress
Definition: address.h:57
-
AddressPoolImpl::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
Definition: address.h:195
+
AddressPoolImpl::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
Definition: address.h:202
+
UsbDevice::address
UsbDeviceAddress address
Definition: address.h:77
UsbDeviceAddress::bmHub
uint8_t bmHub
Definition: address.h:64
diff --git a/adk_8cpp.html b/adk_8cpp.html index 5a467497..27b043b7 100644 --- a/adk_8cpp.html +++ b/adk_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: adk.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for adk.cpp: diff --git a/adk_8cpp_source.html b/adk_8cpp_source.html index ba2db15a..cd9c6cf8 100644 --- a/adk_8cpp_source.html +++ b/adk_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: adk.cpp Source File @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
-
16 */
+
16  */
17 
18 /* Google ADK interface */
19 
@@ -133,7 +133,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
42 bNumEP(1), //if config descriptor needs to be parsed
43 ready(false) {
44  // initialize endpoint data structures
-
45  for (uint8_t i = 0; i < ADK_MAX_ENDPOINTS; i++) {
+
45  for(uint8_t i = 0; i < ADK_MAX_ENDPOINTS; i++) {
46  epInfo[i].epAddr = 0;
47  epInfo[i].maxPktSize = (i) ? 0 : 8;
48  epInfo[i].epAttribs = 0;
@@ -141,7 +141,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
50  }//for(uint8_t i=0; i<ADK_MAX_ENDPOINTS; i++...
51 
52  // register in USB subsystem
-
53  if (pUsb) {
+
53  if(pUsb) {
54  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
55  }
56 }
@@ -153,324 +153,335 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
62 /* Connection initialization of an Android phone */
63 uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) {
64  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
-
65  uint8_t rcode;
-
66  uint8_t num_of_conf; // number of configurations
-
67  UsbDevice *p = NULL;
-
68  EpInfo *oldep_ptr = NULL;
-
69 
-
70  // get memory address of USB device address pool
-
71  AddressPool &addrPool = pUsb->GetAddressPool();
-
72 
-
73  USBTRACE("\r\nADK Init");
-
74 
-
75  // check if address has already been assigned to an instance
-
76  if (bAddress) {
-
77  USBTRACE("\r\nAddress in use");
-
78  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
79  }
-
80 
-
81  // Get pointer to pseudo device with address 0 assigned
-
82  p = addrPool.GetUsbDevicePtr(0);
-
83 
-
84  if (!p) {
-
85  USBTRACE("\r\nAddress not found");
-
86  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
87  }
-
88 
-
89  if (!p->epinfo) {
-
90  USBTRACE("epinfo is null\r\n");
-
91  return USB_ERROR_EPINFO_IS_NULL;
-
92  }
-
93 
-
94  // Save old pointer to EP_RECORD of address 0
-
95  oldep_ptr = p->epinfo;
-
96 
-
97  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
98  p->epinfo = epInfo;
-
99 
-
100  p->lowspeed = lowspeed;
-
101 
-
102  // Get device descriptor
-
103  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
-
104 
-
105  // Restore p->epinfo
-
106  p->epinfo = oldep_ptr;
-
107 
-
108  if (rcode) {
-
109  goto FailGetDevDescr;
-
110  }
-
111 
-
112  // Allocate new address according to device class
-
113  bAddress = addrPool.AllocAddress(parent, false, port);
-
114 
-
115  // Extract Max Packet Size from device descriptor
-
116  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
117 
-
118  // Assign new address to the device
-
119  rcode = pUsb->setAddr(0, 0, bAddress);
-
120  if (rcode) {
-
121  p->lowspeed = false;
-
122  addrPool.FreeAddress(bAddress);
-
123  bAddress = 0;
-
124  //USBTRACE2("setAddr:",rcode);
-
125  return rcode;
-
126  }//if (rcode...
-
127 
-
128  //USBTRACE2("\r\nAddr:", bAddress);
-
129  // Spec says you should wait at least 200ms.
-
130  delay(300);
-
131 
-
132  p->lowspeed = false;
-
133 
-
134  //get pointer to assigned address record
-
135  p = addrPool.GetUsbDevicePtr(bAddress);
-
136  if (!p) {
-
137  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
138  }
-
139 
-
140  p->lowspeed = lowspeed;
-
141 
-
142  // Assign epInfo to epinfo pointer - only EP0 is known
-
143  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
144  if (rcode) {
-
145  goto FailSetDevTblEntry;
-
146  }
-
147 
-
148  //check if ADK device is already in accessory mode; if yes, configure and exit
-
149  if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor == ADK_VID &&
-
150  (((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADK_PID || ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADB_PID)) {
-
151  USBTRACE("\r\nAcc.mode device detected");
-
152  /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */
-
153  num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;
-
154 
-
155  //USBTRACE2("\r\nNC:",num_of_conf);
-
156  for (uint8_t i = 0; i < num_of_conf; i++) {
-
157  ConfigDescParser < 0, 0, 0, 0 > confDescrParser(this);
-
158  delay(1);
-
159  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
160 #if defined(XOOM)
-
161  //added by Jaylen Scott Vanorden
-
162  if (rcode) {
-
163  USBTRACE2("\r\nGot 1st bad code for config: ", rcode);
-
164  // Try once more
-
165  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
166  }
-
167 #endif
-
168  if (rcode) {
-
169  goto FailGetConfDescr;
-
170  }
-
171  if (bNumEP > 2) {
-
172  break;
-
173  }
-
174  } // for (uint8_t i=0; i<num_of_conf; i++...
-
175 
-
176  if (bNumEP == 3) {
-
177  // Assign epInfo to epinfo pointer - this time all 3 endpoins
-
178  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
-
179  if (rcode) {
-
180  goto FailSetDevTblEntry;
-
181  }
-
182  }
-
183 
-
184  // Set Configuration Value
-
185  rcode = pUsb->setConf(bAddress, 0, bConfNum);
-
186  if (rcode) {
-
187  goto FailSetConfDescr;
-
188  }
-
189  /* print endpoint structure */
-
190  /*
-
191  USBTRACE("\r\nEndpoint Structure:");
-
192  USBTRACE("\r\nEP0:");
-
193  USBTRACE2("\r\nAddr: ", epInfo[0].epAddr);
-
194  USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize);
-
195  USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs);
-
196  USBTRACE("\r\nEpout:");
-
197  USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr);
-
198  USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize);
-
199  USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs);
-
200  USBTRACE("\r\nEpin:");
-
201  USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr);
-
202  USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize);
-
203  USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs);
-
204  */
-
205 
-
206  USBTRACE("\r\nConfiguration successful");
-
207  ready = true;
-
208  return 0; //successful configuration
-
209  }//if( buf->idVendor == ADK_VID...
-
210 
-
211  //probe device - get accessory protocol revision
-
212  {
-
213  uint16_t adkproto = -1;
-
214  delay(1);
-
215  rcode = getProto((uint8_t*) & adkproto);
-
216 #if defined(XOOM)
-
217  //added by Jaylen Scott Vanorden
-
218  if (rcode) {
-
219  USBTRACE2("\r\nGot 1st bad code for proto: ", rcode);
-
220  // Try once more
-
221  rcode = getProto((uint8_t*) & adkproto);
-
222  }
-
223 #endif
-
224  if (rcode) {
-
225  goto FailGetProto; //init fails
-
226  }
-
227  USBTRACE2("\r\nADK protocol rev. ", adkproto);
-
228  }
-
229 
-
230  //sending ID strings
-
231  sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer);
-
232  sendStr(ACCESSORY_STRING_MODEL, model);
-
233  sendStr(ACCESSORY_STRING_DESCRIPTION, description);
-
234  sendStr(ACCESSORY_STRING_VERSION, version);
-
235  sendStr(ACCESSORY_STRING_URI, uri);
-
236  sendStr(ACCESSORY_STRING_SERIAL, serial);
-
237 
-
238  //switch to accessory mode
-
239  //the Android phone will reset
-
240  rcode = switchAcc();
-
241  if (rcode) {
-
242  goto FailSwAcc; //init fails
-
243  }
-
244  rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
-
245  delay(1000); // Give Android a chance to do its reset. This is a guess, and possibly could be lower.
-
246  goto SwAttempt; //switch to accessory mode attempted
+
65  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
66  uint8_t rcode;
+
67  uint8_t num_of_conf; // number of configurations
+
68  UsbDevice *p = NULL;
+
69  EpInfo *oldep_ptr = NULL;
+
70 
+
71  // get memory address of USB device address pool
+
72  AddressPool &addrPool = pUsb->GetAddressPool();
+
73 
+
74  USBTRACE("\r\nADK Init");
+
75 
+
76  // check if address has already been assigned to an instance
+
77  if(bAddress) {
+
78  USBTRACE("\r\nAddress in use");
+
79  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
80  }
+
81 
+
82  // Get pointer to pseudo device with address 0 assigned
+
83  p = addrPool.GetUsbDevicePtr(0);
+
84 
+
85  if(!p) {
+
86  USBTRACE("\r\nAddress not found");
+
87  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
88  }
+
89 
+
90  if(!p->epinfo) {
+
91  USBTRACE("epinfo is null\r\n");
+
92  return USB_ERROR_EPINFO_IS_NULL;
+
93  }
+
94 
+
95  // Save old pointer to EP_RECORD of address 0
+
96  oldep_ptr = p->epinfo;
+
97 
+
98  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
99  p->epinfo = epInfo;
+
100 
+
101  p->lowspeed = lowspeed;
+
102 
+
103  // Get device descriptor
+
104  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
+
105 
+
106  // Restore p->epinfo
+
107  p->epinfo = oldep_ptr;
+
108 
+
109  if(rcode) {
+
110  goto FailGetDevDescr;
+
111  }
+
112 
+
113  // Allocate new address according to device class
+
114  bAddress = addrPool.AllocAddress(parent, false, port);
+
115 
+
116  // Extract Max Packet Size from device descriptor
+
117  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
118 
+
119  // Assign new address to the device
+
120  rcode = pUsb->setAddr(0, 0, bAddress);
+
121  if(rcode) {
+
122  p->lowspeed = false;
+
123  addrPool.FreeAddress(bAddress);
+
124  bAddress = 0;
+
125  //USBTRACE2("setAddr:",rcode);
+
126  return rcode;
+
127  }//if (rcode...
+
128 
+
129  //USBTRACE2("\r\nAddr:", bAddress);
+
130  // Spec says you should wait at least 200ms.
+
131  //delay(300);
+
132 
+
133  p->lowspeed = false;
+
134 
+
135  //get pointer to assigned address record
+
136  p = addrPool.GetUsbDevicePtr(bAddress);
+
137  if(!p) {
+
138  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
139  }
+
140 
+
141  p->lowspeed = lowspeed;
+
142 
+
143  // Assign epInfo to epinfo pointer - only EP0 is known
+
144  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
145  if(rcode) {
+
146  goto FailSetDevTblEntry;
+
147  }
+
148 
+
149  //check if ADK device is already in accessory mode; if yes, configure and exit
+
150  if(udd->idVendor == ADK_VID &&
+
151  (udd->idProduct == ADK_PID || udd->idProduct == ADB_PID)) {
+
152  USBTRACE("\r\nAcc.mode device detected");
+
153  /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */
+
154  num_of_conf = udd->bNumConfigurations;
+
155 
+
156  //USBTRACE2("\r\nNC:",num_of_conf);
+
157  for(uint8_t i = 0; i < num_of_conf; i++) {
+
158  ConfigDescParser < 0, 0, 0, 0 > confDescrParser(this);
+
159  delay(1);
+
160  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
161 #if defined(XOOM)
+
162  //added by Jaylen Scott Vanorden
+
163  if(rcode) {
+
164  USBTRACE2("\r\nGot 1st bad code for config: ", rcode);
+
165  // Try once more
+
166  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
167  }
+
168 #endif
+
169  if(rcode) {
+
170  goto FailGetConfDescr;
+
171  }
+
172  if(bNumEP > 2) {
+
173  break;
+
174  }
+
175  } // for (uint8_t i=0; i<num_of_conf; i++...
+
176 
+
177  if(bNumEP == 3) {
+
178  // Assign epInfo to epinfo pointer - this time all 3 endpoins
+
179  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
+
180  if(rcode) {
+
181  goto FailSetDevTblEntry;
+
182  }
+
183  }
+
184 
+
185  // Set Configuration Value
+
186  rcode = pUsb->setConf(bAddress, 0, bConfNum);
+
187  if(rcode) {
+
188  goto FailSetConfDescr;
+
189  }
+
190  /* print endpoint structure */
+
191  /*
+
192  USBTRACE("\r\nEndpoint Structure:");
+
193  USBTRACE("\r\nEP0:");
+
194  USBTRACE2("\r\nAddr: ", epInfo[0].epAddr);
+
195  USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize);
+
196  USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs);
+
197  USBTRACE("\r\nEpout:");
+
198  USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr);
+
199  USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize);
+
200  USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs);
+
201  USBTRACE("\r\nEpin:");
+
202  USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr);
+
203  USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize);
+
204  USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs);
+
205  */
+
206 
+
207  USBTRACE("\r\nConfiguration successful");
+
208  ready = true;
+
209  return 0; //successful configuration
+
210  }//if( buf->idVendor == ADK_VID...
+
211 
+
212  //probe device - get accessory protocol revision
+
213  {
+
214  uint16_t adkproto = -1;
+
215  delay(1);
+
216  rcode = getProto((uint8_t*) & adkproto);
+
217 #if defined(XOOM)
+
218  //added by Jaylen Scott Vanorden
+
219  if(rcode) {
+
220  USBTRACE2("\r\nGot 1st bad code for proto: ", rcode);
+
221  // Try once more
+
222  rcode = getProto((uint8_t*) & adkproto);
+
223  }
+
224 #endif
+
225  if(rcode) {
+
226  goto FailGetProto; //init fails
+
227  }
+
228  USBTRACE2("\r\nADK protocol rev. ", adkproto);
+
229  }
+
230 
+
231  delay(100);
+
232 
+
233  //sending ID strings
+
234  sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer);
+
235  delay(10);
+
236  sendStr(ACCESSORY_STRING_MODEL, model);
+
237  delay(10);
+
238  sendStr(ACCESSORY_STRING_DESCRIPTION, description);
+
239  delay(10);
+
240  sendStr(ACCESSORY_STRING_VERSION, version);
+
241  delay(10);
+
242  sendStr(ACCESSORY_STRING_URI, uri);
+
243  delay(10);
+
244  sendStr(ACCESSORY_STRING_SERIAL, serial);
+
245 
+
246  delay(100);
247 
-
248  /* diagnostic messages */
-
249 FailGetDevDescr:
-
250 #ifdef DEBUG_USB_HOST
-
251  NotifyFailGetDevDescr(rcode);
-
252  goto Fail;
-
253 #endif
-
254 
-
255 FailSetDevTblEntry:
-
256 #ifdef DEBUG_USB_HOST
-
257  NotifyFailSetDevTblEntry(rcode);
-
258  goto Fail;
-
259 #endif
-
260 
-
261 FailGetConfDescr:
-
262 #ifdef DEBUG_USB_HOST
-
263  NotifyFailGetConfDescr(rcode);
-
264  goto Fail;
-
265 #endif
-
266 
-
267 FailSetConfDescr:
-
268 #ifdef DEBUG_USB_HOST
-
269  NotifyFailSetConfDescr(rcode);
-
270  goto Fail;
-
271 #endif
-
272 
-
273 FailGetProto:
-
274 #ifdef DEBUG_USB_HOST
-
275  USBTRACE("\r\ngetProto:");
-
276  goto Fail;
-
277 #endif
-
278 
-
279 FailSwAcc:
-
280 #ifdef DEBUG_USB_HOST
-
281  USBTRACE("\r\nswAcc:");
-
282  goto Fail;
-
283 #endif
-
284 
-
285 SwAttempt:
-
286 #ifdef DEBUG_USB_HOST
-
287  USBTRACE("\r\nAccessory mode switch attempt");
-
288 #endif
-
289 //FailOnInit:
-
290 // USBTRACE("OnInit:");
-
291 // goto Fail;
-
292 Fail:
-
293  //USBTRACE2("\r\nADK Init Failed, error code: ", rcode);
-
294  //NotifyFail(rcode);
-
295  Release();
-
296  return rcode;
-
297 }
-
298 
-
299 /* Extracts bulk-IN and bulk-OUT endpoint information from config descriptor */
-
300 void ADK::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
-
301  //ErrorMessage<uint8_t>(PSTR("Conf.Val"), conf);
-
302  //ErrorMessage<uint8_t>(PSTR("Iface Num"), iface);
-
303  //ErrorMessage<uint8_t>(PSTR("Alt.Set"), alt);
-
304 
-
305  //added by Yuuichi Akagawa
-
306  if (bNumEP == 3) {
-
307  return;
-
308  }
+
248  //switch to accessory mode
+
249  //the Android phone will reset
+
250  rcode = switchAcc();
+
251  if(rcode) {
+
252  goto FailSwAcc; //init fails
+
253  }
+
254  rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
+
255  delay(100); // Give Android a chance to do its reset. This is a guess, and possibly could be lower.
+
256  goto SwAttempt; //switch to accessory mode attempted
+
257 
+
258  /* diagnostic messages */
+
259 FailGetDevDescr:
+
260 #ifdef DEBUG_USB_HOST
+
261  NotifyFailGetDevDescr(rcode);
+
262  goto Fail;
+
263 #endif
+
264 
+
265 FailSetDevTblEntry:
+
266 #ifdef DEBUG_USB_HOST
+
267  NotifyFailSetDevTblEntry(rcode);
+
268  goto Fail;
+
269 #endif
+
270 
+
271 FailGetConfDescr:
+
272 #ifdef DEBUG_USB_HOST
+
273  NotifyFailGetConfDescr(rcode);
+
274  goto Fail;
+
275 #endif
+
276 
+
277 FailSetConfDescr:
+
278 #ifdef DEBUG_USB_HOST
+
279  NotifyFailSetConfDescr(rcode);
+
280  goto Fail;
+
281 #endif
+
282 
+
283 FailGetProto:
+
284 #ifdef DEBUG_USB_HOST
+
285  USBTRACE("\r\ngetProto:");
+
286  goto Fail;
+
287 #endif
+
288 
+
289 FailSwAcc:
+
290 #ifdef DEBUG_USB_HOST
+
291  USBTRACE("\r\nswAcc:");
+
292  goto Fail;
+
293 #endif
+
294 
+
295  //FailOnInit:
+
296  // USBTRACE("OnInit:");
+
297  // goto Fail;
+
298  //
+
299 SwAttempt:
+
300 #ifdef DEBUG_USB_HOST
+
301  USBTRACE("\r\nAccessory mode switch attempt");
+
302 Fail:
+
303 #endif
+
304  //USBTRACE2("\r\nADK Init Failed, error code: ", rcode);
+
305  //NotifyFail(rcode);
+
306  Release();
+
307  return rcode;
+
308 }
309 
-
310  bConfNum = conf;
-
311 
-
312  if ((pep->bmAttributes & 0x02) == 2) {
-
313  uint8_t index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
-
314  // Fill in the endpoint info structure
-
315  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
-
316  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
-
317 
-
318  bNumEP++;
-
319 
-
320  //PrintEndpointDescriptor(pep);
-
321  }
-
322 }
-
323 
-
324 /* Performs a cleanup after failed Init() attempt */
-
325 uint8_t ADK::Release() {
-
326  pUsb->GetAddressPool().FreeAddress(bAddress);
-
327 
-
328  bNumEP = 1; //must have to be reset to 1
-
329 
-
330  bAddress = 0;
-
331  ready = false;
-
332  return 0;
+
310 /* Extracts bulk-IN and bulk-OUT endpoint information from config descriptor */
+
311 void ADK::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
+
312  //ErrorMessage<uint8_t>(PSTR("Conf.Val"), conf);
+
313  //ErrorMessage<uint8_t>(PSTR("Iface Num"), iface);
+
314  //ErrorMessage<uint8_t>(PSTR("Alt.Set"), alt);
+
315 
+
316  //added by Yuuichi Akagawa
+
317  if(bNumEP == 3) {
+
318  return;
+
319  }
+
320 
+
321  bConfNum = conf;
+
322 
+
323  if((pep->bmAttributes & 0x02) == 2) {
+
324  uint8_t index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
+
325  // Fill in the endpoint info structure
+
326  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+
327  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+
328 
+
329  bNumEP++;
+
330 
+
331  //PrintEndpointDescriptor(pep);
+
332  }
333 }
334 
-
335 uint8_t ADK::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
-
336  //USBTRACE2("\r\nAddr: ", bAddress );
-
337  //USBTRACE2("\r\nEP: ",epInfo[epDataInIndex].epAddr);
-
338  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
-
339 }
+
335 /* Performs a cleanup after failed Init() attempt */
+
336 uint8_t ADK::Release() {
+
337  pUsb->GetAddressPool().FreeAddress(bAddress);
+
338 
+
339  bNumEP = 1; //must have to be reset to 1
340 
-
341 uint8_t ADK::SndData(uint16_t nbytes, uint8_t *dataptr) {
-
342  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
-
343 }
-
344 
-
345 void ADK::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
-
346  Notify(PSTR("Endpoint descriptor:"), 0x80);
-
347  Notify(PSTR("\r\nLength:\t\t"), 0x80);
-
348  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
-
349  Notify(PSTR("\r\nType:\t\t"), 0x80);
-
350  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
-
351  Notify(PSTR("\r\nAddress:\t"), 0x80);
-
352  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
-
353  Notify(PSTR("\r\nAttributes:\t"), 0x80);
-
354  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
-
355  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
-
356  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
-
357  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
-
358  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
-
359  Notify(PSTR("\r\n"), 0x80);
-
360 }
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
341  bAddress = 0;
+
342  ready = false;
+
343  return 0;
+
344 }
+
345 
+
346 uint8_t ADK::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
+
347  //USBTRACE2("\r\nAddr: ", bAddress );
+
348  //USBTRACE2("\r\nEP: ",epInfo[epDataInIndex].epAddr);
+
349  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
+
350 }
+
351 
+
352 uint8_t ADK::SndData(uint16_t nbytes, uint8_t *dataptr) {
+
353  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
+
354 }
+
355 
+
356 void ADK::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
+
357  Notify(PSTR("Endpoint descriptor:"), 0x80);
+
358  Notify(PSTR("\r\nLength:\t\t"), 0x80);
+
359  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
+
360  Notify(PSTR("\r\nType:\t\t"), 0x80);
+
361  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
+
362  Notify(PSTR("\r\nAddress:\t"), 0x80);
+
363  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
+
364  Notify(PSTR("\r\nAttributes:\t"), 0x80);
+
365  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
+
366  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
+
367  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
+
368  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
+
369  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
+
370  Notify(PSTR("\r\n"), 0x80);
+
371 }
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
AddressPool
Definition: address.h:83
ADB_PID
#define ADB_PID
Definition: adk.h:27
ACCESSORY_STRING_MODEL
#define ACCESSORY_STRING_MODEL
Definition: adk.h:43
ADK::epDataInIndex
static const uint8_t epDataInIndex
Definition: adk.h:69
-
ADK::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: adk.cpp:335
+
ADK::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: adk.cpp:346
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
UsbDevice
Definition: address.h:75
-
ADK::Release
virtual uint8_t Release()
Definition: adk.cpp:325
+
ADK::Release
virtual uint8_t Release()
Definition: adk.cpp:336
adk.h
-
ADK::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: adk.cpp:341
+
ADK::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: adk.cpp:352
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
USB_ENDPOINT_DESCRIPTOR::bInterval
uint8_t bInterval
Definition: usb_ch9.h:147
USB_ENDPOINT_DESCRIPTOR::bLength
uint8_t bLength
Definition: usb_ch9.h:142
ACCESSORY_STRING_URI
#define ACCESSORY_STRING_URI
Definition: adk.h:46
ACCESSORY_STRING_MANUFACTURER
#define ACCESSORY_STRING_MANUFACTURER
Definition: adk.h:42
-
ADK::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: adk.cpp:300
+
ADK::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: adk.cpp:311
ADK::pUsb
USB * pUsb
Definition: adk.h:73
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
ADK::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:58
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
ADK::epDataOutIndex
static const uint8_t epDataOutIndex
Definition: adk.h:70
@@ -481,16 +492,16 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
Notify
#define Notify(...)
Definition: message.h:44
USB_ENDPOINT_DESCRIPTOR::bmAttributes
uint8_t bmAttributes
Definition: usb_ch9.h:145
-
ConfigDescParser
Definition: confdescparser.h:39
-
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:61
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
ConfigDescParser
Definition: confdescparser.h:38
+
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:67
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
NotifyFailGetConfDescr
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
ADK::ready
bool ready
Definition: adk.h:78
ACCESSORY_STRING_SERIAL
#define ACCESSORY_STRING_SERIAL
Definition: adk.h:47
EpInfo
Definition: address.h:32
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
USB_ENDPOINT_DESCRIPTOR::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
ACCESSORY_STRING_VERSION
#define ACCESSORY_STRING_VERSION
Definition: adk.h:45
ADK::ADK
ADK(USB *pUsb, const char *manufacturer, const char *model, const char *description, const char *version, const char *uri, const char *serial)
Definition: adk.cpp:25
@@ -500,22 +511,22 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
ADK_MAX_ENDPOINTS
#define ADK_MAX_ENDPOINTS
Definition: adk.h:49
USB_ENDPOINT_DESCRIPTOR::bDescriptorType
uint8_t bDescriptorType
Definition: usb_ch9.h:143
-
ADK::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: adk.cpp:345
+
ADK::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: adk.cpp:356
USB_NAK_NOWAIT
#define USB_NAK_NOWAIT
Definition: address.h:29
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
ADK::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:63
-
USB
Definition: UsbCore.h:152
+
USB
Definition: UsbCore.h:176
ACCESSORY_STRING_DESCRIPTION
#define ACCESSORY_STRING_DESCRIPTION
Definition: adk.h:44
ADK::bNumEP
uint8_t bNumEP
Definition: adk.h:77
ADK_VID
#define ADK_VID
Definition: adk.h:25
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
ADK::bConfNum
uint8_t bConfNum
Definition: adk.h:75
-
USBTRACE
#define USBTRACE(s)
Definition: macros.h:60
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
USBTRACE
#define USBTRACE(s)
Definition: macros.h:65
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
ADK::bAddress
uint8_t bAddress
Definition: adk.h:74
USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:72
@@ -525,7 +536,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/adk_8h.html b/adk_8h.html index 080b194b..80d33557 100644 --- a/adk_8h.html +++ b/adk_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: adk.h File Reference @@ -31,7 +31,7 @@ - + @@ -380,7 +380,7 @@ Macros diff --git a/adk_8h_source.html b/adk_8h_source.html index a3b2c0f8..76cc8578 100644 --- a/adk_8h_source.html +++ b/adk_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: adk.h Source File @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
-
16 */
+
16  */
17 
18 /* Google ADK interface support header */
19 
@@ -118,8 +118,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
27 #define ADB_PID 0x2D01
28 
29 #define XOOM //enables repeating getProto() and getConf() attempts
-
30  //necessary for slow devices such as Motorola XOOM
-
31  //defined by default, can be commented out to save memory
+
30 //necessary for slow devices such as Motorola XOOM
+
31 //defined by default, can be commented out to save memory
32 
33 /* requests */
34 
@@ -215,27 +215,27 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
124 
125 /* returns 2 bytes in *adkproto */
126 inline uint8_t ADK::getProto(uint8_t* adkproto) {
-
127  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL));
+
127  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL));
128 }
129 
130 /* send ADK string */
131 inline uint8_t ADK::sendStr(uint8_t index, const char* str) {
-
132  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*) str, NULL));
+
132  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL));
133 }
134 
135 /* switch to accessory mode */
136 inline uint8_t ADK::switchAcc(void) {
-
137  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
+
137  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
138 }
139 
140 #endif // _ADK_H_
ADB_PID
#define ADB_PID
Definition: adk.h:27
ADK::epDataInIndex
static const uint8_t epDataInIndex
Definition: adk.h:69
-
ADK::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: adk.cpp:335
-
ADK::Release
virtual uint8_t Release()
Definition: adk.cpp:325
-
ADK::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: adk.cpp:341
+
ADK::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: adk.cpp:346
+
ADK::Release
virtual uint8_t Release()
Definition: adk.cpp:336
+
ADK::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: adk.cpp:352
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
-
ADK::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: adk.cpp:300
+
ADK::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: adk.cpp:311
ADK::pUsb
USB * pUsb
Definition: adk.h:73
ADK::ConfigureDevice
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:58
ADK_GETPROTO
#define ADK_GETPROTO
Definition: adk.h:35
@@ -258,10 +258,10 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
ADK::epInfo
EpInfo epInfo[ADK_MAX_ENDPOINTS]
Definition: adk.h:81
bmREQ_ADK_SEND
#define bmREQ_ADK_SEND
Definition: adk.h:40
ADK_MAX_ENDPOINTS
#define ADK_MAX_ENDPOINTS
Definition: adk.h:49
-
UsbConfigXtracter
Definition: confdescparser.h:24
-
ADK::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: adk.cpp:345
+
UsbConfigXtracter
Definition: confdescparser.h:23
+
ADK::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: adk.cpp:356
ADK::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:63
-
USB
Definition: UsbCore.h:152
+
USB
Definition: UsbCore.h:176
ADK::bNumEP
uint8_t bNumEP
Definition: adk.h:77
ADK_VID
#define ADK_VID
Definition: adk.h:25
ADK::bConfNum
uint8_t bConfNum
Definition: adk.h:75
@@ -271,7 +271,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/annotated.html b/annotated.html index 71b7fb53..b33e5e5b 100644 --- a/annotated.html +++ b/annotated.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Class List @@ -31,7 +31,7 @@ - + @@ -141,32 +141,36 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); oCPL2303 oCPS3BT oCPS3USB -oCPTPListParser -oCReportDescParser -oCReportDescParser2 -oCReportDescParserBase -oCRequestSenseResponce -oCSETUP_PKT -oCSPi -oCSPP -oCTEL_RINGER_FUNC_DESCR -oCUniversalReportParser -oCUSB -oCUSB_CONFIGURATION_DESCRIPTOR -oCUSB_DEVICE_DESCRIPTOR -oCUSB_ENDPOINT_DESCRIPTOR -oCUSB_HID_DESCRIPTOR -oCUSB_INTERFACE_DESCRIPTOR -oCUsbConfigXtracter -oCUsbDevice -oCUsbDeviceAddress -oCUSBDeviceConfig -oCUSBHub -oCUSBReadParser -oCWII -oCXBOXOLD -oCXBOXRECV -\CXBOXUSB +oCPS4BT +oCPS4Buttons +oCPS4Data +oCPTPListParser +oCReportDescParser +oCReportDescParser2 +oCReportDescParserBase +oCRequestSenseResponce +oCSETUP_PKT +oCSinkParser +oCSPi +oCSPP +oCTEL_RINGER_FUNC_DESCR +oCUniversalReportParser +oCUSB +oCUSB_CONFIGURATION_DESCRIPTOR +oCUSB_DEVICE_DESCRIPTOR +oCUSB_ENDPOINT_DESCRIPTOR +oCUSB_HID_DESCRIPTOR +oCUSB_INTERFACE_DESCRIPTOR +oCUsbConfigXtracter +oCUsbDevice +oCUsbDeviceAddress +oCUSBDeviceConfig +oCUSBHub +oCUSBReadParser +oCWII +oCXBOXOLD +oCXBOXRECV +\CXBOXUSB @@ -174,7 +178,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/avrpins_8h.html b/avrpins_8h.html index 566ef76b..f5e1737e 100644 --- a/avrpins_8h.html +++ b/avrpins_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: avrpins.h File Reference @@ -31,7 +31,7 @@ - + @@ -96,7 +96,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/avrpins_8h_source.html b/avrpins_8h_source.html index 6a5627d8..c1beeaed 100644 --- a/avrpins_8h_source.html +++ b/avrpins_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: avrpins.h Source File @@ -31,7 +31,7 @@ - + @@ -309,7 +309,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
218  }
219 
220  static uint8_t IsSet() {
-
221  return PORT::PinRead() & (uint8_t) (1 << PIN);
+
221  return PORT::PinRead() & (uint8_t)(1 << PIN);
222  }
223 
224  static void WaiteForSet() {
@@ -918,7 +918,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/cdcacm_8cpp.html b/cdcacm_8cpp.html index 6447b79a..509eb0a0 100644 --- a/cdcacm_8cpp.html +++ b/cdcacm_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcacm.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for cdcacm.cpp: diff --git a/cdcacm_8cpp_source.html b/cdcacm_8cpp_source.html index b9a15cbb..38e2e43d 100644 --- a/cdcacm_8cpp_source.html +++ b/cdcacm_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcacm.cpp Source File @@ -31,7 +31,7 @@ - + @@ -119,9 +119,9 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
28 bDataIface(0),
29 bNumEP(1),
30 qNextPollTime(0),
-
31 ready(false),
-
32 bPollEnable(false) {
-
33  for (uint8_t i = 0; i < ACM_MAX_ENDPOINTS; i++) {
+
31 bPollEnable(false),
+
32 ready(false) {
+
33  for(uint8_t i = 0; i < ACM_MAX_ENDPOINTS; i++) {
34  epInfo[i].epAddr = 0;
35  epInfo[i].maxPktSize = (i) ? 0 : 8;
36  epInfo[i].epAttribs = 0;
@@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
40  //if (!i)
41  epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
42  }
-
43  if (pUsb)
+
43  if(pUsb)
44  pUsb->RegisterDeviceClass(this);
45 }
46 
@@ -139,407 +139,411 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
48  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
49 
50  uint8_t buf[constBufSize];
-
51  uint8_t rcode;
-
52  UsbDevice *p = NULL;
-
53  EpInfo *oldep_ptr = NULL;
-
54  uint8_t num_of_conf; // number of configurations
-
55 
-
56  AddressPool &addrPool = pUsb->GetAddressPool();
+
51  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
52 
+
53  uint8_t rcode;
+
54  UsbDevice *p = NULL;
+
55  EpInfo *oldep_ptr = NULL;
+
56  uint8_t num_of_conf; // number of configurations
57 
-
58  USBTRACE("ACM Init\r\n");
+
58  AddressPool &addrPool = pUsb->GetAddressPool();
59 
-
60  if (bAddress)
-
61  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
62 
-
63  // Get pointer to pseudo device with address 0 assigned
-
64  p = addrPool.GetUsbDevicePtr(0);
-
65 
-
66  if (!p)
-
67  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
68 
-
69  if (!p->epinfo) {
-
70  USBTRACE("epinfo\r\n");
-
71  return USB_ERROR_EPINFO_IS_NULL;
-
72  }
-
73 
-
74  // Save old pointer to EP_RECORD of address 0
-
75  oldep_ptr = p->epinfo;
-
76 
-
77  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
78  p->epinfo = epInfo;
-
79 
-
80  p->lowspeed = lowspeed;
+
60  USBTRACE("ACM Init\r\n");
+
61 
+
62  if(bAddress)
+
63  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
64 
+
65  // Get pointer to pseudo device with address 0 assigned
+
66  p = addrPool.GetUsbDevicePtr(0);
+
67 
+
68  if(!p)
+
69  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
70 
+
71  if(!p->epinfo) {
+
72  USBTRACE("epinfo\r\n");
+
73  return USB_ERROR_EPINFO_IS_NULL;
+
74  }
+
75 
+
76  // Save old pointer to EP_RECORD of address 0
+
77  oldep_ptr = p->epinfo;
+
78 
+
79  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
80  p->epinfo = epInfo;
81 
-
82  // Get device descriptor
-
83  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf);
-
84 
-
85  // Restore p->epinfo
-
86  p->epinfo = oldep_ptr;
-
87 
-
88  if (rcode)
-
89  goto FailGetDevDescr;
-
90 
-
91  // Allocate new address according to device class
-
92  bAddress = addrPool.AllocAddress(parent, false, port);
-
93 
-
94  if (!bAddress)
-
95  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
96 
-
97  // Extract Max Packet Size from the device descriptor
-
98  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
99 
-
100  // Assign new address to the device
-
101  rcode = pUsb->setAddr(0, 0, bAddress);
-
102 
-
103  if (rcode) {
-
104  p->lowspeed = false;
-
105  addrPool.FreeAddress(bAddress);
-
106  bAddress = 0;
-
107  USBTRACE2("setAddr:", rcode);
-
108  return rcode;
-
109  }
-
110 
-
111  USBTRACE2("Addr:", bAddress);
+
82  p->lowspeed = lowspeed;
+
83 
+
84  // Get device descriptor
+
85  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf);
+
86 
+
87  // Restore p->epinfo
+
88  p->epinfo = oldep_ptr;
+
89 
+
90  if(rcode)
+
91  goto FailGetDevDescr;
+
92 
+
93  // Allocate new address according to device class
+
94  bAddress = addrPool.AllocAddress(parent, false, port);
+
95 
+
96  if(!bAddress)
+
97  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
98 
+
99  // Extract Max Packet Size from the device descriptor
+
100  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
101 
+
102  // Assign new address to the device
+
103  rcode = pUsb->setAddr(0, 0, bAddress);
+
104 
+
105  if(rcode) {
+
106  p->lowspeed = false;
+
107  addrPool.FreeAddress(bAddress);
+
108  bAddress = 0;
+
109  USBTRACE2("setAddr:", rcode);
+
110  return rcode;
+
111  }
112 
-
113  p->lowspeed = false;
+
113  USBTRACE2("Addr:", bAddress);
114 
-
115  p = addrPool.GetUsbDevicePtr(bAddress);
+
115  p->lowspeed = false;
116 
-
117  if (!p)
-
118  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
119 
-
120  p->lowspeed = lowspeed;
+
117  p = addrPool.GetUsbDevicePtr(bAddress);
+
118 
+
119  if(!p)
+
120  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
121 
-
122  num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;
+
122  p->lowspeed = lowspeed;
123 
-
124  // Assign epInfo to epinfo pointer
-
125  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
126 
-
127  if (rcode)
-
128  goto FailSetDevTblEntry;
-
129 
-
130  USBTRACE2("NC:", num_of_conf);
+
124  num_of_conf = udd->bNumConfigurations;
+
125 
+
126  // Assign epInfo to epinfo pointer
+
127  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
128 
+
129  if(rcode)
+
130  goto FailSetDevTblEntry;
131 
-
132  for (uint8_t i = 0; i < num_of_conf; i++) {
-
133  ConfigDescParser< USB_CLASS_COM_AND_CDC_CTRL,
-
134  CDC_SUBCLASS_ACM,
-
135  CDC_PROTOCOL_ITU_T_V_250,
-
136  CP_MASK_COMPARE_CLASS |
-
137  CP_MASK_COMPARE_SUBCLASS |
-
138  CP_MASK_COMPARE_PROTOCOL > CdcControlParser(this);
-
139 
-
140  ConfigDescParser<USB_CLASS_CDC_DATA, 0, 0,
-
141  CP_MASK_COMPARE_CLASS> CdcDataParser(this);
-
142 
-
143  rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcControlParser);
+
132  USBTRACE2("NC:", num_of_conf);
+
133 
+
134  for(uint8_t i = 0; i < num_of_conf; i++) {
+
135  ConfigDescParser< USB_CLASS_COM_AND_CDC_CTRL,
+
136  CDC_SUBCLASS_ACM,
+
137  CDC_PROTOCOL_ITU_T_V_250,
+
138  CP_MASK_COMPARE_CLASS |
+
139  CP_MASK_COMPARE_SUBCLASS |
+
140  CP_MASK_COMPARE_PROTOCOL > CdcControlParser(this);
+
141 
+
142  ConfigDescParser<USB_CLASS_CDC_DATA, 0, 0,
+
143  CP_MASK_COMPARE_CLASS> CdcDataParser(this);
144 
-
145  if (rcode)
-
146  goto FailGetConfDescr;
-
147 
-
148  rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcDataParser);
+
145  rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcControlParser);
+
146 
+
147  if(rcode)
+
148  goto FailGetConfDescr;
149 
-
150  if (rcode)
-
151  goto FailGetConfDescr;
-
152 
-
153  if (bNumEP > 1)
-
154  break;
-
155  } // for
-
156 
-
157  if (bNumEP < 4)
-
158  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
159 
-
160  // Assign epInfo to epinfo pointer
-
161  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
-
162 
-
163  USBTRACE2("Conf:", bConfNum);
+
150  rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcDataParser);
+
151 
+
152  if(rcode)
+
153  goto FailGetConfDescr;
+
154 
+
155  if(bNumEP > 1)
+
156  break;
+
157  } // for
+
158 
+
159  if(bNumEP < 4)
+
160  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
161 
+
162  // Assign epInfo to epinfo pointer
+
163  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
164 
-
165  // Set Configuration Value
-
166  rcode = pUsb->setConf(bAddress, 0, bConfNum);
-
167 
-
168  if (rcode)
-
169  goto FailSetConfDescr;
-
170 
-
171  rcode = pAsync->OnInit(this);
+
165  USBTRACE2("Conf:", bConfNum);
+
166 
+
167  // Set Configuration Value
+
168  rcode = pUsb->setConf(bAddress, 0, bConfNum);
+
169 
+
170  if(rcode)
+
171  goto FailSetConfDescr;
172 
-
173  if (rcode)
-
174  goto FailOnInit;
-
175 
-
176  USBTRACE("ACM configured\r\n");
+
173  rcode = pAsync->OnInit(this);
+
174 
+
175  if(rcode)
+
176  goto FailOnInit;
177 
-
178  ready = true;
+
178  USBTRACE("ACM configured\r\n");
179 
-
180  //bPollEnable = true;
+
180  ready = true;
181 
-
182  //USBTRACE("Poll enabled\r\n");
-
183  return 0;
-
184 
-
185 FailGetDevDescr:
-
186 #ifdef DEBUG_USB_HOST
-
187  NotifyFailGetDevDescr();
-
188  goto Fail;
-
189 #endif
-
190 
-
191 FailSetDevTblEntry:
-
192 #ifdef DEBUG_USB_HOST
-
193  NotifyFailSetDevTblEntry();
-
194  goto Fail;
-
195 #endif
-
196 
-
197 FailGetConfDescr:
-
198 #ifdef DEBUG_USB_HOST
-
199  NotifyFailGetConfDescr();
-
200  goto Fail;
-
201 #endif
-
202 
-
203 FailSetConfDescr:
-
204 #ifdef DEBUG_USB_HOST
-
205  NotifyFailSetConfDescr();
-
206  goto Fail;
-
207 #endif
-
208 
-
209 FailOnInit:
-
210 #ifdef DEBUG_USB_HOST
-
211  USBTRACE("OnInit:");
-
212 #endif
-
213 
-
214 Fail:
-
215 #ifdef DEBUG_USB_HOST
-
216  NotifyFail(rcode);
-
217 #endif
-
218  Release();
-
219  return rcode;
-
220 }
-
221 
-
222 void ACM::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
-
223  ErrorMessage<uint8_t > (PSTR("Conf.Val"), conf);
-
224  ErrorMessage<uint8_t > (PSTR("Iface Num"), iface);
-
225  ErrorMessage<uint8_t > (PSTR("Alt.Set"), alt);
-
226 
-
227  bConfNum = conf;
+
182  //bPollEnable = true;
+
183 
+
184  //USBTRACE("Poll enabled\r\n");
+
185  return 0;
+
186 
+
187 FailGetDevDescr:
+
188 #ifdef DEBUG_USB_HOST
+
189  NotifyFailGetDevDescr();
+
190  goto Fail;
+
191 #endif
+
192 
+
193 FailSetDevTblEntry:
+
194 #ifdef DEBUG_USB_HOST
+
195  NotifyFailSetDevTblEntry();
+
196  goto Fail;
+
197 #endif
+
198 
+
199 FailGetConfDescr:
+
200 #ifdef DEBUG_USB_HOST
+
201  NotifyFailGetConfDescr();
+
202  goto Fail;
+
203 #endif
+
204 
+
205 FailSetConfDescr:
+
206 #ifdef DEBUG_USB_HOST
+
207  NotifyFailSetConfDescr();
+
208  goto Fail;
+
209 #endif
+
210 
+
211 FailOnInit:
+
212 #ifdef DEBUG_USB_HOST
+
213  USBTRACE("OnInit:");
+
214 #endif
+
215 
+
216 #ifdef DEBUG_USB_HOST
+
217 Fail:
+
218  NotifyFail(rcode);
+
219 #endif
+
220  Release();
+
221  return rcode;
+
222 }
+
223 
+
224 void ACM::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
+
225  ErrorMessage<uint8_t > (PSTR("Conf.Val"), conf);
+
226  ErrorMessage<uint8_t > (PSTR("Iface Num"), iface);
+
227  ErrorMessage<uint8_t > (PSTR("Alt.Set"), alt);
228 
-
229  uint8_t index;
+
229  bConfNum = conf;
230 
-
231  if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
-
232  index = epInterruptInIndex;
-
233  else
-
234  if ((pep->bmAttributes & 0x02) == 2)
-
235  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
-
236  else
-
237  return;
-
238 
-
239  // Fill in the endpoint info structure
-
240  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
-
241  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
-
242  epInfo[index].epAttribs = 0;
-
243 
-
244  bNumEP++;
+
231  uint8_t index;
+
232 
+
233  if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
+
234  index = epInterruptInIndex;
+
235  else
+
236  if((pep->bmAttributes & 0x02) == 2)
+
237  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
+
238  else
+
239  return;
+
240 
+
241  // Fill in the endpoint info structure
+
242  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+
243  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+
244  epInfo[index].epAttribs = 0;
245 
-
246  PrintEndpointDescriptor(pep);
-
247 }
-
248 
-
249 uint8_t ACM::Release() {
-
250  pUsb->GetAddressPool().FreeAddress(bAddress);
-
251 
-
252  bControlIface = 0;
-
253  bDataIface = 0;
-
254  bNumEP = 1;
-
255 
-
256  bAddress = 0;
-
257  qNextPollTime = 0;
-
258  bPollEnable = false;
-
259  return 0;
-
260 }
-
261 
-
262 uint8_t ACM::Poll() {
-
263  uint8_t rcode = 0;
-
264 
-
265  if (!bPollEnable)
-
266  return 0;
-
267 
-
268  //uint32_t time_now = millis();
+
246  bNumEP++;
+
247 
+
248  PrintEndpointDescriptor(pep);
+
249 }
+
250 
+
251 uint8_t ACM::Release() {
+
252  pUsb->GetAddressPool().FreeAddress(bAddress);
+
253 
+
254  bControlIface = 0;
+
255  bDataIface = 0;
+
256  bNumEP = 1;
+
257 
+
258  bAddress = 0;
+
259  qNextPollTime = 0;
+
260  bPollEnable = false;
+
261  return 0;
+
262 }
+
263 
+
264 uint8_t ACM::Poll() {
+
265  uint8_t rcode = 0;
+
266 
+
267  if(!bPollEnable)
+
268  return 0;
269 
-
270  //if (qNextPollTime <= time_now)
-
271  //{
-
272  // qNextPollTime = time_now + 100;
-
273 
-
274  // uint8_t rcode;
-
275  // const uint8_t constBufSize = 16;
-
276  // uint8_t buf[constBufSize];
-
277 
-
278  // for (uint8_t i=0; i<constBufSize; i++)
-
279  // buf[i] = 0;
-
280 
-
281  // uint16_t read = (constBufSize > epInfo[epInterruptInIndex].maxPktSize)
-
282  // ? epInfo[epInterruptInIndex].maxPktSize : constBufSize;
-
283  // rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex].epAddr, &read, buf);
-
284 
-
285  // if (rcode)
-
286  // return rcode;
-
287 
-
288  // for (uint8_t i=0; i<read; i++)
-
289  // {
-
290  // PrintHex<uint8_t>(buf[i]);
-
291  // USB_HOST_SERIAL.print(" ");
-
292  // }
-
293  // USBTRACE("\r\n");
-
294  //}
-
295  return rcode;
-
296 }
-
297 
-
298 uint8_t ACM::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
-
299  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
-
300 }
-
301 
-
302 uint8_t ACM::SndData(uint16_t nbytes, uint8_t *dataptr) {
-
303  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
-
304 }
-
305 
-
306 uint8_t ACM::SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) {
-
307  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL));
-
308 }
-
309 
-
310 uint8_t ACM::GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) {
-
311  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL));
-
312 }
-
313 
-
314 uint8_t ACM::ClearCommFeature(uint16_t fid) {
-
315  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL));
-
316 }
-
317 
-
318 uint8_t ACM::SetLineCoding(const LINE_CODING *dataptr) {
-
319  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL));
-
320 }
-
321 
-
322 uint8_t ACM::GetLineCoding(LINE_CODING *dataptr) {
-
323  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL));
-
324 }
-
325 
-
326 uint8_t ACM::SetControlLineState(uint8_t state) {
-
327  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL));
-
328 }
-
329 
-
330 uint8_t ACM::SendBreak(uint16_t duration) {
-
331  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL));
-
332 }
-
333 
-
334 void ACM::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
-
335  Notify(PSTR("Endpoint descriptor:"), 0x80);
-
336  Notify(PSTR("\r\nLength:\t\t"), 0x80);
-
337  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
-
338  Notify(PSTR("\r\nType:\t\t"), 0x80);
-
339  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
-
340  Notify(PSTR("\r\nAddress:\t"), 0x80);
-
341  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
-
342  Notify(PSTR("\r\nAttributes:\t"), 0x80);
-
343  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
-
344  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
-
345  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
-
346  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
-
347  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
-
348  Notify(PSTR("\r\n"), 0x80);
-
349 }
+
270  //uint32_t time_now = millis();
+
271 
+
272  //if (qNextPollTime <= time_now)
+
273  //{
+
274  // qNextPollTime = time_now + 100;
+
275 
+
276  // uint8_t rcode;
+
277  // const uint8_t constBufSize = 16;
+
278  // uint8_t buf[constBufSize];
+
279 
+
280  // for (uint8_t i=0; i<constBufSize; i++)
+
281  // buf[i] = 0;
+
282 
+
283  // uint16_t read = (constBufSize > epInfo[epInterruptInIndex].maxPktSize)
+
284  // ? epInfo[epInterruptInIndex].maxPktSize : constBufSize;
+
285  // rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex].epAddr, &read, buf);
+
286 
+
287  // if (rcode)
+
288  // return rcode;
+
289 
+
290  // for (uint8_t i=0; i<read; i++)
+
291  // {
+
292  // PrintHex<uint8_t>(buf[i]);
+
293  // USB_HOST_SERIAL.print(" ");
+
294  // }
+
295  // USBTRACE("\r\n");
+
296  //}
+
297  return rcode;
+
298 }
+
299 
+
300 uint8_t ACM::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
+
301  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
+
302 }
+
303 
+
304 uint8_t ACM::SndData(uint16_t nbytes, uint8_t *dataptr) {
+
305  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
+
306 }
+
307 
+
308 uint8_t ACM::SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) {
+
309  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL));
+
310 }
+
311 
+
312 uint8_t ACM::GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) {
+
313  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL));
+
314 }
+
315 
+
316 uint8_t ACM::ClearCommFeature(uint16_t fid) {
+
317  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL));
+
318 }
+
319 
+
320 uint8_t ACM::SetLineCoding(const LINE_CODING *dataptr) {
+
321  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL));
+
322 }
+
323 
+
324 uint8_t ACM::GetLineCoding(LINE_CODING *dataptr) {
+
325  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL));
+
326 }
+
327 
+
328 uint8_t ACM::SetControlLineState(uint8_t state) {
+
329  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL));
+
330 }
+
331 
+
332 uint8_t ACM::SendBreak(uint16_t duration) {
+
333  return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL));
+
334 }
+
335 
+
336 void ACM::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
+
337  Notify(PSTR("Endpoint descriptor:"), 0x80);
+
338  Notify(PSTR("\r\nLength:\t\t"), 0x80);
+
339  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
+
340  Notify(PSTR("\r\nType:\t\t"), 0x80);
+
341  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
+
342  Notify(PSTR("\r\nAddress:\t"), 0x80);
+
343  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
+
344  Notify(PSTR("\r\nAttributes:\t"), 0x80);
+
345  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
+
346  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
+
347  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
+
348  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
+
349  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
+
350  Notify(PSTR("\r\n"), 0x80);
+
351 }
USB_CLASS_COM_AND_CDC_CTRL
#define USB_CLASS_COM_AND_CDC_CTRL
Definition: UsbCore.h:42
USB_CLASS_CDC_DATA
#define USB_CLASS_CDC_DATA
Definition: UsbCore.h:49
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
AddressPool
Definition: address.h:83
CDC_SUBCLASS_ACM
#define CDC_SUBCLASS_ACM
Definition: cdcacm.h:27
ACM::ACM
ACM(USB *pusb, CDCAsyncOper *pasync)
Definition: cdcacm.cpp:23
CDC_PROTOCOL_ITU_T_V_250
#define CDC_PROTOCOL_ITU_T_V_250
Definition: cdcacm.h:40
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
CP_MASK_COMPARE_PROTOCOL
#define CP_MASK_COMPARE_PROTOCOL
Definition: confdescparser.h:33
+
CP_MASK_COMPARE_PROTOCOL
#define CP_MASK_COMPARE_PROTOCOL
Definition: confdescparser.h:32
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
ACM::epInterruptInIndex
static const uint8_t epInterruptInIndex
Definition: cdcacm.h:143
+
ACM::epInterruptInIndex
static const uint8_t epInterruptInIndex
Definition: cdcacm.h:142
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
-
ACM::epDataOutIndex
static const uint8_t epDataOutIndex
Definition: cdcacm.h:142
+
ACM::epDataOutIndex
static const uint8_t epDataOutIndex
Definition: cdcacm.h:141
CDC_CLEAR_COMM_FEATURE
#define CDC_CLEAR_COMM_FEATURE
Definition: cdcacm.h:55
-
ACM::qNextPollTime
uint32_t qNextPollTime
Definition: cdcacm.h:152
+
ACM::qNextPollTime
uint32_t qNextPollTime
Definition: cdcacm.h:151
UsbDevice
Definition: address.h:75
-
ACM::bControlIface
uint8_t bControlIface
Definition: cdcacm.h:149
+
ACM::bControlIface
uint8_t bControlIface
Definition: cdcacm.h:148
CDC_SET_COMM_FEATURE
#define CDC_SET_COMM_FEATURE
Definition: cdcacm.h:53
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
USB_ENDPOINT_DESCRIPTOR::bInterval
uint8_t bInterval
Definition: usb_ch9.h:147
CDC_SET_LINE_CODING
#define CDC_SET_LINE_CODING
Definition: cdcacm.h:62
USB_ENDPOINT_DESCRIPTOR::bLength
uint8_t bLength
Definition: usb_ch9.h:142
-
ACM::ready
bool ready
Definition: cdcacm.h:154
+
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
+
ACM::ready
bool ready
Definition: cdcacm.h:153
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
-
ACM::bDataIface
uint8_t bDataIface
Definition: cdcacm.h:150
-
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:145
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:151
+
ACM::bDataIface
uint8_t bDataIface
Definition: cdcacm.h:149
+
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:144
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:150
bmREQ_CDCOUT
#define bmREQ_CDCOUT
Definition: cdcacm.h:22
-
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:156
+
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:155
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
CP_MASK_COMPARE_CLASS
#define CP_MASK_COMPARE_CLASS
Definition: confdescparser.h:31
-
ACM::bPollEnable
bool bPollEnable
Definition: cdcacm.h:153
+
CP_MASK_COMPARE_CLASS
#define CP_MASK_COMPARE_CLASS
Definition: confdescparser.h:30
+
ACM::bPollEnable
bool bPollEnable
Definition: cdcacm.h:152
CDC_SEND_BREAK
#define CDC_SEND_BREAK
Definition: cdcacm.h:65
CDC_GET_COMM_FEATURE
#define CDC_GET_COMM_FEATURE
Definition: cdcacm.h:54
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
-
ACM::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: cdcacm.cpp:334
+
ACM::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: cdcacm.cpp:336
Notify
#define Notify(...)
Definition: message.h:44
-
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:146
+
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:145
USB_ENDPOINT_DESCRIPTOR::bmAttributes
uint8_t bmAttributes
Definition: usb_ch9.h:145
-
ConfigDescParser
Definition: confdescparser.h:39
-
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:61
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
-
ACM_MAX_ENDPOINTS
#define ACM_MAX_ENDPOINTS
Definition: cdcacm.h:137
+
ConfigDescParser
Definition: confdescparser.h:38
+
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:67
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
+
ACM_MAX_ENDPOINTS
#define ACM_MAX_ENDPOINTS
Definition: cdcacm.h:136
NotifyFailGetConfDescr
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
-
ACM::GetLineCoding
uint8_t GetLineCoding(LINE_CODING *dataptr)
Definition: cdcacm.cpp:322
+
ACM::GetLineCoding
uint8_t GetLineCoding(LINE_CODING *dataptr)
Definition: cdcacm.cpp:324
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
bmREQ_CDCIN
#define bmREQ_CDCIN
Definition: cdcacm.h:23
-
ACM::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:302
-
ACM::Poll
virtual uint8_t Poll()
Definition: cdcacm.cpp:262
+
ACM::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:304
+
ACM::Poll
virtual uint8_t Poll()
Definition: cdcacm.cpp:264
EpInfo
Definition: address.h:32
CDC_GET_LINE_CODING
#define CDC_GET_LINE_CODING
Definition: cdcacm.h:63
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
USB_ENDPOINT_DESCRIPTOR::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
ACM::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: cdcacm.cpp:47
-
CP_MASK_COMPARE_SUBCLASS
#define CP_MASK_COMPARE_SUBCLASS
Definition: confdescparser.h:32
+
CP_MASK_COMPARE_SUBCLASS
#define CP_MASK_COMPARE_SUBCLASS
Definition: confdescparser.h:31
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
USB_ENDPOINT_DESCRIPTOR::bEndpointAddress
uint8_t bEndpointAddress
Definition: usb_ch9.h:144
-
ACM::epDataInIndex
static const uint8_t epDataInIndex
Definition: cdcacm.h:141
-
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:147
+
ACM::epDataInIndex
static const uint8_t epDataInIndex
Definition: cdcacm.h:140
+
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:146
LINE_CODING
Definition: cdcacm.h:110
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
USB_ENDPOINT_DESCRIPTOR::bDescriptorType
uint8_t bDescriptorType
Definition: usb_ch9.h:143
-
ACM::SetLineCoding
uint8_t SetLineCoding(const LINE_CODING *dataptr)
Definition: cdcacm.cpp:318
+
ACM::SetLineCoding
uint8_t SetLineCoding(const LINE_CODING *dataptr)
Definition: cdcacm.cpp:320
cdcacm.h
-
ACM::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcacm.cpp:222
-
ACM::SendBreak
uint8_t SendBreak(uint16_t duration)
Definition: cdcacm.cpp:330
+
ACM::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcacm.cpp:224
+
ACM::SendBreak
uint8_t SendBreak(uint16_t duration)
Definition: cdcacm.cpp:332
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
-
CDCAsyncOper
Definition: cdcacm.h:129
+
CDCAsyncOper
Definition: cdcacm.h:128
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
-
ACM::GetCommFeature
uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:310
-
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:249
-
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:148
+
ACM::GetCommFeature
uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:312
+
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:251
+
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:147
+
USB_DEVICE_DESCRIPTOR::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:112
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
CDC_SET_CONTROL_LINE_STATE
#define CDC_SET_CONTROL_LINE_STATE
Definition: cdcacm.h:64
CDCAsyncOper::OnInit
virtual uint8_t OnInit(ACM *pacm)=0
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB
Definition: UsbCore.h:152
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB
Definition: UsbCore.h:176
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
ACM::SetControlLineState
uint8_t SetControlLineState(uint8_t state)
Definition: cdcacm.cpp:326
-
ACM::SetCommFeature
uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:306
-
ACM::ClearCommFeature
uint8_t ClearCommFeature(uint16_t fid)
Definition: cdcacm.cpp:314
-
USBTRACE
#define USBTRACE(s)
Definition: macros.h:60
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
ACM::SetControlLineState
uint8_t SetControlLineState(uint8_t state)
Definition: cdcacm.cpp:328
+
ACM::SetCommFeature
uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:308
+
ACM::ClearCommFeature
uint8_t ClearCommFeature(uint16_t fid)
Definition: cdcacm.cpp:316
+
USBTRACE
#define USBTRACE(s)
Definition: macros.h:65
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
-
ACM::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: cdcacm.cpp:298
+
ACM::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: cdcacm.cpp:300
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
diff --git a/cdcacm_8h.html b/cdcacm_8h.html index 74296c8e..841976cf 100644 --- a/cdcacm_8h.html +++ b/cdcacm_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcacm.h File Reference @@ -31,7 +31,7 @@ - + @@ -969,7 +969,7 @@ Typedefs
-

Definition at line 137 of file cdcacm.h.

+

Definition at line 136 of file cdcacm.h.

@@ -1016,7 +1016,7 @@ Typedefs diff --git a/cdcacm_8h_source.html b/cdcacm_8h_source.html index 7027b43e..1cf53ccd 100644 --- a/cdcacm_8h_source.html +++ b/cdcacm_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcacm.h Source File @@ -31,7 +31,7 @@ - + @@ -110,67 +110,67 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
19 
20 #include "Usb.h"
21 
-
22 #define bmREQ_CDCOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
-
23 #define bmREQ_CDCIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
+
22 #define bmREQ_CDCOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
+
23 #define bmREQ_CDCIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
24 
25 // CDC Subclass Constants
-
26 #define CDC_SUBCLASS_DLCM 0x01 // Direct Line Control Model
-
27 #define CDC_SUBCLASS_ACM 0x02 // Abstract Control Model
-
28 #define CDC_SUBCLASS_TCM 0x03 // Telephone Control Model
-
29 #define CDC_SUBCLASS_MCCM 0x04 // Multi Channel Control Model
-
30 #define CDC_SUBCLASS_CAPI 0x05 // CAPI Control Model
-
31 #define CDC_SUBCLASS_ETHERNET 0x06 // Ethernet Network Control Model
-
32 #define CDC_SUBCLASS_ATM 0x07 // ATM Network Control Model
-
33 #define CDC_SUBCLASS_WIRELESS_HANDSET 0x08 // Wireless Handset Control Model
-
34 #define CDC_SUBCLASS_DEVICE_MANAGEMENT 0x09 // Device Management
-
35 #define CDC_SUBCLASS_MOBILE_DIRECT_LINE 0x0A // Mobile Direct Line Model
-
36 #define CDC_SUBCLASS_OBEX 0x0B // OBEX
-
37 #define CDC_SUBCLASS_ETHERNET_EMU 0x0C // Ethernet Emulation Model
+
26 #define CDC_SUBCLASS_DLCM 0x01 // Direct Line Control Model
+
27 #define CDC_SUBCLASS_ACM 0x02 // Abstract Control Model
+
28 #define CDC_SUBCLASS_TCM 0x03 // Telephone Control Model
+
29 #define CDC_SUBCLASS_MCCM 0x04 // Multi Channel Control Model
+
30 #define CDC_SUBCLASS_CAPI 0x05 // CAPI Control Model
+
31 #define CDC_SUBCLASS_ETHERNET 0x06 // Ethernet Network Control Model
+
32 #define CDC_SUBCLASS_ATM 0x07 // ATM Network Control Model
+
33 #define CDC_SUBCLASS_WIRELESS_HANDSET 0x08 // Wireless Handset Control Model
+
34 #define CDC_SUBCLASS_DEVICE_MANAGEMENT 0x09 // Device Management
+
35 #define CDC_SUBCLASS_MOBILE_DIRECT_LINE 0x0A // Mobile Direct Line Model
+
36 #define CDC_SUBCLASS_OBEX 0x0B // OBEX
+
37 #define CDC_SUBCLASS_ETHERNET_EMU 0x0C // Ethernet Emulation Model
38 
39 // Communication Interface Class Control Protocol Codes
-
40 #define CDC_PROTOCOL_ITU_T_V_250 0x01 // AT Commands defined by ITU-T V.250
-
41 #define CDC_PROTOCOL_PCCA_101 0x02 // AT Commands defined by PCCA-101
-
42 #define CDC_PROTOCOL_PCCA_101_O 0x03 // AT Commands defined by PCCA-101 & Annex O
-
43 #define CDC_PROTOCOL_GSM_7_07 0x04 // AT Commands defined by GSM 7.07
-
44 #define CDC_PROTOCOL_3GPP_27_07 0x05 // AT Commands defined by 3GPP 27.007
-
45 #define CDC_PROTOCOL_C_S0017_0 0x06 // AT Commands defined by TIA for CDMA
-
46 #define CDC_PROTOCOL_USB_EEM 0x07 // Ethernet Emulation Model
+
40 #define CDC_PROTOCOL_ITU_T_V_250 0x01 // AT Commands defined by ITU-T V.250
+
41 #define CDC_PROTOCOL_PCCA_101 0x02 // AT Commands defined by PCCA-101
+
42 #define CDC_PROTOCOL_PCCA_101_O 0x03 // AT Commands defined by PCCA-101 & Annex O
+
43 #define CDC_PROTOCOL_GSM_7_07 0x04 // AT Commands defined by GSM 7.07
+
44 #define CDC_PROTOCOL_3GPP_27_07 0x05 // AT Commands defined by 3GPP 27.007
+
45 #define CDC_PROTOCOL_C_S0017_0 0x06 // AT Commands defined by TIA for CDMA
+
46 #define CDC_PROTOCOL_USB_EEM 0x07 // Ethernet Emulation Model
47 
48 // CDC Commands defined by CDC 1.2
-
49 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
-
50 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
+
49 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
+
50 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
51 
52 // CDC Commands defined by PSTN 1.2
-
53 #define CDC_SET_COMM_FEATURE 0x02
-
54 #define CDC_GET_COMM_FEATURE 0x03
-
55 #define CDC_CLEAR_COMM_FEATURE 0x04
-
56 #define CDC_SET_AUX_LINE_STATE 0x10
-
57 #define CDC_SET_HOOK_STATE 0x11
-
58 #define CDC_PULSE_SETUP 0x12
-
59 #define CDC_SEND_PULSE 0x13
-
60 #define CDC_SET_PULSE_TIME 0x14
-
61 #define CDC_RING_AUX_JACK 0x15
-
62 #define CDC_SET_LINE_CODING 0x20
-
63 #define CDC_GET_LINE_CODING 0x21
-
64 #define CDC_SET_CONTROL_LINE_STATE 0x22
-
65 #define CDC_SEND_BREAK 0x23
-
66 #define CDC_SET_RINGER_PARMS 0x30
-
67 #define CDC_GET_RINGER_PARMS 0x31
-
68 #define CDC_SET_OPERATION_PARMS 0x32
-
69 #define CDC_GET_OPERATION_PARMS 0x33
-
70 #define CDC_SET_LINE_PARMS 0x34
-
71 #define CDC_GET_LINE_PARMS 0x35
-
72 #define CDC_DIAL_DIGITS 0x36
+
53 #define CDC_SET_COMM_FEATURE 0x02
+
54 #define CDC_GET_COMM_FEATURE 0x03
+
55 #define CDC_CLEAR_COMM_FEATURE 0x04
+
56 #define CDC_SET_AUX_LINE_STATE 0x10
+
57 #define CDC_SET_HOOK_STATE 0x11
+
58 #define CDC_PULSE_SETUP 0x12
+
59 #define CDC_SEND_PULSE 0x13
+
60 #define CDC_SET_PULSE_TIME 0x14
+
61 #define CDC_RING_AUX_JACK 0x15
+
62 #define CDC_SET_LINE_CODING 0x20
+
63 #define CDC_GET_LINE_CODING 0x21
+
64 #define CDC_SET_CONTROL_LINE_STATE 0x22
+
65 #define CDC_SEND_BREAK 0x23
+
66 #define CDC_SET_RINGER_PARMS 0x30
+
67 #define CDC_GET_RINGER_PARMS 0x31
+
68 #define CDC_SET_OPERATION_PARMS 0x32
+
69 #define CDC_GET_OPERATION_PARMS 0x33
+
70 #define CDC_SET_LINE_PARMS 0x34
+
71 #define CDC_GET_LINE_PARMS 0x35
+
72 #define CDC_DIAL_DIGITS 0x36
73 
74 //Class-Specific Notification Codes
-
75 #define NETWORK_CONNECTION 0x00
-
76 #define RESPONSE_AVAILABLE 0x01
-
77 #define AUX_JACK_HOOK_STATE 0x08
-
78 #define RING_DETECT 0x09
-
79 #define SERIAL_STATE 0x20
-
80 #define CALL_STATE_CHANGE 0x28
-
81 #define LINE_STATE_CHANGE 0x29
-
82 #define CONNECTION_SPEED_CHANGE 0x2a
+
75 #define NETWORK_CONNECTION 0x00
+
76 #define RESPONSE_AVAILABLE 0x01
+
77 #define AUX_JACK_HOOK_STATE 0x08
+
78 #define RING_DETECT 0x09
+
79 #define SERIAL_STATE 0x20
+
80 #define CALL_STATE_CHANGE 0x28
+
81 #define LINE_STATE_CHANGE 0x29
+
82 #define CONNECTION_SPEED_CHANGE 0x2a
83 
84 // CDC Functional Descriptor Structures
85 
@@ -205,163 +205,162 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
114  uint8_t bDataBits; // Data bits (5, 6, 7, 8 or 16)
115 } LINE_CODING;
116 
-
117 typedef struct
-
118 {
-
119  uint8_t bmRequestType; // 0xa1 for class-specific notifications
-
120  uint8_t bNotification;
-
121  uint16_t wValue;
-
122  uint16_t wIndex;
-
123  uint16_t wLength;
-
124  uint16_t bmState; //UART state bitmap for SERIAL_STATE, other notifications variable length
-
125 } CLASS_NOTIFICATION;
-
126 
-
127 class ACM;
-
128 
-
129 class CDCAsyncOper {
-
130 public:
-
131  virtual uint8_t OnInit(ACM *pacm) = 0;
-
132  //virtual void OnDataRcvd(ACM *pacm, uint8_t nbytes, uint8_t *dataptr) = 0;
-
133  //virtual void OnDisconnected(ACM *pacm) = 0;
-
134 };
+
117 typedef struct {
+
118  uint8_t bmRequestType; // 0xa1 for class-specific notifications
+
119  uint8_t bNotification;
+
120  uint16_t wValue;
+
121  uint16_t wIndex;
+
122  uint16_t wLength;
+
123  uint16_t bmState; //UART state bitmap for SERIAL_STATE, other notifications variable length
+
124 } CLASS_NOTIFICATION;
+
125 
+
126 class ACM;
+
127 
+
128 class CDCAsyncOper {
+
129 public:
+
130  virtual uint8_t OnInit(ACM *pacm) = 0;
+
131  //virtual void OnDataRcvd(ACM *pacm, uint8_t nbytes, uint8_t *dataptr) = 0;
+
132  //virtual void OnDisconnected(ACM *pacm) = 0;
+
133 };
+
134 
135 
-
136 
-
137 #define ACM_MAX_ENDPOINTS 4
-
138 
-
139 class ACM : public USBDeviceConfig, public UsbConfigXtracter {
-
140 protected:
-
141  static const uint8_t epDataInIndex; // DataIn endpoint index
-
142  static const uint8_t epDataOutIndex; // DataOUT endpoint index
-
143  static const uint8_t epInterruptInIndex; // InterruptIN endpoint index
-
144 
-
145  USB *pUsb;
-
146  CDCAsyncOper *pAsync;
-
147  uint8_t bAddress;
-
148  uint8_t bConfNum; // configuration number
-
149  uint8_t bControlIface; // Control interface value
-
150  uint8_t bDataIface; // Data interface value
-
151  uint8_t bNumEP; // total number of EP in the configuration
-
152  uint32_t qNextPollTime; // next poll time
-
153  bool bPollEnable; // poll enable flag
-
154  bool ready; //device ready indicator
-
155 
-
156  EpInfo epInfo[ACM_MAX_ENDPOINTS];
-
157 
-
158  void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
-
159 
-
160 public:
-
161  ACM(USB *pusb, CDCAsyncOper *pasync);
-
162 
-
163  uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
-
164  uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
-
165  uint8_t ClearCommFeature(uint16_t fid);
-
166  uint8_t SetLineCoding(const LINE_CODING *dataptr);
-
167  uint8_t GetLineCoding(LINE_CODING *dataptr);
-
168  uint8_t SetControlLineState(uint8_t state);
-
169  uint8_t SendBreak(uint16_t duration);
-
170  uint8_t GetNotif( uint16_t *bytes_rcvd, uint8_t *dataptr );
-
171 
-
172  // Methods for recieving and sending data
-
173  uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
-
174  uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
-
175 
-
176  // USBDeviceConfig implementation
-
177  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
-
178  virtual uint8_t Release();
-
179  virtual uint8_t Poll();
-
180 
-
181  virtual uint8_t GetAddress() {
-
182  return bAddress;
-
183  };
-
184 
-
185  virtual bool isReady() {
-
186  return ready;
-
187  };
-
188 
-
189  // UsbConfigXtracter implementation
-
190  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
-
191 };
-
192 
-
193 #endif // __CDCACM_H__
-
CLASS_NOTIFICATION::wIndex
uint16_t wIndex
Definition: cdcacm.h:122
+
136 #define ACM_MAX_ENDPOINTS 4
+
137 
+
138 class ACM : public USBDeviceConfig, public UsbConfigXtracter {
+
139 protected:
+
140  static const uint8_t epDataInIndex; // DataIn endpoint index
+
141  static const uint8_t epDataOutIndex; // DataOUT endpoint index
+
142  static const uint8_t epInterruptInIndex; // InterruptIN endpoint index
+
143 
+
144  USB *pUsb;
+
145  CDCAsyncOper *pAsync;
+
146  uint8_t bAddress;
+
147  uint8_t bConfNum; // configuration number
+
148  uint8_t bControlIface; // Control interface value
+
149  uint8_t bDataIface; // Data interface value
+
150  uint8_t bNumEP; // total number of EP in the configuration
+
151  uint32_t qNextPollTime; // next poll time
+
152  bool bPollEnable; // poll enable flag
+
153  bool ready; //device ready indicator
+
154 
+
155  EpInfo epInfo[ACM_MAX_ENDPOINTS];
+
156 
+
157  void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
+
158 
+
159 public:
+
160  ACM(USB *pusb, CDCAsyncOper *pasync);
+
161 
+
162  uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
+
163  uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
+
164  uint8_t ClearCommFeature(uint16_t fid);
+
165  uint8_t SetLineCoding(const LINE_CODING *dataptr);
+
166  uint8_t GetLineCoding(LINE_CODING *dataptr);
+
167  uint8_t SetControlLineState(uint8_t state);
+
168  uint8_t SendBreak(uint16_t duration);
+
169  uint8_t GetNotif(uint16_t *bytes_rcvd, uint8_t *dataptr);
+
170 
+
171  // Methods for recieving and sending data
+
172  uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
+
173  uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
+
174 
+
175  // USBDeviceConfig implementation
+
176  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
+
177  virtual uint8_t Release();
+
178  virtual uint8_t Poll();
+
179 
+
180  virtual uint8_t GetAddress() {
+
181  return bAddress;
+
182  };
+
183 
+
184  virtual bool isReady() {
+
185  return ready;
+
186  };
+
187 
+
188  // UsbConfigXtracter implementation
+
189  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
+
190 };
+
191 
+
192 #endif // __CDCACM_H__
+
CLASS_NOTIFICATION::wIndex
uint16_t wIndex
Definition: cdcacm.h:121
ACM::ACM
ACM(USB *pusb, CDCAsyncOper *pasync)
Definition: cdcacm.cpp:23
-
ACM::epInterruptInIndex
static const uint8_t epInterruptInIndex
Definition: cdcacm.h:143
-
ACM::GetAddress
virtual uint8_t GetAddress()
Definition: cdcacm.h:181
-
ACM::epDataOutIndex
static const uint8_t epDataOutIndex
Definition: cdcacm.h:142
-
ACM::qNextPollTime
uint32_t qNextPollTime
Definition: cdcacm.h:152
+
ACM::epInterruptInIndex
static const uint8_t epInterruptInIndex
Definition: cdcacm.h:142
+
ACM::GetAddress
virtual uint8_t GetAddress()
Definition: cdcacm.h:180
+
ACM::epDataOutIndex
static const uint8_t epDataOutIndex
Definition: cdcacm.h:141
+
ACM::qNextPollTime
uint32_t qNextPollTime
Definition: cdcacm.h:151
LINE_CODING::bParityType
uint8_t bParityType
Definition: cdcacm.h:113
LINE_CODING::bCharFormat
uint8_t bCharFormat
Definition: cdcacm.h:112
LINE_CODING::bDataBits
uint8_t bDataBits
Definition: cdcacm.h:114
-
CLASS_NOTIFICATION::bNotification
uint8_t bNotification
Definition: cdcacm.h:120
-
ACM::bControlIface
uint8_t bControlIface
Definition: cdcacm.h:149
-
CLASS_NOTIFICATION::wValue
uint16_t wValue
Definition: cdcacm.h:121
+
CLASS_NOTIFICATION::bNotification
uint8_t bNotification
Definition: cdcacm.h:119
+
ACM::bControlIface
uint8_t bControlIface
Definition: cdcacm.h:148
+
CLASS_NOTIFICATION::wValue
uint16_t wValue
Definition: cdcacm.h:120
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
-
ACM::ready
bool ready
Definition: cdcacm.h:154
-
ACM::bDataIface
uint8_t bDataIface
Definition: cdcacm.h:150
-
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:145
+
ACM::ready
bool ready
Definition: cdcacm.h:153
+
ACM::bDataIface
uint8_t bDataIface
Definition: cdcacm.h:149
+
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:144
CALL_MGMNT_FUNC_DESCR::bDataInterface
uint8_t bDataInterface
Definition: cdcacm.h:91
CALL_MGMNT_FUNC_DESCR::bDescriptorType
uint8_t bDescriptorType
Definition: cdcacm.h:88
-
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:151
+
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:150
TEL_RINGER_FUNC_DESCR
Definition: cdcacm.h:102
-
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:156
+
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:155
USBDeviceConfig
Definition: UsbCore.h:105
Usb.h
CLASS_NOTIFICATION
Definition: cdcacm.h:117
ACM_FUNC_DESCR::bFunctionLength
uint8_t bFunctionLength
Definition: cdcacm.h:95
CALL_MGMNT_FUNC_DESCR::bDescriptorSubtype
uint8_t bDescriptorSubtype
Definition: cdcacm.h:89
TEL_RINGER_FUNC_DESCR::bNumRingerPatterns
uint8_t bNumRingerPatterns
Definition: cdcacm.h:107
-
ACM::bPollEnable
bool bPollEnable
Definition: cdcacm.h:153
+
ACM::bPollEnable
bool bPollEnable
Definition: cdcacm.h:152
ACM_FUNC_DESCR::bDescriptorSubtype
uint8_t bDescriptorSubtype
Definition: cdcacm.h:97
-
CLASS_NOTIFICATION::bmState
uint16_t bmState
Definition: cdcacm.h:124
-
ACM::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: cdcacm.cpp:334
-
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:146
-
ACM_MAX_ENDPOINTS
#define ACM_MAX_ENDPOINTS
Definition: cdcacm.h:137
-
ACM::GetLineCoding
uint8_t GetLineCoding(LINE_CODING *dataptr)
Definition: cdcacm.cpp:322
+
CLASS_NOTIFICATION::bmState
uint16_t bmState
Definition: cdcacm.h:123
+
ACM::PrintEndpointDescriptor
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: cdcacm.cpp:336
+
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:145
+
ACM_MAX_ENDPOINTS
#define ACM_MAX_ENDPOINTS
Definition: cdcacm.h:136
+
ACM::GetLineCoding
uint8_t GetLineCoding(LINE_CODING *dataptr)
Definition: cdcacm.cpp:324
CALL_MGMNT_FUNC_DESCR
Definition: cdcacm.h:86
ACM_FUNC_DESCR::bDescriptorType
uint8_t bDescriptorType
Definition: cdcacm.h:96
TEL_RINGER_FUNC_DESCR::bRingerVolSteps
uint8_t bRingerVolSteps
Definition: cdcacm.h:106
-
ACM::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:302
-
ACM::Poll
virtual uint8_t Poll()
Definition: cdcacm.cpp:262
+
ACM::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:304
+
ACM::Poll
virtual uint8_t Poll()
Definition: cdcacm.cpp:264
EpInfo
Definition: address.h:32
ACM_FUNC_DESCR::bmCapabilities
uint8_t bmCapabilities
Definition: cdcacm.h:98
TEL_RINGER_FUNC_DESCR::bDescriptorSubtype
uint8_t bDescriptorSubtype
Definition: cdcacm.h:105
ACM::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: cdcacm.cpp:47
-
CLASS_NOTIFICATION::bmRequestType
uint8_t bmRequestType
Definition: cdcacm.h:119
-
ACM::epDataInIndex
static const uint8_t epDataInIndex
Definition: cdcacm.h:141
-
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:147
+
CLASS_NOTIFICATION::bmRequestType
uint8_t bmRequestType
Definition: cdcacm.h:118
+
ACM::epDataInIndex
static const uint8_t epDataInIndex
Definition: cdcacm.h:140
+
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:146
LINE_CODING
Definition: cdcacm.h:110
-
ACM::isReady
virtual bool isReady()
Definition: cdcacm.h:185
-
ACM::SetLineCoding
uint8_t SetLineCoding(const LINE_CODING *dataptr)
Definition: cdcacm.cpp:318
-
UsbConfigXtracter
Definition: confdescparser.h:24
+
ACM::isReady
virtual bool isReady()
Definition: cdcacm.h:184
+
ACM::SetLineCoding
uint8_t SetLineCoding(const LINE_CODING *dataptr)
Definition: cdcacm.cpp:320
+
UsbConfigXtracter
Definition: confdescparser.h:23
TEL_RINGER_FUNC_DESCR::bFunctionLength
uint8_t bFunctionLength
Definition: cdcacm.h:103
TEL_CALL_STATE_REP_CPBL_FUNC_DESCR
struct ACM_FUNC_DESCR TEL_CALL_STATE_REP_CPBL_FUNC_DESCR
-
ACM::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcacm.cpp:222
-
ACM::SendBreak
uint8_t SendBreak(uint16_t duration)
Definition: cdcacm.cpp:330
-
CLASS_NOTIFICATION::wLength
uint16_t wLength
Definition: cdcacm.h:123
-
CDCAsyncOper
Definition: cdcacm.h:129
+
ACM::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcacm.cpp:224
+
ACM::SendBreak
uint8_t SendBreak(uint16_t duration)
Definition: cdcacm.cpp:332
+
CLASS_NOTIFICATION::wLength
uint16_t wLength
Definition: cdcacm.h:122
+
CDCAsyncOper
Definition: cdcacm.h:128
ACM::GetNotif
uint8_t GetNotif(uint16_t *bytes_rcvd, uint8_t *dataptr)
LINE_CODING::dwDTERate
uint32_t dwDTERate
Definition: cdcacm.h:111
-
ACM::GetCommFeature
uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:310
-
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:249
-
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:148
+
ACM::GetCommFeature
uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:312
+
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:251
+
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:147
TEL_OPER_MODES_FUNC_DESCR
struct ACM_FUNC_DESCR TEL_OPER_MODES_FUNC_DESCR
CDCAsyncOper::OnInit
virtual uint8_t OnInit(ACM *pacm)=0
ACM_FUNC_DESCR
Definition: cdcacm.h:94
-
USB
Definition: UsbCore.h:152
-
ACM
Definition: cdcacm.h:139
+
USB
Definition: UsbCore.h:176
+
ACM
Definition: cdcacm.h:138
TEL_RINGER_FUNC_DESCR::bDescriptorType
uint8_t bDescriptorType
Definition: cdcacm.h:104
-
ACM::SetControlLineState
uint8_t SetControlLineState(uint8_t state)
Definition: cdcacm.cpp:326
-
ACM::SetCommFeature
uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:306
-
ACM::ClearCommFeature
uint8_t ClearCommFeature(uint16_t fid)
Definition: cdcacm.cpp:314
+
ACM::SetControlLineState
uint8_t SetControlLineState(uint8_t state)
Definition: cdcacm.cpp:328
+
ACM::SetCommFeature
uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr)
Definition: cdcacm.cpp:308
+
ACM::ClearCommFeature
uint8_t ClearCommFeature(uint16_t fid)
Definition: cdcacm.cpp:316
DLM_FUNC_DESCR
struct ACM_FUNC_DESCR DLM_FUNC_DESCR
CALL_MGMNT_FUNC_DESCR::bFunctionLength
uint8_t bFunctionLength
Definition: cdcacm.h:87
CALL_MGMNT_FUNC_DESCR::bmCapabilities
uint8_t bmCapabilities
Definition: cdcacm.h:90
-
ACM::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: cdcacm.cpp:298
+
ACM::RcvData
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: cdcacm.cpp:300
diff --git a/cdcftdi_8cpp.html b/cdcftdi_8cpp.html index 27425ee7..5faf57a0 100644 --- a/cdcftdi_8cpp.html +++ b/cdcftdi_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcftdi.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for cdcftdi.cpp: diff --git a/cdcftdi_8cpp_source.html b/cdcftdi_8cpp_source.html index 2c2f3870..bd05660d 100644 --- a/cdcftdi_8cpp_source.html +++ b/cdcftdi_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcftdi.cpp Source File @@ -31,7 +31,7 @@ - + @@ -117,7 +117,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
26 bAddress(0),
27 bNumEP(1),
28 wFTDIType(0) {
-
29  for (uint8_t i = 0; i < FTDI_MAX_ENDPOINTS; i++) {
+
29  for(uint8_t i = 0; i < FTDI_MAX_ENDPOINTS; i++) {
30  epInfo[i].epAddr = 0;
31  epInfo[i].maxPktSize = (i) ? 0 : 8;
32  epInfo[i].epAttribs = 0;
@@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
34  //if (!i)
35  epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
36  }
-
37  if (pUsb)
+
37  if(pUsb)
38  pUsb->RegisterDeviceClass(this);
39 }
40 
@@ -133,69 +133,69 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
42  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
43 
44  uint8_t buf[constBufSize];
-
45  uint8_t rcode;
-
46  UsbDevice *p = NULL;
-
47  EpInfo *oldep_ptr = NULL;
-
48  //uint8_t len = 0;
-
49  //uint16_t cd_len = 0;
-
50 
-
51  uint8_t num_of_conf; // number of configurations
-
52  //uint8_t num_of_intf; // number of interfaces
-
53 
-
54  AddressPool &addrPool = pUsb->GetAddressPool();
-
55 
-
56  USBTRACE("FTDI Init\r\n");
-
57 
-
58  if (bAddress)
-
59  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
60 
-
61  // Get pointer to pseudo device with address 0 assigned
-
62  p = addrPool.GetUsbDevicePtr(0);
-
63 
-
64  if (!p)
-
65  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
66 
-
67  if (!p->epinfo) {
-
68  USBTRACE("epinfo\r\n");
-
69  return USB_ERROR_EPINFO_IS_NULL;
-
70  }
-
71 
-
72  // Save old pointer to EP_RECORD of address 0
-
73  oldep_ptr = p->epinfo;
-
74 
-
75  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
76  p->epinfo = epInfo;
-
77 
-
78  p->lowspeed = lowspeed;
-
79 
-
80  // Get device descriptor
-
81  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
-
82 
-
83  // Restore p->epinfo
-
84  p->epinfo = oldep_ptr;
-
85 
-
86  if (rcode)
-
87  goto FailGetDevDescr;
-
88 
-
89  if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor != FTDI_VID || ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct != FTDI_PID)
+
45  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
46  uint8_t rcode;
+
47  UsbDevice *p = NULL;
+
48  EpInfo *oldep_ptr = NULL;
+
49  //uint8_t len = 0;
+
50  //uint16_t cd_len = 0;
+
51 
+
52  uint8_t num_of_conf; // number of configurations
+
53  //uint8_t num_of_intf; // number of interfaces
+
54 
+
55  AddressPool &addrPool = pUsb->GetAddressPool();
+
56 
+
57  USBTRACE("FTDI Init\r\n");
+
58 
+
59  if(bAddress)
+
60  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
61 
+
62  // Get pointer to pseudo device with address 0 assigned
+
63  p = addrPool.GetUsbDevicePtr(0);
+
64 
+
65  if(!p)
+
66  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
67 
+
68  if(!p->epinfo) {
+
69  USBTRACE("epinfo\r\n");
+
70  return USB_ERROR_EPINFO_IS_NULL;
+
71  }
+
72 
+
73  // Save old pointer to EP_RECORD of address 0
+
74  oldep_ptr = p->epinfo;
+
75 
+
76  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
77  p->epinfo = epInfo;
+
78 
+
79  p->lowspeed = lowspeed;
+
80 
+
81  // Get device descriptor
+
82  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), buf);
+
83 
+
84  // Restore p->epinfo
+
85  p->epinfo = oldep_ptr;
+
86 
+
87  if(rcode)
+
88  goto FailGetDevDescr;
+
89  if(udd->idVendor != FTDI_VID || udd->idProduct != FTDI_PID)
90  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
91 
92  // Save type of FTDI chip
-
93  wFTDIType = ((USB_DEVICE_DESCRIPTOR*)buf)->bcdDevice;
+
93  wFTDIType = udd->bcdDevice;
94 
95  // Allocate new address according to device class
96  bAddress = addrPool.AllocAddress(parent, false, port);
97 
-
98  if (!bAddress)
+
98  if(!bAddress)
99  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
100 
101  // Extract Max Packet Size from the device descriptor
-
102  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
+
102  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
103 
104  // Assign new address to the device
105  rcode = pUsb->setAddr(0, 0, bAddress);
106 
-
107  if (rcode) {
+
107  if(rcode) {
108  p->lowspeed = false;
109  addrPool.FreeAddress(bAddress);
110  bAddress = 0;
@@ -209,40 +209,40 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
118 
119  p = addrPool.GetUsbDevicePtr(bAddress);
120 
-
121  if (!p)
+
121  if(!p)
122  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
123 
124  p->lowspeed = lowspeed;
125 
-
126  num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;
+
126  num_of_conf = udd->bNumConfigurations;
127 
128  // Assign epInfo to epinfo pointer
129  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
130 
-
131  if (rcode)
+
131  if(rcode)
132  goto FailSetDevTblEntry;
133 
134  USBTRACE2("NC:", num_of_conf);
135 
-
136  for (uint8_t i = 0; i < num_of_conf; i++) {
+
136  for(uint8_t i = 0; i < num_of_conf; i++) {
137  HexDumper<USBReadParser, uint16_t, uint16_t> HexDump;
138  ConfigDescParser < 0xFF, 0xFF, 0xFF, CP_MASK_COMPARE_ALL> confDescrParser(this);
139 
140  rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump);
141 
-
142  if (rcode)
+
142  if(rcode)
143  goto FailGetConfDescr;
144 
145  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
146 
-
147  if (rcode)
+
147  if(rcode)
148  goto FailGetConfDescr;
149 
-
150  if (bNumEP > 1)
+
150  if(bNumEP > 1)
151  break;
152  } // for
153 
-
154  if (bNumEP < 2)
+
154  if(bNumEP < 2)
155  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
156 
157  USBTRACE2("NumEP:", bNumEP);
@@ -255,12 +255,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
164  // Set Configuration Value
165  rcode = pUsb->setConf(bAddress, 0, bConfNum);
166 
-
167  if (rcode)
+
167  if(rcode)
168  goto FailSetConfDescr;
169 
170  rcode = pAsync->OnInit(this);
171 
-
172  if (rcode)
+
172  if(rcode)
173  goto FailOnInit;
174 
175  USBTRACE("FTDI configured\r\n");
@@ -295,183 +295,184 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
204 FailOnInit:
205 #ifdef DEBUG_USB_HOST
206  USBTRACE("OnInit:");
-
207 #endif
-
208 
-
209 Fail:
-
210 #ifdef DEBUG_USB_HOST
-
211  NotifyFail(rcode);
-
212 #endif
-
213  Release();
-
214  return rcode;
-
215 }
-
216 
-
217 void FTDI::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
-
218  ErrorMessage<uint8_t > (PSTR("Conf.Val"), conf);
-
219  ErrorMessage<uint8_t > (PSTR("Iface Num"), iface);
-
220  ErrorMessage<uint8_t > (PSTR("Alt.Set"), alt);
+
207 
+
208 Fail:
+
209  NotifyFail(rcode);
+
210 #endif
+
211  Release();
+
212  return rcode;
+
213 }
+
214 
+
215 void FTDI::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) {
+
216  ErrorMessage<uint8_t > (PSTR("Conf.Val"), conf);
+
217  ErrorMessage<uint8_t > (PSTR("Iface Num"), iface);
+
218  ErrorMessage<uint8_t > (PSTR("Alt.Set"), alt);
+
219 
+
220  bConfNum = conf;
221 
-
222  bConfNum = conf;
+
222  uint8_t index;
223 
-
224  uint8_t index;
-
225 
-
226  if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
-
227  index = epInterruptInIndex;
-
228  else
-
229  if ((pep->bmAttributes & 0x02) == 2)
-
230  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
-
231  else
-
232  return;
-
233 
-
234  // Fill in the endpoint info structure
-
235  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
-
236  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
-
237  epInfo[index].epAttribs = 0;
+
224  if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
+
225  index = epInterruptInIndex;
+
226  else
+
227  if((pep->bmAttributes & 0x02) == 2)
+
228  index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
+
229  else
+
230  return;
+
231 
+
232  // Fill in the endpoint info structure
+
233  epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+
234  epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+
235  epInfo[index].epAttribs = 0;
+
236 
+
237  bNumEP++;
238 
-
239  bNumEP++;
-
240 
-
241  PrintEndpointDescriptor(pep);
-
242 }
-
243 
-
244 uint8_t FTDI::Release() {
-
245  pUsb->GetAddressPool().FreeAddress(bAddress);
-
246 
-
247  bAddress = 0;
-
248  bNumEP = 1;
-
249  qNextPollTime = 0;
-
250  bPollEnable = false;
-
251  return 0;
-
252 }
-
253 
-
254 uint8_t FTDI::Poll() {
-
255  uint8_t rcode = 0;
-
256 
-
257  //if (!bPollEnable)
-
258  // return 0;
-
259 
-
260  //if (qNextPollTime <= millis())
-
261  //{
-
262  // USB_HOST_SERIAL.println(bAddress, HEX);
-
263 
-
264  // qNextPollTime = millis() + 100;
-
265  //}
-
266  return rcode;
-
267 }
-
268 
-
269 uint8_t FTDI::SetBaudRate(uint32_t baud) {
-
270  uint16_t baud_value, baud_index = 0;
-
271  uint32_t divisor3;
+
239  PrintEndpointDescriptor(pep);
+
240 }
+
241 
+
242 uint8_t FTDI::Release() {
+
243  pUsb->GetAddressPool().FreeAddress(bAddress);
+
244 
+
245  bAddress = 0;
+
246  bNumEP = 1;
+
247  qNextPollTime = 0;
+
248  bPollEnable = false;
+
249  return 0;
+
250 }
+
251 
+
252 uint8_t FTDI::Poll() {
+
253  uint8_t rcode = 0;
+
254 
+
255  //if (!bPollEnable)
+
256  // return 0;
+
257 
+
258  //if (qNextPollTime <= millis())
+
259  //{
+
260  // USB_HOST_SERIAL.println(bAddress, HEX);
+
261 
+
262  // qNextPollTime = millis() + 100;
+
263  //}
+
264  return rcode;
+
265 }
+
266 
+
267 uint8_t FTDI::SetBaudRate(uint32_t baud) {
+
268  uint16_t baud_value, baud_index = 0;
+
269  uint32_t divisor3;
+
270 
+
271  divisor3 = 48000000 / 2 / baud; // divisor shifted 3 bits to the left
272 
-
273  divisor3 = 48000000 / 2 / baud; // divisor shifted 3 bits to the left
-
274 
-
275  if (wFTDIType == FT232AM) {
-
276  if ((divisor3 & 0x7) == 7)
-
277  divisor3++; // round x.7/8 up to x+1
-
278 
-
279  baud_value = divisor3 >> 3;
-
280  divisor3 &= 0x7;
-
281 
-
282  if (divisor3 == 1) baud_value |= 0xc000;
-
283  else // 0.125
-
284  if (divisor3 >= 4) baud_value |= 0x4000;
-
285  else // 0.5
-
286  if (divisor3 != 0) baud_value |= 0x8000; // 0.25
-
287  if (baud_value == 1) baud_value = 0; /* special case for maximum baud rate */
-
288  } else {
-
289  static const unsigned char divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3};
-
290  static const unsigned char divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1};
-
291 
-
292  baud_value = divisor3 >> 3;
-
293  baud_value |= divfrac [divisor3 & 0x7] << 14;
-
294  baud_index = divindex[divisor3 & 0x7];
-
295 
-
296  /* Deal with special cases for highest baud rates. */
-
297  if (baud_value == 1) baud_value = 0;
-
298  else // 1.0
-
299  if (baud_value == 0x4001) baud_value = 1; // 1.5
-
300  }
-
301  USBTRACE2("baud_value:", baud_value);
-
302  USBTRACE2("baud_index:", baud_index);
-
303  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL);
-
304 }
-
305 
-
306 uint8_t FTDI::SetModemControl(uint16_t signal) {
-
307  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL);
-
308 }
-
309 
-
310 uint8_t FTDI::SetFlowControl(uint8_t protocol, uint8_t xon, uint8_t xoff) {
-
311  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL);
-
312 }
-
313 
-
314 uint8_t FTDI::SetData(uint16_t databm) {
-
315  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL);
-
316 }
-
317 
-
318 uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
-
319  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
-
320 }
-
321 
-
322 uint8_t FTDI::SndData(uint16_t nbytes, uint8_t *dataptr) {
-
323  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
-
324 }
-
325 
-
326 void FTDI::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
-
327  Notify(PSTR("Endpoint descriptor:"), 0x80);
-
328  Notify(PSTR("\r\nLength:\t\t"), 0x80);
-
329  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
-
330  Notify(PSTR("\r\nType:\t\t"), 0x80);
-
331  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
-
332  Notify(PSTR("\r\nAddress:\t"), 0x80);
-
333  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
-
334  Notify(PSTR("\r\nAttributes:\t"), 0x80);
-
335  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
-
336  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
-
337  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
-
338  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
-
339  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
-
340  Notify(PSTR("\r\n"), 0x80);
-
341 }
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
273  if(wFTDIType == FT232AM) {
+
274  if((divisor3 & 0x7) == 7)
+
275  divisor3++; // round x.7/8 up to x+1
+
276 
+
277  baud_value = divisor3 >> 3;
+
278  divisor3 &= 0x7;
+
279 
+
280  if(divisor3 == 1) baud_value |= 0xc000;
+
281  else // 0.125
+
282  if(divisor3 >= 4) baud_value |= 0x4000;
+
283  else // 0.5
+
284  if(divisor3 != 0) baud_value |= 0x8000; // 0.25
+
285  if(baud_value == 1) baud_value = 0; /* special case for maximum baud rate */
+
286  } else {
+
287  static const unsigned char divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3};
+
288  static const unsigned char divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1};
+
289 
+
290  baud_value = divisor3 >> 3;
+
291  baud_value |= divfrac [divisor3 & 0x7] << 14;
+
292  baud_index = divindex[divisor3 & 0x7];
+
293 
+
294  /* Deal with special cases for highest baud rates. */
+
295  if(baud_value == 1) baud_value = 0;
+
296  else // 1.0
+
297  if(baud_value == 0x4001) baud_value = 1; // 1.5
+
298  }
+
299  USBTRACE2("baud_value:", baud_value);
+
300  USBTRACE2("baud_index:", baud_index);
+
301  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL);
+
302 }
+
303 
+
304 uint8_t FTDI::SetModemControl(uint16_t signal) {
+
305  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL);
+
306 }
+
307 
+
308 uint8_t FTDI::SetFlowControl(uint8_t protocol, uint8_t xon, uint8_t xoff) {
+
309  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL);
+
310 }
+
311 
+
312 uint8_t FTDI::SetData(uint16_t databm) {
+
313  return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL);
+
314 }
+
315 
+
316 uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) {
+
317  return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
+
318 }
+
319 
+
320 uint8_t FTDI::SndData(uint16_t nbytes, uint8_t *dataptr) {
+
321  return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
+
322 }
+
323 
+
324 void FTDI::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
+
325  Notify(PSTR("Endpoint descriptor:"), 0x80);
+
326  Notify(PSTR("\r\nLength:\t\t"), 0x80);
+
327  PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
+
328  Notify(PSTR("\r\nType:\t\t"), 0x80);
+
329  PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
+
330  Notify(PSTR("\r\nAddress:\t"), 0x80);
+
331  PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
+
332  Notify(PSTR("\r\nAttributes:\t"), 0x80);
+
333  PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
+
334  Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
+
335  PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
+
336  Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
+
337  PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
+
338  Notify(PSTR("\r\n"), 0x80);
+
339 }
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
AddressPool
Definition: address.h:83
bmREQ_FTDI_OUT
#define bmREQ_FTDI_OUT
Definition: cdcftdi.h:22
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
-
FTDI::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcftdi.cpp:217
+
FTDI::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcftdi.cpp:215
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
-
FTDI::SetBaudRate
uint8_t SetBaudRate(uint32_t baud)
Definition: cdcftdi.cpp:269
+
FTDI::SetBaudRate
uint8_t SetBaudRate(uint32_t baud)
Definition: cdcftdi.cpp:267
EpInfo::bmNakPower
uint8_t bmNakPower
Definition: address.h:42
FT232AM
#define FT232AM
Definition: cdcftdi.h:31
UsbDevice
Definition: address.h:75
-
FTDI::SetModemControl
uint8_t SetModemControl(uint16_t control)
Definition: cdcftdi.cpp:306
+
USB_DEVICE_DESCRIPTOR::bcdDevice
uint16_t bcdDevice
Definition: usb_ch9.h:108
+
FTDI::SetModemControl
uint8_t SetModemControl(uint16_t control)
Definition: cdcftdi.cpp:304
+
USB_DEVICE_DESCRIPTOR::idVendor
uint16_t idVendor
Definition: usb_ch9.h:106
HexDumper
Definition: hexdump.h:25
FTDI_SIO_SET_BAUD_RATE
#define FTDI_SIO_SET_BAUD_RATE
Definition: cdcftdi.h:40
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
USB_ENDPOINT_DESCRIPTOR::bInterval
uint8_t bInterval
Definition: usb_ch9.h:147
USB_ENDPOINT_DESCRIPTOR::bLength
uint8_t bLength
Definition: usb_ch9.h:142
+
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
FTDI::FTDI
FTDI(USB *pusb, FTDIAsyncOper *pasync)
Definition: cdcftdi.cpp:23
cdcftdi.h
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
FTDI_SIO_SET_DATA
#define FTDI_SIO_SET_DATA
Definition: cdcftdi.h:41
-
FTDI::SetFlowControl
uint8_t SetFlowControl(uint8_t protocol, uint8_t xon=0x11, uint8_t xoff=0x13)
Definition: cdcftdi.cpp:310
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
+
FTDI::SetFlowControl
uint8_t SetFlowControl(uint8_t protocol, uint8_t xon=0x11, uint8_t xoff=0x13)
Definition: cdcftdi.cpp:308
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
FTDIAsyncOper
Definition: cdcftdi.h:79
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
-
FTDI::RcvData
uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
Definition: cdcftdi.cpp:318
+
FTDI::RcvData
uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
Definition: cdcftdi.cpp:316
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
EpInfo::epAttribs
uint8_t epAttribs
Definition: address.h:37
USB::ctrlReq
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
Notify
#define Notify(...)
Definition: message.h:44
USB_ENDPOINT_DESCRIPTOR::bmAttributes
uint8_t bmAttributes
Definition: usb_ch9.h:145
-
ConfigDescParser
Definition: confdescparser.h:39
-
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:61
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
ConfigDescParser
Definition: confdescparser.h:38
+
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:67
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
NotifyFailGetConfDescr
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
EpInfo::epAddr
uint8_t epAddr
Definition: address.h:33
USB_NAK_MAX_POWER
#define USB_NAK_MAX_POWER
Definition: address.h:27
-
FTDI::Poll
virtual uint8_t Poll()
Definition: cdcftdi.cpp:254
+
FTDI::Poll
virtual uint8_t Poll()
Definition: cdcftdi.cpp:252
EpInfo
Definition: address.h:32
-
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
+
USB::outTransfer
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:292
USB_ENDPOINT_DESCRIPTOR::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usb_ch9.h:146
FTDI_PID
#define FTDI_PID
Definition: cdcftdi.h:29
FTDI::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: cdcftdi.cpp:41
@@ -479,25 +480,27 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
USB_ENDPOINT_DESCRIPTOR::bEndpointAddress
uint8_t bEndpointAddress
Definition: usb_ch9.h:144
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
-
FTDI::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcftdi.cpp:322
+
FTDI::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcftdi.cpp:320
USB_ENDPOINT_DESCRIPTOR::bDescriptorType
uint8_t bDescriptorType
Definition: usb_ch9.h:143
FTDIAsyncOper::OnInit
virtual uint8_t OnInit(FTDI *pftdi)=0
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
FTDI_VID
#define FTDI_VID
Definition: cdcftdi.h:28
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
-
FTDI::Release
virtual uint8_t Release()
Definition: cdcftdi.cpp:244
+
FTDI::Release
virtual uint8_t Release()
Definition: cdcftdi.cpp:242
+
USB_DEVICE_DESCRIPTOR::idProduct
uint16_t idProduct
Definition: usb_ch9.h:107
+
USB_DEVICE_DESCRIPTOR::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:112
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
FTDI_SIO_MODEM_CTRL
#define FTDI_SIO_MODEM_CTRL
Definition: cdcftdi.h:38
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB
Definition: UsbCore.h:152
-
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB
Definition: UsbCore.h:176
+
USB::RegisterDeviceClass
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:196
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
FTDI::SetData
uint8_t SetData(uint16_t databm)
Definition: cdcftdi.cpp:314
+
FTDI::SetData
uint8_t SetData(uint16_t databm)
Definition: cdcftdi.cpp:312
FTDI_MAX_ENDPOINTS
#define FTDI_MAX_ENDPOINTS
Definition: cdcftdi.h:87
-
USBTRACE
#define USBTRACE(s)
Definition: macros.h:60
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
USBTRACE
#define USBTRACE(s)
Definition: macros.h:65
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
@@ -505,7 +508,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/cdcftdi_8h.html b/cdcftdi_8h.html index 6cb3b53d..1e9bf198 100644 --- a/cdcftdi_8h.html +++ b/cdcftdi_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcftdi.h File Reference @@ -31,7 +31,7 @@ - + @@ -814,7 +814,7 @@ Macros diff --git a/cdcftdi_8h_source.html b/cdcftdi_8h_source.html index dcf8e79d..b1085a10 100644 --- a/cdcftdi_8h_source.html +++ b/cdcftdi_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcftdi.h Source File @@ -31,7 +31,7 @@ - + @@ -222,34 +222,34 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
131 };
132 
133 #endif // __CDCFTDI_H__
-
FTDI::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcftdi.cpp:217
-
FTDI::SetBaudRate
uint8_t SetBaudRate(uint32_t baud)
Definition: cdcftdi.cpp:269
-
FTDI::SetModemControl
uint8_t SetModemControl(uint16_t control)
Definition: cdcftdi.cpp:306
+
FTDI::EndpointXtract
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: cdcftdi.cpp:215
+
FTDI::SetBaudRate
uint8_t SetBaudRate(uint32_t baud)
Definition: cdcftdi.cpp:267
+
FTDI::SetModemControl
uint8_t SetModemControl(uint16_t control)
Definition: cdcftdi.cpp:304
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:141
FTDI::FTDI
FTDI(USB *pusb, FTDIAsyncOper *pasync)
Definition: cdcftdi.cpp:23
-
FTDI::SetFlowControl
uint8_t SetFlowControl(uint8_t protocol, uint8_t xon=0x11, uint8_t xoff=0x13)
Definition: cdcftdi.cpp:310
+
FTDI::SetFlowControl
uint8_t SetFlowControl(uint8_t protocol, uint8_t xon=0x11, uint8_t xoff=0x13)
Definition: cdcftdi.cpp:308
USBDeviceConfig
Definition: UsbCore.h:105
FTDIAsyncOper
Definition: cdcftdi.h:79
Usb.h
-
FTDI::RcvData
uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
Definition: cdcftdi.cpp:318
-
FTDI::Poll
virtual uint8_t Poll()
Definition: cdcftdi.cpp:254
+
FTDI::RcvData
uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
Definition: cdcftdi.cpp:316
+
FTDI::Poll
virtual uint8_t Poll()
Definition: cdcftdi.cpp:252
EpInfo
Definition: address.h:32
FTDI
Definition: cdcftdi.h:89
FTDI::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: cdcftdi.cpp:41
-
FTDI::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcftdi.cpp:322
+
FTDI::SndData
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: cdcftdi.cpp:320
FTDI::GetAddress
virtual uint8_t GetAddress()
Definition: cdcftdi.h:125
-
UsbConfigXtracter
Definition: confdescparser.h:24
+
UsbConfigXtracter
Definition: confdescparser.h:23
FTDIAsyncOper::OnInit
virtual uint8_t OnInit(FTDI *pftdi)=0
-
FTDI::Release
virtual uint8_t Release()
Definition: cdcftdi.cpp:244
-
USB
Definition: UsbCore.h:152
-
FTDI::SetData
uint8_t SetData(uint16_t databm)
Definition: cdcftdi.cpp:314
+
FTDI::Release
virtual uint8_t Release()
Definition: cdcftdi.cpp:242
+
USB
Definition: UsbCore.h:176
+
FTDI::SetData
uint8_t SetData(uint16_t databm)
Definition: cdcftdi.cpp:312
FTDI_MAX_ENDPOINTS
#define FTDI_MAX_ENDPOINTS
Definition: cdcftdi.h:87
diff --git a/cdcprolific_8cpp.html b/cdcprolific_8cpp.html index 8afe9dc5..222d7a4e 100644 --- a/cdcprolific_8cpp.html +++ b/cdcprolific_8cpp.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcprolific.cpp File Reference @@ -31,7 +31,7 @@ - + @@ -104,7 +104,7 @@ Include dependency graph for cdcprolific.cpp: diff --git a/cdcprolific_8cpp_source.html b/cdcprolific_8cpp_source.html index 992bb191..3535bc7a 100644 --- a/cdcprolific_8cpp_source.html +++ b/cdcprolific_8cpp_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcprolific.cpp Source File @@ -31,7 +31,7 @@ - + @@ -116,235 +116,239 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
25  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
26 
27  uint8_t buf[constBufSize];
-
28  uint8_t rcode;
-
29  UsbDevice *p = NULL;
-
30  EpInfo *oldep_ptr = NULL;
-
31  uint8_t num_of_conf; // number of configurations
-
32 
-
33  AddressPool &addrPool = pUsb->GetAddressPool();
-
34 
-
35  USBTRACE("PL Init\r\n");
-
36 
-
37  if (bAddress)
-
38  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
-
39 
-
40  // Get pointer to pseudo device with address 0 assigned
-
41  p = addrPool.GetUsbDevicePtr(0);
-
42 
-
43  if (!p)
-
44  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
45 
-
46  if (!p->epinfo) {
-
47  USBTRACE("epinfo\r\n");
-
48  return USB_ERROR_EPINFO_IS_NULL;
-
49  }
-
50 
-
51  // Save old pointer to EP_RECORD of address 0
-
52  oldep_ptr = p->epinfo;
-
53 
-
54  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
-
55  p->epinfo = epInfo;
-
56 
-
57  p->lowspeed = lowspeed;
-
58 
-
59  // Get device descriptor
-
60  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
-
61 
-
62  // Restore p->epinfo
-
63  p->epinfo = oldep_ptr;
-
64 
-
65  if (rcode)
-
66  goto FailGetDevDescr;
-
67 
-
68  if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor != PL_VID && ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct != PL_PID)
-
69  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
70 
-
71  // Save type of PL chip
-
72  wPLType = ((USB_DEVICE_DESCRIPTOR*)buf)->bcdDevice;
-
73 
-
74  // Allocate new address according to device class
-
75  bAddress = addrPool.AllocAddress(parent, false, port);
-
76 
-
77  if (!bAddress)
-
78  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
-
79 
-
80  // Extract Max Packet Size from the device descriptor
-
81  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
-
82 
-
83  // Assign new address to the device
-
84  rcode = pUsb->setAddr(0, 0, bAddress);
-
85 
-
86  if (rcode) {
-
87  p->lowspeed = false;
-
88  addrPool.FreeAddress(bAddress);
-
89  bAddress = 0;
-
90  USBTRACE2("setAddr:", rcode);
-
91  return rcode;
-
92  }
-
93 
-
94  USBTRACE2("Addr:", bAddress);
-
95 
-
96  p->lowspeed = false;
-
97 
-
98  p = addrPool.GetUsbDevicePtr(bAddress);
-
99 
-
100  if (!p)
-
101  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
-
102 
-
103  p->lowspeed = lowspeed;
-
104 
-
105  num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;
-
106 
-
107  // Assign epInfo to epinfo pointer
-
108  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
-
109 
-
110  if (rcode)
-
111  goto FailSetDevTblEntry;
-
112 
-
113  USBTRACE2("NC:", num_of_conf);
-
114 
-
115  for (uint8_t i = 0; i < num_of_conf; i++) {
-
116  HexDumper<USBReadParser, uint16_t, uint16_t> HexDump;
-
117  ConfigDescParser < 0xFF, 0, 0, CP_MASK_COMPARE_CLASS> confDescrParser(this);
-
118 
-
119  rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump);
-
120 
-
121  if (rcode)
-
122  goto FailGetConfDescr;
-
123 
-
124  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
-
125 
-
126  if (rcode)
-
127  goto FailGetConfDescr;
-
128 
-
129  if (bNumEP > 1)
-
130  break;
-
131  } // for
-
132 
-
133  if (bNumEP < 2)
-
134  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
-
135 
-
136  // Assign epInfo to epinfo pointer
-
137  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
-
138 
-
139  USBTRACE2("Conf:", bConfNum);
-
140 
-
141  // Set Configuration Value
-
142  rcode = pUsb->setConf(bAddress, 0, bConfNum);
-
143 
-
144  if (rcode)
-
145  goto FailSetConfDescr;
-
146 
-
147  rcode = pAsync->OnInit(this);
-
148 
-
149  if (rcode)
-
150  goto FailOnInit;
-
151 
-
152  USBTRACE("PL configured\r\n");
-
153 
-
154  //bPollEnable = true;
-
155  ready = true;
-
156  return 0;
-
157 
-
158 FailGetDevDescr:
-
159 #ifdef DEBUG_USB_HOST
-
160  NotifyFailGetDevDescr();
-
161  goto Fail;
-
162 #endif
-
163 
-
164 FailSetDevTblEntry:
-
165 #ifdef DEBUG_USB_HOST
-
166  NotifyFailSetDevTblEntry();
-
167  goto Fail;
-
168 #endif
-
169 
-
170 FailGetConfDescr:
-
171 #ifdef DEBUG_USB_HOST
-
172  NotifyFailGetConfDescr();
-
173  goto Fail;
-
174 #endif
-
175 
-
176 FailSetConfDescr:
-
177 #ifdef DEBUG_USB_HOST
-
178  NotifyFailSetConfDescr();
-
179  goto Fail;
-
180 #endif
-
181 
-
182 FailOnInit:
-
183 #ifdef DEBUG_USB_HOST
-
184  USBTRACE("OnInit:");
-
185 #endif
-
186 
-
187 Fail:
+
28  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
+
29  uint8_t rcode;
+
30  UsbDevice *p = NULL;
+
31  EpInfo *oldep_ptr = NULL;
+
32  uint8_t num_of_conf; // number of configurations
+
33 
+
34  AddressPool &addrPool = pUsb->GetAddressPool();
+
35 
+
36  USBTRACE("PL Init\r\n");
+
37 
+
38  if(bAddress)
+
39  return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
+
40 
+
41  // Get pointer to pseudo device with address 0 assigned
+
42  p = addrPool.GetUsbDevicePtr(0);
+
43 
+
44  if(!p)
+
45  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
46 
+
47  if(!p->epinfo) {
+
48  USBTRACE("epinfo\r\n");
+
49  return USB_ERROR_EPINFO_IS_NULL;
+
50  }
+
51 
+
52  // Save old pointer to EP_RECORD of address 0
+
53  oldep_ptr = p->epinfo;
+
54 
+
55  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
+
56  p->epinfo = epInfo;
+
57 
+
58  p->lowspeed = lowspeed;
+
59 
+
60  // Get device descriptor
+
61  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);
+
62 
+
63  // Restore p->epinfo
+
64  p->epinfo = oldep_ptr;
+
65 
+
66  if(rcode)
+
67  goto FailGetDevDescr;
+
68 
+
69  if(udd->idVendor != PL_VID && udd->idProduct != PL_PID)
+
70  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
71 
+
72  // Save type of PL chip
+
73  wPLType = udd->bcdDevice;
+
74 
+
75  // Allocate new address according to device class
+
76  bAddress = addrPool.AllocAddress(parent, false, port);
+
77 
+
78  if(!bAddress)
+
79  return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
+
80 
+
81  // Extract Max Packet Size from the device descriptor
+
82  epInfo[0].maxPktSize = udd->bMaxPacketSize0;
+
83 
+
84  // Assign new address to the device
+
85  rcode = pUsb->setAddr(0, 0, bAddress);
+
86 
+
87  if(rcode) {
+
88  p->lowspeed = false;
+
89  addrPool.FreeAddress(bAddress);
+
90  bAddress = 0;
+
91  USBTRACE2("setAddr:", rcode);
+
92  return rcode;
+
93  }
+
94 
+
95  USBTRACE2("Addr:", bAddress);
+
96 
+
97  p->lowspeed = false;
+
98 
+
99  p = addrPool.GetUsbDevicePtr(bAddress);
+
100 
+
101  if(!p)
+
102  return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
+
103 
+
104  p->lowspeed = lowspeed;
+
105 
+
106  num_of_conf = udd->bNumConfigurations;
+
107 
+
108  // Assign epInfo to epinfo pointer
+
109  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
+
110 
+
111  if(rcode)
+
112  goto FailSetDevTblEntry;
+
113 
+
114  USBTRACE2("NC:", num_of_conf);
+
115 
+
116  for(uint8_t i = 0; i < num_of_conf; i++) {
+
117  HexDumper<USBReadParser, uint16_t, uint16_t> HexDump;
+
118  ConfigDescParser < 0xFF, 0, 0, CP_MASK_COMPARE_CLASS> confDescrParser(this);
+
119 
+
120  rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump);
+
121 
+
122  if(rcode)
+
123  goto FailGetConfDescr;
+
124 
+
125  rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
+
126 
+
127  if(rcode)
+
128  goto FailGetConfDescr;
+
129 
+
130  if(bNumEP > 1)
+
131  break;
+
132  } // for
+
133 
+
134  if(bNumEP < 2)
+
135  return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
+
136 
+
137  // Assign epInfo to epinfo pointer
+
138  rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
+
139 
+
140  USBTRACE2("Conf:", bConfNum);
+
141 
+
142  // Set Configuration Value
+
143  rcode = pUsb->setConf(bAddress, 0, bConfNum);
+
144 
+
145  if(rcode)
+
146  goto FailSetConfDescr;
+
147 
+
148  rcode = pAsync->OnInit(this);
+
149 
+
150  if(rcode)
+
151  goto FailOnInit;
+
152 
+
153  USBTRACE("PL configured\r\n");
+
154 
+
155  //bPollEnable = true;
+
156  ready = true;
+
157  return 0;
+
158 
+
159 FailGetDevDescr:
+
160 #ifdef DEBUG_USB_HOST
+
161  NotifyFailGetDevDescr();
+
162  goto Fail;
+
163 #endif
+
164 
+
165 FailSetDevTblEntry:
+
166 #ifdef DEBUG_USB_HOST
+
167  NotifyFailSetDevTblEntry();
+
168  goto Fail;
+
169 #endif
+
170 
+
171 FailGetConfDescr:
+
172 #ifdef DEBUG_USB_HOST
+
173  NotifyFailGetConfDescr();
+
174  goto Fail;
+
175 #endif
+
176 
+
177 FailSetConfDescr:
+
178 #ifdef DEBUG_USB_HOST
+
179  NotifyFailSetConfDescr();
+
180  goto Fail;
+
181 #endif
+
182 
+
183 FailOnInit:
+
184 #ifdef DEBUG_USB_HOST
+
185  USBTRACE("OnInit:");
+
186 #endif
+
187 
188 #ifdef DEBUG_USB_HOST
-
189  NotifyFail(rcode);
-
190 #endif
-
191  Release();
-
192  return rcode;
-
193 }
-
194 
-
195 //uint8_t PL::Poll()
-
196 //{
-
197 // uint8_t rcode = 0;
-
198 //
-
199 // //if (!bPollEnable)
-
200 // // return 0;
-
201 //
-
202 // //if (qNextPollTime <= millis())
-
203 // //{
-
204 // // USB_HOST_SERIAL.println(bAddress, HEX);
-
205 //
-
206 // // qNextPollTime = millis() + 100;
-
207 // //}
-
208 // return rcode;
-
209 //}
-
210 
-
211 
-
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:764
+
189 Fail:
+
190  NotifyFail(rcode);
+
191 #endif
+
192  Release();
+
193  return rcode;
+
194 }
+
195 
+
196 //uint8_t PL::Poll()
+
197 //{
+
198 // uint8_t rcode = 0;
+
199 //
+
200 // //if (!bPollEnable)
+
201 // // return 0;
+
202 //
+
203 // //if (qNextPollTime <= millis())
+
204 // //{
+
205 // // USB_HOST_SERIAL.println(bAddress, HEX);
+
206 //
+
207 // // qNextPollTime = millis() + 100;
+
208 // //}
+
209 // return rcode;
+
210 //}
+
USB::getConfDescr
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition: Usb.cpp:766
AddressPool
Definition: address.h:83
UsbDevice::epinfo
EpInfo * epinfo
Definition: address.h:76
UsbDevice::lowspeed
bool lowspeed
Definition: address.h:79
USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
UsbDevice
Definition: address.h:75
+
USB_DEVICE_DESCRIPTOR::bcdDevice
uint16_t bcdDevice
Definition: usb_ch9.h:108
PL_PID
#define PL_PID
Definition: cdcprolific.h:23
PL2303::Init
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: cdcprolific.cpp:24
+
USB_DEVICE_DESCRIPTOR::idVendor
uint16_t idVendor
Definition: usb_ch9.h:106
PL2303::PL2303
PL2303(USB *pusb, CDCAsyncOper *pasync)
Definition: cdcprolific.cpp:19
HexDumper
Definition: hexdump.h:25
-
ACM::ready
bool ready
Definition: cdcacm.h:154
+
USB_DEVICE_DESCRIPTOR::bMaxPacketSize0
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:105
+
ACM::ready
bool ready
Definition: cdcacm.h:153
NotifyFail
#define NotifyFail(...)
Definition: message.h:55
-
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:145
-
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
-
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:151
-
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:156
+
ACM::pUsb
USB * pUsb
Definition: cdcacm.h:144
+
USB::setConf
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:805
+
ACM::bNumEP
uint8_t bNumEP
Definition: cdcacm.h:150
+
ACM::epInfo
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition: cdcacm.h:155
NotifyFailGetDevDescr
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
USB::setEpInfoEntry
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
AddressPool::FreeAddress
virtual void FreeAddress(uint8_t addr)=0
AddressPool::GetUsbDevicePtr
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
-
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:146
-
ConfigDescParser
Definition: confdescparser.h:39
-
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:61
-
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
+
ACM::pAsync
CDCAsyncOper * pAsync
Definition: cdcacm.h:145
+
ConfigDescParser
Definition: confdescparser.h:38
+
USBTRACE2
#define USBTRACE2(s, r)
Definition: macros.h:67
+
USB::setAddr
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:796
NotifyFailGetConfDescr
#define NotifyFailGetConfDescr(...)
Definition: message.h:52
EpInfo
Definition: address.h:32
PL_VID
#define PL_VID
Definition: cdcprolific.h:22
cdcprolific.h
AddressPool::AllocAddress
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
-
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:147
+
ACM::bAddress
uint8_t bAddress
Definition: cdcacm.h:146
USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
-
CDCAsyncOper
Definition: cdcacm.h:129
+
CDCAsyncOper
Definition: cdcacm.h:128
USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
-
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:249
-
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:148
+
USB_DEVICE_DESCRIPTOR::idProduct
uint16_t idProduct
Definition: usb_ch9.h:107
+
ACM::Release
virtual uint8_t Release()
Definition: cdcacm.cpp:251
+
ACM::bConfNum
uint8_t bConfNum
Definition: cdcacm.h:147
+
USB_DEVICE_DESCRIPTOR::bNumConfigurations
uint8_t bNumConfigurations
Definition: usb_ch9.h:112
USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
CDCAsyncOper::OnInit
virtual uint8_t OnInit(ACM *pacm)=0
EpInfo::maxPktSize
uint8_t maxPktSize
Definition: address.h:34
-
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
-
USB
Definition: UsbCore.h:152
-
ACM
Definition: cdcacm.h:139
+
USB::GetAddressPool
AddressPool & GetAddressPool()
Definition: UsbCore.h:192
+
USB
Definition: UsbCore.h:176
+
ACM
Definition: cdcacm.h:138
NotifyFailSetConfDescr
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
-
USBTRACE
#define USBTRACE(s)
Definition: macros.h:60
-
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
+
USBTRACE
#define USBTRACE(s)
Definition: macros.h:65
+
USB::getDevDescr
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:761
NotifyFailSetDevTblEntry
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51
USB_DEVICE_DESCRIPTOR
Definition: usb_ch9.h:98
@@ -352,7 +356,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/cdcprolific_8h.html b/cdcprolific_8h.html index 975bccbf..5de418a7 100644 --- a/cdcprolific_8h.html +++ b/cdcprolific_8h.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcprolific.h File Reference @@ -31,7 +31,7 @@ - + @@ -1098,15 +1098,15 @@ Enumerations
- - - - -
Enumerator
kXOnSent  +
Enumerator
kXOnSent 
kXOffSent  +
kXOffSent 
kXO_Idle  +
kXO_Idle 
kXOffNeeded  +
kXOffNeeded 
kXOnNeeded  +
kXOnNeeded 
@@ -1124,15 +1124,15 @@ Enumerations
- - - - -
Enumerator
unknown  +
Enumerator
unknown 
type_1  +
type_1 
rev_X  +
rev_X 
rev_HX  +
rev_HX 
rev_H  +
rev_H 
@@ -1145,7 +1145,7 @@ Enumerations diff --git a/cdcprolific_8h_source.html b/cdcprolific_8h_source.html index bcc0c049..3e4d4139 100644 --- a/cdcprolific_8h_source.html +++ b/cdcprolific_8h_source.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: cdcprolific.h Source File @@ -31,7 +31,7 @@
- + @@ -236,17 +236,17 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
kXOnNeeded
Definition: cdcprolific.h:65
pl2303_type
pl2303_type
Definition: cdcprolific.h:107
cdcacm.h
-
CDCAsyncOper
Definition: cdcacm.h:129
+
CDCAsyncOper
Definition: cdcacm.h:128
PL2303
Definition: cdcprolific.h:118
kXO_Idle
Definition: cdcprolific.h:63
-
USB
Definition: UsbCore.h:152
-
ACM
Definition: cdcacm.h:139
+
USB
Definition: UsbCore.h:176
+
ACM
Definition: cdcacm.h:138
diff --git a/class_a_c_m-members.html b/class_a_c_m-members.html index d74ffb0d..26a310de 100644 --- a/class_a_c_m-members.html +++ b/class_a_c_m-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_a_c_m.html b/class_a_c_m.html index ada8e7bd..54250739 100644 --- a/class_a_c_m.html +++ b/class_a_c_m.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: ACM Class Reference @@ -31,7 +31,7 @@ - + @@ -197,7 +197,7 @@ Static Protected Attributes

Detailed Description

-

Definition at line 139 of file cdcacm.h.

+

Definition at line 138 of file cdcacm.h.

Constructor & Destructor Documentation

@@ -250,7 +250,7 @@ Static Protected Attributes
-

Definition at line 334 of file cdcacm.cpp.

+

Definition at line 336 of file cdcacm.cpp.

@@ -284,7 +284,7 @@ Static Protected Attributes
-

Definition at line 306 of file cdcacm.cpp.

+

Definition at line 308 of file cdcacm.cpp.

@@ -318,7 +318,7 @@ Static Protected Attributes
-

Definition at line 310 of file cdcacm.cpp.

+

Definition at line 312 of file cdcacm.cpp.

@@ -336,7 +336,7 @@ Static Protected Attributes
-

Definition at line 314 of file cdcacm.cpp.

+

Definition at line 316 of file cdcacm.cpp.

@@ -354,7 +354,7 @@ Static Protected Attributes
-

Definition at line 318 of file cdcacm.cpp.

+

Definition at line 320 of file cdcacm.cpp.

@@ -372,7 +372,7 @@ Static Protected Attributes
-

Definition at line 322 of file cdcacm.cpp.

+

Definition at line 324 of file cdcacm.cpp.

@@ -390,7 +390,7 @@ Static Protected Attributes
-

Definition at line 326 of file cdcacm.cpp.

+

Definition at line 328 of file cdcacm.cpp.

@@ -408,7 +408,7 @@ Static Protected Attributes
-

Definition at line 330 of file cdcacm.cpp.

+

Definition at line 332 of file cdcacm.cpp.

@@ -462,7 +462,7 @@ Static Protected Attributes
-

Definition at line 298 of file cdcacm.cpp.

+

Definition at line 300 of file cdcacm.cpp.

@@ -490,7 +490,7 @@ Static Protected Attributes
-

Definition at line 302 of file cdcacm.cpp.

+

Definition at line 304 of file cdcacm.cpp.

@@ -563,7 +563,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 249 of file cdcacm.cpp.

+

Definition at line 251 of file cdcacm.cpp.

@@ -590,7 +590,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 262 of file cdcacm.cpp.

+

Definition at line 264 of file cdcacm.cpp.

@@ -617,7 +617,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 181 of file cdcacm.h.

+

Definition at line 180 of file cdcacm.h.

@@ -642,7 +642,7 @@ Static Protected Attributes
-

Definition at line 185 of file cdcacm.h.

+

Definition at line 184 of file cdcacm.h.

@@ -698,7 +698,7 @@ Static Protected Attributes

Implements UsbConfigXtracter.

-

Definition at line 222 of file cdcacm.cpp.

+

Definition at line 224 of file cdcacm.cpp.

@@ -721,7 +721,7 @@ Static Protected Attributes
-

Definition at line 141 of file cdcacm.h.

+

Definition at line 140 of file cdcacm.h.

@@ -743,7 +743,7 @@ Static Protected Attributes
-

Definition at line 142 of file cdcacm.h.

+

Definition at line 141 of file cdcacm.h.

@@ -765,7 +765,7 @@ Static Protected Attributes
-

Definition at line 143 of file cdcacm.h.

+

Definition at line 142 of file cdcacm.h.

@@ -787,7 +787,7 @@ Static Protected Attributes
-

Definition at line 145 of file cdcacm.h.

+

Definition at line 144 of file cdcacm.h.

@@ -809,7 +809,7 @@ Static Protected Attributes
-

Definition at line 146 of file cdcacm.h.

+

Definition at line 145 of file cdcacm.h.

@@ -831,7 +831,7 @@ Static Protected Attributes
-

Definition at line 147 of file cdcacm.h.

+

Definition at line 146 of file cdcacm.h.

@@ -853,7 +853,7 @@ Static Protected Attributes
-

Definition at line 148 of file cdcacm.h.

+

Definition at line 147 of file cdcacm.h.

@@ -875,7 +875,7 @@ Static Protected Attributes
-

Definition at line 149 of file cdcacm.h.

+

Definition at line 148 of file cdcacm.h.

@@ -897,7 +897,7 @@ Static Protected Attributes
-

Definition at line 150 of file cdcacm.h.

+

Definition at line 149 of file cdcacm.h.

@@ -919,7 +919,7 @@ Static Protected Attributes
-

Definition at line 151 of file cdcacm.h.

+

Definition at line 150 of file cdcacm.h.

@@ -941,7 +941,7 @@ Static Protected Attributes
-

Definition at line 152 of file cdcacm.h.

+

Definition at line 151 of file cdcacm.h.

@@ -963,7 +963,7 @@ Static Protected Attributes
-

Definition at line 153 of file cdcacm.h.

+

Definition at line 152 of file cdcacm.h.

@@ -985,7 +985,7 @@ Static Protected Attributes
-

Definition at line 154 of file cdcacm.h.

+

Definition at line 153 of file cdcacm.h.

@@ -1007,7 +1007,7 @@ Static Protected Attributes
-

Definition at line 156 of file cdcacm.h.

+

Definition at line 155 of file cdcacm.h.

@@ -1020,7 +1020,7 @@ Static Protected Attributes diff --git a/class_a_d_k-members.html b/class_a_d_k-members.html index 774ab07d..6b1b2d1d 100644 --- a/class_a_d_k-members.html +++ b/class_a_d_k-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -117,7 +117,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_a_d_k.html b/class_a_d_k.html index b2b368ed..24a359b2 100644 --- a/class_a_d_k.html +++ b/class_a_d_k.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: ADK Class Reference @@ -31,7 +31,7 @@ - + @@ -252,7 +252,7 @@ Static Protected Attributes
-

Definition at line 345 of file adk.cpp.

+

Definition at line 356 of file adk.cpp.

@@ -280,7 +280,7 @@ Static Protected Attributes
-

Definition at line 335 of file adk.cpp.

+

Definition at line 346 of file adk.cpp.

@@ -308,7 +308,7 @@ Static Protected Attributes
-

Definition at line 341 of file adk.cpp.

+

Definition at line 352 of file adk.cpp.

@@ -423,7 +423,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 325 of file adk.cpp.

+

Definition at line 336 of file adk.cpp.

@@ -596,7 +596,7 @@ Static Protected Attributes

Implements UsbConfigXtracter.

-

Definition at line 300 of file adk.cpp.

+

Definition at line 311 of file adk.cpp.

@@ -786,7 +786,7 @@ Static Protected Attributes diff --git a/class_address_pool-members.html b/class_address_pool-members.html index 83bafb82..80003e58 100644 --- a/class_address_pool-members.html +++ b/class_address_pool-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -98,7 +98,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_address_pool.html b/class_address_pool.html index 6d7f98d5..7e4ec1f0 100644 --- a/class_address_pool.html +++ b/class_address_pool.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: AddressPool Class Reference @@ -31,7 +31,7 @@ - + @@ -215,7 +215,7 @@ Public Member Functions diff --git a/class_address_pool_impl-members.html b/class_address_pool_impl-members.html index b968b8a3..69587925 100644 --- a/class_address_pool_impl-members.html +++ b/class_address_pool_impl-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -100,7 +100,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_address_pool_impl.html b/class_address_pool_impl.html index 6d4fa197..a009e4d6 100644 --- a/class_address_pool_impl.html +++ b/class_address_pool_impl.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: AddressPoolImpl< MAX_DEVICES_ALLOWED > Class Template Reference @@ -31,7 +31,7 @@ - + @@ -150,7 +150,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED>
-

Definition at line 159 of file address.h.

+

Definition at line 164 of file address.h.

@@ -181,7 +181,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED>

Implements AddressPool.

-

Definition at line 174 of file address.h.

+

Definition at line 180 of file address.h.

@@ -209,7 +209,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED>
-

Definition at line 185 of file address.h.

+

Definition at line 191 of file address.h.

@@ -255,7 +255,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED>

Implements AddressPool.

-

Definition at line 195 of file address.h.

+

Definition at line 202 of file address.h.

@@ -285,7 +285,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED>

Implements AddressPool.

-

Definition at line 246 of file address.h.

+

Definition at line 254 of file address.h.

@@ -297,7 +297,7 @@ template<const uint8_t MAX_DEVICES_ALLOWED> diff --git a/class_b_t_d-members.html b/class_b_t_d-members.html index a3f56580..9828e306 100644 --- a/class_b_t_d-members.html +++ b/class_b_t_d-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -168,7 +168,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_b_t_d.html b/class_b_t_d.html index 34f8e52e..506fbddf 100644 --- a/class_b_t_d.html +++ b/class_b_t_d.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTD Class Reference @@ -31,7 +31,7 @@ - + @@ -280,7 +280,7 @@ Static Protected Attributes

Detailed Description

The Bluetooth Dongle class will take care of all the USB communication and then pass the data to the BluetoothService classes.

-

Definition at line 158 of file BTD.h.

+

Definition at line 230 of file BTD.h.

Constructor & Destructor Documentation

@@ -412,7 +412,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 121 of file BTD.cpp.

+

Definition at line 122 of file BTD.cpp.

@@ -441,7 +441,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 369 of file BTD.cpp.

+

Definition at line 365 of file BTD.cpp.

@@ -470,7 +470,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 375 of file BTD.cpp.

+

Definition at line 371 of file BTD.cpp.

@@ -499,7 +499,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 198 of file BTD.h.

+

Definition at line 270 of file BTD.h.

@@ -526,7 +526,7 @@ Static Protected Attributes

Used to check if the dongle has been initialized.

Returns
True if it's ready.
-

Definition at line 206 of file BTD.h.

+

Definition at line 278 of file BTD.h.

@@ -562,7 +562,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 214 of file BTD.h.

+

Definition at line 287 of file BTD.h.

@@ -609,7 +609,7 @@ Static Protected Attributes

Reimplemented from USBDeviceConfig.

-

Definition at line 223 of file BTD.h.

+

Definition at line 298 of file BTD.h.

@@ -676,7 +676,7 @@ Static Protected Attributes

Implements UsbConfigXtracter.

-

Definition at line 318 of file BTD.cpp.

+

Definition at line 314 of file BTD.cpp.

@@ -702,7 +702,7 @@ Static Protected Attributes

Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services.

-

Definition at line 247 of file BTD.h.

+

Definition at line 322 of file BTD.h.

@@ -736,7 +736,7 @@ Static Protected Attributes
Returns
The serice ID on succes or -1 on fail.
-

Definition at line 258 of file BTD.h.

+

Definition at line 333 of file BTD.h.

@@ -772,7 +772,7 @@ Static Protected Attributes -

Definition at line 912 of file BTD.cpp.

+

Definition at line 922 of file BTD.cpp.

@@ -790,7 +790,7 @@ Static Protected Attributes

Reset the Bluetooth dongle.

-

Definition at line 917 of file BTD.cpp.

+

Definition at line 927 of file BTD.cpp.

@@ -808,7 +808,7 @@ Static Protected Attributes

Read the Bluetooth address of the dongle.

-

Definition at line 948 of file BTD.cpp.

+

Definition at line 958 of file BTD.cpp.

@@ -826,7 +826,7 @@ Static Protected Attributes

Read the HCI Version of the Bluetooth dongle.

-

Definition at line 956 of file BTD.cpp.

+

Definition at line 967 of file BTD.cpp.

@@ -851,7 +851,7 @@ Static Protected Attributes -

Definition at line 999 of file BTD.cpp.

+

Definition at line 1011 of file BTD.cpp.

@@ -869,7 +869,7 @@ Static Protected Attributes

Enable visibility to other Bluetooth devices.

-

Definition at line 926 of file BTD.cpp.

+

Definition at line 936 of file BTD.cpp.

@@ -887,7 +887,7 @@ Static Protected Attributes

Disable visibility to other Bluetooth devices.

-

Definition at line 939 of file BTD.cpp.

+

Definition at line 949 of file BTD.cpp.

@@ -905,7 +905,7 @@ Static Protected Attributes

Read the remote devices name.

-

Definition at line 980 of file BTD.cpp.

+

Definition at line 992 of file BTD.cpp.

@@ -923,7 +923,7 @@ Static Protected Attributes

Accept the connection with the Bluetooth device.

-

Definition at line 964 of file BTD.cpp.

+

Definition at line 976 of file BTD.cpp.

@@ -948,7 +948,7 @@ Static Protected Attributes -

Definition at line 1133 of file BTD.cpp.

+

Definition at line 1145 of file BTD.cpp.

@@ -966,7 +966,7 @@ Static Protected Attributes

Respond with the pin for the connection. The pin is automatically set for the Wii library, but can be customized for the SPP library.

-

Definition at line 1059 of file BTD.cpp.

+

Definition at line 1071 of file BTD.cpp.

@@ -984,7 +984,7 @@ Static Protected Attributes

Respons when no pin was set.

-

Definition at line 1095 of file BTD.cpp.

+

Definition at line 1107 of file BTD.cpp.

@@ -1002,7 +1002,7 @@ Static Protected Attributes

Command is used to reply to a Link Key Request event from the BR/EDR Controller if the Host does not have a stored Link Key for the connection.

-

Definition at line 1109 of file BTD.cpp.

+

Definition at line 1121 of file BTD.cpp.

@@ -1020,7 +1020,7 @@ Static Protected Attributes

Used to try to authenticate with the remote device.

-

Definition at line 1123 of file BTD.cpp.

+

Definition at line 1135 of file BTD.cpp.

@@ -1038,7 +1038,7 @@ Static Protected Attributes

Start a HCI inquiry.

-

Definition at line 1011 of file BTD.cpp.

+

Definition at line 1023 of file BTD.cpp.

@@ -1056,7 +1056,7 @@ Static Protected Attributes

Cancel a HCI inquiry.

-

Definition at line 1025 of file BTD.cpp.

+

Definition at line 1037 of file BTD.cpp.

@@ -1074,7 +1074,7 @@ Static Protected Attributes

Connect to last device communicated with.

-

Definition at line 1033 of file BTD.cpp.

+

Definition at line 1045 of file BTD.cpp.

@@ -1099,7 +1099,7 @@ Static Protected Attributes -

Definition at line 1037 of file BTD.cpp.

+

Definition at line 1049 of file BTD.cpp.

@@ -1117,7 +1117,7 @@ Static Protected Attributes

Used to a set the class of the device.

-

Definition at line 1145 of file BTD.cpp.

+

Definition at line 1157 of file BTD.cpp.

@@ -1173,7 +1173,7 @@ Static Protected Attributes -

Definition at line 1181 of file BTD.cpp.

+

Definition at line 1193 of file BTD.cpp.

@@ -1223,7 +1223,7 @@ Static Protected Attributes -

Definition at line 1209 of file BTD.cpp.

+

Definition at line 1221 of file BTD.cpp.

@@ -1280,7 +1280,7 @@ Static Protected Attributes -

Definition at line 1222 of file BTD.cpp.

+

Definition at line 1234 of file BTD.cpp.

@@ -1323,7 +1323,7 @@ Static Protected Attributes -

Definition at line 1239 of file BTD.cpp.

+

Definition at line 1251 of file BTD.cpp.

@@ -1366,7 +1366,7 @@ Static Protected Attributes -

Definition at line 1256 of file BTD.cpp.

+

Definition at line 1268 of file BTD.cpp.

@@ -1416,7 +1416,7 @@ Static Protected Attributes -

Definition at line 1275 of file BTD.cpp.

+

Definition at line 1287 of file BTD.cpp.

@@ -1466,7 +1466,7 @@ Static Protected Attributes -

Definition at line 1288 of file BTD.cpp.

+

Definition at line 1300 of file BTD.cpp.

@@ -1515,7 +1515,7 @@ Static Protected Attributes -

Definition at line 1301 of file BTD.cpp.

+

Definition at line 1313 of file BTD.cpp.

@@ -1541,7 +1541,7 @@ Static Protected Attributes

Call this function to pair with a Wiimote

-

Definition at line 425 of file BTD.h.

+

Definition at line 500 of file BTD.h.

@@ -1567,7 +1567,7 @@ Static Protected Attributes

Call this function to pair with a Wiimote

-

Definition at line 441 of file BTD.h.

+

Definition at line 516 of file BTD.h.

@@ -1594,7 +1594,7 @@ Static Protected Attributes

Read the poll interval taken from the endpoint descriptors.

Returns
The poll interval in ms.
-

Definition at line 456 of file BTD.h.

+

Definition at line 531 of file BTD.h.

@@ -1627,7 +1627,7 @@ Static Protected Attributes -

Definition at line 350 of file BTD.cpp.

+

Definition at line 346 of file BTD.cpp.

@@ -1643,7 +1643,7 @@ Static Protected Attributes

Use this to see if it is waiting for a incoming connection.

-

Definition at line 396 of file BTD.h.

+

Definition at line 471 of file BTD.h.

@@ -1658,7 +1658,7 @@ Static Protected Attributes

This is used by the service to know when to store the device information.

-

Definition at line 398 of file BTD.h.

+

Definition at line 473 of file BTD.h.

@@ -1673,7 +1673,7 @@ Static Protected Attributes

This is used by the SPP library to claim the current SDP incoming request.

-

Definition at line 400 of file BTD.h.

+

Definition at line 475 of file BTD.h.

@@ -1688,7 +1688,7 @@ Static Protected Attributes

This is used by the SPP library to claim the current RFCOMM incoming request.

-

Definition at line 402 of file BTD.h.

+

Definition at line 477 of file BTD.h.

@@ -1703,7 +1703,7 @@ Static Protected Attributes

The name you wish to make the dongle show up as. It is set automatically by the SPP library.

-

Definition at line 405 of file BTD.h.

+

Definition at line 480 of file BTD.h.

@@ -1716,9 +1716,9 @@ Static Protected Attributes
-

The pin you wish to make the dongle use for authentication. It is set automatically by the SPP library.

+

The pin you wish to make the dongle use for authentication. It is set automatically by the SPP and BTHID library.

-

Definition at line 407 of file BTD.h.

+

Definition at line 482 of file BTD.h.

@@ -1733,7 +1733,7 @@ Static Protected Attributes

The bluetooth dongles Bluetooth address.

-

Definition at line 410 of file BTD.h.

+

Definition at line 485 of file BTD.h.

@@ -1748,7 +1748,7 @@ Static Protected Attributes

HCI handle for the last connection.

-

Definition at line 412 of file BTD.h.

+

Definition at line 487 of file BTD.h.

@@ -1763,7 +1763,7 @@ Static Protected Attributes

Last incoming devices Bluetooth address.

-

Definition at line 414 of file BTD.h.

+

Definition at line 489 of file BTD.h.

@@ -1778,7 +1778,7 @@ Static Protected Attributes

First 30 chars of last remote name.

-

Definition at line 416 of file BTD.h.

+

Definition at line 491 of file BTD.h.

@@ -1793,7 +1793,7 @@ Static Protected Attributes

The supported HCI Version read from the Bluetooth dongle. Used by the PS3BT library to check the HCI Version of the Bluetooth dongle, it should be at least 3 to work properly with the library.

-

Definition at line 422 of file BTD.h.

+

Definition at line 497 of file BTD.h.

@@ -1808,7 +1808,7 @@ Static Protected Attributes

Used to only send the ACL data to the wiimote.

-

Definition at line 428 of file BTD.h.

+

Definition at line 503 of file BTD.h.

@@ -1823,7 +1823,7 @@ Static Protected Attributes

True if a Wiimote is connecting.

-

Definition at line 432 of file BTD.h.

+

Definition at line 507 of file BTD.h.

@@ -1838,7 +1838,7 @@ Static Protected Attributes

True when it should pair with a Wiimote.

-

Definition at line 434 of file BTD.h.

+

Definition at line 509 of file BTD.h.

@@ -1853,7 +1853,7 @@ Static Protected Attributes

True if it's the new Wiimote with the Motion Plus Inside or a Wii U Pro Controller.

-

Definition at line 436 of file BTD.h.

+

Definition at line 511 of file BTD.h.

@@ -1868,7 +1868,7 @@ Static Protected Attributes

True if it's a Wii U Pro Controller.

-

Definition at line 438 of file BTD.h.

+

Definition at line 513 of file BTD.h.

@@ -1883,7 +1883,7 @@ Static Protected Attributes

Used to only send the ACL data to the wiimote.

-

Definition at line 444 of file BTD.h.

+

Definition at line 519 of file BTD.h.

@@ -1898,7 +1898,7 @@ Static Protected Attributes

True if a Wiimote is connecting.

-

Definition at line 448 of file BTD.h.

+

Definition at line 523 of file BTD.h.

@@ -1913,7 +1913,7 @@ Static Protected Attributes

True when it should pair with a device like a mouse or keyboard.

-

Definition at line 450 of file BTD.h.

+

Definition at line 525 of file BTD.h.

@@ -1936,7 +1936,7 @@ Static Protected Attributes

Pointer to USB class instance.

-

Definition at line 458 of file BTD.h.

+

Definition at line 533 of file BTD.h.

@@ -1959,7 +1959,7 @@ Static Protected Attributes

Device address.

-

Definition at line 464 of file BTD.h.

+

Definition at line 539 of file BTD.h.

@@ -1982,7 +1982,7 @@ Static Protected Attributes

Endpoint info structure.

-

Definition at line 466 of file BTD.h.

+

Definition at line 541 of file BTD.h.

@@ -2005,7 +2005,7 @@ Static Protected Attributes

Configuration number.

-

Definition at line 469 of file BTD.h.

+

Definition at line 544 of file BTD.h.

@@ -2028,7 +2028,7 @@ Static Protected Attributes

Total number of endpoints in the configuration.

-

Definition at line 471 of file BTD.h.

+

Definition at line 546 of file BTD.h.

@@ -2051,7 +2051,7 @@ Static Protected Attributes

Next poll time based on poll interval taken from the USB descriptor.

-

Definition at line 473 of file BTD.h.

+

Definition at line 548 of file BTD.h.

@@ -2074,7 +2074,7 @@ Static Protected Attributes

Bluetooth dongle control endpoint.

-

Definition at line 476 of file BTD.h.

+

Definition at line 551 of file BTD.h.

@@ -2097,7 +2097,7 @@ Static Protected Attributes

HCI event endpoint index.

-

Definition at line 478 of file BTD.h.

+

Definition at line 553 of file BTD.h.

@@ -2120,7 +2120,7 @@ Static Protected Attributes

ACL In endpoint index.

-

Definition at line 480 of file BTD.h.

+

Definition at line 555 of file BTD.h.

@@ -2143,7 +2143,7 @@ Static Protected Attributes

ACL Out endpoint index.

-

Definition at line 482 of file BTD.h.

+

Definition at line 557 of file BTD.h.

@@ -2156,7 +2156,7 @@ Static Protected Attributes diff --git a/class_b_t_h_i_d-members.html b/class_b_t_h_i_d-members.html index f7367150..1d7a36e9 100644 --- a/class_b_t_h_i_d-members.html +++ b/class_b_t_h_i_d-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -92,21 +92,22 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); - + - - + + +
ACLData(uint8_t *ACLData)BTHIDvirtual
attachOnInit(void(*funcOnInit)(void))BTHIDinline
BTHID(BTD *p, bool pair=false, const char *pin="1234")BTHID
BTHID(BTD *p, bool pair=false, const char *pin="0000")BTHID
connectedBTHID
disconnect()BTHIDvirtual
GetReportParser(uint8_t id)BTHIDinline
pair(void)BTHIDinline
Reset()BTHIDvirtual
Run()BTHIDvirtual
setProtocolMode(uint8_t mode)BTHIDinline
SetReportParser(uint8_t id, HIDReportParser *prs)BTHIDinline
setLeds(uint8_t data)BTHID
setProtocolMode(uint8_t mode)BTHIDinline
SetReportParser(uint8_t id, HIDReportParser *prs)BTHIDinline
diff --git a/class_b_t_h_i_d.html b/class_b_t_h_i_d.html index 960ebc3a..b5fe1e2e 100644 --- a/class_b_t_h_i_d.html +++ b/class_b_t_h_i_d.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BTHID Class Reference @@ -31,7 +31,7 @@ - + @@ -110,14 +110,16 @@ Collaboration diagram for BTHID: - - + + + + @@ -140,9 +142,9 @@ Public Attributes

Detailed Description

This BluetoothService class implements support for the HID keyboard and mice.

-

Definition at line 68 of file BTHID.h.

+

Definition at line 29 of file BTHID.h.

Constructor & Destructor Documentation

- +

Public Member Functions

 BTHID (BTD *p, bool pair=false, const char *pin="1234")
 
 BTHID (BTD *p, bool pair=false, const char *pin="0000")
 
HIDReportParserGetReportParser (uint8_t id)
 
bool SetReportParser (uint8_t id, HIDReportParser *prs)
 
void setProtocolMode (uint8_t mode)
 
void setLeds (uint8_t data)
 
void pair (void)
 
void attachOnInit (void(*funcOnInit)(void))
@@ -162,7 +164,7 @@ Public Attributes - + @@ -176,7 +178,7 @@ Public Attributes
const char * pin = "1234" pin = "0000" 
- +
pPointer to the BTD class instance.
pairSet this to true in order to pair with the device. If the argument is omitted then it will not pair with it. One can use PAIR to set it to true.
pinWrite the pin to BTD::btdPin. If argument is omitted, then "1234" will be used.
pinWrite the pin to BTD::btdPin. If argument is omitted, then "0000" will be used.
@@ -217,7 +219,7 @@ Public Attributes

Reimplemented from BluetoothService.

-

Definition at line 61 of file BTHID.cpp.

+

Definition at line 58 of file BTHID.cpp.

@@ -241,7 +243,7 @@ Public Attributes
-

Used to run part of the state maschine.

+

Used to run part of the state machine.

Reimplemented from BluetoothService.

@@ -273,7 +275,7 @@ Public Attributes

Reimplemented from BluetoothService.

-

Definition at line 47 of file BTHID.cpp.

+

Definition at line 44 of file BTHID.cpp.

@@ -297,11 +299,11 @@ Public Attributes
-

Used this to disconnect any of the controllers.

+

Used this to disconnect the devices.

Reimplemented from BluetoothService.

-

Definition at line 54 of file BTHID.cpp.

+

Definition at line 51 of file BTHID.cpp.

@@ -326,8 +328,16 @@ Public Attributes
+

Get HIDReportParser.

+
Parameters
+ + +
idID of parser.
+
+
+
Returns
Returns the corresponding HIDReportParser. Returns NULL if id is not valid.
-

Definition at line 92 of file BTHID.h.

+

Definition at line 59 of file BTHID.h.

@@ -362,8 +372,17 @@ Public Attributes
+

Set HIDReportParser to be used.

+
Parameters
+ + + +
idId of parser.
prsPointer to HIDReportParser.
+
+
+
Returns
Returns true if the HIDReportParser is set. False otherwise.
-

Definition at line 96 of file BTHID.h.

+

Definition at line 71 of file BTHID.h.

@@ -388,8 +407,40 @@ Public Attributes
+

Set HID protocol mode.

+
Parameters
+ + +
modeHID protocol to use. Either HID_BOOT_PROTOCOL or HID_RPT_PROTOCOL.
+
+
-

Definition at line 101 of file BTHID.h.

+

Definition at line 82 of file BTHID.h.

+ +
+ + +
+
+ + + + + + + + +
void BTHID::setLeds (uint8_t data)
+
+

Used to set the leds on a keyboard.

+
Parameters
+ + +
dataSee KBDLEDS in hidboot.h
+
+
+ +

Definition at line 396 of file BTHID.cpp.

@@ -414,9 +465,9 @@ Public Attributes
-

Call this to start the paring sequence with a controller

+

Call this to start the paring sequence with a device

-

Definition at line 109 of file BTHID.h.

+

Definition at line 96 of file BTHID.h.

@@ -441,7 +492,7 @@ Public Attributes
-

Used to call your own function when the controller is successfully initialized.

+

Used to call your own function when the device is successfully initialized.

Parameters
@@ -449,7 +500,7 @@ Public Attributes -

Definition at line 118 of file BTHID.h.

+

Definition at line 105 of file BTHID.h.

@@ -465,7 +516,7 @@ Public Attributes

True if a device is connected

-

Definition at line 103 of file BTHID.h.

+

Definition at line 93 of file BTHID.h.

@@ -478,7 +529,7 @@ Public Attributes diff --git a/class_bluetooth_service-members.html b/class_bluetooth_service-members.html index dd7f26ec..252ecf4c 100644 --- a/class_bluetooth_service-members.html +++ b/class_bluetooth_service-members.html @@ -3,7 +3,7 @@ - +USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@
funcOnInitFunction to call.
- + @@ -99,7 +99,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_bluetooth_service.html b/class_bluetooth_service.html index 78541ac1..53f97555 100644 --- a/class_bluetooth_service.html +++ b/class_bluetooth_service.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BluetoothService Class Reference @@ -31,7 +31,7 @@ - + @@ -112,9 +112,9 @@ Public Member Functions  

Detailed Description

-

All Bluetooth services should include this class.

+

All Bluetooth services should inherit this class.

-

Definition at line 139 of file BTD.h.

+

Definition at line 211 of file BTD.h.

Member Function Documentation

@@ -145,7 +145,7 @@ Public Member Functions -

Reimplemented in SPP, WII, BTHID, and PS3BT.

+

Reimplemented in SPP, WII, PS3BT, and BTHID.

@@ -171,7 +171,7 @@ Public Member Functions

Used to run the different state machines in the Bluetooth service.

-

Reimplemented in SPP, WII, BTHID, and PS3BT.

+

Reimplemented in SPP, WII, PS3BT, and BTHID.

@@ -197,7 +197,7 @@ Public Member Functions

Used to reset the Bluetooth service.

-

Reimplemented in SPP, WII, BTHID, and PS3BT.

+

Reimplemented in SPP, WII, PS3BT, and BTHID.

@@ -223,7 +223,7 @@ Public Member Functions

Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service.

-

Reimplemented in SPP, WII, BTHID, and PS3BT.

+

Reimplemented in SPP, WII, PS3BT, and BTHID.

@@ -235,7 +235,7 @@ Public Member Functions diff --git a/class_bulk_only-members.html b/class_bulk_only-members.html index 0eb15006..705820a9 100644 --- a/class_bulk_only-members.html +++ b/class_bulk_only-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -140,7 +140,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_bulk_only.html b/class_bulk_only.html index 110ea50e..54c2785b 100644 --- a/class_bulk_only.html +++ b/class_bulk_only.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: BulkOnly Class Reference @@ -31,7 +31,7 @@ - + @@ -264,7 +264,7 @@ Static Protected Attributes -

Definition at line 1182 of file masstorage.cpp.

+

Definition at line 1181 of file masstorage.cpp.

@@ -531,7 +531,7 @@ Static Protected Attributes
-

Definition at line 1209 of file masstorage.cpp.

+

Definition at line 1208 of file masstorage.cpp.

@@ -1526,7 +1526,7 @@ Static Protected Attributes diff --git a/class_byte_skipper-members.html b/class_byte_skipper-members.html index 64e812dd..a971cceb 100644 --- a/class_byte_skipper-members.html +++ b/class_byte_skipper-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -98,7 +98,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_byte_skipper.html b/class_byte_skipper.html index 1eda1b71..6f46260d 100644 --- a/class_byte_skipper.html +++ b/class_byte_skipper.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: ByteSkipper Class Reference @@ -31,7 +31,7 @@ - + @@ -208,7 +208,7 @@ Public Member Functions diff --git a/class_c_d_c_async_oper-members.html b/class_c_d_c_async_oper-members.html index d2a6b622..d009cf9f 100644 --- a/class_c_d_c_async_oper-members.html +++ b/class_c_d_c_async_oper-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -96,7 +96,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_c_d_c_async_oper.html b/class_c_d_c_async_oper.html index 3f3d21be..ced21e37 100644 --- a/class_c_d_c_async_oper.html +++ b/class_c_d_c_async_oper.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: CDCAsyncOper Class Reference @@ -31,7 +31,7 @@ - + @@ -100,7 +100,7 @@ Public Member Functions

Detailed Description

-

Definition at line 129 of file cdcacm.h.

+

Definition at line 128 of file cdcacm.h.

Member Function Documentation

@@ -134,7 +134,7 @@ Public Member Functions diff --git a/class_config_desc_parser-members.html b/class_config_desc_parser-members.html index 34f6534e..30ef3392 100644 --- a/class_config_desc_parser-members.html +++ b/class_config_desc_parser-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@
- + @@ -92,12 +92,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); +
ConfigDescParser(UsbConfigXtracter *xtractor)ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK >
Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset)ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK >virtual
SetOR(void)ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK >inline
diff --git a/class_config_desc_parser.html b/class_config_desc_parser.html index 56605672..f29888a6 100644 --- a/class_config_desc_parser.html +++ b/class_config_desc_parser.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK > Class Template Reference @@ -31,7 +31,7 @@ - + @@ -109,6 +109,8 @@ Collaboration diagram for ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_I + + @@ -119,7 +121,7 @@ Public Member Functions class ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK > -

Definition at line 39 of file confdescparser.h.

+

Definition at line 38 of file confdescparser.h.

Constructor & Destructor Documentation

@@ -137,11 +139,39 @@ template<const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PRO

Public Member Functions

void SetOR (void)
 
 ConfigDescParser (UsbConfigXtracter *xtractor)
 
virtual void Parse (const uint16_t len, const uint8_t *pbuf, const uint16_t &offset)
-

Definition at line 67 of file confdescparser.h.

+

Definition at line 70 of file confdescparser.h.

Member Function Documentation

+ +
+
+
+template<const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
+ + + + + +
+ + + + + + + + +
void ConfigDescParser< CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK >::SetOR (void )
+
+inline
+
+ +

Definition at line 62 of file confdescparser.h.

+ +
+
@@ -184,7 +214,7 @@ template<const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PRO

Implements USBReadParser.

-

Definition at line 78 of file confdescparser.h.

+

Definition at line 82 of file confdescparser.h.

@@ -196,7 +226,7 @@ template<const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PRO diff --git a/class_f_t_d_i-members.html b/class_f_t_d_i-members.html index 2bc2c7b3..23968221 100644 --- a/class_f_t_d_i-members.html +++ b/class_f_t_d_i-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -111,7 +111,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_f_t_d_i.html b/class_f_t_d_i.html index e99a9da8..21f702b0 100644 --- a/class_f_t_d_i.html +++ b/class_f_t_d_i.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: FTDI Class Reference @@ -31,7 +31,7 @@ - + @@ -190,7 +190,7 @@ Public Member Functions
-

Definition at line 269 of file cdcftdi.cpp.

+

Definition at line 267 of file cdcftdi.cpp.

@@ -208,7 +208,7 @@ Public Member Functions
-

Definition at line 306 of file cdcftdi.cpp.

+

Definition at line 304 of file cdcftdi.cpp.

@@ -242,7 +242,7 @@ Public Member Functions
-

Definition at line 310 of file cdcftdi.cpp.

+

Definition at line 308 of file cdcftdi.cpp.

@@ -260,7 +260,7 @@ Public Member Functions
-

Definition at line 314 of file cdcftdi.cpp.

+

Definition at line 312 of file cdcftdi.cpp.

@@ -288,7 +288,7 @@ Public Member Functions
-

Definition at line 318 of file cdcftdi.cpp.

+

Definition at line 316 of file cdcftdi.cpp.

@@ -316,7 +316,7 @@ Public Member Functions
-

Definition at line 322 of file cdcftdi.cpp.

+

Definition at line 320 of file cdcftdi.cpp.

@@ -387,7 +387,7 @@ Public Member Functions

Reimplemented from USBDeviceConfig.

-

Definition at line 244 of file cdcftdi.cpp.

+

Definition at line 242 of file cdcftdi.cpp.

@@ -414,7 +414,7 @@ Public Member Functions

Reimplemented from USBDeviceConfig.

-

Definition at line 254 of file cdcftdi.cpp.

+

Definition at line 252 of file cdcftdi.cpp.

@@ -497,7 +497,7 @@ Public Member Functions

Implements UsbConfigXtracter.

-

Definition at line 217 of file cdcftdi.cpp.

+

Definition at line 215 of file cdcftdi.cpp.

@@ -510,7 +510,7 @@ Public Member Functions diff --git a/class_f_t_d_i_async_oper-members.html b/class_f_t_d_i_async_oper-members.html index 3a2d41bb..e4083697 100644 --- a/class_f_t_d_i_async_oper-members.html +++ b/class_f_t_d_i_async_oper-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -96,7 +96,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_f_t_d_i_async_oper.html b/class_f_t_d_i_async_oper.html index 6dc950d8..9f981e68 100644 --- a/class_f_t_d_i_async_oper.html +++ b/class_f_t_d_i_async_oper.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: FTDIAsyncOper Class Reference @@ -31,7 +31,7 @@ - + @@ -134,7 +134,7 @@ Public Member Functions diff --git a/class_h_i_d-members.html b/class_h_i_d-members.html index a44c33d4..06ee618c 100644 --- a/class_h_i_d-members.html +++ b/class_h_i_d-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); GetIdle(uint8_t iface, uint8_t reportID, uint8_t *dataptr)HID GetProtocol(uint8_t iface, uint8_t *dataptr)HID GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)HID - GetReportDescr(uint8_t ep, USBReadParser *parser=NULL)HID + GetReportDescr(uint16_t wIndex, USBReadParser *parser=NULL)HID GetReportParser(uint8_t id)HIDprotectedvirtual GetUsb()HIDinline HID(USB *pusb)HIDinline @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_h_i_d.html b/class_h_i_d.html index 9f77a14a..b11df6a2 100644 --- a/class_h_i_d.html +++ b/class_h_i_d.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: HID Class Reference @@ -31,7 +31,7 @@ - + @@ -126,8 +126,8 @@ Public Member Functions   uint8_t SetIdle (uint8_t iface, uint8_t reportID, uint8_t duration)   -uint8_t GetReportDescr (uint8_t ep, USBReadParser *parser=NULL) -  +uint8_t GetReportDescr (uint16_t wIndex, USBReadParser *parser=NULL) +  uint8_t GetHidDescr (uint8_t ep, uint16_t nbytes, uint8_t *dataptr)   uint8_t GetReport (uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr) @@ -237,7 +237,7 @@ Static Protected Attributes
-

Definition at line 44 of file hid.cpp.

+

Definition at line 57 of file hid.cpp.

@@ -263,7 +263,7 @@ Static Protected Attributes
-

Definition at line 60 of file hid.cpp.

+

Definition at line 73 of file hid.cpp.

@@ -378,7 +378,7 @@ Static Protected Attributes
-

Definition at line 36 of file hid.cpp.

+

Definition at line 49 of file hid.cpp.

@@ -406,7 +406,7 @@ Static Protected Attributes
-

Definition at line 40 of file hid.cpp.

+

Definition at line 53 of file hid.cpp.

@@ -440,7 +440,7 @@ Static Protected Attributes
-

Definition at line 28 of file hid.cpp.

+

Definition at line 41 of file hid.cpp.

@@ -474,19 +474,19 @@ Static Protected Attributes
-

Definition at line 32 of file hid.cpp.

+

Definition at line 45 of file hid.cpp.

- +
- - + + @@ -502,7 +502,7 @@ Static Protected Attributes
uint8_t HID::GetReportDescr (uint8_t ep, uint16_t wIndex,
-

Definition at line 5 of file hid.cpp.

+

Definition at line 17 of file hid.cpp.

@@ -586,7 +586,7 @@ Static Protected Attributes
-

Definition at line 24 of file hid.cpp.

+

Definition at line 37 of file hid.cpp.

@@ -638,7 +638,7 @@ Static Protected Attributes
-

Definition at line 20 of file hid.cpp.

+

Definition at line 33 of file hid.cpp.

@@ -806,7 +806,7 @@ Static Protected Attributes diff --git a/class_h_i_d_boot-members.html b/class_h_i_d_boot-members.html index b001f751..be41097d 100644 --- a/class_h_i_d_boot-members.html +++ b/class_h_i_d_boot-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); GetIdle(uint8_t iface, uint8_t reportID, uint8_t *dataptr)HID GetProtocol(uint8_t iface, uint8_t *dataptr)HID GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)HID - GetReportDescr(uint8_t ep, USBReadParser *parser=NULL)HID + GetReportDescr(uint16_t wIndex, USBReadParser *parser=NULL)HID GetUsb()HIDinline HID(USB *pusb)HIDinline HIDBoot(USB *p)HIDBoot< BOOT_PROTOCOL > @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_h_i_d_boot.html b/class_h_i_d_boot.html index 30e6ba30..c31d3a65 100644 --- a/class_h_i_d_boot.html +++ b/class_h_i_d_boot.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: HIDBoot< BOOT_PROTOCOL > Class Template Reference @@ -31,7 +31,7 @@ - + @@ -136,8 +136,8 @@ Public Member Functions   uint8_t SetIdle (uint8_t iface, uint8_t reportID, uint8_t duration)   -uint8_t GetReportDescr (uint8_t ep, USBReadParser *parser=NULL) -  +uint8_t GetReportDescr (uint16_t wIndex, USBReadParser *parser=NULL) +  uint8_t GetHidDescr (uint8_t ep, uint16_t nbytes, uint8_t *dataptr)   uint8_t GetReport (uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr) @@ -183,7 +183,7 @@ Additional Inherited Members class HIDBoot< BOOT_PROTOCOL > -

Definition at line 160 of file hidboot.h.

+

Definition at line 179 of file hidboot.h.

Constructor & Destructor Documentation

@@ -201,7 +201,7 @@ template<const uint8_t BOOT_PROTOCOL>
-

Definition at line 200 of file hidboot.h.

+

Definition at line 220 of file hidboot.h.

@@ -242,7 +242,7 @@ template<const uint8_t BOOT_PROTOCOL>

Reimplemented from HID.

-

Definition at line 181 of file hidboot.h.

+

Definition at line 201 of file hidboot.h.

@@ -288,7 +288,7 @@ template<const uint8_t BOOT_PROTOCOL>

Reimplemented from USBDeviceConfig.

-

Definition at line 227 of file hidboot.h.

+

Definition at line 247 of file hidboot.h.

@@ -317,7 +317,7 @@ template<const uint8_t BOOT_PROTOCOL>

Reimplemented from USBDeviceConfig.

-

Definition at line 463 of file hidboot.h.

+

Definition at line 522 of file hidboot.h.

@@ -346,7 +346,7 @@ template<const uint8_t BOOT_PROTOCOL>

Reimplemented from USBDeviceConfig.

-

Definition at line 476 of file hidboot.h.

+

Definition at line 536 of file hidboot.h.

@@ -375,7 +375,7 @@ template<const uint8_t BOOT_PROTOCOL>

Reimplemented from USBDeviceConfig.

-

Definition at line 191 of file hidboot.h.

+

Definition at line 211 of file hidboot.h.

@@ -433,7 +433,7 @@ template<const uint8_t BOOT_PROTOCOL>

Implements UsbConfigXtracter.

-

Definition at line 441 of file hidboot.h.

+

Definition at line 498 of file hidboot.h.

@@ -445,7 +445,7 @@ template<const uint8_t BOOT_PROTOCOL> diff --git a/class_h_i_d_report_parser-members.html b/class_h_i_d_report_parser-members.html index 8a17eebf..02328928 100644 --- a/class_h_i_d_report_parser-members.html +++ b/class_h_i_d_report_parser-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -96,7 +96,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_h_i_d_report_parser.html b/class_h_i_d_report_parser.html index b4191950..c8f06d95 100644 --- a/class_h_i_d_report_parser.html +++ b/class_h_i_d_report_parser.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: HIDReportParser Class Reference @@ -31,7 +31,7 @@ - + @@ -97,7 +97,7 @@ Inheritance diagram for HIDReportParser:
Inheritance graph
- +
[legend]

@@ -107,7 +107,7 @@ Public Member Functions

Detailed Description

-

Definition at line 135 of file hid.h.

+

Definition at line 138 of file hid.h.

Member Function Documentation

@@ -153,7 +153,7 @@ Public Member Functions
-

Implemented in UniversalReportParser, KeyboardReportParser, and MouseReportParser.

+

Implemented in UniversalReportParser, KeyboardReportParser, PS4BT, and MouseReportParser.

@@ -165,7 +165,7 @@ Public Member Functions diff --git a/class_h_i_d_report_parser__inherit__graph.map b/class_h_i_d_report_parser__inherit__graph.map index 663f5228..b852667b 100644 --- a/class_h_i_d_report_parser__inherit__graph.map +++ b/class_h_i_d_report_parser__inherit__graph.map @@ -1,5 +1,6 @@ - + + diff --git a/class_h_i_d_report_parser__inherit__graph.md5 b/class_h_i_d_report_parser__inherit__graph.md5 index 44e50d86..c1f93e19 100644 --- a/class_h_i_d_report_parser__inherit__graph.md5 +++ b/class_h_i_d_report_parser__inherit__graph.md5 @@ -1 +1 @@ -c82eb64e4e9d8248b32e0db32cbfa973 \ No newline at end of file +dcf21fd85d8fe0426e091fadd5132a12 \ No newline at end of file diff --git a/class_h_i_d_report_parser__inherit__graph.png b/class_h_i_d_report_parser__inherit__graph.png index 980a75bf..5be1f8fd 100644 Binary files a/class_h_i_d_report_parser__inherit__graph.png and b/class_h_i_d_report_parser__inherit__graph.png differ diff --git a/class_h_i_d_universal-members.html b/class_h_i_d_universal-members.html index 98b6c5db..0d2be32b 100644 --- a/class_h_i_d_universal-members.html +++ b/class_h_i_d_universal-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -102,7 +102,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); GetIdle(uint8_t iface, uint8_t reportID, uint8_t *dataptr)HID GetProtocol(uint8_t iface, uint8_t *dataptr)HID GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)HID - GetReportDescr(uint8_t ep, USBReadParser *parser=NULL)HID + GetReportDescr(uint16_t wIndex, USBReadParser *parser=NULL)HID GetReportParser(uint8_t id)HIDUniversalprotectedvirtual GetUsb()HIDinline HID(USB *pusb)HIDinline @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_h_i_d_universal.html b/class_h_i_d_universal.html index 298d5cc7..66003f9e 100644 --- a/class_h_i_d_universal.html +++ b/class_h_i_d_universal.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: HIDUniversal Class Reference @@ -31,7 +31,7 @@ - + @@ -139,8 +139,8 @@ Public Member Functions   uint8_t SetIdle (uint8_t iface, uint8_t reportID, uint8_t duration)   -uint8_t GetReportDescr (uint8_t ep, USBReadParser *parser=NULL) -  +uint8_t GetReportDescr (uint16_t wIndex, USBReadParser *parser=NULL) +  uint8_t GetHidDescr (uint8_t ep, uint16_t nbytes, uint8_t *dataptr)   uint8_t GetReport (uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr) @@ -374,7 +374,7 @@ Additional Inherited Members

Reimplemented from USBDeviceConfig.

-

Definition at line 314 of file hiduniversal.cpp.

+

Definition at line 315 of file hiduniversal.cpp.

@@ -401,7 +401,7 @@ Additional Inherited Members

Reimplemented from USBDeviceConfig.

-

Definition at line 341 of file hiduniversal.cpp.

+

Definition at line 342 of file hiduniversal.cpp.

@@ -484,7 +484,7 @@ Additional Inherited Members

Implements UsbConfigXtracter.

-

Definition at line 271 of file hiduniversal.cpp.

+

Definition at line 272 of file hiduniversal.cpp.

@@ -520,7 +520,7 @@ Additional Inherited Members diff --git a/class_hex_dumper-members.html b/class_hex_dumper-members.html index 1ffddfd1..bf33941a 100644 --- a/class_hex_dumper-members.html +++ b/class_hex_dumper-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -98,7 +98,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_hex_dumper.html b/class_hex_dumper.html index bdc7807a..22c3a399 100644 --- a/class_hex_dumper.html +++ b/class_hex_dumper.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: HexDumper< BASE_CLASS, LEN_TYPE, OFFSET_TYPE > Class Template Reference @@ -31,7 +31,7 @@ - + @@ -226,7 +226,7 @@ template<class BASE_CLASS , class LEN_TYPE , class OFFSET_TYPE > diff --git a/class_keyboard_report_parser-members.html b/class_keyboard_report_parser-members.html index 7c72c492..7e24c1bf 100644 --- a/class_keyboard_report_parser-members.html +++ b/class_keyboard_report_parser-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -92,6 +92,10 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); + + + + @@ -108,7 +112,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/class_keyboard_report_parser.html b/class_keyboard_report_parser.html index 5a481b8a..623c6c86 100644 --- a/class_keyboard_report_parser.html +++ b/class_keyboard_report_parser.html @@ -3,7 +3,7 @@ - +USB Host Shield 2.0: KeyboardReportParser Class Reference @@ -31,7 +31,7 @@
bInfoKeyboardReportParser
bLedsKeyboardReportParser
getNumKeys()KeyboardReportParserinlineprotectedvirtual
getPadKeys()KeyboardReportParserinlineprotectedvirtual
getSymKeysLo()KeyboardReportParserinlineprotectedvirtual
getSymKeysUp()KeyboardReportParserinlineprotectedvirtual
HandleLockingKeys(HID *hid, uint8_t key)KeyboardReportParserprotectedvirtual
kbdInfoKeyboardReportParser
kbdLedsKeyboardReportParser
- + @@ -128,6 +128,14 @@ Protected Member Functions   virtual void OnKeyUp (uint8_t mod, uint8_t key)   +virtual const uint8_t * getNumKeys () +  +virtual const uint8_t * getSymKeysUp () +  +virtual const uint8_t * getSymKeysLo () +  +virtual const uint8_t * getPadKeys () +  @@ -148,7 +156,7 @@ Protected Attributes

Protected Attributes

Detailed Description

-

Definition at line 114 of file hidboot.h.

+

Definition at line 121 of file hidboot.h.

Constructor & Destructor Documentation

@@ -171,7 +179,7 @@ Protected Attributes
-

Definition at line 136 of file hidboot.h.

+

Definition at line 143 of file hidboot.h.

@@ -208,7 +216,7 @@ Protected Attributes
-

Definition at line 107 of file hidboot.cpp.

+

Definition at line 186 of file hidboot.cpp.

@@ -258,7 +266,7 @@ Protected Attributes

Implements HIDReportParser.

-

Definition at line 48 of file hidboot.cpp.

+

Definition at line 127 of file hidboot.cpp.

@@ -294,7 +302,7 @@ Protected Attributes
-

Definition at line 81 of file hidboot.cpp.

+

Definition at line 160 of file hidboot.cpp.

@@ -330,7 +338,7 @@ Protected Attributes
-

Definition at line 145 of file hidboot.h.

+

Definition at line 152 of file hidboot.h.

@@ -366,7 +374,7 @@ Protected Attributes
-

Definition at line 148 of file hidboot.h.

+

Definition at line 155 of file hidboot.h.

@@ -402,7 +410,107 @@ Protected Attributes
-

Definition at line 151 of file hidboot.h.

+

Definition at line 158 of file hidboot.h.

+ +
+ + +
+
+ + + + + +
+ + + + + + + +
virtual const uint8_t* KeyboardReportParser::getNumKeys ()
+
+inlineprotectedvirtual
+
+ +

Definition at line 161 of file hidboot.h.

+ +
+
+ +
+
+ + + + + +
+ + + + + + + +
virtual const uint8_t* KeyboardReportParser::getSymKeysUp ()
+
+inlineprotectedvirtual
+
+ +

Definition at line 165 of file hidboot.h.

+ +
+
+ +
+
+ + + + + +
+ + + + + + + +
virtual const uint8_t* KeyboardReportParser::getSymKeysLo ()
+
+inlineprotectedvirtual
+
+ +

Definition at line 169 of file hidboot.h.

+ +
+
+ +
+
+ + + + + +
+ + + + + + + +
virtual const uint8_t* KeyboardReportParser::getPadKeys ()
+
+inlineprotectedvirtual
+
+ +

Definition at line 173 of file hidboot.h.

@@ -417,7 +525,7 @@ Protected Attributes
-

Definition at line 123 of file hidboot.h.

+

Definition at line 130 of file hidboot.h.

@@ -431,7 +539,7 @@ Protected Attributes
-

Definition at line 124 of file hidboot.h.

+

Definition at line 131 of file hidboot.h.

@@ -457,7 +565,7 @@ Protected Attributes
-

Definition at line 128 of file hidboot.h.

+

Definition at line 135 of file hidboot.h.

@@ -471,7 +579,7 @@ Protected Attributes
-

Definition at line 129 of file hidboot.h.

+

Definition at line 136 of file hidboot.h.

@@ -496,7 +604,7 @@ Protected Attributes diff --git a/class_m_a_x3421e-members.html b/class_m_a_x3421e-members.html index d50708b7..fce6fdc5 100644 --- a/class_m_a_x3421e-members.html +++ b/class_m_a_x3421e-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@ - + @@ -84,34 +84,34 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
-
MAX3421e< SS, INTR > Member List
+
MAX3421e< SPI_SS, INTR > Member List
-

This is the complete list of members for MAX3421e< SS, INTR >, including all inherited members.

+

This is the complete list of members for MAX3421e< SPI_SS, INTR >, including all inherited members.

- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
busprobe()MAX3421e< SS, INTR >
bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)MAX3421e< SS, INTR >
bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)MAX3421e< SS, INTR >
getVbusState(void)MAX3421e< SS, INTR >inline
gpioRd()MAX3421e< SS, INTR >
gpioWr(uint8_t data)MAX3421e< SS, INTR >
GpxHandler()MAX3421e< SS, INTR >
Init()MAX3421e< SS, INTR >
Init(int mseconds)MAX3421e< SS, INTR >
IntHandler()MAX3421e< SS, INTR >
MAX3421e()MAX3421e< SS, INTR >
regRd(uint8_t reg)MAX3421e< SS, INTR >
regWr(uint8_t reg, uint8_t data)MAX3421e< SS, INTR >
reset()MAX3421e< SS, INTR >
Task()MAX3421e< SS, INTR >
vbusPower(VBUS_t state)MAX3421e< SS, INTR >inline
busprobe()MAX3421e< SPI_SS, INTR >
bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)MAX3421e< SPI_SS, INTR >
bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)MAX3421e< SPI_SS, INTR >
getVbusState(void)MAX3421e< SPI_SS, INTR >inline
gpioRd()MAX3421e< SPI_SS, INTR >
gpioWr(uint8_t data)MAX3421e< SPI_SS, INTR >
GpxHandler()MAX3421e< SPI_SS, INTR >
Init()MAX3421e< SPI_SS, INTR >
Init(int mseconds)MAX3421e< SPI_SS, INTR >
IntHandler()MAX3421e< SPI_SS, INTR >
MAX3421e()MAX3421e< SPI_SS, INTR >
regRd(uint8_t reg)MAX3421e< SPI_SS, INTR >
regWr(uint8_t reg, uint8_t data)MAX3421e< SPI_SS, INTR >
reset()MAX3421e< SPI_SS, INTR >
Task()MAX3421e< SPI_SS, INTR >
vbusPower(VBUS_t state)MAX3421e< SPI_SS, INTR >inline
diff --git a/class_m_a_x3421e.html b/class_m_a_x3421e.html index b60198c7..d24ea38b 100644 --- a/class_m_a_x3421e.html +++ b/class_m_a_x3421e.html @@ -3,8 +3,8 @@ - -USB Host Shield 2.0: MAX3421e< SS, INTR > Class Template Reference + +USB Host Shield 2.0: MAX3421e< SPI_SS, INTR > Class Template Reference @@ -31,7 +31,7 @@ - + @@ -87,69 +87,69 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); Public Member Functions | List of all members
-
MAX3421e< SS, INTR > Class Template Reference
+
MAX3421e< SPI_SS, INTR > Class Template Reference

#include <usbhost.h>

-Inheritance diagram for MAX3421e< SS, INTR >:
+Inheritance diagram for MAX3421e< SPI_SS, INTR >:
-
Inheritance graph
- - +
Inheritance graph
+ +
[legend]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 MAX3421e ()
 
void regWr (uint8_t reg, uint8_t data)
 
uint8_t * bytesWr (uint8_t reg, uint8_t nbytes, uint8_t *data_p)
 
void gpioWr (uint8_t data)
 
uint8_t regRd (uint8_t reg)
 
uint8_t * bytesRd (uint8_t reg, uint8_t nbytes, uint8_t *data_p)
 
uint8_t gpioRd ()
 
uint16_t reset ()
 
int8_t Init ()
 
int8_t Init (int mseconds)
 
void vbusPower (VBUS_t state)
 
uint8_t getVbusState (void)
 
void busprobe ()
 
uint8_t GpxHandler ()
 
uint8_t IntHandler ()
 
uint8_t Task ()
 
 MAX3421e ()
 
void regWr (uint8_t reg, uint8_t data)
 
uint8_t * bytesWr (uint8_t reg, uint8_t nbytes, uint8_t *data_p)
 
void gpioWr (uint8_t data)
 
uint8_t regRd (uint8_t reg)
 
uint8_t * bytesRd (uint8_t reg, uint8_t nbytes, uint8_t *data_p)
 
uint8_t gpioRd ()
 
uint16_t reset ()
 
int8_t Init ()
 
int8_t Init (int mseconds)
 
void vbusPower (VBUS_t state)
 
uint8_t getVbusState (void)
 
void busprobe ()
 
uint8_t GpxHandler ()
 
uint8_t IntHandler ()
 
uint8_t Task ()
 

Detailed Description

-

template<typename SS, typename INTR>
-class MAX3421e< SS, INTR >

+

template<typename SPI_SS, typename INTR>
+class MAX3421e< SPI_SS, INTR >

Definition at line 81 of file usbhost.h.

Constructor & Destructor Documentation

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -162,14 +162,14 @@ template<typename SS , typename INTR >

Member Function Documentation

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
MAX3421e< SS, INTR >::MAX3421e MAX3421e< SPI_SS, INTR >::MAX3421e ( )
- + @@ -192,14 +192,14 @@ template<typename SS , typename INTR > - +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
void MAX3421e< SS, INTR >::regWr void MAX3421e< SPI_SS, INTR >::regWr ( uint8_t  reg,
- + @@ -228,14 +228,14 @@ template<typename SS , typename INTR > - +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
uint8_t * MAX3421e< SS, INTR >::bytesWr uint8_t * MAX3421e< SPI_SS, INTR >::bytesWr ( uint8_t  reg,
- + @@ -244,18 +244,18 @@ template<typename SS , typename INTR >
void MAX3421e< SS, INTR >::gpioWr void MAX3421e< SPI_SS, INTR >::gpioWr ( uint8_t  data)
-

Definition at line 172 of file usbhost.h.

+

Definition at line 173 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -264,18 +264,18 @@ template<typename SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::regRd uint8_t MAX3421e< SPI_SS, INTR >::regRd ( uint8_t  reg)
-

Definition at line 181 of file usbhost.h.

+

Definition at line 182 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -300,18 +300,18 @@ template<typename SS , typename INTR >
uint8_t * MAX3421e< SS, INTR >::bytesRd uint8_t * MAX3421e< SPI_SS, INTR >::bytesRd ( uint8_t  reg,
-

Definition at line 203 of file usbhost.h.

+

Definition at line 204 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -319,18 +319,18 @@ template<typename SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::gpioRd uint8_t MAX3421e< SPI_SS, INTR >::gpioRd ( )
-

Definition at line 238 of file usbhost.h.

+

Definition at line 239 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -338,18 +338,18 @@ template<typename SS , typename INTR >
uint16_t MAX3421e< SS, INTR >::reset uint16_t MAX3421e< SPI_SS, INTR >::reset ( )
-

Definition at line 249 of file usbhost.h.

+

Definition at line 250 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -357,18 +357,18 @@ template<typename SS , typename INTR >
int8_t MAX3421e< SS, INTR >::Init int8_t MAX3421e< SPI_SS, INTR >::Init ( )
-

Definition at line 263 of file usbhost.h.

+

Definition at line 264 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -377,21 +377,21 @@ template<typename SS , typename INTR >
int8_t MAX3421e< SS, INTR >::Init int8_t MAX3421e< SPI_SS, INTR >::Init ( int  mseconds)
-

Definition at line 300 of file usbhost.h.

+

Definition at line 301 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- +
- + @@ -409,17 +409,17 @@ template<typename SS , typename INTR > - +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
void MAX3421e< SS, INTR >::vbusPower void MAX3421e< SPI_SS, INTR >::vbusPower ( VBUS_t  state)
- + @@ -437,14 +437,14 @@ template<typename SS , typename INTR > - +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::getVbusState uint8_t MAX3421e< SPI_SS, INTR >::getVbusState ( void  )
- + @@ -452,18 +452,18 @@ template<typename SS , typename INTR >
void MAX3421e< SS, INTR >::busprobe void MAX3421e< SPI_SS, INTR >::busprobe ( )
-

Definition at line 344 of file usbhost.h.

+

Definition at line 345 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -473,14 +473,14 @@ template<typename SS , typename INTR > - +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::GpxHandler uint8_t MAX3421e< SPI_SS, INTR >::GpxHandler ( )
- + @@ -488,18 +488,18 @@ template<typename SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::IntHandler uint8_t MAX3421e< SPI_SS, INTR >::IntHandler ( )
-

Definition at line 398 of file usbhost.h.

+

Definition at line 399 of file usbhost.h.

- +
-template<typename SS , typename INTR >
+template<typename SPI_SS , typename INTR >
- + @@ -508,7 +508,7 @@ template<typename SS , typename INTR >
uint8_t MAX3421e< SS, INTR >::Task uint8_t MAX3421e< SPI_SS, INTR >::Task ( void  )
-

Definition at line 379 of file usbhost.h.

+

Definition at line 380 of file usbhost.h.

@@ -520,7 +520,7 @@ template<typename SS , typename INTR > diff --git a/class_m_a_x3421e__inherit__graph.map b/class_m_a_x3421e__inherit__graph.map index 7259aa1f..ebb57324 100644 --- a/class_m_a_x3421e__inherit__graph.map +++ b/class_m_a_x3421e__inherit__graph.map @@ -1,3 +1,3 @@ - - + + diff --git a/class_m_a_x3421e__inherit__graph.md5 b/class_m_a_x3421e__inherit__graph.md5 index 791a3434..9c6ebd2d 100644 --- a/class_m_a_x3421e__inherit__graph.md5 +++ b/class_m_a_x3421e__inherit__graph.md5 @@ -1 +1 @@ -d35ce90200ec61a9a48a5d7ddf420ab5 \ No newline at end of file +77bb5e0b002d7306a86fd50983493adb \ No newline at end of file diff --git a/class_m_a_x3421e__inherit__graph.png b/class_m_a_x3421e__inherit__graph.png index 538b3450..e781d3dd 100644 Binary files a/class_m_a_x3421e__inherit__graph.png and b/class_m_a_x3421e__inherit__graph.png differ diff --git a/class_max___l_c_d-members.html b/class_max___l_c_d-members.html index 5f2f0c35..b8be3c8a 100644 --- a/class_max___l_c_d-members.html +++ b/class_max___l_c_d-members.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Member List @@ -31,7 +31,7 @@
- + @@ -110,13 +110,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
scrollDisplayLeft()Max_LCD
scrollDisplayRight()Max_LCD
setCursor(uint8_t, uint8_t)Max_LCD
write(uint8_t)Max_LCDinlinevirtual
write(uint8_t)Max_LCDinlinevirtual
diff --git a/class_max___l_c_d.html b/class_max___l_c_d.html index a992d430..83db0f98 100644 --- a/class_max___l_c_d.html +++ b/class_max___l_c_d.html @@ -3,7 +3,7 @@ - + USB Host Shield 2.0: Max_LCD Class Reference @@ -31,7 +31,7 @@ - + @@ -92,6 +92,16 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');

#include <max_LCD.h>

+
+Inheritance diagram for Max_LCD:
+
+
Inheritance graph
+
[legend]
+
+Collaboration diagram for Max_LCD:
+
+
Collaboration graph
+
[legend]
@@ -133,10 +143,10 @@ Public Member Functions - - + +

Public Member Functions

 
void setCursor (uint8_t, uint8_t)
 
virtual void write (uint8_t)
 
void command (uint8_t)
 
virtual size_t write (uint8_t)
 

Detailed Description

@@ -510,32 +520,6 @@ Public Member Functions

Definition at line 124 of file max_LCD.cpp.

-
-
- -
-
- - - - - -
- - - - - - - - -
void Max_LCD::write (uint8_t value)
-
-inlinevirtual
-
- -

Definition at line 226 of file max_LCD.cpp.

-
@@ -562,6 +546,32 @@ Public Member Functions

Definition at line 221 of file max_LCD.cpp.

+ + + +
+
+ + + + + +
+ + + + + + + + +
size_t Max_LCD::write (uint8_t value)
+
+inlinevirtual
+
+ +

Definition at line 228 of file max_LCD.cpp.

+

The documentation for this class was generated from the following files: @@ -122,135 +122,165 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');

- a -

- b -

- c -

- d -

- f -

- g -

- h -

- k -