Skip to content

Commit f866225

Browse files
authored
Merge pull request #19 from FrameworkComputer/hx20mec152x
Hx20mec152x
2 parents 71d23f9 + 6aa7848 commit f866225

29 files changed

+1536
-392
lines changed

.github/workflows/hx20.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: build hx20 firmware
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
name: Build hx20 evt
8+
runs-on: ubuntu-20.04
9+
10+
steps:
11+
- name: install toolchain
12+
run: sudo apt install gcc-arm-none-eabi libftdi1-dev
13+
# Checks out a copy of your repository on the ubuntu-latest machine
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
- name: build hx20 board
17+
env:
18+
BOARD: hx20
19+
ORB: n
20+
run: |
21+
make -j BOARD=$BOARD HX20_ORB=$ORB CROSS_COMPILE=arm-none-eabi-
22+
echo Built $BOARD ec
23+
- name: file sha256
24+
run: sha256sum build/hx20/ec.bin
25+
- name: generate artifact version
26+
run: |
27+
echo "::set-env name=VERSION_NAME::$(date -u +'%Y-%m-%d-%H-%M-%S')_$(git rev-parse --short HEAD)"
28+
29+
- uses: actions/upload-artifact@v2
30+
with:
31+
name: hx20.${{env.VERSION_NAME}}.bin
32+
path: build/hx20/ec.bin

.github/workflows/lint.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: lint code in pull request
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened]
6+
7+
jobs:
8+
build:
9+
name: lint new changes
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
- name: get checkpatch
17+
run: |
18+
wget "https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl"
19+
wget "https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt"
20+
chmod +x checkpatch.pl
21+
22+
- name: checkpatch
23+
run: |
24+
git diff origin/${{ github.base_ref }} | ./checkpatch.pl --mailback --no-tree --ignore MAINTAINERS,FILE_PATH_CHANGES - > checkpatch.txt || true
25+
if [ -s checkpatch.txt ]; then
26+
errors=$(cat checkpatch.txt)
27+
errors="${errors//'%'/'%25'}"
28+
errors="${errors//$'\n'/'%0A'}"
29+
errors="${errors//$'\r'/'%0D'}"
30+
echo "::error file=Checkpatch.txt::$errors"
31+
exit=1
32+
fi
33+
if [ ${exit} == 1 ]; then
34+
exit 1;
35+
fi
36+
- name: output
37+
run: |
38+
cat checkpatch.txt

board/hx20/battery.c

+17-173
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Battery pack vendor provided charging profile
66
*/
77

8+
#include "adc.h"
9+
#include "adc_chip.h"
810
#include "battery.h"
911
#include "battery_smart.h"
1012
#include "charge_state.h"
@@ -17,18 +19,18 @@
1719
#define PARAM_CUT_OFF_LOW 0x10
1820
#define PARAM_CUT_OFF_HIGH 0x00
1921

20-
/* Battery info for BQ40Z55 */
22+
/* Battery info for BQ40Z50 */
2123
static const struct battery_info info = {
22-
.voltage_max = 8700, /* mV */
23-
.voltage_normal = 7600,
24+
.voltage_max = 17600, /* mV */
25+
.voltage_normal = 15400,
2426
.voltage_min = 6000,
25-
.precharge_current = 256, /* mA */
27+
.precharge_current = 72, /* mA */
2628
.start_charging_min_c = 0,
27-
.start_charging_max_c = 46,
29+
.start_charging_max_c = 47,
2830
.charging_min_c = 0,
29-
.charging_max_c = 60,
31+
.charging_max_c = 52,
3032
.discharging_min_c = 0,
31-
.discharging_max_c = 60,
33+
.discharging_max_c = 62,
3234
};
3335

3436
const struct battery_info *battery_get_info(void)
@@ -56,175 +58,17 @@ int board_cut_off_battery(void)
5658
return rv;
5759
}
5860

