ESP32VGA
ESP32 VGA Controller and Graphics Library
VGASignalsGenerator.h
Go to the documentation of this file.
1 #ifndef _VGASIGNALGENERATOR_H_INCLUDED
2 #define _VGASIGNALGENERATOR_H_INCLUDED
3 
4 
13 #include "Arduino.h"
14 
15 #include <stdint.h>
16 #include <stddef.h>
17 
18 #include "rom/lldesc.h"
19 
20 #include "VGAConf.h"
21 
22 
23 namespace ESP32VGA {
24 
25 
26 #if VGACOLORS == 8
27 # define VGAREDBIT 0
28 # define VGAGREENBIT 1
29 # define VGABLUEBIT 2
30 # define VGAHSYNCBIT 3
31 # define VGAVSYNCBIT 4
32 #elif VGACOLORS == 64
33 # define VGAREDBIT 0
34 # define VGAGREENBIT 2
35 # define VGABLUEBIT 4
36 # define VGAHSYNCBIT 6
37 # define VGAVSYNCBIT 7
38 #else
39 # error "VGACOLORS must be 8 or 64!"
40 #endif
41 
42 
43 enum VGAFrequency {
44  F_10727680Hz,
45  F_12000000Hz,
46  F_12336000Hz,
47  F_12588000Hz,
48  F_12600000Hz,
49  F_12930000Hz,
50  F_13500000Hz,
51  F_13846000Hz,
52  F_13875000Hz,
53  F_14750000Hz,
54  F_15750000Hz,
55  F_16257000Hz,
56  F_17750000Hz,
57  F_18000000Hz,
58  F_20000000Hz,
59  F_21210000Hz,
60  F_22450000Hz,
61  F_24750000Hz,
62  F_25000000Hz,
63  F_25175000Hz,
64  F_25180000Hz,
65  F_25200000Hz,
66  F_27000000Hz,
67  F_27027000Hz,
68  F_28150000Hz,
69  F_28322000Hz,
70  F_28640000Hz,
71  F_29500000Hz,
72  F_30240000Hz,
73  F_31050000Hz,
74  F_31150000Hz,
75  F_31220000Hz,
76  F_31500000Hz,
77  F_32500000Hz,
78  F_34960000Hz,
79  F_35500000Hz,
80  F_36000000Hz,
81  F_40000000Hz,
82 };
83 
84 
85 
86 typedef void (*VGAVSyncInterrupt_t)();
87 
88 
89 class VGASignalsGeneratorClass {
90 public:
91 
92  #if VGACOLORS == 8
93  void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO, VGAVSyncInterrupt_t VSyncInterruptCallBack);
94  #endif
95  #if VGACOLORS == 64
96  void begin(gpio_num_t red1GPIO, gpio_num_t red0GPIO, gpio_num_t green1GPIO, gpio_num_t green0GPIO, gpio_num_t blue1GPIO, gpio_num_t blue0GPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO, VGAVSyncInterrupt_t VSyncInterruptCallBack);
97  #endif
98 
99  // VGASignalsGeneratorClass is not owner of actual buffers. Can be used to change buffers count, maintainig already set pointers.
100  bool setBuffersCount(int buffersCount);
101  int getBuffersCount() { return m_buffersCount; }
102 
103  // length is in bytes. Max 4092 bytes.
104  // Returns allocated buffer
105  void * allocateBuffer(size_t length);
106 
107  size_t getFreeMemory();
108 
109  // free buffer allocated with allocateBuffer()
110  void freeBuffer(void * buffer);
111 
112  // address must be allocated with allocateBuffer or even an address of another already allocated buffer
113  void setBuffer(int index, void volatile * address, int length);
114 
115  void volatile * getBuffer(int index, int * length);
116 
117  void start(VGAFrequency freq);
118 
119  void stop();
120 
121  // can be nested
122  void enableVSyncInterrupts();
123  void disableVSyncInterrupts();
124 
125 private:
126 
127  void init(gpio_num_t VSyncGPIO, VGAVSyncInterrupt_t VSyncInterruptCallBack);
128  void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
129  void setupClock(VGAFrequency freq);
130 
131  lldesc_t volatile * m_dmabuffers;
132  int m_buffersCount;
133  gpio_num_t m_VSyncGPIO;
134  VGAVSyncInterrupt_t m_VSyncInterruptCallback;
135  int m_VSyncInterruptDisabled; // 0 = enabled, >0 disabled
136  bool m_started;
137 };
138 
139 
140 } // end of namespace
141 
142 
143 extern ESP32VGA::VGASignalsGeneratorClass VGASignalsGenerator;
144 
145 
146 #endif
This file contains ESP32VGA library configuration settings, like number of supported colors...
Definition: VGACanvas.cpp:7