Intel® Quark™ Microcontroller Software Interface  1.4.0
Intel® Quark™ Microcontroller BSP
qm_ss_gpio.h
1 /*
2  * {% copyright %}
3  */
4 
5 #ifndef __QM_SS_GPIO_H__
6 #define __QM_SS_GPIO_H__
7 
8 #include "qm_common.h"
9 #include "qm_sensor_regs.h"
10 
11 /**
12  * General Purpose IO for Sensor Subsystem.
13  *
14  * @defgroup groupSSGPIO SS GPIO
15  * @{
16  */
17 
18 /**
19  * GPIO SS pin states.
20  */
21 typedef enum {
22  QM_SS_GPIO_LOW = 0, /**< Pin level high. */
23  QM_SS_GPIO_HIGH, /**< Pin level low. */
24  QM_SS_GPIO_STATE_NUM /**< Number of states. */
26 
27 /**
28 * SS GPIO port configuration type.
29 *
30 * Each bit in the registers control a GPIO pin.
31 */
32 typedef struct {
33  uint32_t direction; /**< SS GPIO direction, 0b: input, 1b: output. */
34  uint32_t int_en; /**< Interrupt enable. */
35  uint32_t int_type; /**< Interrupt type, 0b: level; 1b: edge. */
36  uint32_t int_polarity; /**< Interrupt polarity, 0b: low, 1b: high. */
37  uint32_t int_debounce; /**< Debounce on/off. */
38 
39 #if HAS_SS_GPIO_INTERRUPT_BOTHEDGE
40  uint32_t int_bothedge; /**< Interrupt on rising and falling edges */
41 #endif
42 
43  /**
44  * User callback.
45  *
46  * Called for any interrupt on the Sensor Subsystem GPIO.
47  *
48  * @param[in] data The callback user data.
49  * @param[in] int_status Bitfield of triggered pins.
50  */
51  void (*callback)(void *data, uint32_t int_status);
52  void *callback_data; /**< Callback user data. */
54 
55 /**
56  * Set SS GPIO port configuration.
57  *
58  * This includes the direction of the pins, if interrupts are enabled or not,
59  * the level on which an interrupt is generated, the polarity of interrupts
60  * and if GPIO-debounce is enabled or not. If interrupts are enabled it also
61  * registers the user defined callback function.
62  *
63  * @param[in] gpio SS GPIO port index to configure.
64  * @param[in] cfg New configuration for SS GPIO port. This must not be NULL.
65  *
66  * @return Standard errno return type for QMSI.
67  * @retval 0 on success.
68  * @retval Negative @ref errno for possible error codes.
69  */
70 int qm_ss_gpio_set_config(const qm_ss_gpio_t gpio,
71  const qm_ss_gpio_port_config_t *const cfg);
72 
73 /**
74  * Read the current value of a single pin on a given SS GPIO port.
75  *
76  * @param[in] gpio SS GPIO port index.
77  * @param[in] pin Pin of SS GPIO port to read.
78  * @param[out] state QM_GPIO_LOW for low or QM_GPIO_HIGH for high. This must not
79  * be NULL.
80  *
81  * @return Standard errno return type for QMSI.
82  * @retval 0 on success.
83  * @retval Negative @ref errno for possible error codes.
84  */
85 int qm_ss_gpio_read_pin(const qm_ss_gpio_t gpio, const uint8_t pin,
86  qm_ss_gpio_state_t *const state);
87 
88 /**
89  * Set a single pin on a given SS GPIO port.
90  *
91  * @param[in] gpio SS GPIO port index.
92  * @param[in] pin Pin of SS GPIO port to set.
93  *
94  * @return Standard errno return type for QMSI.
95  * @retval 0 on success.
96  * @retval Negative @ref errno for possible error codes.
97  */
98 int qm_ss_gpio_set_pin(const qm_ss_gpio_t gpio, const uint8_t pin);
99 
100 /**
101  * Clear a single pin on a given SS GPIO port.
102  *
103  * @param[in] gpio SS GPIO port index.
104  * @param[in] pin Pin of SS GPIO port to clear.
105  *
106  * @return Standard errno return type for QMSI.
107  * @retval 0 on success.
108  * @retval Negative @ref errno for possible error codes.
109  */
110 int qm_ss_gpio_clear_pin(const qm_ss_gpio_t gpio, const uint8_t pin);
111 
112 /**
113  * Set or clear a single SS GPIO pin using a state variable.
114  *
115  * @param[in] gpio GPIO port index.
116  * @param[in] pin Pin of GPIO port to update.
117  * @param[in] state QM_GPIO_LOW for low or QM_GPIO_HIGH for high.
118  *
119  * @return Standard errno return type for QMSI.
120  * @retval 0 on success.
121  * @retval Negative @ref errno for possible error codes.
122  */
123 int qm_ss_gpio_set_pin_state(const qm_ss_gpio_t gpio, const uint8_t pin,
124  const qm_ss_gpio_state_t state);
125 
126 /**
127  * Get SS GPIO port values.
128  *
129  * Read entire SS GPIO port. Each bit of the val parameter is set to the current
130  * value of each pin on the port. Maximum 32 pins per port.
131  *
132  * @param[in] gpio SS GPIO port index.
133  * @param[out] port Value of all pins on GPIO port. This must not be NULL.
134  *
135  * @return Standard errno return type for QMSI.
136  * @retval 0 on success.
137  * @retval Negative @ref errno for possible error codes.
138  */
139 int qm_ss_gpio_read_port(const qm_ss_gpio_t gpio, uint32_t *const port);
140 
141 /**
142  * Get SS GPIO port values.
143  *
144  * Write entire SS GPIO port. Each pin on the SS GPIO port is set to the
145  * corresponding value set in the val parameter. Maximum 32 pins per port.
146  *
147  * @param[in] gpio SS GPIO port index.
148  * @param[in] val Value of all pins on SS GPIO port.
149  *
150  * @return Standard errno return type for QMSI.
151  * @retval 0 on success.
152  * @retval Negative @ref errno for possible error codes.
153  */
154 int qm_ss_gpio_write_port(const qm_ss_gpio_t gpio, const uint32_t val);
155 
156 /**
157  * Save SS GPIO context.
158  *
159  * Save the configuration of the specified GPIO peripheral
160  * before entering sleep.
161  *
162  * @param[in] gpio SS GPIO port index.
163  * @param[out] ctx SS GPIO context structure. This must not be NULL.
164  *
165  * @return Standard errno return type for QMSI.
166  * @retval 0 on success.
167  * @retval Negative @ref errno for possible error codes.
168  */
170  qm_ss_gpio_context_t *const ctx);
171 
172 /**
173  * Restore SS GPIO context.
174  *
175  * Restore the configuration of the specified GPIO peripheral
176  * after exiting sleep.
177  *
178  * @param[in] gpio SS GPIO port index.
179  * @param[in] ctx SS GPIO context structure. This must not be NULL.
180  *
181  * @return Standard errno return type for QMSI.
182  * @retval 0 on success.
183  * @retval Negative @ref errno for possible error codes.
184  */
186  const qm_ss_gpio_context_t *const ctx);
187 
188 /**
189  * @}
190  */
191 #endif /* __QM_SS_GPIO_H__ */
qm_ss_gpio_state_t
GPIO SS pin states.
Definition: qm_ss_gpio.h:21
Pin level low.
Definition: qm_ss_gpio.h:23
Pin level high.
Definition: qm_ss_gpio.h:22
uint32_t int_type
Interrupt type, 0b: level; 1b: edge.
Definition: qm_ss_gpio.h:35
qm_ss_gpio_t
Sensor Subsystem GPIO.
uint32_t int_polarity
Interrupt polarity, 0b: low, 1b: high.
Definition: qm_ss_gpio.h:36
uint32_t int_en
Interrupt enable.
Definition: qm_ss_gpio.h:34
int qm_ss_gpio_save_context(const qm_ss_gpio_t gpio, qm_ss_gpio_context_t *const ctx)
Save SS GPIO context.
Definition: qm_ss_gpio.c:158
Number of states.
Definition: qm_ss_gpio.h:24
int qm_ss_gpio_set_pin(const qm_ss_gpio_t gpio, const uint8_t pin)
Set a single pin on a given SS GPIO port.
Definition: qm_ss_gpio.c:98
uint32_t int_bothedge
Interrupt on rising and falling edges.
Definition: qm_ss_gpio.h:40
int qm_ss_gpio_clear_pin(const qm_ss_gpio_t gpio, const uint8_t pin)
Clear a single pin on a given SS GPIO port.
Definition: qm_ss_gpio.c:111
SS GPIO port configuration type.
Definition: qm_ss_gpio.h:32
int qm_ss_gpio_set_pin_state(const qm_ss_gpio_t gpio, const uint8_t pin, const qm_ss_gpio_state_t state)
Set or clear a single SS GPIO pin using a state variable.
Definition: qm_ss_gpio.c:124
int qm_ss_gpio_write_port(const qm_ss_gpio_t gpio, const uint32_t val)
Get SS GPIO port values.
Definition: qm_ss_gpio.c:148
int qm_ss_gpio_read_port(const qm_ss_gpio_t gpio, uint32_t *const port)
Get SS GPIO port values.
Definition: qm_ss_gpio.c:138
int qm_ss_gpio_set_config(const qm_ss_gpio_t gpio, const qm_ss_gpio_port_config_t *const cfg)
Set SS GPIO port configuration.
Definition: qm_ss_gpio.c:37
int qm_ss_gpio_read_pin(const qm_ss_gpio_t gpio, const uint8_t pin, qm_ss_gpio_state_t *const state)
Read the current value of a single pin on a given SS GPIO port.
Definition: qm_ss_gpio.c:84
int qm_ss_gpio_restore_context(const qm_ss_gpio_t gpio, const qm_ss_gpio_context_t *const ctx)
Restore SS GPIO context.
Definition: qm_ss_gpio.c:184
SS GPIO context type.
uint32_t direction
SS GPIO direction, 0b: input, 1b: output.
Definition: qm_ss_gpio.h:33
uint32_t int_debounce
Debounce on/off.
Definition: qm_ss_gpio.h:37
void * callback_data
Callback user data.
Definition: qm_ss_gpio.h:52