Skip to content

Commit

Permalink
MSDK-1013: Adding ME18 GPIO4 support. (#343)
Browse files Browse the repository at this point in the history
* MSDK-1013: Adding ME18 GPIO4 support.

* MSDK-1013: Resolving clang-format errors.

---------

Co-authored-by: Scheiffler <Jacob.Scheiffler@analog.com>
  • Loading branch information
Jacob-Scheiffler and Jacob-Scheiffler authored Feb 1, 2023
1 parent 9534dc2 commit c08bf27
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 111 deletions.
101 changes: 28 additions & 73 deletions Libraries/Boards/MAX32690/Source/pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include "pwrseq_regs.h"
#include "mcr_regs.h"

/* Save the callback state for GPIO4 */
static pb_callback gpio4_callback;
static int gpio4_pb;

/******************************************************************************/
int PB_Init(void)
{
Expand All @@ -50,18 +46,11 @@ int PB_Init(void)

// Enable pushbutton inputs
for (i = 0; i < num_pbs; i++) {
if (MXC_GPIO_GET_IDX(pb_pin[i].port) == 4) {
MXC_MCR->gpio4_ctrl &= ~(MXC_F_MCR_GPIO4_CTRL_P40_OE | MXC_F_MCR_GPIO4_CTRL_P40_PE);
MXC_MCR->gpio4_ctrl |= MXC_F_MCR_GPIO4_CTRL_P40_DO;
} else if (MXC_GPIO_Config(&pb_pin[i]) != E_NO_ERROR) {
if (MXC_GPIO_Config(&pb_pin[i]) != E_NO_ERROR) {
retval = E_UNKNOWN;
}
}

/* Initialize the GPIO4 callback state */
gpio4_callback = NULL;
gpio4_pb = -1;

return retval;
}

Expand All @@ -71,35 +60,25 @@ int PB_RegisterCallback(unsigned int pb, pb_callback callback)
MXC_ASSERT(pb < num_pbs);

if (callback) {
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
/* Save the GPIO4 callback and pb index */
gpio4_callback = callback;
gpio4_pb = pb;

MXC_PWRSEQ->lpwkst4 = pb_pin[gpio4_pb].mask;
MXC_PWRSEQ->lpwken4 |= pb_pin[pb].mask;
NVIC_EnableIRQ(GPIOWAKE_IRQn);
return E_NO_ERROR;
}

// Register callback
MXC_GPIO_RegisterCallback(&pb_pin[pb], callback, (void *)pb);

// Configure and enable interrupt
// Enable interrupt
MXC_GPIO_IntConfig(&pb_pin[pb], MXC_GPIO_INT_FALLING);
MXC_GPIO_EnableInt(pb_pin[pb].port, pb_pin[pb].mask);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(MXC_GPIO_GET_IDX(pb_pin[pb].port)));

// Enable IRQ in NVIC
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
MXC_PWRSEQ->lpwkst4 = pb_pin[pb].mask;
NVIC_EnableIRQ(GPIOWAKE_IRQn);
} else {
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(MXC_GPIO_GET_IDX(pb_pin[pb].port)));
}
} else {
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
/* Clear the GPIO4 callback and pb index */
gpio4_callback = NULL;
gpio4_pb = -1;

NVIC_DisableIRQ(GPIOWAKE_IRQn);
MXC_PWRSEQ->lpwken4 &= ~pb_pin[pb].mask;

return E_NO_ERROR;
}

// Disable interrupt and clear callback
MXC_GPIO_DisableInt(pb_pin[pb].port, pb_pin[pb].mask);
MXC_GPIO_RegisterCallback(&pb_pin[pb], NULL, NULL);
Expand All @@ -114,34 +93,23 @@ int PB_RegisterCallbackRiseFall(unsigned int pb, pb_callback callback)
MXC_ASSERT(pb < num_pbs);

