Add LED feature to Sun converter
This commit is contained in:
parent
8a84993ed6
commit
06ed34ec8c
@ -555,6 +555,7 @@ void keyboard_init(void)
|
|||||||
void keyboard_task(void)
|
void keyboard_task(void)
|
||||||
{
|
{
|
||||||
static matrix_row_t matrix_prev[MATRIX_ROWS];
|
static matrix_row_t matrix_prev[MATRIX_ROWS];
|
||||||
|
static uint8_t led_status = 0;
|
||||||
matrix_row_t matrix_row = 0;
|
matrix_row_t matrix_row = 0;
|
||||||
matrix_row_t matrix_change = 0;
|
matrix_row_t matrix_change = 0;
|
||||||
|
|
||||||
@ -617,6 +618,12 @@ void keyboard_task(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update LED
|
||||||
|
if (led_status != host_keyboard_leds()) {
|
||||||
|
led_status = host_keyboard_leds();
|
||||||
|
keyboard_set_leds(led_status);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,5 +41,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
/* host role */
|
/* host role */
|
||||||
void serial_init(void);
|
void serial_init(void);
|
||||||
uint8_t serial_recv(void);
|
uint8_t serial_recv(void);
|
||||||
|
void serial_send(uint8_t data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,9 +51,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
void serial_init(void)
|
void serial_init(void)
|
||||||
{
|
{
|
||||||
SERIAL_RXD_INIT();
|
SERIAL_RXD_INIT();
|
||||||
|
SERIAL_TXD_INIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RX ring buffer
|
/* RX ring buffer */
|
||||||
#define RBUF_SIZE 8
|
#define RBUF_SIZE 8
|
||||||
static uint8_t rbuf[RBUF_SIZE];
|
static uint8_t rbuf[RBUF_SIZE];
|
||||||
static uint8_t rbuf_head = 0;
|
static uint8_t rbuf_head = 0;
|
||||||
@ -71,39 +72,63 @@ uint8_t serial_recv(void)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ISR(INT2_vect)
|
void serial_send(uint8_t data)
|
||||||
|
{
|
||||||
|
/* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
|
||||||
|
/* start bit */
|
||||||
|
SERIAL_TXD_OFF();
|
||||||
|
_delay_us(WAIT_US);
|
||||||
|
|
||||||
|
#ifdef SERIAL_BIT_ORDER_MSB
|
||||||
|
uint8_t mask = 0x80;
|
||||||
|
#else
|
||||||
|
uint8_t mask = 0x01;
|
||||||
|
#endif
|
||||||
|
while (mask) {
|
||||||
|
if (data&mask) { SERIAL_TXD_ON(); } else { SERIAL_TXD_OFF(); }
|
||||||
|
_delay_us(WAIT_US);
|
||||||
|
|
||||||
|
#ifdef SERIAL_BIT_ORDER_MSB
|
||||||
|
mask >>= 1;
|
||||||
|
#else
|
||||||
|
mask <<= 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stop bit */
|
||||||
|
SERIAL_TXD_ON();
|
||||||
|
_delay_us(WAIT_US);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* detect edge of start bit */
|
||||||
ISR(SERIAL_RXD_VECT)
|
ISR(SERIAL_RXD_VECT)
|
||||||
{
|
{
|
||||||
SERIAL_RXD_INT_ENTER()
|
SERIAL_RXD_INT_ENTER()
|
||||||
|
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
#ifdef SERIAL_BIT_ORDER_MSB
|
#ifdef SERIAL_BIT_ORDER_MSB
|
||||||
uint8_t pos = 0x80;
|
uint8_t mask = 0x80;
|
||||||
#else
|
#else
|
||||||
uint8_t pos = 0x01;
|
uint8_t mask = 0x01;
|
||||||
#endif
|
#endif
|
||||||
// to center of start bit
|
/* to center of start bit */
|
||||||
_delay_us(WAIT_US/2);
|
_delay_us(WAIT_US/2);
|
||||||
do {
|
do {
|
||||||
// to center of next bit
|
/* to center of next bit */
|
||||||
_delay_us(WAIT_US);
|
_delay_us(WAIT_US);
|
||||||
|
|
||||||
if (SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) {
|
if (SERIAL_RXD_READ()) {
|
||||||
data |= pos;
|
data |= mask;
|
||||||
}
|
}
|
||||||
#ifdef SERIAL_BIT_ORDER_MSB
|
#ifdef SERIAL_BIT_ORDER_MSB
|
||||||
pos >>= 1;
|
mask >>= 1;
|
||||||
#else
|
#else
|
||||||
pos <<= 1;
|
mask <<= 1;
|
||||||
#endif
|
#endif
|
||||||
} while (pos);
|
} while (mask);
|
||||||
// to center of stop bit
|
/* to center of stop bit */
|
||||||
_delay_us(WAIT_US);
|
_delay_us(WAIT_US);
|
||||||
|
|
||||||
#ifdef SERIAL_NEGATIVE_LOGIC
|
|
||||||
data = ~data;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
|
uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
|
||||||
if (next != rbuf_tail) {
|
if (next != rbuf_tail) {
|
||||||
rbuf[rbuf_head] = data;
|
rbuf[rbuf_head] = data;
|
||||||
|
Reference in New Issue
Block a user