/
uCtrl.h
189 lines (147 loc) · 4.63 KB
/
uCtrl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*!
* @file uCtrl.h
* Project Arduino Library API interface for uMODULAR projects
* @brief ...
* @version 1.1.0
* @author Romulo Silva
* @date 30/10/22
* @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef __U_CTRL_H__
#define __U_CTRL_H__
#include <Arduino.h>
#include <SPI.h>
// modules classes includes
#include "module/oled/oled.hpp"
#include "module/midi/midi.hpp"
// dout 595 or single output for arduino only
#include "module/dout/dout.hpp"
#include "module/din/din.hpp"
#include "module/ain/ain.hpp"
#include "module/touch/touch.hpp"
#if defined(USE_EXT_RAM)
#include "module/ram/ram.hpp"
#endif // defined(USE_EXT_RAM)
#include "module/storage/storage.hpp"
#if defined(USE_SDCARD)
#include "module/sdcard/sdcard.hpp"
#endif // defined(USE_SDCARD)
#include "module/page/page.hpp"
#if defined(USE_DEVICE)
#include "module/device/device.hpp"
#endif // defined(USE_DEVICE)
// tools
#define BLINK_TIME 250
namespace uctrl {
typedef struct
{
uint16_t port;
uint16_t value;
} EVENT_QUEUE_DATA;
typedef struct
{
EVENT_QUEUE_DATA event[8];
volatile uint8_t head;
volatile uint8_t tail;
uint8_t size; //of the buffer
} EVENT_QUEUE;
class uCtrlClass
{
public:
uCtrlClass();
~uCtrlClass();
//
// Grab config data and create all memory data layout
//
void init();
//
// modules access
//
#if defined(USE_EXT_RAM)
// external ram module
bool initRam(SPIClass * device);
uctrl::module::Ram * ram = nullptr;
#endif // defined(USE_EXT_RAM)
bool initStorage(SPIClass * spi_device = nullptr);
uctrl::module::Storage * storage = nullptr;
// oled module
#if defined(USE_OLED_U8G2)
bool initOled(U8G2 * display);
#else // defined(USE_OLED_U8G2)
bool initOled(U8X8 * display);
#endif // defined(USE_OLED_U8G2)
#if defined(USE_EXT_RAM)
#if defined(USE_DEVICE)
void processDisplay();
#endif // defined(USE_DEVICE)
#endif // defined(USE_EXT_RAM)
uctrl::module::Oled * oled = nullptr;
// midi module
bool initMidi();
void processMidi();
uctrl::module::Midi * midi = nullptr;
// dout module
bool initDout(SPIClass * spi_device = nullptr, uint8_t latch_pin = 2);
uctrl::module::Dout * dout = nullptr;
// din module
bool initDin(SPIClass * spi_device = nullptr, uint8_t latch_pin = 2);
uctrl::module::Din * din = nullptr;
// ain module
bool initAin(int8_t pin1 = -1, int8_t pin2 = -1, int8_t pin3 = -1, int8_t pin4 = -1);
void processAin();
uctrl::module::Ain * ain = nullptr;
volatile EVENT_QUEUE _ain_event_queue;
// capacitive touch module
bool initCapTouch(int8_t pin1 = -1, int8_t pin2 = -1, int8_t pin3 = -1, int8_t pin4 = -1);
uctrl::module::CapTouch * touch = nullptr;
#if defined(USE_SDCARD)
// sdcard module
bool initSdCard(SPIClass * spi_device = nullptr);
uctrl::module::SdCard * sdcard;
#endif // defined(USE_SDCARD)
// page module
bool initPage(uint8_t pages_size);
void processPage();
uctrl::module::Page * page = nullptr;
#if defined(USE_DEVICE)
// device module
bool initDevice(uint8_t device_number, uint16_t event_buffer_size, uint8_t sysex_buffer_size = 0, uint16_t device_label_buffer_size = 0);
uctrl::module::Device * device = nullptr;
#endif // defined(USE_DEVICE)
//
// Registred Ports query
//
uint8_t getOutputPorts();
uint8_t getAnalogPorts();
uint8_t getDigitalPorts();
void run();
void setOn250usCallback(void (*callback)()) {
on250usCallback = callback;
}
void setOn1msCallback(void (*callback)()) {
on1msCallback = callback;
}
void (*on250usCallback)();
void (*on1msCallback)();
};
}
extern uctrl::uCtrlClass uCtrl;
#endif // __U_CTRL_H__