FabGL
ESP32 Display Controller and Graphics Library
PIT8253.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#include "fabgl.h"
30
31
32namespace fabgl {
33
34
35
36// PIT (timers) frequency in Hertz
37#define PIT_TICK_FREQ 1193182
38
39
40
41// PIT 8253 (Programmable Interval Timers)
42
43class PIT8253 {
44
45public:
46
47 typedef void (*ChangeOut)(void * context, int timerIndex);
48
49 struct TimerInfo {
50 bool BCD; // BCD mode
51 int32_t mode; // Timer mode
52 int32_t RLMode; // Read/Load mode
53 int32_t resetHolding; // Holding area for timer reset count
54 int32_t resetCount; // Reload value when count is zero
55 int32_t count; // Current timer counter
56 int32_t latch; // Latched timer count (-1 = not latched)
57 bool LSBToggle; // true: Read load LSB, false: Read load MSB
58 bool out; // out state
59 bool gate; // date (1 = timer running)
60 bool running; // counting down in course
61 bool ctrlSet; // control word set
62 };
63
64 PIT8253();
65 ~PIT8253();
66
67 void setCallbacks(void * context, ChangeOut changeOut) {
68 m_context = context;
69 m_changeOut = changeOut;
70 }
71
72 void reset();
73
74 void tick();
75
76 void write(int reg, uint8_t value);
77 uint8_t read(int reg);
78
79 bool getOut(int timerIndex) { return m_timer[timerIndex].out; }
80 bool getGate(int timerIndex) { return m_timer[timerIndex].gate; }
81
82 void setGate(int timerIndex, bool value);
83
84 TimerInfo const & timerInfo(int timerIndex) { return m_timer[timerIndex]; }
85
86
87private:
88
89 void changeOut(int timer, bool value);
90
91
92 TimerInfo m_timer[3];
93
94 // callbacks
95 void * m_context;
96 ChangeOut m_changeOut;
97 uint64_t m_lastTickTime;
98
99};
100
101
102} // namespace fabgl
This file is the all in one include file. Application can just include this file to use FabGL library...