Skip to content

Commit

Permalink
hw/mcu/dialog: GPIO configuration with single value (#3339)
Browse files Browse the repository at this point in the history
* hw/mcu/dialog: GPIO configuration with single value

Add API to support GPIO configuration using a combined mode / I/O properties
value.
  • Loading branch information
apc067 authored Nov 13, 2024
1 parent d431da8 commit 66cb554
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
19 changes: 19 additions & 0 deletions hw/mcu/dialog/da1469x/include/mcu/da1469x_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ const struct qspi_flash_config *da1469x_qspi_get_config(void);
*/
void hal_os_tick_calc_params(uint32_t cycles_per_sec);

/**
* Configure GPIO using a single value.
*
* @param pin GPIO ID
* @param raw_mode Combined mode / I/O properties value
* Mode: Selected feed in the GPIO matrix (see MCU_GPIO_FUNC_*)
* I/O propeties: Input [bare/PU/PD] or output [PP/OD] (see MCU_GPIO_MODE_*)
*/
void mcu_gpio_set_pin_function_raw(int pin, uint32_t raw_mode);

/**
* Query GPIO mode as a single value.
*
* @param pin GPIO ID
*
* @return Combined mode / I/O properties value
*/
uint32_t mcu_gpio_get_pin_function_raw(int pin);

#ifdef __cplusplus
}
#endif
Expand Down
23 changes: 16 additions & 7 deletions hw/mcu/dialog/da1469x/src/hal_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,31 @@ hal_gpio_irq_disable(int pin)
}

void
mcu_gpio_set_pin_function(int pin, int mode, mcu_gpio_func func)
mcu_gpio_set_pin_function_raw(int pin, uint32_t raw_mode)
{
uint32_t primask;

__HAL_DISABLE_INTERRUPTS(primask);

mcu_gpio_unlatch_prepare(pin);

GPIO_PIN_MODE_REG(pin) = (func & GPIO_P0_00_MODE_REG_PID_Msk) |
(mode & (GPIO_P0_00_MODE_REG_PUPD_Msk | GPIO_P0_00_MODE_REG_PPOD_Msk));

GPIO_PIN_MODE_REG(pin) = raw_mode;
mcu_gpio_unlatch(pin);

__HAL_ENABLE_INTERRUPTS(primask);
}

uint32_t
mcu_gpio_get_pin_function_raw(int pin)
{
return GPIO_PIN_MODE_REG(pin);
}

void
mcu_gpio_set_pin_function(int pin, int mode, mcu_gpio_func func)
{
mcu_gpio_set_pin_function_raw(pin, (func & GPIO_P0_00_MODE_REG_PID_Msk) |
(mode &
(GPIO_P0_00_MODE_REG_PUPD_Msk | GPIO_P0_00_MODE_REG_PPOD_Msk)));
}

void
mcu_gpio_enter_sleep(void)
{
Expand Down

0 comments on commit 66cb554

Please sign in to comment.