clean up header structure

master
Stefan Dorn 2016-06-11 21:19:48 +01:00
parent 46b1493a07
commit 0c141072da
31 changed files with 207 additions and 1485 deletions

View File

@ -5,8 +5,8 @@
# require "muflax"
LayoutDir = "src/keyboard/layout"
LayoutFile = "#{LayoutDir}/saneo-mod.c"
LayoutDir = "src/keyboard"
LayoutFile = "#{LayoutDir}/layout.c"
puts "generating #{LayoutFile}..."
@ -222,14 +222,7 @@ class Layout
// ----------------------------------------------------------------------------
// ergoDOX layout : saneo (generated)
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include "../../lib/data-types/misc.h"
#include "../../lib/usb/usage-page/keyboard.h"
#include "../../lib/key-functions/public.h"
#include "../matrix.h"
#include "../layout.h"
#include "./layout.h"
// ----------------------------------------------------------------------------
HEADER

View File

@ -6,12 +6,7 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include "./matrix.h"
#include "./controller/mcp23018--functions.h"
#include "./controller/teensy-2-0--functions.h"
#include "./controller.h"
// ----------------------------------------------------------------------------
@ -40,4 +35,3 @@ uint8_t kb_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]) {
return 0; // success
}

View File

@ -6,17 +6,15 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#ifndef KEYBOARD__ERGODOX__CONTROLLER_h
#define KEYBOARD__ERGODOX__CONTROLLER_h
#include <stdbool.h>
#include <stdint.h>
#include "./matrix.h"
#include "./controller/mcp23018.h"
#include "./controller/teensy-2-0.h"
#include <stdbool.h>
#include <stdint.h>
#include "./matrix.h"
// --------------------------------------------------------------------
// --------------------------------------------------------------------
uint8_t kb_init(void);
uint8_t kb_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]);
#endif
uint8_t kb_init(void);
uint8_t kb_update_matrix(bool matrix[KB_ROWS][KB_COLUMNS]);

View File

@ -1,27 +0,0 @@
/* ----------------------------------------------------------------------------
* ergoDOX : controller : MCP23018 specific exports : functions
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef KEYBOARD__ERGODOX__CONTROLLER__MCP23018__FUNCTIONS_h
#define KEYBOARD__ERGODOX__CONTROLLER__MCP23018__FUNCTIONS_h
#include <stdbool.h>
#include <stdint.h>
#include "../matrix.h"
// --------------------------------------------------------------------
#define MCP23018_TWI_ADDRESS 0b0100000
// --------------------------------------------------------------------
uint8_t mcp23018_init(void);
uint8_t mcp23018_update_matrix( bool matrix[KB_ROWS][KB_COLUMNS] );
#endif

View File

@ -7,13 +7,7 @@
* ------------------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include <util/twi.h>
#include "../../lib/teensy-2-0.h" // `TWI_FREQ` defined in "teensy-2-0.c"
#include "../options.h"
#include "../matrix.h"
#include "./mcp23018--functions.h"
#include "./mcp23018.h"
// ----------------------------------------------------------------------------

View File

@ -1,27 +1,25 @@
/* ----------------------------------------------------------------------------
* key functions : private : exports
*
* Things to be used only by keyfunctions. Exported so layouts can use these
* functions to help define their own, if they like.
* ergoDOX : controller : MCP23018 specific exports : functions
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef LIB__KEY_FUNCTIONS__INTERNAL_h
#define LIB__KEY_FUNCTIONS__INTERNAL_h
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "../../keyboard/matrix.h"
#include <util/twi.h>
#include "../../lib/teensy-2-0.h" // `TWI_FREQ` defined in "teensy-2-0.c"
#include "../options.h"
#include "../matrix.h"
// --------------------------------------------------------------------
void _kbfun_press_release (bool press, uint8_t keycode);
bool _kbfun_is_pressed (uint8_t keycode);
void _kbfun_mediakey_press_release (bool press, uint8_t keycode);
uint8_t _kbfun_get_keycode (void);
#define MCP23018_TWI_ADDRESS 0b0100000
#endif
// --------------------------------------------------------------------
uint8_t mcp23018_init(void);
uint8_t mcp23018_update_matrix( bool matrix[KB_ROWS][KB_COLUMNS] );

View File

@ -6,54 +6,49 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#ifndef KEYBOARD__ERGODOX__CONTROLLER__TEENSY_2_0__LED_h
#define KEYBOARD__ERGODOX__CONTROLLER__TEENSY_2_0__LED_h
#include <stdint.h>
#include <avr/io.h> // for the register macros
#include <stdint.h>
#include <avr/io.h> // for the register macros
// --------------------------------------------------------------------
// --------------------------------------------------------------------
#define _kb_led_1_on() (DDRB |= (1<<5))
#define _kb_led_1_off() (DDRB &= ~(1<<5))
#define _kb_led_1_set(n) (OCR1A = (uint8_t)(n))
#define _kb_led_1_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
#define _kb_led_1_on() (DDRB |= (1<<5))
#define _kb_led_1_off() (DDRB &= ~(1<<5))
#define _kb_led_1_set(n) (OCR1A = (uint8_t)(n))
#define _kb_led_1_set_percent(n) (OCR1A = (uint8_t)((n) * 0xFF))
#define _kb_led_2_on() (DDRB |= (1<<6))
#define _kb_led_2_off() (DDRB &= ~(1<<6))
#define _kb_led_2_set(n) (OCR1B = (uint8_t)(n))
#define _kb_led_2_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
#define _kb_led_2_on() (DDRB |= (1<<6))
#define _kb_led_2_off() (DDRB &= ~(1<<6))
#define _kb_led_2_set(n) (OCR1B = (uint8_t)(n))
#define _kb_led_2_set_percent(n) (OCR1B = (uint8_t)((n) * 0xFF))
#define _kb_led_3_on() (DDRB |= (1<<7))
#define _kb_led_3_off() (DDRB &= ~(1<<7))
#define _kb_led_3_set(n) (OCR1C = (uint8_t)(n))
#define _kb_led_3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
#define _kb_led_3_on() (DDRB |= (1<<7))
#define _kb_led_3_off() (DDRB &= ~(1<<7))
#define _kb_led_3_set(n) (OCR1C = (uint8_t)(n))
#define _kb_led_3_set_percent(n) (OCR1C = (uint8_t)((n) * 0xFF))
#define _kb_led_all_on() do { \
_kb_led_1_on(); \
_kb_led_2_on(); \
_kb_led_3_on(); \
} while(0)
#define _kb_led_all_on() do { \
_kb_led_1_on(); \
_kb_led_2_on(); \
_kb_led_3_on(); \
} while(0)
#define _kb_led_all_off() do { \
_kb_led_1_off(); \
_kb_led_2_off(); \
_kb_led_3_off(); \
} while(0)
#define _kb_led_all_off() do { \
_kb_led_1_off(); \
_kb_led_2_off(); \
_kb_led_3_off(); \
} while(0)
#define _kb_led_all_set(n) do { \
_kb_led_1_set(n); \
_kb_led_2_set(n); \
_kb_led_3_set(n); \
} while(0)
#define _kb_led_all_set_percent(n) do { \
_kb_led_1_set_percent(n); \
_kb_led_2_set_percent(n); \
_kb_led_3_set_percent(n); \
} while(0)
#endif
#define _kb_led_all_set(n) do { \
_kb_led_1_set(n); \
_kb_led_2_set(n); \
_kb_led_3_set(n); \
} while(0)
#define _kb_led_all_set_percent(n) do { \
_kb_led_1_set_percent(n); \
_kb_led_2_set_percent(n); \
_kb_led_3_set_percent(n); \
} while(0)

View File

@ -10,15 +10,7 @@
// for "lib/twi.h"
#define TWI_FREQ 400000
#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
#include "../../lib/teensy-2-0.h"
#include "../options.h"
#include "../matrix.h"
#include "./teensy-2-0--functions.h"
#include "./teensy-2-0--led.h"
#include "./teensy-2-0.h"
// ----------------------------------------------------------------------------

View File

@ -6,18 +6,18 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#ifndef KEYBOARD__ERGODOX__CONTROLLER__TEENSY_2_0__FUNCTIONS_h
#define KEYBOARD__ERGODOX__CONTROLLER__TEENSY_2_0__FUNCTIONS_h
#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
#include "../../lib/teensy-2-0.h"
#include "../options.h"
#include "../matrix.h"
#include "./teensy-2-0--led.h"
#include <stdbool.h>
#include <stdint.h>
#include "../matrix.h"
// --------------------------------------------------------------------
uint8_t teensy_init(void);
uint8_t teensy_update_matrix( bool matrix[KB_ROWS][KB_COLUMNS] );
#endif
// --------------------------------------------------------------------
uint8_t teensy_init(void);
uint8_t teensy_update_matrix( bool matrix[KB_ROWS][KB_COLUMNS] );

View File

@ -0,0 +1,77 @@
/* ----------------------------------------------------------------------------
* ergoDOX : layout : default matrix control
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#include <stdint.h>
#include <avr/pgmspace.h>
#include "../lib/key-functions/public.h"
#include "./matrix.h"
typedef void (*void_funptr_t)(void);
// --------------------------------------------------------------------
#ifndef KB_LAYERS
#define KB_LAYERS 10
#endif
// --------------------------------------------------------------------
/*
* matrix 'get' macros, and `extern` matrix declarations
*
* These are written for when the matrices are stored solely in Flash.
* Layouts may redefine them if they wish and use Flash, RAM, EEPROM,
* or any combination of the three, as long as they maintain the same
* interface.
*
* - If the macro is overridden, the matrix declaration must be too,
* and vice versa.
*
* - 'set' functions are optional, and should be defined in the layout
* specific '.h'. They'll require the use of the EEPROM, possibly in
* clever conjunction with one of the other two memories (since the
* EEPROM is small). Custom key functions will also need to be
* written.
*
* - To override these macros with real functions, set the macro equal
* to itself (e.g. `#define kb_layout_get kb_layout_get`) and provide
* function prototypes, in the layout specific '.h'
*/
#ifndef kb_layout_get
extern const uint8_t PROGMEM \
_kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_get(layer,row,column) \
( (uint8_t) \
pgm_read_byte(&( \
_kb_layout[layer][row][column] )) )
#endif
#ifndef kb_layout_press_get
extern const void_funptr_t PROGMEM \
_kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_press_get(layer,row,column) \
( (void_funptr_t) \
pgm_read_word(&( \
_kb_layout_press[layer][row][column] )) )
#endif
#ifndef kb_layout_release_get
extern const void_funptr_t PROGMEM \
_kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_release_get(layer,row,column) \
( (void_funptr_t) \
pgm_read_word(&( \
_kb_layout_release[layer][row][column] )) )
#endif

View File

@ -1,14 +1,7 @@
// ----------------------------------------------------------------------------
// ergoDOX layout : saneo (generated)
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include "../../lib/data-types/misc.h"
#include "../../lib/usb/usage-page/keyboard.h"
#include "../../lib/key-functions/public.h"
#include "../matrix.h"
#include "../layout.h"
#include "./layout.h"
// ----------------------------------------------------------------------------
const uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { KB_MATRIX_LAYER(

View File

@ -1,20 +1,18 @@
/* ----------------------------------------------------------------------------
* ergoDOX : layout exports
*
* Different layouts are included by modifying a variable in the makefile.
* ergoDOX : layout : saneo : exports
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#ifndef KEYBOARD__ERGODOX__LAYOUT_h
#define KEYBOARD__ERGODOX__LAYOUT_h
// --------------------------------------------------------------------
// include the appropriate keyboard layout header
#include "./layout/saneo-mod.h"
#endif
#include <stdint.h>
#include <stddef.h>
#include <avr/pgmspace.h>
#include "../lib/usb-keyboard.h"
#include "../lib/key-functions/public.h"
#include "./matrix.h"
#include "./default--matrix-control.h"
#include "./controller.h"

View File

@ -1,80 +0,0 @@
/* ----------------------------------------------------------------------------
* ergoDOX : layout : default matrix control
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef KEYBOARD__ERGODOX__LAYOUT__DEFAULT__MATRIX_CONTROL_h
#define KEYBOARD__ERGODOX__LAYOUT__DEFAULT__MATRIX_CONTROL_h
#include <stdint.h>
#include <avr/pgmspace.h>
#include "../../lib/data-types/misc.h"
#include "../../lib/key-functions/public.h"
#include "../matrix.h"
// --------------------------------------------------------------------
#ifndef KB_LAYERS
#define KB_LAYERS 10
#endif
// --------------------------------------------------------------------
/*
* matrix 'get' macros, and `extern` matrix declarations
*
* These are written for when the matrices are stored solely in Flash.
* Layouts may redefine them if they wish and use Flash, RAM, EEPROM,
* or any combination of the three, as long as they maintain the same
* interface.
*
* - If the macro is overridden, the matrix declaration must be too,
* and vice versa.
*
* - 'set' functions are optional, and should be defined in the layout
* specific '.h'. They'll require the use of the EEPROM, possibly in
* clever conjunction with one of the other two memories (since the
* EEPROM is small). Custom key functions will also need to be
* written.
*
* - To override these macros with real functions, set the macro equal
* to itself (e.g. `#define kb_layout_get kb_layout_get`) and provide
* function prototypes, in the layout specific '.h'
*/
#ifndef kb_layout_get
extern const uint8_t PROGMEM \
_kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_get(layer,row,column) \
( (uint8_t) \
pgm_read_byte(&( \
_kb_layout[layer][row][column] )) )
#endif
#ifndef kb_layout_press_get
extern const void_funptr_t PROGMEM \
_kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_press_get(layer,row,column) \
( (void_funptr_t) \
pgm_read_word(&( \
_kb_layout_press[layer][row][column] )) )
#endif
#ifndef kb_layout_release_get
extern const void_funptr_t PROGMEM \
_kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS];
#define kb_layout_release_get(layer,row,column) \
( (void_funptr_t) \
pgm_read_word(&( \
_kb_layout_release[layer][row][column] )) )
#endif
#endif

View File

@ -1,16 +0,0 @@
/* ----------------------------------------------------------------------------
* ergoDOX : layout : saneo : exports
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef KEYBOARD__ERGODOX__LAYOUT__SANEO_h
#define KEYBOARD__ERGODOX__LAYOUT__SANEO_h
#include "../controller.h"
#include "./default--matrix-control.h"
#endif

View File

@ -24,8 +24,7 @@
// Version 1.0: Initial Release
// Version 1.1: Add support for Teensy 2.0
#define USB_SERIAL_PRIVATE_INCLUDE
#include "usb_keyboard.h"
#include "./usb_keyboard.h"
/**************************************************************************
*

View File

@ -1,6 +1,8 @@
#ifndef usb_serial_h__
#define usb_serial_h__
#pragma once
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdint.h>
void usb_init(void); // initialize everything
@ -22,120 +24,6 @@ extern uint16_t consumer_key;
int8_t usb_extra_consumer_send();
#if 0 // removed in favor of equivalent code elsewhere ::Ben Blazak, 2012::
#define KEY_CTRL 0x01
#define KEY_SHIFT 0x02
#define KEY_ALT 0x04
#define KEY_GUI 0x08
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
#define KEY_LEFT_ALT 0x04
#define KEY_LEFT_GUI 0x08
#define KEY_RIGHT_CTRL 0x10
#define KEY_RIGHT_SHIFT 0x20
#define KEY_RIGHT_ALT 0x40
#define KEY_RIGHT_GUI 0x80
#define KEY_A 4
#define KEY_B 5
#define KEY_C 6
#define KEY_D 7
#define KEY_E 8
#define KEY_F 9
#define KEY_G 10
#define KEY_H 11
#define KEY_I 12
#define KEY_J 13
#define KEY_K 14
#define KEY_L 15
#define KEY_M 16
#define KEY_N 17
#define KEY_O 18
#define KEY_P 19
#define KEY_Q 20
#define KEY_R 21
#define KEY_S 22
#define KEY_T 23
#define KEY_U 24
#define KEY_V 25
#define KEY_W 26
#define KEY_X 27
#define KEY_Y 28
#define KEY_Z 29
#define KEY_1 30
#define KEY_2 31
#define KEY_3 32
#define KEY_4 33
#define KEY_5 34
#define KEY_6 35
#define KEY_7 36
#define KEY_8 37
#define KEY_9 38
#define KEY_0 39
#define KEY_ENTER 40
#define KEY_ESC 41
#define KEY_BACKSPACE 42
#define KEY_TAB 43
#define KEY_SPACE 44
#define KEY_MINUS 45
#define KEY_EQUAL 46
#define KEY_LEFT_BRACE 47
#define KEY_RIGHT_BRACE 48
#define KEY_BACKSLASH 49
#define KEY_NUMBER 50
#define KEY_SEMICOLON 51
#define KEY_QUOTE 52
#define KEY_TILDE 53
#define KEY_COMMA 54
#define KEY_PERIOD 55
#define KEY_SLASH 56
#define KEY_CAPS_LOCK 57
#define KEY_F1 58
#define KEY_F2 59
#define KEY_F3 60
#define KEY_F4 61
#define KEY_F5 62
#define KEY_F6 63
#define KEY_F7 64
#define KEY_F8 65
#define KEY_F9 66
#define KEY_F10 67
#define KEY_F11 68
#define KEY_F12 69
#define KEY_PRINTSCREEN 70
#define KEY_SCROLL_LOCK 71
#define KEY_PAUSE 72
#define KEY_INSERT 73
#define KEY_HOME 74
#define KEY_PAGE_UP 75
#define KEY_DELETE 76
#define KEY_END 77
#define KEY_PAGE_DOWN 78
#define KEY_RIGHT 79
#define KEY_LEFT 80
#define KEY_DOWN 81
#define KEY_UP 82
#define KEY_NUM_LOCK 83
#define KEYPAD_SLASH 84
#define KEYPAD_ASTERIX 85
#define KEYPAD_MINUS 86
#define KEYPAD_PLUS 87
#define KEYPAD_ENTER 88
#define KEYPAD_1 89
#define KEYPAD_2 90
#define KEYPAD_3 91
#define KEYPAD_4 92
#define KEYPAD_5 93
#define KEYPAD_6 94
#define KEYPAD_7 95
#define KEYPAD_8 96
#define KEYPAD_9 97
#define KEYPAD_0 98
#define KEYPAD_PERIOD 99
#endif
/* Consumer Page(0x0C)
* following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
*/
@ -172,10 +60,6 @@ int8_t usb_extra_consumer_send();
#define SYSTEM_WAKE_UP 0x0083
// 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>
#define EP_TYPE_CONTROL 0x00
#define EP_TYPE_BULK_IN 0x81
@ -199,7 +83,7 @@ int8_t usb_extra_consumer_send();
#define MSB(n) ((n >> 8) & 255)
#if defined(__AVR_AT90USB162__)
#define HW_CONFIG()
#define HW_CONFIG()
#define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
#define USB_CONFIG() (USBCON = (1<<USBE))
#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
@ -241,5 +125,3 @@ int8_t usb_extra_consumer_send();
#define CDC_SET_LINE_CODING 0x20
#define CDC_GET_LINE_CODING 0x21
#define CDC_SET_CONTROL_LINE_STATE 0x22
#endif
#endif

View File

@ -1,15 +0,0 @@
/* ----------------------------------------------------------------------------
* miscellaneous data types
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef LIB__DATA_TYPES_h
#define LIB__DATA_TYPES_h
typedef void (*void_funptr_t)(void);
#endif

View File

@ -7,10 +7,7 @@
* ------------------------------------------------------------------------- */
#include "../../../main.h"
#include "../../../keyboard/layout.h"
#include "../public.h"
#include "../private.h"
#include "./public.h"
/*
* Generate a normal keypress or keyrelease

View File

@ -7,10 +7,7 @@
* ------------------------------------------------------------------------- */
#include <avr/interrupt.h>
#include <util/delay.h>
#include "../public.h"
#include "./public.h"
// ----------------------------------------------------------------------------
// descriptions
@ -23,12 +20,6 @@
* [description]
* For reflashing the controller
*/
void kbfun_jump_to_bootloader(void);
// ----------------------------------------------------------------------------
#if MAKEFILE_BOARD == teensy-2-0
// ----------------------------------------------------------------------------
// from PJRC (slightly modified)
// <http://www.pjrc.com/teensy/jump_to_bootloader.html>
@ -52,16 +43,3 @@ void kbfun_jump_to_bootloader(void) {
PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
asm volatile("jmp 0x7E00");
}
// ----------------------------------------------------------------------------
#else
// ----------------------------------------------------------------------------
void kbfun_jump_to_bootloader(void) {}
// ----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------

View File

@ -6,13 +6,6 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include "../../lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "../../lib/usb/usage-page/keyboard.h"
#include "../../keyboard/layout.h"
#include "../../keyboard/matrix.h"
#include "../../main.h"
#include "./public.h"
/*

View File

@ -6,12 +6,17 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#ifndef LIB__KEY_FUNCTIONS__COMMON_h
#define LIB__KEY_FUNCTIONS__COMMON_h
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdbool.h>
#include <stdint.h>
#include "../../main.h"
#include "../../keyboard/layout.h"
#include "../../keyboard/matrix.h"
#include "../../lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "../../lib/usb-keyboard.h"
// --------------------------------------------------------------------
@ -35,4 +40,11 @@ void kbfun_control_press_release (void);
void kbfun_2_keys_capslock_press_release (void);
void kbfun_mediakey_press_release (void);
#endif
// private
void _kbfun_press_release (bool press, uint8_t keycode);
bool _kbfun_is_pressed (uint8_t keycode);
void _kbfun_mediakey_press_release (bool press, uint8_t keycode);
uint8_t _kbfun_get_keycode (void);
// device
void kbfun_jump_to_bootloader(void);

View File

@ -7,14 +7,7 @@
* ------------------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include "../../../lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "../../../lib/usb/usage-page/keyboard.h"
#include "../../../keyboard/layout.h"
#include "../../../main.h"
#include "../public.h"
#include "../private.h"
#include "./public.h"
// ----------------------------------------------------------------------------

View File

@ -20,14 +20,6 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
// ----------------------------------------------------------------------------
// conditional compile
#if MAKEFILE_BOARD == teensy-2-0
// ----------------------------------------------------------------------------
#include <util/twi.h>
#include "./teensy-2-0.h"
// ----------------------------------------------------------------------------
@ -87,8 +79,3 @@ uint8_t twi_read(uint8_t * data) {
return TW_STATUS; // error
return 0; // success
}
// ----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------

View File

@ -6,23 +6,19 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#pragma once
#include <util/twi.h>
#ifndef TWI_h
#define TWI_h
// --------------------------------------------------------------------
#ifndef TWI_FREQ
#define TWI_FREQ 100000 // in Hz
#endif
// --------------------------------------------------------------------
void twi_init (void);
uint8_t twi_start (void);
void twi_stop (void);
uint8_t twi_send (uint8_t data);
uint8_t twi_read (uint8_t * data);
// --------------------------------------------------------------------
#ifndef TWI_FREQ
#define TWI_FREQ 100000 // in Hz
#endif
// --------------------------------------------------------------------
void twi_init (void);
uint8_t twi_start (void);
void twi_stop (void);
uint8_t twi_send (uint8_t data);
uint8_t twi_read (uint8_t * data);

View File

@ -20,9 +20,7 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef USB_USAGE_PAGE_KEYBOARD_h
#define USB_USAGE_PAGE_KEYBOARD_h
#pragma once
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@ -291,7 +289,3 @@
#define MEDIAKEY_BROWSER_STOP 18
#define MEDIAKEY_BROWSER_REFRESH 19
#define MEDIAKEY_BROWSER_BOOKMARKS 20
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif

View File

@ -1,53 +0,0 @@
/* ----------------------------------------------------------------------------
* TODO: not sure where this stuff should be yet. a lot of it (depending on
* what ends up here) will likely be device and application specific.
*
* - The following document versions were used, unless otherwise noted:
* - USB Specification: revision 2.0
* - HID Usage Tables: version 1.12
* - Device Class Definition for Human Interface Devices (HID): version 1.11
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
// TODO: does stuff from spec sec 9.4.* belong directly in an interrupt vector?
// - spec sec 9.4.1 (Standard Device Requests / Clear Feature) (pg 252)
// - spec sec 9.4.2 (Standard Device Requests / Get Configuration) (pg 253)
// - spec sec 9.4.3 (Standard Device Requests / Get Descriptor) (pg 253)
// - spec sec 9.4.4 (Standard Device Requests / Get Interface) (pg 254)
// - spec sec 9.4.5 (Standard Device Requests / Get Status) (pg 254)
// - spec sec 9.4.6 (Standard Device Requests / Set Address) (pg 256)
// - spec sec 9.4.7 (Standard Device Requests / Set Configuration) (pg 257)
// - spec sec 9.4.8 (Standard Device Requests / Set Descriptor) (pg 257)
// - spec sec 9.4.9 (Standard Device Requests / Set Feature) (pg 258)
// - spec sec 9.4.10 (Standard Device Requests / Set Interface) (pg 259)
// - spec sec 9.4.11 (Standard Device Requests / Synch Frame) (pg 260)
// TODO
// - read the hid device class definition .pdf
// - set USB vendor ID = 0x1d50 // Openmoko, Inc.
// USB product ID = 0x6028 // ErgoDox ergonomic keyboard
// DONE
// - read the hid usage tables .pdf
// - i think this is more for reference and implementation than
// understanding. i've copied the relevant (i think) tables ones into
// headers. the unicode usage page, i'll have to look into more later: i'm
// not sure if it can be used with keyboards. if so though, i'll have to
// look on the unicode website, or elsewhere, coz this .pdf doesn't list
// anything about them out, it just references the unicode spec.

View File

@ -1,52 +0,0 @@
/* ----------------------------------------------------------------------------
* USB 2.0 common macros and definitions
*
* See "notes from usb 2.0 spec sec 9 (usb device framework).h".
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef USB_COMMON_h
#define USB_COMMON_h
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// - spec table 9-4 (Standard Request Codes)
#define USB_GET_STATUS 0
#define USB_CLEAR_FEATURE 1
// (reserved for future use): 2
#define USB_SET_FEATURE 3
// (reserved for future use): 4
#define USB_SET_ADDRESS 5
#define USB_GET_DESCRIPTOR 6
#define USB_SET_DESCRIPTOR 7
#define USB_GET_CONFIGURATION 8
#define USB_SET_CONFIGURATION 9
#define USB_GET_INTERFACE 10
#define USB_SET_INTERFACE 11
#define USB_SYNCH_FRAME 12
// - spec table 9-5 (Descriptor Types)
#define USB_DEVICE 1
#define USB_CONFIGURATION 2
#define USB_STRING 3
#define USB_INTERFACE 4
#define USB_ENDPOINT 5
#define USB_DEVICE_QUALIFIER 6
#define USB_OTHER_SPEED_CONFIGURATION 7
#define USB_INTERFACE_POWER 8
// - spec table 9-6 (Standard Feature Selectors)
#define USB_DEVICE_REMOTE_WAKEUP 1 // recipient: device
#define USB_ENDPOINT_HALT 0 // recipient: endpoint
#define USB_TEST_MODE 2 // recipient: device
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif

View File

@ -1,27 +0,0 @@
# Notes from the HID Device Class Definition, version 1.11
* sec 4.1 (The HID Class)
* The `bInterfaceClass` member of an Interface descriptor is always 3 for
HID class devices.
* sec 4.2 (Subclass)
* The `bInterfaceSubClass` member declares whether a device supports a boot interface.
* 0 => no subclass
* 1 => boot interface subclass
* 2..255 => reserved
* sec 4.3 (Protocols)
* The `bInterfaceProtocol` member of an Interface descriptor only has meaning if the `bInterfaceSubClass` member declares that the device supports a boot interface, otherwise it is 0.
* 0 => none
* 1 => keyboard
* 2 => mouse
* 3..255 => reserved
-------------------------------------------------------------------------------
Copyright &copy; 2012 Ben Blazak <benblazak.dev@gmail.com>
Released under The MIT License (MIT) (see "license.md")
Project located at <https://github.com/benblazak/ergodox-firmware>

View File

@ -1,858 +0,0 @@
/* ----------------------------------------------------------------------------
* Notes from the USB 2.0 specification
*
* Written as a header file because I was going to actually use it. Changed my
* mind because it's simpler to use uint8_t arrays for things than to use
* structs. it's also easier i think to keep the least and most significant
* bits of uint16_t values separate initially instead of separating them later.
* Kept it as a header because it looks cleaner this way than i could make it
* look as an .md file.
*
* - conventions from the spec
* - variable prefixes
* - 'b' : bits or bytes; dependent on context
* - 'bcd' : binary-coded decimal
* - 'bm' : bitmap
* - 'd' : descriptor
* - 'i' : index
* - 'w' : word
*
* - conventions used in this file
* - everything prefixed with or `USB_` (for non-function-like macros) or
* `usb_` (for everything else)
*
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef USB_DATA_STRUCTURES_h
#define USB_DATA_STRUCTURES_h
#pragma pack(push)
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <stdint.h>
// ----------------------------------------------------------------------------
/* - spec sec 9.3 (USB Device Requests)
* - table 9-2 (Format of Setup Data)
*/
struct usb_setup_data {
uint8_t bmRequestType;
/* value: bitmap
* - data transfer direction, type, recipient
* (see macros below)
*/
uint8_t bRequest;
/* value: value
* - type of request (depending on bmRequestType)
* (see spec table 9-3 (Standard Device Requests))
*/
uint16_t wValue;
/* value: value
* - varies according to request; used to pass a request specific
* parameter to the device
*/
uint16_t wIndex;
/* value: index or offset
* - varies according to request; often used to specify an endpoint or
* an interface
* (see spec figure 9-2 and 9-3, copied below)
*/
uint16_t wLength;
/* value: count
* - number of bytes to transfer if there is a data stage
*/
};
/* - spec sec 9.3 (USB Device Requests)
* - table 9-2 (Format of Setup Data)
* - bmRequestType
*
* .-------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |-------------------------------------------------------|
* | direction | type | recipient |
* '-------------------------------------------------------'
*
* - direction: 0 => host to device
* 1 => device to host
*
* - type: 0 => standard
* 1 => class
* 2 = vendor
* 3 = reserved
*
* - recipient: 0 => device
* 1 => interface
* 2 => endpoint
* 3 => other
* 4..31 => reserved
*/
// --- data transfer direction
#define usb_bmRequestType_hostToDevice(val) (((val) & (0b1<<7)) == (0<<7))
#define usb_bmRequestType_deviceToHost(val) (((val) & (0b1<<7)) == (1<<7))
// --- type
#define usb_bmRequestType_standard(val) (((val) & (0b11<<5)) == (0<<5))
#define usb_bmRequestType_class(val) (((val) & (0b11<<5)) == (1<<5))
#define usb_bmRequestType_vendor(val) (((val) & (0b11<<5)) == (2<<5))
#define usb_bmRequestType_reserved(val) (((val) & (0b11<<5)) == (3<<5))
// --- recipient
#define usb_bmRequestType_device(val) (((val) & (0b11111<<0)) == (0<<0))
#define usb_bmRequestType_interface(val) (((val) & (0b11111<<0)) == (1<<0))
#define usb_bmRequestType_endpoint(val) (((val) & (0b11111<<0)) == (2<<0))
#define usb_bmRequestType_other(val) (((val) & (0b11111<<0)) == (3<<0))
#define usb_bmRequestType_reserved(val) (((val) & (0b11100<<0)) != (0<<0))
/* - spec sec 9.3.4 (wIndex)
* - figure 9-2 (format when specifying an endpoint)
*
* .-------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |-------------------------------------------------------|
* | direction | reserved (reset to 0) | endpoint number |
* >-----------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |-------------------------------------------------------|
* | reserved (reset to 0) |
* '-------------------------------------------------------'
*
* - direction: 0 => out (to device), 1 => in (to host)
*/
#define usb_wIndex_endpoint(direction, endpoint_number) \
( (uint16_t) (((direction)<<7) | (endpoint_number)) )
/* - spec sec 9.3.4 (wIndex)
* - figure 9-3 (format when specifying an interface)
*
* .-------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |-------------------------------------------------------|
* | interface number |
* >-----------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |-------------------------------------------------------|
* | reserved (reset to 0) |
* '-------------------------------------------------------'
*/
#define usb_wIndex_interface(interface_number) \
( (uint16_t) (interface_number) )
// ----------------------------------------------------------------------------
/* - spec table 9-4 (Standard Request Codes)
*/
#define USB_GET_STATUS 0
#define USB_CLEAR_FEATURE 1
// (reserved for future use): 2
#define USB_SET_FEATURE 3
// (reserved for future use): 4
#define USB_SET_ADDRESS 5
#define USB_GET_DESCRIPTOR 6
#define USB_SET_DESCRIPTOR 7
#define USB_GET_CONFIGURATION 8
#define USB_SET_CONFIGURATION 9
#define USB_GET_INTERFACE 10
#define USB_SET_INTERFACE 11
#define USB_SYNCH_FRAME 12
/* - spec table 9-5 (Descriptor Types)
*/
#define USB_DEVICE 1
#define USB_CONFIGURATION 2
#define USB_STRING 3
#define USB_INTERFACE 4
#define USB_ENDPOINT 5
#define USB_DEVICE_QUALIFIER 6
#define USB_OTHER_SPEED_CONFIGURATION 7
#define USB_INTERFACE_POWER 8
/* - spec table 9-6 (Standard Feature Selectors)
*/
#define USB_DEVICE_REMOTE_WAKEUP 1 // recipient: device
#define USB_ENDPOINT_HALT 0 // recipient: endpoint
#define USB_TEST_MODE 2 // recipient: device
/* - spec sec 9.4.5 (Standard Device Requests / Get Status)
* - figure 9-4 (information returned by a GetStatus() request to a device)
*
* .------------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |------------------------------------------------------------|
* | reserved (reset to 0) | remote wakeup | self powered |
* >----------------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |------------------------------------------------------------|
* | reserved (reset to 0) |
* '------------------------------------------------------------'
*
* - remote wakeup: 0 => ability of device to signal remote wakeup disabled
* (default)
* 1 => ability ................................. enabled
*
* - self powered: 0 => device is bus powered
* 1 => device is self powered
*/
#define usb_getStatus_device(remote_wakeup, self_powered) \
( (uint16_t) (((remote_wakeup)<<1) | (self_powered)) )
/* - spec sec 9.4.5 (Standard Device Requests / Get Status)
* - figure 9-5 (information returned by a GetStatus() request to an
* interface)
*
* .------------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |------------------------------------------------------------|
* | reserved (reset to 0) |
* >----------------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |------------------------------------------------------------|
* | reserved (reset to 0) |
* '------------------------------------------------------------'
*/
#define usb_getStatus_interface() ( (uint16_t) 0 )
/* - spec sec 9.4.5 (Standard Device Requests / Get Status)
* - figure 9-6 (information returned by a GetStatus() request to an
* endpoint)
*
* .------------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |------------------------------------------------------------|
* | reserved (reset to 0) | halt |
* >----------------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |------------------------------------------------------------|
* | reserved (reset to 0) |
* '------------------------------------------------------------'
*
* - halt: 0 => endpoint not currently halted
* 1 => endpoint currently halted
*/
#define usb_getStatus_endpoint(halt) ( (uint16_t) (halt) )
/* - spec sec 9.4.9 (Set Feature)
* - table 9-7 (Test Mode Selectors)
*
* - in the case of a SetFeature(TEST_MODE...):
* - the most significant byte of wIndex is used to specify the test mode
* - the lower byte of wIndex must be zero, because the recipient must be the
* device
*/
// (reserved): (0x0000)
#define USB_TEST_MODE_wIndex_Test_J ( (uint16_t) (0x0100) )
#define USB_TEST_MODE_wIndex_Test_K ( (uint16_t) (0x0200) )
#define USB_TEST_MODE_wIndex_Test_SE0_NAK ( (uint16_t) (0x0300) )
#define USB_TEST_MODE_wIndex_Test_Packet ( (uint16_t) (0x0400) )
#define USB_TEST_MODE_wIndex_Test_Force_Enable ( (uint16_t) (0x0500) )
// (reserved for standard test selectors): (0x0600)..(0x3F00)
// (reserved): (0x3F00)..(0xBF00)
// (reserved for vendor-specific test modes): (0xC000)..(0xFF00)
// ----------------------------------------------------------------------------
/* - spec sec 9.6.1 (Standard USB Descriptor Definitions / Device)
* - table 9-8 (Standard Device Descriptor)
*/
struct usb_device_descriptor {
uint8_t bLength;
/* value: number
* - size of this descriptor in bytes
*/
uint8_t bDescriptorType;
/* value: constant
* - DEVICE Descriptor Type
* - a high speed capable device will set this to 2.0 (0x0200). if the
* device is full-speed or low-speed only, this version number only
* means that it'll send a request error when asked for the
* device_qualifier descriptor
*/
uint16_t bcdUSB;
/* value: binary coded decimal
* - usb spec release number
* - format: 0xJJMN, where JJ = major version, M = minor version,
* N = sub-minor version; e.g. version 2.1.3 => 0x0213
*/
uint8_t bDeviceClass;
/* value: class
* - class code (assigned by the USB-IF)
* - 0x00 => each interface within a configuration specifies its own
* class information and the various interfaces operate independently
* - 0x01..0xFE => the device supports different class specifications
* on different interfaces and the interfaces may not operate
* independently. this value identifies the class definition used
* for the aggregate interfaces
* - 0xFF => the device class is vendor-specific
*/
uint8_t bDeviceSubClass;
/* value: subclass
* - subclass code (assigned by the USB-IF)
* - qualified by bDeviceClass
* - if bDeviceClass is reset to 0, this field must be also
* - if bDeviceClass != 0xFF , all values are reserved for assignment
* by the USB-IF
*/
uint8_t bDeviceProtocol;
/* value: protocol
* - protocol code (assigned by the USB-IF)
* - qualified by bDeviceClass and bDeviceSubClass
* - if a device supports class-specific protocols on a device basis as
* opposed to an interface basis, this code identifies the protocols
* that the device uses as defined by the specification of the device
* class
* - 0x00 => the device does not use class-specific protocols on a
* device basis. however, it may use class-specific protocols on an
* interface basis
* - 0xFF => the device uses a vendor-specific protocol on a device
* basis
*/
uint8_t bMaxPacketSize0;
/* value: number
* - max packet size for endpoint 0
* - only 8, 16, 32, or 64 are valid
* - if operating at high-speed, the value must be 64
*/
uint16_t idVendor;
/* value: id
* - vendor ID (assigned by the USB-IF)
*/
uint16_t idProduct;
/* value: id
* - product ID (assigned by the manufacturer)
*/
uint16_t bcdDevice;
/* value: binary coded decimal
* - device release number
*/
uint8_t iManufacturer;
/* value: index
* - index of string descriptor describing manufacturer
*/
uint8_t iProduct;
/* value: index
* - index of string descriptor describing product
*/
uint8_t iSerialNumber;
/* value: index
* - index of string descriptor describing the device's serial number
*/
uint8_t bNumConfigurations;
/* value: number
* - number of possible configurations (at the current operating speed)
*/
};
// ----------------------------------------------------------------------------
/* - spec sec 9.6.2 (Standard USB Descriptor Definitions / Device_Qualifier)
* - table 9-9 (Device_Qualifier Descriptor)
*
* - required if the device has different device information for full-speed and
* high-speed
*
* - not valid for a full-speed only device (with a device descriptor version
* number equal to 0x0200); if requested, the device must respond with a
* request error
*/
struct usb_device_qualifier_descriptor {
uint8_t bLength;
/* value: number
* - size of descriptor
*/
uint8_t bDescriptorType;
/* value: constant
* - device qualifier type
*/
uint16_t bcdUSB;
/* value: binary coded decimal
* - usb spec release number
* - format: (see note for usb_device_descriptor.bcdUSB)
* - must be at least 2.0 (0x0200) for this descriptor
*/
uint8_t bDeviceClass;
/* value: class
*/
uint8_t bDeviceSubClass;
/* value: subclass
*/
uint8_t bDeviceProtocol;
/* value: protocol
*/
uint8_t bMaxPacketSize0;
/* value: number
* - max packet size for other speed
*/
uint8_t bNumConfigurations;
/* value: number
* - number of other-speed configurations
*/
uint8_t bReserved;
/* value: 0
* - reserved for future use
*/
};
// ----------------------------------------------------------------------------
/* - spec sec 9.6.3 (Standard USB Descriptor Definitions / Configuration)
* - table 9-10 (Standard Configuration Descriptor)
*
* - spec sec 9.6.4 (Standard USB Descriptor Definitions /
* Other_Speed_Configuration)
* - table 9-11 (Other_Speed_Configuration Descriptor)
*
* - both descriptors have the same structure. the only specified difference
* is the value of the bDescriptorType constant.
*/
struct usb_configuration_descriptor {
uint8_t bLength;
/* value: number
* - size of this descriptor in bytes
uint8_t bDescriptorType;
* value: constant
* - CONFIGURATION Descriptor Type
* (for Standard Configuration Descriptor)
* - OTHER_SPEED_CONFIGURATION Type
* (for Other Speed Configuration Descriptor)
*/
uint16_t wTotalLength;
/* value: number
* - total length of data returned for this configuration. includes
* the combined length of all descriptors (configuration, interface,
* endpoint, and class- or vendor-specific) returned for this
* configuration.
*/
uint8_t bNumInterfaces;
/* value: number
* - number of interfaces supported by this configuration
*/
uint8_t bConfigurationValue;
/* value: number
* - value to use as an argument to the SetConfiguration() request to
* select this configuration
*/
uint8_t iConfiguration;
/* value: index
* - index of string descriptor describing this configuration
*/
uint8_t bmAttributes;
/* value: bitmap
* - self-powered, remote wakeup
* (see macro below)
*/
uint8_t bMaxPower;
/* value: mA
* - max power consumption of the USB device from the bus
* (configuration specific) (when device is fully operational)
* - format: expressed in 2 mA units (i.e. value=50 => 100mA)
* - note: a device configuration reports whether the configuration is
* bus-powered or self-powered. device status reports whether the
* device is currently self-powered. if a device is disconnected
* from its external power source, it updates device status to
* indicate that. it may not increase its power draw from the bus
* beyond the amount reported by its configuration. if it can
* continue to operate, it does so. if not, it fails operations it
* can no longer support, and the host software can determine the
* cause of failure by checking the status and noting the loss of the
* device's external power.
*/
};
/* - spec sec 9.6.3 (Standard USB Descriptor Definitions / Configuration)
* - table 9-10 (Standard Configuration Descriptor)
* - bmAttributes
*
* .--------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |--------------------------------------------------------|
* | reserved | self | remote | reserved |
* | (set to 1) | powered | wakeup | (reset to 0) |
* '--------------------------------------------------------'
*
* - D7: must be set to 1 for historical reasons
*
* - self powered: 0 => false
* 1 => true
* - a device configuration that uses both bus and local power must report a
* non-zero value in bMaxPower (to indicate the amount of bus power
* required) and set D6 = 1
*
* - remote wakeup: 0 => not supported by configuration
* 1 => supported by configuration
*/
#define usb_configuration_bmAttributes(self_powered, remote_wakeup) \
( (uint8_t) ((1<<7) | ((self_powered)<<6) | ((remote_wakeup)<<5)) )
// ----------------------------------------------------------------------------
/* - spec sec 9.6.5 (Standard USB Descriptor Definitions / Interface)
* - table 9-12 (Standard Interface Descriptor)
*/
struct usb_interface_descriptor {
uint8_t bLength;
/* value: number
* - size of this descriptor in bytes
*/
uint8_t bDescriptorType;
/* value: constant
* - INTERFACE Descriptor Type
*/
uint8_t bInterfaceNumber;
/* value: number
* - number of this interface
* - zero-based value identifying the index in the array of concurrent
* interfaces supported by this configuration
*/
uint8_t bAlternateSetting;
/* value: number
* - value used to select this alternate setting for the interface
* identified in the prior field
*/
uint8_t bNumEndpoints;
/* value: number
* - number of endpoints used by this interface (excluding endpoint
* zero)
* - if this value is zero, this interface only uses the Default
* Control Pipe
*/
uint8_t bInterfaceClass;
/* value: class
* - class code (assigned by the USB-IF)
* - 0x00 => reserved for future standardization
* - 0xFF => interface class is vendor specific
* - [others] => reserved for assignment by the USB-IF
*/
uint8_t bInterfaceSubClass;
/* value: subclass
* - subclass code (assigned by the USB-IF)
* - qualified by the value of the bInterfaceClass field
* - if the bInterfaceClass field is reset to zero, this field must be
* also
* - if the bInterfaceClass field is not set to 0xFF, all values are
* reserved for assignment by the USB-IF
*/
uint8_t bInterfaceProtocol;
/* value: protocol
* - protocol code (assigned by the USB)
* - qualified by the values of the bInterfaceClass and
* bInterfaceSubClass fields
* - if an interface supports class-specific requests, this code
* identifies the protocols that the device uses as defined by the
* specification of the device class.
* - 0x00 => the device does not use a class-specific protocol on this
* interface
* - 0xFF => the device uses a vendor-specific protocol for this
* interface
*/
uint8_t iInterface;
/* value: index
* - index of string descriptor describing this interface
*/
};
// ----------------------------------------------------------------------------
/* - spec sec 9.6.6 (Standard USB Descriptor Definitions / Endpoint)
* - table 9-13 (Standard Endpoint Descriptor)
*
* - a feedback endpoint (explicit or implicit) needs to be associated with one
* (or more) isochronous data endpoints to which it provides feedback
* service. the association is based on endpoint number matching. a
* feedback endpoint always has the opposite direction from the data
* endpoint(s) it services. if multiple data endpoints are to be serviced by
* the same feedback endpoint, the data endpoints must have ascending ordered
* (but not necessarily consecutive) endpoint numbers. the first data
* endpoint and the feedback endpoint must have the same endpoint number (and
* opposite direction). this ensures that a data endpoint can uniquely
* identify its feedback endpoint by searching for the first feedback
* endpoint that has an endpoint number equal or less than its own endpoint
* number.
* - see spec figures 9-7 and 9-8
*/
struct usb_endpoint_descriptor {
uint8_t bLength;
/* value: number
* - size of this descriptor in bytes
*/
uint8_t bDescriptorType;
/* value: constant
* - ENDPOINT Descriptor Type
*/
uint8_t bEndpointAddress;
/* value: endpoint
* - the address and direction of the endpoint described
* (see macro below)
*/
uint8_t bmAttributes;
/* value: bitmap
* - endpoint's attributes when it is configured using the
* bConfigurationValue
* - includes: transfer type
* - if transfer type == isochronous, also includes:
* synchronization type, usage type
* - (see spec chapter 5 for more information)
* - (see macros below)
*/
uint16_t wMaxPacketSize;
/* value: number
* - max packet size this endpoint is capable of sending or receiving
* when this configuration is selected
* - for isochronous endpoints, this value is used to reserve the bus
* time in the schedule, required for the per-(micro)frame data
* payloads. the pipe may, on an ongoing basis, actually use less
* bandwidth than reserved. the device reports, if necessary, the
* actual bandwidth used via its normal, non-USB defined mechanisms
* - (see spec chapter 5 for more information)
* - (see macro below)
*/
uint8_t bInterval;
/* value: number
* - interval for polling endpoint for data transfers
* - expressed in frames or microframes, depending on the device
* operating speed (i.e. either 1 ms or 125 μs units)
* - for (full|high)-speed isochronous endpoints and high-speed
* interrupt endpoints, this value must be between 1..16 . this
* value is used as the exponent for a 2^(bInterval-1) value (e.g. a
* bInterval of 4 => a period of 8 == 2^(4-1))
* - for (full|low)-speed interrupt endpoints, this value may be
* between 1..255
* - for high-speed bulk/control OUT endpoints, this value must specify
* the max NAK rate of the endpoint. a value of 0 => the endpoint
* never NAKs. other values indicate at most 1 NAK each bInterval
* number of microframes. this value must be between 0..255
* - for high-speed bulk and control OUT endpoints, this field is only
* used for compliance purposes (the host controller is not required
* to change its behavior based on the value in this field)
* - (see spec chapter 5 description of periods for more detail)
*/
};
/* - spec sec 9.6.6 (Standard USB Descriptor Definitions / Endpoint)
* - table 9-13 (Standard Endpoint Descriptor)
* - bEndpointAddress
*
* .-------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |-------------------------------------------------------|
* | direction | reserved (reset to 0) | endpoint number |
* '-------------------------------------------------------'
*
* - D7: 0 => OUT endpoint
* 1 => IN endpoint
* - ignored for control endpoints
*/
#define usb_endpoint_bEndpointAddress(direction, endpoint_number) \
( (uint8_t) ((direction)<<7) | (endpoint_number) )
/* - spec sec 9.6.6 (Standard USB Descriptor Definitions / Endpoint)
* - table 9-13 (Standard Endpoint Descriptor)
* - bmAttributes
*
* .------------------------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |------------------------------------------------------------------------|
* | reserved | usage type | synchronization type | transfer type |
* | (reset to 0) | (if isochronous) | (if isochronous) | |
* | |(else reset to 0) | (else reset to 0) | |
* '------------------------------------------------------------------------'
*
* - transfer type: 0b00 => control
* 0b01 => isochronous
* 0b10 => bulk
* 0b11 => interrupt
*
* - synchronization type: 0b00 => no synchronization
* 0b01 => asynchronous
* 0b10 => adaptive
* 0b11 => synchronous
* - if transfer type != isochronous, field is reset to 0
*
* - usage type: 0b00 => data endpoint
* 0b01 => feedback endpoint
* 0b10 => implicit feedback data endpoint
* 0b11 => reserved
* - if transfer type != isochronous, field is reset to 0
*
* - if usage type == feedback endpoint, then transfer type must be isochronous
* and synchronization type must be no synchronization
*/
#define usb_endpoint_bmAttributes(transfer_type) \
( (uint8_t) (transfer_type) )
#define usb_endpoint_bmAttributes_isochronous( \
synchronization_type, usage_type ) \
( (uint8_t) (0b01 | ((synchronization_type)<<2) | ((usage_type)<<4)) )
/* - spec sec 9.6.6 (Standard USB Descriptor Definitions / Endpoint)
* - table 9-13 (Standard Endpoint Descriptor)
* - wMaxPacketSize
*
* .-----------------------------------------------------------------.
* | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
* |-----------------------------------------------------------------|
* | max packet size |
* | (D10..D0) |
* | |
* >---------------------------------------------------------------<
* | D15 | D14 | D13 | D12 | D11 | D10 | D9 | D8 |
* |-----------------------------------------------------------------|
* | reserved | number of additional | max packet size |
* | (reset to 0) | transaction opportunities | (D10..D0) |
* | | per microframe | (continued) |
* | | (for high-speed isochronous | |
* | | and interrupt endpoints) | |
* '-----------------------------------------------------------------'
*
* - D12..D11 (additional transaction opportunities for each microframe
* specified by bInterval):
* 0b00 => none (1 transaction per microframe)
* => max packet size: 1..1024
* 0b01 => 1 additional (2 per microframe)
* => max packet size: 513..1024
* 0b10 => 2 additional (3 per microframe)
* => max packet size: 683..1024
* 0b11 => reserved
* - for high-speed isochronous and interrupt endpoints only. else reset to
* 0, and max packet size can be any allowed value (as defined in spec
* chapter 5)
*/
#define usb_endpoint_wMaxPacketSize(adtl_trans_ops, max_packet_size) \
( (uint16_t) (((adtl_trans_ops)<<11) | max_packet_size) )
// ----------------------------------------------------------------------------
/* - spec sec 9.6.7 (Standard USB Descriptor Definitions / String)
* - table 9-15 (String Descriptor Zero, Specifying Languages Supported by
* the Device)
*
* - string descriptors are optional. if a device does not support them, all
* references to them within all descriptors must be reset to 0 .
*
* - string descriptors use unicode encodings (as defined in version 3.0 of the
* unicode standard)
*
* - the strings may support multiple languages. when requesting a string
* descriptor, the requester specifies the desired language using a 16 bit
* language ID (LANGID) (defined by the USB-IF; see
* <http://www.usb.org/developers/docs.html>).
*
* - string index 0 for all languages returns a string descriptor that contains
* an array of two-byte LANGID codes supported by the device. USB devices
* that omit all string descriptors must not return an array of LANGID codes.
*/
struct usb_string_descriptor_zero {
uint8_t bLength;
/* value: N+2
* - the size of this descriptor in bytes (which equals the size of the
* array of LANGIDs (in bytes) plus two)
*/
uint8_t bDescriptorType;
/* value: constant
* - STRING Descriptor Type
*/
uint16_t (* wLANGID_ptr)[];
/* value: a pointer to the array of supported LANGID codes
* - note: these must be transmitted as part of the descriptor; a
* pointer is used here to avoid using variable length struct members
* + malloc()
*/
};
/* - spec sec 9.6.7 (Standard USB Descriptor Definitions / String)
* - table 9-16 (UNICODE String Descriptor)
*/
struct usb_string_descriptor {
uint8_t bLength;
/* value: number
* - the size of this descriptor in bytes (which equals the size of the
* string (in bytes) plus two)
*/
uint8_t bDescriptorType;
/* value: constant
* - STRING Descriptor Type
*/
uint8_t bString;
/* value: number
* - UNICODE encoded string
*/
};
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#pragma pack(pop)
#endif

View File

@ -7,23 +7,10 @@
* ------------------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>
#include <util/delay.h>
#include "./lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "./lib/key-functions/public.h"
#include "./keyboard/controller.h"
#include "./keyboard/layout.h"
#include "./keyboard/matrix.h"
#include "./main.h"
// ----------------------------------------------------------------------------
// TODO remove this; for now we'll just limit it to the number of layers
#define MAX_ACTIVE_LAYERS KB_LAYERS
// ----------------------------------------------------------------------------
static bool _main_kb_is_pressed[KB_ROWS][KB_COLUMNS];
bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS] = &_main_kb_is_pressed;

View File

@ -6,14 +6,16 @@
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#ifndef MAIN_h
#define MAIN_h
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "keyboard/layout.h"
#include "keyboard/matrix.h"
#include <util/delay.h>
#include "./lib-other/pjrc/usb_keyboard/usb_keyboard.h"
#include "./lib/key-functions/public.h"
#include "./keyboard/controller.h"
#include "./keyboard/layout.h"
#include "./keyboard/matrix.h"
// --------------------------------------------------------------------
@ -47,5 +49,3 @@ uint8_t main_layers_sticky (uint8_t layer);
void main_layers_enable (uint8_t layer, uint8_t sticky);
void main_layers_disable (uint8_t layer);
void main_layers_disable_top (void);
#endif