1
1
#include " Charger.h"
2
2
#include < map>
3
3
4
- std::map<float , ChargeCurrent> chargeCurrentMap = {
5
- {0.1 , ChargeCurrent::I_100_mA},
6
- {0.15 , ChargeCurrent::I_150_mA},
7
- {0.2 , ChargeCurrent::I_200_mA},
8
- {0.25 , ChargeCurrent::I_250_mA},
9
- {0.3 , ChargeCurrent::I_300_mA},
10
- {0.35 , ChargeCurrent::I_350_mA},
11
- {0.4 , ChargeCurrent::I_400_mA},
12
- {0.45 , ChargeCurrent::I_450_mA},
13
- {0.5 , ChargeCurrent::I_500_mA},
14
- {0.55 , ChargeCurrent::I_550_mA},
15
- {0.6 , ChargeCurrent::I_600_mA},
16
- {0.65 , ChargeCurrent::I_650_mA},
17
- {0.7 , ChargeCurrent::I_700_mA},
18
- {0.75 , ChargeCurrent::I_750_mA},
19
- {0.8 , ChargeCurrent::I_800_mA},
20
- {0.85 , ChargeCurrent::I_850_mA},
21
- {0.9 , ChargeCurrent::I_900_mA},
22
- {0.95 , ChargeCurrent::I_950_mA},
23
- {1.0 , ChargeCurrent::I_1000_mA}
4
+ std::map<uint16_t , ChargeCurrent> chargeCurrentMap = {
5
+ {100 , ChargeCurrent::I_100_mA},
6
+ {150 , ChargeCurrent::I_150_mA},
7
+ {200 , ChargeCurrent::I_200_mA},
8
+ {250 , ChargeCurrent::I_250_mA},
9
+ {300 , ChargeCurrent::I_300_mA},
10
+ {350 , ChargeCurrent::I_350_mA},
11
+ {400 , ChargeCurrent::I_400_mA},
12
+ {450 , ChargeCurrent::I_450_mA},
13
+ {500 , ChargeCurrent::I_500_mA},
14
+ {550 , ChargeCurrent::I_550_mA},
15
+ {600 , ChargeCurrent::I_600_mA},
16
+ {650 , ChargeCurrent::I_650_mA},
17
+ {700 , ChargeCurrent::I_700_mA},
18
+ {750 , ChargeCurrent::I_750_mA},
19
+ {800 , ChargeCurrent::I_800_mA},
20
+ {850 , ChargeCurrent::I_850_mA},
21
+ {900 , ChargeCurrent::I_900_mA},
22
+ {950 , ChargeCurrent::I_950_mA},
23
+ {1000 , ChargeCurrent::I_1000_mA}
24
24
};
25
25
26
26
std::map<float , ChargeVoltage> chargeVoltageMap = {
@@ -74,36 +74,36 @@ std::map<float, ChargeVoltage> chargeVoltageMap = {
74
74
{4.44 , ChargeVoltage::V_4_44}
75
75
};
76
76
77
- std::map<float , EndOfChargeCurrent> endOfChargeCurrentMap = {
78
- {0.005 , EndOfChargeCurrent::I_5_mA},
79
- {0.01 , EndOfChargeCurrent::I_10_mA},
80
- {0.02 , EndOfChargeCurrent::I_20_mA},
81
- {0.03 , EndOfChargeCurrent::I_30_mA},
82
- {0.05 , EndOfChargeCurrent::I_50_mA}
77
+ std::map<uint16_t , EndOfChargeCurrent> endOfChargeCurrentMap = {
78
+ {5 , EndOfChargeCurrent::I_5_mA},
79
+ {10 , EndOfChargeCurrent::I_10_mA},
80
+ {20 , EndOfChargeCurrent::I_20_mA},
81
+ {30 , EndOfChargeCurrent::I_30_mA},
82
+ {50 , EndOfChargeCurrent::I_50_mA}
83
83
};
84
84
85
- std::map<float , InputCurrentLimit> inputCurrentLimitMap = {
86
- {0.01 , InputCurrentLimit::I_10_mA},
87
- {0.015 , InputCurrentLimit::I_15_mA},
88
- {0.02 , InputCurrentLimit::I_20_mA},
89
- {0.025 , InputCurrentLimit::I_25_mA},
90
- {0.03 , InputCurrentLimit::I_30_mA},
91
- {0.035 , InputCurrentLimit::I_35_mA},
92
- {0.04 , InputCurrentLimit::I_40_mA},
93
- {0.045 , InputCurrentLimit::I_45_mA},
94
- {0.05 , InputCurrentLimit::I_50_mA},
95
- {0.1 , InputCurrentLimit::I_100_mA},
96
- {0.15 , InputCurrentLimit::I_150_mA},
97
- {0.2 , InputCurrentLimit::I_200_mA},
98
- {0.3 , InputCurrentLimit::I_300_mA},
99
- {0.4 , InputCurrentLimit::I_400_mA},
100
- {0.5 , InputCurrentLimit::I_500_mA},
101
- {0.6 , InputCurrentLimit::I_600_mA},
102
- {0.7 , InputCurrentLimit::I_700_mA},
103
- {0.8 , InputCurrentLimit::I_800_mA},
104
- {0.9 , InputCurrentLimit::I_900_mA},
105
- {1.0 , InputCurrentLimit::I_1000_mA},
106
- {1.5 , InputCurrentLimit::I_1500_mA}
85
+ std::map<uint16_t , InputCurrentLimit> inputCurrentLimitMap = {
86
+ {10 , InputCurrentLimit::I_10_mA},
87
+ {15 , InputCurrentLimit::I_15_mA},
88
+ {20 , InputCurrentLimit::I_20_mA},
89
+ {25 , InputCurrentLimit::I_25_mA},
90
+ {30 , InputCurrentLimit::I_30_mA},
91
+ {35 , InputCurrentLimit::I_35_mA},
92
+ {40 , InputCurrentLimit::I_40_mA},
93
+ {45 , InputCurrentLimit::I_45_mA},
94
+ {50 , InputCurrentLimit::I_50_mA},
95
+ {100 , InputCurrentLimit::I_100_mA},
96
+ {150 , InputCurrentLimit::I_150_mA},
97
+ {200 , InputCurrentLimit::I_200_mA},
98
+ {300 , InputCurrentLimit::I_300_mA},
99
+ {400 , InputCurrentLimit::I_400_mA},
100
+ {500 , InputCurrentLimit::I_500_mA},
101
+ {600 , InputCurrentLimit::I_600_mA},
102
+ {700 , InputCurrentLimit::I_700_mA},
103
+ {800 , InputCurrentLimit::I_800_mA},
104
+ {900 , InputCurrentLimit::I_900_mA},
105
+ {1000 , InputCurrentLimit::I_1000_mA},
106
+ {1500 , InputCurrentLimit::I_1500_mA}
107
107
};
108
108
109
109
@@ -113,7 +113,11 @@ bool Charger::begin(){
113
113
return PMIC.begin () == 0 ;
114
114
}
115
115
116
- bool Charger::setChargeCurrent (float current) {
116
+ bool Charger::setChargeCurrent (uint16_t current) {
117
+ #if defined(ARDUINO_NICLA_VISION)
118
+ return false ; // Not supported on Nicla Vision
119
+ #endif
120
+
117
121
if (chargeCurrentMap.find (current) != chargeCurrentMap.end ()) {
118
122
ChargeCurrent convertedCurrent = chargeCurrentMap[current];
119
123
PMIC.getControl () -> setFastChargeCurrent (convertedCurrent);
@@ -122,7 +126,7 @@ bool Charger::setChargeCurrent(float current) {
122
126
return false ;
123
127
}
124
128
125
- float Charger::getChargeCurrent () {
129
+ uint16_t Charger::getChargeCurrent () {
126
130
auto currentValue = PMIC.readPMICreg (Register::CHARGER_CHG_CURR_CFG);
127
131
currentValue = (currentValue & REG_CHG_CURR_CFG_CHG_CC_mask);
128
132
ChargeCurrent current = static_cast <ChargeCurrent>(currentValue);
@@ -157,7 +161,10 @@ bool Charger::setChargeVoltage(float voltage) {
157
161
return false ;
158
162
}
159
163
160
- bool Charger::setEndOfChargeCurrent (float current) {
164
+ bool Charger::setEndOfChargeCurrent (uint16_t current) {
165
+ #if defined(ARDUINO_NICLA_VISION)
166
+ return false ; // Not supported on Nicla Vision
167
+ #endif
161
168
if (endOfChargeCurrentMap.find (current) != endOfChargeCurrentMap.end ()) {
162
169
EndOfChargeCurrent convertedCurrent = endOfChargeCurrentMap[current];
163
170
PMIC.getControl () -> setEndOfChargeCurrent (convertedCurrent);
@@ -166,7 +173,7 @@ bool Charger::setEndOfChargeCurrent(float current) {
166
173
return false ;
167
174
}
168
175
169
- float Charger::getEndOfChargeCurrent () {
176
+ uint16_t Charger::getEndOfChargeCurrent () {
170
177
uint8_t currentValue = PMIC.readPMICreg (Register::CHARGER_CHG_EOC_CNFG);
171
178
currentValue = (currentValue & REG_CHG_EOC_CNFG_IEOC_mask);
172
179
EndOfChargeCurrent current = static_cast <EndOfChargeCurrent>(currentValue);
@@ -178,7 +185,7 @@ float Charger::getEndOfChargeCurrent() {
178
185
return -1 ;
179
186
}
180
187
181
- bool Charger::setInputCurrentLimit (float current) {
188
+ bool Charger::setInputCurrentLimit (uint16_t current) {
182
189
if (inputCurrentLimitMap.find (current) != inputCurrentLimitMap.end ()) {
183
190
InputCurrentLimit convertedCurrent = inputCurrentLimitMap[current];
184
191
PMIC.getControl () -> setInputCurrentLimit (convertedCurrent);
@@ -187,7 +194,7 @@ bool Charger::setInputCurrentLimit(float current) {
187
194
return false ;
188
195
}
189
196
190
- float Charger::getInputCurrentLimit () {
197
+ uint16_t Charger::getInputCurrentLimit () {
191
198
uint8_t currentValue = PMIC.readPMICreg (Register::CHARGER_VBUS_INLIM_CNFG);
192
199
currentValue = (currentValue & REG_VBUS_INLIM_CNFG_VBUS_LIN_INLIM_mask);
193
200
InputCurrentLimit current = static_cast <InputCurrentLimit>(currentValue);
0 commit comments