archimedes: Update LED

This commit is contained in:
tmk 2023-10-19 22:47:55 +09:00
parent 28508afb7d
commit 643cee3280
2 changed files with 22 additions and 11 deletions

View file

@ -21,9 +21,10 @@ SOFTWARE.
*/ */
#include <stdint.h> #include <stdint.h>
#include <util/delay.h> #include <avr/interrupt.h>
#include "protocol/serial.h" #include "protocol/serial.h"
#include "wait.h" #include "wait.h"
#include "timer.h"
#include "debug.h" #include "debug.h"
#include "print.h" #include "print.h"
@ -64,10 +65,13 @@ void matrix_init(void)
xprintf("EIMSK: %02X\n", EIMSK); xprintf("EIMSK: %02X\n", EIMSK);
xprintf("EICRA: %02X\n", EICRA); xprintf("EICRA: %02X\n", EICRA);
return; return;
} }
static uint8_t arc_led = 1<<ARC_LED_SCROLL_LOCK; // LED status
static uint8_t arc_led = 0;
static uint8_t arc_led_prev = 0;
static enum { static enum {
INIT, INIT,
SCAN, SCAN,
@ -88,7 +92,9 @@ static int16_t check_reply(void)
static void send_cmd(uint8_t cmd) static void send_cmd(uint8_t cmd)
{ {
xprintf("s%02X ", cmd); xprintf("s%02X ", cmd);
cli();
serial_send(cmd); serial_send(cmd);
sei();
} }
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
@ -131,8 +137,13 @@ uint8_t matrix_scan(void)
int16_t d; int16_t d;
d = check_reply(); d = check_reply();
switch (d) { switch (d) {
case -1: case -1: // no input
// no reply // update LED
if (arc_led != arc_led_prev) {
wait_ms(1);
send_cmd(LEDS(arc_led));
arc_led_prev = arc_led;
}
break; break;
case KDDA ... KDDA+15: case KDDA ... KDDA+15:
case KUDA ... KUDA+15: case KUDA ... KUDA+15:
@ -180,14 +191,13 @@ uint8_t matrix_scan(void)
} }
} }
// TODO // DEBUG
// toggle ScrollLock LED // toggle ScrollLock LED
/* static uint16_t time_last;
wait_ms(10); if (timer_elapsed(time_last) > 1000) {
arc_led = arc_led ^ 1<<ARC_LED_SCROLL_LOCK; arc_led = arc_led ^ 1<<ARC_LED_SCROLL_LOCK;
serial_send(LEDS(arc_led % 8)); time_last = timer_read();
wait_ms(500); }
*/
return 0; return 0;
} }

View file

@ -60,6 +60,7 @@ SOFTWARE.
#define SERIAL_SOFT_RXD_BIT 1 #define SERIAL_SOFT_RXD_BIT 1
#define SERIAL_SOFT_RXD_VECT INT1_vect #define SERIAL_SOFT_RXD_VECT INT1_vect
// XXX: phantom interrupt(INT1) occrus on rising edge of PD3/TXD for some reason.
/* RXD Interupt */ /* RXD Interupt */
#ifdef SERIAL_SOFT_LOGIC_NEGATIVE #ifdef SERIAL_SOFT_LOGIC_NEGATIVE
/* enable interrupt: INT1(rising edge) */ /* enable interrupt: INT1(rising edge) */