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