news: Add LED support
This commit is contained in:
parent
6d577b33b7
commit
b7188acd4f
6 changed files with 82 additions and 35 deletions
|
|
@ -9,7 +9,6 @@ TARGET_DIR = .
|
|||
|
||||
# keyboard dependent files
|
||||
SRC = matrix.c \
|
||||
led.c \
|
||||
tone.c \
|
||||
news.c
|
||||
|
||||
|
|
@ -71,7 +70,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
|||
# Build Options
|
||||
# *Comment out* to disable the options.
|
||||
#
|
||||
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
|
||||
#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
|
||||
CONSOLE_ENABLE = yes # Console for debug
|
||||
|
|
|
|||
|
|
@ -54,8 +54,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
# define NEWS_KBD_RX_INIT() do { \
|
||||
UBRR1L = (uint8_t) NEWS_KBD_RX_UBBR; \
|
||||
UBRR1H = (uint8_t) (NEWS_KBD_RX_UBBR>>8); \
|
||||
UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); \
|
||||
UCSR1B |= (1<<RXCIE1) | (1<<RXEN1) | (1<<TXEN1); \
|
||||
sei(); \
|
||||
} while(0)
|
||||
# define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
|
||||
# define SERIAL_UART_DATA UDR1
|
||||
#else
|
||||
# error "USART configuration is needed."
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "stdint.h"
|
||||
#include "news.h"
|
||||
#include "led.h"
|
||||
|
||||
|
||||
void led_set(uint8_t usb_led)
|
||||
{
|
||||
// not supported now
|
||||
}
|
||||
|
|
@ -24,6 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "news.h"
|
||||
#include "matrix.h"
|
||||
#include "debug.h"
|
||||
#include "led.h"
|
||||
#include "hook.h"
|
||||
#include "wait.h"
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -47,6 +50,8 @@ static uint8_t matrix[MATRIX_ROWS];
|
|||
#define ROW(code) ((code>>3)&0xF)
|
||||
#define COL(code) (code&0x07)
|
||||
|
||||
static uint8_t news_led = 0;
|
||||
|
||||
|
||||
void matrix_init(void)
|
||||
{
|
||||
|
|
@ -58,17 +63,67 @@ void matrix_init(void)
|
|||
return;
|
||||
}
|
||||
|
||||
static uint16_t send_cmd(uint8_t cmd)
|
||||
{
|
||||
int16_t ret = 0;
|
||||
|
||||
xprintf("s%02X ", cmd);
|
||||
news_send(cmd);
|
||||
wait_ms(10);
|
||||
|
||||
int16_t c;
|
||||
while ((c = news_recv()) != -1) {
|
||||
if ((c != 0x7B) && (c != 0xFB)) {
|
||||
ret <<= 8;
|
||||
ret |= c & 0xFF;
|
||||
}
|
||||
xprintf("r%02X ", c);
|
||||
if (c == 0xFB) {
|
||||
xprintf("\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void hook_late_init(void)
|
||||
{
|
||||
/* Commands for starup
|
||||
* 82 is needed to enable LED command at least
|
||||
*
|
||||
* 80 Reset? turns LEDs off
|
||||
* FB
|
||||
* 81 replies whether LED command is enabled
|
||||
* 7B [00|01] FB
|
||||
* 82 enable LED command
|
||||
* 83 replies DIP switches status
|
||||
* 7B 00 0X FB
|
||||
*/
|
||||
send_cmd(0x80);
|
||||
send_cmd(0x82);
|
||||
send_cmd(0x81);
|
||||
send_cmd(0x83);
|
||||
}
|
||||
|
||||
void tone(unsigned int frequency, unsigned long duration);
|
||||
void noTone(void);
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
uint8_t code;
|
||||
static uint8_t sent_led = 0;
|
||||
int16_t code;
|
||||
|
||||
code = news_recv();
|
||||
if (code == 0) {
|
||||
if (code == -1) {
|
||||
// update LED
|
||||
if (news_led != sent_led) {
|
||||
send_cmd(0xB0);
|
||||
send_cmd(news_led);
|
||||
sent_led = news_led;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
phex(code); print(" ");
|
||||
xprintf("%02X ", code);
|
||||
if (code&0x80) {
|
||||
// break code
|
||||
if (matrix_is_on(ROW(code), COL(code))) {
|
||||
|
|
@ -89,3 +144,12 @@ uint8_t matrix_get_row(uint8_t row)
|
|||
{
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void led_set(uint8_t usb_led)
|
||||
{
|
||||
news_led = 0;
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK))
|
||||
news_led |= 4;
|
||||
if (usb_led & (1<<USB_LED_NUM_LOCK))
|
||||
news_led |= 8;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,11 +52,11 @@ static uint8_t rbuf[RBUF_SIZE];
|
|||
static uint8_t rbuf_head = 0;
|
||||
static uint8_t rbuf_tail = 0;
|
||||
|
||||
uint8_t news_recv(void)
|
||||
int16_t news_recv(void)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
if (rbuf_head == rbuf_tail) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = rbuf[rbuf_tail];
|
||||
|
|
@ -74,6 +74,12 @@ ISR(NEWS_KBD_RX_VECT)
|
|||
}
|
||||
}
|
||||
|
||||
void news_send(uint8_t data)
|
||||
{
|
||||
while (!SERIAL_UART_TXD_READY) ;
|
||||
SERIAL_UART_DATA = data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SONY NEWS Keyboard Protocol
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
/* host role */
|
||||
void news_init(void);
|
||||
uint8_t news_recv(void);
|
||||
int16_t news_recv(void);
|
||||
void news_send(uint8_t data);
|
||||
|
||||
/* device role */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue