Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HWDEF_TF_BOOST_HDR_H
- #define HWDEF_TF_BOOST_HDR_H
- #define LAYOUT_DEFINED
- #ifdef ATTINY
- #undef ATTINY
- #endif
- #define ATTINY 1616
- #include <avr/io.h>
- #define PWM_CHANNELS 1
- #ifndef SWITCH_PIN
- #define SWITCH_PIN PIN5_bp
- #define SWITCH_PORT VPORTB.IN
- #define SWITCH_ISC_REG PORTB.PIN5CTRL
- #define SWITCH_VECT PORTB_PORT_vect
- #define SWITCH_INTFLG VPORTB.INTFLAGS
- #endif
- #ifndef PWM1_PIN
- #define PWM1_PIN PB0 //
- #define PWM1_LVL TCA0.SINGLE.CMP0 // CMP0 is the output compare register for PB0
- #endif
- //boost enable
- #define LED_ENABLE_PIN PIN5_bp
- #define LED_ENABLE_PORT PORTA_OUT
- #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
- #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN7_gc // which ADC channel to read, AIN7 for PA7
- // Raw ADC readings at 4.4V and 2.2V
- // calibrate the voltage readout here
- // estimated / calculated values are:
- // [(Vbatt)*(R2/(R2+R1)) / 1.1] * 1023
- // R1 = R2 = 100kR
- #ifndef ADC_44
- #define ADC_44 804
- #endif
- #ifndef ADC_22
- #define ADC_22 402
- #endif
- // this driver allows for aux LEDs under the optic
- #ifndef AUXLED_R_PIN
- #define AUXLED_R_PIN PIN1_bp
- #endif
- #ifndef AUXLED_G_PIN
- #define AUXLED_G_PIN PIN2_bp
- #endif
- #ifndef AUXLED_B_PIN
- #define AUXLED_B_PIN PIN3_bp
- #endif
- #define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC
- // with so many pins, doing this all with #ifdefs gets awkward...
- // ... so just hardcode it in each hwdef file instead
- inline void hwdef_setup() {
- // set up the system clock to run at 5 MHz instead of the default 3.33 MHz
- _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm );
- VPORTA.DIR = PIN5_bm; //enable
- VPORTB.DIR = PIN0_bm; // PWM
- VPORTA.DIR = PIN1_bm; //R
- VPORTA.DIR = PIN2_bm; //G
- VPORTA.DIR = PIN3_bm; //B
- //VPORTC.DIR = PIN0_bm | PIN1_bm; // PWM pins as output
- //VPORTA.DIR = PIN6_bm; // current range pin
- // enable pullups on the input pins to reduce power
- PORTA.PIN0CTRL = PORT_PULLUPEN_bm;
- //PORTA.PIN1CTRL = PORT_PULLUPEN_bm;R
- //PORTA.PIN2CTRL = PORT_PULLUPEN_bm;G
- //PORTA.PIN3CTRL = PORT_PULLUPEN_bm;B
- PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
- //PORTA.PIN5CTRL = PORT_PULLUPEN_bm; enable
- PORTA.PIN6CTRL = PORT_PULLUPEN_bm; //
- //PORTA.PIN7CTRL = PORT_PULLUPEN_bm; // Vbat
- //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // PWM
- PORTB.PIN1CTRL = PORT_PULLUPEN_bm; //
- PORTB.PIN2CTRL = PORT_PULLUPEN_bm; //
- PORTB.PIN3CTRL = PORT_PULLUPEN_bm; //
- PORTB.PIN4CTRL = PORT_PULLUPEN_bm; //
- PORTB.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // e-switch
- PORTC.PIN0CTRL = PORT_PULLUPEN_bm; //
- PORTC.PIN1CTRL = PORT_PULLUPEN_bm; //
- PORTC.PIN2CTRL = PORT_PULLUPEN_bm;
- PORTC.PIN3CTRL = PORT_PULLUPEN_bm;
- //set up PWM TCA
- TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
- TCA0.SINGLE.PER = 255;
- TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement