Browse Source

more or less working

master
Robin Thoni 8 years ago
parent
commit
fcbc9590fa
4 changed files with 35 additions and 37 deletions
  1. 4
    8
      UsbRawHid.h
  2. 27
    28
      UsbRawHid.hxx
  3. 3
    0
      examples/UsbRawHidDemo1/main.ino
  4. 1
    1
      usbconfig.h

+ 4
- 8
UsbRawHid.h View File

25
   }                             \
25
   }                             \
26
 } while(0)
26
 } while(0)
27
 
27
 
28
-#define BUFFER_SIZE 4 // Minimum of 2: 1 for modifiers + 1 for keystroke 
28
+#define BUFFER_SIZE 64
29
 
29
 
30
-typedef struct{
31
-    uchar   buttonMask;
32
-    char    dx;
33
-    char    dy;
34
-    char    dWheel;
35
-}report_t;
36
 
30
 
37
 static uchar    idleRate;/* repeat rate for keyboards, never used for mice */
31
 static uchar    idleRate;/* repeat rate for keyboards, never used for mice */
38
 
32
 
45
     void update() {
39
     void update() {
46
         usbPoll();
40
         usbPoll();
47
     }
41
     }
42
+
43
+    void sendData(const char* data, unsigned size = 0);
48
     
44
     
49
     //private: TODO: Make friend?
45
     //private: TODO: Make friend?
50
-    report_t reportBuffer;    // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
46
+    byte reportBuffer[BUFFER_SIZE];    // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
51
 
47
 
52
 private:
48
 private:
53
 
49
 

+ 27
- 28
UsbRawHid.hxx View File

13
  * Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
13
  * Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
14
  * for the second INPUT item.
14
  * for the second INPUT item.
15
  */
15
  */
16
-PROGMEM const char usbHidReportDescriptor[52] = { /* USB report descriptor, size must match usbconfig.h */
17
-        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
18
-        0x09, 0x02,                    // USAGE (Mouse)
19
-        0xa1, 0x01,                    // COLLECTION (Application)
20
-        0x09, 0x01,                    //   USAGE (Pointer)
21
-        0xA1, 0x00,                    //   COLLECTION (Physical)
22
-        0x05, 0x09,                    //     USAGE_PAGE (Button)
23
-        0x19, 0x01,                    //     USAGE_MINIMUM
24
-        0x29, 0x03,                    //     USAGE_MAXIMUM
25
-        0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
26
-        0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
27
-        0x95, 0x03,                    //     REPORT_COUNT (3)
28
-        0x75, 0x01,                    //     REPORT_SIZE (1)
29
-        0x81, 0x02,                    //     INPUT (Data,Var,Abs)
30
-        0x95, 0x01,                    //     REPORT_COUNT (1)
31
-        0x75, 0x05,                    //     REPORT_SIZE (5)
32
-        0x81, 0x03,                    //     INPUT (Const,Var,Abs)
33
-        0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
34
-        0x09, 0x30,                    //     USAGE (X)
35
-        0x09, 0x31,                    //     USAGE (Y)
36
-        0x09, 0x38,                    //     USAGE (Wheel)
37
-        0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
38
-        0x25, 0x7F,                    //     LOGICAL_MAXIMUM (127)
39
-        0x75, 0x08,                    //     REPORT_SIZE (8)
40
-        0x95, 0x03,                    //     REPORT_COUNT (3)
41
-        0x81, 0x06,                    //     INPUT (Data,Var,Rel)
42
-        0xC0,                          //   END_COLLECTION
43
-        0xC0,                          // END COLLECTION
16
+PROGMEM const char usbHidReportDescriptor[32] = {
17
+        0x06, 0x42, 0xff,
18
+        0x0A, 0x42, 0xff,
19
+        0xA1, 0x01,				// Collection 0x01
20
+        0x75, 0x08,				// report size = 8 bits
21
+        0x15, 0x00,				// logical minimum = 0
22
+        0x26, 0xFF, 0x00,			// logical maximum = 255
23
+        0x95, RAWHID_TX_SIZE,			// report count
24
+        0x09, 0x01,				// usage
25
+        0x81, 0x02,				// Input (array)
26
+        0x95, RAWHID_RX_SIZE,			// report count
27
+        0x09, 0x02,				// usage
28
+        0x91, 0x02,				// Output (array)
29
+        0xC0					// end collection
44
 };
30
 };
