mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Several minor changes
This commit is contained in:
parent
234685359b
commit
a093e777d3
7 changed files with 33 additions and 89 deletions
49
BTD.cpp
49
BTD.cpp
|
@ -108,8 +108,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
|||
|
||||
// Assign new address to the device
|
||||
rcode = pUsb->setAddr( 0, 0, bAddress );
|
||||
if (rcode)
|
||||
{
|
||||
if (rcode) {
|
||||
p->lowspeed = false;
|
||||
addrPool.FreeAddress(bAddress);
|
||||
bAddress = 0;
|
||||
|
@ -140,44 +139,18 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
|||
PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
|
||||
|
||||
if(VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
|
||||
/* The application will work in reduced host mode, so we can save program and data
|
||||
memory space. After verifying the PID and VID we will use known values for the
|
||||
configuration values for device, interface, endpoints and HID for the PS3 Controllers */
|
||||
|
||||
/* Initialize data structures for endpoints of device */
|
||||
epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint
|
||||
epInfo[ PS3_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
|
||||
epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
|
||||
epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
|
||||
epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
|
||||
epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
|
||||
epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint
|
||||
epInfo[ PS3_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
|
||||
epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
|
||||
epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
|
||||
epInfo[ PS3_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
|
||||
epInfo[ PS3_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
|
||||
|
||||
rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
|
||||
if( rcode )
|
||||
goto FailSetDevTblEntry;
|
||||
|
||||
delay(200);//Give time for address change
|
||||
|
||||
/* We only need the Control endpoint, so we don't have to initialize the other endpoints of device */
|
||||
rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1);
|
||||
if( rcode )
|
||||
goto FailSetConf;
|
||||
|
||||
if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
|
||||
if(PID == PS3_PID) {
|
||||
#ifdef DEBUG
|
||||
if(PID == PS3_PID)
|
||||
Notify(PSTR("\r\nDualshock 3 Controller Connected"));
|
||||
#endif
|
||||
} else { // must be a navigation controller
|
||||
#ifdef DEBUG
|
||||
else // must be a navigation controller
|
||||
Notify(PSTR("\r\nNavigation Controller Connected"));
|
||||
#endif
|
||||
}
|
||||
/* Set internal bluetooth address */
|
||||
setBdaddr(my_bdaddr);
|
||||
}
|
||||
|
@ -241,7 +214,7 @@ FailSetDevTblEntry:
|
|||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nsetDevTblEn"));
|
||||
#endif
|
||||
goto Fail;
|
||||
goto Fail;
|
||||
FailGetConfDescr:
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\ngetConf"));
|
||||
|
@ -807,11 +780,11 @@ void BTD::hci_disconnect(uint16_t handle) { // This is called by the different s
|
|||
/************************************************************/
|
||||
void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
|
||||
uint8_t buf[256];
|
||||
buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
|
||||
buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
|
||||
buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
|
||||
buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
|
||||
buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
|
||||
buf[3] = (uint8_t)((4 + nbytes) >> 8);
|
||||
buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
|
||||
buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
|
||||
buf[5] = (uint8_t)(nbytes >> 8);
|
||||
buf[6] = channelLow;
|
||||
buf[7] = channelHigh;
|
||||
|
@ -920,8 +893,7 @@ void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t info
|
|||
}
|
||||
|
||||
/* PS3 Commands - only set Bluetooth address is implemented */
|
||||
void BTD::setBdaddr(uint8_t* BDADDR)
|
||||
{
|
||||
void BTD::setBdaddr(uint8_t* BDADDR) {
|
||||
/* Set the internal bluetooth address */
|
||||
uint8_t buf[8];
|
||||
buf[0] = 0x01;
|
||||
|
@ -942,8 +914,7 @@ void BTD::setBdaddr(uint8_t* BDADDR)
|
|||
#endif
|
||||
return;
|
||||
}
|
||||
void BTD::setMoveBdaddr(uint8_t* BDADDR)
|
||||
{
|
||||
void BTD::setMoveBdaddr(uint8_t* BDADDR) {
|
||||
/* Set the internal bluetooth address */
|
||||
uint8_t buf[11];
|
||||
buf[0] = 0x05;
|
||||
|
|
17
BTD.h
17
BTD.h
|
@ -18,17 +18,6 @@
|
|||
#ifndef _btd_h_
|
||||
#define _btd_h_
|
||||
|
||||
#define PS3_CONTROL_PIPE 0
|
||||
#define PS3_OUTPUT_PIPE 1
|
||||
#define PS3_INPUT_PIPE 2
|
||||
|
||||
#define PS3_CONTROL_PIPE 0
|
||||
#define PS3_OUTPUT_PIPE 1
|
||||
#define PS3_INPUT_PIPE 2
|
||||
|
||||
#define EP_INTERRUPT 0x03
|
||||
#define EP_MAXPKTSIZE 64 // max size for data via USB
|
||||
|
||||
#include "Usb.h"
|
||||
#include "confdescparser.h"
|
||||
|
||||
|
@ -127,7 +116,7 @@ class BluetoothService { // All services should include this class
|
|||
public:
|
||||
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
|
||||
virtual void Poll(); // Used to run the different state machines
|
||||
virtual void Release(); // Used to disconnect both the L2CAP Channel and the HCI Connection
|
||||
virtual void Release(); // Used to reset the services
|
||||
virtual void disconnect(); // Used to disconnect both the L2CAP Channel and the HCI Connection
|
||||
};
|
||||
|
||||
|
@ -150,7 +139,7 @@ public:
|
|||
for (uint8_t i=0; i<BTD_NUMDEVICES; i++)
|
||||
if (btService[i])
|
||||
btService[i]->disconnect(); // Disconnect both the L2CAP Channel and the HCI Connection
|
||||
};
|
||||
};
|
||||
|
||||
/* Register bluetooth dongle members/services */
|
||||
uint8_t registerServiceClass(BluetoothService *pService) {
|
||||
|
@ -220,7 +209,7 @@ private:
|
|||
BluetoothService* btService[BTD_NUMDEVICES];
|
||||
|
||||
bool bPollEnable;
|
||||
uint8_t pollInterval;
|
||||
uint8_t pollInterval;
|
||||
|
||||
/* variables used by high level HCI task */
|
||||
uint8_t hci_state; //current state of bluetooth hci connection
|
||||
|
|
47
PS3BT.cpp
47
PS3BT.cpp
|
@ -60,8 +60,7 @@ pBtd(p) // pointer to USB class instance - mandatory
|
|||
|
||||
Release();
|
||||
}
|
||||
bool PS3BT::getButton(Button b)
|
||||
{
|
||||
bool PS3BT::getButton(Button b) {
|
||||
if (l2capinpointer == NULL)
|
||||
return false;
|
||||
if(PS3MoveConnected) {
|
||||
|
@ -76,20 +75,17 @@ bool PS3BT::getButton(Button b)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
uint8_t PS3BT::getAnalogButton(AnalogButton a)
|
||||
{
|
||||
uint8_t PS3BT::getAnalogButton(AnalogButton a) {
|
||||
if (l2capinpointer == NULL)
|
||||
return 0;
|
||||
return (uint8_t)(l2capinpointer[(uint16_t)a]);
|
||||
}
|
||||
uint8_t PS3BT::getAnalogHat(AnalogHat a)
|
||||
{
|
||||
uint8_t PS3BT::getAnalogHat(AnalogHat a) {
|
||||
if (l2capinpointer == NULL)
|
||||
return 0;
|
||||
return (uint8_t)(l2capinpointer[(uint16_t)a]);
|
||||
}
|
||||
int16_t PS3BT::getSensor(Sensor a)
|
||||
{
|
||||
int16_t PS3BT::getSensor(Sensor a) {
|
||||
if (l2capinpointer == NULL)
|
||||
return 0;
|
||||
if (a == aX || a == aY || a == aZ || a == gZ)
|
||||
|
@ -157,18 +153,15 @@ String PS3BT::getTemperature() {
|
|||
return output;
|
||||
}
|
||||
}
|
||||
bool PS3BT::getStatus(Status c)
|
||||
{
|
||||
bool PS3BT::getStatus(Status c) {
|
||||
if (l2capinpointer == NULL)
|
||||
return false;
|
||||
if (l2capinpointer[(uint16_t)c >> 8] == ((uint8_t)c & 0xff))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
String PS3BT::getStatusString()
|
||||
{
|
||||
if (PS3Connected || PS3NavigationConnected)
|
||||
{
|
||||
String PS3BT::getStatusString() {
|
||||
if (PS3Connected || PS3NavigationConnected) {
|
||||
char statusOutput[100];
|
||||
|
||||
strcpy(statusOutput,"ConnectionStatus: ");
|
||||
|
@ -199,8 +192,7 @@ String PS3BT::getStatusString()
|
|||
return statusOutput;
|
||||
|
||||
}
|
||||
else if(PS3MoveConnected)
|
||||
{
|
||||
else if(PS3MoveConnected) {
|
||||
char statusOutput[50];
|
||||
|
||||
strcpy(statusOutput,"PowerRating: ");
|
||||
|
@ -371,8 +363,7 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
|
|||
//Serial.print("\r\nL2CAP Interrupt");
|
||||
if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
|
||||
/* Read Report */
|
||||
if(l2capinbuf[8] == 0xA1) // HID_THDR_DATA_INPUT
|
||||
{
|
||||
if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
|
||||
if(PS3Connected || PS3NavigationConnected)
|
||||
ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
|
||||
else if(PS3MoveConnected)
|
||||
|
@ -381,8 +372,7 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
|
|||
//Notify(PSTR("\r\nButtonState");
|
||||
//PrintHex<uint32_t>(ButtonState);
|
||||
|
||||
if(ButtonState != OldButtonState)
|
||||
{
|
||||
if(ButtonState != OldButtonState) {
|
||||
buttonChanged = true;
|
||||
if(ButtonState != 0x00) {
|
||||
buttonPressed = true;
|
||||
|
@ -391,16 +381,13 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
|
|||
buttonPressed = false;
|
||||
buttonReleased = true;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
}
|
||||
else {
|
||||
buttonChanged = false;
|
||||
buttonPressed = false;
|
||||
buttonReleased = false;
|
||||
}
|
||||
|
||||
OldButtonState = ButtonState;
|
||||
}
|
||||
OldButtonState = ButtonState;
|
||||
}
|
||||
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
|
||||
if(l2capinbuf[8] == 0xA1) { //HID_THDR_DATA_INPUT
|
||||
|
@ -532,10 +519,8 @@ void PS3BT::Poll() {
|
|||
break;
|
||||
|
||||
case L2CAP_EV_DONE:
|
||||
if (PS3MoveConnected)//The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on
|
||||
{
|
||||
if (millis() - timerBulbRumble > 4000)//Send at least every 4th second
|
||||
{
|
||||
if (PS3MoveConnected) { //The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on
|
||||
if (millis() - timerBulbRumble > 4000) { //Send at least every 4th second
|
||||
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);//The Bulb and rumble values, has to be written again and again, for it to stay turned on
|
||||
timerBulbRumble = millis();
|
||||
}
|
||||
|
|
2
PS3BT.h
2
PS3BT.h
|
@ -220,7 +220,7 @@ public:
|
|||
// BluetoothService implementation
|
||||
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
|
||||
virtual void Poll(); // Used to run the state maschine
|
||||
virtual void Release();
|
||||
virtual void Release(); // Use this to reset the service
|
||||
virtual void disconnect(); // Use this void to disconnect any of the controllers
|
||||
|
||||
/* PS3 Controller Commands */
|
||||
|
|
3
SPP.cpp
3
SPP.cpp
|
@ -66,8 +66,7 @@ void SPP::Release() {
|
|||
SDPConnected = false;
|
||||
l2cap_sdp_state = L2CAP_SDP_WAIT;
|
||||
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
||||
l2cap_event_flag = 0;
|
||||
|
||||
l2cap_event_flag = 0;
|
||||
}
|
||||
void SPP::disconnect(){
|
||||
connected = false;
|
||||
|
|
2
SPP.h
2
SPP.h
|
@ -100,7 +100,7 @@ public:
|
|||
// BluetoothService implementation
|
||||
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
|
||||
virtual void Poll(); // Used to run SDP_task() and RFCOMM_task()
|
||||
virtual void Release();
|
||||
virtual void Release(); // Use this to reset the service
|
||||
virtual void disconnect(); // Used this void to disconnect the virtual serial port
|
||||
|
||||
bool connected;// Variable used to indicate if the connection is established
|
||||
|
|
|
@ -41,7 +41,7 @@ buttonChanged KEYWORD2
|
|||
buttonPressed KEYWORD2
|
||||
buttonReleased KEYWORD2
|
||||
|
||||
isWatingForConnection KEYWORD2
|
||||
watingForConnection KEYWORD2
|
||||
|
||||
####################################################
|
||||
# Constants and enums (LITERAL1)
|
||||
|
|
Loading…
Reference in a new issue