amiro-os / include / amiro / power / adconverter.hpp @ 88afb834
History | View | Annotate | Download (1.057 KB)
1 |
/*
|
---|---|
2 |
* ADC for monitoring the system voltage and handling the charger logic
|
3 |
*/
|
4 |
|
5 |
#ifndef AMIRO_ADCONVERTER_HPP
|
6 |
#define AMIRO_ADCONVERTER_HPP
|
7 |
|
8 |
#include <ch.hpp> |
9 |
#include <hal.h> |
10 |
#include <evtimer.h> |
11 |
|
12 |
namespace amiro {
|
13 |
|
14 |
class ADConverter : public chibios_rt::BaseStaticThread<256> |
15 |
{ |
16 |
public:
|
17 |
enum Events {
|
18 |
EVT_WATCHDOG = 0x00,
|
19 |
EVT_TIMER = 0x01
|
20 |
}; |
21 |
|
22 |
static uint16_t uV2Adc(const uint32_t uV); |
23 |
static uint32_t adc2uV(const uint16_t adc); |
24 |
|
25 |
private:
|
26 |
ADCDriver& driver; |
27 |
ADCConversionGroup& conversion_group; |
28 |
uint32_t watchdog_threshold_uV; |
29 |
chibios_rt::EvtListener evt_listener; |
30 |
chibios_rt::EvtSource* evt_source; |
31 |
EvTimer evt_timer; |
32 |
|
33 |
public:
|
34 |
ADConverter(ADCDriver &adcdrv, ADCConversionGroup& adccgrp, const uint32_t threshold_uV);
|
35 |
virtual ~ADConverter();
|
36 |
|
37 |
ADCConversionGroup& getConversionGroup() {return this->conversion_group;} |
38 |
const ADCConversionGroup& getConversionGroup() const {return this->conversion_group;} |
39 |
|
40 |
protected:
|
41 |
virtual msg_t main(void); |
42 |
|
43 |
private:
|
44 |
void enableWatchdog(const bool enable = true); |
45 |
|
46 |
}; |
47 |
|
48 |
} |
49 |
|
50 |
#endif // AMIRO_ADCONVERTER_HPP |
51 |
|