Skip to content

Commit 954a923

Browse files
committed
main: add power and sleep keys
1 parent 28ed4c1 commit 954a923

File tree

15 files changed

+556
-211
lines changed

15 files changed

+556
-211
lines changed

main/Kconfig.projbuild

Lines changed: 83 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
menu "PWM Fan Controller"
22

3-
menu "Fan Configuration"
4-
config FAN_OUT_PIN
5-
int "Fan Out Pin"
6-
default 33
3+
menu "Bluetooth Configuration"
4+
config BT_NAME
5+
string "Bluetooth Name"
6+
default "PWM Fan Controller"
7+
help
8+
Bluetooth name exposed by the device.
79

8-
config FAN_IN_PIN
9-
int "Fan In Pin"
10-
default 27
10+
config ENABLE_BLE_IF
11+
bool "Enable BLE Control Interface"
12+
default y
13+
help
14+
Select this to enable BLE OTA and RC features.
1115
endmenu
1216

1317
menu "Power Configuration"
@@ -34,22 +38,18 @@ config I2C_SCL_PIN
3438
depends on ENABLE_POWER_MONITOR
3539
endmenu
3640

37-
menu "Bluetooth Configuration"
38-
config BT_NAME
39-
string "Bluetooth Name"
40-
default "PWM Fan Controller"
41-
help
42-
Bluetooth name exposed by the device.
41+
menu "Fan Configuration"
42+
config FAN_OUT_PIN
43+
int "Fan Out Pin"
44+
default 33
4345

44-
config ENABLE_BLE_CONTROL_IF
45-
bool "Enable BLE Control Interface"
46-
default y
47-
help
48-
Select this to enable BLE OTA and RC features.
49-
endmenu
46+
config FAN_IN_PIN
47+
int "Fan In Pin"
48+
default 27
49+
endmenu
5050

5151
menu "Key Configuration"
52-
config ENABLE_ENCODER
52+
config ENABLE_EC
5353
bool "Enable Encoder"
5454
default y
5555
help
@@ -58,7 +58,7 @@ config ENABLE_ENCODER
5858
choice EC_TYPE
5959
prompt "Encoder Type"
6060
default EC_TYPE_1P2D
61-
depends on ENABLE_ENCODER
61+
depends on ENABLE_EC
6262
help
6363
Select the encoder type.
6464

@@ -71,17 +71,76 @@ endchoice
7171
config EC_PHASE_A_PIN
7272
int "Encoder Phase A Pin"
7373
default 21
74-
depends on ENABLE_ENCODER
74+
depends on ENABLE_EC
7575

7676
config EC_PHASE_B_PIN
7777
int "Encoder Phase B Pin"
7878
default 22
79-
depends on ENABLE_ENCODER
79+
depends on ENABLE_EC
8080

8181
config EC_BUTTON_PIN
8282
int "Encoder Button Pin"
8383
default 32
84-
depends on ENABLE_ENCODER
84+
depends on ENABLE_EC
85+
86+
config ENABLE_PWR_KEY
87+
bool "Enable Power Key"
88+
default y
89+
depends on ENABLE_QC
90+
help
91+
Select this to enable Power Key.
92+
93+
config PWR_KEY_HOLD_TIME
94+
int "Power Key Hold Time (ms)"
95+
default 50
96+
depends on ENABLE_PWR_KEY
97+
98+
choice PWR_KEY_ACTIVE_LEVEL
99+
prompt "Power Key Active Level"
100+
default PWR_KEY_ACTIVE_LOW
101+
depends on ENABLE_PWR_KEY
102+
help
103+
Select Power Key Active Level.
104+
105+
config PWR_KEY_ACTIVE_HIGH
106+
bool "Active High"
107+
config PWR_KEY_ACTIVE_LOW
108+
bool "Active Low"
109+
endchoice
110+
111+
config PWR_KEY_PIN
112+
int "Power Key Pin"
113+
default 0
114+
depends on ENABLE_PWR_KEY
115+
116+
config ENABLE_SLP_KEY
117+
bool "Enable Sleep Key"
118+
default y
119+
help
120+
Select this to enable Sleep Key.
121+
122+
config SLP_KEY_HOLD_TIME
123+
int "Sleep Key Hold Time (ms)"
124+
default 50
125+
depends on ENABLE_SLP_KEY
126+
127+
choice SLP_KEY_ACTIVE_LEVEL
128+
prompt "Sleep Key Active Level"
129+
default SLP_KEY_ACTIVE_LOW
130+
depends on ENABLE_SLP_KEY
131+
help
132+
Select Sleep Key Active Level.
133+
134+
config SLP_KEY_ACTIVE_HIGH
135+
bool "Active High"
136+
config SLP_KEY_ACTIVE_LOW
137+
bool "Active Low"
138+
endchoice
139+
140+
config SLP_KEY_PIN
141+
int "Sleep Key Pin"
142+
default 35
143+
depends on ENABLE_SLP_KEY
85144
endmenu
86145

87146
menu "GUI Configuration"

main/inc/core/os.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
#include "freertos/event_groups.h"
1313

