Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw/mcu/dialog: GPIO configuration with single value #3339

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
apc067 marked this conversation as resolved.
Show resolved Hide resolved
* 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
22 changes: 15 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,30 @@ 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)
apc067 marked this conversation as resolved.
Show resolved Hide resolved
{
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
Loading