FabGL
ESP32 Display Controller and Graphics Library
MC146818.h
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29
30#include "nvs_flash.h"
31#include "nvs.h"
32#include "esp_timer.h"
33
34#include "fabgl.h"
35
36
37#if FABGL_ESP_IDF_VERSION <= FABGL_ESP_IDF_VERSION_VAL(3, 3, 5)
38typedef nvs_handle nvs_handle_t;
39#endif
40
41
42namespace fabgl {
43
44
45// RTC MC146818 emulator
46
47// On the PC/AT there are following connections:
48// /IRQ -> IRQ8 (INT 70h)
49// CKFS -> 5V (hence CKOUT has the same frequency as OSC1)
50// PS -> 5V
51// /RESET -> 5V
52// OSC1 -> 32768Hz clock
53// OSC2 -> NC
54// CKOUT -> NC
55// SQW -> NC
56
57// I/O Access
58// port 0x70 (W) : Register address port (bits 0-6)
59// port 0x71 (R/W) : Register read or write
60
61
62class MC146818 {
63
64public:
65
66 typedef bool (*InterruptCallback)(void * context);
67
68 MC146818();
69 ~MC146818();
70
71 void init(char const * NVSNameSpace);
72
73 void setCallbacks(void * context, InterruptCallback interruptCallback) {
74 m_context = context;
75 m_interruptCallback = interruptCallback;
76 }
77
78 void reset();
79
80 void commit();
81
82 uint8_t read(int address);
83 void write(int address, uint8_t value);
84
85 uint8_t & reg(int address) { return m_regs[address]; }
86
87 void updateTime();
88
89private:
90
91 void enableTimers();
92
93 void stopPeriodicTimer();
94 void stopEndUpdateTimer();
95
96 static void periodIntTimerFunc(void * args);
97 static void endUpdateIntTimerFunc(void * args);
98
99
100 nvs_handle_t m_nvs;
101
102 uint8_t m_regs[64];
103 uint8_t m_regSel;
104
105 void * m_context;
106 InterruptCallback m_interruptCallback;
107
108 esp_timer_handle_t m_periodicIntTimerHandle;
109 esp_timer_handle_t m_endUpdateIntTimerHandle;
110
111};
112
113
114
115
116
117
118
119} // fabgl namespace
This file is the all in one include file. Application can just include this file to use FabGL library...