aboutsummaryrefslogtreecommitdiffstats
path: root/pjrc
diff options
context:
space:
mode:
Diffstat (limited to 'pjrc')
-rw-r--r--pjrc/host.c10
-rw-r--r--pjrc/main.c97
-rw-r--r--pjrc/pjrc.c76
-rw-r--r--pjrc/pjrc.h26
-rw-r--r--pjrc/usb.c34
-rw-r--r--pjrc/usb.h2
-rw-r--r--pjrc/usb_keyboard.c4
7 files changed, 224 insertions, 25 deletions
diff --git a/pjrc/host.c b/pjrc/host.c
index 35d59de80..fcf71d579 100644
--- a/pjrc/host.c
+++ b/pjrc/host.c
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
#include "usb_mouse.h"
#endif
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
#include "usb_extra.h"
#endif
#include "debug.h"
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
bool keyboard_nkro = false;
#endif
@@ -51,7 +51,7 @@ uint8_t host_keyboard_leds(void)
/* keyboard report operations */
void host_add_key(uint8_t key)
{
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
if (keyboard_nkro) {
add_key_bit(key);
return;
@@ -109,7 +109,7 @@ uint8_t host_has_anykey(void)
uint8_t host_get_first_key(void)
{
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
if (keyboard_nkro) {
uint8_t i = 0;
for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++)
@@ -133,7 +133,7 @@ void host_mouse_send(report_mouse_t *report)
}
#endif
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
void host_system_send(uint16_t data)
{
usb_extra_system_send(data);
diff --git a/pjrc/main.c b/pjrc/main.c
new file mode 100644
index 000000000..f84925d7f
--- /dev/null
+++ b/pjrc/main.c
@@ -0,0 +1,97 @@
+/* Keyboard example with debug channel, for Teensy USB Development Board
+ * http://www.pjrc.com/teensy/usb_keyboard.html
+ * Copyright (c) 2008 PJRC.COM, LLC
+ *
+ * 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.
+ */
+
+#include <stdbool.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "keyboard.h"
+#include "usb.h"
+#include "matrix.h"
+#include "print.h"
+#include "debug.h"
+#include "util.h"
+#include "jump_bootloader.h"
+#ifdef PS2_MOUSE_ENABLE
+# include "ps2_mouse.h"
+#endif
+#include "host.h"
+#include "pjrc.h"
+
+
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+
+
+bool debug_enable = false;
+bool debug_matrix = false;
+bool debug_keyboard = false;
+bool debug_mouse = false;
+
+
+int main(void)
+{
+ DEBUG_LED_CONFIG;
+ DEBUG_LED_OFF;
+
+ // set for 16 MHz clock
+ CPU_PRESCALE(0);
+
+ // Initialize the USB, and then wait for the host to set configuration.
+ // If the Teensy is powered without a PC connected to the USB port,
+ // this will wait forever.
+ usb_init();
+ while (!usb_configured()) /* wait */ ;
+
+ keyboard_init();
+ matrix_scan();
+ if (matrix_key_count() >= 3) {
+#ifdef DEBUG_LED
+ for (int i = 0; i < 6; i++) {
+ DEBUG_LED_CONFIG;
+ DEBUG_LED_ON;
+ _delay_ms(500);
+ DEBUG_LED_OFF;
+ _delay_ms(500);
+ }
+#else
+ _delay_ms(5000);
+#endif
+ print_enable = true;
+ debug_enable = true;
+ debug_matrix = true;
+ debug_keyboard = true;
+ debug_mouse = true;
+ print("debug enabled.\n");
+ }
+ if (matrix_key_count() >= 4) {
+ print("jump to bootloader...\n");
+ _delay_ms(1000);
+ jump_bootloader(); // not return
+ }
+
+
+ host_set_driver(pjrc_driver());
+ while (1) {
+ keyboard_proc();
+ }
+}
diff --git a/pjrc/pjrc.c b/pjrc/pjrc.c
new file mode 100644
index 000000000..0562a12ff
--- /dev/null
+++ b/pjrc/pjrc.c
@@ -0,0 +1,76 @@
+/*
+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 <stdint.h>
+#include "usb_keyboard.h"
+#include "usb_mouse.h"
+#include "usb_extra.h"
+#include "host_driver.h"
+#include "pjrc.h"
+
+
+/*------------------------------------------------------------------*
+ * Host driver
+ *------------------------------------------------------------------*/
+static uint8_t keyboard_leds(void);
+static void send_keyboard(report_keyboard_t *report);
+static void send_mouse(report_mouse_t *report);
+static void send_system(uint16_t data);
+static void send_consumer(uint16_t data);
+
+static host_driver_t driver = {
+ keyboard_leds,
+ send_keyboard,
+ send_mouse,
+ send_system,
+ send_consumer
+};
+
+host_driver_t *pjrc_driver(void)
+{
+ return &driver;
+}
+
+static uint8_t keyboard_leds(void) {
+ return usb_keyboard_leds;
+}
+
+static void send_keyboard(report_keyboard_t *report)
+{
+ usb_keyboard_send_report(report);
+}
+
+static void send_mouse(report_mouse_t *report)
+{
+#ifdef MOUSE_ENABLE
+ usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
+#endif
+}
+
+static void send_system(uint16_t data)
+{
+#ifdef EXTRAKEY_ENABLE
+ usb_extra_system_send(data);
+#endif
+}
+
+static void send_consumer(uint16_t data)
+{
+#ifdef EXTRAKEY_ENABLE
+ usb_extra_consumer_send(data);
+#endif
+}
diff --git a/pjrc/pjrc.h b/pjrc/pjrc.h
new file mode 100644
index 000000000..06e79626f
--- /dev/null
+++ b/pjrc/pjrc.h
@@ -0,0 +1,26 @@
+/*
+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/>.
+*/
+
+#ifndef PJRC_H
+#define PJRC_H
+
+#include "host_driver.h"
+
+
+host_driver_t *pjrc_driver(void);
+
+#endif
diff --git a/pjrc/usb.c b/pjrc/usb.c
index ea2e71b3d..9989a4b2d 100644
--- a/pjrc/usb.c
+++ b/pjrc/usb.c
@@ -91,18 +91,18 @@ bool suspend = false;
static const uint8_t PROGMEM endpoint_config_table[] = {
// enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD_SIZE) | KBD_BUFFER, // 1
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2
#else
0, // 2
#endif
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4
#else
0, // 4
#endif
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5
#else
0, // 5
@@ -176,7 +176,7 @@ static uint8_t PROGMEM keyboard_hid_report_desc[] = {
0x81, 0x00, // Input (Data, Array),
0xc0 // End Collection
};
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
static uint8_t PROGMEM keyboard2_hid_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
@@ -213,7 +213,7 @@ static uint8_t PROGMEM keyboard2_hid_report_desc[] = {
};
#endif
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
// Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
// http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
// http://www.keil.com/forum/15671/
@@ -282,7 +282,7 @@ static uint8_t PROGMEM debug_hid_report_desc[] = {
0xC0 // end collection
};
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
// audio controls & system controls
// http://www.microsoft.com/whdc/archive/w2kbd.mspx
static uint8_t PROGMEM extra_hid_report_desc[] = {
@@ -318,7 +318,7 @@ static uint8_t PROGMEM extra_hid_report_desc[] = {
#define KBD_HID_DESC_NUM 0
#define KBD_HID_DESC_OFFSET (9+(9+9+7)*KBD_HID_DESC_NUM+9)
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1)
# define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*MOUSE_HID_DESC_NUM+9)
#else
@@ -328,14 +328,14 @@ static uint8_t PROGMEM extra_hid_report_desc[] = {
#define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1)
#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*DEBUG_HID_DESC_NUM+9)
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 1)
# define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
#else
# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 0)
#endif
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
# define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
# define KBD2_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
#else
@@ -383,7 +383,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
KBD_SIZE, 0, // wMaxPacketSize
10, // bInterval
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
@@ -444,7 +444,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
DEBUG_TX_SIZE, 0, // wMaxPacketSize
1, // bInterval
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
@@ -473,7 +473,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
10, // bInterval
#endif
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
@@ -542,17 +542,17 @@ static struct descriptor_list_struct {
// HID/REPORT descriptors
{0x2100, KBD_INTERFACE, config1_descriptor+KBD_HID_DESC_OFFSET, 9},
{0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
{0x2100, MOUSE_INTERFACE, config1_descriptor+MOUSE_HID_DESC_OFFSET, 9},
{0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
#endif
{0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
{0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
-#ifdef USB_EXTRA_ENABLE
+#ifdef EXTRAKEY_ENABLE
{0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9},
{0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
#endif
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
{0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9},
{0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)},
#endif
@@ -653,7 +653,7 @@ ISR(USB_GEN_vect)
}
}
/* TODO: should keep IDLE rate on each keyboard interface */
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) {
#else
if (usb_keyboard_idle_config && (++div4 & 3) == 0) {
@@ -894,7 +894,7 @@ ISR(USB_COM_vect)
}
}
}
-#ifdef USB_MOUSE_ENABLE
+#ifdef MOUSE_ENABLE
if (wIndex == MOUSE_INTERFACE) {
if (bmRequestType == 0xA1) {
if (bRequest == HID_GET_REPORT) {
diff --git a/pjrc/usb.h b/pjrc/usb.h
index a4e40bdd1..82e18f176 100644
--- a/pjrc/usb.h
+++ b/pjrc/usb.h
@@ -120,7 +120,7 @@ void usb_remote_wakeup(void);
#define KBD_REPORT_KEYS (KBD_SIZE - 2)
// secondary keyboard
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
#define KBD2_INTERFACE 4
#define KBD2_ENDPOINT 5
#define KBD2_SIZE 16
diff --git a/pjrc/usb_keyboard.c b/pjrc/usb_keyboard.c
index 34e9d495b..e057c77fa 100644
--- a/pjrc/usb_keyboard.c
+++ b/pjrc/usb_keyboard.c
@@ -55,7 +55,7 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report)
{
int8_t result = 0;
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
if (keyboard_nkro)
result = send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS);
else
@@ -105,7 +105,7 @@ static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, ui
UENUM = endpoint;
}
UEDATX = report->mods;
-#ifdef USB_NKRO_ENABLE
+#ifdef NKRO_ENABLE
if (!keyboard_nkro)
UEDATX = 0;
#else