-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathboard.h
More file actions
381 lines (303 loc) · 8.45 KB
/
Copy pathboard.h
File metadata and controls
381 lines (303 loc) · 8.45 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#pragma once
#include <vector>
#include "../displays/images/themes/themes.h"
#include "asic.h"
#include "bm1368.h"
#include "nvs_config.h"
#include "../pid/PID_v1_bc.h"
class Board {
public:
enum Error {
NONE,
TEMP_FAULT,
VREG_TEMP_FAULT,
PSU_FAULT,
IOUT_OC_FAULT,
VOUT_FAULT,
COINBASE_VERIFY_FAULT
};
static const char* errorToStr(Error err) {
switch (err) {
case Error::NONE: return "";
case Error::TEMP_FAULT: return "MINER OVERHEATED";
case Error::VREG_TEMP_FAULT: return "VREG OVERHEATED";
case Error::PSU_FAULT: return "PSU FAULT";
case Error::IOUT_OC_FAULT: return "CURRENT PROTECTION";
case Error::VOUT_FAULT: return "VOLTAGE PROTECTION";
case Error::COINBASE_VERIFY_FAULT: return "VERIFY FAILED";
default: return "INVALID ERROR";
}
}
protected:
// general board information
const char *m_deviceModel;
int m_version;
const char *m_asicModel;
const char *m_miningAgent;
int m_asicCount;
int m_chipsDetected = 0;
int m_numTempSensors = 0;
float *m_chipTemps;
const char *m_swarmColorName = "blue";
uint32_t m_vrFrequency;
uint32_t m_defaultVrFrequency;
bool m_hasHashCounter;
const char *m_defaultTheme = "cosmic";
// Index 0: ASIC/chip-temp PID (fan 0). Index 1: VR-temp PID (fan 1).
// ch1 base defaults (overridden in subclass ctors where needed): 65°C, p=6, i=0.1, d=10.
PidSettings m_pidSettings[2] = {{}, {65, 600, 10, 1000}};
// Fan control mode per channel (0=manual, 2=PID, 3=linked). Initialized to
// the default here and overwritten from NVS in loadSettings() — same
// handling as m_pidSettings. ch0 = global Kconfig default, ch1 = linked.
int m_fanMode[2] = {CONFIG_AUTO_FAN_SPEED_VALUE, 3};
// Human-readable connector labels shown in the web UI
const char* m_fanLabels[2] = {"Fan 1", "Fan 2"};
// asic settings
int m_asicJobIntervalMs;
int m_asicFrequency;
int m_asicVoltageMillis;
int m_absMaxAsicFrequency;
int m_absMinAsicVoltageMillis;
int m_absMaxAsicVoltageMillis;
// frequency and voltage options
std::vector<uint32_t> m_asicFrequencies;
std::vector<uint32_t> m_asicVoltages;
// default settings
int m_defaultAsicFrequency;
int m_defaultAsicVoltageMillis;
// default settings
int m_ecoAsicFrequency;
int m_ecoAsicVoltageMillis;
// asic difficulty settings
uint32_t m_asicMinDifficulty;
uint32_t m_asicMinDifficultyDualPool;
uint32_t m_asicMaxDifficulty;
// Voltage regulator max temperature
float m_vr_maxTemp = 0.0;
// fans
bool m_fanInvertPolarity;
float m_fanPerc;
// flip screen
bool m_flipScreen;
// max power settings
float m_maxPin;
float m_minPin;
float m_maxVin;
float m_minVin;
float m_minCurrentA = 0.0f;
float m_maxCurrentA = 8.0f; // default for small devices
int m_numFans;
bool m_shutdown = false;
// display m_theme
Theme *m_theme = nullptr;
Asic *m_asics = nullptr;
bool m_isInitialized = false;
bool m_isBuckInitialized = false;
public:
Board();
virtual bool initBoard();
virtual bool initAsics() = 0;
void loadSettings();
const char *getDeviceModel();
const char *getMiningAgent();
int getVersion();
const char *getAsicModel();
int getAsicCount();
int getAsicJobIntervalMs();
uint32_t getInitialASICDifficulty();
virtual bool setAsicFrequency(float f);
bool validateFrequency(float frequency);
bool validateVoltage(float core_voltage);
void setVrFrequency(uint32_t freq);
// abstract common methos
virtual bool setVoltage(float core_voltage) = 0;
virtual void setFanPolarity(bool invert) = 0;
virtual void setFanSpeedCh(int channel, float perc) = 0;
virtual void setFanSpeed(float perc) {
for (int i=0;i<getNumFans();i++) {
setFanSpeedCh(i, perc);
}
}
virtual void getFanSpeedCh(int channel, uint16_t *rpm) = 0;
virtual int getNumFans() { return m_numFans; }
virtual float getTemperature(int index) = 0;
virtual float getVRTemp() = 0;
virtual bool isPIDAvailable() = 0;
virtual float getVin() = 0;
virtual float getIin() = 0;
virtual float getPin() = 0;
virtual float getVout() = 0;
virtual float getIout() = 0;
virtual float getPout() = 0;
virtual void requestBuckTelemtry() = 0;
virtual void requestChipTemps();
void setChipTemp(int nr, float temp);
float getMaxChipTemp();
float getChipTemp(int nr);
virtual void shutdown() {
m_shutdown = true;
}
virtual Error getFault(uint32_t *status)
{
*status = 0x00000000;
return Error::NONE;
}
virtual bool selfTest();
Theme *getTheme()
{
return m_theme;
};
uint32_t getAsicMaxDifficulty()
{
return m_asicMaxDifficulty;
};
uint32_t getAsicMinDifficulty()
{
return m_asicMinDifficulty;
};
uint32_t getAsicMinDifficultyDualPool()
{
return m_asicMinDifficultyDualPool;
};
bool isInitialized()
{
return m_isInitialized;
};
bool isBuckInitialized()
{
return m_isBuckInitialized;
}
virtual Asic *getAsics()
{
return m_isInitialized ? m_asics : nullptr;
}
int getAsicVoltageMillis()
{
return m_asicVoltageMillis;
}
int getAsicFrequency()
{
return m_asicFrequency;
}
int getAbsMaxAsicFrequency() {
return m_absMaxAsicFrequency;
}
int getAbsMinAsicVoltageMillis() {
return m_absMinAsicVoltageMillis;
}
int getAbsMaxAsicVoltageMillis() {
return m_absMaxAsicVoltageMillis;
}
int getDefaultAsicVoltageMillis()
{
return m_defaultAsicVoltageMillis;
}
int getDefaultAsicFrequency()
{
return m_defaultAsicFrequency;
}
int getEcoAsicVoltageMillis()
{
return m_ecoAsicVoltageMillis;
}
int getEcoAsicFrequency()
{
return m_ecoAsicFrequency;
}
uint32_t getDefaultVrFrequency() {
return m_defaultVrFrequency;
}
uint32_t getVrFrequency() {
return m_vrFrequency;
}
float getMinPin()
{
return m_minPin;
}
float getMaxPin()
{
return m_maxPin;
}
float getMinVin()
{
return m_minVin;
}
float getMaxVin()
{
return m_maxVin;
}
// Returns the minimum input current (A) for UI gauge scaling
float getMinCurrentA()
const {
return m_minCurrentA;
}
// Returns the maximum input current (A) for UI gauge scaling
float getMaxCurrentA()
const {
return m_maxCurrentA;
}
float getVrMaxTemp()
{
return m_vr_maxTemp;
}
int getNumTempSensors()
{
return m_numTempSensors;
}
bool isFlipScreenEnabled()
{
return m_flipScreen;
}
bool isInvertFanPolarityEnabled()
{
return m_fanInvertPolarity;
}
PidSettings *getPidSettings(int ch = 0) {
return &m_pidSettings[ch];
}
int getFanMode(int ch) {
return m_fanMode[ch];
}
const char* getFanLabel(int ch) const {
if (ch < 0 || ch >= m_numFans) return "";
return m_fanLabels[ch];
}
const std::vector<uint32_t>& getFrequencyOptions() const {
return m_asicFrequencies;
}
const std::vector<uint32_t>& getVoltageOptions() const {
return m_asicVoltages;
}
const char* getSwarmColorName() {
return m_swarmColorName;
}
virtual bool hasHashrateCounter() {
return m_hasHashCounter;
}
virtual bool hasEthernet() {
return false;
}
virtual bool hasCanExtension() {
return false;
}
virtual bool isCanSlave() {
return false;
}
// Returns the slave ID (1-based) to use for CAN telemetry/nonce frames.
// Override in boards that implement multi-slave DIP switch detection.
virtual uint8_t getCanSlaveId() {
return 1;
}
// CAN transceiver GPIO pins. Override in boards that have CAN hardware.
virtual int getCanTxPin() { return -1; }
virtual int getCanRxPin() { return -1; }
const char* getDefaultTheme() {
return m_defaultTheme;
}
bool isShutdown() {
return m_shutdown;
}
virtual float getVRTempInt() {
return 0.0f;
}
};