I am having trouble modifying simple_hal.c from the mesh SDK v4.1 when buttons are on Port1 instead of Port0 on a nRF52840. I have buttons on P1.01 and P1.02.
Everything in simple_hal.c seems to be based on 'NRF_GPIO' which is defined as NRF_P0. I was able to make modifications for the leds that I have on Port1, but have had no luck for the buttons.
I redefined BUTTON_3 and BUTTON_4 in pca10056.h to 33 and 34, but am getting no events.
I tried modifying hal_buttons_init() by replacing the for loop:
uint32_t hal_buttons_init(hal_button_handler_cb_t cb)
{
#if !BUTTON_BOARD
return NRF_ERROR_NOT_SUPPORTED;
#else
if (cb == NULL)
{
return NRF_ERROR_NULL;
}
m_button_handler_cb = cb;
/*for (uint32_t i = 0; i < BUTTONS_NUMBER ; ++i)
{
NRF_GPIO->PIN_CNF[m_buttons_list[i]] = BUTTON_PIN_CONFIG;
}*/
NRF_P0->PIN_CNF[m_buttons_list[0]] = BUTTON_PIN_CONFIG;
NRF_P0->PIN_CNF[m_buttons_list[1]] = BUTTON_PIN_CONFIG;
NRF_P1->PIN_CNF[m_buttons_list[2]-32] = BUTTON_PIN_CONFIG;
NRF_P1->PIN_CNF[m_buttons_list[3]-32] = BUTTON_PIN_CONFIG;
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
NRF_GPIOTE->EVENTS_PORT = 0;
NVIC_SetPriority(GPIOTE_IRQn, GPIOTE_IRQ_LEVEL);
NVIC_EnableIRQ(GPIOTE_IRQn);
return NRF_SUCCESS;
#endif
}
I made similar modifications for the interrupt handler:
void GPIOTE_IRQHandler(void)
{
NRF_GPIOTE->EVENTS_PORT = 0;
for (uint8_t i = 0; i < BUTTONS_NUMBER; ++i)
{
/* Check that the event was generated by a button press, and reject if it's too soon (debounce).
* NOTE: There is a bug with this at the wrap-around for the RTC1 where the button could be
* pressed before HAL_BUTTON_PRESS_FREQUENCY has passed a single time. It doesn't matter practically.
*/
if(m_buttons_list[i] < 32) {
if ((~NRF_P0->IN & (1 << (m_buttons_list[i]))) &&
TIMER_DIFF(m_last_button_press, NRF_RTC1->COUNTER) > HAL_BUTTON_PRESS_FREQUENCY)
{
m_last_button_press = NRF_RTC1->COUNTER;
m_button_handler_cb(i);
}
}
else {
if ((~NRF_P1->IN & (1 << (m_buttons_list[i]-32))) &&
TIMER_DIFF(m_last_button_press, NRF_RTC1->COUNTER) > HAL_BUTTON_PRESS_FREQUENCY)
{
m_last_button_press = NRF_RTC1->COUNTER;
m_button_handler_cb(i);
}
}
}
}
Thanks for the help.