123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- #include <stdbool.h>
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "news.h"
- void news_init(void)
- {
- NEWS_KBD_RX_INIT();
- }
- #define RBUF_SIZE 8
- static uint8_t rbuf[RBUF_SIZE];
- static uint8_t rbuf_head = 0;
- static uint8_t rbuf_tail = 0;
- uint8_t news_recv(void)
- {
- uint8_t data = 0;
- if (rbuf_head == rbuf_tail) {
- return 0;
- }
- data = rbuf[rbuf_tail];
- rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
- return data;
- }
- ISR(NEWS_KBD_RX_VECT)
- {
- uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
- if (next != rbuf_tail) {
- rbuf[rbuf_head] = NEWS_KBD_RX_DATA;
- rbuf_head = next;
- }
- }
|