m5stack / M5StickC

M5StickC Arduino Library
MIT License
477 stars 222 forks source link

Implement AXP methods SetChargeVoltage & SetAdcRate #106

Closed fustilio closed 4 years ago

fustilio commented 4 years ago

This PR consists of two functions that were required by our team, hoping to share with the rest of the community if they're useful.

Implement method to set target charging voltage

Writes to 6:5 bits of address 0x33 as per datasheet: image

Implementation reads address and modifies only 6:5 bits

//    0x60 = 0b01100000
// ~(0x60) = 0b10011111
buf = (buf & ~(0x60)) | (voltage & 0x60);

Usage: M5.Axp.SetChargeVoltage(VOLTAGE_4360MV);

Implement method to set ADC sample rate

Writes to 7:6 bits of address 0x84 as per datasheet: image

Implementation reads address and modifies only 7:6 bits

//    0xc0 = 0b11000000
// ~(0xc0) = 0b00111111
buf = (buf & ~(0xc0)) | (rate & 0xc0);

Usage: M5.Axp.SetAdcRate(ADC_RATE_025HZ); // default is ADC_RATE_200HZ

EeeeBin commented 4 years ago

Merged in https://github.com/m5stack/M5StickC/pull/104 Have some different?

fustilio commented 4 years ago

Ah I see, there were some changes made to the master branch which I used to make previous PR before they were merged. I'll be more careful to make PRs from a separate branch in the future. I'll close this PR then. Thanks!