Starting to update the keyboardio core for arduino

pull/18/head
Jesse Vincent 10 years ago
parent 8c88c19cb1
commit bc2516607e

@ -0,0 +1,37 @@
keyboardio.name=Keyboardio Model 00
keyboardio.upload.protocol=avr109
keyboardio.upload.maximum_size=28672
keyboardio.upload.speed=57600
keyboardio.upload.disable_flushing=true
keyboardio.bootloader.low_fuses=0xff
keyboardio.bootloader.high_fuses=0xd8
keyboardio.bootloader.extended_fuses=0xcb
keyboardio.bootloader.path=caterina
keyboardio.bootloader.file=Caterina-keyboardio.hex
keyboardio.bootloader.unlock_bits=0x3F
keyboardio.bootloader.lock_bits=0x2F
keyboardio.build.mcu=atmega32u4
keyboardio.build.f_cpu=16000000L
keyboardio.build.vid=0x2341
keyboardio.build.pid=0x8037
keyboardio.build.core=keyboardio
keyboardio.build.variant=model00
symmetric60.name=Keyboardio Symmetric 60
symmetric60.upload.protocol=avr109
symmetric60.upload.maximum_size=28672
symmetric60.upload.speed=57600
symmetric60.upload.disable_flushing=true
symmetric60.bootloader.low_fuses=0xff
symmetric60.bootloader.high_fuses=0xd8
symmetric60.bootloader.extended_fuses=0xcb
symmetric60.bootloader.path=caterina
symmetric60.bootloader.file=Caterina-symmetric60.hex
symmetric60.bootloader.unlock_bits=0x3F
symmetric60.bootloader.lock_bits=0x2F
symmetric60.build.mcu=atmega32u4
symmetric60.build.f_cpu=16000000L
symmetric60.build.vid=0x2341
symmetric60.build.pid=0x8037
symmetric60.build.core=keyboardio
symmetric60.build.variant=symmetric60

@ -1,7 +1,27 @@
/*
Arduino.h - Main include file for the Arduino SDK
Copyright (c) 2005-2013 Arduino Team. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef Arduino_h
#define Arduino_h
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
@ -15,6 +35,8 @@
extern "C"{
#endif
void yield(void);
#define HIGH 0x1
#define LOW 0x0
@ -22,14 +44,12 @@ extern "C"{
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#define true 0x1
#define false 0x0
#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define EULER 2.718281828459045235360287471352
#define SERIAL 0x0
#define DISPLAY 0x1
@ -85,6 +105,10 @@ extern "C"{
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
// avr-libc defines _NOP() since 1.6.2
#ifndef _NOP
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
#endif
typedef unsigned int word;
@ -94,6 +118,9 @@ typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void initVariant(void);
int atexit(void (*func)()) __attribute__((weak));
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
@ -149,6 +176,8 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
#define NOT_A_PIN 0
#define NOT_A_PORT 0
#define NOT_AN_INTERRUPT -1
#ifdef ARDUINO_MAIN
#define PA 1
#define PB 2
@ -168,20 +197,21 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4
#define TIMER2 5
#define TIMER2A 6
#define TIMER2B 7
#define TIMER3A 8
#define TIMER3B 9
#define TIMER3C 10
#define TIMER4A 11
#define TIMER4B 12
#define TIMER4C 13
#define TIMER4D 14
#define TIMER5A 15
#define TIMER5B 16
#define TIMER5C 17
#define TIMER1C 5
#define TIMER2 6
#define TIMER2A 7
#define TIMER2B 8
#define TIMER3A 9
#define TIMER3B 10
#define TIMER3C 11
#define TIMER4A 12
#define TIMER4B 13
#define TIMER4C 14
#define TIMER4D 15
#define TIMER5A 16
#define TIMER5B 17
#define TIMER5C 18
#ifdef __cplusplus
} // extern "C"
@ -191,6 +221,10 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
#include "WCharacter.h"
#include "WString.h"
#include "HardwareSerial.h"
#include "USBAPI.h"
#if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)
#error "Targets with both UART0 and CDC serial not supported"
#endif
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);

@ -16,28 +16,12 @@
** SOFTWARE.
*/
#include "Platform.h"
#include "USBAPI.h"
#include <avr/wdt.h>
#if defined(USBCON)
#ifdef CDC_ENABLED
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
struct ring_buffer
{
unsigned char buffer[SERIAL_BUFFER_SIZE];
volatile int head;
volatile int tail;
};
ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
typedef struct
{
u32 dwDTERate;
@ -95,102 +79,81 @@ bool WEAK CDC_Setup(Setup& setup)
if (CDC_SET_LINE_CODING == r)
{
USB_RecvControl((void*)&_usbLineInfo,7);
return true;
}
if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
}
if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
{
// auto-reset into the bootloader is triggered when the port, already
// open at 1200 bps, is closed. this is the signal to start the watchdog
// with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends
if (1200 == _usbLineInfo.dwDTERate) {
// We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0) {
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
} else {
// Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually
// cancel if DTR goes back high.
wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
}
// We check DTR state to determine if host port is open (bit 0 of lineState).
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
{
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
}
else
{
// Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually
// cancel if DTR goes back high.
wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
}
return true;
}
return true;
}
return false;
}
int _serialPeek = -1;
void Serial_::begin(unsigned long baud_count)
void Serial_::begin(unsigned long /* baud_count */)
{
peek_buffer = -1;
}
void Serial_::begin(unsigned long baud_count, byte config)
void Serial_::begin(unsigned long /* baud_count */, byte /* config */)
{
peek_buffer = -1;
}
void Serial_::end(void)
{
}
void Serial_::accept(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
// while we have room to store a byte
while (i != buffer->tail) {
int c = USB_Recv(CDC_RX);
if (c == -1)
break; // no more data
buffer->buffer[buffer->head] = c;
buffer->head = i;
i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
}
}
int Serial_::available(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
if (peek_buffer >= 0) {
return 1 + USB_Available(CDC_RX);
}
return USB_Available(CDC_RX);
}
int Serial_::peek(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
if (buffer->head == buffer->tail) {
return -1;
} else {
return buffer->buffer[buffer->tail];
}
if (peek_buffer < 0)
peek_buffer = USB_Recv(CDC_RX);
return peek_buffer;
}
int Serial_::read(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
// if the head isn't ahead of the tail, we don't have any characters
if (buffer->head == buffer->tail) {
return -1;
} else {
unsigned char c = buffer->buffer[buffer->tail];
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
if (peek_buffer >= 0) {
int c = peek_buffer;
peek_buffer = -1;
return c;
}
return USB_Recv(CDC_RX);
}
void Serial_::flush(void)
@ -199,6 +162,11 @@ void Serial_::flush(void)
}
size_t Serial_::write(uint8_t c)
{
return write(&c, 1);
}
size_t Serial_::write(const uint8_t *buffer, size_t size)
{
/* only try to send bytes if the high-level CDC connection itself
is open (not just the pipe) - the OS should set lineState when the port
@ -210,7 +178,7 @@ size_t Serial_::write(uint8_t c)
// open connection isn't broken cleanly (cable is yanked out, host dies
// or locks up, or host virtual serial port hangs)
if (_usbLineInfo.lineState > 0) {
int r = USB_Send(CDC_TX,&c,1);
int r = USB_Send(CDC_TX,buffer,size);
if (r > 0) {
return r;
} else {

@ -0,0 +1,45 @@
/*
Client.h - Base class that provides Client
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef client_h
#define client_h
#include "Print.h"
#include "Stream.h"
#include "IPAddress.h"
class Client : public Stream {
public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;
virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
virtual int peek() = 0;
virtual void flush() = 0;
virtual void stop() = 0;
virtual uint8_t connected() = 0;
virtual operator bool() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
};
#endif

@ -0,0 +1,803 @@
/* Copyright (c) 2011, Peter Barrett
**
** Sleep/Wakeup/SystemControl support added by Michael Dreher
**
** Permission to use, copy, modify, and/or distribute this software for
** any purpose with or without fee is hereby granted, provided that the
** above copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#include "USBAPI.h"
#include "USBDesc.h"
#include "HIDTables.h"
#if defined(USBCON)
#ifdef HID_ENABLED
#define HID_MOUSE_ABS_ENABLED
//#define RAWHID_ENABLED
// Singletons for mouse and keyboard
Mouse_ Mouse;
Keyboard_ Keyboard;
//================================================================================
//================================================================================
// HID report descriptor
#define LSB(_x) ((_x) & 0xFF)
#define MSB(_x) ((_x) >> 8)
#define RAWHID_USAGE_PAGE 0xFFC0
#define RAWHID_USAGE 0x0C00
#define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64
#define HID_REPORTID_KEYBOARD (1)
#define HID_REPORTID_MOUSE (2)
#define HID_REPORTID_MOUSE_ABS (3)
#define HID_REPORTID_SYSTEMCONTROL (4)
#define HID_REPORTID_CONSUMERCONTROL (5)
#define HID_REPORTID_RAWHID (6)
#define HID_REPORT_KEYBOARD /* Keyboard */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 47 */ \
0x09, 0x06, /* USAGE (Keyboard) */ \
0xa1, 0x01, /* COLLECTION (Application) */ \
0x85, HID_REPORTID_KEYBOARD, /* REPORT_ID */ \
0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \
\
/* Keyboard Modifiers (shift, alt, ...) */ \
0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */ \
0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
0x75, 0x01, /* REPORT_SIZE (1) */ \
\
0x95, 0x08, /* REPORT_COUNT (8) */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0x95, 0x01, /* REPORT_COUNT (1) */ \
0x75, 0x08, /* REPORT_SIZE (8) */ \
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \
\
/* Keyboard keys */ \
0x95, 0x06, /* REPORT_COUNT (6) */ \
0x75, 0x08, /* REPORT_SIZE (8) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x26, 0xDF, 0x00, /* LOGICAL_MAXIMUM (239) */ \
0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \
0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */ \
0x29, 0xDF, /* USAGE_MAXIMUM (Left Control - 1) */ \
0x81, 0x00, /* INPUT (Data,Ary,Abs) */ \
0xc0 /* END_COLLECTION */
#define HID_REPORT_MOUSE_ABSOLUTE /* Mouse absolute */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
0x09, 0x02, /* USAGE (Mouse) */ \
0xa1, 0x01, /* COLLECTION (Application) */ \
0x09, 0x01, /* USAGE (Pointer) */ \
0xa1, 0x00, /* COLLECTION (Physical) */ \
0x85, HID_REPORTID_MOUSE_ABS, /* REPORT_ID */ \
0x05, 0x09, /* USAGE_PAGE (Button) */ \
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \
0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
0x95, 0x03, /* REPORT_COUNT (3) */ \
0x75, 0x01, /* REPORT_SIZE (1) */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0x95, 0x01, /* REPORT_COUNT (1) */ \
0x75, 0x05, /* REPORT_SIZE (5) */ \
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
0x09, 0x30, /* USAGE (X) */ \
0x09, 0x31, /* USAGE (Y) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x26, 0xff, 0x7f, /* LOGICAL_MAXIMUM (32767) */ \
0x75, 0x10, /* REPORT_SIZE (16) */ \
0x95, 0x02, /* REPORT_COUNT (2) */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0xc0, /* END_COLLECTION */ \
0xc0 /* END_COLLECTION */
#define HID_REPORT_MOUSE_RELATIVE /* Mouse relative */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 54 */ \
0x09, 0x02, /* USAGE (Mouse) */ \
0xa1, 0x01, /* COLLECTION (Application) */ \
0x09, 0x01, /* USAGE (Pointer) */ \
0xa1, 0x00, /* COLLECTION (Physical) */ \
0x85, HID_REPORTID_MOUSE, /* REPORT_ID */ \
0x05, 0x09, /* USAGE_PAGE (Button) */ \
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \
0x29, 0x05, /* USAGE_MAXIMUM (Button 5) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
0x95, 0x05, /* REPORT_COUNT (5) */ \
0x75, 0x01, /* REPORT_SIZE (1) */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0x95, 0x01, /* REPORT_COUNT (1) */ \
0x75, 0x03, /* REPORT_SIZE (3) */ \
0x81, 0x01, /* INPUT (Cnst,Var,Abs) */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
0x09, 0x30, /* USAGE (X) */ \
0x09, 0x31, /* USAGE (Y) */ \
0x09, 0x38, /* USAGE (Wheel) */ \
0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ \
0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ \
0x75, 0x08, /* REPORT_SIZE (8) */ \
0x95, 0x03, /* REPORT_COUNT (3) */ \
0x81, 0x06, /* INPUT (Data,Var,Rel) */ \
0xc0, /* END_COLLECTION */ \
0xc0 /* END_COLLECTION */
#define HID_REPORT_SYSTEMCONTROL /* System Control (Power Down, Sleep, Wakeup, ...) */ \
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \
0x09, 0x80, /* USAGE (System Control) */ \
0xa1, 0x01, /* COLLECTION (Application) */ \
0x85, HID_REPORTID_SYSTEMCONTROL, /* REPORT_ID */ \
0x09, 0x81, /* USAGE (System Power Down) */ \
0x09, 0x82, /* USAGE (System Sleep) */ \
0x09, 0x83, /* USAGE (System Wakeup) */ \
0x09, 0x8E, /* USAGE (System Cold Restart) */ \
0x09, 0x8F, /* USAGE (System Warm Restart) */ \
0x09, 0xA0, /* USAGE (System Dock) */ \
0x09, 0xA1, /* USAGE (System Undock) */ \
0x09, 0xA7, /* USAGE (System Speaker Mute) */ \
0x09, 0xA8, /* USAGE (System Hibernate) */ \
/* although these display usages are not that important, they don't cost */ \
/* much more than declaring the otherwise necessary constant fill bits */ \
0x09, 0xB0, /* USAGE (System Display Invert) */ \
0x09, 0xB1, /* USAGE (System Display Internal) */ \
0x09, 0xB2, /* USAGE (System Display External) */ \
0x09, 0xB3, /* USAGE (System Display Both) */ \
0x09, 0xB4, /* USAGE (System Display Dual) */ \
0x09, 0xB5, /* USAGE (System Display Toggle Intern/Extern) */ \
0x09, 0xB6, /* USAGE (System Display Swap) */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
0x75, 0x01, /* REPORT_SIZE (1) */ \
0x95, 0x10, /* REPORT_COUNT (16) */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0xc0 /* END_COLLECTION */
#define HID_REPORT_CONSUMERCONTROL /* Consumer Control (Sound/Media keys) */ \
0x05, 0x0c, /* USAGE_PAGE (Consumer Devices) */ \
0x09, 0x01, /* USAGE (Consumer Control) */ \
0xa1, 0x01, /* COLLECTION (Application) */ \
0x85, HID_REPORTID_CONSUMERCONTROL, /* REPORT_ID */ \
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \
0x75, 0x01, /* REPORT_SIZE (1) */ \
0x95, 0x08, /* REPORT_COUNT (8) */ \
0x09, 0xe2, /* USAGE (Mute) 0x01 */ \
0x09, 0xe9, /* USAGE (Volume Up) 0x02 */ \
0x09, 0xea, /* USAGE (Volume Down) 0x03 */ \
0x09, 0xcd, /* USAGE (Play/Pause) 0x04 */ \
0x09, 0xb7, /* USAGE (Stop) 0x05 */ \
0x09, 0xb6, /* USAGE (Scan Previous Track) 0x06 */ \
0x09, 0xb5, /* USAGE (Scan Next Track) 0x07 */ \
0x09, 0xb8, /* USAGE (Eject) 0x08 */ \
0x81, 0x02, /* INPUT (Data,Var,Abs) */ \
0xc0
#define HID_REPORT_RAWHID /* RAW HID */ \
0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), /* 30 */ \
0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), \
\
0xA1, 0x01, /* Collection 0x01 */ \
0x85, HID_REPORTID_RAWHID, /* REPORT_ID */ \
0x75, 0x08, /* report size = 8 bits */ \
0x15, 0x00, /* logical minimum = 0 */ \
0x26, 0xFF, 0x00, /* logical maximum = 255 */ \
\
0x95, 64, /* report count TX */ \
0x09, 0x01, /* usage */ \
0x81, 0x02, /* Input (array) */ \
\
0x95, 64, /* report count RX */ \
0x09, 0x02, /* usage */ \
0x91, 0x02, /* Output (array) */ \
0xC0 /* end collection */
extern const u8 _hidReportDescriptor[] PROGMEM;
const u8 _hidReportDescriptor[] = {
HID_REPORT_KEYBOARD,
HID_REPORT_MOUSE_RELATIVE,
#ifdef HID_MOUSE_ABS_ENABLED
HID_REPORT_MOUSE_ABSOLUTE,
#endif
HID_REPORT_SYSTEMCONTROL,
HID_REPORT_CONSUMERCONTROL,
#if RAWHID_ENABLED
HID_REPORT_RAWHID
#endif
};
extern const HIDDescriptor _hidInterface PROGMEM;
const HIDDescriptor _hidInterface =
{
D_INTERFACE(HID_INTERFACE,1,3,0,0),
D_HIDREPORT(sizeof(_hidReportDescriptor)),
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
};
//================================================================================
//================================================================================
// Driver
u8 _hid_protocol = 1;
u8 _hid_idle = 1;
#define WEAK __attribute__ ((weak))
int WEAK HID_GetInterface(u8* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
}
int WEAK HID_GetDescriptor(int /* i */)
{
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
}
void WEAK HID_SendReport(u8 id, const void* data, int len)
{
USB_Send(HID_TX, &id, 1);
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
}
bool WEAK HID_Setup(Setup& setup)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
if (HID_GET_REPORT == r)
{
//HID_GetReport();
return true;
}
if (HID_GET_PROTOCOL == r)
{
//Send8(_hid_protocol); // TODO
return true;
}
}
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
{
if (HID_SET_PROTOCOL == r)
{
_hid_protocol = setup.wValueL;
return true;
}
if (HID_SET_IDLE == r)
{
_hid_idle = setup.wValueL;
return true;
}
}
return false;
}
//================================================================================
//================================================================================
// Mouse
Mouse_::Mouse_(void) : _buttons(0)
{
}
void Mouse_::begin(void)
{
}
void Mouse_::end(void)
{
}
void Mouse_::click(uint8_t b)
{
_buttons = b;
move(0,0,0);
_buttons = 0;
move(0,0,0);
}
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
u8 m[4];
m[0] = _buttons;
m[1] = x;
m[2] = y;
m[3] = wheel;
HID_SendReport(HID_REPORTID_MOUSE,m,sizeof(m));
}
// X and Y have the range of 0 to 32767.
// The USB Host will convert them to pixels on the screen.
//
// x=0,y=0 is top-left corner of the screen
// x=32767,y=0 is the top right corner
// x=32767,y=32767 is the bottom right corner
// x=0,y=32767 is the bottom left corner
//
// When converting these coordinates to pixels on screen, Mac OS X's
// default HID driver maps the inner 85% of the coordinate space to
// the screen's physical dimensions. This means that any value between
// 0 and 2293 or 30474 and 32767 will move the mouse to the screen
// edge on a Mac
//
// For details, see:
// http://lists.apple.com/archives/usb/2011/Jun/msg00032.html
void Mouse_::moveAbsolute(uint16_t x, uint16_t y)
{
u8 m[5];
m[0] = _buttons;
m[1] = LSB(x);
m[2] = MSB(x);
m[3] = LSB(y);
m[4] = MSB(y);
HID_SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m));
}
void Mouse_::buttons(uint8_t b)
{
if (b != _buttons)
{
_buttons = b;
move(0,0,0);
}
}
void Mouse_::press(uint8_t b)
{
buttons(_buttons | b);
}
void Mouse_::release(uint8_t b)
{
buttons(_buttons & ~b);
}
bool Mouse_::isPressed(uint8_t b)
{
if ((b & _buttons) > 0)
return true;
return false;
}
//================================================================================
//================================================================================
// Keyboard
Keyboard_::Keyboard_(void)
{
}
void Keyboard_::begin(void)
{
}
void Keyboard_::end(void)
{
}
void Keyboard_::sendReport(KeyReport* keys)
{
HID_SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys));
}
extern
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
0x00, // NUL
0x00, // SOH
0x00, // STX
0x00, // ETX
0x00, // EOT
0x00, // ENQ
0x00, // ACK
0x00, // BEL
0x2a, // BS Backspace
0x2b, // TAB Tab
0x28, // LF Enter
0x00, // VT
0x00, // FF
0x00, // CR
0x00, // SO
0x00, // SI
0x00, // DEL
0x00, // DC1
0x00, // DC2
0x00, // DC3
0x00, // DC4
0x00, // NAK
0x00, // SYN
0x00, // ETB
0x00, // CAN
0x00, // EM
0x00, // SUB
0x00, // ESC
0x00, // FS
0x00, // GS
0x00, // RS
0x00, // US
0x2c, // ' '
0x1e|SHIFT, // !
0x34|SHIFT, // "
0x20|SHIFT, // #
0x21|SHIFT, // $
0x22|SHIFT, // %
0x24|SHIFT, // &
0x34, // '
0x26|SHIFT, // (
0x27|SHIFT, // )
0x25|SHIFT, // *
0x2e|SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
0x38, // /
0x27, // 0
0x1e, // 1
0x1f, // 2
0x20, // 3
0x21, // 4
0x22, // 5
0x23, // 6
0x24, // 7
0x25, // 8
0x26, // 9
0x33|SHIFT, // :
0x33, // ;
0x36|SHIFT, // <
0x2e, // =
0x37|SHIFT, // >
0x38|SHIFT, // ?
0x1f|SHIFT, // @
0x04|SHIFT, // A
0x05|SHIFT, // B
0x06|SHIFT, // C
0x07|SHIFT, // D
0x08|SHIFT, // E
0x09|SHIFT, // F
0x0a|SHIFT, // G
0x0b|SHIFT, // H
0x0c|SHIFT, // I
0x0d|SHIFT, // J
0x0e|SHIFT, // K
0x0f|SHIFT, // L
0x10|SHIFT, // M
0x11|SHIFT, // N
0x12|SHIFT, // O
0x13|SHIFT, // P
0x14|SHIFT, // Q
0x15|SHIFT, // R
0x16|SHIFT, // S
0x17|SHIFT, // T
0x18|SHIFT, // U
0x19|SHIFT, // V
0x1a|SHIFT, // W
0x1b|SHIFT, // X
0x1c|SHIFT, // Y
0x1d|SHIFT, // Z
0x2f, // [
0x31, // bslash
0x30, // ]
0x23|SHIFT, // ^
0x2d|SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
0x06, // c
0x07, // d
0x08, // e
0x09, // f
0x0a, // g
0x0b, // h
0x0c, // i
0x0d, // j
0x0e, // k
0x0f, // l
0x10, // m
0x11, // n
0x12, // o
0x13, // p
0x14, // q
0x15, // r
0x16, // s
0x17, // t
0x18, // u
0x19, // v
0x1a, // w
0x1b, // x
0x1c, // y
0x1d, // z
0x2f|SHIFT, //
0x31|SHIFT, // |
0x30|SHIFT, // }
0x35|SHIFT, // ~
0 // DEL
};
uint8_t USBPutChar(uint8_t c);
// pressKeycode() adds the specified key (printing, non-printing, or modifier)
// to the persistent key report and sends the report. Because of the way
// USB HID works, the host acts like the key remains pressed until we
// call releaseKeycode(), releaseAll(), or otherwise clear the report and resend.
size_t Keyboard_::pressKeycode(uint8_t k)
{
if (!addKeycodeToReport(k)) {
return 0;
}
sendReport(&_keyReport);
}
size_t Keyboard_::addKeycodeToReport(uint8_t k)
{
uint8_t index = 0;
uint8_t done = 0;
if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) {
// it's a modifier key
_keyReport.modifiers |= (0x01 << (k - HID_KEYBOARD_LEFT_CONTROL));
} else {
// it's some other key:
// Add k to the key report only if it's not already present
// and if there is an empty slot.
for (index = 0; index < KEYREPORT_KEYCOUNT; index++) {
if (_keyReport.keys[index] != k) { // is k already in list?
if (0 == _keyReport.keys[index]) { // have we found an empty slot?
_keyReport.keys[index] = k;
done = 1;
break;
}
} else {
done = 1;
break;
}
}
// use separate variable to check if slot was found
// for style reasons - we do not know how the compiler
// handles the for() index when it leaves the loop
if (0 == done) {
setWriteError();
return 0;
}
}
return 1;
}
// press() transforms the given key to the actual keycode and calls
// pressKeycode() to actually press this key.
//
size_t Keyboard_::press(uint8_t k)
{
if (k >= KEY_RIGHT_GUI + 1) {
// it's a non-printing key (not a modifier)
k = k - (KEY_RIGHT_GUI + 1);
} else {
if (k >= KEY_LEFT_CTRL) {
// it's a modifier key
k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL;
} else {
k = pgm_read_byte(_asciimap + k);
if (k) {
if (k & SHIFT) {
// it's a capital letter or other character reached with shift
// the left shift modifier
addKeycodeToReport(HID_KEYBOARD_LEFT_SHIFT);
k = k ^ SHIFT;
}
} else {
return 0;
}
}
}
pressKeycode(k);
return 1;
}
// System Control
// k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::systemControl(uint8_t k)
{
if(k <= 16)
{
u16 mask = 0;
u8 m[2];
if(k > 0)
{
mask = 1 << (k - 1);
}
m[0] = LSB(mask);
m[1] = MSB(mask);
HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));
// these are all OSCs, so send a clear to make it possible to send it again later
m[0] = 0;
m[1] = 0;
HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));
return 1;
}
else
{
setWriteError();
return 0;
}
}
// Consumer Control
// k is one of the CONSUMER_CONTROL defines which come from the HID usage table "Consumer Devices Page (0x0c)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::consumerControl(uint8_t k)
{
if(k <= 8)
{
u16 mask = 0;
u8 m[2];
if(k > 0)
{
mask = 1 << (k - 1);
}
m[0] = LSB(mask);
m[1] = MSB(mask);
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
// these are all OSCs, so send a clear to make it possible to send it again later
m[0] = 0;
m[1] = 0;
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
return 1;
}
else
{
setWriteError();
return 0;
}
}
// releaseKeycode() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
// When send is set to FALSE (= 0) no sendReport() is executed. This comes in
// handy when combining key releases (e.g. SHIFT+A).
size_t Keyboard_::releaseKeycode(uint8_t k)
{
if (!removeKeycodeFromReport(k)) {
return 0;
}
sendReport(&_keyReport);
}
size_t Keyboard_::removeKeycodeFromReport(uint8_t k)
{
uint8_t indexA;
uint8_t indexB;
uint8_t count;
if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) {
// it's a modifier key
_keyReport.modifiers = _keyReport.modifiers & (~(0x01 << (k - HID_KEYBOARD_LEFT_CONTROL)));
} else {
// it's some other key:
// Test the key report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it shouldn't be)
for (indexA = 0; indexA < KEYREPORT_KEYCOUNT; indexA++) {
if (_keyReport.keys[indexA] == k) {
_keyReport.keys[indexA] = 0;
}
}
// finally rearrange the keys list so that the free (= 0x00) are at the
// end of the keys list - some implementations stop for keys at the
// first occurence of an 0x00 in the keys list
// so (0x00)(0x01)(0x00)(0x03)(0x02)(0x00) becomes
// (0x01)(0x03)(0x02)(0x00)(0x00)(0x00)
count = 0; // holds the number of zeros we've found
indexA = 0;
while ((indexA + count) < KEYREPORT_KEYCOUNT) {
if (0 == _keyReport.keys[indexA]) {
count++; // one more zero
for (indexB = indexA; indexB < KEYREPORT_KEYCOUNT-count; indexB++) {
_keyReport.keys[indexB] = _keyReport.keys[indexB+1];
}
_keyReport.keys[KEYREPORT_KEYCOUNT-count] = 0;
} else {
indexA++; // one more non-zero
}
}
}
return 1;
}
// release() transforms the given key to the actual keycode and calls
// releaseKeycode() to actually release this key.
//
size_t Keyboard_::release(uint8_t k)
{
uint8_t i;
if (k >= KEY_RIGHT_GUI + 1) {
// it's a non-printing key (not a modifier)
k = k - (KEY_RIGHT_GUI + 1);
} else {
if (k >= KEY_LEFT_CTRL) {
// it's a modifier key
k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL;
} else {
k = pgm_read_byte(_asciimap + k);
if (k) {
if ((k & SHIFT)) {
// it's a capital letter or other character reached with shift
// the left shift modifier
removeKeycodeFromReport(HID_KEYBOARD_LEFT_SHIFT);
k = k ^ SHIFT;
}
} else {
return 0;
}
}
}
releaseKeycode(k);
return 1;
}
void Keyboard_::releaseAll(void)
{
memset(&_keyReport, 0x00, sizeof(_keyReport));
sendReport(&_keyReport);
}
size_t Keyboard_::write(uint8_t c)
{
uint8_t p = press(c); // Keydown
release(c); // Keyup
return p; // just return the result of press() since release() almost always returns 1
}
size_t Keyboard_::writeKeycode(uint8_t c)
{
uint8_t p = pressKeycode(c); // Keydown
releaseKeycode(c); // Keyup
return (p); // just return the result of pressKeycode() since release() almost always returns 1
}
#endif
#endif /* if defined(USBCON) */

