Skip to content

Commit

Permalink
rg_input: Added formulas given in issue #93
Browse files Browse the repository at this point in the history
Untested at the moment!
  • Loading branch information
ducalex committed Feb 29, 2024
1 parent 6baf173 commit 53717b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion components/retro-go/rg_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static rg_battery_t battery_state = {0};
bool rg_input_read_battery_raw(rg_battery_t *out)
{
uint32_t raw_value = 0;
bool present = true;
bool charging = false;

#if RG_BATTERY_DRIVER == 1 /* ADC1 */
for (int i = 0; i < 4; ++i)
Expand All @@ -44,6 +46,7 @@ bool rg_input_read_battery_raw(rg_battery_t *out)
if (!rg_i2c_read(0x20, -1, &data, 5))
return false;
raw_value = data[4];
charging = data[4] == 255;
#else
return false;
#endif
Expand All @@ -53,7 +56,8 @@ bool rg_input_read_battery_raw(rg_battery_t *out)
*out = (rg_battery_t){
.level = RG_MAX(0.f, RG_MIN(100.f, RG_BATTERY_CALC_PERCENT(raw_value))),
.volts = RG_BATTERY_CALC_VOLTAGE(raw_value),
.present = true,
.present = present,
.charging = charging,
};
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/targets/mrgc-g32/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// Battery
#define RG_BATTERY_DRIVER 2
#define RG_BATTERY_CALC_PERCENT(raw) (((raw) - 170) / 30.f * 100.f)
#define RG_BATTERY_CALC_VOLTAGE(raw) (0)
#define RG_BATTERY_CALC_VOLTAGE(raw) (3 * (raw) * 3.3f / 256)

// Status LED
// #define RG_GPIO_LED GPIO_NUM_NC
Expand Down
2 changes: 1 addition & 1 deletion components/retro-go/targets/mrgc-gbm/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// Battery
#define RG_BATTERY_DRIVER 2
#define RG_BATTERY_CALC_PERCENT(raw) (((raw) - 170) / 30.f * 100.f)
#define RG_BATTERY_CALC_VOLTAGE(raw) (0)
#define RG_BATTERY_CALC_VOLTAGE(raw) (128 * 3.3f / (raw))

// Status LED
// #define RG_GPIO_LED GPIO_NUM_NC
Expand Down

0 comments on commit 53717b7

Please sign in to comment.