From b7188acd4f4a695ea342c591e32fb2ee6da91215 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 7 Nov 2023 11:28:36 +0900 Subject: [PATCH] news: Add LED support --- converter/news_usb/Makefile | 3 +- converter/news_usb/config.h | 5 ++- converter/news_usb/led.c | 26 -------------- converter/news_usb/matrix.c | 70 +++++++++++++++++++++++++++++++++++-- tmk_core/protocol/news.c | 10 ++++-- tmk_core/protocol/news.h | 3 +- 6 files changed, 82 insertions(+), 35 deletions(-) delete mode 100644 converter/news_usb/led.c diff --git a/converter/news_usb/Makefile b/converter/news_usb/Makefile index 2b48b964..027fa18a 100644 --- a/converter/news_usb/Makefile +++ b/converter/news_usb/Makefile @@ -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 diff --git a/converter/news_usb/config.h b/converter/news_usb/config.h index c444941a..85fdf272 100644 --- a/converter/news_usb/config.h +++ b/converter/news_usb/config.h @@ -54,8 +54,11 @@ along with this program. If not, see . # define NEWS_KBD_RX_INIT() do { \ UBRR1L = (uint8_t) NEWS_KBD_RX_UBBR; \ UBRR1H = (uint8_t) (NEWS_KBD_RX_UBBR>>8); \ - UCSR1B |= (1< - -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 . -*/ - -#include "stdint.h" -#include "news.h" -#include "led.h" - - -void led_set(uint8_t usb_led) -{ - // not supported now -} diff --git a/converter/news_usb/matrix.c b/converter/news_usb/matrix.c index cd1511c6..32685a3d 100644 --- a/converter/news_usb/matrix.c +++ b/converter/news_usb/matrix.c @@ -24,6 +24,9 @@ along with this program. If not, see . #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<