refactor
This commit is contained in:
parent
211469f27b
commit
2e7135fcb6
|
@ -1,9 +1,11 @@
|
|||
#include <keyboard.h>
|
||||
#include <SDL.h>
|
||||
#include <component.h>
|
||||
#include <pins.h>
|
||||
|
||||
extern std::vector<Component *> components;
|
||||
void uart_rx_getchar(uint8_t ch);
|
||||
void uart_rx_term_focus(bool v);
|
||||
void kb_push_key(uint8_t scancode, bool is_keydown);
|
||||
static bool focus_uart_rx_term = false;
|
||||
|
||||
static void mousedown_handler(const SDL_Event &ev) {
|
||||
|
@ -39,11 +41,6 @@ static void mouseup_handler(const SDL_Event &ev) {
|
|||
}
|
||||
}
|
||||
|
||||
static void key_handler(uint8_t scancode, int is_keydown){
|
||||
extern KEYBOARD* kb;
|
||||
kb->push_key(scancode, is_keydown);
|
||||
}
|
||||
|
||||
void read_event() {
|
||||
SDL_Event ev;
|
||||
SDL_PollEvent(&ev);
|
||||
|
@ -59,7 +56,7 @@ void read_event() {
|
|||
uart_rx_getchar('\n');
|
||||
}
|
||||
case SDL_KEYUP:
|
||||
if (!focus_uart_rx_term) key_handler(ev.key.keysym.scancode, ev.key.type == SDL_KEYDOWN);
|
||||
if (!focus_uart_rx_term) kb_push_key(ev.key.keysym.scancode, ev.key.type == SDL_KEYDOWN);
|
||||
break;
|
||||
case SDL_TEXTINPUT: if (focus_uart_rx_term) uart_rx_getchar(ev.text.text[0]); break;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <pins.h>
|
||||
#include "at_scancode.h"
|
||||
|
||||
KEYBOARD* kb = NULL;
|
||||
static KEYBOARD* kb = NULL;
|
||||
bool is_kb_idle = true;
|
||||
|
||||
#define FILL_KEYMAP_FIRST(a) keymap_first[SDL_PREFIX(a)] = GET_FIRST(AT_PREFIX(a));
|
||||
|
@ -70,3 +70,11 @@ void init_keyboard(SDL_Renderer *renderer) {
|
|||
MAP(SCANCODE_LIST, FILL_KEYMAP_FIRST)
|
||||
MAP(SCANCODE_LIST, FILL_KEYMAP_DECOND)
|
||||
}
|
||||
|
||||
void kb_update() {
|
||||
kb->update_state();
|
||||
}
|
||||
|
||||
void kb_push_key(uint8_t scancode, bool is_keydown){
|
||||
kb->push_key(scancode, is_keydown);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include <nvboard.h>
|
||||
#include <keyboard.h>
|
||||
#include <vga.h>
|
||||
#include <uart.h>
|
||||
#include <stdarg.h>
|
||||
#include <macro.h>
|
||||
|
||||
|
@ -14,20 +12,22 @@ PinNode pin_array[NR_PINS];
|
|||
static bool need_redraw = true;
|
||||
void set_redraw() { need_redraw = true; }
|
||||
|
||||
void vga_update();
|
||||
void kb_update();
|
||||
void uart_tx_receive();
|
||||
void uart_rx_send();
|
||||
|
||||
void nvboard_update() {
|
||||
extern VGA *vga;
|
||||
extern uint8_t *vga_blank_n_ptr;
|
||||
if (*vga_blank_n_ptr) vga->update_state();
|
||||
if (*vga_blank_n_ptr) vga_update();
|
||||
|
||||
extern KEYBOARD* kb;
|
||||
extern bool is_kb_idle;
|
||||
if (unlikely(!is_kb_idle)) kb->update_state();
|
||||
if (unlikely(!is_kb_idle)) kb_update();
|
||||
|
||||
extern UART* uart;
|
||||
extern int16_t uart_divisor_cnt;
|
||||
if (unlikely((-- uart_divisor_cnt) < 0)) {
|
||||
uart->tx_receive();
|
||||
uart->rx_send();
|
||||
uart_tx_receive();
|
||||
uart_rx_send();
|
||||
}
|
||||
|
||||
static uint64_t last = 0;
|
||||
|
|
10
src/uart.cpp
10
src/uart.cpp
|
@ -4,7 +4,7 @@
|
|||
// There is no need to update TX too frequently
|
||||
#define UART_TX_FPS 5
|
||||
|
||||
UART* uart = NULL;
|
||||
static UART* uart = NULL;
|
||||
int16_t uart_divisor_cnt = 0;
|
||||
|
||||
|
||||
|
@ -123,6 +123,14 @@ void init_uart(SDL_Renderer *renderer) {
|
|||
add_component(uart);
|
||||
}
|
||||
|
||||
void uart_tx_receive() {
|
||||
uart->tx_receive();
|
||||
}
|
||||
|
||||
void uart_rx_send() {
|
||||
uart->rx_send();
|
||||
}
|
||||
|
||||
void uart_rx_getchar(uint8_t ch) {
|
||||
uart->rx_getchar(ch);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <vga.h>
|
||||
#include <macro.h>
|
||||
|
||||
VGA* vga = NULL;
|
||||
static VGA* vga = NULL;
|
||||
|
||||
VGA_MODE vga_mod_accepted[NR_VGA_MODE] = {
|
||||
[VGA_MODE_640_480] = {
|
||||
|
@ -117,3 +117,7 @@ void init_vga(SDL_Renderer *renderer) {
|
|||
vga->add_pin(p);
|
||||
}
|
||||
}
|
||||
|
||||
void vga_update() {
|
||||
vga->update_state();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue