| Nordic Thingy:52 v2.0.0

drv_ext_gpio.h
1 /*
2 Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form, except as embedded into a Nordic
12 Semiconductor ASA integrated circuit in a product or a software update for
13 such product, must reproduce the above copyright notice, this list of
14 conditions and the following disclaimer in the documentation and/or other
15 materials provided with the distribution.
16
17 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18 contributors may be used to endorse or promote products derived from this
19 software without specific prior written permission.
20
21 4. This software, with or without modification, must only be used with a
22 Nordic Semiconductor ASA integrated circuit.
23
24 5. Any software provided in binary form under this license must not be reverse
25 engineered, decompiled, modified and/or disassembled.
26
27 THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
48 #ifndef __DRV_EXT_GPIO_H__
49 #define __DRV_EXT_GPIO_H__
50
51 #include <stdint.h>
52 #include "nrf_error.h"
53 #include "drv_sx1509.h"
54
57 enum
58 {
59 DRV_EXT_GPIO_STATUS_CODE_SUCCESS = NRF_SUCCESS,
60 DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM,
61 DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN
62 };
63
64 #define DRV_EXT_GPIO_PIN_HIGHEST_ID DRV_SX1509_DATA_PIN15_Pos
65 #define DRV_EXT_GPIO_NUM_PINS_TOTAL (DRV_EXT_GPIO_PIN_HIGHEST_ID + 1)
66
67
69 typedef enum
70 {
71 DRV_EXT_GPIO_PIN_DIR_OUTPUT,
72 DRV_EXT_GPIO_PIN_DIR_INPUT
73 } drv_ext_gpio_pin_dir_t;
74
77 typedef enum
78 {
79 DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED,
80 DRV_EXT_GPIO_PIN_INPUT_BUF_DISABLED
81 } drv_ext_gpio_pin_input_buf_t;
82
85 typedef enum
86 {
87 DRV_EXT_GPIO_PIN_NOPULL,
88 DRV_EXT_GPIO_PIN_PULLDOWN,
89 DRV_EXT_GPIO_PIN_PULLUP
90 } drv_ext_gpio_pin_pull_t;
91
94 typedef enum
95 {
96 DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL,
97 DRV_EXT_GPIO_PIN_DRIVE_OPENDRAIN
98 }drv_ext_gpio_pin_drive_type_t;
99
102 typedef enum
103 {
104 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED,
105 DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_ENABLED
106 }drv_ext_gpio_pin_slew_rate_t;
107
125 uint32_t drv_ext_gpio_cfg(
126 uint32_t pin_number,
127 drv_ext_gpio_pin_dir_t dir,
128 drv_ext_gpio_pin_input_buf_t input_buf,
129 drv_ext_gpio_pin_pull_t pull_config,
130 drv_ext_gpio_pin_drive_type_t drive_type,
131 drv_ext_gpio_pin_slew_rate_t slew_rate);
132
135 typedef struct
136 {
137 drv_sx1509_cfg_t const * p_cfg;
138 } drv_ext_gpio_init_t;
139
147 uint32_t drv_ext_gpio_reset(void);
148
164 uint32_t drv_ext_gpio_reg_data_init(uint32_t data);
165
174 uint32_t drv_ext_gpio_cfg_output(uint32_t pin_number);
175
186 uint32_t drv_ext_gpio_cfg_input(uint32_t pin_number, drv_ext_gpio_pin_pull_t pull_config);
187
198 uint32_t drv_ext_gpio_pin_dir_modify(uint32_t pin_number, drv_ext_gpio_pin_dir_t direction);
199
210 uint32_t drv_ext_gpio_pin_slew_rate_modify(uint32_t pin_number, drv_ext_gpio_pin_slew_rate_t slew_rate);
211
222 uint32_t drv_ext_gpio_pin_drive_type_modify(uint32_t pin_number, drv_ext_gpio_pin_drive_type_t drive_type);
223
234 uint32_t drv_ext_gpio_pin_input_buffer_modify(uint32_t pin_number, drv_ext_gpio_pin_input_buf_t input_buf);
235
246 uint32_t drv_ext_gpio_pin_set(uint32_t pin_number);
247
258 uint32_t drv_ext_gpio_pins_set(uint32_t pin_mask);
259
270 uint32_t drv_ext_gpio_pin_clear(uint32_t pin_number);
271
282 uint32_t drv_ext_gpio_pins_clear(uint32_t pin_mask);
283
294 uint32_t drv_ext_gpio_pin_toggle(uint32_t pin_number);
295
306 uint32_t drv_ext_gpio_pins_toggle(uint32_t pin_mask);
307
321 uint32_t drv_ext_gpio_pin_write(uint32_t pin_number, uint32_t value);
322
337 uint32_t drv_ext_gpio_pin_read(uint32_t pin_number, uint32_t * const p_pin);
338
350 uint32_t drv_ext_gpio_pins_read(uint32_t * const p_pins);
351
361 uint32_t drv_ext_gpio_init(drv_ext_gpio_init_t const * const p_init, bool on_init_reset);
362
363 #endif
364
drv_ext_gpio_cfg_output
uint32_t drv_ext_gpio_cfg_output(uint32_t pin_number)
Function for configuring the given GPIO pin_number as output with given initial value set...
DRV_EXT_GPIO_STATUS_CODE_SUCCESS
Successfull.
Definition: drv_ext_gpio.h:59
DRV_EXT_GPIO_PIN_PULLDOWN
Pin pulldown resistor enabled.
Definition: drv_ext_gpio.h:88
drv_ext_gpio_pin_dir_t
drv_ext_gpio_pin_dir_t
Pin direction definitions.
Definition: drv_ext_gpio.h:69
drv_sx1509_cfg_t
SX1509 configuration.
Definition: drv_sx1509.h:70
drv_ext_gpio_pin_slew_rate_t
drv_ext_gpio_pin_slew_rate_t
Regular or increased slew rate.
Definition: drv_ext_gpio.h:102
drv_ext_gpio_pins_clear
uint32_t drv_ext_gpio_pins_clear(uint32_t pin_mask)
Function for clearing GPIO pins.
drv_ext_gpio_pin_drive_type_t
drv_ext_gpio_pin_drive_type_t
Push-pull or open drain operation.
Definition: drv_ext_gpio.h:94
drv_ext_gpio_reset
uint32_t drv_ext_gpio_reset(void)
Function for resetting all the registers of the GPIO extender to their default values.
drv_ext_gpio_pin_set
uint32_t drv_ext_gpio_pin_set(uint32_t pin_number)
Function for setting a GPIO pin.
drv_ext_gpio_init
uint32_t drv_ext_gpio_init(drv_ext_gpio_init_t const *const p_init, bool on_init_reset)
Function for initializing the GPIO extender.
drv_ext_gpio_pins_read
uint32_t drv_ext_gpio_pins_read(uint32_t *const p_pins)
Function for reading the input level of all GPIO pins.
DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM
Invalid parameters.
Definition: drv_ext_gpio.h:60
drv_ext_gpio_pins_set
uint32_t drv_ext_gpio_pins_set(uint32_t pin_mask)
Function for setting GPIO pins.
drv_ext_gpio_reg_data_init
uint32_t drv_ext_gpio_reg_data_init(uint32_t data)
Function for setting all the RegData registers at the same time.
drv_ext_gpio_pin_dir_modify
uint32_t drv_ext_gpio_pin_dir_modify(uint32_t pin_number, drv_ext_gpio_pin_dir_t direction)
Function for setting the direction of a GPIO pin.
drv_ext_gpio_cfg
uint32_t drv_ext_gpio_cfg(uint32_t pin_number, drv_ext_gpio_pin_dir_t dir, drv_ext_gpio_pin_input_buf_t input_buf, drv_ext_gpio_pin_pull_t pull_config, drv_ext_gpio_pin_drive_type_t drive_type, drv_ext_gpio_pin_slew_rate_t slew_rate)
Pin configuration function.
drv_ext_gpio_pin_input_buf_t
drv_ext_gpio_pin_input_buf_t
Connection of input buffer.
Definition: drv_ext_gpio.h:77
drv_ext_gpio_pin_read
uint32_t drv_ext_gpio_pin_read(uint32_t pin_number, uint32_t *const p_pin)
Function for reading the input level of a GPIO pin.
drv_ext_gpio_pin_toggle
uint32_t drv_ext_gpio_pin_toggle(uint32_t pin_number)
Function for toggling a GPIO pin.
DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL
Standard push-pull operation.
Definition: drv_ext_gpio.h:96
drv_ext_gpio_pins_toggle
uint32_t drv_ext_gpio_pins_toggle(uint32_t pin_mask)
Function for toggling GPIO pins.
DRV_EXT_GPIO_PIN_DRIVE_OPENDRAIN
Open drain.
Definition: drv_ext_gpio.h:97
drv_ext_gpio_pin_drive_type_modify
uint32_t drv_ext_gpio_pin_drive_type_modify(uint32_t pin_number, drv_ext_gpio_pin_drive_type_t drive_type)
Function for setting the drive type a given GPIO pin.
drv_ext_gpio_pin_slew_rate_modify
uint32_t drv_ext_gpio_pin_slew_rate_modify(uint32_t pin_number, drv_ext_gpio_pin_slew_rate_t slew_rate)
Function for enabling or disabling increased slew rate for a given GPIO pin.
drv_ext_gpio_pin_input_buffer_modify
uint32_t drv_ext_gpio_pin_input_buffer_modify(uint32_t pin_number, drv_ext_gpio_pin_input_buf_t input_buf)
Function for enabling and disabling the input buffer.
DRV_EXT_GPIO_PIN_NOPULL
No pin pullup or pulldown.
Definition: drv_ext_gpio.h:87
DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN
Invalid GPIO pin or pin mask selected.
Definition: drv_ext_gpio.h:61
DRV_EXT_GPIO_PIN_DIR_INPUT
Input.
Definition: drv_ext_gpio.h:72
DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED
Connect input buffer.
Definition: drv_ext_gpio.h:79
drv_ext_gpio_cfg_input
uint32_t drv_ext_gpio_cfg_input(uint32_t pin_number, drv_ext_gpio_pin_pull_t pull_config)
Function for configuring the given GPIO pin number as input with given initial value set...
DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_ENABLED
Increased slew rate.
Definition: drv_ext_gpio.h:105
drv_ext_gpio_pin_pull_t
drv_ext_gpio_pin_pull_t
Pin to be pulled down, up, or no-pull.
Definition: drv_ext_gpio.h:85
DRV_EXT_GPIO_PIN_PULLUP
Pin pullup resistor enabled.
Definition: drv_ext_gpio.h:89
DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED
No slew rate alteration.
Definition: drv_ext_gpio.h:104
drv_ext_gpio_pin_write
uint32_t drv_ext_gpio_pin_write(uint32_t pin_number, uint32_t value)
Function for writing a value to a GPIO pin.
drv_ext_gpio_pin_clear
uint32_t drv_ext_gpio_pin_clear(uint32_t pin_number)
Function for clearing a GPIO pin.
DRV_EXT_GPIO_PIN_INPUT_BUF_DISABLED
Disconnect input buffer.
Definition: drv_ext_gpio.h:80
DRV_EXT_GPIO_PIN_DIR_OUTPUT
Output.
Definition: drv_ext_gpio.h:71
drv_ext_gpio_init_t
GPIO extender driver configuration.
Definition: drv_ext_gpio.h:135