diff options
-rw-r--r-- | board.h | 2 | ||||
-rw-r--r-- | halconf.h | 2 | ||||
-rw-r--r-- | main.cpp | 37 |
3 files changed, 39 insertions, 2 deletions
@@ -61,7 +61,7 @@ * PC11 - Push Pull output (USB DISC).
* PC12 - Push Pull output (LED).
*/
-#define VAL_GPIOCCRL 0x44848888 /* PC7...PC0 */
+#define VAL_GPIOCCRL 0x44008888 /* PC7...PC0 */
#define VAL_GPIOCCRH 0x88833388 /* PC15...PC8 */
#define VAL_GPIOCODR 0xFFFFFFFF
@@ -45,7 +45,7 @@ * @brief Enables the ADC subsystem.
*/
#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC FALSE
+#define HAL_USE_ADC TRUE
#endif
/**
@@ -199,6 +199,41 @@ static ICUConfig icucfg = { icuperiodcb
};
+static const ADCConversionGroup adcgrpcfg = {
+ FALSE,
+ 2,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ ADC_SQR1_NUM_CH(2),
+ 0,
+ ADC_SQR3_SQ2_N(ADC_CHANNEL_IN14) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN15)
+};
+
+class ADCThread : public BaseThread<ADCThread, 128> {
+ private:
+ adcsample_t adc_samples[2];
+
+ public:
+ noreturn_t thread_main() {
+ adcStart(&ADCD1, NULL);
+
+ systime_t time = chTimeNow();
+ while (TRUE) {
+ adcStartConversion(&ADCD1, &adcgrpcfg, adc_samples, 1);
+ sensordata[12] = adc_samples[0] * 1265 / 1000;
+ sensordata[13] = adc_samples[1] * 2201 / 1000;
+
+ time += MS2ST(1000);
+ chThdSleepUntil(time);
+ }
+ }
+};
+
+ADCThread adc_thread;
+
int main(void) {
halInit();
chSysInit();
@@ -212,6 +247,8 @@ int main(void) { i2c_thread.start();
+ adc_thread.start();
+
pwmStart(&PWMD2, &pwmcfg);
palSetPadMode(GPIOA, 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOA, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|