|
@@ -21,10 +21,12 @@
|
|
* THE SOFTWARE.
|
|
* THE SOFTWARE.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+#include <avr/io.h>
|
|
#include <avr/pgmspace.h>
|
|
#include <avr/pgmspace.h>
|
|
#include <avr/interrupt.h>
|
|
#include <avr/interrupt.h>
|
|
-#include "usb_device.h"
|
|
+#include "usb.h"
|
|
#include "usb_keyboard.h"
|
|
#include "usb_keyboard.h"
|
|
|
|
+#include "usb_mouse.h"
|
|
#include "usb_debug.h"
|
|
#include "usb_debug.h"
|
|
|
|
|
|
|
|
|
|
@@ -64,11 +66,15 @@
|
|
|
|
|
|
#define ENDPOINT0_SIZE 32
|
|
#define ENDPOINT0_SIZE 32
|
|
|
|
|
|
|
|
+
|
|
static const uint8_t PROGMEM endpoint_config_table[] = {
|
|
static const uint8_t PROGMEM endpoint_config_table[] = {
|
|
- 0,
|
|
+
|
|
- 0,
|
|
+ 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER,
|
|
- 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER,
|
|
+ 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER,
|
|
- 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER
|
|
+ 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER,
|
|
|
|
+ 0,
|
|
|
|
+ 0,
|
|
|
|
+ 0,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -138,6 +144,36 @@ static uint8_t PROGMEM keyboard_hid_report_desc[] = {
|
|
0xc0
|
|
0xc0
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
|
|
+static uint8_t PROGMEM mouse_hid_report_desc[] = {
|
|
|
|
+ 0x05, 0x01,
|
|
|
|
+ 0x09, 0x02,
|
|
|
|
+ 0xA1, 0x01,
|
|
|
|
+ 0x05, 0x09,
|
|
|
|
+ 0x19, 0x01,
|
|
|
|
+ 0x29, 0x03,
|
|
|
|
+ 0x15, 0x00,
|
|
|
|
+ 0x25, 0x01,
|
|
|
|
+ 0x95, 0x03,
|
|
|
|
+ 0x75, 0x01,
|
|
|
|
+ 0x81, 0x02,
|
|
|
|
+ 0x95, 0x01,
|
|
|
|
+ 0x75, 0x05,
|
|
|
|
+ 0x81, 0x03,
|
|
|
|
+ 0x05, 0x01,
|
|
|
|
+ 0x09, 0x30,
|
|
|
|
+ 0x09, 0x31,
|
|
|
|
+ 0x15, 0x81,
|
|
|
|
+ 0x25, 0x7F,
|
|
|
|
+ 0x75, 0x08,
|
|
|
|
+ 0x95, 0x02,
|
|
|
|
+ 0x81, 0x06,
|
|
|
|
+ 0x09, 0x38,
|
|
|
|
+ 0x95, 0x01,
|
|
|
|
+ 0x81, 0x06,
|
|
|
|
+ 0xC0
|
|
|
|
+};
|
|
|
|
+
|
|
static uint8_t PROGMEM debug_hid_report_desc[] = {
|
|
static uint8_t PROGMEM debug_hid_report_desc[] = {
|
|
0x06, 0x31, 0xFF,
|
|
0x06, 0x31, 0xFF,
|
|
0x09, 0x74,
|
|
0x09, 0x74,
|
|
@@ -151,20 +187,22 @@ static uint8_t PROGMEM debug_hid_report_desc[] = {
|
|
0xC0
|
|
0xC0
|
|
};
|
|
};
|
|
|
|
|
|
-#define CONFIG1_DESC_SIZE (9+9+9+7+9+9+7)
|
|
+#define CONFIG1_DESC_SIZE (9+(9+9+7)+(9+9+7)+(9+9+7))
|
|
#define KEYBOARD_HID_DESC_OFFSET (9+9)
|
|
#define KEYBOARD_HID_DESC_OFFSET (9+9)
|
|
-#define DEBUG_HID_DESC_OFFSET (9+9+9+7+9)
|
|
+#define MOUSE_HID_DESC_OFFSET (9+(9+9+7)+9)
|
|
|
|
+#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)+(9+9+7)+9)
|
|
static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
|
|
static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
|
|
|
|
|
|
9,
|
|
9,
|
|
2,
|
|
2,
|
|
LSB(CONFIG1_DESC_SIZE),
|
|
LSB(CONFIG1_DESC_SIZE),
|
|
MSB(CONFIG1_DESC_SIZE),
|
|
MSB(CONFIG1_DESC_SIZE),
|
|
- 2,
|
|
+ 3,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
0xC0,
|
|
0xC0,
|
|
50,
|
|
50,
|
|
|
|
+
|
|
|
|
|
|
9,
|
|
9,
|
|
4,
|
|
4,
|
|
@@ -175,7 +213,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
|
|
0x01,
|
|
0x01,
|
|
0x01,
|
|
0x01,
|
|
0,
|
|
0,
|
|
-
|
|
+
|
|
9,
|
|
9,
|
|
0x21,
|
|
0x21,
|
|
0x11, 0x01,
|
|
0x11, 0x01,
|
|
@@ -191,6 +229,34 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
|
|
0x03,
|
|
0x03,
|
|
KEYBOARD_SIZE, 0,
|
|
KEYBOARD_SIZE, 0,
|
|
1,
|
|
1,
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 9,
|
|
|
|
+ 4,
|
|
|
|
+ MOUSE_INTERFACE,
|
|
|
|
+ 0,
|
|
|
|
+ 1,
|
|
|
|
+ 0x03,
|
|
|
|
+ 0x01,
|
|
|
|
+ 0x02,
|
|
|
|
+ 0,
|
|
|
|
+
|
|
|
|
+ 9,
|
|
|
|
+ 0x21,
|
|
|
|
+ 0x11, 0x01,
|
|
|
|
+ 0,
|
|
|
|
+ 1,
|
|
|
|
+ 0x22,
|
|
|
|
+ sizeof(mouse_hid_report_desc),
|
|
|
|
+ 0,
|
|
|
|
+
|
|
|
|
+ 7,
|
|
|
|
+ 5,
|
|
|
|
+ MOUSE_ENDPOINT | 0x80,
|
|
|
|
+ 0x03,
|
|
|
|
+ 4, 0,
|
|
|
|
+ 1,
|
|
|
|
+
|
|
|
|
|
|
9,
|
|
9,
|
|
4,
|
|
4,
|
|
@@ -201,7 +267,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
|
|
0x00,
|
|
0x00,
|
|
0x00,
|
|
0x00,
|
|
0,
|
|
0,
|
|
-
|
|
+
|
|
9,
|
|
9,
|
|
0x21,
|
|
0x21,
|
|
0x11, 0x01,
|
|
0x11, 0x01,
|
|
@@ -259,6 +325,9 @@ static struct descriptor_list_struct {
|
|
{0x2200, KEYBOARD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
|
|
{0x2200, KEYBOARD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
|
|
{0x2100, KEYBOARD_INTERFACE, config1_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
|
|
{0x2100, KEYBOARD_INTERFACE, config1_descriptor+KEYBOARD_HID_DESC_OFFSET, 9},
|
|
|
|
|
|
|
|
+ {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
|
|
|
|
+ {0x2100, MOUSE_INTERFACE, config1_descriptor+MOUSE_HID_DESC_OFFSET, 9},
|
|
|
|
+
|
|
{0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
|
|
{0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
|
|
{0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
|
|
{0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
|
|
|
|
|
|
@@ -470,7 +539,7 @@ ISR(USB_COM_vect)
|
|
usb_configuration = wValue;
|
|
usb_configuration = wValue;
|
|
usb_send_in();
|
|
usb_send_in();
|
|
cfg = endpoint_config_table;
|
|
cfg = endpoint_config_table;
|
|
- for (i=1; i<5; i++) {
|
|
+ for (i=1; i<=6; i++) {
|
|
UENUM = i;
|
|
UENUM = i;
|
|
en = pgm_read_byte(cfg++);
|
|
en = pgm_read_byte(cfg++);
|
|
UECONX = en;
|
|
UECONX = en;
|
|
@@ -479,7 +548,7 @@ ISR(USB_COM_vect)
|
|
UECFG1X = pgm_read_byte(cfg++);
|
|
UECFG1X = pgm_read_byte(cfg++);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- UERST = 0x1E;
|
|
+ UERST = 0x7E;
|
|
UERST = 0;
|
|
UERST = 0;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -571,6 +640,32 @@ ISR(USB_COM_vect)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (wIndex == MOUSE_INTERFACE) {
|
|
|
|
+ if (bmRequestType == 0xA1) {
|
|
|
|
+ if (bRequest == HID_GET_REPORT) {
|
|
|
|
+ usb_wait_in_ready();
|
|
|
|
+ UEDATX = mouse_buttons;
|
|
|
|
+ UEDATX = 0;
|
|
|
|
+ UEDATX = 0;
|
|
|
|
+ UEDATX = 0;
|
|
|
|
+ usb_send_in();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (bRequest == HID_GET_PROTOCOL) {
|
|
|
|
+ usb_wait_in_ready();
|
|
|
|
+ UEDATX = mouse_protocol;
|
|
|
|
+ usb_send_in();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (bmRequestType == 0x21) {
|
|
|
|
+ if (bRequest == HID_SET_PROTOCOL) {
|
|
|
|
+ mouse_protocol = wValue;
|
|
|
|
+ usb_send_in();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if (wIndex == DEBUG_INTERFACE) {
|
|
if (wIndex == DEBUG_INTERFACE) {
|
|
if (bRequest == HID_GET_REPORT && bmRequestType == 0xA1) {
|
|
if (bRequest == HID_GET_REPORT && bmRequestType == 0xA1) {
|
|
len = wLength;
|
|
len = wLength;
|