├── COPYING.md ├── LICENSE ├── README.md ├── k3ng_keyer ├── AudioPWMSineWave.h ├── TinyFSK.h ├── k3ng_keyer.ino ├── keyer.h ├── keyer_callsign_prefixes.h ├── keyer_debug.h ├── keyer_dependencies.h ├── keyer_features_and_options.h ├── keyer_features_and_options_fk_10.h ├── keyer_features_and_options_fk_11.h ├── keyer_features_and_options_generic_STM32F103C.h ├── keyer_features_and_options_iz3gme.h ├── keyer_features_and_options_k5bcq.h ├── keyer_features_and_options_maple_mini.h ├── keyer_features_and_options_megakeyer.h ├── keyer_features_and_options_mortty.h ├── keyer_features_and_options_mortty_pico_over_usb.h ├── keyer_features_and_options_mortty_regular.h ├── keyer_features_and_options_mortty_regular_with_potentiometer.h ├── keyer_features_and_options_mortty_so2r.h ├── keyer_features_and_options_mortty_so2r_with_potentiometer.h ├── keyer_features_and_options_nanokeyer_rev_b.h ├── keyer_features_and_options_nanokeyer_rev_d.h ├── keyer_features_and_options_open_interface.h ├── keyer_features_and_options_opencwkeyer_mk2.h ├── keyer_features_and_options_test.h ├── keyer_features_and_options_test_everything.h ├── keyer_features_and_options_tinykeyer.h ├── keyer_features_and_options_yaacwk.h ├── keyer_features_and_options_yccc_so2r_mini.h ├── keyer_hardware.h ├── keyer_pin_settings.h ├── keyer_pin_settings_fk_10.h ├── keyer_pin_settings_fk_11.h ├── keyer_pin_settings_generic_STM32F103C.h ├── keyer_pin_settings_iz3gme.h ├── keyer_pin_settings_k5bcq.h ├── keyer_pin_settings_maple_mini.h ├── keyer_pin_settings_megakeyer.h ├── keyer_pin_settings_mortty.h ├── keyer_pin_settings_mortty_pico_over_usb.h ├── keyer_pin_settings_mortty_regular.h ├── keyer_pin_settings_mortty_regular_with_potentiometer.h ├── keyer_pin_settings_mortty_so2r.h ├── keyer_pin_settings_mortty_so2r_with_potentiometer.h ├── keyer_pin_settings_nanokeyer_rev_b.h ├── keyer_pin_settings_nanokeyer_rev_d.h ├── keyer_pin_settings_open_interface.h ├── keyer_pin_settings_opencwkeyer_mk2.h ├── keyer_pin_settings_test.h ├── keyer_pin_settings_test_everything.h ├── keyer_pin_settings_tinykeyer.h ├── keyer_pin_settings_yaacwk.h ├── keyer_pin_settings_yccc_so2r_mini.h ├── keyer_settings.h ├── keyer_settings_fk_10.h ├── keyer_settings_fk_11.h ├── keyer_settings_generic_STM32F103C.h ├── keyer_settings_iz3gme.h ├── keyer_settings_k5bcq.h ├── keyer_settings_maple_mini.h ├── keyer_settings_megakeyer.h ├── keyer_settings_mortty.h ├── keyer_settings_mortty_pico_over_usb.h ├── keyer_settings_mortty_regular.h ├── keyer_settings_mortty_regular_with_potentiometer.h ├── keyer_settings_mortty_so2r.h ├── keyer_settings_mortty_so2r_with_potentiometer.h ├── keyer_settings_nanokeyer_rev_b.h ├── keyer_settings_nanokeyer_rev_d.h ├── keyer_settings_open_interface.h ├── keyer_settings_opencwkeyer_mk2.h ├── keyer_settings_test.h ├── keyer_settings_test_everything.h ├── keyer_settings_tinykeyer.h ├── keyer_settings_yaacwk.h ├── keyer_settings_yccc_so2r_mini.h ├── keyer_stm32duino.h ├── keyer_training_text_czech.h ├── keyer_training_text_english.h ├── keyer_training_text_norsk.h ├── keyer_training_text_polish.h └── src │ └── buttonarray │ ├── buttonarray.cpp │ ├── buttonarray.h │ └── buttonarray.ino ├── libraries ├── Adafruit_LiquidCrystal │ ├── Adafruit_LiquidCrystal.cpp │ ├── Adafruit_LiquidCrystal.h │ ├── README.md │ ├── keywords.txt │ ├── library.properties │ └── utility │ │ ├── Adafruit_MCP23008.cpp │ │ └── Adafruit_MCP23008.h ├── Adafruit_MCP23017 │ ├── Adafruit_MCP23017.cpp │ └── Adafruit_MCP23017.h ├── Adafruit_RGBLCDShield │ ├── Adafruit_RGBLCDShield.cpp │ └── Adafruit_RGBLCDShield.h ├── BasicTerm │ ├── BasicTerm.cpp │ └── BasicTerm.h ├── E24C1024 │ ├── E24C1024.cpp │ └── E24C1024.h ├── Goertzel │ ├── goertzel.cpp │ └── goertzel.h ├── K3NG_PS2Keyboard │ ├── K3NG_PS2Keyboard.cpp │ ├── K3NG_PS2Keyboard.h │ └── library.properties ├── Keypad │ ├── Keypad.cpp │ └── Keypad.h ├── NewTone │ ├── NewTone.cpp │ ├── NewTone.h │ └── keywords.txt ├── README.md ├── TwiLiquidCrystal │ ├── LICENSE │ ├── README.md │ ├── TwiLiquidCrystal.cpp │ ├── TwiLiquidCrystal.h │ └── library.properties └── USB_Host_Shield │ ├── .gitattributes │ ├── .gitignore │ ├── .gitmodules │ ├── BTD.cpp │ ├── BTD.h │ ├── BTHID.cpp │ ├── BTHID.h │ ├── PS3BT.cpp │ ├── PS3BT.h │ ├── PS3Enums.h │ ├── PS3USB.cpp │ ├── PS3USB.h │ ├── PS4BT.h │ ├── PS4Parser.cpp │ ├── PS4Parser.h │ ├── PS4USB.h │ ├── PSBuzz.cpp │ ├── PSBuzz.h │ ├── README.md │ ├── SPP.cpp │ ├── SPP.h │ ├── Usb.cpp │ ├── Usb.h │ ├── UsbCore.h │ ├── Wii.cpp │ ├── Wii.h │ ├── WiiCameraReadme.md │ ├── XBOXOLD.cpp │ ├── XBOXOLD.h │ ├── XBOXRECV.cpp │ ├── XBOXRECV.h │ ├── XBOXUSB.cpp │ ├── XBOXUSB.h │ ├── address.h │ ├── adk.cpp │ ├── adk.h │ ├── avrpins.h │ ├── cdc_XR21B1411.cpp │ ├── cdc_XR21B1411.h │ ├── cdcacm.cpp │ ├── cdcacm.h │ ├── cdcftdi.cpp │ ├── cdcftdi.h │ ├── cdcprolific.cpp │ ├── cdcprolific.h │ ├── confdescparser.h │ ├── controllerEnums.h │ ├── examples │ ├── Bluetooth │ │ ├── BTHID │ │ │ ├── BTHID.ino │ │ │ ├── KeyboardParser.h │ │ │ └── MouseParser.h │ │ ├── PS3BT │ │ │ └── PS3BT.ino │ │ ├── PS3Multi │ │ │ └── PS3Multi.ino │ │ ├── PS3SPP │ │ │ └── PS3SPP.ino │ │ ├── PS4BT │ │ │ └── PS4BT.ino │ │ ├── SPP │ │ │ └── SPP.ino │ │ ├── SPPMulti │ │ │ └── SPPMulti.ino │ │ ├── Wii │ │ │ └── Wii.ino │ │ ├── WiiIRCamera │ │ │ └── WiiIRCamera.ino │ │ ├── WiiMulti │ │ │ └── WiiMulti.ino │ │ └── WiiUProController │ │ │ └── WiiUProController.ino │ ├── HID │ │ ├── USBHIDBootKbd │ │ │ └── USBHIDBootKbd.ino │ │ ├── USBHIDBootKbdAndMouse │ │ │ └── USBHIDBootKbdAndMouse.ino │ │ ├── USBHIDBootMouse │ │ │ └── USBHIDBootMouse.ino │ │ ├── USBHIDJoystick │ │ │ ├── USBHIDJoystick.ino │ │ │ ├── hidjoystickrptparser.cpp │ │ │ └── hidjoystickrptparser.h │ │ ├── USBHID_desc │ │ │ ├── USBHID_desc.ino │ │ │ └── pgmstrings.h │ │ ├── le3dp │ │ │ ├── le3dp.ino │ │ │ ├── le3dp_rptparser.cpp │ │ │ └── le3dp_rptparser.h │ │ └── scale │ │ │ ├── scale.ino │ │ │ ├── scale_rptparser.cpp │ │ │ └── scale_rptparser.h │ ├── PS3USB │ │ └── PS3USB.ino │ ├── PS4USB │ │ └── PS4USB.ino │ ├── PSBuzz │ │ └── PSBuzz.ino │ ├── USB_desc │ │ ├── USB_desc.ino │ │ └── pgmstrings.h │ ├── Xbox │ │ ├── XBOXOLD │ │ │ └── XBOXOLD.ino │ │ ├── XBOXRECV │ │ │ └── XBOXRECV.ino │ │ └── XBOXUSB │ │ │ └── XBOXUSB.ino │ ├── acm │ │ └── acm_terminal │ │ │ ├── acm_terminal.ino │ │ │ └── pgmstrings.h │ ├── adk │ │ ├── ArduinoBlinkLED │ │ │ └── ArduinoBlinkLED.ino │ │ ├── adk_barcode │ │ │ └── adk_barcode.ino │ │ ├── demokit_20 │ │ │ └── demokit_20.ino │ │ ├── term_test │ │ │ └── term_test.ino │ │ └── term_time │ │ │ └── term_time.ino │ ├── board_qc │ │ └── board_qc.ino │ ├── cdc_XR21B1411 │ │ └── XR_terminal │ │ │ └── XR_terminal.ino │ ├── ftdi │ │ └── USBFTDILoopback │ │ │ ├── USBFTDILoopback.ino │ │ │ └── pgmstrings.h │ ├── hub_demo │ │ ├── hub_demo.ino │ │ └── pgmstrings.h │ ├── max_LCD │ │ └── max_LCD.ino │ ├── pl2303 │ │ ├── pl2303_gprs_terminal │ │ │ └── pl2303_gprs_terminal.ino │ │ ├── pl2303_gps │ │ │ └── pl2303_gps.ino │ │ ├── pl2303_tinygps │ │ │ └── pl2303_tinygps.ino │ │ └── pl2303_xbee_terminal │ │ │ └── pl2303_xbee_terminal.ino │ └── testusbhostFAT │ │ ├── Makefile │ │ ├── README.md │ │ └── testusbhostFAT.ino │ ├── gpl2.txt │ ├── hexdump.h │ ├── hid.cpp │ ├── hid.h │ ├── hidboot.cpp │ ├── hidboot.h │ ├── hidescriptorparser.cpp │ ├── hidescriptorparser.h │ ├── hiduniversal.cpp │ ├── hiduniversal.h │ ├── hidusagestr.h │ ├── hidusagetitlearrays.cpp │ ├── keywords.txt │ ├── library.json │ ├── macros.h │ ├── masstorage.cpp │ ├── masstorage.h │ ├── max3421e.h │ ├── max_LCD.cpp │ ├── max_LCD.h │ ├── message.cpp │ ├── message.h │ ├── parsetools.cpp │ ├── parsetools.h │ ├── printhex.h │ ├── settings.h │ ├── sink_parser.h │ ├── usb_ch9.h │ ├── usbhost.h │ ├── usbhub.cpp │ ├── usbhub.h │ ├── version_helper.h │ └── xboxEnums.h └── preconfigurations └── YaaCWk ├── so1r └── PS2_WINKEY_Atmega644P │ ├── keyer_features_and_options_yaacwk.h │ └── keyer_pin_settings_yaacwk.h └── so2r ├── PS2_WINKEY_Atmega644P ├── default.txt ├── keyer_features_and_options_yaacwk.h └── keyer_pin_settings_yaacwk.h ├── USB_Atmega644P ├── keyer_features_and_options_yaacwk.h └── keyer_pin_settings_yaacwk.h └── USB_WINKEY_Atmega1284P ├── keyer_features_and_options_yaacwk.h └── keyer_pin_settings_yaacwk.h /README.md: -------------------------------------------------------------------------------- 1 | # k3ng_cw_keyer 2 | K3NG Arduino CW Keyer 3 | 4 | The K3NG Keyer is an open source Arduino based CW (Morse Code) keyer with a lot of features and flexibility, rivaling commercial keyers which often cost significantly more. The code can be used with a full blown Arduino board or an AVR microcontroller chip can be programmed and used directly in a circuit. This keyer is suitable as a standalone keyer or for use permanently installed inside a rig, especially homebrew QRP rigs. It’s open source code so you can fully customize it to fit your needs and also perhaps learn from it or find coding ideas for other projects. 5 | 6 | Documentation is located here: 7 | https://github.com/k3ng/k3ng_cw_keyer/wiki 8 | -------------------------------------------------------------------------------- /k3ng_keyer/keyer_debug.h: -------------------------------------------------------------------------------- 1 | // don't touch these unless you know what the hell you are doing or you're asked to uncomment these for debug dumps 2 | // #define DEBUG_STARTUP 3 | // #define DEBUG_STARTUP_BLINKS 4 | // #define DEBUG_LOOP 5 | // #define DEBUG_EEPROM 6 | // #define DEBUG_MEMORIES 7 | // #define DEBUG_PLAY_MEMORY 8 | // #define DEBUG_SEND_CHAR 9 | // #define DEBUG_MEMORY_WRITE 10 | // #define DEBUG_MEMORYCHECK 11 | // #define DEBUG_MEMORY_LOCATIONS 12 | // #define DEBUG_CAPTURE_COM_PORT 13 | // #define DEBUG_HELL_TEST 14 | // #define DEBUG_WINKEY_PROTOCOL_USING_CW 15 | // #define DEBUG_CHECK_SERIAL 16 | // #define DEBUG_PS2_KEYBOARD 17 | // #define DEBUG_VARIABLE_DUMP 18 | // #define DEBUG_BUTTONS 19 | // #define DEBUG_COMMAND_MODE 20 | // #define DEBUG_GET_CW_INPUT_FROM_USER 21 | // #define DEBUG_POTENTIOMETER 22 | // #define DEBUG_CW_DECODER 23 | // #define DEBUG_CW_DECODER_WPM 24 | // #define DEBUG_SERIAL_SEND_CW_CALLOUT 25 | // #define DEBUG_SLEEP 26 | // #define DEBUG_BACKLIGHT 27 | // #define DEBUG_BUTTON_ARRAY 28 | // #define DEBUG_USB 29 | // #define DEBUG_USB_KEYBOARD 30 | // #define DEBUG_CAPACITIVE_PADDLE 31 | // #define DEBUG_DISPLAY_SCROLL_PRINT_CHAR 32 | // #define DEBUG_WINKEY // <- to use this you must have a multi-serial port Arduino and use FEATURE_COMMAND_LINE_INTERFACE_ON_SECONDARY_PORT 33 | // #define DEBUG_WINKEY_SEND_ERRANT_BYTE 34 | // #define DEBUG_WINKEY_PORT_WRITE 35 | // #define DEBUG_CW_COMPUTER_KEYBOARD 36 | // #define DEBUG_CW_DECODER_WITH_TONE 37 | // #define DEBUG_OPTION_CW_DECODER_GOERTZEL_AUDIO_DETECTOR 38 | // #define DEBUG_FEATURE_COMPETITION_COMPRESSION_DETECTION 39 | // #define DEBUG_FEATURE_STRAIGHT_KEY_ECHO 40 | // #define DEBUG_UDP 41 | // #define DEBUG_UDP_WRITE 42 | // #define DEBUG_WEB_SERVER 43 | // #define DEBUG_WEB_PARSE_GET 44 | // #define DEBUG_WEB_SERVER_READS 45 | // #define DEBUG_INTERNET_LINKING_RECEIVE 46 | // #define DEBUG_INTERNET_LINKING_SEND 47 | // #define DEBUG_UDP_PACKET_RECEIVE 48 | // #define DEBUG_FORCE_RESET 49 | // #define DEBUG_WINKEY_DISABLE_LEAD_IN_TIME_SETTING 50 | // #define DEBUG_KEYPAD_SERIAL 51 | // #define DEBUG_CALLSIGN_PRACTICE_SHOW_CALLSIGN 52 | // #define DEBUG_WORDSWORTH 53 | // #define DEBUG_PRACTICE_SERIAL 54 | // #define DEBUG_PRACTICE_CMD_MODE 55 | // #define DEBUG_SD_CARD 56 | // #define DEBUG_FARNSWORTH 57 | // #define DEBUG_FARNSWORTH_TIMING 58 | // #define DEBUG_ASYNC_EEPROM_WRITE 59 | // #define DEBUG_SERVICE_SEND_BUFFER 60 | // #define DEBUG_EEPROM_READ_SETTINGS 61 | // #define DEBUG_LOOP_ELEMENT_LENGTHS 62 | 63 | // #define OPTION_WINKEY_IGNORE_FIRST_STATUS_REQUEST 64 | -------------------------------------------------------------------------------- /k3ng_keyer/keyer_dependencies.h: -------------------------------------------------------------------------------- 1 | 2 | #if defined(FEATURE_LCD_4BIT) || defined(FEATURE_LCD_8BIT) || defined(FEATURE_LCD_ADAFRUIT_I2C) || defined(FEATURE_LCD_ADAFRUIT_BACKPACK) || defined(FEATURE_LCD_YDv1) ||defined(FEATURE_LCD1602_N07DH) || defined(FEATURE_LCD_SAINSMART_I2C) || defined(FEATURE_LCD_FABO_PCF8574) || defined(FEATURE_LCD_MATHERTEL_PCF8574) || defined(FEATURE_LCD_HD44780) || defined(FEATURE_LCD_I2C_FDEBRABANDER) || defined(FEATURE_LCD_TWILIQUIDCRYSTAL) || defined(FEATURE_OLED_SSD1306) 3 | #define FEATURE_DISPLAY 4 | #endif 5 | 6 | #if defined(FEATURE_COMMAND_LINE_INTERFACE_ON_SECONDARY_PORT) && !defined(FEATURE_COMMAND_LINE_INTERFACE) 7 | #define FEATURE_COMMAND_LINE_INTERFACE 8 | #endif 9 | 10 | #if defined(FEATURE_COMMAND_LINE_INTERFACE) || defined(FEATURE_WINKEY_EMULATION) 11 | #define FEATURE_SERIAL 12 | #endif 13 | 14 | //#if defined(HARDWARE_ARDUINO_DUE) && !defined(FEATURE_EEPROM_E24C1024) && defined(FEATURE_MEMORIES) 15 | #if defined(ARDUINO_SAM_DUE) && !defined(FEATURE_EEPROM_E24C1024) && defined(FEATURE_MEMORIES) 16 | #error "In order to use FEATURE_MEMORIES with HARDWARE_ARDUINO_DUE you need FEATURE_EEPROM_E24C1024" 17 | #endif 18 | 19 | #if defined(FEATURE_DISPLAY) || defined(FEATURE_COMMAND_LINE_INTERFACE) || defined(FEATURE_CW_COMPUTER_KEYBOARD) 20 | #define FEATURE_PADDLE_ECHO 21 | #endif 22 | 23 | 24 | #if defined(FEATURE_STRAIGHT_KEY) && (defined(FEATURE_STRAIGHT_KEY_ECHO) || defined(FEATURE_MEMORIES) || defined(FEATURE_CW_COMPUTER_KEYBOARD)) 25 | #define FEATURE_STRAIGHT_KEY_DECODE 26 | #endif 27 | 28 | #if defined(FEATURE_WEB_SERVER) || defined(FEATURE_INTERNET_LINK) 29 | #define FEATURE_ETHERNET 30 | #endif 31 | 32 | #if defined(FEATURE_INTERNET_LINK) 33 | #define FEATURE_UDP 34 | #endif 35 | 36 | #if defined(FEATURE_4x4_KEYPAD) && defined(FEATURE_3x4_KEYPAD) 37 | #error "You can't use both FEATURE_4x4_KEYPAD and FEATURE_3x4_KEYPAD simultaneously" 38 | #endif 39 | 40 | #if defined(FEATURE_TRAINING_COMMAND_LINE_INTERFACE) && defined(OPTION_WORDSWORTH_NORSK) && !defined(OPTION_NON_ENGLISH_EXTENSIONS) 41 | #define OPTION_NON_ENGLISH_EXTENSIONS 42 | #endif 43 | 44 | #if defined(FEATURE_BEACON_SETTING) && !defined(FEATURE_MEMORIES) 45 | #error "FEATURE_BEACON_SETTING requires FEATURE_MEMORIES and you may also want FEATURE_MEMORY_MACROS" 46 | #endif 47 | 48 | #if defined(FEATURE_COMMAND_MODE) && !defined(FEATURE_BUTTONS) 49 | #error "FEATURE_COMMAND_MODE requires FEATURE_BUTTONS" 50 | #endif 51 | 52 | #if defined(PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE) 53 | #error "PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE set" 54 | #endif 55 | -------------------------------------------------------------------------------- /k3ng_keyer/keyer_pin_settings_nanokeyer_rev_b.h: -------------------------------------------------------------------------------- 1 | #ifndef keyer_pin_settings_h 2 | #define keyer_pin_settings_h 3 | 4 | #define paddle_left 2 5 | #define paddle_right 5 6 | #define tx_key_line_1 11 // (high = key down/tx on) 7 | #define tx_key_line_2 13 // Rev A & B nanoKeyer PTT port 8 | #define tx_key_line_3 0 9 | #define tx_key_line_4 0 10 | #define tx_key_line_5 0 11 | #define tx_key_line_6 0 12 | #define sidetone_line 4 // connect a speaker for sidetone 13 | #define potentiometer A7 // Rev A & B nanoKeyer 14 | #define ptt_tx_1 0 // PTT ("push to talk") lines 15 | //#define ptt_tx_1 13 // nanoKeyer PTT port 16 | #define ptt_tx_2 0 // Can be used for keying fox transmitter, T/R switch, or keying slow boatanchors 17 | #define ptt_tx_3 0 // These are optional - set to 0 if unused 18 | #define ptt_tx_4 0 19 | #define ptt_tx_5 0 20 | #define ptt_tx_6 0 21 | #define analog_buttons_pin A6 // Rev A & B nanokeyer 22 | #define lcd_rs A2 23 | #define lcd_enable 10 24 | #define lcd_d4 6 25 | #define lcd_d5 7 26 | #define lcd_d6 8 27 | #define lcd_d7 9 28 | #define ps2_keyboard_data A5 // Rev A & B nanokeyer 29 | #define ps2_keyboard_clock 3 30 | #define tx_key_dit 0 // if defined, goes active for dit (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 31 | #define tx_key_dah 0 // if defined, goes active for dah (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 32 | 33 | #define potentiometer_enable_pin 0 // if defined, the potentiometer will be enabled only when this pin is held low; set to 0 to ignore this pin 34 | 35 | #if defined(FEATURE_SLEEP) 36 | #define keyer_awake 13 // Goes active when keyer is awake, inactive when in sleep mode; change active and inactive states in keyer_settings file 37 | #endif 38 | 39 | #if defined(FEATURE_LCD_BACKLIGHT_AUTO_DIM) 40 | #define keyer_power_led 0 // must be a PWM-capable pin 41 | #endif 42 | 43 | #if defined(FEATURE_CAPACITIVE_PADDLE_PINS) 44 | #define capactive_paddle_pin_inhibit_pin 0 // if this pin is defined and is set high, the capacitive paddle pins will switch to normal (non-capacitive) sensing mode 45 | #endif 46 | 47 | /* 48 | FEATURE_SIDETONE_SWITCH 49 | Enabling this feature and an external toggle switch adds switch control for playing cw sidetone. 50 | ST Switch status is displayed in the status command. This feature will override the software control of the sidetone (\o). 51 | Arduino pin is assigned by SIDETONE_SWITCH 52 | */ 53 | 54 | #ifdef FEATURE_SIDETONE_SWITCH 55 | #define SIDETONE_SWITCH 8 56 | #endif //FEATURE_SIDETONE_SWITCH 57 | 58 | #ifdef FEATURE_4x4_KEYPAD 59 | #define Row3 33 60 | #define Row2 32 61 | #define Row1 31 62 | #define Row0 30 63 | #define Col3 37 64 | #define Col2 36 65 | #define Col1 35 66 | #define Col0 34 67 | #endif 68 | 69 | #ifdef FEATURE_3x4_KEYPAD 70 | #define Row3 33 71 | #define Row2 32 72 | #define Row1 31 73 | #define Row0 30 74 | #define Col2 36 75 | #define Col1 35 76 | #define Col0 34 77 | #endif 78 | 79 | #ifdef FEATURE_SEQUENCER 80 | #define sequencer_1_pin 0 81 | #define sequencer_2_pin 0 82 | #define sequencer_3_pin 0 83 | #define sequencer_4_pin 0 84 | #define sequencer_5_pin 0 85 | #endif //FEATURE_SEQUENCER 86 | 87 | #define ptt_input_pin 0 88 | 89 | #define tx_inhibit_pin 0 90 | #define tx_pause_pin 0 91 | 92 | #define pin_sending_mode_automatic 0 // goes HIGH when keyer is sending code automatically 93 | #define pin_sending_mode_manual 0 // goes HIGH when keyer is sending code manually (i.e. the paddle or straight key) 94 | 95 | #else 96 | 97 | #error "Multiple pin_settings.h files included somehow..." 98 | 99 | #endif //keyer_pin_settings_h -------------------------------------------------------------------------------- /k3ng_keyer/keyer_pin_settings_nanokeyer_rev_d.h: -------------------------------------------------------------------------------- 1 | #ifndef keyer_pin_settings_h 2 | #define keyer_pin_settings_h 3 | 4 | #define paddle_left 2 5 | #define paddle_right 5 6 | #define tx_key_line_1 11 // (high = key down/tx on) 7 | #define tx_key_line_2 0 // nanoKeyer PTT port (Pin 13) may be used as 2nd keying line for SO2R 8 | #define tx_key_line_3 0 9 | #define tx_key_line_4 0 10 | #define tx_key_line_5 0 11 | #define tx_key_line_6 0 12 | #define sidetone_line 4 // connect a speaker for sidetone 13 | #define potentiometer A0 // Rev D nanoKeyer 14 | #define ptt_tx_1 13 // nanoKeyer PTT port (uncomment if using above as 2nd CW port for SO2R operation) 15 | #define ptt_tx_2 0 // Can be used for keying fox transmitter, T/R switch, or keying slow boatanchors 16 | #define ptt_tx_3 0 // These are optional - set to 0 if unused 17 | #define ptt_tx_4 0 18 | #define ptt_tx_5 0 19 | #define ptt_tx_6 0 20 | #define analog_buttons_pin A1 // Rev D nanokeyer 21 | #define lcd_rs A2 22 | #define lcd_enable 10 23 | #define lcd_d4 6 24 | #define lcd_d5 7 25 | #define lcd_d6 8 26 | #define lcd_d7 9 27 | #define ps2_keyboard_data A3 // Rev D nanokeyer 28 | #define ps2_keyboard_clock 3 29 | #define tx_key_dit 0 // if defined, goes active for dit (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 30 | #define tx_key_dah 0 // if defined, goes active for dah (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 31 | 32 | #define potentiometer_enable_pin 0 // if defined, the potentiometer will be enabled only when this pin is held low; set to 0 to ignore this pin 33 | 34 | #if defined(FEATURE_SLEEP) 35 | #define keyer_awake 13 // Goes active when keyer is awake, inactive when in sleep mode; change active and inactive states in keyer_settings file 36 | #endif 37 | 38 | #if defined(FEATURE_LCD_BACKLIGHT_AUTO_DIM) 39 | #define keyer_power_led 0 // must be a PWM-capable pin 40 | #endif 41 | 42 | #if defined(FEATURE_CAPACITIVE_PADDLE_PINS) 43 | #define capactive_paddle_pin_inhibit_pin 0 // if this pin is defined and is set high, the capacitive paddle pins will switch to normal (non-capacitive) sensing mode 44 | #endif 45 | 46 | /* 47 | FEATURE_SIDETONE_SWITCH 48 | Enabling this feature and an external toggle switch adds switch control for playing cw sidetone. 49 | ST Switch status is displayed in the status command. This feature will override the software control of the sidetone (\o). 50 | Arduino pin is assigned by SIDETONE_SWITCH 51 | */ 52 | 53 | #ifdef FEATURE_SIDETONE_SWITCH 54 | #define SIDETONE_SWITCH 8 55 | #endif //FEATURE_SIDETONE_SWITCH 56 | 57 | #ifdef FEATURE_SEQUENCER 58 | #define sequencer_1_pin 0 59 | #define sequencer_2_pin 0 60 | #define sequencer_3_pin 0 61 | #define sequencer_4_pin 0 62 | #define sequencer_5_pin 0 63 | #endif //FEATURE_SEQUENCER 64 | 65 | #define ptt_input_pin 0 66 | 67 | #define tx_inhibit_pin 0 68 | #define tx_pause_pin 0 69 | 70 | #define pin_sending_mode_automatic 0 // goes HIGH when keyer is sending code automatically 71 | #define pin_sending_mode_manual 0 // goes HIGH when keyer is sending code manually (i.e. the paddle or straight key) 72 | 73 | #else 74 | 75 | #error "Multiple pin_settings.h files included somehow..." 76 | 77 | #endif //keyer_pin_settings_h 78 | -------------------------------------------------------------------------------- /k3ng_keyer/keyer_pin_settings_tinykeyer.h: -------------------------------------------------------------------------------- 1 | // features & options for TinyKeyer by OK1RR 2 | #ifndef keyer_pin_settings_h 3 | #define keyer_pin_settings_h 4 | 5 | #define paddle_left 2 // dit 6 | #define paddle_right 5 // dah 7 | #define tx_key_line_1 12 // tinykeyer keyed port (high = key down/tx on) 8 | #define tx_key_line_2 0 9 | #define tx_key_line_3 0 10 | #define tx_key_line_4 0 11 | #define tx_key_line_5 0 12 | #define tx_key_line_6 0 13 | #define sidetone_line 4 // connect a speaker for sidetone 14 | #define potentiometer 0 // tinykeyer no pot used 15 | #define ptt_tx_1 0 // (put 13 instead 0 to activate) tinykeyer PTT port (high = PTT down/PTT on) 16 | #define ptt_tx_2 0 // Can be used for keying fox transmitter, T/R switch, or keying slow boatanchors 17 | #define ptt_tx_3 0 // These are optional - set to 0 if unused 18 | #define ptt_tx_4 0 19 | #define ptt_tx_5 0 20 | #define ptt_tx_6 0 21 | #define analog_buttons_pin A1 // tinykeyer 22 | #define command_mode_active_led 9 // tinykeyer - command mode LED indicator 23 | #define tx_key_dit 0 // if defined, goes active for dit (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 24 | #define tx_key_dah 0 // if defined, goes active for dah (any transmitter) - customized with tx_key_dit_and_dah_pins_active_state and tx_key_dit_and_dah_pins_inactive_state 25 | 26 | #define potentiometer_enable_pin 0 // if defined, the potentiometer will be enabled only when this pin is held low; set to 0 to ignore this pin 27 | 28 | // rotary encoder pins and options - rotary encoder code from Jim Balls M0CKE 29 | #ifdef FEATURE_ROTARY_ENCODER 30 | #define OPTION_ENCODER_HALF_STEP_MODE // Half-step mode? 31 | #define rotary_pin1 11 // CW Encoder Pin 32 | #define rotary_pin2 10 // CCW Encoder Pin 33 | #define OPTION_ENCODER_ENABLE_PULLUPS // define to enable weak pullups. 34 | #endif //FEATURE_ROTARY_ENCODER 35 | 36 | #if defined(FEATURE_SLEEP) 37 | #define keyer_awake 8 // Goes active when keyer is awake, inactive when in sleep mode; change active and inactive states in keyer_settings file 38 | #endif 39 | 40 | #if defined(FEATURE_LCD_BACKLIGHT_AUTO_DIM) 41 | #define keyer_power_led 0 // must be a PWM-capable pin 42 | #endif 43 | 44 | /* 45 | FEATURE_SIDETONE_SWITCH 46 | Enabling this feature and an external toggle switch adds switch control for playing cw sidetone. 47 | ST Switch status is displayed in the status command. This feature will override the software control of the sidetone (\o). 48 | Arduino pin is assigned by SIDETONE_SWITCH 49 | */ 50 | 51 | #ifdef FEATURE_SIDETONE_SWITCH 52 | #define SIDETONE_SWITCH 8 53 | #endif //FEATURE_SIDETONE_SWITCH 54 | 55 | #ifdef FEATURE_4x4_KEYPAD 56 | #define Row3 33 57 | #define Row2 32 58 | #define Row1 31 59 | #define Row0 30 60 | #define Col3 37 61 | #define Col2 36 62 | #define Col1 35 63 | #define Col0 34 64 | #endif 65 | 66 | #ifdef FEATURE_3x4_KEYPAD 67 | #define Row3 33 68 | #define Row2 32 69 | #define Row1 31 70 | #define Row0 30 71 | #define Col2 36 72 | #define Col1 35 73 | #define Col0 34 74 | #endif 75 | 76 | 77 | #ifdef FEATURE_SEQUENCER 78 | #define sequencer_1_pin 0 79 | #define sequencer_2_pin 0 80 | #define sequencer_3_pin 0 81 | #define sequencer_4_pin 0 82 | #define sequencer_5_pin 0 83 | #endif //FEATURE_SEQUENCER 84 | 85 | #define ptt_input_pin 0 86 | 87 | #define tx_inhibit_pin 0 88 | #define tx_pause_pin 0 89 | 90 | #define pin_sending_mode_automatic 0 // goes HIGH when keyer is sending code automatically 91 | #define pin_sending_mode_manual 0 // goes HIGH when keyer is sending code manually (i.e. the paddle or straight key) 92 | 93 | #else 94 | 95 | #error "Multiple pin_settings.h files included somehow..." 96 | 97 | #endif //keyer_pin_settings_h 98 | -------------------------------------------------------------------------------- /k3ng_keyer/keyer_stm32duino.h: -------------------------------------------------------------------------------- 1 | /* keyer_stm32fduino.h 2 | 3 | 4 | Use this file to enables clean compilation using the STM32duino board support for STM32 ARM 5 | processors. This requires the installation of https://github.com/rogerclarkmelbourne/Arduino_STM32 6 | 7 | For more information about STM32duino visit the primary support forum: http://www.stm32duino.com/ 8 | 9 | */ 10 | 11 | void initialize_pins(void); 12 | void initialize_keyer_state(void); 13 | void initialize_potentiometer(void); 14 | void initialize_rotary_encoder(void); 15 | void initialize_default_modes(void); 16 | void initialize_watchdog(void); 17 | void initialize_ethernet_variables(void); 18 | void check_eeprom_for_initialization(void); 19 | void check_for_beacon_mode(void); 20 | void check_for_debug_modes(void); 21 | void initialize_analog_button_array(void); 22 | void initialize_serial_ports(void); 23 | void initialize_ps2_keyboard(void); 24 | void initialize_usb(void); 25 | void initialize_cw_keyboard(void); 26 | void initialize_display(void); 27 | void initialize_ethernet(void); 28 | void initialize_udp(void); 29 | void initialize_web_server(void); 30 | void initialize_debug_startup(void); 31 | 32 | void check_paddles(void); 33 | void service_dit_dah_buffers(void); 34 | void service_send_buffer(byte); 35 | void check_ptt_tail(void); 36 | void check_for_dirty_configuration(void); 37 | void tone(uint32_t, uint32_t, uint32_t); 38 | void noTone(uint32_t); 39 | void serial_status(PRIMARY_SERIAL_CLS*); 40 | -------------------------------------------------------------------------------- /k3ng_keyer/src/buttonarray/buttonarray.h: -------------------------------------------------------------------------------- 1 | #ifndef buttonarray_h 2 | #define buttonarray_h 3 | #include "Arduino.h" 4 | #ifndef MAX_ARRAY_BUTTONS 5 | #define MAX_ARRAY_BUTTONS 13 6 | #endif 7 | #define DEBOUNCE_MS 200 8 | #define NUMBER_OF_BUTTON_READS_TO_AVERAGE 19 9 | 10 | #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_GENERIC_STM32F103C) 11 | #define max_value 4095 12 | #else 13 | #define max_value 1023 14 | #endif 15 | 16 | #define r1_value 10 17 | #define r2_value 1 18 | 19 | /* contributed by W6IPA */ 20 | 21 | class Button { 22 | private: 23 | int32_t low_limit_; 24 | int32_t high_limit_; 25 | uint8_t step_; 26 | public: 27 | Button(){}; 28 | void InitLimits(uint8_t step); 29 | void InitLimits(uint8_t step, int32_t low_limit, int32_t high_limit); 30 | bool Pressed(int32_t analog_reading); 31 | int32_t high_limit(); 32 | int32_t low_limit(); 33 | }; 34 | 35 | class ButtonArray { 36 | private: 37 | Button button_array_[MAX_ARRAY_BUTTONS]; 38 | uint8_t pin_; 39 | uint8_t nb_buttons_; 40 | int32_t high_limit_; 41 | bool reversed_; 42 | int8_t ReadButtons(); 43 | bool AnyPressed(); 44 | 45 | public: 46 | uint32_t last_pressed_ms; 47 | ButtonArray(uint8_t pin, uint8_t nb, bool reversed): pin_(pin), nb_buttons_(nb), reversed_(reversed){}; 48 | void AddAll(); 49 | void Add(uint8_t step, uint8_t index); 50 | void Add(uint8_t step, uint8_t index, int32_t low_limit, int32_t high_limit); 51 | int32_t high_limit(); 52 | int8_t Pressed(); 53 | bool Pressed(uint8_t index); 54 | bool Held(uint8_t index); 55 | bool Held(uint8_t index, uint32_t deadline ); 56 | }; 57 | 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /k3ng_keyer/src/buttonarray/buttonarray.ino: -------------------------------------------------------------------------------- 1 | // Button Array test 2 | 3 | #include "buttonarray.h" 4 | 5 | #define ARRAY_PIN A3 6 | #define NB_BUTTONS 2 7 | #define ENCODER_PIN A1 8 | 9 | 10 | int button_array_high_limit[NB_BUTTONS]; 11 | int button_array_low_limit[NB_BUTTONS]; 12 | long button_depress_time; 13 | 14 | 15 | 16 | ButtonArray button_array(ARRAY_PIN, NB_BUTTONS, false); 17 | ButtonArray encoder(ENCODER_PIN, 1, false); 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | delay(1000); 22 | button_array.AddAll(); 23 | encoder.AddAll(); 24 | } 25 | 26 | void loop() { 27 | 28 | int analogbuttontemp = button_array.Pressed(); 29 | if (encoder.Pressed() == 0) { 30 | Serial.println("encoder pressed "); 31 | } 32 | if (analogbuttontemp >= 0 ) { 33 | // button pressed. 34 | 35 | button_depress_time = button_array.last_pressed_ms; 36 | 37 | while (button_array.Held(analogbuttontemp, button_depress_time + 1000)) { 38 | 39 | } 40 | if (millis() - button_depress_time < 400) { 41 | Serial.print("button pressed "); 42 | Serial.println(analogbuttontemp); 43 | } else { 44 | Serial.print("button "); 45 | Serial.print(analogbuttontemp); 46 | Serial.print(" held for "); 47 | Serial.println(millis() - button_depress_time); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/Adafruit_LiquidCrystal.h: -------------------------------------------------------------------------------- 1 | #ifndef Adafruit_LiquidCrystal_h 2 | #define Adafruit_LiquidCrystal_h 3 | 4 | #include "Arduino.h" 5 | #include 6 | #include "Print.h" 7 | #include "utility/Adafruit_MCP23008.h" 8 | 9 | // commands 10 | #define LCD_CLEARDISPLAY 0x01 11 | #define LCD_RETURNHOME 0x02 12 | #define LCD_ENTRYMODESET 0x04 13 | #define LCD_DISPLAYCONTROL 0x08 14 | #define LCD_CURSORSHIFT 0x10 15 | #define LCD_FUNCTIONSET 0x20 16 | #define LCD_SETCGRAMADDR 0x40 17 | #define LCD_SETDDRAMADDR 0x80 18 | 19 | // flags for display entry mode 20 | #define LCD_ENTRYRIGHT 0x00 21 | #define LCD_ENTRYLEFT 0x02 22 | #define LCD_ENTRYSHIFTINCREMENT 0x01 23 | #define LCD_ENTRYSHIFTDECREMENT 0x00 24 | 25 | // flags for display on/off control 26 | #define LCD_DISPLAYON 0x04 27 | #define LCD_DISPLAYOFF 0x00 28 | #define LCD_CURSORON 0x02 29 | #define LCD_CURSOROFF 0x00 30 | #define LCD_BLINKON 0x01 31 | #define LCD_BLINKOFF 0x00 32 | 33 | // flags for display/cursor shift 34 | #define LCD_DISPLAYMOVE 0x08 35 | #define LCD_CURSORMOVE 0x00 36 | #define LCD_MOVERIGHT 0x04 37 | #define LCD_MOVELEFT 0x00 38 | 39 | // flags for function set 40 | #define LCD_8BITMODE 0x10 41 | #define LCD_4BITMODE 0x00 42 | #define LCD_2LINE 0x08 43 | #define LCD_1LINE 0x00 44 | #define LCD_5x10DOTS 0x04 45 | #define LCD_5x8DOTS 0x00 46 | 47 | class Adafruit_LiquidCrystal : public Print { 48 | public: 49 | Adafruit_LiquidCrystal(uint8_t rs, uint8_t enable, 50 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 51 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 52 | Adafruit_LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 53 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 54 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 55 | Adafruit_LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 56 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 57 | Adafruit_LiquidCrystal(uint8_t rs, uint8_t enable, 58 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 59 | 60 | Adafruit_LiquidCrystal(uint8_t i2cAddr); 61 | Adafruit_LiquidCrystal(uint8_t data, uint8_t clock, uint8_t latch); 62 | 63 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 64 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 65 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 66 | 67 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 68 | 69 | void clear(); 70 | void home(); 71 | 72 | void noDisplay(); 73 | void display(); 74 | void noBlink(); 75 | void blink(); 76 | void noCursor(); 77 | void cursor(); 78 | void scrollDisplayLeft(); 79 | void scrollDisplayRight(); 80 | void leftToRight(); 81 | void rightToLeft(); 82 | void autoscroll(); 83 | void noAutoscroll(); 84 | 85 | // only if using backpack 86 | void setBacklight(uint8_t status); 87 | 88 | void createChar(uint8_t, uint8_t[]); 89 | void setCursor(uint8_t, uint8_t); 90 | #if ARDUINO >= 100 91 | virtual size_t write(uint8_t); 92 | #else 93 | virtual void write(uint8_t); 94 | #endif 95 | void command(uint8_t); 96 | private: 97 | void send(uint8_t value, boolean mode); 98 | void write4bits(uint8_t); 99 | void write8bits(uint8_t); 100 | void pulseEnable(); 101 | void _digitalWrite(uint8_t, uint8_t); 102 | void _pinMode(uint8_t, uint8_t); 103 | 104 | uint8_t _rs_pin; // LOW: command. HIGH: character. 105 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 106 | uint8_t _enable_pin; // activated by a HIGH pulse. 107 | uint8_t _data_pins[8]; 108 | 109 | uint8_t _displayfunction; 110 | uint8_t _displaycontrol; 111 | uint8_t _displaymode; 112 | 113 | uint8_t _initialized; 114 | 115 | uint8_t _numlines,_currline; 116 | 117 | uint8_t _SPIclock, _SPIdata, _SPIlatch; 118 | uint8_t _SPIbuff; 119 | 120 | uint8_t _i2cAddr; 121 | Adafruit_MCP23008 _i2c; 122 | }; 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/README.md: -------------------------------------------------------------------------------- 1 | # Adafruit_LiquidCrystal 2 | 3 | This library has been renamed Adafruit_LiquidCrystal so as not to conflict with LiquidCrystal. Also, it now works with tiny85's if you have Adafruit AVR board pkg 1.4.3+ 4 | 5 | 6 | 7 | ## Compatibility 8 | 9 | MCU | Tested Works | Doesn't Work | Not Tested | Notes 10 | ----------------- | :----------: | :----------: | :---------: | ----- 11 | Atmega328 @ 16MHz | X | | | 12 | Atmega328 @ 12MHz | X | | | For SPI, Pro Trinket has no pin 2, can move to pin 5. 13 | Atmega32u4 @ 16MHz | X | | | 14 | Atmega32u4 @ 8MHz | X | | | 15 | ESP8266 | X | | | For SPI, ESP8266 has no pin 3, moved to pin 5. 16 | Atmega2560 @ 16MHz | X | | | 17 | ATSAM3X8E | X | | | 18 | ATSAM21D | | X | | I2C works, use SDA and SCL pins. For SPI, LCD blinks once on start up. 19 | ATtiny85 @ 16MHz | | X | | Use TinyLiquidCrystal libray instead: https://github.com/adafruit/TinyLiquidCrystal 20 | 21 | I2C uses SDA & SCL pins 0 & 2 22 | ATtiny85 @ 8MHz | | X | | Use TinyLiquidCrystal libray instead: https://github.com/adafruit/TinyLiquidCrystal 23 | 24 | I2C uses SDA & SCL pins 0 & 2 25 | 26 | * ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini 27 | * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V 28 | * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 29 | * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro 30 | * ESP8266 : Adafruit Huzzah 31 | * ATmega2560 @ 16MHz : Arduino Mega 32 | * ATSAM3X8E : Arduino Due 33 | * ATSAM21D : Arduino Zero, M0 Pro 34 | * ATtiny85 @ 16MHz : Adafruit Trinket 5V 35 | * ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V 36 | 37 | 38 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For LiquidCrystal 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Adafruit_LiquidCrystal KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | clear KEYWORD2 17 | home KEYWORD2 18 | print KEYWORD2 19 | setCursor KEYWORD2 20 | cursor KEYWORD2 21 | noCursor KEYWORD2 22 | blink KEYWORD2 23 | noBlink KEYWORD2 24 | display KEYWORD2 25 | noDisplay KEYWORD2 26 | autoscroll KEYWORD2 27 | noAutoscroll KEYWORD2 28 | leftToRight KEYWORD2 29 | rightToLeft KEYWORD2 30 | scrollDisplayLeft KEYWORD2 31 | scrollDisplayRight KEYWORD2 32 | createChar KEYWORD2 33 | setBacklight KEYWORD2 34 | 35 | ####################################### 36 | # Constants (LITERAL1) 37 | ####################################### 38 | 39 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit LiquidCrystal 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Fork of LiquidCrystal HD44780-compatible LCD driver library, now with support for ATtiny85. 6 | paragraph=Fork of LiquidCrystal HD44780-compatible LCD driver library, now with support for ATtiny85. 7 | category=Display 8 | url=https://github.com/adafruit/LiquidCrystal/ 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/utility/Adafruit_MCP23008.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the MCP23008 i2c port expander 3 | 4 | These displays use I2C to communicate, 2 pins are required to 5 | interface 6 | Adafruit invests time and resources providing this open source code, 7 | please support Adafruit and open-source hardware by purchasing 8 | products from Adafruit! 9 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | #if ARDUINO >= 100 15 | #include "Arduino.h" 16 | #else 17 | #include "WProgram.h" 18 | #endif 19 | #include 20 | #include "Adafruit_MCP23008.h" 21 | 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | // RTC_DS1307 implementation 25 | 26 | void Adafruit_MCP23008::begin(uint8_t addr) { 27 | addr &= 7; 28 | 29 | i2caddr = addr; 30 | 31 | Wire.begin(); 32 | 33 | // set defaults! 34 | Wire.beginTransmission(MCP23008_ADDRESS | i2caddr); 35 | #if ARDUINO >= 100 36 | Wire.write((byte)MCP23008_IODIR); 37 | Wire.write((byte)0xFF); // all inputs 38 | Wire.write((byte)0x00); 39 | Wire.write((byte)0x00); 40 | Wire.write((byte)0x00); 41 | Wire.write((byte)0x00); 42 | Wire.write((byte)0x00); 43 | Wire.write((byte)0x00); 44 | Wire.write((byte)0x00); 45 | Wire.write((byte)0x00); 46 | Wire.write((byte)0x00); 47 | #else 48 | Wire.send(MCP23008_IODIR); 49 | Wire.send(0xFF); // all inputs 50 | Wire.send(0x00); 51 | Wire.send(0x00); 52 | Wire.send(0x00); 53 | Wire.send(0x00); 54 | Wire.send(0x00); 55 | Wire.send(0x00); 56 | Wire.send(0x00); 57 | Wire.send(0x00); 58 | Wire.send(0x00); 59 | #endif 60 | Wire.endTransmission(); 61 | 62 | } 63 | 64 | void Adafruit_MCP23008::begin(void) { 65 | begin(0); 66 | } 67 | 68 | void Adafruit_MCP23008::pinMode(uint8_t p, uint8_t d) { 69 | uint8_t iodir; 70 | 71 | 72 | // only 8 bits! 73 | if (p > 7) 74 | return; 75 | 76 | iodir = read8(MCP23008_IODIR); 77 | 78 | // set the pin and direction 79 | if (d == INPUT) { 80 | iodir |= 1 << p; 81 | } else { 82 | iodir &= ~(1 << p); 83 | } 84 | 85 | // write the new IODIR 86 | write8(MCP23008_IODIR, iodir); 87 | } 88 | 89 | uint8_t Adafruit_MCP23008::readGPIO(void) { 90 | // read the current GPIO input 91 | return read8(MCP23008_GPIO); 92 | } 93 | 94 | void Adafruit_MCP23008::writeGPIO(uint8_t gpio) { 95 | write8(MCP23008_GPIO, gpio); 96 | } 97 | 98 | 99 | void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) { 100 | uint8_t gpio; 101 | 102 | // only 8 bits! 103 | if (p > 7) 104 | return; 105 | 106 | // read the current GPIO output latches 107 | gpio = readGPIO(); 108 | 109 | // set the pin and direction 110 | if (d == HIGH) { 111 | gpio |= 1 << p; 112 | } else { 113 | gpio &= ~(1 << p); 114 | } 115 | 116 | // write the new GPIO 117 | writeGPIO(gpio); 118 | } 119 | 120 | void Adafruit_MCP23008::pullUp(uint8_t p, uint8_t d) { 121 | uint8_t gppu; 122 | 123 | // only 8 bits! 124 | if (p > 7) 125 | return; 126 | 127 | gppu = read8(MCP23008_GPPU); 128 | // set the pin and direction 129 | if (d == HIGH) { 130 | gppu |= 1 << p; 131 | } else { 132 | gppu &= ~(1 << p); 133 | } 134 | // write the new GPIO 135 | write8(MCP23008_GPPU, gppu); 136 | } 137 | 138 | uint8_t Adafruit_MCP23008::digitalRead(uint8_t p) { 139 | // only 8 bits! 140 | if (p > 7) 141 | return 0; 142 | 143 | // read the current GPIO 144 | return (readGPIO() >> p) & 0x1; 145 | } 146 | 147 | uint8_t Adafruit_MCP23008::read8(uint8_t addr) { 148 | Wire.beginTransmission(MCP23008_ADDRESS | i2caddr); 149 | #if ARDUINO >= 100 150 | Wire.write((byte)addr); 151 | #else 152 | Wire.send(addr); 153 | #endif 154 | Wire.endTransmission(); 155 | Wire.requestFrom(MCP23008_ADDRESS | i2caddr, 1); 156 | 157 | #if ARDUINO >= 100 158 | return Wire.read(); 159 | #else 160 | return Wire.receive(); 161 | #endif 162 | } 163 | 164 | 165 | void Adafruit_MCP23008::write8(uint8_t addr, uint8_t data) { 166 | Wire.beginTransmission(MCP23008_ADDRESS | i2caddr); 167 | #if ARDUINO >= 100 168 | Wire.write((byte)addr); 169 | Wire.write((byte)data); 170 | #else 171 | Wire.send(addr); 172 | Wire.send(data); 173 | #endif 174 | Wire.endTransmission(); 175 | } 176 | -------------------------------------------------------------------------------- /libraries/Adafruit_LiquidCrystal/utility/Adafruit_MCP23008.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the MCP23008 i2c port expander 3 | 4 | These displays use I2C to communicate, 2 pins are required to 5 | interface 6 | Adafruit invests time and resources providing this open source code, 7 | please support Adafruit and open-source hardware by purchasing 8 | products from Adafruit! 9 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | #ifndef _ADAFRUIT_MCP23008_H 15 | #define _ADAFRUIT_MCP23008_H 16 | // Don't forget the Wire library 17 | class Adafruit_MCP23008 { 18 | public: 19 | void begin(uint8_t addr); 20 | void begin(void); 21 | 22 | void pinMode(uint8_t p, uint8_t d); 23 | void digitalWrite(uint8_t p, uint8_t d); 24 | void pullUp(uint8_t p, uint8_t d); 25 | uint8_t digitalRead(uint8_t p); 26 | uint8_t readGPIO(void); 27 | void writeGPIO(uint8_t); 28 | 29 | private: 30 | uint8_t i2caddr; 31 | uint8_t read8(uint8_t addr); 32 | void write8(uint8_t addr, uint8_t data); 33 | }; 34 | 35 | #define MCP23008_ADDRESS 0x20 36 | 37 | // registers 38 | #define MCP23008_IODIR 0x00 39 | #define MCP23008_IPOL 0x01 40 | #define MCP23008_GPINTEN 0x02 41 | #define MCP23008_DEFVAL 0x03 42 | #define MCP23008_INTCON 0x04 43 | #define MCP23008_IOCON 0x05 44 | #define MCP23008_GPPU 0x06 45 | #define MCP23008_INTF 0x07 46 | #define MCP23008_INTCAP 0x08 47 | #define MCP23008_GPIO 0x09 48 | #define MCP23008_OLAT 0x0A 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libraries/Adafruit_MCP23017/Adafruit_MCP23017.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the MCP23017 i2c port expander 3 | 4 | These displays use I2C to communicate, 2 pins are required to 5 | interface 6 | Adafruit invests time and resources providing this open source code, 7 | please support Adafruit and open-source hardware by purchasing 8 | products from Adafruit! 9 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | #ifndef _Adafruit_MCP23017_H_ 15 | #define _Adafruit_MCP23017_H_ 16 | 17 | // Don't forget the Wire library 18 | class Adafruit_MCP23017 { 19 | public: 20 | void begin(uint8_t addr); 21 | void begin(void); 22 | 23 | void pinMode(uint8_t p, uint8_t d); 24 | void digitalWrite(uint8_t p, uint8_t d); 25 | void pullUp(uint8_t p, uint8_t d); 26 | uint8_t digitalRead(uint8_t p); 27 | 28 | void writeGPIOAB(uint16_t); 29 | uint16_t readGPIOAB(); 30 | 31 | private: 32 | uint8_t i2caddr; 33 | }; 34 | 35 | #define MCP23017_ADDRESS 0x20 36 | 37 | // registers 38 | #define MCP23017_IODIRA 0x00 39 | #define MCP23017_IPOLA 0x02 40 | #define MCP23017_GPINTENA 0x04 41 | #define MCP23017_DEFVALA 0x06 42 | #define MCP23017_INTCONA 0x08 43 | #define MCP23017_IOCONA 0x0A 44 | #define MCP23017_GPPUA 0x0C 45 | #define MCP23017_INTFA 0x0E 46 | #define MCP23017_INTCAPA 0x10 47 | #define MCP23017_GPIOA 0x12 48 | #define MCP23017_OLATA 0x14 49 | 50 | 51 | #define MCP23017_IODIRB 0x01 52 | #define MCP23017_IPOLB 0x03 53 | #define MCP23017_GPINTENB 0x05 54 | #define MCP23017_DEFVALB 0x07 55 | #define MCP23017_INTCONB 0x09 56 | #define MCP23017_IOCONB 0x0B 57 | #define MCP23017_GPPUB 0x0D 58 | #define MCP23017_INTFB 0x0F 59 | #define MCP23017_INTCAPB 0x11 60 | #define MCP23017_GPIOB 0x13 61 | #define MCP23017_OLATB 0x15 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /libraries/Adafruit_RGBLCDShield/Adafruit_RGBLCDShield.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit RGB 16x2 LCD Shield 3 | Pick one up at the Adafruit shop! 4 | ---------> http://http://www.adafruit.com/products/714 5 | 6 | The shield uses I2C to communicate, 2 pins are required to 7 | interface 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | BSD license, all text above must be included in any redistribution 14 | ****************************************************/ 15 | 16 | #ifndef Adafruit_RGBLCDShield_h 17 | #define Adafruit_RGBLCDShield_h 18 | 19 | #include 20 | #include "Print.h" 21 | #include 22 | 23 | // commands 24 | #define LCD_CLEARDISPLAY 0x01 25 | #define LCD_RETURNHOME 0x02 26 | #define LCD_ENTRYMODESET 0x04 27 | #define LCD_DISPLAYCONTROL 0x08 28 | #define LCD_CURSORSHIFT 0x10 29 | #define LCD_FUNCTIONSET 0x20 30 | #define LCD_SETCGRAMADDR 0x40 31 | #define LCD_SETDDRAMADDR 0x80 32 | 33 | // flags for display entry mode 34 | #define LCD_ENTRYRIGHT 0x00 35 | #define LCD_ENTRYLEFT 0x02 36 | #define LCD_ENTRYSHIFTINCREMENT 0x01 37 | #define LCD_ENTRYSHIFTDECREMENT 0x00 38 | 39 | // flags for display on/off control 40 | #define LCD_DISPLAYON 0x04 41 | #define LCD_DISPLAYOFF 0x00 42 | #define LCD_CURSORON 0x02 43 | #define LCD_CURSOROFF 0x00 44 | #define LCD_BLINKON 0x01 45 | #define LCD_BLINKOFF 0x00 46 | 47 | // flags for display/cursor shift 48 | #define LCD_DISPLAYMOVE 0x08 49 | #define LCD_CURSORMOVE 0x00 50 | #define LCD_MOVERIGHT 0x04 51 | #define LCD_MOVELEFT 0x00 52 | 53 | // flags for function set 54 | #define LCD_8BITMODE 0x10 55 | #define LCD_4BITMODE 0x00 56 | #define LCD_2LINE 0x08 57 | #define LCD_1LINE 0x00 58 | #define LCD_5x10DOTS 0x04 59 | #define LCD_5x8DOTS 0x00 60 | 61 | #define BUTTON_UP 0x08 62 | #define BUTTON_DOWN 0x04 63 | #define BUTTON_LEFT 0x10 64 | #define BUTTON_RIGHT 0x02 65 | #define BUTTON_SELECT 0x01 66 | 67 | 68 | class Adafruit_RGBLCDShield : public Print { 69 | public: 70 | Adafruit_RGBLCDShield(); 71 | 72 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 73 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 74 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 75 | 76 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 77 | 78 | void clear(); 79 | void home(); 80 | 81 | void noDisplay(); 82 | void display(); 83 | void noBlink(); 84 | void blink(); 85 | void noCursor(); 86 | void cursor(); 87 | void scrollDisplayLeft(); 88 | void scrollDisplayRight(); 89 | void leftToRight(); 90 | void rightToLeft(); 91 | void autoscroll(); 92 | void noAutoscroll(); 93 | 94 | // only if using backpack 95 | void setBacklight(uint8_t status); 96 | 97 | void createChar(uint8_t, uint8_t[]); 98 | void setCursor(uint8_t, uint8_t); 99 | #if ARDUINO >= 100 100 | virtual size_t write(uint8_t); 101 | #else 102 | virtual void write(uint8_t); 103 | #endif 104 | void command(uint8_t); 105 | uint8_t readButtons(); 106 | 107 | private: 108 | void send(uint8_t, uint8_t); 109 | void write4bits(uint8_t); 110 | void write8bits(uint8_t); 111 | void pulseEnable(); 112 | void _digitalWrite(uint8_t, uint8_t); 113 | void _pinMode(uint8_t, uint8_t); 114 | 115 | uint8_t _rs_pin; // LOW: command. HIGH: character. 116 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 117 | uint8_t _enable_pin; // activated by a HIGH pulse. 118 | uint8_t _data_pins[8]; 119 | uint8_t _button_pins[5]; 120 | uint8_t _displayfunction; 121 | uint8_t _displaycontrol; 122 | uint8_t _displaymode; 123 | 124 | uint8_t _initialized; 125 | 126 | uint8_t _numlines,_currline; 127 | 128 | uint8_t _i2cAddr; 129 | Adafruit_MCP23017 _i2c; 130 | }; 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /libraries/BasicTerm/BasicTerm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicTerm.cpp 3 | * Provides basic ANSI/VT220 terminal control over a serial interface 4 | * Copyright 2011 Trannie Carter 5 | * Licensed for use under the terms of the GNU Lesser General Public License v3 6 | */ 7 | 8 | #include "BasicTerm.h" 9 | 10 | BasicTerm::BasicTerm(Stream *ser) { 11 | serial = ser; 12 | } 13 | 14 | int BasicTerm::available(void) { 15 | return serial->available(); 16 | } 17 | 18 | int BasicTerm::peek(void) { 19 | return serial->peek(); 20 | } 21 | 22 | int BasicTerm::read(void) { 23 | return serial->read(); 24 | } 25 | 26 | void BasicTerm::flush(void) { 27 | serial->flush(); 28 | } 29 | 30 | size_t BasicTerm::write(uint8_t c) { 31 | return serial->write(c); 32 | } 33 | 34 | void BasicTerm::init(void) { 35 | serial->print(F("\x1b\x63")); 36 | } 37 | 38 | void BasicTerm::cls(void) { 39 | serial->print(F("\x1b[2J")); 40 | } 41 | 42 | void BasicTerm::position(uint8_t row, uint8_t col) { 43 | serial->print(F("\x1b[")); 44 | serial->print((uint8_t)row + 1); 45 | serial->print(F(";")); 46 | serial->print((uint8_t)col + 1); 47 | serial->print(F("H")); 48 | } 49 | 50 | void BasicTerm::show_cursor(boolean show) { 51 | if(show) { 52 | serial->print(F("\x1b[?25h")); 53 | } else { 54 | serial->print(F("\x1b[?25l")); 55 | } 56 | } 57 | 58 | int16_t BasicTerm::get_key(void) { 59 | int16_t key; 60 | uint16_t when; 61 | 62 | key = serial->read(); 63 | 64 | if(key == 0x1b) { /* escape sequence */ 65 | when = millis(); 66 | while(serial->available() < 2) { 67 | if(((uint16_t) millis() - when) > 1000) { 68 | return key; 69 | } 70 | } 71 | 72 | key = serial->read(); 73 | 74 | switch(key) { 75 | case '[': 76 | key = serial->read(); 77 | switch(key) { 78 | case 'A': 79 | return BT_KEY_UP; 80 | case 'B': 81 | return BT_KEY_DOWN; 82 | case 'C': 83 | return BT_KEY_RIGHT; 84 | case 'D': 85 | return BT_KEY_LEFT; 86 | default: 87 | return key; 88 | } 89 | break; 90 | case 'O': 91 | key = serial->read(); 92 | switch(key) { 93 | case 'P': 94 | return BT_KEY_F(1); 95 | case 'Q': 96 | return BT_KEY_F(2); 97 | case 'R': 98 | return BT_KEY_F(3); 99 | case 'S': 100 | return BT_KEY_F(4); 101 | default: 102 | return key; 103 | } 104 | break; 105 | default: 106 | return key; 107 | } 108 | } 109 | 110 | return key; 111 | } 112 | 113 | void BasicTerm::set_attribute(uint8_t attr) { 114 | if(attr & BT_REVERSE) { 115 | serial->print(F("\x1b[7m")); 116 | } 117 | if(attr & BT_UNDERLINE) { 118 | serial->print(F("\x1b[4m")); 119 | } 120 | if(attr & BT_BOLD) { 121 | serial->print(F("\x1b[1m")); 122 | } 123 | if(attr & BT_BLINK) { 124 | serial->print(F("\x1b[5m")); 125 | } 126 | if(attr == BT_NORMAL) { 127 | serial->print(F("\x1b[0m")); 128 | } 129 | } 130 | 131 | void BasicTerm::set_color(uint8_t fg, uint8_t bg) { 132 | serial->print(F("\x1b[")); 133 | serial->print(30 + fg); 134 | serial->print(";"); 135 | serial->print(40 + bg); 136 | serial->print("m"); 137 | } 138 | -------------------------------------------------------------------------------- /libraries/BasicTerm/BasicTerm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicTerm.h 3 | * Provides basic ANSI/VT220 terminal control over a serial interface 4 | * Copyright 2011 Trannie Carter 5 | * Licensed for use under the terms of the GNU Lesser General Public License v3 6 | */ 7 | 8 | #ifndef BASICTERM_H 9 | #define BASICTERM_H 10 | 11 | #include 12 | 13 | class BasicTerm : public Stream { 14 | 15 | #define BT_NORMAL 0 16 | #define BT_BOLD 1 17 | #define BT_UNDERLINE 2 18 | #define BT_BLINK 4 19 | #define BT_REVERSE 8 20 | 21 | #define BT_BLACK 0 22 | #define BT_RED 1 23 | #define BT_GREEN 2 24 | #define BT_YELLOW 3 25 | #define BT_BLUE 4 26 | #define BT_MAGENTA 5 27 | #define BT_CYAN 6 28 | #define BT_WHITE 7 29 | 30 | #define BT_KEY_UNKNOWN 0401 31 | #define BT_KEY_DOWN 0402 32 | #define BT_KEY_UP 0403 33 | #define BT_KEY_LEFT 0404 34 | #define BT_KEY_RIGHT 0405 35 | #define BT_KEY_F0 0410 36 | #define BT_KEY_F(n) (BT_KEY_F0 + (n)) 37 | 38 | private: 39 | Stream *serial; 40 | 41 | public: 42 | BasicTerm(Stream *); 43 | void init(void); 44 | void cls(void); 45 | void position(uint8_t, uint8_t); 46 | void show_cursor(boolean); 47 | void set_attribute(uint8_t); 48 | void set_color(uint8_t, uint8_t); 49 | int16_t get_key(void); 50 | 51 | virtual int available(void); 52 | virtual int peek(void); 53 | virtual int read(void); 54 | virtual void flush(void); 55 | virtual size_t write(uint8_t); 56 | 57 | using Print::write; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libraries/E24C1024/E24C1024.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k3ng/k3ng_cw_keyer/8e501ebaa65828d388ee0b7ec450542eb9b95e67/libraries/E24C1024/E24C1024.cpp -------------------------------------------------------------------------------- /libraries/E24C1024/E24C1024.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/k3ng/k3ng_cw_keyer/8e501ebaa65828d388ee0b7ec450542eb9b95e67/libraries/E24C1024/E24C1024.h -------------------------------------------------------------------------------- /libraries/Goertzel/goertzel.cpp: -------------------------------------------------------------------------------- 1 | #include "goertzel.h" 2 | 3 | /* 4 | 5 | 6 | Goertzel formula audio detector 7 | 8 | This code comes from http://www.skovholm.com/cwdecoder , http://www.skovholm.com/decoder11.ino 9 | 10 | Hjalmar skovholm Hansen, Oz1jhm 11 | 12 | 13 | 14 | 15 | */ 16 | 17 | #if defined(ARDUINO) && ARDUINO >= 100 18 | #include "Arduino.h" 19 | #else 20 | #include "WProgram.h" 21 | #endif 22 | 23 | 24 | 25 | float coeff = 0; 26 | float Q1 = 0; 27 | float Q2 = 0; 28 | float sine = 0; 29 | float cosine = 0; 30 | //float sampling_freq = GOERTZ_SAMPLING_FREQ; 31 | //float target_freq = GOERTZ_TARGET_FREQ; 32 | //float n = GOERTZ_SAMPLES_FLOAT; 33 | int testData[GOERTZ_SAMPLES]; 34 | int audioInPin = 0; 35 | int realstate = LOW; 36 | int realstatebefore = LOW; 37 | int filteredstate = LOW; 38 | unsigned long laststarttime = 0; 39 | int magnitudelimit = 100; 40 | float magnitude = 0; 41 | 42 | ////////////////////////////// 43 | // Noise Blanker time which // 44 | // shall be computed so // 45 | // this is initial // 46 | ////////////////////////////// 47 | 48 | int nbtime = GOERTZ_NOISE_BLANKER_INITIAL_MS; 49 | 50 | 51 | Goertzdetector::Goertzdetector(){} 52 | 53 | 54 | void Goertzdetector::init(int _audioInPin){ 55 | // The basic goertzel calculation 56 | 57 | int k = 0; 58 | float omega = 0; 59 | //k = (int) (0.5 + ((n * target_freq) / sampling_freq)); 60 | k = (int) (0.5 + (((float)GOERTZ_SAMPLES * (float)GOERTZ_TARGET_FREQ) / (float)GOERTZ_SAMPLING_FREQ)); 61 | //omega = (2.0 * PI * k) / n; 62 | omega = (2.0 * PI * k) / (float) GOERTZ_SAMPLES; 63 | sine = sin(omega); 64 | cosine = cos(omega); 65 | coeff = 2.0 * cosine; 66 | 67 | audioInPin = _audioInPin; 68 | 69 | } 70 | 71 | int Goertzdetector::detecttone(){ 72 | 73 | 74 | // The basic where we get the tone 75 | 76 | 77 | for (char index = 0; index < GOERTZ_SAMPLES; index++){ 78 | testData[index] = analogRead(audioInPin); 79 | } 80 | 81 | for (char index = 0; index < GOERTZ_SAMPLES; index++){ 82 | float Q0; 83 | Q0 = coeff * Q1 - Q2 + (float) testData[index]; 84 | Q2 = Q1; 85 | Q1 = Q0; 86 | } 87 | 88 | float magnitudeSquared = (Q1*Q1)+(Q2*Q2)-Q1*Q2*coeff; // we do only need the real part // 89 | 90 | magnitude = sqrt(magnitudeSquared); 91 | 92 | Q2 = 0; 93 | Q1 = 0; 94 | 95 | 96 | /////////////////////////////////////////////////////////// 97 | // here we will try to set the magnitude limit automatic // 98 | /////////////////////////////////////////////////////////// 99 | 100 | 101 | if (magnitude > GOERTZ_MAGNITUDE_LIMIT_LOW){ 102 | magnitudelimit = (magnitudelimit + ((magnitude - magnitudelimit) / GOERTZ_MOVING_AVERAGE_FILTER)); /// moving average filter 103 | } else { 104 | magnitudelimit = GOERTZ_MAGNITUDE_LIMIT_LOW; 105 | } 106 | 107 | //////////////////////////////////// 108 | // now we check for the magnitude // 109 | //////////////////////////////////// 110 | 111 | if (magnitude > ((float) magnitudelimit * (float) GOERTZ_MAGNITUDE_THRESHOLD)){ 112 | realstate = HIGH; 113 | } else { 114 | realstate = LOW; 115 | } 116 | 117 | ///////////////////////////////////////////////////// 118 | // here we clean up the state with a noise blanker // 119 | ///////////////////////////////////////////////////// 120 | 121 | if (realstate != realstatebefore){ 122 | laststarttime = millis(); 123 | } 124 | 125 | if ((millis()-laststarttime) > nbtime){ 126 | if (realstate != filteredstate){ 127 | filteredstate = realstate; 128 | } 129 | } 130 | 131 | 132 | realstatebefore = realstate; 133 | 134 | return(filteredstate); 135 | 136 | } 137 | -------------------------------------------------------------------------------- /libraries/Goertzel/goertzel.h: -------------------------------------------------------------------------------- 1 | #ifndef GOERTZEL_H 2 | #define GOERTZEL_H 3 | 4 | 5 | /* 6 | 7 | 8 | Goertzel formula audio detector 9 | 10 | This code comes from http://www.skovholm.com/cwdecoder , http://www.skovholm.com/decoder11.ino 11 | 12 | Hjalmar skovholm Hansen, OZ1JHM 13 | 14 | 15 | Notes from the original code author, OZ1JHM (with edits from Goody K3NG) 16 | 17 | GOERTZ_SAMPLING_FREQ will be 8928 on a 16 mhz without any prescaler etc. 18 | because we need the tone in the center of the bins 19 | you can set GOERTZ_TARGET_FREQ (the tone) to 496, 558, 744 or 992 20 | then GOERTZ_SAMPLES_INT the number of samples which give the bandwidth 21 | which can be (8928 / GOERTZ_TARGET_FREQ) * 1 or 2 or 3 or 4 etc 22 | init is 8928/558 = 16 * 4 = 64 samples 23 | 24 | try to take GOERTZ_SAMPLES = 96 or 128 ;o) 25 | 26 | 48 will give you a bandwidth around 186 hz 27 | 64 will give you a bandwidth around 140 hz 28 | 96 will give you a bandwidth around 94 hz 29 | 128 will give you a bandwidth around 70 hz 30 | 31 | BUT remember that a high GOERTZ_SAMPLES will take a lot of time so you have to find a compromise 32 | 33 | */ 34 | 35 | #if defined(_VARIANT_ARDUINO_DUE_X_) 36 | // Arduino Due (84 Mhz clock) 37 | #define GOERTZ_SAMPLING_FREQ 46872.0 38 | #define GOERTZ_SAMPLES 252 //168 //84 39 | #else 40 | // Arduino Uno, Mega (16 Mhz clock) 41 | #define GOERTZ_SAMPLING_FREQ 8928.0 42 | #define GOERTZ_SAMPLES 48 //48 //64 43 | #endif 44 | 45 | #define GOERTZ_NOISE_BLANKER_INITIAL_MS 6 46 | #define GOERTZ_TARGET_FREQ 558.0 47 | 48 | 49 | 50 | #define GOERTZ_MAGNITUDE_LIMIT_LOW 100 51 | #define GOERTZ_MAGNITUDE_THRESHOLD 0.6 //0.6 52 | #define GOERTZ_MOVING_AVERAGE_FILTER 6 53 | 54 | 55 | class Goertzdetector { 56 | 57 | public: 58 | Goertzdetector(); 59 | void init(int _audioInPin); 60 | int detecttone(); 61 | int testData[GOERTZ_SAMPLES]; 62 | float magnitude; 63 | int magnitudelimit; 64 | int magnitudelimit_low; 65 | 66 | private: 67 | 68 | float coeff; 69 | float Q1; 70 | float Q2; 71 | float sine; 72 | float cosine; 73 | int audioInPin; 74 | int realstate; 75 | int realstatebefore; 76 | int filteredstate; 77 | unsigned long laststarttime; 78 | 79 | }; 80 | 81 | #endif //GOERTZEL_H 82 | -------------------------------------------------------------------------------- /libraries/K3NG_PS2Keyboard/library.properties: -------------------------------------------------------------------------------- 1 | name=K3NG_PS2Keyboard 2 | version=2021.12.16.01 3 | author=Anthony Good, K3NG 4 | maintainer=Anthony Good, K3NG 5 | sentence=For use with the K3NG CW Keyer for PS2 keyboard support 6 | paragraph=For use with the K3NG CW Keyer for PS2 keyboard support 7 | category=Uncategorized 8 | url=https://github.com/k3ng/k3ng_cw_keyer/tree/master/libraries/K3NG_PS2Keyboard 9 | architectures=avr,STM32F1 10 | includes=K3NG_PS2Keyboard.h -------------------------------------------------------------------------------- /libraries/NewTone/NewTone.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Created by Tim Eckel - teckel@leethost.com 3 | // Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html 4 | // 5 | // See "NewTone.h" for purpose, syntax, version history, links, and more. 6 | // --------------------------------------------------------------------------- 7 | 8 | #include "NewTone.h" 9 | 10 | unsigned long _nt_time; // Time note should end. 11 | uint8_t _pinMask = 0; // Pin bitmask. 12 | volatile uint8_t *_pinOutput; // Output port register 13 | 14 | void NewTone(uint8_t pin, unsigned long frequency, unsigned long length) { 15 | uint8_t prescaler = _BV(CS10); // Try using prescaler 1 first. 16 | unsigned long top = F_CPU / frequency / 4 - 1; // Calculate the top. 17 | if (top > 65535) { // If not in the range for prescaler 1, use prescaler 256 (61 Hz and lower @ 16 MHz). 18 | prescaler = _BV(CS12); // Set the 256 prescaler bit. 19 | top = top / 256 - 1; // Calculate the top using prescaler 256. 20 | } 21 | 22 | if (length > 0) _nt_time = millis() + length; else _nt_time = 0xFFFFFFFF; // Set when the note should end, or play "forever". 23 | 24 | if (_pinMask == 0) { 25 | _pinMask = digitalPinToBitMask(pin); // Get the port register bitmask for the pin. 26 | _pinOutput = portOutputRegister(digitalPinToPort(pin)); // Get the output port register for the pin. 27 | uint8_t *_pinMode = (uint8_t *) portModeRegister(digitalPinToPort(pin)); // Get the port mode register for the pin. 28 | *_pinMode |= _pinMask; // Set the pin to Output mode. 29 | } 30 | 31 | ICR1 = top; // Set the top. 32 | if (TCNT1 > top) TCNT1 = top; // Counter over the top, put within range. 33 | TCCR1B = _BV(WGM13) | prescaler; // Set PWM, phase and frequency corrected (ICR1) and prescaler. 34 | TCCR1A = _BV(COM1B0); 35 | TIMSK1 |= _BV(OCIE1A); // Activate the timer interrupt. 36 | } 37 | 38 | void noNewTone(uint8_t pin) { 39 | TIMSK1 &= ~_BV(OCIE1A); // Remove the timer interrupt. 40 | TCCR1B = _BV(CS11); // Default clock prescaler of 8. 41 | TCCR1A = _BV(WGM10); // Set to defaults so PWM can work like normal (PWM, phase corrected, 8bit). 42 | *_pinOutput &= ~_pinMask; // Set pin to LOW. 43 | _pinMask = 0; // Flag so we know note is no longer playing. 44 | } 45 | 46 | ISR(TIMER1_COMPA_vect) { // Timer interrupt vector. 47 | if (millis() >= _nt_time) noNewTone(); // Check to see if it's time for the note to end. 48 | *_pinOutput ^= _pinMask; // Toggle the pin state. 49 | } -------------------------------------------------------------------------------- /libraries/NewTone/NewTone.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // NewTone Library - v1.0 - 01/20/2013 3 | // 4 | // AUTHOR/LICENSE: 5 | // Created by Tim Eckel - teckel@leethost.com 6 | // Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html 7 | // 8 | // LINKS: 9 | // Project home: http://code.google.com/p/arduino-new-tone/ 10 | // Blog: http://arduino.cc/forum/index.php/XXX 11 | // 12 | // DISCLAIMER: 13 | // This software is furnished "as is", without technical support, and with no 14 | // warranty, express or implied, as to its usefulness for any purpose. 15 | // 16 | // PURPOSE: 17 | // Almost 1,300 bytes smaller code size than the Tone library. Faster execution 18 | // time. Exclusive use of port registers for fastest and smallest code. Higher 19 | // quality sound output than tone library. Plug-in replacement for Tone. Uses 20 | // timer 1 which may free up conflicts with the tone library. 21 | // 22 | // SYNTAX: 23 | // NewTone( pin, frequency [, length ] ) - Play a note on pin at frequency in Hz. 24 | // Parameters: 25 | // * pin - Pin speaker is wired to (other wire to ground, be sure to add an inline 100 ohm resistor). 26 | // * frequency - Play the specified frequency indefinitely, turn off with noNewTone(). 27 | // * length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1) 28 | // noNewTone(pin) - Stop playing note (pin is optional, will always stop playing on pin that was last used). 29 | // 30 | // HISTORY: 31 | // 01/20/2013 v1.0 - Initial release. 32 | // 33 | // --------------------------------------------------------------------------- 34 | 35 | #ifndef NewTone_h 36 | #define NewTone_h 37 | 38 | #if defined(ARDUINO) && ARDUINO >= 100 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) 45 | #define TIMSK1 TIMSK 46 | #endif 47 | 48 | void NewTone(uint8_t pin, unsigned long frequency, unsigned long length = 0); 49 | void noNewTone(uint8_t pin = 0); 50 | #endif -------------------------------------------------------------------------------- /libraries/NewTone/keywords.txt: -------------------------------------------------------------------------------- 1 | ################################### 2 | # Syntax Coloring Map For NewPing 3 | ################################### 4 | 5 | ################################### 6 | # Datatypes (KEYWORD1) 7 | ################################### 8 | 9 | ################################### 10 | # Methods and Functions (KEYWORD2) 11 | ################################### 12 | 13 | NewTone KEYWORD2 14 | noNewTone KEYWORD2 15 | 16 | ################################### 17 | # Constants (LITERAL1) 18 | ################################### 19 | -------------------------------------------------------------------------------- /libraries/README.md: -------------------------------------------------------------------------------- 1 | AS OF VERSION 2.2.2016012004 LIBRARY FILES MUST BE PUT IN LIBRARIES DIRECTORY AND NOT THE INO SKETCH DIRECTORY !!!! 2 | -------------------------------------------------------------------------------- /libraries/TwiLiquidCrystal/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /libraries/TwiLiquidCrystal/README.md: -------------------------------------------------------------------------------- 1 | # Arnakazim's TwiLiquidCrystal Arduino Library 2 | 3 | ## About 4 | 5 | A library to interface an HD44780 based LCD via I2C (or TWI in Arduino terms). 6 | 7 | Like its counterpart the LiquidCrystal library, this library allows an Arduino board to control Liquid Crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The difference is that instead of using multiple digital pins, it communicates with the Arduino via TWI (I2C) with the help of an I2C backpack attached to the LCD. 8 | 9 | ## Q&A 10 | 11 | __Why another I2C/TWI LCD display library for Arduino?__ 12 | 13 | That's a good question with a simple answer: there is no need for another one. I am in the process on making a board around an ATMega328P and I am planning to use a HD44780 base 16x2 display over I2C. 14 | 15 | I was using LiquidCrystal_I2C at first, but it is not well maintained and is basically a copy/paste of LiquidCrystal with a different write4bits() function. It is nice from far, but the LiquidCrystal library isn't so perfect... 16 | 17 | So, I have retrieved the HD44780 datasheet, read from it and started writing my own library. It worked fine for what I needed, but then I was "why not making it LiquidCrystal compatible?". And there I am. 18 | 19 | At the moment it is 99% compatible. Timings are improved from the original library. 20 | 21 | __What is a TWI/I2C backpack for my LCD?__ 22 | 23 | An I2C backpack is a module you connect in between your LCD and your Arduino. It enables communicating with the LCD via I2C. You willl be able to communicate via only two pins from your Arduino, instead of six or 10. 24 | 25 | You can buy I2C backpack on [Adafruit shop](https://www.adafruit.com/product/292) for example. 26 | 27 | The pinout to communicate using I2C on your Arduino depends on its model. You can find more information on the [Arduino website](https://www.arduino.cc/en/reference/wire). 28 | 29 | __What's the difference with the Arduino LiquidCrystal library?__ 30 | 31 | For you? Not much. If you have a sketch using the LiquidCrystal library, you can easily switch to this one. The only thing is that you will need an I2C backpack for your LCD. 32 | 33 | To switch from the LiquidCrystal library to the TwiLiquidCrystal it is simple. After rewiring your LCD screen, simply replace the library include and the type of your lcd variable and its parameters. That's all! Here is an example: 34 | 35 | With the LiquidCrystal library you would use: 36 | 37 | ```cpp 38 | #include 39 | 40 | const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 41 | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 42 | ``` 43 | 44 | And to use the same code with TwiLiquidCrystal you would simple replace this code by: 45 | 46 | ```cpp 47 | #include 48 | 49 | const int twiAddress = 0x27; // The I2C address of your LCD backpack 50 | TwiLiquidCrystal lcd(twiAddress); 51 | ``` 52 | 53 | __Can I help improve this library?__ 54 | 55 | Of course you can help! One of my goals is to keep this library active, bug free and updated. If you've seen a problem with this library or you think you can improve it I am open to all suggestions! 56 | 57 | __Why so many delays in the library code?__ 58 | 59 | The HD44780 is a time sensitive chipset. It needs delays to register commands and execute them. I have reduced them as much as I can, according to the HD44780 datasheet (). The thing is, the datasheet says that it takes nano seconds for certain action. The library does at best microseconds so there is a bit of time loss there. Also transmitting data over I2C takes time. I don't have an oscilloscope at hand, but I am pretty sure some delays aren't needed anymore or can be shortened... 60 | 61 | __Hey! I find your library usefull. Can I buy you a beer?__ 62 | 63 | Yes of course! You can tip me via my Ko-fi page. If I don't invest it in my future projects, I'll make sure to at least invest it in a beer ;) 64 | 65 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B03OTWP) 66 | 67 | __Can I sell a product using your library?__ 68 | 69 | Haven't you read the licence file? Of course you can! I've made this project in the public domain via the Unlicense license. I did not wrote this library to make money and if it can help others, even to make money, I would make me really happy. And if you make a few bucks with it and you want to thank me, you can help me with a tip (see previous answer). 70 | 71 | This is free and unencumbered software released into the public domain. For more information, see http://unlicense.org/ or the accompanying (un)LICENSE file. -------------------------------------------------------------------------------- /libraries/TwiLiquidCrystal/library.properties: -------------------------------------------------------------------------------- 1 | name=TwiLiquidCrytal by Arnakazim 2 | version=1.0.1 3 | author=Arnaud Ouvrier (Arnakazim) 4 | maintainer=Arnaud Ouvrier (Arnakazim) 5 | sentence=A library to interface an HD44780 based LCD via I2C (or TWI in Arduino terms). 6 | paragraph=Like its counterpart the LiquidCrystal library, this library allows an Arduino board to control Liquid Crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The difference is that instead of using multiple digital pins, it communicates with the Arduino via TWI (I2C) with the help of an I2C backpack attached to the LCD. 7 | category=Display 8 | url=https://github.com/arnakazim/TwiLiquidCrystal-library 9 | architectures=avr 10 | includes=TwiLiquidCrystal.h 11 | depends=Wire 12 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | * text eol=lf 4 | 5 | # Custom for Visual Studio 6 | *.cs diff=csharp 7 | *.sln merge=union 8 | *.csproj merge=union 9 | *.vbproj merge=union 10 | *.fsproj merge=union 11 | *.dbproj merge=union 12 | 13 | # Standard to msysgit 14 | *.doc diff=astextplain 15 | *.DOC diff=astextplain 16 | *.docx diff=astextplain 17 | *.DOCX diff=astextplain 18 | *.dot diff=astextplain 19 | *.DOT diff=astextplain 20 | *.pdf diff=astextplain 21 | *.PDF diff=astextplain 22 | *.rtf diff=astextplain 23 | *.RTF diff=astextplain 24 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.zip 3 | *.rar 4 | build/ -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "examples/testusbhostFAT/generic_storage"] 2 | path = examples/testusbhostFAT/generic_storage 3 | url = https://github.com/xxxajk/generic_storage 4 | [submodule "examples/testusbhostFAT/xmem2"] 5 | path = examples/testusbhostFAT/xmem2 6 | url = https://github.com/xxxajk/xmem2 7 | [submodule "examples/testusbhostFAT/Arduino_Makefile_master"] 8 | path = examples/testusbhostFAT/Arduino_Makefile_master 9 | url = https://github.com/xxxajk/Arduino_Makefile_master 10 | [submodule "examples/testusbhostFAT/RTClib"] 11 | path = examples/testusbhostFAT/RTClib 12 | url = https://github.com/xxxajk/RTClib 13 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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/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/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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 24 | if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 0 && 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(len - 2, 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/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/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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 12 | #ifdef dobogusinclude 13 | #include 14 | #include 15 | #endif 16 | 17 | USB Usb; 18 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 19 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 20 | 21 | /* You can create the instance of the class in two ways */ 22 | // This will start an inquiry and then pair with your device - you only have to do this once 23 | // If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter 24 | BTHID bthid(&Btd, PAIR, "0000"); 25 | 26 | // After that you can simply create the instance like so and then press any button on the device 27 | //BTHID hid(&Btd); 28 | 29 | KbdRptParser keyboardPrs; 30 | MouseRptParser mousePrs; 31 | 32 | void setup() { 33 | Serial.begin(115200); 34 | #if !defined(__MIPSEL__) 35 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 36 | #endif 37 | if (Usb.Init() == -1) { 38 | Serial.print(F("\r\nOSC did not start")); 39 | while (1); // Halt 40 | } 41 | 42 | bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs); 43 | bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs); 44 | 45 | // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" 46 | // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report 47 | bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode 48 | //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode 49 | 50 | Serial.print(F("\r\nHID Bluetooth Library Started")); 51 | } 52 | void loop() { 53 | Usb.Task(); 54 | } 55 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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(HID *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(HID *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/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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 17 | 18 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 19 | /* You can create the instance of the class in two ways */ 20 | SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000" 21 | //SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so 22 | 23 | bool firstMessage = true; 24 | 25 | void setup() { 26 | Serial.begin(115200); 27 | #if !defined(__MIPSEL__) 28 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 29 | #endif 30 | if (Usb.Init() == -1) { 31 | Serial.print(F("\r\nOSC did not start")); 32 | while (1); //halt 33 | } 34 | Serial.print(F("\r\nSPP Bluetooth Library Started")); 35 | } 36 | void loop() { 37 | Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 38 | 39 | if (SerialBT.connected) { 40 | if (firstMessage) { 41 | firstMessage = false; 42 | SerialBT.println(F("Hello from Arduino")); // Send welcome message 43 | } 44 | if (Serial.available()) 45 | SerialBT.write(Serial.read()); 46 | if (SerialBT.available()) 47 | Serial.write(SerialBT.read()); 48 | } 49 | else 50 | firstMessage = true; 51 | } 52 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 17 | 18 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 19 | 20 | const uint8_t length = 2; // Set the number of instances here 21 | 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! 22 | 23 | bool firstMessage[length] = { true }; // Set all to true 24 | 25 | void setup() { 26 | for (uint8_t i = 0; i < length; i++) 27 | SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "0000" for all connections 28 | 29 | Serial.begin(115200); 30 | #if !defined(__MIPSEL__) 31 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 32 | #endif 33 | if (Usb.Init() == -1) { 34 | Serial.print(F("\r\nOSC did not start")); 35 | while (1); // Halt 36 | } 37 | Serial.print(F("\r\nSPP Bluetooth Library Started")); 38 | } 39 | 40 | void loop() { 41 | Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 42 | 43 | for (uint8_t i = 0; i < length; i++) { 44 | if (SerialBT[i]->connected) { 45 | if (firstMessage[i]) { 46 | firstMessage[i] = false; 47 | SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message 48 | } 49 | if (SerialBT[i]->available()) 50 | Serial.write(SerialBT[i]->read()); 51 | } 52 | else 53 | firstMessage[i] = true; 54 | } 55 | 56 | // Set the connection you want to send to using the first character 57 | // For instance "0Hello World" would send "Hello World" to connection 0 58 | if (Serial.available()) { 59 | delay(10); // Wait for the rest of the data to arrive 60 | uint8_t id = Serial.read() - '0'; // Convert from ASCII 61 | if (id < length && SerialBT[id]->connected) { // Make sure that the id is valid and make sure that a device is actually connected 62 | while (Serial.available()) // Check if data is available 63 | SerialBT[id]->write(Serial.read()); // Send the data 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 17 | 18 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 19 | /* You can create the instance of the class in two ways */ 20 | WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once 21 | //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote 22 | 23 | bool printAngle; 24 | 25 | void setup() { 26 | Serial.begin(115200); 27 | #if !defined(__MIPSEL__) 28 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 29 | #endif 30 | if (Usb.Init() == -1) { 31 | Serial.print(F("\r\nOSC did not start")); 32 | while (1); //halt 33 | } 34 | Serial.print(F("\r\nWiimote Bluetooth Library Started")); 35 | } 36 | void loop() { 37 | Usb.Task(); 38 | if (Wii.wiimoteConnected) { 39 | if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down 40 | Serial.print(F("\r\nHOME")); 41 | Wii.disconnect(); 42 | } 43 | else { 44 | if (Wii.getButtonClick(LEFT)) { 45 | Wii.setLedOff(); 46 | Wii.setLedOn(LED1); 47 | Serial.print(F("\r\nLeft")); 48 | } 49 | if (Wii.getButtonClick(RIGHT)) { 50 | Wii.setLedOff(); 51 | Wii.setLedOn(LED3); 52 | Serial.print(F("\r\nRight")); 53 | } 54 | if (Wii.getButtonClick(DOWN)) { 55 | Wii.setLedOff(); 56 | Wii.setLedOn(LED4); 57 | Serial.print(F("\r\nDown")); 58 | } 59 | if (Wii.getButtonClick(UP)) { 60 | Wii.setLedOff(); 61 | Wii.setLedOn(LED2); 62 | Serial.print(F("\r\nUp")); 63 | } 64 | 65 | if (Wii.getButtonClick(PLUS)) 66 | Serial.print(F("\r\nPlus")); 67 | if (Wii.getButtonClick(MINUS)) 68 | Serial.print(F("\r\nMinus")); 69 | 70 | if (Wii.getButtonClick(ONE)) 71 | Serial.print(F("\r\nOne")); 72 | if (Wii.getButtonClick(TWO)) 73 | Serial.print(F("\r\nTwo")); 74 | 75 | if (Wii.getButtonClick(A)) { 76 | printAngle = !printAngle; 77 | Serial.print(F("\r\nA")); 78 | } 79 | if (Wii.getButtonClick(B)) { 80 | Wii.setRumbleToggle(); 81 | Serial.print(F("\r\nB")); 82 | } 83 | } 84 | #if 0 // Set this to 1 in order to see the angle of the controllers 85 | if (printAngle) { 86 | Serial.print(F("\r\nPitch: ")); 87 | Serial.print(Wii.getPitch()); 88 | Serial.print(F("\tRoll: ")); 89 | Serial.print(Wii.getRoll()); 90 | if (Wii.motionPlusConnected) { 91 | Serial.print(F("\tYaw: ")); 92 | Serial.print(Wii.getYaw()); 93 | } 94 | if (Wii.nunchuckConnected) { 95 | Serial.print(F("\tNunchuck Pitch: ")); 96 | Serial.print(Wii.getNunchuckPitch()); 97 | Serial.print(F("\tNunchuck Roll: ")); 98 | Serial.print(Wii.getNunchuckRoll()); 99 | } 100 | } 101 | #endif 102 | } 103 | #if 0 // Set this to 1 if you are using a Nunchuck controller 104 | if (Wii.nunchuckConnected) { 105 | if (Wii.getButtonClick(Z)) 106 | Serial.print(F("\r\nZ")); 107 | if (Wii.getButtonClick(C)) 108 | Serial.print(F("\r\nC")); 109 | if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) { 110 | Serial.print(F("\r\nHatX: ")); 111 | Serial.print(Wii.getAnalogHat(HatX)); 112 | Serial.print(F("\tHatY: ")); 113 | Serial.print(Wii.getAnalogHat(HatY)); 114 | } 115 | } 116 | #endif 117 | } 118 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | //USBHub Hub1(&Usb); // Some dongles have a hub inside 17 | 18 | BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 19 | /* You can create the instance of the class in two ways */ 20 | WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once 21 | //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | if (Usb.Init() == -1) { 29 | Serial.print(F("\r\nOSC did not start")); 30 | while (1); //halt 31 | } 32 | Serial.print(F("\r\nWiimote Bluetooth Library Started")); 33 | } 34 | void loop() { 35 | Usb.Task(); 36 | if (Wii.wiiUProControllerConnected) { 37 | if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down 38 | Serial.print(F("\r\nHome")); 39 | Wii.disconnect(); 40 | } 41 | else { 42 | if (Wii.getButtonClick(LEFT)) { 43 | Wii.setLedOff(); 44 | Wii.setLedOn(LED1); 45 | Serial.print(F("\r\nLeft")); 46 | } 47 | if (Wii.getButtonClick(RIGHT)) { 48 | Wii.setLedOff(); 49 | Wii.setLedOn(LED3); 50 | Serial.print(F("\r\nRight")); 51 | } 52 | if (Wii.getButtonClick(DOWN)) { 53 | Wii.setLedOff(); 54 | Wii.setLedOn(LED4); 55 | Serial.print(F("\r\nDown")); 56 | } 57 | if (Wii.getButtonClick(UP)) { 58 | Wii.setLedOff(); 59 | Wii.setLedOn(LED2); 60 | Serial.print(F("\r\nUp")); 61 | } 62 | 63 | if (Wii.getButtonClick(PLUS)) 64 | Serial.print(F("\r\nPlus")); 65 | if (Wii.getButtonClick(MINUS)) 66 | Serial.print(F("\r\nMinus")); 67 | 68 | if (Wii.getButtonClick(A)) 69 | Serial.print(F("\r\nA")); 70 | if (Wii.getButtonClick(B)) { 71 | Wii.setRumbleToggle(); 72 | Serial.print(F("\r\nB")); 73 | } 74 | if (Wii.getButtonClick(X)) 75 | Serial.print(F("\r\nX")); 76 | if (Wii.getButtonClick(Y)) 77 | Serial.print(F("\r\nY")); 78 | 79 | if (Wii.getButtonClick(L)) 80 | Serial.print(F("\r\nL")); 81 | if (Wii.getButtonClick(R)) 82 | Serial.print(F("\r\nR")); 83 | if (Wii.getButtonClick(ZL)) 84 | Serial.print(F("\r\nZL")); 85 | if (Wii.getButtonClick(ZR)) 86 | Serial.print(F("\r\nZR")); 87 | if (Wii.getButtonClick(L3)) 88 | Serial.print(F("\r\nL3")); 89 | if (Wii.getButtonClick(R3)) 90 | Serial.print(F("\r\nR3")); 91 | } 92 | 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) { 93 | Serial.print(F("\r\nLeftHatX: ")); 94 | Serial.print(Wii.getAnalogHat(LeftHatX)); 95 | Serial.print(F("\tLeftHatY: ")); 96 | Serial.print(Wii.getAnalogHat(LeftHatY)); 97 | Serial.print(F("\tRightHatX: ")); 98 | Serial.print(Wii.getAnalogHat(RightHatX)); 99 | Serial.print(F("\tRightHatY: ")); 100 | Serial.print(Wii.getAnalogHat(RightHatY)); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // Satisfy IDE, which only needs to see the include statment in the ino. 5 | #ifdef dobogusinclude 6 | #include 7 | #include 8 | #endif 9 | 10 | 11 | class KbdRptParser : public KeyboardReportParser 12 | { 13 | void PrintKey(uint8_t mod, uint8_t key); 14 | 15 | protected: 16 | void OnControlKeysChanged(uint8_t before, uint8_t after); 17 | 18 | void OnKeyDown (uint8_t mod, uint8_t key); 19 | void OnKeyUp (uint8_t mod, uint8_t key); 20 | void OnKeyPressed(uint8_t key); 21 | }; 22 | 23 | void KbdRptParser::PrintKey(uint8_t m, uint8_t key) 24 | { 25 | MODIFIERKEYS mod; 26 | *((uint8_t*)&mod) = m; 27 | Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); 28 | Serial.print((mod.bmLeftShift == 1) ? "S" : " "); 29 | Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); 30 | Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); 31 | 32 | Serial.print(" >"); 33 | PrintHex(key, 0x80); 34 | Serial.print("< "); 35 | 36 | Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); 37 | Serial.print((mod.bmRightShift == 1) ? "S" : " "); 38 | Serial.print((mod.bmRightAlt == 1) ? "A" : " "); 39 | Serial.println((mod.bmRightGUI == 1) ? "G" : " "); 40 | }; 41 | 42 | void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 43 | { 44 | Serial.print("DN "); 45 | PrintKey(mod, key); 46 | uint8_t c = OemToAscii(mod, key); 47 | 48 | if (c) 49 | OnKeyPressed(c); 50 | } 51 | 52 | void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) { 53 | 54 | MODIFIERKEYS beforeMod; 55 | *((uint8_t*)&beforeMod) = before; 56 | 57 | MODIFIERKEYS afterMod; 58 | *((uint8_t*)&afterMod) = after; 59 | 60 | if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { 61 | Serial.println("LeftCtrl changed"); 62 | } 63 | if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { 64 | Serial.println("LeftShift changed"); 65 | } 66 | if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { 67 | Serial.println("LeftAlt changed"); 68 | } 69 | if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { 70 | Serial.println("LeftGUI changed"); 71 | } 72 | 73 | if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { 74 | Serial.println("RightCtrl changed"); 75 | } 76 | if (beforeMod.bmRightShift != afterMod.bmRightShift) { 77 | Serial.println("RightShift changed"); 78 | } 79 | if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { 80 | Serial.println("RightAlt changed"); 81 | } 82 | if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { 83 | Serial.println("RightGUI changed"); 84 | } 85 | 86 | } 87 | 88 | void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) 89 | { 90 | Serial.print("UP "); 91 | PrintKey(mod, key); 92 | } 93 | 94 | void KbdRptParser::OnKeyPressed(uint8_t key) 95 | { 96 | Serial.print("ASCII: "); 97 | Serial.println((char)key); 98 | }; 99 | 100 | USB Usb; 101 | //USBHub Hub(&Usb); 102 | HIDBoot HidKeyboard(&Usb); 103 | 104 | uint32_t next_time; 105 | 106 | KbdRptParser Prs; 107 | 108 | void setup() 109 | { 110 | Serial.begin( 115200 ); 111 | #if !defined(__MIPSEL__) 112 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 113 | #endif 114 | Serial.println("Start"); 115 | 116 | if (Usb.Init() == -1) 117 | Serial.println("OSC did not start."); 118 | 119 | delay( 200 ); 120 | 121 | next_time = millis() + 5000; 122 | 123 | HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); 124 | } 125 | 126 | void loop() 127 | { 128 | Usb.Task(); 129 | } 130 | 131 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Satisfy IDE, which only needs to see the include statment in the ino. 4 | #ifdef dobogusinclude 5 | #include 6 | #include 7 | #endif 8 | 9 | class MouseRptParser : public MouseReportParser 10 | { 11 | protected: 12 | void OnMouseMove (MOUSEINFO *mi); 13 | void OnLeftButtonUp (MOUSEINFO *mi); 14 | void OnLeftButtonDown (MOUSEINFO *mi); 15 | void OnRightButtonUp (MOUSEINFO *mi); 16 | void OnRightButtonDown (MOUSEINFO *mi); 17 | void OnMiddleButtonUp (MOUSEINFO *mi); 18 | void OnMiddleButtonDown (MOUSEINFO *mi); 19 | }; 20 | void MouseRptParser::OnMouseMove(MOUSEINFO *mi) 21 | { 22 | Serial.print("dx="); 23 | Serial.print(mi->dX, DEC); 24 | Serial.print(" dy="); 25 | Serial.println(mi->dY, DEC); 26 | }; 27 | void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) 28 | { 29 | Serial.println("L Butt Up"); 30 | }; 31 | void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) 32 | { 33 | Serial.println("L Butt Dn"); 34 | }; 35 | void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) 36 | { 37 | Serial.println("R Butt Up"); 38 | }; 39 | void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) 40 | { 41 | Serial.println("R Butt Dn"); 42 | }; 43 | void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) 44 | { 45 | Serial.println("M Butt Up"); 46 | }; 47 | void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) 48 | { 49 | Serial.println("M Butt Dn"); 50 | }; 51 | 52 | USB Usb; 53 | USBHub Hub(&Usb); 54 | HIDBoot HidMouse(&Usb); 55 | 56 | uint32_t next_time; 57 | 58 | MouseRptParser Prs; 59 | 60 | void setup() 61 | { 62 | Serial.begin( 115200 ); 63 | #if !defined(__MIPSEL__) 64 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 65 | #endif 66 | Serial.println("Start"); 67 | 68 | if (Usb.Init() == -1) 69 | Serial.println("OSC did not start."); 70 | 71 | delay( 200 ); 72 | 73 | next_time = millis() + 5000; 74 | 75 | HidMouse.SetReportParser(0,(HIDReportParser*)&Prs); 76 | } 77 | 78 | void loop() 79 | { 80 | Usb.Task(); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/HID/USBHIDJoystick/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // Satisfy IDE, which only needs to see the include statment in the ino. 5 | #ifdef dobogusinclude 6 | #include 7 | #include 8 | #endif 9 | 10 | #include "hidjoystickrptparser.h" 11 | 12 | USB Usb; 13 | USBHub Hub(&Usb); 14 | HIDUniversal Hid(&Usb); 15 | JoystickEvents JoyEvents; 16 | JoystickReportParser Joy(&JoyEvents); 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 | Serial.println("Start"); 24 | 25 | if (Usb.Init() == -1) 26 | Serial.println("OSC did not start."); 27 | 28 | delay(200); 29 | 30 | if (!Hid.SetReportParser(0, &Joy)) 31 | ErrorMessage (PSTR("SetReportParser"), 1); 32 | } 33 | 34 | void loop() { 35 | Usb.Task(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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(HID *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 | oldButtons = buttons; 53 | } 54 | } 55 | 56 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 57 | Serial.print("X1: "); 58 | PrintHex (evt->X, 0x80); 59 | Serial.print("\tY1: "); 60 | PrintHex (evt->Y, 0x80); 61 | Serial.print("\tX2: "); 62 | PrintHex (evt->Z1, 0x80); 63 | Serial.print("\tY2: "); 64 | PrintHex (evt->Z2, 0x80); 65 | Serial.print("\tRz: "); 66 | PrintHex (evt->Rz, 0x80); 67 | Serial.println(""); 68 | } 69 | 70 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 71 | Serial.print("Hat Switch: "); 72 | PrintHex (hat, 0x80); 73 | Serial.println(""); 74 | } 75 | 76 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 77 | Serial.print("Up: "); 78 | Serial.println(but_id, DEC); 79 | } 80 | 81 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 82 | Serial.print("Dn: "); 83 | Serial.println(but_id, DEC); 84 | } 85 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 31 | }; 32 | 33 | #endif // __HIDJOYSTICKRPTPARSER_H__ 34 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/HID/USBHID_desc/USBHID_desc.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pgmstrings.h" 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #include 10 | #endif 11 | 12 | class HIDUniversal2 : public HIDUniversal 13 | { 14 | public: 15 | HIDUniversal2(USB *usb) : HIDUniversal(usb) {}; 16 | 17 | protected: 18 | uint8_t OnInitSuccessful(); 19 | }; 20 | 21 | uint8_t HIDUniversal2::OnInitSuccessful() 22 | { 23 | uint8_t rcode; 24 | 25 | HexDumper Hex; 26 | ReportDescParser Rpt; 27 | 28 | if ((rcode = GetReportDescr(0, &Hex))) 29 | goto FailGetReportDescr1; 30 | 31 | if ((rcode = GetReportDescr(0, &Rpt))) 32 | goto FailGetReportDescr2; 33 | 34 | return 0; 35 | 36 | FailGetReportDescr1: 37 | USBTRACE("GetReportDescr1:"); 38 | goto Fail; 39 | 40 | FailGetReportDescr2: 41 | USBTRACE("GetReportDescr2:"); 42 | goto Fail; 43 | 44 | Fail: 45 | Serial.println(rcode, HEX); 46 | Release(); 47 | return rcode; 48 | } 49 | 50 | USB Usb; 51 | //USBHub Hub(&Usb); 52 | HIDUniversal2 Hid(&Usb); 53 | UniversalReportParser Uni; 54 | 55 | void setup() 56 | { 57 | Serial.begin( 115200 ); 58 | #if !defined(__MIPSEL__) 59 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 60 | #endif 61 | Serial.println("Start"); 62 | 63 | if (Usb.Init() == -1) 64 | Serial.println("OSC did not start."); 65 | 66 | delay( 200 ); 67 | 68 | if (!Hid.SetReportParser(0, &Uni)) 69 | ErrorMessage(PSTR("SetReportParser"), 1 ); 70 | } 71 | 72 | void loop() 73 | { 74 | Usb.Task(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #include 12 | #endif 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 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("Start"); 27 | 28 | if (Usb.Init() == -1) 29 | Serial.println("OSC did not start."); 30 | 31 | delay( 200 ); 32 | 33 | if (!Hid.SetReportParser(0, &Joy)) 34 | ErrorMessage(PSTR("SetReportParser"), 1 ); 35 | } 36 | 37 | void loop() 38 | { 39 | Usb.Task(); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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(HID *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/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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 40 | }; 41 | 42 | #endif // __HIDJOYSTICKRPTPARSER_H__ 43 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | USBHub Hub(&Usb); 17 | HIDUniversal Hid(&Usb); 18 | Max_LCD LCD(&Usb); 19 | ScaleEvents ScaleEvents(&LCD); 20 | ScaleReportParser Scale(&ScaleEvents); 21 | 22 | void setup() 23 | { 24 | Serial.begin( 115200 ); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | // set up the LCD's number of rows and columns: 34 | LCD.begin(16, 2); 35 | LCD.clear(); 36 | LCD.home(); 37 | LCD.setCursor(0,0); 38 | LCD.write('R'); 39 | 40 | delay( 200 ); 41 | 42 | if (!Hid.SetReportParser(0, &Scale)) 43 | ErrorMessage(PSTR("SetReportParser"), 1 ); 44 | } 45 | 46 | void loop() 47 | { 48 | Usb.Task(); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/HID/scale/scale_rptparser.cpp: -------------------------------------------------------------------------------- 1 | /* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */ 2 | #include "scale_rptparser.h" 3 | 4 | const char* UNITS[13] = { 5 | "units", // unknown unit 6 | "mg", // milligram 7 | "g", // gram 8 | "kg", // kilogram 9 | "cd", // carat 10 | "taels", // lian 11 | "gr", // grain 12 | "dwt", // pennyweight 13 | "tonnes", // metric tons 14 | "tons", // avoir ton 15 | "ozt", // troy ounce 16 | "oz", // ounce 17 | "lbs" // pound 18 | }; 19 | 20 | ScaleReportParser::ScaleReportParser(ScaleEvents *evt) : 21 | scaleEvents(evt) 22 | {} 23 | 24 | void ScaleReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) 25 | { 26 | bool match = true; 27 | 28 | // Checking if there are changes in report since the method was last called 29 | for (uint8_t i=0; iOnScaleChanged((const ScaleEventData*)buf); 38 | 39 | for (uint8_t i=0; iwrite( *str++ ); 55 | 56 | } 57 | } 58 | 59 | void ScaleEvents::OnScaleChanged(const ScaleEventData *evt) 60 | { 61 | 62 | pLcd->clear(); 63 | pLcd->home(); 64 | pLcd->setCursor(0,0); 65 | 66 | if( evt->reportID != 3 ) { 67 | 68 | const char inv_report[]="Invalid report!"; 69 | 70 | Serial.println(inv_report); 71 | LcdPrint(inv_report); 72 | 73 | return; 74 | 75 | }//if( evt->reportID != 3... 76 | 77 | switch( evt->status ) { 78 | 79 | case REPORT_FAULT: 80 | Serial.println(F("Report fault")); 81 | break; 82 | 83 | case ZEROED: 84 | Serial.println(F("Scale zero set")); 85 | break; 86 | 87 | case WEIGHING: { 88 | 89 | const char progress[] = "Weighing..."; 90 | Serial.println(progress); 91 | LcdPrint(progress); 92 | break; 93 | } 94 | 95 | case WEIGHT_VALID: { 96 | 97 | char buf[10]; 98 | double weight = evt->weight * pow( 10, evt->exp ); 99 | 100 | 101 | 102 | Serial.print(F("Weight: ")); 103 | Serial.print( weight ); 104 | Serial.print(F(" ")); 105 | Serial.println( UNITS[ evt->unit ]); 106 | 107 | LcdPrint("Weight: "); 108 | dtostrf( weight, 4, 2, buf ); 109 | LcdPrint( buf ); 110 | LcdPrint( UNITS[ evt->unit ]); 111 | 112 | break; 113 | 114 | }//case WEIGHT_VALID... 115 | 116 | case WEIGHT_NEGATIVE: { 117 | 118 | const char negweight[] = "Negative weight"; 119 | Serial.println(negweight); 120 | LcdPrint(negweight); 121 | break; 122 | } 123 | 124 | case OVERWEIGHT: { 125 | 126 | const char overweight[] = "Max.weight reached"; 127 | Serial.println(overweight); 128 | LcdPrint( overweight ); 129 | break; 130 | } 131 | 132 | case CALIBRATE_ME: 133 | 134 | Serial.println(F("Scale calibration required")); 135 | break; 136 | 137 | case ZERO_ME: 138 | 139 | Serial.println(F("Scale zeroing required")); 140 | break; 141 | 142 | default: 143 | 144 | Serial.print(F("Undefined status code: ")); 145 | Serial.println( evt->status ); 146 | break; 147 | 148 | }//switch( evt->status... 149 | 150 | } 151 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 53 | }; 54 | 55 | #endif // __SCALERPTPARSER_H__ 56 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 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/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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 10 | #ifdef dobogusinclude 11 | #include 12 | #include 13 | #endif 14 | 15 | USB Usb; 16 | USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed 17 | XBOXOLD 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 Library Started")); 29 | } 30 | void loop() { 31 | Usb.Task(); 32 | if (Xbox.XboxConnected) { 33 | if (Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) { 34 | Serial.print("BLACK: "); 35 | Serial.print(Xbox.getButtonPress(BLACK)); 36 | Serial.print("\tWHITE: "); 37 | Serial.println(Xbox.getButtonPress(WHITE)); 38 | Xbox.setRumbleOn(Xbox.getButtonPress(BLACK), Xbox.getButtonPress(WHITE)); 39 | } else 40 | Xbox.setRumbleOn(0, 0); 41 | 42 | 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) { 43 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { 44 | Serial.print(F("LeftHatX: ")); 45 | Serial.print(Xbox.getAnalogHat(LeftHatX)); 46 | Serial.print("\t"); 47 | } 48 | if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { 49 | Serial.print(F("LeftHatY: ")); 50 | Serial.print(Xbox.getAnalogHat(LeftHatY)); 51 | Serial.print("\t"); 52 | } 53 | if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { 54 | Serial.print(F("RightHatX: ")); 55 | Serial.print(Xbox.getAnalogHat(RightHatX)); 56 | Serial.print("\t"); 57 | } 58 | if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 59 | Serial.print(F("RightHatY: ")); 60 | Serial.print(Xbox.getAnalogHat(RightHatY)); 61 | } 62 | Serial.println(); 63 | } 64 | 65 | if (Xbox.getButtonClick(UP)) 66 | Serial.println(F("Up")); 67 | if (Xbox.getButtonClick(DOWN)) 68 | Serial.println(F("Down")); 69 | if (Xbox.getButtonClick(LEFT)) 70 | Serial.println(F("Left")); 71 | if (Xbox.getButtonClick(RIGHT)) 72 | Serial.println(F("Right")); 73 | 74 | if (Xbox.getButtonClick(START)) 75 | Serial.println(F("Start")); 76 | if (Xbox.getButtonClick(BACK)) 77 | Serial.println(F("Back")); 78 | if (Xbox.getButtonClick(L3)) 79 | Serial.println(F("L3")); 80 | if (Xbox.getButtonClick(R3)) 81 | Serial.println(F("R3")); 82 | 83 | if (Xbox.getButtonPress(A)) { 84 | Serial.print(F("A: ")); 85 | Serial.println(Xbox.getButtonPress(A)); 86 | } 87 | if (Xbox.getButtonPress(B)) { 88 | Serial.print(F("B: ")); 89 | Serial.println(Xbox.getButtonPress(B)); 90 | } 91 | if (Xbox.getButtonPress(X)) { 92 | Serial.print(F("X: ")); 93 | Serial.println(Xbox.getButtonPress(X)); 94 | } 95 | if (Xbox.getButtonPress(Y)) { 96 | Serial.print(F("Y: ")); 97 | Serial.println(Xbox.getButtonPress(Y)); 98 | } 99 | if (Xbox.getButtonPress(L1)) { 100 | Serial.print(F("L1: ")); 101 | Serial.println(Xbox.getButtonPress(L1)); 102 | } 103 | if (Xbox.getButtonPress(R1)) { 104 | Serial.print(F("R1: ")); 105 | Serial.println(Xbox.getButtonPress(R1)); 106 | } 107 | } 108 | delay(1); 109 | } 110 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #include 12 | #endif 13 | 14 | USB Usb; 15 | XBOXUSB Xbox(&Usb); 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | #if !defined(__MIPSEL__) 20 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 21 | #endif 22 | if (Usb.Init() == -1) { 23 | Serial.print(F("\r\nOSC did not start")); 24 | while (1); //halt 25 | } 26 | Serial.print(F("\r\nXBOX USB Library Started")); 27 | } 28 | void loop() { 29 | Usb.Task(); 30 | if (Xbox.Xbox360Connected) { 31 | if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) { 32 | Serial.print("L2: "); 33 | Serial.print(Xbox.getButtonPress(L2)); 34 | Serial.print("\tR2: "); 35 | Serial.println(Xbox.getButtonPress(R2)); 36 | Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2)); 37 | } else 38 | Xbox.setRumbleOn(0, 0); 39 | 40 | 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) { 41 | if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { 42 | Serial.print(F("LeftHatX: ")); 43 | Serial.print(Xbox.getAnalogHat(LeftHatX)); 44 | Serial.print("\t"); 45 | } 46 | if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { 47 | Serial.print(F("LeftHatY: ")); 48 | Serial.print(Xbox.getAnalogHat(LeftHatY)); 49 | Serial.print("\t"); 50 | } 51 | if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { 52 | Serial.print(F("RightHatX: ")); 53 | Serial.print(Xbox.getAnalogHat(RightHatX)); 54 | Serial.print("\t"); 55 | } 56 | if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { 57 | Serial.print(F("RightHatY: ")); 58 | Serial.print(Xbox.getAnalogHat(RightHatY)); 59 | } 60 | Serial.println(); 61 | } 62 | 63 | if (Xbox.getButtonClick(UP)) { 64 | Xbox.setLedOn(LED1); 65 | Serial.println(F("Up")); 66 | } 67 | if (Xbox.getButtonClick(DOWN)) { 68 | Xbox.setLedOn(LED4); 69 | Serial.println(F("Down")); 70 | } 71 | if (Xbox.getButtonClick(LEFT)) { 72 | Xbox.setLedOn(LED3); 73 | Serial.println(F("Left")); 74 | } 75 | if (Xbox.getButtonClick(RIGHT)) { 76 | Xbox.setLedOn(LED2); 77 | Serial.println(F("Right")); 78 | } 79 | 80 | if (Xbox.getButtonClick(START)) { 81 | Xbox.setLedMode(ALTERNATING); 82 | Serial.println(F("Start")); 83 | } 84 | if (Xbox.getButtonClick(BACK)) { 85 | Xbox.setLedBlink(ALL); 86 | Serial.println(F("Back")); 87 | } 88 | if (Xbox.getButtonClick(L3)) 89 | Serial.println(F("L3")); 90 | if (Xbox.getButtonClick(R3)) 91 | Serial.println(F("R3")); 92 | 93 | if (Xbox.getButtonClick(L1)) 94 | Serial.println(F("L1")); 95 | if (Xbox.getButtonClick(R1)) 96 | Serial.println(F("R1")); 97 | if (Xbox.getButtonClick(XBOX)) { 98 | Xbox.setLedMode(ROTATING); 99 | Serial.println(F("Xbox")); 100 | } 101 | 102 | if (Xbox.getButtonClick(A)) 103 | Serial.println(F("A")); 104 | if (Xbox.getButtonClick(B)) 105 | Serial.println(F("B")); 106 | if (Xbox.getButtonClick(X)) 107 | Serial.println(F("X")); 108 | if (Xbox.getButtonClick(Y)) 109 | Serial.println(F("Y")); 110 | } 111 | delay(1); 112 | } 113 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/acm/acm_terminal/acm_terminal.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pgmstrings.h" 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #include 10 | #endif 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/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/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 | #include 24 | #endif 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 (millis() - timer >= 1000) { // Send data every 1s 72 | timer = 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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 8 | #ifdef dobogusinclude 9 | #include 10 | #include 11 | #endif 12 | 13 | USB Usb; 14 | USBHub Hub1(&Usb); 15 | USBHub Hub2(&Usb); 16 | HIDBoot Keyboard(&Usb); 17 | 18 | ADK adk(&Usb,"Circuits@Home, ltd.", 19 | "USB Host Shield", 20 | "Arduino Terminal for Android", 21 | "1.0", 22 | "http://www.circuitsathome.com", 23 | "0000000000000001"); 24 | 25 | 26 | class KbdRptParser : public KeyboardReportParser 27 | { 28 | 29 | protected: 30 | void OnKeyDown (uint8_t mod, uint8_t key); 31 | void OnKeyPressed(uint8_t key); 32 | }; 33 | 34 | void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 35 | { 36 | uint8_t c = OemToAscii(mod, key); 37 | 38 | if (c) 39 | OnKeyPressed(c); 40 | } 41 | 42 | /* what to do when symbol arrives */ 43 | void KbdRptParser::OnKeyPressed(uint8_t key) 44 | { 45 | const char* new_line = "\n"; 46 | uint8_t rcode; 47 | uint8_t keylcl; 48 | 49 | if( adk.isReady() == false ) { 50 | return; 51 | } 52 | 53 | keylcl = key; 54 | 55 | if( keylcl == 0x13 ) { 56 | rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line ); 57 | } 58 | else { 59 | rcode = adk.SndData( 1, &keylcl ); 60 | } 61 | 62 | Serial.print((char) keylcl ); 63 | Serial.print(" : "); 64 | Serial.println( keylcl, HEX ); 65 | }; 66 | 67 | KbdRptParser Prs; 68 | 69 | void setup() 70 | { 71 | Serial.begin(115200); 72 | #if !defined(__MIPSEL__) 73 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 74 | #endif 75 | Serial.println("\r\nADK demo start"); 76 | 77 | if (Usb.Init() == -1) { 78 | Serial.println("OSCOKIRQ failed to assert"); 79 | while(1); //halt 80 | }//if (Usb.Init() == -1... 81 | 82 | Keyboard.SetReportParser(0, (HIDReportParser*)&Prs); 83 | 84 | delay( 200 ); 85 | } 86 | 87 | void loop() 88 | { 89 | Usb.Task(); 90 | } 91 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/adk/demokit_20/demokit_20.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Satisfy IDE, which only needs to see the include statment in the ino. 4 | #ifdef dobogusinclude 5 | #include 6 | #include 7 | #endif 8 | 9 | USB Usb; 10 | USBHub hub0(&Usb); 11 | USBHub hub1(&Usb); 12 | ADK adk(&Usb,"Google, Inc.", 13 | "DemoKit", 14 | "DemoKit Arduino Board", 15 | "1.0", 16 | "http://www.android.com", 17 | "0000000012345678"); 18 | uint8_t b, b1; 19 | 20 | 21 | #define LED1_RED 3 22 | #define BUTTON1 2 23 | 24 | void init_buttons() 25 | { 26 | pinMode(BUTTON1, INPUT); 27 | 28 | // enable the internal pullups 29 | digitalWrite(BUTTON1, HIGH); 30 | } 31 | 32 | void init_leds() 33 | { 34 | digitalWrite(LED1_RED, 0); 35 | 36 | pinMode(LED1_RED, OUTPUT); 37 | } 38 | 39 | void setup() 40 | { 41 | Serial.begin(115200); 42 | #if !defined(__MIPSEL__) 43 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 44 | #endif 45 | Serial.println("\r\nADK demo start"); 46 | 47 | if (Usb.Init() == -1) { 48 | Serial.println("OSCOKIRQ failed to assert"); 49 | while(1); //halt 50 | }//if (Usb.Init() == -1... 51 | 52 | 53 | init_leds(); 54 | init_buttons(); 55 | b1 = digitalRead(BUTTON1); 56 | } 57 | 58 | void loop() 59 | { 60 | uint8_t rcode; 61 | uint8_t msg[3] = { 0x00 }; 62 | Usb.Task(); 63 | 64 | if( adk.isReady() == false ) { 65 | analogWrite(LED1_RED, 255); 66 | return; 67 | } 68 | uint16_t len = sizeof(msg); 69 | 70 | rcode = adk.RcvData(&len, msg); 71 | if( rcode ) { 72 | USBTRACE2("Data rcv. :", rcode ); 73 | } 74 | if(len > 0) { 75 | USBTRACE("\r\nData Packet."); 76 | // assumes only one command per packet 77 | if (msg[0] == 0x2) { 78 | switch( msg[1] ) { 79 | case 0: 80 | analogWrite(LED1_RED, 255 - msg[2]); 81 | break; 82 | }//switch( msg[1]... 83 | }//if (msg[0] == 0x2... 84 | }//if( len > 0... 85 | 86 | msg[0] = 0x1; 87 | 88 | b = digitalRead(BUTTON1); 89 | if (b != b1) { 90 | USBTRACE("\r\nButton state changed"); 91 | msg[1] = 0; 92 | msg[2] = b ? 0 : 1; 93 | rcode = adk.SndData( 3, msg ); 94 | if( rcode ) { 95 | USBTRACE2("Button send: ", rcode ); 96 | } 97 | b1 = b; 98 | }//if (b != b1... 99 | 100 | 101 | delay( 10 ); 102 | } 103 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/adk/term_test/term_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Satisfy IDE, which only needs to see the include statment in the ino. 4 | #ifdef dobogusinclude 5 | #include 6 | #include 7 | #endif 8 | 9 | USB Usb; 10 | //USBHub Hub(&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 rcode; 36 | uint8_t msg[64] = { 0x00 }; 37 | const char* recv = "Received: "; 38 | 39 | Usb.Task(); 40 | 41 | if( adk.isReady() == false ) { 42 | return; 43 | } 44 | uint16_t len = 64; 45 | 46 | rcode = adk.RcvData(&len, msg); 47 | if( rcode & ( rcode != hrNAK )) { 48 | USBTRACE2("Data rcv. :", rcode ); 49 | } 50 | if(len > 0) { 51 | USBTRACE("\r\nData Packet."); 52 | 53 | for( uint8_t i = 0; i < len; i++ ) { 54 | Serial.print((char)msg[i]); 55 | } 56 | /* sending back what was received */ 57 | rcode = adk.SndData( strlen( recv ), (uint8_t *)recv ); 58 | rcode = adk.SndData( strlen(( char * )msg ), msg ); 59 | 60 | }//if( len > 0 )... 61 | 62 | delay( 1000 ); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/examples/adk/term_time/term_time.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // Satisfy IDE, which only needs to see the include statment in the ino. 4 | #ifdef dobogusinclude 5 | #include 6 | #include 7 | #endif 8 | 9 | USB Usb; 10 | 11 | ADK adk(&Usb,"Circuits@Home, ltd.", 12 | "USB Host Shield", 13 | "Arduino Terminal for Android", 14 | "1.0", 15 | "http://www.circuitsathome.com", 16 | "0000000000000001"); 17 | 18 | void setup() 19 | { 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("\r\nADK demo start"); 25 | 26 | if (Usb.Init() == -1) { 27 | Serial.println("OSCOKIRQ failed to assert"); 28 | while(1); //halt 29 | }//if (Usb.Init() == -1... 30 | } 31 | 32 | void loop() 33 | { 34 | uint8_t buf[ 12 ] = { 0 }; //buffer to convert unsigned long to ASCII 35 | const char* sec_ela = " seconds elapsed\r"; 36 | uint8_t rcode; 37 | 38 | Usb.Task(); 39 | if( adk.isReady() == false ) { 40 | return; 41 | } 42 | 43 | ultoa( millis()/1000, (char *)buf, 10 ); 44 | 45 | rcode = adk.SndData( strlen((char *)buf), buf ); 46 | rcode = adk.SndData( strlen( sec_ela), (uint8_t *)sec_ela ); 47 | 48 | delay( 1000 ); 49 | } 50 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | #include 7 | #endif 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/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pgmstrings.h" 5 | // Satisfy IDE, which only needs to see the include statment in the ino. 6 | #ifdef dobogusinclude 7 | #include 8 | #include 9 | #endif 10 | 11 | class FTDIAsync : public FTDIAsyncOper 12 | { 13 | public: 14 | uint8_t OnInit(FTDI *pftdi); 15 | }; 16 | 17 | uint8_t FTDIAsync::OnInit(FTDI *pftdi) 18 | { 19 | uint8_t rcode = 0; 20 | 21 | rcode = pftdi->SetBaudRate(115200); 22 | 23 | if (rcode) 24 | { 25 | ErrorMessage(PSTR("SetBaudRate"), rcode); 26 | return rcode; 27 | } 28 | rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL); 29 | 30 | if (rcode) 31 | ErrorMessage(PSTR("SetFlowControl"), rcode); 32 | 33 | return rcode; 34 | } 35 | 36 | USB Usb; 37 | //USBHub Hub(&Usb); 38 | FTDIAsync FtdiAsync; 39 | FTDI Ftdi(&Usb, &FtdiAsync); 40 | 41 | uint32_t next_time; 42 | 43 | void setup() 44 | { 45 | Serial.begin( 115200 ); 46 | #if !defined(__MIPSEL__) 47 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 48 | #endif 49 | Serial.println("Start"); 50 | 51 | if (Usb.Init() == -1) 52 | Serial.println("OSC did not start."); 53 | 54 | delay( 200 ); 55 | 56 | next_time = millis() + 5000; 57 | } 58 | 59 | void loop() 60 | { 61 | Usb.Task(); 62 | 63 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 64 | { 65 | uint8_t rcode; 66 | char strbuf[] = "DEADBEEF"; 67 | //char strbuf[] = "The quick brown fox jumps over the lazy dog"; 68 | //char strbuf[] = "This string contains 61 character to demonstrate FTDI buffers"; //add one symbol to it to see some garbage 69 | Serial.print("."); 70 | 71 | rcode = Ftdi.SndData(strlen(strbuf), (uint8_t*)strbuf); 72 | 73 | if (rcode) 74 | ErrorMessage(PSTR("SndData"), rcode); 75 | 76 | delay(50); 77 | 78 | uint8_t buf[64]; 79 | 80 | for (uint8_t i=0; i<64; i++) 81 | buf[i] = 0; 82 | 83 | uint16_t rcvd = 64; 84 | rcode = Ftdi.RcvData(&rcvd, buf); 85 | 86 | if (rcode && rcode != hrNAK) 87 | ErrorMessage(PSTR("Ret"), rcode); 88 | 89 | // The device reserves the first two bytes of data 90 | // to contain the current values of the modem and line status registers. 91 | if (rcvd > 2) 92 | Serial.print((char*)(buf+2)); 93 | 94 | delay(10); 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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/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/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 8 | #ifdef dobogusinclude 9 | #include 10 | #include 11 | #endif 12 | 13 | USB Usb; 14 | Max_LCD lcd(&Usb); 15 | 16 | void setup() { 17 | // Set up the LCD's number of columns and rows: 18 | lcd.begin(16, 2); 19 | // Print a message to the LCD. 20 | lcd.print("Hello, World!"); 21 | } 22 | 23 | void loop() { 24 | // Set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0): 25 | lcd.setCursor(0, 1); 26 | // Print the number of seconds since reset: 27 | lcd.print(millis() / 1000); 28 | } 29 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 8 | #ifdef dobogusinclude 9 | #include 10 | #include 11 | #endif 12 | 13 | class PLAsyncOper : public CDCAsyncOper 14 | { 15 | public: 16 | uint8_t OnInit(ACM *pacm); 17 | }; 18 | 19 | uint8_t PLAsyncOper::OnInit(ACM *pacm) 20 | { 21 | uint8_t rcode; 22 | 23 | // Set DTR = 1 24 | rcode = pacm->SetControlLineState(1); 25 | 26 | if (rcode) 27 | { 28 | ErrorMessage(PSTR("SetControlLineState"), rcode); 29 | return rcode; 30 | } 31 | 32 | LINE_CODING lc; 33 | //lc.dwDTERate = 9600; 34 | lc.dwDTERate = 115200; 35 | lc.bCharFormat = 0; 36 | lc.bParityType = 0; 37 | lc.bDataBits = 8; 38 | 39 | rcode = pacm->SetLineCoding(&lc); 40 | 41 | if (rcode) 42 | ErrorMessage(PSTR("SetLineCoding"), rcode); 43 | 44 | return rcode; 45 | } 46 | USB Usb; 47 | //USBHub Hub(&Usb); 48 | PLAsyncOper AsyncOper; 49 | PL2303 Pl(&Usb, &AsyncOper); 50 | 51 | void setup() 52 | { 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 | { 67 | Usb.Task(); 68 | 69 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 70 | { 71 | uint8_t rcode; 72 | 73 | /* reading the keyboard */ 74 | if(Serial.available()) { 75 | uint8_t data= Serial.read(); 76 | 77 | /* sending to the phone */ 78 | rcode = Pl.SndData(1, &data); 79 | if (rcode) 80 | ErrorMessage(PSTR("SndData"), rcode); 81 | }//if(Serial.available()... 82 | 83 | /* reading the converter */ 84 | /* buffer size must be greater or equal to max.packet size */ 85 | /* it it set to 64 (largest possible max.packet size) here, can be tuned down 86 | for particular endpoint */ 87 | uint8_t buf[64]; 88 | uint16_t rcvd = 64; 89 | rcode = Pl.RcvData(&rcvd, buf); 90 | if (rcode && rcode != hrNAK) 91 | ErrorMessage(PSTR("Ret"), rcode); 92 | 93 | if( rcvd ) { //more than zero bytes received 94 | for(uint16_t i=0; i < rcvd; i++ ) { 95 | Serial.print((char)buf[i]); //printing on the screen 96 | } 97 | }//if( rcvd ... 98 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 99 | } 100 | 101 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #include 12 | #endif 13 | 14 | class PLAsyncOper : public CDCAsyncOper { 15 | public: 16 | uint8_t OnInit(ACM *pacm); 17 | }; 18 | 19 | uint8_t PLAsyncOper::OnInit(ACM *pacm) { 20 | uint8_t rcode; 21 | 22 | // Set DTR = 1 23 | rcode = pacm->SetControlLineState(1); 24 | 25 | if(rcode) { 26 | ErrorMessage(PSTR("SetControlLineState"), rcode); 27 | return rcode; 28 | } 29 | 30 | LINE_CODING lc; 31 | lc.dwDTERate = 4800; //default serial speed of GPS unit 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 | PLAsyncOper AsyncOper; 47 | PL2303 Pl(&Usb, &AsyncOper); 48 | uint32_t read_delay; 49 | #define READ_DELAY 100 50 | 51 | void setup() { 52 | Serial.begin(115200); 53 | #if !defined(__MIPSEL__) 54 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 55 | #endif 56 | Serial.println("Start"); 57 | 58 | if(Usb.Init() == -1) 59 | Serial.println("OSCOKIRQ failed to assert"); 60 | 61 | delay(200); 62 | } 63 | 64 | void loop() { 65 | uint8_t rcode; 66 | uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint 67 | uint16_t rcvd = 64; 68 | 69 | Usb.Task(); 70 | 71 | if(Pl.isReady()) { 72 | /* reading the GPS */ 73 | if((long)(millis() - read_delay) >= 0L) { 74 | read_delay += READ_DELAY; 75 | rcode = Pl.RcvData(&rcvd, buf); 76 | if(rcode && rcode != hrNAK) 77 | ErrorMessage(PSTR("Ret"), rcode); 78 | if(rcvd) { //more than zero bytes received 79 | for(uint16_t i = 0; i < rcvd; i++) { 80 | Serial.print((char)buf[i]); //printing on the screen 81 | }//for( uint16_t i=0; i < rcvd; i++... 82 | }//if( rcvd 83 | }//if( read_delay > millis()... 84 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 85 | } 86 | 87 | 88 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 | // Satisfy IDE, which only needs to see the include statment in the ino. 9 | #ifdef dobogusinclude 10 | #include 11 | #include 12 | #endif 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 = 115200; 35 | lc.bCharFormat = 0; 36 | lc.bParityType = 0; 37 | lc.bDataBits = 8; 38 | 39 | rcode = pacm->SetLineCoding(&lc); 40 | 41 | if (rcode) 42 | ErrorMessage(PSTR("SetLineCoding"), rcode); 43 | 44 | return rcode; 45 | } 46 | USB Usb; 47 | //USBHub Hub(&Usb); 48 | PLAsyncOper AsyncOper; 49 | PL2303 Pl(&Usb, &AsyncOper); 50 | 51 | void setup() 52 | { 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 | { 67 | Usb.Task(); 68 | 69 | if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) 70 | { 71 | uint8_t rcode; 72 | 73 | /* reading the keyboard */ 74 | if(Serial.available()) { 75 | uint8_t data= Serial.read(); 76 | 77 | if ( data == '\r' ) { 78 | Serial.print("\r\n"); //insert linefeed 79 | } 80 | else { 81 | Serial.print( data ); //echo back to the screen 82 | } 83 | 84 | /* sending to the phone */ 85 | rcode = Pl.SndData(1, &data); 86 | if (rcode) 87 | ErrorMessage(PSTR("SndData"), rcode); 88 | }//if(Serial.available()... 89 | 90 | delay(50); 91 | 92 | /* reading the converter */ 93 | /* buffer size must be greater or equal to max.packet size */ 94 | /* it it set to 64 (largest possible max.packet size) here, can be tuned down 95 | for particular endpoint */ 96 | uint8_t buf[64]; 97 | uint16_t rcvd = 64; 98 | rcode = Pl.RcvData(&rcvd, buf); 99 | if (rcode && rcode != hrNAK) 100 | ErrorMessage(PSTR("Ret"), rcode); 101 | 102 | if( rcvd ) { //more than zero bytes received 103 | for(uint16_t i=0; i < rcvd; i++ ) { 104 | if( buf[i] =='\r' ) { 105 | Serial.print("\r\n"); //insert linefeed 106 | } 107 | else { 108 | Serial.print((char)buf[i]); //printing on the screen 109 | } 110 | } 111 | } 112 | delay(10); 113 | }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. 114 | } 115 | 116 | 117 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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 uncomment the following two lines 6 | # BOARD = mega2560 7 | # PROGRAMMER = wiring 8 | # ...and then comment out the following two lines 9 | BOARD = mega 10 | PROGRAMMER = arduino 11 | 12 | #BOARD = teensypp2 13 | #BOARD = teensy3 14 | #BOARD = teensy31 15 | 16 | # set your Arduino tty port here 17 | PORT = /dev/ttyUSB0 18 | 19 | EXTRA_FLAGS = -D _USE_LFN=3 20 | 21 | # change to 0 if you have quadram to take advantage of caching FAT 22 | EXTRA_FLAGS += -D _FS_TINY=1 23 | 24 | 25 | EXTRA_FLAGS += -D _MAX_SS=512 26 | 27 | 28 | # Don't worry if you don't have external RAM, xmem2 detects this situation. 29 | # You *WILL* be wanting to get some kind of external ram on your mega in order to 30 | # do anything that is intense. 31 | EXTRA_FLAGS += -D EXT_RAM_STACK=1 32 | EXTRA_FLAGS += -D EXT_RAM_HEAP=1 33 | 34 | 35 | # These are no longer needed for the demo to work. 36 | # In the event you need more ram, uncomment these 3 lines. 37 | #EXTRA_FLAGS += -D DISABLE_SERIAL1 38 | #EXTRA_FLAGS += -D DISABLE_SERIAL2 39 | #EXTRA_FLAGS += -D DISABLE_SERIAL3 40 | 41 | # 42 | # Advanced debug on Serial3 43 | # 44 | 45 | # uncomment the next two to enable debug on Serial3 46 | EXTRA_FLAGS += -D USB_HOST_SERIAL=Serial3 47 | #EXTRA_FLAGS += -D DEBUG_USB_HOST 48 | 49 | # The following are the libraries used. 50 | LIB_DIRS += ../../ 51 | LIB_DIRS += ../testusbhostFAT/xmem2 52 | LIB_DIRS += ../testusbhostFAT/generic_storage 53 | LIB_DIRS += ../testusbhostFAT/RTClib 54 | LIB_DIRS += $(ARD_HOME)/libraries/Wire 55 | LIB_DIRS += $(ARD_HOME)/libraries/Wire/utility 56 | 57 | # And finally, the part that brings everything together for you. 58 | include Arduino_Makefile_master/_Makefile.master 59 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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/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) { 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/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 "hid.h" 22 | //#include "hidescriptorparser.h" 23 | 24 | class HIDUniversal : public HID { 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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 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.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 | "examples": 35 | [ 36 | "examples/*/*.ino", 37 | "examples/*/*/*.ino" 38 | ], 39 | "frameworks": "arduino", 40 | "platforms": 41 | [ 42 | "atmelavr", 43 | "teensy", 44 | "atmelsam" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /libraries/USB_Host_Shield/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/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/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/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, ERROR_TYPE rcode = 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/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/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/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, int lvl) { 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/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/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 | -------------------------------------------------------------------------------- /preconfigurations/YaaCWk/so2r/PS2_WINKEY_Atmega644P/default.txt: -------------------------------------------------------------------------------- 1 | this is the default profile 2 | --------------------------------------------------------------------------------