SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP202Regs.hpp
Go to the documentation of this file.
1
46#pragma once
47#include <stdint.h>
48
55 // -------------------- Status --------------------
56 struct bmu {
57 static constexpr uint8_t STATUS = 0x00;
58 static constexpr uint8_t MODE_CHGSTATUS = 0x01;
59 static constexpr uint8_t OTG_STATUS = 0x02;
60 static constexpr uint8_t IC_TYPE = 0x03;
61 static constexpr uint8_t DATA_BUFFER1 = 0x04;
62 static constexpr uint8_t DATA_BUFFER2 = 0x05;
63 static constexpr uint8_t DATA_BUFFER3 = 0x06;
64 static constexpr uint8_t DATA_BUFFER4 = 0x07;
65 };
66
67 // -------------------- Power Control --------------------
68 struct pmu {
69 static constexpr uint8_t LDO234_DC23_CTL = 0x12;
70 static constexpr uint8_t DC2OUT_VOL = 0x23;
71 static constexpr uint8_t DC3OUT_VOL = 0x27;
72 static constexpr uint8_t LDO24OUT_VOL = 0x28;
73 static constexpr uint8_t LDO3OUT_VOL = 0x29;
74 static constexpr uint8_t IPS_SET = 0x30;
75 static constexpr uint8_t VOFF_SET = 0x31;
76 static constexpr uint8_t OFF_CTL = 0x32;
77 static constexpr uint8_t POK_SET = 0x36;
78 static constexpr uint8_t LDO3_DC2_DVM = 0x25;
79 static constexpr uint8_t DCDC_FREQSET = 0x37;
80 static constexpr uint8_t APS_WARNING1 = 0x3A;
81 static constexpr uint8_t APS_WARNING2 = 0x3B;
82 static constexpr uint8_t DCDC_MODESET = 0x80;
83 static constexpr uint8_t VBUS_DET_SRP = 0x8B;
84 static constexpr uint8_t HOTOVER_CTL = 0x8F;
85
86 // REG30H[1:0] current-limit encoding (AXP202)
87 // 00=900mA, 01=500mA, 10=100mA, 11=OFF
88 static constexpr uint8_t INPUT_CURR_MASK = 0x03;
89
90 static inline uint8_t encodeInputCurrentLimit(uint32_t mA)
91 {
92 if (mA >= 900) {
93 return 0x00;
94 }
95 if (mA >= 500) {
96 return 0x01;
97 }
98 if (mA >= 100) {
99 return 0x02;
100 }
101 return 0x03;
102 }
103
104 static inline uint32_t decodeInputCurrentLimit(uint8_t reg)
105 {
106 switch (reg & INPUT_CURR_MASK) {
107 case 0x00: return 900;
108 case 0x01: return 500;
109 case 0x02: return 100;
110 default: return 0;
111 }
112 }
113 };
114
115 // -------------------- Charger --------------------
116 struct chg {
117 static constexpr uint8_t CHARGE1 = 0x33;
118 static constexpr uint8_t CHARGE2 = 0x34;
119 static constexpr uint8_t BACKUP_CHG = 0x35;
120 static constexpr uint8_t VLTF_CHGSET = 0x38;
121 static constexpr uint8_t VHTF_CHGSET = 0x39;
122 static constexpr uint8_t TLTF_DISCHGSET = 0x3C;
123 static constexpr uint8_t THTF_DISCHGSET = 0x3D;
124
125 // Charger constants
126 static constexpr uint16_t CHG_CUR_MIN = 300;
127 static constexpr uint16_t CHG_CUR_MAX = 1800;
128 static constexpr uint16_t CHG_CUR_STEP = 100;
129 };
130
131 // -------------------- IRQ --------------------
132 struct irq {
133 static constexpr uint8_t ENABLE1 = 0x40;
134 static constexpr uint8_t ENABLE2 = 0x41;
135 static constexpr uint8_t ENABLE3 = 0x42;
136 static constexpr uint8_t ENABLE4 = 0x43;
137 static constexpr uint8_t ENABLE5 = 0x44;
138 static constexpr uint8_t STATUS1 = 0x48;
139 static constexpr uint8_t STATUS2 = 0x49;
140 static constexpr uint8_t STATUS3 = 0x4A;
141 static constexpr uint8_t STATUS4 = 0x4B;
142 static constexpr uint8_t STATUS5 = 0x4C;
143 };
144
145 // -------------------- ADC --------------------
146 struct adc {
147 static constexpr uint8_t ADC_EN1 = 0x82;
148 static constexpr uint8_t ADC_EN2 = 0x83;
149 static constexpr uint8_t ADC_SPEED = 0x84;
150 static constexpr uint8_t ADC_INPUTRANGE = 0x85;
151 static constexpr uint8_t ADC_IRQ_RETFSET = 0x86;
152 static constexpr uint8_t ADC_IRQ_FETFSET = 0x87;
153
154 static constexpr uint8_t ACIN_VOL_H = 0x56;
155 static constexpr uint8_t ACIN_VOL_L = 0x57;
156 static constexpr uint8_t ACIN_CUR_H = 0x58;
157 static constexpr uint8_t ACIN_CUR_L = 0x59;
158
159 static constexpr uint8_t VBUS_VOL_H = 0x5A;
160 static constexpr uint8_t VBUS_VOL_L = 0x5B;
161 static constexpr uint8_t VBUS_CUR_H = 0x5C;
162 static constexpr uint8_t VBUS_CUR_L = 0x5D;
163 static constexpr uint8_t INTERNAL_TEMP_H = 0x5E;
164 static constexpr uint8_t INTERNAL_TEMP_L = 0x5F;
165 static constexpr uint8_t TS_IN_H = 0x62;
166 static constexpr uint8_t TS_IN_L = 0x63;
167 static constexpr uint8_t GPIO0_ADC_H = 0x64;
168 static constexpr uint8_t GPIO0_ADC_L = 0x65;
169 static constexpr uint8_t GPIO1_ADC_H = 0x66;
170 static constexpr uint8_t GPIO1_ADC_L = 0x67;
171 static constexpr uint8_t BAT_AVERVOL_H = 0x78;
172 static constexpr uint8_t BAT_AVERVOL_L = 0x79;
173 static constexpr uint8_t BAT_AVERCHGCUR_H = 0x7A;
174 static constexpr uint8_t BAT_AVERCHGCUR_L = 0x7B;
175 static constexpr uint8_t BAT_AVERDISCHGCUR_H = 0x7C;
176 static constexpr uint8_t BAT_AVERDISCHGCUR_L = 0x7D;
177 static constexpr uint8_t APS_AVERVOL_H = 0x7E;
178 static constexpr uint8_t APS_AVERVOL_L = 0x7F;
179 static constexpr uint8_t BAT_POWER_H = 0x70;
180 static constexpr uint8_t BAT_POWER_M = 0x71;
181 static constexpr uint8_t BAT_POWER_L = 0x72;
182 static constexpr uint8_t BATT_PERCENTAGE = 0xB9;
183 };
184
185 // -------------------- GPIO --------------------
186 struct gpio {
187 static constexpr uint8_t GPIO0_CTL = 0x90;
188 static constexpr uint8_t GPIO0_VOL = 0x91;
189 static constexpr uint8_t GPIO1_CTL = 0x92;
190 static constexpr uint8_t GPIO2_CTL = 0x93;
191 static constexpr uint8_t GPIO012_SIGNAL = 0x94;
192 static constexpr uint8_t GPIO3_CTL = 0x95;
193 };
194
195 // -------------------- Coulomb Counter --------------------
196 struct coulomb {
197 static constexpr uint8_t BAT_CHGCOULOMB3 = 0xB0;
198 static constexpr uint8_t BAT_CHGCOULOMB2 = 0xB1;
199 static constexpr uint8_t BAT_CHGCOULOMB1 = 0xB2;
200 static constexpr uint8_t BAT_CHGCOULOMB0 = 0xB3;
201 static constexpr uint8_t BAT_DISCHGCOULOMB3 = 0xB4;
202 static constexpr uint8_t BAT_DISCHGCOULOMB2 = 0xB5;
203 static constexpr uint8_t BAT_DISCHGCOULOMB1 = 0xB6;
204 static constexpr uint8_t BAT_DISCHGCOULOMB0 = 0xB7;
205 static constexpr uint8_t COULOMB_CTL = 0xB8;
206 };
207
208 // -------------------- Timer / Watchdog --------------------
209 struct timer {
210 static constexpr uint8_t TIMER_CTL = 0x8A;
211 };
212
213 // -------------------- Factory ADC conversion factors --------------------
214 struct factory {
215 static constexpr float FACTORY_VBUS_VOLTAGE = 1.7f;
216 static constexpr float FACTORY_VBUS_CURRENT = 0.375f;
217 static constexpr float FACTORY_VBAT_VOLTAGE = 1.1f;
218 static constexpr float FACTORY_BAT_CURRENT = 0.5f;
219 static constexpr float FACTORY_APS_VOLTAGE = 1.4f;
220 static constexpr float FACTORY_INTERNAL_TEMP = 0.1f;
221 static constexpr float FACTORY_INTERNAL_OFFSET = 144.7f;
222 static constexpr float FACTORY_ACIN_VOLTAGE = 1.7f;
223 static constexpr float FACTORY_ACIN_CURRENT = 0.625f;
224 static constexpr float FACTORY_TS_VOLTAGE = 0.8f;
225 static constexpr float FACTORY_GPIO_VOLTAGE = 0.5f;
226 };
227
228 // -------------------- Constants --------------------
229 static constexpr uint8_t CHIP_ID = 0x41;
230
231 // Power enable bits in LDO234_DC23_CTL (0x12)
232 static constexpr uint8_t BIT_EXTEN = 0;
233 static constexpr uint8_t BIT_DCDC3 = 1;
234 static constexpr uint8_t BIT_LDO2 = 2;
235 static constexpr uint8_t BIT_LDO4 = 3;
236 static constexpr uint8_t BIT_DCDC2 = 4;
237 static constexpr uint8_t BIT_LDO3 = 6;
238
239 // Aliases used by some .cpp files (same as bmu/pmu)
240 using status = bmu;
241 using power = pmu;
242};
static constexpr uint8_t ADC_IRQ_RETFSET
static constexpr uint8_t GPIO0_ADC_H
static constexpr uint8_t ACIN_CUR_H
static constexpr uint8_t BAT_POWER_M
static constexpr uint8_t BATT_PERCENTAGE
static constexpr uint8_t GPIO1_ADC_H
static constexpr uint8_t BAT_POWER_H
static constexpr uint8_t GPIO0_ADC_L
static constexpr uint8_t ACIN_CUR_L
static constexpr uint8_t INTERNAL_TEMP_H
static constexpr uint8_t BAT_AVERVOL_L
static constexpr uint8_t VBUS_CUR_L
static constexpr uint8_t ACIN_VOL_H
static constexpr uint8_t ADC_INPUTRANGE
static constexpr uint8_t APS_AVERVOL_L
static constexpr uint8_t VBUS_VOL_H
static constexpr uint8_t BAT_POWER_L
static constexpr uint8_t TS_IN_H
static constexpr uint8_t ADC_SPEED
static constexpr uint8_t ADC_EN2
static constexpr uint8_t BAT_AVERDISCHGCUR_H
static constexpr uint8_t ACIN_VOL_L
static constexpr uint8_t ADC_IRQ_FETFSET
static constexpr uint8_t BAT_AVERDISCHGCUR_L
static constexpr uint8_t BAT_AVERCHGCUR_H
static constexpr uint8_t GPIO1_ADC_L
static constexpr uint8_t APS_AVERVOL_H
static constexpr uint8_t INTERNAL_TEMP_L
static constexpr uint8_t BAT_AVERVOL_H
static constexpr uint8_t VBUS_CUR_H
static constexpr uint8_t VBUS_VOL_L
static constexpr uint8_t TS_IN_L
static constexpr uint8_t BAT_AVERCHGCUR_L
static constexpr uint8_t ADC_EN1
static constexpr uint8_t STATUS
static constexpr uint8_t DATA_BUFFER1
static constexpr uint8_t DATA_BUFFER4
static constexpr uint8_t DATA_BUFFER3
static constexpr uint8_t OTG_STATUS
static constexpr uint8_t IC_TYPE
static constexpr uint8_t DATA_BUFFER2
static constexpr uint8_t MODE_CHGSTATUS
static constexpr uint16_t CHG_CUR_STEP
static constexpr uint8_t BACKUP_CHG
static constexpr uint8_t VLTF_CHGSET
static constexpr uint8_t TLTF_DISCHGSET
static constexpr uint16_t CHG_CUR_MAX
static constexpr uint8_t VHTF_CHGSET
static constexpr uint8_t THTF_DISCHGSET
static constexpr uint8_t CHARGE1
static constexpr uint16_t CHG_CUR_MIN
static constexpr uint8_t CHARGE2
static constexpr uint8_t BAT_CHGCOULOMB0
static constexpr uint8_t BAT_DISCHGCOULOMB1
static constexpr uint8_t COULOMB_CTL
static constexpr uint8_t BAT_CHGCOULOMB2
static constexpr uint8_t BAT_CHGCOULOMB3
static constexpr uint8_t BAT_CHGCOULOMB1
static constexpr uint8_t BAT_DISCHGCOULOMB3
static constexpr uint8_t BAT_DISCHGCOULOMB2
static constexpr uint8_t BAT_DISCHGCOULOMB0
static constexpr float FACTORY_VBAT_VOLTAGE
static constexpr float FACTORY_GPIO_VOLTAGE
static constexpr float FACTORY_APS_VOLTAGE
static constexpr float FACTORY_ACIN_CURRENT
static constexpr float FACTORY_INTERNAL_OFFSET
static constexpr float FACTORY_ACIN_VOLTAGE
static constexpr float FACTORY_TS_VOLTAGE
static constexpr float FACTORY_BAT_CURRENT
static constexpr float FACTORY_VBUS_VOLTAGE
static constexpr float FACTORY_VBUS_CURRENT
static constexpr float FACTORY_INTERNAL_TEMP
static constexpr uint8_t GPIO0_CTL
static constexpr uint8_t GPIO1_CTL
static constexpr uint8_t GPIO2_CTL
static constexpr uint8_t GPIO3_CTL
static constexpr uint8_t GPIO0_VOL
static constexpr uint8_t GPIO012_SIGNAL
static constexpr uint8_t ENABLE1
static constexpr uint8_t ENABLE5
static constexpr uint8_t STATUS5
static constexpr uint8_t STATUS1
static constexpr uint8_t STATUS2
static constexpr uint8_t STATUS4
static constexpr uint8_t ENABLE2
static constexpr uint8_t STATUS3
static constexpr uint8_t ENABLE4
static constexpr uint8_t ENABLE3
static constexpr uint8_t LDO24OUT_VOL
static constexpr uint8_t LDO3_DC2_DVM
static constexpr uint8_t LDO234_DC23_CTL
static constexpr uint8_t VBUS_DET_SRP
static constexpr uint8_t VOFF_SET
static constexpr uint8_t APS_WARNING2
static constexpr uint8_t OFF_CTL
static constexpr uint8_t HOTOVER_CTL
static constexpr uint8_t DC3OUT_VOL
static constexpr uint8_t POK_SET
static constexpr uint8_t INPUT_CURR_MASK
static uint32_t decodeInputCurrentLimit(uint8_t reg)
static constexpr uint8_t DCDC_FREQSET
static constexpr uint8_t DC2OUT_VOL
static constexpr uint8_t APS_WARNING1
static constexpr uint8_t LDO3OUT_VOL
static constexpr uint8_t DCDC_MODESET
static constexpr uint8_t IPS_SET
static uint8_t encodeInputCurrentLimit(uint32_t mA)
static constexpr uint8_t TIMER_CTL
AXP202 register map and constants.
static constexpr uint8_t BIT_DCDC3
static constexpr uint8_t BIT_EXTEN
static constexpr uint8_t BIT_DCDC2
static constexpr uint8_t BIT_LDO2
static constexpr uint8_t BIT_LDO4
static constexpr uint8_t BIT_LDO3
static constexpr uint8_t CHIP_ID