config.h
/*
Copyright 2012 Jun Wako <
wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <
http://www.gnu.org/licenses/>;.
*/
#ifndef CONFIG_H
#define CONFIG_H
/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x1111
#define DEVICE_VER 0x0001
#define MANUFACTURER CC
#define PRODUCT Onekey
#define DESCRIPTION CC keyboard firmware for GH60-CC
/* key matrix size */
#define MATRIX_ROWS 5
#define MATRIX_COLS 14
/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE
/* key combination for command */
#define IS_COMMAND() ( \
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
/* PS/2 mouse */
#ifdef PS2_USE_BUSYWAIT
# define PS2_CLOCK_PORT PORTD
# define PS2_CLOCK_PIN PIND
# define PS2_CLOCK_DDR DDRD
# define PS2_CLOCK_BIT 1
# define PS2_DATA_PORT PORTD
# define PS2_DATA_PIN PIND
# define PS2_DATA_DDR DDRD
# define PS2_DATA_BIT 2
#endif
/* PS/2 mouse interrupt version */
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1
#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 2
#define PS2_INT_INIT() do { \
EICRA |= ((1<<ISC11) | \
(0<<ISC10)); \
} while (0)
#define PS2_INT_ON() do { \
EIMSK |= (1<<INT1); \
} while (0)
#define PS2_INT_OFF() do { \
EIMSK &= ~(1<<INT1); \
} while (0)
#define PS2_INT_VECT INT1_vect
#endif
/* PS/2 mouse USART version */
#ifdef PS2_USE_USART
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
/* XCK for clock line and RXD for data line */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 5
#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 2
/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
#define PS2_USART_INIT() do { \
PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
UCSR1C = ((1 << UMSEL10) | \
(3 << UPM10) | \
(0 << USBS1) | \
(3 << UCSZ10) | \
(0 << UCPOL1)); \
UCSR1A = 0; \
UBRR1H = 0; \
UBRR1L = 0; \
} while (0)
#define PS2_USART_RX_INT_ON() do { \
UCSR1B = ((1 << RXCIE1) | \
(1 << RXEN1)); \
} while (0)
#define PS2_USART_RX_POLL_ON() do { \
UCSR1B = (1 << RXEN1); \
} while (0)
#define PS2_USART_OFF() do { \
UCSR1C = 0; \
UCSR1B &= ~((1 << RXEN1) | \
(1 << TXEN1)); \
} while (0)
#define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
#define PS2_USART_RX_DATA UDR1
#define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
#define PS2_USART_RX_VECT USART1_RX_vect
#endif
#endif
#endif
keymap_common_gh60_cc.h
#ifndef KEYMAP_COMMON_GH60_CC_H
#define KEYMAP_COMMON_GH60_CC_H
#include <stdint.h>
#include <stdbool.h>
#include "keycode.h"
#include "action.h"
#include "action_macro.h"
#include "report.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "keymap.h"
#define KEYMAP( \
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, \
K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \
K40, K41, K42, K45, K4A, K4B, K4C, K4D \
) { \
{ KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \
{ KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \
{ KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_NO, KC_##K2D }, \
{ KC_##K30, KC_NO, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \
{ KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_NO, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \
}
#endif
keymap_gh60_cc.c
#include "keymap_common_gh60_cc.h"
/*
* CC
*/
const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* MIT Layout (default)
*
* ,-------------------------------------------------------------------------------------.
* |ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | Backsp |
* |-------------------------------------------------------------------------------------|
* |Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ |
* |-------------------------------------------------------------------------------------|
* |Caps | A | S | D | F | G | H | J | K | L | ; | ' | Enter |
* |-------------------------------------------------------------------------------------|
* |Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Fn |
* |-------------------------------------------------------------------------------------|
* | Ctrl|Super| Alt | Space | Left | Down| Up |Right|
* `-------------------------------------------------------------------------------------'
*/
KEYMAP(
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
LCTL,A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, FN0, \
LCTL,LGUI,LALT, SPC, LEFT,DOWN,UP,RGHT),
/* MIT Layout (Fn)
*
* ,-------------------------------------------------------------------------------------.
* | ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12| prtscn |
* |-------------------------------------------------------------------------------------|
* |Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ |
* |-------------------------------------------------------------------------------------|
* |Caps | A | S | D | F | G | H | J | K | L | ; | ' | Enter |
* |-------------------------------------------------------------------------------------|
* |Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Fn |
* |-------------------------------------------------------------------------------------|
* | Ctrl| | Alt | | HOME| END |Insrt|Delt|
* `-------------------------------------------------------------------------------------'
*/
KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
TRNS, NO,TRNS, TRNS, HOME, END, INS,DELETE),
};
const action_t PROGMEM fn_actions[] = {
[0] = ACTION_LAYER_MOMENTARY(0),
[1] = ACTION_LAYER_MOMENTARY(1),
};
matrix_gh60_cc.c
/*
Copyright 2017 Jun Wako <
wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <" target="_blank">
http://www.gnu.org/licenses/>;.
*/
/*
* scan matrix
*/
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include "debug.h"
#include "timer.h"
#include "matrix.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
/* matrix state(1:on, 0:off) */
/*
static matrix_row_t row_debounced = 0;
static matrix_row_t row_debouncing = 0;
static bool debouncing = false;
static uint16_t debouncing_time = 0;
*/
static uint8_t debouncing = DEBOUNCE;
/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
static matrix_row_t read_cols(void);
static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);
/*
void matrix_init(void)
{
debug_enable = true;
debug_matrix = true;
debug_mouse = true;
// PB0: Input with pull-up(DDR:0, PORT:1)
DDRB &= ~(1<<0);
PORTB |= (1<<0);
}
*/
void matrix_init(void)
{
// initialize row and col
unselect_rows();
init_cols();
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
matrix
= 0;
matrix_debouncing = 0;
}
}
/*
uint8_t matrix_scan(void)
{
matrix_row_t r = (PINB&(1<<0) ? 0 : 1);
if (row_debouncing != r) {
row_debouncing = r;
debouncing = true;
debouncing_time = timer_read();
}
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
row_debounced = row_debouncing;
debouncing = false;
}
return 1;
}
*/
uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i);
_delay_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols();
if (matrix_debouncing != cols) {
matrix_debouncing = cols;
if (debouncing) {
debug("bounce!: "); debug_hex(debouncing); debug("\n");
}
debouncing = DEBOUNCE;
}
unselect_rows();
}
if (debouncing) {
if (--debouncing) {
_delay_ms(1);
} else {
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
matrix = matrix_debouncing;
}
}
}
return 1;
}
inline
matrix_row_t matrix_get_row(uint8_t row)
{
/*
return row_debounced;
*/
return matrix[row];
}
/*
Col: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Pin: D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 C2 C3 C4 C5
*/
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRD &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
PORTD |= (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
DDRC &= ~(1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);值为00000000&11000000=00000000
PORTC |= (1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);值为00000000|00111111=00111111
}
static matrix_row_t read_cols(void)
{
return (PIND&(1<<0) ? 0 : (1<<0)) |
(PIND&(1<<1) ? 0 : (1<<1)) |
(PIND&(1<<2) ? 0 : (1<<2)) |
(PIND&(1<<3) ? 0 : (1<<3)) |
(PIND&(1<<4) ? 0 : (1<<4)) |
(PIND&(1<<5) ? 0 : (1<<5)) |
(PIND&(1<<6) ? 0 : (1<<6)) |
(PIND&(1<<7) ? 0 : (1<<7)) |
(PINC&(1<<0) ? 0 : (1<<8)) |
(PINC&(1<<1) ? 0 : (1<<9)) |
(PINC&(1<<2) ? 0 : (1<<10)) |
(PINC&(1<<3) ? 0 : (1<<11)) |
(PINC&(1<<4) ? 0 : (1<<12)) |
(PINC&(1<<5) ? 0 : (1<<13));
}
/*
Row: 1 2 3 4 5
Pin: C6 C7 A7 A6 A5
*/
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRC &= ~0b11000000;//初始化后的值(执行过一遍init cols后)等于01000000&00111111=00000000:case0;等于10000000&00111111=00000000:case1,初始值为:00000000&00111111=00000000
PORTC &= ~0b11000000;//初始化后的值(执行过一遍init cols后)等于00111111&00111111=00111111:case0;等于00111111&00111111=00111111:case1,初始值为:00000000&00111111=00000000
DDRA &= ~0b11100000;//初始化后的值(执行过一遍init cols后)等于10000000&00011111=00000000:case2;等于01000000&00011111=00000000:case3;等于00100000&00011111=00000000:case4,初始值为:00000000&00011111=00000000
PORTA &= ~0b11100000;//初始化后的值(执行过一遍init cols后)等于00000000&00011111=00000000:case2;等于00000000&00011111=00000000:case3;等于00000000&00011111=00000000:case4,初始值为:00000000&00011111=00000000
}
static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
switch (row) {
case 0:
DDRC |= (1<<6);//等于00000000|01000000=01000000:case0;
PORTC &= ~(1<<6);//等于00111111&10111111=00111111:case0;
break;
case 1:
DDRC |= (1<<7);//等于00000000|10000000=10000000:case1;
PORTC &= ~(1<<7);//等于00111111&01111111=00111111:case1;
break;
case 2:
DDRA |= (1<<7);//等于00000000|10000000=10000000
PORTA &= ~(1<<7);//等于00000000|01111111=00000000
break;
case 3:
DDRA |= (1<<6);//等于00000000|01000000=01000000
PORTA &= ~(1<<6);//等于00000000|10111111=00000000
break;
case 4:
DDRA |= (1<<5);//等于00000000|00100000=00100000
PORTA &= ~(1<<5);//等于00000000|11011111=00000000
break;
}
}
由于单片机芯片每次只能扫描一种状态(每大端口(C端口或C组端口):比如C,而不是C0~7中的小端口如:C1端口),切换状态需要使用Hiz(又称三态Or高阻态),如果不用高阻态重置状态就会出现处理器无法理解到底是新的(行:row的)高电平还是旧的(列:col的)高电平没变
--------------------------------------------------------------------------------
matrix_gh60_cc.c
/*
Copyright 2017 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <" target="_blank">http://www.gnu.org/licenses/>;.
*/
/*
* scan matrix
*/
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <util/delay.h>
#include "print.h"
#include "debug.h"
#include "util.h"
#include "matrix.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
/* matrix state(1:on, 0:off) */
/*
static matrix_row_t row_debounced = 0;
static matrix_row_t row_debouncing = 0;
static bool debouncing = false;
static uint16_t debouncing_time = 0;
*/
static uint8_t debouncing = DEBOUNCE;
/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
static matrix_row_t read_cols(void);
static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);
/*
void matrix_init(void)
{
debug_enable = true;
debug_matrix = true;
debug_mouse = true;
// PB0: Input with pull-up(DDR:0, PORT:1)
DDRB &= ~(1<<0);
PORTB |= (1<<0);
}
*/
void matrix_init(void)
{
// initialize row and col
unselect_rows();
init_cols();
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
matrix = 0;
matrix_debouncing = 0;
}
}
/*
uint8_t matrix_scan(void)
{
matrix_row_t r = (PINB&(1<<0) ? 0 : 1);
if (row_debouncing != r) {
row_debouncing = r;
debouncing = true;
debouncing_time = timer_read();
}
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
row_debounced = row_debouncing;
debouncing = false;
}
return 1;
}
*/
uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i);
_delay_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols();
if (matrix_debouncing != cols) {
matrix_debouncing = cols;
if (debouncing) {
debug("bounce!: "); debug_hex(debouncing); debug("\n");
}
debouncing = DEBOUNCE;
}
unselect_rows();
}
if (debouncing) {
if (--debouncing) {
_delay_ms(1);
} else {
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
matrix[i] = matrix_debouncing[i];
}
}
}
return 1;
}
inline
matrix_row_t matrix_get_row(uint8_t row)
{
/*
return row_debounced;
*/
return matrix[row];
}
/*
Col: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Pin: D0 D1 D2 D3 D4 D5 D6 D7 C0 C1 C2 C3 C4 C5
*/
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRD &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
PORTD |= (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
DDRC &= ~(1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
PORTC |= (1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}
static matrix_row_t read_cols(void)
{
return (PIND&(1<<0) ? 0 : (1<<0)) |
(PIND&(1<<1) ? 0 : (1<<1)) |
(PIND&(1<<2) ? 0 : (1<<2)) |
(PIND&(1<<3) ? 0 : (1<<3)) |
(PIND&(1<<4) ? 0 : (1<<4)) |
(PIND&(1<<5) ? 0 : (1<<5)) |
(PIND&(1<<6) ? 0 : (1<<6)) |
(PIND&(1<<7) ? 0 : (1<<7)) |
(PINC&(1<<0) ? 0 : (1<<8)) |
(PINC&(1<<1) ? 0 : (1<<9)) |
(PINC&(1<<2) ? 0 : (1<<10)) |
(PINC&(1<<3) ? 0 : (1<<11)) |
(PINC&(1<<4) ? 0 : (1<<12)) |
(PINC&(1<<5) ? 0 : (1<<13));
}
/*
Row: 1 2 3 4 5
Pin: C6 C7 A7 A6 A5
*/
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRC &= ~0b11000000;
PORTC &= ~0b11000000;
DDRA &= ~0b11100000;
PORTA &= ~0b11100000;
}
static void select_row(uint8_t row)
{
// Output low(DDR:1, PORT:0) to select
switch (row) {
case 0:
DDRC |= (1<<6);
PORTC &= ~(1<<6);
break;
case 1:
DDRC |= (1<<7);
PORTC &= ~(1<<7);
break;
case 2:
DDRA |= (1<<7);
PORTA &= ~(1<<7);
break;
case 3:
DDRA |= (1<<6);
PORTA &= ~(1<<6);
break;
case 4:
DDRA |= (1<<5);
PORTA &= ~(1<<5);
break;
}
}
--------------------------------------------------------------------------------
Makefile
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device.
# Please customize your programmer settings(PROGRAM_CMD)
#
# make teensy = Download the hex file to the device, using teensy_loader_cli.
# (must have teensy_loader_cli installed).
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
# (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
# (must have Atmel FLIP installed).
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# Target file name (without extension).
TARGET = gh60_cc
# Directory common source filess exist
TMK_DIR = ../../tmk_core
# Directory keyboard dependent files exist
TARGET_DIR = .
# project specific files
SRC = keymap_gh60_cc.c \
matrix_gh60_cc.c \
led_gh60_cc.c
CONFIG_H = config.h
# MCU name
#MCU = at90usb1287
#MCU = atmega32u4
MCU = at90usb1286
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
#
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
# differ from F_CPU if prescaling is used on the latter, and is required as the
# raw input clock is fed directly to the PLL sections of the AVR for high speed
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
# at the end, this will be done automatically to create a 32-bit value in your
# source code.
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Boot Section Size in *bytes*
# Teensy halfKay 512
# Teensy++ halfKay 1024
# Atmel DFU loader 4096
# LUFA bootloader 4096
# USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=8192
# Build Options
# comment out to disable the options.
#
#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
#MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
#EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = yes # Console for debug(+400)
#COMMAND_ENABLE = yes # Commands for debug and configuration
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes # USB Nkey Rollover
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
#PS2_USE_BUSYWAIT = yes # uses primitive reference code
#PS2_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin
#PS2_USE_USART = yes # uses hardware USART engine for PS/2 signal receive(recomened)
# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TMK_DIR)
include $(TMK_DIR)/common.mk
include $(TMK_DIR)/protocol.mk
include $(TMK_DIR)/protocol/lufa.mk
include $(TMK_DIR)/rules.mk
led_gh60_cc.c
/*
Copyright 2012 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <" target="_blank">http://www.gnu.org/licenses/>;.
*/
#include <avr/io.h>
#include "stdint.h"
#include "led.h"
/*
LED Col 1:PB0
LED Col 2:PB1
LED Col 3:PB2
LED Col 4:PB3
LED Col 5:PB4
LED Col 6:PB5
LED Col 7:PB6
LED Col 8:PB7
LED Col 9:PF0
LED Col 10:PF1
LED Col 11:PF2
LED Col 12:PF3
LED Col 13:PF4
LED Col 14:PF5
*/
/*
LED Row 1:PA1
LED Row 2:PA2
LED Row 3:PA3
*/
void led_set(uint8_t usb_led)
{
/* if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
// output low
DDRB |= (1<<2);
PORTB &= ~(1<<2);
} else {
// Hi-Z
DDRB &= ~(1<<2);
PORTB &= ~(1<<2);
}
*/
}
cygwin -bash:make: 未找到命令:
重新点击我们的安装包
在选择保的时候,展开Devel
在里面找到make,然后,Bin 和 Src 如果可以勾选都 勾选上,点击下一步就可以安装了
Using the GNU AVR toolchain on Windows 10(不设置无法编译出键盘.hex文件,编译时会cgwin提示缺少avr-gcc,
而这个包是不在包管理器里的)
Table of Contents
Introduction
Install Git
Install the Atmel GNU Toolchain
Install GNU Make
Install avrdude
Update your PATH
Install Drivers for your Programmer
Sanity Check
Introduction
This page attempts to describe a procedure for installing a complete GCC-based toolchain on a modern Windows system. I've developed these instructions on my Windows 10 machine, but they should work for versions of Windows as far back as Windows 7. On older versions, you might want to use WinAVR. WinAVR used to be the preferred way to get this toolchain set up on Windows, even to the point of being semi-official, but has not been maintained in years. The installer reportedly wreaks havoc on newer Windows versions, but it likely works great on XP.
Install Git
We're going to use the bash shell installed by Git as our starting point. It's easy to install, and if you're using
Git on Windows, you might have it already. Click the Start menu and search for "Git Bash". If it comes up, you have it already. If not, download and install Git for Windows. The defaults for all of the choices in the installer will work for our purposes.
Install the Atmel GNU Toolchain
Download the Atmel AVR Toolchain for Windows from Atmel's site and run the installer. When asked where to extract the files, click the "..." button and navigate to C:\Program Files, then click Extract.
- toolchain_install.png (3.99 KiB) 查看 16130 次
Install GNU Make
Download Gnu Make and launch the installer. Accept the default location for the installation. You can choose whether or not you want an icon in your start menu.
Install avrdude
Download avrdude
. Unzip the archive, and copy the archive inside to C:\Program Files.
Update your PATH
Now we need to tell Windows where to locate all of the tools you've just installed when you type their names on the command line. Go to the Start menu and open the Control Panel, then go to System. From the left pane, choose "Advanced System Settings". Under the Advanced tab, click the "Environment Variables" button.
Under User variables, select "Path" and click the Edit button. If you don't already have a variable called "Path", click the New button to create it, enter "Path" without the name, and fill out the value as described below.
The Edit window that pops up is unfortunately different depending on whether you are creating a new variable or only have one item in your path, or if you have multiple items in your path already. In the first two cases, you just get a textbox for a value. In the third case, you get a list of values. Either way, you want to add the following three values. If you get the list, add them as separate items (see screenshot below). If you get the textbox, enter them separated by semicolons. Make sure that they are entered exactly or Windows won't be able to find the programs.
The three values to add are:
C:\Program Files\avr8-gnu-toolchain\bin
C:\Program Files (x86)\GnuWin32\bin
C:\Program Files\avrdude
Click OK on all of the windows you've opened.
Install Drivers for your Programmer
This tutorial assumes you are going to use a FabISP, FabTinyStarISP, or other USBtiny-based programmer. If you are using one of the official Atmel programmers instead, the easiest way to get the drivers is to install Atmel Studio.
The USBtiny programmers use a generic libusb driver, but Windows 10's driver signing policy makes the installation more complicated. Fortunately, there's a tool that helps with this. Download Zadig and launch it. Plug in your programmer, and select the "USBtinySPI" device in the list. (If it doesn't show up, go to the Options menu and click "List All Devices". The driver you want to install (to the right of the green arrow) is either libusb-win32 or libusb0. Click the "Install Driver" button. You should only have to do this once.
Sanity Check
Everything is now installed. Let's check that it all works.
Go to the start menu and search for "Git Bash" and start it. When you see instructions telling you to open your terminal in other tutorials, this is the terminal window you should use.
Check to make sure that the commands we installed work okay:
make
Type make -v and press enter. You should see:
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
... and so on.
If you get a "command not found" error instead, re-check your installation of make and your path variable setting for typos.
avr-gcc
Type avr-gcc --version and press enter. You should see:
avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 4.9.2
... and so on.
If you get a "command not found" error instead, re-check your installation of the Atmel toolchain and your path variable setting for typos.
avrdude
Connect your programmer to a USB port and type: avrdude -c usbtiny -p t45 and press enter. You should see:
avrdude.exe: initialization failed, rc=-1
...
This means that avrdude successfully found your programmer, but failed to talk to a target board (expected because we don't have anything conencted to the programmer right now.)
If instead you see:
avrdude.exe: Error: Could not find USBtiny device (0x1781/0xc9f)
check your USB driver installation (the Zadig steps).
If you get a "command not found" error, check your installation of avrdude and your path variable.
Yay!
You should be ready to go!
打开cgwin并输入:
cd 'C:\Users\Anti Chen\Documents\tmk_keyboard-master\keyboard\onekey'
make -f Makefile clean
make -f Makefile
Git for windows的安装
下载:访问网站下载最新版的git版本
安装:点击”next“,转到步骤3
安装地址:可以更改也可以直接使用默认的
将Additional icons中的On the Desktop勾上;
将Windows Explorer integration选项中的“Git Bash here”和“Git GUI here”勾上。
在“Adjusting your PATH environment”选项中,选择默认即可。
在Choosing HTTPS transport backend 中选择默认。
在“Configuring the line ending conversions”选项中,第一个选项:如果是跨平台项目,在windows系统安装,选择;第二个选项:如果是跨平台项目,在Unix系统安装,选择;第三个选项:非跨平台项目,选择。
在Configuring the terminal emulator to use with Git Bash中选择默认
在Configuring extra options中选择默认,
然后点击“Install”开始安装。如果之前安装过旧版本,会先卸载然后再安装新版本。
安装完成后点击“finish”即可
桌面上或者开始菜单找到Git Bash 双击打开即可开始愉快的Git之旅了
从https://
www.pjrc.com/teensy/loader_cli.html下载Windows binary (于C盘根目录解压放置exe)
然后在系统环境变量里加入C盘根目录就行了,就可以
cd 'C:\Users\Anti Chen\Documents\tmk_keyboard-master\keyboard\onekey'
make -f Makefile teensy,然后按reset烧录了