remove useless variables

This commit is contained in:
Martino Facchin 2015-06-08 11:30:34 +02:00 committed by Cristian Maglie
parent 2aa2332f88
commit f67318a8b1
4 changed files with 22 additions and 31 deletions

View File

@ -25,9 +25,6 @@
#define MAX_MODULES 6 #define MAX_MODULES 6
static u8 startIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
static u8 firstEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
@ -36,18 +33,18 @@ extern u8 _initEndpoints[];
PUSBCallbacks cbs[MAX_MODULES]; PUSBCallbacks cbs[MAX_MODULES];
u8 modules_count = 0; u8 modules_count = 0;
int PUSB_GetInterface(u8* interfaceNum) int8_t PUSB_GetInterface(u8* interfaceNum)
{ {
int ret = 0; int8_t ret = 0;
for (u8 i=0; i<modules_count; i++) { for (u8 i=0; i<modules_count; i++) {
ret = cbs[i].getInterface(interfaceNum); ret = cbs[i].getInterface(interfaceNum);
} }
return ret; return ret;
} }
int PUSB_GetDescriptor(int t) int8_t PUSB_GetDescriptor(int8_t t)
{ {
int ret = 0; int8_t ret = 0;
for (u8 i=0; i<modules_count && ret == 0; i++) { for (u8 i=0; i<modules_count && ret == 0; i++) {
ret = cbs[i].getDescriptor(t); ret = cbs[i].getDescriptor(t);
} }
@ -63,7 +60,7 @@ bool PUSB_Setup(Setup& setup, u8 j)
return ret; return ret;
} }
int PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
{ {
if (modules_count >= MAX_MODULES) { if (modules_count >= MAX_MODULES) {
return 0; return 0;

View File

@ -28,9 +28,9 @@
typedef struct typedef struct
{ {
bool (*setup)(Setup& setup, u8 i); bool (*setup)(Setup& setup, u8 i);
int (*getInterface)(u8* interfaceNum); int8_t (*getInterface)(u8* interfaceNum);
int (*getDescriptor)(int t); int8_t (*getDescriptor)(int8_t t);
int numEndpoints; int8_t numEndpoints;
u8 endpointType[6]; u8 endpointType[6];
} PUSBCallbacks; } PUSBCallbacks;
@ -40,11 +40,11 @@ typedef struct
u8 firstEndpoint; u8 firstEndpoint;
} PUSBReturn; } PUSBReturn;
int PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface);
int PUSB_GetInterface(u8* interfaceNum); int8_t PUSB_GetInterface(u8* interfaceNum);
int PUSB_GetDescriptor(int t); int8_t PUSB_GetDescriptor(int8_t t);
bool PUSB_Setup(Setup& setup, u8 i); bool PUSB_Setup(Setup& setup, u8 i);

View File

@ -29,6 +29,8 @@ Mouse_ Mouse;
Keyboard_ Keyboard; Keyboard_ Keyboard;
HID_ HID; HID_ HID;
static u8 HID_ENDPOINT_INT;
//================================================================================ //================================================================================
//================================================================================ //================================================================================
@ -43,10 +45,6 @@ HID_ HID;
#define RAWHID_RX_SIZE 64 #define RAWHID_RX_SIZE 64
static u8 HID_INTERFACE; static u8 HID_INTERFACE;
static u8 HID_FIRST_ENDPOINT;
static u8 HID_ENDPOINT_INT;
static PUSBCallbacks cb;
extern const u8 _hidReportDescriptor[] PROGMEM; extern const u8 _hidReportDescriptor[] PROGMEM;
const u8 _hidReportDescriptor[] = { const u8 _hidReportDescriptor[] = {
@ -144,13 +142,13 @@ u8 _hid_idle = 1;
#define WEAK __attribute__ ((weak)) #define WEAK __attribute__ ((weak))
int WEAK HID_GetInterface(u8* interfaceNum) int8_t WEAK HID_GetInterface(u8* interfaceNum)
{ {
interfaceNum[0] += 1; // uses 1 interfaceNum[0] += 1; // uses 1
return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface));
} }
int WEAK HID_GetDescriptor(int t) int8_t WEAK HID_GetDescriptor(int8_t t)
{ {
if (HID_REPORT_DESCRIPTOR_TYPE == t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) {
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
@ -205,20 +203,16 @@ bool WEAK HID_Setup(Setup& setup, u8 i)
} }
// to be called by begin(), will trigger USB disconnection and reconnection // to be called by begin(), will trigger USB disconnection and reconnection
int HID_Plug(void) int8_t HID_Plug(void)
{ {
u8 interface; PUSBCallbacks cb;
u8 res;
cb.setup = &HID_Setup; cb.setup = &HID_Setup;
cb.getInterface = &HID_GetInterface; cb.getInterface = &HID_GetInterface;
cb.getDescriptor = &HID_GetDescriptor; cb.getDescriptor = &HID_GetDescriptor;
cb.numEndpoints = 1; cb.numEndpoints = 1;
cb.endpointType[0] = EP_TYPE_INTERRUPT_IN; cb.endpointType[0] = EP_TYPE_INTERRUPT_IN;
res = PUSB_AddFunction(&cb, &interface); HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE);
HID_INTERFACE = interface;
HID_FIRST_ENDPOINT = res;
HID_ENDPOINT_INT = res;
_hidInterface = _hidInterface =
{ {
@ -227,7 +221,7 @@ int HID_Plug(void)
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
}; };
return res; return HID_ENDPOINT_INT;
} }
HID_::HID_(void) HID_::HID_(void)

View File

@ -129,9 +129,9 @@ public:
int begin(void); int begin(void);
}; };
int HID_Plug(void); int8_t HID_Plug(void);
int HID_GetInterface(u8* interfaceNum); int8_t HID_GetInterface(u8* interfaceNum);
int HID_GetDescriptor(int t); int8_t HID_GetDescriptor(int8_t t);
bool HID_Setup(Setup& setup, u8 i); bool HID_Setup(Setup& setup, u8 i);
void HID_SendReport(uint8_t id, const void* data, int len); void HID_SendReport(uint8_t id, const void* data, int len);