@ -0,0 +1,677 @@
#ifndef __HIDTables__
#define HID___HIDTables__
// These mappings were extracted and transcribed from
// http://www.usb.org_SLASH_developers_SLASH_devclass_docs_SLASH_Hut1_12v2.pdf
//
// In most cases, I've preserved the "official" USB Implementers forum
// "Usage Name", though I've standardized some abbreviations and spacing
// that were inconsistent in the original specification. Non alpha-numeric
// characters in symbol names were converted into those characters' names.
//
// To match Arduino code style, all hid usage names are fully upper case.
//
// Not every HID usage listed in this file is currently supported by Arduino
// In particular, any System Control or Consumer Control entry that doesn't
// have a comment indicating that it's "HID type OSC" will require additional
// code in the Arduino core to work.
//
// Non-working usages are listed here in the interest of not having to manually
// convert more usage names each and every time our HID stack gets a little bit
// better.
//
//
// -- Jesse Vincent <jesse@keyboard.io>, January 2014
// System control mappings
#define HID_SYSTEM_POWER_DOWN 0x81 // HID type OSC
#define HID_SYSTEM_SLEEP 0x82 // HID type OSC
#define HID_SYSTEM_WAKE_UP 0x83 // HID type OSC
#define HID_SYSTEM_CONTEXT_MENU 0x84 // HID type OSC
#define HID_SYSTEM_MAIN_MENU 0x85 // HID type OSC
#define HID_SYSTEM_APP_MENU 0x86 // HID type OSC
#define HID_SYSTEM_MENU_HELP 0x87 // HID type OSC
#define HID_SYSTEM_MENU_EXIT 0x88 // HID type OSC
#define HID_SYSTEM_MENU_SELECT 0x89 // HID type OSC
#define HID_SYSTEM_MENU_RIGHT 0x8A // HID type RTC
#define HID_SYSTEM_MENU_LEFT 0x8B // HID type RTC
#define HID_SYSTEM_MENU_UP 0x8C // HID type RTC
#define HID_SYSTEM_MENU_DOWN 0x8D // HID type RTC
#define HID_SYSTEM_COLD_RESTART 0x8E // HID type OSC
#define HID_SYSTEM_WARM_RESTART 0x8F // HID type OSC
#define HID_D_PAD_UP 0x90 // HID type OOC
#define HID_D_PAD_DOWN 0x91 // HID type OOC
#define HID_D_PAD_RIGHT 0x92 // HID type OOC
#define HID_D_PAD_LEFT 0x93 // HID type OOC
// 0x94-0x9F are reserved
#define HID_SYSTEM_DOCK 0xA0 // HID type OSC
#define HID_SYSTEM_UNDOCK 0xA1 // HID type OSC
#define HID_SYSTEM_SETUP 0xA2 // HID type OSC
#define HID_SYSTEM_BREAK 0xA3 // HID type OSC
#define HID_SYSTEM_DEBUGGER_BREAK 0xA4 // HID type OSC
#define HID_APPLICATION_BREAK 0xA5 // HID type OSC
#define HID_APPLICATION_DEBUGGER_BREAK 0xA6 // HID type OSC
#define HID_SYSTEM_SPEAKER_MUTE 0xA7 // HID type OSC
#define HID_SYSTEM_HIBERNATE 0xA8 // HID type OSC
// 0xA9-0xAF are reserved
#define HID_SYSTEM_DISPLAY_INVERT 0xB0 // HID type OSC
#define HID_SYSTEM_DISPLAY_INTERNAL 0xB1 // HID type OSC
#define HID_SYSTEM_DISPLAY_EXTERNAL 0xB2 // HID type OSC
#define HID_SYSTEM_DISPLAY_BOTH 0xB3 // HID type OSC
#define HID_SYSTEM_DISPLAY_DUAL 0xB4 // HID type OSC
#define HID_SYSTEM_DISPLAY_TOGGLE_INT_SLASH_EXT 0xB5 // HID type OSC
#define HID_SYSTEM_DISPLAY_SWAP_PRIMARY_SLASH_SECONDARY 0xB6 // HID type OSC
#define HID_SYSTEM_DISPLAY_LCD_AUTOSCALE 0xB7 // HID type OSC
// Keyboard HID mappings
// Reserved (no_event_indicated) 0x00
#define HID_KEYBOARD_ERROR_ROLLOVER 0x01
#define HID_KEYBOARD_POST_FAIL 0x02
#define HID_KEYBOARD_ERROR_UNDEFINED 0x03
#define HID_KEYBOARD_A_AND_A 0x04
#define HID_KEYBOARD_B_AND_B 0x05
#define HID_KEYBOARD_C_AND_C 0x06
#define HID_KEYBOARD_D_AND_D 0x07
#define HID_KEYBOARD_E_AND_E 0x08
#define HID_KEYBOARD_F_AND_F 0x09
#define HID_KEYBOARD_G_AND_G 0x0A
#define HID_KEYBOARD_H_AND_H 0x0B
#define HID_KEYBOARD_I_AND_I 0x0C
#define HID_KEYBOARD_J_AND_J 0x0D
#define HID_KEYBOARD_K_AND_K 0x0E
#define HID_KEYBOARD_L_AND_L 0x0F
#define HID_KEYBOARD_M_AND_M 0x10
#define HID_KEYBOARD_N_AND_N 0x11
#define HID_KEYBOARD_O_AND_O 0x12
#define HID_KEYBOARD_P_AND_P 0x13
#define HID_KEYBOARD_Q_AND_Q 0x14
#define HID_KEYBOARD_R_AND_R 0x15
#define HID_KEYBOARD_S_AND_S 0x16
#define HID_KEYBOARD_T_AND_T 0x17
#define HID_KEYBOARD_U_AND_U 0x18
#define HID_KEYBOARD_V_AND_V 0x19
#define HID_KEYBOARD_W_AND_W 0x1A
#define HID_KEYBOARD_X_AND_X 0x1B
#define HID_KEYBOARD_Y_AND_Y 0x1C
#define HID_KEYBOARD_Z_AND_Z 0x1D
#define HID_KEYBOARD_1_AND_EXCLAMATION_POINT 0x1E
#define HID_KEYBOARD_2_AND_AT 0x1F
#define HID_KEYBOARD_3_AND_POUND 0x20
#define HID_KEYBOARD_4_AND_DOLLAR 0x21
#define HID_KEYBOARD_5_AND_PERCENT 0x22
#define HID_KEYBOARD_6_AND_CARAT 0x23
#define HID_KEYBOARD_7_AND_AMPERSAND 0x24
#define HID_KEYBOARD_8_AND_ASTERISK 0x25
#define HID_KEYBOARD_9_AND_LEFT_PAREN 0x26
#define HID_KEYBOARD_0_AND_RIGHT_PAREN 0x27
#define HID_KEYBOARD_ENTER 0x28 // (MARKED AS ENTER_SLASH_RETURN)
#define HID_KEYBOARD_ESCAPE 0x29
#define HID_KEYBOARD_DELETE 0x2A // (BACKSPACE)
#define HID_KEYBOARD_TAB 0x2B
#define HID_KEYBOARD_SPACEBAR 0x2C
#define HID_KEYBOARD_MINUS_AND_UNDERSCORE 0x2D // (UNDERSCORE)
#define HID_KEYBOARD_EQUALS_AND_PLUS 0x2E
#define HID_KEYBOARD_LEFT_BRACKET_AND_LEFT_CURLY_BRACE 0x2F
#define HID_KEYBOARD_RIGHT_BRACKET_AND_RIGHT_CURLY_BRACE 0x30
#define HID_KEYBOARD_BACKSLASH_AND_PIPE 0x31
#define HID_KEYBOARD_NON_US_POUND_AND_TILDE 0x32
#define HID_KEYBOARD_SEMICOLON_AND_COLON 0x33
#define HID_KEYBOARD_QUOTE_AND_DOUBLEQUOTE 0x34
#define HID_KEYBOARD_GRAVE_ACCENT_AND_TILDE 0x35
#define HID_KEYBOARD_COMMA_AND_LESS_THAN 0x36
#define HID_KEYBOARD_PERIOD_AND_GREATER_THAN 0x37
#define HID_KEYBOARD_SLASH_AND_QUESTION_MARK 0x38
#define HID_KEYBOARD_CAPS_LOCK 0x39
#define HID_KEYBOARD_F1 0x3A
#define HID_KEYBOARD_F2 0x3B
#define HID_KEYBOARD_F3 0x3C
#define HID_KEYBOARD_F4 0x3D
#define HID_KEYBOARD_F5 0x3E
#define HID_KEYBOARD_F6 0x3F
#define HID_KEYBOARD_F7 0x40
#define HID_KEYBOARD_F8 0x41
#define HID_KEYBOARD_F9 0x42
#define HID_KEYBOARD_F10 0x43
#define HID_KEYBOARD_F11 0x44
#define HID_KEYBOARD_F12 0x45
#define HID_KEYBOARD_PRINTSCREEN 0x46
#define HID_KEYBOARD_SCROLL_LOCK 0x47
#define HID_KEYBOARD_PAUSE 0x48
#define HID_KEYBOARD_INSERT 0x49
#define HID_KEYBOARD_HOME 0x4A
#define HID_KEYBOARD_PAGE_UP 0x4B
#define HID_KEYBOARD_DELETE_FORWARD 0x4C
#define HID_KEYBOARD_END 0x4D
#define HID_KEYBOARD_PAGE_DOWN 0x4E
#define HID_KEYBOARD_RIGHTARROW 0x4F
#define HID_KEYBOARD_LEFTARROW 0x50
#define HID_KEYBOARD_DOWNARROW 0x51
#define HID_KEYBOARD_UPARROW 0x52
#define HID_KEYPAD_NUM_LOCK_AND_CLEAR 0x53
#define HID_KEYPAD_DIVIDE 0x54
#define HID_KEYPAD_MULTIPLY 0x55
#define HID_KEYPAD_SUBTRACT 0x56
#define HID_KEYPAD_ADD 0x57
#define HID_KEYPAD_ENTER 0x58
#define HID_KEYPAD_1_AND_END 0x59
#define HID_KEYPAD_2_AND_DOWN_ARROW 0x5A
#define HID_KEYPAD_3_AND_PAGE_DOWN 0x5B
#define HID_KEYPAD_4_AND_LEFT_ARROW 0x5C
#define HID_KEYPAD_5 0x5D
#define HID_KEYPAD_6_AND_RIGHT_ARROW 0x5E
#define HID_KEYPAD_7_AND_HOME 0x5F
#define HID_KEYPAD_8_AND_UP_ARROW 0x60
#define HID_KEYPAD_9_AND_PAGE_UP 0x61
#define HID_KEYPAD_0_AND_INSERT 0x62
#define HID_KEYPAD_PERIOD_AND_DELETE 0x63
#define HID_KEYBOARD_NON_US_BACKSLASH_AND_PIPE 0x64
#define HID_KEYBOARD_APPLICATION 0x65
#define HID_KEYBOARD_POWER 0x66
#define HID_KEYPAD_EQUALS 0x67
#define HID_KEYBOARD_F13 0x68
#define HID_KEYBOARD_F14 0x69
#define HID_KEYBOARD_F15 0x6A
#define HID_KEYBOARD_F16 0x6B
#define HID_KEYBOARD_F17 0x6C
#define HID_KEYBOARD_F18 0x6D
#define HID_KEYBOARD_F19 0x6E
#define HID_KEYBOARD_F20 0x6F
#define HID_KEYBOARD_F21 0x70
#define HID_KEYBOARD_F22 0x71
#define HID_KEYBOARD_F23 0x72
#define HID_KEYBOARD_F24 0x73
#define HID_KEYBOARD_EXECUTE 0x74
#define HID_KEYBOARD_HELP 0x75
#define HID_KEYBOARD_MENU 0x76
#define HID_KEYBOARD_SELECT 0x77
#define HID_KEYBOARD_STOP 0x78
#define HID_KEYBOARD_AGAIN 0x79
#define HID_KEYBOARD_UNDO 0x7A
#define HID_KEYBOARD_CUT 0x7B
#define HID_KEYBOARD_COPY 0x7C
#define HID_KEYBOARD_PASTE 0x7D
#define HID_KEYBOARD_FIND 0x7E
#define HID_KEYBOARD_MUTE 0x7F
#define HID_KEYBOARD_VOLUME_UP 0x80
#define HID_KEYBOARD_VOLUME_DOWN 0x81
#define HID_KEYBOARD_LOCKING_CAPS_LOCK 0x82
#define HID_KEYBOARD_LOCKING_NUM_LOCK 0x83
#define HID_KEYBOARD_LOCKING_SCROLL_LOCK 0x84
#define HID_KEYPAD_COMMA 0x85
#define HID_KEYPAD_EQUAL_SIGN 0x86
#define HID_KEYBOARD_INTERNATIONAL1 0x87
#define HID_KEYBOARD_INTERNATIONAL2 0x88
#define HID_KEYBOARD_INTERNATIONAL3 0x89
#define HID_KEYBOARD_INTERNATIONAL4 0x8A
#define HID_KEYBOARD_INTERNATIONAL5 0x8B
#define HID_KEYBOARD_INTERNATIONAL6 0x8C
#define HID_KEYBOARD_INTERNATIONAL7 0x8D
#define HID_KEYBOARD_INTERNATIONAL8 0x8E
#define HID_KEYBOARD_INTERNATIONAL9 0x8F
#define HID_KEYBOARD_LANG1 0x90
#define HID_KEYBOARD_LANG2 0x91
#define HID_KEYBOARD_LANG3 0x92
#define HID_KEYBOARD_LANG4 0x93
#define HID_KEYBOARD_LANG5 0x94
#define HID_KEYBOARD_LANG6 0x95
#define HID_KEYBOARD_LANG7 0x96
#define HID_KEYBOARD_LANG8 0x97
#define HID_KEYBOARD_LANG9 0x98
#define HID_KEYBOARD_ALTERNATE_ERASE 0x99
#define HID_KEYBOARD_SYSREQ_SLASH_ATTENTION 0x9A
#define HID_KEYBOARD_CANCEL 0x9B
#define HID_KEYBOARD_CLEAR 0x9C
#define HID_KEYBOARD_PRIOR 0x9D
#define HID_KEYBOARD_RETURN 0x9E
#define HID_KEYBOARD_SEPARATOR 0x9F
#define HID_KEYBOARD_OUT 0xA0
#define HID_KEYBOARD_OPER 0xA1
#define HID_KEYBOARD_CLEAR_SLASH_AGAIN 0xA2
#define HID_KEYBOARD_CRSEL_SLASH_PROPS 0xA3
#define HID_KEYBOARD_EXSEL 0xA4
// Reserved 0xA5-AF
#define HID_KEYPAD_00 0xB0
#define HID_KEYPAD_000 0xB1
#define HID_THOUSANDS_SEPARATOR 0xB2
#define HID_DECIMAL_SEPARATOR 0xB3
#define HID_CURRENCY_UNIT 0xB4
#define HID_CURRENCY_SUBUNIT 0xB5
#define HID_KEYPAD_LEFT_PAREN 0xB6
#define HID_KEYPAD_RIGHT_PAREN 0xB7
#define HID_KEYPAD_LEFT_CURLY_BRACE 0xB8
#define HID_KEYPAD_RIGHT_CURLY_BRACE 0xB9
#define HID_KEYPAD_TAB 0xBA
#define HID_KEYPAD_BACKSPACE 0xBB
#define HID_KEYPAD_A 0xBC
#define HID_KEYPAD_B 0xBD
#define HID_KEYPAD_C 0xBE
#define HID_KEYPAD_D 0xBF
#define HID_KEYPAD_E 0xC0
#define HID_KEYPAD_F 0xC1
#define HID_KEYPAD_XOR 0xC2
#define HID_KEYPAD_CARAT 0xC3
#define HID_KEYPAD_PERCENT 0xC4
#define HID_KEYPAD_LESS_THAN 0xC5
#define HID_KEYPAD_GREATER_THAN 0xC6
#define HID_KEYPAD_AMPERSAND 0xC7
#define HID_KEYPAD_DOUBLEAMPERSAND 0xC8
#define HID_KEYPAD_PIPE 0xC9
#define HID_KEYPAD_DOUBLEPIPE 0xCA
#define HID_KEYPAD_COLON 0xCB
#define HID_KEYPAD_POUND_SIGN 0xCC
#define HID_KEYPAD_SPACE 0xCD
#define HID_KEYPAD_AT_SIGN 0xCE
#define HID_KEYPAD_EXCLAMATION_POINT 0xCF
#define HID_KEYPAD_MEMORY_STORE 0xD0
#define HID_KEYPAD_MEMORY_RECALL 0xD1
#define HID_KEYPAD_MEMORY_CLEAR 0xD2
#define HID_KEYPAD_MEMORY_ADD 0xD3
#define HID_KEYPAD_MEMORY_SUBTRACT 0xD4
#define HID_KEYPAD_MEMORY_MULTIPLY 0xD5
#define HID_KEYPAD_MEMORY_DIVIDE 0xD6
#define HID_KEYPAD_PLUS_SLASH_MINUS 0xD7
#define HID_KEYPAD_CLEAR 0xD8
#define HID_KEYPAD_CLEAR_ENTRY 0xD9
#define HID_KEYPAD_BINARY 0xDA
#define HID_KEYPAD_OCTAL 0xDB
#define HID_KEYPAD_DECIMAL 0xDC
#define HID_KEYPAD_HEXADECIMAL 0xDD
// 0xDE-0xDF - RESERVED
#define HID_KEYBOARD_LEFT_CONTROL 0xE0
#define HID_KEYBOARD_LEFT_SHIFT 0xE1
#define HID_KEYBOARD_LEFT_ALT 0xE2
#define HID_KEYBOARD_LEFT_GUI 0xE3
#define HID_KEYBOARD_RIGHT_CONTROL 0xE4
#define HID_KEYBOARD_RIGHT_SHIFT 0xE5
#define HID_KEYBOARD_RIGHT_ALT 0xE6
#define HID_KEYBOARD_RIGHT_GUI 0xE7
// Consumer_Page_(0x0C) 0x15
#define HID_CONSUMER_NUMERIC_KEY_PAD 0x02 // HID type NARY
#define HID_CONSUMER_PROGRAMMABLE_BUTTONS 0x03 // HID type NARY
#define HID_CONSUMER_MICROPHONE_CA 0x04
#define HID_CONSUMER_HEADPHONE_CA 0x05
#define HID_CONSUMER_GRAPHIC_EQUALIZER_CA 0x06
// Reserved 0x07-1F
#define HID_CONSUMER_PLUS_10 0x20 // HID type OSC
#define HID_CONSUMER_PLUS_100 0x21 // HID type OSC
#define HID_CONSUMER_AM_SLASH_PM 0x22 // HID type OSC
// Reserved 0x23-3F
#define HID_CONSUMER_POWER 0x30 // HID type OOC
#define HID_CONSUMER_RESET 0x31 // HID type OSC
#define HID_CONSUMER_SLEEP 0x32 // HID type OSC
#define HID_CONSUMER_SLEEP_AFTER 0x33 // HID type OSC
#define HID_CONSUMER_SLEEP_MODE 0x34 // HID type RTC
#define HID_CONSUMER_ILLUMINATION 0x35 // HID type OOC
#define HID_CONSUMER_FUNCTION_BUTTONS 0x36 // HID type NARY
// Reserved 0x37-3F
#define HID_CONSUMER_MENU 0x40 // HID type OOC
#define HID_CONSUMER_MENU_PICK 0x41 // HID type OSC
#define HID_CONSUMER_MENU_UP 0x42 // HID type OSC
#define HID_CONSUMER_MENU_DOWN 0x43 // HID type OSC
#define HID_CONSUMER_MENU_LEFT 0x44 // HID type OSC
#define HID_CONSUMER_MENU_RIGHT 0x45 // HID type OSC
#define HID_CONSUMER_MENU_ESCAPE 0x46 // HID type OSC
#define HID_CONSUMER_MENU_VALUE_INCREASE 0x47 // HID type OSC
#define HID_CONSUMER_MENU_VALUE_DECREASE 0x48 // HID type OSC
// Reserved 0x49-5F
#define HID_CONSUMER_DATA_ON_SCREEN 0x60 // HID type OOC
#define HID_CONSUMER_CLOSED_CAPTION 0x61 // HID type OOC
#define HID_CONSUMER_CLOSED_CAPTION_SELECT 0x62 // HID type OSC
#define HID_CONSUMER_VCR_SLASH_TV 0x63 // HID type OOC
#define HID_CONSUMER_BROADCAST_MODE 0x64 // HID type OSC
#define HID_CONSUMER_SNAPSHOT 0x65 // HID type OSC
#define HID_CONSUMER_STILL 0x66 // HID type OSC
// Reserved 0x67-7F
#define HID_CONSUMER_SELECTION 0x80 // HID type NARY
#define HID_CONSUMER_ASSIGN_SELECTION 0x81 // HID type OSC
#define HID_CONSUMER_MODE_STEP 0x82 // HID type OSC
#define HID_CONSUMER_RECALL_LAST 0x83 // HID type OSC
#define HID_CONSUMER_ENTER_CHANNEL 0x84 // HID type OSC
#define HID_CONSUMER_ORDER_MOVIE 0x85 // HID type OSC
#define HID_CONSUMER_CHANNEL 0x86 // HID type LC
#define HID_CONSUMER_MEDIA_SELECTION 0x87 // HID type NARY
#define HID_CONSUMER_MEDIA_SELECT_COMPUTER 0x88 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_TV 0x89 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_WWW 0x8A // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_DVD 0x8B // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_TELEPHONE 0x8C // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_PROGRAM_GUIDE 0x8D // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_VIDEO_PHONE 0x8E // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_GAMES 0x8F // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_MESSAGES 0x90 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_CD 0x91 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_VCR 0x92 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_TUNER 0x93 // HID type SEL
#define HID_CONSUMER_QUIT 0x94 // HID type OSC
#define HID_CONSUMER_HELP 0x95 // HID type OOC
#define HID_CONSUMER_MEDIA_SELECT_TAPE 0x96 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_CABLE 0x97 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_SATELLITE 0x98 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_SECURITY 0x99 // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_HOME 0x9A // HID type SEL
#define HID_CONSUMER_MEDIA_SELECT_CALL 0x9B // HID type SEL
#define HID_CONSUMER_CHANNEL_INCREMENT 0x9C // HID type OSC
#define HID_CONSUMER_CHANNEL_DECREMENT 0x9D // HID type OSC
#define HID_CONSUMER_MEDIA_SELECT_SAP 0x9E // HID type SEL
// Reserved 0x9F
#define HID_CONSUMER_VCR_PLUS 0xA0 // HID type OSC
#define HID_CONSUMER_ONCE 0xA1 // HID type OSC
#define HID_CONSUMER_DAILY 0xA2 // HID type OSC
#define HID_CONSUMER_WEEKLY 0xA3 // HID type OSC
#define HID_CONSUMER_MONTHLY 0xA4 // HID type OSC
// Reserved 0xA5-AF
#define HID_CONSUMER_PLAY 0xB0 // HID type OOC
#define HID_CONSUMER_PAUSE 0xB1 // HID type OOC
#define HID_CONSUMER_RECORD 0xB2 // HID type OOC
#define HID_CONSUMER_FAST_FORWARD 0xB3 // HID type OOC
#define HID_CONSUMER_REWIND 0xB4 // HID type OOC
#define HID_CONSUMER_SCAN_NEXT_TRACK 0xB5 // HID type OSC
#define HID_CONSUMER_SCAN_PREVIOUS_TRACK 0xB6 // HID type OSC
#define HID_CONSUMER_STOP 0xB7 // HID type OSC
#define HID_CONSUMER_EJECT 0xB8 // HID type OSC
#define HID_CONSUMER_RANDOM_PLAY 0xB9 // HID type OOC
#define HID_CONSUMER_SELECT_DISC 0xBA // HID type NARY
#define HID_CONSUMER_ENTER_DISC_MC 0xBB
#define HID_CONSUMER_REPEAT 0xBC // HID type OSC
#define HID_CONSUMER_TRACKING 0xBD // HID type LC
#define HID_CONSUMER_TRACK_NORMAL 0xBE // HID type OSC
#define HID_CONSUMER_SLOW_TRACKING 0xBF // HID type LC
#define HID_CONSUMER_FRAME_FORWARD 0xC0 // HID type RTC
#define HID_CONSUMER_FRAME_BACK 0xC1 // HID type RTC
#define HID_CONSUMER_MARK 0xC2 // HID type OSC
#define HID_CONSUMER_CLEAR_MARK 0xC3 // HID type OSC
#define HID_CONSUMER_REPEAT_FROM_MARK 0xC4 // HID type OOC
#define HID_CONSUMER_RETURN_TO_MARK 0xC5 // HID type OSC
#define HID_CONSUMER_SEARCH_MARK_FORWARD 0xC6 // HID type OSC
#define HID_CONSUMER_SEARCH_MARK_BACKWARDS 0xC7 // HID type OSC
#define HID_CONSUMER_COUNTER_RESET 0xC8 // HID type OSC
#define HID_CONSUMER_SHOW_COUNTER 0xC9 // HID type OSC
#define HID_CONSUMER_TRACKING_INCREMENT 0xCA // HID type RTC
#define HID_CONSUMER_TRACKING_DECREMENT 0xCB // HID type RTC
#define HID_CONSUMER_STOP_SLASH_EJECT 0xCC // HID type OSC
#define HID_CONSUMER_PLAY_SLASH_PAUSE 0xCD // HID type OSC
#define HID_CONSUMER_PLAY_SLASH_SKIP 0xCE // HID type OSC
// Reserved 0xCF-DF
#define HID_CONSUMER_VOLUME 0xE0 // HID type LC
#define HID_CONSUMER_BALANCE 0xE1 // HID type LC
#define HID_CONSUMER_MUTE 0xE2 // HID type OOC
#define HID_CONSUMER_BASS 0xE3 // HID type LC
#define HID_CONSUMER_TREBLE 0xE4 // HID type LC
#define HID_CONSUMER_BASS_BOOST 0xE5 // HID type OOC
#define HID_CONSUMER_SURROUND_MODE 0xE6 // HID type OSC
#define HID_CONSUMER_LOUDNESS 0xE7 // HID type OOC
#define HID_CONSUMER_MPX 0xE8 // HID type OOC
#define HID_CONSUMER_VOLUME_INCREMENT 0xE9 // HID type RTC
#define HID_CONSUMER_VOLUME_DECREMENT 0xEA // HID type RTC
// Reserved 0xEB-EF
#define HID_CONSUMER_SPEED_SELECT 0xF0 // HID type OSC
#define HID_CONSUMER_PLAYBACK_SPEED 0xF1 // HID type NARY
#define HID_CONSUMER_STANDARD_PLAY 0xF2 // HID type SEL
#define HID_CONSUMER_LONG_PLAY 0xF3 // HID type SEL
#define HID_CONSUMER_EXTENDED_PLAY 0xF4 // HID type SEL
#define HID_CONSUMER_SLOW 0xF5 // HID type OSC
// Reserved 0xF6-FF
#define HID_CONSUMER_FAN_ENABLE 0x100 // HID type OOC
#define HID_CONSUMER_FAN_SPEED 0x101 // HID type LC
#define HID_CONSUMER_LIGHT_ENABLE 0x102 // HID type OOC
#define HID_CONSUMER_LIGHT_ILLUMINATION_LEVEL 0x103 // HID type LC
#define HID_CONSUMER_CLIMATE_CONTROL_ENABLE 0x104 // HID type OOC
#define HID_CONSUMER_ROOM_TEMPERATURE 0x105 // HID type LC
#define HID_CONSUMER_SECURITY_ENABLE 0x106 // HID type OOC
#define HID_CONSUMER_FIRE_ALARM 0x107 // HID type OSC
#define HID_CONSUMER_POLICE_ALARM 0x108 // HID type OSC
#define HID_CONSUMER_PROXIMITY 0x109 // HID type LC
#define HID_CONSUMER_MOTION 0x10A // HID type OSC
#define HID_CONSUMER_DURESS_ALARM 0x10B // HID type OSC
#define HID_CONSUMER_HOLDUP_ALARM 0x10C // HID type OSC
#define HID_CONSUMER_MEDICAL_ALARM 0x10D // HID type OSC
// Reserved 0x10E-14F
#define HID_CONSUMER_BALANCE_RIGHT 0x150 // HID type RTC
#define HID_CONSUMER_BALANCE_LEFT 0x151 // HID type RTC
#define HID_CONSUMER_BASS_INCREMENT 0x152 // HID type RTC
#define HID_CONSUMER_BASS_DECREMENT 0x153 // HID type RTC
#define HID_CONSUMER_TREBLE_INCREMENT 0x154 // HID type RTC
#define HID_CONSUMER_TREBLE_DECREMENT 0x155 // HID type RTC
// Reserved 0x156-15F
#define HID_CONSUMER_SPEAKER_SYSTEM 0x160 // HID type CL
#define HID_CONSUMER_CHANNEL_LEFT 0x161 // HID type CL
#define HID_CONSUMER_CHANNEL_RIGHT 0x162 // HID type CL
#define HID_CONSUMER_CHANNEL_CENTER 0x163 // HID type CL
#define HID_CONSUMER_CHANNEL_FRONT 0x164 // HID type CL
#define HID_CONSUMER_CHANNEL_CENTER_FRONT 0x165 // HID type CL
#define HID_CONSUMER_CHANNEL_SIDE 0x166 // HID type CL
#define HID_CONSUMER_CHANNEL_SURROUND 0x167 // HID type CL
#define HID_CONSUMER_CHANNEL_LOW_FREQUENCY_ENHANCEMENT 0x168 // HID type CL
#define HID_CONSUMER_CHANNEL_TOP 0x169 // HID type CL
#define HID_CONSUMER_CHANNEL_UNKNOWN 0x16A // HID type CL
// Reserved 0x16B-16F
#define HID_CONSUMER_SUB-CHANNEL 0x170 // HID type LC
#define HID_CONSUMER_SUB-CHANNEL_INCREMENT 0x171 // HID type OSC
#define HID_CONSUMER_SUB-CHANNEL_DECREMENT 0x172 // HID type OSC
#define HID_CONSUMER_ALTERNATE_AUDIO_INCREMENT 0x173 // HID type OSC
#define HID_CONSUMER_ALTERNATE_AUDIO_DECREMENT 0x174 // HID type OSC
// Reserved 0x175-17F
#define HID_CONSUMER_APPLICATION_LAUNCH_BUTTONS 0x180 // HID type NARY
#define HID_CONSUMER_AL_LAUNCH_BUTTON_CONFIGURATION_TOOL 0x181 // HID type SEL
#define HID_CONSUMER_AL_PROGRAMMABLE_BUTTON_CONFIGURATION 0x182 // HID type SEL
#define HID_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION 0x183 // HID type SEL
#define HID_CONSUMER_AL_WORD_PROCESSOR 0x184 // HID type SEL
#define HID_CONSUMER_AL_TEXT_EDITOR 0x185 // HID type SEL
#define HID_CONSUMER_AL_SPREADSHEET 0x186 // HID type SEL
#define HID_CONSUMER_AL_GRAPHICS_EDITOR 0x187 // HID type SEL
#define HID_CONSUMER_AL_PRESENTATION_APP 0x188 // HID type SEL
#define HID_CONSUMER_AL_DATABASE_APP 0x189 // HID type SEL
#define HID_CONSUMER_AL_EMAIL_READER 0x18A // HID type SEL
#define HID_CONSUMER_AL_NEWSREADER 0x18B // HID type SEL
#define HID_CONSUMER_AL_VOICEMAIL 0x18C // HID type SEL
#define HID_CONSUMER_AL_CONTACTS_SLASH_ADDRESS_BOOK 0x18D // HID type SEL
#define HID_CONSUMER_AL_CALENDAR_SLASH_SCHEDULE 0x18E // HID type SEL
#define HID_CONSUMER_AL_TASK_SLASH_PROJECT_MANAGER 0x18F // HID type SEL
#define HID_CONSUMER_AL_LOG_SLASH_JOURNAL_SLASH_TIMECARD 0x190 // HID type SEL
#define HID_CONSUMER_AL_CHECKBOOK_SLASH_FINANCE 0x191 // HID type SEL
#define HID_CONSUMER_AL_CALCULATOR 0x192 // HID type SEL
#define HID_CONSUMER_AL_A_SLASH_V_CAPTURE_SLASH_PLAYBACK 0x193 // HID type SEL
#define HID_CONSUMER_AL_LOCAL_MACHINE_BROWSER 0x194 // HID type SEL
#define HID_CONSUMER_AL_LAN_SLASH_WAN_BROWSER 0x195 // HID type SEL
#define HID_CONSUMER_AL_INTERNET_BROWSER 0x196 // HID type SEL
#define HID_CONSUMER_AL_REMOTE_NETWORKING_SLASH_ISP_CONNECT 0x197 // HID type SEL
#define HID_CONSUMER_AL_NETWORK_CONFERENCE 0x198 // HID type SEL
#define HID_CONSUMER_AL_NETWORK_CHAT 0x199 // HID type SEL
#define HID_CONSUMER_AL_TELEPHONY_SLASH_DIALER 0x19A // HID type SEL
#define HID_CONSUMER_AL_LOGON 0x19B // HID type SEL
#define HID_CONSUMER_AL_LOGOFF 0x19C // HID type SEL
#define HID_CONSUMER_AL_LOGON_SLASH_LOGOFF 0x19D // HID type SEL
#define HID_CONSUMER_AL_TERMINAL_LOCK_SLASH_SCREENSAVER 0x19E // HID type SEL
#define HID_CONSUMER_AL_CONTROL_PANEL 0x19F // HID type SEL
#define HID_CONSUMER_AL_COMMAND_LINE_PROCESSOR_SLASH_RUN 0x1A0 // HID type SEL
#define HID_CONSUMER_AL_PROCESS_SLASH_TASK_MANAGER 0x1A1 // HID type SEL
#define HID_CONSUMER_AL_SELECT_TASK_SLASH_APPLICATION 0x1A2 // HID type SEL
#define HID_CONSUMER_AL_NEXT_TASK_SLASH_APPLICATION 0x1A3 // HID type SEL
#define HID_CONSUMER_AL_PREVIOUS_TASK_SLASH_APPLICATION 0x1A4 // HID type SEL
#define HID_CONSUMER_AL_PREEMPTIVE_HALT_TASK_SLASH_APPLICATION 0x1A5 // HID type SEL
#define HID_CONSUMER_AL_INTEGRATED_HELP_CENTER 0x1A6 // HID type SEL
#define HID_CONSUMER_AL_DOCUMENTS 0x1A7 // HID type SEL
#define HID_CONSUMER_AL_THESAURUS 0x1A8 // HID type SEL
#define HID_CONSUMER_AL_DICTIONARY 0x1A9 // HID type SEL
#define HID_CONSUMER_AL_DESKTOP 0x1AA // HID type SEL
#define HID_CONSUMER_AL_SPELL_CHECK 0x1AB // HID type SEL
#define HID_CONSUMER_AL_GRAMMAR_CHECK 0x1AC // HID type SEL
#define HID_CONSUMER_AL_WIRELESS_STATUS 0x1AD // HID type SEL
#define HID_CONSUMER_AL_KEYBOARD_LAYOUT 0x1AE // HID type SEL
#define HID_CONSUMER_AL_VIRUS_PROTECTION 0x1AF // HID type SEL
#define HID_CONSUMER_AL_ENCRYPTION 0x1B0 // HID type SEL
#define HID_CONSUMER_AL_SCREEN_SAVER 0x1B1 // HID type SEL
#define HID_CONSUMER_AL_ALARMS 0x1B2 // HID type SEL
#define HID_CONSUMER_AL_CLOCK 0x1B3 // HID type SEL
#define HID_CONSUMER_AL_FILE_BROWSER 0x1B4 // HID type SEL
#define HID_CONSUMER_AL_POWER_STATUS 0x1B5 // HID type SEL
#define HID_CONSUMER_AL_IMAGE_BROWSER 0x1B6 // HID type SEL
#define HID_CONSUMER_AL_AUDIO_BROWSER 0x1B7 // HID type SEL
#define HID_CONSUMER_AL_MOVIE_BROWSER 0x1B8 // HID type SEL
#define HID_CONSUMER_AL_DIGITAL_RIGHTS_MANAGER 0x1B9 // HID type SEL
#define HID_CONSUMER_AL_DIGITAL_WALLET 0x1BA // HID type SEL
// _Reserved 0x1BB
#define HID_CONSUMER_AL_INSTANT_MESSAGING 0x1BC // HID type SEL
#define HID_CONSUMER_AL_OEM_FEATURES_SLASH__TIPS_SLASH_TUTORIAL_BROWSER 0x1BD // HID type SEL
#define HID_CONSUMER_AL_OEM_HELP 0x1BE // HID type SEL
#define HID_CONSUMER_AL_ONLINE_COMMUNITY 0x1BF // HID type SEL
#define HID_CONSUMER_AL_ENTERTAINMENT_CONTENT_BROWSER 0x1C0 // HID type SEL
#define HID_CONSUMER_AL_ONLINE_SHOPPING_BROWSER 0x1C1 // HID type SEL
#define HID_CONSUMER_AL_SMARTCARD_INFORMATION_SLASH_HELP 0x1C2 // HID type SEL
#define HID_CONSUMER_AL_MARKET_MONITOR_SLASH_FINANCE_BROWSER 0x1C3 // HID type SEL
#define HID_CONSUMER_AL_CUSTOMIZED_CORPORATE_NEWS_BROWSER 0x1C4 // HID type SEL
#define HID_CONSUMER_AL_ONLINE_ACTIVITY_BROWSER 0x1C5 // HID type SEL
#define HID_CONSUMER_AL_RESEARCH_SLASH_SEARCH_BROWSER 0x1C6 // HID type SEL
#define HID_CONSUMER_AL_AUDIO_PLAYER 0x1C7 // HID type SEL
// Reserved 0x1C8-1FF
#define HID_CONSUMER_GENERIC_GUI_APPLICATION_CONTROLS 0x200 // HID type NARY
#define HID_CONSUMER_AC_NEW 0x201 // HID type SEL
#define HID_CONSUMER_AC_OPEN 0x202 // HID type SEL
#define HID_CONSUMER_AC_CLOSE 0x203 // HID type SEL
#define HID_CONSUMER_AC_EXIT 0x204 // HID type SEL
#define HID_CONSUMER_AC_MAXIMIZE 0x205 // HID type SEL
#define HID_CONSUMER_AC_MINIMIZE 0x206 // HID type SEL
#define HID_CONSUMER_AC_SAVE 0x207 // HID type SEL
#define HID_CONSUMER_AC_PRINT 0x208 // HID type SEL
#define HID_CONSUMER_AC_PROPERTIES 0x209 // HID type SEL
#define HID_CONSUMER_AC_UNDO 0x21A // HID type SEL
#define HID_CONSUMER_AC_COPY 0x21B // HID type SEL
#define HID_CONSUMER_AC_CUT 0x21C // HID type SEL
#define HID_CONSUMER_AC_PASTE 0x21D // HID type SEL
#define HID_CONSUMER_AC_SELECT_ALL 0x21E // HID type SEL
#define HID_CONSUMER_AC_FIND 0x21F // HID type SEL
#define HID_CONSUMER_AC_FIND_AND_REPLACE 0x220 // HID type SEL
#define HID_CONSUMER_AC_SEARCH 0x221 // HID type SEL
#define HID_CONSUMER_AC_GO_TO 0x222 // HID type SEL
#define HID_CONSUMER_AC_HOME 0x223 // HID type SEL
#define HID_CONSUMER_AC_BACK 0x224 // HID type SEL
#define HID_CONSUMER_AC_FORWARD 0x225 // HID type SEL
#define HID_CONSUMER_AC_STOP 0x226 // HID type SEL
#define HID_CONSUMER_AC_REFRESH 0x227 // HID type SEL
#define HID_CONSUMER_AC_PREVIOUS_LINK 0x228 // HID type SEL
#define HID_CONSUMER_AC_NEXT_LINK 0x229 // HID type SEL
#define HID_CONSUMER_AC_BOOKMARKS 0x22A // HID type SEL
#define HID_CONSUMER_AC_HISTORY 0x22B // HID type SEL
#define HID_CONSUMER_AC_SUBSCRIPTIONS 0x22C // HID type SEL
#define HID_CONSUMER_AC_ZOOM_IN 0x22D // HID type SEL
#define HID_CONSUMER_AC_ZOOM_OUT 0x22E // HID type SEL
#define HID_CONSUMER_AC_ZOOM 0x22F // HID type LC
#define HID_CONSUMER_AC_FULL_SCREEN_VIEW 0x230 // HID type SEL
#define HID_CONSUMER_AC_NORMAL_VIEW 0x231 // HID type SEL
#define HID_CONSUMER_AC_VIEW_TOGGLE 0x232 // HID type SEL
#define HID_CONSUMER_AC_SCROLL_UP 0x233 // HID type SEL
#define HID_CONSUMER_AC_SCROLL_DOWN 0x234 // HID type SEL
#define HID_CONSUMER_AC_SCROLL 0x235 // HID type LC
#define HID_CONSUMER_AC_PAN_LEFT 0x236 // HID type SEL
#define HID_CONSUMER_AC_PAN_RIGHT 0x237 // HID type SEL
#define HID_CONSUMER_AC_PAN 0x238 // HID type LC
#define HID_CONSUMER_AC_NEW_WINDOW 0x239 // HID type SEL
#define HID_CONSUMER_AC_TILE_HORIZONTALLY 0x23A // HID type SEL
#define HID_CONSUMER_AC_TILE_VERTICALLY 0x23B // HID type SEL
#define HID_CONSUMER_AC_FORMAT 0x23C // HID type SEL
#define HID_CONSUMER_AC_EDIT 0x23D // HID type SEL
#define HID_CONSUMER_AC_BOLD 0x23E // HID type SEL
#define HID_CONSUMER_AC_ITALICS 0x23F // HID type SEL
#define HID_CONSUMER_AC_UNDERLINE 0x240 // HID type SEL
#define HID_CONSUMER_AC_STRIKETHROUGH 0x241 // HID type SEL
#define HID_CONSUMER_AC_SUBSCRIPT 0x242 // HID type SEL
#define HID_CONSUMER_AC_SUPERSCRIPT 0x243 // HID type SEL
#define HID_CONSUMER_AC_ALL_CAPS 0x244 // HID type SEL
#define HID_CONSUMER_AC_ROTATE 0x245 // HID type SEL
#define HID_CONSUMER_AC_RESIZE 0x246 // HID type SEL
#define HID_CONSUMER_AC_FLIP_HORIZONTAL 0x247 // HID type SEL
#define HID_CONSUMER_AC_FLIP_VERTICAL 0x248 // HID type SEL
#define HID_CONSUMER_AC_MIRROR_HORIZONTAL 0x249 // HID type SEL
#define HID_CONSUMER_AC_MIRROR_VERTICAL 0x24A // HID type SEL
#define HID_CONSUMER_AC_FONT_SELECT 0x24B // HID type SEL
#define HID_CONSUMER_AC_FONT_COLOR 0x24C // HID type SEL
#define HID_CONSUMER_AC_FONT_SIZE 0x24D // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_LEFT 0x24E // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_CENTER_H 0x24F // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_RIGHT 0x250 // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_BLOCK_H 0x251 // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_TOP 0x252 // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_CENTER_V 0x253 // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_BOTTOM 0x254 // HID type SEL
#define HID_CONSUMER_AC_JUSTIFY_BLOCK_V 0x255 // HID type SEL
#define HID_CONSUMER_AC_INDENT_DECREASE 0x256 // HID type SEL
#define HID_CONSUMER_AC_INDENT_INCREASE 0x257 // HID type SEL
#define HID_CONSUMER_AC_NUMBERED_LIST 0x258 // HID type SEL
#define HID_CONSUMER_AC_RESTART_NUMBERING 0x259 // HID type SEL
#define HID_CONSUMER_AC_BULLETED_LIST 0x25A // HID type SEL
#define HID_CONSUMER_AC_PROMOTE 0x25B // HID type SEL
#define HID_CONSUMER_AC_DEMOTE 0x25C // HID type SEL
#define HID_CONSUMER_AC_YES 0x25D // HID type SEL
#define HID_CONSUMER_AC_NO 0x25E // HID type SEL
#define HID_CONSUMER_AC_CANCEL 0x25F // HID type SEL
#define HID_CONSUMER_AC_CATALOG 0x260 // HID type SEL
#define HID_CONSUMER_AC_BUY_SLASH_CHECKOUT 0x261 // HID type SEL
#define HID_CONSUMER_AC_ADD_TO_CART 0x262 // HID type SEL
#define HID_CONSUMER_AC_EXPAND 0x263 // HID type SEL
#define HID_CONSUMER_AC_EXPAND_ALL 0x264 // HID type SEL
#define HID_CONSUMER_AC_COLLAPSE 0x265 // HID type SEL
#define HID_CONSUMER_AC_COLLAPSE_ALL 0x266 // HID type SEL
#define HID_CONSUMER_AC_PRINT_PREVIEW 0x267 // HID type SEL
#define HID_CONSUMER_AC_PASTE_SPECIAL 0x268 // HID type SEL
#define HID_CONSUMER_AC_INSERT_MODE 0x269 // HID type SEL
#define HID_CONSUMER_AC_DELETE 0x26A // HID type SEL
#define HID_CONSUMER_AC_LOCK 0x26B // HID type SEL
#define HID_CONSUMER_AC_UNLOCK 0x26C // HID type SEL
#define HID_CONSUMER_AC_PROTECT 0x26D // HID type SEL
#define HID_CONSUMER_AC_UNPROTECT 0x26E // HID type SEL
#define HID_CONSUMER_AC_ATTACH_COMMENT 0x26F // HID type SEL
#define HID_CONSUMER_AC_DELETE_COMMENT 0x270 // HID type SEL
#define HID_CONSUMER_AC_VIEW_COMMENT 0x271 // HID type SEL
#define HID_CONSUMER_AC_SELECT_WORD 0x272 // HID type SEL
#define HID_CONSUMER_AC_SELECT_SENTENCE 0x273 // HID type SEL
#define HID_CONSUMER_AC_SELECT_PARAGRAPH 0x274 // HID type SEL
#define HID_CONSUMER_AC_SELECT_COLUMN 0x275 // HID type SEL
#define HID_CONSUMER_AC_SELECT_ROW 0x276 // HID type SEL
#define HID_CONSUMER_AC_SELECT_TABLE 0x277 // HID type SEL
#define HID_CONSUMER_AC_SELECT_OBJECT 0x278 // HID type SEL
#define HID_CONSUMER_AC_REDO_SLASH_REPEAT 0x279 // HID type SEL
#define HID_CONSUMER_AC_SORT 0x27A // HID type SEL
#define HID_CONSUMER_AC_SORT_ASCENDING 0x27B // HID type SEL
#define HID_CONSUMER_AC_SORT_DESCENDING 0x27C // HID type SEL
#define HID_CONSUMER_AC_FILTER 0x27D // HID type SEL
#define HID_CONSUMER_AC_SET_CLOCK 0x27E // HID type SEL
#define HID_CONSUMER_AC_VIEW_CLOCK 0x27F // HID type SEL
#define HID_CONSUMER_AC_SELECT_TIME_ZONE 0x280 // HID type SEL
#define HID_CONSUMER_AC_EDIT_TIME_ZONES 0x281 // HID type SEL
#define HID_CONSUMER_AC_SET_ALARM 0x282 // HID type SEL
#define HID_CONSUMER_AC_CLEAR_ALARM 0x283 // HID type SEL
#define HID_CONSUMER_AC_SNOOZE_ALARM 0x284 // HID type SEL
#define HID_CONSUMER_AC_RESET_ALARM 0x285 // HID type SEL
#define HID_CONSUMER_AC_SYNCHRONIZE 0x286 // HID type SEL
#define HID_CONSUMER_AC_SEND_SLASH_RECEIVE 0x287 // HID type SEL
#define HID_CONSUMER_AC_SEND_TO 0x288 // HID type SEL
#define HID_CONSUMER_AC_REPLY 0x289 // HID type SEL
#define HID_CONSUMER_AC_REPLY_ALL 0x28A // HID type SEL
#define HID_CONSUMER_AC_FORWARD_MSG 0x28B // HID type SEL
#define HID_CONSUMER_AC_SEND 0x28C // HID type SEL
#define HID_CONSUMER_AC_ATTACH_FILE 0x28D // HID type SEL
#define HID_CONSUMER_AC_UPLOAD 0x28E // HID type SEL
#define HID_CONSUMER_AC_DOWNLOAD_(SAVE_TARGET_AS) 0x28F // HID type SEL
#define HID_CONSUMER_AC_SET_BORDERS 0x290 // HID type SEL
#define HID_CONSUMER_AC_INSERT_ROW 0x291 // HID type SEL
#define HID_CONSUMER_AC_INSERT_COLUMN 0x292 // HID type SEL
#define HID_CONSUMER_AC_INSERT_FILE 0x293 // HID type SEL
#define HID_CONSUMER_AC_INSERT_PICTURE 0x294 // HID type SEL
#define HID_CONSUMER_AC_INSERT_OBJECT 0x295 // HID type SEL
#define HID_CONSUMER_AC_INSERT_SYMBOL 0x296 // HID type SEL
#define HID_CONSUMER_AC_SAVE_AND_CLOSE 0x297 // HID type SEL
#define HID_CONSUMER_AC_RENAME 0x298 // HID type SEL
#define HID_CONSUMER_AC_MERGE 0x299 // HID type SEL
#define HID_CONSUMER_AC_SPLIT 0x29A // HID type SEL
#define HID_CONSUMER_AC_DISRIBUTE_HORIZONTALLY 0x29B // HID type SEL
#define HID_CONSUMER_AC_DISTRIBUTE_VERTICALLY 0x29C // HID type SEL
#endif // __HIDTables__

