├── pictures ├── UNO.jpg ├── Keyb_Adapter.jpg ├── Proto_Interface.jpg └── USB_Host_Shield.jpg ├── II_Encoder.h ├── layoutmemory.h ├── libraries └── USB_Host_Shield_Library_2.0 │ ├── library.properties │ ├── examples │ ├── max_LCD │ │ └── max_LCD.ino │ ├── HID │ │ ├── USBHIDJoystick │ │ │ ├── hidjoystickrptparser.h │ │ │ ├── USBHIDJoystick.ino │ │ │ └── hidjoystickrptparser.cpp │ │ ├── le3dp │ │ │ ├── le3dp_rptparser.h │ │ │ ├── le3dp.ino │ │ │ └── le3dp_rptparser.cpp │ │ ├── scale │ │ │ ├── scale_rptparser.h │ │ │ ├── scale.ino │ │ │ └── scale_rptparser.cpp │ │ ├── USBHID_desc │ │ │ ├── USBHID_desc.ino │ │ │ └── pgmstrings.h │ │ ├── USBHIDMultimediaKbd │ │ │ └── USBHIDMultimediaKbd.ino │ │ ├── SRWS1 │ │ │ ├── SRWS1.cpp │ │ │ └── SRWS1.h │ │ ├── USBHIDBootMouse │ │ │ └── USBHIDBootMouse.ino │ │ └── USBHIDBootKbd │ │ │ └── USBHIDBootKbd.ino │ ├── testusbhostFAT │ │ ├── README.md │ │ └── Makefile │ ├── Bluetooth │ │ ├── BTHID │ │ │ ├── MouseParser.h │ │ │ ├── BTHID.ino │ │ │ └── KeyboardParser.h │ │ ├── SPP │ │ │ └── SPP.ino │ │ ├── WiiBalanceBoard │ │ │ └── WiiBalanceBoard.ino │ │ ├── SPPMulti │ │ │ └── SPPMulti.ino │ │ ├── WiiUProController │ │ │ └── WiiUProController.ino │ │ └── Wii │ │ │ └── Wii.ino │ ├── PSBuzz │ │ └── PSBuzz.ino │ ├── adk │ │ ├── term_time │ │ │ └── term_time.ino │ │ ├── term_test │ │ │ └── term_test.ino │ │ ├── adk_barcode │ │ │ └── adk_barcode.ino │ │ ├── demokit_20 │ │ │ └── demokit_20.ino │ │ └── ArduinoBlinkLED │ │ │ └── ArduinoBlinkLED.ino │ ├── USBH_MIDI │ │ ├── eVY1_sample │ │ │ └── eVY1_sample.ino │ │ ├── USB_MIDI_converter │ │ │ └── USB_MIDI_converter.ino │ │ ├── USB_MIDI_converter_multi │ │ │ └── USB_MIDI_converter_multi.ino │ │ ├── USBH_MIDI_dump │ │ │ └── USBH_MIDI_dump.ino │ │ └── bidirectional_converter │ │ │ └── bidirectional_converter.ino │ ├── cdc_XR21B1411 │ │ └── XR_terminal │ │ │ └── XR_terminal.ino │ ├── ftdi │ │ └── USBFTDILoopback │ │ │ ├── USBFTDILoopback.ino │ │ │ └── pgmstrings.h │ ├── acm │ │ └── acm_terminal │ │ │ ├── acm_terminal.ino │ │ │ └── pgmstrings.h │ ├── pl2303 │ │ ├── pl2303_gps │ │ │ └── pl2303_gps.ino │ │ ├── pl2303_gprs_terminal │ │ │ └── pl2303_gprs_terminal.ino │ │ └── pl2303_xbee_terminal │ │ │ └── pl2303_xbee_terminal.ino │ ├── USB_desc │ │ └── pgmstrings.h │ ├── hub_demo │ │ └── pgmstrings.h │ ├── Xbox │ │ ├── XBOXUSB │ │ │ └── XBOXUSB.ino │ │ ├── XBOXOLD │ │ │ └── XBOXOLD.ino │ │ ├── XBOXONE │ │ │ └── XBOXONE.ino │ │ └── XBOXRECV │ │ │ └── XBOXRECV.ino │ └── PS4USB │ │ └── PS4USB.ino │ ├── WiiCameraReadme.md │ ├── Usb.h │ ├── sink_parser.h │ ├── library.json │ ├── xboxEnums.h │ ├── hexdump.h │ ├── parsetools.cpp │ ├── printhex.h │ ├── message.h │ ├── max_LCD.h │ ├── message.cpp │ ├── PSBuzz.cpp │ ├── usbh_midi.h │ ├── hidcomposite.h │ ├── hiduniversal.h │ ├── macros.h │ ├── parsetools.h │ ├── PS3Enums.h │ ├── PS4BT.h │ └── adk.h ├── backlog.h ├── layoutmemory.cpp ├── README.md └── II_Encoder.cpp /pictures/UNO.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mafrmt00/Apple_II_Keyboard/HEAD/pictures/UNO.jpg -------------------------------------------------------------------------------- /pictures/Keyb_Adapter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mafrmt00/Apple_II_Keyboard/HEAD/pictures/Keyb_Adapter.jpg -------------------------------------------------------------------------------- /pictures/Proto_Interface.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mafrmt00/Apple_II_Keyboard/HEAD/pictures/Proto_Interface.jpg -------------------------------------------------------------------------------- /pictures/USB_Host_Shield.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mafrmt00/Apple_II_Keyboard/HEAD/pictures/USB_Host_Shield.jpg -------------------------------------------------------------------------------- /II_Encoder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Arduino Pin definitioin for Keyboard Interface 4 | #define IIKEYB_D0 A2 5 | #define IIKEYB_D1 A3 6 | #define IIKEYB_D2 A0 7 | #define IIKEYB_D3 A1 8 | #define IIKEYB_D4 7 9 | #define IIKEYB_D5 6 10 | #define IIKEYB_D6 8 11 | 12 | #define IIKEYB_RESET 5 13 | #define IIKEYB_STRB 4 14 | 15 | 16 | class II_Encoder 17 | { 18 | public: 19 | void begin(void); 20 | void Reset(void); 21 | int IIputchar(int bOutput); 22 | int IIputs(const char *string); 23 | void IIprintf(char* format, ...); 24 | 25 | char *convert(unsigned int num, const int base, char *ptr); 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /layoutmemory.h: -------------------------------------------------------------------------------- 1 | /*! \file layoutmemory.h 2 | * \brief Handles selection of multiple keyboard layout. 3 | * 4 | * Toggles the keyboard layout WIN+SPace as a trigger e.g. and stores the current layout in eeprom. 5 | */ 6 | #pragma once 7 | 8 | class KeyLayout 9 | { 10 | public: 11 | KeyLayout(); 12 | void Init(void); 13 | void Restore(void); 14 | void Store(void); 15 | 16 | void Print(void); 17 | 18 | void Toggle(void); 19 | void Set(uint8_t uiLayoutID); 20 | uint8_t Get(void); 21 | 22 | private: 23 | uint8_t uiCurrentKeyboardLayout;//ID of the current active keyboard Layout 24 | 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/library.properties: -------------------------------------------------------------------------------- 1 | name=USB Host Shield Library 2.0 2 | version=1.3.2 3 | author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) 4 | maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll 5 | sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. 6 | paragraph=Supports HID devices, FTDI, ADK, ACM, PL2303, Bluetooth HID devices, SPP communication and mass storage devices. Furthermore it supports PS3, PS4, PS Buzz, Wii and Xbox controllers. 7 | category=Other 8 | url=https://github.com/felis/USB_Host_Shield_2.0 9 | architectures=* 10 | -------------------------------------------------------------------------------- /backlog.h: -------------------------------------------------------------------------------- 1 | /*! \file backlog.h 2 | * \brief Provides BASH like command backlog. 3 | * 4 | * With the Arrow Up / Down keys the last commands can be recalled and used. 5 | */ 6 | #pragma once 7 | 8 | #define BUFFER_STEPS 40 9 | #define BACKLOG_STEPS 10 10 | #define CHAR_OUT_DELAY 10 11 | 12 | class Backlog 13 | { 14 | private: 15 | uint8_t BacklogOutputPointer; 16 | 17 | char* StringBacklog[BACKLOG_STEPS]; 18 | char* pCurrentInputString; 19 | void IncreaseBuffer(void); 20 | void BacklogCurrString(void); 21 | 22 | int (*pputs)(const char *string); 23 | 24 | void EraseCurrent(void); 25 | void OutputCurrent(void); 26 | 27 | void ChangeToIndex(uint8_t uiNewIndex); 28 | 29 | public: 30 | Backlog(); 31 | void addchar(char c); 32 | void SetPuts(int (*pputs_funcp)(const char *string)); 33 | void OneBack(void); 34 | void OneForeward(void); 35 | }; 36 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/max_LCD/max_LCD.ino: -------------------------------------------------------------------------------- 1 | // Just a copy of the HelloWorld example bundled with the LiquidCrystal library in the Arduino IDE 2 | 3 | // HD44780 compatible LCD display via MAX3421E GPOUT support header 4 | // pinout: D[4-7] -> GPOUT[4-7], RS-> GPOUT[2], E ->GPOUT[3] 5 | 6 | #include 7 | 8 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #endif 12 | #include 13 | 14 | USB Usb; 15 | Max_LCD lcd(&Usb); 16 | 17 | void setup() { 18 | // Set up the LCD's number of columns and rows: 19 | lcd.begin(16, 2); 20 | // Print a message to the LCD. 21 | lcd.print("Hello, World!"); 22 | } 23 | 24 | void loop() { 25 | // Set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0): 26 | lcd.setCursor(0, 1); 27 | // Print the number of seconds since reset: 28 | lcd.print((uint32_t)millis() / 1000); 29 | } 30 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/WiiCameraReadme.md: -------------------------------------------------------------------------------- 1 | Please see for the complete capabilities of the Wii camera. The IR camera code was written based on the above website and with support from Kristian Lauszus. 2 | 3 | This library is large, if you run into memory problems when uploading to the Arduino, disable serial debugging. 4 | 5 | To enable the IR camera code, simply set ```ENABLE_WII_IR_CAMERA``` to 1 in [settings.h](settings.h). 6 | 7 | This library implements the following settings: 8 | 9 | * Report sensitivity mode: 00 00 00 00 00 00 90 00 41 40 00 Suggested by inio (high sensitivity) 10 | * Data Format: Extended mode (0x03). Full mode is not working yet. The output reports 0x3e and 0x3f need tampering with 11 | * In this mode the camera outputs x and y coordinates and a size dimension for the 4 brightest points. 12 | 13 | Again, read through to get an understanding of the camera and its settings. 14 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDJoystick/hidjoystickrptparser.h: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | }; 17 | 18 | #define RPT_GEMEPAD_LEN 5 19 | 20 | class JoystickReportParser : public HIDReportParser { 21 | JoystickEvents *joyEvents; 22 | 23 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 24 | uint8_t oldHat; 25 | uint16_t oldButtons; 26 | 27 | public: 28 | JoystickReportParser(JoystickEvents *evt); 29 | 30 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 31 | }; 32 | 33 | #endif // __HIDJOYSTICKRPTPARSER_H__ 34 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/le3dp/le3dp_rptparser.h: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData 7 | { 8 | union { //axes and hut switch 9 | uint32_t axes; 10 | struct { 11 | uint32_t x : 10; 12 | uint32_t y : 10; 13 | uint32_t hat : 4; 14 | uint32_t twist : 8; 15 | }; 16 | }; 17 | uint8_t buttons_a; 18 | uint8_t slider; 19 | uint8_t buttons_b; 20 | }; 21 | 22 | class JoystickEvents 23 | { 24 | public: 25 | virtual void OnGamePadChanged(const GamePadEventData *evt); 26 | }; 27 | 28 | #define RPT_GAMEPAD_LEN sizeof(GamePadEventData)/sizeof(uint8_t) 29 | 30 | class JoystickReportParser : public HIDReportParser 31 | { 32 | JoystickEvents *joyEvents; 33 | 34 | uint8_t oldPad[RPT_GAMEPAD_LEN]; 35 | 36 | public: 37 | JoystickReportParser(JoystickEvents *evt); 38 | 39 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 40 | }; 41 | 42 | #endif // __HIDJOYSTICKRPTPARSER_H__ 43 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDJoystick/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Satisfy IDE, which only needs to see the include statment in the ino. 6 | #ifdef dobogusinclude 7 | #include 8 | #endif 9 | #include 10 | 11 | #include "hidjoystickrptparser.h" 12 | 13 | USB Usb; 14 | USBHub Hub(&Usb); 15 | HIDUniversal Hid(&Usb); 16 | JoystickEvents JoyEvents; 17 | JoystickReportParser Joy(&JoyEvents); 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | #if !defined(__MIPSEL__) 22 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 23 | #endif 24 | Serial.println("Start"); 25 | 26 | if (Usb.Init() == -1) 27 | Serial.println("OSC did not start."); 28 | 29 | delay(200); 30 | 31 | if (!Hid.SetReportParser(0, &Joy)) 32 | ErrorMessage (PSTR("SetReportParser"), 1); 33 | } 34 | 35 | void loop() { 36 | Usb.Task(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/le3dp/le3dp.ino: -------------------------------------------------------------------------------- 1 | /* Simplified Logitech Extreme 3D Pro Joystick Report Parser */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "le3dp_rptparser.h" 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | USB Usb; 16 | USBHub Hub(&Usb); 17 | HIDUniversal Hid(&Usb); 18 | JoystickEvents JoyEvents; 19 | JoystickReportParser Joy(&JoyEvents); 20 | 21 | void setup() 22 | { 23 | Serial.begin( 115200 ); 24 | #if !defined(__MIPSEL__) 25 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 26 | #endif 27 | Serial.println("Start"); 28 | 29 | if (Usb.Init() == -1) 30 | Serial.println("OSC did not start."); 31 | 32 | delay( 200 ); 33 | 34 | if (!Hid.SetReportParser(0, &Joy)) 35 | ErrorMessage(PSTR("SetReportParser"), 1 ); 36 | } 37 | 38 | void loop() 39 | { 40 | Usb.Task(); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/scale/scale_rptparser.h: -------------------------------------------------------------------------------- 1 | #if !defined(__SCALERPTPARSER_H__) 2 | #define __SCALERPTPARSER_H__ 3 | 4 | #include 5 | #include 6 | 7 | /* Scale status constants */ 8 | #define REPORT_FAULT 0x01 9 | #define ZEROED 0x02 10 | #define WEIGHING 0x03 11 | #define WEIGHT_VALID 0x04 12 | #define WEIGHT_NEGATIVE 0x05 13 | #define OVERWEIGHT 0x06 14 | #define CALIBRATE_ME 0x07 15 | #define ZERO_ME 0x08 16 | 17 | /* input data report */ 18 | struct ScaleEventData 19 | { 20 | uint8_t reportID; //must be 3 21 | uint8_t status; 22 | uint8_t unit; 23 | int8_t exp; //scale factor for the weight 24 | uint16_t weight; // 25 | }; 26 | 27 | class ScaleEvents 28 | { 29 | 30 | Max_LCD* pLcd; 31 | 32 | void LcdPrint( const char* str ); 33 | 34 | public: 35 | 36 | ScaleEvents( Max_LCD* pLCD ); 37 | 38 | virtual void OnScaleChanged(const ScaleEventData *evt); 39 | }; 40 | 41 | #define RPT_SCALE_LEN sizeof(ScaleEventData)/sizeof(uint8_t) 42 | 43 | class ScaleReportParser : public HIDReportParser 44 | { 45 | ScaleEvents *scaleEvents; 46 | 47 | uint8_t oldScale[RPT_SCALE_LEN]; 48 | 49 | public: 50 | ScaleReportParser(ScaleEvents *evt); 51 | 52 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 53 | }; 54 | 55 | #endif // __SCALERPTPARSER_H__ 56 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/Usb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | /* USB functions */ 18 | #ifndef _usb_h_ 19 | #define _usb_h_ 20 | 21 | // WARNING: Do not change the order of includes, or stuff will break! 22 | #include 23 | #include 24 | #include 25 | 26 | // None of these should ever be included by a driver, or a user's sketch. 27 | #include "settings.h" 28 | #include "printhex.h" 29 | #include "message.h" 30 | #include "hexdump.h" 31 | #include "sink_parser.h" 32 | #include "max3421e.h" 33 | #include "address.h" 34 | #include "avrpins.h" 35 | #include "usb_ch9.h" 36 | #include "usbhost.h" 37 | #include "UsbCore.h" 38 | #include "parsetools.h" 39 | #include "confdescparser.h" 40 | 41 | #endif //_usb_h_ 42 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/sink_parser.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | #if !defined(_usb_h_) || defined(__SINK_PARSER_H__) 18 | #error "Never include hexdump.h directly; include Usb.h instead" 19 | #else 20 | #define __SINK_PARSER_H__ 21 | 22 | extern int UsbDEBUGlvl; 23 | 24 | // This parser does absolutely nothing with the data, just swallows it. 25 | 26 | template 27 | class SinkParser : public BASE_CLASS { 28 | public: 29 | 30 | SinkParser() { 31 | }; 32 | 33 | void Initialize() { 34 | }; 35 | 36 | void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) { 37 | }; 38 | }; 39 | 40 | 41 | #endif // __HEXDUMP_H__ 42 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/testusbhostFAT/README.md: -------------------------------------------------------------------------------- 1 | This small sketch tests the USB host shield mass storage library. 2 | 3 | __Note:__ This will not run a Arduino Uno due to the limited ram available in the ATmega328p. 4 | 5 | The Arduino Mega (ATmega1280) and the Arduino Mega 2560 (ATmega2560) are confirmed to work with this test code. 6 | 7 | To compile this example you will need the following libraries as well: 8 | 9 | * [xmem2](https://github.com/xxxajk/xmem2) 10 | * [generic_storage FATfs](https://github.com/xxxajk/generic_storage) 11 | * [RTClib](https://github.com/xxxajk/RTClib) 12 | 13 | The following shield is recommended for larger projects: . 14 | 15 | You may use the bundled [Makefile](Makefile) to compile the code instead of the Arduino IDE if you have problems or want a smaller binary. The master makefile is bundled as a submodule, but can also be downloaded manually at the following link: . 16 | 17 | To download the USB Host library and all the needed libraries for this test. 18 | 19 | Run the following command in a terminal application: 20 | 21 | ``` 22 | git clone --recursive https://github.com/felis/USB_Host_Shield_2.0 23 | ``` 24 | 25 | If you want to update all the submodules run: 26 | 27 | ``` 28 | git submodule foreach --recursive git pull origin master 29 | ``` 30 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/le3dp/le3dp_rptparser.cpp: -------------------------------------------------------------------------------- 1 | #include "le3dp_rptparser.h" 2 | 3 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 4 | joyEvents(evt) 5 | {} 6 | 7 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) 8 | { 9 | bool match = true; 10 | 11 | // Checking if there are changes in report since the method was last called 12 | for (uint8_t i=0; iOnGamePadChanged((const GamePadEventData*)buf); 21 | 22 | for (uint8_t i=0; i(evt->x, 0x80); 30 | Serial.print(" Y: "); 31 | PrintHex(evt->y, 0x80); 32 | Serial.print(" Hat Switch: "); 33 | PrintHex(evt->hat, 0x80); 34 | Serial.print(" Twist: "); 35 | PrintHex(evt->twist, 0x80); 36 | Serial.print(" Slider: "); 37 | PrintHex(evt->slider, 0x80); 38 | Serial.print(" Buttons A: "); 39 | PrintHex(evt->buttons_a, 0x80); 40 | Serial.print(" Buttons B: "); 41 | PrintHex(evt->buttons_b, 0x80); 42 | Serial.println(""); 43 | } 44 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/BTHID/MouseParser.h: -------------------------------------------------------------------------------- 1 | #ifndef __mouserptparser_h__ 2 | #define __mouserptparser_h__ 3 | 4 | class MouseRptParser : public MouseReportParser { 5 | protected: 6 | virtual void OnMouseMove(MOUSEINFO *mi); 7 | virtual void OnLeftButtonUp(MOUSEINFO *mi); 8 | virtual void OnLeftButtonDown(MOUSEINFO *mi); 9 | virtual void OnRightButtonUp(MOUSEINFO *mi); 10 | virtual void OnRightButtonDown(MOUSEINFO *mi); 11 | virtual void OnMiddleButtonUp(MOUSEINFO *mi); 12 | virtual void OnMiddleButtonDown(MOUSEINFO *mi); 13 | }; 14 | 15 | void MouseRptParser::OnMouseMove(MOUSEINFO *mi) { 16 | Serial.print(F("dx=")); 17 | Serial.print(mi->dX, DEC); 18 | Serial.print(F(" dy=")); 19 | Serial.println(mi->dY, DEC); 20 | }; 21 | 22 | void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) { 23 | Serial.println(F("L Butt Up")); 24 | }; 25 | 26 | void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) { 27 | Serial.println(F("L Butt Dn")); 28 | }; 29 | 30 | void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) { 31 | Serial.println(F("R Butt Up")); 32 | }; 33 | 34 | void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) { 35 | Serial.println(F("R Butt Dn")); 36 | }; 37 | 38 | void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) { 39 | Serial.println(F("M Butt Up")); 40 | }; 41 | 42 | void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) { 43 | Serial.println(F("M Butt Dn")); 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "USB-Host-Shield-20", 3 | "keywords": "usb, host, ftdi, adk, acm, pl2303, hid, bluetooth, spp, ps3, ps4, buzz, xbox, wii, mass storage", 4 | "description": "Revision 2.0 of MAX3421E-based USB Host Shield Library", 5 | "authors": 6 | [ 7 | { 8 | "name": "Oleg Mazurov", 9 | "email": "mazurov@circuitsathome.com", 10 | "url": "http://www.circuitsathome.com", 11 | "maintainer": true 12 | }, 13 | { 14 | "name": "Alexei Glushchenko", 15 | "email": "alex-gl@mail.ru" 16 | }, 17 | { 18 | "name": "Kristian Lauszus", 19 | "email": "kristianl@tkjelectronics.com", 20 | "url": "http://tkjelectronics.com", 21 | "maintainer": true 22 | }, 23 | { 24 | "name": "Andrew Kroll", 25 | "email": "xxxajk@gmail.com", 26 | "maintainer": true 27 | } 28 | ], 29 | "repository": 30 | { 31 | "type": "git", 32 | "url": "https://github.com/felis/USB_Host_Shield_2.0.git" 33 | }, 34 | "version": "1.3.2", 35 | "license": "GPL-2.0", 36 | "examples": 37 | [ 38 | "examples/*/*.ino", 39 | "examples/*/*/*.ino" 40 | ], 41 | "frameworks": 42 | [ 43 | "arduino", 44 | "spl" 45 | ], 46 | "platforms": 47 | [ 48 | "atmelavr", 49 | "intel_arc32", 50 | "teensy", 51 | "atmelsam", 52 | "nordicnrf51", 53 | "ststm32", 54 | "espressif8266", 55 | "espressif32" 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/PSBuzz/PSBuzz.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Playstation Buzz library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | USB Usb; 16 | PSBuzz Buzz(&Usb); 17 | 18 | void setup() { 19 | Serial.begin(115200); 20 | #if !defined(__MIPSEL__) 21 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 22 | #endif 23 | if (Usb.Init() == -1) { 24 | Serial.print(F("\r\nOSC did not start")); 25 | while (1); // Halt 26 | } 27 | Serial.println(F("\r\nPS Buzz Library Started")); 28 | } 29 | 30 | void loop() { 31 | Usb.Task(); 32 | 33 | if (Buzz.connected()) { 34 | for (uint8_t i = 0; i < 4; i++) { 35 | if (Buzz.getButtonClick(RED, i)) { 36 | Buzz.setLedToggle(i); // Toggle the LED 37 | Serial.println(F("RED")); 38 | } 39 | if (Buzz.getButtonClick(YELLOW, i)) 40 | Serial.println(F("YELLOW")); 41 | if (Buzz.getButtonClick(GREEN, i)) 42 | Serial.println(F("GREEN")); 43 | if (Buzz.getButtonClick(ORANGE, i)) 44 | Serial.println(F("ORANGE")); 45 | if (Buzz.getButtonClick(BLUE, i)) 46 | Serial.println(F("BLUE")); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/scale/scale.ino: -------------------------------------------------------------------------------- 1 | /* Digital Scale Output. Written for Stamps.com Model 510 */ 2 | /* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "scale_rptparser.h" 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | USBHub Hub(&Usb); 18 | HIDUniversal Hid(&Usb); 19 | Max_LCD LCD(&Usb); 20 | ScaleEvents ScaleEvents(&LCD); 21 | ScaleReportParser Scale(&ScaleEvents); 22 | 23 | void setup() 24 | { 25 | Serial.begin( 115200 ); 26 | #if !defined(__MIPSEL__) 27 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 28 | #endif 29 | Serial.println("Start"); 30 | 31 | if (Usb.Init() == -1) 32 | Serial.println("OSC did not start."); 33 | 34 | // set up the LCD's number of rows and columns: 35 | LCD.begin(16, 2); 36 | LCD.clear(); 37 | LCD.home(); 38 | LCD.setCursor(0,0); 39 | LCD.write('R'); 40 | 41 | delay( 200 ); 42 | 43 | if (!Hid.SetReportParser(0, &Scale)) 44 | ErrorMessage(PSTR("SetReportParser"), 1 ); 45 | } 46 | 47 | void loop() 48 | { 49 | Usb.Task(); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/adk/term_time/term_time.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy IDE, which only needs to see the include statment in the ino. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | USB Usb; 11 | 12 | ADK adk(&Usb, "Circuits@Home, ltd.", 13 | "USB Host Shield", 14 | "Arduino Terminal for Android", 15 | "1.0", 16 | "http://www.circuitsathome.com", 17 | "0000000000000001"); 18 | 19 | void setup() 20 | { 21 | Serial.begin(115200); 22 | #if !defined(__MIPSEL__) 23 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 24 | #endif 25 | Serial.println("\r\nADK demo start"); 26 | 27 | if (Usb.Init() == -1) { 28 | Serial.println("OSCOKIRQ failed to assert"); 29 | while (1); //halt 30 | }//if (Usb.Init() == -1... 31 | } 32 | 33 | void loop() 34 | { 35 | uint8_t buf[ 12 ] = { 0 }; //buffer to convert unsigned long to ASCII 36 | const char* sec_ela = " seconds elapsed\r"; 37 | uint8_t rcode; 38 | 39 | Usb.Task(); 40 | if ( adk.isReady() == false ) { 41 | return; 42 | } 43 | 44 | ultoa((uint32_t)millis() / 1000, (char *)buf, 10 ); 45 | 46 | rcode = adk.SndData( strlen((char *)buf), buf ); 47 | if (rcode && rcode != hrNAK) { 48 | Serial.print(F("\r\nData send: ")); 49 | Serial.print(rcode, HEX); 50 | } 51 | rcode = adk.SndData( strlen( sec_ela), (uint8_t *)sec_ela ); 52 | if (rcode && rcode != hrNAK) { 53 | Serial.print(F("\r\nData send: ")); 54 | Serial.print(rcode, HEX); 55 | } 56 | 57 | delay( 1000 ); 58 | } 59 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/SPP/SPP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 18 | 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | /* You can create the instance of the class in two ways */ 21 | SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000" 22 | //SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so 23 | 24 | bool firstMessage = true; 25 | 26 | void setup() { 27 | Serial.begin(115200); 28 | #if !defined(__MIPSEL__) 29 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 30 | #endif 31 | if (Usb.Init() == -1) { 32 | Serial.print(F("\r\nOSC did not start")); 33 | while (1); //halt 34 | } 35 | Serial.print(F("\r\nSPP Bluetooth Library Started")); 36 | } 37 | void loop() { 38 | Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 39 | 40 | if (SerialBT.connected) { 41 | if (firstMessage) { 42 | firstMessage = false; 43 | SerialBT.println(F("Hello from Arduino")); // Send welcome message 44 | } 45 | if (Serial.available()) 46 | SerialBT.write(Serial.read()); 47 | if (SerialBT.available()) 48 | Serial.write(SerialBT.read()); 49 | } 50 | else 51 | firstMessage = true; 52 | } 53 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHID_desc/USBHID_desc.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pgmstrings.h" 6 | 7 | // Satisfy the IDE, which needs to see the include statment in the ino too. 8 | #ifdef dobogusinclude 9 | #include 10 | #endif 11 | #include 12 | 13 | class HIDUniversal2 : public HIDUniversal 14 | { 15 | public: 16 | HIDUniversal2(USB *usb) : HIDUniversal(usb) {}; 17 | 18 | protected: 19 | uint8_t OnInitSuccessful(); 20 | }; 21 | 22 | uint8_t HIDUniversal2::OnInitSuccessful() 23 | { 24 | uint8_t rcode; 25 | 26 | HexDumper Hex; 27 | ReportDescParser Rpt; 28 | 29 | if ((rcode = GetReportDescr(0, &Hex))) 30 | goto FailGetReportDescr1; 31 | 32 | if ((rcode = GetReportDescr(0, &Rpt))) 33 | goto FailGetReportDescr2; 34 | 35 | return 0; 36 | 37 | FailGetReportDescr1: 38 | USBTRACE("GetReportDescr1:"); 39 | goto Fail; 40 | 41 | FailGetReportDescr2: 42 | USBTRACE("GetReportDescr2:"); 43 | goto Fail; 44 | 45 | Fail: 46 | Serial.println(rcode, HEX); 47 | Release(); 48 | return rcode; 49 | } 50 | 51 | USB Usb; 52 | //USBHub Hub(&Usb); 53 | HIDUniversal2 Hid(&Usb); 54 | UniversalReportParser Uni; 55 | 56 | void setup() 57 | { 58 | Serial.begin( 115200 ); 59 | #if !defined(__MIPSEL__) 60 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 61 | #endif 62 | Serial.println("Start"); 63 | 64 | if (Usb.Init() == -1) 65 | Serial.println("OSC did not start."); 66 | 67 | delay( 200 ); 68 | 69 | if (!Hid.SetReportParser(0, &Uni)) 70 | ErrorMessage(PSTR("SetReportParser"), 1 ); 71 | } 72 | 73 | void loop() 74 | { 75 | Usb.Task(); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /layoutmemory.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | #include "layoutmemory.h" 4 | 5 | #define MAX_KEYB_LAYOUT_ID 1 6 | 7 | /*! \brief Only init variables 8 | 9 | */ 10 | KeyLayout::KeyLayout() 11 | { 12 | uiCurrentKeyboardLayout = 0xFF; 13 | } 14 | 15 | /*! \brief Init function, not to be called from constructor. 16 | 17 | Restores settings from eeprom. 18 | */ 19 | void KeyLayout::Init(void) 20 | { 21 | Restore(); 22 | } 23 | 24 | /*! \brief Print current selected layout namew. 25 | 26 | */ 27 | void KeyLayout::Print(void) 28 | { 29 | Serial.print("Keyboard Layout is: "); 30 | 31 | switch (uiCurrentKeyboardLayout) 32 | { 33 | case 0: 34 | Serial.println("US"); 35 | break; 36 | case 1: 37 | Serial.println("DE"); 38 | break; 39 | default: 40 | Serial.println(uiCurrentKeyboardLayout, HEX); 41 | break; 42 | } 43 | } 44 | 45 | /*! \brief Stores current active layout to eeprom. 46 | 47 | */ 48 | void KeyLayout::Store(void) 49 | { 50 | EEPROM.write(0, uiCurrentKeyboardLayout); 51 | } 52 | 53 | /*! \brief Restores active layout from eeprom. 54 | 55 | */ 56 | void KeyLayout::Restore(void) 57 | { 58 | Set(EEPROM.read(0)); 59 | } 60 | 61 | /*! \brief Select new layout. 62 | 63 | Switch to the next layout and back to 0 if the MAX_KEYB_LAYOUT_ID is reached. 64 | */ 65 | void KeyLayout::Toggle(void) 66 | { 67 | Set(uiCurrentKeyboardLayout + 1); 68 | } 69 | 70 | 71 | /*! \brief Set the active layout direct.. 72 | 73 | Sets the active layout and thecks the range. 74 | */ 75 | void KeyLayout::Set(uint8_t uiLayoutID) 76 | { 77 | if (uiLayoutID > MAX_KEYB_LAYOUT_ID) 78 | uiLayoutID = 0; 79 | 80 | if (uiCurrentKeyboardLayout != uiLayoutID) 81 | { 82 | uiCurrentKeyboardLayout = uiLayoutID; 83 | Store(); 84 | Print(); 85 | } 86 | } 87 | 88 | 89 | /*! \brief Returns the current active layout. 90 | 91 | */ 92 | uint8_t KeyLayout::Get(void) 93 | { 94 | return uiCurrentKeyboardLayout; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/xboxEnums.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #ifndef _xboxenums_h 19 | #define _xboxenums_h 20 | 21 | #include "controllerEnums.h" 22 | 23 | /** Enum used to set special LED modes supported by the Xbox controller. */ 24 | enum LEDModeEnum { 25 | ROTATING = 0x0A, 26 | FASTBLINK = 0x0B, 27 | SLOWBLINK = 0x0C, 28 | ALTERNATING = 0x0D, 29 | }; 30 | 31 | /** Used to set the LEDs on the controllers */ 32 | const uint8_t XBOX_LEDS[] PROGMEM = { 33 | 0x00, // OFF 34 | 0x02, // LED1 35 | 0x03, // LED2 36 | 0x04, // LED3 37 | 0x05, // LED4 38 | 0x01, // ALL - Used to blink all LEDs 39 | }; 40 | /** Buttons on the controllers */ 41 | const uint16_t XBOX_BUTTONS[] PROGMEM = { 42 | 0x0100, // UP 43 | 0x0800, // RIGHT 44 | 0x0200, // DOWN 45 | 0x0400, // LEFT 46 | 47 | 0x2000, // BACK 48 | 0x1000, // START 49 | 0x4000, // L3 50 | 0x8000, // R3 51 | 52 | 0, 0, // Skip L2 and R2 as these are analog buttons 53 | 0x0001, // L1 54 | 0x0002, // R1 55 | 56 | 0x0020, // B 57 | 0x0010, // A 58 | 0x0040, // X 59 | 0x0080, // Y 60 | 61 | 0x0004, // XBOX 62 | 0x0008, // SYNC 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Wii Balance Board Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 18 | 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | /* You can create the instance of the class in two ways */ 21 | WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wii Balance Board - you only have to do this once 22 | //WII Wii(&Btd); // After that you can simply create the instance like so and then press the power button on the Wii Balance Board 23 | 24 | void setup() { 25 | Serial.begin(115200); 26 | #if !defined(__MIPSEL__) 27 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 28 | #endif 29 | if (Usb.Init() == -1) { 30 | Serial.print(F("\r\nOSC did not start")); 31 | while (1); //halt 32 | } 33 | Serial.print(F("\r\nWii Balance Board Bluetooth Library Started")); 34 | } 35 | void loop() { 36 | Usb.Task(); 37 | if (Wii.wiiBalanceBoardConnected) { 38 | Serial.print(F("\r\nWeight: ")); 39 | for (uint8_t i = 0; i < 4; i++) { 40 | Serial.print(Wii.getWeight((BalanceBoardEnum)i)); 41 | Serial.print(F("\t")); 42 | } 43 | Serial.print(F("Total Weight: ")); 44 | Serial.print(Wii.getTotalWeight()); 45 | if (Wii.getButtonClick(A)) { 46 | Serial.print(F("\r\nA")); 47 | //Wii.setLedToggle(LED1); // The Wii Balance Board has one LED as well 48 | Wii.disconnect(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy the IDE, which needs to see the include statment in the ino too. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | // Override HIDComposite to be able to select which interface we want to hook into 11 | class HIDSelector : public HIDComposite 12 | { 13 | public: 14 | HIDSelector(USB *p) : HIDComposite(p) {}; 15 | 16 | protected: 17 | void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library 18 | bool SelectInterface(uint8_t iface, uint8_t proto); 19 | }; 20 | 21 | // Return true for the interface we want to hook into 22 | bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) 23 | { 24 | if (proto != 0) 25 | return true; 26 | 27 | return false; 28 | } 29 | 30 | // Will be called for all HID data received from the USB interface 31 | void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { 32 | #if 1 33 | if (len && buf) { 34 | Notify(PSTR("\r\n"), 0x80); 35 | for (uint8_t i = 0; i < len; i++) { 36 | D_PrintHex (buf[i], 0x80); 37 | Notify(PSTR(" "), 0x80); 38 | } 39 | } 40 | #endif 41 | } 42 | 43 | USB Usb; 44 | //USBHub Hub(&Usb); 45 | HIDSelector hidSelector(&Usb); 46 | 47 | void setup() 48 | { 49 | Serial.begin( 115200 ); 50 | #if !defined(__MIPSEL__) 51 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 52 | #endif 53 | Serial.println("Start"); 54 | 55 | if (Usb.Init() == -1) 56 | Serial.println("OSC did not start."); 57 | 58 | // Set this to higher values to enable more debug information 59 | // minimum 0x00, maximum 0xff, default 0x80 60 | UsbDEBUGlvl = 0xff; 61 | 62 | delay( 200 ); 63 | } 64 | 65 | void loop() 66 | { 67 | Usb.Task(); 68 | } 69 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/adk/term_test/term_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy IDE, which only needs to see the include statment in the ino. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | USB Usb; 11 | //USBHub Hub(&Usb); 12 | 13 | ADK adk(&Usb, "Circuits@Home, ltd.", 14 | "USB Host Shield", 15 | "Arduino Terminal for Android", 16 | "1.0", 17 | "http://www.circuitsathome.com", 18 | "0000000000000001"); 19 | 20 | void setup() 21 | { 22 | Serial.begin(115200); 23 | #if !defined(__MIPSEL__) 24 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 25 | #endif 26 | Serial.println("\r\nADK demo start"); 27 | 28 | if (Usb.Init() == -1) { 29 | Serial.println("OSCOKIRQ failed to assert"); 30 | while (1); //halt 31 | }//if (Usb.Init() == -1... 32 | } 33 | 34 | void loop() 35 | { 36 | uint8_t rcode; 37 | uint8_t msg[64] = { 0x00 }; 38 | const char* recv = "Received: "; 39 | 40 | Usb.Task(); 41 | 42 | if ( adk.isReady() == false ) { 43 | return; 44 | } 45 | uint16_t len = 64; 46 | 47 | rcode = adk.RcvData(&len, msg); 48 | if ( rcode & ( rcode != hrNAK )) { 49 | USBTRACE2("Data rcv. :", rcode ); 50 | } 51 | if (len > 0) { 52 | USBTRACE("\r\nData Packet."); 53 | 54 | for ( uint8_t i = 0; i < len; i++ ) { 55 | Serial.print((char)msg[i]); 56 | } 57 | /* sending back what was received */ 58 | rcode = adk.SndData( strlen( recv ), (uint8_t *)recv ); 59 | if (rcode && rcode != hrNAK) { 60 | Serial.print(F("\r\nData send: ")); 61 | Serial.print(rcode, HEX); 62 | } 63 | rcode = adk.SndData( strlen(( char * )msg ), msg ); 64 | if (rcode && rcode != hrNAK) { 65 | Serial.print(F("\r\nData send: ")); 66 | Serial.print(rcode, HEX); 67 | } 68 | 69 | }//if( len > 0 )... 70 | 71 | delay( 1000 ); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/BTHID/BTHID.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the HID Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | #include "KeyboardParser.h" 10 | #include "MouseParser.h" 11 | 12 | // Satisfy the IDE, which needs to see the include statment in the ino too. 13 | #ifdef dobogusinclude 14 | #include 15 | #endif 16 | #include 17 | 18 | USB Usb; 19 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 20 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 21 | 22 | /* You can create the instance of the class in two ways */ 23 | // This will start an inquiry and then pair with your device - you only have to do this once 24 | // If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter 25 | BTHID bthid(&Btd, PAIR, "0000"); 26 | 27 | // After that you can simply create the instance like so and then press any button on the device 28 | //BTHID hid(&Btd); 29 | 30 | KbdRptParser keyboardPrs; 31 | MouseRptParser mousePrs; 32 | 33 | void setup() { 34 | Serial.begin(115200); 35 | #if !defined(__MIPSEL__) 36 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 37 | #endif 38 | if (Usb.Init() == -1) { 39 | Serial.print(F("\r\nOSC did not start")); 40 | while (1); // Halt 41 | } 42 | 43 | bthid.SetReportParser(KEYBOARD_PARSER_ID, &keyboardPrs); 44 | bthid.SetReportParser(MOUSE_PARSER_ID, &mousePrs); 45 | 46 | // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" 47 | // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report 48 | bthid.setProtocolMode(USB_HID_BOOT_PROTOCOL); // Boot Protocol Mode 49 | //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode 50 | 51 | Serial.print(F("\r\nHID Bluetooth Library Started")); 52 | } 53 | void loop() { 54 | Usb.Task(); 55 | } 56 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/SRWS1/SRWS1.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2016 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #include "SRWS1.h" 19 | 20 | void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 21 | if (HIDUniversal::VID != STEELSERIES_VID || HIDUniversal::PID != STEELSERIES_SRWS1_PID) // Make sure the right device is actually connected 22 | return; 23 | #if 0 24 | if (len && buf) { 25 | Notify(PSTR("\r\n"), 0x80); 26 | for (uint8_t i = 0; i < len; i++) { 27 | D_PrintHex (buf[i], 0x80); 28 | Notify(PSTR(" "), 0x80); 29 | } 30 | } 31 | #endif 32 | memcpy(&srws1Data, buf, min(len, MFK_CASTUINT8T sizeof(srws1Data))); 33 | 34 | static SRWS1DataButtons oldButtonState; 35 | if (srws1Data.btn.val != oldButtonState.val) { // Check if anything has changed 36 | buttonClickState.val = srws1Data.btn.val & ~oldButtonState.val; // Update click state variable 37 | oldButtonState.val = srws1Data.btn.val; 38 | } 39 | } 40 | 41 | // See: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-steelseries.c 42 | void SRWS1::setLeds(uint16_t leds) { 43 | uint8_t buf[3]; 44 | buf[0] = 0x40; // Report ID 45 | buf[1] = leds & 0xFF; 46 | buf[2] = (leds >> 8) & 0x7F; 47 | pUsb->outTransfer(bAddress, epInfo[ hidInterfaces[0].epIndex[epInterruptOutIndex] ].epAddr, sizeof(buf), buf); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * eVY1 Shield sample - Say 'Konnichiwa' 4 | * Copyright (C) 2014-2016 Yuuichi Akagawa 5 | * 6 | * This is sample program. Do not expect perfect behavior. 7 | ******************************************************************************* 8 | */ 9 | #include 10 | #include 11 | 12 | // Satisfy the IDE, which needs to see the include statment in the ino too. 13 | #ifdef dobogusinclude 14 | #include 15 | #endif 16 | #include 17 | 18 | USB Usb; 19 | //USBHub Hub(&Usb); 20 | USBH_MIDI Midi(&Usb); 21 | 22 | void MIDI_poll(); 23 | void noteOn(uint8_t note); 24 | void noteOff(uint8_t note); 25 | 26 | uint16_t pid, vid; 27 | uint8_t exdata[] = { 28 | 0xf0, 0x43, 0x79, 0x09, 0x00, 0x50, 0x10, 29 | 'k', ' ', 'o', ',', //Ko 30 | 'N', '\\', ',', //N 31 | 'J', ' ', 'i', ',', //Ni 32 | 't', 'S', ' ', 'i', ',', //Chi 33 | 'w', ' ', 'a', //Wa 34 | 0x00, 0xf7 35 | }; 36 | 37 | void setup() 38 | { 39 | vid = pid = 0; 40 | Serial.begin(115200); 41 | 42 | if (Usb.Init() == -1) { 43 | while (1); //halt 44 | }//if (Usb.Init() == -1... 45 | delay( 200 ); 46 | } 47 | 48 | void loop() 49 | { 50 | Usb.Task(); 51 | if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 52 | { 53 | MIDI_poll(); 54 | noteOn(0x3f); 55 | delay(400); 56 | noteOff(0x3f); 57 | delay(100); 58 | } 59 | } 60 | 61 | // Poll USB MIDI Controler 62 | void MIDI_poll() 63 | { 64 | uint8_t inBuf[ 3 ]; 65 | 66 | //first call? 67 | if (Midi.vid != vid || Midi.pid != pid) { 68 | vid = Midi.vid; pid = Midi.pid; 69 | Midi.SendSysEx(exdata, sizeof(exdata)); 70 | delay(500); 71 | } 72 | Midi.RecvData(inBuf); 73 | } 74 | 75 | //note On 76 | void noteOn(uint8_t note) 77 | { 78 | uint8_t buf[3]; 79 | buf[0] = 0x90; 80 | buf[1] = note; 81 | buf[2] = 0x7f; 82 | Midi.SendData(buf); 83 | } 84 | 85 | //note Off 86 | void noteOff(uint8_t note) 87 | { 88 | uint8_t buf[3]; 89 | buf[0] = 0x80; 90 | buf[1] = note; 91 | buf[2] = 0x00; 92 | Midi.SendData(buf); 93 | } 94 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy the IDE, which needs to see the include statment in the ino too. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | class MouseRptParser : public MouseReportParser 11 | { 12 | protected: 13 | void OnMouseMove (MOUSEINFO *mi); 14 | void OnLeftButtonUp (MOUSEINFO *mi); 15 | void OnLeftButtonDown (MOUSEINFO *mi); 16 | void OnRightButtonUp (MOUSEINFO *mi); 17 | void OnRightButtonDown (MOUSEINFO *mi); 18 | void OnMiddleButtonUp (MOUSEINFO *mi); 19 | void OnMiddleButtonDown (MOUSEINFO *mi); 20 | }; 21 | void MouseRptParser::OnMouseMove(MOUSEINFO *mi) 22 | { 23 | Serial.print("dx="); 24 | Serial.print(mi->dX, DEC); 25 | Serial.print(" dy="); 26 | Serial.println(mi->dY, DEC); 27 | }; 28 | void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) 29 | { 30 | Serial.println("L Butt Up"); 31 | }; 32 | void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) 33 | { 34 | Serial.println("L Butt Dn"); 35 | }; 36 | void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) 37 | { 38 | Serial.println("R Butt Up"); 39 | }; 40 | void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) 41 | { 42 | Serial.println("R Butt Dn"); 43 | }; 44 | void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) 45 | { 46 | Serial.println("M Butt Up"); 47 | }; 48 | void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) 49 | { 50 | Serial.println("M Butt Dn"); 51 | }; 52 | 53 | USB Usb; 54 | USBHub Hub(&Usb); 55 | HIDBoot HidMouse(&Usb); 56 | 57 | MouseRptParser Prs; 58 | 59 | void setup() 60 | { 61 | Serial.begin( 115200 ); 62 | #if !defined(__MIPSEL__) 63 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 64 | #endif 65 | Serial.println("Start"); 66 | 67 | if (Usb.Init() == -1) 68 | Serial.println("OSC did not start."); 69 | 70 | delay( 200 ); 71 | 72 | HidMouse.SetReportParser(0, &Prs); 73 | } 74 | 75 | void loop() 76 | { 77 | Usb.Task(); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/testusbhostFAT/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # These are set for a mega 1280 + quadram plus my serial patch. 3 | # If you lack quadram, or want to disable LFN, just change _FS_TINY=1 _USE_LFN=0 4 | # 5 | # If your board is a mega 2560 comment out the following two lines 6 | BOARD = mega 7 | 8 | BOARD_SUB = mega.menu.cpu.atmega1280 9 | PROGRAMMER = arduino 10 | 11 | # ...and then uncomment out the following two lines 12 | #BOARD_SUB = mega.menu.cpu.atmega2560 13 | #PROGRAMMER = wiring 14 | 15 | #BOARD = teensypp2 16 | #BOARD = teensy3 17 | #BOARD = teensy31 18 | 19 | # set your Arduino tty port here 20 | PORT = /dev/ttyUSB0 21 | 22 | EXTRA_FLAGS = -D _USE_LFN=3 23 | 24 | # change to 0 if you have quadram to take advantage of caching FAT 25 | EXTRA_FLAGS += -D _FS_TINY=1 26 | 27 | 28 | EXTRA_FLAGS += -D _MAX_SS=512 29 | 30 | 31 | # Don't worry if you don't have external RAM, xmem2 detects this situation. 32 | # You *WILL* be wanting to get some kind of external ram on your mega in order to 33 | # do anything that is intense. 34 | EXTRA_FLAGS += -D EXT_RAM_STACK=1 35 | EXTRA_FLAGS += -D EXT_RAM_HEAP=1 36 | 37 | 38 | # These are no longer needed for the demo to work. 39 | # In the event you need more ram, uncomment these 3 lines. 40 | #EXTRA_FLAGS += -D DISABLE_SERIAL1 41 | #EXTRA_FLAGS += -D DISABLE_SERIAL2 42 | #EXTRA_FLAGS += -D DISABLE_SERIAL3 43 | 44 | # 45 | # Advanced debug on Serial3 46 | # 47 | 48 | # uncomment the next two to enable debug on Serial3 49 | EXTRA_FLAGS += -D USB_HOST_SERIAL=Serial3 50 | #EXTRA_FLAGS += -D DEBUG_USB_HOST 51 | 52 | # The following are the libraries used. 53 | LIB_DIRS += ../../ 54 | LIB_DIRS += ../testusbhostFAT/xmem2 55 | LIB_DIRS += ../testusbhostFAT/generic_storage 56 | LIB_DIRS += ../testusbhostFAT/RTClib 57 | LIB_DIRS += $(ARD_HOME)/libraries/Wire 58 | LIB_DIRS += $(ARD_HOME)/libraries/Wire/utility 59 | LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/Wire 60 | LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/Wire/utility 61 | LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/SPI 62 | 63 | # And finally, the part that brings everything together for you. 64 | include Arduino_Makefile_master/_Makefile.master 65 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * USB-MIDI to Legacy Serial MIDI converter 4 | * Copyright (C) 2012-2017 Yuuichi Akagawa 5 | * 6 | * Idea from LPK25 USB-MIDI to Serial MIDI converter 7 | * by Collin Cunningham - makezine.com, narbotic.com 8 | * 9 | * This is sample program. Do not expect perfect behavior. 10 | ******************************************************************************* 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | // Satisfy the IDE, which needs to see the include statment in the ino too. 17 | #ifdef dobogusinclude 18 | #include 19 | #endif 20 | #include 21 | 22 | #ifdef USBCON 23 | #define _MIDI_SERIAL_PORT Serial1 24 | #else 25 | #define _MIDI_SERIAL_PORT Serial 26 | #endif 27 | ////////////////////////// 28 | // MIDI Pin assign 29 | // 2 : GND 30 | // 4 : +5V(Vcc) with 220ohm 31 | // 5 : TX 32 | ////////////////////////// 33 | 34 | USB Usb; 35 | USBH_MIDI Midi(&Usb); 36 | 37 | void MIDI_poll(); 38 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); 39 | 40 | void setup() 41 | { 42 | _MIDI_SERIAL_PORT.begin(31250); 43 | 44 | if (Usb.Init() == -1) { 45 | while (1); //halt 46 | }//if (Usb.Init() == -1... 47 | delay( 200 ); 48 | } 49 | 50 | void loop() 51 | { 52 | Usb.Task(); 53 | uint32_t t1 = (uint32_t)micros(); 54 | if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 55 | { 56 | MIDI_poll(); 57 | } 58 | //delay(1ms) 59 | doDelay(t1, (uint32_t)micros(), 1000); 60 | } 61 | 62 | // Poll USB MIDI Controler and send to serial MIDI 63 | void MIDI_poll() 64 | { 65 | uint8_t outBuf[ 3 ]; 66 | uint8_t size; 67 | 68 | do { 69 | if ( (size = Midi.RecvData(outBuf)) > 0 ) { 70 | //MIDI Output 71 | _MIDI_SERIAL_PORT.write(outBuf, size); 72 | } 73 | } while (size > 0); 74 | } 75 | 76 | // Delay time (max 16383 us) 77 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) 78 | { 79 | uint32_t t3; 80 | 81 | if ( t1 > t2 ) { 82 | t3 = (0xFFFFFFFF - t1 + t2); 83 | } else { 84 | t3 = t2 - t1; 85 | } 86 | 87 | if ( t3 < delayTime ) { 88 | delayMicroseconds(delayTime - t3); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/hexdump.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | #if !defined(_usb_h_) || defined(__HEXDUMP_H__) 18 | #error "Never include hexdump.h directly; include Usb.h instead" 19 | #else 20 | #define __HEXDUMP_H__ 21 | 22 | extern int UsbDEBUGlvl; 23 | 24 | template 25 | class HexDumper : public BASE_CLASS { 26 | uint8_t byteCount; 27 | OFFSET_TYPE byteTotal; 28 | 29 | public: 30 | 31 | HexDumper() : byteCount(0), byteTotal(0) { 32 | }; 33 | 34 | void Initialize() { 35 | byteCount = 0; 36 | byteTotal = 0; 37 | }; 38 | 39 | void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset); 40 | }; 41 | 42 | template 43 | void HexDumper::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset __attribute__((unused))) { 44 | if(UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug. 45 | for(LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) { 46 | if(!byteCount) { 47 | PrintHex (byteTotal, 0x80); 48 | E_Notify(PSTR(": "), 0x80); 49 | } 50 | PrintHex (pbuf[j], 0x80); 51 | E_Notify(PSTR(" "), 0x80); 52 | 53 | if(byteCount == 15) { 54 | E_Notify(PSTR("\r\n"), 0x80); 55 | byteCount = 0xFF; 56 | } 57 | } 58 | } 59 | } 60 | 61 | #endif // __HEXDUMP_H__ 62 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * USB-MIDI to Legacy Serial MIDI converter 4 | * Copyright (C) 2012-2017 Yuuichi Akagawa 5 | * 6 | * Idea from LPK25 USB-MIDI to Serial MIDI converter 7 | * by Collin Cunningham - makezine.com, narbotic.com 8 | * 9 | * This is sample program. Do not expect perfect behavior. 10 | ******************************************************************************* 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | // Satisfy the IDE, which needs to see the include statment in the ino too. 17 | #ifdef dobogusinclude 18 | #include 19 | #endif 20 | #include 21 | 22 | #ifdef USBCON 23 | #define _MIDI_SERIAL_PORT Serial1 24 | #else 25 | #define _MIDI_SERIAL_PORT Serial 26 | #endif 27 | ////////////////////////// 28 | // MIDI Pin assign 29 | // 2 : GND 30 | // 4 : +5V(Vcc) with 220ohm 31 | // 5 : TX 32 | ////////////////////////// 33 | 34 | USB Usb; 35 | USBHub Hub1(&Usb); 36 | USBH_MIDI Midi1(&Usb); 37 | USBH_MIDI Midi2(&Usb); 38 | 39 | void MIDI_poll(); 40 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); 41 | 42 | void setup() 43 | { 44 | _MIDI_SERIAL_PORT.begin(31250); 45 | 46 | if (Usb.Init() == -1) { 47 | while (1); //halt 48 | }//if (Usb.Init() == -1... 49 | delay( 200 ); 50 | } 51 | 52 | void loop() 53 | { 54 | Usb.Task(); 55 | uint32_t t1 = (uint32_t)micros(); 56 | if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 57 | { 58 | MIDI_poll(); 59 | } 60 | //delay(1ms) 61 | doDelay(t1, (uint32_t)micros(), 1000); 62 | } 63 | 64 | // Poll USB MIDI Controler and send to serial MIDI 65 | void MIDI_poll() 66 | { 67 | uint8_t outBuf[ 3 ]; 68 | uint8_t size; 69 | 70 | do { 71 | if ( (size = Midi1.RecvData(outBuf)) > 0 ) { 72 | //MIDI Output 73 | _MIDI_SERIAL_PORT.write(outBuf, size); 74 | } 75 | } while (size > 0); 76 | do { 77 | if ( (size = Midi2.RecvData(outBuf)) > 0 ) { 78 | //MIDI Output 79 | _MIDI_SERIAL_PORT.write(outBuf, size); 80 | } 81 | } while (size > 0); 82 | } 83 | 84 | // Delay time (max 16383 us) 85 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) 86 | { 87 | uint32_t t3; 88 | 89 | if ( t1 > t2 ) { 90 | t3 = (0xFFFFFFFF - t1 + t2); 91 | } else { 92 | t3 = t2 - t1; 93 | } 94 | 95 | if ( t3 < delayTime ) { 96 | delayMicroseconds(delayTime - t3); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Satisfy IDE, which only needs to see the include statment in the ino. 4 | #ifdef dobogusinclude 5 | #include 6 | #endif 7 | #include 8 | 9 | class ACMAsyncOper : public CDCAsyncOper 10 | { 11 | public: 12 | uint8_t OnInit(ACM *pacm); 13 | }; 14 | 15 | uint8_t ACMAsyncOper::OnInit(ACM *pacm) 16 | { 17 | uint8_t rcode; 18 | // Set DTR = 1 RTS=1 19 | rcode = pacm->SetControlLineState(3); 20 | 21 | if (rcode) 22 | { 23 | ErrorMessage(PSTR("SetControlLineState"), rcode); 24 | return rcode; 25 | } 26 | 27 | LINE_CODING lc; 28 | lc.dwDTERate = 115200; 29 | lc.bCharFormat = 0; 30 | lc.bParityType = 0; 31 | lc.bDataBits = 8; 32 | 33 | rcode = pacm->SetLineCoding(&lc); 34 | 35 | if (rcode) 36 | ErrorMessage(PSTR("SetLineCoding"), rcode); 37 | 38 | return rcode; 39 | } 40 | 41 | USB Usb; 42 | ACMAsyncOper AsyncOper; 43 | XR21B1411 Acm(&Usb, &AsyncOper); 44 | 45 | void setup() { 46 | Serial.begin( 115200 ); 47 | #if !defined(__MIPSEL__) 48 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 49 | #endif 50 | Serial.println("\r\n\r\nStart"); 51 | 52 | if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert"); 53 | } 54 | 55 | void loop() { 56 | Usb.Task(); 57 | if( Acm.isReady()) { 58 | uint8_t rcode; 59 | uint8_t buf[1]; 60 | uint16_t rcvd = 1; 61 | 62 | /* read keyboard */ 63 | if(Serial.available()) { 64 | uint8_t data = Serial.read(); 65 | /* send */ 66 | rcode = Acm.SndData(1, &data); 67 | if (rcode) 68 | ErrorMessage(PSTR("SndData"), rcode); 69 | } 70 | 71 | /* read XR serial */ 72 | rcode = Acm.RcvData(&rcvd, buf); 73 | if (rcode && rcode != hrNAK) 74 | ErrorMessage(PSTR("Ret"), rcode); 75 | 76 | if( rcvd ) { //more than zero bytes received 77 | for(uint16_t i=0; i < rcvd; i++ ) { 78 | Serial.print((char)buf[i]); 79 | } 80 | } 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/parsetools.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | #include "Usb.h" 18 | 19 | bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn) { 20 | if(!pBuf) { 21 | Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80); 22 | return false; 23 | } 24 | for(; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++) 25 | pBuf[valueSize - countDown] = (**pp); 26 | 27 | if(countDown) 28 | return false; 29 | 30 | countDown = valueSize; 31 | return true; 32 | } 33 | 34 | bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) { 35 | switch(nStage) { 36 | case 0: 37 | pBuf->valueSize = lenSize; 38 | theParser.Initialize(pBuf); 39 | nStage = 1; 40 | 41 | case 1: 42 | if(!theParser.Parse(pp, pcntdn)) 43 | return false; 44 | 45 | arLen = 0; 46 | arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue)); 47 | arLenCntdn = arLen; 48 | nStage = 2; 49 | 50 | case 2: 51 | pBuf->valueSize = valSize; 52 | theParser.Initialize(pBuf); 53 | nStage = 3; 54 | 55 | case 3: 56 | for(; arLenCntdn; arLenCntdn--) { 57 | if(!theParser.Parse(pp, pcntdn)) 58 | return false; 59 | 60 | if(pf) 61 | pf(pBuf, (arLen - arLenCntdn), me); 62 | } 63 | 64 | nStage = 0; 65 | } 66 | return true; 67 | } 68 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/printhex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #if !defined(_usb_h_) || defined(__PRINTHEX_H__) 19 | #error "Never include printhex.h directly; include Usb.h instead" 20 | #else 21 | #define __PRINTHEX_H__ 22 | 23 | void E_Notifyc(char c, int lvl); 24 | 25 | template 26 | void PrintHex(T val, int lvl) { 27 | int num_nibbles = sizeof (T) * 2; 28 | 29 | do { 30 | char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); 31 | if(v > 57) v += 7; 32 | E_Notifyc(v, lvl); 33 | } while(--num_nibbles); 34 | } 35 | 36 | template 37 | void PrintBin(T val, int lvl) { 38 | for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1) 39 | if(val & mask) 40 | E_Notifyc('1', lvl); 41 | else 42 | E_Notifyc('0', lvl); 43 | } 44 | 45 | template 46 | void SerialPrintHex(T val) { 47 | int num_nibbles = sizeof (T) * 2; 48 | 49 | do { 50 | char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); 51 | if(v > 57) v += 7; 52 | USB_HOST_SERIAL.print(v); 53 | } while(--num_nibbles); 54 | } 55 | 56 | template 57 | void PrintHex2(Print *prn, T val) { 58 | T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2)); 59 | 60 | while(mask > 1) { 61 | if(val < mask) 62 | prn->print("0"); 63 | 64 | mask >>= 4; 65 | } 66 | prn->print((T)val, HEX); 67 | } 68 | 69 | template void D_PrintHex(T val __attribute__((unused)), int lvl __attribute__((unused))) { 70 | #ifdef DEBUG_USB_HOST 71 | PrintHex (val, lvl); 72 | #endif 73 | } 74 | 75 | template 76 | void D_PrintBin(T val, int lvl) { 77 | #ifdef DEBUG_USB_HOST 78 | PrintBin (val, lvl); 79 | #endif 80 | } 81 | 82 | 83 | 84 | #endif // __PRINTHEX_H__ 85 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pgmstrings.h" 5 | 6 | // Satisfy the IDE, which needs to see the include statment in the ino too. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | class FTDIAsync : public FTDIAsyncOper 13 | { 14 | public: 15 | uint8_t OnInit(FTDI *pftdi); 16 | }; 17 | 18 | uint8_t FTDIAsync::OnInit(FTDI *pftdi) 19 | { 20 | uint8_t rcode = 0; 21 | 22 | rcode = pftdi->SetBaudRate(115200); 23 | 24 | if (rcode) 25 | { 26 | ErrorMessage(PSTR("SetBaudRate"), rcode); 27 | return rcode; 28 | } 29 | rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL); 30 | 31 | if (rcode) 32 | ErrorMessage(PSTR("SetFlowControl"), rcode); 33 | 34 | return rcode; 35 | } 36 | 37 | USB Usb; 38 | //USBHub Hub(&Usb); 39 | FTDIAsync FtdiAsync; 40 | FTDI Ftdi(&Usb, &FtdiAsync); 41 | 42 | void setup() 43 | { 44 | Serial.begin( 115200 ); 45 | #if !defined(__MIPSEL__) 46 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 47 | #endif 48 | Serial.println("Start"); 49 | 50 | if (Usb.Init() == -1) 51 | Serial.println("OSC did not start."); 52 | 53 | delay( 200 ); 54 | } 55 | 56 | void loop() 57 | { 58 | Usb.Task(); 59 | 60 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 61 | { 62 | uint8_t rcode; 63 | char strbuf[] = "DEADBEEF"; 64 | //char strbuf[] = "The quick brown fox jumps over the lazy dog"; 65 | //char strbuf[] = "This string contains 61 character to demonstrate FTDI buffers"; //add one symbol to it to see some garbage 66 | Serial.print("."); 67 | 68 | rcode = Ftdi.SndData(strlen(strbuf), (uint8_t*)strbuf); 69 | 70 | if (rcode) 71 | ErrorMessage(PSTR("SndData"), rcode); 72 | 73 | delay(50); 74 | 75 | uint8_t buf[64]; 76 | 77 | for (uint8_t i=0; i<64; i++) 78 | buf[i] = 0; 79 | 80 | uint16_t rcvd = 64; 81 | rcode = Ftdi.RcvData(&rcvd, buf); 82 | 83 | if (rcode && rcode != hrNAK) 84 | ErrorMessage(PSTR("Ret"), rcode); 85 | 86 | // The device reserves the first two bytes of data 87 | // to contain the current values of the modem and line status registers. 88 | if (rcvd > 2) 89 | Serial.print((char*)(buf+2)); 90 | 91 | delay(10); 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * USB-MIDI dump utility 4 | * Copyright (C) 2013-2017 Yuuichi Akagawa 5 | * 6 | * for use with USB Host Shield 2.0 from Circuitsathome.com 7 | * https://github.com/felis/USB_Host_Shield_2.0 8 | * 9 | * This is sample program. Do not expect perfect behavior. 10 | ******************************************************************************* 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | // Satisfy the IDE, which needs to see the include statment in the ino too. 17 | #ifdef dobogusinclude 18 | #include 19 | #endif 20 | #include 21 | 22 | USB Usb; 23 | //USBHub Hub(&Usb); 24 | USBH_MIDI Midi(&Usb); 25 | 26 | void MIDI_poll(); 27 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); 28 | 29 | boolean bFirst; 30 | uint16_t pid, vid; 31 | 32 | void setup() 33 | { 34 | bFirst = true; 35 | vid = pid = 0; 36 | Serial.begin(115200); 37 | 38 | if (Usb.Init() == -1) { 39 | while (1); //halt 40 | }//if (Usb.Init() == -1... 41 | delay( 200 ); 42 | } 43 | 44 | void loop() 45 | { 46 | Usb.Task(); 47 | //uint32_t t1 = (uint32_t)micros(); 48 | if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 49 | { 50 | MIDI_poll(); 51 | } 52 | //delay(1ms) 53 | //doDelay(t1, (uint32_t)micros(), 1000); 54 | } 55 | 56 | // Poll USB MIDI Controler and send to serial MIDI 57 | void MIDI_poll() 58 | { 59 | char buf[20]; 60 | uint8_t bufMidi[64]; 61 | uint16_t rcvd; 62 | 63 | if (Midi.vid != vid || Midi.pid != pid) { 64 | sprintf(buf, "VID:%04X, PID:%04X", Midi.vid, Midi.pid); 65 | Serial.println(buf); 66 | vid = Midi.vid; 67 | pid = Midi.pid; 68 | } 69 | if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { 70 | uint32_t time = (uint32_t)millis(); 71 | sprintf(buf, "%04X%04X: ", (uint16_t)(time >> 16), (uint16_t)(time & 0xFFFF)); // Split variable to prevent warnings on the ESP8266 platform 72 | Serial.print(buf); 73 | Serial.print(rcvd); 74 | Serial.print(':'); 75 | for (int i = 0; i < 64; i++) { 76 | sprintf(buf, " %02X", bufMidi[i]); 77 | Serial.print(buf); 78 | } 79 | Serial.println(""); 80 | } 81 | } 82 | 83 | // Delay time (max 16383 us) 84 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) 85 | { 86 | uint32_t t3; 87 | 88 | if ( t1 > t2 ) { 89 | t3 = (0xFFFFFFFF - t1 + t2); 90 | } else { 91 | t3 = t2 - t1; 92 | } 93 | 94 | if ( t3 < delayTime ) { 95 | delayMicroseconds(delayTime - t3); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/adk/adk_barcode/adk_barcode.ino: -------------------------------------------------------------------------------- 1 | /**/ 2 | /* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */ 3 | /**/ 4 | #include 5 | #include 6 | #include 7 | 8 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #endif 12 | #include 13 | 14 | USB Usb; 15 | USBHub Hub1(&Usb); 16 | USBHub Hub2(&Usb); 17 | HIDBoot HidKeyboard(&Usb); 18 | 19 | ADK adk(&Usb,"Circuits@Home, ltd.", 20 | "USB Host Shield", 21 | "Arduino Terminal for Android", 22 | "1.0", 23 | "http://www.circuitsathome.com", 24 | "0000000000000001"); 25 | 26 | 27 | class KbdRptParser : public KeyboardReportParser 28 | { 29 | 30 | protected: 31 | void OnKeyDown (uint8_t mod, uint8_t key); 32 | void OnKeyPressed(uint8_t key); 33 | }; 34 | 35 | void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 36 | { 37 | uint8_t c = OemToAscii(mod, key); 38 | 39 | if (c) 40 | OnKeyPressed(c); 41 | } 42 | 43 | /* what to do when symbol arrives */ 44 | void KbdRptParser::OnKeyPressed(uint8_t key) 45 | { 46 | const char* new_line = "\n"; 47 | uint8_t rcode; 48 | uint8_t keylcl; 49 | 50 | if( adk.isReady() == false ) { 51 | return; 52 | } 53 | 54 | keylcl = key; 55 | 56 | if( keylcl == 0x13 ) { 57 | rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line ); 58 | if (rcode && rcode != hrNAK) { 59 | Serial.print(F("\r\nData send: ")); 60 | Serial.print(rcode, HEX); 61 | } 62 | } 63 | else { 64 | rcode = adk.SndData( 1, &keylcl ); 65 | if (rcode && rcode != hrNAK) { 66 | Serial.print(F("\r\nData send: ")); 67 | Serial.print(rcode, HEX); 68 | } 69 | } 70 | 71 | Serial.print((char) keylcl ); 72 | Serial.print(" : "); 73 | Serial.println( keylcl, HEX ); 74 | }; 75 | 76 | KbdRptParser Prs; 77 | 78 | void setup() 79 | { 80 | Serial.begin(115200); 81 | #if !defined(__MIPSEL__) 82 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 83 | #endif 84 | Serial.println("\r\nADK demo start"); 85 | 86 | if (Usb.Init() == -1) { 87 | Serial.println("OSCOKIRQ failed to assert"); 88 | while(1); //halt 89 | }//if (Usb.Init() == -1... 90 | 91 | HidKeyboard.SetReportParser(0, &Prs); 92 | 93 | delay( 200 ); 94 | } 95 | 96 | void loop() 97 | { 98 | Usb.Task(); 99 | } 100 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/SPPMulti/SPPMulti.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy IDE, which only needs to see the include statment in the ino. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 18 | 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | 21 | const uint8_t length = 2; // Set the number of instances here 22 | SPP *SerialBT[length]; // We will use this pointer to store the instances, you can easily make it larger if you like, but it will use a lot of RAM! 23 | 24 | bool firstMessage[length] = { true }; // Set all to true 25 | 26 | void setup() { 27 | for (uint8_t i = 0; i < length; i++) 28 | SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "0000" for all connections 29 | 30 | Serial.begin(115200); 31 | #if !defined(__MIPSEL__) 32 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 33 | #endif 34 | if (Usb.Init() == -1) { 35 | Serial.print(F("\r\nOSC did not start")); 36 | while (1); // Halt 37 | } 38 | Serial.print(F("\r\nSPP Bluetooth Library Started")); 39 | } 40 | 41 | void loop() { 42 | Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 43 | 44 | for (uint8_t i = 0; i < length; i++) { 45 | if (SerialBT[i]->connected) { 46 | if (firstMessage[i]) { 47 | firstMessage[i] = false; 48 | SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message 49 | } 50 | if (SerialBT[i]->available()) 51 | Serial.write(SerialBT[i]->read()); 52 | } 53 | else 54 | firstMessage[i] = true; 55 | } 56 | 57 | // Set the connection you want to send to using the first character 58 | // For instance "0Hello World" would send "Hello World" to connection 0 59 | if (Serial.available()) { 60 | delay(10); // Wait for the rest of the data to arrive 61 | uint8_t id = Serial.read() - '0'; // Convert from ASCII 62 | if (id < length && SerialBT[id]->connected) { // Make sure that the id is valid and make sure that a device is actually connected 63 | while (Serial.available()) // Check if data is available 64 | SerialBT[id]->write(Serial.read()); // Send the data 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/acm/acm_terminal/acm_terminal.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pgmstrings.h" 5 | 6 | // Satisfy the IDE, which needs to see the include statment in the ino too. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | class ACMAsyncOper : public CDCAsyncOper 13 | { 14 | public: 15 | uint8_t OnInit(ACM *pacm); 16 | }; 17 | 18 | uint8_t ACMAsyncOper::OnInit(ACM *pacm) 19 | { 20 | uint8_t rcode; 21 | // Set DTR = 1 RTS=1 22 | rcode = pacm->SetControlLineState(3); 23 | 24 | if (rcode) 25 | { 26 | ErrorMessage(PSTR("SetControlLineState"), rcode); 27 | return rcode; 28 | } 29 | 30 | LINE_CODING lc; 31 | lc.dwDTERate = 115200; 32 | lc.bCharFormat = 0; 33 | lc.bParityType = 0; 34 | lc.bDataBits = 8; 35 | 36 | rcode = pacm->SetLineCoding(&lc); 37 | 38 | if (rcode) 39 | ErrorMessage(PSTR("SetLineCoding"), rcode); 40 | 41 | return rcode; 42 | } 43 | 44 | USB Usb; 45 | //USBHub Hub(&Usb); 46 | ACMAsyncOper AsyncOper; 47 | ACM Acm(&Usb, &AsyncOper); 48 | 49 | void setup() 50 | { 51 | Serial.begin( 115200 ); 52 | #if !defined(__MIPSEL__) 53 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 54 | #endif 55 | Serial.println("Start"); 56 | 57 | if (Usb.Init() == -1) 58 | Serial.println("OSCOKIRQ failed to assert"); 59 | 60 | delay( 200 ); 61 | } 62 | 63 | void loop() 64 | { 65 | Usb.Task(); 66 | 67 | if( Acm.isReady()) { 68 | uint8_t rcode; 69 | 70 | /* reading the keyboard */ 71 | if(Serial.available()) { 72 | uint8_t data= Serial.read(); 73 | /* sending to the phone */ 74 | rcode = Acm.SndData(1, &data); 75 | if (rcode) 76 | ErrorMessage(PSTR("SndData"), rcode); 77 | }//if(Serial.available()... 78 | 79 | delay(50); 80 | 81 | /* reading the phone */ 82 | /* buffer size must be greater or equal to max.packet size */ 83 | /* it it set to 64 (largest possible max.packet size) here, can be tuned down 84 | for particular endpoint */ 85 | uint8_t buf[64]; 86 | uint16_t rcvd = 64; 87 | rcode = Acm.RcvData(&rcvd, buf); 88 | if (rcode && rcode != hrNAK) 89 | ErrorMessage(PSTR("Ret"), rcode); 90 | 91 | if( rcvd ) { //more than zero bytes received 92 | for(uint16_t i=0; i < rcvd; i++ ) { 93 | Serial.print((char)buf[i]); //printing on the screen 94 | } 95 | } 96 | delay(10); 97 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 98 | } 99 | 100 | 101 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/message.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | #if !defined(_usb_h_) || defined(__MESSAGE_H__) 18 | #error "Never include message.h directly; include Usb.h instead" 19 | #else 20 | #define __MESSAGE_H__ 21 | 22 | extern int UsbDEBUGlvl; 23 | 24 | void E_Notify(char const * msg, int lvl); 25 | void E_Notify(uint8_t b, int lvl); 26 | void E_NotifyStr(char const * msg, int lvl); 27 | void E_Notifyc(char c, int lvl); 28 | 29 | #ifdef DEBUG_USB_HOST 30 | #define Notify E_Notify 31 | #define NotifyStr E_NotifyStr 32 | #define Notifyc E_Notifyc 33 | void NotifyFailGetDevDescr(uint8_t reason); 34 | void NotifyFailSetDevTblEntry(uint8_t reason); 35 | void NotifyFailGetConfDescr(uint8_t reason); 36 | void NotifyFailSetConfDescr(uint8_t reason); 37 | void NotifyFailGetDevDescr(void); 38 | void NotifyFailSetDevTblEntry(void); 39 | void NotifyFailGetConfDescr(void); 40 | void NotifyFailSetConfDescr(void); 41 | void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID); 42 | void NotifyFail(uint8_t rcode); 43 | #else 44 | #define Notify(...) ((void)0) 45 | #define NotifyStr(...) ((void)0) 46 | #define Notifyc(...) ((void)0) 47 | #define NotifyFailGetDevDescr(...) ((void)0) 48 | #define NotifyFailSetDevTblEntry(...) ((void)0) 49 | #define NotifyFailGetConfDescr(...) ((void)0) 50 | #define NotifyFailGetDevDescr(...) ((void)0) 51 | #define NotifyFailSetDevTblEntry(...) ((void)0) 52 | #define NotifyFailGetConfDescr(...) ((void)0) 53 | #define NotifyFailSetConfDescr(...) ((void)0) 54 | #define NotifyFailUnknownDevice(...) ((void)0) 55 | #define NotifyFail(...) ((void)0) 56 | #endif 57 | 58 | template 59 | void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { 60 | #ifdef DEBUG_USB_HOST 61 | Notify(msg, level); 62 | Notify(PSTR(": "), level); 63 | D_PrintHex (rcode, level); 64 | Notify(PSTR("\r\n"), level); 65 | #endif 66 | } 67 | 68 | template 69 | void ErrorMessage(char const * msg __attribute__((unused)), ERROR_TYPE rcode __attribute__((unused)) = 0) { 70 | #ifdef DEBUG_USB_HOST 71 | Notify(msg, 0x80); 72 | Notify(PSTR(": "), 0x80); 73 | D_PrintHex (rcode, 0x80); 74 | Notify(PSTR("\r\n"), 0x80); 75 | #endif 76 | } 77 | 78 | #endif // __MESSAGE_H__ 79 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/pl2303/pl2303_gps/pl2303_gps.ino: -------------------------------------------------------------------------------- 1 | /* USB Host to PL2303-based USB GPS unit interface */ 2 | /* Navibee GM720 receiver - Sirf Star III */ 3 | /* USB support */ 4 | #include 5 | /* CDC support */ 6 | #include 7 | #include 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | class PLAsyncOper : public CDCAsyncOper { 16 | public: 17 | uint8_t OnInit(ACM *pacm); 18 | }; 19 | 20 | uint8_t PLAsyncOper::OnInit(ACM *pacm) { 21 | uint8_t rcode; 22 | 23 | // Set DTR = 1 24 | rcode = pacm->SetControlLineState(1); 25 | 26 | if(rcode) { 27 | ErrorMessage(PSTR("SetControlLineState"), rcode); 28 | return rcode; 29 | } 30 | 31 | LINE_CODING lc; 32 | lc.dwDTERate = 4800; //default serial speed of GPS unit 33 | lc.bCharFormat = 0; 34 | lc.bParityType = 0; 35 | lc.bDataBits = 8; 36 | 37 | rcode = pacm->SetLineCoding(&lc); 38 | 39 | if(rcode) 40 | ErrorMessage(PSTR("SetLineCoding"), rcode); 41 | 42 | return rcode; 43 | } 44 | 45 | USB Usb; 46 | USBHub Hub(&Usb); 47 | PLAsyncOper AsyncOper; 48 | PL2303 Pl(&Usb, &AsyncOper); 49 | uint32_t read_delay; 50 | #define READ_DELAY 100 51 | 52 | void setup() { 53 | Serial.begin(115200); 54 | #if !defined(__MIPSEL__) 55 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 56 | #endif 57 | Serial.println("Start"); 58 | 59 | if(Usb.Init() == -1) 60 | Serial.println("OSCOKIRQ failed to assert"); 61 | 62 | delay(200); 63 | } 64 | 65 | void loop() { 66 | uint8_t rcode; 67 | uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint 68 | uint16_t rcvd = 64; 69 | 70 | Usb.Task(); 71 | 72 | if(Pl.isReady()) { 73 | /* reading the GPS */ 74 | if((int32_t)((uint32_t)millis() - read_delay) >= 0L) { 75 | read_delay += READ_DELAY; 76 | rcode = Pl.RcvData(&rcvd, buf); 77 | if(rcode && rcode != hrNAK) 78 | ErrorMessage(PSTR("Ret"), rcode); 79 | if(rcvd) { //more than zero bytes received 80 | for(uint16_t i = 0; i < rcvd; i++) { 81 | Serial.print((char)buf[i]); //printing on the screen 82 | }//for( uint16_t i=0; i < rcvd; i++... 83 | }//if( rcvd 84 | }//if( read_delay > millis()... 85 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USB_desc/pgmstrings.h: -------------------------------------------------------------------------------- 1 | #if !defined(__PGMSTRINGS_H__) 2 | #define __PGMSTRINGS_H__ 3 | 4 | #define LOBYTE(x) ((char*)(&(x)))[0] 5 | #define HIBYTE(x) ((char*)(&(x)))[1] 6 | #define BUFSIZE 256 //buffer size 7 | 8 | 9 | /* Print strings in Program Memory */ 10 | const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; 11 | const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; 12 | const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; 13 | const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; 14 | const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; 15 | const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; 16 | const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; 17 | const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; 18 | const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; 19 | const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; 20 | const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; 21 | const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; 22 | const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; 23 | const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; 24 | const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; 25 | const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; 26 | const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; 27 | const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; 28 | const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; 29 | const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; 30 | const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; 31 | const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; 32 | const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 33 | const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; 34 | const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; 35 | const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; 36 | const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; 37 | const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; 38 | const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; 39 | const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; 40 | const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; 41 | const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; 42 | const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; 43 | const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; 44 | const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 45 | const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; 46 | const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; 47 | const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; 48 | const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; 49 | const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; 50 | const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; 51 | 52 | #endif // __PGMSTRINGS_H__ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/hub_demo/pgmstrings.h: -------------------------------------------------------------------------------- 1 | #if !defined(__PGMSTRINGS_H__) 2 | #define __PGMSTRINGS_H__ 3 | 4 | #define LOBYTE(x) ((char*)(&(x)))[0] 5 | #define HIBYTE(x) ((char*)(&(x)))[1] 6 | #define BUFSIZE 256 //buffer size 7 | 8 | 9 | /* Print strings in Program Memory */ 10 | const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; 11 | const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; 12 | const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; 13 | const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; 14 | const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; 15 | const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; 16 | const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; 17 | const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; 18 | const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; 19 | const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; 20 | const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; 21 | const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; 22 | const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; 23 | const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; 24 | const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; 25 | const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; 26 | const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; 27 | const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; 28 | const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; 29 | const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; 30 | const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; 31 | const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; 32 | const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 33 | const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; 34 | const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; 35 | const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; 36 | const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; 37 | const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; 38 | const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; 39 | const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; 40 | const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; 41 | const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; 42 | const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; 43 | const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; 44 | const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 45 | const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; 46 | const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; 47 | const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; 48 | const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; 49 | const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; 50 | const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; 51 | 52 | #endif // __PGMSTRINGS_H__ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHID_desc/pgmstrings.h: -------------------------------------------------------------------------------- 1 | #if !defined(__PGMSTRINGS_H__) 2 | #define __PGMSTRINGS_H__ 3 | 4 | #define LOBYTE(x) ((char*)(&(x)))[0] 5 | #define HIBYTE(x) ((char*)(&(x)))[1] 6 | #define BUFSIZE 256 //buffer size 7 | 8 | 9 | /* Print strings in Program Memory */ 10 | const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; 11 | const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; 12 | const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; 13 | const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; 14 | const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; 15 | const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; 16 | const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; 17 | const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; 18 | const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; 19 | const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; 20 | const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; 21 | const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; 22 | const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; 23 | const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; 24 | const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; 25 | const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; 26 | const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; 27 | const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; 28 | const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; 29 | const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; 30 | const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; 31 | const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; 32 | const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 33 | const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; 34 | const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; 35 | const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; 36 | const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; 37 | const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; 38 | const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; 39 | const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; 40 | const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; 41 | const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; 42 | const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; 43 | const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; 44 | const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 45 | const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; 46 | const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; 47 | const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; 48 | const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; 49 | const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; 50 | const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; 51 | 52 | #endif // __PGMSTRINGS_H__ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/acm/acm_terminal/pgmstrings.h: -------------------------------------------------------------------------------- 1 | #if !defined(__PGMSTRINGS_H__) 2 | #define __PGMSTRINGS_H__ 3 | 4 | #define LOBYTE(x) ((char*)(&(x)))[0] 5 | #define HIBYTE(x) ((char*)(&(x)))[1] 6 | #define BUFSIZE 256 //buffer size 7 | 8 | 9 | /* Print strings in Program Memory */ 10 | const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; 11 | const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; 12 | const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; 13 | const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; 14 | const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; 15 | const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; 16 | const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; 17 | const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; 18 | const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; 19 | const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; 20 | const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; 21 | const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; 22 | const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; 23 | const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; 24 | const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; 25 | const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; 26 | const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; 27 | const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; 28 | const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; 29 | const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; 30 | const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; 31 | const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; 32 | const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 33 | const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; 34 | const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; 35 | const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; 36 | const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; 37 | const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; 38 | const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; 39 | const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; 40 | const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; 41 | const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; 42 | const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; 43 | const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; 44 | const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 45 | const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; 46 | const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; 47 | const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; 48 | const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; 49 | const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; 50 | const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; 51 | 52 | #endif // __PGMSTRINGS_H__ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/ftdi/USBFTDILoopback/pgmstrings.h: -------------------------------------------------------------------------------- 1 | #if !defined(__PGMSTRINGS_H__) 2 | #define __PGMSTRINGS_H__ 3 | 4 | #define LOBYTE(x) ((char*)(&(x)))[0] 5 | #define HIBYTE(x) ((char*)(&(x)))[1] 6 | #define BUFSIZE 256 //buffer size 7 | 8 | 9 | /* Print strings in Program Memory */ 10 | const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; 11 | const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; 12 | const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; 13 | const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; 14 | const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; 15 | const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; 16 | const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; 17 | const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; 18 | const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; 19 | const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; 20 | const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; 21 | const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; 22 | const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; 23 | const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; 24 | const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; 25 | const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; 26 | const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; 27 | const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; 28 | const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; 29 | const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; 30 | const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; 31 | const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; 32 | const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 33 | const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; 34 | const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; 35 | const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; 36 | const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; 37 | const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; 38 | const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; 39 | const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; 40 | const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; 41 | const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; 42 | const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; 43 | const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; 44 | const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; 45 | const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; 46 | const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; 47 | const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; 48 | const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; 49 | const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; 50 | const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; 51 | 52 | #endif // __PGMSTRINGS_H__ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/adk/demokit_20/demokit_20.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy IDE, which only needs to see the include statment in the ino. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | USB Usb; 11 | USBHub hub0(&Usb); 12 | USBHub hub1(&Usb); 13 | ADK adk(&Usb, "Google, Inc.", 14 | "DemoKit", 15 | "DemoKit Arduino Board", 16 | "1.0", 17 | "http://www.android.com", 18 | "0000000012345678"); 19 | uint8_t b, b1; 20 | 21 | 22 | #define LED1_RED 3 23 | #define BUTTON1 2 24 | 25 | #ifdef ESP32 26 | #define LED1_RED_CHANNEL 0 27 | #endif 28 | 29 | void init_buttons() 30 | { 31 | pinMode(BUTTON1, INPUT); 32 | 33 | // enable the internal pullups 34 | digitalWrite(BUTTON1, HIGH); 35 | } 36 | 37 | void init_leds() 38 | { 39 | digitalWrite(LED1_RED, 0); 40 | 41 | #ifdef ESP32 42 | ledcAttachPin(LED1_RED, LED1_RED_CHANNEL); // Assign LED pin to channel 0 43 | ledcSetup(LED1_RED_CHANNEL, 12000, 8); // 12 kHz PWM, 8-bit resolution 44 | #else 45 | pinMode(LED1_RED, OUTPUT); 46 | #endif 47 | } 48 | 49 | void setup() 50 | { 51 | Serial.begin(115200); 52 | #if !defined(__MIPSEL__) 53 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 54 | #endif 55 | Serial.println("\r\nADK demo start"); 56 | 57 | if (Usb.Init() == -1) { 58 | Serial.println("OSCOKIRQ failed to assert"); 59 | while (1); //halt 60 | }//if (Usb.Init() == -1... 61 | 62 | init_leds(); 63 | init_buttons(); 64 | b1 = digitalRead(BUTTON1); 65 | } 66 | 67 | void loop() 68 | { 69 | uint8_t rcode; 70 | uint8_t msg[3] = { 0x00 }; 71 | Usb.Task(); 72 | 73 | if ( adk.isReady() == false ) { 74 | #ifdef ESP32 75 | ledcWrite(LED1_RED_CHANNEL, 255); 76 | #else 77 | analogWrite(LED1_RED, 255); 78 | #endif 79 | return; 80 | } 81 | uint16_t len = sizeof(msg); 82 | 83 | rcode = adk.RcvData(&len, msg); 84 | if ( rcode ) { 85 | USBTRACE2("Data rcv. :", rcode ); 86 | } 87 | if (len > 0) { 88 | USBTRACE("\r\nData Packet."); 89 | // assumes only one command per packet 90 | if (msg[0] == 0x2) { 91 | switch ( msg[1] ) { 92 | case 0: 93 | #ifdef ESP32 94 | ledcWrite(LED1_RED_CHANNEL, 255 - msg[2]); 95 | #else 96 | analogWrite(LED1_RED, 255 - msg[2]); 97 | #endif 98 | break; 99 | }//switch( msg[1]... 100 | }//if (msg[0] == 0x2... 101 | }//if( len > 0... 102 | 103 | msg[0] = 0x1; 104 | 105 | b = digitalRead(BUTTON1); 106 | if (b != b1) { 107 | USBTRACE("\r\nButton state changed"); 108 | msg[1] = 0; 109 | msg[2] = b ? 0 : 1; 110 | rcode = adk.SndData( 3, msg ); 111 | if ( rcode ) { 112 | USBTRACE2("Button send: ", rcode ); 113 | } 114 | b1 = b; 115 | }//if (b != b1... 116 | 117 | 118 | delay( 10 ); 119 | } 120 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino: -------------------------------------------------------------------------------- 1 | /* Arduino terminal for PL2303 USB to serial converter and DealeXtreme GPRS modem. */ 2 | /* USB support */ 3 | #include 4 | /* CDC support */ 5 | #include 6 | #include 7 | 8 | // Satisfy the IDE, which needs to see the include statment in the ino too. 9 | #ifdef dobogusinclude 10 | #include 11 | #endif 12 | #include 13 | 14 | class PLAsyncOper : public CDCAsyncOper 15 | { 16 | public: 17 | uint8_t OnInit(ACM *pacm); 18 | }; 19 | 20 | uint8_t PLAsyncOper::OnInit(ACM *pacm) 21 | { 22 | uint8_t rcode; 23 | 24 | // Set DTR = 1 25 | rcode = pacm->SetControlLineState(1); 26 | 27 | if (rcode) 28 | { 29 | ErrorMessage(PSTR("SetControlLineState"), rcode); 30 | return rcode; 31 | } 32 | 33 | LINE_CODING lc; 34 | //lc.dwDTERate = 9600; 35 | lc.dwDTERate = 115200; 36 | lc.bCharFormat = 0; 37 | lc.bParityType = 0; 38 | lc.bDataBits = 8; 39 | 40 | rcode = pacm->SetLineCoding(&lc); 41 | 42 | if (rcode) 43 | ErrorMessage(PSTR("SetLineCoding"), rcode); 44 | 45 | return rcode; 46 | } 47 | USB Usb; 48 | //USBHub Hub(&Usb); 49 | PLAsyncOper AsyncOper; 50 | PL2303 Pl(&Usb, &AsyncOper); 51 | 52 | void setup() 53 | { 54 | Serial.begin( 115200 ); 55 | #if !defined(__MIPSEL__) 56 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 57 | #endif 58 | Serial.println("Start"); 59 | 60 | if (Usb.Init() == -1) 61 | Serial.println("OSCOKIRQ failed to assert"); 62 | 63 | delay( 200 ); 64 | } 65 | 66 | void loop() 67 | { 68 | Usb.Task(); 69 | 70 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 71 | { 72 | uint8_t rcode; 73 | 74 | /* reading the keyboard */ 75 | if(Serial.available()) { 76 | uint8_t data= Serial.read(); 77 | 78 | /* sending to the phone */ 79 | rcode = Pl.SndData(1, &data); 80 | if (rcode) 81 | ErrorMessage(PSTR("SndData"), rcode); 82 | }//if(Serial.available()... 83 | 84 | /* reading the converter */ 85 | /* buffer size must be greater or equal to max.packet size */ 86 | /* it it set to 64 (largest possible max.packet size) here, can be tuned down 87 | for particular endpoint */ 88 | uint8_t buf[64]; 89 | uint16_t rcvd = 64; 90 | rcode = Pl.RcvData(&rcvd, buf); 91 | if (rcode && rcode != hrNAK) 92 | ErrorMessage(PSTR("Ret"), rcode); 93 | 94 | if( rcvd ) { //more than zero bytes received 95 | for(uint16_t i=0; i < rcvd; i++ ) { 96 | Serial.print((char)buf[i]); //printing on the screen 97 | } 98 | }//if( rcvd ... 99 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 100 | } 101 | 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # USB Apple II Keyboard 2 | Arduino Sketch to use a USB keyboard with an Apple II as ASCII keyboard. 3 | 4 | Features: 5 | - Upper and Lowercase (Shift and Caps work), for older Models and full compatibility use caps. 6 | - Selectable Layout (Currently DE and US) toggle via WIN + SPACE. 7 | - Providing reset to the Apple II. Used via CTRL + ALT + DEL 8 | - Bash like backscroll capability. Use up and down arrow keys to scroll through your last commands. 9 | 10 | ![Apple II USB Keyboard Interface](https://github.com/mafrmt00/Apple_II_Keyboard/blob/master/pictures/Keyb_Adapter.jpg "The assembled interface") 11 | 12 | ### Needed Hardware and Software 13 | 14 | Hardware: 15 | - [Arduino Uno](https://en.wikipedia.org/wiki/Arduino_Uno) 16 | - [Arduino USB Host Shield](https://www.elecrow.com/wiki/index.php?title=USB_Host_Shield_for_Arduino 17 | ) 18 | - optional [Arduino Proto Board](https://store.arduino.cc/proto-shield-rev3-uno-size) with DIP Socket 19 | - Compatible USB keyboard. Tested with a Logitech K120. 20 | 21 | Software: 22 | - Arduino IDE 23 | - USB Host Shield Library 2.0 (The modified Version included in this repo!) 24 | 25 | ### Installation 26 | - Create a folder "Apple_II_Keyboard" under your sketches dir and copy all files from the root dir of this repo there (The dir where the .ino lies). 27 | - Copy the "USB_Host_Shield_Library_2.0" dir to you libraries dir. 28 | - Select Uno as board in the Arduino IDE 29 | - Use Upload in the Arduino IDE. If you can see some output in the serial monitor as you type everythin works. 30 | 31 | ### Connecting the Arduino to the Apple II 32 | This Table shows how to connect the Apple II Keyboard Connector (A7) to the Arduino. The Pin definitions can also be changed in II_Encoder.h 33 | 34 | | APPLE II DIP Pin| Function | Arduino Pin | 35 | | --------------- | -------- | ----------- | 36 | | 1 | +5V | 5V | 37 | | 2 | Strobe | 4 | 38 | | 3 | Reset | 5 | 39 | | 4 | NC | NC | 40 | | 5 | DATA 5 | 6 | 41 | | 6 | DATA 4 | 7 | 42 | | 7 | DATA 6 | 8 | 43 | | 8 | GND | GND | 44 | | 9 | NC | NC | 45 | | 10 | DATA 2 | A0 | 46 | | 11 | DATA 3 | A1 | 47 | | 12 | DATA 0 | A2 | 48 | | 13 | DATA 1 | A3 | 49 | | 14 | NC | NC | 50 | | 15 | -12V | NC | 51 | | 16 | NC | NC | 52 | 53 | 54 | ### Setting the Arduino USB Host Shield for 5V operation 55 | 56 | ![Correctly jumpered Host Shield](https://github.com/mafrmt00/Apple_II_Keyboard/blob/master/pictures/USB_Host_Shield.jpg "Correctly jumpered Host Shield") 57 | Make sure to set the solder jumpers as shoen in the picture. The Apple II and the UNO operate at 5V. 58 | 59 | ### License 60 | The content of this repos is published under the GNU GENERAL PUBLIC LICENSE Version 2 61 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 4 | joyEvents(evt), 5 | oldHat(0xDE), 6 | oldButtons(0) { 7 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 8 | oldPad[i] = 0xD; 9 | } 10 | 11 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 12 | bool match = true; 13 | 14 | // Checking if there are changes in report since the method was last called 15 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 16 | if (buf[i] != oldPad[i]) { 17 | match = false; 18 | break; 19 | } 20 | 21 | // Calling Game Pad event handler 22 | if (!match && joyEvents) { 23 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 24 | 25 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 26 | } 27 | 28 | uint8_t hat = (buf[5] & 0xF); 29 | 30 | // Calling Hat Switch event handler 31 | if (hat != oldHat && joyEvents) { 32 | joyEvents->OnHatSwitch(hat); 33 | oldHat = hat; 34 | } 35 | 36 | uint16_t buttons = (0x0000 | buf[6]); 37 | buttons <<= 4; 38 | buttons |= (buf[5] >> 4); 39 | uint16_t changes = (buttons ^ oldButtons); 40 | 41 | // Calling Button Event Handler for every button changed 42 | if (changes) { 43 | for (uint8_t i = 0; i < 0x0C; i++) { 44 | uint16_t mask = (0x0001 << i); 45 | 46 | if (((mask & changes) > 0) && joyEvents) { 47 | if ((buttons & mask) > 0) 48 | joyEvents->OnButtonDn(i + 1); 49 | else 50 | joyEvents->OnButtonUp(i + 1); 51 | } 52 | } 53 | oldButtons = buttons; 54 | } 55 | } 56 | 57 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 58 | Serial.print("X1: "); 59 | PrintHex (evt->X, 0x80); 60 | Serial.print("\tY1: "); 61 | PrintHex (evt->Y, 0x80); 62 | Serial.print("\tX2: "); 63 | PrintHex (evt->Z1, 0x80); 64 | Serial.print("\tY2: "); 65 | PrintHex (evt->Z2, 0x80); 66 | Serial.print("\tRz: "); 67 | PrintHex (evt->Rz, 0x80); 68 | Serial.println(""); 69 | } 70 | 71 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 72 | Serial.print("Hat Switch: "); 73 | PrintHex (hat, 0x80); 74 | Serial.println(""); 75 | } 76 | 77 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 78 | Serial.print("Up: "); 79 | Serial.println(but_id, DEC); 80 | } 81 | 82 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 83 | Serial.print("Dn: "); 84 | Serial.println(but_id, DEC); 85 | } 86 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino: -------------------------------------------------------------------------------- 1 | // The source for the Android application can be found at the following link: https://github.com/Lauszus/ArduinoBlinkLED 2 | // The code for the Android application is heavily based on this guide: http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/ by Miguel 3 | #include 4 | 5 | // 6 | // CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ! 7 | // 8 | // Pin 13 is occupied by the SCK pin on various Arduino boards, 9 | // including Uno, Duemilanove, etc., so use a different pin for those boards. 10 | // 11 | // CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ! 12 | // 13 | #if defined(LED_BUILTIN) 14 | #define LED LED_BUILTIN // Use built in LED 15 | #else 16 | #define LED 9 // Set to something here that makes sense for your board. 17 | #endif 18 | 19 | 20 | // Satisfy IDE, which only needs to see the include statment in the ino. 21 | #ifdef dobogusinclude 22 | #include 23 | #endif 24 | #include 25 | 26 | USB Usb; 27 | ADK adk(&Usb, "TKJElectronics", // Manufacturer Name 28 | "ArduinoBlinkLED", // Model Name 29 | "Example sketch for the USB Host Shield", // Description (user-visible string) 30 | "1.0", // Version 31 | "http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory) 32 | "123456789"); // Serial Number (optional) 33 | 34 | uint32_t timer; 35 | bool connected; 36 | 37 | void setup() { 38 | Serial.begin(115200); 39 | #if !defined(__MIPSEL__) 40 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 41 | #endif 42 | if (Usb.Init() == -1) { 43 | Serial.print("\r\nOSCOKIRQ failed to assert"); 44 | while (1); // halt 45 | } 46 | pinMode(LED, OUTPUT); 47 | Serial.print("\r\nArduino Blink LED Started"); 48 | } 49 | 50 | void loop() { 51 | Usb.Task(); 52 | 53 | if (adk.isReady()) { 54 | if (!connected) { 55 | connected = true; 56 | Serial.print(F("\r\nConnected to accessory")); 57 | } 58 | 59 | uint8_t msg[1]; 60 | uint16_t len = sizeof(msg); 61 | uint8_t rcode = adk.RcvData(&len, msg); 62 | if (rcode && rcode != hrNAK) { 63 | Serial.print(F("\r\nData rcv: ")); 64 | Serial.print(rcode, HEX); 65 | } else if (len > 0) { 66 | Serial.print(F("\r\nData Packet: ")); 67 | Serial.print(msg[0]); 68 | digitalWrite(LED, msg[0] ? HIGH : LOW); 69 | } 70 | 71 | if ((int32_t)((uint32_t)millis() - timer) >= 1000) { // Send data every 1s 72 | timer = (uint32_t)millis(); 73 | rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer); 74 | if (rcode && rcode != hrNAK) { 75 | Serial.print(F("\r\nData send: ")); 76 | Serial.print(rcode, HEX); 77 | } else if (rcode != hrNAK) { 78 | Serial.print(F("\r\nTimer: ")); 79 | Serial.print(timer); 80 | } 81 | } 82 | } else { 83 | if (connected) { 84 | connected = false; 85 | Serial.print(F("\r\nDisconnected from accessory")); 86 | digitalWrite(LED, LOW); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/SRWS1/SRWS1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2016 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #ifndef __srws1_h__ 19 | #define __srws1_h__ 20 | 21 | #include 22 | 23 | #define STEELSERIES_VID 0x1038 24 | #define STEELSERIES_SRWS1_PID 0x1410 25 | 26 | enum DPADEnum { 27 | DPAD_UP = 0x0, 28 | DPAD_UP_RIGHT = 0x1, 29 | DPAD_RIGHT = 0x2, 30 | DPAD_RIGHT_DOWN = 0x3, 31 | DPAD_DOWN = 0x4, 32 | DPAD_DOWN_LEFT = 0x5, 33 | DPAD_LEFT = 0x6, 34 | DPAD_LEFT_UP = 0x7, 35 | DPAD_OFF = 0xF, 36 | }; 37 | 38 | union SRWS1DataButtons { 39 | struct { 40 | uint8_t dpad : 4; 41 | uint8_t dummy : 3; 42 | uint8_t select : 1; 43 | 44 | uint8_t back : 1; 45 | uint8_t lookLeft : 1; 46 | uint8_t lights : 1; 47 | uint8_t lookBack : 1; 48 | uint8_t rearBrakeBalance : 1; 49 | uint8_t frontBrakeBalance : 1; 50 | uint8_t requestPit : 1; 51 | uint8_t leftGear : 1; 52 | 53 | uint8_t camera : 1; 54 | uint8_t lookRight : 1; 55 | uint8_t boost : 1; 56 | uint8_t horn : 1; 57 | uint8_t hud : 1; 58 | uint8_t launchControl : 1; 59 | uint8_t speedLimiter : 1; 60 | uint8_t rightGear : 1; 61 | } __attribute__((packed)); 62 | uint32_t val : 24; 63 | } __attribute__((packed)); 64 | 65 | struct SRWS1Data { 66 | int16_t tilt; // Range [-1800:1800] 67 | uint16_t rightTrigger : 12; // Range [0:1023] i.e. only 10 bits 68 | uint16_t leftTrigger : 12; // Range [0:1023] i.e. only 10 bits 69 | SRWS1DataButtons btn; 70 | uint8_t assists : 4; 71 | uint8_t steeringSensitivity : 4; 72 | uint8_t assistValues : 4; 73 | } __attribute__((packed)); 74 | 75 | class SRWS1 : public HIDUniversal { 76 | public: 77 | SRWS1(USB *p) : HIDUniversal(p) {}; 78 | bool connected() { 79 | return HIDUniversal::isReady() && HIDUniversal::VID == STEELSERIES_VID && HIDUniversal::PID == STEELSERIES_SRWS1_PID; 80 | }; 81 | void setLeds(uint16_t leds); 82 | SRWS1Data srws1Data; 83 | SRWS1DataButtons buttonClickState; 84 | 85 | private: 86 | void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDUniversal library 87 | uint8_t OnInitSuccessful() { // Called by the HIDUniversal library on success 88 | if (HIDUniversal::VID != STEELSERIES_VID || HIDUniversal::PID != STEELSERIES_SRWS1_PID) // Make sure the right device is actually connected 89 | return 1; 90 | setLeds(0); 91 | return 0; 92 | }; 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino: -------------------------------------------------------------------------------- 1 | /* Arduino terminal for PL2303 USB to serial converter and XBee radio. */ 2 | /* Inserts linefeed after carriage return in data sent to and received from Xbee */ 3 | /* USB support */ 4 | #include 5 | /* CDC support */ 6 | #include 7 | #include 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | class PLAsyncOper : public CDCAsyncOper 16 | { 17 | public: 18 | uint8_t OnInit(ACM *pacm); 19 | }; 20 | 21 | uint8_t PLAsyncOper::OnInit(ACM *pacm) 22 | { 23 | uint8_t rcode; 24 | 25 | // Set DTR = 1 26 | rcode = pacm->SetControlLineState(1); 27 | 28 | if (rcode) 29 | { 30 | ErrorMessage(PSTR("SetControlLineState"), rcode); 31 | return rcode; 32 | } 33 | 34 | LINE_CODING lc; 35 | lc.dwDTERate = 115200; 36 | lc.bCharFormat = 0; 37 | lc.bParityType = 0; 38 | lc.bDataBits = 8; 39 | 40 | rcode = pacm->SetLineCoding(&lc); 41 | 42 | if (rcode) 43 | ErrorMessage(PSTR("SetLineCoding"), rcode); 44 | 45 | return rcode; 46 | } 47 | USB Usb; 48 | //USBHub Hub(&Usb); 49 | PLAsyncOper AsyncOper; 50 | PL2303 Pl(&Usb, &AsyncOper); 51 | 52 | void setup() 53 | { 54 | Serial.begin( 115200 ); 55 | #if !defined(__MIPSEL__) 56 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 57 | #endif 58 | Serial.println("Start"); 59 | 60 | if (Usb.Init() == -1) 61 | Serial.println("OSCOKIRQ failed to assert"); 62 | 63 | delay( 200 ); 64 | } 65 | 66 | void loop() 67 | { 68 | Usb.Task(); 69 | 70 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 71 | { 72 | uint8_t rcode; 73 | 74 | /* reading the keyboard */ 75 | if(Serial.available()) { 76 | uint8_t data= Serial.read(); 77 | 78 | if ( data == '\r' ) { 79 | Serial.print("\r\n"); //insert linefeed 80 | } 81 | else { 82 | Serial.print( data ); //echo back to the screen 83 | } 84 | 85 | /* sending to the phone */ 86 | rcode = Pl.SndData(1, &data); 87 | if (rcode) 88 | ErrorMessage(PSTR("SndData"), rcode); 89 | }//if(Serial.available()... 90 | 91 | delay(50); 92 | 93 | /* reading the converter */ 94 | /* buffer size must be greater or equal to max.packet size */ 95 | /* it it set to 64 (largest possible max.packet size) here, can be tuned down 96 | for particular endpoint */ 97 | uint8_t buf[64]; 98 | uint16_t rcvd = 64; 99 | rcode = Pl.RcvData(&rcvd, buf); 100 | if (rcode && rcode != hrNAK) 101 | ErrorMessage(PSTR("Ret"), rcode); 102 | 103 | if( rcvd ) { //more than zero bytes received 104 | for(uint16_t i=0; i < rcvd; i++ ) { 105 | if( buf[i] =='\r' ) { 106 | Serial.print("\r\n"); //insert linefeed 107 | } 108 | else { 109 | Serial.print((char)buf[i]); //printing on the screen 110 | } 111 | } 112 | } 113 | delay(10); 114 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/max_LCD.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | //HD44780 compatible LCD display via MAX3421E GPOUT support header 18 | //pinout: D[4-7] -> GPOUT[4-7], RS-> GPOUT[2], E ->GPOUT[3] 19 | // 20 | 21 | #ifndef _Max_LCD_h_ 22 | #define _Max_LCD_h_ 23 | 24 | #include "Usb.h" 25 | #include "Print.h" 26 | 27 | // commands 28 | #define LCD_CLEARDISPLAY 0x01 29 | #define LCD_RETURNHOME 0x02 30 | #define LCD_ENTRYMODESET 0x04 31 | #define LCD_DISPLAYCONTROL 0x08 32 | #define LCD_CURSORSHIFT 0x10 33 | #define LCD_FUNCTIONSET 0x20 34 | #define LCD_SETCGRAMADDR 0x40 35 | #define LCD_SETDDRAMADDR 0x80 36 | 37 | // flags for display entry mode 38 | #define LCD_ENTRYRIGHT 0x00 39 | #define LCD_ENTRYLEFT 0x02 40 | #define LCD_ENTRYSHIFTINCREMENT 0x01 41 | #define LCD_ENTRYSHIFTDECREMENT 0x00 42 | 43 | // flags for display on/off control 44 | #define LCD_DISPLAYON 0x04 45 | #define LCD_DISPLAYOFF 0x00 46 | #define LCD_CURSORON 0x02 47 | #define LCD_CURSOROFF 0x00 48 | #define LCD_BLINKON 0x01 49 | #define LCD_BLINKOFF 0x00 50 | 51 | // flags for display/cursor shift 52 | #define LCD_DISPLAYMOVE 0x08 53 | #define LCD_CURSORMOVE 0x00 54 | #define LCD_MOVERIGHT 0x04 55 | #define LCD_MOVELEFT 0x00 56 | 57 | // flags for function set 58 | #define LCD_8BITMODE 0x10 59 | #define LCD_4BITMODE 0x00 60 | #define LCD_2LINE 0x08 61 | #define LCD_1LINE 0x00 62 | #define LCD_5x10DOTS 0x04 63 | #define LCD_5x8DOTS 0x00 64 | 65 | class Max_LCD : public Print { 66 | USB *pUsb; 67 | 68 | public: 69 | Max_LCD(USB *pusb); 70 | void init(); 71 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 72 | void clear(); 73 | void home(); 74 | void noDisplay(); 75 | void display(); 76 | void noBlink(); 77 | void blink(); 78 | void noCursor(); 79 | void cursor(); 80 | void scrollDisplayLeft(); 81 | void scrollDisplayRight(); 82 | void leftToRight(); 83 | void rightToLeft(); 84 | void autoscroll(); 85 | void noAutoscroll(); 86 | void createChar(uint8_t, uint8_t[]); 87 | void setCursor(uint8_t, uint8_t); 88 | void command(uint8_t); 89 | 90 | #if defined(ARDUINO) && ARDUINO >=100 91 | size_t write(uint8_t); 92 | using Print::write; 93 | #else 94 | void write(uint8_t); 95 | #endif 96 | 97 | private: 98 | void sendbyte(uint8_t val); 99 | uint8_t _displayfunction; //tokill 100 | uint8_t _displaycontrol; 101 | uint8_t _displaymode; 102 | uint8_t _initialized; 103 | uint8_t _numlines, _currline; 104 | }; 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/message.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #include "Usb.h" 19 | // 0x80 is the default (i.e. trace) to turn off set this global to something lower. 20 | // this allows for 126 other debugging levels. 21 | // TO-DO: Allow assignment to a different serial port by software 22 | int UsbDEBUGlvl = 0x80; 23 | 24 | void E_Notifyc(char c, int lvl) { 25 | if(UsbDEBUGlvl < lvl) return; 26 | #if defined(ARDUINO) && ARDUINO >=100 27 | USB_HOST_SERIAL.print(c); 28 | #else 29 | USB_HOST_SERIAL.print(c, BYTE); 30 | #endif 31 | //USB_HOST_SERIAL.flush(); 32 | } 33 | 34 | void E_Notify(char const * msg, int lvl) { 35 | if(UsbDEBUGlvl < lvl) return; 36 | if(!msg) return; 37 | char c; 38 | 39 | while((c = pgm_read_byte(msg++))) E_Notifyc(c, lvl); 40 | } 41 | 42 | void E_NotifyStr(char const * msg, int lvl) { 43 | if(UsbDEBUGlvl < lvl) return; 44 | if(!msg) return; 45 | char c; 46 | 47 | while((c = *msg++)) E_Notifyc(c, lvl); 48 | } 49 | 50 | void E_Notify(uint8_t b, int lvl) { 51 | if(UsbDEBUGlvl < lvl) return; 52 | #if defined(ARDUINO) && ARDUINO >=100 53 | USB_HOST_SERIAL.print(b); 54 | #else 55 | USB_HOST_SERIAL.print(b, DEC); 56 | #endif 57 | //USB_HOST_SERIAL.flush(); 58 | } 59 | 60 | void E_Notify(double d, int lvl) { 61 | if(UsbDEBUGlvl < lvl) return; 62 | USB_HOST_SERIAL.print(d); 63 | //USB_HOST_SERIAL.flush(); 64 | } 65 | 66 | #ifdef DEBUG_USB_HOST 67 | 68 | void NotifyFailGetDevDescr(void) { 69 | Notify(PSTR("\r\ngetDevDescr "), 0x80); 70 | } 71 | 72 | void NotifyFailSetDevTblEntry(void) { 73 | Notify(PSTR("\r\nsetDevTblEn "), 0x80); 74 | } 75 | 76 | void NotifyFailGetConfDescr(void) { 77 | Notify(PSTR("\r\ngetConf "), 0x80); 78 | } 79 | 80 | void NotifyFailSetConfDescr(void) { 81 | Notify(PSTR("\r\nsetConf "), 0x80); 82 | } 83 | 84 | void NotifyFailGetDevDescr(uint8_t reason) { 85 | NotifyFailGetDevDescr(); 86 | NotifyFail(reason); 87 | } 88 | 89 | void NotifyFailSetDevTblEntry(uint8_t reason) { 90 | NotifyFailSetDevTblEntry(); 91 | NotifyFail(reason); 92 | 93 | } 94 | 95 | void NotifyFailGetConfDescr(uint8_t reason) { 96 | NotifyFailGetConfDescr(); 97 | NotifyFail(reason); 98 | } 99 | 100 | void NotifyFailSetConfDescr(uint8_t reason) { 101 | NotifyFailSetConfDescr(); 102 | NotifyFail(reason); 103 | } 104 | 105 | void NotifyFailUnknownDevice(uint16_t VID, uint16_t PID) { 106 | Notify(PSTR("\r\nUnknown Device Connected - VID: "), 0x80); 107 | D_PrintHex (VID, 0x80); 108 | Notify(PSTR(" PID: "), 0x80); 109 | D_PrintHex (PID, 0x80); 110 | } 111 | 112 | void NotifyFail(uint8_t rcode) { 113 | D_PrintHex (rcode, 0x80); 114 | Notify(PSTR("\r\n"), 0x80); 115 | } 116 | #endif 117 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Satisfy the IDE, which needs to see the include statment in the ino too. 5 | #ifdef dobogusinclude 6 | #include 7 | #endif 8 | #include 9 | 10 | class KbdRptParser : public KeyboardReportParser 11 | { 12 | void PrintKey(uint8_t mod, uint8_t key); 13 | 14 | protected: 15 | void OnControlKeysChanged(uint8_t before, uint8_t after); 16 | 17 | void OnKeyDown (uint8_t mod, uint8_t key); 18 | void OnKeyUp (uint8_t mod, uint8_t key); 19 | void OnKeyPressed(uint8_t key); 20 | }; 21 | 22 | void KbdRptParser::PrintKey(uint8_t m, uint8_t key) 23 | { 24 | MODIFIERKEYS mod; 25 | *((uint8_t*)&mod) = m; 26 | Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); 27 | Serial.print((mod.bmLeftShift == 1) ? "S" : " "); 28 | Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); 29 | Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); 30 | 31 | Serial.print(" >"); 32 | PrintHex(key, 0x80); 33 | Serial.print("< "); 34 | 35 | Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); 36 | Serial.print((mod.bmRightShift == 1) ? "S" : " "); 37 | Serial.print((mod.bmRightAlt == 1) ? "A" : " "); 38 | Serial.println((mod.bmRightGUI == 1) ? "G" : " "); 39 | }; 40 | 41 | void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 42 | { 43 | Serial.print("DN "); 44 | PrintKey(mod, key); 45 | uint8_t c = OemToAscii(mod, key); 46 | 47 | if (c) 48 | OnKeyPressed(c); 49 | } 50 | 51 | void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) { 52 | 53 | MODIFIERKEYS beforeMod; 54 | *((uint8_t*)&beforeMod) = before; 55 | 56 | MODIFIERKEYS afterMod; 57 | *((uint8_t*)&afterMod) = after; 58 | 59 | if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { 60 | Serial.println("LeftCtrl changed"); 61 | } 62 | if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { 63 | Serial.println("LeftShift changed"); 64 | } 65 | if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { 66 | Serial.println("LeftAlt changed"); 67 | } 68 | if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { 69 | Serial.println("LeftGUI changed"); 70 | } 71 | 72 | if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { 73 | Serial.println("RightCtrl changed"); 74 | } 75 | if (beforeMod.bmRightShift != afterMod.bmRightShift) { 76 | Serial.println("RightShift changed"); 77 | } 78 | if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { 79 | Serial.println("RightAlt changed"); 80 | } 81 | if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { 82 | Serial.println("RightGUI changed"); 83 | } 84 | 85 | } 86 | 87 | void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) 88 | { 89 | Serial.print("UP "); 90 | PrintKey(mod, key); 91 | } 92 | 93 | void KbdRptParser::OnKeyPressed(uint8_t key) 94 | { 95 | Serial.print("ASCII: "); 96 | Serial.println((char)key); 97 | }; 98 | 99 | USB Usb; 100 | //USBHub Hub(&Usb); 101 | HIDBoot HidKeyboard(&Usb); 102 | 103 | KbdRptParser Prs; 104 | 105 | void setup() 106 | { 107 | Serial.begin( 115200 ); 108 | #if !defined(__MIPSEL__) 109 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 110 | #endif 111 | Serial.println("Start"); 112 | 113 | if (Usb.Init() == -1) 114 | Serial.println("OSC did not start."); 115 | 116 | delay( 200 ); 117 | 118 | HidKeyboard.SetReportParser(0, &Prs); 119 | } 120 | 121 | void loop() 122 | { 123 | Usb.Task(); 124 | } 125 | 126 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/HID/scale/scale_rptparser.cpp: -------------------------------------------------------------------------------- 1 | /* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */ 2 | #ifdef ARDUINO_SAM_DUE 3 | #include 4 | #endif 5 | #include "scale_rptparser.h" 6 | 7 | const char* UNITS[13] = { 8 | "units", // unknown unit 9 | "mg", // milligram 10 | "g", // gram 11 | "kg", // kilogram 12 | "cd", // carat 13 | "taels", // lian 14 | "gr", // grain 15 | "dwt", // pennyweight 16 | "tonnes", // metric tons 17 | "tons", // avoir ton 18 | "ozt", // troy ounce 19 | "oz", // ounce 20 | "lbs" // pound 21 | }; 22 | 23 | ScaleReportParser::ScaleReportParser(ScaleEvents *evt) : 24 | scaleEvents(evt) 25 | {} 26 | 27 | void ScaleReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) 28 | { 29 | bool match = true; 30 | 31 | // Checking if there are changes in report since the method was last called 32 | for (uint8_t i=0; iOnScaleChanged((const ScaleEventData*)buf); 41 | 42 | for (uint8_t i=0; iwrite( *str++ ); 58 | 59 | } 60 | } 61 | 62 | void ScaleEvents::OnScaleChanged(const ScaleEventData *evt) 63 | { 64 | 65 | pLcd->clear(); 66 | pLcd->home(); 67 | pLcd->setCursor(0,0); 68 | 69 | if( evt->reportID != 3 ) { 70 | 71 | const char inv_report[]="Invalid report!"; 72 | 73 | Serial.println(inv_report); 74 | LcdPrint(inv_report); 75 | 76 | return; 77 | 78 | }//if( evt->reportID != 3... 79 | 80 | switch( evt->status ) { 81 | 82 | case REPORT_FAULT: 83 | Serial.println(F("Report fault")); 84 | break; 85 | 86 | case ZEROED: 87 | Serial.println(F("Scale zero set")); 88 | break; 89 | 90 | case WEIGHING: { 91 | 92 | const char progress[] = "Weighing..."; 93 | Serial.println(progress); 94 | LcdPrint(progress); 95 | break; 96 | } 97 | 98 | case WEIGHT_VALID: { 99 | 100 | char buf[10]; 101 | double weight = evt->weight * pow( 10, evt->exp ); 102 | 103 | 104 | 105 | Serial.print(F("Weight: ")); 106 | Serial.print( weight ); 107 | Serial.print(F(" ")); 108 | Serial.println( UNITS[ evt->unit ]); 109 | 110 | LcdPrint("Weight: "); 111 | dtostrf( weight, 4, 2, buf ); 112 | LcdPrint( buf ); 113 | LcdPrint( UNITS[ evt->unit ]); 114 | 115 | break; 116 | 117 | }//case WEIGHT_VALID... 118 | 119 | case WEIGHT_NEGATIVE: { 120 | 121 | const char negweight[] = "Negative weight"; 122 | Serial.println(negweight); 123 | LcdPrint(negweight); 124 | break; 125 | } 126 | 127 | case OVERWEIGHT: { 128 | 129 | const char overweight[] = "Max.weight reached"; 130 | Serial.println(overweight); 131 | LcdPrint( overweight ); 132 | break; 133 | } 134 | 135 | case CALIBRATE_ME: 136 | 137 | Serial.println(F("Scale calibration required")); 138 | break; 139 | 140 | case ZERO_ME: 141 | 142 | Serial.println(F("Scale zeroing required")); 143 | break; 144 | 145 | default: 146 | 147 | Serial.print(F("Undefined status code: ")); 148 | Serial.println( evt->status ); 149 | break; 150 | 151 | }//switch( evt->status... 152 | 153 | } 154 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/BTHID/KeyboardParser.h: -------------------------------------------------------------------------------- 1 | #ifndef __kbdrptparser_h_ 2 | #define __kbdrptparser_h_ 3 | 4 | class KbdRptParser : public KeyboardReportParser { 5 | protected: 6 | virtual uint8_t HandleLockingKeys(USBHID *hid, uint8_t key); 7 | virtual void OnControlKeysChanged(uint8_t before, uint8_t after); 8 | virtual void OnKeyDown(uint8_t mod, uint8_t key); 9 | virtual void OnKeyUp(uint8_t mod, uint8_t key); 10 | virtual void OnKeyPressed(uint8_t key); 11 | 12 | private: 13 | void PrintKey(uint8_t mod, uint8_t key); 14 | }; 15 | 16 | uint8_t KbdRptParser::HandleLockingKeys(USBHID *hid, uint8_t key) { 17 | uint8_t old_keys = kbdLockingKeys.bLeds; 18 | 19 | switch (key) { 20 | case UHS_HID_BOOT_KEY_NUM_LOCK: 21 | Serial.println(F("Num lock")); 22 | kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock; 23 | break; 24 | case UHS_HID_BOOT_KEY_CAPS_LOCK: 25 | Serial.println(F("Caps lock")); 26 | kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock; 27 | break; 28 | case UHS_HID_BOOT_KEY_SCROLL_LOCK: 29 | Serial.println(F("Scroll lock")); 30 | kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock; 31 | break; 32 | } 33 | 34 | if (old_keys != kbdLockingKeys.bLeds && hid) { 35 | BTHID *pBTHID = reinterpret_cast (hid); // A cast the other way around is done in BTHID.cpp 36 | pBTHID->setLeds(kbdLockingKeys.bLeds); // Update the LEDs on the keyboard 37 | } 38 | 39 | return 0; 40 | }; 41 | 42 | void KbdRptParser::PrintKey(uint8_t m, uint8_t key) { 43 | MODIFIERKEYS mod; 44 | *((uint8_t*)&mod) = m; 45 | Serial.print((mod.bmLeftCtrl == 1) ? F("C") : F(" ")); 46 | Serial.print((mod.bmLeftShift == 1) ? F("S") : F(" ")); 47 | Serial.print((mod.bmLeftAlt == 1) ? F("A") : F(" ")); 48 | Serial.print((mod.bmLeftGUI == 1) ? F("G") : F(" ")); 49 | 50 | Serial.print(F(" >")); 51 | PrintHex(key, 0x80); 52 | Serial.print(F("< ")); 53 | 54 | Serial.print((mod.bmRightCtrl == 1) ? F("C") : F(" ")); 55 | Serial.print((mod.bmRightShift == 1) ? F("S") : F(" ")); 56 | Serial.print((mod.bmRightAlt == 1) ? F("A") : F(" ")); 57 | Serial.println((mod.bmRightGUI == 1) ? F("G") : F(" ")); 58 | }; 59 | 60 | void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) { 61 | Serial.print(F("DN ")); 62 | PrintKey(mod, key); 63 | uint8_t c = OemToAscii(mod, key); 64 | 65 | if (c) 66 | OnKeyPressed(c); 67 | }; 68 | 69 | void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) { 70 | MODIFIERKEYS beforeMod; 71 | *((uint8_t*)&beforeMod) = before; 72 | 73 | MODIFIERKEYS afterMod; 74 | *((uint8_t*)&afterMod) = after; 75 | 76 | if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) 77 | Serial.println(F("LeftCtrl changed")); 78 | if (beforeMod.bmLeftShift != afterMod.bmLeftShift) 79 | Serial.println(F("LeftShift changed")); 80 | if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) 81 | Serial.println(F("LeftAlt changed")); 82 | if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) 83 | Serial.println(F("LeftGUI changed")); 84 | 85 | if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) 86 | Serial.println(F("RightCtrl changed")); 87 | if (beforeMod.bmRightShift != afterMod.bmRightShift) 88 | Serial.println(F("RightShift changed")); 89 | if (beforeMod.bmRightAlt != afterMod.bmRightAlt) 90 | Serial.println(F("RightAlt changed")); 91 | if (beforeMod.bmRightGUI != afterMod.bmRightGUI) 92 | Serial.println(F("RightGUI changed")); 93 | }; 94 | 95 | void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) { 96 | Serial.print(F("UP ")); 97 | PrintKey(mod, key); 98 | }; 99 | 100 | void KbdRptParser::OnKeyPressed(uint8_t key) { 101 | Serial.print(F("ASCII: ")); 102 | Serial.println((char)key); 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/PSBuzz.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #include "PSBuzz.h" 19 | 20 | // To enable serial debugging see "settings.h" 21 | //#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers 22 | 23 | void PSBuzz::ParseHIDData(USBHID *hid __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len, uint8_t *buf) { 24 | if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) { 25 | #ifdef PRINTREPORT 26 | Notify(PSTR("\r\n"), 0x80); 27 | for (uint8_t i = 0; i < len; i++) { 28 | D_PrintHex (buf[i], 0x80); 29 | Notify(PSTR(" "), 0x80); 30 | } 31 | #endif 32 | memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), MFK_CASTUINT8T sizeof(psbuzzButtons))); 33 | 34 | if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed 35 | buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable 36 | oldButtonState.val = psbuzzButtons.val; 37 | } 38 | } 39 | }; 40 | 41 | uint8_t PSBuzz::OnInitSuccessful() { 42 | if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID) { 43 | Reset(); 44 | if (pFuncOnInit) 45 | pFuncOnInit(); // Call the user function 46 | else 47 | setLedOnAll(); // Turn the LED on, on all four controllers 48 | }; 49 | return 0; 50 | }; 51 | 52 | bool PSBuzz::getButtonPress(ButtonEnum b, uint8_t controller) { 53 | return psbuzzButtons.val & (1UL << (b + 5 * controller)); // Each controller uses 5 bits, so the value is shifted 5 for each controller 54 | }; 55 | 56 | bool PSBuzz::getButtonClick(ButtonEnum b, uint8_t controller) { 57 | uint32_t mask = (1UL << (b + 5 * controller)); // Each controller uses 5 bits, so the value is shifted 5 for each controller 58 | bool click = buttonClickState.val & mask; 59 | buttonClickState.val &= ~mask; // Clear "click" event 60 | return click; 61 | }; 62 | 63 | // Source: http://www.developerfusion.com/article/84338/making-usb-c-friendly/ and https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c 64 | void PSBuzz::setLedRaw(bool value, uint8_t controller) { 65 | ledState[controller] = value; // Save value for next time it is called 66 | 67 | uint8_t buf[7]; 68 | buf[0] = 0x00; 69 | buf[1] = ledState[0] ? 0xFF : 0x00; 70 | buf[2] = ledState[1] ? 0xFF : 0x00; 71 | buf[3] = ledState[2] ? 0xFF : 0x00; 72 | buf[4] = ledState[3] ? 0xFF : 0x00; 73 | buf[5] = 0x00; 74 | buf[6] = 0x00; 75 | 76 | PSBuzz_Command(buf, sizeof(buf)); 77 | }; 78 | 79 | void PSBuzz::PSBuzz_Command(uint8_t *data, uint16_t nbytes) { 80 | // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data) 81 | pUsb->ctrlReq(bAddress, epInfo[0].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL); 82 | }; 83 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 18 | 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | /* You can create the instance of the class in two ways */ 21 | WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once 22 | //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote 23 | 24 | void setup() { 25 | Serial.begin(115200); 26 | #if !defined(__MIPSEL__) 27 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 28 | #endif 29 | if (Usb.Init() == -1) { 30 | Serial.print(F("\r\nOSC did not start")); 31 | while (1); //halt 32 | } 33 | Serial.print(F("\r\nWiimote Bluetooth Library Started")); 34 | } 35 | void loop() { 36 | Usb.Task(); 37 | if (Wii.wiiUProControllerConnected) { 38 | if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down 39 | Serial.print(F("\r\nHome")); 40 | Wii.disconnect(); 41 | } 42 | else { 43 | if (Wii.getButtonClick(LEFT)) { 44 | Wii.setLedOff(); 45 | Wii.setLedOn(LED1); 46 | Serial.print(F("\r\nLeft")); 47 | } 48 | if (Wii.getButtonClick(RIGHT)) { 49 | Wii.setLedOff(); 50 | Wii.setLedOn(LED3); 51 | Serial.print(F("\r\nRight")); 52 | } 53 | if (Wii.getButtonClick(DOWN)) { 54 | Wii.setLedOff(); 55 | Wii.setLedOn(LED4); 56 | Serial.print(F("\r\nDown")); 57 | } 58 | if (Wii.getButtonClick(UP)) { 59 | Wii.setLedOff(); 60 | Wii.setLedOn(LED2); 61 | Serial.print(F("\r\nUp")); 62 | } 63 | 64 | if (Wii.getButtonClick(PLUS)) 65 | Serial.print(F("\r\nPlus")); 66 | if (Wii.getButtonClick(MINUS)) 67 | Serial.print(F("\r\nMinus")); 68 | 69 | if (Wii.getButtonClick(A)) 70 | Serial.print(F("\r\nA")); 71 | if (Wii.getButtonClick(B)) { 72 | Wii.setRumbleToggle(); 73 | Serial.print(F("\r\nB")); 74 | } 75 | if (Wii.getButtonClick(X)) 76 | Serial.print(F("\r\nX")); 77 | if (Wii.getButtonClick(Y)) 78 | Serial.print(F("\r\nY")); 79 | 80 | if (Wii.getButtonClick(L)) 81 | Serial.print(F("\r\nL")); 82 | if (Wii.getButtonClick(R)) 83 | Serial.print(F("\r\nR")); 84 | if (Wii.getButtonClick(ZL)) 85 | Serial.print(F("\r\nZL")); 86 | if (Wii.getButtonClick(ZR)) 87 | Serial.print(F("\r\nZR")); 88 | if (Wii.getButtonClick(L3)) 89 | Serial.print(F("\r\nL3")); 90 | if (Wii.getButtonClick(R3)) 91 | Serial.print(F("\r\nR3")); 92 | } 93 | if (Wii.getAnalogHat(LeftHatX) > 2200 || Wii.getAnalogHat(LeftHatX) < 1800 || Wii.getAnalogHat(LeftHatY) > 2200 || Wii.getAnalogHat(LeftHatY) < 1800 || Wii.getAnalogHat(RightHatX) > 2200 || Wii.getAnalogHat(RightHatX) < 1800 || Wii.getAnalogHat(RightHatY) > 2200 || Wii.getAnalogHat(RightHatY) < 1800) { 94 | Serial.print(F("\r\nLeftHatX: ")); 95 | Serial.print(Wii.getAnalogHat(LeftHatX)); 96 | Serial.print(F("\tLeftHatY: ")); 97 | Serial.print(Wii.getAnalogHat(LeftHatY)); 98 | Serial.print(F("\tRightHatX: ")); 99 | Serial.print(Wii.getAnalogHat(RightHatX)); 100 | Serial.print(F("\tRightHatY: ")); 101 | Serial.print(Wii.getAnalogHat(RightHatY)); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/usbh_midi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * USB-MIDI class driver for USB Host Shield 2.0 Library 4 | * Copyright (c) 2012-2017 Yuuichi Akagawa 5 | * 6 | * Idea from LPK25 USB-MIDI to Serial MIDI converter 7 | * by Collin Cunningham - makezine.com, narbotic.com 8 | * 9 | * for use with USB Host Shield 2.0 from Circuitsathome.com 10 | * https://github.com/felis/USB_Host_Shield_2.0 11 | ******************************************************************************* 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see 24 | ******************************************************************************* 25 | */ 26 | 27 | #if !defined(_USBH_MIDI_H_) 28 | #define _USBH_MIDI_H_ 29 | //#define DEBUG_USB_HOST 30 | #include "Usb.h" 31 | 32 | #define MIDI_MAX_ENDPOINTS 5 //endpoint 0, bulk_IN(MIDI), bulk_OUT(MIDI), bulk_IN(VSP), bulk_OUT(VSP) 33 | #define USB_SUBCLASS_MIDISTREAMING 3 34 | #define DESC_BUFF_SIZE 256 35 | #define MIDI_EVENT_PACKET_SIZE 64 36 | #define MIDI_MAX_SYSEX_SIZE 256 37 | class USBH_MIDI; 38 | 39 | class USBH_MIDI : public USBDeviceConfig 40 | { 41 | protected: 42 | static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI) 43 | static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI) 44 | static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl) 45 | static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl) 46 | 47 | /* mandatory members */ 48 | USB *pUsb; 49 | uint8_t bAddress; 50 | uint8_t bConfNum; // configuration number 51 | uint8_t bNumEP; // total number of EP in the configuration 52 | bool bPollEnable; 53 | 54 | bool isMidiFound; 55 | /* Endpoint data structure */ 56 | EpInfo epInfo[MIDI_MAX_ENDPOINTS]; 57 | /* MIDI Event packet buffer */ 58 | uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; 59 | uint8_t readPtr; 60 | 61 | uint8_t parseConfigDescr(uint8_t addr, uint8_t conf); 62 | uint16_t countSysExDataSize(uint8_t *dataptr); 63 | #ifdef DEBUG_USB_HOST 64 | void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); 65 | #endif 66 | public: 67 | uint16_t pid, vid; 68 | USBH_MIDI(USB *p); 69 | // Methods for recieving and sending data 70 | uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr); 71 | uint8_t RecvData(uint8_t *outBuf, bool isRaw=false); 72 | uint8_t RecvRawData(uint8_t *outBuf); 73 | uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0); 74 | uint8_t lookupMsgSize(uint8_t midiMsg, uint8_t cin=0); 75 | uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0); 76 | uint8_t extractSysExData(uint8_t *p, uint8_t *buf); 77 | uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr); 78 | // backward compatibility functions 79 | inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; 80 | inline uint8_t RcvData(uint8_t *outBuf){ return RecvData(outBuf); }; 81 | 82 | // USBDeviceConfig implementation 83 | virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 84 | virtual uint8_t Release(); 85 | virtual uint8_t GetAddress() { return bAddress; }; 86 | }; 87 | #endif //_USBH_MIDI_H_ 88 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/hidcomposite.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #if !defined(__HIDCOMPOSITE_H__) 19 | #define __HIDCOMPOSITE_H__ 20 | 21 | #include "usbhid.h" 22 | //#include "hidescriptorparser.h" 23 | 24 | class HIDComposite : public USBHID { 25 | 26 | struct ReportParser { 27 | uint8_t rptId; 28 | HIDReportParser *rptParser; 29 | } rptParsers[MAX_REPORT_PARSERS]; 30 | 31 | // HID class specific descriptor type and length info obtained from HID descriptor 32 | HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]; 33 | 34 | // Returns HID class specific descriptor length by its type and order number 35 | uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num); 36 | 37 | struct HIDInterface { 38 | struct { 39 | uint8_t bmInterface : 3; 40 | uint8_t bmAltSet : 3; 41 | uint8_t bmProtocol : 2; 42 | }; 43 | uint8_t epIndex[maxEpPerInterface]; 44 | }; 45 | 46 | uint8_t bConfNum; // configuration number 47 | uint8_t bNumIface; // number of interfaces in the configuration 48 | uint8_t bNumEP; // total number of EP in the configuration 49 | uint32_t qNextPollTime; // next poll time 50 | uint8_t pollInterval; 51 | bool bPollEnable; // poll enable flag 52 | 53 | static const uint16_t constBuffLen = 64; // event buffer length 54 | 55 | void Initialize(); 56 | HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto); 57 | 58 | void ZeroMemory(uint8_t len, uint8_t *buf); 59 | 60 | protected: 61 | EpInfo epInfo[totalEndpoints]; 62 | HIDInterface hidInterfaces[maxHidInterfaces]; 63 | 64 | bool bHasReportId; 65 | 66 | uint16_t PID, VID; // PID and VID of connected device 67 | 68 | // HID implementation 69 | HIDReportParser* GetReportParser(uint8_t id); 70 | 71 | virtual uint8_t OnInitSuccessful() { 72 | return 0; 73 | }; 74 | 75 | virtual void ParseHIDData(USBHID *hid __attribute__((unused)), uint8_t ep __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len __attribute__((unused)), uint8_t *buf __attribute__((unused))) { 76 | return; 77 | }; 78 | 79 | public: 80 | HIDComposite(USB *p); 81 | 82 | // HID implementation 83 | bool SetReportParser(uint8_t id, HIDReportParser *prs); 84 | 85 | // USBDeviceConfig implementation 86 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 87 | uint8_t Release(); 88 | uint8_t Poll(); 89 | 90 | virtual uint8_t GetAddress() { 91 | return bAddress; 92 | }; 93 | 94 | virtual bool isReady() { 95 | return bPollEnable; 96 | }; 97 | 98 | // UsbConfigXtracter implementation 99 | void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); 100 | 101 | // Send report - do not mix with SetReport()! 102 | uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); 103 | 104 | // Returns true if we should listen on an interface, false if not 105 | virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0; 106 | }; 107 | 108 | #endif // __HIDCOMPOSITE_H__ 109 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/hiduniversal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #if !defined(__HIDUNIVERSAL_H__) 19 | #define __HIDUNIVERSAL_H__ 20 | 21 | #include "usbhid.h" 22 | //#include "hidescriptorparser.h" 23 | 24 | class HIDUniversal : public USBHID { 25 | 26 | struct ReportParser { 27 | uint8_t rptId; 28 | HIDReportParser *rptParser; 29 | } rptParsers[MAX_REPORT_PARSERS]; 30 | 31 | // HID class specific descriptor type and length info obtained from HID descriptor 32 | HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]; 33 | 34 | // Returns HID class specific descriptor length by its type and order number 35 | uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num); 36 | 37 | struct HIDInterface { 38 | struct { 39 | uint8_t bmInterface : 3; 40 | uint8_t bmAltSet : 3; 41 | uint8_t bmProtocol : 2; 42 | }; 43 | uint8_t epIndex[maxEpPerInterface]; 44 | }; 45 | 46 | uint8_t bConfNum; // configuration number 47 | uint8_t bNumIface; // number of interfaces in the configuration 48 | uint8_t bNumEP; // total number of EP in the configuration 49 | uint32_t qNextPollTime; // next poll time 50 | uint8_t pollInterval; 51 | bool bPollEnable; // poll enable flag 52 | 53 | static const uint16_t constBuffLen = 64; // event buffer length 54 | uint8_t prevBuf[constBuffLen]; // previous event buffer 55 | 56 | void Initialize(); 57 | HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto); 58 | 59 | void ZeroMemory(uint8_t len, uint8_t *buf); 60 | bool BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2); 61 | void SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest); 62 | 63 | protected: 64 | EpInfo epInfo[totalEndpoints]; 65 | HIDInterface hidInterfaces[maxHidInterfaces]; 66 | 67 | bool bHasReportId; 68 | 69 | uint16_t PID, VID; // PID and VID of connected device 70 | 71 | // HID implementation 72 | HIDReportParser* GetReportParser(uint8_t id); 73 | 74 | virtual uint8_t OnInitSuccessful() { 75 | return 0; 76 | }; 77 | 78 | virtual void ParseHIDData(USBHID *hid __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len __attribute__((unused)), uint8_t *buf __attribute__((unused))) { 79 | return; 80 | }; 81 | 82 | public: 83 | HIDUniversal(USB *p); 84 | 85 | // HID implementation 86 | bool SetReportParser(uint8_t id, HIDReportParser *prs); 87 | 88 | // USBDeviceConfig implementation 89 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 90 | uint8_t Release(); 91 | uint8_t Poll(); 92 | 93 | virtual uint8_t GetAddress() { 94 | return bAddress; 95 | }; 96 | 97 | virtual bool isReady() { 98 | return bPollEnable; 99 | }; 100 | 101 | // UsbConfigXtracter implementation 102 | void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); 103 | 104 | // Send report - do not mix with SetReport()! 105 | uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); 106 | }; 107 | 108 | #endif // __HIDUNIVERSAL_H__ 109 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Xbox/XBOXUSB/XBOXUSB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Xbox 360 USB library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | USB Usb; 16 | XBOXUSB Xbox(&Usb); 17 | 18 | void setup() { 19 | Serial.begin(115200); 20 | #if !defined(__MIPSEL__) 21 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 22 | #endif 23 | if (Usb.Init() == -1) { 24 | Serial.print(F("\r\nOSC did not start")); 25 | while (1); //halt 26 | } 27 | Serial.print(F("\r\nXBOX USB Library Started")); 28 | } 29 | void loop() { 30 | Usb.Task(); 31 | if (Xbox.Xbox360Connected) { 32 | if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) { 33 | Serial.print("L2: "); 34 | Serial.print(Xbox.getButtonPress(L2)); 35 | Serial.print("\tR2: "); 36 | Serial.println(Xbox.getButtonPress(R2)); 37 | Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2)); 38 | } else 39 | Xbox.setRumbleOn(0, 0); 40 | 41 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 42 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { 43 | Serial.print(F("LeftHatX: ")); 44 | Serial.print(Xbox.getAnalogHat(LeftHatX)); 45 | Serial.print("\t"); 46 | } 47 | if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { 48 | Serial.print(F("LeftHatY: ")); 49 | Serial.print(Xbox.getAnalogHat(LeftHatY)); 50 | Serial.print("\t"); 51 | } 52 | if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { 53 | Serial.print(F("RightHatX: ")); 54 | Serial.print(Xbox.getAnalogHat(RightHatX)); 55 | Serial.print("\t"); 56 | } 57 | if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 58 | Serial.print(F("RightHatY: ")); 59 | Serial.print(Xbox.getAnalogHat(RightHatY)); 60 | } 61 | Serial.println(); 62 | } 63 | 64 | if (Xbox.getButtonClick(UP)) { 65 | Xbox.setLedOn(LED1); 66 | Serial.println(F("Up")); 67 | } 68 | if (Xbox.getButtonClick(DOWN)) { 69 | Xbox.setLedOn(LED4); 70 | Serial.println(F("Down")); 71 | } 72 | if (Xbox.getButtonClick(LEFT)) { 73 | Xbox.setLedOn(LED3); 74 | Serial.println(F("Left")); 75 | } 76 | if (Xbox.getButtonClick(RIGHT)) { 77 | Xbox.setLedOn(LED2); 78 | Serial.println(F("Right")); 79 | } 80 | 81 | if (Xbox.getButtonClick(START)) { 82 | Xbox.setLedMode(ALTERNATING); 83 | Serial.println(F("Start")); 84 | } 85 | if (Xbox.getButtonClick(BACK)) { 86 | Xbox.setLedBlink(ALL); 87 | Serial.println(F("Back")); 88 | } 89 | if (Xbox.getButtonClick(L3)) 90 | Serial.println(F("L3")); 91 | if (Xbox.getButtonClick(R3)) 92 | Serial.println(F("R3")); 93 | 94 | if (Xbox.getButtonClick(L1)) 95 | Serial.println(F("L1")); 96 | if (Xbox.getButtonClick(R1)) 97 | Serial.println(F("R1")); 98 | if (Xbox.getButtonClick(XBOX)) { 99 | Xbox.setLedMode(ROTATING); 100 | Serial.println(F("Xbox")); 101 | } 102 | 103 | if (Xbox.getButtonClick(A)) 104 | Serial.println(F("A")); 105 | if (Xbox.getButtonClick(B)) 106 | Serial.println(F("B")); 107 | if (Xbox.getButtonClick(X)) 108 | Serial.println(F("X")); 109 | if (Xbox.getButtonClick(Y)) 110 | Serial.println(F("Y")); 111 | } 112 | delay(1); 113 | } 114 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Bluetooth/Wii/Wii.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 18 | 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | /* You can create the instance of the class in two ways */ 21 | WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once 22 | //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote 23 | 24 | bool printAngle; 25 | 26 | void setup() { 27 | Serial.begin(115200); 28 | #if !defined(__MIPSEL__) 29 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 30 | #endif 31 | if (Usb.Init() == -1) { 32 | Serial.print(F("\r\nOSC did not start")); 33 | while (1); //halt 34 | } 35 | Serial.print(F("\r\nWiimote Bluetooth Library Started")); 36 | } 37 | void loop() { 38 | Usb.Task(); 39 | if (Wii.wiimoteConnected) { 40 | if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down 41 | Serial.print(F("\r\nHOME")); 42 | Wii.disconnect(); 43 | } 44 | else { 45 | if (Wii.getButtonClick(LEFT)) { 46 | Wii.setLedOff(); 47 | Wii.setLedOn(LED1); 48 | Serial.print(F("\r\nLeft")); 49 | } 50 | if (Wii.getButtonClick(RIGHT)) { 51 | Wii.setLedOff(); 52 | Wii.setLedOn(LED3); 53 | Serial.print(F("\r\nRight")); 54 | } 55 | if (Wii.getButtonClick(DOWN)) { 56 | Wii.setLedOff(); 57 | Wii.setLedOn(LED4); 58 | Serial.print(F("\r\nDown")); 59 | } 60 | if (Wii.getButtonClick(UP)) { 61 | Wii.setLedOff(); 62 | Wii.setLedOn(LED2); 63 | Serial.print(F("\r\nUp")); 64 | } 65 | 66 | if (Wii.getButtonClick(PLUS)) 67 | Serial.print(F("\r\nPlus")); 68 | if (Wii.getButtonClick(MINUS)) 69 | Serial.print(F("\r\nMinus")); 70 | 71 | if (Wii.getButtonClick(ONE)) 72 | Serial.print(F("\r\nOne")); 73 | if (Wii.getButtonClick(TWO)) 74 | Serial.print(F("\r\nTwo")); 75 | 76 | if (Wii.getButtonClick(A)) { 77 | printAngle = !printAngle; 78 | Serial.print(F("\r\nA")); 79 | } 80 | if (Wii.getButtonClick(B)) { 81 | Wii.setRumbleToggle(); 82 | Serial.print(F("\r\nB")); 83 | } 84 | } 85 | #if 0 // Set this to 1 in order to see the angle of the controllers 86 | if (printAngle) { 87 | Serial.print(F("\r\nPitch: ")); 88 | Serial.print(Wii.getPitch()); 89 | Serial.print(F("\tRoll: ")); 90 | Serial.print(Wii.getRoll()); 91 | if (Wii.motionPlusConnected) { 92 | Serial.print(F("\tYaw: ")); 93 | Serial.print(Wii.getYaw()); 94 | } 95 | if (Wii.nunchuckConnected) { 96 | Serial.print(F("\tNunchuck Pitch: ")); 97 | Serial.print(Wii.getNunchuckPitch()); 98 | Serial.print(F("\tNunchuck Roll: ")); 99 | Serial.print(Wii.getNunchuckRoll()); 100 | } 101 | } 102 | #endif 103 | } 104 | #if 0 // Set this to 1 if you are using a Nunchuck controller 105 | if (Wii.nunchuckConnected) { 106 | if (Wii.getButtonClick(Z)) 107 | Serial.print(F("\r\nZ")); 108 | if (Wii.getButtonClick(C)) 109 | Serial.print(F("\r\nC")); 110 | if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) { 111 | Serial.print(F("\r\nHatX: ")); 112 | Serial.print(Wii.getAnalogHat(HatX)); 113 | Serial.print(F("\tHatY: ")); 114 | Serial.print(Wii.getAnalogHat(HatY)); 115 | } 116 | } 117 | #endif 118 | } 119 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #if !defined(_usb_h_) || defined(MACROS_H) 19 | #error "Never include macros.h directly; include Usb.h instead" 20 | #else 21 | #define MACROS_H 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // HANDY MACROS 25 | //////////////////////////////////////////////////////////////////////////////// 26 | 27 | #define VALUE_BETWEEN(v,l,h) (((v)>(l)) && ((v)<(h))) 28 | #define VALUE_WITHIN(v,l,h) (((v)>=(l)) && ((v)<=(h))) 29 | #define output_pgm_message(wa,fp,mp,el) wa = &mp, fp((char *)pgm_read_pointer(wa), el) 30 | #define output_if_between(v,l,h,wa,fp,mp,el) if(VALUE_BETWEEN(v,l,h)) output_pgm_message(wa,fp,mp[v-(l+1)],el); 31 | 32 | #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) 33 | #ifndef __BYTE_GRABBING_DEFINED__ 34 | #define __BYTE_GRABBING_DEFINED__ 1 35 | #ifdef BROKEN_OPTIMIZER_LITTLE_ENDIAN 36 | // Note: Use this if your compiler generates horrible assembler! 37 | #define BGRAB0(__usi__) (((uint8_t *)&(__usi__))[0]) 38 | #define BGRAB1(__usi__) (((uint8_t *)&(__usi__))[1]) 39 | #define BGRAB2(__usi__) (((uint8_t *)&(__usi__))[2]) 40 | #define BGRAB3(__usi__) (((uint8_t *)&(__usi__))[3]) 41 | #define BGRAB4(__usi__) (((uint8_t *)&(__usi__))[4]) 42 | #define BGRAB5(__usi__) (((uint8_t *)&(__usi__))[5]) 43 | #define BGRAB6(__usi__) (((uint8_t *)&(__usi__))[6]) 44 | #define BGRAB7(__usi__) (((uint8_t *)&(__usi__))[7]) 45 | #else 46 | // Note: The cast alone to uint8_t is actually enough. 47 | // GCC throws out the "& 0xff", and the size is no different. 48 | // Some compilers need it. 49 | #define BGRAB0(__usi__) ((uint8_t)((__usi__) & 0xff )) 50 | #define BGRAB1(__usi__) ((uint8_t)(((__usi__) >> 8) & 0xff)) 51 | #define BGRAB2(__usi__) ((uint8_t)(((__usi__) >> 16) & 0xff)) 52 | #define BGRAB3(__usi__) ((uint8_t)(((__usi__) >> 24) & 0xff)) 53 | #define BGRAB4(__usi__) ((uint8_t)(((__usi__) >> 32) & 0xff)) 54 | #define BGRAB5(__usi__) ((uint8_t)(((__usi__) >> 40) & 0xff)) 55 | #define BGRAB6(__usi__) ((uint8_t)(((__usi__) >> 48) & 0xff)) 56 | #define BGRAB7(__usi__) ((uint8_t)(((__usi__) >> 56) & 0xff)) 57 | #endif 58 | #define BOVER1(__usi__) ((uint16_t)(__usi__) << 8) 59 | #define BOVER2(__usi__) ((uint32_t)(__usi__) << 16) 60 | #define BOVER3(__usi__) ((uint32_t)(__usi__) << 24) 61 | #define BOVER4(__usi__) ((uint64_t)(__usi__) << 32) 62 | #define BOVER5(__usi__) ((uint64_t)(__usi__) << 40) 63 | #define BOVER6(__usi__) ((uint64_t)(__usi__) << 48) 64 | #define BOVER7(__usi__) ((uint64_t)(__usi__) << 56) 65 | 66 | // These are the smallest and fastest ways I have found so far in pure C/C++. 67 | #define BMAKE16(__usc1__,__usc0__) ((uint16_t)((uint16_t)(__usc0__) | (uint16_t)BOVER1(__usc1__))) 68 | #define BMAKE32(__usc3__,__usc2__,__usc1__,__usc0__) ((uint32_t)((uint32_t)(__usc0__) | (uint32_t)BOVER1(__usc1__) | (uint32_t)BOVER2(__usc2__) | (uint32_t)BOVER3(__usc3__))) 69 | #define BMAKE64(__usc7__,__usc6__,__usc5__,__usc4__,__usc3__,__usc2__,__usc1__,__usc0__) ((uint64_t)((uint64_t)__usc0__ | (uint64_t)BOVER1(__usc1__) | (uint64_t)BOVER2(__usc2__) | (uint64_t)BOVER3(__usc3__) | (uint64_t)BOVER4(__usc4__) | (uint64_t)BOVER5(__usc5__) | (uint64_t)BOVER6(__usc6__) | (uint64_t)BOVER1(__usc7__))) 70 | #endif 71 | 72 | /* 73 | * Debug macros: Strings are stored in progmem (flash) instead of RAM. 74 | */ 75 | #define USBTRACE(s) (Notify(PSTR(s), 0x80)) 76 | #define USBTRACE1(s,l) (Notify(PSTR(s), l)) 77 | #define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80)) 78 | #define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l)) 79 | 80 | 81 | #endif /* MACROS_H */ 82 | 83 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Xbox/XBOXOLD/XBOXOLD.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the original Xbox library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed 18 | XBOXOLD Xbox(&Usb); 19 | 20 | void setup() { 21 | Serial.begin(115200); 22 | #if !defined(__MIPSEL__) 23 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 24 | #endif 25 | if (Usb.Init() == -1) { 26 | Serial.print(F("\r\nOSC did not start")); 27 | while (1); // halt 28 | } 29 | Serial.print(F("\r\nXBOX Library Started")); 30 | } 31 | void loop() { 32 | Usb.Task(); 33 | if (Xbox.XboxConnected) { 34 | if (Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) { 35 | Serial.print("BLACK: "); 36 | Serial.print(Xbox.getButtonPress(BLACK)); 37 | Serial.print("\tWHITE: "); 38 | Serial.println(Xbox.getButtonPress(WHITE)); 39 | Xbox.setRumbleOn(Xbox.getButtonPress(BLACK), Xbox.getButtonPress(WHITE)); 40 | } else 41 | Xbox.setRumbleOn(0, 0); 42 | 43 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 44 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { 45 | Serial.print(F("LeftHatX: ")); 46 | Serial.print(Xbox.getAnalogHat(LeftHatX)); 47 | Serial.print("\t"); 48 | } 49 | if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { 50 | Serial.print(F("LeftHatY: ")); 51 | Serial.print(Xbox.getAnalogHat(LeftHatY)); 52 | Serial.print("\t"); 53 | } 54 | if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { 55 | Serial.print(F("RightHatX: ")); 56 | Serial.print(Xbox.getAnalogHat(RightHatX)); 57 | Serial.print("\t"); 58 | } 59 | if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 60 | Serial.print(F("RightHatY: ")); 61 | Serial.print(Xbox.getAnalogHat(RightHatY)); 62 | } 63 | Serial.println(); 64 | } 65 | 66 | if (Xbox.getButtonClick(UP)) 67 | Serial.println(F("Up")); 68 | if (Xbox.getButtonClick(DOWN)) 69 | Serial.println(F("Down")); 70 | if (Xbox.getButtonClick(LEFT)) 71 | Serial.println(F("Left")); 72 | if (Xbox.getButtonClick(RIGHT)) 73 | Serial.println(F("Right")); 74 | 75 | if (Xbox.getButtonClick(START)) 76 | Serial.println(F("Start")); 77 | if (Xbox.getButtonClick(BACK)) 78 | Serial.println(F("Back")); 79 | if (Xbox.getButtonClick(L3)) 80 | Serial.println(F("L3")); 81 | if (Xbox.getButtonClick(R3)) 82 | Serial.println(F("R3")); 83 | 84 | if (Xbox.getButtonPress(A)) { 85 | Serial.print(F("A: ")); 86 | Serial.println(Xbox.getButtonPress(A)); 87 | } 88 | if (Xbox.getButtonPress(B)) { 89 | Serial.print(F("B: ")); 90 | Serial.println(Xbox.getButtonPress(B)); 91 | } 92 | if (Xbox.getButtonPress(X)) { 93 | Serial.print(F("X: ")); 94 | Serial.println(Xbox.getButtonPress(X)); 95 | } 96 | if (Xbox.getButtonPress(Y)) { 97 | Serial.print(F("Y: ")); 98 | Serial.println(Xbox.getButtonPress(Y)); 99 | } 100 | if (Xbox.getButtonPress(L1)) { 101 | Serial.print(F("L1: ")); 102 | Serial.println(Xbox.getButtonPress(L1)); 103 | } 104 | if (Xbox.getButtonPress(R1)) { 105 | Serial.print(F("R1: ")); 106 | Serial.println(Xbox.getButtonPress(R1)); 107 | } 108 | } 109 | delay(1); 110 | } 111 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Legacy Serial MIDI and USB Host bidirectional converter 4 | * Copyright (C) 2013-2017 Yuuichi Akagawa 5 | * 6 | * for use with Arduino MIDI library 7 | * https://github.com/FortySevenEffects/arduino_midi_library/ 8 | * 9 | * Note: 10 | * - If you want use with Leonardo, you must choose Arduino MIDI library v4.0 or higher. 11 | * - This is sample program. Do not expect perfect behavior. 12 | ******************************************************************************* 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | // Satisfy the IDE, which needs to see the include statment in the ino too. 20 | #ifdef dobogusinclude 21 | #include 22 | #endif 23 | #include 24 | 25 | //Arduino MIDI library v4.2 compatibility 26 | #ifdef MIDI_CREATE_DEFAULT_INSTANCE 27 | MIDI_CREATE_DEFAULT_INSTANCE(); 28 | #endif 29 | #ifdef USBCON 30 | #define _MIDI_SERIAL_PORT Serial1 31 | #else 32 | #define _MIDI_SERIAL_PORT Serial 33 | #endif 34 | 35 | ////////////////////////// 36 | // MIDI Pin assign 37 | // 2 : GND 38 | // 4 : +5V(Vcc) with 220ohm 39 | // 5 : TX 40 | ////////////////////////// 41 | 42 | USB Usb; 43 | USBH_MIDI Midi(&Usb); 44 | 45 | void MIDI_poll(); 46 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); 47 | 48 | //If you want handle System Exclusive message, enable this #define otherwise comment out it. 49 | #define USBH_MIDI_SYSEX_ENABLE 50 | 51 | #ifdef USBH_MIDI_SYSEX_ENABLE 52 | //SysEx: 53 | void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) { 54 | Midi.SendSysEx(sysexmsg, sizeofsysex); 55 | } 56 | #endif 57 | 58 | void setup() 59 | { 60 | MIDI.begin(MIDI_CHANNEL_OMNI); 61 | #ifdef USBH_MIDI_SYSEX_ENABLE 62 | MIDI.setHandleSystemExclusive(handle_sysex); 63 | #endif 64 | if (Usb.Init() == -1) { 65 | while (1); //halt 66 | }//if (Usb.Init() == -1... 67 | delay( 200 ); 68 | } 69 | 70 | void loop() 71 | { 72 | uint8_t msg[4]; 73 | 74 | Usb.Task(); 75 | uint32_t t1 = (uint32_t)micros(); 76 | if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 77 | { 78 | MIDI_poll(); 79 | if (MIDI.read()) { 80 | msg[0] = MIDI.getType(); 81 | switch (msg[0]) { 82 | case midi::ActiveSensing : 83 | break; 84 | case midi::SystemExclusive : 85 | //SysEx is handled by event. 86 | break; 87 | default : 88 | msg[1] = MIDI.getData1(); 89 | msg[2] = MIDI.getData2(); 90 | Midi.SendData(msg, 0); 91 | break; 92 | } 93 | } 94 | } 95 | //delay(1ms) 96 | doDelay(t1, (uint32_t)micros(), 1000); 97 | } 98 | 99 | // Poll USB MIDI Controler and send to serial MIDI 100 | void MIDI_poll() 101 | { 102 | uint8_t size; 103 | #ifdef USBH_MIDI_SYSEX_ENABLE 104 | uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; 105 | uint8_t rcode = 0; //return code 106 | uint16_t rcvd; 107 | uint8_t readPtr = 0; 108 | 109 | rcode = Midi.RecvData( &rcvd, recvBuf); 110 | 111 | //data check 112 | if (rcode != 0) return; 113 | if ( recvBuf[0] == 0 && recvBuf[1] == 0 && recvBuf[2] == 0 && recvBuf[3] == 0 ) { 114 | return ; 115 | } 116 | 117 | uint8_t *p = recvBuf; 118 | while (readPtr < MIDI_EVENT_PACKET_SIZE) { 119 | if (*p == 0 && *(p + 1) == 0) break; //data end 120 | 121 | uint8_t outbuf[3]; 122 | uint8_t rc = Midi.extractSysExData(p, outbuf); 123 | if ( rc == 0 ) { 124 | p++; 125 | size = Midi.lookupMsgSize(*p); 126 | _MIDI_SERIAL_PORT.write(p, size); 127 | p += 3; 128 | } else { 129 | _MIDI_SERIAL_PORT.write(outbuf, rc); 130 | p += 4; 131 | } 132 | readPtr += 4; 133 | } 134 | #else 135 | uint8_t outBuf[3]; 136 | do { 137 | if ( (size = Midi.RecvData(outBuf)) > 0 ) { 138 | //MIDI Output 139 | _MIDI_SERIAL_PORT.write(outBuf, size); 140 | } 141 | } while (size > 0); 142 | #endif 143 | } 144 | 145 | // Delay time (max 16383 us) 146 | void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) 147 | { 148 | uint32_t t3; 149 | 150 | if ( t1 > t2 ) { 151 | t3 = (0xFFFFFFFF - t1 + t2); 152 | } else { 153 | t3 = t2 - t1; 154 | } 155 | 156 | if ( t3 < delayTime ) { 157 | delayMicroseconds(delayTime - t3); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/parsetools.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | #if !defined(_usb_h_) || defined(__PARSETOOLS_H__) 19 | #error "Never include parsetools.h directly; include Usb.h instead" 20 | #else 21 | #define __PARSETOOLS_H__ 22 | 23 | struct MultiValueBuffer { 24 | uint8_t valueSize; 25 | void *pValue; 26 | } __attribute__((packed)); 27 | 28 | class MultiByteValueParser { 29 | uint8_t * pBuf; 30 | uint8_t countDown; 31 | uint8_t valueSize; 32 | 33 | public: 34 | 35 | MultiByteValueParser() : pBuf(NULL), countDown(0), valueSize(0) { 36 | }; 37 | 38 | const uint8_t* GetBuffer() { 39 | return pBuf; 40 | }; 41 | 42 | void Initialize(MultiValueBuffer * const pbuf) { 43 | pBuf = (uint8_t*)pbuf->pValue; 44 | countDown = valueSize = pbuf->valueSize; 45 | }; 46 | 47 | bool Parse(uint8_t **pp, uint16_t *pcntdn); 48 | }; 49 | 50 | class ByteSkipper { 51 | uint8_t *pBuf; 52 | uint8_t nStage; 53 | uint16_t countDown; 54 | 55 | public: 56 | 57 | ByteSkipper() : pBuf(NULL), nStage(0), countDown(0) { 58 | }; 59 | 60 | void Initialize(MultiValueBuffer *pbuf) { 61 | pBuf = (uint8_t*)pbuf->pValue; 62 | countDown = 0; 63 | }; 64 | 65 | bool Skip(uint8_t **pp, uint16_t *pcntdn, uint16_t bytes_to_skip) { 66 | switch(nStage) { 67 | case 0: 68 | countDown = bytes_to_skip; 69 | nStage++; 70 | case 1: 71 | for(; countDown && (*pcntdn); countDown--, (*pp)++, (*pcntdn)--); 72 | 73 | if(!countDown) 74 | nStage = 0; 75 | }; 76 | return (!countDown); 77 | }; 78 | }; 79 | 80 | // Pointer to a callback function triggered for each element of PTP array when used with PTPArrayParser 81 | typedef void (*PTP_ARRAY_EL_FUNC)(const MultiValueBuffer * const p, uint32_t count, const void *me); 82 | 83 | class PTPListParser { 84 | public: 85 | 86 | enum ParseMode { 87 | modeArray, modeRange/*, modeEnum*/ 88 | }; 89 | 90 | private: 91 | uint8_t nStage; 92 | uint8_t enStage; 93 | 94 | uint32_t arLen; 95 | uint32_t arLenCntdn; 96 | 97 | uint8_t lenSize; // size of the array length field in bytes 98 | uint8_t valSize; // size of the array element in bytes 99 | 100 | MultiValueBuffer *pBuf; 101 | 102 | // The only parser for both size and array element parsing 103 | MultiByteValueParser theParser; 104 | 105 | uint8_t /*ParseMode*/ prsMode; 106 | 107 | public: 108 | 109 | PTPListParser() : 110 | nStage(0), 111 | enStage(0), 112 | arLen(0), 113 | arLenCntdn(0), 114 | lenSize(0), 115 | valSize(0), 116 | pBuf(NULL), 117 | prsMode(modeArray) { 118 | }; 119 | 120 | void Initialize(const uint8_t len_size, const uint8_t val_size, MultiValueBuffer * const p, const uint8_t mode = modeArray) { 121 | pBuf = p; 122 | lenSize = len_size; 123 | valSize = val_size; 124 | prsMode = mode; 125 | 126 | if(prsMode == modeRange) { 127 | arLenCntdn = arLen = 3; 128 | nStage = 2; 129 | } else { 130 | arLenCntdn = arLen = 0; 131 | nStage = 0; 132 | } 133 | enStage = 0; 134 | theParser.Initialize(p); 135 | }; 136 | 137 | bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me = NULL); 138 | }; 139 | 140 | #endif // __PARSETOOLS_H__ 141 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Xbox/XBOXONE/XBOXONE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Xbox ONE USB library - by guruthree, based on work by 3 | Kristian Lauszus. 4 | */ 5 | 6 | #include 7 | 8 | // Satisfy the IDE, which needs to see the include statment in the ino too. 9 | #ifdef dobogusinclude 10 | #include 11 | #endif 12 | #include 13 | 14 | USB Usb; 15 | XBOXONE Xbox(&Usb); 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 20 | if (Usb.Init() == -1) { 21 | Serial.print(F("\r\nOSC did not start")); 22 | while (1); //halt 23 | } 24 | Serial.print(F("\r\nXBOX USB Library Started")); 25 | } 26 | void loop() { 27 | Usb.Task(); 28 | if (Xbox.XboxOneConnected) { 29 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 30 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { 31 | Serial.print(F("LeftHatX: ")); 32 | Serial.print(Xbox.getAnalogHat(LeftHatX)); 33 | Serial.print("\t"); 34 | } 35 | if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { 36 | Serial.print(F("LeftHatY: ")); 37 | Serial.print(Xbox.getAnalogHat(LeftHatY)); 38 | Serial.print("\t"); 39 | } 40 | if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { 41 | Serial.print(F("RightHatX: ")); 42 | Serial.print(Xbox.getAnalogHat(RightHatX)); 43 | Serial.print("\t"); 44 | } 45 | if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 46 | Serial.print(F("RightHatY: ")); 47 | Serial.print(Xbox.getAnalogHat(RightHatY)); 48 | } 49 | Serial.println(); 50 | } 51 | 52 | if (Xbox.getButtonPress(L2) > 0 || Xbox.getButtonPress(R2) > 0) { 53 | if (Xbox.getButtonPress(L2) > 0) { 54 | Serial.print(F("L2: ")); 55 | Serial.print(Xbox.getButtonPress(L2)); 56 | Serial.print("\t"); 57 | } 58 | if (Xbox.getButtonPress(R2) > 0) { 59 | Serial.print(F("R2: ")); 60 | Serial.print(Xbox.getButtonPress(R2)); 61 | Serial.print("\t"); 62 | } 63 | Serial.println(); 64 | } 65 | 66 | // Set rumble effect 67 | static uint16_t oldL2Value, oldR2Value; 68 | if (Xbox.getButtonPress(L2) != oldL2Value || Xbox.getButtonPress(R2) != oldR2Value) { 69 | oldL2Value = Xbox.getButtonPress(L2); 70 | oldR2Value = Xbox.getButtonPress(R2); 71 | uint8_t leftRumble = map(oldL2Value, 0, 1023, 0, 255); // Map the trigger values into a byte 72 | uint8_t rightRumble = map(oldR2Value, 0, 1023, 0, 255); 73 | if (leftRumble > 0 || rightRumble > 0) 74 | Xbox.setRumbleOn(leftRumble, rightRumble, leftRumble, rightRumble); 75 | else 76 | Xbox.setRumbleOff(); 77 | } 78 | 79 | if (Xbox.getButtonClick(UP)) 80 | Serial.println(F("Up")); 81 | if (Xbox.getButtonClick(DOWN)) 82 | Serial.println(F("Down")); 83 | if (Xbox.getButtonClick(LEFT)) 84 | Serial.println(F("Left")); 85 | if (Xbox.getButtonClick(RIGHT)) 86 | Serial.println(F("Right")); 87 | 88 | if (Xbox.getButtonClick(START)) 89 | Serial.println(F("Start")); 90 | if (Xbox.getButtonClick(BACK)) 91 | Serial.println(F("Back")); 92 | if (Xbox.getButtonClick(XBOX)) 93 | Serial.println(F("Xbox")); 94 | if (Xbox.getButtonClick(SYNC)) 95 | Serial.println(F("Sync")); 96 | 97 | if (Xbox.getButtonClick(L1)) 98 | Serial.println(F("L1")); 99 | if (Xbox.getButtonClick(R1)) 100 | Serial.println(F("R1")); 101 | if (Xbox.getButtonClick(L2)) 102 | Serial.println(F("L2")); 103 | if (Xbox.getButtonClick(R2)) 104 | Serial.println(F("R2")); 105 | if (Xbox.getButtonClick(L3)) 106 | Serial.println(F("L3")); 107 | if (Xbox.getButtonClick(R3)) 108 | Serial.println(F("R3")); 109 | 110 | 111 | if (Xbox.getButtonClick(A)) 112 | Serial.println(F("A")); 113 | if (Xbox.getButtonClick(B)) 114 | Serial.println(F("B")); 115 | if (Xbox.getButtonClick(X)) 116 | Serial.println(F("X")); 117 | if (Xbox.getButtonClick(Y)) 118 | Serial.println(F("Y")); 119 | } 120 | delay(1); 121 | } 122 | -------------------------------------------------------------------------------- /II_Encoder.cpp: -------------------------------------------------------------------------------- 1 | /*! \file II_Encoder.cpp 2 | * \brief Output ASCII in parallel form to Apple II keyboard connector. 3 | * 4 | * Takes a ASCII character or string and sets the IO Pins accordingly for APPLE II keayboard Input. 5 | */ 6 | 7 | #include "Arduino.h" 8 | #include "II_Encoder.h" 9 | 10 | void II_Encoder::begin(void) 11 | { 12 | pinMode(IIKEYB_D0, OUTPUT); 13 | pinMode(IIKEYB_D1, OUTPUT); 14 | pinMode(IIKEYB_D2, OUTPUT); 15 | pinMode(IIKEYB_D3, OUTPUT); 16 | pinMode(IIKEYB_D4, OUTPUT); 17 | pinMode(IIKEYB_D5, OUTPUT); 18 | pinMode(IIKEYB_D6, OUTPUT); 19 | 20 | pinMode(IIKEYB_RESET, INPUT_PULLUP); 21 | pinMode(IIKEYB_STRB, OUTPUT); 22 | 23 | digitalWrite(IIKEYB_D0, LOW); 24 | digitalWrite(IIKEYB_D1, LOW); 25 | digitalWrite(IIKEYB_D2, LOW); 26 | digitalWrite(IIKEYB_D3, LOW); 27 | digitalWrite(IIKEYB_D4, LOW); 28 | digitalWrite(IIKEYB_D5, LOW); 29 | digitalWrite(IIKEYB_D6, LOW); 30 | 31 | digitalWrite(IIKEYB_RESET, HIGH); 32 | digitalWrite(IIKEYB_STRB, HIGH); 33 | 34 | } 35 | 36 | void II_Encoder::Reset(void) 37 | { 38 | pinMode(IIKEYB_RESET, OUTPUT); 39 | digitalWrite(IIKEYB_RESET, LOW); 40 | delay(10); 41 | pinMode(IIKEYB_RESET, INPUT_PULLUP); 42 | digitalWrite(IIKEYB_RESET, HIGH); 43 | 44 | } 45 | 46 | int II_Encoder::IIputchar(int bOutput) 47 | { 48 | if (bOutput & 0b00000001) 49 | digitalWrite(IIKEYB_D0, HIGH); 50 | else 51 | digitalWrite(IIKEYB_D0, LOW); 52 | 53 | if (bOutput & 0b00000010) 54 | digitalWrite(IIKEYB_D1, HIGH); 55 | else 56 | digitalWrite(IIKEYB_D1, LOW); 57 | 58 | if (bOutput & 0b00000100) 59 | digitalWrite(IIKEYB_D2, HIGH); 60 | else 61 | digitalWrite(IIKEYB_D2, LOW); 62 | 63 | if (bOutput & 0b00001000) 64 | digitalWrite(IIKEYB_D3, HIGH); 65 | else 66 | digitalWrite(IIKEYB_D3, LOW); 67 | 68 | if (bOutput & 0b00010000) 69 | digitalWrite(IIKEYB_D4, HIGH); 70 | else 71 | digitalWrite(IIKEYB_D4, LOW); 72 | 73 | if (bOutput & 0b00100000) 74 | digitalWrite(IIKEYB_D5, HIGH); 75 | else 76 | digitalWrite(IIKEYB_D5, LOW); 77 | 78 | if (bOutput & 0b01000000) 79 | digitalWrite(IIKEYB_D6, HIGH); 80 | else 81 | digitalWrite(IIKEYB_D6, LOW); 82 | 83 | pinMode(IIKEYB_STRB, HIGH); 84 | delay(1); 85 | pinMode(IIKEYB_STRB, LOW); 86 | 87 | delay(10); 88 | return (bOutput); 89 | } 90 | 91 | int II_Encoder::IIputs(const char *string) 92 | { 93 | int i = 0; 94 | while (string[i]) //standard c idiom for looping through a null-terminated string 95 | { 96 | if (IIputchar(string[i]) == EOF) //if we got the EOF value from writing the char 97 | { 98 | return EOF; 99 | } 100 | i++; 101 | } 102 | 103 | if (IIputchar('\r') == EOF) //this will occur right after we quit due to the null terminated character. 104 | { 105 | return EOF; 106 | } 107 | return 1; //to meet spec. 108 | } 109 | 110 | char *II_Encoder::convert(unsigned int num, const int base, char *ptr) 111 | { 112 | static char Representation[] = "0123456789ABCDEF"; 113 | *ptr = '\0'; 114 | 115 | do 116 | { 117 | *--ptr = Representation[num % base]; 118 | num /= base; 119 | } while (num != 0); 120 | 121 | return (ptr); 122 | } 123 | 124 | void II_Encoder::IIprintf(char* format, ...) 125 | { 126 | char *traverse; 127 | unsigned int i; 128 | char *s; 129 | char pBuffer[25]; 130 | 131 | //Module 1: Initializing Myprintf's arguments 132 | va_list arg; 133 | va_start(arg, format); 134 | 135 | for (traverse = format; *traverse != '\0'; traverse++) 136 | { 137 | while ( *traverse != '%' ) 138 | { 139 | IIputchar(*traverse); 140 | traverse++; 141 | } 142 | 143 | traverse++; 144 | 145 | //Module 2: Fetching and executing arguments 146 | switch (*traverse) 147 | { 148 | case 'c' : i = va_arg(arg, int); //Fetch char argument 149 | IIputchar(i); 150 | break; 151 | 152 | case 'd' : i = va_arg(arg, int); //Fetch Decimal/Integer argument 153 | if (i < 0) 154 | { 155 | i = -i; 156 | IIputchar('-'); 157 | } 158 | IIputs(convert(i, 10, pBuffer)); 159 | break; 160 | 161 | case 'o': i = va_arg(arg, unsigned int); //Fetch Octal representation 162 | IIputs(convert(i, 8, pBuffer)); 163 | break; 164 | 165 | case 's': s = va_arg(arg, char *); //Fetch string 166 | IIputs(s); 167 | break; 168 | 169 | case 'x': i = va_arg(arg, unsigned int); //Fetch Hexadecimal representation 170 | 171 | IIputs(convert(i, 16, pBuffer)); 172 | break; 173 | } 174 | } 175 | 176 | //Module 3: Closing argument list to necessary clean-up 177 | va_end(arg); 178 | } 179 | 180 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/PS3Enums.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #ifndef _ps3enums_h 19 | #define _ps3enums_h 20 | 21 | #include "controllerEnums.h" 22 | 23 | /** Size of the output report buffer for the Dualshock and Navigation controllers */ 24 | #define PS3_REPORT_BUFFER_SIZE 48 25 | 26 | /** Report buffer for all PS3 commands */ 27 | const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE] PROGMEM = { 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0xff, 0x27, 0x10, 0x00, 0x32, 31 | 0xff, 0x27, 0x10, 0x00, 0x32, 32 | 0xff, 0x27, 0x10, 0x00, 0x32, 33 | 0xff, 0x27, 0x10, 0x00, 0x32, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 37 | }; 38 | 39 | /** Size of the output report buffer for the Move Controller */ 40 | #define MOVE_REPORT_BUFFER_SIZE 7 41 | 42 | /** Used to set the LEDs on the controllers */ 43 | const uint8_t PS3_LEDS[] PROGMEM = { 44 | 0x00, // OFF 45 | 0x01, // LED1 46 | 0x02, // LED2 47 | 0x04, // LED3 48 | 0x08, // LED4 49 | 50 | 0x09, // LED5 51 | 0x0A, // LED6 52 | 0x0C, // LED7 53 | 0x0D, // LED8 54 | 0x0E, // LED9 55 | 0x0F, // LED10 56 | }; 57 | 58 | /** 59 | * Buttons on the controllers. 60 | * Note: that the location is shifted 9 when it's connected via USB. 61 | */ 62 | const uint32_t PS3_BUTTONS[] PROGMEM = { 63 | 0x10, // UP 64 | 0x20, // RIGHT 65 | 0x40, // DOWN 66 | 0x80, // LEFT 67 | 68 | 0x01, // SELECT 69 | 0x08, // START 70 | 0x02, // L3 71 | 0x04, // R3 72 | 73 | 0x0100, // L2 74 | 0x0200, // R2 75 | 0x0400, // L1 76 | 0x0800, // R1 77 | 78 | 0x1000, // TRIANGLE 79 | 0x2000, // CIRCLE 80 | 0x4000, // CROSS 81 | 0x8000, // SQUARE 82 | 83 | 0x010000, // PS 84 | 0x080000, // MOVE - covers 12 bits - we only need to read the top 8 85 | 0x100000, // T - covers 12 bits - we only need to read the top 8 86 | }; 87 | 88 | /** 89 | * Analog buttons on the controllers. 90 | * Note: that the location is shifted 9 when it's connected via USB. 91 | */ 92 | const uint8_t PS3_ANALOG_BUTTONS[] PROGMEM = { 93 | 23, // UP_ANALOG 94 | 24, // RIGHT_ANALOG 95 | 25, // DOWN_ANALOG 96 | 26, // LEFT_ANALOG 97 | 0, 0, 0, 0, // Skip SELECT, L3, R3 and START 98 | 99 | 27, // L2_ANALOG 100 | 28, // R2_ANALOG 101 | 29, // L1_ANALOG 102 | 30, // R1_ANALOG 103 | 31, // TRIANGLE_ANALOG 104 | 32, // CIRCLE_ANALOG 105 | 33, // CROSS_ANALOG 106 | 34, // SQUARE_ANALOG 107 | 0, 0, // Skip PS and MOVE 108 | 109 | // Playstation Move Controller 110 | 15, // T_ANALOG - Both at byte 14 (last reading) and byte 15 (current reading) 111 | }; 112 | 113 | enum StatusEnum { 114 | // Note that the location is shifted 9 when it's connected via USB 115 | // Byte location | bit location 116 | Plugged = (38 << 8) | 0x02, 117 | Unplugged = (38 << 8) | 0x03, 118 | 119 | Charging = (39 << 8) | 0xEE, 120 | NotCharging = (39 << 8) | 0xF1, 121 | Shutdown = (39 << 8) | 0x01, 122 | Dying = (39 << 8) | 0x02, 123 | Low = (39 << 8) | 0x03, 124 | High = (39 << 8) | 0x04, 125 | Full = (39 << 8) | 0x05, 126 | 127 | MoveCharging = (21 << 8) | 0xEE, 128 | MoveNotCharging = (21 << 8) | 0xF1, 129 | MoveShutdown = (21 << 8) | 0x01, 130 | MoveDying = (21 << 8) | 0x02, 131 | MoveLow = (21 << 8) | 0x03, 132 | MoveHigh = (21 << 8) | 0x04, 133 | MoveFull = (21 << 8) | 0x05, 134 | 135 | CableRumble = (40 << 8) | 0x10, // Operating by USB and rumble is turned on 136 | Cable = (40 << 8) | 0x12, // Operating by USB and rumble is turned off 137 | BluetoothRumble = (40 << 8) | 0x14, // Operating by Bluetooth and rumble is turned on 138 | Bluetooth = (40 << 8) | 0x16, // Operating by Bluetooth and rumble is turned off 139 | }; 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/PS4BT.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2014 Kristian Lauszus, TKJ Electronics. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Kristian Lauszus, TKJ Electronics 14 | Web : http://www.tkjelectronics.com 15 | e-mail : kristianl@tkjelectronics.com 16 | */ 17 | 18 | #ifndef _ps4bt_h_ 19 | #define _ps4bt_h_ 20 | 21 | #include "BTHID.h" 22 | #include "PS4Parser.h" 23 | 24 | /** 25 | * This class implements support for the PS4 controller via Bluetooth. 26 | * It uses the BTHID class for all the Bluetooth communication. 27 | */ 28 | class PS4BT : public BTHID, public PS4Parser { 29 | public: 30 | /** 31 | * Constructor for the PS4BT class. 32 | * @param p Pointer to the BTD class instance. 33 | * @param pair Set this to true in order to pair with the device. If the argument is omitted then it will not pair with it. One can use ::PAIR to set it to true. 34 | * @param pin Write the pin to BTD#btdPin. If argument is omitted, then "0000" will be used. 35 | */ 36 | PS4BT(BTD *p, bool pair = false, const char *pin = "0000") : 37 | BTHID(p, pair, pin) { 38 | PS4Parser::Reset(); 39 | }; 40 | 41 | /** 42 | * Used to check if a PS4 controller is connected. 43 | * @return Returns true if it is connected. 44 | */ 45 | bool connected() { 46 | return BTHID::connected; 47 | }; 48 | 49 | protected: 50 | /** @name BTHID implementation */ 51 | /** 52 | * Used to parse Bluetooth HID data. 53 | * @param len The length of the incoming data. 54 | * @param buf Pointer to the data buffer. 55 | */ 56 | virtual void ParseBTHIDData(uint8_t len, uint8_t *buf) { 57 | PS4Parser::Parse(len, buf); 58 | }; 59 | 60 | /** 61 | * Called when a device is successfully initialized. 62 | * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. 63 | * This is useful for instance if you want to set the LEDs in a specific way. 64 | */ 65 | virtual void OnInitBTHID() { 66 | PS4Parser::Reset(); 67 | enable_sixaxis(); // Make the controller send out the entire output report 68 | if (pFuncOnInit) 69 | pFuncOnInit(); // Call the user function 70 | else 71 | setLed(Blue); 72 | }; 73 | 74 | /** Used to reset the different buffers to there default values */ 75 | virtual void ResetBTHID() { 76 | PS4Parser::Reset(); 77 | }; 78 | /**@}*/ 79 | 80 | /** @name PS4Parser implementation */ 81 | virtual void sendOutputReport(PS4Output *output) { // Source: https://github.com/chrippa/ds4drv 82 | uint8_t buf[79]; 83 | memset(buf, 0, sizeof(buf)); 84 | 85 | buf[0] = 0x52; // HID BT Set_report (0x50) | Report Type (Output 0x02) 86 | buf[1] = 0x11; // Report ID 87 | buf[2] = 0x80; 88 | buf[4]= 0xFF; 89 | 90 | buf[7] = output->smallRumble; // Small Rumble 91 | buf[8] = output->bigRumble; // Big rumble 92 | 93 | buf[9] = output->r; // Red 94 | buf[10] = output->g; // Green 95 | buf[11] = output->b; // Blue 96 | 97 | buf[12] = output->flashOn; // Time to flash bright (255 = 2.5 seconds) 98 | buf[13] = output->flashOff; // Time to flash dark (255 = 2.5 seconds) 99 | 100 | output->reportChanged = false; 101 | 102 | // The PS4 console actually set the four last bytes to a CRC32 checksum, but it seems like it is actually not needed 103 | 104 | HID_Command(buf, sizeof(buf)); 105 | }; 106 | /**@}*/ 107 | 108 | private: 109 | void enable_sixaxis() { // Command used to make the PS4 controller send out the entire output report 110 | uint8_t buf[2]; 111 | buf[0] = 0x43; // HID BT Get_report (0x40) | Report Type (Feature 0x03) 112 | buf[1] = 0x02; // Report ID 113 | 114 | HID_Command(buf, 2); 115 | }; 116 | 117 | void HID_Command(uint8_t *data, uint8_t nbytes) { 118 | pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); 119 | }; 120 | }; 121 | #endif 122 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/Xbox/XBOXRECV/XBOXRECV.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the Xbox Wireless Reciver library - developed by Kristian Lauszus 3 | It supports up to four controllers wirelessly 4 | For more information see the blog post: http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/ or 5 | send me an e-mail: kristianl@tkjelectronics.com 6 | */ 7 | 8 | #include 9 | 10 | // Satisfy the IDE, which needs to see the include statment in the ino too. 11 | #ifdef dobogusinclude 12 | #include 13 | #endif 14 | #include 15 | 16 | USB Usb; 17 | XBOXRECV Xbox(&Usb); 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | #if !defined(__MIPSEL__) 22 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 23 | #endif 24 | if (Usb.Init() == -1) { 25 | Serial.print(F("\r\nOSC did not start")); 26 | while (1); //halt 27 | } 28 | Serial.print(F("\r\nXbox Wireless Receiver Library Started")); 29 | } 30 | void loop() { 31 | Usb.Task(); 32 | if (Xbox.XboxReceiverConnected) { 33 | for (uint8_t i = 0; i < 4; i++) { 34 | if (Xbox.Xbox360Connected[i]) { 35 | if (Xbox.getButtonPress(L2, i) || Xbox.getButtonPress(R2, i)) { 36 | Serial.print("L2: "); 37 | Serial.print(Xbox.getButtonPress(L2, i)); 38 | Serial.print("\tR2: "); 39 | Serial.println(Xbox.getButtonPress(R2, i)); 40 | Xbox.setRumbleOn(Xbox.getButtonPress(L2, i), Xbox.getButtonPress(R2, i), i); 41 | } 42 | 43 | if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500 || Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500 || Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500 || Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) { 44 | if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500) { 45 | Serial.print(F("LeftHatX: ")); 46 | Serial.print(Xbox.getAnalogHat(LeftHatX, i)); 47 | Serial.print("\t"); 48 | } 49 | if (Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500) { 50 | Serial.print(F("LeftHatY: ")); 51 | Serial.print(Xbox.getAnalogHat(LeftHatY, i)); 52 | Serial.print("\t"); 53 | } 54 | if (Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500) { 55 | Serial.print(F("RightHatX: ")); 56 | Serial.print(Xbox.getAnalogHat(RightHatX, i)); 57 | Serial.print("\t"); 58 | } 59 | if (Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) { 60 | Serial.print(F("RightHatY: ")); 61 | Serial.print(Xbox.getAnalogHat(RightHatY, i)); 62 | } 63 | Serial.println(); 64 | } 65 | 66 | if (Xbox.getButtonClick(UP, i)) { 67 | Xbox.setLedOn(LED1, i); 68 | Serial.println(F("Up")); 69 | } 70 | if (Xbox.getButtonClick(DOWN, i)) { 71 | Xbox.setLedOn(LED4, i); 72 | Serial.println(F("Down")); 73 | } 74 | if (Xbox.getButtonClick(LEFT, i)) { 75 | Xbox.setLedOn(LED3, i); 76 | Serial.println(F("Left")); 77 | } 78 | if (Xbox.getButtonClick(RIGHT, i)) { 79 | Xbox.setLedOn(LED2, i); 80 | Serial.println(F("Right")); 81 | } 82 | 83 | if (Xbox.getButtonClick(START, i)) { 84 | Xbox.setLedMode(ALTERNATING, i); 85 | Serial.println(F("Start")); 86 | } 87 | if (Xbox.getButtonClick(BACK, i)) { 88 | Xbox.setLedBlink(ALL, i); 89 | Serial.println(F("Back")); 90 | } 91 | if (Xbox.getButtonClick(L3, i)) 92 | Serial.println(F("L3")); 93 | if (Xbox.getButtonClick(R3, i)) 94 | Serial.println(F("R3")); 95 | 96 | if (Xbox.getButtonClick(L1, i)) 97 | Serial.println(F("L1")); 98 | if (Xbox.getButtonClick(R1, i)) 99 | Serial.println(F("R1")); 100 | if (Xbox.getButtonClick(XBOX, i)) { 101 | Xbox.setLedMode(ROTATING, i); 102 | Serial.print(F("Xbox (Battery: ")); 103 | Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3 104 | Serial.println(F(")")); 105 | } 106 | if (Xbox.getButtonClick(SYNC, i)) { 107 | Serial.println(F("Sync")); 108 | Xbox.disconnect(i); 109 | } 110 | 111 | if (Xbox.getButtonClick(A, i)) 112 | Serial.println(F("A")); 113 | if (Xbox.getButtonClick(B, i)) 114 | Serial.println(F("B")); 115 | if (Xbox.getButtonClick(X, i)) 116 | Serial.println(F("X")); 117 | if (Xbox.getButtonClick(Y, i)) 118 | Serial.println(F("Y")); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/adk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 2 | 3 | This software may be distributed and modified under the terms of the GNU 4 | General Public License version 2 (GPL2) as published by the Free Software 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of 6 | this file. Please note that GPL2 Section 2[b] requires that all works based 7 | on this software must also be made publicly available under the terms of 8 | the GPL2 ("Copyleft"). 9 | 10 | Contact information 11 | ------------------- 12 | 13 | Circuits At Home, LTD 14 | Web : http://www.circuitsathome.com 15 | e-mail : support@circuitsathome.com 16 | */ 17 | 18 | /* Google ADK interface support header */ 19 | 20 | #if !defined(_ADK_H_) 21 | #define _ADK_H_ 22 | 23 | #include "Usb.h" 24 | 25 | #define ADK_VID 0x18D1 26 | #define ADK_PID 0x2D00 27 | #define ADB_PID 0x2D01 28 | 29 | #define XOOM //enables repeating getProto() and getConf() attempts 30 | //necessary for slow devices such as Motorola XOOM 31 | //defined by default, can be commented out to save memory 32 | 33 | /* requests */ 34 | 35 | #define ADK_GETPROTO 51 //check USB accessory protocol version 36 | #define ADK_SENDSTR 52 //send identifying string 37 | #define ADK_ACCSTART 53 //start device in accessory mode 38 | 39 | #define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE 40 | #define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE 41 | 42 | #define ACCESSORY_STRING_MANUFACTURER 0 43 | #define ACCESSORY_STRING_MODEL 1 44 | #define ACCESSORY_STRING_DESCRIPTION 2 45 | #define ACCESSORY_STRING_VERSION 3 46 | #define ACCESSORY_STRING_URI 4 47 | #define ACCESSORY_STRING_SERIAL 5 48 | 49 | #define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT 50 | 51 | class ADK; 52 | 53 | class ADK : public USBDeviceConfig, public UsbConfigXtracter { 54 | private: 55 | /* ID strings */ 56 | const char* manufacturer; 57 | const char* model; 58 | const char* description; 59 | const char* version; 60 | const char* uri; 61 | const char* serial; 62 | 63 | /* ADK proprietary requests */ 64 | uint8_t getProto(uint8_t* adkproto); 65 | uint8_t sendStr(uint8_t index, const char* str); 66 | uint8_t switchAcc(void); 67 | 68 | protected: 69 | static const uint8_t epDataInIndex; // DataIn endpoint index 70 | static const uint8_t epDataOutIndex; // DataOUT endpoint index 71 | 72 | /* mandatory members */ 73 | USB *pUsb; 74 | uint8_t bAddress; 75 | uint8_t bConfNum; // configuration number 76 | 77 | uint8_t bNumEP; // total number of EP in the configuration 78 | bool ready; 79 | 80 | /* Endpoint data structure */ 81 | EpInfo epInfo[ADK_MAX_ENDPOINTS]; 82 | 83 | void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); 84 | 85 | public: 86 | ADK(USB *pUsb, const char* manufacturer, 87 | const char* model, 88 | const char* description, 89 | const char* version, 90 | const char* uri, 91 | const char* serial); 92 | 93 | // Methods for receiving and sending data 94 | uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr); 95 | uint8_t SndData(uint16_t nbytes, uint8_t *dataptr); 96 | 97 | 98 | // USBDeviceConfig implementation 99 | uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed); 100 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 101 | uint8_t Release(); 102 | 103 | virtual uint8_t Poll() { 104 | return 0; 105 | }; 106 | 107 | virtual uint8_t GetAddress() { 108 | return bAddress; 109 | }; 110 | 111 | virtual bool isReady() { 112 | return ready; 113 | }; 114 | 115 | virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { 116 | return (vid == ADK_VID && (pid == ADK_PID || pid == ADB_PID)); 117 | }; 118 | 119 | //UsbConfigXtracter implementation 120 | void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); 121 | }; //class ADK : public USBDeviceConfig ... 122 | 123 | /* get ADK protocol version */ 124 | 125 | /* returns 2 bytes in *adkproto */ 126 | inline uint8_t ADK::getProto(uint8_t* adkproto) { 127 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL)); 128 | } 129 | 130 | /* send ADK string */ 131 | inline uint8_t ADK::sendStr(uint8_t index, const char* str) { 132 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL)); 133 | } 134 | 135 | /* switch to accessory mode */ 136 | inline uint8_t ADK::switchAcc(void) { 137 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL)); 138 | } 139 | 140 | #endif // _ADK_H_ 141 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield_Library_2.0/examples/PS4USB/PS4USB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Example sketch for the PS4 USB library - developed by Kristian Lauszus 3 | For more information visit my blog: http://blog.tkjelectronics.dk/ or 4 | send me an e-mail: kristianl@tkjelectronics.com 5 | */ 6 | 7 | #include 8 | 9 | // Satisfy the IDE, which needs to see the include statment in the ino too. 10 | #ifdef dobogusinclude 11 | #include 12 | #endif 13 | #include 14 | 15 | USB Usb; 16 | PS4USB PS4(&Usb); 17 | 18 | bool printAngle, printTouch; 19 | uint8_t oldL2Value, oldR2Value; 20 | 21 | void setup() { 22 | Serial.begin(115200); 23 | #if !defined(__MIPSEL__) 24 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 25 | #endif 26 | if (Usb.Init() == -1) { 27 | Serial.print(F("\r\nOSC did not start")); 28 | while (1); // Halt 29 | } 30 | Serial.print(F("\r\nPS4 USB Library Started")); 31 | } 32 | 33 | void loop() { 34 | Usb.Task(); 35 | 36 | if (PS4.connected()) { 37 | if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) { 38 | Serial.print(F("\r\nLeftHatX: ")); 39 | Serial.print(PS4.getAnalogHat(LeftHatX)); 40 | Serial.print(F("\tLeftHatY: ")); 41 | Serial.print(PS4.getAnalogHat(LeftHatY)); 42 | Serial.print(F("\tRightHatX: ")); 43 | Serial.print(PS4.getAnalogHat(RightHatX)); 44 | Serial.print(F("\tRightHatY: ")); 45 | Serial.print(PS4.getAnalogHat(RightHatY)); 46 | } 47 | 48 | if (PS4.getAnalogButton(L2) || PS4.getAnalogButton(R2)) { // These are the only analog buttons on the PS4 controller 49 | Serial.print(F("\r\nL2: ")); 50 | Serial.print(PS4.getAnalogButton(L2)); 51 | Serial.print(F("\tR2: ")); 52 | Serial.print(PS4.getAnalogButton(R2)); 53 | } 54 | if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different 55 | PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2)); 56 | oldL2Value = PS4.getAnalogButton(L2); 57 | oldR2Value = PS4.getAnalogButton(R2); 58 | 59 | if (PS4.getButtonClick(PS)) 60 | Serial.print(F("\r\nPS")); 61 | if (PS4.getButtonClick(TRIANGLE)) { 62 | Serial.print(F("\r\nTraingle")); 63 | PS4.setRumbleOn(RumbleLow); 64 | } 65 | if (PS4.getButtonClick(CIRCLE)) { 66 | Serial.print(F("\r\nCircle")); 67 | PS4.setRumbleOn(RumbleHigh); 68 | } 69 | if (PS4.getButtonClick(CROSS)) { 70 | Serial.print(F("\r\nCross")); 71 | PS4.setLedFlash(10, 10); // Set it to blink rapidly 72 | } 73 | if (PS4.getButtonClick(SQUARE)) { 74 | Serial.print(F("\r\nSquare")); 75 | PS4.setLedFlash(0, 0); // Turn off blinking 76 | } 77 | 78 | if (PS4.getButtonClick(UP)) { 79 | Serial.print(F("\r\nUp")); 80 | PS4.setLed(Red); 81 | } if (PS4.getButtonClick(RIGHT)) { 82 | Serial.print(F("\r\nRight")); 83 | PS4.setLed(Blue); 84 | } if (PS4.getButtonClick(DOWN)) { 85 | Serial.print(F("\r\nDown")); 86 | PS4.setLed(Yellow); 87 | } if (PS4.getButtonClick(LEFT)) { 88 | Serial.print(F("\r\nLeft")); 89 | PS4.setLed(Green); 90 | } 91 | 92 | if (PS4.getButtonClick(L1)) 93 | Serial.print(F("\r\nL1")); 94 | if (PS4.getButtonClick(L3)) 95 | Serial.print(F("\r\nL3")); 96 | if (PS4.getButtonClick(R1)) 97 | Serial.print(F("\r\nR1")); 98 | if (PS4.getButtonClick(R3)) 99 | Serial.print(F("\r\nR3")); 100 | 101 | if (PS4.getButtonClick(SHARE)) 102 | Serial.print(F("\r\nShare")); 103 | if (PS4.getButtonClick(OPTIONS)) { 104 | Serial.print(F("\r\nOptions")); 105 | printAngle = !printAngle; 106 | } 107 | if (PS4.getButtonClick(TOUCHPAD)) { 108 | Serial.print(F("\r\nTouchpad")); 109 | printTouch = !printTouch; 110 | } 111 | 112 | if (printAngle) { // Print angle calculated using the accelerometer only 113 | Serial.print(F("\r\nPitch: ")); 114 | Serial.print(PS4.getAngle(Pitch)); 115 | Serial.print(F("\tRoll: ")); 116 | Serial.print(PS4.getAngle(Roll)); 117 | } 118 | 119 | if (printTouch) { // Print the x, y coordinates of the touchpad 120 | if (PS4.isTouching(0) || PS4.isTouching(1)) // Print newline and carriage return if any of the fingers are touching the touchpad 121 | Serial.print(F("\r\n")); 122 | for (uint8_t i = 0; i < 2; i++) { // The touchpad track two fingers 123 | if (PS4.isTouching(i)) { // Print the position of the finger if it is touching the touchpad 124 | Serial.print(F("X")); Serial.print(i + 1); Serial.print(F(": ")); 125 | Serial.print(PS4.getX(i)); 126 | Serial.print(F("\tY")); Serial.print(i + 1); Serial.print(F(": ")); 127 | Serial.print(PS4.getY(i)); 128 | Serial.print(F("\t")); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | --------------------------------------------------------------------------------