kopia lustrzana https://github.com/OpenRTX/OpenRTX
core: battery: split configurations for battery chemistry and cells number
rodzic
28aa4378c2
commit
71c144d426
|
@ -26,17 +26,10 @@
|
|||
* Obtained by multiplying the values in volt by 256.
|
||||
*/
|
||||
|
||||
#if defined CONFIG_BAT_LIPO_1S
|
||||
static const uint16_t bat_v_min = 0x039C; // 3.61V
|
||||
static const uint16_t bat_v_max = 0x0426; // 4.15V
|
||||
#elif defined CONFIG_BAT_LIPO_2S
|
||||
static const uint16_t bat_v_min = 0x071A; // 7.10V
|
||||
static const uint16_t bat_v_max = 0x0819; // 8.10V
|
||||
#elif defined CONFIG_BAT_LIPO_3S
|
||||
static const uint16_t bat_v_min = 0x0AD4; // 10.83V
|
||||
static const uint16_t bat_v_max = 0x0C73; // 12.45V
|
||||
#elif defined CONFIG_BAT_NONE
|
||||
// Nothing to do, just avoid arising the compiler error
|
||||
#if defined(CONFIG_BAT_LIPO)
|
||||
static const uint16_t vcell_max = 0x0414; // 4.08V
|
||||
static const uint16_t vcell_min = 0x039C; // 3.61V
|
||||
#elif defined(CONFIG_BAT_NONE)
|
||||
#else
|
||||
#error Please define a battery type into platform/targets/.../hwconfig.h
|
||||
#endif
|
||||
|
@ -64,6 +57,9 @@ uint8_t battery_getCharge(uint16_t vbat)
|
|||
* of 0.79% and minimum error of -0.78%
|
||||
*/
|
||||
|
||||
const uint32_t vbat_max = vcell_max * CONFIG_BAT_NCELLS;
|
||||
const uint32_t vbat_min = vcell_min * CONFIG_BAT_NCELLS;
|
||||
|
||||
uint32_t vb = vbat << 16;
|
||||
vb = vb / 1000;
|
||||
vb = (vb + 256) >> 8;
|
||||
|
@ -72,10 +68,10 @@ uint8_t battery_getCharge(uint16_t vbat)
|
|||
* If the voltage is below minimum we return 0 to prevent an underflow in
|
||||
* the following calculation
|
||||
*/
|
||||
if (vb < bat_v_min) return 0;
|
||||
if (vb < vbat_min) return 0;
|
||||
|
||||
uint32_t diff = vb - bat_v_min;
|
||||
uint32_t range = bat_v_max - bat_v_min;
|
||||
uint32_t diff = vb - vbat_min;
|
||||
uint32_t range = vbat_max - vbat_min;
|
||||
uint32_t result = ((diff << 8) / range) * 100;
|
||||
result += 128;
|
||||
result >>= 8;
|
||||
|
|
|
@ -62,7 +62,8 @@ extern const struct sky73210 pll;
|
|||
#define CONFIG_SCREEN_BRIGHTNESS
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -62,7 +62,8 @@ extern const struct sky73210 pll;
|
|||
#define CONFIG_SCREEN_BRIGHTNESS
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -56,7 +56,8 @@ extern const struct Adc adc1;
|
|||
#define CONFIG_PIX_FMT_RGB565
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -51,7 +51,8 @@ extern const struct spiDevice c6000_spi;
|
|||
#define CONFIG_SCREEN_BRIGHTNESS
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ extern const struct Adc adc1;
|
|||
#define CONFIG_SCREEN_BRIGHTNESS
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -58,7 +58,8 @@ extern const struct Adc adc1;
|
|||
#define CONFIG_PIX_FMT_RGB565
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -33,7 +33,8 @@ enum Mod17Flags
|
|||
#define CONFIG_SCREEN_BRIGHTNESS
|
||||
|
||||
/* Battery type */
|
||||
#define CONFIG_BAT_LIPO_2S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 2
|
||||
|
||||
/* Device supports M17 mode */
|
||||
#define CONFIG_M17
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
#define CONFIG_PIX_FMT_BW
|
||||
#define CONFIG_GPS
|
||||
|
||||
#define CONFIG_BAT_LIPO_1S
|
||||
#define CONFIG_BAT_LIPO
|
||||
#define CONFIG_BAT_NCELLS 1
|
||||
|
||||
#define CONFIG_M17
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue