Merge branch 'lufa'

This commit is contained in:
tmk 2012-06-30 14:56:24 +09:00
commit fca518f90d
41 changed files with 1937 additions and 266 deletions

View file

@ -1,22 +1,23 @@
SRC += host.c \
keyboard.c \
command.c \
layer.c \
timer.c \
print.c \
bootloader.c \
util.c
COMMON_DIR = common
SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/keyboard.c \
$(COMMON_DIR)/command.c \
$(COMMON_DIR)/layer.c \
$(COMMON_DIR)/timer.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/bootloader.c \
$(COMMON_DIR)/util.c
# Option modules
ifdef MOUSEKEY_ENABLE
SRC += mousekey.c
SRC += $(COMMON_DIR)/mousekey.c
OPT_DEFS += -DMOUSEKEY_ENABLE
endif
ifdef PS2_MOUSE_ENABLE
SRC += ps2.c \
ps2_mouse.c
SRC += $(COMMON_DIR)/ps2.c \
$(COMMON_DIR)/ps2_mouse.c
OPT_DEFS += -DPS2_MOUSE_ENABLE
endif

View file

@ -1,22 +1,87 @@
/*
Copyright 2011 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/>.
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "bootloader.h"
/* Start Bootloader from Application
* See
* http://www.pjrc.com/teensy/jump_to_bootloader.html
* http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html
*/
void bootloader_jump(void) __attribute__ ((weak));
void bootloader_jump(void) {}
// TODO: support usbasp
/* Boot Section Size in bytes
* Teensy halfKay 512
* Atmel DFU loader 4096
* LUFA bootloader 4096
*/
#ifndef BOOT_SIZE
#define BOOT_SIZE 512
#endif
#define FLASH_SIZE (FLASHEND + 1)
#define BOOTLOADER_START (FLASHEND - BOOT_SIZE)
void bootloader_jump(void) {
cli();
//
//Teensy
//
#if defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
// disable watchdog, if enabled
// disable all peripherals
UDCON = 1;
USBCON = (1<<FRZCLK); // disable USB
UCSR1B = 0;
_delay_ms(5);
#else
// This makes custom USBasploader come up.
MCUSR = 0;
#endif
#if defined(__AVR_AT90USB162__)
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
DDRB = 0; DDRC = 0; DDRD = 0;
PORTB = 0; PORTC = 0; PORTD = 0;
#elif defined(__AVR_ATmega32U4__)
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
#elif defined(__AVR_AT90USB646__)
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
#elif defined(__AVR_AT90USB1286__)
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
#endif
//
//USBasp
//
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P)
// This makes custom USBasploader come up.
MCUSR = 0;
// initialize ports
PORTB = 0; PORTC= 0; PORTD = 0;
DDRB = 0; DDRC= 0; DDRD = 0;
// disable interrupts
EIMSK = 0; EECR = 0; SPCR = 0;
ACSR = 0; SPMCSR = 0; WDTCSR = 0; PCICR = 0;
TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0;
ADCSRA = 0; TWCR = 0; UCSR0B = 0;
#endif
// start Bootloader
((void (*)(void))BOOTLOADER_START)();
}

View file

@ -138,6 +138,7 @@ static uint8_t command_common(void)
}
break;
case KB_S:
print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
#ifdef HOST_PJRC
print("UDCON: "); phex(UDCON); print("\n");
print("UDIEN: "); phex(UDIEN); print("\n");

View file

@ -168,13 +168,16 @@ void host_mouse_send(report_mouse_t *report)
void host_system_send(uint16_t data)
{
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;
if (!driver) return;
(*driver->send_system)(data);
}
void host_consumer_send(uint16_t data)
{
// TODO: this is needed?
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;

View file

@ -49,6 +49,7 @@ void keyboard_proc(void)
uint8_t fn_bits = 0;
#ifdef EXTRAKEY_ENABLE
uint16_t consumer_code = 0;
uint16_t system_code = 0;
#endif
matrix_scan();
@ -89,22 +90,13 @@ void keyboard_proc(void)
#ifdef HOST_PJRC
if (suspend && remote_wakeup) {
usb_remote_wakeup();
} else {
host_system_send(SYSTEM_POWER_DOWN);
}
#else
host_system_send(SYSTEM_POWER_DOWN);
#endif
host_system_send(0);
_delay_ms(500);
system_code = SYSTEM_POWER_DOWN;
} else if (code == KB_SYSTEM_SLEEP) {
host_system_send(SYSTEM_SLEEP);
host_system_send(0);
_delay_ms(500);
system_code = SYSTEM_SLEEP;
} else if (code == KB_SYSTEM_WAKE) {
host_system_send(SYSTEM_WAKE_UP);
host_system_send(0);
_delay_ms(500);
system_code = SYSTEM_WAKE_UP;
}
// Consumer Page
else if (code == KB_AUDIO_MUTE) {
@ -173,6 +165,7 @@ void keyboard_proc(void)
host_send_keyboard_report();
#ifdef EXTRAKEY_ENABLE
host_consumer_send(consumer_code);
host_system_send(system_code);
#endif
#ifdef DEBUG_LED
// LED flash for debug

View file

@ -121,12 +121,12 @@ void mousekey_clear_report(void)
static void mousekey_debug(void)
{
if (!debug_mouse) return;
print("mousekey[btn|x y v h]: ");
print("mousekey [btn|x y v h]rep: [");
phex(report.buttons); print("|");
phex(report.x); print(" ");
phex(report.y); print(" ");
phex(report.v); print(" ");
phex(report.h);
phex(report.h); print("]");
phex(mousekey_repeat);
print("\n");
}

View file

@ -82,15 +82,14 @@ typedef struct {
uint8_t mods;
uint8_t rserved;
uint8_t keys[REPORT_KEYS];
} report_keyboard_t;
} __attribute__ ((packed)) report_keyboard_t;
typedef struct {
uint8_t report_id;
uint8_t buttons;
int8_t x;
int8_t y;
int8_t v;
int8_t h;
} report_mouse_t;
} __attribute__ ((packed)) report_mouse_t;
#endif

View file

@ -8,8 +8,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
adb.c
@ -42,16 +41,11 @@ EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
#---------------- Programming Options --------------------------
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk
dfu: PROGRAM_CMD = dfu-programmer atmega32u4 flash $(TARGET).hex
dfu: program

View file

@ -8,8 +8,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
m0110.c
@ -47,6 +46,10 @@ EXTRAKEY_ENABLE = yes # Audio control and System control
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
news.c
@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
ps2.c
@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
ps2_usart.c
@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
ps2_usart.c
@ -85,6 +84,18 @@ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Boot Section Size in bytes
# Teensy halfKay 512
# Atmel DFU loader 4096
# LUFA bootloader 4096
# USBasp 2048
OPT_DEFS += -DBOOT_SIZE=2048
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/vusb.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap_102.c \
SRC = keymap_102.c \
matrix.c \
led.c \
ps2.c
@ -51,6 +50,10 @@ NKRO_ENABLE = yes # USB Nkey Rollover
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap_122.c \
SRC = keymap_122.c \
matrix.c \
led.c \
ps2.c
@ -51,6 +50,10 @@ F_CPU = 16000000
PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -13,8 +13,7 @@ TOP_DIR = ../..
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
SRC = keymap.c \
matrix.c \
led.c \
x68k.c
@ -80,6 +79,10 @@ AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
PROGRAM_CMD = dfu-programmer atmega32u4 flash $(TARGET).hex
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk

View file

@ -1,56 +0,0 @@
# Target file name (without extension).
TARGET = hbk
# Directory common source filess exist
TOP_DIR = ../..
# Directory keyboard dependent files exist
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
matrix.c \
led.c
CONFIG_H = config.h
# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
#MCU = at90usb162 # Teensy 1.0
MCU = atmega32u4 # Teensy 2.0
#MCU = at90usb646 # Teensy++ 1.0
#MCU = at90usb1286 # Teensy++ 2.0
# Processor frequency.
# Normally the first thing your program should do is set the clock prescaler,
# so your program will run at the correct speed. You should also set this
# variable to same clock speed. The _delay_ms() macro uses this, and many
# examples use this variable to calculate timings. Do not add a "UL" here.
F_CPU = 16000000
# Build Options
# comment out to disable the options.
#
MOUSEKEY_ENABLE = yes # Mouse keys
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
#---------------- Programming Options --------------------------
#PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
PROGRAM_CMD = /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) erase && \
/opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) flash $(TARGET).hex && \
/opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) start
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk

1
keyboard/hbkb/Makefile Symbolic link
View file

@ -0,0 +1 @@
Makefile.lufa

119
keyboard/hbkb/Makefile.lufa Normal file
View file

@ -0,0 +1,119 @@
#----------------------------------------------------------------------------
# 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 = hbkb_lufa
# Directory common source filess exist
TOP_DIR = ../..
# Directory keyboard dependent files exist
TARGET_DIR = .
# List C source files here. (C dependencies are automatically generated.)
SRC += keymap.c \
matrix.c \
led.c
CONFIG_H = config.h
# MCU name
#MCU = at90usb1287
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
#
# 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)
# Build Options
# comment out to disable the options.
#
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
# Boot Section Size in bytes
# Teensy halfKay 512
# Atmel DFU loader 4096
# LUFA bootloader 4096
OPT_DEFS += -DBOOT_SIZE=4096
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/lufa.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk

View file

@ -0,0 +1,56 @@
# Target file name (without extension).
TARGET = hbkb
# Directory common source filess exist
TOP_DIR = ../..
# Directory keyboard dependent files exist
TARGET_DIR = .
# keyboard dependent files
SRC = main.c \
keymap.c \
matrix.c \
led.c
CONFIG_H = config.h
# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
#MCU = at90usb162 # Teensy 1.0
MCU = atmega32u4 # Teensy 2.0
#MCU = at90usb646 # Teensy++ 1.0
#MCU = at90usb1286 # Teensy++ 2.0
# Processor frequency.
# Normally the first thing your program should do is set the clock prescaler,
# so your program will run at the correct speed. You should also set this
# variable to same clock speed. The _delay_ms() macro uses this, and many
# examples use this variable to calculate timings. Do not add a "UL" here.
F_CPU = 16000000
# Build Options
# comment out to disable the options.
#
MOUSEKEY_ENABLE = yes # Mouse keys
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
#---------------- Programming Options --------------------------
#PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
PROGRAM_CMD = /opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) erase && \
/opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) flash $(TARGET).hex && \
/opt/dfu-programmer-0.5.2/bin/dfu-programmer $(MCU) start
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/protocol.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk

View file

@ -24,7 +24,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0xBB00
#define MANUFACTURER t.m.k.
#define DEVICE_VER 0x0100
#define PRODUCT Happy Buckling Keyboard
#define DESCRIPTION mod version of IBM Model M keyboard

Some files were not shown because too many files have changed in this diff Show more