(lots of work)

partial-rewrite
Ben Blazak 2013-03-26 23:16:24 -07:00
parent b37f69824c
commit 7eec5fb237
17 changed files with 550 additions and 115 deletions

View File

@ -115,6 +115,10 @@
Nice little web interface to a really helpful (when you're dealing with
confusing type signatures in C) command line program.
* [changing a 16-bit binary number into two 8-bit binary numbers]
(http://arduino.cc/forum/index.php/topic,44830.0.html)
(on <http://arduino.cc/>)
### C++ Stuff
* [Google C++ Style Guide]

View File

@ -8,7 +8,6 @@
* Implements the "controller" section of '.../firmware/keyboard.h'
*/
#include <stdbool.h>
#include <stdint.h>
#include "../../../firmware/keyboard.h"
@ -17,11 +16,6 @@
// ----------------------------------------------------------------------------
/** functions/kb__init/description
* Returns:
* - success: `0`
* - failure: the number of the function that failed
*/
uint8_t kb__init(void) {
if (teensy__init()) // must be first (to initialize twi, and such)
return 1;
@ -31,11 +25,6 @@ uint8_t kb__init(void) {
return 0; // success
}
/** functions/kb__update_matrix/description
* Returns:
* - success: `0`
* - failure: number of the function that failed
*/
uint8_t kb__update_matrix(bool matrix[KB__ROWS][KB__COLUMNS]) {
if (teensy__update_matrix(matrix))
return 1;

View File

@ -98,6 +98,7 @@ Sh2KCapL, Z, X, C, V, B, L0pu1po,
Bs, Del, End,
// right hand ..... ......... ......... ......... ......... ......... .........
NumPush, K6, K7, K8, K9, K0, Dash,
// capslock)
BrktL, Y, U, I, O, P, BrktR,
H, J, K, L, Semicol, Quote,
L0pu1po, N, M, Comma, Period, Slash, Sh2KCapR,

View File

@ -10,7 +10,6 @@
* Code is specific to Teensy 2.0
*/
#include <stdint.h>
#include <avr/io.h>

View File

@ -11,7 +11,10 @@
#
# TODO: include the other 'options.mk' files that we need to
include ../../../firmware/lib/twi/options.mk
include ../../../firmware/lib/usb/options.mk
include ../../../firmware/lib/layout/key-functions/options.mk
# TODO: add other 'options.mk' files as they appear
BINARY_FORMAT := ihex

View File

@ -27,7 +27,6 @@ typedef void (*kf__function_pointer_t)(uint16_t value);
// basic
void kf__press (uint16_t keycode);
void kf__release (uint16_t keycode);
void kf__send (uint16_t ignore);
void kf__toggle (uint16_t keycode);
void kf__layer__push (uint16_t id__layer);
void kf__layer__pop (uint16_t id__ignore);
@ -35,11 +34,29 @@ void kf__macro__sram (uint16_t pointer);
void kf__macro__progmem (uint16_t pointer);
void kf__macro__eeprom (uint16_t pointer);
// TODO: chording
//
// - consider making a 'kf__chord(uint16_t pointer)' that takes a pointer to an
// array containing whatever's needed to specify [ which group of keys it
// belongs to; whether to increment or decrement the counter for that group;
// the threshold for action for that group; the action (possibly a
// layer/row/col tuple for a key to call exec on, or possible just a row/col,
// and a layer shift some other way, ...) ]
//
// - create a auto-resizing array ('flex_array'?) for use with this function,
// and probably with the the layer stack functions as well. IDs can be
// treated as array indices (the burden being on the user not to use indices
// that are too large...)
//
// TODO: rewrite layouts to reflect
// - kf__two_keys_capslock() -> kf__toggle_capslock()
// - the removal of kf__send()
// device
void kf__jump_to_bootloader (uint16_t ignore);
// special
void kf__two_keys_capslock (uint16_t pressed);
void kf__toggle_capslock (uint16_t ignore);
// ----------------------------------------------------------------------------
@ -78,7 +95,7 @@ void kf__two_keys_capslock (uint16_t pressed);
// === kf__press() ===
/** functions/kf__press/description
* Generate a normal keypress.
* Generate a normal keypress (and send the USB report).
*
* Arguments:
* - `keycode`: The keycode to "press"
@ -86,21 +103,12 @@ void kf__two_keys_capslock (uint16_t pressed);
// === kf__release() ===
/** functions/kf__release/description
* Generate a normal keyrelease.
* Generate a normal keyrelease (and send the USB report).
*
* Arguments:
* - `keycode`: The keycode to "release"
*/
// === kf__send() ===
/** functions/kf__send/description
* Send the USB report (immediately, instead of waiting for the scan cycle to
* end).
*
* Arguments:
* - `ignore`: [ignore]
*/
// === kf__toggle() ===
/** functions/kf__toggle/description
* Toggle the key pressed or unpressed.
@ -201,26 +209,17 @@ void kf__two_keys_capslock (uint16_t pressed);
// ----------------------------------------------------------------------------
// special --------------------------------------------------------------------
// === kf__two_keys_capslock() ===
/** functions/kf__two_keys_capslock/description
* For implementing the behavior wherein pressing both shift keys at the same
* time toggles capslock.
*
* If the count of pressed keys with this function assigned is greater than or
* equal to 1, any subsequent "presses" of this function will toggle capslock.
// === kf__toggle_capslock() ===
/** functions/kf__toggle_capslock/description
* Toggle the state of 'capslock'
*
* Arguments:
* - `pressed`:
* - `true`: Add `1` to the count of pressed keys with this function
* assigned.
* - `false`: Subtract `1` from the count of pressed keys with this
* function assigned.
* - `ignore`: [ignore]
*
* Notes:
* - If either or both of the two shifts is active when capslock is toggled
* (which should usually be the case), they will be released so that capslock
* will register properly when toggled (that is, when we automatically press
* then release it). After this, the original state of the shifts will be
* restored.
* - This requires special handling because neither of the shift keys may be
* active when 'capslock' is pressed, or it will not register properly. This
* function disables both shift keys, toggles 'capslock', and then restores
* the state of both shift keys before exiting.
*/

View File

@ -0,0 +1,53 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "basic" section of
* ".../firmware/lib/layout/key-functions.h"
*/
#include <stdint.h>
#include <avr/pgmspace.h>
#include "../../../../firmware/lib/usb.h"
#include "../../../../firmware/lib/layout/layer-stack.h"
// ----------------------------------------------------------------------------
void kf__press(uint16_t keycode) {
usb__kb__set_key(true, keycode);
usb__kb__send_report();
}
void kf__release(uint16_t keycode) {
usb__kb__set_key(false, keycode);
usb__kb__send_report();
}
void kf__toggle(uint16_t keycode) {
if (usb__kb__read_key(keycode))
usb__kb__set_key(false, keycode);
else
usb__kb__set_key(true, keycode):
}
void kf__layer__push(uint16_t id__layer) {
layer_stack__push( ((uint8_t)(id__layer >> 8)),
((uint8_t)(id__layer & 0xff)) );
}
void kf__layer__pop(uint16_t id__ignore) {
layer_stack__pop_id( ((uint8_t)(id__ignore >> 8)) );
}
void kf__macro__sram(uint16_t pointer) { // TODO
}
void kf__macro__progmem(uint16_t pointer) { // TODO
}
void kf__macro__eeprom(uint16_t pointer) { // TODO
}

View File

@ -0,0 +1,41 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "device" section of
* ".../firmware/lib/layout/key-functions.h"
*/
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdint.h>
// ----------------------------------------------------------------------------
// from PJRC (slightly modified)
// <http://www.pjrc.com/teensy/jump_to_bootloader.html>
void kf__jump_to_bootloader (uint16_t ignore) {
// --- for all Teensy boards ---
cli();
// disable watchdog, if enabled
// disable all peripherals
UDCON = 1;
USBCON = (1<<FRZCLK); // disable USB
UCSR1B = 0;
_delay_ms(5);
// --- Teensy 2.0 specific ---
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;
asm volatile("jmp 0x7E00");
}

View File

@ -5,11 +5,11 @@
# -----------------------------------------------------------------------------
## description
# USB keyboard options
# key-functions options
#
# This file is meant to be included by the using '.../options.mk'
#
SRC += $(wildcard from-pjrc/*.c)
SRC += $(wildcard *.c)

View File

@ -0,0 +1,40 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "special" section of
* ".../firmware/lib/layout/key-functions.h"
*/
#include <stdbool.h>
#include <stdint.h>
#include "../../../../firmware/lib/usb.h"
#include "../../../../firmware/lib/usb/usage-page/keyboard.h"
// ----------------------------------------------------------------------------
void kf__toggle_capslock (uint16_t ignore) {
// save the state of left and right shift
bool lshift_pressed = usb__kb__read_key(KEY__LeftShift);
bool rshift_pressed = usb__kb__read_key(KEY__RightShift);
// disable both shifts
usb__kb__set_key(false, KEY__LeftShift);
usb__kb__set_key(false, KEY_RightShift);
// toggle capslock
usb__kb__set_key(true, KEY_CapsLock);
usb_keyboard_send();
usb__kb__set_key(false, KEY_CapsLock);
usb_keyboard_send();
// restore the state of both shifts
if (lshift_pressed) usb__kb__set_key(true, KEY_LeftShift);
if (rshift_pressed) usb__kb__set_key(true, KEY_RightShift);
}

146
firmware/lib/usb.h Normal file
View File

@ -0,0 +1,146 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* The USB interface
*
* Prefixes: `usb__` `usb__kb__`
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <stdbool.h>
#include <stdint.h>
// ----------------------------------------------------------------------------
// --- general ---
void usb__init (void);
bool usb__is_configured (void);
// --- keyboard ---
uint8_t usb__kb__set_key (bool pressed, uint8_t keycode);
bool usb__kb__read_key (uint8_t keycode);
bool usb__kb__read_led (char led);
uint8_t usb__kb__send_report (void);
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__H
// ============================================================================
// === documentation ==========================================================
// ============================================================================
// ----------------------------------------------------------------------------
// general --------------------------------------------------------------------
// === usb__init() ===
/** functions/usb__init/description
* Initialize USB for this device
*
* Notes:
* - Should be called exactly once by `main()`, and nothing else USB related
* should be done until `usb__configured` is `true`
*/
// === usb__is_configured ===
/** variables/usb__is_configured/description
* Check whether this device has been configured by the host
*
* Returns:
* - `true`: if the device has been configured
* - `false`: if the device has not been configured
*
* Notes:
* - Should return `true` before calling any function other than `usb__init()`
*/
// ----------------------------------------------------------------------------
// keyboard -------------------------------------------------------------------
// === usb__kb__set_key() ===
/** functions/usb__kb__set_key/description
* Set the given keycode as 'pressed' ('on') or 'released' ('off') (device
* side)
*
* Arguments:
* - `pressed`: whether to set the keycode 'on' (`true`) or 'off' (`false`)
* - `keycode`: the keycode to set
*
* Returns:
* - success: `0`
* - failure: status code (unspecified, nonzero)
*
* Notes:
* - Setting a keycode 'on' or 'off' does not send the report, and the host
* will not know the state of the keycode until the report is sent. If a key
* is set 'on' then 'off' without sending the report in between, the host
* will know nothing about it.
*/
// === usb__kb__read_key() ===
/** functions/usb__kb__read_key/description
* Check whether the given keycode is set to 'on' (device side)
*
* Arguments:
* - `keycode`: the keycode to check
*
* Returns:
* - `false`: if the state of the given keycode is set to 'off'
* - `true`: if the state of the given keycode is set to 'on'
*
* Notes:
* - The fact that a given keycode is set to some value here does not mean that
* the host knows about it. The host will only know the current state of the
* keycodes if the report has been sent since the last change.
*/
// === usb__kb__read_led() ===
/** functions/usb__kb__read_led/description
* Check whether the given (logical) LED is set to 'on' (host side)
*
* Arguments:
* - `led`:
* - `N`: numlock
* - `C`: capslock
* - `S`: scroll lock
* - `O`: compose
* - `K`: kana
*
* Returns:
* - `false`: if the state of the given (logical) LED is set to 'off'
* - `true`: if the state of the given (logical) LED is set to 'on'
*
* Notes:
* - No data is actually exchanged with the host by this function, but
* maintaining the state of these (logical) LEDs (and informing the device
* when they change) is the host's responsibility. The device only keeps
* track of what the host tells it.
*/
// === usb__kb__send_report() ===
/** functions/usb__kb__send_report/description
* Send the USB report to the host (update the host on the state of the
* keycodes)
*
* Returns:
* - success: `0`
* - failure: status code (unspecified, nonzero)
*/

View File

@ -0,0 +1,20 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "general" section of '.../firmware/lib/usb.h'
*
* This is currently a wrapper for the PJRC code
*/
#include "./keyboard/from-pjrc/usb_keyboard.h"
// ----------------------------------------------------------------------------
void usb__init(void) { usb_init(); }
bool usb__is_configured(void) { usb_configured(); }

123
firmware/lib/usb/keyboard.c Normal file
View File

@ -0,0 +1,123 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "keyboard" section of '.../firmware/lib/usb.h'
*/
#include <stdbool.h>
#include <stdint.h>
#include "./usage-page/keyboard.h"
#include "./keyboard/from-pjrc/usb_keyboard.h"
// ----------------------------------------------------------------------------
uint8_t usb__kb__set_key(bool pressed, uint8_t keycode) {
// no-op
if (keycode == 0)
return 1;
// modifier keys
switch (keycode) {
case KEY__LeftControl: (pressed)
? (keyboard_modifier_keys |= (1<<0))
: (keyboard_modifier_keys &= ~(1<<0));
return 0;
case KEY__LeftShift: (pressed)
? (keyboard_modifier_keys |= (1<<1))
: (keyboard_modifier_keys &= ~(1<<1));
return 0;
case KEY__LeftAlt: (pressed)
? (keyboard_modifier_keys |= (1<<2))
: (keyboard_modifier_keys &= ~(1<<2));
return 0;
case KEY__LeftGUI: (pressed)
? (keyboard_modifier_keys |= (1<<3))
: (keyboard_modifier_keys &= ~(1<<3));
return 0;
case KEY__RightControl: (pressed)
? (keyboard_modifier_keys |= (1<<4))
: (keyboard_modifier_keys &= ~(1<<4));
return 0;
case KEY__RightShift: (pressed)
? (keyboard_modifier_keys |= (1<<5))
: (keyboard_modifier_keys &= ~(1<<5));
return 0;
case KEY__RightAlt: (pressed)
? (keyboard_modifier_keys |= (1<<6))
: (keyboard_modifier_keys &= ~(1<<6));
return 0;
case KEY__RightGUI: (pressed)
? (keyboard_modifier_keys |= (1<<7))
: (keyboard_modifier_keys &= ~(1<<7));
return 0;
}
// all others
for (uint8_t i=0; i<6; i++) {
if (pressed) {
if (keyboard_keys[i] == 0) {
keyboard_keys[i] = keycode;
return 0;
}
} else {
if (keyboard_keys[i] == keycode) {
keyboard_keys[i] = 0;
return 0;
}
}
}
return 1;
}
bool usb__kb__read_key(uint8_t keycode) {
// no-op
if (keycode == 0)
return false;
// modifier keys
switch (keycode) {
case KEY__LeftControl: if (keyboard_modifier_keys & (1<<0))
return true;
case KEY__LeftShift: if (keyboard_modifier_keys & (1<<1))
return true;
case KEY__LeftAlt: if (keyboard_modifier_keys & (1<<2))
return true;
case KEY__LeftGUI: if (keyboard_modifier_keys & (1<<3))
return true;
case KEY__RightControl: if (keyboard_modifier_keys & (1<<4))
return true;
case KEY__RightShift: if (keyboard_modifier_keys & (1<<5))
return true;
case KEY__RightAlt: if (keyboard_modifier_keys & (1<<6))
return true;
case KEY__RightGUI: if (keyboard_modifier_keys & (1<<7))
return true;
}
// all others
for (uint8_t i=0; i<6; i++)
if (keyboard_keys[i] == keycode)
return true;
return false;
}
bool usb__kb__read_led(char led) {
switch(led) {
case 'N': return keyboard_leds & (1<<0); // numlock
case 'C': return keyboard_leds & (1<<1); // capslock
case 'S': return keyboard_leds & (1<<2); // scroll lock
case 'O': return keyboard_leds & (1<<3); // compose
case 'K': return keyboard_leds & (1<<4); // kana
};
}
uint8_t usb__kb__send_report(void) {
return (uint8_t) usb_keyboard_send();
}

View File

@ -0,0 +1,14 @@
The PJRC USB keyboard implementation
Originally from [PJRC] (http://pjrc.com/teensy/) : [usb_keyboard]
(http://pjrc.com/teensy/usb_keyboard.zip)
Modifications are noted in the files.
-------------------------------------------------------------------------------
Copyright &copy; 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
Released under The MIT License (see "doc/licenses/MIT.md")
Project located at <https://github.com/benblazak/ergodox-firmware>

View File

@ -1,5 +1,4 @@
/* ----------------------------------------------------------------------------
* USB Keyboard Example for Teensy USB Development Board
/* USB Keyboard Example for Teensy USB Development Board
* http://www.pjrc.com/teensy/usb_keyboard.html
* Copyright (c) 2009 PJRC.COM, LLC
*
@ -20,19 +19,22 @@
* 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.
* ------------------------------------------------------------------------- */
*/
// Version 1.0: Initial Release
// Version 1.1: Add support for Teensy 2.0
/** description
* Implements the USB interface
* The PJRC USB keyboard implementation
*
* History:
* - Originally from [PJRC] (http://pjrc.com/teensy/) : [usb_keyboard]
* (http://pjrc.com/teensy/usb_keyboard.zip)
* - Modified 2012, Ben Blazak
* - Modified 2013, Ben Blazak
*
* Notes:
* - 'description' added
* - `usb_keyboard_press()` removed
* - `OPT__` macros added (and other code modified accordingly)
*/
@ -128,7 +130,7 @@ static const uint8_t PROGMEM endpoint_config_table[] = {
// spec and relevant portions of any USB class specifications!
static const uint8_t PROGMEM device_descriptor[] = {
static uint8_t PROGMEM device_descriptor[] = {
18, // bLength
1, // bDescriptorType
0x00, 0x02, // bcdUSB
@ -146,7 +148,7 @@ static const uint8_t PROGMEM device_descriptor[] = {
};
// Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
static uint8_t PROGMEM keyboard_hid_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
@ -183,7 +185,7 @@ static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
#define CONFIG1_DESC_SIZE (9+9+9+7)
#define KEYBOARD_HID_DESC_OFFSET (9+9)
static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
// configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
9, // bLength;
2, // bDescriptorType;
@ -230,17 +232,17 @@ struct usb_string_descriptor_struct {
uint8_t bDescriptorType;
int16_t wString[];
};
static const struct usb_string_descriptor_struct PROGMEM string0 = {
static struct usb_string_descriptor_struct PROGMEM string0 = {
4,
3,
{0x0409}
};
static const struct usb_string_descriptor_struct PROGMEM string1 = {
static struct usb_string_descriptor_struct PROGMEM string1 = {
sizeof(STR_MANUFACTURER),
3,
STR_MANUFACTURER
};
static const struct usb_string_descriptor_struct PROGMEM string2 = {
static struct usb_string_descriptor_struct PROGMEM string2 = {
sizeof(STR_PRODUCT),
3,
STR_PRODUCT
@ -253,7 +255,7 @@ static struct descriptor_list_struct {
uint16_t wIndex;
const uint8_t *addr;
uint8_t length;
} const PROGMEM descriptor_list[] = {
} PROGMEM descriptor_list[] = {
{0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
{0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)},
{0x2200, KEYBOARD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
@ -277,10 +279,10 @@ static volatile uint8_t usb_configuration=0;
// which modifier keys are currently pressed
// 1=left ctrl, 2=left shift, 4=left alt, 8=left gui
// 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
uint8_t usb__kb__modifier_keys=0;
uint8_t keyboard_modifier_keys=0;
// which keys are currently pressed, up to 6 keys may be down at once
uint8_t usb__kb__keys[6]={0,0,0,0,0,0};
uint8_t keyboard_keys[6]={0,0,0,0,0,0};
// protocol setting from the host. We use exactly the same report
// either way, so this variable only stores the setting since we
@ -295,7 +297,7 @@ static uint8_t keyboard_idle_config=125;
static uint8_t keyboard_idle_count=0;
// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
volatile uint8_t usb__kb__leds=0;
volatile uint8_t keyboard_leds=0;
/**************************************************************************
@ -306,7 +308,7 @@ volatile uint8_t usb__kb__leds=0;
// initialize USB
void usb__init(void)
void usb_init(void)
{
HW_CONFIG();
USB_FREEZE(); // enable USB
@ -321,14 +323,13 @@ void usb__init(void)
// return 0 if the USB is not configured, or the configuration
// number selected by the HOST
uint8_t usb__is_configured(void)
uint8_t usb_configured(void)
{
return usb_configuration;
}
// send the contents of usb__kb__keys and usb__kb__modifier_keys
int8_t usb__kb__send(void)
// send the contents of keyboard_keys and keyboard_modifier_keys
int8_t usb_keyboard_send(void)
{
uint8_t i, intr_state, timeout;
@ -350,10 +351,10 @@ int8_t usb__kb__send(void)
cli();
UENUM = KEYBOARD_ENDPOINT;
}
UEDATX = usb__kb__modifier_keys;
UEDATX = keyboard_modifier_keys;
UEDATX = 0;
for (i=0; i<6; i++) {
UEDATX = usb__kb__keys[i];
UEDATX = keyboard_keys[i];
}
UEINTX = 0x3A;
keyboard_idle_count = 0;
@ -374,8 +375,7 @@ int8_t usb__kb__send(void)
//
ISR(USB_GEN_vect)
{
uint8_t intbits, i; // used to declare a variable `t` as well, but it
// wasn't used ::Ben Blazak, 2012::
uint8_t intbits, t, i;
static uint8_t div4=0;
intbits = UDINT;
@ -395,10 +395,10 @@ ISR(USB_GEN_vect)
keyboard_idle_count++;
if (keyboard_idle_count == keyboard_idle_config) {
keyboard_idle_count = 0;
UEDATX = usb__kb__modifier_keys;
UEDATX = keyboard_modifier_keys;
UEDATX = 0;
for (i=0; i<6; i++) {
UEDATX = usb__kb__keys[i];
UEDATX = keyboard_keys[i];
}
UEINTX = 0x3A;
}
@ -569,10 +569,10 @@ ISR(USB_COM_vect)
if (bmRequestType == 0xA1) {
if (bRequest == HID_GET_REPORT) {
usb_wait_in_ready();
UEDATX = usb__kb__modifier_keys;
UEDATX = keyboard_modifier_keys;
UEDATX = 0;
for (i=0; i<6; i++) {
UEDATX = usb__kb__keys[i];
UEDATX = keyboard_keys[i];
}
usb_send_in();
return;
@ -593,7 +593,7 @@ ISR(USB_COM_vect)
if (bmRequestType == 0x21) {
if (bRequest == HID_SET_REPORT) {
usb_wait_receive_out();
usb__kb__leds = UEDATX;
keyboard_leds = UEDATX;
usb_ack_out();
usb_send_in();
return;

View File

@ -1,46 +1,40 @@
/* ----------------------------------------------------------------------------
* (See '.c' file for copyright and such)
* ------------------------------------------------------------------------- */
/** description
* The PJRC USB interface
* The PJRC USB keyboard interface
*
* Prefix: `usb__`
* See the '.c' file for copyright and such
*
* File History:
* - Originally from [PJRC] (http://pjrc.com/teensy/) : [usb_keyboard]
* (http://pjrc.com/teensy/usb_keyboard.zip)
* - Modified 2012, Ben Blazak. I'd like to rewrite it someday (partly to add
* a few extra features (like mouse keys), mostly to learn how); but alas,
* someday has not yet come.
* Modified 2013, Ben Blazak
*
* Should be included only by those files that wrap parts of it to conform with
* '.../firmware/lib/usb.h'
*
* Notes:
* - 'description' added
* - `usb_keyboard_press()` removed
* - the empty macros for `usb_debug_putchar()` and `usb_debug_flush_output()`
* removed
* - keycode macros removed
*/
// ----------------------------------------------------------------------------
#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__FROM_PJRC__USB_KEYBOARD__USB_KEYBOARD__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__FROM_PJRC__USB_KEYBOARD__USB_KEYBOARD__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifndef usb_serial_h__
#define usb_serial_h__
#include <stdint.h>
// ----------------------------------------------------------------------------
void usb__init (void); // initialize everything
uint8_t usb__is_configured (void); // is the USB port configured?
int8_t usb__kb__send (void);
extern uint8_t usb__kb__modifier_keys;
extern uint8_t usb__kb__keys[6];
extern volatile uint8_t usb__kb__leds;
void usb_init(void); // initialize everything
uint8_t usb_configured(void); // is the USB port configured
int8_t usb_keyboard_send(void);
extern uint8_t keyboard_modifier_keys;
extern uint8_t keyboard_keys[6];
extern volatile uint8_t keyboard_leds;
// ----------------------------------------------------------------------------
// Everything below this point is only intended for usb_serial.c --------------
// ----------------------------------------------------------------------------
// Everything below this point is only intended for usb_serial.c
#ifdef USB_SERIAL_PRIVATE_INCLUDE
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
@ -86,7 +80,7 @@ extern volatile uint8_t usb__kb__leds;
#define PLL_CONFIG() (PLLCSR = 0x16)
#define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
#endif // defined(__AVR_AT90USB162__)
#endif
// standard control endpoint request types
#define GET_STATUS 0
@ -109,12 +103,5 @@ extern volatile uint8_t usb__kb__leds;
#define CDC_SET_LINE_CODING 0x20
#define CDC_GET_LINE_CODING 0x21
#define CDC_SET_CONTROL_LINE_STATE 0x22
#endif // USB_SERIAL_PRIVATE_INCLUDE
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__FROM_PJRC__USB_KEYBOARD__USB_KEYBOARD__H
#endif
#endif

View File

@ -0,0 +1,16 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (see "doc/licenses/MIT.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
## description
# USB keyboard options
#
# This file is meant to be included by the using '.../options.mk'
#
SRC += $(wildcard *.c)
SRC += $(wildcard keyboard/from-pjrc/*.c)