@ -0,0 +1,252 @@
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "Arduino.h"
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a uart
#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
// SerialEvent functions are weak, so when the user doesn't define them,
// the linker just sets their address to 0 (which is checked below).
// The Serialx_available is just a wrapper around Serialx.available(),
// but we can refer to it weakly so we don't pull in the entire
// HardwareSerial instance if the user doesn't also refer to it.
#if defined(HAVE_HWSERIAL0)
void serialEvent() __attribute__((weak));
bool Serial0_available() __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL1)
void serialEvent1() __attribute__((weak));
bool Serial1_available() __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL2)
void serialEvent2() __attribute__((weak));
bool Serial2_available() __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL3)
void serialEvent3() __attribute__((weak));
bool Serial3_available() __attribute__((weak));
#endif
void serialEventRun(void)
{
#if defined(HAVE_HWSERIAL0)
if (Serial0_available && serialEvent && Serial0_available()) serialEvent();
#endif
#if defined(HAVE_HWSERIAL1)
if (Serial1_available && serialEvent1 && Serial1_available()) serialEvent1();
#endif
#if defined(HAVE_HWSERIAL2)
if (Serial2_available && serialEvent2 && Serial2_available()) serialEvent2();
#endif
#if defined(HAVE_HWSERIAL3)
if (Serial3_available && serialEvent3 && Serial3_available()) serialEvent3();
#endif
}
// Actual interrupt handlers //////////////////////////////////////////////////////////////
void HardwareSerial::_tx_udr_empty_irq(void)
{
// If interrupts are enabled, there must be more data in the output
// buffer. Send the next byte
unsigned char c = _tx_buffer[_tx_buffer_tail];
_tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_TX_BUFFER_SIZE;
*_udr = c;
// clear the TXC bit -- "can be cleared by writing a one to its bit
// location". This makes sure flush() won't return until the bytes
// actually got written
sbi(*_ucsra, TXC0);
if (_tx_buffer_head == _tx_buffer_tail) {
// Buffer empty, so disable interrupts
cbi(*_ucsrb, UDRIE0);
}
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(unsigned long baud, byte config)
{
// Try u2x mode first
uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
*_ucsra = 1 << U2X0;
// hardcoded exception for 57600 for compatibility with the bootloader
// shipped with the Duemilanove and previous boards and the firmware
// on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
// be > 4095, so switch back to non-u2x mode if the baud rate is too
// low.
if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
{
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
_written = false;
//set the data bits, parity, and stop bits
#if defined(__AVR_ATmega8__)
config |= 0x80; // select UCSRC register (shared with UBRRH)
#endif
*_ucsrc = config;
sbi(*_ucsrb, RXEN0);
sbi(*_ucsrb, TXEN0);
sbi(*_ucsrb, RXCIE0);
cbi(*_ucsrb, UDRIE0);
}
void HardwareSerial::end()
{
// wait for transmission of outgoing data
while (_tx_buffer_head != _tx_buffer_tail)
;
cbi(*_ucsrb, RXEN0);
cbi(*_ucsrb, TXEN0);
cbi(*_ucsrb, RXCIE0);
cbi(*_ucsrb, UDRIE0);
// clear any received data
_rx_buffer_head = _rx_buffer_tail;
}
int HardwareSerial::available(void)
{
return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
}
int HardwareSerial::peek(void)
{
if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
return _rx_buffer[_rx_buffer_tail];
}
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
unsigned char c = _rx_buffer[_rx_buffer_tail];
_rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE;
return c;
}
}
int HardwareSerial::availableForWrite(void)
{
#if (SERIAL_TX_BUFFER_SIZE>256)
uint8_t oldSREG = SREG;
cli();
#endif
tx_buffer_index_t head = _tx_buffer_head;
tx_buffer_index_t tail = _tx_buffer_tail;
#if (SERIAL_TX_BUFFER_SIZE>256)
SREG = oldSREG;
#endif
if (head >= tail) return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
return tail - head - 1;
}
void HardwareSerial::flush()
{
// If we have never written a byte, no need to flush. This special
// case is needed since there is no way to force the TXC (transmit
// complete) bit to 1 during initialization
if (!_written)
return;
while (bit_is_set(*_ucsrb, UDRIE0) || bit_is_clear(*_ucsra, TXC0)) {
if (bit_is_clear(SREG, SREG_I) && bit_is_set(*_ucsrb, UDRIE0))
// Interrupts are globally disabled, but the DR empty
// interrupt should be enabled, so poll the DR empty flag to
// prevent deadlock
if (bit_is_set(*_ucsra, UDRE0))
_tx_udr_empty_irq();
}
// If we get here, nothing is queued anymore (DRIE is disabled) and
// the hardware finished tranmission (TXC is set).
}
size_t HardwareSerial::write(uint8_t c)
{
// If the buffer and the data register is empty, just write the byte
// to the data register and be done. This shortcut helps
// significantly improve the effective datarate at high (>
// 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
if (_tx_buffer_head == _tx_buffer_tail && bit_is_set(*_ucsra, UDRE0)) {
*_udr = c;
sbi(*_ucsra, TXC0);
return 1;
}
tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
while (i == _tx_buffer_tail) {
if (bit_is_clear(SREG, SREG_I)) {
// Interrupts are disabled, so we'll have to poll the data
// register empty flag ourselves. If it is set, pretend an
// interrupt has happened and call the handler to free up
// space for us.
if(bit_is_set(*_ucsra, UDRE0))
_tx_udr_empty_irq();
} else {
// nop, the interrupt handler will free up space for us
}
}
_tx_buffer[_tx_buffer_head] = c;
_tx_buffer_head = i;
sbi(*_ucsrb, UDRIE0);
_written = true;
return 1;
}
#endif // whole file

