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-2020 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #pragma once
24 
25 
26 
34 #include <stdint.h>
35 #include <stddef.h>
36 
37 #include "rom/lldesc.h"
38 
39 #include "fabglconf.h"
40 
41 
42 
43 
44 
45 namespace fabgl {
46 
47 
48 
49 /*
50  * This is a square wave generator or DMA->GPIO stream generator that uses APLL internal Audio PLL clock.
51  *
52  * When FABGLIB_USE_APLL_AB_COEF = 0 (the default) the frequency range is 2651514 Hz to 62500000 Hz.<br>
53  * Average error is 21 Hz, Minimum error is 0, Maximum error is 1000 Hz except for range 41666667 Hz to 42708333 Hz while
54  * frequency remains fixed at 41666666 Hz (error from 0 Hz to 1041666 Hz) and except for range 42708334 hz to 43748999 Hz while
55  * frequency remains fixed at 43750000 Hz (error from 750001 Hz to 1041666 Hz).
56  *
57  * 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>
58  * Average error is about 7 Hz, Minimum error is 0, Maximum error is 6349 Hz.
59  */
60 class GPIOStream {
61 
62 public:
63 
64  void begin();
65 
66  /*
67  * Initializes GPIOStream and associate GPIOs to the outputs.
68  *
69  * div1_onGPIO0 If true the undivided frequency is delivered on GPIO0.
70  * div2 Specifies the GPIO where to send frequency / 2 (set GPIO_UNUSED to disable output).
71  * div4 Specifies the GPIO where to send frequency / 4 (set GPIO_UNUSED to disable output).
72  * div8 Specifies the GPIO where to send frequency / 8 (set GPIO_UNUSED to disable output).
73  * div16 Specifies the GPIO where to send frequency / 16 (set GPIO_UNUSED to disable output).
74  * div32 Specifies the GPIO where to send frequency / 32 (set GPIO_UNUSED to disable output).
75  * div64 Specifies the GPIO where to send frequency / 64 (set GPIO_UNUSED to disable output).
76  * div128 Specifies the GPIO where to send frequency / 128 (set GPIO_UNUSED to disable output).
77  * div256 Specifies the GPIO where to send frequency / 256 (set GPIO_UNUSED to disable output).
78  *
79  * Example:
80  *
81  * // Outputs 25Mhz on GPIO0 and 6.25Mhz on GPIO5, for 5 seconds
82  * GPIOStream.begin(true, GPIO_UNUSED, GPIO_NUM_5);
83  * GPIOStream.play(25000000);
84  * delay(5000);
85  * // Outputs 20Mhz on GPIO and 5Mhz on GPIO5, for 10 seconds
86  * GPIOStream.play(20000000);
87  * delay(10000);
88  * GPIOStream.stop();
89  */
90  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);
91 
92  /*
93  * Disables all outputs.
94  */
95  void end();
96 
97  /*
98  * Sets the main frequency.
99  *
100  * freq Frequency in Hertz.
101  * dmaBuffers Use only to provide custom DMA buffers.
102  *
103  * Example:
104  *
105  * // Set 25MHz as main frequency
106  * GPIOStream.play(25000000);
107  */
108  void play(int freq, lldesc_t volatile * dmaBuffers = nullptr);
109 
110  /*
111  * Disables all outputs.
112  */
113  void stop();
114 
115 private:
116 
117  void setupClock(int freq);
118  static void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
119 
120  bool m_DMAStarted;
121  volatile lldesc_t * m_DMABuffer;
122  volatile uint8_t * m_DMAData;
123 };
124 
125 
126 
127 
128 
129 } // end of namespace
130 
131 
132 
133 
134 
135 
136 
137 
138 
Definition: canvas.cpp:31
This file contains FabGL library configuration settings, like number of supported colors...