if (callback) {
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
/* Save the GPIO4 callback and pb index */
gpio4_callback = callback;
gpio4_pb = pb;

MXC_PWRSEQ->lpwkst4 = pb_pin[gpio4_pb].mask;
MXC_PWRSEQ->lpwken4 |= pb_pin[pb].mask;
NVIC_EnableIRQ(GPIOWAKE_IRQn);

return E_NO_ERROR;
}
// Register callback
MXC_GPIO_RegisterCallback(&pb_pin[pb], callback, (void *)pb);

// Configure and enable interrupt
MXC_GPIO_IntConfig(&pb_pin[pb], MXC_GPIO_INT_BOTH);
MXC_GPIO_EnableInt(pb_pin[pb].port, pb_pin[pb].mask);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(MXC_GPIO_GET_IDX(pb_pin[pb].port)));

// Enable IRQ in NVIC
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
MXC_PWRSEQ->lpwkst4 = pb_pin[pb].mask;
NVIC_EnableIRQ(GPIOWAKE_IRQn);
} else {
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(MXC_GPIO_GET_IDX(pb_pin[pb].port)));
}
} else {
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
/* Clear the GPIO4 callback and pb index */
gpio4_callback = NULL;
gpio4_pb = -1;

NVIC_DisableIRQ(GPIOWAKE_IRQn);
MXC_PWRSEQ->lpwken4 &= ~pb_pin[pb].mask;

return E_NO_ERROR;
}

// Disable interrupt and clear callback
Expand Down Expand Up @@ -179,59 +147,46 @@ void GPIO3_IRQHandler(void)
//******************************************************************************
void GPIOWAKE_IRQHandler(void)
{
/* Clear the interrupt status */
MXC_PWRSEQ->lpwkst4 = pb_pin[gpio4_pb].mask;
NVIC_ClearPendingIRQ(GPIOWAKE_IRQn);

/* Call the saved callback if available */
if (gpio4_callback != NULL) {
gpio4_callback((void *)&pb_pin[gpio4_pb]);
}
MXC_GPIO_Handler(MXC_GPIO_GET_IDX(MXC_GPIO4));
}

//******************************************************************************
void PB_IntEnable(unsigned int pb)
{
MXC_ASSERT(pb < num_pbs);

MXC_GPIO_EnableInt(pb_pin[pb].port, pb_pin[pb].mask);

if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
MXC_PWRSEQ->lpwkst4 = pb_pin[pb].mask;
MXC_PWRSEQ->lpwken4 |= pb_pin[pb].mask;
NVIC_EnableIRQ(GPIOWAKE_IRQn);
} else {
MXC_GPIO_EnableInt(pb_pin[pb].port, pb_pin[pb].mask);
}
}

//******************************************************************************
void PB_IntDisable(unsigned int pb)
{
MXC_ASSERT(pb < num_pbs);

MXC_GPIO_DisableInt(pb_pin[pb].port, pb_pin[pb].mask);

if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
MXC_PWRSEQ->lpwken4 &= ~pb_pin[pb].mask;
NVIC_DisableIRQ(GPIOWAKE_IRQn);
} else {
MXC_GPIO_DisableInt(pb_pin[pb].port, pb_pin[pb].mask);
}
}

//******************************************************************************
void PB_IntClear(unsigned int pb)
{
MXC_ASSERT(pb < num_pbs);
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
MXC_PWRSEQ->lpwkst4 = pb_pin[pb].mask;
} else {
MXC_GPIO_ClearFlags(pb_pin[pb].port, pb_pin[pb].mask);
}

MXC_GPIO_ClearFlags(pb_pin[pb].port, pb_pin[pb].mask);
}

//******************************************************************************
int PB_Get(unsigned int pb)
{
MXC_ASSERT(pb < num_pbs);
if (MXC_GPIO_GET_IDX(pb_pin[pb].port) == 4) {
return !(MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN);
}

return !MXC_GPIO_InGet(pb_pin[pb].port, pb_pin[pb].mask);
}
Loading

0 comments on commit c08bf27

Please sign in to comment.