FabGL
ESP32 Display Controller and Graphics Library
swgenerator.h
Go to the documentation of this file.
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
38#include <stdint.h>
39#include <stddef.h>
40
41
42#if __has_include("esp32/rom/lldesc.h")
43 #include "esp32/rom/lldesc.h"
44#else
45 #include "rom/lldesc.h"
46#endif
47
48#include "fabglconf.h"
49
50
51
52
53
54namespace fabgl {
55
56
57
58/*
59 * This is a square wave generator or DMA->GPIO stream generator that uses APLL internal Audio PLL clock.
60 *
61 * When FABGLIB_USE_APLL_AB_COEF = 0 (the default) the frequency range is 2651514 Hz to 62500000 Hz.<br>
62 * Average error is 21 Hz, Minimum error is 0, Maximum error is 1000 Hz except for range 41666667 Hz to 42708333 Hz while
63 * frequency remains fixed at 41666666 Hz (error from 0 Hz to 1041666 Hz) and except for range 42708334 hz to 43748999 Hz while
64 * frequency remains fixed at 43750000 Hz (error from 750001 Hz to 1041666 Hz).
65 *
66 * When FABGLIB_USE_APLL_AB_COEF = 1 the frequency range is 82500 Hz to 62500000 Hz. Unfortunately the output has lot of frequency jittering.<br>
67 * Average error is about 7 Hz, Minimum error is 0, Maximum error is 6349 Hz.
68 */
69class GPIOStream {
70
71public:
72
73 void begin();
74
75 /*
76 * Initializes GPIOStream and associate GPIOs to the outputs.
77 *
78 * div1_onGPIO0 If true the undivided frequency is delivered on GPIO0.
79 * div2 Specifies the GPIO where to send frequency / 2 (set GPIO_UNUSED to disable output).
80 * div4 Specifies the GPIO where to send frequency / 4 (set GPIO_UNUSED to disable output).
81 * div8 Specifies the GPIO where to send frequency / 8 (set GPIO_UNUSED to disable output).
82 * div16 Specifies the GPIO where to send frequency / 16 (set GPIO_UNUSED to disable output).
83 * div32 Specifies the GPIO where to send frequency / 32 (set GPIO_UNUSED to disable output).
84 * div64 Specifies the GPIO where to send frequency / 64 (set GPIO_UNUSED to disable output).
85 * div128 Specifies the GPIO where to send frequency / 128 (set GPIO_UNUSED to disable output).
86 * div256 Specifies the GPIO where to send frequency / 256 (set GPIO_UNUSED to disable output).
87 *
88 * Example:
89 *
90 * // Outputs 25Mhz on GPIO0 and 6.25Mhz on GPIO5, for 5 seconds
91 * GPIOStream.begin(true, GPIO_UNUSED, GPIO_NUM_5);
92 * GPIOStream.play(25000000);
93 * delay(5000);
94 * // Outputs 20Mhz on GPIO and 5Mhz on GPIO5, for 10 seconds
95 * GPIOStream.play(20000000);
96 * delay(10000);
97 * GPIOStream.stop();
98 */
99 void begin(bool div1_onGPIO0, gpio_num_t div2 = GPIO_UNUSED, gpio_num_t div4 = GPIO_UNUSED, gpio_num_t div8 = GPIO_UNUSED, gpio_num_t div16 = GPIO_UNUSED, gpio_num_t div32 = GPIO_UNUSED, gpio_num_t div64 = GPIO_UNUSED, gpio_num_t div128 = GPIO_UNUSED, gpio_num_t div256 = GPIO_UNUSED);
100
101 /*
102 * Disables all outputs.
103 */
104 void end();
105
106 /*
107 * Sets the main frequency.
108 *
109 * freq Frequency in Hertz.
110 * dmaBuffers Use only to provide custom DMA buffers.
111 *
112 * Example:
113 *
114 * // Set 25MHz as main frequency
115 * GPIOStream.play(25000000);
116 */
117 void play(int freq, lldesc_t volatile * dmaBuffers = nullptr);
118
119 /*
120 * Disables all outputs.
121 */
122 void stop();
123
124private:
125
126 void setupClock(int freq);
127 static void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
128
129 bool m_DMAStarted;
130 volatile lldesc_t * m_DMABuffer;
131 volatile uint8_t * m_DMAData;
132};
133
134
135
136
137
138} // end of namespace
139
140
141
142
143
144
145
146
147
This file contains FabGL library configuration settings, like number of supported colors,...