├── gcc-code ├── API ├── example │ ├── usbdrv │ ├── hidcore.c │ ├── hidcore.h │ ├── asciimap.c │ ├── asciimap.h │ ├── iocomfort.h │ ├── tinyusbboard.h │ ├── usbconfig.h │ ├── bootloaderconfig.h │ ├── main.h │ ├── main.c │ └── Makefile ├── usbdrv ├── usborg │ ├── dt2_4.zip │ ├── HID1_11.pdf │ ├── Hut1_11.pdf │ └── usb_keydemo.zip ├── generic │ ├── bootloaderconfig.h │ └── usbconfig.h └── lib │ ├── asciimap.c │ ├── asciimap.h │ ├── hidcore.h │ └── hidcore.c ├── example ├── arduino-code └── libraries │ └── VUSBHIDKeyboardMouse │ ├── asciimap.c │ ├── asciimap.h │ ├── hidcore.c │ ├── hidcore.h │ ├── oddebug.c │ ├── oddebug.h │ ├── usbdrv.c │ ├── usbdrv.h │ ├── License.txt │ ├── Readme.txt │ ├── usbconfig.h │ ├── usbdrvasm.S │ ├── Changelog.txt │ ├── USB-ID-FAQ.txt │ ├── asmcommon.inc │ ├── usbdrvasm.asm │ ├── usbdrvasm12.inc │ ├── usbdrvasm128.inc │ ├── usbdrvasm15.inc │ ├── usbdrvasm16.inc │ ├── usbdrvasm165.inc │ ├── usbdrvasm18.inc │ ├── usbdrvasm20.inc │ ├── usbportability.h │ ├── bootloaderconfig.h │ ├── usbdrvasm18-crc.inc │ ├── CommercialLicense.txt │ ├── USB-IDs-for-free.txt │ ├── usbconfig-prototype.h │ ├── keywords.txt │ ├── examples │ ├── KeyboardMouseDemoEmpty │ │ └── KeyboardMouseDemoEmpty.ino │ ├── UsbKeyBoardDemoClassical │ │ └── UsbKeyBoardDemoClassical.ino │ └── KeyboardMouseDemo │ │ └── KeyboardMouseDemo.ino │ └── VUSBHIDKeyboardMouse.h └── readme.md /gcc-code/API: -------------------------------------------------------------------------------- 1 | ../../API/ -------------------------------------------------------------------------------- /example: -------------------------------------------------------------------------------- 1 | gcc-code/example/ -------------------------------------------------------------------------------- /gcc-code/example/usbdrv: -------------------------------------------------------------------------------- 1 | ../usbdrv/ -------------------------------------------------------------------------------- /gcc-code/usbdrv: -------------------------------------------------------------------------------- 1 | ../../v-usb/usbdrv/ -------------------------------------------------------------------------------- /gcc-code/example/hidcore.c: -------------------------------------------------------------------------------- 1 | ../lib/hidcore.c -------------------------------------------------------------------------------- /gcc-code/example/hidcore.h: -------------------------------------------------------------------------------- 1 | ../lib/hidcore.h -------------------------------------------------------------------------------- /gcc-code/example/asciimap.c: -------------------------------------------------------------------------------- 1 | ../lib/asciimap.c -------------------------------------------------------------------------------- /gcc-code/example/asciimap.h: -------------------------------------------------------------------------------- 1 | ../lib/asciimap.h -------------------------------------------------------------------------------- /gcc-code/example/iocomfort.h: -------------------------------------------------------------------------------- 1 | ../API/iocomfort.h -------------------------------------------------------------------------------- /gcc-code/example/tinyusbboard.h: -------------------------------------------------------------------------------- 1 | ../API/tinyusbboard.h -------------------------------------------------------------------------------- /gcc-code/example/usbconfig.h: -------------------------------------------------------------------------------- 1 | ../generic/usbconfig.h -------------------------------------------------------------------------------- /gcc-code/example/bootloaderconfig.h: -------------------------------------------------------------------------------- 1 | ../API/bootloaderconfig.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/asciimap.c: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/lib/asciimap.c -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/asciimap.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/lib/asciimap.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/hidcore.c: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/lib/hidcore.c -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/hidcore.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/lib/hidcore.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/oddebug.c: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/oddebug.c -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/oddebug.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/oddebug.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrv.c: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrv.c -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrv.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrv.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/License.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/License.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/Readme.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/Readme.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbconfig.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/generic/usbconfig.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm.S: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm.S -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/Changelog.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/Changelog.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/USB-ID-FAQ.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/USB-ID-FAQ.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/asmcommon.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/asmcommon.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm.asm: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm.asm -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm12.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm12.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm128.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm128.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm15.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm15.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm16.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm16.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm165.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm165.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm18.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm18.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm20.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm20.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbportability.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbportability.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/bootloaderconfig.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/generic/bootloaderconfig.h -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbdrvasm18-crc.inc: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbdrvasm18-crc.inc -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/CommercialLicense.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/CommercialLicense.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/USB-IDs-for-free.txt: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/USB-IDs-for-free.txt -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/usbconfig-prototype.h: -------------------------------------------------------------------------------- 1 | ../../../gcc-code/usbdrv/usbconfig-prototype.h -------------------------------------------------------------------------------- /gcc-code/usborg/dt2_4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyusbboard/hid-KeyboardMouse/HEAD/gcc-code/usborg/dt2_4.zip -------------------------------------------------------------------------------- /gcc-code/usborg/HID1_11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyusbboard/hid-KeyboardMouse/HEAD/gcc-code/usborg/HID1_11.pdf -------------------------------------------------------------------------------- /gcc-code/usborg/Hut1_11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyusbboard/hid-KeyboardMouse/HEAD/gcc-code/usborg/Hut1_11.pdf -------------------------------------------------------------------------------- /gcc-code/usborg/usb_keydemo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyusbboard/hid-KeyboardMouse/HEAD/gcc-code/usborg/usb_keydemo.zip -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/keywords.txt: -------------------------------------------------------------------------------- 1 | VUSBHIDKeyboardMouse KEYWORD3 2 | UsbKeyboard KEYWORD3 3 | UsbMouse KEYWORD3 -------------------------------------------------------------------------------- /gcc-code/example/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H_1c0fdb4cd9ec4e16951610dd60361c6a 2 | #define __MAIN_H_1c0fdb4cd9ec4e16951610dd60361c6a 1 3 | 4 | 5 | #endif -------------------------------------------------------------------------------- /gcc-code/generic/bootloaderconfig.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __BOOTLOADER_CONFIG_c598b89084594144b7b9257956453d4c 3 | #define __BOOTLOADER_CONFIG_c598b89084594144b7b9257956453d4c 1 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | hid-KeyboardMouse 2 | ================= 3 | 4 | This is a library for implementing both a HID (boot) compliant Keyboard and 5 | Mouse based on V-USB at the same time. 6 | All the USB stuff is primarily handled internally and abstracted. 7 | 8 | It is designed (but not limited to) tinyUSBboard and can be used in 9 | (avr-gc)C and Arduino. (The latter one is based on the C-Code). 10 | While the C integration is more native (and fast), the Arduino- 11 | library is called VUSBHIDKeyboardMouse. 12 | 13 | Additional features like mousewheel support can be activated for C, 14 | via external defines in the Makefile. 15 | 16 | by Stephan Baerwolf (matrixstorm@gmx.de), Schwansee 2014 17 | -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/examples/KeyboardMouseDemoEmpty/KeyboardMouseDemoEmpty.ino: -------------------------------------------------------------------------------- 1 | #include "VUSBHIDKeyboardMouse.h" 2 | 3 | #define LED_NUMLOCK 8 4 | #define LED_CAPSLLOCK 9 5 | #define LED_SCROLLLOCK 5 6 | #define LED_BLINK 3 7 | 8 | 9 | /* 10 | * in order to work without timer, the following value configures timing 11 | * please calibrate it, to see the "LED_BLINK" blink 12 | * with about 8sec (4sec on and 4sec off).. 13 | */ 14 | #define TIMECTRLTUNE 400 15 | 16 | 17 | 18 | void setup() { 19 | // disables Arduino's default millisecond counter (it disturbs the USB otherwise) 20 | #ifdef TIMSK 21 | // older ATmega 22 | TIMSK &= ~(_BV(TOIE0)); 23 | #else 24 | // newer ATmega 25 | TIMSK0 &= ~(_BV(TOIE0)); 26 | #endif 27 | 28 | // remaining inits... 29 | pinMode(LED_NUMLOCK, OUTPUT); 30 | pinMode(LED_CAPSLLOCK, OUTPUT); 31 | pinMode(LED_SCROLLLOCK, OUTPUT); 32 | pinMode(LED_BLINK, OUTPUT); 33 | 34 | /* start with LED switched on */ 35 | digitalWrite(LED_BLINK, 1); 36 | } 37 | 38 | static uint16_t toSecondsCounter = 0; 39 | static uint16_t timeCalibrationCounter = 0; 40 | void loop() { 41 | timeCalibrationCounter++; 42 | 43 | if (timeCalibrationCounter= 1000) { 54 | toSecondsCounter=0; 55 | digitalWrite(LED_BLINK, !digitalRead(LED_BLINK)); 56 | } 57 | } 58 | 59 | 60 | 61 | #ifndef USB_CFG_HID_NOKEYBOARD 62 | #ifdef __cplusplus 63 | extern "C"{ 64 | #endif 65 | void EVENT_CHANGE_LED_state (void) { 66 | digitalWrite(LED_NUMLOCK, current_LED_state & _BV(HIDKEYBOARD_LEDBIT_NUM_LOCK)); 67 | digitalWrite(LED_CAPSLLOCK, current_LED_state & _BV(HIDKEYBOARD_LEDBIT_CAPS_LOCK)); 68 | digitalWrite(LED_SCROLLLOCK, current_LED_state & _BV(HIDKEYBOARD_LEDBIT_SCROLL_LOCK)); 69 | } 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | #endif 74 | -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/examples/UsbKeyBoardDemoClassical/UsbKeyBoardDemoClassical.ino: -------------------------------------------------------------------------------- 1 | #include "VUSBHIDKeyboardMouse.h" 2 | 3 | 4 | #define LED_BLINK 3 5 | #define BUTTON_PIN 6 6 | 7 | /* 8 | * in order to work without timer, the following value configures timing 9 | * please calibrate it, to see the "LED_BLINK" blink 10 | * with about 8sec (4sec on and 4sec off).. 11 | */ 12 | #define TIMECTRLTUNE 300 13 | 14 | 15 | void setup() { 16 | // disables Arduino's default millisecond counter (it disturbs the USB otherwise) 17 | #ifdef TIMSK 18 | // older ATmega 19 | TIMSK &= ~(_BV(TOIE0)); 20 | #else 21 | // newer ATmega 22 | TIMSK0 &= ~(_BV(TOIE0)); 23 | #endif 24 | 25 | // remaining inits... 26 | pinMode(BUTTON_PIN, INPUT_PULLUP); 27 | digitalWrite(BUTTON_PIN, HIGH); 28 | 29 | /* start with LED switched on */ 30 | pinMode(LED_BLINK, OUTPUT); 31 | digitalWrite(LED_BLINK, 1); 32 | } 33 | 34 | 35 | 36 | 37 | static uint16_t toSecondsCounter = 0; 38 | static uint16_t timeCalibrationCounter = 0; 39 | void loop() { 40 | timeCalibrationCounter++; 41 | 42 | if (timeCalibrationCounter= 1000) { 53 | toSecondsCounter=0; 54 | digitalWrite(LED_BLINK, !digitalRead(LED_BLINK)); 55 | } 56 | 57 | if (digitalRead(BUTTON_PIN) == 0) { 58 | 59 | //UsbKeyboard.sendKeyStroke(KEY_B, MOD_GUI_LEFT); 60 | 61 | UsbKeyboard.sendKeyStroke(KEY_H); 62 | UsbKeyboard.sendKeyStroke(KEY_E); 63 | UsbKeyboard.sendKeyStroke(KEY_L); 64 | UsbKeyboard.sendKeyStroke(KEY_L); 65 | UsbKeyboard.sendKeyStroke(KEY_O); 66 | 67 | UsbKeyboard.sendKeyStroke(KEY_SPACE); 68 | 69 | UsbKeyboard.sendKeyStroke(KEY_W); 70 | UsbKeyboard.sendKeyStroke(KEY_O); 71 | UsbKeyboard.sendKeyStroke(KEY_R); 72 | UsbKeyboard.sendKeyStroke(KEY_L); 73 | UsbKeyboard.sendKeyStroke(KEY_D); 74 | //UsbKeyboard.sendKeyStroke(KEY_B, MOD_GUI_LEFT); 75 | 76 | UsbKeyboard.sendKeyStroke(KEY_ENTER); 77 | } 78 | } -------------------------------------------------------------------------------- /gcc-code/example/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "main.h" 3 | #include "tinyusbboard.h" 4 | #include "hidcore.h" 5 | #include "asciimap.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "usbdrv.h" 14 | #include "oddebug.h" 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #ifndef USB_CFG_HID_NOKEYBOARD 22 | # define LED_NUMLOCK LED_B 23 | # define LED_CAPSLOCK LED_PWM 24 | # define LED_SCROLLLOCK LED_LEFT 25 | void EVENT_CHANGE_LED_state (void) { 26 | // NUM LOCK 27 | if (current_LED_state & _BV(HIDKEYBOARD_LEDBIT_NUM_LOCK)) SET_HIGH(LED_NUMLOCK); 28 | else SET_LOW(LED_NUMLOCK); 29 | 30 | // CAPS LOCK 31 | if (current_LED_state & _BV(HIDKEYBOARD_LEDBIT_CAPS_LOCK)) SET_HIGH(LED_CAPSLOCK); 32 | else SET_LOW(LED_CAPSLOCK); 33 | 34 | // SCROLL LOCK 35 | if (current_LED_state & _BV(HIDKEYBOARD_LEDBIT_SCROLL_LOCK)) SET_HIGH(LED_SCROLLLOCK); 36 | else SET_LOW(LED_SCROLLLOCK); 37 | } 38 | #endif 39 | 40 | 41 | int main(void) { 42 | uint8_t zahleins = 1; 43 | uint8_t zahlnull = 0; 44 | uint16_t tmp = 0; 45 | uint16_t counter = 0; 46 | 47 | bool pressed = false; 48 | 49 | /* confige peripherals */ 50 | CFG_PULLUP(BUTTON_PROG); 51 | CFG_OUTPUT(LED_B); 52 | CFG_OUTPUT(LED_PWM); 53 | CFG_OUTPUT(LED_LEFT); 54 | CFG_OUTPUT(LED_RIGHT); 55 | 56 | hidInit(); 57 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ 58 | 59 | /* usb disconnect delay */ 60 | _delay_ms(300); 61 | wdt_reset(); 62 | 63 | /* connect the usb */ 64 | usbDeviceConnect(); 65 | usbInit(); 66 | sei(); 67 | 68 | 69 | 70 | for(;;) { 71 | wdt_reset(); 72 | 73 | #if (!(defined(USB_CFG_HID_NOMOUSE))) && (defined(USB_CFG_HID_WHEELMOUSE)) 74 | if (IS_PRESSED(BUTTON_PROG)) { 75 | if /*(!(pressed))*/ (true) { 76 | if (!(mouse_report_dirty)) { 77 | pressed=true; 78 | mouse_report_clear(¤t_mouse_report); 79 | current_mouse_report.displacement[mouse_report_displacement_wheel]=+1; 80 | mouse_report_dirty |= 0x2; 81 | } 82 | } 83 | } else { 84 | if (pressed) { 85 | if (!(mouse_report_dirty)) { 86 | pressed=false; 87 | mouse_report_clear(¤t_mouse_report); 88 | mouse_report_dirty |= 0x2; 89 | } 90 | } 91 | } 92 | #endif 93 | 94 | counter++; 95 | #define counterthreshold 555 /* calibrated to about 4ms - LED_RIGHT should flash every 4sec then */ 96 | if (counter >= counterthreshold) { 97 | counter-=counterthreshold; 98 | hidPoll(&zahleins); 99 | tmp++; 100 | #define tmpthreshold 1000 101 | if (tmp >= tmpthreshold) { 102 | tmp-=tmpthreshold; 103 | TOGGLE(LED_RIGHT); 104 | } 105 | } else hidPoll(&zahlnull); 106 | 107 | } 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/examples/KeyboardMouseDemo/KeyboardMouseDemo.ino: -------------------------------------------------------------------------------- 1 | #include "VUSBHIDKeyboardMouse.h" 2 | 3 | #define LED_KLICK 3 4 | #define LED_BLINK 5 5 | #define BUTTON_PIN 6 6 | 7 | #define TYPEDELAY_4MS 20 8 | #define WIGGLEDELAY_4MS 10 9 | 10 | /* 11 | * in order to work without timer, the following value configures timing 12 | * please calibrate it, to see the "LED_BLINK" blink 13 | * with about 8sec (4sec on and 4sec off).. 14 | */ 15 | #define TIMECTRLTUNE 350 16 | 17 | 18 | const unsigned char message[] PROGMEM = { 19 | "tinyUSBboard\n" 20 | "http://matrixstorm.com/avr/tinyusbboard/\n" 21 | "\n" 22 | "\n" 23 | "In case you encouter problems, have any questions or in case\n" 24 | "you just have remarks, please do not hesitate to contact:\n" 25 | "Stephan Baerwolf - stephan@matrixstorm.com\n" 26 | "matrixstorm@gmx.de, or stephan.baerwolf@tu-ilmenau.de\n" 27 | "\n" 28 | "PGP-KeyID\t: 0xFB9B12DB\n" 29 | "Fingerprint\t: 2252 B41E 12DF 41AD 476F 7F36 084A 0911 FB9B 12DB\n" 30 | "\n" 31 | "\n" 32 | "\n" 33 | }; 34 | 35 | void setup() { 36 | // disables Arduino's default millisecond counter (it disturbs the USB otherwise) 37 | #ifdef TIMSK 38 | // older ATmega 39 | TIMSK &= ~(_BV(TOIE0)); 40 | #else 41 | // newer ATmega 42 | TIMSK0 &= ~(_BV(TOIE0)); 43 | #endif 44 | 45 | // remaining inits... 46 | randomSeed(analogRead(0)); 47 | 48 | pinMode(BUTTON_PIN, INPUT_PULLUP); 49 | digitalWrite(BUTTON_PIN, HIGH); 50 | 51 | pinMode(LED_KLICK, OUTPUT); 52 | 53 | /* start with LED switched on */ 54 | pinMode(LED_BLINK, OUTPUT); 55 | digitalWrite(LED_BLINK, 1); 56 | } 57 | 58 | 59 | static byte typeDelayCounter = 0; 60 | static byte wiggleDelayCounter = 0; 61 | static size_t charPosition = sizeof(message); /* message symbol */ 62 | 63 | static uint16_t toSecondsCounter = 0; 64 | static uint16_t timeCalibrationCounter = 0; 65 | void loop() { 66 | timeCalibrationCounter++; 67 | 68 | if (timeCalibrationCounter= TYPEDELAY_4MS) { 77 | typeDelayCounter=0; 78 | if (!digitalRead(BUTTON_PIN)) { 79 | digitalWrite(LED_KLICK, 1); 80 | charPosition++; 81 | 82 | //type a key 83 | if (charPosition>=sizeof(message)) charPosition=0; 84 | UsbKeyboard.write(pgm_read_byte_near(message + charPosition)); 85 | } else digitalWrite(LED_KLICK, 0); 86 | } 87 | 88 | /* mouse */ 89 | wiggleDelayCounter++; 90 | if (wiggleDelayCounter >= WIGGLEDELAY_4MS) { 91 | // wiggle the mouse 92 | wiggleDelayCounter=0; 93 | UsbMouse.move(random(-8,8), random(-8,8)); 94 | } 95 | 96 | VUSBHIDKeyboardMouse.update(1); 97 | toSecondsCounter++; 98 | } 99 | 100 | 101 | /* the calibrated frequency to measure */ 102 | if (toSecondsCounter >= 1000) { 103 | toSecondsCounter=0; 104 | digitalWrite(LED_BLINK, !digitalRead(LED_BLINK)); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /gcc-code/lib/asciimap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * asciimap.c 3 | * 4 | * This file implements ASCII symbol to keystroke- 5 | * report mapping. 6 | * Currently implemented keyboard layouts are: 7 | * # en_us (41) 8 | * # de (10) 9 | * 10 | * The default layout always will be en_us. 11 | * Unknown symbols aren't mapped. 12 | * 13 | * by Stephan Baerwolf (stephan@matrixstorm.com), Schwansee 2014 14 | * for http://matrixstorm.com/avr/tinyusbboard/ 15 | * (please contact me at least before commercial use) 16 | */ 17 | 18 | #define __ASCIIMAP_C_7b57b2239b7d418b8332be68649a9120 1 19 | 20 | #include "asciimap.h" 21 | 22 | #ifndef USB_CFG_HID_NOKEYBOARD 23 | 24 | uint8_t asciitokeyreport(uint8_t key, keyboard_report_t *report) { 25 | uint8_t result = 1; 26 | 27 | if (key == ' ') { 28 | report->keycode[0] = HIDKEYBOARD_KEYUSE_spacebar; 29 | } else if (key == '\n') { 30 | report->keycode[0] = HIDKEYBOARD_KEYUSE_return; 31 | } else if (key == '\t') { 32 | report->keycode[0] = HIDKEYBOARD_KEYUSE_tab; 33 | #if ASCIIMAP_LAYOUT == ASCIIMAP_LAYOUT_DE 34 | } else if (key == 'z') { 35 | report->keycode[0] = HIDKEYBOARD_KEYUSE_y; 36 | } else if (key == 'Z') { 37 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 38 | report->keycode[0] = HIDKEYBOARD_KEYUSE_y; 39 | } else if (key == 'y') { 40 | report->keycode[0] = HIDKEYBOARD_KEYUSE_z; 41 | } else if (key == 'Y') { 42 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 43 | report->keycode[0] = HIDKEYBOARD_KEYUSE_z; 44 | #endif 45 | } else if ((key >= 'a') && (key <= 'z')) { 46 | report->keycode[0] = (key-'a')+HIDKEYBOARD_KEYUSE_a; 47 | } else if ((key >= 'A') && (key <= 'Z')) { 48 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 49 | report->keycode[0] = (key-'A')+HIDKEYBOARD_KEYUSE_a; 50 | } else if ((key >= '1') && (key <= '9')) { 51 | report->keycode[0] = (key-'1')+HIDKEYBOARD_KEYUSE_1; 52 | } else if (key == '0') { 53 | report->keycode[0] = HIDKEYBOARD_KEYUSE_0; 54 | } else if (key == '@') { 55 | #if ASCIIMAP_LAYOUT == ASCIIMAP_LAYOUT_DE 56 | report->modifier = _BV(HIDKEYBOARD_MODBIT_RIGHT_ALT); 57 | report->keycode[0] = HIDKEYBOARD_KEYUSE_q; 58 | #else 59 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 60 | report->keycode[0] = HIDKEYBOARD_KEYUSE_2; 61 | #endif 62 | } else if (key == ':') { 63 | #if ASCIIMAP_LAYOUT == ASCIIMAP_LAYOUT_DE 64 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 65 | report->keycode[0] = HIDKEYBOARD_KEYUSE_period; 66 | #else 67 | report->modifier = _BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT); 68 | report->keycode[0] = HIDKEYBOARD_KEYUSE_semicolon; 69 | #endif 70 | } else if (key == ',') { 71 | report->keycode[0] = HIDKEYBOARD_KEYUSE_comma; 72 | } else if (key == '/') { 73 | report->keycode[0] = HIDKEYBOARD_KEYUSE_KEYPAD_div; 74 | } else if (key == '*') { 75 | report->keycode[0] = HIDKEYBOARD_KEYUSE_KEYPAD_mul; 76 | } else if (key == '+') { 77 | report->keycode[0] = HIDKEYBOARD_KEYUSE_KEYPAD_add; 78 | } else if (key == '-') { 79 | report->keycode[0] = HIDKEYBOARD_KEYUSE_KEYPAD_min; 80 | } else if (key == '.') { 81 | report->keycode[0] = HIDKEYBOARD_KEYUSE_period; 82 | } else result=0; 83 | 84 | return result; 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /gcc-code/example/Makefile: -------------------------------------------------------------------------------- 1 | ####################################################################################### 2 | 3 | # environment variable of the current user to locate the AVR8 toolchain 4 | AVRPATH = $(AVR8TOOLCHAINBINDIR) 5 | 6 | # the type of avr microcontroller 7 | DEVICE = atmega8 8 | 9 | # the frequency the microcontroller is clocked with 10 | F_CPU = 16000000 11 | 12 | #tinyUSBboard Rev3 and newer 13 | DEFINES += -DVUSB_CFG_IOPORTNAME=D -DVUSB_CFG_DMINUS_BIT=7 -DVUSB_CFG_DPLUS_BIT=2 14 | DEFINES += -DVUSB_CFG_HASNO_PULLUP_IOPORTNAME -DVUSB_CFG_HASNO_PULLUP_BIT 15 | 16 | # extra defines 17 | DEFINES += -DUSB_CFG_HID_WHEELMOUSE 18 | # DEFINES += -DUSB_CFG_HID_NOMOUSE 19 | # DEFINES += -DUSB_CFG_HID_NOKEYBOARD 20 | 21 | # where the firmware should be located within the flashmemory (in case you trampoline) 22 | FLASHADDRESS = 0x0000 23 | 24 | # (not important for compiling) - the device transporting firmware into the controller 25 | PROGRAMMER = -c usbasp 26 | 27 | ####################################################################################### 28 | 29 | 30 | 31 | # Tools: 32 | ECHO=@echo 33 | GCC=gcc 34 | MAKE=@make 35 | RM=@rm -f 36 | 37 | CC=$(AVRPATH)avr-gcc 38 | OBC=@$(AVRPATH)avr-objcopy 39 | OBD=@$(AVRPATH)avr-objdump 40 | SIZ=@$(AVRPATH)avr-size 41 | 42 | AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) 43 | 44 | 45 | MYCFLAGS = -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -Iusbdrv -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) $(CFLAGS) $(DEFINES) 46 | MYLDFLAGS = -Wl,--relax,--gc-sections $(LDFLAGS) 47 | 48 | 49 | FLASHPREAMBLEDEFINE = 50 | ifneq ($(FLASHADDRESS), 0) 51 | ifneq ($(FLASHADDRESS), 00) 52 | ifneq ($(FLASHADDRESS), 000) 53 | ifneq ($(FLASHADDRESS), 0000) 54 | ifneq ($(FLASHADDRESS), 00000) 55 | ifneq ($(FLASHADDRESS), 0x0) 56 | ifneq ($(FLASHADDRESS), 0x00) 57 | ifneq ($(FLASHADDRESS), 0x000) 58 | ifneq ($(FLASHADDRESS), 0x0000) 59 | ifneq ($(FLASHADDRESS), 0x00000) 60 | FLASHPREAMBLE = 0x0000 61 | FLASHPREAMBLEDEFINE = -DFLASHPREAMBLE=$(FLASHPREAMBLE) 62 | MYLDFLAGS += -Wl,--section-start=.text=$(FLASHADDRESS) 63 | endif 64 | endif 65 | endif 66 | endif 67 | endif 68 | endif 69 | endif 70 | endif 71 | endif 72 | endif 73 | 74 | 75 | 76 | 77 | STDDEP = *.h usbdrv/*.h 78 | EXTRADEP = Makefile 79 | 80 | 81 | all: main.hex main.raw main.asm 82 | 83 | usbdrv/usbdrvasm.o: usbdrv/usbdrvasm.S $(STDDEP) $(EXTRADEP) 84 | $(CC) -x assembler-with-cpp -c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o $(MYCFLAGS) 85 | 86 | usbdrv/oddebug.o: usbdrv/oddebug.c $(STDDEP) $(EXTRADEP) 87 | $(CC) usbdrv/oddebug.c -c -o usbdrv/oddebug.o $(MYCFLAGS) 88 | 89 | usbdrv/usbdrv.o: usbdrv/usbdrv.c $(STDDEP) $(EXTRADEP) 90 | $(CC) usbdrv/usbdrv.c -c -o usbdrv/usbdrv.o $(MYCFLAGS) 91 | 92 | hidcore.o: hidcore.c $(STDDEP) $(EXTRADEP) 93 | $(CC) hidcore.c -c -o hidcore.o $(MYCFLAGS) 94 | 95 | asciimap.o: asciimap.c $(STDDEP) $(EXTRADEP) 96 | $(CC) asciimap.c -c -o asciimap.o $(MYCFLAGS) 97 | 98 | main.o: main.c $(STDDEP) $(EXTRADEP) 99 | $(CC) main.c -c -o main.o $(MYCFLAGS) 100 | 101 | main.elf: main.o hidcore.o asciimap.o usbdrv/usbdrv.o usbdrv/oddebug.o usbdrv/usbdrvasm.o $(STDDEP) $(EXTRADEP) 102 | $(CC) main.o hidcore.o asciimap.o usbdrv/usbdrv.o usbdrv/oddebug.o usbdrv/usbdrvasm.o -o main.elf $(MYCFLAGS) -Wl,-Map,main.map $(MYLDFLAGS) 103 | $(ECHO) "." 104 | $(SIZ) main.elf 105 | $(ECHO) "." 106 | 107 | main.hex: main.elf $(STDDEP) $(EXTRADEP) 108 | $(OBC) -j .text -j .data -O ihex main.elf main.hex 109 | 110 | main.raw: main.elf $(STDDEP) $(EXTRADEP) 111 | $(OBC) -j .text -j .data -O binary main.elf main.raw 112 | 113 | main.asm: main.elf $(STDDEP) $(EXTRADEP) 114 | $(OBD) -d main.elf > main.asm 115 | 116 | disasm: main.elf $(STDDEP) $(EXTRADEP) 117 | $(OBD) -d main.elf 118 | 119 | flash: all 120 | $(ECHO) "." 121 | $(AVRDUDE) -U flash:w:main.hex:i 122 | $(ECHO) "." 123 | 124 | deepclean: clean 125 | $(RM) usbdrv/*~ 126 | $(RM) *~ 127 | 128 | clean: 129 | $(RM) *.o 130 | $(RM) usbdrv/*.o 131 | $(RM) main.hex 132 | $(RM) main.raw 133 | $(RM) main.asm 134 | $(RM) main.map 135 | $(RM) main.elf 136 | -------------------------------------------------------------------------------- /gcc-code/lib/asciimap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * asciimap.h 3 | * 4 | * This file is the head for ASCII symbol to keystroke- 5 | * report mapping. 6 | * 7 | * by Stephan Baerwolf (stephan@matrixstorm.com), Schwansee 2014 8 | * for http://matrixstorm.com/avr/tinyusbboard/ 9 | * (please contact me at least before commercial use) 10 | */ 11 | 12 | #ifndef __ASCIIMAP_H_7b57b2239b7d418b8332be68649a9120 13 | #define __ASCIIMAP_H_7b57b2239b7d418b8332be68649a9120 1 14 | 15 | #include "hidcore.h" 16 | 17 | #ifdef __ASCIIMAP_C_7b57b2239b7d418b8332be68649a9120 18 | # define ASCIIMAPPUBLIC 19 | #else 20 | # define ASCIIMAPPUBLIC extern 21 | #endif 22 | 23 | 24 | #define ASCIIMAP_LAYOUT_DE 10 25 | #define ASCIIMAP_LAYOUT_ENUS 41 26 | 27 | #ifndef ASCIIMAP_LAYOUT 28 | # define ASCIIMAP_LAYOUT ASCIIMAP_LAYOUT_ENUS 29 | #endif 30 | 31 | #ifndef USB_CFG_HID_NOKEYBOARD 32 | /* 33 | * http://www.cygnal.org/ubb/Forum9/HTML/001381.html and also 34 | * from page 59 of: 35 | * HID Usage Tables 36 | * 6/27/01 37 | * Version 1.11 38 | * Hut1_11.pdf 39 | * 40 | * 41 | * The bitmap of modifier byte is defined in the HID spec. 42 | * 8.3 Report Format for Array Items (HID1_11.pdf p56) 43 | * 44 | * bit 45 | * 0 LEFT CTRL 46 | * 1 LEFT SHIFT 47 | * 2 LEFT ALT 48 | * 3 LEFT GUI 49 | * 4 RIGHT CTRL 50 | * 5 RIGHT SHIFT 51 | * 6 RIGHT ALT 52 | * 7 RIGHT GUI 53 | */ 54 | #define HIDKEYBOARD_MODBIT_LEFT_CTRL 0 55 | #define HIDKEYBOARD_MODBIT_LEFT_SHIFT 1 56 | #define HIDKEYBOARD_MODBIT_LEFT_ALT 2 57 | #define HIDKEYBOARD_MODBIT_LEFT_GUI 3 58 | #define HIDKEYBOARD_MODBIT_RIGHT_CTRL 4 59 | #define HIDKEYBOARD_MODBIT_RIGHT_SHIFT 5 60 | #define HIDKEYBOARD_MODBIT_RIGHT_ALT 6 61 | #define HIDKEYBOARD_MODBIT_RIGHT_GUI 7 62 | 63 | 64 | #define HIDKEYBOARD_KEYUSE_a 0x04 65 | #define HIDKEYBOARD_KEYUSE_b 0x05 66 | #define HIDKEYBOARD_KEYUSE_c 0x06 67 | #define HIDKEYBOARD_KEYUSE_d 0x07 68 | #define HIDKEYBOARD_KEYUSE_e 0x08 69 | #define HIDKEYBOARD_KEYUSE_f 0x09 70 | #define HIDKEYBOARD_KEYUSE_g 0x0a 71 | #define HIDKEYBOARD_KEYUSE_h 0x0b 72 | #define HIDKEYBOARD_KEYUSE_i 0x0c 73 | #define HIDKEYBOARD_KEYUSE_j 0x0d 74 | #define HIDKEYBOARD_KEYUSE_k 0x0e 75 | #define HIDKEYBOARD_KEYUSE_l 0x0f 76 | #define HIDKEYBOARD_KEYUSE_m 0x10 77 | #define HIDKEYBOARD_KEYUSE_n 0x11 78 | #define HIDKEYBOARD_KEYUSE_o 0x12 79 | #define HIDKEYBOARD_KEYUSE_p 0x13 80 | #define HIDKEYBOARD_KEYUSE_q 0x14 81 | #define HIDKEYBOARD_KEYUSE_r 0x15 82 | #define HIDKEYBOARD_KEYUSE_s 0x16 83 | #define HIDKEYBOARD_KEYUSE_t 0x17 84 | #define HIDKEYBOARD_KEYUSE_u 0x18 85 | #define HIDKEYBOARD_KEYUSE_v 0x19 86 | #define HIDKEYBOARD_KEYUSE_w 0x1a 87 | #define HIDKEYBOARD_KEYUSE_x 0x1b 88 | #define HIDKEYBOARD_KEYUSE_y 0x1c 89 | #define HIDKEYBOARD_KEYUSE_z 0x1d 90 | 91 | #define HIDKEYBOARD_KEYUSE_1 0x1e 92 | #define HIDKEYBOARD_KEYUSE_2 0x1f 93 | #define HIDKEYBOARD_KEYUSE_3 0x20 94 | #define HIDKEYBOARD_KEYUSE_4 0x21 95 | #define HIDKEYBOARD_KEYUSE_5 0x22 96 | #define HIDKEYBOARD_KEYUSE_6 0x23 97 | #define HIDKEYBOARD_KEYUSE_7 0x24 98 | #define HIDKEYBOARD_KEYUSE_8 0x25 99 | #define HIDKEYBOARD_KEYUSE_9 0x26 100 | #define HIDKEYBOARD_KEYUSE_0 0x27 101 | 102 | #define HIDKEYBOARD_KEYUSE_return 0x28 103 | #define HIDKEYBOARD_KEYUSE_escape 0x29 104 | #define HIDKEYBOARD_KEYUSE_delete 0x2a 105 | #define HIDKEYBOARD_KEYUSE_tab 0x2b 106 | #define HIDKEYBOARD_KEYUSE_spacebar 0x2c 107 | #define HIDKEYBOARD_KEYUSE_minus 0x2d 108 | #define HIDKEYBOARD_KEYUSE_equal 0x2e 109 | #define HIDKEYBOARD_KEYUSE_bracketopen 0x2f 110 | #define HIDKEYBOARD_KEYUSE_bracketclose 0x30 111 | #define HIDKEYBOARD_KEYUSE_backslash 0x31 112 | #define HIDKEYBOARD_KEYUSE_hashtag 0x32 113 | #define HIDKEYBOARD_KEYUSE_semicolon 0x33 114 | #define HIDKEYBOARD_KEYUSE_apostrophe 0x34 115 | #define HIDKEYBOARD_KEYUSE_graveaccent 0x35 116 | #define HIDKEYBOARD_KEYUSE_comma 0x36 117 | #define HIDKEYBOARD_KEYUSE_period 0x37 118 | #define HIDKEYBOARD_KEYUSE_slash 0x38 119 | 120 | #define HIDKEYBOARD_KEYUSE_F1 0x3a 121 | #define HIDKEYBOARD_KEYUSE_F2 0x3b 122 | #define HIDKEYBOARD_KEYUSE_F3 0x3c 123 | #define HIDKEYBOARD_KEYUSE_F4 0x3d 124 | #define HIDKEYBOARD_KEYUSE_F5 0x3e 125 | #define HIDKEYBOARD_KEYUSE_F6 0x3f 126 | #define HIDKEYBOARD_KEYUSE_F7 0x40 127 | #define HIDKEYBOARD_KEYUSE_F8 0x41 128 | #define HIDKEYBOARD_KEYUSE_F9 0x42 129 | #define HIDKEYBOARD_KEYUSE_F10 0x43 130 | #define HIDKEYBOARD_KEYUSE_F11 0x44 131 | #define HIDKEYBOARD_KEYUSE_F12 0x45 132 | 133 | #define HIDKEYBOARD_KEYUSE_pageup 0x4b 134 | #define HIDKEYBOARD_KEYUSE_pagedown 0x4e 135 | 136 | #define HIDKEYBOARD_KEYUSE_arrow_right 0x4f 137 | #define HIDKEYBOARD_KEYUSE_arrow_left 0x50 138 | #define HIDKEYBOARD_KEYUSE_arrow_down 0x51 139 | #define HIDKEYBOARD_KEYUSE_arrow_up 0x52 140 | 141 | #define HIDKEYBOARD_KEYUSE_KEYPAD_div 0x54 142 | #define HIDKEYBOARD_KEYUSE_KEYPAD_mul 0x55 143 | #define HIDKEYBOARD_KEYUSE_KEYPAD_min 0x56 144 | #define HIDKEYBOARD_KEYUSE_KEYPAD_add 0x57 145 | #define HIDKEYBOARD_KEYUSE_KEYPAD_enter 0x58 146 | 147 | ASCIIMAPPUBLIC uint8_t asciitokeyreport(uint8_t key, keyboard_report_t *report); 148 | #endif 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /gcc-code/lib/hidcore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hidcore.h 3 | * 4 | * This file is the head for basic HID keyboard and 5 | * Mouse devices (at the same time) using V-USB on 6 | * an Atmel ATmega microcontroller. 7 | * The device will be HID BOOT v1.1 conform, so it also 8 | * will work in BIOS and in legacy operating systems. 9 | * 10 | * by Stephan Baerwolf (stephan@matrixstorm.com), Schwansee 2014 11 | * for http://matrixstorm.com/avr/tinyusbboard/ 12 | * (please contact me at least before commercial use) 13 | */ 14 | 15 | #ifndef __HIDCORE_H_7b57b2239b7d418b8332be68649a9120 16 | #define __HIDCORE_H_7b57b2239b7d418b8332be68649a9120 1 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | 24 | 25 | #ifdef __HIDCORE_C_7b57b2239b7d418b8332be68649a9120 26 | # define HIDCOREPUBLIC 27 | #else 28 | # define HIDCOREPUBLIC extern 29 | #endif 30 | 31 | #ifndef USBIFACE_CLASS_HID 32 | # define USBIFACE_CLASS_HID 0x03 33 | #endif 34 | 35 | #ifndef USBIFACE_SUBCLASS_BOOT 36 | # define USBIFACE_SUBCLASS_BOOT 0x01 37 | #endif 38 | 39 | 40 | #ifndef USBIFACE_PROTOCOL_KEYBOARD 41 | # define USBIFACE_PROTOCOL_KEYBOARD 0x01 42 | #endif 43 | #ifndef USBIFACE_PROTOCOL_MOUSE 44 | # define USBIFACE_PROTOCOL_MOUSE 0x02 45 | #endif 46 | 47 | 48 | #ifndef USBIFACE_NO_DESCRIPTOR 49 | # define USBIFACE_NO_DESCRIPTOR 0x0 50 | #endif 51 | 52 | 53 | #ifndef USB_CFG_HID_NOKEYBOARD 54 | # ifndef USBIFACE_INDEX_KEYBOARD 55 | # define USBIFACE_INDEX_KEYBOARD 0x0 56 | # endif 57 | #endif 58 | 59 | 60 | #ifndef USB_CFG_HID_NOMOUSE 61 | # ifndef USBIFACE_INDEX_MOUSE 62 | # ifdef USB_CFG_HID_NOKEYBOARD 63 | # define USBIFACE_INDEX_MOUSE 0x0 64 | # else 65 | # define USBIFACE_INDEX_MOUSE 0x1 66 | # endif 67 | # endif 68 | #endif 69 | 70 | 71 | 72 | #if (USB_CFG_DESCR_PROPS_CONFIGURATION > 0) 73 | 74 | #if (USB_CFG_HAVE_INTRIN_ENDPOINT==0) 75 | # error USB_CFG_HAVE_INTRIN_ENDPOINT has to be activated when implementing dual HID 76 | #endif 77 | 78 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 79 | # if (USB_CFG_HAVE_INTRIN_ENDPOINT3==0) 80 | # error USB_CFG_HAVE_INTRIN_ENDPOINT3 has to be activated when implementing dual HID 81 | # endif 82 | #endif 83 | 84 | #if (USB_CFG_DESCR_PROPS_HID!=0) 85 | # if (USB_CFG_DESCR_PROPS_HID!=USB_PROP_IS_DYNAMIC) 86 | # error USB_CFG_DESCR_PROPS_HID is ignored when implementing dual HID 87 | # endif 88 | #endif 89 | 90 | #if (USB_CFG_DESCR_PROPS_HID!=0) 91 | # if (USB_CFG_DESCR_PROPS_HID!=USB_PROP_IS_DYNAMIC) 92 | # error USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH is ignored when implementing dual HID 93 | # endif 94 | #endif 95 | 96 | #ifdef USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 97 | # error USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH must not be used when implementing dual HID 98 | #endif 99 | 100 | #ifdef USB_CFG_INTERFACE_CLASS 101 | # if (USB_CFG_INTERFACE_CLASS!=0) 102 | # warning USB_CFG_INTERFACE_CLASS is ignored when implementing dual HID 103 | # endif 104 | #endif 105 | 106 | #ifdef USB_CFG_INTERFACE_SUBCLASS 107 | # if (USB_CFG_INTERFACE_SUBCLASS!=0) 108 | # warning USB_CFG_INTERFACE_SUBCLASS is ignored when implementing dual HID 109 | # endif 110 | #endif 111 | 112 | #ifdef USB_CFG_INTERFACE_PROTOCOL 113 | # if (USB_CFG_INTERFACE_PROTOCOL!=0) 114 | # warning USB_CFG_INTERFACE_PROTOCOL is ignored when implementing dual HID 115 | # endif 116 | #endif 117 | 118 | 119 | #ifndef USB_CFG_HID_NOKEYBOARD 120 | typedef struct __keyboard_report_t keyboard_report_t; 121 | 122 | struct __keyboard_report_t { 123 | uint8_t modifier; 124 | uint8_t reserved; 125 | uint8_t keycode[6]; 126 | } __attribute__((packed)); 127 | #endif 128 | 129 | #ifndef USB_CFG_HID_NOMOUSE 130 | typedef struct __mouse_report_t mouse_report_t; 131 | 132 | #define mouse_report_buttonbit_left 0 133 | #define mouse_report_buttonbit_right 1 134 | #define mouse_report_buttonbit_middle 2 135 | 136 | #define mouse_report_displacement_X 0 137 | #define mouse_report_displacement_Y 1 138 | #ifdef USB_CFG_HID_WHEELMOUSE 139 | # define mouse_report_displacement_wheel 2 140 | #endif 141 | struct __mouse_report_t { 142 | uint8_t buttons; 143 | #ifdef USB_CFG_HID_WHEELMOUSE 144 | int8_t displacement[3]; // [0]=X, [1]=Y, [2]=wheel 145 | #else 146 | int8_t displacement[2]; // [0]=X, [1]=Y 147 | #endif 148 | } __attribute__((packed)); 149 | #endif 150 | 151 | 152 | 153 | #if (!(defined(USB_CFG_HID_NOKEYBOARD))) 154 | # define HIDKEYBOARD_LEDBIT_NUM_LOCK 0 155 | # define HIDKEYBOARD_LEDBIT_CAPS_LOCK 1 156 | # define HIDKEYBOARD_LEDBIT_SCROLL_LOCK 2 157 | # define HIDKEYBOARD_LEDBIT_COMPOSE 3 158 | # define HIDKEYBOARD_LEDBIT_KANA 4 159 | 160 | # define HIDKEYBOARD_BOOT_KEYUSAGE_NoEvent 0x00 161 | # define HIDKEYBOARD_BOOT_KEYUSAGE_ErrorRollOver 0x01 162 | # define HIDKEYBOARD_BOOT_KEYUSAGE_POSTFail 0x02 163 | # define HIDKEYBOARD_BOOT_KEYUSAGE_ErrorUndefined 0x03 164 | #endif 165 | 166 | 167 | HIDCOREPUBLIC PROGMEM const char usbDescriptorConfiguration[]; 168 | 169 | #ifndef USB_CFG_HID_NOKEYBOARD 170 | HIDCOREPUBLIC keyboard_report_t current_keyboard_report; 171 | HIDCOREPUBLIC uint8_t keyboard_report_dirty; 172 | HIDCOREPUBLIC volatile uchar current_LED_state; // keyboard LEDs 173 | 174 | HIDCOREPUBLIC PROGMEM const char usbHidKeyboardReportDescriptor[]; 175 | HIDCOREPUBLIC void EVENT_CHANGE_LED_state (void); 176 | HIDCOREPUBLIC void keyboard_report_fillkeys(keyboard_report_t *report, uint8_t usagecode); 177 | HIDCOREPUBLIC void keyboard_report_setNoEvent(keyboard_report_t *report); 178 | HIDCOREPUBLIC void keyboard_report_setErrorRollOver(keyboard_report_t *report); 179 | HIDCOREPUBLIC void keyboard_report_clear(keyboard_report_t *report); 180 | #endif 181 | 182 | #ifndef USB_CFG_HID_NOMOUSE 183 | HIDCOREPUBLIC mouse_report_t current_mouse_report; 184 | HIDCOREPUBLIC uint8_t mouse_report_dirty; 185 | 186 | HIDCOREPUBLIC PROGMEM const char usbHidMouseReportDescriptor[]; 187 | HIDCOREPUBLIC void mouse_report_clear(mouse_report_t *report); 188 | #endif 189 | 190 | HIDCOREPUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq); 191 | 192 | HIDCOREPUBLIC void hidInit(void); 193 | HIDCOREPUBLIC void hidPoll(uint8_t *time_since_lastcall_in_four_ms_units); 194 | 195 | HIDCOREPUBLIC usbMsgLen_t hidFunctionSetup(uchar data[8]); 196 | 197 | #endif /* (USB_CFG_DESCR_PROPS_CONFIGURATION > 0) */ 198 | 199 | #endif 200 | -------------------------------------------------------------------------------- /arduino-code/libraries/VUSBHIDKeyboardMouse/VUSBHIDKeyboardMouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Idea from: http://code.rancidbacon.com/ProjectLogArduinoUSB 3 | * (Interfaces are kept nearly the same.) 4 | * 5 | * by Stephan Baerwolf (stephan@matrixstorm.com), Schwansee 2014 6 | * for http://matrixstorm.com/avr/tinyusbboard/ 7 | * (please contact me at least before commercial use) 8 | */ 9 | 10 | #ifndef __VUSBHIDKEYBOARDMOUSE_H_abe53fffc7524ee19e61f5f3305779a2 11 | #define __VUSBHIDKEYBOARDMOUSE_H_abe53fffc7524ee19e61f5f3305779a2 1 12 | 13 | #ifdef USB_CFG_HID_NOKEYBOARD 14 | # if (USB_CFG_HID_NOKEYBOARD <= 0) 15 | # undef USB_CFG_HID_NOKEYBOARD 16 | # endif 17 | #endif 18 | 19 | #ifdef USB_CFG_HID_NOMOUSE 20 | # if (USB_CFG_HID_NOMOUSE <= 0) 21 | # undef USB_CFG_HID_NOMOUSE 22 | # endif 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | extern "C"{ 27 | #endif 28 | # include "asciimap.h" 29 | # include "hidcore.h" 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | typedef uint8_t byte; 44 | 45 | #ifndef USB_CFG_HID_NOKEYBOARD 46 | # define MOD_CONTROL_LEFT (_BV(HIDKEYBOARD_MODBIT_LEFT_CTRL)) 47 | # define MOD_SHIFT_LEFT (_BV(HIDKEYBOARD_MODBIT_LEFT_SHIFT)) 48 | # define MOD_ALT_LEFT (_BV(HIDKEYBOARD_MODBIT_LEFT_ALT)) 49 | # define MOD_GUI_LEFT (_BV(HIDKEYBOARD_MODBIT_LEFT_GUI)) 50 | # define MOD_CONTROL_RIGHT (_BV(HIDKEYBOARD_MODBIT_RIGHT_CTRL)) 51 | # define MOD_SHIFT_RIGHT (_BV(HIDKEYBOARD_MODBIT_RIGHT_SHIFT)) 52 | # define MOD_ALT_RIGHT (_BV(HIDKEYBOARD_MODBIT_RIGHT_ALT)) 53 | # define MOD_GUI_RIGHT (_BV(HIDKEYBOARD_MODBIT_RIGHT_GUI)) 54 | 55 | # define KEY_A HIDKEYBOARD_KEYUSE_a 56 | # define KEY_B HIDKEYBOARD_KEYUSE_b 57 | # define KEY_C HIDKEYBOARD_KEYUSE_c 58 | # define KEY_D HIDKEYBOARD_KEYUSE_d 59 | # define KEY_E HIDKEYBOARD_KEYUSE_e 60 | # define KEY_F HIDKEYBOARD_KEYUSE_f 61 | # define KEY_G HIDKEYBOARD_KEYUSE_g 62 | # define KEY_H HIDKEYBOARD_KEYUSE_h 63 | # define KEY_I HIDKEYBOARD_KEYUSE_i 64 | # define KEY_J HIDKEYBOARD_KEYUSE_j 65 | # define KEY_K HIDKEYBOARD_KEYUSE_k 66 | # define KEY_L HIDKEYBOARD_KEYUSE_l 67 | # define KEY_M HIDKEYBOARD_KEYUSE_m 68 | # define KEY_N HIDKEYBOARD_KEYUSE_n 69 | # define KEY_O HIDKEYBOARD_KEYUSE_o 70 | # define KEY_P HIDKEYBOARD_KEYUSE_p 71 | # define KEY_Q HIDKEYBOARD_KEYUSE_q 72 | # define KEY_R HIDKEYBOARD_KEYUSE_r 73 | # define KEY_S HIDKEYBOARD_KEYUSE_s 74 | # define KEY_T HIDKEYBOARD_KEYUSE_t 75 | # define KEY_U HIDKEYBOARD_KEYUSE_u 76 | # define KEY_V HIDKEYBOARD_KEYUSE_v 77 | # define KEY_W HIDKEYBOARD_KEYUSE_w 78 | # define KEY_X HIDKEYBOARD_KEYUSE_x 79 | # define KEY_Y HIDKEYBOARD_KEYUSE_y 80 | # define KEY_Z HIDKEYBOARD_KEYUSE_z 81 | # define KEY_1 HIDKEYBOARD_KEYUSE_1 82 | # define KEY_2 HIDKEYBOARD_KEYUSE_2 83 | # define KEY_3 HIDKEYBOARD_KEYUSE_3 84 | # define KEY_4 HIDKEYBOARD_KEYUSE_4 85 | # define KEY_5 HIDKEYBOARD_KEYUSE_5 86 | # define KEY_6 HIDKEYBOARD_KEYUSE_6 87 | # define KEY_7 HIDKEYBOARD_KEYUSE_7 88 | # define KEY_8 HIDKEYBOARD_KEYUSE_8 89 | # define KEY_9 HIDKEYBOARD_KEYUSE_9 90 | # define KEY_0 HIDKEYBOARD_KEYUSE_0 91 | 92 | # define KEY_ENTER HIDKEYBOARD_KEYUSE_return 93 | 94 | # define KEY_SPACE HIDKEYBOARD_KEYUSE_spacebar 95 | 96 | # define KEY_F1 HIDKEYBOARD_KEYUSE_F1 97 | # define KEY_F2 HIDKEYBOARD_KEYUSE_F2 98 | # define KEY_F3 HIDKEYBOARD_KEYUSE_F3 99 | # define KEY_F4 HIDKEYBOARD_KEYUSE_F4 100 | # define KEY_F5 HIDKEYBOARD_KEYUSE_F5 101 | # define KEY_F6 HIDKEYBOARD_KEYUSE_F6 102 | # define KEY_F7 HIDKEYBOARD_KEYUSE_F7 103 | # define KEY_F8 HIDKEYBOARD_KEYUSE_F8 104 | # define KEY_F9 HIDKEYBOARD_KEYUSE_F9 105 | # define KEY_F10 HIDKEYBOARD_KEYUSE_F10 106 | # define KEY_F11 HIDKEYBOARD_KEYUSE_F11 107 | # define KEY_F12 HIDKEYBOARD_KEYUSE_F12 108 | 109 | # define KEY_ARROW_LEFT HIDKEYBOARD_KEYUSE_arrow_left 110 | #endif 111 | 112 | 113 | #ifndef USB_CFG_HID_NOMOUSE 114 | # define MOD_MOUSE_LEFT (_BV(mouse_report_buttonbit_left)) 115 | # define MOD_MOUSE_MIDDLE (_BV(mouse_report_buttonbit_middle)) 116 | # define MOD_MOUSE_RIGHT (_BV(mouse_report_buttonbit_right)) 117 | #endif 118 | 119 | 120 | class VUSBHIDKeyboardMouseDevice { 121 | public: 122 | VUSBHIDKeyboardMouseDevice () { 123 | uint8_t i; 124 | 125 | hidInit(); 126 | 127 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ 128 | 129 | do { 130 | i++; 131 | wdt_reset(); 132 | _delay_ms(1); 133 | wdt_reset(); 134 | } while (i); 135 | 136 | usbDeviceConnect(); 137 | usbInit(); 138 | sei(); 139 | } 140 | 141 | 142 | void update(uint8_t time_since_lastcall_in_four_ms_units) { 143 | hidPoll(&time_since_lastcall_in_four_ms_units); 144 | } 145 | void update() { 146 | update(0); 147 | } 148 | 149 | // Keyboard 150 | #ifndef USB_CFG_HID_NOKEYBOARD 151 | void sendKeyReport(keyboard_report_t *report) { 152 | while (keyboard_report_dirty) { 153 | update(); 154 | } 155 | 156 | memcpy(¤t_keyboard_report, report, sizeof(keyboard_report_t)); 157 | keyboard_report_dirty|=_BV(1); 158 | 159 | update(); 160 | } 161 | void sendKeyRelease() { 162 | keyboard_report_t report; 163 | keyboard_report_clear(&report); 164 | keyboard_report_setNoEvent(&report); 165 | sendKeyReport(&report); 166 | } 167 | void sendKeyStroke(byte keyStroke, byte modifiers) { 168 | keyboard_report_t report; 169 | keyboard_report_clear(&report); 170 | 171 | report.modifier =modifiers; 172 | report.keycode[0]=keyStroke; 173 | 174 | sendKeyReport(&report); 175 | sendKeyRelease(); 176 | } 177 | void sendKeyStroke(byte keyStroke) { 178 | sendKeyStroke(keyStroke, 0); 179 | } 180 | 181 | keyboard_report_t getKeyReportFromChar(byte symbol) { 182 | keyboard_report_t result; 183 | keyboard_report_clear(&result); 184 | asciitokeyreport(symbol, &result); 185 | return result; 186 | } 187 | void sendKey(byte symbol) { 188 | keyboard_report_t report = getKeyReportFromChar(symbol); 189 | sendKeyReport(&report); 190 | sendKeyRelease(); 191 | } 192 | 193 | /* for more compatibility with other keyboard libs */ 194 | void write(byte symbol) { 195 | sendKey(symbol); 196 | } 197 | #endif 198 | 199 | 200 | // Mouse 201 | #ifndef USB_CFG_HID_NOMOUSE 202 | void sendMouseReport(mouse_report_t *report) { 203 | while (mouse_report_dirty) { 204 | update(); 205 | } 206 | 207 | memcpy(¤t_mouse_report, report, sizeof(mouse_report_t)); 208 | mouse_report_dirty|=_BV(1); 209 | 210 | update(); 211 | } 212 | mouse_report_t getMouseReport(int8_t deltaX, int8_t deltaY, uint8_t buttons) { 213 | mouse_report_t result; 214 | mouse_report_clear(&result); 215 | result.buttons = buttons; 216 | result.displacement[mouse_report_displacement_X] = deltaX; 217 | result.displacement[mouse_report_displacement_Y] = deltaY; 218 | return result; 219 | } 220 | void sendMouseIdle() { 221 | mouse_report_t report; 222 | mouse_report_clear(&report); 223 | sendMouseReport(&report); 224 | } 225 | void sendMouseEvent(int8_t deltaX, int8_t deltaY, uint8_t buttons) { 226 | if ((deltaX!=0) || (deltaY!=0) || (buttons!=0)) { 227 | mouse_report_t report = getMouseReport(deltaX, deltaY, buttons); 228 | sendMouseReport(&report); 229 | } else sendMouseIdle(); 230 | } 231 | 232 | /* for more compatibility with other mouse libs */ 233 | void move(int8_t deltaX, int8_t deltaY) { 234 | sendMouseEvent(deltaX, deltaY, 0); 235 | } 236 | void click(uint8_t buttons) { 237 | sendMouseEvent(0, 0, buttons); 238 | } 239 | #endif 240 | }; 241 | 242 | #ifndef USB_CFG_HID_NOKEYBOARD 243 | # define UsbKeyboard VUSBHIDKeyboardMouse 244 | #endif 245 | 246 | #ifndef USB_CFG_HID_NOMOUSE 247 | # define UsbMouse VUSBHIDKeyboardMouse 248 | #endif 249 | 250 | VUSBHIDKeyboardMouseDevice VUSBHIDKeyboardMouse = VUSBHIDKeyboardMouseDevice(); 251 | 252 | #endif // __VUSBHIDKEYBOARDMOUSE_H_abe53fffc7524ee19e61f5f3305779a2 253 | -------------------------------------------------------------------------------- /gcc-code/lib/hidcore.c: -------------------------------------------------------------------------------- 1 | /* 2 | * hidcore.c 3 | * 4 | * This file implements a comfortable API for HID 5 | * keyboard and Mouse devices using V-USB on 6 | * an Atmel ATmega microcontroller. 7 | * The device will be HID BOOT v1.1 conform, so it also 8 | * will work in BIOS and in legacy operating systems. 9 | * 10 | * by Stephan Baerwolf (stephan@matrixstorm.com), Schwansee 2014 11 | * for http://matrixstorm.com/avr/tinyusbboard/ 12 | * (please contact me at least before commercial use) 13 | */ 14 | 15 | #define __HIDCORE_C_7b57b2239b7d418b8332be68649a9120 1 16 | 17 | #include "hidcore.h" 18 | 19 | #include 20 | 21 | #if (USB_CFG_DESCR_PROPS_CONFIGURATION > 0) 22 | 23 | 24 | #ifndef USB_CFG_HID_NOKEYBOARD 25 | /* implement the HID BOOT conform keyboard 26 | * from page 59 and page 69 of: 27 | * Device Class Definition for Human Interface Devices (HID) 28 | * Firmware Specification--6/27/01 29 | * Version 1.11 30 | * http://www.usb.org/developers/hidpage/HID1_11.pdf 31 | */ 32 | keyboard_report_t current_keyboard_report; 33 | uint8_t keyboard_report_dirty; 34 | static uint8_t keyboard_bootprotocol = 1; // 0 = boot protocol, 1 = report protocol 35 | static uint8_t keyboard_idleRate = 125; // repeat rate for keyboards in 4 ms units 36 | static uint8_t keyboard_idleTime = 0; 37 | 38 | volatile uchar current_LED_state; // keyboard LEDs 39 | 40 | PROGMEM const char usbHidKeyboardReportDescriptor[] = { 41 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 42 | 0x09, 0x06, // USAGE (Keyboard) 43 | 0xa1, 0x01, // COLLECTION (Application) 44 | 0x05, 0x07, // USAGE_PAGE (Keyboard)(Key Codes) 45 | 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)(224) 46 | 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)(231) 47 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 48 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 49 | 0x75, 0x01, // REPORT_SIZE (1) 50 | 0x95, 0x08, // REPORT_COUNT (8) 51 | 0x81, 0x02, // INPUT (Data,Var,Abs) ; Modifier byte 52 | 0x95, 0x01, // REPORT_COUNT (1) 53 | 0x75, 0x08, // REPORT_SIZE (8) 54 | 0x81, 0x01, // INPUT (Cnst,Var,Abs) ; Reserved byte 55 | 0x95, 0x05, // REPORT_COUNT (5) 56 | 0x75, 0x01, // REPORT_SIZE (1) 57 | 0x05, 0x08, // USAGE_PAGE (LEDs) 58 | 0x19, 0x01, // USAGE_MINIMUM (Num Lock) 59 | 0x29, 0x05, // USAGE_MAXIMUM (Kana) 60 | 0x91, 0x02, // OUTPUT (Data,Var,Abs) ; LED report 61 | 0x95, 0x01, // REPORT_COUNT (1) 62 | 0x75, 0x03, // REPORT_SIZE (3) 63 | 0x91, 0x01, // OUTPUT (Cnst,Var,Abs) ; LED report padding 64 | 0x95, 0x06, // REPORT_COUNT (6) 65 | 0x75, 0x08, // REPORT_SIZE (8) 66 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 67 | 0x25, 0x65, // LOGICAL_MAXIMUM (101) 68 | 0x05, 0x07, // USAGE_PAGE (Keyboard)(Key Codes) 69 | 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))(0) 70 | 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)(101) 71 | 0x81, 0x00, // INPUT (Data,Ary,Abs) 72 | 0xc0 // END_COLLECTION 73 | }; 74 | 75 | void __attribute__((weak)) EVENT_CHANGE_LED_state (void) { 76 | } 77 | 78 | void keyboard_report_fillkeys(keyboard_report_t *report, uint8_t usagecode) { 79 | memset((void*)&report->keycode, usagecode, sizeof(report->keycode)); 80 | } 81 | void keyboard_report_setNoEvent(keyboard_report_t *report) { 82 | keyboard_report_fillkeys(report, HIDKEYBOARD_BOOT_KEYUSAGE_NoEvent); 83 | } 84 | void keyboard_report_setErrorRollOver(keyboard_report_t *report) { 85 | keyboard_report_fillkeys(report, HIDKEYBOARD_BOOT_KEYUSAGE_ErrorRollOver); 86 | } 87 | 88 | void keyboard_report_clear(keyboard_report_t *report) { 89 | report->modifier = 0x00; 90 | report->reserved = 0x00; 91 | keyboard_report_setNoEvent(report); 92 | } 93 | #endif 94 | 95 | #ifndef USB_CFG_HID_NOMOUSE 96 | /* implement the HID BOOT conform mouse 97 | * from page 61 and page 71 of: 98 | * Device Class Definition for Human Interface Devices (HID) 99 | * Firmware Specification--6/27/01 100 | * Version 1.11 101 | * http://www.usb.org/developers/hidpage/HID1_11.pdf 102 | */ 103 | mouse_report_t current_mouse_report; 104 | uint8_t mouse_report_dirty; 105 | static uint8_t mouse_bootprotocol = 1; // 0 = boot protocol, 1 = report protocol 106 | static uint8_t mouse_idleRate = 0; // repeat rate for mouses in 4 ms units 107 | static uint8_t mouse_idleTime = 0; 108 | 109 | PROGMEM const char usbHidMouseReportDescriptor[] = { 110 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 111 | 0x09, 0x02, // USAGE (Mouse) 112 | 0xa1, 0x01, // COLLECTION (Application) 113 | 0x09, 0x01, // USAGE (Pointer) 114 | 0xa1, 0x00, // COLLECTION (Physical) 115 | 0x05, 0x09, // USAGE_PAGE (Buttons) 116 | 0x19, 0x01, // USAGE_MINIMUM (01) 117 | 0x29, 0x03, // USAGE_MAXIMUM (03) 118 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 119 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 120 | 0x95, 0x03, // REPORT_COUNT (3) 121 | 0x75, 0x01, // REPORT_SIZE (1) 122 | 0x81, 0x02, // INPUT (Data,Var,Abs) ; 3 button bits 123 | 0x95, 0x01, // REPORT_COUNT (1) 124 | 0x75, 0x05, // REPORT_SIZE (5) 125 | 0x81, 0x01, // INPUT (Cnst.) ; 5 bit padding 126 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 127 | 0x09, 0x30, // USAGE_X 128 | 0x09, 0x31, // USAGE_Y 129 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) 130 | 0x25, 0x7f, // LOGICAL_MAXIMUM (+127) 131 | 0x75, 0x08, // REPORT_SIZE (8) 132 | 0x95, 0x02, // REPORT_COUNT (2) 133 | 0x81, 0x06, // INPUT (Data,Var,Rel) ; 2 position bytes (X & Y) 134 | #ifdef USB_CFG_HID_WHEELMOUSE 135 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 136 | 0x09, 0x38, // USAGE (Wheel) 137 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) 138 | 0x25, 0x7f, // LOGICAL_MAXIMUM (127) 139 | 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical 140 | 0x45, 0x00, // PHYSICAL_MAXIMUM (0) 141 | 0x95, 0x01, // REPORT_COUNT (1) 142 | 0x75, 0x08, // REPORT_SIZE (8) 143 | 0x81, 0x06, // INPUT (Data,Var,Rel) 144 | #endif 145 | 0xc0, // END_COLLECTION 146 | 0xc0, // END_COLLECTION 147 | }; 148 | 149 | void mouse_report_clear(mouse_report_t *report) { 150 | memset((void*)report, 0x0, sizeof(mouse_report_t)); 151 | } 152 | #endif 153 | 154 | 155 | PROGMEM const char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 156 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ 157 | USBDESCR_CONFIG, /* descriptor type */ 158 | USB_CFG_DESCR_PROPS_CONFIGURATION, 0, 159 | /* total length of data returned (including inlined descriptors) */ 160 | #if (defined(USB_CFG_HID_NOKEYBOARD) || defined(USB_CFG_HID_NOMOUSE)) 161 | #if (defined(USB_CFG_HID_NOKEYBOARD) && defined(USB_CFG_HID_NOMOUSE)) 162 | 0, /* no interface */ 163 | #else 164 | 1, /* just a mouse or keyboard interface */ 165 | #endif 166 | #else 167 | 2, /* number of interfaces in this configuration */ 168 | #endif 169 | 1, /* index of this configuration */ 170 | 0, /* configuration name string index */ 171 | #if USB_CFG_IS_SELF_POWERED 172 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ 173 | #else 174 | (1 << 7), /* attributes */ 175 | #endif 176 | USB_CFG_MAX_BUS_POWER/2, /* max USB current in 2mA units */ 177 | 178 | #ifndef USB_CFG_HID_NOKEYBOARD 179 | /* interface descriptor nr. 1 (keyboard) follows inline: */ 180 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ 181 | USBDESCR_INTERFACE, /* descriptor type */ 182 | USBIFACE_INDEX_KEYBOARD, /* index of this interface */ 183 | 0, /* alternate setting for this interface */ 184 | 1, /* endpoints excl 0: the keyboard endpoint */ 185 | USBIFACE_CLASS_HID, 186 | USBIFACE_SUBCLASS_BOOT, 187 | USBIFACE_PROTOCOL_KEYBOARD, 188 | USBIFACE_NO_DESCRIPTOR, /* string index for interface */ 189 | /* HID descriptor */ 190 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ 191 | USBDESCR_HID, /* descriptor type: HID */ 192 | 0x01, 0x01, /* BCD representation of HID version */ 193 | 0x00, /* target country code */ 194 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ 195 | 0x22, /* descriptor type: report */ 196 | sizeof(usbHidKeyboardReportDescriptor), 0, /* total length of report descriptor */ 197 | /* the endpoint */ 198 | 7, /* sizeof(usbDescrEndpoint) */ 199 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ 200 | (char)0x81, /* IN endpoint number 1 */ 201 | 0x03, /* attrib: Interrupt endpoint */ 202 | 8, 0, /* maximum packet size */ 203 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ 204 | #endif 205 | 206 | #ifndef USB_CFG_HID_NOMOUSE 207 | /* interface descriptor nr. 2 (mouse) follows inline: */ 208 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ 209 | USBDESCR_INTERFACE, /* descriptor type */ 210 | USBIFACE_INDEX_MOUSE, /* index of this interface */ 211 | 0, /* alternate setting for this interface */ 212 | 1, /* endpoints excl 0: the keyboard endpoint */ 213 | USBIFACE_CLASS_HID, 214 | USBIFACE_SUBCLASS_BOOT, 215 | USBIFACE_PROTOCOL_MOUSE, 216 | USBIFACE_NO_DESCRIPTOR, /* string index for interface */ 217 | /* HID descriptor */ 218 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ 219 | USBDESCR_HID, /* descriptor type: HID */ 220 | 0x01, 0x01, /* BCD representation of HID version */ 221 | 0x00, /* target country code */ 222 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ 223 | 0x22, /* descriptor type: report */ 224 | sizeof(usbHidMouseReportDescriptor), 0, /* total length of report descriptor */ 225 | /* the endpoint */ 226 | 7, /* sizeof(usbDescrEndpoint) */ 227 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ 228 | #ifndef USB_CFG_HID_NOKEYBOARD 229 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ 230 | #else 231 | (char)0x81, /* IN endpoint number 1 */ 232 | #endif 233 | 0x03, /* attrib: Interrupt endpoint */ 234 | 8, 0, /* maximum packet size */ 235 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ 236 | #endif 237 | }; 238 | 239 | 240 | usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) { 241 | if (rq->wValue.bytes[1] == USBDESCR_HID) { 242 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 243 | /* ugly hardcoding data within usbDescriptorConfiguration */ 244 | if (rq->wIndex.word == USBIFACE_INDEX_MOUSE) { 245 | #endif 246 | #ifndef USB_CFG_HID_NOMOUSE 247 | # ifndef USB_CFG_HID_NOKEYBOARD 248 | usbMsgPtr=(usbMsgPtr_t)&usbDescriptorConfiguration[43]; /* point to the HID mouse */ 249 | # else 250 | usbMsgPtr=(usbMsgPtr_t)&usbDescriptorConfiguration[18]; /* point to the HID mouse */ 251 | # endif 252 | #endif 253 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 254 | } else { 255 | #endif 256 | #ifndef USB_CFG_HID_NOKEYBOARD 257 | usbMsgPtr=(usbMsgPtr_t)&usbDescriptorConfiguration[18]; /* point to the HID keyboard */ 258 | #endif 259 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 260 | } 261 | #endif 262 | } else if (rq->wValue.bytes[1] == USBDESCR_HID_REPORT) { 263 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 264 | if (rq->wIndex.word == USBIFACE_INDEX_MOUSE) { 265 | #endif 266 | #ifndef USB_CFG_HID_NOMOUSE 267 | usbMsgPtr=(usbMsgPtr_t)&usbHidMouseReportDescriptor[0]; 268 | return sizeof(usbHidMouseReportDescriptor); 269 | #endif 270 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 271 | } else { 272 | #endif 273 | #ifndef USB_CFG_HID_NOKEYBOARD 274 | usbMsgPtr=(usbMsgPtr_t)&usbHidKeyboardReportDescriptor[0]; 275 | return sizeof(usbHidKeyboardReportDescriptor); 276 | #endif 277 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 278 | } 279 | #endif 280 | } 281 | 282 | return 0; 283 | } 284 | 285 | 286 | void hidInit(void) { 287 | // keyboard 288 | #ifndef USB_CFG_HID_NOKEYBOARD 289 | keyboard_report_clear(¤t_keyboard_report); 290 | keyboard_report_dirty = 0; 291 | keyboard_bootprotocol = 1; 292 | 293 | keyboard_idleRate = 125; 294 | keyboard_idleTime = 0; 295 | 296 | // LEDs 297 | current_LED_state = 0xff; 298 | #endif 299 | 300 | // mouse 301 | #ifndef USB_CFG_HID_NOMOUSE 302 | mouse_report_clear(¤t_mouse_report); 303 | mouse_report_dirty = 0; 304 | mouse_bootprotocol = 1; 305 | 306 | mouse_idleRate = 0; 307 | mouse_idleTime = 0; 308 | #endif 309 | } 310 | 311 | 312 | void hidPoll(uint8_t *time_since_lastcall_in_four_ms_units) { 313 | uint8_t _time = (*time_since_lastcall_in_four_ms_units); 314 | 315 | usbPoll(); 316 | 317 | #ifndef USB_CFG_HID_NOKEYBOARD 318 | // is it time to file a report: keyboard 319 | if (keyboard_idleRate > 0) { 320 | keyboard_idleTime += _time; 321 | if (keyboard_idleTime >= keyboard_idleRate) { 322 | keyboard_idleTime = 0; 323 | keyboard_report_dirty |= 0x80; 324 | } 325 | } 326 | #endif 327 | 328 | #ifndef USB_CFG_HID_NOMOUSE 329 | // is it time to file a report: mouse 330 | if (mouse_idleRate > 0) { 331 | mouse_idleTime += _time; 332 | if (mouse_idleTime >= mouse_idleRate) { 333 | mouse_idleTime = 0; 334 | mouse_report_dirty |= 0x80; 335 | } 336 | } 337 | #endif 338 | 339 | #ifndef USB_CFG_HID_NOKEYBOARD 340 | if (keyboard_report_dirty) 341 | if (usbInterruptIsReady()) { 342 | usbSetInterrupt((void *)¤t_keyboard_report, sizeof(current_keyboard_report)); 343 | keyboard_report_dirty = 0; 344 | } 345 | #endif 346 | 347 | #ifndef USB_CFG_HID_NOMOUSE 348 | if (mouse_report_dirty) 349 | #ifndef USB_CFG_HID_NOKEYBOARD 350 | if (usbInterruptIsReady3()) { 351 | usbSetInterrupt3((void *)¤t_mouse_report, sizeof(current_mouse_report)); 352 | #else 353 | if (usbInterruptIsReady()) { 354 | usbSetInterrupt((void *)¤t_mouse_report, sizeof(current_mouse_report)); 355 | #endif 356 | mouse_report_dirty = 0; 357 | } 358 | #endif 359 | 360 | usbPoll(); 361 | } 362 | 363 | 364 | usbMsgLen_t __attribute__((weak)) hidFunctionSetup(uchar data[8]) { 365 | return 0; 366 | } 367 | 368 | USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]) { 369 | usbRequest_t *rq = (void *)data; 370 | 371 | /* from page 50 of: 372 | * Device Class Definition for Human Interface Devices (HID) 373 | * Firmware Specification--6/27/01 374 | * Version 1.11 375 | * http://www.usb.org/developers/hidpage/HID1_11.pdf 376 | */ 377 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { 378 | switch(rq->bRequest) { 379 | case USBRQ_HID_GET_REPORT: { 380 | // send "no keys pressed" and "no mouse event" if asked here 381 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 382 | usbWord_t index = rq->wIndex; 383 | #endif 384 | usbMsgPtr = (usbMsgPtr_t)&data[0]; // we only have this one 385 | memset((void*)usbMsgPtr, 0x00, sizeof(data)); 386 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 387 | if (index.word==USBIFACE_INDEX_MOUSE) { 388 | #endif 389 | #ifndef USB_CFG_HID_NOMOUSE 390 | // mouse 391 | return sizeof(current_mouse_report); 392 | #endif 393 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 394 | } else { 395 | #endif 396 | #ifndef USB_CFG_HID_NOKEYBOARD 397 | // keyboard 398 | return sizeof(current_keyboard_report); 399 | #endif 400 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 401 | } 402 | #endif 403 | } 404 | case USBRQ_HID_SET_REPORT: { 405 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 406 | if (rq->wIndex.word==USBIFACE_INDEX_MOUSE) { 407 | #endif 408 | #ifndef USB_CFG_HID_NOMOUSE 409 | // mouse 410 | return 0; 411 | #endif 412 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 413 | } else { 414 | #endif 415 | #ifndef USB_CFG_HID_NOKEYBOARD 416 | // keyboard 417 | // if wLength == 1, should be LED state 418 | return (rq->wLength.word == 1) ? USB_NO_MSG : 0; 419 | #endif 420 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 421 | } 422 | #endif 423 | } 424 | 425 | case USBRQ_HID_GET_IDLE: { 426 | // send idle rate to PC as required by spec 427 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 428 | usbMsgPtr = (rq->wIndex.word==USBIFACE_INDEX_MOUSE)?(usbMsgPtr_t)&mouse_idleRate:(usbMsgPtr_t)&keyboard_idleRate; 429 | #else 430 | #ifndef USB_CFG_HID_NOMOUSE 431 | usbMsgPtr = (usbMsgPtr_t)&mouse_idleRate; 432 | #endif 433 | #ifndef USB_CFG_HID_NOKEYBOARD 434 | usbMsgPtr = (usbMsgPtr_t)&keyboard_idleRate; 435 | #endif 436 | #endif 437 | return 1; 438 | } 439 | case USBRQ_HID_SET_IDLE: { 440 | // save idle rate as required by spec 441 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 442 | if (rq->wIndex.word==USBIFACE_INDEX_MOUSE) { 443 | #endif 444 | #ifndef USB_CFG_HID_NOMOUSE 445 | mouse_idleRate = rq->wValue.bytes[1]; 446 | #endif 447 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 448 | } else { 449 | #endif 450 | #ifndef USB_CFG_HID_NOKEYBOARD 451 | keyboard_idleRate = rq->wValue.bytes[1]; 452 | #endif 453 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 454 | } 455 | #endif 456 | return 0; 457 | } 458 | 459 | case USBRQ_HID_GET_PROTOCOL: { 460 | // send protocol to PC as required by spec 461 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 462 | usbMsgPtr = (rq->wIndex.word==USBIFACE_INDEX_MOUSE)?(usbMsgPtr_t)&mouse_bootprotocol:(usbMsgPtr_t)&keyboard_bootprotocol; 463 | #else 464 | #ifndef USB_CFG_HID_NOMOUSE 465 | usbMsgPtr = (usbMsgPtr_t)&mouse_bootprotocol; 466 | #endif 467 | #ifndef USB_CFG_HID_NOKEYBOARD 468 | usbMsgPtr = (usbMsgPtr_t)&keyboard_bootprotocol; 469 | #endif 470 | #endif 471 | return 1; 472 | } 473 | case USBRQ_HID_SET_PROTOCOL: { 474 | // save idle rate as required by spec 475 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 476 | if (rq->wIndex.word==USBIFACE_INDEX_MOUSE) { 477 | #endif 478 | #ifndef USB_CFG_HID_NOMOUSE 479 | mouse_bootprotocol = rq->wValue.bytes[0]; 480 | #endif 481 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 482 | } else { 483 | #endif 484 | #ifndef USB_CFG_HID_NOKEYBOARD 485 | keyboard_bootprotocol = rq->wValue.bytes[0]; 486 | #endif 487 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 488 | } 489 | #endif 490 | return 0; 491 | } 492 | } 493 | } 494 | 495 | return hidFunctionSetup(data); // by default don't return any data 496 | } 497 | 498 | #ifndef USB_CFG_HID_NOKEYBOARD 499 | USB_PUBLIC usbMsgLen_t usbFunctionWrite(uint8_t * data, uchar len) { 500 | if (data[0] != current_LED_state) { 501 | current_LED_state = data[0]; 502 | EVENT_CHANGE_LED_state(); //state change 503 | } 504 | return 1; // Data read, not expecting more 505 | } 506 | #endif 507 | 508 | 509 | #endif /* (USB_CFG_DESCR_PROPS_CONFIGURATION > 0) */ 510 | -------------------------------------------------------------------------------- /gcc-code/generic/usbconfig.h: -------------------------------------------------------------------------------- 1 | /* Name: usbconfig.h 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2005-04-01 5 | * Tabsize: 4 6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | * This Revision: $Id: usbconfig-prototype.h 767 2009-08-22 11:39:22Z cs $ 9 | * 10 | * Configurable PIN layout by Stephan Baerwolf (stephan@matrixstorm.com), Ilmenau 2014 11 | */ 12 | 13 | #ifndef __usbconfig_h_included__ 14 | #define __usbconfig_h_included__ 15 | 16 | #include "bootloaderconfig.h" 17 | 18 | #if (defined(ARDUINO) && (ARDUINO >= 100)) 19 | # define Pins_Arduino_h 20 | # include "pins_arduino.h" 21 | #endif 22 | 23 | /* 24 | General Description: 25 | This file is an example configuration (with inline documentation) for the USB 26 | driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is 27 | also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may 28 | wire the lines to any other port, as long as D+ is also wired to INT0 (or any 29 | other hardware interrupt, as long as it is the highest level interrupt, see 30 | section at the end of this file). 31 | + To create your own usbconfig.h file, copy this file to your project's 32 | + firmware source directory) and rename it to "usbconfig.h". 33 | + Then edit it accordingly. 34 | */ 35 | 36 | /* ---------------------------- Hardware Config ---------------------------- */ 37 | 38 | #ifndef VUSB_CFG_IOPORTNAME 39 | # define USB_CFG_IOPORTNAME D 40 | #else 41 | # define USB_CFG_IOPORTNAME VUSB_CFG_IOPORTNAME 42 | #endif 43 | /* This is the port where the USB bus is connected. When you configure it to 44 | * "B", the registers PORTB, PINB and DDRB will be used. 45 | */ 46 | #ifndef VUSB_CFG_DMINUS_BIT 47 | # define USB_CFG_DMINUS_BIT 4 48 | #else 49 | # define USB_CFG_DMINUS_BIT VUSB_CFG_DMINUS_BIT 50 | #endif 51 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. 52 | * This may be any bit in the port. 53 | */ 54 | #ifndef VUSB_CFG_DPLUS_BIT 55 | # define USB_CFG_DPLUS_BIT 2 56 | #else 57 | # define USB_CFG_DPLUS_BIT VUSB_CFG_DPLUS_BIT 58 | #endif 59 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. 60 | * This may be any bit in the port. Please note that D+ must also be connected 61 | * to interrupt pin INT0! [You can also use other interrupts, see section 62 | * "Optional MCU Description" below, or you can connect D- to the interrupt, as 63 | * it is required if you use the USB_COUNT_SOF feature. If you use D- for the 64 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame 65 | * markers every millisecond.] 66 | */ 67 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000) 68 | /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, 69 | * 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no 70 | * crystal, they tolerate +/- 1% deviation from the nominal frequency. All 71 | * other rates require a precision of 2000 ppm and thus a crystal! 72 | * Default if not specified: 12 MHz 73 | */ 74 | #ifndef VUSB_CFG_CHECK_CRC 75 | # define USB_CFG_CHECK_CRC 0 76 | #else 77 | # define USB_CFG_CHECK_CRC VUSB_CFG_CHECK_CRC 78 | #endif 79 | /* Define this to 1 if you want that the driver checks integrity of incoming 80 | * data packets (CRC checks). CRC checks cost quite a bit of code size and are 81 | * currently only available for 18 MHz crystal clock. You must choose 82 | * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. 83 | */ 84 | 85 | /* ----------------------- Optional Hardware Config ------------------------ */ 86 | 87 | #ifndef VUSB_CFG_HASNO_PULLUP_IOPORTNAME 88 | # ifndef VUSB_CFG_PULLUP_IOPORTNAME 89 | # define USB_CFG_PULLUP_IOPORTNAME D 90 | # else 91 | # define USB_CFG_PULLUP_IOPORTNAME VUSB_CFG_PULLUP_IOPORTNAME 92 | # endif 93 | #endif 94 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of 95 | * V+, you can connect and disconnect the device from firmware by calling 96 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). 97 | * This constant defines the port on which the pullup resistor is connected. 98 | */ 99 | #ifndef VUSB_CFG_HASNO_PULLUP_BIT 100 | # ifndef VUSB_CFG_PULLUP_BIT 101 | # define USB_CFG_PULLUP_BIT 5 102 | # else 103 | # define USB_CFG_PULLUP_BIT VUSB_CFG_PULLUP_BIT 104 | # endif 105 | #endif 106 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined 107 | * above) where the 1.5k pullup resistor is connected. See description 108 | * above for details. 109 | */ 110 | 111 | /* --------------------------- Functional Range ---------------------------- */ 112 | 113 | #define USB_CFG_HAVE_INTRIN_ENDPOINT 1 114 | /* Define this to 1 if you want to compile a version with two endpoints: The 115 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint 116 | * number). 117 | */ 118 | #if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 119 | # define USB_CFG_HAVE_INTRIN_ENDPOINT3 1 120 | #else 121 | # define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 122 | #endif 123 | /* Define this to 1 if you want to compile a version with three endpoints: The 124 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number 125 | * configured below) and a catch-all default interrupt-in endpoint as above. 126 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. 127 | */ 128 | #define USB_CFG_EP3_NUMBER 3 129 | /* If the so-called endpoint 3 is used, it can now be configured to any other 130 | * endpoint number (except 0) with this macro. Default if undefined is 3. 131 | */ 132 | /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ 133 | /* The above macro defines the startup condition for data toggling on the 134 | * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. 135 | * Since the token is toggled BEFORE sending any data, the first packet is 136 | * sent with the oposite value of this configuration! 137 | */ 138 | #define USB_CFG_IMPLEMENT_HALT 0 139 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature 140 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, 141 | * it is required by the standard. We have made it a config option because it 142 | * bloats the code considerably. 143 | */ 144 | #define USB_CFG_SUPPRESS_INTR_CODE 0 145 | /* Define this to 1 if you want to declare interrupt-in endpoints, but don't 146 | * want to send any data over them. If this macro is defined to 1, functions 147 | * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if 148 | * you need the interrupt-in endpoints in order to comply to an interface 149 | * (e.g. HID), but never want to send any data. This option saves a couple 150 | * of bytes in flash memory and the transmit buffers in RAM. 151 | */ 152 | #ifdef USB_CFG_INTR_POLL_INTERVAL 153 | # if (USB_CFG_INTR_POLL_INTERVAL < 10) 154 | # undef USB_CFG_INTR_POLL_INTERVAL 155 | # warning USB_CFG_INTR_POLL_INTERVAL too small, reseting to default 156 | # define USB_CFG_INTR_POLL_INTERVAL 25 157 | # endif 158 | #else 159 | # define USB_CFG_INTR_POLL_INTERVAL 25 160 | #endif 161 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll 162 | * interval. The value is in milliseconds and must not be less than 10 ms for 163 | * low speed devices. 164 | */ 165 | #ifndef USB_CFG_IS_SELF_POWERED 166 | # define USB_CFG_IS_SELF_POWERED 0 167 | #endif 168 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the 169 | * device is powered from the USB bus. 170 | */ 171 | #ifndef USB_CFG_MAX_BUS_POWER 172 | # define USB_CFG_MAX_BUS_POWER 100 173 | #endif 174 | /* Set this variable to the maximum USB bus power consumption of your device. 175 | * The value is in milliamperes. [It will be divided by two since USB 176 | * communicates power requirements in units of 2 mA.] 177 | */ 178 | #ifndef USB_CFG_HID_NOKEYBOARD 179 | # define USB_CFG_IMPLEMENT_FN_WRITE 1 180 | #else 181 | # define USB_CFG_IMPLEMENT_FN_WRITE 0 182 | #endif 183 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out 184 | * transfers. Set it to 0 if you don't need it and want to save a couple of 185 | * bytes. 186 | */ 187 | #define USB_CFG_IMPLEMENT_FN_READ 0 188 | /* Set this to 1 if you need to send control replies which are generated 189 | * "on the fly" when usbFunctionRead() is called. If you only want to send 190 | * data from a static buffer, set it to 0 and return the data from 191 | * usbFunctionSetup(). This saves a couple of bytes. 192 | */ 193 | #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 194 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. 195 | * You must implement the function usbFunctionWriteOut() which receives all 196 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number 197 | * can be found in 'usbRxToken'. 198 | */ 199 | #define USB_CFG_HAVE_FLOWCONTROL 0 200 | /* Define this to 1 if you want flowcontrol over USB data. See the definition 201 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in 202 | * usbdrv.h. 203 | */ 204 | #ifndef USB_CFG_DRIVER_FLASH_PAGE 205 | # define USB_CFG_DRIVER_FLASH_PAGE 0 206 | #endif 207 | /* If the device has more than 64 kBytes of flash, define this to the 64 k page 208 | * where the driver's constants (descriptors) are located. Or in other words: 209 | * Define this to 1 for boot loaders on the ATMega128. 210 | */ 211 | #ifndef USB_CFG_LONG_TRANSFERS 212 | # define USB_CFG_LONG_TRANSFERS 0 213 | #endif 214 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes 215 | * in a single control-in or control-out transfer. Note that the capability 216 | * for long transfers increases the driver size. 217 | */ 218 | /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ 219 | /* This macro is a hook if you want to do unconventional things. If it is 220 | * defined, it's inserted at the beginning of received message processing. 221 | * If you eat the received message and don't want default processing to 222 | * proceed, do a return after doing your things. One possible application 223 | * (besides debugging) is to flash a status LED on each packet. 224 | */ 225 | /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ 226 | /* This macro is a hook if you need to know when an USB RESET occurs. It has 227 | * one parameter which distinguishes between the start of RESET state and its 228 | * end. 229 | */ 230 | /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ 231 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was 232 | * received. 233 | */ 234 | #define USB_COUNT_SOF 0 235 | /* define this macro to 1 if you need the global variable "usbSofCount" which 236 | * counts SOF packets. This feature requires that the hardware interrupt is 237 | * connected to D- instead of D+. 238 | */ 239 | /* #ifdef __ASSEMBLER__ 240 | * macro myAssemblerMacro 241 | * in YL, TCNT0 242 | * sts timer0Snapshot, YL 243 | * endm 244 | * #endif 245 | * #define USB_SOF_HOOK myAssemblerMacro 246 | * This macro (if defined) is executed in the assembler module when a 247 | * Start Of Frame condition is detected. It is recommended to define it to 248 | * the name of an assembler macro which is defined here as well so that more 249 | * than one assembler instruction can be used. The macro may use the register 250 | * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages 251 | * immediately after an SOF pulse may be lost and must be retried by the host. 252 | * What can you do with this hook? Since the SOF signal occurs exactly every 253 | * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in 254 | * designs running on the internal RC oscillator. 255 | * Please note that Start Of Frame detection works only if D- is wired to the 256 | * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! 257 | */ 258 | #define USB_CFG_CHECK_DATA_TOGGLING 0 259 | /* define this macro to 1 if you want to filter out duplicate data packets 260 | * sent by the host. Duplicates occur only as a consequence of communication 261 | * errors, when the host does not receive an ACK. Please note that you need to 262 | * implement the filtering yourself in usbFunctionWriteOut() and 263 | * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable 264 | * for each control- and out-endpoint to check for duplicate packets. 265 | */ 266 | #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 267 | /* define this macro to 1 if you want the function usbMeasureFrameLength() 268 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. 269 | */ 270 | #ifndef USB_USE_FAST_CRC 271 | # define USB_USE_FAST_CRC 1 272 | #endif 273 | /* The assembler module has two implementations for the CRC algorithm. One is 274 | * faster, the other is smaller. This CRC routine is only used for transmitted 275 | * messages where timing is not critical. The faster routine needs 31 cycles 276 | * per byte while the smaller one needs 61 to 69 cycles. The faster routine 277 | * may be worth the 32 bytes bigger code size if you transmit lots of data and 278 | * run the AVR close to its limit. 279 | */ 280 | 281 | /* -------------------------- Device Description --------------------------- */ 282 | 283 | #ifndef USB_CFG_VENDOR_ID 284 | # define USB_CFG_VENDOR_ID 0x42, 0x42 285 | #endif 286 | /* USB vendor ID for the device, low byte first. If you have registered your 287 | * own Vendor ID, define it here. Otherwise you may use one of obdev's free 288 | * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! 289 | * *** IMPORTANT NOTE *** 290 | * This template uses obdev's shared VID/PID pair for Vendor Class devices 291 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand 292 | * the implications! 293 | */ 294 | 295 | #ifndef USB_CFG_DEVICE_ID 296 | # define USB_CFG_DEVICE_ID 0x31, 0xe1 297 | #endif 298 | /* This is the ID of the product, low byte first. It is interpreted in the 299 | * scope of the vendor ID. If you have registered your own VID with usb.org 300 | * or if you have licensed a PID from somebody else, define it here. Otherwise 301 | * you may use one of obdev's free shared VID/PID pairs. See the file 302 | * USB-IDs-for-free.txt for details! 303 | * *** IMPORTANT NOTE *** 304 | * This template uses obdev's shared VID/PID pair for Vendor Class devices 305 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand 306 | * the implications! 307 | */ 308 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 309 | /* Version number of the device: Minor number first, then major number. 310 | */ 311 | #ifndef USB_CFG_VENDOR_NAME 312 | # define USB_CFG_VENDOR_NAME 'h', 't', 't', 'p', ':', '/', '/', 'm', 'a', 't', 'r', 'i', 'x', 's', 't', 'o', 'r', 'm', '.','c','o', 'm', '/', 'a','v','r', '/', 't', 'i','n', 'y', 'u', 's', 'b', 'b', 'o', 'a', 'r', 'd', '/' 313 | #endif 314 | #ifndef USB_CFG_VENDOR_NAME_LEN 315 | # define USB_CFG_VENDOR_NAME_LEN 40 316 | #endif 317 | /* These two values define the vendor name returned by the USB device. The name 318 | * must be given as a list of characters under single quotes. The characters 319 | * are interpreted as Unicode (UTF-16) entities. 320 | * If you don't want a vendor name string, undefine these macros. 321 | * ALWAYS define a vendor name containing your Internet domain name if you use 322 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for 323 | * details. 324 | */ 325 | #ifndef USB_CFG_DEVICE_NAME 326 | # define USB_CFG_DEVICE_NAME 't', 'i', 'n', 'y', 'U', 'S', 'B', 'b', 'o', 'a', 'r', 'd' 327 | #endif 328 | #ifndef USB_CFG_DEVICE_NAME_LEN 329 | # define USB_CFG_DEVICE_NAME_LEN 12 330 | #endif 331 | /* Same as above for the device name. If you don't want a device name, undefine 332 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if 333 | * you use a shared VID/PID. 334 | */ 335 | #ifndef USB_CFG_SERIAL_NUMBER 336 | # define USB_CFG_SERIAL_NUMBER 'v', '0', '.', '4', '-', '2', '0', '1', '9', '1', '2', '0', '8', '0', '0', '3', '0', 'Z' 337 | #endif 338 | #ifndef USB_CFG_SERIAL_NUMBER_LEN 339 | # define USB_CFG_SERIAL_NUMBER_LEN 18 340 | #endif 341 | /* Same as above for the serial number. If you don't want a serial number, 342 | * undefine the macros. 343 | * It may be useful to provide the serial number through other means than at 344 | * compile time. See the section about descriptor properties below for how 345 | * to fine tune control over USB descriptors such as the string descriptor 346 | * for the serial number. 347 | */ 348 | #define USB_CFG_DEVICE_CLASS 0 /* set to 0 if deferred to interface */ 349 | #define USB_CFG_DEVICE_SUBCLASS 0 350 | /* See USB specification if you want to conform to an existing device class. 351 | * Class 0xff is "vendor specific". 352 | */ 353 | #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ 354 | #define USB_CFG_INTERFACE_SUBCLASS 0 355 | #define USB_CFG_INTERFACE_PROTOCOL 0 356 | /* See USB specification if you want to conform to an existing device class or 357 | * protocol. The following classes must be set at interface level: 358 | * HID class is 3, no subclass and protocol required (but may be useful!) 359 | * CDC class is 2, use subclass 2 and protocol 1 for ACM 360 | */ 361 | /* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ 362 | /* Define this to the length of the HID report descriptor, if you implement 363 | * an HID device. Otherwise don't define it or define it to 0. 364 | * If you use this define, you must add a PROGMEM character array named 365 | * "usbHidReportDescriptor" to your code which contains the report descriptor. 366 | * Don't forget to keep the array and this define in sync! 367 | */ 368 | 369 | /* #define USB_PUBLIC static */ 370 | /* Use the define above if you #include usbdrv.c instead of linking against it. 371 | * This technique saves a couple of bytes in flash memory. 372 | */ 373 | 374 | /* ------------------- Fine Control over USB Descriptors ------------------- */ 375 | /* If you don't want to use the driver's default USB descriptors, you can 376 | * provide our own. These can be provided as (1) fixed length static data in 377 | * flash memory, (2) fixed length static data in RAM or (3) dynamically at 378 | * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more 379 | * information about this function. 380 | * Descriptor handling is configured through the descriptor's properties. If 381 | * no properties are defined or if they are 0, the default descriptor is used. 382 | * Possible properties are: 383 | * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched 384 | * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is 385 | * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if 386 | * you want RAM pointers. 387 | * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found 388 | * in static memory is in RAM, not in flash memory. 389 | * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), 390 | * the driver must know the descriptor's length. The descriptor itself is 391 | * found at the address of a well known identifier (see below). 392 | * List of static descriptor names (must be declared PROGMEM if in flash): 393 | * char usbDescriptorDevice[]; 394 | * char usbDescriptorConfiguration[]; 395 | * char usbDescriptorHidReport[]; 396 | * char usbDescriptorString0[]; 397 | * int usbDescriptorStringVendor[]; 398 | * int usbDescriptorStringDevice[]; 399 | * int usbDescriptorStringSerialNumber[]; 400 | * Other descriptors can't be provided statically, they must be provided 401 | * dynamically at runtime. 402 | * 403 | * Descriptor properties are or-ed or added together, e.g.: 404 | * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) 405 | * 406 | * The following descriptors are defined: 407 | * USB_CFG_DESCR_PROPS_DEVICE 408 | * USB_CFG_DESCR_PROPS_CONFIGURATION 409 | * USB_CFG_DESCR_PROPS_STRINGS 410 | * USB_CFG_DESCR_PROPS_STRING_0 411 | * USB_CFG_DESCR_PROPS_STRING_VENDOR 412 | * USB_CFG_DESCR_PROPS_STRING_PRODUCT 413 | * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 414 | * USB_CFG_DESCR_PROPS_HID 415 | * USB_CFG_DESCR_PROPS_HID_REPORT 416 | * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) 417 | * 418 | * Note about string descriptors: String descriptors are not just strings, they 419 | * are Unicode strings prefixed with a 2 byte header. Example: 420 | * int serialNumberDescriptor[] = { 421 | * USB_STRING_DESCRIPTOR_HEADER(6), 422 | * 'S', 'e', 'r', 'i', 'a', 'l' 423 | * }; 424 | */ 425 | 426 | /* look into descriptor.h to fill in correct sizes */ 427 | #define USB_CFG_DESCR_PROPS_DEVICE 0 428 | 429 | #if ((defined(USB_CFG_HID_NOMOUSE)) && (defined(USB_CFG_HID_NOKEYBOARD))) 430 | # error With USB_CFG_HID_NOMOUSE and USB_CFG_HID_NOKEYBOARD there is not much of a device! 431 | #else 432 | # if ((!defined(USB_CFG_HID_NOMOUSE)) && (!defined(USB_CFG_HID_NOKEYBOARD))) 433 | # define USB_CFG_DESCR_PROPS_CONFIGURATION (9+2*(9+9+7)) 434 | # else 435 | # if (!defined(USB_CFG_HID_NOMOUSE)) 436 | # define USB_CFG_DESCR_PROPS_CONFIGURATION (9+1*(9+9+7)) 437 | # endif 438 | # if (!defined(USB_CFG_HID_NOKEYBOARD)) 439 | # define USB_CFG_DESCR_PROPS_CONFIGURATION (9+1*(9+9+7)) 440 | # endif 441 | # endif 442 | #endif 443 | 444 | #define USB_CFG_DESCR_PROPS_STRINGS 0 445 | #define USB_CFG_DESCR_PROPS_STRING_0 0 446 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 447 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 448 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 449 | 450 | #define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC 451 | #define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC 452 | 453 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0xffff /* for usbFunctionDescriptor */ 454 | 455 | 456 | #define usbMsgPtr_t unsigned short 457 | /* If usbMsgPtr_t is not defined, it defaults to 'uchar *'. We define it to 458 | * a scalar type here because gcc generates slightly shorter code for scalar 459 | * arithmetics than for pointer arithmetics. Remove this define for backward 460 | * type compatibility or define it to an 8 bit type if you use data in RAM only 461 | * and all RAM is below 256 bytes (tiny memory model in IAR CC). 462 | */ 463 | 464 | /* ----------------------- Optional MCU Description ------------------------ */ 465 | 466 | /* The following configurations have working defaults in usbdrv.h. You 467 | * usually don't need to set them explicitly. Only if you want to run 468 | * the driver on a device which is not yet supported or with a compiler 469 | * which is not fully supported (such as IAR C) or if you use a differnt 470 | * interrupt than INT0, you may have to define some of these. 471 | */ 472 | /* #define USB_INTR_CFG MCUCR */ 473 | /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ 474 | /* #define USB_INTR_CFG_CLR 0 */ 475 | /* #define USB_INTR_ENABLE GIMSK */ 476 | /* #define USB_INTR_ENABLE_BIT INT0 */ 477 | /* #define USB_INTR_PENDING GIFR */ 478 | /* #define USB_INTR_PENDING_BIT INTF0 */ 479 | /* #define USB_INTR_VECTOR SIG_INTERRUPT0 */ 480 | 481 | #ifndef VUSB_INTR_VECTOR 482 | # define USB_INTR_VECTOR INT0_vect 483 | #else 484 | # define USB_INTR_VECTOR VUSB_INTR_VECTOR 485 | #endif 486 | 487 | 488 | #endif /* __usbconfig_h_included__ */ 489 | --------------------------------------------------------------------------------