Skip to content

Commit c4b8240

Browse files
committed
power manage support pmu error report
Signed-off-by: Adam BZH <adam@onekey.so>
1 parent eb95d79 commit c4b8240

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

core/embed/trezorhal/ble.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
uint8_t battery_cap = 0xFF;
99
uint8_t dev_pwr_sta = 0;
10+
uint8_t dev_pwr_err = 0;
1011

1112
static usart_msg ble_usart_msg;
1213
static bool get_ble_name = false;
@@ -30,7 +31,6 @@ static uint8_t ble_build[8] = {0};
3031
static uint8_t ble_hash[32] = {0};
3132
static uint8_t ble_mac_addr[6] = {0};
3233
static uint8_t dev_press_sta = 0;
33-
static uint8_t dev_pwr = 0;
3434
static int ble_request_state = -1;
3535
static uint8_t ble_response_buf[64];
3636

@@ -345,30 +345,30 @@ void ble_uart_poll(void) {
345345
memcpy(ble_boot_ver, ble_usart_msg.cmd_vale, 5);
346346
get_ble_boot_ver = true;
347347
break;
348-
case BLE_CMD_PLUG_STA:
348+
case BLE_CMD_POWER_STA:
349349
get_ble_charging = true;
350-
if (ble_usart_msg.cmd_vale[0] == 1 || ble_usart_msg.cmd_vale[0] == 3 ||
351-
ble_usart_msg.cmd_vale[0] == 4) {
350+
if (ble_usart_msg.cmd_vale[0] == BLE_INSERT_POWER ||
351+
ble_usart_msg.cmd_vale[0] == BLE_CHARGING_PWR ||
352+
ble_usart_msg.cmd_vale[0] == BLE_CHAGE_OVER) {
352353
dev_pwr_sta = 1;
353-
if (ble_usart_msg.cmd_vale[1] == CHARGE_BY_USB ||
354-
ble_usart_msg.cmd_vale[1] == CHARGE_BY_WIRELESS) {
354+
if (ble_usart_msg.cmd_vale[1] == CHARGE_TYPE_USB ||
355+
ble_usart_msg.cmd_vale[1] == CHARGE_TYPE_WIRELESS) {
355356
ble_charging_type = ble_usart_msg.cmd_vale[1];
356357
}
357358
} else {
358359
dev_pwr_sta = 0;
359360
ble_charging_type = 0;
360361
}
361-
362362
break;
363363
case BLE_CMD_EQ:
364364
get_ble_battery = true;
365365
battery_cap = ble_usart_msg.cmd_vale[0];
366366
break;
367-
case BLE_CMD_RPESS:
367+
case BLE_CMD_KEY_STA:
368368
dev_press_sta = ble_usart_msg.cmd_vale[0];
369369
break;
370-
case BLE_CMD_PWR:
371-
dev_pwr = ble_usart_msg.cmd_vale[0];
370+
case BLE_CMD_POWER_ERR:
371+
dev_pwr_err = ble_usart_msg.cmd_vale[0];
372372
break;
373373
case BLE_CMD_BATTERY_INFO:
374374
if (ble_usart_msg.cmd_vale[0] == BLE_BATTERY_INFO_VOLTAGE) {

core/embed/trezorhal/ble.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
extern uint8_t battery_cap;
99
extern uint8_t dev_pwr_sta;
10+
extern uint8_t dev_pwr_err;
1011

1112
#define BLE_NAME_LEN 16
12-
#define CHARGE_BY_USB 0x01
13-
#define CHARGE_BY_WIRELESS 0x02
1413

1514
// BLE send command
1615
#define BLE_CMD_ADV 0x01
@@ -20,17 +19,43 @@ extern uint8_t dev_pwr_sta;
2019
#define BLE_CMD_FM_VER 0x05
2120
#define BLE_CMD_PROTO_VER 0x06
2221
#define BLE_CMD_BOOT_VER 0x07
23-
#define BLE_CMD_PLUG_STA 0x08
22+
#define BLE_CMD_POWER_STA 0x08
2423
#define BLE_CMD_EQ 0x09
25-
#define BLE_CMD_RPESS 0x0A
26-
#define BLE_CMD_PWR 0x0B
24+
#define BLE_CMD_KEY_STA 0x0A
25+
#define BLE_CMD_POWER_ERR 0x0B
2726
#define BLE_CMD_FLASHLED_STATE 0x0C
2827
#define BLE_CMD_BATTERY_INFO 0x0D
2928
#define BLE_CMD_DEV_KEY 0x0E
3029
#define BLE_CMD_BT_BUILD_ID 0x10
3130
#define BLE_CMD_BT_HASH 0x11
3231
#define BLE_CMD_BT_MAC 0x12
3332

33+
#if defined(BLE_CMD_POWER_STA)
34+
#define BLE_INSERT_POWER 0x01
35+
#define BLE_REMOVE_POWER 0x02
36+
#define BLE_CHARGING_PWR 0x03
37+
#define BLE_CHAGE_OVER 0x04
38+
39+
#define CHARGE_TYPE_USB 0x01
40+
#define CHARGE_TYPE_WIRELESS 0x02
41+
#endif
42+
43+
#if defined(BLE_CMD_KEY_STA)
44+
#define BLE_KEY_SHORT_PRESS 0x01
45+
#define BLE_KEY_LONG_PRESS 0x02
46+
#define BLE_KEY_PRESS 0x20
47+
#define BLE_KEY_RELEASE 0x40
48+
#endif
49+
50+
#if defined(BLE_CMD_POWER_ERR)
51+
#define BLE_CMD_POWER_ERR__NONE 0x00
52+
#define BLE_CMD_POWER_ERR__PMU_OVER_TEMP 0x01
53+
#define BLE_CMD_POWER_ERR__BATT_OVER_TEMP 0x02
54+
#define BLE_CMD_POWER_ERR__BATT_UNDER_TEMP 0x03
55+
#define BLE_CMD_POWER_ERR__BATT_OVER_VOLTAGE 0x04
56+
#define BLE_CMD_POWER_ERR__CHARGE_TIMEOUT 0x05
57+
#endif
58+
3459
#define BLE_KEY_RESP_SUCCESS 0x00
3560
#define BLE_KEY_RESP_FAILED 0x01
3661
#define BLE_KEY_RESP_PUBKEY 0x02
@@ -127,6 +152,7 @@ void ble_reset(void);
127152
#define ble_set_switch(...)
128153
#define ble_get_switch(...) false
129154
#define change_ble_sta(...)
155+
130156
#endif
131157

132158
#endif

core/embed/trezorhal/device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,10 @@ void device_burnin_test(bool force) {
11681168
charge_type_last = charge_type;
11691169
display_bar(0, battery_info_offset_y - 20, 360, FONT_HEIGHT,
11701170
COLOR_BLACK);
1171-
if (CHARGE_BY_USB == charge_type_last) {
1171+
if (CHARGE_TYPE_USB == charge_type_last) {
11721172
display_text(0, battery_info_offset_y, "charging via usb", -1,
11731173
FONT_NORMAL, COLOR_WHITE, COLOR_BLACK);
1174-
} else if (CHARGE_BY_WIRELESS == charge_type_last) {
1174+
} else if (CHARGE_TYPE_WIRELESS == charge_type_last) {
11751175
display_text(0, battery_info_offset_y, "charging via wireless", -1,
11761176
FONT_NORMAL, COLOR_WHITE, COLOR_BLACK);
11771177
} else {

0 commit comments

Comments
 (0)