1414
typedef enum user_event_group_bits {
15-
OS_PWR_RESTART_BIT = BIT0,
15+
OS_PWR_SLP_BIT = BIT0,
16+
OS_PWR_RST_BIT = BIT1,
1617

17-
BLE_GATTS_IDLE_BIT = BIT1,
18-
BLE_GATTS_LOCK_BIT = BIT2,
18+
BLE_GATTS_IDLE_BIT = BIT2,
19+
BLE_GATTS_LOCK_BIT = BIT3,
1920

20-
FAN_RUN_BIT = BIT3,
21-
GUI_RELOAD_BIT = BIT4,
21+
FAN_RUN_BIT = BIT4,
22+
KEY_RUN_BIT = BIT5,
23+
GUI_RELOAD_BIT = BIT6,
2224
} user_event_group_bits_t;
2325

2426
extern EventGroupHandle_t user_event_group;
2527

26-
extern void os_power_restart_wait(EventBits_t bits);
28+
extern void os_pwr_slp_wait(EventBits_t bits);
29+
extern void os_pwr_rst_wait(EventBits_t bits);
2730

2831
extern void os_init(void);
2932

main/inc/user/ec.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* ec.h
3+
*
4+
* Created on: 2020-05-25 13:32
5+
* Author: Jack Chen <[email protected]>
6+
*/
7+
8+
#ifndef INC_USER_EC_H_
9+
#define INC_USER_EC_H_
10+
11+
typedef enum {
12+
EC_EVT_N = 0x0,
13+
EC_EVT_I = 0x1,
14+
EC_EVT_D = 0x2,
15+
16+
EC_EVT_N_B = 0x3,
17+
EC_EVT_I_B = 0x4,
18+
EC_EVT_D_B = 0x5,
19+
20+
EC_EVT_MAX
21+
} encoder_evt_t;
22+
23+
extern void ec_init(void);
24+
25+
#endif /* INC_USER_EC_H_ */

main/inc/user/key.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
/*
22
* key.h
33
*
4-
* Created on: 2020-05-25 13:32
4+
* Created on: 2018-05-31 14:07
55
* Author: Jack Chen <[email protected]>
66
*/
77

88
#ifndef INC_USER_KEY_H_
99
#define INC_USER_KEY_H_
1010

11-
typedef enum {
12-
EC_EVT_N = 0x0,
13-
EC_EVT_I = 0x1,
14-
EC_EVT_D = 0x2,
15-
16-
EC_EVT_N_B = 0x3,
17-
EC_EVT_I_B = 0x4,
18-
EC_EVT_D_B = 0x5,
19-
20-
EC_EVT_MAX
21-
} encoder_evt_t;
22-
2311
extern void key_init(void);
2412

2513
#endif /* INC_USER_KEY_H_ */

main/inc/user/key_handle.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* key_handle.h
3+
*
4+
* Created on: 2019-07-06 10:35
5+
* Author: Jack Chen <[email protected]>
6+
*/
7+
8+
#ifndef INC_USER_KEY_HANDLE_H_
9+
#define INC_USER_KEY_HANDLE_H_
10+
11+
extern void pwr_key_handle(void);
12+
extern void slp_key_handle(void);
13+
14+
#endif /* INC_USER_KEY_HANDLE_H_ */

main/inc/user/pwr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ typedef enum {
2020
PWR_IDX_MAX
2121
} pwr_idx_t;
2222

23+
extern void pwr_set_mode(pwr_idx_t idx);
24+
2325
extern pwr_idx_t pwr_get_mode(void);
2426
extern char *pwr_get_mode_str(void);
2527

26-
extern void pwr_init(pwr_idx_t idx);
28+
extern void pwr_init(void);
2729

2830
#endif /* INC_USER_PWR_H_ */

main/src/app_main.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
#include "board/ina219.h"
1717

18+
#include "user/ec.h"
19+
#include "user/key.h"
1820
#include "user/pwr.h"
1921
#include "user/fan.h"
2022
#include "user/gui.h"
2123
#include "user/led.h"
22-
#include "user/key.h"
2324
#include "user/ble_app.h"
2425

2526
static void core_init(void)
@@ -53,8 +54,16 @@ static void board_init(void)
5354

5455
static void user_init(void)
5556
{
57+
#ifdef CONFIG_ENABLE_EC
58+
ec_init();
59+
#endif
60+
61+
#if defined(CONFIG_ENABLE_PWR_KEY) || defined(CONFIG_ENABLE_SLP_KEY)
62+
key_init();
63+
#endif
64+
5665
#ifdef CONFIG_ENABLE_QC
57-
pwr_init(PWR_IDX_QC_12V);
66+
pwr_init();
5867
#endif
5968

6069
fan_init();
@@ -67,11 +76,7 @@ static void user_init(void)
6776
led_init();
6877
#endif
6978

70-
#ifdef CONFIG_ENABLE_ENCODER
71-
key_init();
72-
#endif
73-
74-
#ifdef CONFIG_ENABLE_BLE_CONTROL_IF
79+
#ifdef CONFIG_ENABLE_BLE_IF
7580
ble_app_init();
7681
#endif
7782
}

0 commit comments

Comments
 (0)