Skip to content

Commit 2bf3ffd

Browse files
authored
Merge pull request #591 from FrameworkComputer/hx40
merge 61wh battery into combined firmware
2 parents 3aa98b5 + 00119f3 commit 2bf3ffd

2 files changed

Lines changed: 118 additions & 5 deletions

File tree

.github/workflows/hx40.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: build hx40 firmware
2+
3+
on:
4+
push:
5+
branches:
6+
- hx4*
7+
pull_request:
8+
branches:
9+
- hx40
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build hx40
15+
runs-on: ubuntu-20.04
16+
17+
steps:
18+
- name: install toolchain
19+
run: sudo apt install gcc-arm-none-eabi libftdi1-dev
20+
# Checks out a copy of your repository on the ubuntu-latest machine
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
- name: build hx40 board
24+
env:
25+
BOARD: hx30
26+
run: |
27+
make -j BOARD=$BOARD CROSS_COMPILE=arm-none-eabi-
28+
echo Built $BOARD ec
29+
- name: file sha256
30+
run: sha256sum build/hx30/ec.bin
31+
- name: generate artifact version
32+
run: |
33+
echo "VERSIONINFO=$(date -u +'%Y-%m-%d-%H-%M-%S')_$GITHUB_SHA" >> $GITHUB_ENV
34+
35+
- uses: actions/upload-artifact@v2
36+
with:
37+
name: hx40.${{ env.VERSIONINFO }}.bin
38+
path: build/hx30/ec.bin

baseboard/fwk/battery.c

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,26 @@
2626
#define PARAM_CUT_OFF_LOW 0x10
2727
#define PARAM_CUT_OFF_HIGH 0x00
2828

29+
enum battery_type {
30+
BATTERY_ADL,
31+
BATTERY_RPL,
32+
BATTERY_TYPE_COUNT,
33+
};
34+
35+
struct board_batt_params {
36+
int design_voltage;
37+
const char *batt_name;
38+
const struct battery_info *batt_info;
39+
};
40+
41+
/*
42+
* Set ADL Battery as default
43+
*/
44+
#define DEFAULT_BATTERY_TYPE BATTERY_ADL
45+
static enum battery_type board_battery_type = BATTERY_TYPE_COUNT;
46+
2947
/* Battery info for BQ40Z50 4-cell */
30-
static const struct battery_info info = {
48+
static const struct battery_info adl_info = {
3149
.voltage_max = 17600, /* mV */
3250
.voltage_normal = 15400,
3351
.voltage_min = 12000,
@@ -40,15 +58,70 @@ static const struct battery_info info = {
4058
.discharging_max_c = 62,
4159
};
4260

43-
static enum battery_present batt_pres_prev = BP_NOT_SURE;
44-
static uint8_t charging_maximum_level = NEED_RESTORE;
45-
static int old_btp;
61+
static const struct battery_info rpl_info = {
62+
.voltage_max = 17800, /* mV */
63+
.voltage_normal = 15480,
64+
.voltage_min = 12000,
65+
.precharge_current = 80, /* mA */
66+
.start_charging_min_c = 0,
67+
.start_charging_max_c = 47,
68+
.charging_min_c = 0,
69+
.charging_max_c = 52,
70+
.discharging_min_c = 0,
71+
.discharging_max_c = 62,
72+
};
73+
74+
static struct board_batt_params info[] = {
75+
[BATTERY_ADL] = {
76+
.design_voltage = 15400,
77+
.batt_name = "ADL-55W",
78+
.batt_info = &adl_info,
79+
},
80+
81+
[BATTERY_RPL] = {
82+
.design_voltage = 15480,
83+
.batt_name = "RPL-61W",
84+
.batt_info = &rpl_info,
85+
},
86+
};
87+
BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_TYPE_COUNT);
88+
89+
/* Get type of the battery connected on the board */
90+
static int board_get_battery_type(void)
91+
{
92+
int i;
93+
int vol;
94+
95+
if (!battery_design_voltage(&vol)) {
96+
for (i = 0; i < BATTERY_TYPE_COUNT; i++) {
97+
if (vol == info[i].design_voltage) {
98+
board_battery_type = i;
99+
break;
100+
}
101+
}
102+
}
103+
return board_battery_type;
104+
}
105+
106+
static void board_init_battery_type(void)
107+
{
108+
if (board_get_battery_type() != BATTERY_TYPE_COUNT)
109+
ccprintf("found batt: %s\n", info[board_battery_type].batt_name);
110+
else
111+
ccprintf("battery not found\n");
112+
}
113+
DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_ADC + 1);
46114

47115
const struct battery_info *battery_get_info(void)
48116
{
49-
return &info;
117+
return info[board_battery_type == BATTERY_TYPE_COUNT ?
118+
DEFAULT_BATTERY_TYPE : board_battery_type].batt_info;
50119
}
51120

121+
static enum battery_present batt_pres_prev = BP_NOT_SURE;
122+
static uint8_t charging_maximum_level = NEED_RESTORE;
123+
static int old_btp;
124+
52125
int board_cut_off_battery(void)
53126
{
54127
int rv;
@@ -95,6 +168,8 @@ static int battery_check_disconnect(void)
95168
if (data[3] & BATTERY_DISCHARGING_DISABLED)
96169
return BATTERY_DISCONNECTED;
97170

171+
/* reinit battery type */
172+
board_init_battery_type();
98173

99174
return BATTERY_NOT_DISCONNECTED;
100175
}

0 commit comments

Comments
 (0)