summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/bootloader.c97
-rw-r--r--common/command.c1
-rw-r--r--common/host.c5
-rw-r--r--common/keyboard.c17
-rw-r--r--common/mousekey.c4
-rw-r--r--common/report.h5
6 files changed, 95 insertions, 34 deletions
diff --git a/common/bootloader.c b/common/bootloader.c
index 5cbfc72e5b..612b949648 100644
--- a/common/bootloader.c
+++ b/common/bootloader.c
@@ -1,22 +1,87 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "bootloader.h"
-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.
+/* 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
+ */
-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.
+// 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
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+#define FLASH_SIZE (FLASHEND + 1)
+#define BOOTLOADER_START (FLASHEND - BOOT_SIZE)
-#include "bootloader.h"
+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
-void bootloader_jump(void) __attribute__ ((weak));
-void bootloader_jump(void) {}
+ // start Bootloader
+ ((void (*)(void))BOOTLOADER_START)();
+}
diff --git a/common/command.c b/common/command.c
index e325a5d847..13d37242d9 100644
--- a/common/command.c
+++ b/common/command.c
@@ -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");
diff --git a/common/host.c b/common/host.c
index cc26d55c22..8dd2abbee8 100644
--- a/common/host.c
+++ b/common/host.c
@@ -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;
diff --git a/common/keyboard.c b/common/keyboard.c
index 5c2643c951..25f32eb02f 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -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
diff --git a/common/mousekey.c b/common/mousekey.c
index 76bd0fd363..1d35355b49 100644
--- a/common/mousekey.c
+++ b/common/mousekey.c
@@ -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");
}
diff --git a/common/report.h b/common/report.h
index b85b86c5f8..45f5c0b881 100644
--- a/common/report.h
+++ b/common/report.h
@@ -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