@ -18,6 +18,7 @@
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#ifndef HardwareSerial_h
@ -27,46 +28,31 @@
#include "Stream.h"
struct ring_buffer;
class HardwareSerial : public Stream
{
private:
ring_buffer *_rx_buffer;
ring_buffer *_tx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_ucsrc;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udrie;
uint8_t _u2x;
bool transmitting;
public:
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *ucsrc, volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
void begin(unsigned long);
void begin(unsigned long, uint8_t);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
};
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
// NOTE: a "power of 2" buffer size is reccomended to dramatically
// optimize all the modulo operations for ring buffers.
#if !(defined(SERIAL_TX_BUFFER_SIZE) && defined(SERIAL_RX_BUFFER_SIZE))
#if (RAMEND < 1000)
#define SERIAL_TX_BUFFER_SIZE 16
#define SERIAL_RX_BUFFER_SIZE 16
#else
#define SERIAL_TX_BUFFER_SIZE 64
#define SERIAL_RX_BUFFER_SIZE 64
#endif
#endif
#if (SERIAL_TX_BUFFER_SIZE>256)
typedef uint16_t tx_buffer_index_t;
#else
typedef uint8_t tx_buffer_index_t;
#endif
#if (SERIAL_RX_BUFFER_SIZE>256)
typedef uint16_t rx_buffer_index_t;
#else
typedef uint8_t rx_buffer_index_t;
#endif
// Define config for Serial.begin(baud, config);
#define SERIAL_5N1 0x00
@ -94,20 +80,70 @@ class HardwareSerial : public Stream
#define SERIAL_7O2 0x3C
#define SERIAL_8O2 0x3E
class HardwareSerial : public Stream
{
protected:
volatile uint8_t * const _ubrrh;
volatile uint8_t * const _ubrrl;
volatile uint8_t * const _ucsra;
volatile uint8_t * const _ucsrb;
volatile uint8_t * const _ucsrc;
volatile uint8_t * const _udr;
// Has any byte been written to the UART since begin()
bool _written;
volatile rx_buffer_index_t _rx_buffer_head;
volatile rx_buffer_index_t _rx_buffer_tail;
volatile tx_buffer_index_t _tx_buffer_head;
volatile tx_buffer_index_t _tx_buffer_tail;
// Don't put any members after these buffers, since only the first
// 32 bytes of this struct can be accessed quickly using the ldd
// instruction.
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
public:
inline HardwareSerial(
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *ucsrc, volatile uint8_t *udr);
void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
void begin(unsigned long, uint8_t);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
int availableForWrite(void);
virtual void flush(void);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool() { return true; }
// Interrupt handlers - Not intended to be called externally
inline void _rx_complete_irq(void);
void _tx_udr_empty_irq(void);
};
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;
#elif defined(USBCON)
#include "USBAPI.h"
// extern HardwareSerial Serial_;
#define HAVE_HWSERIAL0
#endif
#if defined(UBRR1H)
extern HardwareSerial Serial1;
#define HAVE_HWSERIAL1
#endif
#if defined(UBRR2H)
extern HardwareSerial Serial2;
#define HAVE_HWSERIAL2
#endif
#if defined(UBRR3H)
extern HardwareSerial Serial3;
#define HAVE_HWSERIAL3
#endif
extern void serialEventRun(void) __attribute__((weak));

