summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-04-16 17:01:55 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-04-16 17:01:55 +0200
commitb92871fcd7203e096551879cd51a850fa585529f (patch)
treee6b2e797f3512b6444011509bf815db54041ed9b
parent286cecb2bf08c5538cfe13053246b0d8b78b2df4 (diff)
Enable battery monitoring.
-rw-r--r--board.h2
-rw-r--r--halconf.h2
-rw-r--r--main.cpp37
3 files changed, 39 insertions, 2 deletions
diff --git a/board.h b/board.h
index 9034d20..8265944 100644
--- a/board.h
+++ b/board.h
@@ -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
diff --git a/halconf.h b/halconf.h
index 1b0e3dd..b4624aa 100644
--- a/halconf.h
+++ b/halconf.h
@@ -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
/**
diff --git a/main.cpp b/main.cpp
index 57d3d17..f8c203f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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);