| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2019-2023, Jacques Gagnon | ||
| 3 | * SPDX-License-Identifier: Apache-2.0 | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "zephyr/types.h" | ||
| 7 | #include "tools/util.h" | ||
| 8 | #include "system/manager.h" | ||
| 9 | #include "adapter/config.h" | ||
| 10 | #include "macro.h" | ||
| 11 | |||
| 12 | typedef void (*config_change_t)(uint32_t index); | ||
| 13 | |||
| 14 | #define BIT_32(n) (1UL << ((n) & 0x1F)) | ||
| 15 | |||
| 16 | #define MACRO_BASE (BIT_32(BR_COMBO_BASE_1) | BIT_32(BR_COMBO_BASE_2) | BIT_32(BR_COMBO_BASE_3)) | ||
| 17 | #define SYS_RESET (MACRO_BASE | BIT_32(BR_COMBO_SYS_RESET)) | ||
| 18 | #define BT_INQUIRY (MACRO_BASE | BIT_32(BR_COMBO_BT_INQUIRY)) | ||
| 19 | #define SYS_POWER_OFF (MACRO_BASE | BIT_32(BR_COMBO_SYS_POWER_OFF)) | ||
| 20 | #define FACTORY_RESET (MACRO_BASE | BIT_32(BR_COMBO_BASE_4) | BIT_32(BR_COMBO_FACTORY_RESET)) | ||
| 21 | #define DEEP_SLEEP (MACRO_BASE | BIT_32(BR_COMBO_BASE_4) | BIT_32(BR_COMBO_DEEP_SLEEP)) | ||
| 22 | #define WIRED_RST (MACRO_BASE | BIT_32(BR_COMBO_WIRED_RST)) | ||
| 23 | |||
| 24 | struct macro { | ||
| 25 | uint32_t macro; | ||
| 26 | uint8_t sys_mgr_cmd; | ||
| 27 | uint32_t flag_mask; | ||
| 28 | config_change_t cfg_func; | ||
| 29 | }; | ||
| 30 | |||
| 31 | static void update_cfg_mode(uint32_t index); | ||
| 32 | |||
| 33 | static struct macro macros[] = { | ||
| 34 | {.macro = SYS_RESET, .sys_mgr_cmd = SYS_MGR_CMD_RST, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO1}, | ||
| 35 | {.macro = BT_INQUIRY, .sys_mgr_cmd = SYS_MGR_CMD_INQ_TOOGLE, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO2}, | ||
| 36 | {.macro = SYS_POWER_OFF, .sys_mgr_cmd = SYS_MGR_CMD_PWR_OFF, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO3}, | ||
| 37 | {.macro = FACTORY_RESET, .sys_mgr_cmd = SYS_MGR_CMD_FACTORY_RST, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO4}, | ||
| 38 | {.macro = DEEP_SLEEP, .sys_mgr_cmd = SYS_MGR_CMD_DEEP_SLEEP, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO5}, | ||
| 39 | {.macro = WIRED_RST, .sys_mgr_cmd = SYS_MGR_CMD_WIRED_RST, .flag_mask = BT_WAITING_FOR_RELEASE_MACRO6, .cfg_func = update_cfg_mode}, | ||
| 40 | }; | ||
| 41 | |||
| 42 | ✗ | static void update_cfg_mode(uint32_t index) { | |
| 43 | ✗ | config.out_cfg[index].dev_mode &= 0x01; | |
| 44 | ✗ | config.out_cfg[index].dev_mode ^= 0x01; | |
| 45 | ✗ | } | |
| 46 | |||
| 47 | 7980 | static void check_macro(uint32_t index, int32_t value, struct macro *macro, atomic_t *flags) { | |
| 48 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→6) taken 7980 times.
|
7980 | if (value == macro->macro) { |
| 49 | ✗ | if (!atomic_test_bit(flags, macro->flag_mask)) { | |
| 50 | ✗ | atomic_set_bit(flags, macro->flag_mask); | |
| 51 | } | ||
| 52 | } | ||
| 53 |
1/2✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→13) taken 7980 times.
|
7980 | else if (atomic_test_bit(flags, macro->flag_mask)) { |
| 54 | ✗ | atomic_clear_bit(flags, macro->flag_mask); | |
| 55 | |||
| 56 | ✗ | printf("# %s: Apply macro %08lX %08lX\n", __FUNCTION__, value, macro->macro); | |
| 57 | ✗ | if (macro->cfg_func) { | |
| 58 | ✗ | macro->cfg_func(index); | |
| 59 | } | ||
| 60 | ✗ | sys_mgr_cmd(macro->sys_mgr_cmd); | |
| 61 | } | ||
| 62 | 7980 | } | |
| 63 | |||
| 64 | 1330 | void sys_macro_hdl(struct wired_ctrl *ctrl_data, atomic_t *flags) { | |
| 65 | 1330 | int32_t value = ctrl_data->btns[3].value; | |
| 66 | |||
| 67 |
2/2✓ Branch 0 (5→3) taken 7980 times.
✓ Branch 1 (5→6) taken 1330 times.
|
9310 | for (uint32_t i = 0; i < sizeof(macros)/sizeof(macros[0]); i++) { |
| 68 | 7980 | struct macro *macro = ¯os[i]; | |
| 69 | |||
| 70 | 7980 | check_macro(ctrl_data->index, value, macro, flags); | |
| 71 | } | ||
| 72 | 1330 | } | |
| 73 |