1
/****************************************************************************************
2
* channels.h - output channel support with ramping tables
8
* For TA style triples, 3 channel:
11
* switch 2 -| |- 7 Voltage ADC or Indicator LED
12
* FET PWM 3 -| |- 6 bank of 7135s PWM
13
* GND 4 -| |- 5 one 7135 PWM
16
* For standard FET+1, 2 channels:
19
* switch 2 -| |- 7 Voltage ADC
20
* Ind.LED 3 -| |- 6 FET PWM
21
* GND 4 -| |- 5 7135 PWM
24
* For 1 channel, using a NANJG or FET+1:
27
* switch 2 -| |- 7 Voltage ADC
28
* Ind.LED 3 -| |- 6 FET or 7135s PWM
29
* GND 4 -| |- 5 Not Used (7135 PWM)
33
****************************************************************************************/
37
//---------------------------------------------------------------------------------------
38
//---------------------------------------------------------------------------------------
39
#if OUT_CHANNELS == 2 // FET+1
40
//---------------------------------------------------------------------------------------
41
//---------------------------------------------------------------------------------------
44
/**************************************************************************************
47
**************************************************************************************/
48
void TurnOnBoardLed(byte on)
54
DDRB = (1 << ONE7135_PWM_PIN) | (1 << FET_PWM_PIN) | (1 << ONBOARD_LED_PIN);
55
PORTB |= (1 << ONBOARD_LED_PIN);
59
DDRB = (1 << ONE7135_PWM_PIN) | (1 << FET_PWM_PIN);
60
PORTB &= 0xff ^ (1 << ONBOARD_LED_PIN);
66
/**************************************************************************************
69
**************************************************************************************/
74
modesCnt = pgm_read_byte(modeSetCnts+modeSetIdx);
76
// Set OFF mode states (index 0)
77
by7135Modes[0] = byFETModes[0] = 0;
82
by7135Modes[1] = moonlightLevel; // PWM value to use for moonlight mode
86
// Populate the RAM based current mode set
87
for (int i = 0; i < modesCnt; i++)
89
by7135Modes[offset+i] = pgm_read_byte(modeTable7135[modeSetIdx]+i);
90
byFETModes[offset+i] = pgm_read_byte(modeTableFet[modeSetIdx]+i);
93
modesCnt += offset; // adjust to total mode count
96
/**************************************************************************************
97
* SetOutput - sets the PWM output values directly for the two channels
99
**************************************************************************************/
100
inline void SetOutput(byte pwm7135, byte pwmFet)
102
ONE7135_PWM_LVL = pwm7135;
103
FET_PWM_LVL = pwmFet;
106
/**************************************************************************************
107
* SetLevel - uses the ramping levels to set the PWM output
108
* ======== (0 is OFF, 1..RAMP_SIZE is the ramping index level)
109
**************************************************************************************/
110
void SetLevel(byte level)
114
SetOutput(OFF_OUTPUT);
123
level -= 1; // make it 0 based
124
SetOutput(pgm_read_byte(ramp_7135 + level), pgm_read_byte(ramp_FET + level));
133
/**************************************************************************************
136
**************************************************************************************/
137
void inline SetMode(byte mode)
139
currOutLvl1 = by7135Modes[mode];
140
currOutLvl2 = byFETModes[mode];
142
SetOutput(currOutLvl1, currOutLvl2);
145
if ((mode == 0) && locatorLed)
147
else if (last_modeIdx == 0)
152
//---------------------------------------------------------------------------------------
153
//---------------------------------------------------------------------------------------
154
#elif OUT_CHANNELS == 3 // Triple Channel
155
//---------------------------------------------------------------------------------------
156
//---------------------------------------------------------------------------------------
159
/**************************************************************************************
162
**************************************************************************************/
163
void TurnOnBoardLed(byte on)
165
if (onboardLedEnable)
169
DDRB = (1 << ONE7135_PWM_PIN) | (1 << BANK_PWM_PIN) | (1 << FET_PWM_PIN) | (1 << ONBOARD_LED_PIN);
171
PORTB |= (1 << ONBOARD_LED_PIN);
175
DDRB = (1 << ONE7135_PWM_PIN) | (1 << BANK_PWM_PIN) | (1 << FET_PWM_PIN);
176
PORTB &= 0xff ^ (1 << ONBOARD_LED_PIN);
182
/**************************************************************************************
185
**************************************************************************************/
190
modesCnt = pgm_read_byte(modeSetCnts+modeSetIdx);
192
// Set OFF mode states (index 0)
193
by7135Modes[0] = by7135sModes[0] = byFETModes[0] = 0;
198
by7135Modes[1] = moonlightLevel; // PWM value to use for moonlight mode
199
by7135sModes[1] = byFETModes[1] = 0;
202
// Populate the RAM based current mode set
203
for (int i = 0; i < modesCnt; i++)
205
by7135Modes[offset+i] = pgm_read_byte(modeTable7135[modeSetIdx]+i);
206
by7135sModes[offset+i] = pgm_read_byte(modeTable7135s[modeSetIdx]+i);
207
byFETModes[offset+i] = pgm_read_byte(modeTableFet[modeSetIdx]+i);
210
modesCnt += offset; // adjust to total mode count
213
/**************************************************************************************
214
* SetOutput - sets the PWM output value directly
216
**************************************************************************************/
217
inline void SetOutput(byte pwm7135, byte pwm7135s, byte pwmFet)
218
ONE7135_PWM_LVL = pwm7135;
219
BANK_PWM_LVL = pwm7135s;
220
FET_PWM_LVL = pwmFet;
222
/**************************************************************************************
223
* SetLevel - uses the ramping levels to set the PWM output
224
* ======== (0 is OFF, 1..RAMP_SIZE is the ramping index level)
225
**************************************************************************************/
226
void SetLevel(byte level)
b'\t\t\tTurnOnBoardLed(1);'
b'\t\tlevel -= 1;\t// make it 0 based'
231
SetOutput(pgm_read_byte(ramp_7135 + level), pgm_read_byte(ramp_7135s + level), pgm_read_byte(ramp_FET + level));
b'\t\t\tTurnOnBoardLed(0);'
236
/**************************************************************************************
239
**************************************************************************************/
240
void inline SetMode(byte mode)
242
currOutLvl1 = by7135Modes[mode];
243
currOutLvl2 = by7135sModes[mode];
244
currOutLvl3 = byFETModes[mode];
246
SetOutput(currOutLvl1, currOutLvl2, currOutLvl3);
248
if ((mode == 0) && locatorLed)
250
else if (last_modeIdx == 0)
255
//---------------------------------------------------------------------------------------
256
//---------------------------------------------------------------------------------------
257
#elif OUT_CHANNELS == 1 // single FET or single bank of 7135's
258
//---------------------------------------------------------------------------------------
259
//---------------------------------------------------------------------------------------
262
/**************************************************************************************
265
**************************************************************************************/
266
void TurnOnBoardLed(byte on)
268
if (onboardLedEnable)
272
DDRB = (1 << MAIN_PWM_PIN) | (1 << ONBOARD_LED_PIN);
273
PORTB |= (1 << ONBOARD_LED_PIN);
277
DDRB = (1 << MAIN_PWM_PIN);
278
PORTB &= 0xff ^ (1 << ONBOARD_LED_PIN);
284
/**************************************************************************************
287
**************************************************************************************/
292
modesCnt = pgm_read_byte(modeSetCnts+modeSetIdx);
294
// Set OFF mode states (index 0)
300
byMainModes[1] = moonlightLevel; // PWM value to use for moonlight mode
303
// Populate the RAM based current mode set
304
for (int i = 0; i < modesCnt; i++)
306
byMainModes[offset+i] = pgm_read_byte(modeTable1Chan[modeSetIdx]+i);
309
modesCnt += offset; // adjust to total mode count
312
/**************************************************************************************
313
* SetOutput - sets the PWM output values directly for the one channel
315
**************************************************************************************/
316
inline void SetOutput(byte pwmChan)
318
MAIN_PWM_LVL = pwmChan;
321
/**************************************************************************************
322
* SetLevel - uses the ramping levels to set the PWM output
323
* ======== (0 is OFF, 1..RAMP_SIZE is the ramping index level)
324
**************************************************************************************/
325
void SetLevel(byte level)
329
SetOutput(OFF_OUTPUT);
338
level -= 1; // make it 0 based
339
SetOutput(pgm_read_byte(ramp_1Chan + level));
348
/**************************************************************************************
351
**************************************************************************************/
352
void inline SetMode(byte mode)
354
currOutLvl = byMainModes[mode];
356
SetOutput(currOutLvl);
359
if ((mode == 0) && locatorLed)
361
else if (last_modeIdx == 0)
368
#endif /* CHANNELS_H_ */
b'\\ No newline at end of file'