File tree 6 files changed +15
-15
lines changed
6 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -50,16 +50,15 @@ int PluggableUSB_::getDescriptor(USBSetup& setup)
50
50
return 0 ;
51
51
}
52
52
53
- char * PluggableUSB_::getShortName (void )
53
+ uint8_t PluggableUSB_::getShortName (char * _iSerialNum, uint8_t max_len )
54
54
{
55
- char * ret = 0 ;
56
- memset (_iSerialNum, 0 , sizeof (_iSerialNum) );
55
+ uint8_t ret = 0 ;
56
+ memset (_iSerialNum, 0 , max_len );
57
57
PluggableUSBModule* node;
58
- for (node = rootNode; node; node = node->next ) {
59
- ret = node->getShortName ();
60
- memcpy (&_iSerialNum[strlen (_iSerialNum)], ret, strlen (ret));
58
+ for (node = rootNode; node && ret < max_len; node = node->next ) {
59
+ ret += node->getShortName (&_iSerialNum[ret]);
61
60
}
62
- return _iSerialNum ;
61
+ return ret ;
63
62
}
64
63
65
64
bool PluggableUSB_::setup (USBSetup& setup)
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class PluggableUSBModule {
35
35
virtual bool setup (USBSetup& setup) = 0;
36
36
virtual int getInterface (uint8_t * interfaceCount) = 0;
37
37
virtual int getDescriptor (USBSetup& setup) = 0;
38
- virtual char * getShortName (void ) = 0;
38
+ virtual uint8_t getShortName (char * name) { name[ 0 ] = ' A ' +pluggedInterface; return 1 ; }
39
39
40
40
uint8_t pluggedInterface;
41
41
uint8_t pluggedEndpoint;
@@ -56,12 +56,11 @@ class PluggableUSB_ {
56
56
int getInterface (uint8_t * interfaceCount);
57
57
int getDescriptor (USBSetup& setup);
58
58
bool setup (USBSetup& setup);
59
- char * getShortName (void );
59
+ uint8_t getShortName (char * _iSerialNum, uint8_t max_len );
60
60
61
61
private:
62
62
uint8_t lastIf;
63
63
uint8_t lastEp;
64
- char _iSerialNum[20 ] = {0 };
65
64
PluggableUSBModule* rootNode;
66
65
};
67
66
Original file line number Diff line number Diff line change @@ -504,7 +504,8 @@ bool SendDescriptor(USBSetup& setup)
504
504
}
505
505
else if (setup.wValueL == ISERIAL) {
506
506
#ifdef PLUGGABLE_USB_ENABLED
507
- char * name = PluggableUSB ().getShortName ();
507
+ char name[ISERIAL_MAX_LEN];
508
+ PluggableUSB ().getShortName (name, sizeof (name));
508
509
return USB_SendStringDescriptor ((uint8_t *)name, strlen (name), 0 );
509
510
#endif
510
511
}
Original file line number Diff line number Diff line change 24
24
#define USB_ENDPOINTS 5 // AtMegaxxU2
25
25
#endif
26
26
27
+ #define ISERIAL_MAX_LEN 20
28
+
27
29
#define CDC_INTERFACE_COUNT 2
28
30
#define CDC_ENPOINT_COUNT 3
29
31
Original file line number Diff line number Diff line change @@ -57,14 +57,13 @@ int HID_::getDescriptor(USBSetup& setup)
57
57
return total;
58
58
}
59
59
60
- char * HID_::getShortName ()
60
+ uint8_t HID_::getShortName (char * name )
61
61
{
62
- static char name[7 ] = {0 };
63
62
char num[3 ];
64
63
memcpy (name, " HID" , 3 );
65
64
itoa (descriptorSize, num, 10 );
66
65
memcpy (&name[3 ], num, 3 );
67
- return name;
66
+ return strlen ( name) ;
68
67
}
69
68
70
69
void HID_::AppendDescriptor (HIDSubDescriptor *node)
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ class HID_ : public PluggableUSBModule
96
96
int getInterface (uint8_t * interfaceCount);
97
97
int getDescriptor (USBSetup& setup);
98
98
bool setup (USBSetup& setup);
99
- char * getShortName (void );
99
+ uint8_t getShortName (char * name );
100
100
101
101
private:
102
102
uint8_t epType[1 ];
You can’t perform that action at this time.
0 commit comments