This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OnBoardKeyCallback Function cc2541

Hi,

I have gone through the code numerous times and figured out how key press changes are being send to application level. I successfully added switch to P0.6 which when pressed toggles the LED. It works fine. But I dont understand how this OnBoard_KeyCallback function works.

A detailed look at this function tell me that it sends message using OnBoard_SendKeys to application level. How do they decide the shift parameter in OnBoard_SendKeys function. They used ternary operator but the last part of the that ternary operator itself is a ternary operator. ((keys & HAL_KEY_SW_6) ? true : false) and why shift parameter depends on SW6?

Then If the message sending is not successful then do nothing. and then last part again they call HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback) which is calling the OnBoard_KeyCallback again inside that function only?

  • Hi Spandan,

    What example project are you referring to? Which version of the BLE SDK are you using?
  • Hi,

    BLE SDK 1.4 and SimpleBLEPeripheral is the example i'm referring to. I believe this file is mostly same for Keyfob app too. 

  • Hi Spandan,

    In hal_key.h, you will see HAL_KEY_SW_6 is mapped to Button S1 of the SmartRF05 board. That is why the shift parameter uses HAL_KEY_SW_6. I agree that the nested ternary operator is a bit hard to read. The summary is that if the key interrupt is disabled and HAL_KEY_SW_6 is pressed, the shift parameter will be set. If key interrupts are enabled, shift will be false.

    After determining shift value, OnBoard_SendKeys is called which turns the key press into a message that gets sent to the application task and gets processed in simpleBLEPeripheral_ProcessOSALMsg. This calls simpleBLEPeripheral_HandleKeys which is where the application determines what to do when a certain key is pressed.

    Hopefully, this clears up some of the confusion!
  • Hi,

    I understand that SW6 is for SmartRF05 Board, but how does that work for Keyfob device? This function is same for all programs and devices. When thinking in terms of CC2541MINI-DK, SW6 doesnt exist and so how do you make sense of shift parameter? To my understanding, We want to send message to Application whenever the key gets pressed, so we can poll the keys and simply send message from there. why we need to do this complicated things? Another thing is ternary operator, I get the gist of that but still its hard to make sense out of it.
    Lastly, Assuming that we somehow understand above things, how do we understand
    HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback);
    During the KeyPoll(), we set the "keys" variable and pass it to KeyCallback function, at this point we simply need to disable the interrupt. Why do we need to call recursion function.

    To me it looks like OnBoard_KeyCallback function could use some relaxation. Would like to see your views on this.
  • You do not need to use the key driver if you do not want to. It, and all the other hal drivers, are only provided as reference examples. You are free to simply configure an interrupt with corresponding ISR and process as desired. Of course, it is recommended to minimize processing in the ISR so you would probably be best served by just using the ISR to post an event to the application for later processing.
  • This shift thing is just a functionality demo for CC254xDK which uses SmartRF05. If you don't need it, you can skip and drop it.