forked from mirrors/qmk_userspace
		
	test build of 'Host shield' in minimal env.
This commit is contained in:
		
					parent
					
						
							
								9382bf2f76
							
						
					
				
			
			
				commit
				
					
						c5060ea819
					
				
			
		
					 26 changed files with 500 additions and 267 deletions
				
			
		| 
						 | 
					@ -5,6 +5,7 @@ SRC +=	$(COMMON_DIR)/host.c \
 | 
				
			||||||
	$(COMMON_DIR)/layer.c \
 | 
						$(COMMON_DIR)/layer.c \
 | 
				
			||||||
	$(COMMON_DIR)/timer.c \
 | 
						$(COMMON_DIR)/timer.c \
 | 
				
			||||||
	$(COMMON_DIR)/print.c \
 | 
						$(COMMON_DIR)/print.c \
 | 
				
			||||||
 | 
						$(COMMON_DIR)/debug.c \
 | 
				
			||||||
	$(COMMON_DIR)/bootloader.c \
 | 
						$(COMMON_DIR)/bootloader.c \
 | 
				
			||||||
	$(COMMON_DIR)/util.c
 | 
						$(COMMON_DIR)/util.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,19 +18,28 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#ifndef DEBUG_H
 | 
					#ifndef DEBUG_H
 | 
				
			||||||
#define DEBUG_H 1
 | 
					#define DEBUG_H 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include "print.h"
 | 
					#include "print.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define debug(s)             if(debug_enable) print(s)
 | 
					#define debug(s)             if(debug_enable) print_P(PSTR(s))
 | 
				
			||||||
#define debug_hex(c)         if(debug_enable) phex(c)
 | 
					#define debug_hex(c)         if(debug_enable) phex(c)
 | 
				
			||||||
#define debug_hex16(i)       if(debug_enable) phex16(i)
 | 
					#define debug_hex16(i)       if(debug_enable) phex16(i)
 | 
				
			||||||
#define debug_bin(c)         if(debug_enable) pbin(c)
 | 
					#define debug_bin(c)         if(debug_enable) pbin(c)
 | 
				
			||||||
#define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c)
 | 
					#define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool debug_enable;
 | 
					#ifdef __cplusplus
 | 
				
			||||||
