Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Button sequence control

Hi,

Recently, I was trying to move my project from STM to Nordic IC.

I just wonder how to implement the below codes into the nRF52832 or how to program it in Nordic environment.

The current SDK I use is 15.2. Whether there is any inc and src files I need to add for the application.

The program purpose is doing the feature like one-click, double-click, press and hold function.

tClockTime presTimeCurr = 0, relsTimeCurr = 0, presTimePrev = 0, relsTimePrev = 0;
BOOL handleButtonEvent = FALSE;

tClockTime Clock_Time(void)
{
return sys_tick_count;
}

void Button_IrqHandler(void)
{
  if(SdkEvalPushButtonGetITPendingBit(USER_BUTTON) == SET) 
  {
    if (SdkEvalPushButtonGetState(USER_BUTTON) == RESET) {
      presTimePrev = presTimeCurr;
      presTimeCurr = Clock_Time();
    } else {
      relsTimePrev = relsTimeCurr;
      relsTimeCurr = Clock_Time();
      handleButtonEvent = TRUE;
    }
    SdkEvalPushButtonClearITPendingBit(USER_BUTTON);
  }
}


void DeviceInputData(void)
{
  uint8_t char_read;
  if (handleButtonEvent && (Clock_Time() - relsTimeCurr > 500)) {
    if (relsTimePrev == 0 || relsTimeCurr - relsTimePrev > 500) {
      if (relsTimeCurr - presTimeCurr > 1500) {
        char_read = 'A';
      } else {
        char_read = 'a';
      }
    } else {
      char_read = 'b';
    }
    handleButtonEvent = FALSE;
  }
}

Question 1 Whether there is suitable solution for my requirement?

Question 2 Should I use app_button instead of bsp_button?

Question 3 I supposed I need timer to count the tick, which source I should use?

Question 4 Is there any easy way I could shift my STM32 program to Nordic, though I know the SDK is quite different.

I apologize for asking multiple question, since I am still not familiar with Nordic.

I hope I could move my project from STM to Nordic in a smooth way.

Parents Reply Children
No Data
Related