SimpleTimer + more (#12)

This commit is contained in:
Stephen Crane 2024-11-23 12:35:37 +00:00 committed by GitHub
parent 9c20f5f15b
commit c89018940b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 51 deletions

View File

@ -2,7 +2,7 @@ t ?= esp32
TERMINAL_SPEED := 115200
CPPFLAGS = -Wall -DDEBUGGING -DCPU_DEBUG=false -DTERMINAL_SPEED=$(TERMINAL_SPEED) -DUSE_OWN_KBD
LIBRARIES = PS2KeyAdvanced PS2KeyMap
LIBRARIES = PS2KeyAdvanced PS2KeyMap SimpleTimer
ifeq ($t, esp8266)
BOARD := d1_mini
@ -11,7 +11,7 @@ EESZ := 4M1M
F_CPU := 80
CPPFLAGS += -DUSER_SETUP_LOADED -DILI9341_DRIVER -DTFT_CS=PIN_D8 -DTFT_DC=PIN_D1 \
-DTFT_RST=-1 -DSPI_FREQUENCY=40000000 -DLOAD_GLCD \
-DHARDWARE_H=\"hw/esp8bit.h\" -DPS2_SERIAL_KBD=\"UK\"
-DHARDWARE_H=\"hw/esp8bit.h\"
LIBRARIES += TFT_eSPI SpiRAM LittleFS
endif

34
io.cpp
View File

@ -6,23 +6,24 @@
#include <serial_kbd.h>
#include <serial_dsp.h>
#include <pia.h>
#include <timed.h>
#include <hardware.h>
#include "io.h"
#include "disp.h"
#include "hardware.h"
#include "config.h"
void io::reset() {
_loading = false;
_dsp.reset();
_kbd.reset();
_loading = false;
PIA::reset();
_pia.reset();
_ch = 0;
}
bool io::start() {
hardware_interval_timer(10, [this]() { poll(); });
_pia.register_portb_write_handler([this](uint8_t b) { _dsp.write(b & 0x7f); });
_pia.register_porta_read_handler([this]() { uint8_t c = _ch; _ch = 0; return c; });
return files.start();
}
@ -34,18 +35,15 @@ void io::load() {
}
void io::enter(uint8_t key) {
PIA::write_ca1(false);
PIA::write_porta_in(key + 0x80);
PIA::write_ca1(true);
_pia.write_ca1(false);
_ch = key | 0x80;
_pia.write_ca1(true);
}
void io::write_portb(uint8_t b) {
b &= 0x7f;
_dsp.write(b);
PIA::write_portb(b);
}
void io::poll() {
if (_ch)
return;
uint8_t io::read_cra() {
if (_loading) {
if (files.more())
enter(files.read());
@ -56,16 +54,14 @@ uint8_t io::read_cra() {
if (c != -1)
enter(c);
}
return PIA::read_cra();
}
void io::checkpoint(Stream &s) {
PIA::checkpoint(s);
_pia.checkpoint(s);
_dsp.checkpoint(s);
}
void io::restore(Stream &s) {
PIA::restore(s);
_pia.restore(s);
_dsp.restore(s);
}

17
io.h
View File

@ -1,10 +1,9 @@
#ifndef _IO_H
#define _IO_H
#pragma once
class serial_kbd;
class disp;
class io: public Memory::Device, public PIA {
class io: public Memory::Device {
public:
io(filer &files, serial_kbd &kbd, disp &dsp):
Memory::Device(Memory::page_size), files(files), _kbd(kbd), _dsp(dsp) {}
@ -12,24 +11,22 @@ public:
void reset();
bool start();
void operator=(uint8_t b) { PIA::write(_acc, b); }
operator uint8_t() { return PIA::read(_acc); }
void operator=(uint8_t b) { _pia.write(_acc, b); }
operator uint8_t() { return _pia.read(_acc); }
void checkpoint(Stream &);
void restore(Stream &);
void write_portb(uint8_t);
uint8_t read_cra();
void poll();
void load();
filer &files;
private:
PIA _pia;
serial_kbd &_kbd;
disp &_dsp;
void enter(uint8_t);
bool _loading;
uint8_t _ch;
};
#endif

View File

@ -2,29 +2,23 @@
#include <memory.h>
#include <display.h>
#include <serial_dsp.h>
#include <timed.h>
#include <hardware.h>
#include "disp.h"
#include "screen_disp.h"
#include "config.h"
static screen_disp *i;
const int TICK_FREQ = 2;
void IRAM_ATTR screen_disp::on_tick() {
static int tick = 0;
tick = (tick + 1) % 3;
i->cursor(tick < 2);
}
void screen_disp::reset() {
if (!i) {
i = this;
timer_create(TICK_FREQ, on_tick);
static bool first_time = true;
if (first_time) {
hardware_interval_timer(500, [this]() {
static int tick = 0;
tick = (tick + 1) % 3;
cursor(tick < 2);
});
first_time = false;
}
Display::begin(BG_COLOUR, FG_COLOUR, ORIENT);

View File

@ -11,12 +11,8 @@ public:
void write(uint8_t);
void status(const char *s) { Display::status(s); }
protected:
static void on_tick();
void cursor(bool on);
private:
void cursor(bool on);
void draw(char, int, int);
static const uint8_t ROWS = 24;