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: Keep GPIO mux powered if non-GPIO pins enabled #2401

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all 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
15 changes: 13 additions & 2 deletions hw/mcu/dialog/da1469x/src/hal_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct hal_gpio_irq hal_gpio_irqs[HAL_GPIO_MAX_IRQ];
#if MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM) >= 0
static uint32_t g_mcu_gpio_latch_state[2];
static uint8_t g_mcu_gpio_retained_num;
static uint32_t g_mcu_gpio_can_sleep;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now this variable is used only with values 0/1 maybe uint32_t is too much

static struct da1469x_retreg g_mcu_gpio_retained[MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM)];
#endif

Expand All @@ -109,6 +110,10 @@ static struct da1469x_retreg g_mcu_gpio_retained[MYNEWT_VAL(MCU_GPIO_RETAINABLE_
*
* Once pin is restored to default configuration it shall be latched again by
* calling mcu_gpio_latch().
*
* If all unlatched pins are configured as GPIO, we can then latch them all and
* disable PD_COM in sleep. Otherwise, we should not do this to keep mux active
* to make sure all pins are driven by proper peripheral.
*/

#if MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM) >= 0
Expand All @@ -128,6 +133,11 @@ mcu_gpio_retained_add_port(uint32_t latch_val, volatile uint32_t *base_reg)

da1469x_retreg_assign(retreg, &base_reg[pin]);

if (base_reg[pin] & GPIO_P0_00_MODE_REG_PID_Msk) {
/* Prevent disabling PD_COM if any pin has non_GPIO function */
g_mcu_gpio_can_sleep = 0;
}

g_mcu_gpio_retained_num++;
retreg++;
}
Expand All @@ -139,6 +149,7 @@ mcu_gpio_retained_refresh(void)
{
#if MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM) >= 0
g_mcu_gpio_retained_num = 0;
g_mcu_gpio_can_sleep = 1;

mcu_gpio_retained_add_port(CRG_TOP->P0_PAD_LATCH_REG, &GPIO->P0_00_MODE_REG);
mcu_gpio_retained_add_port(CRG_TOP->P1_PAD_LATCH_REG, &GPIO->P1_00_MODE_REG);
Expand Down Expand Up @@ -469,7 +480,7 @@ void
mcu_gpio_enter_sleep(void)
{
#if MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM) >= 0
if (g_mcu_gpio_retained_num == 0) {
if (!g_mcu_gpio_can_sleep || (g_mcu_gpio_retained_num == 0)) {
return;
}

Expand All @@ -489,7 +500,7 @@ void
mcu_gpio_exit_sleep(void)
{
#if MYNEWT_VAL(MCU_GPIO_RETAINABLE_NUM) >= 0
if (g_mcu_gpio_retained_num == 0) {
if (!g_mcu_gpio_can_sleep || (g_mcu_gpio_retained_num == 0)) {
return;
}

Expand Down