├── firmware └── Arduino │ ├── hardware │ └── MaKeyMaKey │ │ ├── driver │ │ ├── makeymakey.cat │ │ └── MaKeyMaKey.inf │ │ ├── bootloaders │ │ └── caterina │ │ │ ├── Makefile │ │ │ ├── Caterina.h │ │ │ ├── Descriptors.h │ │ │ ├── Descriptors.c │ │ │ └── Caterina-makeymakey.hex │ │ ├── cores │ │ └── arduino │ │ │ ├── Server.h │ │ │ ├── main.cpp │ │ │ ├── new.cpp │ │ │ ├── Platform.h │ │ │ ├── new.h │ │ │ ├── Client.h │ │ │ ├── IPAddress.cpp │ │ │ ├── Printable.h │ │ │ ├── wiring_shift.c │ │ │ ├── WMath.cpp │ │ │ ├── wiring_private.h │ │ │ ├── USBDesc.h │ │ │ ├── HardwareSerial.h │ │ │ ├── Print.h │ │ │ ├── wiring_pulse.c │ │ │ ├── IPAddress.h │ │ │ ├── Stream.h │ │ │ ├── Udp.h │ │ │ ├── WCharacter.h │ │ │ ├── wiring_digital.c │ │ │ ├── USBAPI.h │ │ │ ├── Print.cpp │ │ │ ├── Arduino.h │ │ │ ├── CDC.cpp │ │ │ ├── Stream.cpp │ │ │ ├── wiring_analog.c │ │ │ ├── USBCore.h │ │ │ ├── WString.h │ │ │ ├── WInterrupts.c │ │ │ ├── wiring.c │ │ │ ├── binary.h │ │ │ └── HardwareSerial.cpp │ │ ├── boards.txt │ │ ├── platform.txt │ │ ├── readme.txt │ │ └── variants │ │ └── MaKeyMaKey │ │ └── pins_arduino.h │ └── makey_makey │ └── settings.h ├── .gitignore └── README.md /firmware/Arduino/hardware/MaKeyMaKey/driver/makeymakey.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/MaKeyMaKey/HEAD/firmware/Arduino/hardware/MaKeyMaKey/driver/makeymakey.cat -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/bootloaders/caterina/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/MaKeyMaKey/HEAD/firmware/Arduino/hardware/MaKeyMaKey/bootloaders/caterina/Makefile -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Server.h: -------------------------------------------------------------------------------- 1 | #ifndef server_h 2 | #define server_h 3 | 4 | class Server : public Print { 5 | public: 6 | virtual void begin() =0; 7 | }; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | init(); 6 | 7 | #if defined(USBCON) 8 | USBDevice.attach(); 9 | #endif 10 | 11 | setup(); 12 | 13 | for (;;) { 14 | loop(); 15 | if (serialEventRun) serialEventRun(); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void * operator new(size_t size) 4 | { 5 | return malloc(size); 6 | } 7 | 8 | void operator delete(void * ptr) 9 | { 10 | free(ptr); 11 | } 12 | 13 | int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; 14 | void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; 15 | void __cxa_guard_abort (__guard *) {}; 16 | 17 | void __cxa_pure_virtual(void) {}; 18 | 19 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Platform.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __PLATFORM_H__ 3 | #define __PLATFORM_H__ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef unsigned char u8; 12 | typedef unsigned short u16; 13 | typedef unsigned long u32; 14 | 15 | #include "Arduino.h" 16 | 17 | #if defined(USBCON) 18 | #include "USBDesc.h" 19 | #include "USBCore.h" 20 | #include "USBAPI.h" 21 | #endif /* if defined(USBCON) */ 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/new.h: -------------------------------------------------------------------------------- 1 | /* Header to define new/delete operators as they aren't provided by avr-gcc by default 2 | Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 3 | */ 4 | 5 | #ifndef NEW_H 6 | #define NEW_H 7 | 8 | #include 9 | 10 | void * operator new(size_t size); 11 | void operator delete(void * ptr); 12 | 13 | __extension__ typedef int __guard __attribute__((mode (__DI__))); 14 | 15 | extern "C" int __cxa_guard_acquire(__guard *); 16 | extern "C" void __cxa_guard_release (__guard *); 17 | extern "C" void __cxa_guard_abort (__guard *); 18 | 19 | extern "C" void __cxa_pure_virtual(void); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Client.h: -------------------------------------------------------------------------------- 1 | #ifndef client_h 2 | #define client_h 3 | #include "Print.h" 4 | #include "Stream.h" 5 | #include "IPAddress.h" 6 | 7 | class Client : public Stream { 8 | 9 | public: 10 | virtual int connect(IPAddress ip, uint16_t port) =0; 11 | virtual int connect(const char *host, uint16_t port) =0; 12 | virtual size_t write(uint8_t) =0; 13 | virtual size_t write(const uint8_t *buf, size_t size) =0; 14 | virtual int available() = 0; 15 | virtual int read() = 0; 16 | virtual int read(uint8_t *buf, size_t size) = 0; 17 | virtual int peek() = 0; 18 | virtual void flush() = 0; 19 | virtual void stop() = 0; 20 | virtual uint8_t connected() = 0; 21 | virtual operator bool() = 0; 22 | protected: 23 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | IPAddress::IPAddress() 6 | { 7 | memset(_address, 0, sizeof(_address)); 8 | } 9 | 10 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 11 | { 12 | _address[0] = first_octet; 13 | _address[1] = second_octet; 14 | _address[2] = third_octet; 15 | _address[3] = fourth_octet; 16 | } 17 | 18 | IPAddress::IPAddress(uint32_t address) 19 | { 20 | memcpy(_address, &address, sizeof(_address)); 21 | } 22 | 23 | IPAddress::IPAddress(const uint8_t *address) 24 | { 25 | memcpy(_address, address, sizeof(_address)); 26 | } 27 | 28 | IPAddress& IPAddress::operator=(const uint8_t *address) 29 | { 30 | memcpy(_address, address, sizeof(_address)); 31 | return *this; 32 | } 33 | 34 | IPAddress& IPAddress::operator=(uint32_t address) 35 | { 36 | memcpy(_address, (const uint8_t *)&address, sizeof(_address)); 37 | return *this; 38 | } 39 | 40 | bool IPAddress::operator==(const uint8_t* addr) 41 | { 42 | return memcmp(addr, _address, sizeof(_address)) == 0; 43 | } 44 | 45 | size_t IPAddress::printTo(Print& p) const 46 | { 47 | size_t n = 0; 48 | for (int i =0; i < 3; i++) 49 | { 50 | n += p.print(_address[i], DEC); 51 | n += p.print('.'); 52 | } 53 | n += p.print(_address[3], DEC); 54 | return n; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/boards.txt: -------------------------------------------------------------------------------- 1 | # Spark Board Contribution Configuration 2 | # 3 | # For more information see: 4 | # * https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 5 | # * https://github.com/arduino/Arduino/wiki/Arduino-Hardware-Cores-migration-guide-from-1.0-to-1.6 6 | # 7 | 8 | menu.cpu=Processor 9 | 10 | ################################################################################ 11 | #################################### MaKey MaKey ############################### 12 | ################################################################################ 13 | makeymakey.name=SparkFun MaKey MaKey 14 | makeymakey.build.board=AVR_MAKEYMAKEY 15 | makeymakey.build.vid.0=0x1B4F 16 | makeymakey.build.pid.0=0x2B74 17 | makeymakey.build.vid.1=0x1B4F 18 | makeymakey.build.pid.1=0x2B75 19 | 20 | makeymakey.upload.tool=arduino:avrdude 21 | makeymakey.upload.protocol=avr109 22 | makeymakey.upload.maximum_size=28672 23 | makeymakey.upload.speed=57600 24 | makeymakey.upload.disable_flushing=true 25 | makeymakey.upload.use_1200bps_touch=true 26 | makeymakey.upload.wait_for_upload_port=true 27 | 28 | makeymakey.bootloader.low_fuses=0xFF 29 | makeymakey.bootloader.high_fuses=0xD8 30 | makeymakey.bootloader.extended_fuses=0xF8 31 | makeymakey.bootloader.file=caterina/Caterina-makey.hex 32 | makeymakey.bootloader.unlock_bits=0x3F 33 | makeymakey.bootloader.lock_bits=0x2F 34 | makeymakey.bootloader.tool=arduino:avrdude 35 | 36 | makeymakey.build.mcu=atmega32u4 37 | makeymakey.build.f_cpu=16000000L 38 | makeymakey.build.vid=0x1B4F 39 | makeymakey.build.pid=0x2B75 40 | makeymakey.build.usb_product="SparkFun MaKey MaKey" 41 | makeymakey.build.core=arduino:arduino 42 | makeymakey.build.variant=promicro 43 | makeymakey.build.extra_flags={build.usb_flags} 44 | makeymakey.build.usb_manufacturer="SparkFun Electronics" -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 28 | uint8_t value = 0; 29 | uint8_t i; 30 | 31 | for (i = 0; i < 8; ++i) { 32 | digitalWrite(clockPin, HIGH); 33 | if (bitOrder == LSBFIRST) 34 | value |= digitalRead(dataPin) << i; 35 | else 36 | value |= digitalRead(dataPin) << (7 - i); 37 | digitalWrite(clockPin, LOW); 38 | } 39 | return value; 40 | } 41 | 42 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 43 | { 44 | uint8_t i; 45 | 46 | for (i = 0; i < 8; i++) { 47 | if (bitOrder == LSBFIRST) 48 | digitalWrite(dataPin, !!(val & (1 << i))); 49 | else 50 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 51 | 52 | digitalWrite(clockPin, HIGH); 53 | digitalWrite(clockPin, LOW); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include "stdlib.h" 28 | } 29 | 30 | void randomSeed(unsigned int seed) 31 | { 32 | if (seed != 0) { 33 | srandom(seed); 34 | } 35 | } 36 | 37 | long random(long howbig) 38 | { 39 | if (howbig == 0) { 40 | return 0; 41 | } 42 | return random() % howbig; 43 | } 44 | 45 | long random(long howsmall, long howbig) 46 | { 47 | if (howsmall >= howbig) { 48 | return howsmall; 49 | } 50 | long diff = howbig - howsmall; 51 | return random(diff) + howsmall; 52 | } 53 | 54 | long map(long x, long in_min, long in_max, long out_min, long out_max) 55 | { 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 57 | } 58 | 59 | unsigned int makeWord(unsigned int w) { return w; } 60 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | */ 24 | 25 | #ifndef WiringPrivate_h 26 | #define WiringPrivate_h 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "Arduino.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C"{ 37 | #endif 38 | 39 | #ifndef cbi 40 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 41 | #endif 42 | #ifndef sbi 43 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 44 | #endif 45 | 46 | #define EXTERNAL_INT_0 0 47 | #define EXTERNAL_INT_1 1 48 | #define EXTERNAL_INT_2 2 49 | #define EXTERNAL_INT_3 3 50 | #define EXTERNAL_INT_4 4 51 | #define EXTERNAL_INT_5 5 52 | #define EXTERNAL_INT_6 6 53 | #define EXTERNAL_INT_7 7 54 | 55 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 56 | #define EXTERNAL_NUM_INTERRUPTS 8 57 | #elif defined(__AVR_ATmega1284P__) 58 | #define EXTERNAL_NUM_INTERRUPTS 3 59 | #else 60 | #define EXTERNAL_NUM_INTERRUPTS 2 61 | #endif 62 | 63 | typedef void (*voidFuncPtr)(void); 64 | 65 | #ifdef __cplusplus 66 | } // extern "C" 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/USBDesc.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* Copyright (c) 2011, Peter Barrett 4 | ** 5 | ** Permission to use, copy, modify, and/or distribute this software for 6 | ** any purpose with or without fee is hereby granted, provided that the 7 | ** above copyright notice and this permission notice appear in all copies. 8 | ** 9 | ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 12 | ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 13 | ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 15 | ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 16 | ** SOFTWARE. 17 | */ 18 | 19 | #define CDC_ENABLED 20 | #define HID_ENABLED 21 | 22 | 23 | #ifdef CDC_ENABLED 24 | #define CDC_INTERFACE_COUNT 2 25 | #define CDC_ENPOINT_COUNT 3 26 | #else 27 | #define CDC_INTERFACE_COUNT 0 28 | #define CDC_ENPOINT_COUNT 0 29 | #endif 30 | 31 | #ifdef HID_ENABLED 32 | #define HID_INTERFACE_COUNT 1 33 | #define HID_ENPOINT_COUNT 1 34 | #else 35 | #define HID_INTERFACE_COUNT 0 36 | #define HID_ENPOINT_COUNT 0 37 | #endif 38 | 39 | #define CDC_ACM_INTERFACE 0 // CDC ACM 40 | #define CDC_DATA_INTERFACE 1 // CDC Data 41 | #define CDC_FIRST_ENDPOINT 1 42 | #define CDC_ENDPOINT_ACM (CDC_FIRST_ENDPOINT) // CDC First 43 | #define CDC_ENDPOINT_OUT (CDC_FIRST_ENDPOINT+1) 44 | #define CDC_ENDPOINT_IN (CDC_FIRST_ENDPOINT+2) 45 | 46 | #define HID_INTERFACE (CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT) // HID Interface 47 | #define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT) 48 | #define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT) 49 | 50 | #define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT) 51 | 52 | #ifdef CDC_ENABLED 53 | #define CDC_RX CDC_ENDPOINT_OUT 54 | #define CDC_TX CDC_ENDPOINT_IN 55 | #endif 56 | 57 | #ifdef HID_ENABLED 58 | #define HID_TX HID_ENDPOINT_INT 59 | #endif 60 | 61 | #define IMANUFACTURER 1 62 | #define IPRODUCT 2 63 | 64 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/platform.txt: -------------------------------------------------------------------------------- 1 | # Spark Board Contribution Platform Configuration 2 | # 3 | # For more information see: 4 | # * https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification 5 | # * https://github.com/arduino/Arduino/wiki/Arduino-Hardware-Cores-migration-guide-from-1.0-to-1.6 6 | # 7 | name=SparkFun Boards 8 | version=1.0.0 9 | 10 | # AVR Uploader/Programmers tools 11 | # ------------------------------ 12 | tools.avrdude.path={runtime.tools.avrdude.path} 13 | tools.avrdude.cmd.path={path}/bin/avrdude 14 | tools.avrdude.config.path={runtime.platform.path}/avrdude.conf 15 | 16 | tools.avrdude.upload.params.verbose=-v 17 | tools.avrdude.upload.params.quiet=-q -q 18 | tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i" 19 | 20 | tools.avrdude.program.params.verbose=-v 21 | tools.avrdude.program.params.quiet=-q -q 22 | tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" 23 | 24 | tools.avrdude.erase.params.verbose=-v 25 | tools.avrdude.erase.params.quiet=-q -q 26 | tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m 27 | 28 | tools.avrdude.bootloader.params.verbose=-v 29 | tools.avrdude.bootloader.params.quiet=-q -q 30 | tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m 31 | 32 | # USB Default Flags 33 | # Default blank usb manufacturer will be filled it at compile time 34 | # - from numeric vendor ID, set to Unknown otherwise 35 | build.usb_manufacturer="Unknown" 36 | build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' 37 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 28 September 2010 by Mark Sproul 20 | */ 21 | 22 | #ifndef HardwareSerial_h 23 | #define HardwareSerial_h 24 | 25 | #include 26 | 27 | #include "Stream.h" 28 | 29 | struct ring_buffer; 30 | 31 | class HardwareSerial : public Stream 32 | { 33 | private: 34 | ring_buffer *_rx_buffer; 35 | ring_buffer *_tx_buffer; 36 | volatile uint8_t *_ubrrh; 37 | volatile uint8_t *_ubrrl; 38 | volatile uint8_t *_ucsra; 39 | volatile uint8_t *_ucsrb; 40 | volatile uint8_t *_udr; 41 | uint8_t _rxen; 42 | uint8_t _txen; 43 | uint8_t _rxcie; 44 | uint8_t _udrie; 45 | uint8_t _u2x; 46 | public: 47 | HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, 48 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 49 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 50 | volatile uint8_t *udr, 51 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x); 52 | void begin(unsigned long); 53 | void end(); 54 | virtual int available(void); 55 | virtual int peek(void); 56 | virtual int read(void); 57 | virtual void flush(void); 58 | virtual size_t write(uint8_t); 59 | using Print::write; // pull in write(str) and write(buf, size) from Print 60 | operator bool(); 61 | }; 62 | 63 | #if defined(UBRRH) || defined(UBRR0H) 64 | extern HardwareSerial Serial; 65 | #elif defined(USBCON) 66 | #include "USBAPI.h" 67 | // extern HardwareSerial Serial_; 68 | #endif 69 | #if defined(UBRR1H) 70 | extern HardwareSerial Serial1; 71 | #endif 72 | #if defined(UBRR2H) 73 | extern HardwareSerial Serial2; 74 | #endif 75 | #if defined(UBRR3H) 76 | extern HardwareSerial Serial3; 77 | #endif 78 | 79 | extern void serialEventRun(void) __attribute__((weak)); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | class Print 35 | { 36 | private: 37 | int write_error; 38 | size_t printNumber(unsigned long, uint8_t); 39 | size_t printFloat(double, uint8_t); 40 | protected: 41 | void setWriteError(int err = 1) { write_error = err; } 42 | public: 43 | Print() : write_error(0) {} 44 | 45 | int getWriteError() { return write_error; } 46 | void clearWriteError() { setWriteError(0); } 47 | 48 | virtual size_t write(uint8_t) = 0; 49 | size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); } 50 | virtual size_t write(const uint8_t *buffer, size_t size); 51 | 52 | size_t print(const __FlashStringHelper *); 53 | size_t print(const String &); 54 | size_t print(const char[]); 55 | size_t print(char); 56 | size_t print(unsigned char, int = DEC); 57 | size_t print(int, int = DEC); 58 | size_t print(unsigned int, int = DEC); 59 | size_t print(long, int = DEC); 60 | size_t print(unsigned long, int = DEC); 61 | size_t print(double, int = 2); 62 | size_t print(const Printable&); 63 | 64 | size_t println(const __FlashStringHelper *); 65 | size_t println(const String &s); 66 | size_t println(const char[]); 67 | size_t println(char); 68 | size_t println(unsigned char, int = DEC); 69 | size_t println(int, int = DEC); 70 | size_t println(unsigned int, int = DEC); 71 | size_t println(long, int = DEC); 72 | size_t println(unsigned long, int = DEC); 73 | size_t println(double, int = 2); 74 | size_t println(const Printable&); 75 | size_t println(void); 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 29 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 30 | * to 3 minutes in length, but must be called at least a few dozen microseconds 31 | * before the start of the pulse. */ 32 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 33 | { 34 | // cache the port and bit of the pin in order to speed up the 35 | // pulse width measuring loop and achieve finer resolution. calling 36 | // digitalRead() instead yields much coarser resolution. 37 | uint8_t bit = digitalPinToBitMask(pin); 38 | uint8_t port = digitalPinToPort(pin); 39 | uint8_t stateMask = (state ? bit : 0); 40 | unsigned long width = 0; // keep initialization out of time critical area 41 | 42 | // convert the timeout from microseconds to a number of times through 43 | // the initial loop; it takes 16 clock cycles per iteration. 44 | unsigned long numloops = 0; 45 | unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; 46 | 47 | // wait for any previous pulse to end 48 | while ((*portInputRegister(port) & bit) == stateMask) 49 | if (numloops++ == maxloops) 50 | return 0; 51 | 52 | // wait for the pulse to start 53 | while ((*portInputRegister(port) & bit) != stateMask) 54 | if (numloops++ == maxloops) 55 | return 0; 56 | 57 | // wait for the pulse to stop 58 | while ((*portInputRegister(port) & bit) == stateMask) { 59 | if (numloops++ == maxloops) 60 | return 0; 61 | width++; 62 | } 63 | 64 | // convert the reading to microseconds. The loop has been determined 65 | // to be 20 clock cycles long and have about 16 clocks between the edge 66 | // and the start of the loop. There will be some error introduced by 67 | // the interrupt handlers. 68 | return clockCyclesToMicroseconds(width * 21 + 16); 69 | } 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ############# 33 | ## Eagle 34 | ############# 35 | 36 | # Ignore the board and schematic backup files 37 | *.b#? 38 | *.s#? 39 | 40 | 41 | ################# 42 | ## Visual Studio 43 | ################# 44 | 45 | ## Ignore Visual Studio temporary files, build results, and 46 | ## files generated by popular Visual Studio add-ons. 47 | 48 | # User-specific files 49 | *.suo 50 | *.user 51 | *.sln.docstates 52 | 53 | # Build results 54 | [Dd]ebug/ 55 | [Rr]elease/ 56 | *_i.c 57 | *_p.c 58 | *.ilk 59 | *.meta 60 | *.obj 61 | *.pch 62 | *.pdb 63 | *.pgc 64 | *.pgd 65 | *.rsp 66 | *.sbr 67 | *.tlb 68 | *.tli 69 | *.tlh 70 | *.tmp 71 | *.vspscc 72 | .builds 73 | *.dotCover 74 | 75 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 76 | #packages/ 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opensdf 83 | *.sdf 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | 89 | # ReSharper is a .NET coding add-in 90 | _ReSharper* 91 | 92 | # Installshield output folder 93 | [Ee]xpress 94 | 95 | # DocProject is a documentation generator add-in 96 | DocProject/buildhelp/ 97 | DocProject/Help/*.HxT 98 | DocProject/Help/*.HxC 99 | DocProject/Help/*.hhc 100 | DocProject/Help/*.hhk 101 | DocProject/Help/*.hhp 102 | DocProject/Help/Html2 103 | DocProject/Help/html 104 | 105 | # Click-Once directory 106 | publish 107 | 108 | # Others 109 | [Bb]in 110 | [Oo]bj 111 | sql 112 | TestResults 113 | *.Cache 114 | ClientBin 115 | stylecop.* 116 | ~$* 117 | *.dbmdl 118 | Generated_Code #added for RIA/Silverlight projects 119 | 120 | # Backup & report files from converting an old project file to a newer 121 | # Visual Studio version. Backup files are not needed, because we have git ;-) 122 | _UpgradeReport_Files/ 123 | Backup*/ 124 | UpgradeLog*.XML 125 | 126 | 127 | ############ 128 | ## Windows 129 | ############ 130 | 131 | # Windows image file caches 132 | Thumbs.db 133 | 134 | # Folder config file 135 | Desktop.ini 136 | 137 | 138 | ############# 139 | ## Python 140 | ############# 141 | 142 | *.py[co] 143 | 144 | # Packages 145 | *.egg 146 | *.egg-info 147 | dist 148 | build 149 | eggs 150 | parts 151 | bin 152 | var 153 | sdist 154 | develop-eggs 155 | .installed.cfg 156 | 157 | # Installer logs 158 | pip-log.txt 159 | 160 | # Unit test / coverage reports 161 | .coverage 162 | .tox 163 | 164 | #Translations 165 | *.mo 166 | 167 | #Mr Developer 168 | .mr.developer.cfg 169 | 170 | # Mac crap 171 | .DS_Store 172 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Note: Retired Product** 2 | =========== 3 | 4 | This product has been retired from our catalog and is no longer for sale. This page is made available for those looking for datasheets and the simply curious. For the latest version of the board manufactured by JoyLabz, check out the [Makey Makey Classic by JoyLabz](https://www.sparkfun.com/products/14478). 5 | 6 | --- 7 | 8 | MaKey MaKey 9 | =========== 10 | 11 | [![MaKey MaKey](https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/5/1/1/11511-01b_medium.jpg) 12 | *MaKey MaKey - Standard Kit (WIG-11511)*](https://www.sparkfun.com/products/11511) 13 | 14 | Using the MaKey MaKey you can *make* anything into a *key* (get it?) just by connecting a few alligator clips. The MaKey MaKey is an invention kit that tricks your computer into thinking that almost anything is a keyboard. This allows you to hook up all kinds of fun things as an input. 15 | 16 | The MaKey MaKey uses high resistance switching to detect when you've made a connection even through materials that aren't very conductive (like leaves, pasta or people). This technique attracts noise on the input, so a moving window averager is used to lowpass the noise. The on-board ATMega32u4 communicates with your computer using the Human Interface Device (HID) protocol which means that it can act like a keyboard or mouse. 17 | 18 | Repository Contents 19 | ------------------- 20 | * **/Firmware** - Example firmware files 21 | * **/Hardware** - All Eagle design files (.brd, .sch) 22 | * **/Production** - Test bed files and production panel files 23 | 24 | Documentation 25 | -------------- 26 | * **[Makey Makey Quickstart Guide](https://learn.sparkfun.com/tutorials/makey-makey-quickstart-guide)** - Basic hookup guide for the Makey Makey. 27 | * **[Makey Makey Advanced Guide](https://learn.sparkfun.com/tutorials/makey-makey-advanced-guide)** - Advanced hookup guide for the Makey Makey. 28 | 29 | Product Versions 30 | ---------------- 31 | 32 | **[WIG-11511 (Retired)](https://www.sparkfun.com/products/11511) - Standard kit, OEM packaging** 33 | The standard kit includes the MaKey MaKey HID board, alligator clips, jumper wires, and a Mini-USB cable in OEM packaging. 34 | 35 | **[WIG-11519 (Retired)](https://www.sparkfun.com/products/11519) - Deluxe kit, OEM packaging** 36 | The deluxe kit includes everything found in the standard kit along with an additional pack of alligator clips and a roll of copper wire (all in OEM packaging). 37 | 38 | **[RTL-11437 (Retired)](https://www.sparkfun.com/products/11437) - Standard kit, retail packaging** 39 | This kit contains everything found in the standard kit and comes in retail-ready plastic packaging. 40 | 41 | License Information 42 | ------------------- 43 | The hardware is released under [Creative Commons ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). 44 | The code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 45 | 46 | Distributed as-is; no warranty is given. 47 | 48 | The MaKey MaKey is a collaboration with Jay Silver and Eric Rosenbaum. You can find more information about them [here](http://www.makeymakey.com/). 49 | 50 | Makey Makey is a registered trademark of JoyLabz LLC. 51 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/driver/MaKeyMaKey.inf: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright 2015 Arduino LLC (http://www.arduino.cc/) 3 | ; 4 | ; Developed by Zach Eveland, Blacklabel Development, Inc. 5 | ; 6 | ; Arduino is free software; you can redistribute it and/or modify 7 | ; it under the terms of the GNU General Public License as published by 8 | ; the Free Software Foundation; either version 2 of the License, or 9 | ; (at your option) any later version. 10 | ; 11 | ; This program is distributed in the hope that it will be useful, 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ; GNU General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU General Public License 17 | ; along with this program; if not, write to the Free Software 18 | ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | ; 20 | ; As a special exception, you may use this file as part of a free software 21 | ; library without restriction. Specifically, if other files instantiate 22 | ; templates or use macros or inline functions from this file, or you compile 23 | ; this file and link it with other files to produce an executable, this 24 | ; file does not by itself cause the resulting executable to be covered by 25 | ; the GNU General Public License. This exception does not however 26 | ; invalidate any other reasons why the executable file might be covered by 27 | ; the GNU General Public License. 28 | ; 29 | 30 | [Strings] 31 | DriverPackageDisplayName="MaKey MaKey USB Driver" 32 | ManufacturerName="SparkFun Electronics" 33 | ServiceName="USB RS-232 Emulation Driver" 34 | MaKeyMaKey.bootloader.name="MaKey MaKey bootloader" 35 | MaKeyMaKey.sketch.name="MaKey MaKey" 36 | 37 | [DefaultInstall] 38 | CopyINF=MaKeyMaKey.inf 39 | 40 | [Version] 41 | Class=Ports 42 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 43 | Signature="$Windows NT$" 44 | Provider=%ManufacturerName% 45 | DriverPackageDisplayName=%DriverPackageDisplayName% 46 | CatalogFile=MaKeyMaKey.cat 47 | DriverVer=08/27/2015,1.0.0.0 48 | 49 | [Manufacturer] 50 | %ManufacturerName%=DeviceList, NTamd64, NTia64 51 | 52 | [DestinationDirs] 53 | FakeModemCopyFileSection=12 54 | DefaultDestDir=12 55 | 56 | [DeviceList] 57 | %MaKeyMaKey.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_2B74 58 | %MaKeyMaKey.sketch.name%=DriverInstall, USB\VID_1B4F&PID_2B75&MI_00 59 | 60 | [DeviceList.NTamd64] 61 | %MaKeyMaKey.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_2B74 62 | %MaKeyMaKey.sketch.name%=DriverInstall, USB\VID_1B4F&PID_2B75&MI_00 63 | 64 | [DeviceList.NTia64] 65 | %MaKeyMaKey.bootloader.name%=DriverInstall, USB\VID_1B4F&PID_2B74 66 | %MaKeyMaKey.sketch.name%=DriverInstall, USB\VID_1B4F&PID_2B75&MI_00 67 | 68 | [DriverInstall] 69 | include=mdmcpq.inf,usb.inf 70 | CopyFiles = FakeModemCopyFileSection 71 | AddReg=DriverAddReg 72 | 73 | [DriverAddReg] 74 | HKR,,DevLoader,,*ntkern 75 | HKR,,NTMPDriver,,usbser.sys 76 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 77 | 78 | [DriverInstall.Services] 79 | include=mdmcpq.inf 80 | AddService=usbser, 0x00000002, DriverService 81 | 82 | [DriverService] 83 | DisplayName=%ServiceName% 84 | ServiceType=1 85 | StartType=3 86 | ErrorControl=1 87 | ServiceBinary=%12%\usbser.sys 88 | LoadOrderGroup=Base 89 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * MIT License: 4 | * Copyright (c) 2011 Adrian McEwen 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | * 23 | * adrianm@mcqn.com 1/1/2011 24 | */ 25 | 26 | #ifndef IPAddress_h 27 | #define IPAddress_h 28 | 29 | #include 30 | 31 | // A class to make it easier to handle and pass around IP addresses 32 | 33 | class IPAddress : public Printable { 34 | private: 35 | uint8_t _address[4]; // IPv4 address 36 | // Access the raw byte array containing the address. Because this returns a pointer 37 | // to the internal structure rather than a copy of the address this function should only 38 | // be used when you know that the usage of the returned uint8_t* will be transient and not 39 | // stored. 40 | uint8_t* raw_address() { return _address; }; 41 | 42 | public: 43 | // Constructors 44 | IPAddress(); 45 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 46 | IPAddress(uint32_t address); 47 | IPAddress(const uint8_t *address); 48 | 49 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 50 | // to a four-byte uint8_t array is expected 51 | operator uint32_t() { return *((uint32_t*)_address); }; 52 | bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; 53 | bool operator==(const uint8_t* addr); 54 | 55 | // Overloaded index operator to allow getting and setting individual octets of the address 56 | uint8_t operator[](int index) const { return _address[index]; }; 57 | uint8_t& operator[](int index) { return _address[index]; }; 58 | 59 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 60 | IPAddress& operator=(const uint8_t *address); 61 | IPAddress& operator=(uint32_t address); 62 | 63 | virtual size_t printTo(Print& p) const; 64 | 65 | friend class EthernetClass; 66 | friend class UDP; 67 | friend class Client; 68 | friend class Server; 69 | friend class DhcpClass; 70 | friend class DNSClient; 71 | }; 72 | 73 | const IPAddress INADDR_NONE(0,0,0,0); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/bootloaders/caterina/Caterina.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2011. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * 33 | * Header file for BootloaderCDC.c. 34 | */ 35 | 36 | #ifndef _CDC_H_ 37 | #define _CDC_H_ 38 | 39 | /* Includes: */ 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "Descriptors.h" 49 | 50 | #include 51 | /* Macros: */ 52 | /** Version major of the CDC bootloader. */ 53 | #define BOOTLOADER_VERSION_MAJOR 0x01 54 | 55 | /** Version minor of the CDC bootloader. */ 56 | #define BOOTLOADER_VERSION_MINOR 0x00 57 | 58 | /** Hardware version major of the CDC bootloader. */ 59 | #define BOOTLOADER_HWVERSION_MAJOR 0x01 60 | 61 | /** Hardware version minor of the CDC bootloader. */ 62 | #define BOOTLOADER_HWVERSION_MINOR 0x00 63 | 64 | /** Eight character bootloader firmware identifier reported to the host when requested */ 65 | #define SOFTWARE_IDENTIFIER "CATERINA" 66 | 67 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) 68 | #define LED_SETUP() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5); 69 | #define L_LED_OFF() PORTC &= ~(1<<7) 70 | #define L_LED_ON() PORTC |= (1<<7) 71 | #define L_LED_TOGGLE() PORTC ^= (1<<7) 72 | #define TX_LED_OFF() PORTD |= (1<<5) 73 | #define TX_LED_ON() PORTD &= ~(1<<5) 74 | #define RX_LED_OFF() PORTB |= (1<<0) 75 | #define RX_LED_ON() PORTB &= ~(1<<0) 76 | 77 | /* Type Defines: */ 78 | /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */ 79 | typedef void (*AppPtr_t)(void) ATTR_NO_RETURN; 80 | 81 | /* Function Prototypes: */ 82 | void StartSketch(void); 83 | void LEDPulse(void); 84 | 85 | void CDC_Task(void); 86 | void SetupHardware(void); 87 | 88 | void EVENT_USB_Device_ConfigurationChanged(void); 89 | 90 | #if defined(INCLUDE_FROM_CATERINA_C) || defined(__DOXYGEN__) 91 | #if !defined(NO_BLOCK_SUPPORT) 92 | static void ReadWriteMemoryBlock(const uint8_t Command); 93 | #endif 94 | static uint8_t FetchNextCommandByte(void); 95 | static void WriteNextResponseByte(const uint8_t Response); 96 | #endif 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/readme.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------ 2 | | MaKey MaKey Arduino Addon (updated August 9, 2012) | 3 | ------------------------------------------------------ 4 | 5 | This Arduino addon for the MaKey MaKey creates an Arduino Board menu option for the MaKey MaKey. 6 | 7 | ------------------------------------------------- 8 | | Installing the Arduino Addon | 9 | ------------------------------------------------- 10 | 11 | To install this addon, unzip the "MaKeyMaKey" folder into a "hardware" folder withing your Arduino sketchbook. If you don't know where your sketchbook is located, you can find it's location by going to File > Preferences within Arduino. 12 | 13 | For Windows XP users, the sketchbook is usually located in your "My Documents/Arduino" directory. So once unzipped, this readme should reside in "My Documents/Arduino/hardware/ProMicro". Windows 7, by default, is something like: C:\Users\\Arduino\hardware\ProMicro. 14 | 15 | Once unzipped, close any Arduino windows and reopen. The following board should be listed in the Tools > Board menu now: 16 | MaKey MaKey 17 | 18 | Important: Though the new bootloader is Leonardo-compatible, DO NOT select "Arduino Leonardo" from the Tools > Board menu before uploading code to the MaKey MaKey. Because the MaKey MaKey runs at 8MHz, the sketch uploaded to the board must be configured for that same speed. 19 | 20 | 21 | ------------------------------------------------- 22 | | Installing the Drivers (Windows only) | 23 | ------------------------------------------------- 24 | Windows users will need to install drivers the first time you connect the MaKey MaKey. Usually a New Hardware Wizard will pop up, you'll need to direct it to the included "Drivers" folder. The driver is "MaKey MaKey.inf". 25 | 26 | The included driver should work for MaKey MaKey's with the Sparkfun VID/PID: 0x1B4F/0x2B74 (bootloader) and 0x2B75 (sketch)). 27 | 28 | 29 | ------------------------------------------------- 30 | | What files are included? | 31 | ------------------------------------------------- 32 | 33 | This addon should work with no need to modify files. If you're curious what we've done to the default Arduino files though, read on... 34 | 35 | * bootloaders/caterina: This is a slightly modified version of the Caterina bootloader, which is used in the Arduino Leonardo. Defines were modified so the VID and PID were set to SparkFun-specific values (VID: 0x1B4F, PIDs: 0xF100/F101 [get it?!]). To compile this, you'll need to download LUFA, and point the makefile to that directory. 36 | 37 | To compile the bootloader for a MaKey MaKey, you must first set F_CPU and PID near the top of the makefile. F_CPU should be 16000000. PID should be 2B74. 38 | 39 | This directory also includes Caterina-makeymakey.hex which is the compiled images of the MaKey MaKey's bootloader. It won't be deleted after running a 'make clean'. 40 | 41 | * cores/arduino: This is a mostly unchanged listing of all the core files required by the MaKey MaKey to compile under Arduino. The files with changes are: 42 | USBCore.cpp: added conditional statement for seting PLLCSR. 43 | 44 | * variants/makeymakey: This is mostly identical to the Leonardo pins_arduino.h. There is a slight change to the RX and TX LED macros, because the LEDs are biased towards ground, instead of VCC, we had to flop those macros. 45 | 46 | * boards.txt: This file is what Arduino looks at when populating its Tools > Board menu. 47 | The "MaKey MaKey" will be added to the Tools > Board menu. 48 | 49 | This also defines a few variables such as clock frequency, USB VID and PID, fuses, and bootloader location. 50 | 51 | ------------------------------------------------- 52 | | Questions, Comments, Concerns? | 53 | ------------------------------------------------- 54 | 55 | Please let us know if this gives you any problems. You can contact our tech support team (techsupport@sparkfun.com), or post a comment on the product page (or even contact me by email, I'd be happy to help) and we'll try to get back to you as quickly as possible. 56 | 57 | Have fun! 58 | -Jim (jim at sparkfun.com) -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | parsing functions based on TextFinder library by Michael Margolis 20 | */ 21 | 22 | #ifndef Stream_h 23 | #define Stream_h 24 | 25 | #include 26 | #include "Print.h" 27 | 28 | // compatability macros for testing 29 | /* 30 | #define getInt() parseInt() 31 | #define getInt(skipChar) parseInt(skipchar) 32 | #define getFloat() parseFloat() 33 | #define getFloat(skipChar) parseFloat(skipChar) 34 | #define getString( pre_string, post_string, buffer, length) 35 | readBytesBetween( pre_string, terminator, buffer, length) 36 | */ 37 | 38 | class Stream : public Print 39 | { 40 | private: 41 | unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read 42 | unsigned long _startMillis; // used for timeout measurement 43 | int timedRead(); // private method to read stream with timeout 44 | int timedPeek(); // private method to peek stream with timeout 45 | int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout 46 | 47 | public: 48 | virtual int available() = 0; 49 | virtual int read() = 0; 50 | virtual int peek() = 0; 51 | virtual void flush() = 0; 52 | 53 | Stream() {_timeout=1000;} 54 | 55 | // parsing methods 56 | 57 | void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second 58 | 59 | bool find(char *target); // reads data from the stream until the target string is found 60 | // returns true if target string is found, false if timed out (see setTimeout) 61 | 62 | bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found 63 | // returns true if target string is found, false if timed out 64 | 65 | bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found 66 | 67 | bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found 68 | 69 | 70 | long parseInt(); // returns the first valid (long) integer value from the current position. 71 | // initial characters that are not digits (or the minus sign) are skipped 72 | // integer is terminated by the first character that is not a digit. 73 | 74 | float parseFloat(); // float version of parseInt 75 | 76 | size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer 77 | // terminates if length characters have been read or timeout (see setTimeout) 78 | // returns the number of characters placed in the buffer (0 means no valid data found) 79 | 80 | size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character 81 | // terminates if length characters have been read, timeout, or if the terminator character detected 82 | // returns the number of characters placed in the buffer (0 means no valid data found) 83 | 84 | // Arduino String functions to be added here 85 | String readString(); 86 | String readStringUntil(char terminator); 87 | 88 | protected: 89 | long parseInt(char skipChar); // as above but the given skipChar is ignored 90 | // as above but the given skipChar is ignored 91 | // this allows format characters (typically commas) in values to be ignored 92 | 93 | float parseFloat(char skipChar); // as above but the given skipChar is ignored 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Udp.cpp: Library to send/receive UDP packets. 3 | * 4 | * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these) 5 | * 1) UDP does not guarantee the order in which assembled UDP packets are received. This 6 | * might not happen often in practice, but in larger network topologies, a UDP 7 | * packet can be received out of sequence. 8 | * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being 9 | * aware of it. Again, this may not be a concern in practice on small local networks. 10 | * For more information, see http://www.cafeaulait.org/course/week12/35.html 11 | * 12 | * MIT License: 13 | * Copyright (c) 2008 Bjoern Hartmann 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * bjoern@cs.stanford.edu 12/30/2008 33 | */ 34 | 35 | #ifndef udp_h 36 | #define udp_h 37 | 38 | #include 39 | #include 40 | 41 | class UDP : public Stream { 42 | 43 | public: 44 | virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 45 | virtual void stop() =0; // Finish with the UDP socket 46 | 47 | // Sending UDP packets 48 | 49 | // Start building up a packet to send to the remote host specific in ip and port 50 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 51 | virtual int beginPacket(IPAddress ip, uint16_t port) =0; 52 | // Start building up a packet to send to the remote host specific in host and port 53 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 54 | virtual int beginPacket(const char *host, uint16_t port) =0; 55 | // Finish off this packet and send it 56 | // Returns 1 if the packet was sent successfully, 0 if there was an error 57 | virtual int endPacket() =0; 58 | // Write a single byte into the packet 59 | virtual size_t write(uint8_t) =0; 60 | // Write size bytes from buffer into the packet 61 | virtual size_t write(const uint8_t *buffer, size_t size) =0; 62 | 63 | // Start processing the next available incoming packet 64 | // Returns the size of the packet in bytes, or 0 if no packets are available 65 | virtual int parsePacket() =0; 66 | // Number of bytes remaining in the current packet 67 | virtual int available() =0; 68 | // Read a single byte from the current packet 69 | virtual int read() =0; 70 | // Read up to len bytes from the current packet and place them into buffer 71 | // Returns the number of bytes read, or 0 if none are available 72 | virtual int read(unsigned char* buffer, size_t len) =0; 73 | // Read up to len characters from the current packet and place them into buffer 74 | // Returns the number of characters read, or 0 if none are available 75 | virtual int read(char* buffer, size_t len) =0; 76 | // Return the next byte from the current packet without moving on to the next byte 77 | virtual int peek() =0; 78 | virtual void flush() =0; // Finish reading the current packet 79 | 80 | // Return the IP address of the host who sent the current incoming packet 81 | virtual IPAddress remoteIP() =0; 82 | // Return the port of the host who sent the current incoming packet 83 | virtual uint16_t remotePort() =0; 84 | protected: 85 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /firmware/Arduino/makey_makey/settings.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | /* 4 | ///////////////////////////////////////////////////////////////////////// 5 | // KEY MAPPINGS: WHICH KEY MAPS TO WHICH PIN ON THE MAKEY MAKEY BOARD? // 6 | ///////////////////////////////////////////////////////////////////////// 7 | 8 | - edit the keyCodes array below to change the keys sent by the MaKey MaKey for each input 9 | - the comments tell you which input sends that key (for example, by default 'w' is sent by pin D5) 10 | - change the keys by replacing them. for example, you can replace 'w' with any other individual letter, 11 | number, or symbol on your keyboard 12 | - you can also use codes for other keys such as modifier and function keys (see the 13 | the list of additional key codes at the bottom of this file) 14 | 15 | */ 16 | 17 | int keyCodes[NUM_INPUTS] = { 18 | // top side of the makey makey board 19 | 20 | KEY_UP_ARROW, // up arrow pad 21 | KEY_DOWN_ARROW, // down arrow pad 22 | KEY_LEFT_ARROW, // left arrow pad 23 | KEY_RIGHT_ARROW, // right arrow pad 24 | ' ', // space button pad 25 | MOUSE_LEFT, // click button pad 26 | 27 | // female header on the back left side 28 | 29 | 'w', // pin D5 30 | 'a', // pin D4 31 | 's', // pin D3 32 | 'd', // pin D2 33 | 'f', // pin D1 34 | 'g', // pin D0 35 | 36 | // female header on the back right side 37 | 38 | MOUSE_MOVE_UP, // pin A5 39 | MOUSE_MOVE_DOWN, // pin A4 40 | MOUSE_MOVE_LEFT, // pin A3 41 | MOUSE_MOVE_RIGHT, // pin A2 42 | MOUSE_LEFT, // pin A1 43 | MOUSE_RIGHT // pin A0 44 | }; 45 | 46 | /////////////////////////// 47 | // NOISE CANCELLATION ///// 48 | /////////////////////////// 49 | #define SWITCH_THRESHOLD_OFFSET_PERC 5 // number between 1 and 49 50 | // larger value protects better against noise oscillations, but makes it harder to press and release 51 | // recommended values are between 2 and 20 52 | // default value is 5 53 | 54 | #define SWITCH_THRESHOLD_CENTER_BIAS 55 // number between 1 and 99 55 | // larger value makes it easier to "release" keys, but harder to "press" 56 | // smaller value makes it easier to "press" keys, but harder to "release" 57 | // recommended values are between 30 and 70 58 | // 50 is "middle" 2.5 volt center 59 | // default value is 55 60 | // 100 = 5V (never use this high) 61 | // 0 = 0 V (never use this low 62 | 63 | 64 | ///////////////////////// 65 | // MOUSE MOTION ///////// 66 | ///////////////////////// 67 | #define MOUSE_MOTION_UPDATE_INTERVAL 35 // how many loops to wait between 68 | // sending mouse motion updates 69 | 70 | #define PIXELS_PER_MOUSE_STEP 4 // a larger number will make the mouse 71 | // move faster 72 | 73 | #define MOUSE_RAMP_SCALE 150 // Scaling factor for mouse movement ramping 74 | // Lower = more sensitive mouse movement 75 | // Higher = slower ramping of speed 76 | // 0 = Ramping off 77 | 78 | #define MOUSE_MAX_PIXELS 10 // Max pixels per step for mouse movement 79 | 80 | /* 81 | 82 | /////////////////////////// 83 | // ADDITIONAL KEY CODES /// 84 | /////////////////////////// 85 | 86 | - you can use these codes in the keyCodes array above 87 | - to get modifier keys, function keys, etc 88 | 89 | KEY_LEFT_CTRL 90 | KEY_LEFT_SHIFT 91 | KEY_LEFT_ALT 92 | KEY_LEFT_GUI 93 | KEY_RIGHT_CTRL 94 | KEY_RIGHT_SHIFT 95 | KEY_RIGHT_ALT 96 | KEY_RIGHT_GUI 97 | 98 | KEY_BACKSPACE 99 | KEY_TAB 100 | KEY_RETURN 101 | KEY_ESC 102 | KEY_INSERT 103 | KEY_DELETE 104 | KEY_PAGE_UP 105 | KEY_PAGE_DOWN 106 | KEY_HOME 107 | KEY_END 108 | KEY_CAPS_LOCK 109 | 110 | KEY_F1 111 | KEY_F2 112 | KEY_F3 113 | KEY_F4 114 | KEY_F5 115 | KEY_F6 116 | KEY_F7 117 | KEY_F8 118 | KEY_F9 119 | KEY_F10 120 | KEY_F11 121 | KEY_F12 122 | 123 | */ 124 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 24 | 25 | // WCharacter.h prototypes 26 | inline boolean isAlphaNumeric(int c) __attribute__((always_inline)); 27 | inline boolean isAlpha(int c) __attribute__((always_inline)); 28 | inline boolean isAscii(int c) __attribute__((always_inline)); 29 | inline boolean isWhitespace(int c) __attribute__((always_inline)); 30 | inline boolean isControl(int c) __attribute__((always_inline)); 31 | inline boolean isDigit(int c) __attribute__((always_inline)); 32 | inline boolean isGraph(int c) __attribute__((always_inline)); 33 | inline boolean isLowerCase(int c) __attribute__((always_inline)); 34 | inline boolean isPrintable(int c) __attribute__((always_inline)); 35 | inline boolean isPunct(int c) __attribute__((always_inline)); 36 | inline boolean isSpace(int c) __attribute__((always_inline)); 37 | inline boolean isUpperCase(int c) __attribute__((always_inline)); 38 | inline boolean isHexadecimalDigit(int c) __attribute__((always_inline)); 39 | inline int toAscii(int c) __attribute__((always_inline)); 40 | inline int toLowerCase(int c) __attribute__((always_inline)); 41 | inline int toUpperCase(int c)__attribute__((always_inline)); 42 | 43 | 44 | // Checks for an alphanumeric character. 45 | // It is equivalent to (isalpha(c) || isdigit(c)). 46 | inline boolean isAlphaNumeric(int c) 47 | { 48 | return ( isalnum(c) == 0 ? false : true); 49 | } 50 | 51 | 52 | // Checks for an alphabetic character. 53 | // It is equivalent to (isupper(c) || islower(c)). 54 | inline boolean isAlpha(int c) 55 | { 56 | return ( isalpha(c) == 0 ? false : true); 57 | } 58 | 59 | 60 | // Checks whether c is a 7-bit unsigned char value 61 | // that fits into the ASCII character set. 62 | inline boolean isAscii(int c) 63 | { 64 | return ( isascii (c) == 0 ? false : true); 65 | } 66 | 67 | 68 | // Checks for a blank character, that is, a space or a tab. 69 | inline boolean isWhitespace(int c) 70 | { 71 | return ( isblank (c) == 0 ? false : true); 72 | } 73 | 74 | 75 | // Checks for a control character. 76 | inline boolean isControl(int c) 77 | { 78 | return ( iscntrl (c) == 0 ? false : true); 79 | } 80 | 81 | 82 | // Checks for a digit (0 through 9). 83 | inline boolean isDigit(int c) 84 | { 85 | return ( isdigit (c) == 0 ? false : true); 86 | } 87 | 88 | 89 | // Checks for any printable character except space. 90 | inline boolean isGraph(int c) 91 | { 92 | return ( isgraph (c) == 0 ? false : true); 93 | } 94 | 95 | 96 | // Checks for a lower-case character. 97 | inline boolean isLowerCase(int c) 98 | { 99 | return (islower (c) == 0 ? false : true); 100 | } 101 | 102 | 103 | // Checks for any printable character including space. 104 | inline boolean isPrintable(int c) 105 | { 106 | return ( isprint (c) == 0 ? false : true); 107 | } 108 | 109 | 110 | // Checks for any printable character which is not a space 111 | // or an alphanumeric character. 112 | inline boolean isPunct(int c) 113 | { 114 | return ( ispunct (c) == 0 ? false : true); 115 | } 116 | 117 | 118 | // Checks for white-space characters. For the avr-libc library, 119 | // these are: space, formfeed ('\f'), newline ('\n'), carriage 120 | // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). 121 | inline boolean isSpace(int c) 122 | { 123 | return ( isspace (c) == 0 ? false : true); 124 | } 125 | 126 | 127 | // Checks for an uppercase letter. 128 | inline boolean isUpperCase(int c) 129 | { 130 | return ( isupper (c) == 0 ? false : true); 131 | } 132 | 133 | 134 | // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 135 | // 8 9 a b c d e f A B C D E F. 136 | inline boolean isHexadecimalDigit(int c) 137 | { 138 | return ( isxdigit (c) == 0 ? false : true); 139 | } 140 | 141 | 142 | // Converts c to a 7-bit unsigned char value that fits into the 143 | // ASCII character set, by clearing the high-order bits. 144 | inline int toAscii(int c) 145 | { 146 | return toascii (c); 147 | } 148 | 149 | 150 | // Warning: 151 | // Many people will be unhappy if you use this function. 152 | // This function will convert accented letters into random 153 | // characters. 154 | 155 | // Converts the letter c to lower case, if possible. 156 | inline int toLowerCase(int c) 157 | { 158 | return tolower (c); 159 | } 160 | 161 | 162 | // Converts the letter c to upper case, if possible. 163 | inline int toUpperCase(int c) 164 | { 165 | return toupper (c); 166 | } 167 | 168 | #endif -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 28 September 2010 by Mark Sproul 23 | 24 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 25 | */ 26 | 27 | #define ARDUINO_MAIN 28 | #include "wiring_private.h" 29 | #include "pins_arduino.h" 30 | 31 | void pinMode(uint8_t pin, uint8_t mode) 32 | { 33 | uint8_t bit = digitalPinToBitMask(pin); 34 | uint8_t port = digitalPinToPort(pin); 35 | volatile uint8_t *reg, *out; 36 | 37 | if (port == NOT_A_PIN) return; 38 | 39 | // JWS: can I let the optimizer do this? 40 | reg = portModeRegister(port); 41 | out = portOutputRegister(port); 42 | 43 | if (mode == INPUT) { 44 | uint8_t oldSREG = SREG; 45 | cli(); 46 | *reg &= ~bit; 47 | *out &= ~bit; 48 | SREG = oldSREG; 49 | } else if (mode == INPUT_PULLUP) { 50 | uint8_t oldSREG = SREG; 51 | cli(); 52 | *reg &= ~bit; 53 | *out |= bit; 54 | SREG = oldSREG; 55 | } else { 56 | uint8_t oldSREG = SREG; 57 | cli(); 58 | *reg |= bit; 59 | SREG = oldSREG; 60 | } 61 | } 62 | 63 | // Forcing this inline keeps the callers from having to push their own stuff 64 | // on the stack. It is a good performance win and only takes 1 more byte per 65 | // user than calling. (It will take more bytes on the 168.) 66 | // 67 | // But shouldn't this be moved into pinMode? Seems silly to check and do on 68 | // each digitalread or write. 69 | // 70 | // Mark Sproul: 71 | // - Removed inline. Save 170 bytes on atmega1280 72 | // - changed to a switch statment; added 32 bytes but much easier to read and maintain. 73 | // - Added more #ifdefs, now compiles for atmega645 74 | // 75 | //static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline)); 76 | //static inline void turnOffPWM(uint8_t timer) 77 | static void turnOffPWM(uint8_t timer) 78 | { 79 | switch (timer) 80 | { 81 | #if defined(TCCR1A) && defined(COM1A1) 82 | case TIMER1A: cbi(TCCR1A, COM1A1); break; 83 | #endif 84 | #if defined(TCCR1A) && defined(COM1B1) 85 | case TIMER1B: cbi(TCCR1A, COM1B1); break; 86 | #endif 87 | 88 | #if defined(TCCR2) && defined(COM21) 89 | case TIMER2: cbi(TCCR2, COM21); break; 90 | #endif 91 | 92 | #if defined(TCCR0A) && defined(COM0A1) 93 | case TIMER0A: cbi(TCCR0A, COM0A1); break; 94 | #endif 95 | 96 | #if defined(TIMER0B) && defined(COM0B1) 97 | case TIMER0B: cbi(TCCR0A, COM0B1); break; 98 | #endif 99 | #if defined(TCCR2A) && defined(COM2A1) 100 | case TIMER2A: cbi(TCCR2A, COM2A1); break; 101 | #endif 102 | #if defined(TCCR2A) && defined(COM2B1) 103 | case TIMER2B: cbi(TCCR2A, COM2B1); break; 104 | #endif 105 | 106 | #if defined(TCCR3A) && defined(COM3A1) 107 | case TIMER3A: cbi(TCCR3A, COM3A1); break; 108 | #endif 109 | #if defined(TCCR3A) && defined(COM3B1) 110 | case TIMER3B: cbi(TCCR3A, COM3B1); break; 111 | #endif 112 | #if defined(TCCR3A) && defined(COM3C1) 113 | case TIMER3C: cbi(TCCR3A, COM3C1); break; 114 | #endif 115 | 116 | #if defined(TCCR4A) && defined(COM4A1) 117 | case TIMER4A: cbi(TCCR4A, COM4A1); break; 118 | #endif 119 | #if defined(TCCR4A) && defined(COM4B1) 120 | case TIMER4B: cbi(TCCR4A, COM4B1); break; 121 | #endif 122 | #if defined(TCCR4A) && defined(COM4C1) 123 | case TIMER4C: cbi(TCCR4A, COM4C1); break; 124 | #endif 125 | #if defined(TCCR4C) && defined(COM4D1) 126 | case TIMER4D: cbi(TCCR4C, COM4D1); break; 127 | #endif 128 | 129 | #if defined(TCCR5A) 130 | case TIMER5A: cbi(TCCR5A, COM5A1); break; 131 | case TIMER5B: cbi(TCCR5A, COM5B1); break; 132 | case TIMER5C: cbi(TCCR5A, COM5C1); break; 133 | #endif 134 | } 135 | } 136 | 137 | void digitalWrite(uint8_t pin, uint8_t val) 138 | { 139 | uint8_t timer = digitalPinToTimer(pin); 140 | uint8_t bit = digitalPinToBitMask(pin); 141 | uint8_t port = digitalPinToPort(pin); 142 | volatile uint8_t *out; 143 | 144 | if (port == NOT_A_PIN) return; 145 | 146 | // If the pin that support PWM output, we need to turn it off 147 | // before doing a digital write. 148 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 149 | 150 | out = portOutputRegister(port); 151 | 152 | uint8_t oldSREG = SREG; 153 | cli(); 154 | 155 | if (val == LOW) { 156 | *out &= ~bit; 157 | } else { 158 | *out |= bit; 159 | } 160 | 161 | SREG = oldSREG; 162 | } 163 | 164 | int digitalRead(uint8_t pin) 165 | { 166 | uint8_t timer = digitalPinToTimer(pin); 167 | uint8_t bit = digitalPinToBitMask(pin); 168 | uint8_t port = digitalPinToPort(pin); 169 | 170 | if (port == NOT_A_PIN) return LOW; 171 | 172 | // If the pin that support PWM output, we need to turn it off 173 | // before getting a digital reading. 174 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 175 | 176 | if (*portInputRegister(port) & bit) return HIGH; 177 | return LOW; 178 | } 179 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/bootloaders/caterina/Descriptors.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2011. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * 33 | * Header file for Descriptors.c. 34 | */ 35 | 36 | #ifndef _DESCRIPTORS_H_ 37 | #define _DESCRIPTORS_H_ 38 | 39 | /* Includes: */ 40 | #include 41 | 42 | /* Macros: */ 43 | #if defined(__AVR_AT90USB1287__) 44 | #define AVR_SIGNATURE_1 0x1E 45 | #define AVR_SIGNATURE_2 0x97 46 | #define AVR_SIGNATURE_3 0x82 47 | #elif defined(__AVR_AT90USB647__) 48 | #define AVR_SIGNATURE_1 0x1E 49 | #define AVR_SIGNATURE_2 0x96 50 | #define AVR_SIGNATURE_3 0x82 51 | #elif defined(__AVR_AT90USB1286__) 52 | #define AVR_SIGNATURE_1 0x1E 53 | #define AVR_SIGNATURE_2 0x97 54 | #define AVR_SIGNATURE_3 0x82 55 | #elif defined(__AVR_AT90USB646__) 56 | #define AVR_SIGNATURE_1 0x1E 57 | #define AVR_SIGNATURE_2 0x96 58 | #define AVR_SIGNATURE_3 0x82 59 | #elif defined(__AVR_ATmega32U6__) 60 | #define AVR_SIGNATURE_1 0x1E 61 | #define AVR_SIGNATURE_2 0x95 62 | #define AVR_SIGNATURE_3 0x88 63 | #elif defined(__AVR_ATmega32U4__) 64 | #define AVR_SIGNATURE_1 0x1E 65 | #define AVR_SIGNATURE_2 0x95 66 | #define AVR_SIGNATURE_3 0x87 67 | #elif defined(__AVR_ATmega16U4__) 68 | #define AVR_SIGNATURE_1 0x1E 69 | #define AVR_SIGNATURE_2 0x94 70 | #define AVR_SIGNATURE_3 0x88 71 | #elif defined(__AVR_ATmega32U2__) 72 | #define AVR_SIGNATURE_1 0x1E 73 | #define AVR_SIGNATURE_2 0x95 74 | #define AVR_SIGNATURE_3 0x8A 75 | #elif defined(__AVR_ATmega16U2__) 76 | #define AVR_SIGNATURE_1 0x1E 77 | #define AVR_SIGNATURE_2 0x94 78 | #define AVR_SIGNATURE_3 0x89 79 | #elif defined(__AVR_AT90USB162__) 80 | #define AVR_SIGNATURE_1 0x1E 81 | #define AVR_SIGNATURE_2 0x94 82 | #define AVR_SIGNATURE_3 0x82 83 | #elif defined(__AVR_ATmega8U2__) 84 | #define AVR_SIGNATURE_1 0x1E 85 | #define AVR_SIGNATURE_2 0x93 86 | #define AVR_SIGNATURE_3 0x89 87 | #elif defined(__AVR_AT90USB82__) 88 | #define AVR_SIGNATURE_1 0x1E 89 | #define AVR_SIGNATURE_2 0x94 90 | #define AVR_SIGNATURE_3 0x82 91 | #else 92 | #error The selected AVR part is not currently supported by this bootloader. 93 | #endif 94 | 95 | /** Endpoint number for the CDC control interface event notification endpoint. */ 96 | #define CDC_NOTIFICATION_EPNUM 2 97 | 98 | /** Endpoint number for the CDC data interface TX (data IN) endpoint. */ 99 | #define CDC_TX_EPNUM 3 100 | 101 | /** Endpoint number for the CDC data interface RX (data OUT) endpoint. */ 102 | #define CDC_RX_EPNUM 4 103 | 104 | /** Size of the CDC data interface TX and RX data endpoint banks, in bytes. */ 105 | #define CDC_TXRX_EPSIZE 16 106 | 107 | /** Size of the CDC control interface notification endpoint bank, in bytes. */ 108 | #define CDC_NOTIFICATION_EPSIZE 8 109 | 110 | /* Type Defines: */ 111 | /** Type define for the device configuration descriptor structure. This must be defined in the 112 | * application code, as the configuration descriptor contains several sub-descriptors which 113 | * vary between devices, and which describe the device's usage to the host. 114 | */ 115 | typedef struct 116 | { 117 | USB_Descriptor_Configuration_Header_t Config; 118 | 119 | // CDC Control Interface 120 | USB_Descriptor_Interface_t CDC_CCI_Interface; 121 | USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header; 122 | USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM; 123 | USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union; 124 | USB_Descriptor_Endpoint_t CDC_NotificationEndpoint; 125 | 126 | // CDC Data Interface 127 | USB_Descriptor_Interface_t CDC_DCI_Interface; 128 | USB_Descriptor_Endpoint_t CDC_DataOutEndpoint; 129 | USB_Descriptor_Endpoint_t CDC_DataInEndpoint; 130 | } USB_Descriptor_Configuration_t; 131 | 132 | /* Function Prototypes: */ 133 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 134 | const uint8_t wIndex, 135 | const void** const DescriptorAddress) 136 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); 137 | 138 | #endif 139 | 140 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/USBAPI.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __USBAPI__ 4 | #define __USBAPI__ 5 | 6 | #if defined(USBCON) 7 | 8 | //================================================================================ 9 | //================================================================================ 10 | // USB 11 | 12 | class USBDevice_ 13 | { 14 | public: 15 | USBDevice_(); 16 | bool configured(); 17 | 18 | void attach(); 19 | void detach(); // Serial port goes down too... 20 | void poll(); 21 | }; 22 | extern USBDevice_ USBDevice; 23 | 24 | //================================================================================ 25 | //================================================================================ 26 | // Serial over CDC (Serial1 is the physical port) 27 | 28 | class Serial_ : public Stream 29 | { 30 | private: 31 | ring_buffer *_cdc_rx_buffer; 32 | public: 33 | void begin(uint16_t baud_count); 34 | void end(void); 35 | 36 | virtual int available(void); 37 | virtual void accept(void); 38 | virtual int peek(void); 39 | virtual int read(void); 40 | virtual void flush(void); 41 | virtual size_t write(uint8_t); 42 | operator bool(); 43 | }; 44 | extern Serial_ Serial; 45 | 46 | //================================================================================ 47 | //================================================================================ 48 | // Mouse 49 | 50 | #define MOUSE_LEFT 1 51 | #define MOUSE_RIGHT 2 52 | #define MOUSE_MIDDLE 4 53 | #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) 54 | 55 | class Mouse_ 56 | { 57 | private: 58 | uint8_t _buttons; 59 | void buttons(uint8_t b); 60 | public: 61 | Mouse_(void); 62 | void begin(void); 63 | void end(void); 64 | void click(uint8_t b = MOUSE_LEFT); 65 | void move(signed char x, signed char y, signed char wheel = 0); 66 | void press(uint8_t b = MOUSE_LEFT); // press LEFT by default 67 | void release(uint8_t b = MOUSE_LEFT); // release LEFT by default 68 | bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default 69 | }; 70 | extern Mouse_ Mouse; 71 | 72 | //================================================================================ 73 | //================================================================================ 74 | // Keyboard 75 | 76 | #define KEY_LEFT_CTRL 0x80 77 | #define KEY_LEFT_SHIFT 0x81 78 | #define KEY_LEFT_ALT 0x82 79 | #define KEY_LEFT_GUI 0x83 80 | #define KEY_RIGHT_CTRL 0x84 81 | #define KEY_RIGHT_SHIFT 0x85 82 | #define KEY_RIGHT_ALT 0x86 83 | #define KEY_RIGHT_GUI 0x87 84 | 85 | #define KEY_UP_ARROW 0xDA 86 | #define KEY_DOWN_ARROW 0xD9 87 | #define KEY_LEFT_ARROW 0xD8 88 | #define KEY_RIGHT_ARROW 0xD7 89 | #define KEY_BACKSPACE 0xB2 90 | #define KEY_TAB 0xB3 91 | #define KEY_RETURN 0xB0 92 | #define KEY_ESC 0xB1 93 | #define KEY_INSERT 0xD1 94 | #define KEY_DELETE 0xD4 95 | #define KEY_PAGE_UP 0xD3 96 | #define KEY_PAGE_DOWN 0xD6 97 | #define KEY_HOME 0xD2 98 | #define KEY_END 0xD5 99 | #define KEY_CAPS_LOCK 0xC1 100 | #define KEY_F1 0xC2 101 | #define KEY_F2 0xC3 102 | #define KEY_F3 0xC4 103 | #define KEY_F4 0xC5 104 | #define KEY_F5 0xC6 105 | #define KEY_F6 0xC7 106 | #define KEY_F7 0xC8 107 | #define KEY_F8 0xC9 108 | #define KEY_F9 0xCA 109 | #define KEY_F10 0xCB 110 | #define KEY_F11 0xCC 111 | #define KEY_F12 0xCD 112 | 113 | // Low level key report: up to 6 keys and shift, ctrl etc at once 114 | typedef struct 115 | { 116 | uint8_t modifiers; 117 | uint8_t reserved; 118 | uint8_t keys[6]; 119 | } KeyReport; 120 | 121 | class Keyboard_ : public Print 122 | { 123 | private: 124 | KeyReport _keyReport; 125 | public: 126 | void sendReport(KeyReport* keys); 127 | Keyboard_(void); 128 | void begin(void); 129 | void end(void); 130 | virtual size_t write(uint8_t k); 131 | virtual size_t press(uint8_t k); 132 | virtual size_t release(uint8_t k); 133 | virtual void releaseAll(void); 134 | }; 135 | extern Keyboard_ Keyboard; 136 | 137 | //================================================================================ 138 | //================================================================================ 139 | // Low level API 140 | 141 | typedef struct 142 | { 143 | uint8_t bmRequestType; 144 | uint8_t bRequest; 145 | uint8_t wValueL; 146 | uint8_t wValueH; 147 | uint16_t wIndex; 148 | uint16_t wLength; 149 | } Setup; 150 | 151 | //================================================================================ 152 | //================================================================================ 153 | // HID 'Driver' 154 | 155 | int HID_GetInterface(uint8_t* interfaceNum); 156 | int HID_GetDescriptor(int i); 157 | bool HID_Setup(Setup& setup); 158 | void HID_SendReport(uint8_t id, const void* data, int len); 159 | 160 | //================================================================================ 161 | //================================================================================ 162 | // MSC 'Driver' 163 | 164 | int MSC_GetInterface(uint8_t* interfaceNum); 165 | int MSC_GetDescriptor(int i); 166 | bool MSC_Setup(Setup& setup); 167 | bool MSC_Data(uint8_t rx,uint8_t tx); 168 | 169 | //================================================================================ 170 | //================================================================================ 171 | // CSC 'Driver' 172 | 173 | int CDC_GetInterface(uint8_t* interfaceNum); 174 | int CDC_GetDescriptor(int i); 175 | bool CDC_Setup(Setup& setup); 176 | 177 | //================================================================================ 178 | //================================================================================ 179 | 180 | #define TRANSFER_PGM 0x80 181 | #define TRANSFER_RELEASE 0x40 182 | #define TRANSFER_ZERO 0x20 183 | 184 | int USB_SendControl(uint8_t flags, const void* d, int len); 185 | int USB_RecvControl(void* d, int len); 186 | 187 | uint8_t USB_Available(uint8_t ep); 188 | int USB_Send(uint8_t ep, const void* data, int len); // blocking 189 | int USB_Recv(uint8_t ep, void* data, int len); // non-blocking 190 | int USB_Recv(uint8_t ep); // non-blocking 191 | void USB_Flush(uint8_t ep); 192 | 193 | #endif 194 | 195 | #endif /* if defined(USBCON) */ -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Print.cpp - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "Arduino.h" 27 | 28 | #include "Print.h" 29 | 30 | // Public Methods ////////////////////////////////////////////////////////////// 31 | 32 | /* default implementation: may be overridden */ 33 | size_t Print::write(const uint8_t *buffer, size_t size) 34 | { 35 | size_t n = 0; 36 | while (size--) { 37 | n += write(*buffer++); 38 | } 39 | return n; 40 | } 41 | 42 | size_t Print::print(const __FlashStringHelper *ifsh) 43 | { 44 | const char PROGMEM *p = (const char PROGMEM *)ifsh; 45 | size_t n = 0; 46 | while (1) { 47 | unsigned char c = pgm_read_byte(p++); 48 | if (c == 0) break; 49 | n += write(c); 50 | } 51 | return n; 52 | } 53 | 54 | size_t Print::print(const String &s) 55 | { 56 | size_t n = 0; 57 | for (uint16_t i = 0; i < s.length(); i++) { 58 | n += write(s[i]); 59 | } 60 | return n; 61 | } 62 | 63 | size_t Print::print(const char str[]) 64 | { 65 | return write(str); 66 | } 67 | 68 | size_t Print::print(char c) 69 | { 70 | return write(c); 71 | } 72 | 73 | size_t Print::print(unsigned char b, int base) 74 | { 75 | return print((unsigned long) b, base); 76 | } 77 | 78 | size_t Print::print(int n, int base) 79 | { 80 | return print((long) n, base); 81 | } 82 | 83 | size_t Print::print(unsigned int n, int base) 84 | { 85 | return print((unsigned long) n, base); 86 | } 87 | 88 | size_t Print::print(long n, int base) 89 | { 90 | if (base == 0) { 91 | return write(n); 92 | } else if (base == 10) { 93 | if (n < 0) { 94 | int t = print('-'); 95 | n = -n; 96 | return printNumber(n, 10) + t; 97 | } 98 | return printNumber(n, 10); 99 | } else { 100 | return printNumber(n, base); 101 | } 102 | } 103 | 104 | size_t Print::print(unsigned long n, int base) 105 | { 106 | if (base == 0) return write(n); 107 | else return printNumber(n, base); 108 | } 109 | 110 | size_t Print::print(double n, int digits) 111 | { 112 | return printFloat(n, digits); 113 | } 114 | 115 | size_t Print::println(const __FlashStringHelper *ifsh) 116 | { 117 | size_t n = print(ifsh); 118 | n += println(); 119 | return n; 120 | } 121 | 122 | size_t Print::print(const Printable& x) 123 | { 124 | return x.printTo(*this); 125 | } 126 | 127 | size_t Print::println(void) 128 | { 129 | size_t n = print('\r'); 130 | n += print('\n'); 131 | return n; 132 | } 133 | 134 | size_t Print::println(const String &s) 135 | { 136 | size_t n = print(s); 137 | n += println(); 138 | return n; 139 | } 140 | 141 | size_t Print::println(const char c[]) 142 | { 143 | size_t n = print(c); 144 | n += println(); 145 | return n; 146 | } 147 | 148 | size_t Print::println(char c) 149 | { 150 | size_t n = print(c); 151 | n += println(); 152 | return n; 153 | } 154 | 155 | size_t Print::println(unsigned char b, int base) 156 | { 157 | size_t n = print(b, base); 158 | n += println(); 159 | return n; 160 | } 161 | 162 | size_t Print::println(int num, int base) 163 | { 164 | size_t n = print(num, base); 165 | n += println(); 166 | return n; 167 | } 168 | 169 | size_t Print::println(unsigned int num, int base) 170 | { 171 | size_t n = print(num, base); 172 | n += println(); 173 | return n; 174 | } 175 | 176 | size_t Print::println(long num, int base) 177 | { 178 | size_t n = print(num, base); 179 | n += println(); 180 | return n; 181 | } 182 | 183 | size_t Print::println(unsigned long num, int base) 184 | { 185 | size_t n = print(num, base); 186 | n += println(); 187 | return n; 188 | } 189 | 190 | size_t Print::println(double num, int digits) 191 | { 192 | size_t n = print(num, digits); 193 | n += println(); 194 | return n; 195 | } 196 | 197 | size_t Print::println(const Printable& x) 198 | { 199 | size_t n = print(x); 200 | n += println(); 201 | return n; 202 | } 203 | 204 | // Private Methods ///////////////////////////////////////////////////////////// 205 | 206 | size_t Print::printNumber(unsigned long n, uint8_t base) { 207 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 208 | char *str = &buf[sizeof(buf) - 1]; 209 | 210 | *str = '\0'; 211 | 212 | // prevent crash if called with base == 1 213 | if (base < 2) base = 10; 214 | 215 | do { 216 | unsigned long m = n; 217 | n /= base; 218 | char c = m - base * n; 219 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 220 | } while(n); 221 | 222 | return write(str); 223 | } 224 | 225 | size_t Print::printFloat(double number, uint8_t digits) 226 | { 227 | size_t n = 0; 228 | 229 | // Handle negative numbers 230 | if (number < 0.0) 231 | { 232 | n += print('-'); 233 | number = -number; 234 | } 235 | 236 | // Round correctly so that print(1.999, 2) prints as "2.00" 237 | double rounding = 0.5; 238 | for (uint8_t i=0; i 0) { 250 | n += print("."); 251 | } 252 | 253 | // Extract digits from the remainder one at a time 254 | while (digits-- > 0) 255 | { 256 | remainder *= 10.0; 257 | int toPrint = int(remainder); 258 | n += print(toPrint); 259 | remainder -= toPrint; 260 | } 261 | 262 | return n; 263 | } 264 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Arduino.h: -------------------------------------------------------------------------------- 1 | #ifndef Arduino_h 2 | #define Arduino_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "binary.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C"{ 16 | #endif 17 | 18 | #define HIGH 0x1 19 | #define LOW 0x0 20 | 21 | #define INPUT 0x0 22 | #define OUTPUT 0x1 23 | #define INPUT_PULLUP 0x2 24 | 25 | #define true 0x1 26 | #define false 0x0 27 | 28 | #define PI 3.1415926535897932384626433832795 29 | #define HALF_PI 1.5707963267948966192313216916398 30 | #define TWO_PI 6.283185307179586476925286766559 31 | #define DEG_TO_RAD 0.017453292519943295769236907684886 32 | #define RAD_TO_DEG 57.295779513082320876798154814105 33 | 34 | #define SERIAL 0x0 35 | #define DISPLAY 0x1 36 | 37 | #define LSBFIRST 0 38 | #define MSBFIRST 1 39 | 40 | #define CHANGE 1 41 | #define FALLING 2 42 | #define RISING 3 43 | 44 | #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 45 | #define DEFAULT 0 46 | #define EXTERNAL 1 47 | #define INTERNAL 2 48 | #else 49 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) 50 | #define INTERNAL1V1 2 51 | #define INTERNAL2V56 3 52 | #else 53 | #define INTERNAL 3 54 | #endif 55 | #define DEFAULT 1 56 | #define EXTERNAL 0 57 | #endif 58 | 59 | // undefine stdlib's abs if encountered 60 | #ifdef abs 61 | #undef abs 62 | #endif 63 | 64 | #define min(a,b) ((a)<(b)?(a):(b)) 65 | #define max(a,b) ((a)>(b)?(a):(b)) 66 | #define abs(x) ((x)>0?(x):-(x)) 67 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 68 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 69 | #define radians(deg) ((deg)*DEG_TO_RAD) 70 | #define degrees(rad) ((rad)*RAD_TO_DEG) 71 | #define sq(x) ((x)*(x)) 72 | 73 | #define interrupts() sei() 74 | #define noInterrupts() cli() 75 | 76 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 77 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 78 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 79 | 80 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 81 | #define highByte(w) ((uint8_t) ((w) >> 8)) 82 | 83 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 84 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 85 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 86 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 87 | 88 | 89 | typedef unsigned int word; 90 | 91 | #define bit(b) (1UL << (b)) 92 | 93 | typedef uint8_t boolean; 94 | typedef uint8_t byte; 95 | 96 | void init(void); 97 | 98 | void pinMode(uint8_t, uint8_t); 99 | void digitalWrite(uint8_t, uint8_t); 100 | int digitalRead(uint8_t); 101 | int analogRead(uint8_t); 102 | void analogReference(uint8_t mode); 103 | void analogWrite(uint8_t, int); 104 | 105 | unsigned long millis(void); 106 | unsigned long micros(void); 107 | void delay(unsigned long); 108 | void delayMicroseconds(unsigned int us); 109 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 110 | 111 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); 112 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); 113 | 114 | void attachInterrupt(uint8_t, void (*)(void), int mode); 115 | void detachInterrupt(uint8_t); 116 | 117 | void setup(void); 118 | void loop(void); 119 | 120 | // Get the bit location within the hardware port of the given virtual pin. 121 | // This comes from the pins_*.c file for the active board configuration. 122 | 123 | #define analogInPinToBit(P) (P) 124 | 125 | // On the ATmega1280, the addresses of some of the port registers are 126 | // greater than 255, so we can't store them in uint8_t's. 127 | extern const uint16_t PROGMEM port_to_mode_PGM[]; 128 | extern const uint16_t PROGMEM port_to_input_PGM[]; 129 | extern const uint16_t PROGMEM port_to_output_PGM[]; 130 | 131 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 132 | // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 133 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 134 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 135 | 136 | // Get the bit location within the hardware port of the given virtual pin. 137 | // This comes from the pins_*.c file for the active board configuration. 138 | // 139 | // These perform slightly better as macros compared to inline functions 140 | // 141 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 142 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 143 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 144 | #define analogInPinToBit(P) (P) 145 | #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) 146 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) 147 | #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) 148 | 149 | #define NOT_A_PIN 0 150 | #define NOT_A_PORT 0 151 | 152 | #ifdef ARDUINO_MAIN 153 | #define PA 1 154 | #define PB 2 155 | #define PC 3 156 | #define PD 4 157 | #define PE 5 158 | #define PF 6 159 | #define PG 7 160 | #define PH 8 161 | #define PJ 10 162 | #define PK 11 163 | #define PL 12 164 | #endif 165 | 166 | #define NOT_ON_TIMER 0 167 | #define TIMER0A 1 168 | #define TIMER0B 2 169 | #define TIMER1A 3 170 | #define TIMER1B 4 171 | #define TIMER2 5 172 | #define TIMER2A 6 173 | #define TIMER2B 7 174 | 175 | #define TIMER3A 8 176 | #define TIMER3B 9 177 | #define TIMER3C 10 178 | #define TIMER4A 11 179 | #define TIMER4B 12 180 | #define TIMER4C 13 181 | #define TIMER4D 14 182 | #define TIMER5A 15 183 | #define TIMER5B 16 184 | #define TIMER5C 17 185 | 186 | #ifdef __cplusplus 187 | } // extern "C" 188 | #endif 189 | 190 | #ifdef __cplusplus 191 | #include "WCharacter.h" 192 | #include "WString.h" 193 | #include "HardwareSerial.h" 194 | 195 | uint16_t makeWord(uint16_t w); 196 | uint16_t makeWord(byte h, byte l); 197 | 198 | #define word(...) makeWord(__VA_ARGS__) 199 | 200 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 201 | 202 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); 203 | void noTone(uint8_t _pin); 204 | 205 | // WMath prototypes 206 | long random(long); 207 | long random(long, long); 208 | void randomSeed(unsigned int); 209 | long map(long, long, long, long, long); 210 | 211 | #endif 212 | 213 | #include "pins_arduino.h" 214 | 215 | #endif 216 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/CDC.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* Copyright (c) 2011, Peter Barrett 4 | ** 5 | ** Permission to use, copy, modify, and/or distribute this software for 6 | ** any purpose with or without fee is hereby granted, provided that the 7 | ** above copyright notice and this permission notice appear in all copies. 8 | ** 9 | ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 12 | ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 13 | ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 14 | ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 15 | ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 16 | ** SOFTWARE. 17 | */ 18 | 19 | #include "Platform.h" 20 | #include "USBAPI.h" 21 | #include 22 | 23 | #if defined(USBCON) 24 | #ifdef CDC_ENABLED 25 | 26 | #if (RAMEND < 1000) 27 | #define SERIAL_BUFFER_SIZE 16 28 | #else 29 | #define SERIAL_BUFFER_SIZE 64 30 | #endif 31 | 32 | struct ring_buffer 33 | { 34 | unsigned char buffer[SERIAL_BUFFER_SIZE]; 35 | volatile int head; 36 | volatile int tail; 37 | }; 38 | 39 | ring_buffer cdc_rx_buffer = { { 0 }, 0, 0}; 40 | 41 | typedef struct 42 | { 43 | u32 dwDTERate; 44 | u8 bCharFormat; 45 | u8 bParityType; 46 | u8 bDataBits; 47 | u8 lineState; 48 | } LineInfo; 49 | 50 | static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 }; 51 | 52 | #define WEAK __attribute__ ((weak)) 53 | 54 | extern const CDCDescriptor _cdcInterface PROGMEM; 55 | const CDCDescriptor _cdcInterface = 56 | { 57 | D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1), 58 | 59 | // CDC communication interface 60 | D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0), 61 | D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd) 62 | D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not) 63 | D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported 64 | D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0 65 | D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40), 66 | 67 | // CDC data interface 68 | D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0), 69 | D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40,0), 70 | D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0) 71 | }; 72 | 73 | int WEAK CDC_GetInterface(u8* interfaceNum) 74 | { 75 | interfaceNum[0] += 2; // uses 2 76 | return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface)); 77 | } 78 | 79 | bool WEAK CDC_Setup(Setup& setup) 80 | { 81 | u8 r = setup.bRequest; 82 | u8 requestType = setup.bmRequestType; 83 | 84 | if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) 85 | { 86 | if (CDC_GET_LINE_CODING == r) 87 | { 88 | USB_SendControl(0,(void*)&_usbLineInfo,7); 89 | return true; 90 | } 91 | } 92 | 93 | if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType) 94 | { 95 | if (CDC_SET_LINE_CODING == r) 96 | { 97 | USB_RecvControl((void*)&_usbLineInfo,7); 98 | return true; 99 | } 100 | 101 | if (CDC_SET_CONTROL_LINE_STATE == r) 102 | { 103 | _usbLineInfo.lineState = setup.wValueL; 104 | 105 | // auto-reset into the bootloader is triggered when the port, already 106 | // open at 1200 bps, is closed. this is the signal to start the watchdog 107 | // with a relatively long period so it can finish housekeeping tasks 108 | // like servicing endpoints before the sketch ends 109 | if (1200 == _usbLineInfo.dwDTERate) { 110 | // We check DTR state to determine if host port is open (bit 0 of lineState). 111 | if ((_usbLineInfo.lineState & 0x01) == 0) { 112 | *(uint16_t *)0x0800 = 0x7777; 113 | wdt_enable(WDTO_120MS); 114 | } else { 115 | // Most OSs do some intermediate steps when configuring ports and DTR can 116 | // twiggle more than once before stabilizing. 117 | // To avoid spurious resets we set the watchdog to 250ms and eventually 118 | // cancel if DTR goes back high. 119 | 120 | wdt_disable(); 121 | wdt_reset(); 122 | *(uint16_t *)0x0800 = 0x0; 123 | } 124 | } 125 | return true; 126 | } 127 | } 128 | return false; 129 | } 130 | 131 | 132 | int _serialPeek = -1; 133 | void Serial_::begin(uint16_t baud_count) 134 | { 135 | } 136 | 137 | void Serial_::end(void) 138 | { 139 | } 140 | 141 | void Serial_::accept(void) 142 | { 143 | ring_buffer *buffer = &cdc_rx_buffer; 144 | int c = USB_Recv(CDC_RX); 145 | int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; 146 | 147 | // if we should be storing the received character into the location 148 | // just before the tail (meaning that the head would advance to the 149 | // current location of the tail), we're about to overflow the buffer 150 | // and so we don't write the character or advance the head. 151 | if (i != buffer->tail) { 152 | buffer->buffer[buffer->head] = c; 153 | buffer->head = i; 154 | } 155 | } 156 | 157 | int Serial_::available(void) 158 | { 159 | ring_buffer *buffer = &cdc_rx_buffer; 160 | return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE; 161 | } 162 | 163 | int Serial_::peek(void) 164 | { 165 | ring_buffer *buffer = &cdc_rx_buffer; 166 | if (buffer->head == buffer->tail) { 167 | return -1; 168 | } else { 169 | return buffer->buffer[buffer->tail]; 170 | } 171 | } 172 | 173 | int Serial_::read(void) 174 | { 175 | ring_buffer *buffer = &cdc_rx_buffer; 176 | // if the head isn't ahead of the tail, we don't have any characters 177 | if (buffer->head == buffer->tail) { 178 | return -1; 179 | } else { 180 | unsigned char c = buffer->buffer[buffer->tail]; 181 | buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; 182 | return c; 183 | } 184 | } 185 | 186 | void Serial_::flush(void) 187 | { 188 | USB_Flush(CDC_TX); 189 | } 190 | 191 | size_t Serial_::write(uint8_t c) 192 | { 193 | /* only try to send bytes if the high-level CDC connection itself 194 | is open (not just the pipe) - the OS should set lineState when the port 195 | is opened and clear lineState when the port is closed. 196 | bytes sent before the user opens the connection or after 197 | the connection is closed are lost - just like with a UART. */ 198 | 199 | // TODO - ZE - check behavior on different OSes and test what happens if an 200 | // open connection isn't broken cleanly (cable is yanked out, host dies 201 | // or locks up, or host virtual serial port hangs) 202 | if (_usbLineInfo.lineState > 0) { 203 | int r = USB_Send(CDC_TX,&c,1); 204 | if (r > 0) { 205 | return r; 206 | } else { 207 | setWriteError(); 208 | return 0; 209 | } 210 | } 211 | setWriteError(); 212 | return 0; 213 | } 214 | 215 | // This operator is a convenient way for a sketch to check whether the 216 | // port has actually been configured and opened by the host (as opposed 217 | // to just being connected to the host). It can be used, for example, in 218 | // setup() before printing to ensure that an application on the host is 219 | // actually ready to receive and display the data. 220 | // We add a short delay before returning to fix a bug observed by Federico 221 | // where the port is configured (lineState != 0) but not quite opened. 222 | Serial_::operator bool() { 223 | bool result = false; 224 | if (_usbLineInfo.lineState > 0) 225 | result = true; 226 | delay(10); 227 | return result; 228 | } 229 | 230 | Serial_ Serial; 231 | 232 | #endif 233 | #endif /* if defined(USBCON) */ 234 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/variants/MaKeyMaKey/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | #include 29 | 30 | #define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0) 31 | #define TXLED0 PORTD |= (1<<5) 32 | #define TXLED1 PORTD &= ~(1<<5) 33 | #define RXLED0 PORTB |= (1<<0) 34 | #define RXLED1 PORTB &= ~(1<<0) 35 | 36 | static const uint8_t SDA = 2; 37 | static const uint8_t SCL = 3; 38 | 39 | // Map SPI port to 'new' pins D14..D17 40 | static const uint8_t SS = 17; 41 | static const uint8_t MOSI = 16; 42 | static const uint8_t MISO = 14; 43 | static const uint8_t SCK = 15; 44 | 45 | // Mapping of analog pins as digital I/O 46 | // A6-A11 share with digital pins 47 | static const uint8_t A0 = 18; 48 | static const uint8_t A1 = 19; 49 | static const uint8_t A2 = 20; 50 | static const uint8_t A3 = 21; 51 | static const uint8_t A4 = 22; 52 | static const uint8_t A5 = 23; 53 | static const uint8_t A6 = 24; // D4 54 | static const uint8_t A7 = 25; // D6 55 | static const uint8_t A8 = 26; // D8 56 | static const uint8_t A9 = 27; // D9 57 | static const uint8_t A10 = 28; // D10 58 | static const uint8_t A11 = 29; // D12 59 | 60 | #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0)) 61 | #define digitalPinToPCICRbit(p) 0 62 | #define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0)) 63 | #define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4)))))) 64 | 65 | // __AVR_ATmega32U4__ has an unusual mapping of pins to channels 66 | extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; 67 | #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) ) 68 | 69 | #ifdef ARDUINO_MAIN 70 | 71 | // On the Arduino board, digital pins are also used 72 | // for the analog output (software PWM). Analog input 73 | // pins are a separate set. 74 | 75 | // ATMEL ATMEGA32U4 / ARDUINO LEONARDO 76 | // 77 | // D0 PD2 RXD1/INT2 78 | // D1 PD3 TXD1/INT3 79 | // D2 PD1 SDA SDA/INT1 80 | // D3# PD0 PWM8/SCL OC0B/SCL/INT0 81 | // D4 A6 PD4 ADC8 82 | // D5# PC6 ??? OC3A/#OC4A 83 | // D6# A7 PD7 FastPWM #OC4D/ADC10 84 | // D7 PE6 INT6/AIN0 85 | // 86 | // D8 A8 PB4 ADC11/PCINT4 87 | // D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5 88 | // D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6 89 | // D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7 90 | // D12 A11 PD6 T1/#OC4D/ADC9 91 | // D13# PC7 PWM10 CLK0/OC4A 92 | // 93 | // A0 D18 PF7 ADC7 94 | // A1 D19 PF6 ADC6 95 | // A2 D20 PF5 ADC5 96 | // A3 D21 PF4 ADC4 97 | // A4 D22 PF1 ADC1 98 | // A5 D23 PF0 ADC0 99 | // 100 | // New pins D14..D17 to map SPI port to digital pins 101 | // 102 | // MISO D14 PB3 MISO,PCINT3 103 | // SCK D15 PB1 SCK,PCINT1 104 | // MOSI D16 PB2 MOSI,PCINT2 105 | // SS D17 PB0 RXLED,SS/PCINT0 106 | // 107 | // TXLED PD5 108 | // RXLED PB0 109 | // HWB PE2 HWB 110 | 111 | // these arrays map port names (e.g. port B) to the 112 | // appropriate addresses for various functions (e.g. reading 113 | // and writing) 114 | const uint16_t PROGMEM port_to_mode_PGM[] = { 115 | NOT_A_PORT, 116 | NOT_A_PORT, 117 | (uint16_t) &DDRB, 118 | (uint16_t) &DDRC, 119 | (uint16_t) &DDRD, 120 | (uint16_t) &DDRE, 121 | (uint16_t) &DDRF, 122 | }; 123 | 124 | const uint16_t PROGMEM port_to_output_PGM[] = { 125 | NOT_A_PORT, 126 | NOT_A_PORT, 127 | (uint16_t) &PORTB, 128 | (uint16_t) &PORTC, 129 | (uint16_t) &PORTD, 130 | (uint16_t) &PORTE, 131 | (uint16_t) &PORTF, 132 | }; 133 | 134 | const uint16_t PROGMEM port_to_input_PGM[] = { 135 | NOT_A_PORT, 136 | NOT_A_PORT, 137 | (uint16_t) &PINB, 138 | (uint16_t) &PINC, 139 | (uint16_t) &PIND, 140 | (uint16_t) &PINE, 141 | (uint16_t) &PINF, 142 | }; 143 | 144 | const uint8_t PROGMEM digital_pin_to_port_PGM[30] = { 145 | PD, // D0 - PD2 146 | PD, // D1 - PD3 147 | PD, // D2 - PD1 148 | PD, // D3 - PD0 149 | PD, // D4 - PD4 150 | PC, // D5 - PC6 151 | PD, // D6 - PD7 152 | PE, // D7 - PE6 153 | 154 | PB, // D8 - PB4 155 | PB, // D9 - PB5 156 | PB, // D10 - PB6 157 | PB, // D11 - PB7 158 | PD, // D12 - PD6 159 | PC, // D13 - PC7 160 | 161 | PB, // D14 - MISO - PB3 162 | PB, // D15 - SCK - PB1 163 | PB, // D16 - MOSI - PB2 164 | PB, // D17 - SS - PB0 165 | 166 | PF, // D18 - A0 - PF7 167 | PF, // D19 - A1 - PF6 168 | PF, // D20 - A2 - PF5 169 | PF, // D21 - A3 - PF4 170 | PF, // D22 - A4 - PF1 171 | PF, // D23 - A5 - PF0 172 | 173 | PD, // D24 / D4 - A6 - PD4 174 | PD, // D25 / D6 - A7 - PD7 175 | PB, // D26 / D8 - A8 - PB4 176 | PB, // D27 / D9 - A9 - PB5 177 | PB, // D28 / D10 - A10 - PB6 178 | PD, // D29 / D12 - A11 - PD6 179 | }; 180 | 181 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[30] = { 182 | _BV(2), // D0 - PD2 183 | _BV(3), // D1 - PD3 184 | _BV(1), // D2 - PD1 185 | _BV(0), // D3 - PD0 186 | _BV(4), // D4 - PD4 187 | _BV(6), // D5 - PC6 188 | _BV(7), // D6 - PD7 189 | _BV(6), // D7 - PE6 190 | 191 | _BV(4), // D8 - PB4 192 | _BV(5), // D9 - PB5 193 | _BV(6), // D10 - PB6 194 | _BV(7), // D11 - PB7 195 | _BV(6), // D12 - PD6 196 | _BV(7), // D13 - PC7 197 | 198 | _BV(3), // D14 - MISO - PB3 199 | _BV(1), // D15 - SCK - PB1 200 | _BV(2), // D16 - MOSI - PB2 201 | _BV(0), // D17 - SS - PB0 202 | 203 | _BV(7), // D18 - A0 - PF7 204 | _BV(6), // D19 - A1 - PF6 205 | _BV(5), // D20 - A2 - PF5 206 | _BV(4), // D21 - A3 - PF4 207 | _BV(1), // D22 - A4 - PF1 208 | _BV(0), // D23 - A5 - PF0 209 | 210 | _BV(4), // D24 / D4 - A6 - PD4 211 | _BV(7), // D25 / D6 - A7 - PD7 212 | _BV(4), // D26 / D8 - A8 - PB4 213 | _BV(5), // D27 / D9 - A9 - PB5 214 | _BV(6), // D28 / D10 - A10 - PB6 215 | _BV(6), // D29 / D12 - A11 - PD6 216 | }; 217 | 218 | const uint8_t PROGMEM digital_pin_to_timer_PGM[16] = { 219 | NOT_ON_TIMER, 220 | NOT_ON_TIMER, 221 | NOT_ON_TIMER, 222 | TIMER0B, /* 3 */ 223 | NOT_ON_TIMER, 224 | TIMER3A, /* 5 */ 225 | TIMER4D, /* 6 */ 226 | NOT_ON_TIMER, 227 | 228 | NOT_ON_TIMER, 229 | TIMER1A, /* 9 */ 230 | TIMER1B, /* 10 */ 231 | TIMER0A, /* 11 */ 232 | 233 | NOT_ON_TIMER, 234 | TIMER4A, /* 13 */ 235 | 236 | NOT_ON_TIMER, 237 | NOT_ON_TIMER, 238 | }; 239 | 240 | const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = { 241 | 7, // A0 PF7 ADC7 242 | 6, // A1 PF6 ADC6 243 | 5, // A2 PF5 ADC5 244 | 4, // A3 PF4 ADC4 245 | 1, // A4 PF1 ADC1 246 | 0, // A5 PF0 ADC0 247 | 8, // A6 D4 PD4 ADC8 248 | 10, // A7 D6 PD7 ADC10 249 | 11, // A8 D8 PB4 ADC11 250 | 12, // A9 D9 PB5 ADC12 251 | 13, // A10 D10 PB6 ADC13 252 | 9 // A11 D12 PD6 ADC9 253 | }; 254 | 255 | #endif /* ARDUINO_MAIN */ 256 | #endif /* Pins_Arduino_h */ 257 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/Stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.cpp - adds parsing methods to Stream class 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Created July 2011 20 | parsing functions based on TextFinder library by Michael Margolis 21 | */ 22 | 23 | #include "Arduino.h" 24 | #include "Stream.h" 25 | 26 | #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait 27 | #define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field 28 | 29 | // private method to read stream with timeout 30 | int Stream::timedRead() 31 | { 32 | int c; 33 | _startMillis = millis(); 34 | do { 35 | c = read(); 36 | if (c >= 0) return c; 37 | } while(millis() - _startMillis < _timeout); 38 | return -1; // -1 indicates timeout 39 | } 40 | 41 | // private method to peek stream with timeout 42 | int Stream::timedPeek() 43 | { 44 | int c; 45 | _startMillis = millis(); 46 | do { 47 | c = peek(); 48 | if (c >= 0) return c; 49 | } while(millis() - _startMillis < _timeout); 50 | return -1; // -1 indicates timeout 51 | } 52 | 53 | // returns peek of the next digit in the stream or -1 if timeout 54 | // discards non-numeric characters 55 | int Stream::peekNextDigit() 56 | { 57 | int c; 58 | while (1) { 59 | c = timedPeek(); 60 | if (c < 0) return c; // timeout 61 | if (c == '-') return c; 62 | if (c >= '0' && c <= '9') return c; 63 | read(); // discard non-numeric 64 | } 65 | } 66 | 67 | // Public Methods 68 | ////////////////////////////////////////////////////////////// 69 | 70 | void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait 71 | { 72 | _timeout = timeout; 73 | } 74 | 75 | // find returns true if the target string is found 76 | bool Stream::find(char *target) 77 | { 78 | return findUntil(target, NULL); 79 | } 80 | 81 | // reads data from the stream until the target string of given length is found 82 | // returns true if target string is found, false if timed out 83 | bool Stream::find(char *target, size_t length) 84 | { 85 | return findUntil(target, length, NULL, 0); 86 | } 87 | 88 | // as find but search ends if the terminator string is found 89 | bool Stream::findUntil(char *target, char *terminator) 90 | { 91 | return findUntil(target, strlen(target), terminator, strlen(terminator)); 92 | } 93 | 94 | // reads data from the stream until the target string of the given length is found 95 | // search terminated if the terminator string is found 96 | // returns true if target string is found, false if terminated or timed out 97 | bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) 98 | { 99 | size_t index = 0; // maximum target string length is 64k bytes! 100 | size_t termIndex = 0; 101 | int c; 102 | 103 | if( *target == 0) 104 | return true; // return true if target is a null string 105 | while( (c = timedRead()) > 0){ 106 | 107 | if(c != target[index]) 108 | index = 0; // reset index if any char does not match 109 | 110 | if( c == target[index]){ 111 | //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); 112 | if(++index >= targetLen){ // return true if all chars in the target match 113 | return true; 114 | } 115 | } 116 | 117 | if(termLen > 0 && c == terminator[termIndex]){ 118 | if(++termIndex >= termLen) 119 | return false; // return false if terminate string found before target string 120 | } 121 | else 122 | termIndex = 0; 123 | } 124 | return false; 125 | } 126 | 127 | 128 | // returns the first valid (long) integer value from the current position. 129 | // initial characters that are not digits (or the minus sign) are skipped 130 | // function is terminated by the first character that is not a digit. 131 | long Stream::parseInt() 132 | { 133 | return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) 134 | } 135 | 136 | // as above but a given skipChar is ignored 137 | // this allows format characters (typically commas) in values to be ignored 138 | long Stream::parseInt(char skipChar) 139 | { 140 | boolean isNegative = false; 141 | long value = 0; 142 | int c; 143 | 144 | c = peekNextDigit(); 145 | // ignore non numeric leading characters 146 | if(c < 0) 147 | return 0; // zero returned if timeout 148 | 149 | do{ 150 | if(c == skipChar) 151 | ; // ignore this charactor 152 | else if(c == '-') 153 | isNegative = true; 154 | else if(c >= '0' && c <= '9') // is c a digit? 155 | value = value * 10 + c - '0'; 156 | read(); // consume the character we got with peek 157 | c = timedPeek(); 158 | } 159 | while( (c >= '0' && c <= '9') || c == skipChar ); 160 | 161 | if(isNegative) 162 | value = -value; 163 | return value; 164 | } 165 | 166 | 167 | // as parseInt but returns a floating point value 168 | float Stream::parseFloat() 169 | { 170 | return parseFloat(NO_SKIP_CHAR); 171 | } 172 | 173 | // as above but the given skipChar is ignored 174 | // this allows format characters (typically commas) in values to be ignored 175 | float Stream::parseFloat(char skipChar){ 176 | boolean isNegative = false; 177 | boolean isFraction = false; 178 | long value = 0; 179 | char c; 180 | float fraction = 1.0; 181 | 182 | c = peekNextDigit(); 183 | // ignore non numeric leading characters 184 | if(c < 0) 185 | return 0; // zero returned if timeout 186 | 187 | do{ 188 | if(c == skipChar) 189 | ; // ignore 190 | else if(c == '-') 191 | isNegative = true; 192 | else if (c == '.') 193 | isFraction = true; 194 | else if(c >= '0' && c <= '9') { // is c a digit? 195 | value = value * 10 + c - '0'; 196 | if(isFraction) 197 | fraction *= 0.1; 198 | } 199 | read(); // consume the character we got with peek 200 | c = timedPeek(); 201 | } 202 | while( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); 203 | 204 | if(isNegative) 205 | value = -value; 206 | if(isFraction) 207 | return value * fraction; 208 | else 209 | return value; 210 | } 211 | 212 | // read characters from stream into buffer 213 | // terminates if length characters have been read, or timeout (see setTimeout) 214 | // returns the number of characters placed in the buffer 215 | // the buffer is NOT null terminated. 216 | // 217 | size_t Stream::readBytes(char *buffer, size_t length) 218 | { 219 | size_t count = 0; 220 | while (count < length) { 221 | int c = timedRead(); 222 | if (c < 0) break; 223 | *buffer++ = (char)c; 224 | count++; 225 | } 226 | return count; 227 | } 228 | 229 | 230 | // as readBytes with terminator character 231 | // terminates if length characters have been read, timeout, or if the terminator character detected 232 | // returns the number of characters placed in the buffer (0 means no valid data found) 233 | 234 | size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) 235 | { 236 | if (length < 1) return 0; 237 | size_t index = 0; 238 | while (index < length) { 239 | int c = timedRead(); 240 | if (c < 0 || c == terminator) break; 241 | *buffer++ = (char)c; 242 | index++; 243 | } 244 | return index; // return number of characters, not including null terminator 245 | } 246 | 247 | String Stream::readString() 248 | { 249 | String ret; 250 | int c = timedRead(); 251 | while (c >= 0) 252 | { 253 | ret += (char)c; 254 | c = timedRead(); 255 | } 256 | return ret; 257 | } 258 | 259 | String Stream::readStringUntil(char terminator) 260 | { 261 | String ret; 262 | int c = timedRead(); 263 | while (c >= 0 && c != terminator) 264 | { 265 | ret += (char)c; 266 | c = timedRead(); 267 | } 268 | return ret; 269 | } 270 | 271 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_analog.c - analog input and output 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | Modified 28 September 2010 by Mark Sproul 23 | 24 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 25 | */ 26 | 27 | #include "wiring_private.h" 28 | #include "pins_arduino.h" 29 | 30 | uint8_t analog_reference = DEFAULT; 31 | 32 | void analogReference(uint8_t mode) 33 | { 34 | // can't actually set the register here because the default setting 35 | // will connect AVCC and the AREF pin, which would cause a short if 36 | // there's something connected to AREF. 37 | analog_reference = mode; 38 | } 39 | 40 | int analogRead(uint8_t pin) 41 | { 42 | uint8_t low, high; 43 | 44 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 45 | if (pin >= 54) pin -= 54; // allow for channel or pin numbers 46 | #elif defined(__AVR_ATmega32U4__) 47 | if (pin >= 18) pin -= 18; // allow for channel or pin numbers 48 | #elif defined(__AVR_ATmega1284__) 49 | if (pin >= 24) pin -= 24; // allow for channel or pin numbers 50 | #else 51 | if (pin >= 14) pin -= 14; // allow for channel or pin numbers 52 | #endif 53 | 54 | #if defined(__AVR_ATmega32U4__) 55 | pin = analogPinToChannel(pin); 56 | ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); 57 | #elif defined(ADCSRB) && defined(MUX5) 58 | // the MUX5 bit of ADCSRB selects whether we're reading from channels 59 | // 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high). 60 | ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); 61 | #endif 62 | 63 | // set the analog reference (high two bits of ADMUX) and select the 64 | // channel (low 4 bits). this also sets ADLAR (left-adjust result) 65 | // to 0 (the default). 66 | #if defined(ADMUX) 67 | ADMUX = (analog_reference << 6) | (pin & 0x07); 68 | #endif 69 | 70 | // without a delay, we seem to read from the wrong channel 71 | //delay(1); 72 | 73 | #if defined(ADCSRA) && defined(ADCL) 74 | // start the conversion 75 | sbi(ADCSRA, ADSC); 76 | 77 | // ADSC is cleared when the conversion finishes 78 | while (bit_is_set(ADCSRA, ADSC)); 79 | 80 | // we have to read ADCL first; doing so locks both ADCL 81 | // and ADCH until ADCH is read. reading ADCL second would 82 | // cause the results of each conversion to be discarded, 83 | // as ADCL and ADCH would be locked when it completed. 84 | low = ADCL; 85 | high = ADCH; 86 | #else 87 | // we dont have an ADC, return 0 88 | low = 0; 89 | high = 0; 90 | #endif 91 | 92 | // combine the two bytes 93 | return (high << 8) | low; 94 | } 95 | 96 | // Right now, PWM output only works on the pins with 97 | // hardware support. These are defined in the appropriate 98 | // pins_*.c file. For the rest of the pins, we default 99 | // to digital output. 100 | void analogWrite(uint8_t pin, int val) 101 | { 102 | // We need to make sure the PWM output is enabled for those pins 103 | // that support it, as we turn it off when digitally reading or 104 | // writing with them. Also, make sure the pin is in output mode 105 | // for consistenty with Wiring, which doesn't require a pinMode 106 | // call for the analog output pins. 107 | pinMode(pin, OUTPUT); 108 | if (val == 0) 109 | { 110 | digitalWrite(pin, LOW); 111 | } 112 | else if (val == 255) 113 | { 114 | digitalWrite(pin, HIGH); 115 | } 116 | else 117 | { 118 | switch(digitalPinToTimer(pin)) 119 | { 120 | // XXX fix needed for atmega8 121 | #if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__) 122 | case TIMER0A: 123 | // connect pwm to pin on timer 0 124 | sbi(TCCR0, COM00); 125 | OCR0 = val; // set pwm duty 126 | break; 127 | #endif 128 | 129 | #if defined(TCCR0A) && defined(COM0A1) 130 | case TIMER0A: 131 | // connect pwm to pin on timer 0, channel A 132 | sbi(TCCR0A, COM0A1); 133 | OCR0A = val; // set pwm duty 134 | break; 135 | #endif 136 | 137 | #if defined(TCCR0A) && defined(COM0B1) 138 | case TIMER0B: 139 | // connect pwm to pin on timer 0, channel B 140 | sbi(TCCR0A, COM0B1); 141 | OCR0B = val; // set pwm duty 142 | break; 143 | #endif 144 | 145 | #if defined(TCCR1A) && defined(COM1A1) 146 | case TIMER1A: 147 | // connect pwm to pin on timer 1, channel A 148 | sbi(TCCR1A, COM1A1); 149 | OCR1A = val; // set pwm duty 150 | break; 151 | #endif 152 | 153 | #if defined(TCCR1A) && defined(COM1B1) 154 | case TIMER1B: 155 | // connect pwm to pin on timer 1, channel B 156 | sbi(TCCR1A, COM1B1); 157 | OCR1B = val; // set pwm duty 158 | break; 159 | #endif 160 | 161 | #if defined(TCCR2) && defined(COM21) 162 | case TIMER2: 163 | // connect pwm to pin on timer 2 164 | sbi(TCCR2, COM21); 165 | OCR2 = val; // set pwm duty 166 | break; 167 | #endif 168 | 169 | #if defined(TCCR2A) && defined(COM2A1) 170 | case TIMER2A: 171 | // connect pwm to pin on timer 2, channel A 172 | sbi(TCCR2A, COM2A1); 173 | OCR2A = val; // set pwm duty 174 | break; 175 | #endif 176 | 177 | #if defined(TCCR2A) && defined(COM2B1) 178 | case TIMER2B: 179 | // connect pwm to pin on timer 2, channel B 180 | sbi(TCCR2A, COM2B1); 181 | OCR2B = val; // set pwm duty 182 | break; 183 | #endif 184 | 185 | #if defined(TCCR3A) && defined(COM3A1) 186 | case TIMER3A: 187 | // connect pwm to pin on timer 3, channel A 188 | sbi(TCCR3A, COM3A1); 189 | OCR3A = val; // set pwm duty 190 | break; 191 | #endif 192 | 193 | #if defined(TCCR3A) && defined(COM3B1) 194 | case TIMER3B: 195 | // connect pwm to pin on timer 3, channel B 196 | sbi(TCCR3A, COM3B1); 197 | OCR3B = val; // set pwm duty 198 | break; 199 | #endif 200 | 201 | #if defined(TCCR3A) && defined(COM3C1) 202 | case TIMER3C: 203 | // connect pwm to pin on timer 3, channel C 204 | sbi(TCCR3A, COM3C1); 205 | OCR3C = val; // set pwm duty 206 | break; 207 | #endif 208 | 209 | #if defined(TCCR4A) 210 | case TIMER4A: 211 | //connect pwm to pin on timer 4, channel A 212 | sbi(TCCR4A, COM4A1); 213 | #if defined(COM4A0) // only used on 32U4 214 | cbi(TCCR4A, COM4A0); 215 | #endif 216 | OCR4A = val; // set pwm duty 217 | break; 218 | #endif 219 | 220 | #if defined(TCCR4A) && defined(COM4B1) 221 | case TIMER4B: 222 | // connect pwm to pin on timer 4, channel B 223 | sbi(TCCR4A, COM4B1); 224 | OCR4B = val; // set pwm duty 225 | break; 226 | #endif 227 | 228 | #if defined(TCCR4A) && defined(COM4C1) 229 | case TIMER4C: 230 | // connect pwm to pin on timer 4, channel C 231 | sbi(TCCR4A, COM4C1); 232 | OCR4C = val; // set pwm duty 233 | break; 234 | #endif 235 | 236 | #if defined(TCCR4C) && defined(COM4D1) 237 | case TIMER4D: 238 | // connect pwm to pin on timer 4, channel D 239 | sbi(TCCR4C, COM4D1); 240 | #if defined(COM4D0) // only used on 32U4 241 | cbi(TCCR4C, COM4D0); 242 | #endif 243 | OCR4D = val; // set pwm duty 244 | break; 245 | #endif 246 | 247 | 248 | #if defined(TCCR5A) && defined(COM5A1) 249 | case TIMER5A: 250 | // connect pwm to pin on timer 5, channel A 251 | sbi(TCCR5A, COM5A1); 252 | OCR5A = val; // set pwm duty 253 | break; 254 | #endif 255 | 256 | #if defined(TCCR5A) && defined(COM5B1) 257 | case TIMER5B: 258 | // connect pwm to pin on timer 5, channel B 259 | sbi(TCCR5A, COM5B1); 260 | OCR5B = val; // set pwm duty 261 | break; 262 | #endif 263 | 264 | #if defined(TCCR5A) && defined(COM5C1) 265 | case TIMER5C: 266 | // connect pwm to pin on timer 5, channel C 267 | sbi(TCCR5A, COM5C1); 268 | OCR5C = val; // set pwm duty 269 | break; 270 | #endif 271 | 272 | case NOT_ON_TIMER: 273 | default: 274 | if (val < 128) { 275 | digitalWrite(pin, LOW); 276 | } else { 277 | digitalWrite(pin, HIGH); 278 | } 279 | } 280 | } 281 | } 282 | 283 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/USBCore.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (c) 2010, Peter Barrett 3 | /* 4 | ** Permission to use, copy, modify, and/or distribute this software for 5 | ** any purpose with or without fee is hereby granted, provided that the 6 | ** above copyright notice and this permission notice appear in all copies. 7 | ** 8 | ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 9 | ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 10 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 11 | ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 12 | ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 13 | ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 14 | ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 15 | ** SOFTWARE. 16 | */ 17 | 18 | #ifndef __USBCORE_H__ 19 | #define __USBCORE_H__ 20 | 21 | // Standard requests 22 | #define GET_STATUS 0 23 | #define CLEAR_FEATURE 1 24 | #define SET_FEATURE 3 25 | #define SET_ADDRESS 5 26 | #define GET_DESCRIPTOR 6 27 | #define SET_DESCRIPTOR 7 28 | #define GET_CONFIGURATION 8 29 | #define SET_CONFIGURATION 9 30 | #define GET_INTERFACE 10 31 | #define SET_INTERFACE 11 32 | 33 | 34 | // bmRequestType 35 | #define REQUEST_HOSTTODEVICE 0x00 36 | #define REQUEST_DEVICETOHOST 0x80 37 | #define REQUEST_DIRECTION 0x80 38 | 39 | #define REQUEST_STANDARD 0x00 40 | #define REQUEST_CLASS 0x20 41 | #define REQUEST_VENDOR 0x40 42 | #define REQUEST_TYPE 0x60 43 | 44 | #define REQUEST_DEVICE 0x00 45 | #define REQUEST_INTERFACE 0x01 46 | #define REQUEST_ENDPOINT 0x02 47 | #define REQUEST_OTHER 0x03 48 | #define REQUEST_RECIPIENT 0x03 49 | 50 | #define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) 51 | #define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) 52 | 53 | // Class requests 54 | 55 | #define CDC_SET_LINE_CODING 0x20 56 | #define CDC_GET_LINE_CODING 0x21 57 | #define CDC_SET_CONTROL_LINE_STATE 0x22 58 | 59 | #define MSC_RESET 0xFF 60 | #define MSC_GET_MAX_LUN 0xFE 61 | 62 | #define HID_GET_REPORT 0x01 63 | #define HID_GET_IDLE 0x02 64 | #define HID_GET_PROTOCOL 0x03 65 | #define HID_SET_REPORT 0x09 66 | #define HID_SET_IDLE 0x0A 67 | #define HID_SET_PROTOCOL 0x0B 68 | 69 | // Descriptors 70 | 71 | #define USB_DEVICE_DESC_SIZE 18 72 | #define USB_CONFIGUARTION_DESC_SIZE 9 73 | #define USB_INTERFACE_DESC_SIZE 9 74 | #define USB_ENDPOINT_DESC_SIZE 7 75 | 76 | #define USB_DEVICE_DESCRIPTOR_TYPE 1 77 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 78 | #define USB_STRING_DESCRIPTOR_TYPE 3 79 | #define USB_INTERFACE_DESCRIPTOR_TYPE 4 80 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 5 81 | 82 | #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 83 | #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 84 | #define USB_DEVICE_CLASS_STORAGE 0x08 85 | #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF 86 | 87 | #define USB_CONFIG_POWERED_MASK 0x40 88 | #define USB_CONFIG_BUS_POWERED 0x80 89 | #define USB_CONFIG_SELF_POWERED 0xC0 90 | #define USB_CONFIG_REMOTE_WAKEUP 0x20 91 | 92 | // bMaxPower in Configuration Descriptor 93 | #define USB_CONFIG_POWER_MA(mA) ((mA)/2) 94 | 95 | // bEndpointAddress in Endpoint Descriptor 96 | #define USB_ENDPOINT_DIRECTION_MASK 0x80 97 | #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) 98 | #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) 99 | 100 | #define USB_ENDPOINT_TYPE_MASK 0x03 101 | #define USB_ENDPOINT_TYPE_CONTROL 0x00 102 | #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 103 | #define USB_ENDPOINT_TYPE_BULK 0x02 104 | #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 105 | 106 | #define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF) 107 | 108 | #define CDC_V1_10 0x0110 109 | #define CDC_COMMUNICATION_INTERFACE_CLASS 0x02 110 | 111 | #define CDC_CALL_MANAGEMENT 0x01 112 | #define CDC_ABSTRACT_CONTROL_MODEL 0x02 113 | #define CDC_HEADER 0x00 114 | #define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02 115 | #define CDC_UNION 0x06 116 | #define CDC_CS_INTERFACE 0x24 117 | #define CDC_CS_ENDPOINT 0x25 118 | #define CDC_DATA_INTERFACE_CLASS 0x0A 119 | 120 | #define MSC_SUBCLASS_SCSI 0x06 121 | #define MSC_PROTOCOL_BULK_ONLY 0x50 122 | 123 | #define HID_HID_DESCRIPTOR_TYPE 0x21 124 | #define HID_REPORT_DESCRIPTOR_TYPE 0x22 125 | #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 126 | 127 | 128 | // Device 129 | typedef struct { 130 | u8 len; // 18 131 | u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE 132 | u16 usbVersion; // 0x200 133 | u8 deviceClass; 134 | u8 deviceSubClass; 135 | u8 deviceProtocol; 136 | u8 packetSize0; // Packet 0 137 | u16 idVendor; 138 | u16 idProduct; 139 | u16 deviceVersion; // 0x100 140 | u8 iManufacturer; 141 | u8 iProduct; 142 | u8 iSerialNumber; 143 | u8 bNumConfigurations; 144 | } DeviceDescriptor; 145 | 146 | // Config 147 | typedef struct { 148 | u8 len; // 9 149 | u8 dtype; // 2 150 | u16 clen; // total length 151 | u8 numInterfaces; 152 | u8 config; 153 | u8 iconfig; 154 | u8 attributes; 155 | u8 maxPower; 156 | } ConfigDescriptor; 157 | 158 | // String 159 | 160 | // Interface 161 | typedef struct 162 | { 163 | u8 len; // 9 164 | u8 dtype; // 4 165 | u8 number; 166 | u8 alternate; 167 | u8 numEndpoints; 168 | u8 interfaceClass; 169 | u8 interfaceSubClass; 170 | u8 protocol; 171 | u8 iInterface; 172 | } InterfaceDescriptor; 173 | 174 | // Endpoint 175 | typedef struct 176 | { 177 | u8 len; // 7 178 | u8 dtype; // 5 179 | u8 addr; 180 | u8 attr; 181 | u16 packetSize; 182 | u8 interval; 183 | } EndpointDescriptor; 184 | 185 | // Interface Association Descriptor 186 | // Used to bind 2 interfaces together in CDC compostite device 187 | typedef struct 188 | { 189 | u8 len; // 8 190 | u8 dtype; // 11 191 | u8 firstInterface; 192 | u8 interfaceCount; 193 | u8 functionClass; 194 | u8 funtionSubClass; 195 | u8 functionProtocol; 196 | u8 iInterface; 197 | } IADDescriptor; 198 | 199 | // CDC CS interface descriptor 200 | typedef struct 201 | { 202 | u8 len; // 5 203 | u8 dtype; // 0x24 204 | u8 subtype; 205 | u8 d0; 206 | u8 d1; 207 | } CDCCSInterfaceDescriptor; 208 | 209 | typedef struct 210 | { 211 | u8 len; // 4 212 | u8 dtype; // 0x24 213 | u8 subtype; 214 | u8 d0; 215 | } CDCCSInterfaceDescriptor4; 216 | 217 | typedef struct 218 | { 219 | u8 len; 220 | u8 dtype; // 0x24 221 | u8 subtype; // 1 222 | u8 bmCapabilities; 223 | u8 bDataInterface; 224 | } CMFunctionalDescriptor; 225 | 226 | typedef struct 227 | { 228 | u8 len; 229 | u8 dtype; // 0x24 230 | u8 subtype; // 1 231 | u8 bmCapabilities; 232 | } ACMFunctionalDescriptor; 233 | 234 | typedef struct 235 | { 236 | // IAD 237 | IADDescriptor iad; // Only needed on compound device 238 | 239 | // Control 240 | InterfaceDescriptor cif; // 241 | CDCCSInterfaceDescriptor header; 242 | CMFunctionalDescriptor callManagement; // Call Management 243 | ACMFunctionalDescriptor controlManagement; // ACM 244 | CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION 245 | EndpointDescriptor cifin; 246 | 247 | // Data 248 | InterfaceDescriptor dif; 249 | EndpointDescriptor in; 250 | EndpointDescriptor out; 251 | } CDCDescriptor; 252 | 253 | typedef struct 254 | { 255 | InterfaceDescriptor msc; 256 | EndpointDescriptor in; 257 | EndpointDescriptor out; 258 | } MSCDescriptor; 259 | 260 | typedef struct 261 | { 262 | u8 len; // 9 263 | u8 dtype; // 0x21 264 | u8 addr; 265 | u8 versionL; // 0x101 266 | u8 versionH; // 0x101 267 | u8 country; 268 | u8 desctype; // 0x22 report 269 | u8 descLenL; 270 | u8 descLenH; 271 | } HIDDescDescriptor; 272 | 273 | typedef struct 274 | { 275 | InterfaceDescriptor hid; 276 | HIDDescDescriptor desc; 277 | EndpointDescriptor in; 278 | } HIDDescriptor; 279 | 280 | 281 | #define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \ 282 | { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs } 283 | 284 | #define D_CONFIG(_totalLength,_interfaces) \ 285 | { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) } 286 | 287 | #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \ 288 | { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 } 289 | 290 | #define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \ 291 | { 7, 5, _addr,_attr,_packetSize, _interval } 292 | 293 | #define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \ 294 | { 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 } 295 | 296 | #define D_HIDREPORT(_descriptorLength) \ 297 | { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } 298 | 299 | #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } 300 | #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } 301 | 302 | 303 | #endif -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/WString.h: -------------------------------------------------------------------------------- 1 | /* 2 | WString.h - String library for Wiring & Arduino 3 | ...mostly rewritten by Paul Stoffregen... 4 | Copyright (c) 2009-10 Hernando Barragan. All right reserved. 5 | Copyright 2011, Paul Stoffregen, paul@pjrc.com 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 String_class_h 23 | #define String_class_h 24 | #ifdef __cplusplus 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | // When compiling programs with this class, the following gcc parameters 32 | // dramatically increase performance and memory (RAM) efficiency, typically 33 | // with little or no increase in code size. 34 | // -felide-constructors 35 | // -std=c++0x 36 | 37 | class __FlashStringHelper; 38 | #define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) 39 | 40 | // An inherited class for holding the result of a concatenation. These 41 | // result objects are assumed to be writable by subsequent concatenations. 42 | class StringSumHelper; 43 | 44 | // The string class 45 | class String 46 | { 47 | // use a function pointer to allow for "if (s)" without the 48 | // complications of an operator bool(). for more information, see: 49 | // http://www.artima.com/cppsource/safebool.html 50 | typedef void (String::*StringIfHelperType)() const; 51 | void StringIfHelper() const {} 52 | 53 | public: 54 | // constructors 55 | // creates a copy of the initial value. 56 | // if the initial value is null or invalid, or if memory allocation 57 | // fails, the string will be marked as invalid (i.e. "if (s)" will 58 | // be false). 59 | String(const char *cstr = ""); 60 | String(const String &str); 61 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 62 | String(String &&rval); 63 | String(StringSumHelper &&rval); 64 | #endif 65 | explicit String(char c); 66 | explicit String(unsigned char, unsigned char base=10); 67 | explicit String(int, unsigned char base=10); 68 | explicit String(unsigned int, unsigned char base=10); 69 | explicit String(long, unsigned char base=10); 70 | explicit String(unsigned long, unsigned char base=10); 71 | ~String(void); 72 | 73 | // memory management 74 | // return true on success, false on failure (in which case, the string 75 | // is left unchanged). reserve(0), if successful, will validate an 76 | // invalid string (i.e., "if (s)" will be true afterwards) 77 | unsigned char reserve(unsigned int size); 78 | inline unsigned int length(void) const {return len;} 79 | 80 | // creates a copy of the assigned value. if the value is null or 81 | // invalid, or if the memory allocation fails, the string will be 82 | // marked as invalid ("if (s)" will be false). 83 | String & operator = (const String &rhs); 84 | String & operator = (const char *cstr); 85 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 86 | String & operator = (String &&rval); 87 | String & operator = (StringSumHelper &&rval); 88 | #endif 89 | 90 | // concatenate (works w/ built-in types) 91 | 92 | // returns true on success, false on failure (in which case, the string 93 | // is left unchanged). if the argument is null or invalid, the 94 | // concatenation is considered unsucessful. 95 | unsigned char concat(const String &str); 96 | unsigned char concat(const char *cstr); 97 | unsigned char concat(char c); 98 | unsigned char concat(unsigned char c); 99 | unsigned char concat(int num); 100 | unsigned char concat(unsigned int num); 101 | unsigned char concat(long num); 102 | unsigned char concat(unsigned long num); 103 | 104 | // if there's not enough memory for the concatenated value, the string 105 | // will be left unchanged (but this isn't signalled in any way) 106 | String & operator += (const String &rhs) {concat(rhs); return (*this);} 107 | String & operator += (const char *cstr) {concat(cstr); return (*this);} 108 | String & operator += (char c) {concat(c); return (*this);} 109 | String & operator += (unsigned char num) {concat(num); return (*this);} 110 | String & operator += (int num) {concat(num); return (*this);} 111 | String & operator += (unsigned int num) {concat(num); return (*this);} 112 | String & operator += (long num) {concat(num); return (*this);} 113 | String & operator += (unsigned long num) {concat(num); return (*this);} 114 | 115 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); 116 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); 117 | friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); 118 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); 119 | friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); 120 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); 121 | friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); 122 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); 123 | 124 | // comparison (only works w/ Strings and "strings") 125 | operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } 126 | int compareTo(const String &s) const; 127 | unsigned char equals(const String &s) const; 128 | unsigned char equals(const char *cstr) const; 129 | unsigned char operator == (const String &rhs) const {return equals(rhs);} 130 | unsigned char operator == (const char *cstr) const {return equals(cstr);} 131 | unsigned char operator != (const String &rhs) const {return !equals(rhs);} 132 | unsigned char operator != (const char *cstr) const {return !equals(cstr);} 133 | unsigned char operator < (const String &rhs) const; 134 | unsigned char operator > (const String &rhs) const; 135 | unsigned char operator <= (const String &rhs) const; 136 | unsigned char operator >= (const String &rhs) const; 137 | unsigned char equalsIgnoreCase(const String &s) const; 138 | unsigned char startsWith( const String &prefix) const; 139 | unsigned char startsWith(const String &prefix, unsigned int offset) const; 140 | unsigned char endsWith(const String &suffix) const; 141 | 142 | // character acccess 143 | char charAt(unsigned int index) const; 144 | void setCharAt(unsigned int index, char c); 145 | char operator [] (unsigned int index) const; 146 | char& operator [] (unsigned int index); 147 | void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; 148 | void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const 149 | {getBytes((unsigned char *)buf, bufsize, index);} 150 | 151 | // search 152 | int indexOf( char ch ) const; 153 | int indexOf( char ch, unsigned int fromIndex ) const; 154 | int indexOf( const String &str ) const; 155 | int indexOf( const String &str, unsigned int fromIndex ) const; 156 | int lastIndexOf( char ch ) const; 157 | int lastIndexOf( char ch, unsigned int fromIndex ) const; 158 | int lastIndexOf( const String &str ) const; 159 | int lastIndexOf( const String &str, unsigned int fromIndex ) const; 160 | String substring( unsigned int beginIndex ) const; 161 | String substring( unsigned int beginIndex, unsigned int endIndex ) const; 162 | 163 | // modification 164 | void replace(char find, char replace); 165 | void replace(const String& find, const String& replace); 166 | void toLowerCase(void); 167 | void toUpperCase(void); 168 | void trim(void); 169 | 170 | // parsing/conversion 171 | long toInt(void) const; 172 | 173 | protected: 174 | char *buffer; // the actual char array 175 | unsigned int capacity; // the array length minus one (for the '\0') 176 | unsigned int len; // the String length (not counting the '\0') 177 | unsigned char flags; // unused, for future features 178 | protected: 179 | void init(void); 180 | void invalidate(void); 181 | unsigned char changeBuffer(unsigned int maxStrLen); 182 | unsigned char concat(const char *cstr, unsigned int length); 183 | 184 | // copy and move 185 | String & copy(const char *cstr, unsigned int length); 186 | #ifdef __GXX_EXPERIMENTAL_CXX0X__ 187 | void move(String &rhs); 188 | #endif 189 | }; 190 | 191 | class StringSumHelper : public String 192 | { 193 | public: 194 | StringSumHelper(const String &s) : String(s) {} 195 | StringSumHelper(const char *p) : String(p) {} 196 | StringSumHelper(char c) : String(c) {} 197 | StringSumHelper(unsigned char num) : String(num) {} 198 | StringSumHelper(int num) : String(num) {} 199 | StringSumHelper(unsigned int num) : String(num) {} 200 | StringSumHelper(long num) : String(num) {} 201 | StringSumHelper(unsigned long num) : String(num) {} 202 | }; 203 | 204 | #endif // __cplusplus 205 | #endif // String_class_h 206 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.uniandes.edu.co 5 | 6 | Copyright (c) 2004-05 Hernando Barragan 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | Modified 24 November 2006 by David A. Mellis 24 | Modified 1 August 2010 by Mark Sproul 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "wiring_private.h" 34 | 35 | static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; 36 | // volatile static voidFuncPtr twiIntFunc; 37 | 38 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { 39 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 40 | intFunc[interruptNum] = userFunc; 41 | 42 | // Configure the interrupt mode (trigger on low input, any change, rising 43 | // edge, or falling edge). The mode constants were chosen to correspond 44 | // to the configuration bits in the hardware register, so we simply shift 45 | // the mode into place. 46 | 47 | // Enable the interrupt. 48 | 49 | switch (interruptNum) { 50 | #if defined(__AVR_ATmega32U4__) 51 | // I hate doing this, but the register assignment differs between the 1280/2560 52 | // and the 32U4. Since avrlib defines registers PCMSK1 and PCMSK2 that aren't 53 | // even present on the 32U4 this is the only way to distinguish between them. 54 | case 0: 55 | EICRA = (EICRA & ~((1<> 8); 225 | const uint8_t DescriptorNumber = (wValue & 0xFF); 226 | 227 | const void* Address = NULL; 228 | uint16_t Size = NO_DESCRIPTOR; 229 | 230 | switch (DescriptorType) 231 | { 232 | case DTYPE_Device: 233 | Address = &DeviceDescriptor; 234 | Size = sizeof(USB_Descriptor_Device_t); 235 | break; 236 | case DTYPE_Configuration: 237 | Address = &ConfigurationDescriptor; 238 | Size = sizeof(USB_Descriptor_Configuration_t); 239 | break; 240 | case DTYPE_String: 241 | if (!(DescriptorNumber)) 242 | { 243 | Address = &LanguageString; 244 | Size = LanguageString.Header.Size; 245 | } 246 | else if (DescriptorNumber == DeviceDescriptor.ProductStrIndex) 247 | { 248 | Address = &ProductString; 249 | Size = ProductString.Header.Size; 250 | } else if (DescriptorNumber == DeviceDescriptor.ManufacturerStrIndex) 251 | { 252 | Address = &ManufNameString; 253 | Size = ManufNameString.Header.Size; 254 | } 255 | 256 | break; 257 | } 258 | 259 | *DescriptorAddress = Address; 260 | return Size; 261 | } 262 | 263 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 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 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id$ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | // the prescaler is set so that timer0 ticks every 64 clock cycles, and the 28 | // the overflow handler is called every 256 ticks. 29 | #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) 30 | 31 | // the whole number of milliseconds per timer0 overflow 32 | #define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) 33 | 34 | // the fractional number of milliseconds per timer0 overflow. we shift right 35 | // by three to fit these numbers into a byte. (for the clock speeds we care 36 | // about - 8 and 16 MHz - this doesn't lose precision.) 37 | #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) 38 | #define FRACT_MAX (1000 >> 3) 39 | 40 | volatile unsigned long timer0_overflow_count = 0; 41 | volatile unsigned long timer0_millis = 0; 42 | static unsigned char timer0_fract = 0; 43 | 44 | #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 45 | SIGNAL(TIM0_OVF_vect) 46 | #else 47 | SIGNAL(TIMER0_OVF_vect) 48 | #endif 49 | { 50 | // copy these to local variables so they can be stored in registers 51 | // (volatile variables must be read from memory on every access) 52 | unsigned long m = timer0_millis; 53 | unsigned char f = timer0_fract; 54 | 55 | m += MILLIS_INC; 56 | f += FRACT_INC; 57 | if (f >= FRACT_MAX) { 58 | f -= FRACT_MAX; 59 | m += 1; 60 | } 61 | 62 | timer0_fract = f; 63 | timer0_millis = m; 64 | timer0_overflow_count++; 65 | } 66 | 67 | unsigned long millis() 68 | { 69 | unsigned long m; 70 | uint8_t oldSREG = SREG; 71 | 72 | // disable interrupts while we read timer0_millis or we might get an 73 | // inconsistent value (e.g. in the middle of a write to timer0_millis) 74 | cli(); 75 | m = timer0_millis; 76 | SREG = oldSREG; 77 | 78 | return m; 79 | } 80 | 81 | unsigned long micros() { 82 | unsigned long m; 83 | uint8_t oldSREG = SREG, t; 84 | 85 | cli(); 86 | m = timer0_overflow_count; 87 | #if defined(TCNT0) 88 | t = TCNT0; 89 | #elif defined(TCNT0L) 90 | t = TCNT0L; 91 | #else 92 | #error TIMER 0 not defined 93 | #endif 94 | 95 | 96 | #ifdef TIFR0 97 | if ((TIFR0 & _BV(TOV0)) && (t < 255)) 98 | m++; 99 | #else 100 | if ((TIFR & _BV(TOV0)) && (t < 255)) 101 | m++; 102 | #endif 103 | 104 | SREG = oldSREG; 105 | 106 | return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); 107 | } 108 | 109 | void delay(unsigned long ms) 110 | { 111 | uint16_t start = (uint16_t)micros(); 112 | 113 | while (ms > 0) { 114 | if (((uint16_t)micros() - start) >= 1000) { 115 | ms--; 116 | start += 1000; 117 | } 118 | } 119 | } 120 | 121 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ 122 | void delayMicroseconds(unsigned int us) 123 | { 124 | // calling avrlib's delay_us() function with low values (e.g. 1 or 125 | // 2 microseconds) gives delays longer than desired. 126 | //delay_us(us); 127 | #if F_CPU >= 20000000L 128 | // for the 20 MHz clock on rare Arduino boards 129 | 130 | // for a one-microsecond delay, simply wait 2 cycle and return. The overhead 131 | // of the function call yields a delay of exactly a one microsecond. 132 | __asm__ __volatile__ ( 133 | "nop" "\n\t" 134 | "nop"); //just waiting 2 cycle 135 | if (--us == 0) 136 | return; 137 | 138 | // the following loop takes a 1/5 of a microsecond (4 cycles) 139 | // per iteration, so execute it five times for each microsecond of 140 | // delay requested. 141 | us = (us<<2) + us; // x5 us 142 | 143 | // account for the time taken in the preceeding commands. 144 | us -= 2; 145 | 146 | #elif F_CPU >= 16000000L 147 | // for the 16 MHz clock on most Arduino boards 148 | 149 | // for a one-microsecond delay, simply return. the overhead 150 | // of the function call yields a delay of approximately 1 1/8 us. 151 | if (--us == 0) 152 | return; 153 | 154 | // the following loop takes a quarter of a microsecond (4 cycles) 155 | // per iteration, so execute it four times for each microsecond of 156 | // delay requested. 157 | us <<= 2; 158 | 159 | // account for the time taken in the preceeding commands. 160 | us -= 2; 161 | #else 162 | // for the 8 MHz internal clock on the ATmega168 163 | 164 | // for a one- or two-microsecond delay, simply return. the overhead of 165 | // the function calls takes more than two microseconds. can't just 166 | // subtract two, since us is unsigned; we'd overflow. 167 | if (--us == 0) 168 | return; 169 | if (--us == 0) 170 | return; 171 | 172 | // the following loop takes half of a microsecond (4 cycles) 173 | // per iteration, so execute it twice for each microsecond of 174 | // delay requested. 175 | us <<= 1; 176 | 177 | // partially compensate for the time taken by the preceeding commands. 178 | // we can't subtract any more than this or we'd overflow w/ small delays. 179 | us--; 180 | #endif 181 | 182 | // busy wait 183 | __asm__ __volatile__ ( 184 | "1: sbiw %0,1" "\n\t" // 2 cycles 185 | "brne 1b" : "=w" (us) : "0" (us) // 2 cycles 186 | ); 187 | } 188 | 189 | void init() 190 | { 191 | // this needs to be called before setup() or some functions won't 192 | // work there 193 | sei(); 194 | 195 | // on the ATmega168, timer 0 is also used for fast hardware pwm 196 | // (using phase-correct PWM would mean that timer 0 overflowed half as often 197 | // resulting in different millis() behavior on the ATmega8 and ATmega168) 198 | #if defined(TCCR0A) && defined(WGM01) 199 | sbi(TCCR0A, WGM01); 200 | sbi(TCCR0A, WGM00); 201 | #endif 202 | 203 | // set timer 0 prescale factor to 64 204 | #if defined(__AVR_ATmega128__) 205 | // CPU specific: different values for the ATmega128 206 | sbi(TCCR0, CS02); 207 | #elif defined(TCCR0) && defined(CS01) && defined(CS00) 208 | // this combination is for the standard atmega8 209 | sbi(TCCR0, CS01); 210 | sbi(TCCR0, CS00); 211 | #elif defined(TCCR0B) && defined(CS01) && defined(CS00) 212 | // this combination is for the standard 168/328/1280/2560 213 | sbi(TCCR0B, CS01); 214 | sbi(TCCR0B, CS00); 215 | #elif defined(TCCR0A) && defined(CS01) && defined(CS00) 216 | // this combination is for the __AVR_ATmega645__ series 217 | sbi(TCCR0A, CS01); 218 | sbi(TCCR0A, CS00); 219 | #else 220 | #error Timer 0 prescale factor 64 not set correctly 221 | #endif 222 | 223 | // enable timer 0 overflow interrupt 224 | #if defined(TIMSK) && defined(TOIE0) 225 | sbi(TIMSK, TOIE0); 226 | #elif defined(TIMSK0) && defined(TOIE0) 227 | sbi(TIMSK0, TOIE0); 228 | #else 229 | #error Timer 0 overflow interrupt not set correctly 230 | #endif 231 | 232 | // timers 1 and 2 are used for phase-correct hardware pwm 233 | // this is better for motors as it ensures an even waveform 234 | // note, however, that fast pwm mode can achieve a frequency of up 235 | // 8 MHz (with a 16 MHz clock) at 50% duty cycle 236 | 237 | #if defined(TCCR1B) && defined(CS11) && defined(CS10) 238 | TCCR1B = 0; 239 | 240 | // set timer 1 prescale factor to 64 241 | sbi(TCCR1B, CS11); 242 | #if F_CPU >= 8000000L 243 | sbi(TCCR1B, CS10); 244 | #endif 245 | #elif defined(TCCR1) && defined(CS11) && defined(CS10) 246 | sbi(TCCR1, CS11); 247 | #if F_CPU >= 8000000L 248 | sbi(TCCR1, CS10); 249 | #endif 250 | #endif 251 | // put timer 1 in 8-bit phase correct pwm mode 252 | #if defined(TCCR1A) && defined(WGM10) 253 | sbi(TCCR1A, WGM10); 254 | #elif defined(TCCR1) 255 | #warning this needs to be finished 256 | #endif 257 | 258 | // set timer 2 prescale factor to 64 259 | #if defined(TCCR2) && defined(CS22) 260 | sbi(TCCR2, CS22); 261 | #elif defined(TCCR2B) && defined(CS22) 262 | sbi(TCCR2B, CS22); 263 | #else 264 | #warning Timer 2 not finished (may not be present on this CPU) 265 | #endif 266 | 267 | // configure timer 2 for phase correct pwm (8-bit) 268 | #if defined(TCCR2) && defined(WGM20) 269 | sbi(TCCR2, WGM20); 270 | #elif defined(TCCR2A) && defined(WGM20) 271 | sbi(TCCR2A, WGM20); 272 | #else 273 | #warning Timer 2 not finished (may not be present on this CPU) 274 | #endif 275 | 276 | #if defined(TCCR3B) && defined(CS31) && defined(WGM30) 277 | sbi(TCCR3B, CS31); // set timer 3 prescale factor to 64 278 | sbi(TCCR3B, CS30); 279 | sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode 280 | #endif 281 | 282 | #if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */ 283 | sbi(TCCR4B, CS42); // set timer4 prescale factor to 64 284 | sbi(TCCR4B, CS41); 285 | sbi(TCCR4B, CS40); 286 | sbi(TCCR4D, WGM40); // put timer 4 in phase- and frequency-correct PWM mode 287 | sbi(TCCR4A, PWM4A); // enable PWM mode for comparator OCR4A 288 | sbi(TCCR4C, PWM4D); // enable PWM mode for comparator OCR4D 289 | #else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */ 290 | #if defined(TCCR4B) && defined(CS41) && defined(WGM40) 291 | sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64 292 | sbi(TCCR4B, CS40); 293 | sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode 294 | #endif 295 | #endif /* end timer4 block for ATMEGA1280/2560 and similar */ 296 | 297 | #if defined(TCCR5B) && defined(CS51) && defined(WGM50) 298 | sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64 299 | sbi(TCCR5B, CS50); 300 | sbi(TCCR5A, WGM50); // put timer 5 in 8-bit phase correct pwm mode 301 | #endif 302 | 303 | #if defined(ADCSRA) 304 | // set a2d prescale factor to 128 305 | // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range. 306 | // XXX: this will not work properly for other clock speeds, and 307 | // this code should use F_CPU to determine the prescale factor. 308 | sbi(ADCSRA, ADPS2); 309 | sbi(ADCSRA, ADPS1); 310 | sbi(ADCSRA, ADPS0); 311 | 312 | // enable a2d conversions 313 | sbi(ADCSRA, ADEN); 314 | #endif 315 | 316 | // the bootloader connects pins 0 and 1 to the USART; disconnect them 317 | // here so they can be used as normal digital i/o; they will be 318 | // reconnected in Serial.begin() 319 | #if defined(UCSRB) 320 | UCSRB = 0; 321 | #elif defined(UCSR0B) 322 | UCSR0B = 0; 323 | #endif 324 | } 325 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/bootloaders/caterina/Caterina-makeymakey.hex: -------------------------------------------------------------------------------- 1 | :1070000055C000006EC000006CC000006AC00000E7 2 | :1070100068C0000066C0000064C0000062C00000DC 3 | :1070200060C000005EC00000F2C400005AC0000052 4 | :1070300058C0000056C0000054C0000052C00000FC 5 | :1070400050C0000078C000004CC000004AC00000E2 6 | :1070500048C0000046C0000044C0000042C000001C 7 | :1070600040C000003EC000003CC000003AC000002C 8 | :1070700038C0000036C0000034C0000032C000003C 9 | :1070800030C000002EC000002CC000002AC000004C 10 | :1070900028C0000026C0000024C0000022C000005C 11 | :1070A00020C000001EC000001CC0000011241FBE34 12 | :1070B000CFEFDAE0DEBFCDBF11E0A0E0B1E0E2E368 13 | :1070C000FFE702C005900D92A03BB107D9F711E090 14 | :1070D000A0EBB1E001C01D92A63CB107E1F78FD350 15 | :1070E00026C78ECFF89410926F00109281001092F4 16 | :1070F00085001092840081E085BF15BE47985D9A97 17 | :10710000289A0C94000008952091BA013091BB0197 18 | :107110002F5F3F4F3093BB012093BA01932F37FF6E 19 | :1071200003C08EEF831B982F990F921710F4479886 20 | :107130000895479A08951F920F920FB60F92112447 21 | :107140002F938F939F93EF93FF931092850010924C 22 | :1071500084008091B0019091B101009741F00197B6 23 | :107160009093B1018093B001892B09F45D9A8091CD 24 | :10717000B2019091B301009741F001979093B30150 25 | :107180008093B201892B09F4289AE0E0F0E0859120 26 | :1071900094918F5F9F4F49F08091B4019091B50118 27 | :1071A00001969093B5018093B401FF91EF919F9167 28 | :1071B0008F912F910F900FBE0F901F90189584E024 29 | :1071C0008093E9000DC08091E8008B778093E80000 30 | :1071D00003C08EB3882351F08091E80082FFF9CF7D 31 | :1071E0008091E80085FFEFCF8091F1000895982FFE 32 | :1071F00083E08093E9008091E80085FD0DC08091D7 33 | :10720000E8008E778093E80003C08EB3882369F08E 34 | :107210008091E80080FFF9CF9093F1005D9884E6BB 35 | :1072200090E09093B1018093B00108954F925F92E6 36 | :107230006F927F928F929F92AF92BF92CF92DF9286 37 | :10724000EF92FF920F931F93CF93DF9384E080938D 38 | :10725000E9008091E80082FF57C2289884E690E018 39 | :107260009093B3018093B201AADF182F853481F483 40 | :107270008CE49DE19093B5018093B40107B600FCC6 41 | :10728000FDCFF999FECF81E180935700E89503C0C7 42 | :10729000843519F494DF8DE00DC28C34E1F3803530 43 | :1072A000D1F3843721F484E4A2DF80E003C2813685 44 | :1072B00011F489E5FFC18134B1F481DF182F7FDF3C 45 | :1072C00090E0880F991FAA2797FDA095BA2F312F1C 46 | :1072D000330F20E0442737FD4095542F822B932B0A 47 | :1072E000A42BB52BB8C1803711F483E5E3C18335F6 48 | :1072F00049F4C0E0D1E089917ADF21E0C730D207BC 49 | :10730000D1F7D9C1863521F481E371DF80E3D2C1A1 50 | :10731000833731F487E86BDF85E969DF8EE1CAC125 51 | :107320008536B9F4E0E0F0E093E085E09093570013 52 | :10733000E89507B600FCFDCF80935700E89507B6A7 53 | :1073400000FCFDCFE058FF4FA0E7E030FA0771F7EF 54 | :10735000A2CF823739F4E1E0F0E089E08093570072 55 | :107360008491A8C1863439F4E0E0F0E089E08093AC 56 | :10737000570084919FC18E3439F4E3E0F0E089E056 57 | :1073800080935700849196C1813539F4E2E0F0E0B2 58 | :1073900089E08093570084918DC1823631F489E56C 59 | :1073A00026DF80E024DF80E885C1823419F087364B 60 | :1073B00009F0E5C01092B5011092B40100DF082F6A 61 | :1073C000FEDEF82EFCDE682E8554823008F071C196 62 | :1073D000902F80E0CF2DD0E0C82BD92B10926F00DA 63 | :1073E000173609F04BC081E180935700E895DD2402 64 | :1073F000CC24C3943FC0E090B601F090B701009157 65 | :10740000B8011091B901B6E46B16D9F4ED2DF0E096 66 | :10741000EE29FF29E4918E2FEADEDD2081F082E063 67 | :1074200090E0A0E0B0E0E80EF91E0A1F1B1FE092FA 68 | :10743000B601F092B7010093B8011093B901DC24B2 69 | :1074400018C0D801C701B695A7959795879559D5C6 70 | :10745000CEDE82E090E0A0E0B0E0E80EF91E0A1F68 71 | :107460001B1FE092B601F092B7010093B801109390 72 | :10747000B9012197209709F0BECF7DC08090B60159 73 | :107480009090B701A090B801B090B90196E4691648 74 | :1074900009F05DC083E0F40180935700E89507B6DA 75 | :1074A00000FCFDCF54C0F6E46F1661F5772031F192 76 | :1074B000E090B601F090B7010091B8011091B901C8 77 | :1074C0007EDED82ECC24852D90E08C299D29F701D5 78 | :1074D0000C0140925700E895112482E090E0A0E072 79 | :1074E000B0E0E80EF91E0A1F1B1FE092B601F092F1 80 | :1074F000B7010093B8011093B90102C060DE582EA5 81 | :10750000742423C0E090B601F090B7010091B80157 82 | :107510001091B90116950795F794E79450DE682FFE 83 | :10752000C701F7D48091B6019091B701A091B8013D 84 | :10753000B091B9010296A11DB11D8093B60190933F 85 | :10754000B701A093B801B093B901219704C05524A5 86 | :10755000772444244394209709F0A5CF96E4691634 87 | :1075600041F485E0F40180935700E89507B600FCEC 88 | :10757000FDCF8DE03CDE82E080936F009CC08334C1 89 | :1075800071F40091B6011091B70119DE90E021E08D 90 | :10759000F8010C0120935700E89511247CCE833626 91 | :1075A00019F5E090B601F090B7010091B801109183 92 | :1075B000B90105DEF701E16090E021E00C012093C4 93 | :1075C0005700E895112482E090E0A0E0B0E0E80EDA 94 | :1075D000F91E0A1F1B1FE092B601F092B70100933B 95 | :1075E000B8011093B90157CE8D3661F4E091B60120 96 | :1075F000F091B70185E080935700E89507B600FC4D 97 | :10760000FDCF49CE823551F4E091B601F091B7013A 98 | :1076100005911491812FEBDD802F4CC0843421F52E 99 | :10762000E090B601F090B7010091B8011091B90156 100 | :1076300016950795F794E794C2DD682FC70169D4C2 101 | :107640008091B6019091B701A091B801B091B901B4 102 | :107650000296A11DB11D8093B6019093B701A0932E 103 | :10766000B801B093B90117CE843609F5E090B601A0 104 | :10767000F090B7010091B8011091B901D801C7018C 105 | :10768000B695A795979587953CD4B1DD82E090E0BB 106 | :10769000A0E0B0E0E80EF91E0A1F1B1FE092B60141 107 | :1076A000F092B7010093B8011093B90104C08B3177 108 | :1076B00011F08FE39CDD83E08093E9009091E80076 109 | :1076C0008091E8008E778093E80095FF04C010C099 110 | :1076D0008EB38823C9F08091E80080FFF9CF8091B4 111 | :1076E000E8008E778093E80003C08EB3882361F0B2 112 | :1076F0008091E80080FFF9CF84E08093E9008091D9 113 | :10770000E8008B778093E800DF91CF911F910F9174 114 | :10771000FF90EF90DF90CF90BF90AF909F908F90B1 115 | :107720007F906F905F904F9008959091BE01892F48 116 | :107730008F77813249F58091BF018032A1F081328B 117 | :1077400019F5913A09F58091E800877F8093E80068 118 | :107750008DE091E067E070E00BD28091E8008B77DC 119 | :107760008093E8000895913279F48091E800877F52 120 | :107770008093E8008DE091E067E070E05DD2809159 121 | :10778000E8008E778093E800089582E061EC42E0A3 122 | :10779000B5D083E061E842E1B1D084E060E842E145 123 | :1077A000ADC084B7877F84BF88E10FB6F89480931B 124 | :1077B0006000109260000FBE20E880E090E00FB6FD 125 | :1077C000F89420936100809361000FBE81E085BF33 126 | :1077D00092E095BF3F9A209A559AE1E6F0E0208327 127 | :1077E000108247985D9A289A109289008AEF8093B8 128 | :1077F000880090936F0083E080938100F0C04091F7 129 | :10780000000850910108109201081092000894B7E6 130 | :1078100014BE88E10FB6F894809360001092600067 131 | :107820000FBE292F30E0F901E270F07091FD18C011 132 | :1078300090FF05C0859194918F5F9F4F81F423FF46 133 | :107840000FC08091090190910A014817590741F032 134 | :10785000E0E0F0E0859194918F5F9F4F09F042DC6A 135 | :10786000A0DF78941092B5011092B4010CC0DEDC58 136 | :1078700036D38091B4019091B50181549F4110F0AD 137 | :107880001092140141DC80911401882381F78091CA 138 | :10789000E00081608093E00025DC80E090E00895C6 139 | :1078A000FA01923049F0933061F09130F9F485E1BA 140 | :1078B00091E022E130E01EC087E291E02EE330E06B 141 | :1078C00019C0882329F485E691E024E030E012C055 142 | :1078D000813029F489E691E028E130E00BC0823064 143 | :1078E00029F483E891E02AE230E004C080E090E0EF 144 | :1078F00020E030E091838083C90108958093E900FE 145 | :107900008091EB0081608093EB001092ED0060931A 146 | :10791000EC004093ED008091EE00881F8827881FBF 147 | :1079200008958091BE0188238CF403C08EB3882310 148 | :10793000B1F08091E80082FFF9CF8091E8008B7769 149 | :107940008093E80008958EB3882349F08091E80081 150 | :1079500080FFF9CF8091E8008E778093E80008954A 151 | :10796000EF92FF920F931F9345D04CD008ED10E09B 152 | :10797000F80180818F778083808180688083808117 153 | :107980008F7D808319BC1EBA1092BC0180EEE82E58 154 | :10799000F12CF70180818B7F8083F80180818160E9 155 | :1079A000808380E060E042E0A9DFE1EEF0E08081EA 156 | :1079B0008E7F8083E2EEF0E0808181608083808131 157 | :1079C00088608083F70180818E7F8083F8018081C9 158 | :1079D000806180831F910F91FF90EF900895E7EDF4 159 | :1079E000F0E08081816080838AE482BF81E08093BF 160 | :1079F000BD01B6CFE8EDF0E080818E7F80831092EC 161 | :107A0000E20008951092DA001092E10008951F92AA 162 | :107A10000F920FB60F9211242F933F934F935F93C2 163 | :107A20006F937F938F939F93AF93BF93EF93FF9346 164 | :107A30008091DA0080FF1BC08091D80080FF17C0C2 165 | :107A40008091DA008E7F8093DA008091D90080FFE8 166 | :107A50000BC080E189BD82E189BD09B400FEFDCF84 167 | :107A600081E08EBB3BD203C019BC1EBA37D28091D5 168 | :107A7000E10080FF17C08091E20080FF13C0809179 169 | :107A8000E2008E7F8093E2008091E200806180932B 170 | :107A9000E2008091D80080628093D80019BC85E014 171 | :107AA0008EBB1CD28091E10084FF2CC08091E2004B 172 | :107AB00084FF28C080E189BD82E189BD09B400FE50 173 | :107AC000FDCF8091D8008F7D8093D8008091E10018 174 | :107AD0008F7E8093E1008091E2008F7E8093E200B0 175 | :107AE0008091E20081608093E2008091BC01882354 176 | :107AF00031F48091E30087FD02C081E001C084E0A1 177 | :107B00008EBBECD18091E10083FF21C08091E20027 178 | :107B100083FF1DC08091E100877F8093E10082E0B8 179 | :107B20008EBB1092BC018091E1008E7F8093E100BA 180 | :107B30008091E2008E7F8093E2008091E20080617C 181 | :107B40008093E20080E060E042E0D8DEC7D1FF91A0 182 | :107B5000EF91BF91AF919F918F917F916F915F91C5 183 | :107B60004F913F912F910F900FBE0F901F9018953E 184 | :107B70009C014091C4015091C5014617570718F464 185 | :107B8000F90190E044C06115710511F0AB01F8CF27 186 | :107B90008091E8008E778093E80040E050E0F0CFDD 187 | :107BA0008EB3882309F444C0853009F443C0809122 188 | :107BB000E80083FF02C081E008958091E80082FD23 189 | :107BC00031C08091E80080FF22C08091F300909145 190 | :107BD000F200782F60E0292F30E0262B372B07C0EA 191 | :107BE00081918093F100415050402F5F3F4F4115EC 192 | :107BF000510519F02830310598F390E0283031050F 193 | :107C000009F491E08091E8008E778093E8004115B7 194 | :107C1000510531F6992321F605C08EB3882341F032 195 | :107C2000853041F08091E80082FFF7CF80E0089531 196 | :107C300082E0089583E008959C016115710529F49F 197 | :107C40008091E8008B778093E800F90126C08EB31D 198 | :107C5000882391F1853091F18091E80083FF02C083 199 | :107C600081E008958091E80082FFF1CF06C0809105 200 | :107C7000F10081936150704059F02091F3008091A0 201 | :107C8000F200322F20E090E0822B932B892B79F7A2 202 | :107C90008091E8008B778093E80061157105B9F653 203 | :107CA00005C08EB3882341F0853041F08091E80013 204 | :107CB00080FFF7CF80E0089582E0089583E0089583 205 | :107CC0000F931F93DF93CF9300D0CDB7DEB7EEEBCA 206 | :107CD000F1E08091F100819381E0E63CF807C9F77B 207 | :107CE00024DD8091E80083FFE4C08091BE01909183 208 | :107CF000BF01953009F46DC0963040F4913081F1A8 209 | :107D0000913070F0933009F0D4C02AC0983009F453 210 | :107D1000A3C0993009F4B2C0963009F0CAC07CC043 211 | :107D2000803809F4C6C0823809F0C3C08091C2010E 212 | :107D300087708093E9008091EB001092E900209118 213 | :107D4000E800277F2093E80090E025E0969587954E 214 | :107D50002A95E1F781708093F1001092F10087C0BD 215 | :107D6000882319F0823009F0A4C08F71823009F0A5 216 | :107D7000A0C08091C001882331F52091C2012770F5 217 | :107D800009F497C02093E9008091EB0080FF1BC0AD 218 | :107D9000933021F48091EB00806213C08091EB005E 219 | :107DA00080618093EB0081E090E002C0880F991F12 220 | :107DB0002A95E2F78093EA001092EA008091EB00A6 221 | :107DC00088608093EB001092E9008091E800877F43 222 | :107DD00051C0882309F06DC01091C0011F770FB703 223 | :107DE000F8948091E800877F8093E8009ADD809185 224 | :107DF000E80080FFFCCF8091E3008078812B8093A6 225 | :107E0000E30080688093E300112311F482E001C055 226 | :107E100083E08EBB0FBF4DC08058823008F049C050 227 | :107E20008091C0019091C1016091C201AE014F5F8C 228 | :107E30005F4F36DDBC01009709F43BC08091E8003C 229 | :107E4000877F8093E80089819A8192DE8091E800A3 230 | :107E50008B778093E8002DC0803859F58091E80039 231 | :107E6000877F8093E8008091BC018093F10080912E 232 | :107E7000E8008E778093E80054DD1BC08823C9F4A6 233 | :107E80009091C0019230A8F48091E800877F8093A0 234 | :107E9000E8009093BC0145DD8091BC01882331F45A 235 | :107EA0008091E30087FD02C081E001C084E08EBBC9 236 | :107EB0006CDC8091E80083FF0AC08091EB00806257 237 | :107EC0008093EB008091E800877F8093E8000F901B 238 | :107ED0000F90CF91DF911F910F91089508951F93F7 239 | :107EE0008EB3882361F01091E9001092E90080912F 240 | :107EF000E80083FF01C0E4DE17701093E9001F91D2 241 | :107F00000895F999FECF92BD81BDF89A992780B561 242 | :107F10000895262FF999FECF1FBA92BD81BD20BDCD 243 | :107F20000FB6F894FA9AF99A0FBE01960895F8944C 244 | :027F3000FFCF81 245 | :107F32004341544552494E41007777000800000002 246 | :107F4200000000080112011001020000084F1B741A 247 | :107F52002B01000201000109023E000201008032F1 248 | :107F6200090400000102020100052400100104249A 249 | :107F720002040524060001070582030800FF090424 250 | :107F82000100020A000000070504021000010705B3 251 | :107F920083021000010403090418034D0061004B21 252 | :107FA200006500790020004D0061004B00650079FA 253 | :107FB2000000002A0353007000610072006B00464B 254 | :107FC2000075006E00200045006C006500630074BF 255 | :107FD2000072006F006E0069006300730000000011 256 | :040000030000700089 257 | :00000001FF 258 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef Binary_h 2 | #define Binary_h 3 | 4 | #define B0 0 5 | #define B00 0 6 | #define B000 0 7 | #define B0000 0 8 | #define B00000 0 9 | #define B000000 0 10 | #define B0000000 0 11 | #define B00000000 0 12 | #define B1 1 13 | #define B01 1 14 | #define B001 1 15 | #define B0001 1 16 | #define B00001 1 17 | #define B000001 1 18 | #define B0000001 1 19 | #define B00000001 1 20 | #define B10 2 21 | #define B010 2 22 | #define B0010 2 23 | #define B00010 2 24 | #define B000010 2 25 | #define B0000010 2 26 | #define B00000010 2 27 | #define B11 3 28 | #define B011 3 29 | #define B0011 3 30 | #define B00011 3 31 | #define B000011 3 32 | #define B0000011 3 33 | #define B00000011 3 34 | #define B100 4 35 | #define B0100 4 36 | #define B00100 4 37 | #define B000100 4 38 | #define B0000100 4 39 | #define B00000100 4 40 | #define B101 5 41 | #define B0101 5 42 | #define B00101 5 43 | #define B000101 5 44 | #define B0000101 5 45 | #define B00000101 5 46 | #define B110 6 47 | #define B0110 6 48 | #define B00110 6 49 | #define B000110 6 50 | #define B0000110 6 51 | #define B00000110 6 52 | #define B111 7 53 | #define B0111 7 54 | #define B00111 7 55 | #define B000111 7 56 | #define B0000111 7 57 | #define B00000111 7 58 | #define B1000 8 59 | #define B01000 8 60 | #define B001000 8 61 | #define B0001000 8 62 | #define B00001000 8 63 | #define B1001 9 64 | #define B01001 9 65 | #define B001001 9 66 | #define B0001001 9 67 | #define B00001001 9 68 | #define B1010 10 69 | #define B01010 10 70 | #define B001010 10 71 | #define B0001010 10 72 | #define B00001010 10 73 | #define B1011 11 74 | #define B01011 11 75 | #define B001011 11 76 | #define B0001011 11 77 | #define B00001011 11 78 | #define B1100 12 79 | #define B01100 12 80 | #define B001100 12 81 | #define B0001100 12 82 | #define B00001100 12 83 | #define B1101 13 84 | #define B01101 13 85 | #define B001101 13 86 | #define B0001101 13 87 | #define B00001101 13 88 | #define B1110 14 89 | #define B01110 14 90 | #define B001110 14 91 | #define B0001110 14 92 | #define B00001110 14 93 | #define B1111 15 94 | #define B01111 15 95 | #define B001111 15 96 | #define B0001111 15 97 | #define B00001111 15 98 | #define B10000 16 99 | #define B010000 16 100 | #define B0010000 16 101 | #define B00010000 16 102 | #define B10001 17 103 | #define B010001 17 104 | #define B0010001 17 105 | #define B00010001 17 106 | #define B10010 18 107 | #define B010010 18 108 | #define B0010010 18 109 | #define B00010010 18 110 | #define B10011 19 111 | #define B010011 19 112 | #define B0010011 19 113 | #define B00010011 19 114 | #define B10100 20 115 | #define B010100 20 116 | #define B0010100 20 117 | #define B00010100 20 118 | #define B10101 21 119 | #define B010101 21 120 | #define B0010101 21 121 | #define B00010101 21 122 | #define B10110 22 123 | #define B010110 22 124 | #define B0010110 22 125 | #define B00010110 22 126 | #define B10111 23 127 | #define B010111 23 128 | #define B0010111 23 129 | #define B00010111 23 130 | #define B11000 24 131 | #define B011000 24 132 | #define B0011000 24 133 | #define B00011000 24 134 | #define B11001 25 135 | #define B011001 25 136 | #define B0011001 25 137 | #define B00011001 25 138 | #define B11010 26 139 | #define B011010 26 140 | #define B0011010 26 141 | #define B00011010 26 142 | #define B11011 27 143 | #define B011011 27 144 | #define B0011011 27 145 | #define B00011011 27 146 | #define B11100 28 147 | #define B011100 28 148 | #define B0011100 28 149 | #define B00011100 28 150 | #define B11101 29 151 | #define B011101 29 152 | #define B0011101 29 153 | #define B00011101 29 154 | #define B11110 30 155 | #define B011110 30 156 | #define B0011110 30 157 | #define B00011110 30 158 | #define B11111 31 159 | #define B011111 31 160 | #define B0011111 31 161 | #define B00011111 31 162 | #define B100000 32 163 | #define B0100000 32 164 | #define B00100000 32 165 | #define B100001 33 166 | #define B0100001 33 167 | #define B00100001 33 168 | #define B100010 34 169 | #define B0100010 34 170 | #define B00100010 34 171 | #define B100011 35 172 | #define B0100011 35 173 | #define B00100011 35 174 | #define B100100 36 175 | #define B0100100 36 176 | #define B00100100 36 177 | #define B100101 37 178 | #define B0100101 37 179 | #define B00100101 37 180 | #define B100110 38 181 | #define B0100110 38 182 | #define B00100110 38 183 | #define B100111 39 184 | #define B0100111 39 185 | #define B00100111 39 186 | #define B101000 40 187 | #define B0101000 40 188 | #define B00101000 40 189 | #define B101001 41 190 | #define B0101001 41 191 | #define B00101001 41 192 | #define B101010 42 193 | #define B0101010 42 194 | #define B00101010 42 195 | #define B101011 43 196 | #define B0101011 43 197 | #define B00101011 43 198 | #define B101100 44 199 | #define B0101100 44 200 | #define B00101100 44 201 | #define B101101 45 202 | #define B0101101 45 203 | #define B00101101 45 204 | #define B101110 46 205 | #define B0101110 46 206 | #define B00101110 46 207 | #define B101111 47 208 | #define B0101111 47 209 | #define B00101111 47 210 | #define B110000 48 211 | #define B0110000 48 212 | #define B00110000 48 213 | #define B110001 49 214 | #define B0110001 49 215 | #define B00110001 49 216 | #define B110010 50 217 | #define B0110010 50 218 | #define B00110010 50 219 | #define B110011 51 220 | #define B0110011 51 221 | #define B00110011 51 222 | #define B110100 52 223 | #define B0110100 52 224 | #define B00110100 52 225 | #define B110101 53 226 | #define B0110101 53 227 | #define B00110101 53 228 | #define B110110 54 229 | #define B0110110 54 230 | #define B00110110 54 231 | #define B110111 55 232 | #define B0110111 55 233 | #define B00110111 55 234 | #define B111000 56 235 | #define B0111000 56 236 | #define B00111000 56 237 | #define B111001 57 238 | #define B0111001 57 239 | #define B00111001 57 240 | #define B111010 58 241 | #define B0111010 58 242 | #define B00111010 58 243 | #define B111011 59 244 | #define B0111011 59 245 | #define B00111011 59 246 | #define B111100 60 247 | #define B0111100 60 248 | #define B00111100 60 249 | #define B111101 61 250 | #define B0111101 61 251 | #define B00111101 61 252 | #define B111110 62 253 | #define B0111110 62 254 | #define B00111110 62 255 | #define B111111 63 256 | #define B0111111 63 257 | #define B00111111 63 258 | #define B1000000 64 259 | #define B01000000 64 260 | #define B1000001 65 261 | #define B01000001 65 262 | #define B1000010 66 263 | #define B01000010 66 264 | #define B1000011 67 265 | #define B01000011 67 266 | #define B1000100 68 267 | #define B01000100 68 268 | #define B1000101 69 269 | #define B01000101 69 270 | #define B1000110 70 271 | #define B01000110 70 272 | #define B1000111 71 273 | #define B01000111 71 274 | #define B1001000 72 275 | #define B01001000 72 276 | #define B1001001 73 277 | #define B01001001 73 278 | #define B1001010 74 279 | #define B01001010 74 280 | #define B1001011 75 281 | #define B01001011 75 282 | #define B1001100 76 283 | #define B01001100 76 284 | #define B1001101 77 285 | #define B01001101 77 286 | #define B1001110 78 287 | #define B01001110 78 288 | #define B1001111 79 289 | #define B01001111 79 290 | #define B1010000 80 291 | #define B01010000 80 292 | #define B1010001 81 293 | #define B01010001 81 294 | #define B1010010 82 295 | #define B01010010 82 296 | #define B1010011 83 297 | #define B01010011 83 298 | #define B1010100 84 299 | #define B01010100 84 300 | #define B1010101 85 301 | #define B01010101 85 302 | #define B1010110 86 303 | #define B01010110 86 304 | #define B1010111 87 305 | #define B01010111 87 306 | #define B1011000 88 307 | #define B01011000 88 308 | #define B1011001 89 309 | #define B01011001 89 310 | #define B1011010 90 311 | #define B01011010 90 312 | #define B1011011 91 313 | #define B01011011 91 314 | #define B1011100 92 315 | #define B01011100 92 316 | #define B1011101 93 317 | #define B01011101 93 318 | #define B1011110 94 319 | #define B01011110 94 320 | #define B1011111 95 321 | #define B01011111 95 322 | #define B1100000 96 323 | #define B01100000 96 324 | #define B1100001 97 325 | #define B01100001 97 326 | #define B1100010 98 327 | #define B01100010 98 328 | #define B1100011 99 329 | #define B01100011 99 330 | #define B1100100 100 331 | #define B01100100 100 332 | #define B1100101 101 333 | #define B01100101 101 334 | #define B1100110 102 335 | #define B01100110 102 336 | #define B1100111 103 337 | #define B01100111 103 338 | #define B1101000 104 339 | #define B01101000 104 340 | #define B1101001 105 341 | #define B01101001 105 342 | #define B1101010 106 343 | #define B01101010 106 344 | #define B1101011 107 345 | #define B01101011 107 346 | #define B1101100 108 347 | #define B01101100 108 348 | #define B1101101 109 349 | #define B01101101 109 350 | #define B1101110 110 351 | #define B01101110 110 352 | #define B1101111 111 353 | #define B01101111 111 354 | #define B1110000 112 355 | #define B01110000 112 356 | #define B1110001 113 357 | #define B01110001 113 358 | #define B1110010 114 359 | #define B01110010 114 360 | #define B1110011 115 361 | #define B01110011 115 362 | #define B1110100 116 363 | #define B01110100 116 364 | #define B1110101 117 365 | #define B01110101 117 366 | #define B1110110 118 367 | #define B01110110 118 368 | #define B1110111 119 369 | #define B01110111 119 370 | #define B1111000 120 371 | #define B01111000 120 372 | #define B1111001 121 373 | #define B01111001 121 374 | #define B1111010 122 375 | #define B01111010 122 376 | #define B1111011 123 377 | #define B01111011 123 378 | #define B1111100 124 379 | #define B01111100 124 380 | #define B1111101 125 381 | #define B01111101 125 382 | #define B1111110 126 383 | #define B01111110 126 384 | #define B1111111 127 385 | #define B01111111 127 386 | #define B10000000 128 387 | #define B10000001 129 388 | #define B10000010 130 389 | #define B10000011 131 390 | #define B10000100 132 391 | #define B10000101 133 392 | #define B10000110 134 393 | #define B10000111 135 394 | #define B10001000 136 395 | #define B10001001 137 396 | #define B10001010 138 397 | #define B10001011 139 398 | #define B10001100 140 399 | #define B10001101 141 400 | #define B10001110 142 401 | #define B10001111 143 402 | #define B10010000 144 403 | #define B10010001 145 404 | #define B10010010 146 405 | #define B10010011 147 406 | #define B10010100 148 407 | #define B10010101 149 408 | #define B10010110 150 409 | #define B10010111 151 410 | #define B10011000 152 411 | #define B10011001 153 412 | #define B10011010 154 413 | #define B10011011 155 414 | #define B10011100 156 415 | #define B10011101 157 416 | #define B10011110 158 417 | #define B10011111 159 418 | #define B10100000 160 419 | #define B10100001 161 420 | #define B10100010 162 421 | #define B10100011 163 422 | #define B10100100 164 423 | #define B10100101 165 424 | #define B10100110 166 425 | #define B10100111 167 426 | #define B10101000 168 427 | #define B10101001 169 428 | #define B10101010 170 429 | #define B10101011 171 430 | #define B10101100 172 431 | #define B10101101 173 432 | #define B10101110 174 433 | #define B10101111 175 434 | #define B10110000 176 435 | #define B10110001 177 436 | #define B10110010 178 437 | #define B10110011 179 438 | #define B10110100 180 439 | #define B10110101 181 440 | #define B10110110 182 441 | #define B10110111 183 442 | #define B10111000 184 443 | #define B10111001 185 444 | #define B10111010 186 445 | #define B10111011 187 446 | #define B10111100 188 447 | #define B10111101 189 448 | #define B10111110 190 449 | #define B10111111 191 450 | #define B11000000 192 451 | #define B11000001 193 452 | #define B11000010 194 453 | #define B11000011 195 454 | #define B11000100 196 455 | #define B11000101 197 456 | #define B11000110 198 457 | #define B11000111 199 458 | #define B11001000 200 459 | #define B11001001 201 460 | #define B11001010 202 461 | #define B11001011 203 462 | #define B11001100 204 463 | #define B11001101 205 464 | #define B11001110 206 465 | #define B11001111 207 466 | #define B11010000 208 467 | #define B11010001 209 468 | #define B11010010 210 469 | #define B11010011 211 470 | #define B11010100 212 471 | #define B11010101 213 472 | #define B11010110 214 473 | #define B11010111 215 474 | #define B11011000 216 475 | #define B11011001 217 476 | #define B11011010 218 477 | #define B11011011 219 478 | #define B11011100 220 479 | #define B11011101 221 480 | #define B11011110 222 481 | #define B11011111 223 482 | #define B11100000 224 483 | #define B11100001 225 484 | #define B11100010 226 485 | #define B11100011 227 486 | #define B11100100 228 487 | #define B11100101 229 488 | #define B11100110 230 489 | #define B11100111 231 490 | #define B11101000 232 491 | #define B11101001 233 492 | #define B11101010 234 493 | #define B11101011 235 494 | #define B11101100 236 495 | #define B11101101 237 496 | #define B11101110 238 497 | #define B11101111 239 498 | #define B11110000 240 499 | #define B11110001 241 500 | #define B11110010 242 501 | #define B11110011 243 502 | #define B11110100 244 503 | #define B11110101 245 504 | #define B11110110 246 505 | #define B11110111 247 506 | #define B11111000 248 507 | #define B11111001 249 508 | #define B11111010 250 509 | #define B11111011 251 510 | #define B11111100 252 511 | #define B11111101 253 512 | #define B11111110 254 513 | #define B11111111 255 514 | 515 | #endif 516 | -------------------------------------------------------------------------------- /firmware/Arduino/hardware/MaKeyMaKey/cores/arduino/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | Modified 28 September 2010 by Mark Sproul 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "Arduino.h" 28 | #include "wiring_private.h" 29 | 30 | // this next line disables the entire HardwareSerial.cpp, 31 | // this is so I can support Attiny series and any other chip without a uart 32 | #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H) 33 | 34 | #include "HardwareSerial.h" 35 | 36 | // Define constants and variables for buffering incoming serial data. We're 37 | // using a ring buffer (I think), in which head is the index of the location 38 | // to which to write the next incoming character and tail is the index of the 39 | // location from which to read. 40 | #if (RAMEND < 1000) 41 | #define SERIAL_BUFFER_SIZE 16 42 | #else 43 | #define SERIAL_BUFFER_SIZE 64 44 | #endif 45 | 46 | struct ring_buffer 47 | { 48 | unsigned char buffer[SERIAL_BUFFER_SIZE]; 49 | volatile unsigned int head; 50 | volatile unsigned int tail; 51 | }; 52 | 53 | #if defined(USBCON) 54 | ring_buffer rx_buffer = { { 0 }, 0, 0}; 55 | ring_buffer tx_buffer = { { 0 }, 0, 0}; 56 | #endif 57 | #if defined(UBRRH) || defined(UBRR0H) 58 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 59 | ring_buffer tx_buffer = { { 0 }, 0, 0 }; 60 | #endif 61 | #if defined(UBRR1H) 62 | ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; 63 | ring_buffer tx_buffer1 = { { 0 }, 0, 0 }; 64 | #endif 65 | #if defined(UBRR2H) 66 | ring_buffer rx_buffer2 = { { 0 }, 0, 0 }; 67 | ring_buffer tx_buffer2 = { { 0 }, 0, 0 }; 68 | #endif 69 | #if defined(UBRR3H) 70 | ring_buffer rx_buffer3 = { { 0 }, 0, 0 }; 71 | ring_buffer tx_buffer3 = { { 0 }, 0, 0 }; 72 | #endif 73 | 74 | inline void store_char(unsigned char c, ring_buffer *buffer) 75 | { 76 | int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE; 77 | 78 | // if we should be storing the received character into the location 79 | // just before the tail (meaning that the head would advance to the 80 | // current location of the tail), we're about to overflow the buffer 81 | // and so we don't write the character or advance the head. 82 | if (i != buffer->tail) { 83 | buffer->buffer[buffer->head] = c; 84 | buffer->head = i; 85 | } 86 | } 87 | 88 | #if !defined(USART0_RX_vect) && defined(USART1_RX_vect) 89 | // do nothing - on the 32u4 the first USART is USART1 90 | #else 91 | #if !defined(USART_RX_vect) && !defined(SIG_USART0_RECV) && \ 92 | !defined(SIG_UART0_RECV) && !defined(USART0_RX_vect) && \ 93 | !defined(SIG_UART_RECV) 94 | #error "Don't know what the Data Received vector is called for the first UART" 95 | #else 96 | void serialEvent() __attribute__((weak)); 97 | void serialEvent() {} 98 | #define serialEvent_implemented 99 | #if defined(USART_RX_vect) 100 | SIGNAL(USART_RX_vect) 101 | #elif defined(SIG_USART0_RECV) 102 | SIGNAL(SIG_USART0_RECV) 103 | #elif defined(SIG_UART0_RECV) 104 | SIGNAL(SIG_UART0_RECV) 105 | #elif defined(USART0_RX_vect) 106 | SIGNAL(USART0_RX_vect) 107 | #elif defined(SIG_UART_RECV) 108 | SIGNAL(SIG_UART_RECV) 109 | #endif 110 | { 111 | #if defined(UDR0) 112 | unsigned char c = UDR0; 113 | #elif defined(UDR) 114 | unsigned char c = UDR; 115 | #else 116 | #error UDR not defined 117 | #endif 118 | store_char(c, &rx_buffer); 119 | } 120 | #endif 121 | #endif 122 | 123 | #if defined(USART1_RX_vect) 124 | void serialEvent1() __attribute__((weak)); 125 | void serialEvent1() {} 126 | #define serialEvent1_implemented 127 | SIGNAL(USART1_RX_vect) 128 | { 129 | unsigned char c = UDR1; 130 | store_char(c, &rx_buffer1); 131 | } 132 | #elif defined(SIG_USART1_RECV) 133 | #error SIG_USART1_RECV 134 | #endif 135 | 136 | #if defined(USART2_RX_vect) && defined(UDR2) 137 | void serialEvent2() __attribute__((weak)); 138 | void serialEvent2() {} 139 | #define serialEvent2_implemented 140 | SIGNAL(USART2_RX_vect) 141 | { 142 | unsigned char c = UDR2; 143 | store_char(c, &rx_buffer2); 144 | } 145 | #elif defined(SIG_USART2_RECV) 146 | #error SIG_USART2_RECV 147 | #endif 148 | 149 | #if defined(USART3_RX_vect) && defined(UDR3) 150 | void serialEvent3() __attribute__((weak)); 151 | void serialEvent3() {} 152 | #define serialEvent3_implemented 153 | SIGNAL(USART3_RX_vect) 154 | { 155 | unsigned char c = UDR3; 156 | store_char(c, &rx_buffer3); 157 | } 158 | #elif defined(SIG_USART3_RECV) 159 | #error SIG_USART3_RECV 160 | #endif 161 | 162 | void serialEventRun(void) 163 | { 164 | #ifdef serialEvent_implemented 165 | if (Serial.available()) serialEvent(); 166 | #endif 167 | #ifdef serialEvent1_implemented 168 | if (Serial1.available()) serialEvent1(); 169 | #endif 170 | #ifdef serialEvent2_implemented 171 | if (Serial2.available()) serialEvent2(); 172 | #endif 173 | #ifdef serialEvent3_implemented 174 | if (Serial3.available()) serialEvent3(); 175 | #endif 176 | } 177 | 178 | 179 | #if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect) 180 | // do nothing - on the 32u4 the first USART is USART1 181 | #else 182 | #if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect) 183 | #error "Don't know what the Data Register Empty vector is called for the first UART" 184 | #else 185 | #if defined(UART0_UDRE_vect) 186 | ISR(UART0_UDRE_vect) 187 | #elif defined(UART_UDRE_vect) 188 | ISR(UART_UDRE_vect) 189 | #elif defined(USART0_UDRE_vect) 190 | ISR(USART0_UDRE_vect) 191 | #elif defined(USART_UDRE_vect) 192 | ISR(USART_UDRE_vect) 193 | #endif 194 | { 195 | if (tx_buffer.head == tx_buffer.tail) { 196 | // Buffer empty, so disable interrupts 197 | #if defined(UCSR0B) 198 | cbi(UCSR0B, UDRIE0); 199 | #else 200 | cbi(UCSRB, UDRIE); 201 | #endif 202 | } 203 | else { 204 | // There is more data in the output buffer. Send the next byte 205 | unsigned char c = tx_buffer.buffer[tx_buffer.tail]; 206 | tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE; 207 | 208 | #if defined(UDR0) 209 | UDR0 = c; 210 | #elif defined(UDR) 211 | UDR = c; 212 | #else 213 | #error UDR not defined 214 | #endif 215 | } 216 | } 217 | #endif 218 | #endif 219 | 220 | #ifdef USART1_UDRE_vect 221 | ISR(USART1_UDRE_vect) 222 | { 223 | if (tx_buffer1.head == tx_buffer1.tail) { 224 | // Buffer empty, so disable interrupts 225 | cbi(UCSR1B, UDRIE1); 226 | } 227 | else { 228 | // There is more data in the output buffer. Send the next byte 229 | unsigned char c = tx_buffer1.buffer[tx_buffer1.tail]; 230 | tx_buffer1.tail = (tx_buffer1.tail + 1) % SERIAL_BUFFER_SIZE; 231 | 232 | UDR1 = c; 233 | } 234 | } 235 | #endif 236 | 237 | #ifdef USART2_UDRE_vect 238 | ISR(USART2_UDRE_vect) 239 | { 240 | if (tx_buffer2.head == tx_buffer2.tail) { 241 | // Buffer empty, so disable interrupts 242 | cbi(UCSR2B, UDRIE2); 243 | } 244 | else { 245 | // There is more data in the output buffer. Send the next byte 246 | unsigned char c = tx_buffer2.buffer[tx_buffer2.tail]; 247 | tx_buffer2.tail = (tx_buffer2.tail + 1) % SERIAL_BUFFER_SIZE; 248 | 249 | UDR2 = c; 250 | } 251 | } 252 | #endif 253 | 254 | #ifdef USART3_UDRE_vect 255 | ISR(USART3_UDRE_vect) 256 | { 257 | if (tx_buffer3.head == tx_buffer3.tail) { 258 | // Buffer empty, so disable interrupts 259 | cbi(UCSR3B, UDRIE3); 260 | } 261 | else { 262 | // There is more data in the output buffer. Send the next byte 263 | unsigned char c = tx_buffer3.buffer[tx_buffer3.tail]; 264 | tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE; 265 | 266 | UDR3 = c; 267 | } 268 | } 269 | #endif 270 | 271 | 272 | // Constructors //////////////////////////////////////////////////////////////// 273 | 274 | HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, 275 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 276 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 277 | volatile uint8_t *udr, 278 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x) 279 | { 280 | _rx_buffer = rx_buffer; 281 | _tx_buffer = tx_buffer; 282 | _ubrrh = ubrrh; 283 | _ubrrl = ubrrl; 284 | _ucsra = ucsra; 285 | _ucsrb = ucsrb; 286 | _udr = udr; 287 | _rxen = rxen; 288 | _txen = txen; 289 | _rxcie = rxcie; 290 | _udrie = udrie; 291 | _u2x = u2x; 292 | } 293 | 294 | // Public Methods ////////////////////////////////////////////////////////////// 295 | 296 | void HardwareSerial::begin(unsigned long baud) 297 | { 298 | uint16_t baud_setting; 299 | bool use_u2x = true; 300 | 301 | #if F_CPU == 16000000UL 302 | // hardcoded exception for compatibility with the bootloader shipped 303 | // with the Duemilanove and previous boards and the firmware on the 8U2 304 | // on the Uno and Mega 2560. 305 | if (baud == 57600) { 306 | use_u2x = false; 307 | } 308 | #endif 309 | 310 | try_again: 311 | 312 | if (use_u2x) { 313 | *_ucsra = 1 << _u2x; 314 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 315 | } else { 316 | *_ucsra = 0; 317 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 318 | } 319 | 320 | if ((baud_setting > 4095) && use_u2x) 321 | { 322 | use_u2x = false; 323 | goto try_again; 324 | } 325 | 326 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 327 | *_ubrrh = baud_setting >> 8; 328 | *_ubrrl = baud_setting; 329 | 330 | sbi(*_ucsrb, _rxen); 331 | sbi(*_ucsrb, _txen); 332 | sbi(*_ucsrb, _rxcie); 333 | cbi(*_ucsrb, _udrie); 334 | } 335 | 336 | void HardwareSerial::end() 337 | { 338 | // wait for transmission of outgoing data 339 | while (_tx_buffer->head != _tx_buffer->tail) 340 | ; 341 | 342 | cbi(*_ucsrb, _rxen); 343 | cbi(*_ucsrb, _txen); 344 | cbi(*_ucsrb, _rxcie); 345 | cbi(*_ucsrb, _udrie); 346 | 347 | // clear any received data 348 | _rx_buffer->head = _rx_buffer->tail; 349 | } 350 | 351 | int HardwareSerial::available(void) 352 | { 353 | return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE; 354 | } 355 | 356 | int HardwareSerial::peek(void) 357 | { 358 | if (_rx_buffer->head == _rx_buffer->tail) { 359 | return -1; 360 | } else { 361 | return _rx_buffer->buffer[_rx_buffer->tail]; 362 | } 363 | } 364 | 365 | int HardwareSerial::read(void) 366 | { 367 | // if the head isn't ahead of the tail, we don't have any characters 368 | if (_rx_buffer->head == _rx_buffer->tail) { 369 | return -1; 370 | } else { 371 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; 372 | _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE; 373 | return c; 374 | } 375 | } 376 | 377 | void HardwareSerial::flush() 378 | { 379 | while (_tx_buffer->head != _tx_buffer->tail) 380 | ; 381 | } 382 | 383 | size_t HardwareSerial::write(uint8_t c) 384 | { 385 | int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE; 386 | 387 | // If the output buffer is full, there's nothing for it other than to 388 | // wait for the interrupt handler to empty it a bit 389 | // ???: return 0 here instead? 390 | while (i == _tx_buffer->tail) 391 | ; 392 | 393 | _tx_buffer->buffer[_tx_buffer->head] = c; 394 | _tx_buffer->head = i; 395 | 396 | sbi(*_ucsrb, _udrie); 397 | 398 | return 1; 399 | } 400 | 401 | HardwareSerial::operator bool() { 402 | return true; 403 | } 404 | 405 | // Preinstantiate Objects ////////////////////////////////////////////////////// 406 | 407 | #if defined(UBRRH) && defined(UBRRL) 408 | HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X); 409 | #elif defined(UBRR0H) && defined(UBRR0L) 410 | HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0); 411 | #elif defined(USBCON) 412 | // do nothing - Serial object and buffers are initialized in CDC code 413 | #else 414 | #error no serial port defined (port 0) 415 | #endif 416 | 417 | #if defined(UBRR1H) 418 | HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1); 419 | #endif 420 | #if defined(UBRR2H) 421 | HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2); 422 | #endif 423 | #if defined(UBRR3H) 424 | HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); 425 | #endif 426 | 427 | #endif // whole file 428 | 429 | --------------------------------------------------------------------------------