59-
#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE
60-
61-
static int fast_charging_allowed = 1;
62-
63-
/*
64-
* This can override the smart battery's charging profile. To make a change,
65-
* modify one or more of requested_voltage, requested_current, or state.
66-
* Leave everything else unchanged.
67-
*
68-
* Return the next poll period in usec, or zero to use the default (which is
69-
* state dependent).
70-
*/
71-
int charger_profile_override(struct charge_state_data *curr)
61+
enum battery_present battery_is_present(void)
7262
{
73-
/* temp in 0.1 deg C */
74-
int temp_c = curr->batt.temperature - 2731;
75-
/* keep track of last temperature range for hysteresis */
76-
static enum {
77-
TEMP_RANGE_1,
78-
TEMP_RANGE_2,
79-
TEMP_RANGE_3,
80-
TEMP_RANGE_4,
81-
TEMP_RANGE_5,
82-
} temp_range = TEMP_RANGE_3;
83-
/* keep track of last voltage range for hysteresis */
84-
static enum {
85-
VOLTAGE_RANGE_LOW,
86-
VOLTAGE_RANGE_HIGH,
87-
} voltage_range = VOLTAGE_RANGE_LOW;
88-
89-
/* Current and previous battery voltage */
90-
int batt_voltage;
91-
static int prev_batt_voltage;
63+
enum battery_present bp;
64+
int mv;
9265

93-
/*
94-
* Determine temperature range. The five ranges are:
95-
* < 10C
96-
* 10-15C
97-
* 15-23C
98-
* 23-45C
99-
* > 45C
100-
*
101-
* Add 0.2 degrees of hysteresis.
102-
* If temp reading was bad, use last range.
103-
*/
104-
if (!(curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE)) {
105-
if (temp_c < 99)
106-
temp_range = TEMP_RANGE_1;
107-
else if (temp_c > 101 && temp_c < 149)
108-
temp_range = TEMP_RANGE_2;
109-
else if (temp_c > 151 && temp_c < 229)
110-
temp_range = TEMP_RANGE_3;
111-
else if (temp_c > 231 && temp_c < 449)
112-
temp_range = TEMP_RANGE_4;
113-
else if (temp_c > 451)
114-
temp_range = TEMP_RANGE_5;
115-
}
66+
mv = adc_read_channel(ADC_VCIN1_BATT_TEMP);
11667

117-
/*
118-
* If battery voltage reading is bad, use the last reading. Otherwise,
119-
* determine voltage range with hysteresis.
120-
*/
121-
if (curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) {
122-
batt_voltage = prev_batt_voltage;
123-
} else {
124-
batt_voltage = prev_batt_voltage = curr->batt.voltage;
125-
if (batt_voltage < 8200)
126-
voltage_range = VOLTAGE_RANGE_LOW;
127-
else if (batt_voltage > 8300)
128-
voltage_range = VOLTAGE_RANGE_HIGH;
129-
}
68+
if (mv == ADC_READ_ERROR)
69+
return -1;
13070

131-
/*
132-
* If we are not charging or we aren't using fast charging profiles,
133-
* then do not override desired current and voltage.
134-
*/
135-
if (curr->state != ST_CHARGE || !fast_charging_allowed)
136-
return 0;
71+
bp = (mv < 3000 ? BP_YES : BP_NO);
13772

138-
/*
139-
* Okay, impose our custom will:
140-
* When battery is 0-10C:
141-
* CC at 486mA @ 8.7V
142-
* CV at 8.7V
143-
*
144-
* When battery is <15C:
145-
* CC at 1458mA @ 8.7V
146-
* CV at 8.7V
147-
*
148-
* When battery is <23C:
149-
* CC at 3402mA until 8.3V @ 8.7V
150-
* CC at 2430mA @ 8.7V
151-
* CV at 8.7V
152-
*
153-
* When battery is <45C:
154-
* CC at 4860mA until 8.3V @ 8.7V
155-
* CC at 2430mA @ 8.7V
156-
* CV at 8.7V until current drops to 450mA
157-
*
158-
* When battery is >45C:
159-
* CC at 2430mA @ 8.3V
160-
* CV at 8.3V (when battery is hot we don't go to fully charged)
161-
*/
162-
switch (temp_range) {
163-
case TEMP_RANGE_1:
164-
curr->requested_current = 486;
165-
curr->requested_voltage = 8700;
166-
break;
167-
case TEMP_RANGE_2:
168-
curr->requested_current = 1458;
169-
curr->requested_voltage = 8700;
170-
break;
171-
case TEMP_RANGE_3:
172-
curr->requested_voltage = 8700;
173-
if (voltage_range == VOLTAGE_RANGE_HIGH)
174-
curr->requested_current = 2430;
175-
else
176-
curr->requested_current = 3402;
177-
break;
178-
case TEMP_RANGE_4:
179-
curr->requested_voltage = 8700;
180-
if (voltage_range == VOLTAGE_RANGE_HIGH)
181-
curr->requested_current = 2430;
182-
else
183-
curr->requested_current = 4860;
184-
break;
185-
case TEMP_RANGE_5:
186-
curr->requested_current = 2430;
187-
curr->requested_voltage = 8300;
188-
break;
189-
}
190-
191-
return 0;
192-
}
193-
194-
/* Customs options controllable by host command. */
195-
#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
196-
197-
enum ec_status charger_profile_override_get_param(uint32_t param,
198-
uint32_t *value)
199-
{
200-
if (param == PARAM_FASTCHARGE) {
201-
*value = fast_charging_allowed;
202-
return EC_RES_SUCCESS;
203-
}
204-
return EC_RES_INVALID_PARAM;
73+
return bp;
20574
}
206-
207-
enum ec_status charger_profile_override_set_param(uint32_t param,
208-
uint32_t value)
209-
{
210-
if (param == PARAM_FASTCHARGE) {
211-
fast_charging_allowed = value;
212-
return EC_RES_SUCCESS;
213-
}
214-
return EC_RES_INVALID_PARAM;
215-
}
216-
217-
static int command_fastcharge(int argc, char **argv)
218-
{
219-
if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed))
220-
return EC_ERROR_PARAM1;
221-
222-
ccprintf("fastcharge %s\n", fast_charging_allowed ? "on" : "off");
223-
224-
return EC_SUCCESS;
225-
}
226-
DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
227-
"[on|off]",
228-
"Get or set fast charging profile");
229-
230-
#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */

0 commit comments

Comments
 (0)