libpropeller
Making PropellerGCC Easier
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Enumerations
Enumerator
Macros
Pages
libpropeller
libpropeller
max8819
max8819.h
Go to the documentation of this file.
1
#ifndef LIBPROPELLER_MAX8819_H_
2
#define LIBPROPELLER_MAX8819_H_
3
4
#include <stdint.h>
5
#include <propeller.h>
6
7
21
class
Max8819
{
22
private
:
23
uint32_t cen_mask;
24
uint32_t chg_mask;
25
uint32_t en_mask;
26
uint32_t dlim1_mask;
27
uint32_t dlim2_mask;
28
public
:
29
46
void
Start
(
int
CENpin,
int
CHGpin,
int
ENpin,
int
DLIM1pin,
int
DLIM2pin);
47
48
~Max8819
();
49
53
void
On
();
54
60
void
Off
();
61
69
bool
GetCharge
();
70
98
void
SetCharge
(
int
rate);
99
100
101
bool
GetPluggedIn
(
void
);
102
103
enum
{
104
HIGH
,
MEDIUM
,
LOW
,
OFF
105
};
106
};
107
108
void
inline
Max8819::Start
(
int
CENpin,
int
CHGpin,
int
ENpin,
int
DLIM1pin,
int
DLIM2pin) {
109
110
111
cen_mask = 1 << CENpin;
112
chg_mask = 1 << CHGpin;
113
en_mask = 1 << ENpin;
114
dlim1_mask = 1 << DLIM1pin;
115
dlim2_mask = 1 << DLIM2pin;
116
117
118
On
();
119
120
DIRA
|= en_mask;
// Set to output
121
DIRA
|= dlim1_mask;
// Set to output
122
DIRA
|= dlim2_mask;
// Set to output
123
DIRA
&= ~chg_mask;
// Set to input
124
DIRA
&= ~cen_mask;
// Set to input
125
126
SetCharge
(
HIGH
);
127
}
128
129
inline
Max8819::~Max8819
() {
130
}
131
132
inline
void
Max8819::On
() {
133
OUTA
|= en_mask;
134
}
135
136
inline
void
Max8819::Off
() {
137
OUTA
&= ~en_mask;
138
}
139
140
inline
bool
Max8819::GetCharge
() {
141
return
(
INA
& chg_mask) == 0;
142
}
143
144
inline
bool
Max8819::GetPluggedIn
() {
145
return
(
INA
& cen_mask) != 0;
146
}
147
148
inline
void
Max8819::SetCharge
(
int
rate) {
149
if
(rate ==
OFF
) {
150
OUTA
|= dlim1_mask;
//1
151
OUTA
|= dlim2_mask;
//1
152
153
}
else
if
(rate ==
HIGH
) {
154
OUTA
&= ~dlim1_mask;
//0
155
OUTA
&= ~dlim2_mask;
//0
156
157
}
else
if
(rate ==
MEDIUM
) {
158
OUTA
&= ~dlim1_mask;
//0
159
OUTA
|= dlim2_mask;
//1
160
}
else
{
//rate == LOW
161
OUTA
|= dlim1_mask;
//1
162
OUTA
&= ~dlim2_mask;
//0
163
}
164
}
165
166
#endif // LIBPROPELLER_MAX8819_H_
Generated on Fri Oct 25 2013 23:41:46 for libpropeller by
1.8.4