3 #if (RUUVI_NRF5_SDK15_GPIO_ENABLED || DOXYGEN || CEEDLING)
8 #include "nrf_drv_gpiote.h"
26 static bool m_gpio_is_init =
false;
31 static inline uint8_t ruuvi_to_nrf_pin_map (
const ri_gpio_id_t pin)
33 return ( (pin >> 3U) & 0xE0U) + (pin & 0x1FU);
39 static inline ri_gpio_id_t nrf_to_ruuvi_pin (nrf_drv_gpiote_pin_t pin)
41 return ( (pin >> 5) << 8) + (pin & 0x1F);
48 m_gpio_is_init =
true;
56 if (
false == m_gpio_is_init)
62 for (uint8_t iii = 0; iii < NUMBER_OF_PINS; iii++)
68 m_gpio_is_init =
false;
74 return m_gpio_is_init;
84 const uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
89 nrf_gpio_cfg_default (nrf_pin);
93 nrf_gpio_cfg_input (nrf_pin, NRF_GPIO_PIN_NOPULL);
97 nrf_gpio_cfg_input (nrf_pin, NRF_GPIO_PIN_PULLUP);
101 nrf_gpio_cfg_input (nrf_pin, NRF_GPIO_PIN_PULLDOWN);
105 nrf_gpio_cfg_output (nrf_pin);
109 nrf_gpio_cfg (nrf_pin,
110 NRF_GPIO_PIN_DIR_OUTPUT,
111 NRF_GPIO_PIN_INPUT_DISCONNECT,
114 NRF_GPIO_PIN_NOSENSE);
118 nrf_gpio_cfg (nrf_pin,
119 NRF_GPIO_PIN_DIR_OUTPUT,
120 NRF_GPIO_PIN_INPUT_CONNECT,
123 NRF_GPIO_PIN_NOSENSE);
127 nrf_gpio_cfg (nrf_pin,
128 NRF_GPIO_PIN_DIR_OUTPUT,
129 NRF_GPIO_PIN_INPUT_CONNECT,
132 NRF_GPIO_PIN_NOSENSE);
136 nrf_gpio_cfg (nrf_pin,
137 NRF_GPIO_PIN_DIR_OUTPUT,
138 NRF_GPIO_PIN_INPUT_CONNECT,
141 NRF_GPIO_PIN_NOSENSE);
145 nrf_gpio_cfg (nrf_pin,
146 NRF_GPIO_PIN_DIR_OUTPUT,
147 NRF_GPIO_PIN_INPUT_CONNECT,
150 NRF_GPIO_PIN_NOSENSE);
165 const uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
166 nrf_gpio_pin_toggle (nrf_pin);
179 const uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
183 nrf_gpio_pin_set (nrf_pin);
187 nrf_gpio_pin_clear (nrf_pin);
209 const uint8_t nrf_pin = ruuvi_to_nrf_pin_map (pin);
210 bool high = nrf_gpio_pin_read (nrf_pin);
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
rd_status_t ri_gpio_uninit(void)
Uninitializes GPIO module. Call this to reset GPIO to High-Z mode. After uninitialization all GPIO pi...
bool ri_gpio_is_init(void)
return true if GPIO is init, false otherwise.
rd_status_t ri_gpio_configure(const ri_gpio_id_t pin, const ri_gpio_mode_t mode)
Configure a pin of a port into a mode. If there are several ports the platform driver must implement ...
rd_status_t ri_gpio_toggle(const ri_gpio_id_t pin)
Toggle the state of a pin of a port. If there are several ports the platform driver must implement a ...
rd_status_t ri_gpio_init(void)
Initializes GPIO module. Call this before other GPIO functions. After initialization all GPIO pins sh...
rd_status_t ri_gpio_read(const ri_gpio_id_t pin, ri_gpio_state_t *const state)
Read state of a pin of a port into bool high If there are several ports the platform driver must impl...
rd_status_t ri_gpio_write(const ri_gpio_id_t pin, const ri_gpio_state_t state)
Write a pin of a port into given state If there are several ports the platform driver must implement ...
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
uint16_t ri_gpio_id_t
port<<8 + pin
#define RI_GPIO_ID_UNUSED
Enable implementation selected by application.
@ RI_GPIO_MODE_OUTPUT_STANDARD
Push-pull output, can be written.
@ RI_GPIO_MODE_SINK_PULLUP_STANDARD
Sink only, pull-up, standard drive. I2C without external resistors.
@ RI_GPIO_MODE_INPUT_PULLUP
Input, can be read. Pulled up by internal resistor, value depends on IC.
@ RI_GPIO_MODE_OUTPUT_HIGHDRIVE
Push-pull output, can be written. Higher current drive than standard.
@ RI_GPIO_MODE_SINK_NOPULL_HIGHDRIVE
Sink only, nopull,, high-drive. I2C with strong external resistors.
@ RI_GPIO_MODE_INPUT_NOPULL
Input, can be read. No pull resistors.
@ RI_GPIO_MODE_SINK_NOPULL_STANDARD
Sink only, nopull, standard drive. I2C with weak external resistors.
@ RI_GPIO_MODE_SINK_PULLUP_HIGHDRIVE
Sink only, pull-up, high-drive. I2C with optional external resistors.
@ RI_GPIO_MODE_HIGH_Z
High-impedance mode, electrically disconnected.
@ RI_GPIO_MODE_INPUT_PULLDOWN
Input, can be read. Pulled dpwn by internal resistor, value depends on IC.
ri_gpio_state_t
States of GPIO pins.
@ RI_GPIO_LOW
GPIO electrically low.
@ RI_GPIO_HIGH
GPIO electrically high.