-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicroFPGA.h
284 lines (226 loc) · 6.91 KB
/
MicroFPGA.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//////////////////////////////////////////////////////////////////////////////
// FILE: MicroFPGA.h
// PROJECT: Micro-Manager
// SUBSYSTEM: DeviceAdapters
//-----------------------------------------------------------------------------
// DESCRIPTION: Adapter for MicroFPGA, a FPGA platform using FPGA boards from
// Alchitry. The adapter must be used with a special firmware, see:
// https://mufpga.github.io/
// https://github.com/mufpga/MicroFPGA
// COPYRIGHT: EMBL
// LICENSE: LGPL
//
// AUTHOR: Joran Deschamps, EMBL, 2020
//
//
#ifndef _MicroFPGA_H_
#define _MicroFPGA_H_
#include "MMDevice.h"
#include "DeviceBase.h"
//////////////////////////////////////////////////////////////////////////////
// Error codes
//
#define ERR_BOARD_NOT_FOUND 101
#define ERR_PORT_OPEN_FAILED 102
#define ERR_NO_PORT_SET 103
#define ERR_VERSION_MISMATCH 104
#define ERR_UNKNOWN_ID 105
#define ERR_COMMAND_UNKNOWN 11206655
class MicroFPGAHub : public HubBase<MicroFPGAHub>
{
public:
MicroFPGAHub();
~MicroFPGAHub();
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
MM::DeviceDetectionStatus DetectDevice(void);
int DetectInstalledDevices();
// property handlers
int OnPort(MM::PropertyBase* pPropt, MM::ActionType eAct);
int OnSyncMode(MM::PropertyBase* pPropt, MM::ActionType eAct);
int PurgeComPortH() {return PurgeComPort(port_.c_str());}
int SendWriteRequest(long address, long value);
int SendReadRequest(long address);
int ReadAnswer(long& answer);
int WriteToComPortH(const unsigned char* command, unsigned len) {return WriteToComPort(port_.c_str(), command, len);}
int ReadFromComPortH(unsigned char* answer, unsigned maxLen, unsigned long& bytesRead) {
return ReadFromComPort(port_.c_str(), answer, maxLen, bytesRead);
}
int SetPassiveSync();
int SetActiveSync();
static MMThreadLock& GetLock() {return lock_;}
private:
int GetControllerVersion(long&);
int GetID(long&);
std::string port_;
bool initialized_;
bool portAvailable_;
long version_;
long id_;
static MMThreadLock lock_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class CameraTrigger : public CGenericBase<CameraTrigger>
{
public:
CameraTrigger();
~CameraTrigger();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy() { return busy_; }
// action interface
// ----------------
int OnStart(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnPulse(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnReadout(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnExposure(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnDelay(MM::PropertyBase* pProp, MM::ActionType eAct);
private:
int WriteToPort(long address, long value);
int ReadFromPort(long& answer);
bool initialized_;
bool mode_;
bool start_;
long pulse_;
long readout_;
long exposure_;
long delay_;
bool busy_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class LaserTrigger : public CGenericBase<LaserTrigger>
{
public:
LaserTrigger();
~LaserTrigger();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy() {return busy_;}
unsigned long GetNumberOfLasers()const {return numlasers_;}
// action interface
// ----------------
int OnMode(MM::PropertyBase* pProp, MM::ActionType eAct, long laser);
int OnDuration(MM::PropertyBase* pProp, MM::ActionType eAct, long laser);
int OnSequence(MM::PropertyBase* pProp, MM::ActionType eAct, long laser);
int OnNumberOfLasers(MM::PropertyBase* pProp, MM::ActionType eAct);
private:
int WriteToPort(long address, long value);
int ReadFromPort(long& answer);
bool initialized_;
long numlasers_;
long *mode_;
long *duration_;
long *sequence_;
bool busy_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class Servo : public CGenericBase<Servo>
{
public:
Servo();
~Servo();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy() {return busy_;}
unsigned long GetNumberOfServos()const {return numServos_;}
// action interface
// ----------------
int OnNumberOfServos(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnPosition(MM::PropertyBase* pProp, MM::ActionType eAct, long servo);
private:
int WriteToPort(long address, long value);
int ReadFromPort(long& answer);
long *position_;
bool initialized_;
long numServos_;
bool busy_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class TTL : public CGenericBase<TTL>
{
public:
TTL();
~TTL();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy() {return busy_;}
unsigned long GetNumberOfChannels()const {return numChannels_;}
// action interface
// ----------------
int OnState(MM::PropertyBase* pProp, MM::ActionType eAct, long channel);
int OnNumberOfChannels(MM::PropertyBase* pProp, MM::ActionType eAct);
private:
int WriteToPort(long channel, long state);
int ReadFromPort(long& answer);
long numChannels_;
long *state_;
bool initialized_;
bool busy_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class PWM : public CGenericBase<PWM>
{
public:
PWM();
~PWM();
// MMDevice API
// ------------
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy() {return busy_;}
unsigned long GetNumberOfChannels()const {return numChannels_;}
// action interface
// ----------------
int OnState(MM::PropertyBase* pProp, MM::ActionType eAct, long servo);
int OnNumberOfChannels(MM::PropertyBase* pProp, MM::ActionType eAct);
private:
int WriteToPort(long channel, long value);
int ReadFromPort(long& answer);
bool initialized_;
long *state_;
long numChannels_;
bool busy_;
};
///////////////////////////////////////////////////////////////////////////////////////////
//////
class AnalogInput : public CGenericBase<AnalogInput>
{
public:
AnalogInput();
~AnalogInput();
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
int OnAnalogInput(MM::PropertyBase* pProp, MM::ActionType eAct, long channel);
int OnNumberOfChannels(MM::PropertyBase* pProp, MM::ActionType eAct);
unsigned long GetNumberOfChannels()const {return numChannels_;}
private:
int WriteToPort(long address);
int ReadFromPort(long& answer);
MMThreadLock lock_;
long numChannels_;
long *state_;
bool initialized_;
};
#endif