diff options
author | QMK Bot <hello@qmk.fm> | 2020-03-11 05:11:02 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2020-03-11 05:11:02 +0000 |
commit | 2b66acf04a82bc571ac5f545be7c43af722d6704 (patch) | |
tree | 45181b60f48802212f9e39865439467e08301b78 | |
parent | 5ac6fe18889027b718a8ed8c65482d0ab26b5f36 (diff) | |
download | qmk_firmware-2b66acf04a82bc571ac5f545be7c43af722d6704.tar.gz qmk_firmware-2b66acf04a82bc571ac5f545be7c43af722d6704.zip |
format code according to conventions [skip ci]
-rw-r--r-- | drivers/arm/analog.c | 53 | ||||
-rw-r--r-- | drivers/arm/analog.h | 19 |
2 files changed, 28 insertions, 44 deletions
diff --git a/drivers/arm/analog.c b/drivers/arm/analog.c index 57f649a81..427381f28 100644 --- a/drivers/arm/analog.c +++ b/drivers/arm/analog.c | |||
@@ -17,35 +17,32 @@ | |||
17 | #include "analog.h" | 17 | #include "analog.h" |
18 | #include "quantum.h" | 18 | #include "quantum.h" |
19 | 19 | ||
20 | |||
21 | /* User configurable ADC options */ | 20 | /* User configurable ADC options */ |
22 | #ifndef ADC_CIRCULAR_BUFFER | 21 | #ifndef ADC_CIRCULAR_BUFFER |
23 | #define ADC_CIRCULAR_BUFFER FALSE | 22 | # define ADC_CIRCULAR_BUFFER FALSE |
24 | #endif | 23 | #endif |
25 | 24 | ||
26 | #ifndef ADC_NUM_CHANNELS | 25 | #ifndef ADC_NUM_CHANNELS |
27 | #define ADC_NUM_CHANNELS 1 | 26 | # define ADC_NUM_CHANNELS 1 |
28 | #elif ADC_NUM_CHANNELS != 1 | 27 | #elif ADC_NUM_CHANNELS != 1 |
29 | #error "The ARM ADC implementation currently only supports reading one channel at a time." | 28 | # error "The ARM ADC implementation currently only supports reading one channel at a time." |
30 | #endif | 29 | #endif |
31 | 30 | ||
32 | #ifndef ADC_BUFFER_DEPTH | 31 | #ifndef ADC_BUFFER_DEPTH |
33 | #define ADC_BUFFER_DEPTH 2 | 32 | # define ADC_BUFFER_DEPTH 2 |
34 | #endif | 33 | #endif |
35 | 34 | ||
36 | // For more sampling rate options, look at hal_adc_lld.h in ChibiOS | 35 | // For more sampling rate options, look at hal_adc_lld.h in ChibiOS |
37 | #ifndef ADC_SAMPLING_RATE | 36 | #ifndef ADC_SAMPLING_RATE |
38 | #define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5 | 37 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5 |
39 | #endif | 38 | #endif |
40 | 39 | ||
41 | // Options are 12, 10, 8, and 6 bit. | 40 | // Options are 12, 10, 8, and 6 bit. |
42 | #ifndef ADC_RESOLUTION | 41 | #ifndef ADC_RESOLUTION |
43 | #define ADC_RESOLUTION ADC_CFGR1_RES_12BIT | 42 | # define ADC_RESOLUTION ADC_CFGR1_RES_12BIT |
44 | #endif | 43 | #endif |
45 | 44 | ||
46 | 45 | static ADCConfig adcCfg = {}; | |
47 | |||
48 | static ADCConfig adcCfg = {}; | ||
49 | static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH]; | 46 | static adcsample_t sampleBuffer[ADC_NUM_CHANNELS * ADC_BUFFER_DEPTH]; |
50 | 47 | ||
51 | // Initialize to max number of ADCs, set to empty object to initialize all to false. | 48 | // Initialize to max number of ADCs, set to empty object to initialize all to false. |
@@ -54,21 +51,18 @@ static bool adcInitialized[1] = {}; | |||
54 | #elif defined(STM32F3XX) | 51 | #elif defined(STM32F3XX) |
55 | static bool adcInitialized[4] = {}; | 52 | static bool adcInitialized[4] = {}; |
56 | #else | 53 | #else |
57 | #error "adcInitialized has not been implemented for this ARM microcontroller." | 54 | # error "adcInitialized has not been implemented for this ARM microcontroller." |
58 | #endif | 55 | #endif |
59 | 56 | ||
60 | |||
61 | |||
62 | static ADCConversionGroup adcConversionGroup = { | 57 | static ADCConversionGroup adcConversionGroup = { |
63 | ADC_CIRCULAR_BUFFER, | 58 | ADC_CIRCULAR_BUFFER, |
64 | (uint16_t)(ADC_NUM_CHANNELS), | 59 | (uint16_t)(ADC_NUM_CHANNELS), |
65 | NULL, // No end callback | 60 | NULL, // No end callback |
66 | NULL, // No error callback | 61 | NULL, // No error callback |
67 | #if defined(STM32F0XX) | 62 | #if defined(STM32F0XX) |
68 | ADC_CFGR1_CONT | ADC_RESOLUTION, | 63 | ADC_CFGR1_CONT | ADC_RESOLUTION, |
69 | ADC_TR(0, 0). | 64 | ADC_TR(0, 0).ADC_SAMPLING_RATE, |
70 | ADC_SAMPLING_RATE, | 65 | NULL, // Doesn't specify a default channel |
71 | NULL, // Doesn't specify a default channel | ||
72 | #elif defined(STM32F3XX) | 66 | #elif defined(STM32F3XX) |
73 | ADC_CFGR_CONT | ADC_RESOLUTION, | 67 | ADC_CFGR_CONT | ADC_RESOLUTION, |
74 | ADC_TR(0, 4095), | 68 | ADC_TR(0, 4095), |
@@ -77,7 +71,7 @@ static ADCConversionGroup adcConversionGroup = { | |||
77 | ADC_SAMPLING_RATE, | 71 | ADC_SAMPLING_RATE, |
78 | }, | 72 | }, |
79 | { | 73 | { |
80 | 0, // Doesn't specify a default channel | 74 | 0, // Doesn't specify a default channel |
81 | 0, | 75 | 0, |
82 | 0, | 76 | 0, |
83 | 0, | 77 | 0, |
@@ -85,10 +79,7 @@ static ADCConversionGroup adcConversionGroup = { | |||
85 | #endif | 79 | #endif |
86 | }; | 80 | }; |
87 | 81 | ||
88 | |||
89 | |||
90 | static inline ADCDriver* intToADCDriver(uint8_t adcInt) { | 82 | static inline ADCDriver* intToADCDriver(uint8_t adcInt) { |
91 | |||
92 | ADCDriver* target; | 83 | ADCDriver* target; |
93 | 84 | ||
94 | switch (adcInt) { | 85 | switch (adcInt) { |
@@ -106,7 +97,7 @@ static inline ADCDriver* intToADCDriver(uint8_t adcInt) { | |||
106 | case 3: target = &ADCD4; break; | 97 | case 3: target = &ADCD4; break; |
107 | #endif | 98 | #endif |
108 | default: target = NULL; break; | 99 | default: target = NULL; break; |
109 | // clang-format on | 100 | // clang-format on |
110 | } | 101 | } |
111 | 102 | ||
112 | return target; | 103 | return target; |
@@ -119,12 +110,10 @@ static inline void manageAdcInitializationDriver(uint8_t adc, ADCDriver* adcDriv | |||
119 | } | 110 | } |
120 | } | 111 | } |
121 | 112 | ||
122 | static inline void manageAdcInitialization(uint8_t adc) { | 113 | static inline void manageAdcInitialization(uint8_t adc) { manageAdcInitializationDriver(adc, intToADCDriver(adc)); } |
123 | manageAdcInitializationDriver(adc, intToADCDriver(adc)); | ||
124 | } | ||
125 | 114 | ||
126 | pin_and_adc pinToMux(pin_t pin) { | 115 | pin_and_adc pinToMux(pin_t pin) { |
127 | switch(pin) { | 116 | switch (pin) { |
128 | // clang-format off | 117 | // clang-format off |
129 | #if defined(STM32F0XX) | 118 | #if defined(STM32F0XX) |
130 | case A0: return (pin_and_adc){ ADC_CHANNEL_IN0, 0 }; | 119 | case A0: return (pin_and_adc){ ADC_CHANNEL_IN0, 0 }; |
@@ -187,17 +176,15 @@ pin_and_adc pinToMux(pin_t pin) { | |||
187 | #error "An ADC pin-to-mux configuration has not been specified for this microcontroller." | 176 | #error "An ADC pin-to-mux configuration has not been specified for this microcontroller." |
188 | #endif | 177 | #endif |
189 | default: return (pin_and_adc){ 0, 0 }; | 178 | default: return (pin_and_adc){ 0, 0 }; |
190 | // clang-format on | 179 | // clang-format on |
191 | } | 180 | } |
192 | } | 181 | } |
193 | 182 | ||
194 | adcsample_t analogReadPin(pin_t pin) { | 183 | adcsample_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); } |
195 | return adc_read(pinToMux(pin)); | ||
196 | } | ||
197 | 184 | ||
198 | adcsample_t analogReadPinAdc(pin_t pin, uint8_t adc) { | 185 | adcsample_t analogReadPinAdc(pin_t pin, uint8_t adc) { |
199 | pin_and_adc target = pinToMux(pin); | 186 | pin_and_adc target = pinToMux(pin); |
200 | target.adc = adc; | 187 | target.adc = adc; |
201 | return adc_read(target); | 188 | return adc_read(target); |
202 | } | 189 | } |
203 | 190 | ||
@@ -207,7 +194,7 @@ adcsample_t adc_read(pin_and_adc mux) { | |||
207 | #elif defined(STM32F3XX) | 194 | #elif defined(STM32F3XX) |
208 | adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(mux.pin); | 195 | adcConversionGroup.sqr[0] = ADC_SQR1_SQ1_N(mux.pin); |
209 | #else | 196 | #else |
210 | #error "adc_read has not been updated to support this ARM microcontroller." | 197 | # error "adc_read has not been updated to support this ARM microcontroller." |
211 | #endif | 198 | #endif |
212 | 199 | ||
213 | ADCDriver* targetDriver = intToADCDriver(mux.adc); | 200 | ADCDriver* targetDriver = intToADCDriver(mux.adc); |
diff --git a/drivers/arm/analog.h b/drivers/arm/analog.h index 081d0c1e7..ab592ada3 100644 --- a/drivers/arm/analog.h +++ b/drivers/arm/analog.h | |||
@@ -20,35 +20,32 @@ | |||
20 | #include "ch.h" | 20 | #include "ch.h" |
21 | #include <hal.h> | 21 | #include <hal.h> |
22 | 22 | ||
23 | |||
24 | #if !defined(STM32F0XX) && !defined(STM32F3XX) | 23 | #if !defined(STM32F0XX) && !defined(STM32F3XX) |
25 | #error "Only STM23F0 and STM32F3 devices have ADC support in QMK at this time." | 24 | # error "Only STM23F0 and STM32F3 devices have ADC support in QMK at this time." |
26 | #endif | 25 | #endif |
27 | 26 | ||
28 | #if !HAL_USE_ADC | 27 | #if !HAL_USE_ADC |
29 | #error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC." | 28 | # error "You need to set HAL_USE_ADC to TRUE in your halconf.h to use the ADC." |
30 | #endif | 29 | #endif |
31 | 30 | ||
32 | #if !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4 | 31 | #if !STM32_ADC_USE_ADC1 && !STM32_ADC_USE_ADC2 && !STM32_ADC_USE_ADC3 && !STM32_ADC_USE_ADC4 |
33 | #error "You need to set one of the 'STM32_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC." | 32 | # error "You need to set one of the 'STM32_ADC_USE_ADCx' settings to TRUE in your mcuconf.h to use the ADC." |
34 | #endif | 33 | #endif |
35 | 34 | ||
36 | #if STM32_ADC_DUAL_MODE | 35 | #if STM32_ADC_DUAL_MODE |
37 | #error "STM32 ADC Dual Mode is not supported at this time." | 36 | # error "STM32 ADC Dual Mode is not supported at this time." |
38 | #endif | 37 | #endif |
39 | 38 | ||
40 | #if STM32_ADCV3_OVERSAMPLING | 39 | #if STM32_ADCV3_OVERSAMPLING |
41 | #error "STM32 ADCV3 Oversampling is not supported at this time." | 40 | # error "STM32 ADCV3 Oversampling is not supported at this time." |
42 | #endif | 41 | #endif |
43 | 42 | ||
44 | |||
45 | |||
46 | typedef struct { | 43 | typedef struct { |
47 | pin_t pin; | 44 | pin_t pin; |
48 | uint8_t adc; | 45 | uint8_t adc; |
49 | } pin_and_adc; | 46 | } pin_and_adc; |
50 | #define PIN_AND_ADC(p,a) (pin_and_adc){p,a} | 47 | #define PIN_AND_ADC(p, a) \ |
51 | 48 | (pin_and_adc) { p, a } | |
52 | 49 | ||
53 | // analogReference has been left un-defined for ARM devices. | 50 | // analogReference has been left un-defined for ARM devices. |
54 | // void analogReference(uint8_t mode); | 51 | // void analogReference(uint8_t mode); |