Skip to content

Commit

Permalink
nrfx: hal: gpio: add pin level retention API
Browse files Browse the repository at this point in the history
So that we can also operate by passing pin numbers.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
  • Loading branch information
gmarull authored and masz-nordic committed Oct 31, 2024
1 parent a386b22 commit 373ae9c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions nrfx/hal/nrf_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ NRF_STATIC_INLINE void nrf_gpio_port_retain_set(NRF_GPIO_Type * p_reg, uint32_t
* @return Mask of retention domains set, created using @ref nrf_gpio_retain_mask_t.
*/
NRF_STATIC_INLINE uint32_t nrf_gpio_port_retain_get(NRF_GPIO_Type const * p_reg);

/**
* @brief Function for checking the retention setting of a pin.
*
* @param pin_number Pin number.
*
* @retval true If pin is retained.
* @retval false If pin is not retained.
*/
NRF_STATIC_INLINE bool nrf_gpio_pin_retain_check(uint32_t pin_number);
#endif

#if NRF_GPIO_HAS_RETENTION_SETCLEAR
Expand All @@ -774,6 +784,20 @@ NRF_STATIC_INLINE void nrf_gpio_port_retain_enable(NRF_GPIO_Type * p_reg, uint32
* @param mask Mask of pins to have retention be disabled, created using @ref nrf_gpio_retain_mask_t.
*/
NRF_STATIC_INLINE void nrf_gpio_port_retain_disable(NRF_GPIO_Type * p_reg, uint32_t mask);

/**
* @brief Function for enabling the retention of a pin.
*
* @param pin_number Pin number.
*/
NRF_STATIC_INLINE void nrf_gpio_pin_retain_enable(uint32_t pin_number);

/**
* @brief Function for disabling the retention of a pin.
*
* @param pin_number Pin number.
*/
NRF_STATIC_INLINE void nrf_gpio_pin_retain_disable(uint32_t pin_number);
#endif


Expand Down Expand Up @@ -1344,6 +1368,13 @@ NRF_STATIC_INLINE uint32_t nrf_gpio_port_retain_get(NRF_GPIO_Type const * p_reg)
{
return p_reg->RETAIN;
}

NRF_STATIC_INLINE bool nrf_gpio_pin_retain_check(uint32_t pin_number)
{
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);

return (nrf_gpio_port_retain_get(reg) & (1UL << pin_number)) != 0U;
}
#endif

#if NRF_GPIO_HAS_RETENTION_SETCLEAR
Expand All @@ -1356,6 +1387,20 @@ NRF_STATIC_INLINE void nrf_gpio_port_retain_disable(NRF_GPIO_Type * p_reg, uint3
{
p_reg->RETAINCLR = mask;
}

NRF_STATIC_INLINE void nrf_gpio_pin_retain_enable(uint32_t pin_number)
{
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);

nrf_gpio_port_retain_enable(reg, 1UL << pin_number);
}

NRF_STATIC_INLINE void nrf_gpio_pin_retain_disable(uint32_t pin_number)
{
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);

nrf_gpio_port_retain_disable(reg, 1UL << pin_number);
}
#endif

#if NRF_GPIO_HAS_DETECT_MODE
Expand Down

0 comments on commit 373ae9c

Please sign in to comment.