Statistics
| Branch: | Tag: | Revision:

amiro-os / include / amiro / power / ltc4412.hpp @ 2af9778e

History | View | Annotate | Download (1.5 KB)

1 58fe0e0b Thomas Schöpping
/*
2
 * LTC4412 - PowerPath Controller
3
 */
4
5
#ifndef AMIRO_LTC4412_H_
6
#define AMIRO_LTC4412_H_
7
8
#include <hal.h>
9
10
namespace amiro {
11
12
class BaseLTC4412
13
{
14
public:
15
  BaseLTC4412()
16
  {}
17
18
  virtual ~BaseLTC4412()
19
  {}
20
21
  virtual bool isPluggedIn() const = 0;
22
};
23
24
class BaseLTC4412wEN : public BaseLTC4412
25
{
26
public:
27
  BaseLTC4412wEN()
28
  {}
29
30
  virtual ~BaseLTC4412wEN()
31
  {}
32
33
  virtual void enable(const bool enable = true) = 0;
34
35
  virtual bool isEnabled() const = 0;
36
37
  virtual bool isPluggedIn() const = 0;
38
};
39
40
41
42
template <uintptr_t STAT_PadGrp, uint8_t STAT_Pad>
43
class LTC4412 : public BaseLTC4412
44
{
45
public:
46
  LTC4412()
47
  {}
48
49
  virtual ~LTC4412()
50
  {}
51
52
  bool isPluggedIn() const
53
  {
54
    return (palReadPad((GPIO_TypeDef*)STAT_PadGrp, STAT_Pad) == PAL_HIGH);
55
  }
56
57
};
58
59
template <uintptr_t STAT_PadGrp, uint8_t STAT_Pad, uintptr_t EN_PadGrp, uint8_t EN_Pad>
60
class LTC4412wEN : public BaseLTC4412wEN
61
{
62
private:
63
  bool is_enabled;
64
65
public:
66
  LTC4412wEN(const bool enable = false) :
67
    is_enabled(enable)
68
  {
69
    this->enable(enable);
70
  }
71
72
  virtual ~LTC4412wEN()
73
  {}
74
75
  void enable(const bool enable = true)
76
  {
77
    // writing to a port is not atomic, thus the system must be locked
78
    chSysLock();
79
    palWritePad((GPIO_TypeDef*)EN_PadGrp, EN_Pad, enable? PAL_LOW : PAL_HIGH);
80
    this->is_enabled = enable;
81
    chSysUnlock();
82
  }
83
84
  bool isEnabled() const
85
  {
86
    return this->is_enabled;
87
  }
88
89
  bool isPluggedIn() const
90
  {
91
    return (palReadPad((GPIO_TypeDef*)STAT_PadGrp, STAT_Pad) == PAL_HIGH);
92
  }
93
94
};
95
96
}
97
98
#endif /* AMIRO_LTC4412_H_ */