diff --git a/src/userland/hid/usagePages/button.c b/src/userland/hid/usagePages/button.c new file mode 100644 index 0000000..488136a --- /dev/null +++ b/src/userland/hid/usagePages/button.c @@ -0,0 +1,38 @@ +#include + +// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf +// section 12, page 67 + +REQUEST(updateButton, "mouse", "updateButton"); + +void handleButton1(int32_t data) { updateButton(1, data); } +void handleButton2(int32_t data) { updateButton(2, data); } +void handleButton3(int32_t data) { updateButton(3, data); } +void handleButton4(int32_t data) { updateButton(4, data); } +void handleButton5(int32_t data) { updateButton(5, data); } + +Usage buttonUsages[] = { + { + .id = 1, + .handle = handleButton1, + .name = "Buton 1", + }, { + .id = 2, + .handle = handleButton2, + .name = "Buton 2", + }, { + .id = 3, + .handle = handleButton3, + .name = "Buton 3", + }, { + .id = 4, + .handle = handleButton4, + .name = "Buton 4", + }, { + .id = 5, + .handle = handleButton5, + .name = "Buton 5", + }, { + .id = -1, // end tag + } +}; diff --git a/src/userland/hid/usagePages/button.c b/src/userland/hid/usagePages/button.c new file mode 100644 index 0000000..488136a --- /dev/null +++ b/src/userland/hid/usagePages/button.c @@ -0,0 +1,38 @@ +#include + +// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf +// section 12, page 67 + +REQUEST(updateButton, "mouse", "updateButton"); + +void handleButton1(int32_t data) { updateButton(1, data); } +void handleButton2(int32_t data) { updateButton(2, data); } +void handleButton3(int32_t data) { updateButton(3, data); } +void handleButton4(int32_t data) { updateButton(4, data); } +void handleButton5(int32_t data) { updateButton(5, data); } + +Usage buttonUsages[] = { + { + .id = 1, + .handle = handleButton1, + .name = "Buton 1", + }, { + .id = 2, + .handle = handleButton2, + .name = "Buton 2", + }, { + .id = 3, + .handle = handleButton3, + .name = "Buton 3", + }, { + .id = 4, + .handle = handleButton4, + .name = "Buton 4", + }, { + .id = 5, + .handle = handleButton5, + .name = "Buton 5", + }, { + .id = -1, // end tag + } +}; diff --git a/src/userland/hid/usagePages/genericDesktopControls.c b/src/userland/hid/usagePages/genericDesktopControls.c index 4d07b1e..035d2ce 100644 --- a/src/userland/hid/usagePages/genericDesktopControls.c +++ b/src/userland/hid/usagePages/genericDesktopControls.c @@ -4,7 +4,6 @@ // section 4, table 6, page 26 REQUEST(moveRelative, "mouse", "moveRelative"); -REQUEST(updateButtons, "mouse", "updateButtons"); void handleX(int32_t dx) { moveRelative(dx, 0); diff --git a/src/userland/hid/usagePages/button.c b/src/userland/hid/usagePages/button.c new file mode 100644 index 0000000..488136a --- /dev/null +++ b/src/userland/hid/usagePages/button.c @@ -0,0 +1,38 @@ +#include + +// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf +// section 12, page 67 + +REQUEST(updateButton, "mouse", "updateButton"); + +void handleButton1(int32_t data) { updateButton(1, data); } +void handleButton2(int32_t data) { updateButton(2, data); } +void handleButton3(int32_t data) { updateButton(3, data); } +void handleButton4(int32_t data) { updateButton(4, data); } +void handleButton5(int32_t data) { updateButton(5, data); } + +Usage buttonUsages[] = { + { + .id = 1, + .handle = handleButton1, + .name = "Buton 1", + }, { + .id = 2, + .handle = handleButton2, + .name = "Buton 2", + }, { + .id = 3, + .handle = handleButton3, + .name = "Buton 3", + }, { + .id = 4, + .handle = handleButton4, + .name = "Buton 4", + }, { + .id = 5, + .handle = handleButton5, + .name = "Buton 5", + }, { + .id = -1, // end tag + } +}; diff --git a/src/userland/hid/usagePages/genericDesktopControls.c b/src/userland/hid/usagePages/genericDesktopControls.c index 4d07b1e..035d2ce 100644 --- a/src/userland/hid/usagePages/genericDesktopControls.c +++ b/src/userland/hid/usagePages/genericDesktopControls.c @@ -4,7 +4,6 @@ // section 4, table 6, page 26 REQUEST(moveRelative, "mouse", "moveRelative"); -REQUEST(updateButtons, "mouse", "updateButtons"); void handleX(int32_t dx) { moveRelative(dx, 0); diff --git a/src/userland/hid/usagePages/usagePages.c b/src/userland/hid/usagePages/usagePages.c index bd4a661..8936c65 100644 --- a/src/userland/hid/usagePages/usagePages.c +++ b/src/userland/hid/usagePages/usagePages.c @@ -1,6 +1,7 @@ #include extern Usage genericDesktopControlsUsages[]; +extern Usage buttonUsages[]; // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf // page 14, section 3, table 1: Usage Page Summary @@ -34,7 +35,7 @@ .usages = NULL, }, { .name = "Button", - .usages = NULL, + .usages = buttonUsages, }, { .name = "Ordinal", .usages = NULL, diff --git a/src/userland/hid/usagePages/button.c b/src/userland/hid/usagePages/button.c new file mode 100644 index 0000000..488136a --- /dev/null +++ b/src/userland/hid/usagePages/button.c @@ -0,0 +1,38 @@ +#include + +// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf +// section 12, page 67 + +REQUEST(updateButton, "mouse", "updateButton"); + +void handleButton1(int32_t data) { updateButton(1, data); } +void handleButton2(int32_t data) { updateButton(2, data); } +void handleButton3(int32_t data) { updateButton(3, data); } +void handleButton4(int32_t data) { updateButton(4, data); } +void handleButton5(int32_t data) { updateButton(5, data); } + +Usage buttonUsages[] = { + { + .id = 1, + .handle = handleButton1, + .name = "Buton 1", + }, { + .id = 2, + .handle = handleButton2, + .name = "Buton 2", + }, { + .id = 3, + .handle = handleButton3, + .name = "Buton 3", + }, { + .id = 4, + .handle = handleButton4, + .name = "Buton 4", + }, { + .id = 5, + .handle = handleButton5, + .name = "Buton 5", + }, { + .id = -1, // end tag + } +}; diff --git a/src/userland/hid/usagePages/genericDesktopControls.c b/src/userland/hid/usagePages/genericDesktopControls.c index 4d07b1e..035d2ce 100644 --- a/src/userland/hid/usagePages/genericDesktopControls.c +++ b/src/userland/hid/usagePages/genericDesktopControls.c @@ -4,7 +4,6 @@ // section 4, table 6, page 26 REQUEST(moveRelative, "mouse", "moveRelative"); -REQUEST(updateButtons, "mouse", "updateButtons"); void handleX(int32_t dx) { moveRelative(dx, 0); diff --git a/src/userland/hid/usagePages/usagePages.c b/src/userland/hid/usagePages/usagePages.c index bd4a661..8936c65 100644 --- a/src/userland/hid/usagePages/usagePages.c +++ b/src/userland/hid/usagePages/usagePages.c @@ -1,6 +1,7 @@ #include extern Usage genericDesktopControlsUsages[]; +extern Usage buttonUsages[]; // https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf // page 14, section 3, table 1: Usage Page Summary @@ -34,7 +35,7 @@ .usages = NULL, }, { .name = "Button", - .usages = NULL, + .usages = buttonUsages, }, { .name = "Ordinal", .usages = NULL, diff --git a/src/userland/mouse/main.c b/src/userland/mouse/main.c index 0776699..19fa935 100644 --- a/src/userland/mouse/main.c +++ b/src/userland/mouse/main.c @@ -2,8 +2,8 @@ #include volatile int32_t x = 0, y = 0; -volatile bool initialized = false; -volatile uint32_t updateEvent, buttons; +volatile uint32_t updateEvent; +volatile bool buttons[5]; REQUEST(checkFocus, "ioManager", "checkFocus"); @@ -19,28 +19,34 @@ fireEvent(updateEvent, 0); } -void updateButtons(uint8_t newButtons) { - buttons = newButtons; +void updateButton(uint8_t button, bool newState) { + if (button > 5 || button == 0) { + // hid button 0 means no button is pressed + // TODO: set all buttons to not pressed when button = 0? + return; + } + buttons[button-1] = newState; fireEvent(updateEvent, 0); } +bool initialized = false; void initialize() { initialized = true; createFunction("moveAbsolute", (void *)moveAbsolute); createFunction("moveRelative", (void *)moveRelative); - createFunction("updateButtons", (void *)updateButtons); + createFunction("updateButton", (void *)updateButton); updateEvent = createEvent("update"); } int32_t main() { if (!initialized) { initialize(); } if (!checkFocus(0, 0)) { - return; + return 0; } uint32_t serviceId = getServiceId(); printf("service: %i, event: %i\n", serviceId, updateEvent); while (1) { await(serviceId, updateEvent); - printf("mouse info: buttons: %i, x: %i, y: %i \r", buttons, x, y); + printf("mouse info: x: %i, y: %i, buttons: %i %i %i \r", x, y, buttons[0], buttons[1], buttons[2]); } }