diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-04-16 17:01:55 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-04-16 17:01:55 +0200 |
commit | b92871fcd7203e096551879cd51a850fa585529f (patch) | |
tree | e6b2e797f3512b6444011509bf815db54041ed9b | |
parent | 286cecb2bf08c5538cfe13053246b0d8b78b2df4 (diff) |
Enable battery monitoring.
-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);
|