@ -0,0 +1,79 @@
/*
HardwareSerial0.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#include "Arduino.h"
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the
// HardwareSerial instance in as well. Putting each instance in its own
// file prevents the linker from pulling in any unused instances in the
// first place.
#if defined(HAVE_HWSERIAL0)
#if defined(USART_RX_vect)
ISR(USART_RX_vect)
#elif defined(USART0_RX_vect)
ISR(USART0_RX_vect)
#elif defined(USART_RXC_vect)
ISR(USART_RXC_vect) // ATmega8
#else
#error "Don't know what the Data Received vector is called for Serial"
#endif
{
Serial._rx_complete_irq();
}
#if defined(UART0_UDRE_vect)
ISR(UART0_UDRE_vect)
#elif defined(UART_UDRE_vect)
ISR(UART_UDRE_vect)
#elif defined(USART0_UDRE_vect)
ISR(USART0_UDRE_vect)
#elif defined(USART_UDRE_vect)
ISR(USART_UDRE_vect)
#else
#error "Don't know what the Data Register Empty vector is called for Serial"
#endif
{
Serial._tx_udr_empty_irq();
}
#if defined(UBRRH) && defined(UBRRL)
HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);
#else
HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
#endif
// Function that can be weakly referenced by serialEventRun to prevent
// pulling in this file if it's not otherwise used.
bool Serial0_available() {
return Serial.available();
}
#endif // HAVE_HWSERIAL0

@ -0,0 +1,69 @@
/*
HardwareSerial1.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#include "Arduino.h"
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the
// HardwareSerial instance in as well. Putting each instance in its own
// file prevents the linker from pulling in any unused instances in the
// first place.
#if defined(HAVE_HWSERIAL1)
#if defined(UART1_RX_vect)
ISR(UART1_RX_vect)
#elif defined(USART1_RX_vect)
ISR(USART1_RX_vect)
#else
#error "Don't know what the Data Register Empty vector is called for Serial1"
#endif
{
Serial1._rx_complete_irq();
}
#if defined(UART1_UDRE_vect)
ISR(UART1_UDRE_vect)
#elif defined(USART1_UDRE_vect)
ISR(USART1_UDRE_vect)
#else
#error "Don't know what the Data Register Empty vector is called for Serial1"
#endif
{
Serial1._tx_udr_empty_irq();
}
HardwareSerial Serial1(&UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1);
// Function that can be weakly referenced by serialEventRun to prevent
// pulling in this file if it's not otherwise used.
bool Serial1_available() {
return Serial1.available();
}
#endif // HAVE_HWSERIAL1

@ -0,0 +1,57 @@
/*
HardwareSerial2.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#include "Arduino.h"
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the
// HardwareSerial instance in as well. Putting each instance in its own
// file prevents the linker from pulling in any unused instances in the
// first place.
#if defined(HAVE_HWSERIAL2)
ISR(USART2_RX_vect)
{
Serial2._rx_complete_irq();
}
ISR(USART2_UDRE_vect)
{
Serial2._tx_udr_empty_irq();
}
HardwareSerial Serial2(&UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2);
// Function that can be weakly referenced by serialEventRun to prevent
// pulling in this file if it's not otherwise used.
bool Serial2_available() {
return Serial2.available();
}
#endif // HAVE_HWSERIAL2

@ -0,0 +1,57 @@
/*
HardwareSerial3.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman
*/
#include "Arduino.h"
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"
// Each HardwareSerial is defined in its own file, sine the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the
// HardwareSerial instance in as well. Putting each instance in its own
// file prevents the linker from pulling in any unused instances in the
// first place.
#if defined(HAVE_HWSERIAL3)
ISR(USART3_RX_vect)
{
Serial3._rx_complete_irq();
}
ISR(USART3_UDRE_vect)
{
Serial3._tx_udr_empty_irq();
}
HardwareSerial Serial3(&UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3);
// Function that can be weakly referenced by serialEventRun to prevent
// pulling in this file if it's not otherwise used.
bool Serial3_available() {
return Serial3.available();
}
#endif // HAVE_HWSERIAL3

@ -0,0 +1,123 @@
/*
HardwareSerial_private.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
*/
#include "wiring_private.h"
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a uart
#if defined(HAVE_HWSERIAL0) || defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3)
// Ensure that the various bit positions we use are available with a 0
// postfix, so we can always use the values for UART0 for all UARTs. The
// alternative, passing the various values for each UART to the
// HardwareSerial constructor also works, but makes the code bigger and
// slower.
#if !defined(TXC0)
#if defined(TXC)
// Some chips like ATmega8 don't have UPE, only PE. The other bits are
// named as expected.
#if !defined(UPE) && defined(PE)
#define UPE PE
#endif
// On ATmega8, the uart and its bits are not numbered, so there is no TXC0 etc.
#define TXC0 TXC
#define RXEN0 RXEN
#define TXEN0 TXEN
#define RXCIE0 RXCIE
#define UDRIE0 UDRIE
#define U2X0 U2X
#define UPE0 UPE
#define UDRE0 UDRE
#elif defined(TXC1)
// Some devices have uart1 but no uart0
#define TXC0 TXC1
#define RXEN0 RXEN1
#define TXEN0 TXEN1
#define RXCIE0 RXCIE1
#define UDRIE0 UDRIE1
#define U2X0 U2X1
#define UPE0 UPE1
#define UDRE0 UDRE1
#else
#error No UART found in HardwareSerial.cpp
#endif
#endif // !defined TXC0
// Check at compiletime that it is really ok to use the bit positions of
// UART0 for the other UARTs as well, in case these values ever get
// changed for future hardware.
#if defined(TXC1) && (TXC1 != TXC0 || RXEN1 != RXEN0 || RXCIE1 != RXCIE0 || \
UDRIE1 != UDRIE0 || U2X1 != U2X0 || UPE1 != UPE0 || \
UDRE1 != UDRE0)
#error "Not all bit positions for UART1 are the same as for UART0"
#endif
#if defined(TXC2) && (TXC2 != TXC0 || RXEN2 != RXEN0 || RXCIE2 != RXCIE0 || \
UDRIE2 != UDRIE0 || U2X2 != U2X0 || UPE2 != UPE0 || \
UDRE2 != UDRE0)
#error "Not all bit positions for UART2 are the same as for UART0"
#endif
#if defined(TXC3) && (TXC3 != TXC0 || RXEN3 != RXEN0 || RXCIE3 != RXCIE0 || \
UDRIE3 != UDRIE0 || U3X3 != U3X0 || UPE3 != UPE0 || \
UDRE3 != UDRE0)
#error "Not all bit positions for UART3 are the same as for UART0"
#endif
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *ucsrc, volatile uint8_t *udr) :
_ubrrh(ubrrh), _ubrrl(ubrrl),
_ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc),
_udr(udr),
_rx_buffer_head(0), _rx_buffer_tail(0),
_tx_buffer_head(0), _tx_buffer_tail(0)
{
}
// Actual interrupt handlers //////////////////////////////////////////////////////////////
void HardwareSerial::_rx_complete_irq(void)
{
if (bit_is_clear(*_ucsra, UPE0)) {
// No Parity error, read byte and store it in the buffer if there is
// room
unsigned char c = *_udr;
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != _rx_buffer_tail) {
_rx_buffer[_rx_buffer_head] = c;
_rx_buffer_head = i;
}
} else {
// Parity error, read byte but discard it
*_udr;
};
}
#endif // whole file

@ -0,0 +1,74 @@
/*
IPAddress.cpp - Base class that provides IPAddress
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
#include <IPAddress.h>
IPAddress::IPAddress()
{
_address.dword = 0;
}
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
{
_address.bytes[0] = first_octet;
_address.bytes[1] = second_octet;
_address.bytes[2] = third_octet;
_address.bytes[3] = fourth_octet;
}
IPAddress::IPAddress(uint32_t address)
{
_address.dword = address;
}
IPAddress::IPAddress(const uint8_t *address)
{
memcpy(_address.bytes, address, sizeof(_address.bytes));
}
IPAddress& IPAddress::operator=(const uint8_t *address)
{
memcpy(_address.bytes, address, sizeof(_address.bytes));
return *this;
}
IPAddress& IPAddress::operator=(uint32_t address)
{
_address.dword = address;
return *this;
}
bool IPAddress::operator==(const uint8_t* addr) const
{
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
}
size_t IPAddress::printTo(Print& p) const
{
size_t n = 0;
for (int i =0; i < 3; i++)
{
n += p.print(_address.bytes[i], DEC);
n += p.print('.');
}
n += p.print(_address.bytes[3], DEC);
return n;
}

@ -0,0 +1,75 @@
/*
IPAddress.h - Base class that provides IPAddress
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef IPAddress_h
#define IPAddress_h
#include <stdint.h>
#include <Printable.h>
// A class to make it easier to handle and pass around IP addresses
class IPAddress : public Printable {
private:
union {
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
} _address;
// Access the raw byte array containing the address. Because this returns a pointer
// to the internal structure rather than a copy of the address this function should only
// be used when you know that the usage of the returned uint8_t* will be transient and not
// stored.
uint8_t* raw_address() { return _address.bytes; };
public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(const uint8_t *address);
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator uint32_t() const { return _address.dword; };
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
bool operator==(const uint8_t* addr) const;
// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address.bytes[index]; };
uint8_t& operator[](int index) { return _address.bytes[index]; };
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
IPAddress& operator=(uint32_t address);
virtual size_t printTo(Print& p) const;
friend class EthernetClass;
friend class UDP;
friend class Client;
friend class Server;
friend class DhcpClass;
friend class DNSClient;
};
const IPAddress INADDR_NONE(0,0,0,0);
#endif

@ -41,7 +41,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)
size_t Print::print(const __FlashStringHelper *ifsh)
{
const char PROGMEM *p = (const char PROGMEM *)ifsh;
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
@ -53,11 +53,7 @@ size_t Print::print(const __FlashStringHelper *ifsh)
size_t Print::print(const String &s)
{
size_t n = 0;
for (uint16_t i = 0; i < s.length(); i++) {
n += write(s[i]);
}
return n;
return write(s.c_str(), s.length());
}
size_t Print::print(const char str[])

@ -51,6 +51,9 @@ class Print
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}
size_t print(const __FlashStringHelper *);
size_t print(const String &);

@ -20,7 +20,7 @@
#ifndef Printable_h
#define Printable_h
#include <new.h>
#include <stdlib.h>
class Print;

@ -0,0 +1,30 @@
/*
Server.h - Base class that provides Server
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef server_h
#define server_h
#include "Print.h"
class Server : public Print {
public:
virtual void begin() =0;
};
#endif

@ -75,7 +75,7 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
// find returns true if the target string is found
bool Stream::find(char *target)
{
return findUntil(target, NULL);
return findUntil(target, (char*)"");
}
// reads data from the stream until the target string of given length is found
@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar){
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
char c;
int c;
float fraction = 1.0;
c = peekNextDigit();

@ -57,14 +57,18 @@ class Stream : public Print
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
bool find(char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target) { return find ((char *)target); }
// returns true if target string is found, false if timed out (see setTimeout)
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
// returns true if target string is found, false if timed out
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
long parseInt(); // returns the first valid (long) integer value from the current position.
@ -74,10 +78,12 @@ class Stream : public Print
float parseFloat(); // float version of parseInt
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
// terminates if length characters have been read or timeout (see setTimeout)
// returns the number of characters placed in the buffer (0 means no valid data found)
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
// terminates if length characters have been read, timeout, or if the terminator character detected
// returns the number of characters placed in the buffer (0 means no valid data found)

@ -1,10 +1,41 @@
/*
USBAPI.h
Copyright (c) 2005-2014 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __USBAPI__
#define __USBAPI__
#include <inttypes.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
#include "Arduino.h"
#if defined(USBCON)
//#define MOUSE_ABS_ENABLED
#include "USBDesc.h"
#include "USBCore.h"
//================================================================================
//================================================================================
@ -27,26 +58,41 @@ extern USBDevice_ USBDevice;
//================================================================================
// Serial over CDC (Serial1 is the physical port)
struct ring_buffer;
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
class Serial_ : public Stream
{
private:
ring_buffer *_cdc_rx_buffer;
int peek_buffer;
public:
Serial_() { peek_buffer = -1; };
void begin(unsigned long);
void begin(unsigned long, uint8_t);
void end(void);
virtual int available(void);
virtual void accept(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t*, size_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
volatile uint8_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail;
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
};
extern Serial_ Serial;
#define HAVE_CDCSERIAL
//================================================================================
//================================================================================
// Mouse
@ -67,9 +113,7 @@ public:
void end(void);
void click(uint8_t b = MOUSE_LEFT);
void move(signed char x, signed char y, signed char wheel = 0);
#ifdef MOUSE_ABS_ENABLED
void moveAbs(int16_t x, int16_t y, int16_t wheel); // all parameters have the range of -32768 to 32767 and must be scaled to screen pixels
#endif
void moveAbsolute(uint16_t x, uint16_t y);
void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
@ -80,6 +124,7 @@ extern Mouse_ Mouse;
//================================================================================
// Keyboard
// Legacy keycodes. These are what you use with 'press()' and 'release()'
#define KEY_LEFT_CTRL 0x80
#define KEY_LEFT_SHIFT 0x81
#define KEY_LEFT_ALT 0x82
@ -142,6 +187,7 @@ extern Mouse_ Mouse;
#define SYSTEM_CONTROL_DISPLAY_SWAP 16
// Consumer Control values for Keyboard_::systemControl()
// these defines come from the HID usage table "Consumer Device Page (0x0c)"
// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf)
@ -156,22 +202,15 @@ extern Mouse_ Mouse;
#define CONSUMER_CONTROL_STOP 5
#define CONSUMER_CONTROL_PREV_TRACK 6
#define CONSUMER_CONTROL_NEXT_TRACK 7
#define CONSUMER_CONTROL_MAIL 8
#define CONSUMER_CONTROL_CALCULATOR 9
#define CONSUMER_CONTROL_WWW_SEARCH 10
#define CONSUMER_CONTROL_WWW_HOME 11
#define CONSUMER_CONTROL_WWW_FAVORITES 12
#define CONSUMER_CONTROL_WWW_REFRESH 13
#define CONSUMER_CONTROL_WWW_STOP 14
#define CONSUMER_CONTROL_WWW_FORWARD 15
#define CONSUMER_CONTROL_WWW_BACK 16
#define CONSUMER_CONTROL_EJECT 8
// Low level key report: up to 6 keys and shift, ctrl etc at once
#define KEYREPORT_KEYCOUNT 0x06
typedef struct
{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
uint8_t keys[KEYREPORT_KEYCOUNT];
} KeyReport;
class Keyboard_ : public Print
@ -186,9 +225,14 @@ public:
virtual size_t write(uint8_t k);
virtual size_t press(uint8_t k);
virtual size_t release(uint8_t k);
virtual size_t writeKeycode(uint8_t k);
virtual size_t pressKeycode(uint8_t k);
virtual size_t releaseKeycode(uint8_t k);
virtual size_t addKeycodeToReport(uint8_t k);
virtual size_t removeKeycodeFromReport(uint8_t k);
virtual void releaseAll(void);
virtual size_t systemControl(uint8_t k);
virtual size_t consumerControl(uint8_t k);
virtual size_t consumerControl(uint8_t k);
};
extern Keyboard_ Keyboard;
@ -248,6 +292,7 @@ int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
int USB_Recv(uint8_t ep); // non-blocking
void USB_Flush(uint8_t ep);
#endif
#endif /* if defined(USBCON) */
#endif

@ -18,9 +18,7 @@
** SOFTWARE.
*/
#include "Platform.h"
#include "USBAPI.h"
#include "USBDesc.h"
#if defined(USBCON)
@ -41,42 +39,40 @@ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
//==================================================================
extern const u16 STRING_LANGUAGE[] PROGMEM;
extern const u16 STRING_IPRODUCT[] PROGMEM;
extern const u16 STRING_IMANUFACTURER[] PROGMEM;
extern const u8 STRING_PRODUCT[] PROGMEM;
extern const u8 STRING_MANUFACTURER[] PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
int usbMaxPower = 500;
const u16 STRING_LANGUAGE[2] = {
(3<<8) | (2+2),
0x0409 // English
};
const u16 STRING_IPRODUCT[17] = {
(3<<8) | (2+2*16),
#if USB_PID == 0x8036
'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o'
#elif USB_PID == 0x8037
'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' '
#elif USB_PID == 0x803C
'A','r','d','u','i','n','o',' ','E','s','p','l','o','r','a',' '
#elif USB_PID == 0x9208
'L','i','l','y','P','a','d','U','S','B',' ',' ',' ',' ',' ',' '
#else
'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' '
#ifndef USB_PRODUCT
// If no product is provided, use USB IO Board
#define USB_PRODUCT "USB IO Board"
#endif
};
const u16 STRING_IMANUFACTURER[12] = {
(3<<8) | (2+2*11),
const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
#if USB_VID == 0x2341
'A','r','d','u','i','n','o',' ','L','L','C'
# if defined(USB_MANUFACTURER)
# undef USB_MANUFACTURER
# endif
# define USB_MANUFACTURER "Arduino LLC"
#elif USB_VID == 0x1b4f
'S','p','a','r','k','F','u','n',' ',' ',' '
#else
'U','n','k','n','o','w','n',' ',' ',' ',' '
# if defined(USB_MANUFACTURER)
# undef USB_MANUFACTURER
# endif
# define USB_MANUFACTURER "SparkFun"
#elif !defined(USB_MANUFACTURER)
// Fall through to unknown if no manufacturer name was provided in a macro
# define USB_MANUFACTURER "Unknown"
#endif
};
const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
#ifdef CDC_ENABLED
#define DEVICE_CLASS 0x02
@ -100,7 +96,8 @@ volatile u8 _usbSuspendState = 0; // copy of UDINT to check SUSPI and WAKEUPI bi
static inline void WaitIN(void)
{
while (!(UEINTX & (1<<TXINI)));
while (!(UEINTX & (1<<TXINI)))
;
}
static inline void ClearIN(void)
@ -280,7 +277,6 @@ int USB_Send(u8 ep, const void* d, int len)
int r = len;
const u8* data = (const u8*)d;
u8 zero = ep & TRANSFER_ZERO;
u8 timeout = 250; // 250ms timeout on send? TODO
while (len)
{
@ -295,9 +291,12 @@ int USB_Send(u8 ep, const void* d, int len)
if (n > len)
n = len;
len -= n;
{
LockEP lock(ep);
// Frame may have been released by the SOF interrupt handler
if (!ReadWriteAllowed())
continue;
len -= n;
if (ep & TRANSFER_ZERO)
{
while (n--)
@ -421,6 +420,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
return sent;
}
// Send a USB descriptor string. The string is stored in PROGMEM as a
// plain ASCII string but is sent out as UTF-16 with the correct 2-byte
// prefix
static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
SendControl(2 + string_len * 2);
SendControl(3);
for(u8 i = 0; i < string_len; i++) {
bool r = SendControl(pgm_read_byte(&string_P[i]));
r &= SendControl(0); // high byte
if(!r) {
return false;
}
}
return true;
}
// Does not timeout or cross fifo boundaries
// Will only work for transfers <= 64 bytes
// TODO
@ -481,7 +496,6 @@ bool SendDescriptor(Setup& setup)
return HID_GetDescriptor(t);
#endif
u8 desc_length = 0;
const u8* desc_addr = 0;
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
{
@ -491,20 +505,22 @@ bool SendDescriptor(Setup& setup)
}
else if (USB_STRING_DESCRIPTOR_TYPE == t)
{
if (setup.wValueL == 0)
if (setup.wValueL == 0) {
desc_addr = (const u8*)&STRING_LANGUAGE;
else if (setup.wValueL == IPRODUCT)
desc_addr = (const u8*)&STRING_IPRODUCT;
else if (setup.wValueL == IMANUFACTURER)
desc_addr = (const u8*)&STRING_IMANUFACTURER;
}
else if (setup.wValueL == IPRODUCT) {
return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
}
else if (setup.wValueL == IMANUFACTURER) {
return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
}
else
return false;
}
if (desc_addr == 0)
return false;
if (desc_length == 0)
desc_length = pgm_read_byte(desc_addr);
u8 desc_length = pgm_read_byte(desc_addr);
USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
return true;
@ -667,8 +683,8 @@ static inline void USB_ClockEnable()
}
// Some tests on specific versions of macosx (10.7.3), reported some
// strange behaviuors when the board is reset using the serial
// port touch at 1200 bps. This delay fixes this behaviour.
// strange behaviors when the board is reset using the serial
// port touch at 1200 bps. This delay fixes this behavior.
delay(1);
USBCON = (USBCON & ~(1<<FRZCLK)) | (1<<OTGPADE); // start USB clock, enable VBUS Pad
@ -700,8 +716,6 @@ ISR(USB_GEN_vect)
{
#ifdef CDC_ENABLED
USB_Flush(CDC_TX); // Send a tx frame if found
if (USB_Available(CDC_RX)) // Handle received bytes (if any)
Serial.accept();
#endif
// check whether the one-shot period has elapsed. if so, turn off the LED

@ -291,7 +291,7 @@ typedef struct
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
#define D_CONFIG(_totalLength,_interfaces) \
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(usbMaxPower) }
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) }
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }

