AnsweredAssumed Answered

How to Use Built in Button in IMX RT 1010

Question asked by Abraham Cohen on Dec 24, 2019
Latest reply on Dec 30, 2019 by Kerry Zhou

Hello Everyone, 

 

I recently bought the IMX RT 1010 dev kit. I am trying to learn how to use this environment using a simple button-led project. Basically, when the button is pressed the LED goes off. 

 

However, I have no idea how to access the button output. 

The question is, I suppose, is:
1) How to access whether the button is pressed down or not. 
2) How to connect #1 to the LED. 

 

Here is the code so far:

 

#include "board.h"
#include "fsl_gpio.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_LED_GPIO BOARD_USER_LED_GPIO
#define EXAMPLE_LED_GPIO_PIN BOARD_USER_LED_GPIO_PIN
#define BUTTON BOARD_USER_BUTTON_GPIO
#define BUTTON_PIN BOARD_USER_BUTTON_GPIO_PIN


/*******************************************************************************
* Prototypes
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/
volatile uint32_t g_systickCounter;
/* The PIN status */
volatile bool g_pinSet = false;

/*******************************************************************************
* Code
******************************************************************************/
void SysTick_Handler(void)
{
if (g_systickCounter != 0U)
{
g_systickCounter--;
}
}

void SysTick_DelayTicks(uint32_t n)
{
g_systickCounter = n;
while (g_systickCounter != 0U)
{
}
}

/*!
* @brief Main function
*/
int main(void)
{
/* Board pin init */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();


//init button
struct _gpio_pin_config *Config = {0};
Config->direction = kGPIO_DigitalOutput;
Config->interruptMode = kGPIO_IntHighLevel;
GPIO_PinInit(BUTTON, BUTTON_PIN, Config);

/* Set systick reload value to generate 1ms interrupt */
if (SysTick_Config(SystemCoreClock / 1000U))
{
while (1)
{
}
}

while (1)
{

//READ BUTTON STATUS
volatile uint32_t button_status = GPIO_PinRead(BUTTON, BUTTON_PIN);
bool button_bool = button_status != 0u;

/* Delay 1000 ms */
SysTick_DelayTicks(1000U);

if(button_bool)
{
GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);
}
}
}

 

Once again, I appreciate everyone's help!

Outcomes