Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ volatile __xdata uint8_t UpPoint2_Busy = 0;

__xdata uint8_t HIDKey[8] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
__xdata uint8_t HIDMouse[4] = {0x0, 0x0, 0x0, 0x0};
__xdata uint16_t HIDConsumer[4] = {0x0, 0x0, 0x0, 0x0};

typedef void (*pTaskFn)(void);

Expand Down Expand Up @@ -97,6 +98,13 @@ uint8_t USB_EP1_send(__data uint8_t reportID) {
Ep1Buffer[64 + 1 + i] = ((uint8_t *)HIDMouse)[i];
}
UEP1_T_LEN = 1 + sizeof(HIDMouse); // data length
} else if (reportID == 3) {
Ep1Buffer[64 + 0] = 3;
for (__data uint8_t i = 0; i < sizeof(HIDConsumer); i++) {
// load data for upload
Ep1Buffer[64 + 1 + i] = ((uint8_t *)HIDConsumer)[i];
}
UEP1_T_LEN = 1 + sizeof(HIDConsumer); // data length
} else if (reportID == 8) {
Ep1Buffer[64 + 0] = 8;
UEP1_T_LEN = 33;
Expand Down Expand Up @@ -229,3 +237,56 @@ uint8_t Mouse_scroll(__data int8_t tilt) {
HIDMouse[3] = 0;
return 1;
}

uint8_t Consumer_press(__data uint16_t k) {
__data uint8_t i;

// Add k to the consumer report only if it's not already present
// and if there is an empty slot.
if (HIDConsumer[0] != k && HIDConsumer[1] != k && HIDConsumer[2] != k &&
HIDConsumer[3] != k) {

for (i = 0; i < 4; i++) {
if (HIDConsumer[i] == 0x00) {
HIDConsumer[i] = k;
break;
}
}
if (i == 4) {
// setWriteError();
return 0;
}
}
USB_EP1_send(3);
return 1;
}

uint8_t Consumer_release(__data uint16_t k) {
__data uint8_t i;

// Test the consumer report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it
// shouldn't be)
for (i = 0; i < 4; i++) {
if (0 != k && HIDConsumer[i] == k) {
HIDConsumer[i] = 0x00;
}
}

USB_EP1_send(3);
return 1;
}

void Consumer_releaseAll(void) {
for (__data uint8_t i = 0; i < 4; i++) { // load data for upload
HIDConsumer[i] = 0;
}
USB_EP1_send(3);
}

uint8_t Consumer_write(__data uint16_t c) {
__data uint8_t p = Consumer_press(c); // Keydown
Consumer_release(c); // Keyup
return p; // just return the result of press() since release() almost always
// returns 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ uint8_t Mouse_click(__data uint8_t k);
uint8_t Mouse_move(__data int8_t x, __xdata int8_t y);
uint8_t Mouse_scroll(__data int8_t tilt);

uint8_t Consumer_press(__data uint16_t k);
uint8_t Consumer_release(__data uint16_t k);
void Consumer_releaseAll(void);

uint8_t Consumer_write(__data uint16_t c);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,20 @@ __code uint8_t ReportDescriptor[] = {
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
// //todo: add media control
0xc0, // END_COLLECTION
// Consumer Keys
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x03, // REPORT_ID (3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x03, // LOGICAL_MAXIMUM (1023)
0x19, 0x00, // USAGE_MINIMUM (Unassigned)
0x2a, 0xff, 0x03, // USAGE_MAXIMUM (Undefined)
0x95, 0x04, // REPORT_COUNT (4)
0x75, 0x10, // REPORT_SIZE (16)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};

__code uint8_t RawHIDReportDescriptor[] = {
Expand Down
Loading