├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── License.txt ├── ProTrinketMouse.cpp ├── ProTrinketMouse.h ├── ProTrinketMouseC.c ├── ProTrinketMouseC.h ├── README.md ├── cmdline_defs.h ├── examples ├── ProTrinketMouseAccel │ ├── ProTrinketMouseAccel.ino │ └── ProTrinketMouseAccelFritzing.png ├── ProTrinketMouseJoystick │ ├── ProTrinketMouse Joystick Fritzing Sketch.png │ └── ProTrinketMouseJoystick.ino └── ProTrinketMouseRandom │ └── ProTrinketMouseRandom.ino ├── library.properties ├── readme.txt ├── usbconfig.h ├── usbdrv ├── Changelog.txt ├── CommercialLicense.txt ├── License.txt ├── Readme.txt ├── USB-ID-FAQ.txt ├── USB-IDs-for-free.txt ├── asmcommon.inc ├── oddebug.c ├── oddebug.h ├── usbdrv.c ├── usbdrv.h ├── usbdrvasm.S ├── usbdrvasm.asm ├── usbdrvasm12.inc ├── usbdrvasm16.inc └── usbportability.h ├── usbdrv_includer.c └── usbdrvasm_includer.S /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py protrinket_3v protrinket_5v 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | -------------------------------------------------------------------------------- /ProTrinketMouse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is the part of the ProTrinketMouse code that is exposed to the user 3 | See the header file for more comments on the functions 4 | 5 | Copyright (c) 2015 Adafruit Industries 6 | All rights reserved. 7 | 8 | ProTrinketMouse is free software: you can redistribute it and/or modify it under 9 | the terms of the GNU Lesser General Public License as published by the Free 10 | Software Foundation, either version 3 of the License, or (at your option) any 11 | later version. 12 | 13 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with ProTrinketMouse. If not, see 20 | . 21 | */ 22 | 23 | #include "ProTrinketMouse.h" 24 | #include "ProTrinketMouseC.h" 25 | #include "cmdline_defs.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | // create an instance that the user can use 32 | Trinket_Mouse TrinketMouse; 33 | 34 | // empty constructor 35 | Trinket_Mouse::Trinket_Mouse() { 36 | // nothing to do 37 | } 38 | 39 | // starts the USB driver, causes re-enumeration 40 | void Trinket_Mouse::begin() { usbBegin(); } 41 | 42 | // makes a mouse movement, must be called at least once every 10ms, even if no 43 | // movement 44 | 45 | void Trinket_Mouse::move(signed char x, signed char y, signed char wheel, 46 | uint8_t buttonMask) { 47 | signed char *signed_ptr = 48 | (signed char *)report_buffer; // this converts signed to unsigned 49 | 50 | // format the report structure 51 | signed_ptr[1] = x; 52 | signed_ptr[2] = y; 53 | signed_ptr[3] = wheel; 54 | report_buffer[0] = buttonMask; 55 | 56 | usbReportSend(); 57 | } 58 | 59 | // checks if USB is connected, 0 if not connected 60 | char Trinket_Mouse::isConnected() { return usb_hasCommed; } 61 | -------------------------------------------------------------------------------- /ProTrinketMouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | This is the part of the ProTrinketMouse code that is exposed to the user 3 | 4 | Copyright (c) 2015 Adafruit Industries 5 | All rights reserved. 6 | 7 | ProTrinketMouse is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) any 10 | later version. 11 | 12 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 15 | details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with ProTrinketMouse. If not, see 19 | . 20 | */ 21 | 22 | #ifndef _PROTRINKETMOUSE_H_ 23 | #define _PROTRINKETMOUSE_H_ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | // use these masks with the "move" function 36 | #define MOUSEBTN_LEFT_MASK 0x01 37 | #define MOUSEBTN_RIGHT_MASK 0x02 38 | #define MOUSEBTN_MIDDLE_MASK 0x04 39 | 40 | class Trinket_Mouse { 41 | private: 42 | public: 43 | Trinket_Mouse(); // empty constructor, ignore me 44 | void begin(); // starts the USB driver, causes re-enumeration 45 | void move(signed char x, signed char y, signed char wheel, 46 | uint8_t buttonMask); // makes a mouse movement, must be called at 47 | // least once every 10ms, even if no movement 48 | char isConnected(); // checks if USB is connected, 0 if not connected 49 | }; 50 | 51 | // an instance that the user can use 52 | extern Trinket_Mouse TrinketMouse; 53 | 54 | #endif -------------------------------------------------------------------------------- /ProTrinketMouseC.c: -------------------------------------------------------------------------------- 1 | /* 2 | This is the part of the ProTrinketMouse code that is usually written in C 3 | Placing it here does not mix it with the object oriented C++ code 4 | 5 | Copyright (c) 2015 Adafruit Industries 6 | All rights reserved. 7 | 8 | ProTrinketMouse is free software: you can redistribute it and/or modify it under 9 | the terms of the GNU Lesser General Public License as published by the Free 10 | Software Foundation, either version 3 of the License, or (at your option) any 11 | later version. 12 | 13 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with ProTrinketMouse. If not, see 20 | . 21 | */ 22 | 23 | #include "ProTrinketMouseC.h" 24 | #include "cmdline_defs.h" 25 | #include "usbconfig.h" 26 | #include "usbdrv/usbdrv.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | uint8_t report_buffer[4]; 34 | char usb_hasCommed = 0; 35 | uint8_t idle_rate = 500 / 4; // see HID1_11.pdf sect 7.2.4 36 | uint8_t protocol_version = 0; // see HID1_11.pdf sect 7.2.6 37 | 38 | void usbBegin() { 39 | cli(); 40 | 41 | // fake a disconnect to force the computer to re-enumerate 42 | PORTD &= ~(_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DPLUS_BIT)); 43 | 44 | usbDeviceDisconnect(); 45 | _delay_ms(250); 46 | usbDeviceConnect(); 47 | 48 | // start the USB driver 49 | usbInit(); 50 | sei(); 51 | } 52 | 53 | void usbPollWrapper() { usbPoll(); } 54 | 55 | void usbReportSend() { 56 | // perform usb background tasks until the report can be sent, then send it 57 | while (1) { 58 | usbPoll(); // this needs to be called at least once every 10 ms 59 | if (usbInterruptIsReady()) { 60 | usbSetInterrupt((uint8_t *)report_buffer, 4); // send 61 | break; 62 | 63 | // see http://vusb.wikidot.com/driver-api 64 | } 65 | } 66 | } 67 | 68 | // USB HID report descriptor for boot protocol keyboard 69 | // see HID1_11.pdf appendix B section 1 70 | // USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH is defined in usbconfig (it's supposed 71 | // to be 50) 72 | const PROGMEM char 73 | usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { 74 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 75 | 0x09, 0x02, // USAGE (Mouse) 76 | 0xa1, 0x01, // COLLECTION (Application) 77 | 0x09, 0x01, // USAGE (Pointer) 78 | 0xA1, 0x00, // COLLECTION (Physical) 79 | 0x05, 0x09, // USAGE_PAGE (Button) 80 | 0x19, 0x01, // USAGE_MINIMUM 81 | 0x29, 0x03, // USAGE_MAXIMUM 82 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 83 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 84 | 0x95, 0x03, // REPORT_COUNT (3) 85 | 0x75, 0x01, // REPORT_SIZE (1) 86 | 0x81, 0x02, // INPUT (Data,Var,Abs) 87 | 0x95, 0x01, // REPORT_COUNT (1) 88 | 0x75, 0x05, // REPORT_SIZE (5) 89 | 0x81, 0x03, // INPUT (Const,Var,Abs) 90 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 91 | 0x09, 0x30, // USAGE (X) 92 | 0x09, 0x31, // USAGE (Y) 93 | 0x09, 0x38, // USAGE (Wheel) 94 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) 95 | 0x25, 0x7F, // LOGICAL_MAXIMUM (127) 96 | 0x75, 0x08, // REPORT_SIZE (8) 97 | 0x95, 0x03, // REPORT_COUNT (3) 98 | 0x81, 0x06, // INPUT (Data,Var,Rel) 99 | 0xC0, // END_COLLECTION 100 | 0xC0, // END COLLECTION 101 | }; 102 | 103 | // see http://vusb.wikidot.com/driver-api 104 | // constants are found in usbdrv.h 105 | usbMsgLen_t usbFunctionSetup(uint8_t data[8]) { 106 | usb_hasCommed = 1; 107 | 108 | // see HID1_11.pdf sect 7.2 and http://vusb.wikidot.com/driver-api 109 | usbRequest_t *rq = (void *)data; 110 | 111 | if ((rq->bmRequestType & USBRQ_TYPE_MASK) != USBRQ_TYPE_CLASS) 112 | return 0; // ignore request if it's not a class specific request 113 | 114 | // see HID1_11.pdf sect 7.2 115 | switch (rq->bRequest) { 116 | case USBRQ_HID_GET_IDLE: 117 | usbMsgPtr = &idle_rate; // send data starting from this byte 118 | return 1; // send 1 byte 119 | case USBRQ_HID_SET_IDLE: 120 | idle_rate = rq->wValue.bytes[1]; // read in idle rate 121 | return 0; // send nothing 122 | case USBRQ_HID_GET_PROTOCOL: 123 | usbMsgPtr = &protocol_version; // send data starting from this byte 124 | return 1; // send 1 byte 125 | case USBRQ_HID_SET_PROTOCOL: 126 | protocol_version = rq->wValue.bytes[1]; 127 | return 0; // send nothing 128 | case USBRQ_HID_GET_REPORT: 129 | usbMsgPtr = (uint8_t *)report_buffer; // send the report data 130 | return 3; 131 | case USBRQ_HID_SET_REPORT: 132 | return 0; // send nothing, mouses don't do this 133 | default: // do not understand data, ignore 134 | return 0; // send nothing 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /ProTrinketMouseC.h: -------------------------------------------------------------------------------- 1 | /* 2 | Header file for ProTrinketMouseC.c 3 | 4 | Copyright (c) 2015 Adafruit Industries 5 | All rights reserved. 6 | 7 | ProTrinketMouse is free software: you can redistribute it and/or modify it under 8 | the terms of the GNU Lesser General Public License as published by the Free 9 | Software Foundation, either version 3 of the License, or (at your option) any 10 | later version. 11 | 12 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT 13 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 15 | details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with ProTrinketMouse. If not, see 19 | . 20 | */ 21 | 22 | #ifndef _PROTRINKETMOUSEC_H_ 23 | #define _PROTRINKETMOUSEC_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #include 30 | 31 | extern char usb_hasCommed; 32 | extern uint8_t report_buffer[4]; 33 | 34 | void usbBegin(); 35 | void usbPollWrapper(); 36 | void usbReportSend(); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit Pro Trinket USB Mouse Library [![Build Status](https://github.com/adafruit/Pro_Trinket_USB_Mouse_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Pro_Trinket_USB_Mouse_Library/actions) 2 | 3 | ProTrinketMouse is Adafruit's Pro Trinket USB HID Arduino Library 4 | 5 | ProTrinketMouse allows the user to implement a simple USB Mouse using an Adafruit Pro Trinket (ATmega 328P based) 6 | 7 | Please see ProTrinketMouse.h for usage documentation, examples are also included 8 | 9 | ProTrinketMouse uses V-USB (http://www.obdev.at/products/vusb/) to implement USB using a bitbang technique. See the folder "usbdrv" for V-USB files. 10 | 11 | Copyright (c) 2015 Adafruit Industries 12 | All rights reserved. 13 | 14 | ProTrinketMouse is free software: you can redistribute it and/or modify 15 | it under the terms of the GNU Lesser General Public License as 16 | published by the Free Software Foundation, either version 3 of 17 | the License, or (at your option) any later version. 18 | 19 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with ProTrinketMouse. If not, see 23 | . 24 | 25 | Version History 26 | 27 | Version 1.0 Works with Pro Trinket 5V at 16 MHz and Pro Trinket 3V at 12 MHz Mike Barela 28 | -------------------------------------------------------------------------------- /cmdline_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file provides the compiler any definitions that would usually go in the 3 | command line options, since Arduino IDE does not allow such additions 4 | 5 | Copyright (c) 2015 Adafruit Industries 6 | All rights reserved. 7 | 8 | ProTrinketKeyboard is free software: you can redistribute it and/or modify it 9 | under the terms of the GNU Lesser General Public License as published by the 10 | Free Software Foundation, either version 3 of the License, or (at your option) 11 | any later version. 12 | 13 | ProTrinketKeyboard is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 16 | more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with ProTrinketKeyboard. If not, see 20 | . 21 | 22 | */ 23 | 24 | #ifndef _CMDLINE_DEFS_H_ 25 | #define _CMDLINE_DEFS_H_ 26 | 27 | /* include */ 28 | 29 | #endif -------------------------------------------------------------------------------- /examples/ProTrinketMouseAccel/ProTrinketMouseAccel.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file ProTrinketMouseAccel.ino 4 | @author Mike Barela for Adafruit Industries 5 | @license BSD (see license.txt) 6 | 7 | This is an example of using the Adafruit Pro Trinket with the Adafruit MMA8451 8 | Accelerometer breakout board to make a mouse using motion gestures 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | @section HISTORY 15 | 16 | v1.0 - First release 1/25/2015 Mike Barela 17 | */ 18 | /**************************************************************************/ 19 | 20 | #include // I2C Library 21 | #include // Accelerometer library 22 | #include // Adafruit sensor library 23 | #include // Pro Trinket V-USB mouse emulator 24 | #define DEBUG 0 // Set to 1 for serial console debugging, 0 otherwise 25 | 26 | const uint8_t LEFTBUTTON = 8; // Left Mouse Button on this Pro Trinket Pin 27 | const uint8_t RIGHTBUTTON = 9; // Right Mouse Button on Pro Trinket 28 | 29 | Adafruit_MMA8451 mma = Adafruit_MMA8451(); 30 | 31 | //Change these values if accelerometer reading are different: 32 | //How far the accerometer is tilted before 33 | //starting to move the mouse: 34 | const int MovementThreshold = 18; 35 | 36 | //The average zero acceleration values read 37 | //from the accelerometer for each axis: 38 | const int ZeroXValue = 0; 39 | const int ZeroYValue = 0; 40 | //const int ZeroZValue = 0; 41 | 42 | //The maximum (positive) acceleration values read 43 | //from the accelerometer for each axis: 44 | const int MaxXValue = 4096; 45 | const int MaxYValue = 4096; 46 | //const int MaxZValue = 4096; 47 | 48 | //The minimum (negative) acceleration values read 49 | //from the accelerometer for each axis: 50 | const int MinXValue = -4096; 51 | const int MinYValue = -4096; 52 | //const int MinZValue = -4096; 53 | 54 | //The sign of the mouse movement relative to the acceleration. 55 | //If your cursor is going in the opposite direction you think it 56 | //should go, change the sign for the appropriate axis. 57 | const int XSign = 1; 58 | const int YSign = 1; 59 | //const int ZSign = 1; 60 | 61 | //The maximum speed in each axis (x and y) 62 | //that the cursor should move. Set this to a higher or lower 63 | //number if the cursor does not move fast enough or is too fast. 64 | const int MaxMouseMovement = 50; 65 | 66 | //This reduces the 'twitchiness' of the cursor by calling 67 | //a delay function at the end of the main loop. 68 | //There are better way to do this without delaying the whole 69 | //microcontroller, but that is left for another tutorial or project. 70 | const int MouseDelay = 12; 71 | 72 | void setup(void) { 73 | #if DEBUG 74 | Serial.begin(9600); 75 | Serial.println("Pro Trinket Accelerometer Mouse"); 76 | #endif 77 | if (! mma.begin()) { // If the accelerometer cannot be found, flash LED 78 | pinMode(13, OUTPUT); 79 | while (1) { // Flash the Pin 13 LED quickly to indicate an error 80 | digitalWrite(13, HIGH); 81 | delay(350); 82 | digitalWrite(13, LOW); 83 | delay(350); 84 | } 85 | } 86 | mma.setRange(MMA8451_RANGE_2_G); // 2G Mode is best for hand gestures 87 | mma.read(); // get an initial read 88 | 89 | TrinketMouse.begin(); // Initialize mouse library 90 | pinMode(LEFTBUTTON, INPUT_PULLUP); // Left and right mouse button pins initialized 91 | pinMode(RIGHTBUTTON, INPUT_PULLUP); // with internal pullup resistors (bring Low with button) 92 | } 93 | 94 | void loop() { 95 | 96 | mma.read(); // // Read the 'raw' data in 14-bit counts 97 | #if DEBUG 98 | Serial.print("X:\t"); Serial.print(mma.x); 99 | Serial.print("\tY:\t"); Serial.print(mma.y); 100 | Serial.print("\tZ:\t"); Serial.println(mma.z); 101 | #endif 102 | 103 | processAccelerometer(mma.x,mma.y, mma.z); // Work with the read data 104 | 105 | delay(MouseDelay); // wait until next reading - was 500 in Adafruit example 106 | } 107 | 108 | //Function to process the acclerometer data 109 | //and send mouse movement information via USB 110 | void processAccelerometer(int16_t XReading, int16_t YReading, int16_t ZReading) 111 | { 112 | //Initialize values for the mouse cursor movement. 113 | int16_t MouseXMovement = 0; 114 | int16_t MouseYMovement = 0; 115 | 116 | //Calculate mouse movement 117 | //If the analog X reading is ouside of the zero threshold... 118 | if( MovementThreshold < abs( XReading - ZeroXValue ) ) 119 | { 120 | //...calculate X mouse movement based on how far the X acceleration is from its zero value. 121 | MouseXMovement = XSign * ( ( ( (float)( 2 * MaxMouseMovement ) / ( MaxXValue - MinXValue ) ) * ( XReading - MinXValue ) ) - MaxMouseMovement ); 122 | //it could use some improvement, like making it trigonometric. 123 | } 124 | else 125 | { 126 | //Within the zero threshold, the cursor does not move in the X. 127 | MouseXMovement = 0; 128 | } 129 | 130 | //If the analog Y reading is ouside of the zero threshold... 131 | if( MovementThreshold < abs( YReading - ZeroYValue ) ) 132 | { 133 | //...calculate Y mouse movement based on how far the Y acceleration is from its zero value. 134 | MouseYMovement = YSign * ( ( ( (float)( 2 * MaxMouseMovement ) / ( MaxYValue - MinYValue ) ) * ( YReading - MinYValue ) ) - MaxMouseMovement ); 135 | //it could use some improvement, like making it trigonometric. 136 | } 137 | else 138 | { 139 | //Within the zero threshold, the cursor does not move in the Y. 140 | MouseYMovement = 0; 141 | } 142 | 143 | if(digitalRead(LEFTBUTTON) == LOW) { // If left button pressed 144 | #if DEBUG 145 | Serial.println("Left Mouse Button"); 146 | #endif 147 | TrinketMouse.move(0,0,0,MOUSEBTN_LEFT_MASK); // tell PC 148 | } 149 | else if (digitalRead(RIGHTBUTTON) == LOW) { // If right button pressed 150 | #if DEBUG 151 | Serial.println("Right Mouse Button"); 152 | #endif 153 | TrinketMouse.move(0,0,0,MOUSEBTN_RIGHT_MASK); // tell PC 154 | } 155 | else { 156 | TrinketMouse.move(MouseXMovement, MouseYMovement, 0, 0); // otherwise just move mouse 157 | } 158 | 159 | } 160 | 161 | -------------------------------------------------------------------------------- /examples/ProTrinketMouseAccel/ProTrinketMouseAccelFritzing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Pro_Trinket_USB_Mouse/c9650b0fb94c39c8901d3acffed462df4a089e02/examples/ProTrinketMouseAccel/ProTrinketMouseAccelFritzing.png -------------------------------------------------------------------------------- /examples/ProTrinketMouseJoystick/ProTrinketMouse Joystick Fritzing Sketch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Pro_Trinket_USB_Mouse/c9650b0fb94c39c8901d3acffed462df4a089e02/examples/ProTrinketMouseJoystick/ProTrinketMouse Joystick Fritzing Sketch.png -------------------------------------------------------------------------------- /examples/ProTrinketMouseJoystick/ProTrinketMouseJoystick.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Joystick Mouse Control 3 | 4 | Controls a PC mouse from a joystick on an Adafruit Pro Trinket. 5 | Uses the joystick pushbutton to click the left mouse button 6 | 7 | Hardware: 8 | * 2-axis joystick connected to pins A0 and A1 with pushbutton on D10 9 | * Pushbutton enable/disable the mouse entirely on D9 (optional) 10 | 11 | The mouse movement is always relative. 12 | 13 | The sketch assumes that the joystick resting values are around the 14 | middle of the range, but that they vary within a threshold. 15 | 16 | WARNING: When you use the new mouse, the Arduino takes 17 | over your mouse! Make sure you have control before you use the project. 18 | This sketch includes a pushbutton to toggle the mouse on and off. 19 | 20 | Based on software on arduino.cc by Tom Igoe placed in the public domain 21 | 22 | Version 1.0 Initial version for Adafruit Pro Trinket by Mike Barela 23 | 24 | */ 25 | #include // include mouse library for Pro Trinket (3V or 5V) 26 | 27 | // set pin numbers for switch, joystick axes, and LED 28 | const int switchPin = 9; // switch to turn on and off mouse control 29 | const int mouseButton = 10; // input pin for the mouse pushButton 30 | const int xAxis = 1; // joystick X axis to A1 31 | const int yAxis = 0; // joystick Y axis to A0 32 | const int ledPin = 13; // Mouse control LED 33 | 34 | // parameters for reading the joystick 35 | int range = 12; // output range of X or Y movement (zero to range) 36 | int responseDelay = 5; // response delay of the mouse, in ms 37 | int threshold = range/4; // resting threshold 38 | int center = range/2; // resting position value 39 | const float powerValue = 1.4; // for exponential behavior, 1 < value < 2 40 | 41 | boolean mouseIsActive = false; // whether or not to control the mouse 42 | int lastSwitchState = LOW; // previous switch state 43 | boolean mouseButtonPressed = false; // whether or not mouse button pressed 44 | int lastReading = 1; // last joystick/mouse button reading 45 | long debounceTime = 0; // last time the mouse button was toggled 46 | long debounce = 50; // debounce time, increase if the mouse clicks rapidly 47 | 48 | void setup() { 49 | pinMode(switchPin, INPUT_PULLUP); // the switch pin 50 | pinMode(mouseButton, INPUT_PULLUP); // mouse button on joystick 51 | pinMode(ledPin, OUTPUT); // the LED pin 52 | TrinketMouse.begin(); // initialize the mouse library 53 | } 54 | 55 | void loop() { 56 | int switchState; // State of the mouse enable/disable button 57 | int buttonState; // State of the mouse left button switch on joystick 58 | int xReading, yReading; // readings of the joystick movements 59 | int buttonReading; // reading of the joystick (left mouse) button 60 | 61 | switchState = digitalRead(switchPin); // read the mouse disable switch 62 | // if it's changed and it's high, toggle the mouse state 63 | if (switchState != lastSwitchState) { 64 | if (switchState == HIGH) { 65 | mouseIsActive = !mouseIsActive; 66 | // digitalWrite(ledPin, mouseIsActive); // toggle LED to indicate mouse state 67 | } 68 | } 69 | lastSwitchState = switchState; // save switch state for next comparison 70 | 71 | // read and scale the two joystick readings, one for each axis 72 | xReading = readAxis(xAxis); 73 | yReading = readAxis(yAxis); 74 | 75 | // This code gives the mouse a nonlinear acceleration 76 | // These 8 lines may be commented out to have linear acceleration 77 | if(xReading > 0) 78 | xReading = (int)pow(powerValue,xReading); 79 | else if(xReading < 0) 80 | xReading = -(int)pow(powerValue,-xReading); 81 | 82 | if(yReading > 0) 83 | yReading = (int)pow(powerValue,yReading); 84 | else if(yReading < 0) 85 | yReading = -(int)pow(powerValue,-yReading); // end nonlinear acceleration code 86 | 87 | // Read the joystick button as the left mouse button. Debounce per 88 | // Ladyada code at https://learn.adafruit.com/tilt-sensor/using-a-tilt-sensor 89 | buttonReading = digitalRead(mouseButton); // read the mouse left button (push joystick) 90 | if(buttonReading != lastReading) { // switch changed 91 | debounceTime = millis(); // reset debounce timer 92 | } 93 | if((millis() - debounceTime) > debounce) { 94 | buttonState = buttonReading; 95 | if(buttonState == LOW) { 96 | mouseButtonPressed = true; 97 | } 98 | else { 99 | mouseButtonPressed = false; 100 | } 101 | } 102 | lastReading = buttonReading; 103 | digitalWrite(ledPin, mouseButtonPressed); // toggle LED to indicate button state 104 | 105 | // if the mouse control state is active, move the mouse: 106 | if (mouseIsActive) { 107 | if (mouseButtonPressed) { // if joystick pressed down, indicate that too 108 | TrinketMouse.move(xReading, yReading, 0, MOUSEBTN_LEFT_MASK); 109 | } 110 | else { 111 | TrinketMouse.move(xReading, yReading, 0, 0); // move, no mouse button press 112 | } 113 | } 114 | delay(responseDelay); // wait between mouse readings 115 | } 116 | 117 | // Reads a joystick axis (0 or 1 for x or y) and scales the 118 | // analog input range to a range from 0 to 119 | int readAxis(int thisAxis) { 120 | int reading = analogRead(thisAxis); // read the analog input 121 | 122 | // map the reading from the analog input range to the output range 123 | reading = map(reading, 0, 1023, 0, range); 124 | 125 | // if the output reading is outside from the rest position threshold, use it 126 | int distance = center - reading; 127 | 128 | if (abs(distance) < threshold) { // if distance not to threshold, no move 129 | distance = 0; // prevents tiny jitters due to readings 130 | } 131 | return distance; // return the distance for this axis 132 | } 133 | 134 | -------------------------------------------------------------------------------- /examples/ProTrinketMouseRandom/ProTrinketMouseRandom.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ProTrinketMouseRandom example 3 | For Pro Trinket (ATmega328 based Trinket) by Adafruit Industries 4 | 5 | Please use library TrinketKeyboard for the ATtiny85 based Trinket 6 | 7 | Version 1.0 2015-01-03 Initial Version derived from TrinketMouseExample Mike Barela 8 | 9 | This example simply starts a mouse and randomly moves it around, while clicking random buttons 10 | */ 11 | 12 | #include 13 | 14 | void setup() 15 | { 16 | TrinketMouse.begin(); 17 | } 18 | 19 | void loop() 20 | { 21 | TrinketMouse.move(random(), random(), random(), random() & 0x07); 22 | } 23 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Pro Trinket USB Mouse 2 | version=1.1.3 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Library for Pro trinket to turn it into a mouse! 6 | paragraph=Library for Pro trinket to turn it into a mouse! 7 | category=Device Control 8 | url=https://github.com/adafruit/Pro_Trinket_USB_Mouse 9 | architectures=* 10 | depends=Adafruit MMA8451 Library 11 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | ProTrinketMouse is Adafruit's Pro Trinket USB HID Arduino Library 2 | 3 | ProTrinketMouse allows the user to implement a simple USB Mouse using an Adafruit Pro Trinket (ATmega 328P based) 4 | 5 | Please see ProTrinketMouse.h for usage documentation, examples are also included 6 | 7 | ProTrinketMouse uses V-USB (http://www.obdev.at/products/vusb/) to implement USB using a bitbang technique. See the folder "usbdrv" for V-USB files. 8 | 9 | Copyright (c) 2015 Adafruit Industries 10 | All rights reserved. 11 | 12 | ProTrinketMouse is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU Lesser General Public License as 14 | published by the Free Software Foundation, either version 3 of 15 | the License, or (at your option) any later version. 16 | 17 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with ProTrinketMouse. If not, see 21 | . 22 | 23 | Version History 24 | 25 | Version 1.0 Works with Pro Trinket 5V at 16 MHz Mike Barela 26 | Version 1.1 Works with Pro Trinket 5V at 16 MHz and Pro Trinket 3V at 12 MHz Mike Barela -------------------------------------------------------------------------------- /usbconfig.h: -------------------------------------------------------------------------------- 1 | /* Name: usbconfig.h 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) 3 | * microcontrollers 4 | * Author: Christian Starkjohann 5 | * Creation Date: 2005-04-01 6 | * Tabsize: 4 7 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 8 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or 9 | * proprietary (CommercialLicense.txt) 10 | */ 11 | 12 | /* 13 | This file has been modified for use as a part of ProTrinketMouse 14 | 15 | Copyright (c) 2015 Adafruit Industries 16 | All rights reserved. 17 | 18 | ProTrinketMouse is free software: you can redistribute it and/or modify it under 19 | the terms of the GNU Lesser General Public License as published by the Free 20 | Software Foundation, either version 3 of the License, or (at your option) any 21 | later version. 22 | 23 | ProTrinketMouse is distributed in the hope that it will be useful, but WITHOUT 24 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 25 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 26 | details. 27 | 28 | You should have received a copy of the GNU Lesser General Public 29 | License along with ProTrinketMouse. If not, see 30 | . 31 | */ 32 | 33 | #include "cmdline_defs.h" 34 | 35 | #ifndef __usbconfig_h_included__ 36 | #define __usbconfig_h_included__ 37 | 38 | /* ------------- Hardware Config ---------------------------- */ 39 | 40 | #define USB_CFG_IOPORTNAME D 41 | /* This is the port where the USB bus is connected. When you configure it to 42 | * "B", the registers PORTB, PINB and DDRB will be used. 43 | */ 44 | #define USB_CFG_DMINUS_BIT 7 45 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. 46 | * This may be any bit in the port. 47 | */ 48 | #define USB_CFG_DPLUS_BIT 2 49 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. 50 | * This may be any bit in the port. Please note that D+ must also be connected 51 | * to interrupt pin INT0! [You can also use other interrupts, see section 52 | * "Optional MCU Description" below, or you can connect D- to the interrupt, as 53 | * it is required if you use the USB_COUNT_SOF feature. If you use D- for the 54 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame 55 | * markers every millisecond.] 56 | */ 57 | 58 | #define USB_CFG_CLOCK_KHZ (F_CPU / 1000) 59 | #if USB_CFG_CLOCK_KHZ != 12000 && USB_CFG_CLOCK_KHZ != 16000 60 | #error "Non-standard clock rate for Pro Trinket detected" 61 | #endif 62 | /* Clock rate of the AVR in kHz. Legal values are 12000 and 16000 63 | * for Pro Trinket. Since F_CPU should be defined to your actual 64 | * clock rate anyway, you should not need to modify this setting. 65 | */ 66 | 67 | #define USB_CFG_CHECK_CRC 0 68 | /* Define this to 1 if you want that the driver checks integrity of incoming 69 | * data packets (CRC checks). CRC checks cost quite a bit of code size and are 70 | * currently only available for 18 MHz crystal clock. You must choose 71 | * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. 72 | */ 73 | 74 | /* ---------Optional Hardware Config ------------------------ */ 75 | 76 | /* #define USB_CFG_PULLUP_IOPORTNAME D */ 77 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of 78 | * V+, you can connect and disconnect the device from firmware by calling 79 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). 80 | * This constant defines the port on which the pullup resistor is connected. 81 | */ 82 | /* #define USB_CFG_PULLUP_BIT 4 */ 83 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined 84 | * above) where the 1.5k pullup resistor is connected. See description 85 | * above for details. 86 | */ 87 | 88 | /* ------------ Functional Range ---------------------------- */ 89 | 90 | #define USB_CFG_HAVE_INTRIN_ENDPOINT 1 91 | /* Define this to 1 if you want to compile a version with two endpoints: The 92 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint 93 | * number). 94 | */ 95 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 96 | /* Define this to 1 if you want to compile a version with three endpoints: The 97 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number 98 | * configured below) and a catch-all default interrupt-in endpoint as above. 99 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. 100 | */ 101 | #define USB_CFG_EP3_NUMBER 3 102 | /* If the so-called endpoint 3 is used, it can now be configured to any other 103 | * endpoint number (except 0) with this macro. Default if undefined is 3. 104 | */ 105 | /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ 106 | /* The above macro defines the startup condition for data toggling on the 107 | * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. 108 | * Since the token is toggled BEFORE sending any data, the first packet is 109 | * sent with the oposite value of this configuration! 110 | */ 111 | #define USB_CFG_IMPLEMENT_HALT 0 112 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature 113 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, 114 | * it is required by the standard. We have made it a config option because it 115 | * bloats the code considerably. 116 | */ 117 | #define USB_CFG_SUPPRESS_INTR_CODE 0 118 | /* Define this to 1 if you want to declare interrupt-in endpoints, but don't 119 | * want to send any data over them. If this macro is defined to 1, functions 120 | * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if 121 | * you need the interrupt-in endpoints in order to comply to an interface 122 | * (e.g. HID), but never want to send any data. This option saves a couple 123 | * of bytes in flash memory and the transmit buffers in RAM. 124 | */ 125 | #define USB_CFG_INTR_POLL_INTERVAL 10 126 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll 127 | * interval. The value is in milliseconds and must not be less than 10 ms for 128 | * low speed devices. 129 | */ 130 | #define USB_CFG_IS_SELF_POWERED 0 131 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the 132 | * device is powered from the USB bus. 133 | */ 134 | #define USB_CFG_MAX_BUS_POWER 100 135 | /* Set this variable to the maximum USB bus power consumption of your device. 136 | * The value is in milliamperes. [It will be divided by two since USB 137 | * communicates power requirements in units of 2 mA.] 138 | */ 139 | #define USB_CFG_IMPLEMENT_FN_WRITE 0 /* 0 for mouse */ 140 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out 141 | * transfers. Set it to 0 if you don't need it and want to save a couple of 142 | * bytes. 143 | */ 144 | #define USB_CFG_IMPLEMENT_FN_READ 0 145 | /* Set this to 1 if you need to send control replies which are generated 146 | * "on the fly" when usbFunctionRead() is called. If you only want to send 147 | * data from a static buffer, set it to 0 and return the data from 148 | * usbFunctionSetup(). This saves a couple of bytes. 149 | */ 150 | #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 151 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. 152 | * You must implement the function usbFunctionWriteOut() which receives all 153 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number 154 | * can be found in 'usbRxToken'. 155 | */ 156 | #define USB_CFG_HAVE_FLOWCONTROL 0 157 | /* Define this to 1 if you want flowcontrol over USB data. See the definition 158 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in 159 | * usbdrv.h. 160 | */ 161 | #define USB_CFG_DRIVER_FLASH_PAGE 0 162 | /* If the device has more than 64 kBytes of flash, define this to the 64 k page 163 | * where the driver's constants (descriptors) are located. Or in other words: 164 | * Define this to 1 for boot loaders on the ATMega128. 165 | */ 166 | #define USB_CFG_LONG_TRANSFERS 0 167 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes 168 | * in a single control-in or control-out transfer. Note that the capability 169 | * for long transfers increases the driver size. 170 | */ 171 | /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) 172 | * blinkLED(); */ 173 | /* This macro is a hook if you want to do unconventional things. If it is 174 | * defined, it's inserted at the beginning of received message processing. 175 | * If you eat the received message and don't want default processing to 176 | * proceed, do a return after doing your things. One possible application 177 | * (besides debugging) is to flash a status LED on each packet. 178 | */ 179 | /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ 180 | /* This macro is a hook if you need to know when an USB RESET occurs. It has 181 | * one parameter which distinguishes between the start of RESET state and its 182 | * end. 183 | */ 184 | /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ 185 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was 186 | * received. 187 | */ 188 | #define USB_COUNT_SOF 0 189 | /* define this macro to 1 if you need the global variable "usbSofCount" which 190 | * counts SOF packets. This feature requires that the hardware interrupt is 191 | * connected to D- instead of D+. 192 | */ 193 | /* #ifdef __ASSEMBLER__ 194 | * macro myAssemblerMacro 195 | * in YL, TCNT0 196 | * sts timer0Snapshot, YL 197 | * endm 198 | * #endif 199 | * #define USB_SOF_HOOK myAssemblerMacro 200 | * This macro (if defined) is executed in the assembler module when a 201 | * Start Of Frame condition is detected. It is recommended to define it to 202 | * the name of an assembler macro which is defined here as well so that more 203 | * than one assembler instruction can be used. The macro may use the register 204 | * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages 205 | * immediately after an SOF pulse may be lost and must be retried by the host. 206 | * What can you do with this hook? Since the SOF signal occurs exactly every 207 | * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in 208 | * designs running on the internal RC oscillator. 209 | * Please note that Start Of Frame detection works only if D- is wired to the 210 | * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! 211 | */ 212 | #define USB_CFG_CHECK_DATA_TOGGLING 0 213 | /* define this macro to 1 if you want to filter out duplicate data packets 214 | * sent by the host. Duplicates occur only as a consequence of communication 215 | * errors, when the host does not receive an ACK. Please note that you need to 216 | * implement the filtering yourself in usbFunctionWriteOut() and 217 | * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable 218 | * for each control- and out-endpoint to check for duplicate packets. 219 | */ 220 | #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 1 221 | /* define this macro to 1 if you want the function usbMeasureFrameLength() 222 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. 223 | */ 224 | #if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__) || \ 225 | defined(__AVR_ATtiny25__) 226 | #ifndef __ASSEMBLER__ 227 | #include // for sei() 228 | extern void calibrateOscillator(void); 229 | #endif 230 | #define USB_RESET_HOOK(resetStarts) \ 231 | if (!resetStarts) { \ 232 | cli(); \ 233 | calibrateOscillator(); \ 234 | sei(); \ 235 | } 236 | #endif 237 | 238 | #define USB_USE_FAST_CRC 0 239 | /* The assembler module has two implementations for the CRC algorithm. One is 240 | * faster, the other is smaller. This CRC routine is only used for transmitted 241 | * messages where timing is not critical. The faster routine needs 31 cycles 242 | * per byte while the smaller one needs 61 to 69 cycles. The faster routine 243 | * may be worth the 32 bytes bigger code size if you transmit lots of data and 244 | * run the AVR close to its limit. 245 | */ 246 | 247 | /* ---------- Device Description --------------------------- */ 248 | 249 | #define USB_CFG_VENDOR_ID 0x81, 0x17 250 | /* USB vendor ID for the device, low byte first. If you have registered your 251 | * own Vendor ID, define it here. Otherwise you may use one of obdev's free 252 | * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! 253 | */ 254 | #define USB_CFG_DEVICE_ID 0x34, 0x14 /* = 0x05dc = 1500 */ 255 | /* This is the ID of the product, low byte first. It is interpreted in the 256 | * scope of the vendor ID. If you have registered your own VID with usb.org 257 | * or if you have licensed a PID from somebody else, define it here. Otherwise 258 | * you may use one of obdev's free shared VID/PID pairs. See the file 259 | * USB-IDs-for-free.txt for details! 260 | * *** IMPORTANT NOTE *** 261 | * This template uses obdev's shared VID/PID pair for Vendor Class devices 262 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand 263 | * the implications! 264 | */ 265 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 266 | /* Version number of the device: Minor number first, then major number. 267 | */ 268 | #define USB_CFG_VENDOR_NAME 'A', 'd', 'a', 'f', 'r', 'u', 'i', 't' 269 | #define USB_CFG_VENDOR_NAME_LEN 8 270 | /* These two values define the vendor name returned by the USB device. The name 271 | * must be given as a list of characters under single quotes. The characters 272 | * are interpreted as Unicode (UTF-16) entities. 273 | * If you don't want a vendor name string, undefine these macros. 274 | * ALWAYS define a vendor name containing your Internet domain name if you use 275 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for 276 | * details. 277 | */ 278 | #define USB_CFG_DEVICE_NAME \ 279 | 'P', 'r', 'o', ' ', 'T', 'r', 'i', 'n', 'k', 'e', 't', ' ', 'M', 'o', 'u', \ 280 | 's', 'e' 281 | #define USB_CFG_DEVICE_NAME_LEN 17 282 | /* Same as above for the device name. If you don't want a device name, undefine 283 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if 284 | * you use a shared VID/PID. 285 | */ 286 | /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ 287 | /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ 288 | /* Same as above for the serial number. If you don't want a serial number, 289 | * undefine the macros. 290 | * It may be useful to provide the serial number through other means than at 291 | * compile time. See the section about descriptor properties below for how 292 | * to fine tune control over USB descriptors such as the string descriptor 293 | * for the serial number. 294 | */ 295 | #define USB_CFG_DEVICE_CLASS \ 296 | 0x00 // 0x00 means "check the interface class instead" 297 | #define USB_CFG_DEVICE_SUBCLASS 0x00 298 | /* See USB specification if you want to conform to an existing device class. 299 | * Class 0xff is "vendor specific". 300 | */ 301 | #define USB_CFG_INTERFACE_CLASS 0x03 // 0x03 means HID 302 | #define USB_CFG_INTERFACE_SUBCLASS 0x00 303 | #define USB_CFG_INTERFACE_PROTOCOL 0x00 304 | /* See USB specification if you want to conform to an existing device class or 305 | * protocol. The following classes must be set at interface level: 306 | * HID class is 3, no subclass and protocol required (but may be useful!) 307 | * CDC class is 2, use subclass 2 and protocol 1 for ACM 308 | */ 309 | #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 52 310 | /* Define this to the length of the HID report descriptor, if you implement 311 | * an HID device. Otherwise don't define it or define it to 0. 312 | * If you use this define, you must add a PROGMEM character array named 313 | * "usbHidReportDescriptor" to your code which contains the report descriptor. 314 | * Don't forget to keep the array and this define in sync! 315 | */ 316 | 317 | //#define USB_PUBLIC static 318 | /* Use the define above if you #include usbdrv.c instead of linking against it. 319 | * This technique saves a couple of bytes in flash memory. 320 | */ 321 | 322 | /* ------------------- Fine Control over USB Descriptors ------------------- */ 323 | /* If you don't want to use the driver's default USB descriptors, you can 324 | * provide our own. These can be provided as (1) fixed length static data in 325 | * flash memory, (2) fixed length static data in RAM or (3) dynamically at 326 | * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more 327 | * information about this function. 328 | * Descriptor handling is configured through the descriptor's properties. If 329 | * no properties are defined or if they are 0, the default descriptor is used. 330 | * Possible properties are: 331 | * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched 332 | * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is 333 | * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if 334 | * you want RAM pointers. 335 | * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found 336 | * in static memory is in RAM, not in flash memory. 337 | * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), 338 | * the driver must know the descriptor's length. The descriptor itself is 339 | * found at the address of a well known identifier (see below). 340 | * List of static descriptor names (must be declared PROGMEM if in flash): 341 | * char usbDescriptorDevice[]; 342 | * char usbDescriptorConfiguration[]; 343 | * char usbDescriptorHidReport[]; 344 | * char usbDescriptorString0[]; 345 | * int usbDescriptorStringVendor[]; 346 | * int usbDescriptorStringDevice[]; 347 | * int usbDescriptorStringSerialNumber[]; 348 | * Other descriptors can't be provided statically, they must be provided 349 | * dynamically at runtime. 350 | * 351 | * Descriptor properties are or-ed or added together, e.g.: 352 | * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) 353 | * 354 | * The following descriptors are defined: 355 | * USB_CFG_DESCR_PROPS_DEVICE 356 | * USB_CFG_DESCR_PROPS_CONFIGURATION 357 | * USB_CFG_DESCR_PROPS_STRINGS 358 | * USB_CFG_DESCR_PROPS_STRING_0 359 | * USB_CFG_DESCR_PROPS_STRING_VENDOR 360 | * USB_CFG_DESCR_PROPS_STRING_PRODUCT 361 | * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 362 | * USB_CFG_DESCR_PROPS_HID 363 | * USB_CFG_DESCR_PROPS_HID_REPORT 364 | * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) 365 | * 366 | * Note about string descriptors: String descriptors are not just strings, they 367 | * are Unicode strings prefixed with a 2 byte header. Example: 368 | * int serialNumberDescriptor[] = { 369 | * USB_STRING_DESCRIPTOR_HEADER(6), 370 | * 'S', 'e', 'r', 'i', 'a', 'l' 371 | * }; 372 | */ 373 | 374 | #define USB_CFG_DESCR_PROPS_DEVICE 0 375 | #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 376 | #define USB_CFG_DESCR_PROPS_STRINGS 0 377 | #define USB_CFG_DESCR_PROPS_STRING_0 0 378 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 379 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 380 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 381 | #define USB_CFG_DESCR_PROPS_HID 0 382 | #define USB_CFG_DESCR_PROPS_HID_REPORT 0 383 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 384 | 385 | #define usbMsgPtr_t unsigned short 386 | /* If usbMsgPtr_t is not defined, it defaults to 'uchar *'. We define it to 387 | * a scalar type here because gcc generates slightly shorter code for scalar 388 | * arithmetics than for pointer arithmetics. Remove this define for backward 389 | * type compatibility or define it to an 8 bit type if you use data in RAM only 390 | * and all RAM is below 256 bytes (tiny memory model in IAR CC). 391 | */ 392 | 393 | /* ------- Optional MCU Description ------------------------ */ 394 | 395 | /* The following configurations have working defaults in usbdrv.h. You 396 | * usually don't need to set them explicitly. Only if you want to run 397 | * the driver on a device which is not yet supported or with a compiler 398 | * which is not fully supported (such as IAR C) or if you use a differnt 399 | * interrupt than INT0, you may have to define some of these. 400 | */ 401 | /* ones below are for Trinket, Pro Trinket can use V-USB values 402 | * #define USB_INTR_CFG PCMSK 403 | * #define USB_INTR_CFG_SET (1 << USB_CFG_DPLUS_BIT) 404 | * #define USB_INTR_CFG_CLR 0 405 | * #define USB_INTR_ENABLE GIMSK 406 | * #define USB_INTR_ENABLE_BIT PCIE 407 | * #define USB_INTR_PENDING GIFR 408 | * #define USB_INTR_PENDING_BIT PCIF 409 | */ 410 | /* Interrupt vector for Pro Trinket's ATmega 328 */ 411 | #define USB_INTR_VECTOR INT0_vect 412 | 413 | #endif /* __usbconfig_h_included__ */ 414 | -------------------------------------------------------------------------------- /usbdrv/Changelog.txt: -------------------------------------------------------------------------------- 1 | This file documents changes in the firmware-only USB driver for atmel's AVR 2 | microcontrollers. New entries are always appended to the end of the file. 3 | Scroll down to the bottom to see the most recent changes. 4 | 5 | 2005-04-01: 6 | - Implemented endpoint 1 as interrupt-in endpoint. 7 | - Moved all configuration options to usbconfig.h which is not part of the 8 | driver. 9 | - Changed interface for usbVendorSetup(). 10 | - Fixed compatibility with ATMega8 device. 11 | - Various minor optimizations. 12 | 13 | 2005-04-11: 14 | - Changed interface to application: Use usbFunctionSetup(), usbFunctionRead() 15 | and usbFunctionWrite() now. Added configuration options to choose which 16 | of these functions to compile in. 17 | - Assembler module delivers receive data non-inverted now. 18 | - Made register and bit names compatible with more AVR devices. 19 | 20 | 2005-05-03: 21 | - Allow address of usbRxBuf on any memory page as long as the buffer does 22 | not cross 256 byte page boundaries. 23 | - Better device compatibility: works with Mega88 now. 24 | - Code optimization in debugging module. 25 | - Documentation updates. 26 | 27 | 2006-01-02: 28 | - Added (free) default Vendor- and Product-IDs bought from voti.nl. 29 | - Added USBID-License.txt file which defines the rules for using the free 30 | shared VID/PID pair. 31 | - Added Readme.txt to the usbdrv directory which clarifies administrative 32 | issues. 33 | 34 | 2006-01-25: 35 | - Added "configured state" to become more standards compliant. 36 | - Added "HALT" state for interrupt endpoint. 37 | - Driver passes the "USB Command Verifier" test from usb.org now. 38 | - Made "serial number" a configuration option. 39 | - Minor optimizations, we now recommend compiler option "-Os" for best 40 | results. 41 | - Added a version number to usbdrv.h 42 | 43 | 2006-02-03: 44 | - New configuration variable USB_BUFFER_SECTION for the memory section where 45 | the USB rx buffer will go. This defaults to ".bss" if not defined. Since 46 | this buffer MUST NOT cross 256 byte pages (not even touch a page at the 47 | end), the user may want to pass a linker option similar to 48 | "-Wl,--section-start=.mybuffer=0x800060". 49 | - Provide structure for usbRequest_t. 50 | - New defines for USB constants. 51 | - Prepared for HID implementations. 52 | - Increased data size limit for interrupt transfers to 8 bytes. 53 | - New macro usbInterruptIsReady() to query interrupt buffer state. 54 | 55 | 2006-02-18: 56 | - Ensure that the data token which is sent as an ack to an OUT transfer is 57 | always zero sized. This fixes a bug where the host reports an error after 58 | sending an out transfer to the device, although all data arrived at the 59 | device. 60 | - Updated docs in usbdrv.h to reflect changed API in usbFunctionWrite(). 61 | 62 | * Release 2006-02-20 63 | 64 | - Give a compiler warning when compiling with debugging turned on. 65 | - Added Oleg Semyonov's changes for IAR-cc compatibility. 66 | - Added new (optional) functions usbDeviceConnect() and usbDeviceDisconnect() 67 | (also thanks to Oleg!). 68 | - Rearranged tests in usbPoll() to save a couple of instructions in the most 69 | likely case that no actions are pending. 70 | - We need a delay between the SET ADDRESS request until the new address 71 | becomes active. This delay was handled in usbPoll() until now. Since the 72 | spec says that the delay must not exceed 2ms, previous versions required 73 | aggressive polling during the enumeration phase. We have now moved the 74 | handling of the delay into the interrupt routine. 75 | - We must not reply with NAK to a SETUP transaction. We can only achieve this 76 | by making sure that the rx buffer is empty when SETUP tokens are expected. 77 | We therefore don't pass zero sized data packets from the status phase of 78 | a transfer to usbPoll(). This change MAY cause troubles if you rely on 79 | receiving a less than 8 bytes long packet in usbFunctionWrite() to 80 | identify the end of a transfer. usbFunctionWrite() will NEVER be called 81 | with a zero length. 82 | 83 | * Release 2006-03-14 84 | 85 | - Improved IAR C support: tiny memory model, more devices 86 | - Added template usbconfig.h file under the name usbconfig-prototype.h 87 | 88 | * Release 2006-03-26 89 | 90 | - Added provision for one more interrupt-in endpoint (endpoint 3). 91 | - Added provision for one interrupt-out endpoint (endpoint 1). 92 | - Added flowcontrol macros for USB. 93 | - Added provision for custom configuration descriptor. 94 | - Allow ANY two port bits for D+ and D-. 95 | - Merged (optional) receive endpoint number into global usbRxToken variable. 96 | - Use USB_CFG_IOPORTNAME instead of USB_CFG_IOPORT. We now construct the 97 | variable name from the single port letter instead of computing the address 98 | of related ports from the output-port address. 99 | 100 | * Release 2006-06-26 101 | 102 | - Updated documentation in usbdrv.h and usbconfig-prototype.h to reflect the 103 | new features. 104 | - Removed "#warning" directives because IAR does not understand them. Use 105 | unused static variables instead to generate a warning. 106 | - Do not include when compiling with IAR. 107 | - Introduced USB_CFG_DESCR_PROPS_* in usbconfig.h to configure how each 108 | USB descriptor should be handled. It is now possible to provide descriptor 109 | data in Flash, RAM or dynamically at runtime. 110 | - STALL is now a status in usbTxLen* instead of a message. We can now conform 111 | to the spec and leave the stall status pending until it is cleared. 112 | - Made usbTxPacketCnt1 and usbTxPacketCnt3 public. This allows the 113 | application code to reset data toggling on interrupt pipes. 114 | 115 | * Release 2006-07-18 116 | 117 | - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes 118 | an assembler error. 119 | - usbDeviceDisconnect() takes pull-up resistor to high impedance now. 120 | 121 | * Release 2007-02-01 122 | 123 | - Merged in some code size improvements from usbtiny (thanks to Dick 124 | Streefland for these optimizations!) 125 | - Special alignment requirement for usbRxBuf not required any more. Thanks 126 | again to Dick Streefland for this hint! 127 | - Reverted to "#warning" instead of unused static variables -- new versions 128 | of IAR CC should handle this directive. 129 | - Changed Open Source license to GNU GPL v2 in order to make linking against 130 | other free libraries easier. We no longer require publication of the 131 | circuit diagrams, but we STRONGLY encourage it. If you improve the driver 132 | itself, PLEASE grant us a royalty free license to your changes for our 133 | commercial license. 134 | 135 | * Release 2007-03-29 136 | 137 | - New configuration option "USB_PUBLIC" in usbconfig.h. 138 | - Set USB version number to 1.10 instead of 1.01. 139 | - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and 140 | USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences 141 | to USB_CFG_DESCR_PROPS_STRING_PRODUCT. 142 | - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver 143 | code. 144 | - New assembler module for 16 MHz crystal. 145 | - usbdrvasm.S contains common code only, clock-specific parts have been moved 146 | to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively. 147 | 148 | * Release 2007-06-25 149 | 150 | - 16 MHz module: Do SE0 check in stuffed bits as well. 151 | 152 | * Release 2007-07-07 153 | 154 | - Define hi8(x) for IAR compiler to limit result to 8 bits. This is necessary 155 | for negative values. 156 | - Added 15 MHz module contributed by V. Bosch. 157 | - Interrupt vector name can now be configured. This is useful if somebody 158 | wants to use a different hardware interrupt than INT0. 159 | 160 | * Release 2007-08-07 161 | 162 | - Moved handleIn3 routine in usbdrvasm16.S so that relative jump range is 163 | not exceeded. 164 | - More config options: USB_RX_USER_HOOK(), USB_INITIAL_DATATOKEN, 165 | USB_COUNT_SOF 166 | - USB_INTR_PENDING can now be a memory address, not just I/O 167 | 168 | * Release 2007-09-19 169 | 170 | - Split out common parts of assembler modules into separate include file 171 | - Made endpoint numbers configurable so that given interface definitions 172 | can be matched. See USB_CFG_EP3_NUMBER in usbconfig-prototype.h. 173 | - Store endpoint number for interrupt/bulk-out so that usbFunctionWriteOut() 174 | can handle any number of endpoints. 175 | - Define usbDeviceConnect() and usbDeviceDisconnect() even if no 176 | USB_CFG_PULLUP_IOPORTNAME is defined. Directly set D+ and D- to 0 in this 177 | case. 178 | 179 | * Release 2007-12-01 180 | 181 | - Optimize usbDeviceConnect() and usbDeviceDisconnect() for less code size 182 | when USB_CFG_PULLUP_IOPORTNAME is not defined. 183 | 184 | * Release 2007-12-13 185 | 186 | - Renamed all include-only assembler modules from *.S to *.inc so that 187 | people don't add them to their project sources. 188 | - Distribute leap bits in tx loop more evenly for 16 MHz module. 189 | - Use "macro" and "endm" instead of ".macro" and ".endm" for IAR 190 | - Avoid compiler warnings for constant expr range by casting some values in 191 | USB descriptors. 192 | 193 | * Release 2008-01-21 194 | 195 | - Fixed bug in 15 and 16 MHz module where the new address set with 196 | SET_ADDRESS was already accepted at the next NAK or ACK we send, not at 197 | the next data packet we send. This caused problems when the host polled 198 | too fast. Thanks to Alexander Neumann for his help and patience debugging 199 | this issue! 200 | 201 | * Release 2008-02-05 202 | 203 | - Fixed bug in 16.5 MHz module where a register was used in the interrupt 204 | handler before it was pushed. This bug was introduced with version 205 | 2007-09-19 when common parts were moved to a separate file. 206 | - Optimized CRC routine (thanks to Reimar Doeffinger). 207 | 208 | * Release 2008-02-16 209 | 210 | - Removed outdated IAR compatibility stuff (code sections). 211 | - Added hook macros for USB_RESET_HOOK() and USB_SET_ADDRESS_HOOK(). 212 | - Added optional routine usbMeasureFrameLength() for calibration of the 213 | internal RC oscillator. 214 | 215 | * Release 2008-02-28 216 | 217 | - USB_INITIAL_DATATOKEN defaults to USBPID_DATA1 now, which means that we 218 | start with sending USBPID_DATA0. 219 | - Changed defaults in usbconfig-prototype.h 220 | - Added free USB VID/PID pair for MIDI class devices 221 | - Restructured AVR-USB as separate package, not part of PowerSwitch any more. 222 | 223 | * Release 2008-04-18 224 | 225 | - Restructured usbdrv.c so that it is easier to read and understand. 226 | - Better code optimization with gcc 4. 227 | - If a second interrupt in endpoint is enabled, also add it to config 228 | descriptor. 229 | - Added config option for long transfers (above 254 bytes), see 230 | USB_CFG_LONG_TRANSFERS in usbconfig.h. 231 | - Added 20 MHz module contributed by Jeroen Benschop. 232 | 233 | * Release 2008-05-13 234 | 235 | - Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length 236 | was not incremented, pointer to length was incremented instead. 237 | - Added code to command line tool(s) which claims an interface. This code 238 | is disabled by default, but may be necessary on newer Linux kernels. 239 | - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING". 240 | - New header "usbportability.h" prepares ports to other development 241 | environments. 242 | - Long transfers (above 254 bytes) did not work when usbFunctionRead() was 243 | used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!] 244 | - In hiddata.c (example code for sending/receiving data over HID), use 245 | USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so 246 | that we need not claim the interface. 247 | - in usbPoll() loop 20 times polling for RESET state instead of 10 times. 248 | This accounts for the higher clock rates we now support. 249 | - Added a module for 12.8 MHz RC oscillator with PLL in receiver loop. 250 | - Added hook to SOF code so that oscillator can be tuned to USB frame clock. 251 | - Added timeout to waitForJ loop. Helps preventing unexpected hangs. 252 | - Added example code for oscillator tuning to libs-device (thanks to 253 | Henrik Haftmann for the idea to this routine). 254 | - Implemented option USB_CFG_SUPPRESS_INTR_CODE. 255 | 256 | * Release 2008-10-22 257 | 258 | - Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and 259 | similar, not offset of 0x20 needs to be added. 260 | - Allow distribution under GPLv3 for those who have to link against other 261 | code distributed under GPLv3. 262 | 263 | * Release 2008-11-26 264 | 265 | - Removed libusb-win32 dependency for hid-data example in Makefile.windows. 266 | It was never required and confused many people. 267 | - Added extern uchar usbRxToken to usbdrv.h. 268 | - Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser. 269 | 270 | * Release 2009-03-23 271 | 272 | - Hid-mouse example used settings from hid-data example, fixed that. 273 | - Renamed project to V-USB due to a trademark issue with Atmel(r). 274 | - Changed CommercialLicense.txt and USBID-License.txt to make the 275 | background of USB ID registration clearer. 276 | 277 | * Release 2009-04-15 278 | 279 | - Changed CommercialLicense.txt to reflect the new range of PIDs from 280 | Jason Kotzin. 281 | - Removed USBID-License.txt in favor of USB-IDs-for-free.txt and 282 | USB-ID-FAQ.txt 283 | - Fixed a bug in the 12.8 MHz module: End Of Packet decection was made in 284 | the center between bit 0 and 1 of each byte. This is where the data lines 285 | are expected to change and the sampled data may therefore be nonsense. 286 | We therefore check EOP ONLY if bits 0 AND 1 have both been read as 0 on D-. 287 | - Fixed a bitstuffing problem in the 16 MHz module: If bit 6 was stuffed, 288 | the unstuffing code in the receiver routine was 1 cycle too long. If 289 | multiple bytes had the unstuffing in bit 6, the error summed up until the 290 | receiver was out of sync. 291 | - Included option for faster CRC routine. 292 | Thanks to Slawomir Fras (BoskiDialer) for this code! 293 | - Updated bits in Configuration Descriptor's bmAttributes according to 294 | USB 1.1 (in particular bit 7, it is a must-be-set bit now). 295 | 296 | * Release 2009-08-22 297 | 298 | - Moved first DBG1() after odDebugInit() in all examples. 299 | - Use vector INT0_vect instead of SIG_INTERRUPT0 if defined. This makes 300 | V-USB compatible with the new "p" suffix devices (e.g. ATMega328p). 301 | - USB_CFG_CLOCK_KHZ setting is now required in usbconfig.h (no default any 302 | more). 303 | - New option USB_CFG_DRIVER_FLASH_PAGE allows boot loaders on devices with 304 | more than 64 kB flash. 305 | - Built-in configuration descriptor allows custom definition for second 306 | endpoint now. 307 | 308 | * Release 2010-07-15 309 | 310 | - Fixed bug in usbDriverSetup() which prevented descriptor sizes above 255 311 | bytes. 312 | - Avoid a compiler warning for unused parameter in usbHandleResetHook() when 313 | compiler option -Wextra is enabled. 314 | - Fixed wrong hex value for some IDs in USB-IDs-for-free.txt. 315 | - Keep a define for USBATTR_BUSPOWER, although the flag does not exist 316 | in USB 1.1 any more. Set it to 0. This is for backward compatibility. 317 | 318 | * Release 2012-01-09 319 | 320 | - Define a separate (defined) type for usbMsgPtr so that projects using a 321 | tiny memory model can define it to an 8 bit type in usbconfig.h. This 322 | change also saves a couple of bytes when using a scalar 16 bit type. 323 | - Inserted "const" keyword for all PROGMEM declarations because new GCC 324 | requires it. 325 | - Fixed problem with dependence of usbportability.h on usbconfig.h. This 326 | problem occurred with IAR CC only. 327 | - Prepared repository for github.com. 328 | 329 | * Release 2012-12-06 -------------------------------------------------------------------------------- /usbdrv/CommercialLicense.txt: -------------------------------------------------------------------------------- 1 | V-USB Driver Software License Agreement 2 | Version 2012-07-09 3 | 4 | THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN 5 | ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING 6 | THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. 7 | 8 | 9 | 1 DEFINITIONS 10 | 11 | 1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, 12 | Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. 13 | 14 | 1.2 "You" shall mean the Licensee. 15 | 16 | 1.3 "V-USB" shall mean all files included in the package distributed under 17 | the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) 18 | unless otherwise noted. This includes the firmware-only USB device 19 | implementation for Atmel AVR microcontrollers, some simple device examples 20 | and host side software examples and libraries. 21 | 22 | 23 | 2 LICENSE GRANTS 24 | 25 | 2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source 26 | code of V-USB. 27 | 28 | 2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the 29 | non-exclusive right to use, copy and distribute V-USB with your hardware 30 | product(s), restricted by the limitations in section 3 below. 31 | 32 | 2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify 33 | the source code and your copy of V-USB according to your needs. 34 | 35 | 2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB 36 | Product ID(s), sent to you in e-mail. These Product IDs are reserved 37 | exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID 38 | ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen 39 | Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from 40 | Jason Kotzin (now flirc.tv, Inc.). Both owners of the Vendor IDs have 41 | obtained these IDs from the USB Implementers Forum, Inc. (www.usb.org). 42 | OBJECTIVE DEVELOPMENT disclaims all liability which might arise from the 43 | assignment of USB IDs. 44 | 45 | 2.5 USB Certification. Although not part of this agreement, we want to make 46 | it clear that you cannot become USB certified when you use V-USB or a USB 47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't 48 | meet the electrical specifications required by the USB specification and 49 | the USB Implementers Forum certifies only members who bought a Vendor ID of 50 | their own. 51 | 52 | 53 | 3 LICENSE RESTRICTIONS 54 | 55 | 3.1 Number of Units. Only one of the following three definitions is 56 | applicable. Which one is determined by the amount you pay to OBJECTIVE 57 | DEVELOPMENT, see section 4 ("Payment") below. 58 | 59 | Hobby License: You may use V-USB according to section 2 above in no more 60 | than 5 hardware units. These units must not be sold for profit. 61 | 62 | Entry Level License: You may use V-USB according to section 2 above in no 63 | more than 150 hardware units. 64 | 65 | Professional License: You may use V-USB according to section 2 above in 66 | any number of hardware units, except for large scale production ("unlimited 67 | fair use"). Quantities below 10,000 units are not considered large scale 68 | production. If your reach quantities which are obviously large scale 69 | production, you must pay a license fee of 0.10 EUR per unit for all units 70 | above 10,000. 71 | 72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber 73 | any copy of V-USB, or any of the rights granted herein. 74 | 75 | 3.3 Transfer. You may not transfer your rights under this Agreement to 76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If 77 | such consent is obtained, you may permanently transfer this License to 78 | another party. The recipient of such transfer must agree to all terms and 79 | conditions of this Agreement. 80 | 81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not 82 | expressly granted. 83 | 84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are 85 | non-exclusive. 86 | 87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled 88 | by third parties. In particular, you are not allowed to use the USB logo or 89 | other trademarks owned by the USB Implementers Forum, Inc. without their 90 | consent. Since such consent depends on USB certification, it should be 91 | noted that V-USB will not pass certification because it does not 92 | implement checksum verification and the microcontroller ports do not meet 93 | the electrical specifications. 94 | 95 | 96 | 4 PAYMENT 97 | 98 | The payment amount depends on the variation of this agreement (according to 99 | section 3.1) into which you want to enter. Concrete prices are listed on 100 | OBJECTIVE DEVELOPMENT's web site, usually at 101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed 102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor 103 | or reseller. 104 | 105 | 106 | 5 COPYRIGHT AND OWNERSHIP 107 | 108 | V-USB is protected by copyright laws and international copyright 109 | treaties, as well as other intellectual property laws and treaties. V-USB 110 | is licensed, not sold. 111 | 112 | 113 | 6 TERM AND TERMINATION 114 | 115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE 116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and 117 | USB-IDs if you fail to comply with any of its terms and conditions. 118 | 119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality 120 | and limitation of liability shall survive termination of this agreement. 121 | 122 | 123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY 124 | 125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE 127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER 128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND 130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE 131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL 132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO 133 | STATE/JURISDICTION. 134 | 135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, 136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY 137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER 138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, 139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY 140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE 141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE 142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY 143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS 144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. 145 | 146 | 147 | 8 MISCELLANEOUS TERMS 148 | 149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing 150 | purposes that you entered into this agreement. 151 | 152 | 8.2 Entire Agreement. This document represents the entire agreement between 153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by 154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you. 155 | 156 | 8.3 Severability. In case a provision of these terms and conditions should 157 | be or become partly or entirely invalid, ineffective, or not executable, 158 | the validity of all other provisions shall not be affected. 159 | 160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic 161 | of Austria. 162 | 163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have 164 | exclusive jurisdiction regarding all disputes in connection with this 165 | agreement. 166 | 167 | -------------------------------------------------------------------------------- /usbdrv/License.txt: -------------------------------------------------------------------------------- 1 | OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the 2 | terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is 3 | your choice whether you apply the terms of version 2 or version 3. The full 4 | text of GPLv2 is included below. In addition to the requirements in the GPL, 5 | we STRONGLY ENCOURAGE you to do the following: 6 | 7 | (1) Publish your entire project on a web site and drop us a note with the URL. 8 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission. 9 | 10 | (2) Adhere to minimum publication standards. Please include AT LEAST: 11 | - a circuit diagram in PDF, PNG or GIF format 12 | - full source code for the host software 13 | - a Readme.txt file in ASCII format which describes the purpose of the 14 | project and what can be found in which directories and which files 15 | - a reference to http://www.obdev.at/vusb/ 16 | 17 | (3) If you improve the driver firmware itself, please give us a free license 18 | to your modifications for our commercial license offerings. 19 | 20 | 21 | 22 | GNU GENERAL PUBLIC LICENSE 23 | Version 2, June 1991 24 | 25 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 26 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | Everyone is permitted to copy and distribute verbatim copies 28 | of this license document, but changing it is not allowed. 29 | 30 | Preamble 31 | 32 | The licenses for most software are designed to take away your 33 | freedom to share and change it. By contrast, the GNU General Public 34 | License is intended to guarantee your freedom to share and change free 35 | software--to make sure the software is free for all its users. This 36 | General Public License applies to most of the Free Software 37 | Foundation's software and to any other program whose authors commit to 38 | using it. (Some other Free Software Foundation software is covered by 39 | the GNU Library General Public License instead.) You can apply it to 40 | your programs, too. 41 | 42 | When we speak of free software, we are referring to freedom, not 43 | price. Our General Public Licenses are designed to make sure that you 44 | have the freedom to distribute copies of free software (and charge for 45 | this service if you wish), that you receive source code or can get it 46 | if you want it, that you can change the software or use pieces of it 47 | in new free programs; and that you know you can do these things. 48 | 49 | To protect your rights, we need to make restrictions that forbid 50 | anyone to deny you these rights or to ask you to surrender the rights. 51 | These restrictions translate to certain responsibilities for you if you 52 | distribute copies of the software, or if you modify it. 53 | 54 | For example, if you distribute copies of such a program, whether 55 | gratis or for a fee, you must give the recipients all the rights that 56 | you have. You must make sure that they, too, receive or can get the 57 | source code. And you must show them these terms so they know their 58 | rights. 59 | 60 | We protect your rights with two steps: (1) copyright the software, and 61 | (2) offer you this license which gives you legal permission to copy, 62 | distribute and/or modify the software. 63 | 64 | Also, for each author's protection and ours, we want to make certain 65 | that everyone understands that there is no warranty for this free 66 | software. If the software is modified by someone else and passed on, we 67 | want its recipients to know that what they have is not the original, so 68 | that any problems introduced by others will not reflect on the original 69 | authors' reputations. 70 | 71 | Finally, any free program is threatened constantly by software 72 | patents. We wish to avoid the danger that redistributors of a free 73 | program will individually obtain patent licenses, in effect making the 74 | program proprietary. To prevent this, we have made it clear that any 75 | patent must be licensed for everyone's free use or not licensed at all. 76 | 77 | The precise terms and conditions for copying, distribution and 78 | modification follow. 79 | 80 | GNU GENERAL PUBLIC LICENSE 81 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 82 | 83 | 0. This License applies to any program or other work which contains 84 | a notice placed by the copyright holder saying it may be distributed 85 | under the terms of this General Public License. The "Program", below, 86 | refers to any such program or work, and a "work based on the Program" 87 | means either the Program or any derivative work under copyright law: 88 | that is to say, a work containing the Program or a portion of it, 89 | either verbatim or with modifications and/or translated into another 90 | language. (Hereinafter, translation is included without limitation in 91 | the term "modification".) Each licensee is addressed as "you". 92 | 93 | Activities other than copying, distribution and modification are not 94 | covered by this License; they are outside its scope. The act of 95 | running the Program is not restricted, and the output from the Program 96 | is covered only if its contents constitute a work based on the 97 | Program (independent of having been made by running the Program). 98 | Whether that is true depends on what the Program does. 99 | 100 | 1. You may copy and distribute verbatim copies of the Program's 101 | source code as you receive it, in any medium, provided that you 102 | conspicuously and appropriately publish on each copy an appropriate 103 | copyright notice and disclaimer of warranty; keep intact all the 104 | notices that refer to this License and to the absence of any warranty; 105 | and give any other recipients of the Program a copy of this License 106 | along with the Program. 107 | 108 | You may charge a fee for the physical act of transferring a copy, and 109 | you may at your option offer warranty protection in exchange for a fee. 110 | 111 | 2. You may modify your copy or copies of the Program or any portion 112 | of it, thus forming a work based on the Program, and copy and 113 | distribute such modifications or work under the terms of Section 1 114 | above, provided that you also meet all of these conditions: 115 | 116 | a) You must cause the modified files to carry prominent notices 117 | stating that you changed the files and the date of any change. 118 | 119 | b) You must cause any work that you distribute or publish, that in 120 | whole or in part contains or is derived from the Program or any 121 | part thereof, to be licensed as a whole at no charge to all third 122 | parties under the terms of this License. 123 | 124 | c) If the modified program normally reads commands interactively 125 | when run, you must cause it, when started running for such 126 | interactive use in the most ordinary way, to print or display an 127 | announcement including an appropriate copyright notice and a 128 | notice that there is no warranty (or else, saying that you provide 129 | a warranty) and that users may redistribute the program under 130 | these conditions, and telling the user how to view a copy of this 131 | License. (Exception: if the Program itself is interactive but 132 | does not normally print such an announcement, your work based on 133 | the Program is not required to print an announcement.) 134 | 135 | These requirements apply to the modified work as a whole. If 136 | identifiable sections of that work are not derived from the Program, 137 | and can be reasonably considered independent and separate works in 138 | themselves, then this License, and its terms, do not apply to those 139 | sections when you distribute them as separate works. But when you 140 | distribute the same sections as part of a whole which is a work based 141 | on the Program, the distribution of the whole must be on the terms of 142 | this License, whose permissions for other licensees extend to the 143 | entire whole, and thus to each and every part regardless of who wrote it. 144 | 145 | Thus, it is not the intent of this section to claim rights or contest 146 | your rights to work written entirely by you; rather, the intent is to 147 | exercise the right to control the distribution of derivative or 148 | collective works based on the Program. 149 | 150 | In addition, mere aggregation of another work not based on the Program 151 | with the Program (or with a work based on the Program) on a volume of 152 | a storage or distribution medium does not bring the other work under 153 | the scope of this License. 154 | 155 | 3. You may copy and distribute the Program (or a work based on it, 156 | under Section 2) in object code or executable form under the terms of 157 | Sections 1 and 2 above provided that you also do one of the following: 158 | 159 | a) Accompany it with the complete corresponding machine-readable 160 | source code, which must be distributed under the terms of Sections 161 | 1 and 2 above on a medium customarily used for software interchange; or, 162 | 163 | b) Accompany it with a written offer, valid for at least three 164 | years, to give any third party, for a charge no more than your 165 | cost of physically performing source distribution, a complete 166 | machine-readable copy of the corresponding source code, to be 167 | distributed under the terms of Sections 1 and 2 above on a medium 168 | customarily used for software interchange; or, 169 | 170 | c) Accompany it with the information you received as to the offer 171 | to distribute corresponding source code. (This alternative is 172 | allowed only for noncommercial distribution and only if you 173 | received the program in object code or executable form with such 174 | an offer, in accord with Subsection b above.) 175 | 176 | The source code for a work means the preferred form of the work for 177 | making modifications to it. For an executable work, complete source 178 | code means all the source code for all modules it contains, plus any 179 | associated interface definition files, plus the scripts used to 180 | control compilation and installation of the executable. However, as a 181 | special exception, the source code distributed need not include 182 | anything that is normally distributed (in either source or binary 183 | form) with the major components (compiler, kernel, and so on) of the 184 | operating system on which the executable runs, unless that component 185 | itself accompanies the executable. 186 | 187 | If distribution of executable or object code is made by offering 188 | access to copy from a designated place, then offering equivalent 189 | access to copy the source code from the same place counts as 190 | distribution of the source code, even though third parties are not 191 | compelled to copy the source along with the object code. 192 | 193 | 4. You may not copy, modify, sublicense, or distribute the Program 194 | except as expressly provided under this License. Any attempt 195 | otherwise to copy, modify, sublicense or distribute the Program is 196 | void, and will automatically terminate your rights under this License. 197 | However, parties who have received copies, or rights, from you under 198 | this License will not have their licenses terminated so long as such 199 | parties remain in full compliance. 200 | 201 | 5. You are not required to accept this License, since you have not 202 | signed it. However, nothing else grants you permission to modify or 203 | distribute the Program or its derivative works. These actions are 204 | prohibited by law if you do not accept this License. Therefore, by 205 | modifying or distributing the Program (or any work based on the 206 | Program), you indicate your acceptance of this License to do so, and 207 | all its terms and conditions for copying, distributing or modifying 208 | the Program or works based on it. 209 | 210 | 6. Each time you redistribute the Program (or any work based on the 211 | Program), the recipient automatically receives a license from the 212 | original licensor to copy, distribute or modify the Program subject to 213 | these terms and conditions. You may not impose any further 214 | restrictions on the recipients' exercise of the rights granted herein. 215 | You are not responsible for enforcing compliance by third parties to 216 | this License. 217 | 218 | 7. If, as a consequence of a court judgment or allegation of patent 219 | infringement or for any other reason (not limited to patent issues), 220 | conditions are imposed on you (whether by court order, agreement or 221 | otherwise) that contradict the conditions of this License, they do not 222 | excuse you from the conditions of this License. If you cannot 223 | distribute so as to satisfy simultaneously your obligations under this 224 | License and any other pertinent obligations, then as a consequence you 225 | may not distribute the Program at all. For example, if a patent 226 | license would not permit royalty-free redistribution of the Program by 227 | all those who receive copies directly or indirectly through you, then 228 | the only way you could satisfy both it and this License would be to 229 | refrain entirely from distribution of the Program. 230 | 231 | If any portion of this section is held invalid or unenforceable under 232 | any particular circumstance, the balance of the section is intended to 233 | apply and the section as a whole is intended to apply in other 234 | circumstances. 235 | 236 | It is not the purpose of this section to induce you to infringe any 237 | patents or other property right claims or to contest validity of any 238 | such claims; this section has the sole purpose of protecting the 239 | integrity of the free software distribution system, which is 240 | implemented by public license practices. Many people have made 241 | generous contributions to the wide range of software distributed 242 | through that system in reliance on consistent application of that 243 | system; it is up to the author/donor to decide if he or she is willing 244 | to distribute software through any other system and a licensee cannot 245 | impose that choice. 246 | 247 | This section is intended to make thoroughly clear what is believed to 248 | be a consequence of the rest of this License. 249 | 250 | 8. If the distribution and/or use of the Program is restricted in 251 | certain countries either by patents or by copyrighted interfaces, the 252 | original copyright holder who places the Program under this License 253 | may add an explicit geographical distribution limitation excluding 254 | those countries, so that distribution is permitted only in or among 255 | countries not thus excluded. In such case, this License incorporates 256 | the limitation as if written in the body of this License. 257 | 258 | 9. The Free Software Foundation may publish revised and/or new versions 259 | of the General Public License from time to time. Such new versions will 260 | be similar in spirit to the present version, but may differ in detail to 261 | address new problems or concerns. 262 | 263 | Each version is given a distinguishing version number. If the Program 264 | specifies a version number of this License which applies to it and "any 265 | later version", you have the option of following the terms and conditions 266 | either of that version or of any later version published by the Free 267 | Software Foundation. If the Program does not specify a version number of 268 | this License, you may choose any version ever published by the Free Software 269 | Foundation. 270 | 271 | 10. If you wish to incorporate parts of the Program into other free 272 | programs whose distribution conditions are different, write to the author 273 | to ask for permission. For software which is copyrighted by the Free 274 | Software Foundation, write to the Free Software Foundation; we sometimes 275 | make exceptions for this. Our decision will be guided by the two goals 276 | of preserving the free status of all derivatives of our free software and 277 | of promoting the sharing and reuse of software generally. 278 | 279 | NO WARRANTY 280 | 281 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 282 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 283 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 284 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 285 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 286 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 287 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 288 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 289 | REPAIR OR CORRECTION. 290 | 291 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 292 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 293 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 294 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 295 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 296 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 297 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 298 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 299 | POSSIBILITY OF SUCH DAMAGES. 300 | 301 | END OF TERMS AND CONDITIONS 302 | 303 | How to Apply These Terms to Your New Programs 304 | 305 | If you develop a new program, and you want it to be of the greatest 306 | possible use to the public, the best way to achieve this is to make it 307 | free software which everyone can redistribute and change under these terms. 308 | 309 | To do so, attach the following notices to the program. It is safest 310 | to attach them to the start of each source file to most effectively 311 | convey the exclusion of warranty; and each file should have at least 312 | the "copyright" line and a pointer to where the full notice is found. 313 | 314 | 315 | Copyright (C) 316 | 317 | This program is free software; you can redistribute it and/or modify 318 | it under the terms of the GNU General Public License as published by 319 | the Free Software Foundation; either version 2 of the License, or 320 | (at your option) any later version. 321 | 322 | This program is distributed in the hope that it will be useful, 323 | but WITHOUT ANY WARRANTY; without even the implied warranty of 324 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 325 | GNU General Public License for more details. 326 | 327 | You should have received a copy of the GNU General Public License 328 | along with this program; if not, write to the Free Software 329 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 330 | 331 | 332 | Also add information on how to contact you by electronic and paper mail. 333 | 334 | If the program is interactive, make it output a short notice like this 335 | when it starts in an interactive mode: 336 | 337 | Gnomovision version 69, Copyright (C) year name of author 338 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 339 | This is free software, and you are welcome to redistribute it 340 | under certain conditions; type `show c' for details. 341 | 342 | The hypothetical commands `show w' and `show c' should show the appropriate 343 | parts of the General Public License. Of course, the commands you use may 344 | be called something other than `show w' and `show c'; they could even be 345 | mouse-clicks or menu items--whatever suits your program. 346 | 347 | You should also get your employer (if you work as a programmer) or your 348 | school, if any, to sign a "copyright disclaimer" for the program, if 349 | necessary. Here is a sample; alter the names: 350 | 351 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 352 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 353 | 354 | , 1 April 1989 355 | Ty Coon, President of Vice 356 | 357 | This General Public License does not permit incorporating your program into 358 | proprietary programs. If your program is a subroutine library, you may 359 | consider it more useful to permit linking proprietary applications with the 360 | library. If this is what you want to do, use the GNU Library General 361 | Public License instead of this License. 362 | -------------------------------------------------------------------------------- /usbdrv/Readme.txt: -------------------------------------------------------------------------------- 1 | This is the Readme file to Objective Development's firmware-only USB driver 2 | for Atmel AVR microcontrollers. For more information please visit 3 | http://www.obdev.at/vusb/ 4 | 5 | This directory contains the USB firmware only. Copy it as-is to your own 6 | project and add all .c and .S files to your project (these files are marked 7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as 8 | usbconfig.h to your project and edit it according to your configuration. 9 | 10 | 11 | TECHNICAL DOCUMENTATION 12 | ======================= 13 | The technical documentation (API) for the firmware driver is contained in the 14 | file "usbdrv.h". Please read all of it carefully! Configuration options are 15 | documented in "usbconfig-prototype.h". 16 | 17 | The driver consists of the following files: 18 | Readme.txt ............. The file you are currently reading. 19 | Changelog.txt .......... Release notes for all versions of the driver. 20 | usbdrv.h ............... Driver interface definitions and technical docs. 21 | * usbdrv.c ............... High level language part of the driver. Link this 22 | module to your code! 23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly 24 | a stub and includes one of the usbdrvasm*.S files 25 | depending on processor clock. Link this module to 26 | your code! 27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies. 28 | Included by usbdrvasm.S, don't link it directly! 29 | asmcommon.inc .......... Common assembler routines. Included by 30 | usbdrvasm*.inc, don't link it directly! 31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file. 32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is 33 | defined to a value greater than 0. Link this module 34 | to your code! 35 | oddebug.h .............. Interface definitions of the debug module. 36 | usbportability.h ....... Header with compiler-dependent stuff. 37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this 38 | module instead of usbdrvasm.S when you assembler 39 | with IAR's tools. 40 | License.txt ............ Open Source license for this driver. 41 | CommercialLicense.txt .. Optional commercial license for this driver. 42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs. 43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs. 44 | 45 | (*) ... These files should be linked to your project. 46 | 47 | 48 | CPU CORE CLOCK FREQUENCY 49 | ======================== 50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz, 51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The 52 | actual clock rate must be configured in usbconfig.h. 53 | 54 | 12 MHz Clock 55 | This is the traditional clock rate of V-USB because it's the lowest clock 56 | rate where the timing constraints of the USB spec can be met. 57 | 58 | 15 MHz Clock 59 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock 60 | rate allows for some loops which make the resulting code size somewhat smaller 61 | than the 12 MHz version. 62 | 63 | 16 MHz Clock 64 | This clock rate has been added for users of the Arduino board and other 65 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option 66 | if you need the slightly higher clock rate for performance reasons. Since 67 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 68 | is somewhat tricky and has to insert a leap cycle every third byte. 69 | 70 | 12.8 MHz and 16.5 MHz Clock 71 | The assembler modules for these clock rates differ from the other modules 72 | because they have been built for an RC oscillator with only 1% precision. The 73 | receiver code inserts leap cycles to compensate for clock deviations. 1% is 74 | also the precision which can be achieved by calibrating the internal RC 75 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL 76 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very 77 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost 78 | all AVRs can reach 12.8 MHz, although this is outside the specified range. 79 | 80 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for 81 | code which calibrates the RC oscillator based on the USB frame clock. 82 | 83 | 18 MHz Clock 84 | This module is closer to the USB specification because it performs an on the 85 | fly CRC check for incoming packets. Packets with invalid checksum are 86 | discarded as required by the spec. If you also implement checks for data 87 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING 88 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC 89 | tables and alignment requirements, this code is bigger than modules for other 90 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1 91 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h. 92 | 93 | 20 MHz Clock 94 | This module is for people who won't do it with less than the maximum. Since 95 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 96 | uses similar tricks as the 16 MHz module to insert leap cycles. 97 | 98 | 99 | USB IDENTIFIERS 100 | =============== 101 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs 102 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you 103 | can assign PIDs at will. 104 | 105 | Since an entry level cost of 1,500 USD is too high for most small companies 106 | and hobbyists, we provide some VID/PID pairs for free. See the file 107 | USB-IDs-for-free.txt for details. 108 | 109 | Objective Development also has some license offerings which include product 110 | IDs. See http://www.obdev.at/vusb/ for details. 111 | 112 | 113 | DEVELOPMENT SYSTEM 114 | ================== 115 | This driver has been developed and optimized for the GNU compiler version 3 116 | and 4. We recommend that you use the GNU compiler suite because it is freely 117 | available. V-USB has also been ported to the IAR compiler and assembler. It 118 | has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the 119 | "small" and "tiny" memory model. Not every release is tested with IAR CC and 120 | the driver may therefore fail to compile with IAR. Please note that gcc is 121 | more efficient for usbdrv.c because this module has been deliberately 122 | optimized for gcc. 123 | 124 | Gcc version 3 produces smaller code than version 4 due to new optimizing 125 | capabilities which don't always improve things on 8 bit CPUs. The code size 126 | generated by gcc 4 can be reduced with the compiler options 127 | -fno-move-loop-invariants, -fno-tree-scev-cprop and 128 | -fno-inline-small-functions in addition to -Os. On devices with more than 129 | 8k of flash memory, we also recommend the linker option --relax (written as 130 | -Wl,--relax for gcc) to convert absolute calls into relative where possible. 131 | 132 | For more information about optimizing options see: 133 | 134 | http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html 135 | 136 | These optimizations are good for gcc 4.x. Version 3.x of gcc does not support 137 | most of these options and produces good code anyway. 138 | 139 | 140 | USING V-USB FOR FREE 141 | ==================== 142 | The AVR firmware driver is published under the GNU General Public License 143 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is 144 | your choice whether you apply the terms of version 2 or version 3. 145 | 146 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the 147 | following things IN ADDITION to the obligations from the GPL: 148 | 149 | (1) Publish your entire project on a web site and drop us a note with the URL. 150 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission. 151 | If you don't have a web site, you can publish the project in obdev's 152 | documentation wiki at 153 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects. 154 | 155 | (2) Adhere to minimum publication standards. Please include AT LEAST: 156 | - a circuit diagram in PDF, PNG or GIF format 157 | - full source code for the host software 158 | - a Readme.txt file in ASCII format which describes the purpose of the 159 | project and what can be found in which directories and which files 160 | - a reference to http://www.obdev.at/vusb/ 161 | 162 | (3) If you improve the driver firmware itself, please give us a free license 163 | to your modifications for our commercial license offerings. 164 | 165 | 166 | COMMERCIAL LICENSES FOR V-USB 167 | ============================= 168 | If you don't want to publish your source code under the terms of the GPL, 169 | you can simply pay money for V-USB. As an additional benefit you get 170 | USB PIDs for free, reserved exclusively to you. See the file 171 | "CommercialLicense.txt" for details. 172 | 173 | -------------------------------------------------------------------------------- /usbdrv/USB-ID-FAQ.txt: -------------------------------------------------------------------------------- 1 | Version 2012-07-09 2 | 3 | ========================== 4 | WHY DO WE NEED THESE IDs? 5 | ========================== 6 | 7 | USB is more than a low level protocol for data transport. It also defines a 8 | common set of requests which must be understood by all devices. And as part 9 | of these common requests, the specification defines data structures, the 10 | USB Descriptors, which are used to describe the properties of the device. 11 | 12 | From the perspective of an operating system, it is therefore possible to find 13 | out basic properties of a device (such as e.g. the manufacturer and the name 14 | of the device) without a device-specific driver. This is essential because 15 | the operating system can choose a driver to load based on this information 16 | (Plug-And-Play). 17 | 18 | Among the most important properties in the Device Descriptor are the USB 19 | Vendor- and Product-ID. Both are 16 bit integers. The most simple form of 20 | driver matching is based on these IDs. The driver announces the Vendor- and 21 | Product-IDs of the devices it can handle and the operating system loads the 22 | appropriate driver when the device is connected. 23 | 24 | It is obvious that this technique only works if the pair Vendor- plus 25 | Product-ID is unique: Only devices which require the same driver can have the 26 | same pair of IDs. 27 | 28 | 29 | ===================================================== 30 | HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? 31 | ===================================================== 32 | 33 | Since it is so important that USB IDs are unique, the USB Implementers Forum, 34 | Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by 35 | law to build a device and assign it any random numbers as IDs. Usb.org 36 | therefore needs an agreement to regulate the use of USB IDs. The agreement 37 | binds only parties who agreed to it, of course. Everybody else is free to use 38 | any numbers for their IDs. 39 | 40 | So how can usb.org ensure that every manufacturer of USB devices enters into 41 | an agreement with them? They do it via trademark licensing. Usb.org has 42 | registered the trademark "USB", all associated logos and related terms. If 43 | you want to put an USB logo on your product or claim that it is USB 44 | compliant, you must license these trademarks from usb.org. And this is where 45 | you enter into an agreement. See the "USB-IF Trademark License Agreement and 46 | Usage Guidelines for the USB-IF Logo" at 47 | http://www.usb.org/developers/logo_license/. 48 | 49 | Licensing the USB trademarks requires that you buy a USB Vendor-ID from 50 | usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org 51 | (yearly fee of ca. 4,000 USD) and that you meet all the technical 52 | specifications from the USB spec. 53 | 54 | This means that most hobbyists and small companies will never be able to 55 | become USB compliant, just because membership is so expensive. And you can't 56 | be compliant with a driver based on V-USB anyway, because the AVR's port pins 57 | don't meet the electrical specifications for USB. So, in principle, all 58 | hobbyists and small companies are free to choose any random numbers for their 59 | IDs. They have nothing to lose... 60 | 61 | There is one exception worth noting, though: If you use a sub-component which 62 | implements USB, the vendor of the sub-components may guarantee USB 63 | compliance. This might apply to some or all of FTDI's solutions. 64 | 65 | 66 | ======================================================================= 67 | WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? 68 | ======================================================================= 69 | 70 | You have learned in the previous section that you are free to choose any 71 | numbers for your IDs anyway. So why not do exactly this? There is still the 72 | technical issue. If you choose IDs which are already in use by somebody else, 73 | operating systems will load the wrong drivers and your device won't work. 74 | Even if you choose IDs which are not currently in use, they may be in use in 75 | the next version of the operating system or even after an automatic update. 76 | 77 | So what you need is a pair of Vendor- and Product-IDs for which you have the 78 | guarantee that no USB compliant product uses them. This implies that no 79 | operating system will ever ship with drivers responsible for these IDs. 80 | 81 | 82 | ============================================== 83 | HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? 84 | ============================================== 85 | 86 | Objective Development gives away pairs of USB-IDs with their V-USB licenses. 87 | In order to ensure that these IDs are unique, Objective Development has an 88 | agreement with the company/person who has bought the USB Vendor-ID from 89 | usb.org. This agreement ensures that a range of USB Product-IDs is reserved 90 | for assignment by Objective Development and that the owner of the Vendor-ID 91 | won't give it to anybody else. 92 | 93 | This means that you have to trust three parties to ensure uniqueness of 94 | your IDs: 95 | 96 | - Objective Development, that they don't give the same PID to more than 97 | one person. 98 | - The owner of the Vendor-ID that they don't assign PIDs from the range 99 | assigned to Objective Development to anybody else. 100 | - Usb.org that they don't assign the same Vendor-ID a second time. 101 | 102 | 103 | ================================== 104 | WHO IS THE OWNER OF THE VENDOR-ID? 105 | ================================== 106 | 107 | Objective Development has obtained ranges of USB Product-IDs under two 108 | Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen 109 | Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason 110 | Kotzin (now flirc.tv, Inc.). Both VID owners have received their Vendor-ID 111 | directly from usb.org. 112 | 113 | 114 | ========================================================================= 115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? 116 | ========================================================================= 117 | 118 | The short answer is: Yes. All you get is a guarantee that the IDs are never 119 | assigned to anybody else. What more do you need? 120 | 121 | 122 | ============================ 123 | WHAT ABOUT SHARED ID PAIRS? 124 | ============================ 125 | 126 | Objective Development has reserved some PID/VID pairs for shared use. You 127 | have no guarantee of uniqueness for them, except that no USB compliant device 128 | uses them. In order to avoid technical problems, we must ensure that all 129 | devices with the same pair of IDs use the same driver on kernel level. For 130 | details, see the file USB-IDs-for-free.txt. 131 | 132 | 133 | ====================================================== 134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? 135 | ====================================================== 136 | 137 | A 16 bit integer number cannot be protected by copyright laws. It is not 138 | sufficiently complex. And since none of the parties involved entered into the 139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So 140 | there is no reason why it should be illegal to sub-license USB-IDs. 141 | 142 | 143 | ============================================= 144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? 145 | ============================================= 146 | 147 | Objective Development disclaims all liabilities which might arise from the 148 | assignment of IDs. If you guarantee product features to your customers 149 | without proper disclaimer, YOU are liable for that. 150 | -------------------------------------------------------------------------------- /usbdrv/USB-IDs-for-free.txt: -------------------------------------------------------------------------------- 1 | Version 2009-08-22 2 | 3 | =========================== 4 | FREE USB-IDs FOR SHARED USE 5 | =========================== 6 | 7 | Objective Development has reserved a set of USB Product-IDs for use according 8 | to the guidelines outlined below. For more information about the concept of 9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees 10 | that the IDs listed below are not used by any USB compliant devices. 11 | 12 | 13 | ==================== 14 | MECHANISM OF SHARING 15 | ==================== 16 | 17 | From a technical point of view, two different devices can share the same USB 18 | Vendor- and Product-ID if they require the same driver on operating system 19 | level. We make use of this fact by assigning separate IDs for various device 20 | classes. On application layer, devices must be distinguished by their textual 21 | name or serial number. We offer separate sets of IDs for discrimination by 22 | textual name and for serial number. 23 | 24 | Examples for shared use of USB IDs are included with V-USB in the "examples" 25 | subdirectory. 26 | 27 | 28 | ====================================== 29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME 30 | ====================================== 31 | 32 | If you use one of the IDs listed below, your device and host-side software 33 | must conform to these rules: 34 | 35 | (1) The USB device MUST provide a textual representation of the manufacturer 36 | and product identification. The manufacturer identification MUST be available 37 | at least in USB language 0x0409 (English/US). 38 | 39 | (2) The textual manufacturer identification MUST contain either an Internet 40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail 41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain 42 | name or e-mail address in any string you like, e.g. "Objective Development 43 | http://www.obdev.at/vusb/". 44 | 45 | (3) You are responsible for retaining ownership of the domain or e-mail 46 | address for as long as any of your products are in use. 47 | 48 | (4) You may choose any string for the textual product identification, as long 49 | as this string is unique within the scope of your textual manufacturer 50 | identification. 51 | 52 | (5) Application side device look-up MUST be based on the textual manufacturer 53 | and product identification in addition to VID/PID matching. The driver 54 | matching MUST be a comparison of the entire strings, NOT a sub-string match. 55 | 56 | (6) For devices which implement a particular USB device class (e.g. HID), the 57 | operating system's default class driver MUST be used. If an operating system 58 | driver for Vendor Class devices is needed, this driver must be libusb or 59 | libusb-win32 (see http://libusb.org/ and 60 | http://libusb-win32.sourceforge.net/). 61 | 62 | Table if IDs for discrimination by textual name: 63 | 64 | PID dec (hex) | VID dec (hex) | Description of use 65 | ==============+===============+============================================ 66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb 67 | --------------+---------------+-------------------------------------------- 68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are 69 | | | NOT mice, keyboards or joysticks) 70 | --------------+---------------+-------------------------------------------- 71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 72 | --------------+---------------+-------------------------------------------- 73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices 74 | --------------+---------------+-------------------------------------------- 75 | 76 | Note that Windows caches the textual product- and vendor-description for 77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not 78 | recommended for these device classes. 79 | 80 | 81 | ======================================= 82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER 83 | ======================================= 84 | 85 | If you use one of the IDs listed below, your device and host-side software 86 | must conform to these rules: 87 | 88 | (1) The USB device MUST provide a textual representation of the serial 89 | number, unless ONLY the operating system's default class driver is used. 90 | The serial number string MUST be available at least in USB language 0x0409 91 | (English/US). 92 | 93 | (2) The serial number MUST start with either an Internet domain name (e.g. 94 | "mycompany.com") registered and owned by you, or an e-mail address under your 95 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. 96 | You MAY append any string you like for further discrimination of your devices. 97 | 98 | (3) You are responsible for retaining ownership of the domain or e-mail 99 | address for as long as any of your products are in use. 100 | 101 | (5) Application side device look-up MUST be based on the serial number string 102 | in addition to VID/PID matching. The matching must start at the first 103 | character of the serial number string and include the colon character 104 | terminating your domain or e-mail address. It MAY stop anywhere after that. 105 | 106 | (6) For devices which implement a particular USB device class (e.g. HID), the 107 | operating system's default class driver MUST be used. If an operating system 108 | driver for Vendor Class devices is needed, this driver must be libusb or 109 | libusb-win32 (see http://libusb.org/ and 110 | http://libusb-win32.sourceforge.net/). 111 | 112 | (7) If ONLY the operating system's default class driver is used, e.g. for 113 | mice, keyboards, joysticks, CDC or MIDI devices and no discrimination by an 114 | application is needed, the serial number may be omitted. 115 | 116 | 117 | Table if IDs for discrimination by serial number string: 118 | 119 | PID dec (hex) | VID dec (hex) | Description of use 120 | ===============+===============+=========================================== 121 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb 122 | ---------------+---------------+------------------------------------------- 123 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are 124 | | | NOT mice, keyboards or joysticks) 125 | ---------------+---------------+------------------------------------------- 126 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice 127 | ---------------+---------------+------------------------------------------- 128 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards 129 | ---------------+---------------+------------------------------------------- 130 | 10204 (0x27dc) | 5824 (0x16c0) | For USB Joysticks 131 | ---------------+---------------+------------------------------------------- 132 | 10205 (0x27dd) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 133 | ---------------+---------------+------------------------------------------- 134 | 10206 (0x27de) | 5824 (0x16c0) | For MIDI class devices 135 | ---------------+---------------+------------------------------------------- 136 | 137 | 138 | ================= 139 | ORIGIN OF USB-IDs 140 | ================= 141 | 142 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed 143 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. 144 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. 145 | (see www.usb.org). The VID is registered for the company name "Van Ooijen 146 | Technische Informatica". 147 | 148 | 149 | ========== 150 | DISCLAIMER 151 | ========== 152 | 153 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any 154 | problems which are caused by the shared use of these VID/PID pairs. 155 | -------------------------------------------------------------------------------- /usbdrv/asmcommon.inc: -------------------------------------------------------------------------------- 1 | /* Name: asmcommon.inc 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-11-05 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | /* Do not link this file! Link usbdrvasm.S instead, which includes the 11 | * appropriate implementation! 12 | */ 13 | 14 | /* 15 | General Description: 16 | This file contains assembler code which is shared among the USB driver 17 | implementations for different CPU cocks. Since the code must be inserted 18 | in the middle of the module, it's split out into this file and #included. 19 | 20 | Jump destinations called from outside: 21 | sofError: Called when no start sequence was found. 22 | se0: Called when a package has been successfully received. 23 | overflow: Called when receive buffer overflows. 24 | doReturn: Called after sending data. 25 | 26 | Outside jump destinations used by this module: 27 | waitForJ: Called to receive an already arriving packet. 28 | sendAckAndReti: 29 | sendNakAndReti: 30 | sendCntAndReti: 31 | usbSendAndReti: 32 | 33 | The following macros must be defined before this file is included: 34 | .macro POP_STANDARD 35 | .endm 36 | .macro POP_RETI 37 | .endm 38 | */ 39 | 40 | #define token x1 41 | 42 | overflow: 43 | ldi x2, 1< 0 14 | 15 | #warning "Never compile production devices with debugging enabled" 16 | 17 | static void uartPutc(char c) { 18 | while (!(ODDBG_USR & (1 << ODDBG_UDRE))) 19 | ; /* wait for data register empty */ 20 | ODDBG_UDR = c; 21 | } 22 | 23 | static uchar hexAscii(uchar h) { 24 | h &= 0xf; 25 | if (h >= 10) 26 | h += 'a' - (uchar)10 - '0'; 27 | h += '0'; 28 | return h; 29 | } 30 | 31 | static void printHex(uchar c) { 32 | uartPutc(hexAscii(c >> 4)); 33 | uartPutc(hexAscii(c)); 34 | } 35 | 36 | void odDebug(uchar prefix, uchar *data, uchar len) { 37 | printHex(prefix); 38 | uartPutc(':'); 39 | while (len--) { 40 | uartPutc(' '); 41 | printHex(*data++); 42 | } 43 | uartPutc('\r'); 44 | uartPutc('\n'); 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /usbdrv/oddebug.h: -------------------------------------------------------------------------------- 1 | /* Name: oddebug.h 2 | * Project: AVR library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2005-01-16 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 8 | * (CommercialLicense.txt) 9 | */ 10 | 11 | #ifndef __oddebug_h_included__ 12 | #define __oddebug_h_included__ 13 | 14 | /* 15 | General Description: 16 | This module implements a function for debug logs on the serial line of the 17 | AVR microcontroller. Debugging can be configured with the define 18 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging 19 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is 20 | 2, DBG1 and DBG2 logs will be printed. 21 | 22 | A debug log consists of a label ('prefix') to indicate which debug log created 23 | the output and a memory block to dump in hex ('data' and 'len'). 24 | */ 25 | 26 | #ifndef F_CPU 27 | #define F_CPU 12000000 /* 12 MHz */ 28 | #endif 29 | 30 | /* make sure we have the UART defines: */ 31 | #include "usbportability.h" 32 | 33 | #ifndef uchar 34 | #define uchar unsigned char 35 | #endif 36 | 37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device \ 38 | */ 39 | #warning "Debugging disabled because device has no UART" 40 | #undef DEBUG_LEVEL 41 | #endif 42 | 43 | #ifndef DEBUG_LEVEL 44 | #define DEBUG_LEVEL 0 45 | #endif 46 | 47 | /* ------------------------------------------------------------------------- */ 48 | 49 | #if DEBUG_LEVEL > 0 50 | #define DBG1(prefix, data, len) odDebug(prefix, data, len) 51 | #else 52 | #define DBG1(prefix, data, len) 53 | #endif 54 | 55 | #if DEBUG_LEVEL > 1 56 | #define DBG2(prefix, data, len) odDebug(prefix, data, len) 57 | #else 58 | #define DBG2(prefix, data, len) 59 | #endif 60 | 61 | /* ------------------------------------------------------------------------- */ 62 | 63 | #if DEBUG_LEVEL > 0 64 | extern void odDebug(uchar prefix, uchar *data, uchar len); 65 | 66 | /* Try to find our control registers; ATMEL likes to rename these */ 67 | 68 | #if defined UBRR 69 | #define ODDBG_UBRR UBRR 70 | #elif defined UBRRL 71 | #define ODDBG_UBRR UBRRL 72 | #elif defined UBRR0 73 | #define ODDBG_UBRR UBRR0 74 | #elif defined UBRR0L 75 | #define ODDBG_UBRR UBRR0L 76 | #endif 77 | 78 | #if defined UCR 79 | #define ODDBG_UCR UCR 80 | #elif defined UCSRB 81 | #define ODDBG_UCR UCSRB 82 | #elif defined UCSR0B 83 | #define ODDBG_UCR UCSR0B 84 | #endif 85 | 86 | #if defined TXEN 87 | #define ODDBG_TXEN TXEN 88 | #else 89 | #define ODDBG_TXEN TXEN0 90 | #endif 91 | 92 | #if defined USR 93 | #define ODDBG_USR USR 94 | #elif defined UCSRA 95 | #define ODDBG_USR UCSRA 96 | #elif defined UCSR0A 97 | #define ODDBG_USR UCSR0A 98 | #endif 99 | 100 | #if defined UDRE 101 | #define ODDBG_UDRE UDRE 102 | #else 103 | #define ODDBG_UDRE UDRE0 104 | #endif 105 | 106 | #if defined UDR 107 | #define ODDBG_UDR UDR 108 | #elif defined UDR0 109 | #define ODDBG_UDR UDR0 110 | #endif 111 | 112 | static inline void odDebugInit(void) { 113 | ODDBG_UCR |= (1 << ODDBG_TXEN); 114 | ODDBG_UBRR = F_CPU / (19200 * 16L) - 1; 115 | } 116 | #else 117 | #define odDebugInit() 118 | #endif 119 | 120 | /* ------------------------------------------------------------------------- */ 121 | 122 | #endif /* __oddebug_h_included__ */ 123 | -------------------------------------------------------------------------------- /usbdrv/usbdrv.c: -------------------------------------------------------------------------------- 1 | /* Name: usbdrv.c 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2004-12-29 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 8 | * (CommercialLicense.txt) 9 | */ 10 | 11 | #include "usbdrv.h" 12 | #include "oddebug.h" 13 | 14 | /* 15 | General Description: 16 | This module implements the C-part of the USB driver. See usbdrv.h for a 17 | documentation of the entire driver. 18 | */ 19 | 20 | /* ------------------------------------------------------------------------- */ 21 | 22 | /* raw USB registers / interface to assembler code: */ 23 | uchar usbRxBuf[2 * 24 | USB_BUFSIZE]; /* raw RX buffer: PID, 8 bytes data, 2 bytes CRC */ 25 | uchar usbInputBufOffset; /* offset in usbRxBuf used for low level receiving */ 26 | uchar usbDeviceAddr; /* assigned during enumeration, defaults to 0 */ 27 | uchar usbNewDeviceAddr; /* device ID which should be set after status phase */ 28 | uchar usbConfiguration; /* currently selected configuration. Administered by 29 | driver, but not used */ 30 | volatile schar usbRxLen; /* = 0; number of bytes in usbRxBuf; 0 means free, -1 31 | for flow control */ 32 | uchar usbCurrentTok; /* last token received or endpoint number for last OUT 33 | token if != 0 */ 34 | uchar 35 | usbRxToken; /* token for data we received; or endpont number for last OUT */ 36 | volatile uchar usbTxLen = USBPID_NAK; /* number of bytes to transmit with next 37 | IN token or handshake token */ 38 | uchar usbTxBuf[USB_BUFSIZE]; /* data to transmit with next IN, free if usbTxLen 39 | contains handshake token */ 40 | #if USB_COUNT_SOF 41 | volatile uchar usbSofCount; /* incremented by assembler module every SOF */ 42 | #endif 43 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE 44 | usbTxStatus_t usbTxStatus1; 45 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 46 | usbTxStatus_t usbTxStatus3; 47 | #endif 48 | #endif 49 | #if USB_CFG_CHECK_DATA_TOGGLING 50 | uchar usbCurrentDataToken; /* when we check data toggling to ignore duplicate 51 | packets */ 52 | #endif 53 | 54 | /* USB status registers / not shared with asm code */ 55 | usbMsgPtr_t usbMsgPtr; /* data to transmit next -- ROM or RAM address */ 56 | static usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */ 57 | static uchar usbMsgFlags; /* flag values see below */ 58 | 59 | #define USB_FLG_MSGPTR_IS_ROM (1 << 6) 60 | #define USB_FLG_USE_USER_RW (1 << 7) 61 | 62 | /* 63 | optimizing hints: 64 | - do not post/pre inc/dec integer values in operations 65 | - assign value of USB_READ_FLASH() to register variables and don't use side 66 | effects in arg 67 | - use narrow scope for variables which should be in X/Y/Z register 68 | - assign char sized expressions to variables to force 8 bit arithmetics 69 | */ 70 | 71 | /* -------------------------- String Descriptors --------------------------- */ 72 | 73 | #if USB_CFG_DESCR_PROPS_STRINGS == 0 74 | 75 | #if USB_CFG_DESCR_PROPS_STRING_0 == 0 76 | #undef USB_CFG_DESCR_PROPS_STRING_0 77 | #define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) 78 | PROGMEM const char usbDescriptorString0[] = { 79 | /* language descriptor */ 80 | 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ 81 | 3, /* descriptor type */ 82 | 0x09, 0x04, /* language index (0x0409 = US-English) */ 83 | }; 84 | #endif 85 | 86 | #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN 87 | #undef USB_CFG_DESCR_PROPS_STRING_VENDOR 88 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) 89 | PROGMEM const int usbDescriptorStringVendor[] = { 90 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME}; 91 | #endif 92 | 93 | #if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN 94 | #undef USB_CFG_DESCR_PROPS_STRING_PRODUCT 95 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) 96 | PROGMEM const int usbDescriptorStringDevice[] = { 97 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME}; 98 | #endif 99 | 100 | #if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN 101 | #undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 102 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER \ 103 | sizeof(usbDescriptorStringSerialNumber) 104 | PROGMEM const int usbDescriptorStringSerialNumber[] = { 105 | USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), 106 | USB_CFG_SERIAL_NUMBER}; 107 | #endif 108 | 109 | #endif /* USB_CFG_DESCR_PROPS_STRINGS == 0 */ 110 | 111 | /* --------------------------- Device Descriptor --------------------------- */ 112 | 113 | #if USB_CFG_DESCR_PROPS_DEVICE == 0 114 | #undef USB_CFG_DESCR_PROPS_DEVICE 115 | #define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) 116 | PROGMEM const char usbDescriptorDevice[] = { 117 | /* USB device descriptor */ 118 | 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ 119 | USBDESCR_DEVICE, /* descriptor type */ 120 | 0x01, 0x01, /* USB version supported */ 121 | USB_CFG_DEVICE_CLASS, USB_CFG_DEVICE_SUBCLASS, 0, /* protocol */ 122 | 8, /* max packet size */ 123 | /* the following two casts affect the first byte of the constant only, but 124 | * that's sufficient to avoid a warning with the default values. 125 | */ 126 | (char)USB_CFG_VENDOR_ID, /* 2 bytes */ 127 | (char)USB_CFG_DEVICE_ID, /* 2 bytes */ 128 | USB_CFG_DEVICE_VERSION, /* 2 bytes */ 129 | USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 130 | : 0, /* manufacturer string index */ 131 | USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0, /* product string index */ 132 | USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 133 | ? 3 134 | : 0, /* serial number string index */ 135 | 1, /* number of configurations */ 136 | }; 137 | #endif 138 | 139 | /* ----------------------- Configuration Descriptor ------------------------ */ 140 | 141 | #if USB_CFG_DESCR_PROPS_HID_REPORT != 0 && USB_CFG_DESCR_PROPS_HID == 0 142 | #undef USB_CFG_DESCR_PROPS_HID 143 | #define USB_CFG_DESCR_PROPS_HID \ 144 | 9 /* length of HID descriptor in config descriptor below */ 145 | #endif 146 | 147 | #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 148 | #undef USB_CFG_DESCR_PROPS_CONFIGURATION 149 | #define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration) 150 | PROGMEM const char usbDescriptorConfiguration[] = { 151 | /* USB configuration descriptor */ 152 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ 153 | USBDESCR_CONFIG, /* descriptor type */ 154 | 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 155 | (USB_CFG_DESCR_PROPS_HID & 0xff), 156 | 0, 157 | /* total length of data returned (including inlined descriptors) */ 158 | 1, /* number of interfaces in this configuration */ 159 | 1, /* index of this configuration */ 160 | 0, /* configuration name string index */ 161 | #if USB_CFG_IS_SELF_POWERED 162 | (1 << 7) | USBATTR_SELFPOWER, /* attributes */ 163 | #else 164 | (1 << 7), /* attributes */ 165 | #endif 166 | USB_CFG_MAX_BUS_POWER / 2, /* max USB current in 2mA units */ 167 | /* interface descriptor follows inline: */ 168 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */ 169 | USBDESCR_INTERFACE, /* descriptor type */ 170 | 0, /* index of this interface */ 171 | 0, /* alternate setting for this interface */ 172 | USB_CFG_HAVE_INTRIN_ENDPOINT + 173 | USB_CFG_HAVE_INTRIN_ENDPOINT3, /* endpoints excl 0: number of endpoint 174 | descriptors to follow */ 175 | USB_CFG_INTERFACE_CLASS, USB_CFG_INTERFACE_SUBCLASS, 176 | USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */ 177 | #if (USB_CFG_DESCR_PROPS_HID & 0xff) /* HID descriptor */ 178 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ 179 | USBDESCR_HID, /* descriptor type: HID */ 180 | 0x01, 0x01, /* BCD representation of HID version */ 181 | 0x00, /* target country code */ 182 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to 183 | follow */ 184 | 0x22, /* descriptor type: report */ 185 | USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 186 | 0, /* total length of report descriptor */ 187 | #endif 188 | #if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ 189 | 7, /* sizeof(usbDescrEndpoint) */ 190 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ 191 | (char)0x81, /* IN endpoint number 1 */ 192 | 0x03, /* attrib: Interrupt endpoint */ 193 | 8, 0, /* maximum packet size */ 194 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ 195 | #endif 196 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ 197 | 7, /* sizeof(usbDescrEndpoint) */ 198 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */ 199 | (char)(0x80 | USB_CFG_EP3_NUMBER), /* IN endpoint number 3 */ 200 | 0x03, /* attrib: Interrupt endpoint */ 201 | 8, 0, /* maximum packet size */ 202 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */ 203 | #endif 204 | }; 205 | #endif 206 | 207 | /* ------------------------------------------------------------------------- */ 208 | 209 | static inline void usbResetDataToggling(void) { 210 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE 211 | USB_SET_DATATOKEN1( 212 | USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ 213 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 214 | USB_SET_DATATOKEN3( 215 | USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */ 216 | #endif 217 | #endif 218 | } 219 | 220 | static inline void usbResetStall(void) { 221 | #if USB_CFG_IMPLEMENT_HALT && USB_CFG_HAVE_INTRIN_ENDPOINT 222 | usbTxLen1 = USBPID_NAK; 223 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 224 | usbTxLen3 = USBPID_NAK; 225 | #endif 226 | #endif 227 | } 228 | 229 | /* ------------------------------------------------------------------------- */ 230 | 231 | #if !USB_CFG_SUPPRESS_INTR_CODE 232 | #if USB_CFG_HAVE_INTRIN_ENDPOINT 233 | static void usbGenericSetInterrupt(uchar *data, uchar len, 234 | usbTxStatus_t *txStatus) { 235 | uchar *p; 236 | char i; 237 | 238 | #if USB_CFG_IMPLEMENT_HALT 239 | if (usbTxLen1 == USBPID_STALL) 240 | return; 241 | #endif 242 | if (txStatus->len & 0x10) { /* packet buffer was empty */ 243 | txStatus->buffer[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ 244 | } else { 245 | txStatus->len = 246 | USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ 247 | } 248 | p = txStatus->buffer + 1; 249 | i = len; 250 | do { /* if len == 0, we still copy 1 byte, but that's no problem */ 251 | *p++ = *data++; 252 | } while ( 253 | --i > 254 | 0); /* loop control at the end is 2 bytes shorter than at beginning */ 255 | usbCrc16Append(&txStatus->buffer[1], len); 256 | txStatus->len = len + 4; /* len must be given including sync byte */ 257 | DBG2(0x21 + (((int)txStatus >> 3) & 3), txStatus->buffer, len + 3); 258 | } 259 | 260 | USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len) { 261 | usbGenericSetInterrupt(data, len, &usbTxStatus1); 262 | } 263 | #endif 264 | 265 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 266 | USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len) { 267 | usbGenericSetInterrupt(data, len, &usbTxStatus3); 268 | } 269 | #endif 270 | #endif /* USB_CFG_SUPPRESS_INTR_CODE */ 271 | 272 | /* ------------------ utilities for code following below ------------------- */ 273 | 274 | /* Use defines for the switch statement so that we can choose between an 275 | * if()else if() and a switch/case based implementation. switch() is more 276 | * efficient for a LARGE set of sequential choices, if() is better in all other 277 | * cases. 278 | */ 279 | #if USB_CFG_USE_SWITCH_STATEMENT 280 | #define SWITCH_START(cmd) \ 281 | switch (cmd) { \ 282 | { 283 | #define SWITCH_CASE(value) \ 284 | } \ 285 | break; \ 286 | case (value): { 287 | #define SWITCH_CASE2(v1, v2) \ 288 | } \ 289 | break; \ 290 | case (v1): \ 291 | case (v2): { 292 | #define SWITCH_CASE3(v1, v2, v3) \ 293 | } \ 294 | break; \ 295 | case (v1): \ 296 | case (v2): \ 297 | case (v3): { 298 | #define SWITCH_DEFAULT \ 299 | } \ 300 | break; \ 301 | default: { 302 | #define SWITCH_END \ 303 | } \ 304 | } 305 | #else 306 | #define SWITCH_START(cmd) \ 307 | { \ 308 | uchar _cmd = cmd; \ 309 | if (0) { 310 | #define SWITCH_CASE(value) \ 311 | } \ 312 | else if (_cmd == (value)) { 313 | #define SWITCH_CASE2(v1, v2) \ 314 | } \ 315 | else if (_cmd == (v1) || _cmd == (v2)) { 316 | #define SWITCH_CASE3(v1, v2, v3) \ 317 | } \ 318 | else if (_cmd == (v1) || _cmd == (v2) || (_cmd == v3)) { 319 | #define SWITCH_DEFAULT \ 320 | } \ 321 | else { 322 | #define SWITCH_END \ 323 | } \ 324 | } 325 | #endif 326 | 327 | #ifndef USB_RX_USER_HOOK 328 | #define USB_RX_USER_HOOK(data, len) 329 | #endif 330 | #ifndef USB_SET_ADDRESS_HOOK 331 | #define USB_SET_ADDRESS_HOOK() 332 | #endif 333 | 334 | /* ------------------------------------------------------------------------- */ 335 | 336 | /* We use if() instead of #if in the macro below because #if can't be used 337 | * in macros and the compiler optimizes constant conditions anyway. 338 | * This may cause problems with undefined symbols if compiled without 339 | * optimizing! 340 | */ 341 | #define GET_DESCRIPTOR(cfgProp, staticName) \ 342 | if (cfgProp) { \ 343 | if ((cfgProp)&USB_PROP_IS_RAM) \ 344 | flags = 0; \ 345 | if ((cfgProp)&USB_PROP_IS_DYNAMIC) { \ 346 | len = usbFunctionDescriptor(rq); \ 347 | } else { \ 348 | len = USB_PROP_LENGTH(cfgProp); \ 349 | usbMsgPtr = (usbMsgPtr_t)(staticName); \ 350 | } \ 351 | } 352 | 353 | /* usbDriverDescriptor() is similar to usbFunctionDescriptor(), but used 354 | * internally for all types of descriptors. 355 | */ 356 | static inline usbMsgLen_t usbDriverDescriptor(usbRequest_t *rq) { 357 | usbMsgLen_t len = 0; 358 | uchar flags = USB_FLG_MSGPTR_IS_ROM; 359 | 360 | SWITCH_START(rq->wValue.bytes[1]) 361 | SWITCH_CASE(USBDESCR_DEVICE) /* 1 */ 362 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_DEVICE, usbDescriptorDevice) 363 | SWITCH_CASE(USBDESCR_CONFIG) /* 2 */ 364 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_CONFIGURATION, usbDescriptorConfiguration) 365 | SWITCH_CASE(USBDESCR_STRING) /* 3 */ 366 | #if USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC 367 | if (USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_RAM) 368 | flags = 0; 369 | len = usbFunctionDescriptor(rq); 370 | #else /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ 371 | SWITCH_START(rq->wValue.bytes[0]) 372 | SWITCH_CASE(0) 373 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_0, usbDescriptorString0) 374 | SWITCH_CASE(1) 375 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_VENDOR, usbDescriptorStringVendor) 376 | SWITCH_CASE(2) 377 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_PRODUCT, usbDescriptorStringDevice) 378 | SWITCH_CASE(3) 379 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER, 380 | usbDescriptorStringSerialNumber) 381 | SWITCH_DEFAULT 382 | if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) { 383 | len = usbFunctionDescriptor(rq); 384 | } 385 | SWITCH_END 386 | #endif /* USB_CFG_DESCR_PROPS_STRINGS & USB_PROP_IS_DYNAMIC */ 387 | #if USB_CFG_DESCR_PROPS_HID_REPORT /* only support HID descriptors if enabled \ 388 | */ 389 | SWITCH_CASE(USBDESCR_HID) /* 0x21 */ 390 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID, usbDescriptorConfiguration + 18) 391 | SWITCH_CASE(USBDESCR_HID_REPORT) /* 0x22 */ 392 | GET_DESCRIPTOR(USB_CFG_DESCR_PROPS_HID_REPORT, usbDescriptorHidReport) 393 | #endif 394 | SWITCH_DEFAULT 395 | if (USB_CFG_DESCR_PROPS_UNKNOWN & USB_PROP_IS_DYNAMIC) { 396 | len = usbFunctionDescriptor(rq); 397 | } 398 | SWITCH_END 399 | usbMsgFlags = flags; 400 | return len; 401 | } 402 | 403 | /* ------------------------------------------------------------------------- */ 404 | 405 | /* usbDriverSetup() is similar to usbFunctionSetup(), but it's used for 406 | * standard requests instead of class and custom requests. 407 | */ 408 | static inline usbMsgLen_t usbDriverSetup(usbRequest_t *rq) { 409 | usbMsgLen_t len = 0; 410 | uchar *dataPtr = 411 | usbTxBuf + 9; /* there are 2 bytes free space at the end of the buffer */ 412 | uchar value = rq->wValue.bytes[0]; 413 | #if USB_CFG_IMPLEMENT_HALT 414 | uchar index = rq->wIndex.bytes[0]; 415 | #endif 416 | 417 | dataPtr[0] = 418 | 0; /* default reply common to USBRQ_GET_STATUS and USBRQ_GET_INTERFACE */ 419 | SWITCH_START(rq->bRequest) 420 | SWITCH_CASE(USBRQ_GET_STATUS) /* 0 */ 421 | uchar recipient = 422 | rq->bmRequestType & 423 | USBRQ_RCPT_MASK; /* assign arith ops to variables to enforce byte size */ 424 | if (USB_CFG_IS_SELF_POWERED && recipient == USBRQ_RCPT_DEVICE) 425 | dataPtr[0] = USB_CFG_IS_SELF_POWERED; 426 | #if USB_CFG_IMPLEMENT_HALT 427 | if (recipient == USBRQ_RCPT_ENDPOINT && 428 | index == 0x81) /* request status for endpoint 1 */ 429 | dataPtr[0] = usbTxLen1 == USBPID_STALL; 430 | #endif 431 | dataPtr[1] = 0; 432 | len = 2; 433 | #if USB_CFG_IMPLEMENT_HALT 434 | SWITCH_CASE2(USBRQ_CLEAR_FEATURE, USBRQ_SET_FEATURE) /* 1, 3 */ 435 | if (value == 0 && index == 0x81) { /* feature 0 == HALT for endpoint == 1 */ 436 | usbTxLen1 = rq->bRequest == USBRQ_CLEAR_FEATURE ? USBPID_NAK : USBPID_STALL; 437 | usbResetDataToggling(); 438 | } 439 | #endif 440 | SWITCH_CASE(USBRQ_SET_ADDRESS) /* 5 */ 441 | usbNewDeviceAddr = value; 442 | USB_SET_ADDRESS_HOOK(); 443 | SWITCH_CASE(USBRQ_GET_DESCRIPTOR) /* 6 */ 444 | len = usbDriverDescriptor(rq); 445 | goto skipMsgPtrAssignment; 446 | SWITCH_CASE(USBRQ_GET_CONFIGURATION) /* 8 */ 447 | dataPtr = &usbConfiguration; /* send current configuration value */ 448 | len = 1; 449 | SWITCH_CASE(USBRQ_SET_CONFIGURATION) /* 9 */ 450 | usbConfiguration = value; 451 | usbResetStall(); 452 | SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */ 453 | len = 1; 454 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE 455 | SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */ 456 | usbResetDataToggling(); 457 | usbResetStall(); 458 | #endif 459 | SWITCH_DEFAULT /* 7=SET_DESCRIPTOR, 12=SYNC_FRAME */ 460 | /* Should we add an optional hook here? */ 461 | SWITCH_END usbMsgPtr = (usbMsgPtr_t)dataPtr; 462 | skipMsgPtrAssignment: 463 | return len; 464 | } 465 | 466 | /* ------------------------------------------------------------------------- */ 467 | 468 | /* usbProcessRx() is called for every message received by the interrupt 469 | * routine. It distinguishes between SETUP and DATA packets and processes 470 | * them accordingly. 471 | */ 472 | static inline void usbProcessRx(uchar *data, uchar len) { 473 | usbRequest_t *rq = (void *)data; 474 | 475 | /* usbRxToken can be: 476 | * 0x2d 00101101 (USBPID_SETUP for setup data) 477 | * 0xe1 11100001 (USBPID_OUT: data phase of setup transfer) 478 | * 0...0x0f for OUT on endpoint X 479 | */ 480 | DBG2(0x10 + (usbRxToken & 0xf), data, 481 | len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */ 482 | USB_RX_USER_HOOK(data, len) 483 | #if USB_CFG_IMPLEMENT_FN_WRITEOUT 484 | if (usbRxToken < 485 | 0x10) { /* OUT to endpoint != 0: endpoint number in usbRxToken */ 486 | usbFunctionWriteOut(data, len); 487 | return; 488 | } 489 | #endif 490 | if (usbRxToken == (uchar)USBPID_SETUP) { 491 | if (len != 8) /* Setup size must be always 8 bytes. Ignore otherwise. */ 492 | return; 493 | usbMsgLen_t replyLen; 494 | usbTxBuf[0] = USBPID_DATA0; /* initialize data toggling */ 495 | usbTxLen = USBPID_NAK; /* abort pending transmit */ 496 | usbMsgFlags = 0; 497 | uchar type = rq->bmRequestType & USBRQ_TYPE_MASK; 498 | if (type != 499 | USBRQ_TYPE_STANDARD) { /* standard requests are handled by driver */ 500 | replyLen = usbFunctionSetup(data); 501 | } else { 502 | replyLen = usbDriverSetup(rq); 503 | } 504 | #if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE 505 | if (replyLen == USB_NO_MSG) { /* use user-supplied read/write function */ 506 | /* do some conditioning on replyLen, but on IN transfers only */ 507 | if ((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE) { 508 | if (sizeof(replyLen) < 509 | sizeof(rq->wLength.word)) { /* help compiler with optimizing */ 510 | replyLen = rq->wLength.bytes[0]; 511 | } else { 512 | replyLen = rq->wLength.word; 513 | } 514 | } 515 | usbMsgFlags = USB_FLG_USE_USER_RW; 516 | } else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the 517 | maximum transfer len. */ 518 | #endif 519 | if (sizeof(replyLen) < 520 | sizeof(rq->wLength.word)) { /* help compiler with optimizing */ 521 | if (!rq->wLength.bytes[1] && 522 | replyLen > rq->wLength.bytes[0]) /* limit length to max */ 523 | replyLen = rq->wLength.bytes[0]; 524 | } else { 525 | if (replyLen > rq->wLength.word) /* limit length to max */ 526 | replyLen = rq->wLength.word; 527 | } 528 | usbMsgLen = replyLen; 529 | } else { /* usbRxToken must be USBPID_OUT, which means data phase of setup 530 | (control-out) */ 531 | #if USB_CFG_IMPLEMENT_FN_WRITE 532 | if (usbMsgFlags & USB_FLG_USE_USER_RW) { 533 | uchar rval = usbFunctionWrite(data, len); 534 | if (rval == 0xff) { /* an error occurred */ 535 | usbTxLen = USBPID_STALL; 536 | } else if (rval != 0) { /* This was the final package */ 537 | usbMsgLen = 0; /* answer with a zero-sized data packet */ 538 | } 539 | } 540 | #endif 541 | } 542 | } 543 | 544 | /* ------------------------------------------------------------------------- */ 545 | 546 | /* This function is similar to usbFunctionRead(), but it's also called for 547 | * data handled automatically by the driver (e.g. descriptor reads). 548 | */ 549 | static uchar usbDeviceRead(uchar *data, uchar len) { 550 | if (len > 0) { /* don't bother app with 0 sized reads */ 551 | #if USB_CFG_IMPLEMENT_FN_READ 552 | if (usbMsgFlags & USB_FLG_USE_USER_RW) { 553 | len = usbFunctionRead(data, len); 554 | } else 555 | #endif 556 | { 557 | uchar i = len; 558 | usbMsgPtr_t r = usbMsgPtr; 559 | if (usbMsgFlags & USB_FLG_MSGPTR_IS_ROM) { /* ROM data */ 560 | do { 561 | uchar c = USB_READ_FLASH( 562 | r); /* assign to char size variable to enforce byte ops */ 563 | *data++ = c; 564 | r++; 565 | } while (--i); 566 | } else { /* RAM data */ 567 | do { 568 | *data++ = *((uchar *)r); 569 | r++; 570 | } while (--i); 571 | } 572 | usbMsgPtr = r; 573 | } 574 | } 575 | return len; 576 | } 577 | 578 | /* ------------------------------------------------------------------------- */ 579 | 580 | /* usbBuildTxBlock() is called when we have data to transmit and the 581 | * interrupt routine's transmit buffer is empty. 582 | */ 583 | static inline void usbBuildTxBlock(void) { 584 | usbMsgLen_t wantLen; 585 | uchar len; 586 | 587 | wantLen = usbMsgLen; 588 | if (wantLen > 8) 589 | wantLen = 8; 590 | usbMsgLen -= wantLen; 591 | usbTxBuf[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* DATA toggling */ 592 | len = usbDeviceRead(usbTxBuf + 1, wantLen); 593 | if (len <= 8) { /* valid data packet */ 594 | usbCrc16Append(&usbTxBuf[1], len); 595 | len += 4; /* length including sync byte */ 596 | if (len < 12) /* a partial package identifies end of message */ 597 | usbMsgLen = USB_NO_MSG; 598 | } else { 599 | len = USBPID_STALL; /* stall the endpoint */ 600 | usbMsgLen = USB_NO_MSG; 601 | } 602 | usbTxLen = len; 603 | DBG2(0x20, usbTxBuf, len - 1); 604 | } 605 | 606 | /* ------------------------------------------------------------------------- */ 607 | 608 | static inline void usbHandleResetHook(uchar notResetState) { 609 | #ifdef USB_RESET_HOOK 610 | static uchar wasReset; 611 | uchar isReset = !notResetState; 612 | 613 | if (wasReset != isReset) { 614 | USB_RESET_HOOK(isReset); 615 | wasReset = isReset; 616 | } 617 | #else 618 | notResetState = notResetState; // avoid compiler warning 619 | #endif 620 | } 621 | 622 | /* ------------------------------------------------------------------------- */ 623 | 624 | USB_PUBLIC void usbPoll(void) { 625 | schar len; 626 | uchar i; 627 | 628 | len = usbRxLen - 3; 629 | if (len >= 0) { 630 | /* We could check CRC16 here -- but ACK has already been sent anyway. If you 631 | * need data integrity checks with this driver, check the CRC in your app 632 | * code and report errors back to the host. Since the ACK was already sent, 633 | * retries must be handled on application level. 634 | * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); 635 | */ 636 | usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len); 637 | #if USB_CFG_HAVE_FLOWCONTROL 638 | if (usbRxLen > 0) /* only mark as available if not inactivated */ 639 | usbRxLen = 0; 640 | #else 641 | usbRxLen = 0; /* mark rx buffer as available */ 642 | #endif 643 | } 644 | if (usbTxLen & 0x10) { /* transmit system idle */ 645 | if (usbMsgLen != USB_NO_MSG) { /* transmit data pending? */ 646 | usbBuildTxBlock(); 647 | } 648 | } 649 | for (i = 20; i > 0; i--) { 650 | uchar usbLineStatus = USBIN & USBMASK; 651 | if (usbLineStatus != 0) /* SE0 has ended */ 652 | goto isNotReset; 653 | } 654 | /* RESET condition, called multiple times during reset */ 655 | usbNewDeviceAddr = 0; 656 | usbDeviceAddr = 0; 657 | usbResetStall(); 658 | DBG1(0xff, 0, 0); 659 | isNotReset: 660 | usbHandleResetHook(i); 661 | } 662 | 663 | /* ------------------------------------------------------------------------- */ 664 | 665 | USB_PUBLIC void usbInit(void) { 666 | #if USB_INTR_CFG_SET != 0 667 | USB_INTR_CFG |= USB_INTR_CFG_SET; 668 | #endif 669 | #if USB_INTR_CFG_CLR != 0 670 | USB_INTR_CFG &= ~(USB_INTR_CFG_CLR); 671 | #endif 672 | USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT); 673 | usbResetDataToggling(); 674 | #if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE 675 | usbTxLen1 = USBPID_NAK; 676 | #if USB_CFG_HAVE_INTRIN_ENDPOINT3 677 | usbTxLen3 = USBPID_NAK; 678 | #endif 679 | #endif 680 | } 681 | 682 | /* ------------------------------------------------------------------------- */ 683 | -------------------------------------------------------------------------------- /usbdrv/usbdrvasm.S: -------------------------------------------------------------------------------- 1 | /* Name: usbdrvasm.S 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-06-13 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | /* 11 | General Description: 12 | This module is the assembler part of the USB driver. This file contains 13 | general code (preprocessor acrobatics and CRC computation) and then includes 14 | the file appropriate for the given clock rate. 15 | */ 16 | 17 | #define __SFR_OFFSET 0 /* used by avr-libc's register definitions */ 18 | #include "usbportability.h" 19 | #include "usbdrv.h" /* for common defs */ 20 | 21 | /* register names */ 22 | #define x1 r16 23 | #define x2 r17 24 | #define shift r18 25 | #define cnt r19 26 | #define x3 r20 27 | #define x4 r21 28 | #define x5 r22 29 | #define bitcnt x5 30 | #define phase x4 31 | #define leap x4 32 | 33 | /* Some assembler dependent definitions and declarations: */ 34 | 35 | #ifdef __IAR_SYSTEMS_ASM__ 36 | extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset 37 | extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen 38 | extern usbTxBuf, usbTxStatus1, usbTxStatus3 39 | # if USB_COUNT_SOF 40 | extern usbSofCount 41 | # endif 42 | public usbCrc16 43 | public usbCrc16Append 44 | 45 | COMMON INTVEC 46 | # ifndef USB_INTR_VECTOR 47 | ORG INT0_vect 48 | # else /* USB_INTR_VECTOR */ 49 | ORG USB_INTR_VECTOR 50 | # undef USB_INTR_VECTOR 51 | # endif /* USB_INTR_VECTOR */ 52 | # define USB_INTR_VECTOR usbInterruptHandler 53 | rjmp USB_INTR_VECTOR 54 | RSEG CODE 55 | 56 | #else /* __IAR_SYSTEMS_ASM__ */ 57 | 58 | # ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */ 59 | # ifdef INT0_vect 60 | # define USB_INTR_VECTOR INT0_vect // this is the "new" define for the vector 61 | # else 62 | # define USB_INTR_VECTOR SIG_INTERRUPT0 // this is the "old" vector 63 | # endif 64 | # endif 65 | .text 66 | .global USB_INTR_VECTOR 67 | .type USB_INTR_VECTOR, @function 68 | .global usbCrc16 69 | .global usbCrc16Append 70 | #endif /* __IAR_SYSTEMS_ASM__ */ 71 | 72 | 73 | #if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */ 74 | # define USB_LOAD_PENDING(reg) in reg, USB_INTR_PENDING 75 | # define USB_STORE_PENDING(reg) out USB_INTR_PENDING, reg 76 | #else /* It's a memory address, use lds and sts */ 77 | # define USB_LOAD_PENDING(reg) lds reg, USB_INTR_PENDING 78 | # define USB_STORE_PENDING(reg) sts USB_INTR_PENDING, reg 79 | #endif 80 | 81 | #define usbTxLen1 usbTxStatus1 82 | #define usbTxBuf1 (usbTxStatus1 + 1) 83 | #define usbTxLen3 usbTxStatus3 84 | #define usbTxBuf3 (usbTxStatus3 + 1) 85 | 86 | 87 | ;---------------------------------------------------------------------------- 88 | ; Utility functions 89 | ;---------------------------------------------------------------------------- 90 | 91 | #ifdef __IAR_SYSTEMS_ASM__ 92 | /* Register assignments for usbCrc16 on IAR cc */ 93 | /* Calling conventions on IAR: 94 | * First parameter passed in r16/r17, second in r18/r19 and so on. 95 | * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) 96 | * Result is passed in r16/r17 97 | * In case of the "tiny" memory model, pointers are only 8 bit with no 98 | * padding. We therefore pass argument 1 as "16 bit unsigned". 99 | */ 100 | RTMODEL "__rt_version", "3" 101 | /* The line above will generate an error if cc calling conventions change. 102 | * The value "3" above is valid for IAR 4.10B/W32 103 | */ 104 | # define argLen r18 /* argument 2 */ 105 | # define argPtrL r16 /* argument 1 */ 106 | # define argPtrH r17 /* argument 1 */ 107 | 108 | # define resCrcL r16 /* result */ 109 | # define resCrcH r17 /* result */ 110 | 111 | # define ptrL ZL 112 | # define ptrH ZH 113 | # define ptr Z 114 | # define byte r22 115 | # define bitCnt r19 116 | # define polyL r20 117 | # define polyH r21 118 | # define scratch r23 119 | 120 | #else /* __IAR_SYSTEMS_ASM__ */ 121 | /* Register assignments for usbCrc16 on gcc */ 122 | /* Calling conventions on gcc: 123 | * First parameter passed in r24/r25, second in r22/23 and so on. 124 | * Callee must preserve r1-r17, r28/r29 125 | * Result is passed in r24/r25 126 | */ 127 | # define argLen r22 /* argument 2 */ 128 | # define argPtrL r24 /* argument 1 */ 129 | # define argPtrH r25 /* argument 1 */ 130 | 131 | # define resCrcL r24 /* result */ 132 | # define resCrcH r25 /* result */ 133 | 134 | # define ptrL XL 135 | # define ptrH XH 136 | # define ptr x 137 | # define byte r18 138 | # define bitCnt r19 139 | # define polyL r20 140 | # define polyH r21 141 | # define scratch r23 142 | 143 | #endif 144 | 145 | #if USB_USE_FAST_CRC 146 | 147 | ; This implementation is faster, but has bigger code size 148 | ; Thanks to Slawomir Fras (BoskiDialer) for this code! 149 | ; It implements the following C pseudo-code: 150 | ; unsigned table(unsigned char x) 151 | ; { 152 | ; unsigned value; 153 | ; 154 | ; value = (unsigned)x << 6; 155 | ; value ^= (unsigned)x << 7; 156 | ; if(parity(x)) 157 | ; value ^= 0xc001; 158 | ; return value; 159 | ; } 160 | ; unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen) 161 | ; { 162 | ; unsigned crc = 0xffff; 163 | ; 164 | ; while(argLen--) 165 | ; crc = table(lo8(crc) ^ *argPtr++) ^ hi8(crc); 166 | ; return ~crc; 167 | ; } 168 | 169 | ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); 170 | ; argPtr r24+25 / r16+r17 171 | ; argLen r22 / r18 172 | ; temp variables: 173 | ; byte r18 / r22 174 | ; scratch r23 175 | ; resCrc r24+r25 / r16+r17 176 | ; ptr X / Z 177 | usbCrc16: 178 | mov ptrL, argPtrL 179 | mov ptrH, argPtrH 180 | ldi resCrcL, 0xFF 181 | ldi resCrcH, 0xFF 182 | rjmp usbCrc16LoopTest 183 | usbCrc16ByteLoop: 184 | ld byte, ptr+ 185 | eor resCrcL, byte ; resCrcL is now 'x' in table() 186 | mov byte, resCrcL ; compute parity of 'x' 187 | swap byte 188 | eor byte, resCrcL 189 | mov scratch, byte 190 | lsr byte 191 | lsr byte 192 | eor byte, scratch 193 | inc byte 194 | lsr byte 195 | andi byte, 1 ; byte is now parity(x) 196 | mov scratch, resCrcL 197 | mov resCrcL, resCrcH 198 | eor resCrcL, byte ; low byte of if(parity(x)) value ^= 0xc001; 199 | neg byte 200 | andi byte, 0xc0 201 | mov resCrcH, byte ; high byte of if(parity(x)) value ^= 0xc001; 202 | clr byte 203 | lsr scratch 204 | ror byte 205 | eor resCrcH, scratch 206 | eor resCrcL, byte 207 | lsr scratch 208 | ror byte 209 | eor resCrcH, scratch 210 | eor resCrcL, byte 211 | usbCrc16LoopTest: 212 | subi argLen, 1 213 | brsh usbCrc16ByteLoop 214 | com resCrcL 215 | com resCrcH 216 | ret 217 | 218 | #else /* USB_USE_FAST_CRC */ 219 | 220 | ; This implementation is slower, but has less code size 221 | ; 222 | ; extern unsigned usbCrc16(unsigned char *argPtr, unsigned char argLen); 223 | ; argPtr r24+25 / r16+r17 224 | ; argLen r22 / r18 225 | ; temp variables: 226 | ; byte r18 / r22 227 | ; bitCnt r19 228 | ; poly r20+r21 229 | ; scratch r23 230 | ; resCrc r24+r25 / r16+r17 231 | ; ptr X / Z 232 | usbCrc16: 233 | mov ptrL, argPtrL 234 | mov ptrH, argPtrH 235 | ldi resCrcL, 0 236 | ldi resCrcH, 0 237 | ldi polyL, lo8(0xa001) 238 | ldi polyH, hi8(0xa001) 239 | com argLen ; argLen = -argLen - 1: modified loop to ensure that carry is set 240 | ldi bitCnt, 0 ; loop counter with starnd condition = end condition 241 | rjmp usbCrcLoopEntry 242 | usbCrcByteLoop: 243 | ld byte, ptr+ 244 | eor resCrcL, byte 245 | usbCrcBitLoop: 246 | ror resCrcH ; carry is always set here (see brcs jumps to here) 247 | ror resCrcL 248 | brcs usbCrcNoXor 249 | eor resCrcL, polyL 250 | eor resCrcH, polyH 251 | usbCrcNoXor: 252 | subi bitCnt, 224 ; (8 * 224) % 256 = 0; this loop iterates 8 times 253 | brcs usbCrcBitLoop 254 | usbCrcLoopEntry: 255 | subi argLen, -1 256 | brcs usbCrcByteLoop 257 | usbCrcReady: 258 | ret 259 | ; Thanks to Reimar Doeffinger for optimizing this CRC routine! 260 | 261 | #endif /* USB_USE_FAST_CRC */ 262 | 263 | ; extern unsigned usbCrc16Append(unsigned char *data, unsigned char len); 264 | usbCrc16Append: 265 | rcall usbCrc16 266 | st ptr+, resCrcL 267 | st ptr+, resCrcH 268 | ret 269 | 270 | #undef argLen 271 | #undef argPtrL 272 | #undef argPtrH 273 | #undef resCrcL 274 | #undef resCrcH 275 | #undef ptrL 276 | #undef ptrH 277 | #undef ptr 278 | #undef byte 279 | #undef bitCnt 280 | #undef polyL 281 | #undef polyH 282 | #undef scratch 283 | 284 | 285 | #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH 286 | #ifdef __IAR_SYSTEMS_ASM__ 287 | /* Register assignments for usbMeasureFrameLength on IAR cc */ 288 | /* Calling conventions on IAR: 289 | * First parameter passed in r16/r17, second in r18/r19 and so on. 290 | * Callee must preserve r4-r15, r24-r29 (r28/r29 is frame pointer) 291 | * Result is passed in r16/r17 292 | * In case of the "tiny" memory model, pointers are only 8 bit with no 293 | * padding. We therefore pass argument 1 as "16 bit unsigned". 294 | */ 295 | # define resL r16 296 | # define resH r17 297 | # define cnt16L r30 298 | # define cnt16H r31 299 | # define cntH r18 300 | 301 | #else /* __IAR_SYSTEMS_ASM__ */ 302 | /* Register assignments for usbMeasureFrameLength on gcc */ 303 | /* Calling conventions on gcc: 304 | * First parameter passed in r24/r25, second in r22/23 and so on. 305 | * Callee must preserve r1-r17, r28/r29 306 | * Result is passed in r24/r25 307 | */ 308 | # define resL r24 309 | # define resH r25 310 | # define cnt16L r24 311 | # define cnt16H r25 312 | # define cntH r26 313 | #endif 314 | # define cnt16 cnt16L 315 | 316 | ; extern unsigned usbMeasurePacketLength(void); 317 | ; returns time between two idle strobes in multiples of 7 CPU clocks 318 | .global usbMeasureFrameLength 319 | usbMeasureFrameLength: 320 | ldi cntH, 6 ; wait ~ 10 ms for D- == 0 321 | clr cnt16L 322 | clr cnt16H 323 | usbMFTime16: 324 | dec cntH 325 | breq usbMFTimeout 326 | usbMFWaitStrobe: ; first wait for D- == 0 (idle strobe) 327 | sbiw cnt16, 1 ;[0] [6] 328 | breq usbMFTime16 ;[2] 329 | sbic USBIN, USBMINUS ;[3] 330 | rjmp usbMFWaitStrobe ;[4] 331 | usbMFWaitIdle: ; then wait until idle again 332 | sbis USBIN, USBMINUS ;1 wait for D- == 1 333 | rjmp usbMFWaitIdle ;2 334 | ldi cnt16L, 1 ;1 represents cycles so far 335 | clr cnt16H ;1 336 | usbMFWaitLoop: 337 | in cntH, USBIN ;[0] [7] 338 | adiw cnt16, 1 ;[1] 339 | breq usbMFTimeout ;[3] 340 | andi cntH, USBMASK ;[4] 341 | brne usbMFWaitLoop ;[5] 342 | usbMFTimeout: 343 | #if resL != cnt16L 344 | mov resL, cnt16L 345 | mov resH, cnt16H 346 | #endif 347 | ret 348 | 349 | #undef resL 350 | #undef resH 351 | #undef cnt16 352 | #undef cnt16L 353 | #undef cnt16H 354 | #undef cntH 355 | 356 | #endif /* USB_CFG_HAVE_MEASURE_FRAME_LENGTH */ 357 | 358 | ;---------------------------------------------------------------------------- 359 | ; Now include the clock rate specific code 360 | ;---------------------------------------------------------------------------- 361 | 362 | #ifndef USB_CFG_CLOCK_KHZ 363 | # ifdef F_CPU 364 | # define USB_CFG_CLOCK_KHZ (F_CPU/1000) 365 | # else 366 | # error "USB_CFG_CLOCK_KHZ not defined in usbconfig.h and no F_CPU set!" 367 | # endif 368 | #endif 369 | 370 | #if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */ 371 | # if USB_CFG_CLOCK_KHZ == 18000 372 | # include "usbdrvasm18-crc.inc" 373 | # else 374 | # error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!" 375 | # endif 376 | #else /* USB_CFG_CHECK_CRC */ 377 | # if USB_CFG_CLOCK_KHZ == 12000 378 | # include "usbdrvasm12.inc" 379 | # elif USB_CFG_CLOCK_KHZ == 12800 380 | # include "usbdrvasm128.inc" 381 | # elif USB_CFG_CLOCK_KHZ == 15000 382 | # include "usbdrvasm15.inc" 383 | # elif USB_CFG_CLOCK_KHZ == 16000 384 | # include "usbdrvasm16.inc" 385 | # elif USB_CFG_CLOCK_KHZ == 16500 386 | # include "usbdrvasm165.inc" 387 | # elif USB_CFG_CLOCK_KHZ == 20000 388 | # include "usbdrvasm20.inc" 389 | # else 390 | # error "USB_CFG_CLOCK_KHZ is not one of the supported non-crc-rates!" 391 | # endif 392 | #endif /* USB_CFG_CHECK_CRC */ 393 | -------------------------------------------------------------------------------- /usbdrv/usbdrvasm.asm: -------------------------------------------------------------------------------- 1 | /* Name: usbdrvasm.asm 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-03-01 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | /* 11 | General Description: 12 | The IAR compiler/assembler system prefers assembler files with file extension 13 | ".asm". We simply provide this file as an alias for usbdrvasm.S. 14 | 15 | Thanks to Oleg Semyonov for his help with the IAR tools port! 16 | */ 17 | 18 | #include "usbdrvasm.S" 19 | 20 | end 21 | -------------------------------------------------------------------------------- /usbdrv/usbdrvasm12.inc: -------------------------------------------------------------------------------- 1 | /* Name: usbdrvasm12.inc 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2004-12-29 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | * This Revision: $Id: usbdrvasm12.inc 740 2009-04-13 18:23:31Z cs $ 9 | */ 10 | 11 | /* Do not link this file! Link usbdrvasm.S instead, which includes the 12 | * appropriate implementation! 13 | */ 14 | 15 | /* 16 | General Description: 17 | This file is the 12 MHz version of the asssembler part of the USB driver. It 18 | requires a 12 MHz crystal (not a ceramic resonator and not a calibrated RC 19 | oscillator). 20 | 21 | See usbdrv.h for a description of the entire driver. 22 | 23 | Since almost all of this code is timing critical, don't change unless you 24 | really know what you are doing! Many parts require not only a maximum number 25 | of CPU cycles, but even an exact number of cycles! 26 | 27 | 28 | Timing constraints according to spec (in bit times): 29 | timing subject min max CPUcycles 30 | --------------------------------------------------------------------------- 31 | EOP of OUT/SETUP to sync pattern of DATA0 (both rx) 2 16 16-128 32 | EOP of IN to sync pattern of DATA0 (rx, then tx) 2 7.5 16-60 33 | DATAx (rx) to ACK/NAK/STALL (tx) 2 7.5 16-60 34 | */ 35 | 36 | ;Software-receiver engine. Strict timing! Don't change unless you can preserve timing! 37 | ;interrupt response time: 4 cycles + insn running = 7 max if interrupts always enabled 38 | ;max allowable interrupt latency: 34 cycles -> max 25 cycles interrupt disable 39 | ;max stack usage: [ret(2), YL, SREG, YH, shift, x1, x2, x3, cnt, x4] = 11 bytes 40 | ;Numbers in brackets are maximum cycles since SOF. 41 | USB_INTR_VECTOR: 42 | ;order of registers pushed: YL, SREG [sofError], YH, shift, x1, x2, x3, cnt 43 | push YL ;2 [35] push only what is necessary to sync with edge ASAP 44 | in YL, SREG ;1 [37] 45 | push YL ;2 [39] 46 | ;---------------------------------------------------------------------------- 47 | ; Synchronize with sync pattern: 48 | ;---------------------------------------------------------------------------- 49 | ;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] 50 | ;sync up with J to K edge during sync pattern -- use fastest possible loops 51 | ;The first part waits at most 1 bit long since we must be in sync pattern. 52 | ;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to 53 | ;waitForJ, ensure that this prerequisite is met. 54 | waitForJ: 55 | inc YL 56 | sbis USBIN, USBMINUS 57 | brne waitForJ ; just make sure we have ANY timeout 58 | waitForK: 59 | ;The following code results in a sampling window of 1/4 bit which meets the spec. 60 | sbis USBIN, USBMINUS 61 | rjmp foundK 62 | sbis USBIN, USBMINUS 63 | rjmp foundK 64 | sbis USBIN, USBMINUS 65 | rjmp foundK 66 | sbis USBIN, USBMINUS 67 | rjmp foundK 68 | sbis USBIN, USBMINUS 69 | rjmp foundK 70 | #if USB_COUNT_SOF 71 | lds YL, usbSofCount 72 | inc YL 73 | sts usbSofCount, YL 74 | #endif /* USB_COUNT_SOF */ 75 | #ifdef USB_SOF_HOOK 76 | USB_SOF_HOOK 77 | #endif 78 | rjmp sofError 79 | foundK: 80 | ;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling] 81 | ;we have 1 bit time for setup purposes, then sample again. Numbers in brackets 82 | ;are cycles from center of first sync (double K) bit after the instruction 83 | push YH ;2 [2] 84 | lds YL, usbInputBufOffset;2 [4] 85 | clr YH ;1 [5] 86 | subi YL, lo8(-(usbRxBuf));1 [6] 87 | sbci YH, hi8(-(usbRxBuf));1 [7] 88 | 89 | sbis USBIN, USBMINUS ;1 [8] we want two bits K [sample 1 cycle too early] 90 | rjmp haveTwoBitsK ;2 [10] 91 | pop YH ;2 [11] undo the push from before 92 | rjmp waitForK ;2 [13] this was not the end of sync, retry 93 | haveTwoBitsK: 94 | ;---------------------------------------------------------------------------- 95 | ; push more registers and initialize values while we sample the first bits: 96 | ;---------------------------------------------------------------------------- 97 | push shift ;2 [16] 98 | push x1 ;2 [12] 99 | push x2 ;2 [14] 100 | 101 | in x1, USBIN ;1 [17] <-- sample bit 0 102 | ldi shift, 0xff ;1 [18] 103 | bst x1, USBMINUS ;1 [19] 104 | bld shift, 0 ;1 [20] 105 | push x3 ;2 [22] 106 | push cnt ;2 [24] 107 | 108 | in x2, USBIN ;1 [25] <-- sample bit 1 109 | ser x3 ;1 [26] [inserted init instruction] 110 | eor x1, x2 ;1 [27] 111 | bst x1, USBMINUS ;1 [28] 112 | bld shift, 1 ;1 [29] 113 | ldi cnt, USB_BUFSIZE;1 [30] [inserted init instruction] 114 | rjmp rxbit2 ;2 [32] 115 | 116 | ;---------------------------------------------------------------------------- 117 | ; Receiver loop (numbers in brackets are cycles within byte after instr) 118 | ;---------------------------------------------------------------------------- 119 | 120 | unstuff0: ;1 (branch taken) 121 | andi x3, ~0x01 ;1 [15] 122 | mov x1, x2 ;1 [16] x2 contains last sampled (stuffed) bit 123 | in x2, USBIN ;1 [17] <-- sample bit 1 again 124 | ori shift, 0x01 ;1 [18] 125 | rjmp didUnstuff0 ;2 [20] 126 | 127 | unstuff1: ;1 (branch taken) 128 | mov x2, x1 ;1 [21] x1 contains last sampled (stuffed) bit 129 | andi x3, ~0x02 ;1 [22] 130 | ori shift, 0x02 ;1 [23] 131 | nop ;1 [24] 132 | in x1, USBIN ;1 [25] <-- sample bit 2 again 133 | rjmp didUnstuff1 ;2 [27] 134 | 135 | unstuff2: ;1 (branch taken) 136 | andi x3, ~0x04 ;1 [29] 137 | ori shift, 0x04 ;1 [30] 138 | mov x1, x2 ;1 [31] x2 contains last sampled (stuffed) bit 139 | nop ;1 [32] 140 | in x2, USBIN ;1 [33] <-- sample bit 3 141 | rjmp didUnstuff2 ;2 [35] 142 | 143 | unstuff3: ;1 (branch taken) 144 | in x2, USBIN ;1 [34] <-- sample stuffed bit 3 [one cycle too late] 145 | andi x3, ~0x08 ;1 [35] 146 | ori shift, 0x08 ;1 [36] 147 | rjmp didUnstuff3 ;2 [38] 148 | 149 | unstuff4: ;1 (branch taken) 150 | andi x3, ~0x10 ;1 [40] 151 | in x1, USBIN ;1 [41] <-- sample stuffed bit 4 152 | ori shift, 0x10 ;1 [42] 153 | rjmp didUnstuff4 ;2 [44] 154 | 155 | unstuff5: ;1 (branch taken) 156 | andi x3, ~0x20 ;1 [48] 157 | in x2, USBIN ;1 [49] <-- sample stuffed bit 5 158 | ori shift, 0x20 ;1 [50] 159 | rjmp didUnstuff5 ;2 [52] 160 | 161 | unstuff6: ;1 (branch taken) 162 | andi x3, ~0x40 ;1 [56] 163 | in x1, USBIN ;1 [57] <-- sample stuffed bit 6 164 | ori shift, 0x40 ;1 [58] 165 | rjmp didUnstuff6 ;2 [60] 166 | 167 | ; extra jobs done during bit interval: 168 | ; bit 0: store, clear [SE0 is unreliable here due to bit dribbling in hubs] 169 | ; bit 1: se0 check 170 | ; bit 2: overflow check 171 | ; bit 3: recovery from delay [bit 0 tasks took too long] 172 | ; bit 4: none 173 | ; bit 5: none 174 | ; bit 6: none 175 | ; bit 7: jump, eor 176 | rxLoop: 177 | eor x3, shift ;1 [0] reconstruct: x3 is 0 at bit locations we changed, 1 at others 178 | in x1, USBIN ;1 [1] <-- sample bit 0 179 | st y+, x3 ;2 [3] store data 180 | ser x3 ;1 [4] 181 | nop ;1 [5] 182 | eor x2, x1 ;1 [6] 183 | bst x2, USBMINUS;1 [7] 184 | bld shift, 0 ;1 [8] 185 | in x2, USBIN ;1 [9] <-- sample bit 1 (or possibly bit 0 stuffed) 186 | andi x2, USBMASK ;1 [10] 187 | breq se0 ;1 [11] SE0 check for bit 1 188 | andi shift, 0xf9 ;1 [12] 189 | didUnstuff0: 190 | breq unstuff0 ;1 [13] 191 | eor x1, x2 ;1 [14] 192 | bst x1, USBMINUS;1 [15] 193 | bld shift, 1 ;1 [16] 194 | rxbit2: 195 | in x1, USBIN ;1 [17] <-- sample bit 2 (or possibly bit 1 stuffed) 196 | andi shift, 0xf3 ;1 [18] 197 | breq unstuff1 ;1 [19] do remaining work for bit 1 198 | didUnstuff1: 199 | subi cnt, 1 ;1 [20] 200 | brcs overflow ;1 [21] loop control 201 | eor x2, x1 ;1 [22] 202 | bst x2, USBMINUS;1 [23] 203 | bld shift, 2 ;1 [24] 204 | in x2, USBIN ;1 [25] <-- sample bit 3 (or possibly bit 2 stuffed) 205 | andi shift, 0xe7 ;1 [26] 206 | breq unstuff2 ;1 [27] 207 | didUnstuff2: 208 | eor x1, x2 ;1 [28] 209 | bst x1, USBMINUS;1 [29] 210 | bld shift, 3 ;1 [30] 211 | didUnstuff3: 212 | andi shift, 0xcf ;1 [31] 213 | breq unstuff3 ;1 [32] 214 | in x1, USBIN ;1 [33] <-- sample bit 4 215 | eor x2, x1 ;1 [34] 216 | bst x2, USBMINUS;1 [35] 217 | bld shift, 4 ;1 [36] 218 | didUnstuff4: 219 | andi shift, 0x9f ;1 [37] 220 | breq unstuff4 ;1 [38] 221 | nop2 ;2 [40] 222 | in x2, USBIN ;1 [41] <-- sample bit 5 223 | eor x1, x2 ;1 [42] 224 | bst x1, USBMINUS;1 [43] 225 | bld shift, 5 ;1 [44] 226 | didUnstuff5: 227 | andi shift, 0x3f ;1 [45] 228 | breq unstuff5 ;1 [46] 229 | nop2 ;2 [48] 230 | in x1, USBIN ;1 [49] <-- sample bit 6 231 | eor x2, x1 ;1 [50] 232 | bst x2, USBMINUS;1 [51] 233 | bld shift, 6 ;1 [52] 234 | didUnstuff6: 235 | cpi shift, 0x02 ;1 [53] 236 | brlo unstuff6 ;1 [54] 237 | nop2 ;2 [56] 238 | in x2, USBIN ;1 [57] <-- sample bit 7 239 | eor x1, x2 ;1 [58] 240 | bst x1, USBMINUS;1 [59] 241 | bld shift, 7 ;1 [60] 242 | didUnstuff7: 243 | cpi shift, 0x04 ;1 [61] 244 | brsh rxLoop ;2 [63] loop control 245 | unstuff7: 246 | andi x3, ~0x80 ;1 [63] 247 | ori shift, 0x80 ;1 [64] 248 | in x2, USBIN ;1 [65] <-- sample stuffed bit 7 249 | nop ;1 [66] 250 | rjmp didUnstuff7 ;2 [68] 251 | 252 | macro POP_STANDARD ; 12 cycles 253 | pop cnt 254 | pop x3 255 | pop x2 256 | pop x1 257 | pop shift 258 | pop YH 259 | endm 260 | macro POP_RETI ; 5 cycles 261 | pop YL 262 | out SREG, YL 263 | pop YL 264 | endm 265 | 266 | #include "asmcommon.inc" 267 | 268 | ;---------------------------------------------------------------------------- 269 | ; Transmitting data 270 | ;---------------------------------------------------------------------------- 271 | 272 | txByteLoop: 273 | txBitloop: 274 | stuffN1Delay: ; [03] 275 | ror shift ;[-5] [11] [59] 276 | brcc doExorN1 ;[-4] [60] 277 | subi x4, 1 ;[-3] 278 | brne commonN1 ;[-2] 279 | lsl shift ;[-1] compensate ror after rjmp stuffDelay 280 | nop ;[00] stuffing consists of just waiting 8 cycles 281 | rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear 282 | 283 | sendNakAndReti: ;0 [-19] 19 cycles until SOP 284 | ldi x3, USBPID_NAK ;1 [-18] 285 | rjmp usbSendX3 ;2 [-16] 286 | sendAckAndReti: ;0 [-19] 19 cycles until SOP 287 | ldi x3, USBPID_ACK ;1 [-18] 288 | rjmp usbSendX3 ;2 [-16] 289 | sendCntAndReti: ;0 [-17] 17 cycles until SOP 290 | mov x3, cnt ;1 [-16] 291 | usbSendX3: ;0 [-16] 292 | ldi YL, 20 ;1 [-15] 'x3' is R20 293 | ldi YH, 0 ;1 [-14] 294 | ldi cnt, 2 ;1 [-13] 295 | ; rjmp usbSendAndReti fallthrough 296 | 297 | ; USB spec says: 298 | ; idle = J 299 | ; J = (D+ = 0), (D- = 1) or USBOUT = 0x01 300 | ; K = (D+ = 1), (D- = 0) or USBOUT = 0x02 301 | ; Spec allows 7.5 bit times from EOP to SOP for replies (= 60 cycles) 302 | 303 | ;usbSend: 304 | ;pointer to data in 'Y' 305 | ;number of bytes in 'cnt' -- including sync byte 306 | ;uses: x1...x2, x4, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x4 = bitstuff cnt] 307 | ;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction) 308 | usbSendAndReti: 309 | in x2, USBDDR ;[-12] 12 cycles until SOP 310 | ori x2, USBMASK ;[-11] 311 | sbi USBOUT, USBMINUS ;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) 312 | out USBDDR, x2 ;[-8] <--- acquire bus 313 | in x1, USBOUT ;[-7] port mirror for tx loop 314 | ldi shift, 0x40 ;[-6] sync byte is first byte sent (we enter loop after ror) 315 | ldi x2, USBMASK ;[-5] 316 | push x4 ;[-4] 317 | doExorN1: 318 | eor x1, x2 ;[-2] [06] [62] 319 | ldi x4, 6 ;[-1] [07] [63] 320 | commonN1: 321 | stuffN2Delay: 322 | out USBOUT, x1 ;[00] [08] [64] <--- set bit 323 | ror shift ;[01] 324 | brcc doExorN2 ;[02] 325 | subi x4, 1 ;[03] 326 | brne commonN2 ;[04] 327 | lsl shift ;[05] compensate ror after rjmp stuffDelay 328 | rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear 329 | doExorN2: 330 | eor x1, x2 ;[04] [12] 331 | ldi x4, 6 ;[05] [13] 332 | commonN2: 333 | nop ;[06] [14] 334 | subi cnt, 171 ;[07] [15] trick: (3 * 171) & 0xff = 1 335 | out USBOUT, x1 ;[08] [16] <--- set bit 336 | brcs txBitloop ;[09] [25] [41] 337 | 338 | stuff6Delay: 339 | ror shift ;[42] [50] 340 | brcc doExor6 ;[43] 341 | subi x4, 1 ;[44] 342 | brne common6 ;[45] 343 | lsl shift ;[46] compensate ror after rjmp stuffDelay 344 | nop ;[47] stuffing consists of just waiting 8 cycles 345 | rjmp stuff6Delay ;[48] after ror, C bit is reliably clear 346 | doExor6: 347 | eor x1, x2 ;[45] [53] 348 | ldi x4, 6 ;[46] 349 | common6: 350 | stuff7Delay: 351 | ror shift ;[47] [55] 352 | out USBOUT, x1 ;[48] <--- set bit 353 | brcc doExor7 ;[49] 354 | subi x4, 1 ;[50] 355 | brne common7 ;[51] 356 | lsl shift ;[52] compensate ror after rjmp stuffDelay 357 | rjmp stuff7Delay ;[53] after ror, C bit is reliably clear 358 | doExor7: 359 | eor x1, x2 ;[51] [59] 360 | ldi x4, 6 ;[52] 361 | common7: 362 | ld shift, y+ ;[53] 363 | tst cnt ;[55] 364 | out USBOUT, x1 ;[56] <--- set bit 365 | brne txByteLoop ;[57] 366 | 367 | ;make SE0: 368 | cbr x1, USBMASK ;[58] prepare SE0 [spec says EOP may be 15 to 18 cycles] 369 | lds x2, usbNewDeviceAddr;[59] 370 | lsl x2 ;[61] we compare with left shifted address 371 | subi YL, 2 + 20 ;[62] Only assign address on data packets, not ACK/NAK in x3 372 | sbci YH, 0 ;[63] 373 | out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle 374 | ;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: 375 | ;set address only after data packet was sent, not after handshake 376 | breq skipAddrAssign ;[01] 377 | sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer 378 | skipAddrAssign: 379 | ;end of usbDeviceAddress transfer 380 | ldi x2, 1< 10.6666666 cycles per bit, 85.333333333 cycles per byte 30 | ; Numbers in brackets are clocks counted from center of last sync bit 31 | ; when instruction starts 32 | 33 | USB_INTR_VECTOR: 34 | ;order of registers pushed: YL, SREG YH, [sofError], bitcnt, shift, x1, x2, x3, x4, cnt 35 | push YL ;[-25] push only what is necessary to sync with edge ASAP 36 | in YL, SREG ;[-23] 37 | push YL ;[-22] 38 | push YH ;[-20] 39 | ;---------------------------------------------------------------------------- 40 | ; Synchronize with sync pattern: 41 | ;---------------------------------------------------------------------------- 42 | ;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K] 43 | ;sync up with J to K edge during sync pattern -- use fastest possible loops 44 | ;The first part waits at most 1 bit long since we must be in sync pattern. 45 | ;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to 46 | ;waitForJ, ensure that this prerequisite is met. 47 | waitForJ: 48 | inc YL 49 | sbis USBIN, USBMINUS 50 | brne waitForJ ; just make sure we have ANY timeout 51 | waitForK: 52 | ;The following code results in a sampling window of < 1/4 bit which meets the spec. 53 | sbis USBIN, USBMINUS ;[-15] 54 | rjmp foundK ;[-14] 55 | sbis USBIN, USBMINUS 56 | rjmp foundK 57 | sbis USBIN, USBMINUS 58 | rjmp foundK 59 | sbis USBIN, USBMINUS 60 | rjmp foundK 61 | sbis USBIN, USBMINUS 62 | rjmp foundK 63 | sbis USBIN, USBMINUS 64 | rjmp foundK 65 | #if USB_COUNT_SOF 66 | lds YL, usbSofCount 67 | inc YL 68 | sts usbSofCount, YL 69 | #endif /* USB_COUNT_SOF */ 70 | #ifdef USB_SOF_HOOK 71 | USB_SOF_HOOK 72 | #endif 73 | rjmp sofError 74 | foundK: ;[-12] 75 | ;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling] 76 | ;we have 1 bit time for setup purposes, then sample again. Numbers in brackets 77 | ;are cycles from center of first sync (double K) bit after the instruction 78 | push bitcnt ;[-12] 79 | ; [---] ;[-11] 80 | lds YL, usbInputBufOffset;[-10] 81 | ; [---] ;[-9] 82 | clr YH ;[-8] 83 | subi YL, lo8(-(usbRxBuf));[-7] [rx loop init] 84 | sbci YH, hi8(-(usbRxBuf));[-6] [rx loop init] 85 | push shift ;[-5] 86 | ; [---] ;[-4] 87 | ldi bitcnt, 0x55 ;[-3] [rx loop init] 88 | sbis USBIN, USBMINUS ;[-2] we want two bits K (sample 2 cycles too early) 89 | rjmp haveTwoBitsK ;[-1] 90 | pop shift ;[0] undo the push from before 91 | pop bitcnt ;[2] undo the push from before 92 | rjmp waitForK ;[4] this was not the end of sync, retry 93 | ; The entire loop from waitForK until rjmp waitForK above must not exceed two 94 | ; bit times (= 21 cycles). 95 | 96 | ;---------------------------------------------------------------------------- 97 | ; push more registers and initialize values while we sample the first bits: 98 | ;---------------------------------------------------------------------------- 99 | haveTwoBitsK: 100 | push x1 ;[1] 101 | push x2 ;[3] 102 | push x3 ;[5] 103 | ldi shift, 0 ;[7] 104 | ldi x3, 1<<4 ;[8] [rx loop init] first sample is inverse bit, compensate that 105 | push x4 ;[9] == leap 106 | 107 | in x1, USBIN ;[11] <-- sample bit 0 108 | andi x1, USBMASK ;[12] 109 | bst x1, USBMINUS ;[13] 110 | bld shift, 7 ;[14] 111 | push cnt ;[15] 112 | ldi leap, 0 ;[17] [rx loop init] 113 | ldi cnt, USB_BUFSIZE;[18] [rx loop init] 114 | rjmp rxbit1 ;[19] arrives at [21] 115 | 116 | ;---------------------------------------------------------------------------- 117 | ; Receiver loop (numbers in brackets are cycles within byte after instr) 118 | ;---------------------------------------------------------------------------- 119 | 120 | ; duration of unstuffing code should be 10.66666667 cycles. We adjust "leap" 121 | ; accordingly to approximate this value in the long run. 122 | 123 | unstuff6: 124 | andi x2, USBMASK ;[03] 125 | ori x3, 1<<6 ;[04] will not be shifted any more 126 | andi shift, ~0x80;[05] 127 | mov x1, x2 ;[06] sampled bit 7 is actually re-sampled bit 6 128 | subi leap, -1 ;[07] total duration = 11 bits -> subtract 1/3 129 | rjmp didUnstuff6 ;[08] 130 | 131 | unstuff7: 132 | ori x3, 1<<7 ;[09] will not be shifted any more 133 | in x2, USBIN ;[00] [10] re-sample bit 7 134 | andi x2, USBMASK ;[01] 135 | andi shift, ~0x80;[02] 136 | subi leap, 2 ;[03] total duration = 10 bits -> add 1/3 137 | rjmp didUnstuff7 ;[04] 138 | 139 | unstuffEven: 140 | ori x3, 1<<6 ;[09] will be shifted right 6 times for bit 0 141 | in x1, USBIN ;[00] [10] 142 | andi shift, ~0x80;[01] 143 | andi x1, USBMASK ;[02] 144 | breq se0 ;[03] 145 | subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 146 | nop2 ;[05] 147 | rjmp didUnstuffE ;[06] 148 | 149 | unstuffOdd: 150 | ori x3, 1<<5 ;[09] will be shifted right 4 times for bit 1 151 | in x2, USBIN ;[00] [10] 152 | andi shift, ~0x80;[01] 153 | andi x2, USBMASK ;[02] 154 | breq se0 ;[03] 155 | subi leap, -1 ;[04] total duration = 11 bits -> subtract 1/3 156 | nop2 ;[05] 157 | rjmp didUnstuffO ;[06] 158 | 159 | rxByteLoop: 160 | andi x1, USBMASK ;[03] 161 | eor x2, x1 ;[04] 162 | subi leap, 1 ;[05] 163 | brpl skipLeap ;[06] 164 | subi leap, -3 ;1 one leap cycle every 3rd byte -> 85 + 1/3 cycles per byte 165 | nop ;1 166 | skipLeap: 167 | subi x2, 1 ;[08] 168 | ror shift ;[09] 169 | didUnstuff6: 170 | cpi shift, 0xfc ;[10] 171 | in x2, USBIN ;[00] [11] <-- sample bit 7 172 | brcc unstuff6 ;[01] 173 | andi x2, USBMASK ;[02] 174 | eor x1, x2 ;[03] 175 | subi x1, 1 ;[04] 176 | ror shift ;[05] 177 | didUnstuff7: 178 | cpi shift, 0xfc ;[06] 179 | brcc unstuff7 ;[07] 180 | eor x3, shift ;[08] reconstruct: x3 is 1 at bit locations we changed, 0 at others 181 | st y+, x3 ;[09] store data 182 | rxBitLoop: 183 | in x1, USBIN ;[00] [11] <-- sample bit 0/2/4 184 | andi x1, USBMASK ;[01] 185 | eor x2, x1 ;[02] 186 | andi x3, 0x3f ;[03] topmost two bits reserved for 6 and 7 187 | subi x2, 1 ;[04] 188 | ror shift ;[05] 189 | cpi shift, 0xfc ;[06] 190 | brcc unstuffEven ;[07] 191 | didUnstuffE: 192 | lsr x3 ;[08] 193 | lsr x3 ;[09] 194 | rxbit1: 195 | in x2, USBIN ;[00] [10] <-- sample bit 1/3/5 196 | andi x2, USBMASK ;[01] 197 | breq se0 ;[02] 198 | eor x1, x2 ;[03] 199 | subi x1, 1 ;[04] 200 | ror shift ;[05] 201 | cpi shift, 0xfc ;[06] 202 | brcc unstuffOdd ;[07] 203 | didUnstuffO: 204 | subi bitcnt, 0xab;[08] == addi 0x55, 0x55 = 0x100/3 205 | brcs rxBitLoop ;[09] 206 | 207 | subi cnt, 1 ;[10] 208 | in x1, USBIN ;[00] [11] <-- sample bit 6 209 | brcc rxByteLoop ;[01] 210 | rjmp overflow 211 | 212 | macro POP_STANDARD ; 14 cycles 213 | pop cnt 214 | pop x4 215 | pop x3 216 | pop x2 217 | pop x1 218 | pop shift 219 | pop bitcnt 220 | endm 221 | macro POP_RETI ; 7 cycles 222 | pop YH 223 | pop YL 224 | out SREG, YL 225 | pop YL 226 | endm 227 | 228 | #include "asmcommon.inc" 229 | 230 | ; USB spec says: 231 | ; idle = J 232 | ; J = (D+ = 0), (D- = 1) 233 | ; K = (D+ = 1), (D- = 0) 234 | ; Spec allows 7.5 bit times from EOP to SOP for replies 235 | 236 | bitstuffN: 237 | eor x1, x4 ;[5] 238 | ldi x2, 0 ;[6] 239 | nop2 ;[7] 240 | nop ;[9] 241 | out USBOUT, x1 ;[10] <-- out 242 | rjmp didStuffN ;[0] 243 | 244 | bitstuff6: 245 | eor x1, x4 ;[5] 246 | ldi x2, 0 ;[6] Carry is zero due to brcc 247 | rol shift ;[7] compensate for ror shift at branch destination 248 | rjmp didStuff6 ;[8] 249 | 250 | bitstuff7: 251 | ldi x2, 0 ;[2] Carry is zero due to brcc 252 | rjmp didStuff7 ;[3] 253 | 254 | 255 | sendNakAndReti: 256 | ldi x3, USBPID_NAK ;[-18] 257 | rjmp sendX3AndReti ;[-17] 258 | sendAckAndReti: 259 | ldi cnt, USBPID_ACK ;[-17] 260 | sendCntAndReti: 261 | mov x3, cnt ;[-16] 262 | sendX3AndReti: 263 | ldi YL, 20 ;[-15] x3==r20 address is 20 264 | ldi YH, 0 ;[-14] 265 | ldi cnt, 2 ;[-13] 266 | ; rjmp usbSendAndReti fallthrough 267 | 268 | ;usbSend: 269 | ;pointer to data in 'Y' 270 | ;number of bytes in 'cnt' -- including sync byte [range 2 ... 12] 271 | ;uses: x1...x4, btcnt, shift, cnt, Y 272 | ;Numbers in brackets are time since first bit of sync pattern is sent 273 | ;We don't match the transfer rate exactly (don't insert leap cycles every third 274 | ;byte) because the spec demands only 1.5% precision anyway. 275 | usbSendAndReti: ; 12 cycles until SOP 276 | in x2, USBDDR ;[-12] 277 | ori x2, USBMASK ;[-11] 278 | sbi USBOUT, USBMINUS;[-10] prepare idle state; D+ and D- must have been 0 (no pullups) 279 | in x1, USBOUT ;[-8] port mirror for tx loop 280 | out USBDDR, x2 ;[-7] <- acquire bus 281 | ; need not init x2 (bitstuff history) because sync starts with 0 282 | ldi x4, USBMASK ;[-6] exor mask 283 | ldi shift, 0x80 ;[-5] sync byte is first byte sent 284 | txByteLoop: 285 | ldi bitcnt, 0x35 ;[-4] [6] binary 0011 0101 286 | txBitLoop: 287 | sbrs shift, 0 ;[-3] [7] 288 | eor x1, x4 ;[-2] [8] 289 | out USBOUT, x1 ;[-1] [9] <-- out N 290 | ror shift ;[0] [10] 291 | ror x2 ;[1] 292 | didStuffN: 293 | cpi x2, 0xfc ;[2] 294 | brcc bitstuffN ;[3] 295 | lsr bitcnt ;[4] 296 | brcc txBitLoop ;[5] 297 | brne txBitLoop ;[6] 298 | 299 | sbrs shift, 0 ;[7] 300 | eor x1, x4 ;[8] 301 | didStuff6: 302 | out USBOUT, x1 ;[-1] [9] <-- out 6 303 | ror shift ;[0] [10] 304 | ror x2 ;[1] 305 | cpi x2, 0xfc ;[2] 306 | brcc bitstuff6 ;[3] 307 | ror shift ;[4] 308 | didStuff7: 309 | ror x2 ;[5] 310 | sbrs x2, 7 ;[6] 311 | eor x1, x4 ;[7] 312 | nop ;[8] 313 | cpi x2, 0xfc ;[9] 314 | out USBOUT, x1 ;[-1][10] <-- out 7 315 | brcc bitstuff7 ;[0] [11] 316 | ld shift, y+ ;[1] 317 | dec cnt ;[3] 318 | brne txByteLoop ;[4] 319 | ;make SE0: 320 | cbr x1, USBMASK ;[5] prepare SE0 [spec says EOP may be 21 to 25 cycles] 321 | lds x2, usbNewDeviceAddr;[6] 322 | lsl x2 ;[8] we compare with left shifted address 323 | subi YL, 20 + 2 ;[9] Only assign address on data packets, not ACK/NAK in x3 324 | sbci YH, 0 ;[10] 325 | out USBOUT, x1 ;[11] <-- out SE0 -- from now 2 bits = 22 cycles until bus idle 326 | ;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm: 327 | ;set address only after data packet was sent, not after handshake 328 | breq skipAddrAssign ;[0] 329 | sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer 330 | skipAddrAssign: 331 | ;end of usbDeviceAddress transfer 332 | ldi x2, 1< 40 | #ifndef __IAR_SYSTEMS_ASM__ 41 | #include 42 | #endif 43 | 44 | #define __attribute__(arg) /* not supported on IAR */ 45 | 46 | #ifdef __IAR_SYSTEMS_ASM__ 47 | #define __ASSEMBLER__ /* IAR does not define standard macro for asm */ 48 | #endif 49 | 50 | #ifdef __HAS_ELPM__ 51 | #define PROGMEM __farflash 52 | #else 53 | #define PROGMEM __flash 54 | #endif 55 | 56 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 57 | 58 | /* The following definitions are not needed by the driver, but may be of some 59 | * help if you port a gcc based project to IAR. 60 | */ 61 | #define cli() __disable_interrupt() 62 | #define sei() __enable_interrupt() 63 | #define wdt_reset() __watchdog_reset() 64 | #define _BV(x) (1 << (x)) 65 | 66 | /* assembler compatibility macros */ 67 | // clang-format off 68 | #define nop2 rjmp $+2 /* jump to next instruction */ 69 | // clang-format on 70 | #define XL r26 71 | #define XH r27 72 | #define YL r28 73 | #define YH r29 74 | #define ZL r30 75 | #define ZH r31 76 | #define lo8(x) LOW(x) 77 | #define hi8(x) \ 78 | (((x) >> 8) & 0xff) /* not HIGH to allow XLINK to make a proper range check \ 79 | */ 80 | 81 | /* Depending on the device you use, you may get problems with the way usbdrv.h 82 | * handles the differences between devices. Since IAR does not use #defines 83 | * for MCU registers, we can't check for the existence of a particular 84 | * register with an #ifdef. If the autodetection mechanism fails, include 85 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See 86 | * usbconfig-prototype.h and usbdrv.h for details. 87 | */ 88 | 89 | /* ------------------------------------------------------------------------- */ 90 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */ 91 | /* ------------------------------------------------------------------------- */ 92 | /* This port is not working (yet) */ 93 | 94 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */ 95 | 96 | #include 97 | #include 98 | 99 | #define __attribute__(arg) /* not supported on IAR */ 100 | 101 | #define PROGMEM __flash 102 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 103 | 104 | #ifndef __ASSEMBLER__ 105 | static inline void cli(void) { 106 | #asm("cli"); 107 | } 108 | static inline void sei(void) { 109 | #asm("sei"); 110 | } 111 | #endif 112 | #define _delay_ms(t) delay_ms(t) 113 | #define _BV(x) (1 << (x)) 114 | #define USB_CFG_USE_SWITCH_STATEMENT \ 115 | 1 /* macro for if() cascase fails for unknown reason */ 116 | 117 | #define macro .macro 118 | #define endm .endmacro 119 | // clang-format off 120 | #define nop2 rjmp .+0 /* jump to next instruction */ 121 | // clang-format on 122 | 123 | /* ------------------------------------------------------------------------- */ 124 | #else /* default development environment is avr-gcc/avr-libc */ 125 | /* ------------------------------------------------------------------------- */ 126 | 127 | #include 128 | #ifdef __ASSEMBLER__ 129 | // clang-format off 130 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */ 131 | // clang-format on 132 | #else 133 | #include 134 | #endif 135 | 136 | #if USB_CFG_DRIVER_FLASH_PAGE 137 | #define USB_READ_FLASH(addr) \ 138 | pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr)) 139 | #else 140 | #define USB_READ_FLASH(addr) pgm_read_byte(addr) 141 | #endif 142 | 143 | #define macro .macro 144 | #define endm .endm 145 | // clang-format off 146 | #define nop2 rjmp .+0 /* jump to next instruction */ 147 | // clang-format on 148 | 149 | #endif /* development environment */ 150 | 151 | /* for conveniecne, ensure that PRG_RDB exists */ 152 | #ifndef PRG_RDB 153 | #define PRG_RDB(addr) USB_READ_FLASH(addr) 154 | #endif 155 | #endif /* __usbportability_h_INCLUDED__ */ 156 | -------------------------------------------------------------------------------- /usbdrv_includer.c: -------------------------------------------------------------------------------- 1 | /* 2 | this file's purpose is to trick the Arduino IDE into including a file for 3 | compilation 4 | 5 | Copyright (c) 2013 Adafruit Industries 6 | All rights reserved. 7 | 8 | TrinketMouse is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as 10 | published by the Free Software Foundation, either version 3 of 11 | the License, or (at your option) any later version. 12 | 13 | TrinketMouse is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with TrinketMouse. If not, see 20 | . 21 | */ 22 | 23 | #include "cmdline_defs.h" 24 | #include "usbconfig.h" 25 | #include "usbdrv/usbdrv.c" -------------------------------------------------------------------------------- /usbdrvasm_includer.S: -------------------------------------------------------------------------------- 1 | /* 2 | this file's purpose is to trick the Arduino IDE into including a file for compilation 3 | 4 | Copyright (c) 2013 Adafruit Industries 5 | All rights reserved. 6 | 7 | TrinketMouse is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as 9 | published by the Free Software Foundation, either version 3 of 10 | the License, or (at your option) any later version. 11 | 12 | TrinketMouse is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with TrinketMouse. If not, see 19 | . 20 | */ 21 | 22 | #include "cmdline_defs.h" 23 | #include "usbconfig.h" 24 | #include "usbdrv/usbdrvasm.S" --------------------------------------------------------------------------------