-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate OS guessing quirk into uac2_speaker_fb example.
- Loading branch information
Showing
5 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 HiFiPhile | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "quirk_os_guessing.h" | ||
|
||
static tusb_desc_type_t desc_req_buf[2]; | ||
static int desc_req_idx = 0; | ||
|
||
// Place at the start of tud_descriptor_device_cb() | ||
void quirk_os_guessing_desc_device_cb() { | ||
desc_req_idx = 0; | ||
} | ||
|
||
// Place at the start of tud_descriptor_configuration_cb() | ||
void quirk_os_guessing_desc_configuration_cb() { | ||
// Skip redundant request | ||
if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_CONFIGURATION)) { | ||
desc_req_buf[desc_req_idx++] = TUSB_DESC_CONFIGURATION; | ||
} | ||
} | ||
|
||
// Place at the start of tud_descriptor_bos_cb() | ||
void quirk_os_guessing_desc_bos_cb() { | ||
// Skip redundant request | ||
if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_BOS)) { | ||
desc_req_buf[desc_req_idx++] = TUSB_DESC_BOS; | ||
} | ||
} | ||
|
||
// Place at the start of tud_descriptor_string_cb() | ||
void quirk_os_guessing_desc_string_cb() { | ||
// Skip redundant request | ||
if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_STRING)) { | ||
desc_req_buf[desc_req_idx++] = TUSB_DESC_STRING; | ||
} | ||
} | ||
|
||
// Each OS request descriptors differently: | ||
// Windows 10 - 11 | ||
// Device Desc | ||
// Config Desc | ||
// BOS Desc | ||
// String Desc | ||
// Linux 3.16 - 6.8 | ||
// Device Desc | ||
// BOS Desc | ||
// Config Desc | ||
// String Desc | ||
// OS X Ventura - Sonoma | ||
// Device Desc | ||
// String Desc | ||
// Config Desc || BOS Desc | ||
// BOS Desc || Config Desc | ||
quirk_os_guessing_t quirk_os_guessing_get(void) { | ||
if (desc_req_idx < 2) { | ||
return QUIRK_OS_GUESSING_UNKNOWN; | ||
} | ||
|
||
if (desc_req_buf[0] == TUSB_DESC_BOS && desc_req_buf[1] == TUSB_DESC_CONFIGURATION) { | ||
return QUIRK_OS_GUESSING_LINUX; | ||
} else if (desc_req_buf[0] == TUSB_DESC_CONFIGURATION && desc_req_buf[1] == TUSB_DESC_BOS) { | ||
return QUIRK_OS_GUESSING_WINDOWS; | ||
} else if (desc_req_buf[0] == TUSB_DESC_STRING && (desc_req_buf[1] == TUSB_DESC_BOS || desc_req_buf[1] == TUSB_DESC_CONFIGURATION)) { | ||
return QUIRK_OS_GUESSING_OSX; | ||
} | ||
|
||
return QUIRK_OS_GUESSING_UNKNOWN; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 HiFiPhile | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#ifndef _QUIRK_OS_GUESSING_H_ | ||
#define _QUIRK_OS_GUESSING_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "tusb.h" | ||
|
||
//================================== !!! WARNING !!! ==================================== | ||
// This quirk operate out of USB specification in order to workaround specific issues. | ||
// It may not work on your platform. | ||
//======================================================================================= | ||
// | ||
// Prerequisites: | ||
// - Set USB version to at least 2.01 in Device Descriptor | ||
// - Has a valid BOS Descriptor, refer to webusb_serial example | ||
// | ||
// Attention: | ||
// Windows detection result comes out after Configuration Descriptor request, | ||
// meaning it will be too late to do descriptor adjustment. It's advised to make | ||
// Windows as default configuration and adjust to other OS accordingly. | ||
|
||
typedef enum { | ||
QUIRK_OS_GUESSING_UNKNOWN, | ||
QUIRK_OS_GUESSING_LINUX, | ||
QUIRK_OS_GUESSING_OSX, | ||
QUIRK_OS_GUESSING_WINDOWS, | ||
} quirk_os_guessing_t; | ||
|
||
// Get Host OS type | ||
quirk_os_guessing_t quirk_os_guessing_get(void); | ||
|
||
// Place at the start of tud_descriptor_device_cb() | ||
void quirk_os_guessing_desc_device_cb(void); | ||
|
||
// Place at the start of tud_descriptor_configuration_cb() | ||
void quirk_os_guessing_desc_configuration_cb(void); | ||
|
||
// Place at the start of tud_descriptor_bos_cb() | ||
void quirk_os_guessing_desc_bos_cb(void); | ||
|
||
// Place at the start of tud_descriptor_string_cb() | ||
void quirk_os_guessing_desc_string_cb(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _QUIRK_OS_GUESSING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters