- Very small updates to files, mostly modifying to remove name duplicationssimple
/* Copyright (C) 2011 by Jacob Alexander | |||||
/* Copyright (C) 2011-2013 by Jacob Alexander | |||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
* of this software and associated documentation files (the "Software"), to deal | * of this software and associated documentation files (the "Software"), to deal | ||||
// USB HID String Output | // USB HID String Output | ||||
void usb_debug_putstr( char* s ) | void usb_debug_putstr( char* s ) | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR | |||||
while ( *s != '\0' ) | while ( *s != '\0' ) | ||||
usb_debug_putchar( *s++ ); | usb_debug_putchar( *s++ ); | ||||
#elif defined(_mk20dx128_) // ARM | |||||
// Count characters until NULL character, then send the amount counted | |||||
uint32_t count = 0; | |||||
while ( s[count] != '\0' ) | |||||
count++; | |||||
usb_serial_write( s, count ); | |||||
#endif | |||||
} | } | ||||
// Multiple string Output | // Multiple string Output | ||||
// Print a constant string | // Print a constant string | ||||
void _print(const char *s) | void _print(const char *s) | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR | |||||
char c; | char c; | ||||
// Acquire the character from flash, and print it, as long as it's not NULL | // Acquire the character from flash, and print it, as long as it's not NULL | ||||
usb_debug_putchar('\r'); | usb_debug_putchar('\r'); | ||||
usb_debug_putchar(c); | usb_debug_putchar(c); | ||||
} | } | ||||
#elif defined(_mk20dx128_) // ARM | |||||
usb_debug_putstr( (char*)s ); | |||||
#endif | |||||
} | } | ||||
#elif defined(_mk20dx128_) | #elif defined(_mk20dx128_) | ||||
#include "arm/usb_keyboard.h" | |||||
#include "arm/usb_serial.h" | |||||
#endif | #endif | ||||
// Additional includes should only be added to this file if they should be added to *all* Macro modules. | // Additional includes should only be added to this file if they should be added to *all* Macro modules. | ||||
// ----- Includes ----- | |||||
#ifndef __MACROLIB_H | #ifndef __MACROLIB_H | ||||
#define __MACROLIB_H | #define __MACROLIB_H | ||||
// ----- Includes ----- | |||||
#include <Lib/Interrupts.h> | |||||
// ARM | // ARM | ||||
#if defined(_mk20dx128_) | #if defined(_mk20dx128_) | ||||
// AVR | // AVR | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
#include <avr/interrupt.h> | |||||
#include <util/delay.h> | #include <util/delay.h> | ||||
#endif | #endif |
// Additional includes should only be added to this file if they should be added to *all* Scan modules. | // Additional includes should only be added to this file if they should be added to *all* Scan modules. | ||||
#ifndef __MAINLIB_H | |||||
#define __MAINLIB_H | |||||
// ----- Includes ----- | // ----- Includes ----- | ||||
#ifndef __MACROLIB_H | |||||
#define __MACROLIB_H | |||||
#include <Lib/Interrupts.h> | |||||
// ARM | // ARM | ||||
#if defined(_mk20dx128_) | #if defined(_mk20dx128_) | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
#include <avr/io.h> | #include <avr/io.h> | ||||
#include <avr/interrupt.h> | |||||
#endif | #endif | ||||
// Additional includes should only be added to this file if they should be added to *all* Scan modules. | // Additional includes should only be added to this file if they should be added to *all* Scan modules. | ||||
// ----- Includes ----- | |||||
#ifndef __SCANLIB_H | #ifndef __SCANLIB_H | ||||
#define __SCANLIB_H | #define __SCANLIB_H | ||||
// ----- Includes ----- | |||||
#include <Lib/Interrupts.h> | |||||
// ARM | // ARM | ||||
#if defined(_mk20dx128_) | #if defined(_mk20dx128_) | ||||
// AVR | // AVR | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) | ||||
#include <avr/interrupt.h> | |||||
#include <avr/io.h> | #include <avr/io.h> | ||||
#include <util/delay.h> | #include <util/delay.h> | ||||
// Additional includes should only be added to this file if they should be added to *all* Scan modules. | // Additional includes should only be added to this file if they should be added to *all* Scan modules. | ||||
// ----- Includes ----- | |||||
#ifndef __USBLIB_H | |||||
#define __USBLIB_H | |||||
#ifndef __MACROLIB_H | |||||
#define __MACROLIB_H | |||||
// ----- Includes ----- | |||||
// ARM | // ARM | ||||
#if defined(_mk20dx128_) | #if defined(_mk20dx128_) |
void jumpToBootloader(void) | void jumpToBootloader(void) | ||||
{ | { | ||||
#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR | |||||
cli(); | cli(); | ||||
// disable watchdog, if enabled | // disable watchdog, if enabled | ||||
// disable all peripherals | // disable all peripherals | ||||
PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; | PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; | ||||
asm volatile("jmp 0x1FC00"); | asm volatile("jmp 0x1FC00"); | ||||
#endif | #endif | ||||
#endif | |||||
} | } | ||||
// Given a sampling array, and the current number of detected keypress | // Given a sampling array, and the current number of detected keypress |
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Key Settings ----- | // ----- Key Settings ----- | ||||
#define KEYBOARD_SIZE 16 // # of keys | |||||
#define KEYBOARD_KEYS 16 // # of keys | |||||
#define MAX_ROW_SIZE 16 // # of keys in the largest row | #define MAX_ROW_SIZE 16 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 1 // # of keys in the largest column | #define MAX_COL_SIZE 1 // # of keys in the largest column | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
inline void scan_setup() | inline void scan_setup() | ||||
{ | { | ||||
// Setup the the USART interface for keyboard data input | // Setup the the USART interface for keyboard data input | ||||
// NOTE: The input data signal needs to be inverted for the Teensy USART to properly work | |||||
// Setup baud rate | // Setup baud rate | ||||
// 16 MHz / ( 16 * Baud ) = UBRR | // 16 MHz / ( 16 * Baud ) = UBRR |
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x7F // 127 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Key Settings ----- | // ----- Key Settings ----- | ||||
#define KEYBOARD_SIZE 63 // # of keys | |||||
#define KEYBOARD_KEYS 63 // # of keys | |||||
#define MAX_ROW_SIZE 12 // # of keys in the largest row | #define MAX_ROW_SIZE 12 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 9 // # of keys in the largest column | #define MAX_COL_SIZE 9 // # of keys in the largest column | ||||
// ----- Key Settings ----- | // ----- Key Settings ----- | ||||
#define KEYBOARD_SIZE 90 // # of keys (It actually has 78, but there are markings up to 81 on the PCB and scan lines enough for 90 | |||||
#define KEYBOARD_KEYS 90 // # of keys (It actually has 78, but there are markings up to 81 on the PCB and scan lines enough for 90 | |||||
#define MAX_ROW_SIZE 6 // # of rows | #define MAX_ROW_SIZE 6 // # of rows | ||||
#define MAX_COL_SIZE 15 // # of columns | #define MAX_COL_SIZE 15 // # of columns | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x4c // 76 - Size of the array space for the keyboardr(max index) | |||||
#define KEYBOARD_KEYS 0x4c // 76 - Size of the array space for the keyboardr(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x62 // 98 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x62 // 98 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Key Settings ----- | // ----- Key Settings ----- | ||||
#define KEYBOARD_SIZE 85 // # of keys (It actually has 66, but there are markings up to 80 on the PCB); 85 due to there being 5 "switch" keys, that have no numbers | |||||
#define KEYBOARD_KEYS 85 // # of keys (It actually has 66, but there are markings up to 80 on the PCB); 85 due to there being 5 "switch" keys, that have no numbers | |||||
#define MAX_ROW_SIZE 9 // # of keys in the largest row | #define MAX_ROW_SIZE 9 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 9 // # of keys in the largest column | #define MAX_COL_SIZE 9 // # of keys in the largest column | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0xFF // 255 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0xFF // 255 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x5A // 90 - Size of the array space for the keyboardr(max index) | |||||
#define KEYBOARD_KEYS 0x5A // 90 - Size of the array space for the keyboardr(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// ----- Defines ----- | // ----- Defines ----- | ||||
#define KEYBOARD_SIZE 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_KEYS 0x68 // 104 - Size of the array space for the keyboard(max index) | |||||
#define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | #define KEYBOARD_BUFFER 24 // Max number of key signals to buffer | ||||
// -- Example for scanCol -- | // -- Example for scanCol -- | ||||
/* | /* | ||||
#define KEYBOARD_SIZE 16 // # of keys | |||||
#define KEYBOARD_KEYS 16 // # of keys | |||||
#define MAX_ROW_SIZE 16 // # of keys in the largest row | #define MAX_ROW_SIZE 16 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 1 // # of keys in the largest column | #define MAX_COL_SIZE 1 // # of keys in the largest column | ||||
*/ | */ | ||||
// -- Example for scanRow -- | // -- Example for scanRow -- | ||||
/* | /* | ||||
#define KEYBOARD_SIZE 16 // # of keys | |||||
#define KEYBOARD_KEYS 16 // # of keys | |||||
#define MAX_ROW_SIZE 1 // # of keys in the largest row | #define MAX_ROW_SIZE 1 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 16 // # of keys in the largest column | #define MAX_COL_SIZE 16 // # of keys in the largest column | ||||
*/ | */ | ||||
// -- Example for scanRow_powrCol, scanCol_powrRow, and scanDual -- | // -- Example for scanRow_powrCol, scanCol_powrRow, and scanDual -- | ||||
/* | /* | ||||
#define KEYBOARD_SIZE 69 // # of keys | |||||
#define KEYBOARD_KEYS 69 // # of keys | |||||
#define MAX_ROW_SIZE 8 // # of keys in the largest row | #define MAX_ROW_SIZE 8 // # of keys in the largest row | ||||
#define MAX_COL_SIZE 9 // # of keys in the largest column | #define MAX_COL_SIZE 9 // # of keys in the largest column | ||||
*/ | */ |
// This is where the matrix scan data is held, as well as debouncing is evaluated to, which (depending on the read value) is handled | // This is where the matrix scan data is held, as well as debouncing is evaluated to, which (depending on the read value) is handled | ||||
// by the macro module | // by the macro module | ||||
uint8_t KeyIndex_Array[KEYBOARD_SIZE + 1]; | |||||
uint8_t KeyIndex_Array[KEYBOARD_KEYS + 1]; | |||||
// NOTE: Highest Bit: Valid keypress (0x80 is valid keypress) | // NOTE: Highest Bit: Valid keypress (0x80 is valid keypress) | ||||
// Other Bits: Pressed state sample counter | // Other Bits: Pressed state sample counter | ||||
extern uint8_t KeyIndex_Array [KEYBOARD_SIZE + 1]; | |||||
static const uint8_t KeyIndex_Size = KEYBOARD_SIZE; | |||||
extern uint8_t KeyIndex_Array [KEYBOARD_KEYS + 1]; | |||||
static const uint8_t KeyIndex_Size = KEYBOARD_KEYS; | |||||
extern volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER]; | extern volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER]; | ||||
extern volatile uint8_t KeyIndex_BufferUsed; | extern volatile uint8_t KeyIndex_BufferUsed; |
arm/usb_dev.c | arm/usb_dev.c | ||||
arm/usb_keyboard.c | arm/usb_keyboard.c | ||||
arm/usb_mem.c | arm/usb_mem.c | ||||
arm/usb_serial.c | |||||
) | ) | ||||
endif ( ${COMPILER_FAMILY} MATCHES "avr" ) | endif ( ${COMPILER_FAMILY} MATCHES "avr" ) |
#include "avr/usb_keyboard_debug.h" | #include "avr/usb_keyboard_debug.h" | ||||
#elif defined(_mk20dx128_) | #elif defined(_mk20dx128_) | ||||
#include "arm/usb_keyboard.h" | #include "arm/usb_keyboard.h" | ||||
#include "arm/usb_dev.h" | |||||
#endif | #endif | ||||
// Local Includes | // Local Includes |
// You can change these to give your code its own name. | // You can change these to give your code its own name. | ||||
// TODO Add to Teensy 3 | |||||
#define STR_MANUFACTURER L"MfgName" | #define STR_MANUFACTURER L"MfgName" | ||||
#define STR_PRODUCT L"Keyboard" | #define STR_PRODUCT L"Keyboard" | ||||
// INF file is needed to load the driver. These numbers need to | // INF file is needed to load the driver. These numbers need to | ||||
// match the INF file. | // match the INF file. | ||||
#define VENDOR_ID 0x16C0 | #define VENDOR_ID 0x16C0 | ||||
#define PRODUCT_ID 0x047D | |||||
#define PRODUCT_ID 0x0487 // New ID for Teensy 3 | |||||
//#define PRODUCT_ID 0x047D // Old ID for Teensy 2 | |||||
#| Mostly for convenience functions like interrupt handlers | #| Mostly for convenience functions like interrupt handlers | ||||
set( COMPILER_SRCS | set( COMPILER_SRCS | ||||
Lib/${CHIP}.c | Lib/${CHIP}.c | ||||
Lib/delay.c | |||||
) | ) | ||||