4
* Driver layout header.
6
* New layout definition structure 2017, (C) Flintrock (FR).
8
* To work with tk-bistro and other compatible software.
10
* Tried to keep it compatible with
11
* previous version, but likely some failure there.
13
* Inspired by and mostly compatible with Original version by Selene Scriven (C) 2015
15
* This program is free software: you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
17
* the Free Software Foundation, either version 3 of the License, or
18
* (at your option) any later version.
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
25
* You should have received a copy of the GNU General Public License
26
* along with this program. If not, see <http://www.gnu.org/licenses/>.
33
/******************** hardware-specific values **************************/
35
#define F_CPU 4800000UL
36
#define _TIMSK_ TIMSK0
37
#define _TIMER0_OVF_vect_ TIM0_OVF_vect
41
// adc_prscl belongs here. It has nothing to do with layout but does relate some to selected F_CPU above.
42
#define ADC_PRSCL 0x06 // 02 is 4, 03, is 8, 04 is 16, 05 is 32, 06 is 64 // adc rate is F_CPU/13/prescale
44
#elif (ATTINY == 25) || (ATTINY == 45) || (ATTINY ==85)
45
// TODO: Use 6.4 MHz instead of 8 MHz?
46
// FR adds some addresses for use in asm I/O address space
48
#define _TIMER0_OVF_vect_ TIMER0_OVF_vect
49
#define F_CPU 8000000UL
50
#define EEPSIZE 128 // not actually correct for 45 and 85 (256) but doesn't matter.
51
#define V_REF REFS1 // just defines which bit controls the voltage reference.
52
// since we don't touch REFS0 2.56V is not available (not very useful anyway).
53
#define VCC_REF_PIN 0x00 // ADC ref when using Vcc as a reference really just a 1 bit value.
54
#define _1V_ADC_INPUT 0x0C // ID For one volt reference when used as input (not reference) to ADC
55
// Bogomips appears to be used in tk-delay.h
56
// as the number ticks needed for a 1 ms delay where a tick is 4 clock cycles
57
// as defined by _delay_loop2:
58
// http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__util__delay__basic_1ga74a94fec42bac9f1ff31fd443d419a6a.html
59
// The example there says 65536 corresponds to 261ms for 1Mhz so 250 ticks per ms ie FCPU/4000.
60
// anyway, the POWERSAVE delay re-implements this with a timer clock instead.
61
#define BOGOMIPS (F_CPU/4000)
62
#define TEMP_CHANNEL 0b00001111
63
// Mooved adc_prscl here. It has nothing to do with layout but does relate to selecte F_CPU above.
64
#define ADC_PRSCL 0x06 // 02 is 4, 03, is 8, 04 is 16, 05 is 32, 06 is 64 // adc rate is F_CPU/13/prescale
66
Hey, you need to define ATTINY.
69
// FR's new simplified "auto"-defines,
70
// 2017 by Flintrock (C)
71
// Just define which PWM channels you want, then the extras.
72
// Also just define everything by PORTB (PB) number. Lookups work out the other details automatically.
75
// A layout for you to customize
79
* PB5 Reset -|1 8|- VCC
80
* PB3 PWM4/OTC/ESWITCH -|2 7|- Voltage/OTSM/ESWITCH PB2
81
* PB4 PWM3 -|3 6|- PWM1 PB1
82
* GND -|4 5|- PWM2 PB0
86
// ALL numbers use PB numbers
87
// First choose which PWM pins to use.
88
//#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
89
//#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
90
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
91
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup.
93
// ASSIGN PINS FOR EXTRA FEATURES, You can change the pin numbers within reason. They can overlap in some cases.
94
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
95
//#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
96
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff. Requires #define OTSM in bistro.c to activate.
97
//#define ESWITCH_PIN PB3 // Usually instead of CAP_PIN. Requires #define USE_ESWITCH in bistro.c to activate.
98
// Can double/triple up on the OTSM/Voltage PIN (e: 4 channel driver) by shorting R2 with the e_switch.
99
// Could even pull it to 0.5V and distinguish the two switches with ADC. (not implemented)
101
//#define STAR2_PIN PB0 // These have no purpose in the bistro software.
102
//#define STAR3_PIN PB4
103
//#define STAR4_PIN PB3
105
/* Note: you can define/uncomment multiple functions for a pin even if some are not used for a particular compilation.
106
* Which functions are used are defined in bistro.
107
* Ex, if you define ESWITCH and Voltage on the same pin (a legitimate combination anyway), but you define READ_VOLTAGE_FROM_VCC in bistro,
108
* bistro will enable a pull-up resistor on the pin to define the open-switch state, in theory at least. In contrast if READ_VOLTAGE_FROM divider
109
* is defined, it will disable the pull-up on the voltage pin. Pull-up on OTSM_PIN is also disabled if USE_OTSM is defined in bistro.
114
#endif // CUSTOM_LAYOUT
116
//FR's new simplified "auto"-defines
117
// you can't really pick and choose where to put pwms
118
// without changing the initialization code.. so define 4 and just choose which ones you want:
119
// Also just define everything by PB number, use lookups to work it out below the config settings.
121
#ifdef TRIPLEDOWN_LAYOUT
124
* PB5 Reset -|1 8|- VCC
125
* PB3 ESWITCH/OTC -|2 7|- Voltage ADC/OTSM/INDICATOR PB2
126
* PB4 PWM3 (FET) -|3 6|- PWM1 (6x7135) PB1
127
* GND -|4 5|- PWM2 (1x7135) PB0
131
// ALL numbers use PB numbers
132
// First choose which PWM pins to use.
133
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
134
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
135
#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
136
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
138
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
139
#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
140
#define VOLTAGE_PIN PB2 // PB2,PB3, PB4 are only really valid. If using VCC it's ignored.
141
#define INDICATOR_PIN PB2 // This only gets used if enabled with #define USE_INDICATOR in main config
142
#define OTSM_PIN PB2 // PIN to check for voltage shutoff (clicky). Requires #define OTSM in bistro.c to activate.
143
// This can be the same as the voltage pin, if the voltage is kept > 1.8V while on.
144
// That generally requires using an LDO as a VCC voltage reference.
145
#define ESWITCH_PIN PB3 // Usually instead of CAP_PIN. Requires #define USE_ESWITCH in bistro.c to activate.
146
// Can double/triple up on the OTSM/Voltage PIN (e: 4 channel driver) by shorting R2 with the e_switch.
147
// Could even pull it to 0.5V and distinguish the two switches with ADC. (not implemented)
149
//#define STAR2_PIN PB0 // These have no purpose in the bistro software.
150
//#define STAR3_PIN PB4
151
//#define STAR4_PIN PB3
153
/* Note: you can define/uncomment multiple functions for a pin even if some are not used for a particular compilation.
154
* Which functions are used are defined in bistro.
155
* Ex, if you define ESWITCH and Voltage on the same pin (a legitimate combination anyway), but you define READ_VOLTAGE_FROM_VCC in bistro,
156
* bistro will enable a pull-up resistor on the pin to define the open-switch state, in theory at least. In contrast if READ_VOLTAGE_FROM divider
157
* is defined, it will disable the pull-up on the voltage pin. Pull-up on OTSM_PIN is also disabled if USE_OTSM is defined in bistro.
162
#endif // TRIPLE_DOWN_LAYOUT
164
/*********************************************************************/
166
#ifdef QUADRUPLEDOWN_LAYOUT
167
// An example of a Quad layout, although the real point here is that these can easily be configured "on the fly" as needed.
171
* PB5 Reset -|1 8|- VCC
172
* PB3 PWM4 Blue -|2 7|- Voltage ADC PB2
173
* PB4 PWM3 Red -|3 6|- PWM1 White PB1
174
* GND -|4 5|- PWM2 Green PB0
178
// ALL numbers use PB numbers
179
// First choose which PWM pins to use.
180
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
181
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
182
#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
183
#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
185
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
186
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
187
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
188
#define OTSM_PIN PB2 // PIN to check for voltage shutoff. Requires #define OTSM in bistro.c to activate.
189
#define ESWITCH_PIN PB2 // Usually instead of CAP_PIN. Requires #define USE_ESWITCH in bistro.c to activate.
190
// Can double/triple up on the OTSM/Voltage PIN (e: 4 channel driver) by shorting R2 with the e_switch.
191
// Could even pull it to 0.5V and distinguish the two switches with ADC. (not implemented)
193
//#define STAR2_PIN PB0 // These have no purpose in the bistro software.
194
//#define STAR3_PIN PB4
195
//#define STAR4_PIN PB3
199
#endif // QUADRUPLE_DOWN_LAYOUT
201
/*********************************************************************/
203
/*********************************************************************/
208
* PB5 Reset -|1 8|- VCC
209
* PB3 e-switch -|2 7|- Voltage PB2 (stock: unused)
210
* PB4 IndicatorLED-|3 6|- PWM (FET) PB1
211
* GND -|4 5|- PWM2 (1x7135) PB0
216
// First choose which PWM pins to use.
217
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
218
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
219
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
220
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
222
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
223
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
224
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
225
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
226
#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
227
#define INDICATOR_PIN PB4 // indicator LED.
228
//#define STAR3_PIN PB4
230
// adc rate is F_CPU/13/prescale
232
#endif // BLFA6_LAYOUT
235
#ifdef FET_7135_LAYOUT
239
* PB5 Reset -|1 8|- VCC
240
* PB3 OTC -|2 7|- PWM4 Blue PB2
241
* PB4 PWM3 Red -|3 6|- PWM1 White PB1
242
* GND -|4 5|- PWM2 Green PB0
246
// ALL numbers use PB numbers
247
// First choose which PWM pins to use.
248
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
249
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
250
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
251
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
253
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
254
#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
255
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
256
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
257
//#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
258
#define STAR2_PIN PB0 // These have no purpose in the bistro software.
259
#define STAR3_PIN PB4
262
#endif //FET_7135_LAYOUT
264
/*********************************************************************/
266
#ifdef FERRERO_ROCHER_LAYOUT
270
* E-switch -|2 7|- Voltage ADC
271
* Red LED -|3 6|- PWM
272
* GND -|4 5|- Green LED
275
// ALL numbers use PB numbers
276
// First choose which PWM pins to use.
277
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually (PWM)
278
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple (GREEN)
279
#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel (RED)
280
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
282
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
283
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
284
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
285
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
286
#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
287
//#define STAR2_PIN PB0 // These have no purpose in the bistro software.
288
//#define STAR3_PIN PB4
289
//#define STAR4_PIN PB3
291
// adc rate is F_CPU/13/prescale
293
#endif // FERRERO_ROCHER_LAYOUT
296
/*********************************************************************/
298
//* NANJG 105C Diagram
301
* PB5 Reset -|1 8|- VCC
302
* PB3 OTC -|2 7|- Voltage ADC PB2
303
* PB4 Star 3-|3 6|- PWM (FET) PB1
304
* GND -|4 5|- PWM2 (1x7135) PB0
309
// First choose which PWM pins to use.
310
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
311
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
312
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
313
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
315
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
316
#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
317
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
318
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
319
//#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
320
#define STAR3_PIN PB4
322
// adc rate is F_CPU/13/prescale
324
#endif // BLFA6_LAYOUT
327
//* NANJG 105D Convoy/biscotti
330
* PB5 Reset -|1 8|- VCC
331
* PB3 -|2 7|- Voltage ADC PB2
333
* GND -|4 5|- PWM2 (FET) PB0
337
#ifdef NANJG105D_LAYOUT
338
// First choose which PWM pins to use.
339
//#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
340
#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
341
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
342
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
344
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
345
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
346
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
347
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
348
//#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
349
//#define STAR3_PIN PB4
351
// adc rate is F_CPU/13/prescale
353
#endif // BLFA6_LAYOUT
356
#ifdef NANJG_LAYOUT // is this even right for anything?
357
// First choose which PWM pins to use.
358
#define ENABLE_PWM1 // PWM on pb1 (pin 5) Single 7135 usually
359
//#define ENABLE_PWM2 // PWM on pb0 (pin 6) FET in FET+1 or 7135s in triple
360
//#define ENABLE_PWM3 // PWM on pb4 (pin 3) FET in triple channel
361
//#define ENABLE_PWM4 // PWM on pb3 (pin 2) Can be used for RGBW setup
363
// SELECT PINS FOR EXTRA FEATURES, these may overlap in some cases.
364
//#define CAP_PIN PB3 // OTC CAP or secondary OTSM CAP
365
#define VOLTAGE_PIN PB2 // set to pb number or VCC Only PB2,PB3, PB4 and VCC are really valid
366
//#define OTSM_PIN PB2 // PIN to check for voltage shutoff
367
//#define ESWITCH_PIN PB3 // usually instead of CAP_PIN but could double up on OTSM PIN
368
#define STAR2_PIN PB0 // These have no purpose in the bistro software.
369
#define STAR3_PIN PB4
370
#define STAR4_PIN PB3
372
// adc rate is F_CPU/13/prescale
374
#endif // NANJG_LAYOUT
377
/*************************************************END OF LAYOUT DEFINITIONS*********************************************/
378
/*******************You should not need to edit below here**************************************************************/
379
// Below are universal associations, mostly to define the PWM OCR associations and adc_mux
380
// corresponding to selected pins.
381
// the idea is these would eventually go after all defines.
385
#define PWM_PIN PB1 // pin 6, FET PWM
386
#define PWM1_LVL OCR0B // OCR0B is the output compare register for PB1
390
#define PWM2_PIN PB0 // pin 5
391
#define PWM2_LVL OCR0A // output compare register for PB4
392
// for backwards compatibility, not used in bistro-HD
393
#define ALT_PWM_PIN PWM2_PIN
394
#define ALT_PWM1_LVL PWM2_LVL
398
#define PWM3_PIN PB4 // pin 3
399
#define PWM3_LVL OCR1B // output compare register for PB4
400
// for backwards compatibility, not used in bistro-HD
402
#define FET_PWM1_LVL PWM3_LVL
406
#define PWM4_PIN PB3 // pin 3
407
#define PWM4_LVL OCR1A // output compare register to be used with PB3
408
// This one does NOT attach to PB3, An interrupt will be used instead.
412
#if defined(VOLTAGE_PIN)
413
//&& VOLTAGE_PIN != VCC_REF_PIN
414
// Should use_vcc just be determined by this config?
415
#define ADC_PIN VOLTAGE_PIN // SYNONYMS
416
#define ADC_DIDR VOLTAGE_PIN // Digital input disable bit corresponding with PB2, redundant
419
#if defined(ADC_PIN) && !defined(VOLTAGE_PIN)
420
#define VOLTAGE_PIN ADC_PIN // for backwards compatibility
424
#if defined(VOLTAGE_PIN)
425
// Lookup the adc channel
426
#if VOLTAGE_PIN == PB2 // is there a more elegant way?
427
#define ADC_CHANNEL 1
428
#elif VOLTAGE_PIN == PB4
429
#define ADC_CHANNEL 2
430
#elif VOLTAGE_PIN == PB3
431
#define ADC_CHANNEL 3
432
#elif VOLTAGE_PIN == PB5 // reset pin, probably going to be... interesting to try.
433
#define ADC_CHANNEL 0
435
No ADC channel exists on the selected VOLTAGE_PIN. Try PB2, PB3, PB4, or PB5 (PB3 on most drivers).
447
#endif // FR_ATTINY_H