-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[RFC] Pluggable USB core for AVR #3304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
09460dd
Remove HID core library
facchinm 5ee69a7
Move EP defines to header
facchinm 2c5dd20
Use generic composite device descriptor
facchinm 1f534ea
move _initEndpoints from PROGMEM to RAM
facchinm 1aec25b
add PluggableUSB module
facchinm ec43b6c
remove useless variable
facchinm b2a6b61
add weak setupUSB() hook
facchinm 018fb96
move HID to general external library
facchinm 91ccab4
make CDC function non removable
facchinm 2aa2332
add arduino header to HID library
facchinm f67318a
remove useless variables
facchinm 7b5c25f
implement PUSB modules as linked list
facchinm 4a55205
remove Mouse and Keyboard from HID module
facchinm c2a083b
standalone Mouse library
facchinm fe825c8
standalone Keyboard library
facchinm feaa14f
standalone MouseAndKeyboard library
facchinm 344896e
Fix HID derived libraries and add automatic setupUSB() weak hook
facchinm 8f0a433
export WEAK macro
facchinm a031921
add stub MIDIUSB library
facchinm f37547e
add numInterfaces field to PUSBCallbacks
facchinm ada0e4c
remove 3 endpoints to match at32u4 limit
facchinm 89928b4
rework PUSBCallbacks initialization
facchinm 0713231
enforce single use of HID submodule
facchinm e211f1e
remove setupUSB weak hook and replace with global constructors
facchinm 91a115a
move HID library to AVR specific location
facchinm 175240a
Add support for waking up a host via USB HID
facchinm a989b72
squash of Overhaul USB HID as a library
facchinm 9074b1e
fix HID descriptors bigger than 127 bytes
facchinm dee43a1
fix HID headers
facchinm 97a3771
rename Setup typedef struct to USBSetup
facchinm 5defaea
rework HID class functions scopes
facchinm 8a45883
save RAM content overridden by bootloader magic
facchinm 6a9568d
fix pluggableUSB linked list
facchinm e1a0350
allow HID submodules to create runtime descriptors
facchinm efd329b
fix MIDIUSB and adapt CompleteHID to PluggableHID
facchinm 8ebc5d0
remove stub MIDIUSB library
facchinm 5cc7c10
remove CompleteHID library
facchinm 9981435
add includes to USB examples
facchinm af290fc
rework HID-based libraries and add Due fallback
facchinm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,100 @@ | ||
/* | ||
PluggableUSB.cpp | ||
Copyright (c) 2015 Arduino LLC | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "USBAPI.h" | ||
#include "PluggableUSB.h" | ||
|
||
#if defined(USBCON) | ||
#ifdef PLUGGABLE_USB_ENABLED | ||
|
||
#define MAX_MODULES 6 | ||
|
||
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; | ||
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; | ||
|
||
extern u8 _initEndpoints[]; | ||
|
||
//PUSBCallbacks cbs[MAX_MODULES]; | ||
static u8 modules_count = 0; | ||
|
||
static PUSBListNode* rootNode = NULL; | ||
|
||
int PUSB_GetInterface(u8* interfaceNum) | ||
{ | ||
int ret = 0; | ||
PUSBListNode* node = rootNode; | ||
for (u8 i=0; i<modules_count; i++) { | ||
ret = node->cb->getInterface(interfaceNum); | ||
node = node->next; | ||
} | ||
return ret; | ||
} | ||
|
||
int PUSB_GetDescriptor(int8_t t) | ||
{ | ||
int ret = 0; | ||
PUSBListNode* node = rootNode; | ||
for (u8 i=0; i<modules_count && ret == 0; i++) { | ||
ret = node->cb->getDescriptor(t); | ||
node = node->next; | ||
} | ||
return ret; | ||
} | ||
|
||
bool PUSB_Setup(USBSetup& setup, u8 j) | ||
{ | ||
bool ret = false; | ||
PUSBListNode* node = rootNode; | ||
for (u8 i=0; i<modules_count && ret == false; i++) { | ||
ret = node->cb->setup(setup, j); | ||
node = node->next; | ||
} | ||
return ret; | ||
} | ||
|
||
int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) | ||
{ | ||
if (modules_count >= MAX_MODULES) { | ||
return 0; | ||
} | ||
|
||
if (modules_count == 0) { | ||
rootNode = node; | ||
} else { | ||
PUSBListNode *current = rootNode; | ||
while(current->next != NULL) { | ||
current = current->next; | ||
} | ||
current->next = node; | ||
} | ||
|
||
*interface = lastIf; | ||
lastIf += node->cb->numInterfaces; | ||
for ( u8 i = 0; i< node->cb->numEndpoints; i++) { | ||
_initEndpoints[lastEp] = node->cb->endpointType[i]; | ||
lastEp++; | ||
} | ||
modules_count++; | ||
return lastEp - node->cb->numEndpoints; | ||
// restart USB layer??? | ||
} | ||
|
||
#endif | ||
|
||
#endif /* if defined(USBCON) */ |
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,63 @@ | ||
/* | ||
PluggableUSB.h | ||
Copyright (c) 2015 Arduino LLC | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef PUSB_h | ||
#define PUSB_h | ||
|
||
#include "USBAPI.h" | ||
#include <stdint.h> | ||
|
||
#if defined(USBCON) | ||
|
||
typedef struct __attribute__((packed)) | ||
{ | ||
bool (*setup)(USBSetup& setup, u8 i); | ||
int (*getInterface)(u8* interfaceNum); | ||
int (*getDescriptor)(int8_t t); | ||
int8_t numEndpoints; | ||
int8_t numInterfaces; | ||
uint8_t *endpointType; | ||
} PUSBCallbacks; | ||
|
||
typedef struct | ||
{ | ||
u8 interface; | ||
u8 firstEndpoint; | ||
} PUSBReturn; | ||
|
||
class PUSBListNode { | ||
public: | ||
PUSBListNode *next = NULL; | ||
PUSBCallbacks *cb; | ||
PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} | ||
}; | ||
|
||
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); | ||
|
||
int PUSB_GetInterface(u8* interfaceNum); | ||
|
||
int PUSB_GetDescriptor(int8_t t); | ||
|
||
bool PUSB_Setup(USBSetup& setup, u8 i); | ||
|
||
void PUSB_Begin(); | ||
|
||
#endif | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted the comment in a commit, but still applies here. I am not sure if all those functions make so much sense with the retvalue. Also lastNode is not really used.