amiro-os / include / amiro / power / bq24103a.hpp @ 3a3d08d9
History | View | Annotate | Download (1.081 KB)
1 | 58fe0e0b | Thomas Schöpping | /*
|
---|---|---|---|
2 | * BQ24103A - Battery Charger
|
||
3 | */
|
||
4 | |||
5 | #ifndef AMIRO_BQ24103A_H_
|
||
6 | #define AMIRO_BQ24103A_H_
|
||
7 | |||
8 | namespace amiro {
|
||
9 | |||
10 | class BaseBQ24103A |
||
11 | { |
||
12 | public:
|
||
13 | BaseBQ24103A() |
||
14 | {} |
||
15 | |||
16 | virtual ~BaseBQ24103A()
|
||
17 | {} |
||
18 | |||
19 | virtual void enable(const bool en = true) = 0; |
||
20 | |||
21 | virtual bool isEnabled() const = 0; |
||
22 | |||
23 | virtual bool isCharging() const = 0; |
||
24 | }; |
||
25 | |||
26 | template <uintptr_t EN_PadGrp, uint32_t EN_Pad, uintptr_t STAT_PadGrp, uint32_t STAT_Pad>
|
||
27 | class BQ24103A : public BaseBQ24103A |
||
28 | { |
||
29 | private:
|
||
30 | bool is_enabled;
|
||
31 | |||
32 | public:
|
||
33 | BQ24103A(const bool enable = false) : |
||
34 | is_enabled(enable) |
||
35 | { |
||
36 | this->enable(enable);
|
||
37 | } |
||
38 | |||
39 | virtual ~BQ24103A()
|
||
40 | {} |
||
41 | |||
42 | void enable(const bool enable = true) |
||
43 | { |
||
44 | // writing to a port is not atomic, thus the system must be locked
|
||
45 | chSysLock(); |
||
46 | palWritePad((GPIO_TypeDef*)EN_PadGrp, EN_Pad, (enable? PAL_LOW : PAL_HIGH)); |
||
47 | this->is_enabled = enable;
|
||
48 | chSysUnlock(); |
||
49 | return;
|
||
50 | } |
||
51 | |||
52 | bool isEnabled() const |
||
53 | { |
||
54 | return this->is_enabled; |
||
55 | } |
||
56 | |||
57 | bool isCharging() const |
||
58 | { |
||
59 | return (palReadPad((GPIO_TypeDef*)STAT_PadGrp, STAT_Pad) == PAL_LOW);
|
||
60 | } |
||
61 | }; |
||
62 | |||
63 | } |
||
64 | |||
65 | #endif /* AMIRO_BQ24103A_H_ */ |