mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'xxxajk' of github.com:felis/USB_Host_Shield_2.0 into xxxajk
This commit is contained in:
commit
fcaef6f5a2
7 changed files with 138 additions and 186 deletions
51
BTD.h
51
BTD.h
|
@ -30,7 +30,7 @@
|
||||||
#define IOGEAR_GBU521_PID 0x21E8
|
#define IOGEAR_GBU521_PID 0x21E8
|
||||||
|
|
||||||
/* Bluetooth dongle data taken from descriptors */
|
/* Bluetooth dongle data taken from descriptors */
|
||||||
#define BULK_MAXPKTSIZE 64 // max size for ACL data
|
#define BULK_MAXPKTSIZE 64 // Max size for ACL data
|
||||||
|
|
||||||
// Used in control endpoint header for HCI Commands
|
// Used in control endpoint header for HCI Commands
|
||||||
#define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
|
#define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
|
||||||
|
@ -71,9 +71,9 @@
|
||||||
#define HCI_FLAG_CONNECT_EVENT 0x100
|
#define HCI_FLAG_CONNECT_EVENT 0x100
|
||||||
|
|
||||||
/* Macros for HCI event flag tests */
|
/* Macros for HCI event flag tests */
|
||||||
#define hci_check_flag(flag) (hci_event_flag & flag)
|
#define hci_check_flag(flag) (hci_event_flag & (flag))
|
||||||
#define hci_set_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 hci_clear_flag(flag) (hci_event_flag &= ~(flag))
|
||||||
|
|
||||||
/* HCI Events managed */
|
/* HCI Events managed */
|
||||||
#define EV_INQUIRY_COMPLETE 0x01
|
#define EV_INQUIRY_COMPLETE 0x01
|
||||||
|
@ -117,23 +117,20 @@
|
||||||
|
|
||||||
/* Used for SDP channel */
|
/* Used for SDP channel */
|
||||||
#define L2CAP_SDP_WAIT 10
|
#define L2CAP_SDP_WAIT 10
|
||||||
#define L2CAP_SDP_REQUEST 11
|
#define L2CAP_SDP_SUCCESS 11
|
||||||
#define L2CAP_SDP_SUCCESS 12
|
|
||||||
#define L2CAP_SDP_DONE 13
|
|
||||||
#define L2CAP_DISCONNECT_RESPONSE 14
|
|
||||||
|
|
||||||
/* Used for RFCOMM channel */
|
/* Used for RFCOMM channel */
|
||||||
#define L2CAP_RFCOMM_WAIT 15
|
#define L2CAP_RFCOMM_WAIT 12
|
||||||
#define L2CAP_RFCOMM_REQUEST 16
|
#define L2CAP_RFCOMM_SUCCESS 13
|
||||||
#define L2CAP_RFCOMM_SUCCESS 17
|
|
||||||
#define L2CAP_RFCOMM_DONE 18
|
#define L2CAP_DISCONNECT_RESPONSE 14 // Used for both SDP and RFCOMM channel
|
||||||
|
|
||||||
/* Bluetooth states used by some drivers */
|
/* Bluetooth states used by some drivers */
|
||||||
#define TURN_ON_LED 19
|
#define TURN_ON_LED 17
|
||||||
#define PS3_ENABLE_SIXAXIS 20
|
#define PS3_ENABLE_SIXAXIS 18
|
||||||
#define WII_CHECK_MOTION_PLUS_STATE 21
|
#define WII_CHECK_MOTION_PLUS_STATE 19
|
||||||
#define WII_CHECK_EXTENSION_STATE 22
|
#define WII_CHECK_EXTENSION_STATE 20
|
||||||
#define WII_INIT_MOTION_PLUS_STATE 23
|
#define WII_INIT_MOTION_PLUS_STATE 21
|
||||||
|
|
||||||
/* L2CAP event flags for HID Control channel */
|
/* L2CAP event flags for HID Control channel */
|
||||||
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x00000001
|
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x00000001
|
||||||
|
@ -149,22 +146,20 @@
|
||||||
|
|
||||||
/* L2CAP event flags for SDP channel */
|
/* L2CAP event flags for SDP channel */
|
||||||
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x00000100
|
#define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x00000100
|
||||||
#define L2CAP_FLAG_CONFIG_SDP_REQUEST 0x00000200
|
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x00000200
|
||||||
#define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x00000400
|
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x00000400
|
||||||
#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x00000800
|
|
||||||
|
|
||||||
/* L2CAP event flags for RFCOMM channel */
|
/* L2CAP event flags for RFCOMM channel */
|
||||||
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x00001000
|
#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x00000800
|
||||||
#define L2CAP_FLAG_CONFIG_RFCOMM_REQUEST 0x00002000
|
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x00001000
|
||||||
#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x00004000
|
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x00002000
|
||||||
#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x00008000
|
|
||||||
|
|
||||||
#define L2CAP_FLAG_DISCONNECT_RESPONSE 0x00010000
|
#define L2CAP_FLAG_DISCONNECT_RESPONSE 0x00004000
|
||||||
|
|
||||||
/* Macros for L2CAP event flag tests */
|
/* Macros for L2CAP event flag tests */
|
||||||
#define l2cap_check_flag(flag) (l2cap_event_flag & flag)
|
#define l2cap_check_flag(flag) (l2cap_event_flag & (flag))
|
||||||
#define l2cap_set_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_clear_flag(flag) (l2cap_event_flag &= ~(flag))
|
||||||
|
|
||||||
/* L2CAP signaling commands */
|
/* L2CAP signaling commands */
|
||||||
#define L2CAP_CMD_COMMAND_REJECT 0x01
|
#define L2CAP_CMD_COMMAND_REJECT 0x01
|
||||||
|
|
11
BTHID.cpp
11
BTHID.cpp
|
@ -31,8 +31,6 @@ protocolMode(HID_BOOT_PROTOCOL)
|
||||||
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
||||||
|
|
||||||
pBtd->pairWithHIDDevice = pair;
|
pBtd->pairWithHIDDevice = pair;
|
||||||
|
|
||||||
if (pair)
|
|
||||||
pBtd->btdPin= pin;
|
pBtd->btdPin= pin;
|
||||||
|
|
||||||
/* Set device cid for the control and intterrupt channelse - LSB */
|
/* Set device cid for the control and intterrupt channelse - LSB */
|
||||||
|
@ -53,7 +51,7 @@ void BTHID::Reset() {
|
||||||
|
|
||||||
void BTHID::disconnect() { // Use this void to disconnect any of the controllers
|
void BTHID::disconnect() { // Use this void to disconnect any of the controllers
|
||||||
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
|
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
|
||||||
pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
|
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
|
||||||
Reset();
|
Reset();
|
||||||
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
||||||
}
|
}
|
||||||
|
@ -204,13 +202,6 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
|
||||||
pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<HID *> (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
|
pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast<HID *> (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x03:
|
|
||||||
#ifdef DEBUG_USB_HOST
|
|
||||||
Notify(PSTR("\r\nChange mode event: "), 0x80);
|
|
||||||
D_PrintHex<uint8_t > (l2capinbuf[11], 0x80);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
#ifdef DEBUG_USB_HOST
|
#ifdef DEBUG_USB_HOST
|
||||||
default:
|
default:
|
||||||
Notify(PSTR("\r\nUnknown Report type: "), 0x80);
|
Notify(PSTR("\r\nUnknown Report type: "), 0x80);
|
||||||
|
|
66
PS3BT.cpp
66
PS3BT.cpp
|
@ -162,48 +162,48 @@ bool PS3BT::getStatus(Status c) {
|
||||||
|
|
||||||
String PS3BT::getStatusString() {
|
String PS3BT::getStatusString() {
|
||||||
if (PS3Connected || PS3NavigationConnected) {
|
if (PS3Connected || PS3NavigationConnected) {
|
||||||
char statusOutput[100];
|
char statusOutput[100]; // Max string length plus null character
|
||||||
|
|
||||||
strcpy(statusOutput, "ConnectionStatus: ");
|
strcpy_P(statusOutput, PSTR("ConnectionStatus: "));
|
||||||
|
|
||||||
if (getStatus(Plugged)) strcat(statusOutput, "Plugged");
|
if (getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged"));
|
||||||
else if (getStatus(Unplugged)) strcat(statusOutput, "Unplugged");
|
else if (getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged"));
|
||||||
else strcat(statusOutput, "Error");
|
else strcat_P(statusOutput, PSTR("Error"));
|
||||||
|
|
||||||
|
|
||||||
strcat(statusOutput, " - PowerRating: ");
|
strcat_P(statusOutput, PSTR(" - PowerRating: "));
|
||||||
if (getStatus(Charging)) strcat(statusOutput, "Charging");
|
if (getStatus(Charging)) strcat_P(statusOutput, PSTR("Charging"));
|
||||||
else if (getStatus(NotCharging)) strcat(statusOutput, "Not Charging");
|
else if (getStatus(NotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
|
||||||
else if (getStatus(Shutdown)) strcat(statusOutput, "Shutdown");
|
else if (getStatus(Shutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
|
||||||
else if (getStatus(Dying)) strcat(statusOutput, "Dying");
|
else if (getStatus(Dying)) strcat_P(statusOutput, PSTR("Dying"));
|
||||||
else if (getStatus(Low)) strcat(statusOutput, "Low");
|
else if (getStatus(Low)) strcat_P(statusOutput, PSTR("Low"));
|
||||||
else if (getStatus(High)) strcat(statusOutput, "High");
|
else if (getStatus(High)) strcat_P(statusOutput, PSTR("High"));
|
||||||
else if (getStatus(Full)) strcat(statusOutput, "Full");
|
else if (getStatus(Full)) strcat_P(statusOutput, PSTR("Full"));
|
||||||
else strcat(statusOutput, "Error");
|
else strcat_P(statusOutput, PSTR("Error"));
|
||||||
|
|
||||||
strcat(statusOutput, " - WirelessStatus: ");
|
strcat_P(statusOutput, PSTR(" - WirelessStatus: "));
|
||||||
|
|
||||||
if (getStatus(CableRumble)) strcat(statusOutput, "Cable - Rumble is on");
|
if (getStatus(CableRumble)) strcat_P(statusOutput, PSTR("Cable - Rumble is on"));
|
||||||
else if (getStatus(Cable)) strcat(statusOutput, "Cable - Rumble is off");
|
else if (getStatus(Cable)) strcat_P(statusOutput, PSTR("Cable - Rumble is off"));
|
||||||
else if (getStatus(BluetoothRumble)) strcat(statusOutput, "Bluetooth - Rumble is on");
|
else if (getStatus(BluetoothRumble)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is on"));
|
||||||
else if (getStatus(Bluetooth)) strcat(statusOutput, "Bluetooth - Rumble is off");
|
else if (getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off"));
|
||||||
else strcat(statusOutput, "Error");
|
else strcat_P(statusOutput, PSTR("Error"));
|
||||||
|
|
||||||
return statusOutput;
|
return statusOutput;
|
||||||
|
|
||||||
} else if (PS3MoveConnected) {
|
} else if (PS3MoveConnected) {
|
||||||
char statusOutput[50];
|
char statusOutput[26]; // Max string length plus null character
|
||||||
|
|
||||||
strcpy(statusOutput, "PowerRating: ");
|
strcpy_P(statusOutput, PSTR("PowerRating: "));
|
||||||
|
|
||||||
if (getStatus(MoveCharging)) strcat(statusOutput, "Charging");
|
if (getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging"));
|
||||||
else if (getStatus(MoveNotCharging)) strcat(statusOutput, "Not Charging");
|
else if (getStatus(MoveNotCharging)) strcat_P(statusOutput, PSTR("Not Charging"));
|
||||||
else if (getStatus(MoveShutdown)) strcat(statusOutput, "Shutdown");
|
else if (getStatus(MoveShutdown)) strcat_P(statusOutput, PSTR("Shutdown"));
|
||||||
else if (getStatus(MoveDying)) strcat(statusOutput, "Dying");
|
else if (getStatus(MoveDying)) strcat_P(statusOutput, PSTR("Dying"));
|
||||||
else if (getStatus(MoveLow)) strcat(statusOutput, "Low");
|
else if (getStatus(MoveLow)) strcat_P(statusOutput, PSTR("Low"));
|
||||||
else if (getStatus(MoveHigh)) strcat(statusOutput, "High");
|
else if (getStatus(MoveHigh)) strcat_P(statusOutput, PSTR("High"));
|
||||||
else if (getStatus(MoveFull)) strcat(statusOutput, "Full");
|
else if (getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full"));
|
||||||
else strcat(statusOutput, "Error");
|
else strcat_P(statusOutput, PSTR("Error"));
|
||||||
|
|
||||||
return statusOutput;
|
return statusOutput;
|
||||||
} else
|
} else
|
||||||
|
@ -218,14 +218,14 @@ void PS3BT::Reset() {
|
||||||
l2cap_event_flag = 0; // Reset flags
|
l2cap_event_flag = 0; // Reset flags
|
||||||
l2cap_state = L2CAP_WAIT;
|
l2cap_state = L2CAP_WAIT;
|
||||||
|
|
||||||
// Needed for PS3 Dualshock Controller commands to work via bluetooth
|
// Needed for PS3 Dualshock Controller commands to work via Bluetooth
|
||||||
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
|
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
|
||||||
HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
|
HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
|
void PS3BT::disconnect() { // Use this void to disconnect any of the controllers
|
||||||
//First the HID interrupt channel has to be disconencted, then the HID control channel and finally the HCI connection
|
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
|
||||||
pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
|
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
|
||||||
Reset();
|
Reset();
|
||||||
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
||||||
}
|
}
|
||||||
|
|
90
SPP.cpp
90
SPP.cpp
|
@ -73,13 +73,13 @@ void SPP::Reset() {
|
||||||
|
|
||||||
void SPP::disconnect() {
|
void SPP::disconnect() {
|
||||||
connected = false;
|
connected = false;
|
||||||
// First the two L2CAP channels has to be disconencted and then the HCI connection
|
// First the two L2CAP channels has to be disconnected and then the HCI connection
|
||||||
if (RFCOMMConnected)
|
if (RFCOMMConnected)
|
||||||
pBtd->l2cap_disconnection_request(hci_handle, 0x0A, rfcomm_scid, rfcomm_dcid);
|
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, rfcomm_scid, rfcomm_dcid);
|
||||||
if (RFCOMMConnected && SDPConnected)
|
if (RFCOMMConnected && SDPConnected)
|
||||||
delay(1); // Add delay between commands
|
delay(1); // Add delay between commands
|
||||||
if (SDPConnected)
|
if (SDPConnected)
|
||||||
pBtd->l2cap_disconnection_request(hci_handle, 0x0B, sdp_scid, sdp_dcid);
|
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, sdp_scid, sdp_dcid);
|
||||||
l2cap_sdp_state = L2CAP_DISCONNECT_RESPONSE;
|
l2cap_sdp_state = L2CAP_DISCONNECT_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +151,10 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
|
||||||
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
|
} else if (l2capinbuf[8] == L2CAP_CMD_CONFIG_REQUEST) {
|
||||||
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
|
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
|
||||||
//Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
|
//Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
|
||||||
identifier = l2capinbuf[9];
|
pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], sdp_scid);
|
||||||
l2cap_set_flag(L2CAP_FLAG_CONFIG_SDP_REQUEST);
|
|
||||||
} else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
|
} else if (l2capinbuf[12] == rfcomm_dcid[0] && l2capinbuf[13] == rfcomm_dcid[1]) {
|
||||||
//Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
|
//Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
|
||||||
identifier = l2capinbuf[9];
|
pBtd->l2cap_config_response(hci_handle, l2capinbuf[9], rfcomm_scid);
|
||||||
l2cap_set_flag(L2CAP_FLAG_CONFIG_RFCOMM_REQUEST);
|
|
||||||
}
|
}
|
||||||
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
|
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
|
||||||
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
|
if (l2capinbuf[12] == sdp_dcid[0] && l2capinbuf[13] == sdp_dcid[1]) {
|
||||||
|
@ -403,7 +401,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
|
||||||
connected = true; // The RFCOMM channel is now established
|
connected = true; // The RFCOMM channel is now established
|
||||||
sppIndex = 0;
|
sppIndex = 0;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_USB_HOST
|
#ifdef EXTRADEBUG
|
||||||
else if (rfcommChannelType != RFCOMM_DISC) {
|
else if (rfcommChannelType != RFCOMM_DISC) {
|
||||||
Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80);
|
Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80);
|
||||||
D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
|
D_PrintHex<uint8_t > (rfcommChannelType, 0x80);
|
||||||
|
@ -453,17 +451,14 @@ void SPP::SDP_task() {
|
||||||
identifier++;
|
identifier++;
|
||||||
delay(1);
|
delay(1);
|
||||||
pBtd->l2cap_config_request(hci_handle, identifier, sdp_scid);
|
pBtd->l2cap_config_request(hci_handle, identifier, sdp_scid);
|
||||||
l2cap_sdp_state = L2CAP_SDP_REQUEST;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case L2CAP_SDP_REQUEST:
|
|
||||||
if (l2cap_check_flag(L2CAP_FLAG_CONFIG_SDP_REQUEST)) {
|
|
||||||
l2cap_clear_flag(L2CAP_FLAG_CONFIG_SDP_REQUEST); // Clear flag
|
|
||||||
#ifdef DEBUG_USB_HOST
|
|
||||||
Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
|
|
||||||
#endif
|
|
||||||
pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid);
|
|
||||||
l2cap_sdp_state = L2CAP_SDP_SUCCESS;
|
l2cap_sdp_state = L2CAP_SDP_SUCCESS;
|
||||||
|
} else if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST)) {
|
||||||
|
l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST); // Clear flag
|
||||||
|
SDPConnected = false;
|
||||||
|
#ifdef DEBUG_USB_HOST
|
||||||
|
Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80);
|
||||||
|
#endif
|
||||||
|
pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case L2CAP_SDP_SUCCESS:
|
case L2CAP_SDP_SUCCESS:
|
||||||
|
@ -474,33 +469,18 @@ void SPP::SDP_task() {
|
||||||
#endif
|
#endif
|
||||||
firstMessage = true; // Reset bool
|
firstMessage = true; // Reset bool
|
||||||
SDPConnected = true;
|
SDPConnected = true;
|
||||||
l2cap_sdp_state = L2CAP_SDP_DONE;
|
l2cap_sdp_state = L2CAP_SDP_WAIT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case L2CAP_SDP_DONE:
|
|
||||||
if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST)) {
|
|
||||||
l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_SDP_REQUEST); // Clear flag
|
|
||||||
SDPConnected = false;
|
|
||||||
#ifdef DEBUG_USB_HOST
|
|
||||||
Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80);
|
|
||||||
#endif
|
|
||||||
pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid);
|
|
||||||
l2cap_sdp_state = L2CAP_SDP_WAIT;
|
|
||||||
} else if (l2cap_check_flag(L2CAP_FLAG_CONNECTION_SDP_REQUEST))
|
|
||||||
l2cap_rfcomm_state = L2CAP_SDP_WAIT;
|
|
||||||
break;
|
|
||||||
case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected
|
case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected
|
||||||
if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RESPONSE)) {
|
if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RESPONSE)) {
|
||||||
#ifdef DEBUG_USB_HOST
|
#ifdef DEBUG_USB_HOST
|
||||||
Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80);
|
Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80);
|
||||||
#endif
|
#endif
|
||||||
RFCOMMConnected = false;
|
|
||||||
SDPConnected = false;
|
|
||||||
pBtd->hci_disconnect(hci_handle);
|
pBtd->hci_disconnect(hci_handle);
|
||||||
hci_handle = -1; // Reset handle
|
hci_handle = -1; // Reset handle
|
||||||
l2cap_event_flag = 0; // Reset flags
|
Reset();
|
||||||
l2cap_sdp_state = L2CAP_SDP_WAIT;
|
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -520,17 +500,15 @@ void SPP::RFCOMM_task() {
|
||||||
identifier++;
|
identifier++;
|
||||||
delay(1);
|
delay(1);
|
||||||
pBtd->l2cap_config_request(hci_handle, identifier, rfcomm_scid);
|
pBtd->l2cap_config_request(hci_handle, identifier, rfcomm_scid);
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_REQUEST;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case L2CAP_RFCOMM_REQUEST:
|
|
||||||
if (l2cap_check_flag(L2CAP_FLAG_CONFIG_RFCOMM_REQUEST)) {
|
|
||||||
l2cap_clear_flag(L2CAP_FLAG_CONFIG_RFCOMM_REQUEST); // Clear flag
|
|
||||||
#ifdef DEBUG_USB_HOST
|
|
||||||
Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
|
|
||||||
#endif
|
|
||||||
pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid);
|
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_SUCCESS;
|
l2cap_rfcomm_state = L2CAP_RFCOMM_SUCCESS;
|
||||||
|
} else if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)) {
|
||||||
|
l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST); // Clear flag
|
||||||
|
RFCOMMConnected = false;
|
||||||
|
connected = false;
|
||||||
|
#ifdef DEBUG_USB_HOST
|
||||||
|
Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80);
|
||||||
|
#endif
|
||||||
|
pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case L2CAP_RFCOMM_SUCCESS:
|
case L2CAP_RFCOMM_SUCCESS:
|
||||||
|
@ -542,22 +520,9 @@ void SPP::RFCOMM_task() {
|
||||||
rfcommAvailable = 0; // Reset number of bytes available
|
rfcommAvailable = 0; // Reset number of bytes available
|
||||||
bytesRead = 0; // Reset number of bytes received
|
bytesRead = 0; // Reset number of bytes received
|
||||||
RFCOMMConnected = true;
|
RFCOMMConnected = true;
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_DONE;
|
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case L2CAP_RFCOMM_DONE:
|
|
||||||
if (l2cap_check_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST)) {
|
|
||||||
l2cap_clear_flag(L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST); // Clear flag
|
|
||||||
RFCOMMConnected = false;
|
|
||||||
connected = false;
|
|
||||||
#ifdef DEBUG_USB_HOST
|
|
||||||
Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80);
|
|
||||||
#endif
|
|
||||||
pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid);
|
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
|
||||||
} else if (l2cap_check_flag(L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST))
|
|
||||||
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
|
@ -741,10 +706,11 @@ uint8_t SPP::crc(uint8_t *data) {
|
||||||
|
|
||||||
/* Calculate FCS */
|
/* Calculate FCS */
|
||||||
uint8_t SPP::calcFcs(uint8_t *data) {
|
uint8_t SPP::calcFcs(uint8_t *data) {
|
||||||
|
uint8_t temp = crc(data);
|
||||||
if ((data[1] & 0xEF) == RFCOMM_UIH)
|
if ((data[1] & 0xEF) == RFCOMM_UIH)
|
||||||
return (0xFF - crc(data)); // FCS on 2 bytes
|
return (0xFF - temp); // FCS on 2 bytes
|
||||||
else
|
else
|
||||||
return (0xFF - pgm_read_byte(&rfcomm_crc_table[crc(data) ^ data[2]])); // FCS on 3 bytes
|
return (0xFF - pgm_read_byte(&rfcomm_crc_table[temp ^ data[2]])); // FCS on 3 bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check FCS */
|
/* Check FCS */
|
||||||
|
|
2
Wii.cpp
2
Wii.cpp
|
@ -126,7 +126,7 @@ void WII::disconnect() { // Use this void to disconnect any of the controllers
|
||||||
} else
|
} else
|
||||||
timer = millis(); // Don't wait
|
timer = millis(); // Don't wait
|
||||||
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
|
// First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection
|
||||||
pBtd->l2cap_disconnection_request(hci_handle, 0x0A, interrupt_scid, interrupt_dcid);
|
pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid);
|
||||||
Reset();
|
Reset();
|
||||||
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
l2cap_state = L2CAP_INTERRUPT_DISCONNECT;
|
||||||
}
|
}
|
||||||
|
|
6
Wii.h
6
Wii.h
|
@ -30,9 +30,9 @@
|
||||||
#define WII_FLAG_MOTION_PLUS_CONNECTED 0x01
|
#define WII_FLAG_MOTION_PLUS_CONNECTED 0x01
|
||||||
#define WII_FLAG_NUNCHUCK_CONNECTED 0x02
|
#define WII_FLAG_NUNCHUCK_CONNECTED 0x02
|
||||||
|
|
||||||
#define wii_check_flag(flag) (wii_event_flag & flag)
|
#define wii_check_flag(flag) (wii_event_flag & (flag))
|
||||||
#define wii_set_flag(flag) (wii_event_flag |= flag)
|
#define wii_set_flag(flag) (wii_event_flag |= (flag))
|
||||||
#define wii_clear_flag(flag) (wii_event_flag &= ~flag)
|
#define wii_clear_flag(flag) (wii_event_flag &= ~(flag))
|
||||||
|
|
||||||
/** Enum used to read the joystick on the Nunchuck. */
|
/** Enum used to read the joystick on the Nunchuck. */
|
||||||
enum Hat {
|
enum Hat {
|
||||||
|
|
96
usbhost.h
96
usbhost.h
|
@ -28,7 +28,7 @@ e-mail : support@circuitsathome.com
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* SPI initialization */
|
/* SPI initialization */
|
||||||
template< typename CLK, typename MOSI, typename MISO, typename SPI_SS > class SPi {
|
template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi {
|
||||||
#if USING_SPI4TEENSY3
|
#if USING_SPI4TEENSY3
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ public:
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
//uint8_t tmp;
|
//uint8_t tmp;
|
||||||
CLK::SetDirWrite();
|
SPI_CLK::SetDirWrite();
|
||||||
MOSI::SetDirWrite();
|
SPI_MOSI::SetDirWrite();
|
||||||
MISO::SetDirRead();
|
SPI_MISO::SetDirRead();
|
||||||
SPI_SS::SetDirWrite();
|
SPI_SS::SetDirWrite();
|
||||||
/* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */
|
/* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */
|
||||||
SPCR = 0x50;
|
SPCR = 0x50;
|
||||||
|
@ -78,7 +78,7 @@ typedef enum {
|
||||||
vbus_off = GPX_VBDET
|
vbus_off = GPX_VBDET
|
||||||
} VBUS_t;
|
} VBUS_t;
|
||||||
|
|
||||||
template< typename SS, typename INTR > class MAX3421e /* : public spi */ {
|
template< typename SPI_SS, typename INTR > class MAX3421e /* : public spi */ {
|
||||||
static uint8_t vbusState;
|
static uint8_t vbusState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -106,12 +106,12 @@ public:
|
||||||
uint8_t Task();
|
uint8_t Task();
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t MAX3421e< SS, INTR >::vbusState = 0;
|
uint8_t MAX3421e< SPI_SS, INTR >::vbusState = 0;
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
MAX3421e< SS, INTR >::MAX3421e() {
|
MAX3421e< SPI_SS, INTR >::MAX3421e() {
|
||||||
// Leaving ADK hardware setup in here, for now. This really belongs with the other parts.
|
// Leaving ADK hardware setup in here, for now. This really belongs with the other parts.
|
||||||
#ifdef BOARD_MEGA_ADK
|
#ifdef BOARD_MEGA_ADK
|
||||||
// For Mega ADK, which has a Max3421e on-board, set MAX_RESET to output mode, and then set it to HIGH
|
// For Mega ADK, which has a Max3421e on-board, set MAX_RESET to output mode, and then set it to HIGH
|
||||||
|
@ -121,10 +121,10 @@ MAX3421e< SS, INTR >::MAX3421e() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* write single byte into MAX3421 register */
|
/* write single byte into MAX3421 register */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
void MAX3421e< SS, INTR >::regWr(uint8_t reg, uint8_t data) {
|
void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
SS::Clear();
|
SPI_SS::Clear();
|
||||||
#if USING_SPI4TEENSY3
|
#if USING_SPI4TEENSY3
|
||||||
uint8_t c[2];
|
uint8_t c[2];
|
||||||
c[0] = reg | 0x02;
|
c[0] = reg | 0x02;
|
||||||
|
@ -136,17 +136,17 @@ void MAX3421e< SS, INTR >::regWr(uint8_t reg, uint8_t data) {
|
||||||
SPDR = data;
|
SPDR = data;
|
||||||
while(!(SPSR & (1 << SPIF)));
|
while(!(SPSR & (1 << SPIF)));
|
||||||
#endif
|
#endif
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
/* multiple-byte write */
|
/* multiple-byte write */
|
||||||
|
|
||||||
/* returns a pointer to memory position after last written */
|
/* returns a pointer to memory position after last written */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t* MAX3421e< SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p) {
|
uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p) {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
SS::Clear();
|
SPI_SS::Clear();
|
||||||
#if USING_SPI4TEENSY3
|
#if USING_SPI4TEENSY3
|
||||||
spi4teensy3::send(reg | 0x02);
|
spi4teensy3::send(reg | 0x02);
|
||||||
spi4teensy3::send(data_p, nbytes);
|
spi4teensy3::send(data_p, nbytes);
|
||||||
|
@ -160,7 +160,7 @@ uint8_t* MAX3421e< SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* dat
|
||||||
}
|
}
|
||||||
while(!(SPSR & (1 << SPIF)));
|
while(!(SPSR & (1 << SPIF)));
|
||||||
#endif
|
#endif
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
return( data_p);
|
return( data_p);
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,8 @@ uint8_t* MAX3421e< SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* dat
|
||||||
/*GPIO byte is split between 2 registers, so two writes are needed to write one byte */
|
/*GPIO byte is split between 2 registers, so two writes are needed to write one byte */
|
||||||
|
|
||||||
/* GPOUT bits are in the low nibble. 0-3 in IOPINS1, 4-7 in IOPINS2 */
|
/* GPOUT bits are in the low nibble. 0-3 in IOPINS1, 4-7 in IOPINS2 */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
void MAX3421e< SS, INTR >::gpioWr(uint8_t data) {
|
void MAX3421e< SPI_SS, INTR >::gpioWr(uint8_t data) {
|
||||||
regWr(rIOPINS1, data);
|
regWr(rIOPINS1, data);
|
||||||
data >>= 4;
|
data >>= 4;
|
||||||
regWr(rIOPINS2, data);
|
regWr(rIOPINS2, data);
|
||||||
|
@ -177,20 +177,20 @@ void MAX3421e< SS, INTR >::gpioWr(uint8_t data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* single host register read */
|
/* single host register read */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t MAX3421e< SS, INTR >::regRd(uint8_t reg) {
|
uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
SS::Clear();
|
SPI_SS::Clear();
|
||||||
#if USING_SPI4TEENSY3
|
#if USING_SPI4TEENSY3
|
||||||
spi4teensy3::send(reg);
|
spi4teensy3::send(reg);
|
||||||
uint8_t rv = spi4teensy3::receive();
|
uint8_t rv = spi4teensy3::receive();
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
#else
|
#else
|
||||||
SPDR = reg;
|
SPDR = reg;
|
||||||
while(!(SPSR & (1 << SPIF)));
|
while(!(SPSR & (1 << SPIF)));
|
||||||
SPDR = 0; //send empty byte
|
SPDR = 0; //send empty byte
|
||||||
while(!(SPSR & (1 << SPIF)));
|
while(!(SPSR & (1 << SPIF)));
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
uint8_t rv = SPDR;
|
uint8_t rv = SPDR;
|
||||||
#endif
|
#endif
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
|
@ -199,10 +199,10 @@ uint8_t MAX3421e< SS, INTR >::regRd(uint8_t reg) {
|
||||||
/* multiple-byte register read */
|
/* multiple-byte register read */
|
||||||
|
|
||||||
/* returns a pointer to a memory position after last read */
|
/* returns a pointer to a memory position after last read */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t* MAX3421e< SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p) {
|
uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p) {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
SS::Clear();
|
SPI_SS::Clear();
|
||||||
#if USING_SPI4TEENSY3
|
#if USING_SPI4TEENSY3
|
||||||
spi4teensy3::send(reg);
|
spi4teensy3::send(reg);
|
||||||
spi4teensy3::receive(data_p, nbytes);
|
spi4teensy3::receive(data_p, nbytes);
|
||||||
|
@ -227,15 +227,15 @@ uint8_t* MAX3421e< SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* dat
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
return( data_p);
|
return( data_p);
|
||||||
}
|
}
|
||||||
/* GPIO read. See gpioWr for explanation */
|
/* GPIO read. See gpioWr for explanation */
|
||||||
|
|
||||||
/* GPIN pins are in high nibbles of IOPINS1, IOPINS2 */
|
/* GPIN pins are in high nibbles of IOPINS1, IOPINS2 */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t MAX3421e< SS, INTR >::gpioRd() {
|
uint8_t MAX3421e< SPI_SS, INTR >::gpioRd() {
|
||||||
uint8_t gpin = 0;
|
uint8_t gpin = 0;
|
||||||
gpin = regRd(rIOPINS2); //pins 4-7
|
gpin = regRd(rIOPINS2); //pins 4-7
|
||||||
gpin &= 0xf0; //clean lower nibble
|
gpin &= 0xf0; //clean lower nibble
|
||||||
|
@ -245,8 +245,8 @@ uint8_t MAX3421e< SS, INTR >::gpioRd() {
|
||||||
|
|
||||||
/* reset MAX3421E. Returns number of cycles it took for PLL to stabilize after reset
|
/* reset MAX3421E. Returns number of cycles it took for PLL to stabilize after reset
|
||||||
or zero if PLL haven't stabilized in 65535 cycles */
|
or zero if PLL haven't stabilized in 65535 cycles */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint16_t MAX3421e< SS, INTR >::reset() {
|
uint16_t MAX3421e< SPI_SS, INTR >::reset() {
|
||||||
uint16_t i = 0;
|
uint16_t i = 0;
|
||||||
regWr(rUSBCTL, bmCHIPRES);
|
regWr(rUSBCTL, bmCHIPRES);
|
||||||
regWr(rUSBCTL, 0x00);
|
regWr(rUSBCTL, 0x00);
|
||||||
|
@ -259,15 +259,15 @@ uint16_t MAX3421e< SS, INTR >::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
|
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
int8_t MAX3421e< SS, INTR >::Init() {
|
int8_t MAX3421e< SPI_SS, INTR >::Init() {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
// Moved here.
|
// Moved here.
|
||||||
// you really should not init hardware in the constructor when it involves locks.
|
// you really should not init hardware in the constructor when it involves locks.
|
||||||
// Also avoids the vbus flicker issue confusing some devices.
|
// Also avoids the vbus flicker issue confusing some devices.
|
||||||
/* pin and peripheral setup */
|
/* pin and peripheral setup */
|
||||||
SS::SetDirWrite();
|
SPI_SS::SetDirWrite();
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
spi::init();
|
spi::init();
|
||||||
INTR::SetDirRead();
|
INTR::SetDirRead();
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
|
@ -296,15 +296,15 @@ int8_t MAX3421e< SS, INTR >::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
|
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
int8_t MAX3421e< SS, INTR >::Init(int mseconds) {
|
int8_t MAX3421e< SPI_SS, INTR >::Init(int mseconds) {
|
||||||
XMEM_ACQUIRE_SPI();
|
XMEM_ACQUIRE_SPI();
|
||||||
// Moved here.
|
// Moved here.
|
||||||
// you really should not init hardware in the constructor when it involves locks.
|
// you really should not init hardware in the constructor when it involves locks.
|
||||||
// Also avoids the vbus flicker issue confusing some devices.
|
// Also avoids the vbus flicker issue confusing some devices.
|
||||||
/* pin and peripheral setup */
|
/* pin and peripheral setup */
|
||||||
SS::SetDirWrite();
|
SPI_SS::SetDirWrite();
|
||||||
SS::Set();
|
SPI_SS::Set();
|
||||||
spi::init();
|
spi::init();
|
||||||
INTR::SetDirRead();
|
INTR::SetDirRead();
|
||||||
XMEM_RELEASE_SPI();
|
XMEM_RELEASE_SPI();
|
||||||
|
@ -340,8 +340,8 @@ int8_t MAX3421e< SS, INTR >::Init(int mseconds) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* probe bus to determine device presence and speed and switch host to this speed */
|
/* probe bus to determine device presence and speed and switch host to this speed */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
void MAX3421e< SS, INTR >::busprobe() {
|
void MAX3421e< SPI_SS, INTR >::busprobe() {
|
||||||
uint8_t bus_sample;
|
uint8_t bus_sample;
|
||||||
bus_sample = regRd(rHRSL); //Get J,K status
|
bus_sample = regRd(rHRSL); //Get J,K status
|
||||||
bus_sample &= (bmJSTATUS | bmKSTATUS); //zero the rest of the byte
|
bus_sample &= (bmJSTATUS | bmKSTATUS); //zero the rest of the byte
|
||||||
|
@ -375,8 +375,8 @@ void MAX3421e< SS, INTR >::busprobe() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MAX3421 state change task and interrupt handler */
|
/* MAX3421 state change task and interrupt handler */
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t MAX3421e< SS, INTR >::Task(void) {
|
uint8_t MAX3421e< SPI_SS, INTR >::Task(void) {
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
uint8_t pinvalue;
|
uint8_t pinvalue;
|
||||||
//USB_HOST_SERIAL.print("Vbus state: ");
|
//USB_HOST_SERIAL.print("Vbus state: ");
|
||||||
|
@ -394,8 +394,8 @@ uint8_t MAX3421e< SS, INTR >::Task(void) {
|
||||||
return( rcode);
|
return( rcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename SS, typename INTR >
|
template< typename SPI_SS, typename INTR >
|
||||||
uint8_t MAX3421e< SS, INTR >::IntHandler() {
|
uint8_t MAX3421e< SPI_SS, INTR >::IntHandler() {
|
||||||
uint8_t HIRQ;
|
uint8_t HIRQ;
|
||||||
uint8_t HIRQ_sendback = 0x00;
|
uint8_t HIRQ_sendback = 0x00;
|
||||||
HIRQ = regRd(rHIRQ); //determine interrupt source
|
HIRQ = regRd(rHIRQ); //determine interrupt source
|
||||||
|
@ -410,8 +410,8 @@ uint8_t MAX3421e< SS, INTR >::IntHandler() {
|
||||||
regWr(rHIRQ, HIRQ_sendback);
|
regWr(rHIRQ, HIRQ_sendback);
|
||||||
return( HIRQ_sendback);
|
return( HIRQ_sendback);
|
||||||
}
|
}
|
||||||
//template< typename SS, typename INTR >
|
//template< typename SPI_SS, typename INTR >
|
||||||
//uint8_t MAX3421e< SS, INTR >::GpxHandler()
|
//uint8_t MAX3421e< SPI_SS, INTR >::GpxHandler()
|
||||||
//{
|
//{
|
||||||
// uint8_t GPINIRQ = regRd( rGPINIRQ ); //read GPIN IRQ register
|
// uint8_t GPINIRQ = regRd( rGPINIRQ ); //read GPIN IRQ register
|
||||||
//// if( GPINIRQ & bmGPINIRQ7 ) { //vbus overload
|
//// if( GPINIRQ & bmGPINIRQ7 ) { //vbus overload
|
||||||
|
|
Loading…
Reference in a new issue