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