Advertisement
Guest User

hwdef

a guest
Apr 6th, 2021
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.09 KB | None | 0 0
  1. #ifndef HWDEF_TF_BOOST_HDR_H
  2. #define HWDEF_TF_BOOST_HDR_H
  3.  
  4.  
  5.  
  6. #define LAYOUT_DEFINED
  7.  
  8. #ifdef ATTINY
  9. #undef ATTINY
  10. #endif
  11. #define ATTINY 1616
  12. #include <avr/io.h>
  13.  
  14. #define PWM_CHANNELS 1
  15.  
  16.  
  17. #ifndef SWITCH_PIN
  18. #define SWITCH_PIN     PIN5_bp    
  19. #define SWITCH_PORT    VPORTB.IN
  20. #define SWITCH_ISC_REG PORTB.PIN5CTRL
  21. #define SWITCH_VECT    PORTB_PORT_vect
  22. #define SWITCH_INTFLG  VPORTB.INTFLAGS
  23. #endif
  24.  
  25. #ifndef PWM1_PIN
  26. #define PWM1_PIN PB0               //
  27. #define PWM1_LVL TCA0.SINGLE.CMP0  // CMP0 is the output compare register for PB0
  28. #endif
  29.  
  30. //boost enable
  31. #define LED_ENABLE_PIN   PIN5_bp
  32. #define LED_ENABLE_PORT  PORTA_OUT
  33.  
  34.  
  35. #define USE_VOLTAGE_DIVIDER       // use a dedicated pin, not VCC, because VCC input is flattened
  36. #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN7_gc  // which ADC channel to read, AIN7 for PA7
  37.  
  38. // Raw ADC readings at 4.4V and 2.2V
  39. // calibrate the voltage readout here
  40. // estimated / calculated values are:
  41. // [(Vbatt)*(R2/(R2+R1)) / 1.1] * 1023
  42. // R1 = R2 = 100kR
  43. #ifndef ADC_44
  44. #define ADC_44 804
  45. #endif
  46. #ifndef ADC_22
  47. #define ADC_22 402
  48. #endif
  49.  
  50.  
  51. // this driver allows for aux LEDs under the optic
  52. #ifndef AUXLED_R_PIN
  53. #define AUXLED_R_PIN  PIN1_bp
  54. #endif
  55. #ifndef AUXLED_G_PIN
  56. #define AUXLED_G_PIN  PIN2_bp
  57. #endif
  58. #ifndef AUXLED_B_PIN
  59. #define AUXLED_B_PIN  PIN3_bp
  60. #endif
  61.  
  62. #define AUXLED_RGB_PORT PORTA  // PORTA or PORTB or PORTC
  63.  
  64.  
  65.  
  66. // with so many pins, doing this all with #ifdefs gets awkward...
  67. // ... so just hardcode it in each hwdef file instead
  68. inline void hwdef_setup() {
  69.  
  70.     // set up the system clock to run at 5 MHz instead of the default 3.33 MHz
  71.     _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm );
  72.  
  73.     VPORTA.DIR = PIN5_bm;  //enable
  74.     VPORTB.DIR = PIN0_bm;   // PWM
  75.     VPORTA.DIR = PIN1_bm; //R
  76.     VPORTA.DIR = PIN2_bm; //G
  77.     VPORTA.DIR = PIN3_bm; //B
  78.    
  79.     //VPORTC.DIR = PIN0_bm | PIN1_bm;  // PWM pins as output
  80.     //VPORTA.DIR = PIN6_bm; // current range pin
  81.  
  82.  
  83.     // enable pullups on the input pins to reduce power
  84.     PORTA.PIN0CTRL = PORT_PULLUPEN_bm;
  85.     //PORTA.PIN1CTRL = PORT_PULLUPEN_bm;R
  86.     //PORTA.PIN2CTRL = PORT_PULLUPEN_bm;G
  87.     //PORTA.PIN3CTRL = PORT_PULLUPEN_bm;B
  88.     PORTA.PIN4CTRL = PORT_PULLUPEN_bm;
  89.     //PORTA.PIN5CTRL = PORT_PULLUPEN_bm; enable
  90.     PORTA.PIN6CTRL = PORT_PULLUPEN_bm; //
  91.     //PORTA.PIN7CTRL = PORT_PULLUPEN_bm; // Vbat
  92.    
  93.     //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; //  PWM
  94.     PORTB.PIN1CTRL = PORT_PULLUPEN_bm; //
  95.     PORTB.PIN2CTRL = PORT_PULLUPEN_bm; //
  96.     PORTB.PIN3CTRL = PORT_PULLUPEN_bm;  //
  97.     PORTB.PIN4CTRL = PORT_PULLUPEN_bm; //
  98.     PORTB.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;   // e-switch
  99.    
  100.     PORTC.PIN0CTRL = PORT_PULLUPEN_bm; //
  101.     PORTC.PIN1CTRL = PORT_PULLUPEN_bm; //
  102.     PORTC.PIN2CTRL = PORT_PULLUPEN_bm;
  103.     PORTC.PIN3CTRL = PORT_PULLUPEN_bm;
  104.  
  105.    
  106.      //set up PWM TCA
  107.     TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc;
  108.     TCA0.SINGLE.PER = 255;
  109.     TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm;
  110.        
  111. }
  112.  
  113.  
  114. #endif
  115.  
  116.  
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement