Skip to content

Commit eca28bb

Browse files
committed
Fix AXP screen backlight brightness adjustment
1 parent 4ed38fe commit eca28bb

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/AXP192.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,29 @@ void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff) {
151151
}
152152
}
153153

154-
void AXP192::ScreenBreath(uint8_t brightness) {
155-
if (brightness > 12) {
156-
brightness = 12;
157-
}
158-
uint8_t buf = Read8bit(0x28);
159-
Write1Byte(0x28, ((buf & 0x0f) | (brightness << 4)));
154+
void AXP192::ScreenBreath(int brightness) {
155+
int vol = map(brightness, 0, 100, 2400, 3300);
156+
// Serial.printf("brightness:%d\n", brightness);
157+
158+
// Serial.printf("vol:%d\n", vol);
159+
// Serial.printf("vol:%u\n", vol);
160+
161+
SetLcdVoltage((uint16_t)vol);
162+
// delay(10);
163+
// uint8_t buf = Read8bit(0x27);
164+
// Serial.printf("brightness:%hhu\n", brightness);
165+
// Serial.printf("brightness:%d\n", brightness);
166+
// Serial.printf("brightness:%x\n", brightness);
167+
168+
// Serial.printf("buf:%hhu\n", buf);
169+
// Serial.printf("buf:%d\n", buf);
170+
// Serial.printf("buf:%x\n", buf);
171+
172+
// Serial.printf("result:%hhu\n", ((buf & 0x0f) | (brightness << 4)));
173+
// Serial.printf("result:%d\n", ((buf & 0x0f) | (brightness << 4)));
174+
// Serial.printf("result:%x\n", ((buf & 0x0f) | (brightness << 4)));
175+
176+
// Write1Byte(0x27, ((buf & 0x0f) | (brightness << 4)));
160177
}
161178

162179
bool AXP192::GetBatState() {
@@ -385,6 +402,7 @@ void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage) {
385402
}
386403
}
387404

405+
/// @param number 0=DCDC1 / 1=DCDC2 / 2=DCDC3
388406
void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) {
389407
uint8_t addr;
390408
if (number > 2) return;
@@ -394,12 +412,15 @@ void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) {
394412
addr = 0x26;
395413
break;
396414
case 1:
397-
addr = 0x25;
415+
addr = 0x23;
398416
break;
399417
case 2:
400418
addr = 0x27;
401419
break;
402420
}
421+
// Serial.printf("result:%hhu\n", (Read8bit(addr) & 0X80) | (voltage & 0X7F));
422+
// Serial.printf("result:%d\n", (Read8bit(addr) & 0X80) | (voltage & 0X7F));
423+
// Serial.printf("result:%x\n", (Read8bit(addr) & 0X80) | (voltage & 0X7F));
403424
Write1Byte(addr, (Read8bit(addr) & 0X80) | (voltage & 0X7F));
404425
}
405426

@@ -408,6 +429,7 @@ void AXP192::SetESPVoltage(uint16_t voltage) {
408429
SetDCVoltage(0, voltage);
409430
}
410431
}
432+
411433
void AXP192::SetLcdVoltage(uint16_t voltage) {
412434
if (voltage >= 2500 && voltage <= 3300) {
413435
SetDCVoltage(2, voltage);

src/AXP192.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AXP192 {
4343
void begin();
4444
// Will be deprecated
4545
void begin(mbus_mode_t mode);
46-
void ScreenBreath(uint8_t brightness);
46+
void ScreenBreath(int brightness);
4747
bool GetBatState();
4848

4949
void EnableCoulombcounter(void);

0 commit comments

Comments
 (0)