Skip to content

Commit

Permalink
onekey: Fix for V-USB of ATtiny85 and key scan
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Sep 14, 2017
1 parent 45f6e5c commit 4dc2fb5
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 140 deletions.
2 changes: 1 addition & 1 deletion keyboard/onekey/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TARGET_DIR = .

# project specific files
SRC = keymap.c \
matrix.c \
onekey.c \
led.c

CONFIG_H = config.h
Expand Down
2 changes: 1 addition & 1 deletion keyboard/onekey/Makefile.pjrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TARGET_DIR = .

# project specific files
SRC = keymap.c \
matrix.c \
onekey.c \
led.c

CONFIG_H = config.h
Expand Down
10 changes: 8 additions & 2 deletions keyboard/onekey/Makefile.vusb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET_DIR = .

# keyboard dependent files
SRC = keymap.c \
matrix.c \
onekey.c \
led.c

CONFIG_H = config.h
Expand All @@ -18,7 +18,8 @@ CONFIG_H = config.h
# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
#MCU = atmega168p
MCU = atmega328p
#MCU = atmega328p
MCU = attiny85


# Processor frequency.
Expand All @@ -35,6 +36,11 @@ F_CPU = 12000000
#MOUSEKEY_ENABLE = yes # Mouse keys
#EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
NO_UART = yes # No UART debug(V-USB)

OPT_DEFS += -DNO_ACTION_TAPPING
OPT_DEFS += -DNO_ACTION_LAYER
OPT_DEFS += -DNO_ACTION_MACRO



Expand Down
2 changes: 1 addition & 1 deletion keyboard/onekey/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Onekey
======
Just one key keyboard for example. It sends 'a' key if pins PB0 and PB1 are short-circuited.
Just one key keyboard for example. It sends 'a' key if pins PB0 and GND are short-circuited.

https://github.com/tmk/tmk_keyboard/issues/56
133 changes: 0 additions & 133 deletions keyboard/onekey/matrix.c

This file was deleted.

70 changes: 70 additions & 0 deletions keyboard/onekey/onekey.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2017 Jun Wako <[email protected]>
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/>.
*/

/*
* 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;


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);
}

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;
}

inline
matrix_row_t matrix_get_row(uint8_t row)
{
return row_debounced;
}
4 changes: 2 additions & 2 deletions keyboard/onekey/usbconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ section at the end of this file).

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
#define USB_CFG_IOPORTNAME B
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
#define USB_CFG_DMINUS_BIT 3
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
Expand Down

0 comments on commit 4dc2fb5

Please sign in to comment.