-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathbutton.h
More file actions
140 lines (118 loc) · 3.2 KB
/
Copy pathbutton.h
File metadata and controls
140 lines (118 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Button API for Chrome EC */
#ifndef __CROS_EC_BUTTON_H
#define __CROS_EC_BUTTON_H
#include "common.h"
#include "compile_time_macros.h"
#include "ec_commands.h"
#include "gpio_signal.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BUTTON_FLAG_ACTIVE_HIGH BIT(0)
#define BUTTON_FLAG_DISABLED BIT(1) /* Button disabled */
#define BUTTON_DEBOUNCE_US CONFIG_BUTTON_DEBOUNCE
struct button_config {
const char *name;
enum keyboard_button_type type;
enum gpio_signal gpio;
uint32_t debounce_us;
#ifdef CONFIG_PLATFORM_EC_POWER_BUTTON_DEBOUNCE
uint32_t debounce_us_ap_on;
uint32_t debounce_us_ap_off;
#endif
int flags;
};
enum button {
#ifdef CONFIG_VOLUME_BUTTONS
BUTTON_VOLUME_UP,
BUTTON_VOLUME_DOWN,
#endif /* defined(CONFIG_VOLUME_BUTTONS) */
#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON
BUTTON_RECOVERY,
#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON_2
BUTTON_RECOVERY_2,
#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON_2) */
#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */
BUTTON_COUNT,
};
/* Table of buttons for the board. */
#ifndef CONFIG_BUTTONS_RUNTIME_CONFIG
extern const struct button_config buttons[];
#else
extern struct button_config buttons[];
#endif
/*
* Buttons used to decide whether recovery is requested or not
*/
extern const struct button_config *recovery_buttons[];
extern const int recovery_buttons_count;
/*
* Button initialization, called from main.
*/
void button_init(void);
/*
* Reassign a button GPIO signal at runtime.
*
* @param button_type Button type to reassign
* @param gpio GPIO to assign to the button
*
* Returns EC_SUCCESS if button change is accepted and made active,
* EC_ERROR_* otherwise.
*/
int button_reassign_gpio(enum button button_type, enum gpio_signal gpio);
/*
* Disable a button GPIO signal at runtime.
*
* @param button_type Button type to reassign
*
* Returns EC_SUCCESS if the button is disabled,
* EC_ERROR_* otherwise.
*/
int button_disable_gpio(enum button button_type);
/*
* Interrupt handler for button.
*
* @param signal Signal which triggered the interrupt.
*/
void button_interrupt(enum gpio_signal signal);
/*
* Is this button using ADC voltages to detect state?
*
* @param gpio The GPIO of interest.
* Returns 1 if button state is detected by ADC, 0 if not.
*/
int button_is_adc_detected(enum gpio_signal gpio);
/*
* Sample the ADC voltage and convert to a physical pressed/not pressed state.
*
* @param gpio ADC detected GPIO.
* Returns the physical state of the button.
*/
int adc_to_physical_value(enum gpio_signal gpio);
/**
* Get states of buttons pressed on POR.
*
* @return button states where bit positions correspond to enum button.
*/
uint32_t button_get_boot_button(void);
/* Public for testing purposes only, undocumented. */
enum debug_state {
STATE_DEBUG_NONE,
STATE_DEBUG_CHECK,
STATE_STAGING,
STATE_DEBUG_MODE_ACTIVE,
STATE_SYSRQ_PATH,
STATE_WARM_RESET_PATH,
STATE_SYSRQ_EXEC,
STATE_WARM_RESET_EXEC,
};
__test_only void reset_button_debug_state(void);
__test_only enum debug_state get_button_debug_state(void);
#ifdef __cplusplus
}
#endif
#endif /* __CROS_EC_BUTTON_H */