bool debug_matrix;
 | 
					extern "C" {
 | 
				
			||||||
bool debug_keyboard;
 | 
					#endif
 | 
				
			||||||
bool debug_mouse;
 | 
					
 | 
				
			||||||
 | 
					extern bool debug_enable;
 | 
				
			||||||
 | 
					extern bool debug_matrix;
 | 
				
			||||||
 | 
					extern bool debug_keyboard;
 | 
				
			||||||
 | 
					extern bool debug_mouse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#include "host_driver.h"
 | 
					#include "host_driver.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef NKRO_ENABLE
 | 
					#ifdef NKRO_ENABLE
 | 
				
			||||||
extern bool keyboard_nkro;
 | 
					extern bool keyboard_nkro;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -54,4 +58,8 @@ void host_mouse_send(report_mouse_t *report);
 | 
				
			||||||
void host_system_send(uint16_t data);
 | 
					void host_system_send(uint16_t data);
 | 
				
			||||||
void host_consumer_send(uint16_t data);
 | 
					void host_consumer_send(uint16_t data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,8 +21,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
void keyboard_init(void);
 | 
					void keyboard_init(void);
 | 
				
			||||||
void keyboard_proc(void);
 | 
					void keyboard_proc(void);
 | 
				
			||||||
void keyboard_set_leds(uint8_t leds);
 | 
					void keyboard_set_leds(uint8_t leds);
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,11 +29,17 @@
 | 
				
			||||||
#include <avr/pgmspace.h>
 | 
					#include <avr/pgmspace.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern bool print_enable;
 | 
					// avoid collision with arduino/Print.h
 | 
				
			||||||
 | 
					#ifndef __cplusplus
 | 
				
			||||||
// this macro allows you to write print("some text") and
 | 
					// this macro allows you to write print("some text") and
 | 
				
			||||||
// the string is automatically placed into flash memory :)
 | 
					// the string is automatically placed into flash memory :)
 | 
				
			||||||
#define print(s) print_P(PSTR(s))
 | 
					#define print(s) print_P(PSTR(s))
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					extern bool print_enable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void print_S(const char *s);
 | 
					void print_S(const char *s);
 | 
				
			||||||
void print_P(const char *s);
 | 
					void print_P(const char *s);
 | 
				
			||||||
| 
						 | 
					@ -41,5 +47,8 @@ void phex(unsigned char c);
 | 
				
			||||||
void phex16(unsigned int i);
 | 
					void phex16(unsigned int i);
 | 
				
			||||||
void pbin(unsigned char c);
 | 
					void pbin(unsigned char c);
 | 
				
			||||||
void pbin_reverse(unsigned char c);
 | 
					void pbin_reverse(unsigned char c);
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,15 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* transmit a character.  return 0 on success, -1 on error. */
 | 
					/* transmit a character.  return 0 on success, -1 on error. */
 | 
				
			||||||
int8_t sendchar(uint8_t c);
 | 
					int8_t sendchar(uint8_t c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,10 +23,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#ifndef TIMER_PRESCALER
 | 
					#ifndef TIMER_PRESCALER
 | 
				
			||||||
#   if F_CPU > 16000000
 | 
					#   if F_CPU > 16000000
 | 
				
			||||||
#       define TIMER_PRESCALER      256
 | 
					#       define TIMER_PRESCALER      256
 | 
				
			||||||
#   elif F_CPU >= 4000000
 | 
					#   elif F_CPU > 2000000
 | 
				
			||||||
#       define TIMER_PRESCALER      64
 | 
					#       define TIMER_PRESCALER      64
 | 
				
			||||||
#   else
 | 
					#   elif F_CPU > 250000
 | 
				
			||||||
#       define TIMER_PRESCALER      8
 | 
					#       define TIMER_PRESCALER      8
 | 
				
			||||||
 | 
					#   else
 | 
				
			||||||
 | 
					#       define TIMER_PRESCALER      1
 | 
				
			||||||
#   endif
 | 
					#   endif
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#define TIMER_RAW_FREQ      (F_CPU/TIMER_PRESCALER)
 | 
					#define TIMER_RAW_FREQ      (F_CPU/TIMER_PRESCALER)
 | 
				
			||||||
| 
						 | 
					@ -42,6 +44,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#define TIMER_DIFF_MS(a, b)     TIMER_DIFF(a, b, UINT16_MAX)
 | 
					#define TIMER_DIFF_MS(a, b)     TIMER_DIFF(a, b, UINT16_MAX)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
extern volatile uint16_t timer_count;
 | 
					extern volatile uint16_t timer_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,5 +54,8 @@ void timer_init(void);
 | 
				
			||||||
void timer_clear(void);
 | 
					void timer_clear(void);
 | 
				
			||||||
uint16_t timer_read(void);
 | 
					uint16_t timer_read(void);
 | 
				
			||||||
uint16_t timer_elapsed(uint16_t last);
 | 
					uint16_t timer_elapsed(uint16_t last);
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,18 +1,20 @@
 | 
				
			||||||
LUFA_DIR = protocol/lufa
 | 
					LUFA_DIR = protocol/lufa
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Path to the LUFA library
 | 
					# Path to the LUFA library
 | 
				
			||||||
LUFA_PATH = $(TOP_DIR)/protocol/lufa/LUFA-120219
 | 
					LUFA_PATH = protocol/lufa/LUFA-120219
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create the LUFA source path variables by including the LUFA root makefile
 | 
					# Create the LUFA source path variables by including the LUFA root makefile
 | 
				
			||||||
include $(LUFA_PATH)/LUFA/makefile
 | 
					include $(TOP_DIR)/$(LUFA_PATH)/LUFA/makefile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LUFA_SRC = $(LUFA_DIR)/lufa.c \
 | 
					LUFA_SRC = $(LUFA_DIR)/lufa.c \
 | 
				
			||||||
	   $(LUFA_DIR)/descriptor.c \
 | 
						   $(LUFA_DIR)/descriptor.c \
 | 
				
			||||||
	   $(LUFA_SRC_USB)
 | 
						   $(LUFA_SRC_USB)
 | 
				
			||||||
SRC += $(subst $(LUFA_PATH)/,,$(LUFA_SRC))
 | 
					
 | 
				
			||||||
 | 
					SRC += $(LUFA_SRC)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Search Path
 | 
					# Search Path
 | 
				
			||||||
VPATH += $(LUFA_PATH)
 | 
					VPATH += $(TOP_DIR)/$(LUFA_DIR)
 | 
				
			||||||
 | 
					VPATH += $(TOP_DIR)/$(LUFA_PATH)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Option modules
 | 
					# Option modules
 | 
				
			||||||
#ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
 | 
					#ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,7 +59,7 @@ static void send_keyboard(report_keyboard_t *report);
 | 
				
			||||||
static void send_mouse(report_mouse_t *report);
 | 
					static void send_mouse(report_mouse_t *report);
 | 
				
			||||||
static void send_system(uint16_t data);
 | 
					static void send_system(uint16_t data);
 | 
				
			||||||
static void send_consumer(uint16_t data);
 | 
					static void send_consumer(uint16_t data);
 | 
				
			||||||
static host_driver_t lufa_driver = {
 | 
					host_driver_t lufa_driver = {
 | 
				
			||||||
    keyboard_leds,
 | 
					    keyboard_leds,
 | 
				
			||||||
    send_keyboard,
 | 
					    send_keyboard,
 | 
				
			||||||
    send_mouse,
 | 
					    send_mouse,
 | 
				
			||||||
| 
						 | 
					@ -68,49 +68,9 @@ static host_driver_t lufa_driver = {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void SetupHardware(void);
 | 
					/*******************************************************************************
 | 
				
			||||||
static void Console_Task(void);
 | 
					 * Console
 | 
				
			||||||
 | 
					 ******************************************************************************/
 | 
				
			||||||
int main(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    SetupHardware();
 | 
					 | 
				
			||||||
    sei();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print_enable = true;
 | 
					 | 
				
			||||||
    debug_enable = true;
 | 
					 | 
				
			||||||
    debug_matrix = true;
 | 
					 | 
				
			||||||
    debug_keyboard = true;
 | 
					 | 
				
			||||||
    debug_mouse = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // TODO: can't print here
 | 
					 | 
				
			||||||
    debug("LUFA init\n");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    keyboard_init();
 | 
					 | 
				
			||||||
    host_set_driver(&lufa_driver);
 | 
					 | 
				
			||||||
    while (1) {
 | 
					 | 
				
			||||||
        keyboard_proc();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
 | 
					 | 
				
			||||||
        USB_USBTask();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SetupHardware(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    /* Disable watchdog if enabled by bootloader/fuses */
 | 
					 | 
				
			||||||
    MCUSR &= ~(1 << WDRF);
 | 
					 | 
				
			||||||
    wdt_disable();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Disable clock division */
 | 
					 | 
				
			||||||
    clock_prescale_set(clock_div_1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    USB_Init();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // for Console_Task
 | 
					 | 
				
			||||||
    USB_Device_EnableSOFEvents();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef CONSOLE_ENABLE
 | 
					#ifdef CONSOLE_ENABLE
 | 
				
			||||||
static void Console_Task(void)
 | 
					static void Console_Task(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -446,3 +406,51 @@ int8_t sendchar(uint8_t c)
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*******************************************************************************
 | 
				
			||||||
 | 
					 * main
 | 
				
			||||||
 | 
					 ******************************************************************************/
 | 
				
			||||||
 | 
					static void SetupHardware(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /* Disable watchdog if enabled by bootloader/fuses */
 | 
				
			||||||
 | 
					    MCUSR &= ~(1 << WDRF);
 | 
				
			||||||
 | 
					    wdt_disable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Disable clock division */
 | 
				
			||||||
 | 
					    clock_prescale_set(clock_div_1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Leonardo needs. Without this USB device is not recognized.
 | 
				
			||||||
 | 
					    USB_Disable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    USB_Init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // for Console_Task
 | 
				
			||||||
 | 
					    USB_Device_EnableSOFEvents();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(void)  __attribute__ ((weak));
 | 
				
			||||||
 | 
					int main(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    SetupHardware();
 | 
				
			||||||
 | 
					    sei();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    print_enable = true;
 | 
				
			||||||
 | 
					    debug_enable = true;
 | 
				
			||||||
 | 
					    debug_matrix = true;
 | 
				
			||||||
 | 
					    debug_keyboard = true;
 | 
				
			||||||
 | 
					    debug_mouse = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: can't print here
 | 
				
			||||||
 | 
					    debug("LUFA init\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    keyboard_init();
 | 
				
			||||||
 | 
					    host_set_driver(&lufa_driver);
 | 
				
			||||||
 | 
					    while (1) {
 | 
				
			||||||
 | 
					        keyboard_proc();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(INTERRUPT_CONTROL_ENDPOINT)
 | 
				
			||||||
 | 
					        USB_USBTask();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,8 +47,19 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <LUFA/Version.h>
 | 
					#include <LUFA/Version.h>
 | 
				
			||||||
#include <LUFA/Drivers/USB/USB.h>
 | 
					#include <LUFA/Drivers/USB/USB.h>
 | 
				
			||||||
 | 
					#include "host.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern host_driver_t lufa_driver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* extra report structure */
 | 
					/* extra report structure */
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    uint8_t  report_id;
 | 
					    uint8_t  report_id;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										67
									
								
								protocol/usb_hid.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								protocol/usb_hid.mk
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,67 @@
 | 
				
			||||||
 | 
					USB_HID_DIR = protocol/usb_hid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# USB Host Shield
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					USB_HOST_SHIELD_DIR = $(USB_HID_DIR)/USB_Host_Shield_2.0
 | 
				
			||||||
 | 
					USB_HOST_SHIELD_SRC = \
 | 
				
			||||||
 | 
						$(USB_HOST_SHIELD_DIR)/Usb.cpp \
 | 
				
			||||||
 | 
						$(USB_HOST_SHIELD_DIR)/hid.cpp \
 | 
				
			||||||
 | 
						$(USB_HOST_SHIELD_DIR)/parsetools.cpp \
 | 
				
			||||||
 | 
						$(USB_HOST_SHIELD_DIR)/message.cpp 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Arduino
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					ARDUINO_DIR = $(USB_HID_DIR)/arduino-1.0.1
 | 
				
			||||||
 | 
					ARDUINO_CORES_DIR = $(ARDUINO_DIR)/cores/arduino
 | 
				
			||||||
 | 
					ARDUINO_CORES_SRC = \
 | 
				
			||||||
 | 
						$(ARDUINO_CORES_DIR)/Print.cpp \
 | 
				
			||||||
 | 
						$(ARDUINO_CORES_DIR)/Stream.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# replaced with override_Serial.c
 | 
				
			||||||
 | 
					#	$(ARDUINO_CORES_DIR)/CDC.cpp \
 | 
				
			||||||
 | 
					#	$(ARDUINO_CORES_DIR)/HID.cpp \
 | 
				
			||||||
 | 
					#	$(ARDUINO_CORES_DIR)/USBCore.cpp \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# replaced with override_wiring.c and common/timer.c
 | 
				
			||||||
 | 
					#	$(ARDUINO_CORES_DIR)/wiring.c \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# HID parser
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					SRC += $(USB_HID_DIR)/parser.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# replace arduino/CDC.cpp
 | 
				
			||||||
 | 
					SRC += $(USB_HID_DIR)/override_Serial.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# replace arduino/wiring.c
 | 
				
			||||||
 | 
					SRC += $(USB_HID_DIR)/override_wiring.c
 | 
				
			||||||
 | 
					SRC += common/timer.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SRC += $(USB_HOST_SHIELD_SRC)
 | 
				
			||||||
 | 
					SRC += $(ARDUINO_CORES_SRC)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					OPT_DEFS += -DARDUINO=101
 | 
				
			||||||
 | 
					# Arduino USBCore needs USB_VID and USB_PID.
 | 
				
			||||||
 | 
					#OPT_DEFS += -DARDUINO=101 -DUSB_VID=0x2341 -DUSB_PID=0x8036
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Search Path
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					VPATH += $(TOP_DIR)/$(USB_HID_DIR)
 | 
				
			||||||
 | 
					VPATH += $(TOP_DIR)/$(USB_HOST_SHIELD_DIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# for #include "Arduino.h"
 | 
				
			||||||
 | 
					VPATH += $(TOP_DIR)/$(ARDUINO_CORES_DIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# for #include "pins_arduino.h"
 | 
				
			||||||
 | 
					VPATH += $(TOP_DIR)/$(ARDUINO_DIR)/variants/leonardo
 | 
				
			||||||
| 
						 | 
					@ -1,44 +0,0 @@
 | 
				
			||||||
#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;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,8 @@
 | 
				
			||||||
 | 
					USB HID protocol
 | 
				
			||||||
 | 
					================
 | 
				
			||||||
 | 
					Host side of USB HID keyboard protocol implementation.
 | 
				
			||||||
 | 
					Only standard HID Boot mode is supported at this time. This means most of normal keyboards are supported while proprietary >6KRO and NKRO is not.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Third party Libraries
 | 
					Third party Libraries
 | 
				
			||||||
---------------------
 | 
					---------------------
 | 
				
			||||||
USB_Host_Shield_2.0
 | 
					USB_Host_Shield_2.0
 | 
				
			||||||
| 
						 | 
					@ -7,3 +12,17 @@ USB_Host_Shield_2.0
 | 
				
			||||||
arduino-1.0.1
 | 
					arduino-1.0.1
 | 
				
			||||||
    Arduino files copied from:
 | 
					    Arduino files copied from:
 | 
				
			||||||
    https://github.com/arduino/Arduino/hardware/arduino/{cores,variants}
 | 
					    https://github.com/arduino/Arduino/hardware/arduino/{cores,variants}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Test build
 | 
				
			||||||
 | 
					----------
 | 
				
			||||||
 | 
					In test directory;
 | 
				
			||||||
 | 
					    $ make
 | 
				
			||||||
 | 
					    $ DEV=/dev/ttyACM0 make program
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can see HID keyboard reports on debug output.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Restriction and Bug
 | 
				
			||||||
 | 
					-------------------
 | 
				
			||||||
 | 
					Not statble yet.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,22 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * 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;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -16,8 +16,8 @@
 | 
				
			||||||
** SOFTWARE.  
 | 
					** SOFTWARE.  
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define CDC_ENABLED
 | 
					#define CDC_ENABLED
 | 
				
			||||||
//#define HID_ENABLED
 | 
					#define HID_ENABLED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef CDC_ENABLED
 | 
					#ifdef CDC_ENABLED
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,7 +108,6 @@ unsigned long micros() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void delay(unsigned long ms)
 | 
					void delay(unsigned long ms)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
//PORTB &= ~(1<<0);
 | 
					 | 
				
			||||||
	uint16_t start = (uint16_t)micros();
 | 
						uint16_t start = (uint16_t)micros();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (ms > 0) {
 | 
						while (ms > 0) {
 | 
				
			||||||
| 
						 | 
					@ -117,7 +116,6 @@ void delay(unsigned long ms)
 | 
				
			||||||
			start += 1000;
 | 
								start += 1000;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
//PORTB |= (1<<0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. */
 | 
					/* Delay for the given number of microseconds.  Assumes a 8 or 16 MHz clock. */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								protocol/usb_hid/leonardo_led.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								protocol/usb_hid/leonardo_led.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					#ifndef LEONARDO_LED_H
 | 
				
			||||||
 | 
					#define LEONARDO_LED_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Leonardo "TX" LED for debug
 | 
				
			||||||
 | 
					#define LED_TX_INIT    (DDRD  |=  (1<<5))
 | 
				
			||||||
 | 
					#define LED_TX_ON      (PORTD &= ~(1<<5))
 | 
				
			||||||
 | 
					#define LED_TX_OFF     (PORTD |=  (1<<5))
 | 
				
			||||||
 | 
					#define LED_TX_TOGGLE  (PORTD ^=  (1<<5))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -1,66 +0,0 @@
 | 
				
			||||||
#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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										51
									
								
								protocol/usb_hid/override_Serial.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								protocol/usb_hid/override_Serial.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,51 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Null implementation of Serial to dump debug print into blackhole
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include "Arduino.h"
 | 
				
			||||||
 | 
					#include "sendchar.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "USBAPI.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Serial_::begin(uint16_t baud_count)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Serial_::end(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Serial_::accept(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int Serial_::available(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int Serial_::peek(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int Serial_::read(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Serial_::flush(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					size_t Serial_::write(uint8_t c)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    sendchar(c);
 | 
				
			||||||
 | 
					    return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Serial_::operator bool() {
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Serial_ Serial;
 | 
				
			||||||
							
								
								
									
										28
									
								
								protocol/usb_hid/override_wiring.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								protocol/usb_hid/override_wiring.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * To keep Timer0 for common/timer.c override arduino/wiring.c.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include <util/delay.h>
 | 
				
			||||||
 | 
					#include "common/timer.h"
 | 
				
			||||||
 | 
					#include "Arduino.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned long millis()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return timer_read();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					unsigned long micros()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return timer_read() * 1000UL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void delay(unsigned long ms)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    _delay_ms(ms);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void delayMicroseconds(unsigned int us)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    _delay_us(us);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void init()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    timer_init();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,14 @@
 | 
				
			||||||
#include "parser.h"
 | 
					#include "parser.h"
 | 
				
			||||||
 | 
					#include "leonardo_led.h"
 | 
				
			||||||
 | 
					#include "debug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
 | 
					void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PORTB ^= (1<<0);
 | 
					    LED_TX_TOGGLE;
 | 
				
			||||||
/*
 | 
					    debug("KBDReport: ");
 | 
				
			||||||
    Serial.print("KBDReport: ");
 | 
					 | 
				
			||||||
    for (uint8_t i = 0; i < len; i++) {
 | 
					    for (uint8_t i = 0; i < len; i++) {
 | 
				
			||||||
        PrintHex<uint8_t>(buf[i]);
 | 
					        debug_hex(buf[i]);
 | 
				
			||||||
        Serial.print(" ");
 | 
					        debug(" ");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Serial.print("\r\n");
 | 
					    debug("\r\n");
 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
    //PORTC &= ~(1<<7);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,6 @@
 | 
				
			||||||
 | 
					#ifndef PARSER_H
 | 
				
			||||||
 | 
					#define PARSER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "hid.h"
 | 
					#include "hid.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class KBDReportParser : public HIDReportParser
 | 
					class KBDReportParser : public HIDReportParser
 | 
				
			||||||
| 
						 | 
					@ -5,3 +8,5 @@ class KBDReportParser : public HIDReportParser
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
 | 
						virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,9 @@
 | 
				
			||||||
#----------------------------------------------------------------------------
 | 
					#----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Target file name (without extension).
 | 
					# Target file name (without extension).
 | 
				
			||||||
TARGET = usbkbd
 | 
					TARGET = usb_hid_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TOP_DIR = ../../..
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Directory keyboard dependent files exist
 | 
					# Directory keyboard dependent files exist
 | 
				
			||||||
TARGET_DIR = .
 | 
					TARGET_DIR = .
 | 
				
			||||||
| 
						 | 
					@ -63,79 +65,62 @@ F_CPU = 16000000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# LUFA specific
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Target architecture (see library "Board Types" documentation).
 | 
				
			||||||
 | 
					ARCH = AVR8
 | 
				
			||||||
 | 
					# Input clock frequency.
 | 
				
			||||||
 | 
					#     This will define a symbol, F_USB, in all source code files equal to the
 | 
				
			||||||
 | 
					#     input clock frequency (before any prescaling is performed) in Hz. This value may
 | 
				
			||||||
 | 
					#     differ from F_CPU if prescaling is used on the latter, and is required as the
 | 
				
			||||||
 | 
					#     raw input clock is fed directly to the PLL sections of the AVR for high speed
 | 
				
			||||||
 | 
					#     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
 | 
				
			||||||
 | 
					#     at the end, this will be done automatically to create a 32-bit value in your
 | 
				
			||||||
 | 
					#     source code.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#     If no clock division is performed on the input clock inside the AVR (via the
 | 
				
			||||||
 | 
					#     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
 | 
				
			||||||
 | 
					F_USB = $(F_CPU)
 | 
				
			||||||
 | 
					# Interrupt driven control endpoint task
 | 
				
			||||||
 | 
					OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
					# Build Options
 | 
				
			||||||
USB_HOST_SRC = \
 | 
					#   comment out to disable the options.
 | 
				
			||||||
	Usb.cpp \
 | 
					#
 | 
				
			||||||
	cdcacm.cpp \
 | 
					# Console for debug
 | 
				
			||||||
	cdcftdi.cpp \
 | 
					OPT_DEFS += -DCONSOLE_ENABLE
 | 
				
			||||||
	cdcprolific.cpp \
 | 
					 | 
				
			||||||
	hid.cpp \
 | 
					 | 
				
			||||||
	hidboot.cpp \
 | 
					 | 
				
			||||||
	hiduniversal.cpp \
 | 
					 | 
				
			||||||
	hidusagetitlearrays.cpp \
 | 
					 | 
				
			||||||
	hidescriptorparser.cpp \
 | 
					 | 
				
			||||||
	message.cpp \
 | 
					 | 
				
			||||||
	parsetools.cpp
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#PS3BT.cpp \
 | 
					# Boot Section Size in bytes
 | 
				
			||||||
	#PS3USB.cpp \
 | 
					#   Teensy halfKay   512
 | 
				
			||||||
	#RFCOMM.cpp \
 | 
					#   Atmel DFU loader 4096
 | 
				
			||||||
	#XBOXUSB.cpp \
 | 
					#   LUFA bootloader  4096
 | 
				
			||||||
	#adk.cpp \
 | 
					#OPT_DEFS += -DBOOT_SIZE=4096
 | 
				
			||||||
	#masstorage.cpp \
 | 
					
 | 
				
			||||||
	#max_LCD.cpp \
 | 
					
 | 
				
			||||||
	#usbhub.cpp
 | 
					
 | 
				
			||||||
 | 
					SRC =  test.cpp
 | 
				
			||||||
 | 
					SRC += common/debug.c
 | 
				
			||||||
 | 
					SRC += common/print.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CONFIG_H = config.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#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
 | 
					# Search Path
 | 
				
			||||||
VPATH += $(TARGET_DIR)
 | 
					VPATH += $(TARGET_DIR)
 | 
				
			||||||
VPATH += $(USB_HOST_DIR)
 | 
					VPATH += $(TOP_DIR)
 | 
				
			||||||
VPATH += $(ARDUINO_DIR)
 | 
					VPATH += $(TOP_DIR)/common
 | 
				
			||||||
# 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 Leonardo
 | 
				
			||||||
PROGRAM_CMD = avrdude -patmega32u4 -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex
 | 
					PROGRAM_CMD = avrdude -p$(MCU) -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include ../../rules.mk
 | 
					
 | 
				
			||||||
 | 
					include $(TOP_DIR)/protocol/usb_hid.mk
 | 
				
			||||||
 | 
					include $(TOP_DIR)/protocol/lufa.mk
 | 
				
			||||||
 | 
					include $(TOP_DIR)/rules.mk
 | 
				
			||||||
							
								
								
									
										40
									
								
								protocol/usb_hid/test/config.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								protocol/usb_hid/test/config.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2012 Jun Wako <wakojun@gmail.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					the Free Software Foundation, either version 2 of the License, or
 | 
				
			||||||
 | 
					(at your option) any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This program 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 General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You should have received a copy of the GNU General Public License
 | 
				
			||||||
 | 
					along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef CONFIG_H
 | 
				
			||||||
 | 
					#define CONFIG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define VENDOR_ID       0xFEED
 | 
				
			||||||
 | 
					#define PRODUCT_ID      0xCAFE
 | 
				
			||||||
 | 
					#define DEVICE_VER      0x0814
 | 
				
			||||||
 | 
					#define MANUFACTURER    t.m.k.
 | 
				
			||||||
 | 
					#define PRODUCT         USB to USB keyboard converter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DESCRIPTION     Product from t.m.k. keyboard firmware project
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* matrix size */
 | 
				
			||||||
 | 
					#define MATRIX_ROWS 32
 | 
				
			||||||
 | 
					#define MATRIX_COLS 8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* key combination for command */
 | 
				
			||||||
 | 
					#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										92
									
								
								protocol/usb_hid/test/test.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								protocol/usb_hid/test/test.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,92 @@
 | 
				
			||||||
 | 
					#include <avr/io.h>
 | 
				
			||||||
 | 
					#include <avr/wdt.h>
 | 
				
			||||||
 | 
					#include <avr/power.h>
 | 
				
			||||||
 | 
					#include <util/delay.h>
 | 
				
			||||||
 | 
					#include <Arduino.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// USB HID host
 | 
				
			||||||
 | 
					#include "Usb.h"
 | 
				
			||||||
 | 
					#include "hid.h"
 | 
				
			||||||
 | 
					#include "hidboot.h"
 | 
				
			||||||
 | 
					#include "parser.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// LUFA
 | 
				
			||||||
 | 
					#include "lufa.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "debug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "leonardo_led.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static USB     usb_host;
 | 
				
			||||||
 | 
					static HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd(&usb_host);
 | 
				
			||||||
 | 
					static KBDReportParser kbd_parser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void LUFA_setup(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /* Disable watchdog if enabled by bootloader/fuses */
 | 
				
			||||||
 | 
					    MCUSR &= ~(1 << WDRF);
 | 
				
			||||||
 | 
					    wdt_disable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Disable clock division */
 | 
				
			||||||
 | 
					    clock_prescale_set(clock_div_1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Leonardo needs. Without this USB device is not recognized.
 | 
				
			||||||
 | 
					    USB_Disable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    USB_Init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // for Console_Task
 | 
				
			||||||
 | 
					    USB_Device_EnableSOFEvents();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void HID_setup()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // Arduino Timer startup: wiring.c
 | 
				
			||||||
 | 
					    init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (usb_host.Init() == -1) {
 | 
				
			||||||
 | 
					        debug("HID init: failed\n");
 | 
				
			||||||
 | 
					        LED_TX_OFF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    _delay_ms(200);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // LED for debug
 | 
				
			||||||
 | 
					    LED_TX_INIT;
 | 
				
			||||||
 | 
					    LED_TX_ON;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    print_enable = true;
 | 
				
			||||||
 | 
					    debug_enable = true;
 | 
				
			||||||
 | 
					    debug_matrix = true;
 | 
				
			||||||
 | 
					    debug_keyboard = true;
 | 
				
			||||||
 | 
					    debug_mouse = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    LUFA_setup();
 | 
				
			||||||
 | 
					    sei();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // wait for startup of sendchar routine
 | 
				
			||||||
 | 
					    while (USB_DeviceState != DEVICE_STATE_Configured) ;
 | 
				
			||||||
 | 
					    if (debug_enable) {
 | 
				
			||||||
 | 
					        _delay_ms(1000);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    HID_setup();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    debug("init: done\n");
 | 
				
			||||||
 | 
					    for (;;) {
 | 
				
			||||||
 | 
					        usb_host.Task();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(INTERRUPT_CONTROL_ENDPOINT)
 | 
				
			||||||
 | 
					        // LUFA Task for control request
 | 
				
			||||||
 | 
					        USB_USBTask();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										9
									
								
								rules.mk
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								rules.mk
									
										
									
									
									
								
							| 
						 | 
					@ -187,6 +187,7 @@ endif
 | 
				
			||||||
#  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
 | 
					#  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
 | 
				
			||||||
#       dump that will be displayed for a given single line of source input.
 | 
					#       dump that will be displayed for a given single line of source input.
 | 
				
			||||||
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
 | 
					ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
 | 
				
			||||||
 | 
					ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 | 
				
			||||||
ifdef CONFIG_H
 | 
					ifdef CONFIG_H
 | 
				
			||||||
    ASFLAGS += -include $(CONFIG_H)
 | 
					    ASFLAGS += -include $(CONFIG_H)
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
| 
						 | 
					@ -345,9 +346,9 @@ GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
 | 
				
			||||||
# Combine all necessary flags and optional flags.
 | 
					# Combine all necessary flags and optional flags.
 | 
				
			||||||
# Add target processor to flags.
 | 
					# Add target processor to flags.
 | 
				
			||||||
# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
 | 
					# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
 | 
				
			||||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
 | 
					ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
 | 
				
			||||||
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
 | 
					ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
 | 
				
			||||||
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
 | 
					ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -569,7 +570,7 @@ $(OBJDIR)/%.o : %.S
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create preprocessed source for use in sending a bug report.
 | 
					# Create preprocessed source for use in sending a bug report.
 | 
				
			||||||
%.i : %.c
 | 
					%.i : %.c
 | 
				
			||||||
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
 | 
						$(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Target: clean project.
 | 
					# Target: clean project.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue