1
0

Impement led matrix for GH60 rev.CNY

This commit is contained in:
Kai Ryu 2014-01-14 16:13:01 +09:00
parent 2e30e38479
commit 91d22894b0
5 changed files with 106 additions and 7 deletions

View File

@ -51,7 +51,8 @@ TARGET_DIR = .
SRC = keymap_common.c \
matrix.c \
led.c \
backlight.c
backlight.c \
led_matrix.c
ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC)

View File

@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/pgmspace.h>
#include "backlight.h"
#ifdef GH60_REV_CHN
#if defined(GH60_REV_CHN)
static const uint8_t backlight_table[] PROGMEM = {
0, 16, 128, 255
};
@ -51,6 +51,26 @@ void backlight_set(uint8_t level)
OCR1B = 0;
}
}
#elif #defined(GH60_REV_CNY)
static const uint8_t backlight_table[] PROGMEM = {
0, 16, 128, 255
};
void backlight_set(uint8_t level)
{
if (level > 0) {
led_matrix_disable();
for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) {
for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) {
led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level]));
}
}
led_matrix_enable();
}
else {
led_matrix_disable();
}
}
#else
void backlight_set(uint8_t level)
{

View File

@ -43,16 +43,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* number of backlight levels */
#if defined(GH60_REV_CHN)
#define BACKLIGHT_LEVELS 3
# define BACKLIGHT_LEVELS 3
#elif defined(GH60_REV_CNY)
#define BACKLIGHT_LEVELS 3
# define BACKLIGHT_LEVELS 3
#else
#define BACKLIGHT_LEVELS 1
# define BACKLIGHT_LEVELS 1
#endif
#ifdef GH60_REV_CNY
#define LED_MATRIX_ROWS 6
#define LED_MATRIX_COLS 14
# define LED_MATRIX_ROWS 6
# define LED_MATRIX_COLS 14
#endif
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */

View File

@ -15,3 +15,78 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include "led_matrix.h"
#if defined(GH60_REV_CNY)
/* LED Column pin configuration
* pin: F0 F1 E6 C7 C6 B7 D4 B0 B1 B5 B4 D7 D6 B3 (Rev.CNY)
*/
void led_matrix_write_cols(led_matrix_row_t cols)
{
(cols & (1<<0)) ? (PORTF |= (1<<PF0)) : (PORTF &= ~(1<<PF0));
(cols & (1<<1)) ? (PORTF |= (1<<PF1)) : (PORTF &= ~(1<<PF1));
(cols & (1<<2)) ? (PORTE |= (1<<PE6)) : (PORTE &= ~(1<<PE6));
(cols & (1<<3)) ? (PORTC |= (1<<PC7)) : (PORTC &= ~(1<<PC7));
(cols & (1<<4)) ? (PORTC |= (1<<PC6)) : (PORTC &= ~(1<<PC6));
(cols & (1<<5)) ? (PORTB |= (1<<PB7)) : (PORTB &= ~(1<<PB7));
(cols & (1<<6)) ? (PORTD |= (1<<PD4)) : (PORTD &= ~(1<<PD4));
(cols & (1<<7)) ? (PORTB |= (1<<PB0)) : (PORTB &= ~(1<<PB0));
(cols & (1<<8)) ? (PORTB |= (1<<PB1)) : (PORTB &= ~(1<<PB1));
(cols & (1<<9)) ? (PORTB |= (1<<PB5)) : (PORTB &= ~(1<<PB5));
(cols & (1<<10)) ? (PORTB |= (1<<PB4)) : (PORTB &= ~(1<<PB4));
(cols & (1<<11)) ? (PORTD |= (1<<PD7)) : (PORTD &= ~(1<<PD7));
(cols & (1<<12)) ? (PORTD |= (1<<PD6)) : (PORTD &= ~(1<<PD6));
(cols & (1<<13)) ? (PORTB |= (1<<PB3)) : (PORTB &= ~(1<<PB3));
}
/* LED Row pin configuration
* row: 0 1 2 3 4 5
* pin: B6 F5 F6 F7 F4 B2
*/
void led_matrix_unselect_rows(void)
{
// bit 76543210
DDRB &= ~0b01000100;
PORTB &= ~0b01000100;
// bit 76543210
DDRF &= ~0b11110000;
PORTF &= ~0b11110000;
}
/* LED Row pin configuration
* row: 0 1 2 3 4 5
* pin: B6 F5 F6 F7 F4 B2
*/
void led_matrix_select_row(uint8_t row)
{
switch (row) {
case 0:
DDRB |= (1<<PB6);
PORTB |= (1<<PB6);
break;
case 1:
DDRF |= (1<<PF5);
PORTF |= (1<<PF5);
break;
case 2:
DDRF |= (1<<PF6);
PORTF |= (1<<PF6);
break;
case 3:
DDRF |= (1<<PF7);
PORTF |= (1<<PF7);
break;
case 4:
DDRF |= (1<<PF4);
PORTF |= (1<<PF4);
break;
case 5:
DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
break;
}
}
#endif

View File

@ -76,6 +76,9 @@ uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i);
#ifdef HYBRID_MATRIX
init_cols();
#endif
_delay_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols();
if (matrix_debouncing[i] != cols) {