45
 
31
 
46
 UsbRawHidDevice::UsbRawHidDevice()
32
 UsbRawHidDevice::UsbRawHidDevice()
53
     usbDeviceConnect();
39
     usbDeviceConnect();
54
     usbInit();
40
     usbInit();
55
     sei();
41
     sei();
42
+    //sendData("", 0);
56
 }
43
 }
57
 
44
 
58
 bool UsbRawHidDevice::isUsbReady()
45
 bool UsbRawHidDevice::isUsbReady()
61
     return usbInterruptIsReady();
48
     return usbInterruptIsReady();
62
 }
49
 }
63
 
50
 
51
+void UsbRawHidDevice::sendData(const char* data, unsigned size)
52
+{
53
+    if (size > RAWHID_TX_SIZE || size == 0)
54
+    {
55
+        size = RAWHID_TX_SIZE;
56
+    }
57
+    memcpy(reportBuffer, data, size);
58
+    memset(reportBuffer + size, 0, RAWHID_TX_SIZE - size);
59
+
60
+    usbSetInterrupt((unsigned char*)(void *)&reportBuffer, sizeof(reportBuffer));
61
+}
62
+
64
 usbMsgLen_t usbFunctionSetup(uchar data[8])
63
 usbMsgLen_t usbFunctionSetup(uchar data[8])
65
 {
64
 {
66
     usbRequest_t    *rq = (usbRequest_t*)(void*)data;
65
     usbRequest_t    *rq = (usbRequest_t*)(void*)data;

+ 3
- 0
examples/UsbRawHidDemo1/main.ino View File

1
 #define ARD_UTILS_DELAYMS
1
 #define ARD_UTILS_DELAYMS
2
 #include "ArdUtils/ArdUtils.h"
2
 #include "ArdUtils/ArdUtils.h"
3
 
3
 
4
+#define RAWHID_TX_SIZE       64
5
+#define RAWHID_RX_SIZE       64
4
 #include "UsbRawHid.h"
6
 #include "UsbRawHid.h"
5
 
7
 
6
 #define ledPin 13
8
 #define ledPin 13
15
 {
17
 {
16
     WAIT_USB;
18
     WAIT_USB;
17
 
19
 
20
+    //UsbRawHid.sendData("test", 4);
18
 
21
 
19
     ArdUtils::delayMs(1000);
22
     ArdUtils::delayMs(1000);
20
     digitalWrite(ledPin, !digitalRead(ledPin));
23
     digitalWrite(ledPin, !digitalRead(ledPin));

+ 1
- 1
usbconfig.h View File

273
  * HID class is 3, no subclass and protocol required (but may be useful!)
273
  * HID class is 3, no subclass and protocol required (but may be useful!)
274
  * CDC class is 2, use subclass 2 and protocol 1 for ACM
274
  * CDC class is 2, use subclass 2 and protocol 1 for ACM
275
  */
275
  */
276
-#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    52
276
+#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    32
277
 /* Define this to the length of the HID report descriptor, if you implement
277
 /* Define this to the length of the HID report descriptor, if you implement
278
  * an HID device. Otherwise don't define it or define it to 0.
278
  * an HID device. Otherwise don't define it or define it to 0.
279
  * If you use this define, you must add a PROGMEM character array named
279
  * If you use this define, you must add a PROGMEM character array named

Loading…
Cancel
Save