Add USB HID(host) protocol.(not finished)

example_keyboards
tmk 12 years ago
parent 7350b7c6aa
commit 895cd4dfa2

@ -0,0 +1,141 @@
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device.
# Please customize your programmer settings(PROGRAM_CMD)
#
# make teensy = Download the hex file to the device, using teensy_loader_cli.
# (must have teensy_loader_cli installed).
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
# (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
# (must have Atmel FLIP installed).
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# Target file name (without extension).
TARGET = usbkbd
# Directory keyboard dependent files exist
TARGET_DIR = .
# MCU name
MCU = atmega32u4
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
ARDUINO_DIR = arduino-1.0.1/cores
ARDUINO_SRC = \
arduino/Print.cpp \
arduino/Stream.cpp \
arduino/wiring.c
# arduino/main.cpp \
# arduino/USBCore.cpp \
# arduino/CDC.cpp \
# arduino/HID.cpp \
# arduino/HardwareSerial.cpp \
# arduino/IPAddress.cpp \
# arduino/Tone.cpp \
# arduino/WMath.cpp \
# arduino/WInterrupts.c \
# arduino/wiring_analog.c \
# arduino/wiring_pulse.c \
# arduino/wiring_shift.c
# arduino/wiring_digital.c \
# arduino/WString.cpp \
# arduino/new.cpp \
USB_HOST_DIR = ./USB_Host_Shield_2.0
USB_HOST_SRC = \
Usb.cpp \
cdcacm.cpp \
cdcftdi.cpp \
cdcprolific.cpp \
hid.cpp \
hidboot.cpp \
hiduniversal.cpp \
hidusagetitlearrays.cpp \
hidescriptorparser.cpp \
message.cpp \
parsetools.cpp
#PS3BT.cpp \
#PS3USB.cpp \
#RFCOMM.cpp \
#XBOXUSB.cpp \
#adk.cpp \
#masstorage.cpp \
#max_LCD.cpp \
#usbhub.cpp
#SRC = host_kbd.cpp
SRC = main.cpp
SRC += parser.cpp
SRC += NullSerial.cpp
SRC += $(USB_HOST_SRC)
SRC += $(ARDUINO_SRC)
OPT_DEFS = -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(USB_HOST_DIR)
VPATH += $(ARDUINO_DIR)
# for Arduino.h
VPATH += arduino-1.0.1/cores/arduino
# for pins_arduino.h
VPATH += arduino-1.0.1/variants/leonardo
# Ad hoc workaround to override original arduino/USBAPI.h with our own USBAPI.h.
# Obsolete but needed in order to remove directory including the current input file from search list.
# Option -iquote can't replace -I- for this purpose.
EXTRAFLAGS += -I-
# program Leonardo
PROGRAM_CMD = avrdude -patmega32u4 -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex
include ../../rules.mk

@ -0,0 +1,44 @@
#include "USBAPI.h"
void NullSerial::begin(uint16_t baud_count)
{
}
void NullSerial::end(void)
{
}
void NullSerial::accept(void)
{
}
int NullSerial::available(void)
{
return 0;
}
int NullSerial::peek(void)
{
return -1;
}
int NullSerial::read(void)
{
return -1;
}
void NullSerial::flush(void)
{
}
size_t NullSerial::write(uint8_t c)
{
return 1;
}
NullSerial::operator bool() {
return true;
}
NullSerial Serial;

@ -0,0 +1,22 @@
/*
* Override original arduino USBAPI.h.
*/
#include <stdint.h>
#include "Stream.h"
class NullSerial : public Stream
{
public:
void begin(uint16_t baud_count);
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);
operator bool();
};
extern NullSerial Serial;

@ -0,0 +1,66 @@
#include <util/delay.h>
#include <Arduino.h>
#include "Usb.h"
#include "hid.h"
#include "hidboot.h"
#include "parser.h"
USB Usb;
HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&Usb);
KBDReportParser Prs;
void usb_disable()
{
USBCON &= ~(1<<VBUSTI);
UDIEN = 0;
USBINT = 0;
UDINT = 0;
UDCON |= (1<<DETACH);
USBCON &= ~(1<<USBE);
PLLCSR = 0;
UHWCON &= ~(1<<UVREGE);
USBCON &= ~(1<<OTGPADE);
}
void setup()
{
usb_disable();
// RX LED for debug
DDRB |= (1<<0);
Serial.begin( 115200 );
while (!Serial) ;
delay( 1000 );
Serial.println("Start");
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
kbd.SetReportParser(0, (HIDReportParser*)&Prs);
}
void loop()
{
Usb.Task();
}
int main(void)
{
// arduino/wiring.c(Timer initialize)
init();
setup();
for (;;) {
loop();
}
return 0;
}

@ -0,0 +1,15 @@
#include "parser.h"
void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
PORTB ^= (1<<0);
/*
Serial.print("KBDReport: ");
for (uint8_t i = 0; i < len; i++) {
PrintHex<uint8_t>(buf[i]);
Serial.print(" ");
}
Serial.print("\r\n");
*/
//PORTC &= ~(1<<7);
}

@ -0,0 +1,7 @@
#include "hid.h"
class KBDReportParser : public HIDReportParser
{
public:
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

@ -158,6 +158,10 @@ CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions CPPFLAGS += -fno-exceptions
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fdata-sections
# to supress "warning: only initialized variables can be placed into program memory area"
CPPFLAGS += -w
CPPFLAGS += -Wall CPPFLAGS += -Wall
CPPFLAGS += -Wundef CPPFLAGS += -Wundef
#CPPFLAGS += -mshort-calls #CPPFLAGS += -mshort-calls
@ -541,6 +545,7 @@ $(OBJDIR)/%.o : %.c
# Compile: create object files from C++ source files. # Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.o : %.cpp
@echo @echo
mkdir -p $(@D)
@echo $(MSG_COMPILING_CPP) $< @echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@ $(CC) -c $(ALL_CPPFLAGS) $< -o $@

Loading…
Cancel
Save