@ -21,7 +21,6 @@
#include "WString.h"
/*********************************************/
/* Constructors */
/*********************************************/
@ -38,6 +37,12 @@ String::String(const String &value)
*this = value;
}
String::String(const __FlashStringHelper *pstr)
{
init();
*this = pstr;
}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String::String(String &&rval)
{
@ -63,7 +68,7 @@ String::String(char c)
String::String(unsigned char value, unsigned char base)
{
init();
char buf[9];
char buf[1 + 8 * sizeof(unsigned char)];
utoa(value, buf, base);
*this = buf;
}
@ -71,7 +76,7 @@ String::String(unsigned char value, unsigned char base)
String::String(int value, unsigned char base)
{
init();
char buf[18];
char buf[2 + 8 * sizeof(int)];
itoa(value, buf, base);
*this = buf;
}
@ -79,7 +84,7 @@ String::String(int value, unsigned char base)
String::String(unsigned int value, unsigned char base)
{
init();
char buf[17];
char buf[1 + 8 * sizeof(unsigned int)];
utoa(value, buf, base);
*this = buf;
}
@ -87,7 +92,7 @@ String::String(unsigned int value, unsigned char base)
String::String(long value, unsigned char base)
{
init();
char buf[34];
char buf[2 + 8 * sizeof(long)];
ltoa(value, buf, base);
*this = buf;
}
@ -95,24 +100,25 @@ String::String(long value, unsigned char base)
String::String(unsigned long value, unsigned char base)
{
init();
char buf[33];
char buf[1 + 8 * sizeof(unsigned long)];
ultoa(value, buf, base);
*this = buf;
}
String::String(float value, int decimalPlaces)
String::String(float value, unsigned char decimalPlaces)
{
init();
char buf[33];
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
}
String::String(double value, int decimalPlaces)
String::String(double value, unsigned char decimalPlaces)
{
init();
char buf[33];
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
}
String::~String()
{
free(buffer);
@ -127,7 +133,6 @@ inline void String::init(void)
buffer = NULL;
capacity = 0;
len = 0;
flags = 0;
}
void String::invalidate(void)
@ -173,6 +178,17 @@ String & String::copy(const char *cstr, unsigned int length)
return *this;
}
String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
{
if (!reserve(length)) {
invalidate();
return *this;
}
len = length;
strcpy_P(buffer, (PGM_P)pstr);
return *this;
}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void String::move(String &rhs)
{
@ -227,6 +243,14 @@ String & String::operator = (const char *cstr)
return *this;
}
String & String::operator = (const __FlashStringHelper *pstr)
{
if (pstr) copy(pstr, strlen_P((PGM_P)pstr));
else invalidate();
return *this;
}
/*********************************************/
/* concat */
/*********************************************/
@ -263,35 +287,35 @@ unsigned char String::concat(char c)
unsigned char String::concat(unsigned char num)
{
char buf[4];
char buf[1 + 3 * sizeof(unsigned char)];
itoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(int num)
{
char buf[7];
char buf[2 + 3 * sizeof(int)];
itoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(unsigned int num)
{
char buf[6];
char buf[1 + 3 * sizeof(unsigned int)];
utoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(long num)
{
char buf[12];
char buf[2 + 3 * sizeof(long)];
ltoa(num, buf, 10);
return concat(buf, strlen(buf));
}
unsigned char String::concat(unsigned long num)
{
char buf[11];
char buf[1 + 3 * sizeof(unsigned long)];
ultoa(num, buf, 10);
return concat(buf, strlen(buf));
}
@ -299,17 +323,29 @@ unsigned char String::concat(unsigned long num)
unsigned char String::concat(float num)
{
char buf[20];
char* string = dtostrf(num, 8, 6, buf);
char* string = dtostrf(num, 4, 2, buf);
return concat(string, strlen(string));
}
unsigned char String::concat(double num)
{
char buf[20];
char* string = dtostrf(num, 8, 6, buf);
char* string = dtostrf(num, 4, 2, buf);
return concat(string, strlen(string));
}
unsigned char String::concat(const __FlashStringHelper * str)
{
if (!str) return 0;
int length = strlen_P((const char *) str);
if (length == 0) return 1;
unsigned int newlen = len + length;
if (!reserve(newlen)) return 0;
strcpy_P(buffer + len, (const char *) str);
len = newlen;
return 1;
}
/*********************************************/
/* Concatenate */
/*********************************************/
@ -383,6 +419,14 @@ StringSumHelper & operator + (const StringSumHelper &lhs, double num)
if (!a.concat(num)) a.invalidate();
return a;
}
StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
{
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
if (!a.concat(rhs)) a.invalidate();
return a;
}
/*********************************************/
/* Comparison */
/*********************************************/
@ -567,11 +611,6 @@ int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
return found;
}
String String::substring( unsigned int left ) const
{
return substring(left, len);
}
String String::substring(unsigned int left, unsigned int right) const
{
if (left > right) {
@ -580,7 +619,7 @@ String String::substring(unsigned int left, unsigned int right) const
left = temp;
}
String out;
if (left > len) return out;
if (left >= len) return out;
if (right > len) right = len;
char temp = buffer[right]; // save the replaced character
buffer[right] = '\0';
@ -645,15 +684,16 @@ void String::replace(const String& find, const String& replace)
}
void String::remove(unsigned int index){
if (index >= len) { return; }
int count = len - index;
remove(index, count);
// Pass the biggest integer as the count. The remove method
// below will take care of truncating it at the end of the
// string.
remove(index, (unsigned int)-1);
}
void String::remove(unsigned int index, unsigned int count){
if (index >= len) { return; }
if (count <= 0) { return; }
if (index + count > len) { count = len - index; }
if (count > len - index) { count = len - index; }
char *writeTo = buffer + index;
len = len - count;
strncpy(writeTo, buffer + index + count,len - index);
@ -698,7 +738,6 @@ long String::toInt(void) const
return 0;
}
float String::toFloat(void) const
{
if (buffer) return float(atof(buffer));

@ -58,6 +58,7 @@ public:
// be false).
String(const char *cstr = "");
String(const String &str);
String(const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(String &&rval);
String(StringSumHelper &&rval);
@ -68,8 +69,8 @@ public:
explicit String(unsigned int, unsigned char base=10);
explicit String(long, unsigned char base=10);
explicit String(unsigned long, unsigned char base=10);
explicit String(float, int decimalPlaces=6);
explicit String(double, int decimalPlaces=6);
explicit String(float, unsigned char decimalPlaces=2);
explicit String(double, unsigned char decimalPlaces=2);
~String(void);
// memory management
@ -84,6 +85,7 @@ public:
// marked as invalid ("if (s)" will be false).
String & operator = (const String &rhs);
String & operator = (const char *cstr);
String & operator = (const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String & operator = (String &&rval);
String & operator = (StringSumHelper &&rval);
@ -104,6 +106,7 @@ public:
unsigned char concat(unsigned long num);
unsigned char concat(float num);
unsigned char concat(double num);
unsigned char concat(const __FlashStringHelper * str);
// if there's not enough memory for the concatenated value, the string
// will be left unchanged (but this isn't signalled in any way)
@ -115,6 +118,9 @@ public:
String & operator += (unsigned int num) {concat(num); return (*this);}
String & operator += (long num) {concat(num); return (*this);}
String & operator += (unsigned long num) {concat(num); return (*this);}
String & operator += (float num) {concat(num); return (*this);}
String & operator += (double num) {concat(num); return (*this);}
String & operator += (const __FlashStringHelper *str){concat(str); return (*this);}
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
@ -126,6 +132,7 @@ public:
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs);
// comparison (only works w/ Strings and "strings")
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
@ -164,7 +171,7 @@ public:
int lastIndexOf( char ch, unsigned int fromIndex ) const;
int lastIndexOf( const String &str ) const;
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
String substring( unsigned int beginIndex ) const;
String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); };
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
// modification
@ -184,7 +191,6 @@ protected:
char *buffer; // the actual char array
unsigned int capacity; // the array length minus one (for the '\0')
unsigned int len; // the String length (not counting the '\0')
unsigned char flags; // unused, for future features
protected:
void init(void);
void invalidate(void);
@ -193,6 +199,7 @@ protected:
// copy and move
String & copy(const char *cstr, unsigned int length);
String & copy(const __FlashStringHelper *pstr, unsigned int length);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void move(String &rhs);
#endif
@ -209,6 +216,8 @@ public:
StringSumHelper(unsigned int num) : String(num) {}
StringSumHelper(long num) : String(num) {}
StringSumHelper(unsigned long num) : String(num) {}
StringSumHelper(float num) : String(num) {}
StringSumHelper(double num) : String(num) {}
};
#endif // __cplusplus

@ -0,0 +1,35 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
void __cxa_pure_virtual(void) {
// We might want to write some diagnostics to uart in this case
//std::terminate();
abort();
}
void __cxa_deleted_virtual(void) {
// We might want to write some diagnostics to uart in this case
//std::terminate();
abort();
}

@ -1,3 +1,22 @@
/*
binary.h - Definitions for binary constants
Copyright (c) 2006 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef Binary_h
#define Binary_h

@ -0,0 +1,31 @@
/*
Copyright (c) 2012 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Empty yield() hook.
*
* This function is intended to be used by library writers to build
* libraries or sketches that supports cooperative threads.
*
* Its defined as a weak symbol and it can be redefined to implement a
* real cooperative scheduler.
*/
static void __empty() {
// Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));

@ -0,0 +1,49 @@
/*
main.cpp - Main loop for Arduino sketches
Copyright (c) 2005-2013 Arduino Team. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
//Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (*func)()) { return 0; }
// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}

@ -0,0 +1,36 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
void *operator new(size_t size) {
return malloc(size);
}
void *operator new[](size_t size) {
return malloc(size);
}
void operator delete(void * ptr) {
free(ptr);
}
void operator delete[](void * ptr) {
free(ptr);
}

@ -0,0 +1,30 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef NEW_H
#define NEW_H
#include <stdlib.h>
void * operator new(size_t size);
void * operator new[](size_t size);
void operator delete(void * ptr);
void operator delete[](void * ptr);
#endif

@ -111,6 +111,7 @@ void delay(unsigned long ms)
uint16_t start = (uint16_t)micros();
while (ms > 0) {
yield();
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;

@ -160,6 +160,14 @@ void analogWrite(uint8_t pin, int val)
break;
#endif
#if defined(TCCR1A) && defined(COM1C1)
case TIMER1C:
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1C1);
OCR1C = val; // set pwm duty
break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2:
// connect pwm to pin on timer 2

@ -84,6 +84,9 @@ static void turnOffPWM(uint8_t timer)
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B: cbi(TCCR1A, COM1B1); break;
#endif
#if defined(TCCR1A) && defined(COM1C1)
case TIMER1C: cbi(TCCR1A, COM1C1); break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2: cbi(TCCR2, COM21); break;

@ -52,7 +52,7 @@ extern "C"{
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
#define EXTERNAL_NUM_INTERRUPTS 8
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
#define EXTERNAL_NUM_INTERRUPTS 3

@ -0,0 +1 @@
name=Keyboardio Keyboards

@ -0,0 +1,359 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
// Workaround for wrong definitions in "iom32u4.h".
// This should be fixed in the AVR toolchain.
#undef UHCON
#undef UHINT
#undef UHIEN
#undef UHADDR
#undef UHFNUM
#undef UHFNUML
#undef UHFNUMH
#undef UHFLEN
#undef UPINRQX
#undef UPINTX
#undef UPNUM
#undef UPRST
#undef UPCONX
#undef UPCFG0X
#undef UPCFG1X
#undef UPSTAX
#undef UPCFG2X
#undef UPIENX
#undef UPDATX
#undef TCCR2A
#undef WGM20
#undef WGM21
#undef COM2B0
#undef COM2B1
#undef COM2A0
#undef COM2A1
#undef TCCR2B
#undef CS20
#undef CS21
#undef CS22
#undef WGM22
#undef FOC2B
#undef FOC2A
#undef TCNT2
#undef TCNT2_0
#undef TCNT2_1
#undef TCNT2_2
#undef TCNT2_3
#undef TCNT2_4
#undef TCNT2_5
#undef TCNT2_6
#undef TCNT2_7
#undef OCR2A
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#undef OCR2B
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#define NUM_DIGITAL_PINS 30
#define NUM_ANALOG_INPUTS 12
#define TXLED0 PORTD &= ~(1<<5)
#define TXLED1 PORTD |= (1<<5)
#define RXLED0 PORTB &= ~(1<<0)
#define RXLED1 PORTB |= (1<<0)
#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0), TXLED0, RXLED0
#define SDA 2
#define SCL 3
#define LED_BUILTIN 13
// Map SPI port to 'new' pins D14..D17
#define SS 17
#define MOSI 16
#define MISO 14
#define SCK 15
// Mapping of analog pins as digital I/O
// A6-A11 share with digital pins
#define A0 18
#define A1 19
#define A2 20
#define A3 21
#define A4 22
#define A5 23
#define A6 24 // D4
#define A7 25 // D6
#define A8 26 // D8
#define A9 27 // D9
#define A10 28 // D10
#define A11 29 // D12
#define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) 0
#define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
#define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
// __AVR_ATmega32U4__ has an unusual mapping of pins to channels
extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
#define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
#ifdef ARDUINO_MAIN
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA32U4 / ARDUINO LEONARDO
//
// D0 PD2 RXD1/INT2
// D1 PD3 TXD1/INT3
// D2 PD1 SDA SDA/INT1
// D3# PD0 PWM8/SCL OC0B/SCL/INT0
// D4 A6 PD4 ADC8
// D5# PC6 ??? OC3A/#OC4A
// D6# A7 PD7 FastPWM #OC4D/ADC10
// D7 PE6 INT6/AIN0
//
// D8 A8 PB4 ADC11/PCINT4
// D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
// D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
// D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
// D12 A11 PD6 T1/#OC4D/ADC9
// D13# PC7 PWM10 CLK0/OC4A
//
// A0 D18 PF7 ADC7
// A1 D19 PF6 ADC6
// A2 D20 PF5 ADC5
// A3 D21 PF4 ADC4
// A4 D22 PF1 ADC1
// A5 D23 PF0 ADC0
//
// New pins D14..D17 to map SPI port to digital pins
//
// MISO D14 PB3 MISO,PCINT3
// SCK D15 PB1 SCK,PCINT1
// MOSI D16 PB2 MOSI,PCINT2
// SS D17 PB0 RXLED,SS/PCINT0
//
// TXLED PD5
// RXLED PB0
// HWB PE2 HWB
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
(uint16_t) &DDRF,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
(uint16_t) &PORTF,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
(uint16_t) &PINF,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, // D0 - PD2
PD, // D1 - PD3
PD, // D2 - PD1
PD, // D3 - PD0
PD, // D4 - PD4
PC, // D5 - PC6
PD, // D6 - PD7
PE, // D7 - PE6
PB, // D8 - PB4
PB, // D9 - PB5
PB, // D10 - PB6
PB, // D11 - PB7
PD, // D12 - PD6
PC, // D13 - PC7
PB, // D14 - MISO - PB3
PB, // D15 - SCK - PB1
PB, // D16 - MOSI - PB2
PB, // D17 - SS - PB0
PF, // D18 - A0 - PF7
PF, // D19 - A1 - PF6
PF, // D20 - A2 - PF5
PF, // D21 - A3 - PF4
PF, // D22 - A4 - PF1
PF, // D23 - A5 - PF0
PD, // D24 / D4 - A6 - PD4
PD, // D25 / D6 - A7 - PD7
PB, // D26 / D8 - A8 - PB4
PB, // D27 / D9 - A9 - PB5
PB, // D28 / D10 - A10 - PB6
PD, // D29 / D12 - A11 - PD6
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(2), // D0 - PD2
_BV(3), // D1 - PD3
_BV(1), // D2 - PD1
_BV(0), // D3 - PD0
_BV(4), // D4 - PD4
_BV(6), // D5 - PC6
_BV(7), // D6 - PD7
_BV(6), // D7 - PE6
_BV(4), // D8 - PB4
_BV(5), // D9 - PB5
_BV(6), // D10 - PB6
_BV(7), // D11 - PB7
_BV(6), // D12 - PD6
_BV(7), // D13 - PC7
_BV(3), // D14 - MISO - PB3
_BV(1), // D15 - SCK - PB1
_BV(2), // D16 - MOSI - PB2
_BV(0), // D17 - SS - PB0
_BV(7), // D18 - A0 - PF7
_BV(6), // D19 - A1 - PF6
_BV(5), // D20 - A2 - PF5
_BV(4), // D21 - A3 - PF4
_BV(1), // D22 - A4 - PF1
_BV(0), // D23 - A5 - PF0
_BV(4), // D24 / D4 - A6 - PD4
_BV(7), // D25 / D6 - A7 - PD7
_BV(4), // D26 / D8 - A8 - PB4
_BV(5), // D27 / D9 - A9 - PB5
_BV(6), // D28 / D10 - A10 - PB6
_BV(6), // D29 / D12 - A11 - PD6
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER0B, /* 3 */
NOT_ON_TIMER,
TIMER3A, /* 5 */
TIMER4D, /* 6 */
NOT_ON_TIMER,
NOT_ON_TIMER,
TIMER1A, /* 9 */
TIMER1B, /* 10 */
TIMER0A, /* 11 */
NOT_ON_TIMER,
TIMER4A, /* 13 */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
7, // A0 PF7 ADC7
6, // A1 PF6 ADC6
5, // A2 PF5 ADC5
4, // A3 PF4 ADC4
1, // A4 PF1 ADC1
0, // A5 PF0 ADC0
8, // A6 D4 PD4 ADC8
10, // A7 D6 PD7 ADC10
11, // A8 D8 PB4 ADC11
12, // A9 D9 PB5 ADC12
13, // A10 D10 PB6 ADC13
9 // A11 D12 PD6 ADC9
};
#endif /* ARDUINO_MAIN */
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1
#endif /* Pins_Arduino_h */

@ -1,18 +0,0 @@
keyboardio.name=Keyboard.IO Model 00
keyboardio.upload.protocol=avr109
keyboardio.upload.maximum_size=28672
keyboardio.upload.speed=57600
keyboardio.upload.disable_flushing=true
keyboardio.bootloader.low_fuses=0xff
keyboardio.bootloader.high_fuses=0xd8
keyboardio.bootloader.extended_fuses=0xcb
keyboardio.bootloader.path=caterina
keyboardio.bootloader.file=Caterina-keyboardio.hex
keyboardio.bootloader.unlock_bits=0x3F
keyboardio.bootloader.lock_bits=0x2F
keyboardio.build.mcu=atmega32u4
keyboardio.build.f_cpu=16000000L
keyboardio.build.vid=0x2341
keyboardio.build.pid=0x8037
keyboardio.build.core=keyboardio
keyboardio.build.variant=model00

@ -1,26 +0,0 @@
#ifndef client_h
#define client_h
#include "Print.h"
#include "Stream.h"
#include "IPAddress.h"
class Client : public Stream {
public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;
virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
virtual int peek() = 0;
virtual void flush() = 0;
virtual void stop() = 0;
virtual uint8_t connected() = 0;
virtual operator bool() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
};
#endif

@ -1,708 +0,0 @@
/* Copyright (c) 2011, Peter Barrett
**
** Sleep/Wakeup/SystemControl support added by Michael Dreher
**
** Permission to use, copy, modify, and/or distribute this software for
** any purpose with or without fee is hereby granted, provided that the
** above copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#include "Platform.h"
#include "USBAPI.h"
#include "USBDesc.h"
#if defined(USBCON)
#ifdef HID_ENABLED
//#define RAWHID_ENABLED
// Singletons for mouse and keyboard
Mouse_ Mouse;
Keyboard_ Keyboard;
//================================================================================
//================================================================================
// HID report descriptor
#define LSB(_x) ((_x) & 0xFF)
#define MSB(_x) ((_x) >> 8)
#define RAWHID_USAGE_PAGE 0xFFC0
#define RAWHID_USAGE 0x0C00
#define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64
#define HID_REPORTID_MOUSE (1)
#define HID_REPORTID_KEYBOARD (2)
#define HID_REPORTID_RAWHID (3)
#define HID_REPORTID_SYSTEMCONTROL (4)
#define HID_REPORTID_MOUSE_ABS (5)
#define HID_REPORTID_CONSUMERCONTROL (6)
extern const u8 _hidReportDescriptor[] PROGMEM;
const u8 _hidReportDescriptor[] = {
// Mouse relative
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x85, HID_REPORTID_MOUSE, // REPORT_ID (1)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x03, // REPORT_COUNT (3)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
#ifdef MOUSE_ABS_ENABLED
// Mouse absolute
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x85, HID_REPORTID_MOUSE_ABS, // REPORT_ID (5)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x03, // REPORT_COUNT (3)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x38, // USAGE (Wheel)
0x16, 0x00, 0x80, // LOGICAL_MINIMUM (-32768)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
#endif
// Keyboard
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, HID_REPORTID_KEYBOARD, // REPORT_ID (2)
0x05, 0x07, // USAGE_PAGE (Keyboard)
// Keyboard Modifiers (shift, alt, ...)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
// Keyboard keys
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xDF, 0x00, // LOGICAL_MAXIMUM (239)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0xDF, // USAGE_MAXIMUM (Left Control - 1)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
// System Control (Power Down, Sleep, Wakeup, ...)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x80, // USAGE (System Control)
0xa1, 0x01, // COLLECTION (Application)
0x85, HID_REPORTID_SYSTEMCONTROL,// REPORT_ID (4)
0x09, 0x81, // USAGE (System Power Down)
0x09, 0x82, // USAGE (System Sleep)
0x09, 0x83, // USAGE (System Wakeup)
0x09, 0x8E, // USAGE (System Cold Restart)
0x09, 0x8F, // USAGE (System Warm Restart)
0x09, 0xA0, // USAGE (System Dock)
0x09, 0xA1, // USAGE (System Undock)
0x09, 0xA7, // USAGE (System Speaker Mute)
0x09, 0xA8, // USAGE (System Hibernate)
// although these display usages are not that important, they don't cost much more than declaring
// the otherwise necessary constant fill bits
0x09, 0xB0, // USAGE (System Display Invert)
0x09, 0xB1, // USAGE (System Display Internal)
0x09, 0xB2, // USAGE (System Display External)
0x09, 0xB3, // USAGE (System Display Both)
0x09, 0xB4, // USAGE (System Display Dual)
0x09, 0xB5, // USAGE (System Display Toggle Intern/Extern)
0x09, 0xB6, // USAGE (System Display Swap)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x10, // REPORT_COUNT (16)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
#if RAWHID_ENABLED
// RAW HID
0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
0xA1, 0x01, // Collection 0x01
0x85, HID_REPORTID_RAWHID, // REPORT_ID (3)
0x75, 0x08, // report size = 8 bits
0x15, 0x00, // logical minimum = 0
0x26, 0xFF, 0x00, // logical maximum = 255
0x95, 64, // report count TX
0x09, 0x01, // usage
0x81, 0x02, // Input (array)
0x95, 64, // report count RX
0x09, 0x02, // usage
0x91, 0x02, // Output (array)
0xC0 // end collection
#endif
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
0x85, HID_REPORTID_CONSUMERCONTROL, // REPORT_ID (4)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x10, // REPORT_COUNT (16)
0x09, 0xe2, // USAGE (Mute) 0x01
0x09, 0xe9, // USAGE (Volume Up) 0x02
0x09, 0xea, // USAGE (Volume Down) 0x03
0x09, 0xcd, // USAGE (Play/Pause) 0x04
0x09, 0xb7, // USAGE (Stop) 0x05
0x09, 0xb6, // USAGE (Scan Previous Track) 0x06
0x09, 0xb5, // USAGE (Scan Next Track) 0x07
0x0a, 0x8a, 0x01, // USAGE (Mail) 0x08
0x0a, 0x92, 0x01, // USAGE (Calculator) 0x09
0x0a, 0x21, 0x02, // USAGE (www search) 0x0a
0x0a, 0x23, 0x02, // USAGE (www home) 0x0b
0x0a, 0x2a, 0x02, // USAGE (www favorites) 0x0c
0x0a, 0x27, 0x02, // USAGE (www refresh) 0x0d
0x0a, 0x26, 0x02, // USAGE (www stop) 0x0e
0x0a, 0x25, 0x02, // USAGE (www forward) 0x0f
0x0a, 0x24, 0x02, // USAGE (www back) 0x10
0x81, 0x62, // INPUT (Data,Var,Abs,NPrf,Null)
0xc0,
};
extern const HIDDescriptor _hidInterface PROGMEM;
const HIDDescriptor _hidInterface =
{
D_INTERFACE(HID_INTERFACE,1,3,0,0),
D_HIDREPORT(sizeof(_hidReportDescriptor)),
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
};
//================================================================================
//================================================================================
// Driver
u8 _hid_protocol = 1;
u8 _hid_idle = 1;
#define WEAK __attribute__ ((weak))
int WEAK HID_GetInterface(u8* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
}
int WEAK HID_GetDescriptor(int i)
{
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
}
void WEAK HID_SendReport(u8 id, const void* data, int len)
{
USB_Send(HID_TX, &id, 1);
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
}
bool WEAK HID_Setup(Setup& setup)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
if (HID_GET_REPORT == r)
{
//HID_GetReport();
return true;
}
if (HID_GET_PROTOCOL == r)
{
//Send8(_hid_protocol); // TODO
return true;
}
}
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
{
if (HID_SET_PROTOCOL == r)
{
_hid_protocol = setup.wValueL;
return true;
}
if (HID_SET_IDLE == r)
{
_hid_idle = setup.wValueL;
return true;
}
}
return false;
}
//================================================================================
//================================================================================
// Mouse
Mouse_::Mouse_(void) : _buttons(0)
{
}
void Mouse_::begin(void)
{
}
void Mouse_::end(void)
{
}
void Mouse_::click(uint8_t b)
{
_buttons = b;
move(0,0,0);
_buttons = 0;
move(0,0,0);
}
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
u8 m[4];
m[0] = _buttons;
m[1] = x;
m[2] = y;
m[3] = wheel;
HID_SendReport(HID_REPORTID_MOUSE,m,sizeof(m));
}
#ifdef MOUSE_ABS_ENABLED
// all parameters have the range of -32768 to 32767 and must be scaled to screen pixels
// some examples:
// x=0,y=0 is the middle of the screen
// x=-32768,y=-32768 is the top left corner
// x=32767,y=-32768 is the top right corner
// x=32767,y=32767 is the bottom right corner
// x=-32768,y=32767 is the bottom left corner
void Mouse_::moveAbs(int16_t x, int16_t y, int16_t wheel)
{
u8 m[7];
m[0] = _buttons; // TODO: is it a good idea to take over the _buttons from relative report here or should it be left out?
m[1] = LSB(x);
m[2] = MSB(x);
m[3] = LSB(y);
m[4] = MSB(y);
m[5] = LSB(wheel);
m[6] = MSB(wheel);
HID_SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m));
}
#endif
void Mouse_::buttons(uint8_t b)
{
if (b != _buttons)
{
_buttons = b;
move(0,0,0);
}
}
void Mouse_::press(uint8_t b)
{
buttons(_buttons | b);
}
void Mouse_::release(uint8_t b)
{
buttons(_buttons & ~b);
}
bool Mouse_::isPressed(uint8_t b)
{
if ((b & _buttons) > 0)
return true;
return false;
}
//================================================================================
//================================================================================
// Keyboard
Keyboard_::Keyboard_(void)
{
}
void Keyboard_::begin(void)
{
}
void Keyboard_::end(void)
{
}
void Keyboard_::sendReport(KeyReport* keys)
{
HID_SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys));
}
extern
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
0x00, // NUL
0x00, // SOH
0x00, // STX
0x00, // ETX
0x00, // EOT
0x00, // ENQ
0x00, // ACK
0x00, // BEL
0x2a, // BS Backspace
0x2b, // TAB Tab
0x28, // LF Enter
0x00, // VT
0x00, // FF
0x00, // CR
0x00, // SO
0x00, // SI
0x00, // DEL
0x00, // DC1
0x00, // DC2
0x00, // DC3
0x00, // DC4
0x00, // NAK
0x00, // SYN
0x00, // ETB
0x00, // CAN
0x00, // EM
0x00, // SUB
0x00, // ESC
0x00, // FS
0x00, // GS
0x00, // RS
0x00, // US
0x2c, // ' '
0x1e|SHIFT, // !
0x34|SHIFT, // "
0x20|SHIFT, // #
0x21|SHIFT, // $
0x22|SHIFT, // %
0x24|SHIFT, // &
0x34, // '
0x26|SHIFT, // (
0x27|SHIFT, // )
0x25|SHIFT, // *
0x2e|SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
0x38, // /
0x27, // 0
0x1e, // 1
0x1f, // 2
0x20, // 3
0x21, // 4
0x22, // 5
0x23, // 6
0x24, // 7
0x25, // 8
0x26, // 9
0x33|SHIFT, // :
0x33, // ;
0x36|SHIFT, // <
0x2e, // =
0x37|SHIFT, // >
0x38|SHIFT, // ?
0x1f|SHIFT, // @
0x04|SHIFT, // A
0x05|SHIFT, // B
0x06|SHIFT, // C
0x07|SHIFT, // D
0x08|SHIFT, // E
0x09|SHIFT, // F
0x0a|SHIFT, // G
0x0b|SHIFT, // H
0x0c|SHIFT, // I
0x0d|SHIFT, // J
0x0e|SHIFT, // K
0x0f|SHIFT, // L
0x10|SHIFT, // M
0x11|SHIFT, // N
0x12|SHIFT, // O
0x13|SHIFT, // P
0x14|SHIFT, // Q
0x15|SHIFT, // R
0x16|SHIFT, // S
0x17|SHIFT, // T
0x18|SHIFT, // U
0x19|SHIFT, // V
0x1a|SHIFT, // W
0x1b|SHIFT, // X
0x1c|SHIFT, // Y
0x1d|SHIFT, // Z
0x2f, // [
0x31, // bslash
0x30, // ]
0x23|SHIFT, // ^
0x2d|SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
0x06, // c
0x07, // d
0x08, // e
0x09, // f
0x0a, // g
0x0b, // h
0x0c, // i
0x0d, // j
0x0e, // k
0x0f, // l
0x10, // m
0x11, // n
0x12, // o
0x13, // p
0x14, // q
0x15, // r
0x16, // s
0x17, // t
0x18, // u
0x19, // v
0x1a, // w
0x1b, // x
0x1c, // y
0x1d, // z
0x2f|SHIFT, //
0x31|SHIFT, // |
0x30|SHIFT, // }
0x35|SHIFT, // ~
0 // DEL
};
uint8_t USBPutChar(uint8_t c);
// press() adds the specified key (printing, non-printing, or modifier)
// to the persistent key report and sends the report. Because of the way
// USB HID works, the host acts like the key remains pressed until we
// call release(), releaseAll(), or otherwise clear the report and resend.
size_t Keyboard_::press(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
} else if (k >= 128) { // it's a modifier key
_keyReport.modifiers |= (1<<(k-128));
k = 0;
} else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
setWriteError();
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers |= 0x02; // the left shift modifier
k &= 0x7F;
}
}
// Add k to the key report only if it's not already present
// and if there is an empty slot.
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
_keyReport.keys[4] != k && _keyReport.keys[5] != k) {
for (i=0; i<6; i++) {
if (_keyReport.keys[i] == 0x00) {
_keyReport.keys[i] = k;
break;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
sendReport(&_keyReport);
return 1;
}
// System Control
// k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::systemControl(uint8_t k)
{
if(k <= 16)
{
u16 mask = 0;
u8 m[2];
if(k > 0)
{
mask = 1 << (k - 1);
}
m[0] = LSB(mask);
m[1] = MSB(mask);
HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));
// these are all OSCs, so send a clear to make it possible to send it again later
m[0] = 0;
m[1] = 0;
HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));
return 1;
}
else
{
setWriteError();
return 0;
}
}
// Consumer Control
// k is one of the CONSUMER_CONTROL defines which come from the HID usage table "Consumer Devices Page (0x0c)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::consumerControl(uint8_t k)
{
if(k <= 16)
{
u16 mask = 0;
u8 m[2];
if(k > 0)
{
mask = 1 << (k - 1);
}
m[0] = LSB(mask);
m[1] = MSB(mask);
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
// these are all OSCs, so send a clear to make it possible to send it again later
m[0] = 0;
m[1] = 0;
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
return 1;
}
else
{
setWriteError();
return 0;
}
}
// release() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
size_t Keyboard_::release(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
} else if (k >= 128) { // it's a modifier key
_keyReport.modifiers &= ~(1<<(k-128));
k = 0;
} else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers &= ~(0x02); // the left shift modifier
k &= 0x7F;
}
}
// Test the key report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it shouldn't be)
for (i=0; i<6; i++) {
if (0 != k && _keyReport.keys[i] == k) {
_keyReport.keys[i] = 0x00;
}
}
sendReport(&_keyReport);
return 1;
}
void Keyboard_::releaseAll(void)
{
_keyReport.keys[0] = 0;
_keyReport.keys[1] = 0;
_keyReport.keys[2] = 0;
_keyReport.keys[3] = 0;
_keyReport.keys[4] = 0;
_keyReport.keys[5] = 0;
_keyReport.modifiers = 0;
sendReport(&_keyReport);
}
size_t Keyboard_::write(uint8_t c)
{
uint8_t p = press(c); // Keydown
uint8_t r = release(c); // Keyup
return (p); // just return the result of press() since release() almost always returns 1
}
#endif
#endif /* if defined(USBCON) */

