Austin Schuh | b402fd4 | 2019-04-13 00:02:53 -0700 | [diff] [blame] | 1 | #include "motors/pistol_grip/controller_adc.h" |
| 2 | |
| 3 | #include "motors/peripheral/adc.h" |
| 4 | |
| 5 | namespace frc971 { |
| 6 | namespace motors { |
| 7 | |
| 8 | void AdcInitSmall() { |
| 9 | AdcInitCommon(); |
| 10 | |
| 11 | // M0_CH0F ADC1_SE17 |
| 12 | PORTA_PCR17 = PORT_PCR_MUX(0); |
| 13 | |
| 14 | // M0_CH1F ADC1_SE14 |
| 15 | PORTB_PCR10 = PORT_PCR_MUX(0); |
| 16 | |
| 17 | // M0_CH2F ADC1_SE15 |
| 18 | PORTB_PCR11 = PORT_PCR_MUX(0); |
| 19 | |
| 20 | // M0_ABS ADC0_SE5b |
| 21 | PORTD_PCR1 = PORT_PCR_MUX(0); |
| 22 | |
| 23 | // M1_CH0F ADC0_SE13 |
| 24 | PORTB_PCR3 = PORT_PCR_MUX(0); |
| 25 | |
| 26 | // M1_CH1F ADC0_SE12 |
| 27 | PORTB_PCR2 = PORT_PCR_MUX(0); |
| 28 | |
| 29 | // M1_CH2F ADC0_SE14 |
| 30 | PORTC_PCR0 = PORT_PCR_MUX(0); |
| 31 | |
| 32 | // M1_ABS ADC0_SE17 |
| 33 | PORTE_PCR24 = PORT_PCR_MUX(0); |
| 34 | |
| 35 | // WHEEL_ABS ADC0_SE18 |
| 36 | PORTE_PCR25 = PORT_PCR_MUX(0); |
| 37 | |
| 38 | // VIN ADC1_SE5B |
| 39 | PORTC_PCR9 = PORT_PCR_MUX(0); |
| 40 | } |
| 41 | |
| 42 | SmallAdcReadings AdcReadSmall0(const DisableInterrupts &) { |
| 43 | SmallAdcReadings r; |
| 44 | |
| 45 | ADC1_SC1A = 17; |
| 46 | while (!(ADC1_SC1A & ADC_SC1_COCO)) { |
| 47 | } |
| 48 | ADC1_SC1A = 14; |
| 49 | r.currents[0] = ADC1_RA; |
| 50 | while (!(ADC1_SC1A & ADC_SC1_COCO)) { |
| 51 | } |
| 52 | ADC1_SC1A = 15; |
| 53 | r.currents[1] = ADC1_RA; |
| 54 | while (!(ADC1_SC1A & ADC_SC1_COCO)) { |
| 55 | } |
| 56 | r.currents[2] = ADC1_RA; |
| 57 | |
| 58 | return r; |
| 59 | } |
| 60 | |
| 61 | SmallAdcReadings AdcReadSmall1(const DisableInterrupts &) { |
| 62 | SmallAdcReadings r; |
| 63 | |
| 64 | ADC0_SC1A = 13; |
| 65 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 66 | } |
| 67 | ADC0_SC1A = 12; |
| 68 | r.currents[0] = ADC0_RA; |
| 69 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 70 | } |
| 71 | ADC0_SC1A = 14; |
| 72 | r.currents[1] = ADC0_RA; |
| 73 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 74 | } |
| 75 | r.currents[2] = ADC0_RA; |
| 76 | |
| 77 | return r; |
| 78 | } |
| 79 | |
| 80 | SmallInitReadings AdcReadSmallInit(const DisableInterrupts &) { |
| 81 | SmallInitReadings r; |
| 82 | |
| 83 | ADC0_SC1A = 5; |
| 84 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 85 | } |
| 86 | ADC0_SC1A = 17; |
| 87 | r.motor0_abs = ADC0_RA; |
| 88 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 89 | } |
| 90 | ADC0_SC1A = 18; |
| 91 | r.motor1_abs = ADC0_RA; |
| 92 | while (!(ADC0_SC1A & ADC_SC1_COCO)) { |
| 93 | } |
| 94 | r.wheel_abs = ADC0_RA; |
| 95 | |
| 96 | return r; |
| 97 | } |
| 98 | |
| 99 | } // namespace motors |
| 100 | } // namespace frc971 |