@ -1,508 +0,0 @@
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "Arduino.h"
#include "wiring_private.h"
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a uart
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
#include "HardwareSerial.h"
/*
* on ATmega8, the uart and its bits are not numbered, so there is no "TXC0"
* definition.
*/
#if !defined(TXC0)
#if defined(TXC)
#define TXC0 TXC
#elif defined(TXC1)
// Some devices have uart1 but no uart0
#define TXC0 TXC1
#else
#error TXC0 not definable in HardwareSerial.h
#endif
#endif
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
struct ring_buffer
{
unsigned char buffer[SERIAL_BUFFER_SIZE];
volatile unsigned int head;
volatile unsigned int tail;
};
#if defined(USBCON)
ring_buffer rx_buffer = { { 0 }, 0, 0};
ring_buffer tx_buffer = { { 0 }, 0, 0};
#endif
#if defined(UBRRH) || defined(UBRR0H)
ring_buffer rx_buffer = { { 0 }, 0, 0 };
ring_buffer tx_buffer = { { 0 }, 0, 0 };
#endif
#if defined(UBRR1H)
ring_buffer rx_buffer1 = { { 0 }, 0, 0 };
ring_buffer tx_buffer1 = { { 0 }, 0, 0 };
#endif
#if defined(UBRR2H)
ring_buffer rx_buffer2 = { { 0 }, 0, 0 };
ring_buffer tx_buffer2 = { { 0 }, 0, 0 };
#endif
#if defined(UBRR3H)
ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
ring_buffer tx_buffer3 = { { 0 }, 0, 0 };
#endif
inline void store_char(unsigned char c, ring_buffer *buffer)
{
int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != buffer->tail) {
buffer->buffer[buffer->head] = c;
buffer->head = i;
}
}
#if !defined(USART0_RX_vect) && defined(USART1_RX_vect)
// do nothing - on the 32u4 the first USART is USART1
#else
#if !defined(USART_RX_vect) && !defined(USART0_RX_vect) && \
!defined(USART_RXC_vect)
#error "Don't know what the Data Received vector is called for the first UART"
#else
void serialEvent() __attribute__((weak));
void serialEvent() {}
#define serialEvent_implemented
#if defined(USART_RX_vect)
ISR(USART_RX_vect)
#elif defined(USART0_RX_vect)
ISR(USART0_RX_vect)
#elif defined(USART_RXC_vect)
ISR(USART_RXC_vect) // ATmega8
#endif
{
#if defined(UDR0)
if (bit_is_clear(UCSR0A, UPE0)) {
unsigned char c = UDR0;
store_char(c, &rx_buffer);
} else {
unsigned char c = UDR0;
};
#elif defined(UDR)
if (bit_is_clear(UCSRA, PE)) {
unsigned char c = UDR;
store_char(c, &rx_buffer);
} else {
unsigned char c = UDR;
};
#else
#error UDR not defined
#endif
}
#endif
#endif
#if defined(USART1_RX_vect)
void serialEvent1() __attribute__((weak));
void serialEvent1() {}
#define serialEvent1_implemented
ISR(USART1_RX_vect)
{
if (bit_is_clear(UCSR1A, UPE1)) {
unsigned char c = UDR1;
store_char(c, &rx_buffer1);
} else {
unsigned char c = UDR1;
};
}
#endif
#if defined(USART2_RX_vect) && defined(UDR2)
void serialEvent2() __attribute__((weak));
void serialEvent2() {}
#define serialEvent2_implemented
ISR(USART2_RX_vect)
{
if (bit_is_clear(UCSR2A, UPE2)) {
unsigned char c = UDR2;
store_char(c, &rx_buffer2);
} else {
unsigned char c = UDR2;
};
}
#endif
#if defined(USART3_RX_vect) && defined(UDR3)
void serialEvent3() __attribute__((weak));
void serialEvent3() {}
#define serialEvent3_implemented
ISR(USART3_RX_vect)
{
if (bit_is_clear(UCSR3A, UPE3)) {
unsigned char c = UDR3;
store_char(c, &rx_buffer3);
} else {
unsigned char c = UDR3;
};
}
#endif
void serialEventRun(void)
{
#ifdef serialEvent_implemented
if (Serial.available()) serialEvent();
#endif
#ifdef serialEvent1_implemented
if (Serial1.available()) serialEvent1();
#endif
#ifdef serialEvent2_implemented
if (Serial2.available()) serialEvent2();
#endif
#ifdef serialEvent3_implemented
if (Serial3.available()) serialEvent3();
#endif
}
#if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect)
// do nothing - on the 32u4 the first USART is USART1
#else
#if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect)
#error "Don't know what the Data Register Empty vector is called for the first UART"
#else
#if defined(UART0_UDRE_vect)
ISR(UART0_UDRE_vect)
#elif defined(UART_UDRE_vect)
ISR(UART_UDRE_vect)
#elif defined(USART0_UDRE_vect)
ISR(USART0_UDRE_vect)
#elif defined(USART_UDRE_vect)
ISR(USART_UDRE_vect)
#endif
{
if (tx_buffer.head == tx_buffer.tail) {
// Buffer empty, so disable interrupts
#if defined(UCSR0B)
cbi(UCSR0B, UDRIE0);
#else
cbi(UCSRB, UDRIE);
#endif
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer.buffer[tx_buffer.tail];
tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE;
#if defined(UDR0)
UDR0 = c;
#elif defined(UDR)
UDR = c;
#else
#error UDR not defined
#endif
}
}
#endif
#endif
#ifdef USART1_UDRE_vect
ISR(USART1_UDRE_vect)
{
if (tx_buffer1.head == tx_buffer1.tail) {
// Buffer empty, so disable interrupts
cbi(UCSR1B, UDRIE1);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer1.buffer[tx_buffer1.tail];
tx_buffer1.tail = (tx_buffer1.tail + 1) % SERIAL_BUFFER_SIZE;
UDR1 = c;
}
}
#endif
#ifdef USART2_UDRE_vect
ISR(USART2_UDRE_vect)
{
if (tx_buffer2.head == tx_buffer2.tail) {
// Buffer empty, so disable interrupts
cbi(UCSR2B, UDRIE2);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer2.buffer[tx_buffer2.tail];
tx_buffer2.tail = (tx_buffer2.tail + 1) % SERIAL_BUFFER_SIZE;
UDR2 = c;
}
}
#endif
#ifdef USART3_UDRE_vect
ISR(USART3_UDRE_vect)
{
if (tx_buffer3.head == tx_buffer3.tail) {
// Buffer empty, so disable interrupts
cbi(UCSR3B, UDRIE3);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;
UDR3 = c;
}
}
#endif
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *ucsrc, volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
{
_rx_buffer = rx_buffer;
_tx_buffer = tx_buffer;
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_ucsrc = ucsrc;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udrie = udrie;
_u2x = u2x;
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(unsigned long baud)
{
uint16_t baud_setting;
bool use_u2x = true;
#if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560.
if (baud == 57600) {
use_u2x = false;
}
#endif
try_again:
if (use_u2x) {
*_ucsra = 1 << _u2x;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
if ((baud_setting > 4095) && use_u2x)
{
use_u2x = false;
goto try_again;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
transmitting = false;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
cbi(*_ucsrb, _udrie);
}
void HardwareSerial::begin(unsigned long baud, byte config)
{
uint16_t baud_setting;
uint8_t current_config;
bool use_u2x = true;
#if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560.
if (baud == 57600) {
use_u2x = false;
}
#endif
try_again:
if (use_u2x) {
*_ucsra = 1 << _u2x;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
if ((baud_setting > 4095) && use_u2x)
{
use_u2x = false;
goto try_again;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
//set the data bits, parity, and stop bits
#if defined(__AVR_ATmega8__)
config |= 0x80; // select UCSRC register (shared with UBRRH)
#endif
*_ucsrc = config;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
cbi(*_ucsrb, _udrie);
}
void HardwareSerial::end()
{
// wait for transmission of outgoing data
while (_tx_buffer->head != _tx_buffer->tail)
;
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
cbi(*_ucsrb, _rxcie);
cbi(*_ucsrb, _udrie);
// clear any received data
_rx_buffer->head = _rx_buffer->tail;
}
int HardwareSerial::available(void)
{
return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
}
int HardwareSerial::peek(void)
{
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
return _rx_buffer->buffer[_rx_buffer->tail];
}
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
return c;
}
}
void HardwareSerial::flush()
{
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
while (transmitting && ! (*_ucsra & _BV(TXC0)));
transmitting = false;
}
size_t HardwareSerial::write(uint8_t c)
{
int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
// ???: return 0 here instead?
while (i == _tx_buffer->tail)
;
_tx_buffer->buffer[_tx_buffer->head] = c;
_tx_buffer->head = i;
sbi(*_ucsrb, _udrie);
// clear the TXC bit -- "can be cleared by writing a one to its bit location"
transmitting = true;
sbi(*_ucsra, TXC0);
return 1;
}
HardwareSerial::operator bool() {
return true;
}
// Preinstantiate Objects //////////////////////////////////////////////////////
#if defined(UBRRH) && defined(UBRRL)
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
#elif defined(UBRR0H) && defined(UBRR0L)
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
#elif defined(USBCON)
// do nothing - Serial object and buffers are initialized in CDC code
#else
#error no serial port defined (port 0)
#endif
#if defined(UBRR1H)
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
#endif
#if defined(UBRR2H)
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
#endif
#if defined(UBRR3H)
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
#endif
#endif // whole file

@ -1,56 +0,0 @@
#include <Arduino.h>
#include <IPAddress.h>
IPAddress::IPAddress()
{
memset(_address, 0, sizeof(_address));
}
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
{
_address[0] = first_octet;
_address[1] = second_octet;
_address[2] = third_octet;
_address[3] = fourth_octet;
}
IPAddress::IPAddress(uint32_t address)
{
memcpy(_address, &address, sizeof(_address));
}
IPAddress::IPAddress(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
}
IPAddress& IPAddress::operator=(const uint8_t *address)
{
memcpy(_address, address, sizeof(_address));
return *this;
}
IPAddress& IPAddress::operator=(uint32_t address)
{
memcpy(_address, (const uint8_t *)&address, sizeof(_address));
return *this;
}
bool IPAddress::operator==(const uint8_t* addr)
{
return memcmp(addr, _address, sizeof(_address)) == 0;
}
size_t IPAddress::printTo(Print& p) const
{
size_t n = 0;
for (int i =0; i < 3; i++)
{
n += p.print(_address[i], DEC);
n += p.print('.');
}
n += p.print(_address[3], DEC);
return n;
}

@ -1,76 +0,0 @@
/*
*
* MIT License:
* Copyright (c) 2011 Adrian McEwen
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* adrianm@mcqn.com 1/1/2011
*/
#ifndef IPAddress_h
#define IPAddress_h
#include <Printable.h>
// A class to make it easier to handle and pass around IP addresses
class IPAddress : public Printable {
private:
uint8_t _address[4]; // IPv4 address
// Access the raw byte array containing the address. Because this returns a pointer
// to the internal structure rather than a copy of the address this function should only
// be used when you know that the usage of the returned uint8_t* will be transient and not
// stored.
uint8_t* raw_address() { return _address; };
public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(const uint8_t *address);
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator uint32_t() { return *((uint32_t*)_address); };
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
bool operator==(const uint8_t* addr);
// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address[index]; };
uint8_t& operator[](int index) { return _address[index]; };
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
IPAddress& operator=(uint32_t address);
virtual size_t printTo(Print& p) const;
friend class EthernetClass;
friend class UDP;
friend class Client;
friend class Server;
friend class DhcpClass;
friend class DNSClient;
};
const IPAddress INADDR_NONE(0,0,0,0);
#endif

@ -1,23 +0,0 @@
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
#include <inttypes.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
#include "Arduino.h"
#if defined(USBCON)
#include "USBDesc.h"
#include "USBCore.h"
#include "USBAPI.h"
#endif /* if defined(USBCON) */
#endif

@ -1,9 +0,0 @@
#ifndef server_h
#define server_h
class Server : public Print {
public:
virtual void begin() =0;
};
#endif

@ -1,267 +0,0 @@
/* Copyright (c) 2002, 2004, 2010 Joerg Wunsch
Copyright (c) 2010 Gerben van den Broeke
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id: malloc.c 2149 2010-06-09 20:45:37Z joerg_wunsch $ */
#include <stdlib.h>
#include "sectionname.h"
#include "stdlib_private.h"
#include <avr/io.h>
/*
* Exported interface:
*
* When extending the data segment, the allocator will not try to go
* beyond the current stack limit, decreased by __malloc_margin bytes.
* Thus, all possible stack frames of interrupt routines that could
* interrupt the current function, plus all further nested function
* calls must not require more stack space, or they'll risk to collide
* with the data segment.
*/
/* May be changed by the user only before the first malloc() call. */
size_t __malloc_margin = 128;
char *__malloc_heap_start = &__heap_start;
char *__malloc_heap_end = &__heap_end;
char *__brkval;
struct __freelist *__flp;
ATTRIBUTE_CLIB_SECTION
void *
malloc(size_t len)
{
struct __freelist *fp1, *fp2, *sfp1, *sfp2;
char *cp;
size_t s, avail;
/*
* Our minimum chunk size is the size of a pointer (plus the
* size of the "sz" field, but we don't need to account for
* this), otherwise we could not possibly fit a freelist entry
* into the chunk later.
*/
if (len < sizeof(struct __freelist) - sizeof(size_t))
len = sizeof(struct __freelist) - sizeof(size_t);
/*
* First, walk the free list and try finding a chunk that
* would match exactly. If we found one, we are done. While
* walking, note down the smallest chunk we found that would
* still fit the request -- we need it for step 2.
*
*/
for (s = 0, fp1 = __flp, fp2 = 0;
fp1;
fp2 = fp1, fp1 = fp1->nx) {
if (fp1->sz < len)
continue;
if (fp1->sz == len) {
/*
* Found it. Disconnect the chunk from the
* freelist, and return it.
*/
if (fp2)
fp2->nx = fp1->nx;
else
__flp = fp1->nx;
return &(fp1->nx);
}
else {
if (s == 0 || fp1->sz < s) {
/* this is the smallest chunk found so far */
s = fp1->sz;
sfp1 = fp1;
sfp2 = fp2;
}
}
}
/*
* Step 2: If we found a chunk on the freelist that would fit
* (but was too large), look it up again and use it, since it
* is our closest match now. Since the freelist entry needs
* to be split into two entries then, watch out that the
* difference between the requested size and the size of the
* chunk found is large enough for another freelist entry; if
* not, just enlarge the request size to what we have found,
* and use the entire chunk.
*/
if (s) {
if (s - len < sizeof(struct __freelist)) {
/* Disconnect it from freelist and return it. */
if (sfp2)
sfp2->nx = sfp1->nx;
else
__flp = sfp1->nx;
return &(sfp1->nx);
}
/*
* Split them up. Note that we leave the first part
* as the new (smaller) freelist entry, and return the
* upper portion to the caller. This saves us the
* work to fix up the freelist chain; we just need to
* fixup the size of the current entry, and note down
* the size of the new chunk before returning it to
* the caller.
*/
cp = (char *)sfp1;
s -= len;
cp += s;
sfp2 = (struct __freelist *)cp;
sfp2->sz = len;
sfp1->sz = s - sizeof(size_t);
return &(sfp2->nx);
}
/*
* Step 3: If the request could not be satisfied from a
* freelist entry, just prepare a new chunk. This means we
* need to obtain more memory first. The largest address just
* not allocated so far is remembered in the brkval variable.
* Under Unix, the "break value" was the end of the data
* segment as dynamically requested from the operating system.
* Since we don't have an operating system, just make sure
* that we don't collide with the stack.
*/
if (__brkval == 0)
__brkval = __malloc_heap_start;
cp = __malloc_heap_end;
if (cp == 0)
cp = STACK_POINTER() - __malloc_margin;
if (cp <= __brkval)
/*
* Memory exhausted.
*/
return 0;
avail = cp - __brkval;
/*
* Both tests below are needed to catch the case len >= 0xfffe.
*/
if (avail >= len && avail >= len + sizeof(size_t)) {
fp1 = (struct __freelist *)__brkval;
__brkval += len + sizeof(size_t);
fp1->sz = len;
return &(fp1->nx);
}
/*
* Step 4: There's no help, just fail. :-/
*/
return 0;
}
ATTRIBUTE_CLIB_SECTION
void
free(void *p)
{
struct __freelist *fp1, *fp2, *fpnew;
char *cp1, *cp2, *cpnew;
/* ISO C says free(NULL) must be a no-op */
if (p == 0)
return;
cpnew = p;
cpnew -= sizeof(size_t);
fpnew = (struct __freelist *)cpnew;
fpnew->nx = 0;
/*
* Trivial case first: if there's no freelist yet, our entry
* will be the only one on it. If this is the last entry, we
* can reduce __brkval instead.
*/
if (__flp == 0) {
if ((char *)p + fpnew->sz == __brkval)
__brkval = cpnew;
else
__flp = fpnew;
return;
}
/*
* Now, find the position where our new entry belongs onto the
* freelist. Try to aggregate the chunk with adjacent chunks
* if possible.
*/
for (fp1 = __flp, fp2 = 0;
fp1;
fp2 = fp1, fp1 = fp1->nx) {
if (fp1 < fpnew)
continue;
cp1 = (char *)fp1;
fpnew->nx = fp1;
if ((char *)&(fpnew->nx) + fpnew->sz == cp1) {
/* upper chunk adjacent, assimilate it */
fpnew->sz += fp1->sz + sizeof(size_t);
fpnew->nx = fp1->nx;
}
if (fp2 == 0) {
/* new head of freelist */
__flp = fpnew;
return;
}
break;
}
/*
* Note that we get here either if we hit the "break" above,
* or if we fell off the end of the loop. The latter means
* we've got a new topmost chunk. Either way, try aggregating
* with the lower chunk if possible.
*/
fp2->nx = fpnew;
cp2 = (char *)&(fp2->nx);
if (cp2 + fp2->sz == cpnew) {
/* lower junk adjacent, merge */
fp2->sz += fpnew->sz + sizeof(size_t);
fp2->nx = fpnew->nx;
}
/*
* If there's a new topmost chunk, lower __brkval instead.
*/
for (fp1 = __flp, fp2 = 0;
fp1->nx != 0;
fp2 = fp1, fp1 = fp1->nx)
/* advance to entry just before end of list */;
cp2 = (char *)&(fp1->nx);
if (cp2 + fp1->sz == __brkval) {
if (fp2 == NULL)
/* Freelist is empty now. */
__flp = NULL;
else
fp2->nx = NULL;
__brkval = cp2 - sizeof(size_t);
}
}

@ -1,150 +0,0 @@
/* Copyright (c) 2004, 2010 Joerg Wunsch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id: realloc.c 2127 2010-06-07 14:49:37Z joerg_wunsch $ */
#include <stdlib.h>
#include <string.h>
#include "sectionname.h"
#include "stdlib_private.h"
#include <avr/io.h>
ATTRIBUTE_CLIB_SECTION
void *
realloc(void *ptr, size_t len)
{
struct __freelist *fp1, *fp2, *fp3, *ofp3;
char *cp, *cp1;
void *memp;
size_t s, incr;
/* Trivial case, required by C standard. */
if (ptr == 0)
return malloc(len);
cp1 = (char *)ptr;
cp1 -= sizeof(size_t);
fp1 = (struct __freelist *)cp1;
cp = (char *)ptr + len; /* new next pointer */
if (cp < cp1)
/* Pointer wrapped across top of RAM, fail. */
return 0;
/*
* See whether we are growing or shrinking. When shrinking,
* we split off a chunk for the released portion, and call
* free() on it. Therefore, we can only shrink if the new
* size is at least sizeof(struct __freelist) smaller than the
* previous size.
*/
if (len <= fp1->sz) {
/* The first test catches a possible unsigned int
* rollover condition. */
if (fp1->sz <= sizeof(struct __freelist) ||
len > fp1->sz - sizeof(struct __freelist))
return ptr;
fp2 = (struct __freelist *)cp;
fp2->sz = fp1->sz - len - sizeof(size_t);
fp1->sz = len;
free(&(fp2->nx));
return ptr;
}
/*
* If we get here, we are growing. First, see whether there
* is space in the free list on top of our current chunk.
*/
incr = len - fp1->sz;
cp = (char *)ptr + fp1->sz;
fp2 = (struct __freelist *)cp;
for (s = 0, ofp3 = 0, fp3 = __flp;
fp3;
ofp3 = fp3, fp3 = fp3->nx) {
if (fp3 == fp2 && fp3->sz + sizeof(size_t) >= incr) {
/* found something that fits */
if (fp3->sz + sizeof(size_t) - incr > sizeof(struct __freelist)) {
/* split off a new freelist entry */
cp = (char *)ptr + len;
fp2 = (struct __freelist *)cp;
fp2->nx = fp3->nx;
fp2->sz = fp3->sz - incr;
fp1->sz = len;
} else {
/* it just fits, so use it entirely */
fp1->sz += fp3->sz + sizeof(size_t);
fp2 = fp3->nx;
}
if (ofp3)
ofp3->nx = fp2;
else
__flp = fp2;
return ptr;
}
/*
* Find the largest chunk on the freelist while
* walking it.
*/
if (fp3->sz > s)
s = fp3->sz;
}
/*
* If we are the topmost chunk in memory, and there was no
* large enough chunk on the freelist that could be re-used
* (by a call to malloc() below), quickly extend the
* allocation area if possible, without need to copy the old
* data.
*/
if (__brkval == (char *)ptr + fp1->sz && len > s) {
cp1 = __malloc_heap_end;
cp = (char *)ptr + len;
if (cp1 == 0)
cp1 = STACK_POINTER() - __malloc_margin;
if (cp < cp1) {
__brkval = cp;
fp1->sz = len;
return ptr;
}
/* If that failed, we are out of luck. */
return 0;
}
/*
* Call malloc() for a new chunk, then copy over the data, and
* release the old region.
*/
if ((memp = malloc(len)) == 0)
return 0;
memcpy(memp, ptr, fp1->sz);
free(ptr);
return memp;
}

@ -1,49 +0,0 @@
/* Copyright (c) 2009 Atmel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __SECTIONNAME_H__
#define __SECTIONNAME_H__
/* Put all avr-libc functions in a common, unique sub-section name under .text. */
#define CLIB_SECTION .text.avr-libc
#define MLIB_SECTION .text.avr-libc.fplib
#define STR(x) _STR(x)
#define _STR(x) #x
#define ATTRIBUTE_CLIB_SECTION __attribute__ ((section (STR(CLIB_SECTION))))
#define ATTRIBUTE_MLIB_SECTION __attribute__ ((section (STR(MLIB_SECTION))))
#define ASSEMBLY_CLIB_SECTION .section CLIB_SECTION, "ax", @progbits
#define ASSEMBLY_MLIB_SECTION .section MLIB_SECTION, "ax", @progbits
#endif

@ -1,58 +0,0 @@
/* Copyright (c) 2004, Joerg Wunsch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id: stdlib_private.h 1657 2008-03-24 17:11:08Z arcanum $ */
#include <inttypes.h>
#include <stdlib.h>
#include <avr/io.h>
#if !defined(__DOXYGEN__)
struct __freelist {
size_t sz;
struct __freelist *nx;
};
#endif
extern char *__brkval; /* first location not yet allocated */
extern struct __freelist *__flp; /* freelist pointer (head of freelist) */
extern size_t __malloc_margin; /* user-changeable before the first malloc() */
extern char *__malloc_heap_start;
extern char *__malloc_heap_end;
extern char __heap_start;
extern char __heap_end;
/* Needed for definition of AVR_STACK_POINTER_REG. */
#include <avr/io.h>
#define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)

@ -1,753 +0,0 @@
this file includes licensing information for parts of arduino.
first, the gnu general public license, which covers the main body
of the processing/arduino code (in general, all the stuff inside the 'app'
and 'core' subfolders).
next, the gnu lesser general public license that covers the arduino core
and libraries.
.....................................................................
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
.....................................................................
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

@ -1,20 +0,0 @@
#include <Arduino.h>
int main(void)
{
init();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}

@ -1,28 +0,0 @@
#include <new.h>
void * operator new(size_t size)
{
return malloc(size);
}
void * operator new[](size_t size)
{
return malloc(size);
}
void operator delete(void * ptr)
{
free(ptr);
}
void operator delete[](void * ptr)
{
free(ptr);
}
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
void __cxa_guard_abort (__guard *) {};
void __cxa_pure_virtual(void) {};

@ -1,24 +0,0 @@
/* Header to define new/delete operators as they aren't provided by avr-gcc by default
Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453
*/
#ifndef NEW_H
#define NEW_H
#include <stdlib.h>
void * operator new(size_t size);
void * operator new[](size_t size);
void operator delete(void * ptr);
void operator delete[](void * ptr);
__extension__ typedef int __guard __attribute__((mode (__DI__)));
extern "C" int __cxa_guard_acquire(__guard *);
extern "C" void __cxa_guard_release (__guard *);
extern "C" void __cxa_guard_abort (__guard *);
extern "C" void __cxa_pure_virtual(void);
#endif

@ -1,201 +0,0 @@
0105 arduino
Fix Linux make.sh, etc. scripts
Test on Linux.
AVR
Ethernet library:
- integrate DHCP support
- client.connect() returns 0 when connection is successful? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238295170
- call Server.begin() from Ethernet.begin() instead of in user's sketch?
- add method for receiving notification of new client connections to a server
- add method for receiving notification of data written to a client
- add method for receiving notification of client disconnections
Incorporate mikalhart's new SoftwareSerial library.
Consider making abs() not a macro. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234908504
Improve shiftOut() performance: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1216659239/0
Add String library.
Add Encoder library.
Bootloader:
- disable watch dog timer
- fix eeprom writing: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1202157667/15
Support pin change interrupts.
Switch pwm output on pins 5 and 6 to phase-correct mode, if possible.
Add parameter to shiftOut() for specifying a number of bits.
Add parameter to Serial.print[ln](x, BIN) for specifying number of bits.
Support PROGMEM strings in Serial.print(): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227919972
Should Serial.print(b) send the ASCII digits of the byte?
Add weak attribute to signal handlers: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203798214
Floating point support in the map() function.
Fix delayMicroseconds(0).
Add sleep function(s).
Add SPI library.
Add OneWire library.
Add pulseOut(), etc. functions from Wiring.
Switch to ServoTimer2 library? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222201226/0#5
Add ContinuousServo class that inherits from Servo?
LiquidCrystal library:
- support going to the next line with println().
Supporting EEMEM directive by changing compiler command line: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1202157667
Include Arduino as AVR-ISP sketch in hardware/firmwares.
Move type definitions into WConstants.h.
Change core and libraries to use Arduino types (e.g. byte, boolean).
COMPUTER
Clear serial monitor button when the serial monitor opens.
Disable checking for updates.
Test the upload.using parameter to upload with a programmer.
Add keyboard shortcut for opening the serial monitor.
Escape characters with copy as html.
Support libraries in the SKETCH/code folder?
Test bootloader burning w/ an AVRISP.
Enable verbose output if shift (or alt?) is held down when pressing run or upload.
Add support for third-party boards in the user's sketchbook folder.
Add support for third-party cores in the user's sketchbook folder.
Re-enable (and fix) the Commander.
Move selection of Linux look and feel from Base.java to arduino.sh script.
Check RAM usage of sketches: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224729260/0#0
Improve preprocessing of sketches:
- Better determine which header files are included (not commented out).
- Remember the original locations of function prototypes to highlight the correct line on error.
Multiple sketch windows.
Avoid library conflicts by only linking in the library whose name matches that of the #included header file.
Easier library discovery and installation ("Add library..." menu item).
Easier board installation ("Add board..." menu item)
Comprehensive board management:
- Enabled and disabled boards.
- Dialog for enabling, disabling, adding, deleting, and possibly editing boards.
- Board descriptions (e.g. explaining differences between boards).
Allow for libraries in <SKETCHBOOK>/libraries.
Allow for boards in <SKETCHBOOK>/boards.
Divide boards.txt into multiple text files.
Allow for core in <SKETCHBOOK>/cores.
Clean up Library and LibraryManager.
Compile libraries dynamically (with compilation of sketch and core files).
Library builds should respect build.verbose.
Detect dependencies between libraries.
Byte-based serial monitor.
Line termination options in the serial monitor.
Clear character should clear serial monitor.
Incorporate serial-net proxy.
Changing font size should change serial monitor font size.
Deal with shorter screens (e.g. ASUS EEPC).
Investigate method for auto-detecting serial port on Windows (javax.usb?)
- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1225226642
Guess serial port on the Mac and Linux.
Automatic detection of baud rate for serial monitor (based on the call to Serial.begin() in the current sketch).
Improve, generally, the upload experience (e.g. faster program start after upload, keep-alive messages to bootloader from IDE, shorter bootloader timeout if possible, progress bar)
Allow uploading of .hex files.
Allow for arbitrary compilation command line arguments.
Find in reference should give same message for missing page as for missing page association.
Test find in reference on libraries.
Change background color while using external editor: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229567785
Compiler.java
- Eliminate the need to pass a Target into the compiler by having the Compiler determine the current target (by checking the preferences directly)?
- Delete the unneeded static functions (for classpath translation, etc.) from the bottom of the file.
Sketch.java
- add system-wide include path in preprocess()?
- should find libraries in the code/ sub-folder of the sketch folder
- do sketches really need to get built in the applet/ sub-folder when uploading?
PreProcessor.java
- split write() into writeHeader() and write() as in Processing?
- add getExtraImports() function instead of having Sketch grab them directly.
Base.java
- add keywords from libraries to the syntax coloring
Editor.java
- allow the Board and Serial port to differ across editor windows. This will require creating a separate instance of the menu for each window, and passing the selections into the sketch when compiling or uploading.
- send the current board and serial port selections to the sketch (which will forward them to the compiler) when compiling or uploading (this should eliminate the need for the Target class, since the compiler will be able to find the target path and its source files itself)
- remove references to the Runner and runtime
DEVELOPMENT
Revise the icon.
Don't recompile the Processing core if the work/ directory exists.
RXTX version patched to not hang with bluetooth serial ports: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237179908
Add licenses for included open source libraries: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234595391
Make run.bat not open a command line window: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1223883872
Update version of the FTDI drivers (Windows).
Remove AVR ISP and giveio drivers (Windows).
Include the executable installer for the FTDI drivers (Windows).
Revise fetch.sh to look for version specific pages (names suffixed with, e.g., "-0007")
Move to ant for build process.
DOCUMENTATION / SITE CONFIGURATION
Multi-language plugin.
Work on opening up website to public editing.
Create form for submitting workshops.
Create form for submitting projects.
DOCUMENTATION / META
Create community section of site.
List of examples we'd like to have.
Style guide for examples, references, and foundations.
Add a Nordic board to the forum.
Add a German board to the forum.
DOCUMENTATION / NAVIGATION
Create About section.
Remove Board page.
Move Environment into the Reference section (which should be renamed Programming).
DOCUMENTATION / FOUNDATIONS
Better documentation of the Arduino BT.
Tutorial about serial communication.
DOCUMENTATION / REFERENCE
Remove parameters from the function links on the reference page.
Document Matrix and Sprite libraries on the Arduino site.
Document Wire.endTransmission() return values: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228240199
DOCUMENTATION / EXAMPLES
Photos:
- Loop
- Analog Input (potentiometer and LDR on analog input 0)
Consistency:
- ledpin vs. ledPin
- value vs. val
Add a Brightness example where an analog input controls the analog output.
Graph example should use an intermediate variable.
Button example says pin 7 but uses pin 2.
Split Loop example in two (one that does loops, another that does arrays).
Add LiquidCrystal library examples.
Add Ethernet library examples.
Add Wire library examples.
Add examples using specific hardware (simple analog sensors, optocouplers, etc.)
Examples should demonstrate use of functions.
Add I2C EEPROM example using Wire library.
Update pictures to use Arduino Diecimila.
Create diagrams and schematics for the examples.
DOCUMENTATION / GETTING STARTED
Arduino feature list (in Getting Started > Introduction).
Main "getting started" link should automatically load page for the user's operating system.
Consider deleting many of the pictures in the howto's as they just make it harder to see the instructions without adding much (e.g. the pictures of files in folders).
Tell people not to put the board on a Powerbook.
People don't know what a jumper is.
Add picture of the RX/TX LEDs flashing.
Show a picture of the LED flashing.
DOCUMENTATION / TROUBLESHOOTING
Add explanation of how to work around auto-reset.
DOCUMENTATION / HACKING
Burning bootloader without an AVRISP: http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html
Documentation for moving from Arduino to custom PCBs.
Write advanced library tutorial.
Loading…
Cancel
Save