/** * Function for application main entry. */ int main(void) { init_leds(); init_clock(); uint32_t err_code; // Button configuration structure. static app_button_cfg_t p_button[] = { {BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}, {BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}}; // Macro for initializing the application timer module. // It will handle dimensioning and allocation of the memory buffer required by the timer, making sure that the buffer is correctly aligned. It will also connect the timer module to the scheduler (if specified). APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL); // Macro for initializing the GPIOTE module. // It will handle dimensioning and allocation of the memory buffer required by the module, making sure that the buffer is correctly aligned. APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); // Initializing the buttons. err_code = app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), BUTTON_DEBOUNCE_DELAY); APP_ERROR_CHECK(err_code); // Enabling the buttons. err_code = app_button_enable(); APP_ERROR_CHECK(err_code); while(true) { // Do nothing. } }
void nsec_buttons_init(void) { ret_code_t err_code; /* * The array must be static because a pointer to it will be saved in the * button handler module. */ static app_button_cfg_t buttons[] = { {INPUT_UP, false, NRF_GPIO_PIN_PULLUP, nsec_button_event_handler}, {INPUT_DOWN, false, NRF_GPIO_PIN_PULLUP, nsec_button_event_handler}, {INPUT_BACK, false, NRF_GPIO_PIN_PULLUP, nsec_button_event_handler}, {INPUT_ENTER, false, NRF_GPIO_PIN_PULLUP, nsec_button_event_handler} }; /* * Configure the button library */ err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); /* * Enable the buttons */ err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
void buttons_init(void) { uint32_t err_code; err_code = app_button_init(buttons, BUTTONS_NO, BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_timer_create(&m_button_long_press_timer_id, APP_TIMER_MODE_SINGLE_SHOT, button_long_press_timeout_handler); APP_ERROR_CHECK(err_code); app_button_enable(); }
/**@brief Function for initializing the button handler module. */ static void buttons_init(void) { uint32_t err_code; //The array must be static because a pointer to it will be saved in the button handler module. static app_button_cfg_t buttons[] = { {LEDBUTTON_BUTTON_PIN, false, BUTTON_PULL, button_event_handler} }; err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the button library. */ static void buttons_init(void) { uint32_t err_code; // The array must be static because a pointer to it will be saved in the button library. static app_button_cfg_t buttons[] = { {BOARD_TESTER_BUTTON, false, BUTTON_PULL, button_event_handler}, {BOARD_DUMMY_BUTTON, false, BUTTON_PULL, button_event_handler} }; err_code = app_button_init(buttons, ARRAY_SIZE(buttons), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Button initialization. * * @details Initializes all Buttons used by this application. */ static void buttons_init(void) { uint32_t err_code; static app_button_cfg_t buttons[] = { {BUTTON_ONE, false, BUTTON_PULL, button_event_handler} }; err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Button initialization. * * @details Initializes all Buttons used by this application. */ static void button_init(void) { uint32_t err_code; static app_button_cfg_t buttons[] = { {BSP_BUTTON_0, false, BUTTON_PULL, button_event_handler}, {BSP_BUTTON_1, false, BUTTON_PULL, button_event_handler} }; #define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing buttons. */ void button_init(void) { // Initialize timer module. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, NULL); // Initialize and enable button handler module. static app_button_cfg_t buttons[] = { {BSP_BUTTON_0, false, BUTTON_PULL, button_event_handler}, {BSP_BUTTON_1, false, BUTTON_PULL, button_event_handler}, }; uint32_t err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
/**@brief Function for the Button initialization. * * @details Initializes all Buttons used by this application. */ static void buttons_init(void) { uint32_t err_code; static app_button_cfg_t buttons[] = { {START_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler}, {STOP_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler}, #ifdef COMMISSIONING_ENABLED {ERASE_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler} #endif // COMMISSIONING_ENABLED }; #define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
static void button_init(void) { uint32_t err_code; // Configure HR_INC_BUTTON_PIN_NO and HR_DEC_BUTTON_PIN_NO as wake up buttons and also configure // for 'pull up' because the eval board does not have external pull up resistors connected to // the buttons. static app_button_cfg_t buttons[] = { {BSP_BUTTON_0, false, BUTTON_PULL, button_event_handler}, {BSP_BUTTON_1, false, BUTTON_PULL, button_event_handler}, {BSP_BUTTON_2, false, BUTTON_PULL, button_event_handler} }; #define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
uint32_t bsp_init(uint32_t type, uint32_t ticks_per_100ms, bsp_event_callback_t callback) { uint32_t err_code = NRF_SUCCESS; #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) m_app_ticks_per_100ms = ticks_per_100ms; m_indication_type = type; #else UNUSED_VARIABLE(ticks_per_100ms); #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) #if (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) m_registered_callback = callback; // BSP will support buttons and generate events if (type & BSP_INIT_BUTTONS) { uint32_t num; for (num = 0; ((num < BUTTONS_NUMBER) && (err_code == NRF_SUCCESS)); num++) { err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_DEFAULT); } if (err_code == NRF_SUCCESS) { err_code = app_button_init((app_button_cfg_t *)app_buttons, BUTTONS_NUMBER, ticks_per_100ms / 2); } if (err_code == NRF_SUCCESS) { err_code = app_button_enable(); } if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_button_timer_id, APP_TIMER_MODE_SINGLE_SHOT, button_timer_handler); } } #elif (BUTTONS_NUMBER > 0) && (defined BSP_SIMPLE) if (type & BSP_INIT_BUTTONS) { uint32_t cnt; uint32_t buttons[] = BUTTONS_LIST; for (cnt = 0; cnt < BUTTONS_NUMBER; cnt++) { nrf_gpio_cfg_input(buttons[cnt], BUTTON_PULL); } } #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) if (type & BSP_INIT_LED) { LEDS_OFF(LEDS_MASK); NRF_GPIO->DIRSET = LEDS_MASK; } // timers module must be already initialized! if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_leds_timer_id, APP_TIMER_MODE_SINGLE_SHOT, leds_timer_handler); } if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_alert_timer_id, APP_TIMER_MODE_REPEATED, alert_timer_handler); } #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) return err_code; }
/**@brief Function for initializing the TWI interface (with transaction manager). */ static void twi_init(void) { uint32_t err_code; nrf_drv_twi_config_t const config = { .scl = 15, .sda = 13, .frequency = NRF_TWI_FREQ_100K, .interrupt_priority = APP_IRQ_PRIORITY_LOW }; // APP_TWI_INIT(&m_app_twi, NULL, TWI_MAX_PENDING_TRANSACTIONS, err_code); APP_TWI_INIT(&m_app_twi, &config, TWI_MAX_PENDING_TRANSACTIONS, err_code); APP_ERROR_CHECK(err_code); } /**@brief Function for handling a button event. * * @param[in] pin_no Pin that had an event happen. * @param[in] button_event APP_BUTTON_PUSH or APP_BUTTON_RELEASE. */ static void button_event_handler(uint8_t pin_no, uint8_t button_event) { // uint32_t err_code; // if ((button_event == APP_BUTTON_PUSH) && (pin_no == BUTTON_1)) // { // switch (m_button_state) // { // case BUTTON_STATE_NONE: // // Starta timer 10s // err_code = app_timer_start(m_button_single_shot_timer_id, BUTTON_LONG_PRESS, NULL); // APP_ERROR_CHECK(err_code); // m_button_state = BUTTON_STATE_FIRST_PRESS; // break; // case BUTTON_STATE_FIRST_PRESS: // // Do nothing, should not happen // break; // case BUTTON_STATE_SECOND_PRESS: // // Set erase state, actual erase will take place on button release // m_button_state = BUTTON_STATE_ERASE; // break; // case BUTTON_STATE_ERASE: // // Do nothing, erase and reset will be done on button release // break; // } // } // else if ((button_event == APP_BUTTON_RELEASE) && (pin_no == BUTTON_1)) // { // switch (m_button_state) // { // case BUTTON_STATE_NONE: // // Do nothing, should not happen <- you never know // break; // case BUTTON_STATE_FIRST_PRESS: // // Stop timer // err_code = app_timer_stop(m_button_single_shot_timer_id); // APP_ERROR_CHECK(err_code); // m_button_state = BUTTON_STATE_NONE; // break; // case BUTTON_STATE_SECOND_PRESS: // // Do nothing // break; // case BUTTON_STATE_ERASE: // // Stop blink timer // err_code = app_timer_stop(m_blink_timer_id); // APP_ERROR_CHECK(err_code); // nrf_gpio_pin_clear(LED_1); // // Erase all and restart // w_conf_storage_erase_all(); // // TODO: Erase bonding data as well // m_flash_mode = FLASH_ERASE_ALL; // break; // } // } } /**@brief Function for initializing buttons and leds. * * @param[out] p_erase_bonds Will be true if the clear bonding button was pressed to wake the application up. */ static void buttons_leds_init(void) { uint32_t err_code; // bsp_event_t startup_event; // uint32_t err_code = bsp_init(BSP_INIT_BUTTONS, // APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), // bsp_event_handler); //// uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, //// APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), //// bsp_event_handler); // APP_ERROR_CHECK(err_code); // err_code = bsp_btn_ble_init(NULL, &startup_event); // APP_ERROR_CHECK(err_code); // *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA); // err_code = bsp_button_is_pressed(0, p_erase_bonds); // APP_ERROR_CHECK(err_code); static const app_button_cfg_t app_buttons[] = { {BUTTON1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_event_handler}, }; err_code = app_button_init((app_button_cfg_t *)app_buttons, sizeof(&app_buttons) / sizeof(&app_buttons[0]), APP_TIMER_TICKS(BUTTON_DEBOUNCE_MS, APP_TIMER_PRESCALER)); APP_ERROR_CHECK(err_code); err_code = app_button_enable(); APP_ERROR_CHECK(err_code); }
uint32_t bsp_init(uint32_t type, bsp_event_callback_t callback) { uint32_t err_code = NRF_SUCCESS; #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) m_indication_type = type; #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) #if (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) m_registered_callback = callback; // BSP will support buttons and generate events if (type & BSP_INIT_BUTTONS) { uint32_t num; for (num = 0; ((num < BUTTONS_NUMBER) && (err_code == NRF_SUCCESS)); num++) { err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_DEFAULT); } if (err_code == NRF_SUCCESS) { err_code = app_button_init((app_button_cfg_t *)app_buttons, BUTTONS_NUMBER, APP_TIMER_TICKS(50)); } if (err_code == NRF_SUCCESS) { err_code = app_button_enable(); } if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_bsp_button_tmr, APP_TIMER_MODE_SINGLE_SHOT, button_timer_handler); } } #elif (BUTTONS_NUMBER > 0) && (defined BSP_SIMPLE) bsp_board_init(type); #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) if (type & BSP_INIT_LEDS) { //handle LEDs only. Buttons are already handled. bsp_board_init(BSP_INIT_LEDS); // timers module must be already initialized! if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_bsp_leds_tmr, APP_TIMER_MODE_SINGLE_SHOT, leds_timer_handler); } if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_bsp_alert_tmr, APP_TIMER_MODE_REPEATED, alert_timer_handler); } } #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) return err_code; }
uint32_t bsp_init(uint32_t type, uint32_t ticks_per_100ms, bsp_event_callback_t callback) { uint32_t err_code = NRF_SUCCESS; #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) m_app_ticks_per_100ms = ticks_per_100ms; m_indication_type = type; #else UNUSED_VARIABLE(ticks_per_100ms); #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) #if (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) m_registered_callback = callback; NRF_LOG_INFO("START BUTTON INIT\r\n"); // BSP will support buttons and generate events if (type & BSP_INIT_BUTTONS) { uint32_t num; for (num = 0; ((num < BUTTONS_NUMBER) && (err_code == NRF_SUCCESS)); num++) { NRF_LOG_INFO("ASSIGN %d\r\n", num); err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_DEFAULT); } if (err_code == NRF_SUCCESS) { NRF_LOG_INFO("INIT \r\n"); err_code = app_button_init((app_button_cfg_t *)app_buttons, BUTTONS_NUMBER, ticks_per_100ms / 2); } if (err_code == NRF_SUCCESS) { NRF_LOG_INFO("Enable \r\n"); err_code = app_button_enable(); } if (err_code == NRF_SUCCESS) { NRF_LOG_INFO("Create \r\n"); err_code = app_timer_create(&m_button_timer_id, APP_TIMER_MODE_SINGLE_SHOT, button_timer_handler); } } #elif (BUTTONS_NUMBER > 0) && (defined BSP_SIMPLE) if (type & BSP_INIT_BUTTONS) { bsp_board_buttons_init(); } #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) if (type & BSP_INIT_LED) { bsp_board_leds_init(); } // timers module must be already initialized! if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_leds_timer_id, APP_TIMER_MODE_SINGLE_SHOT, leds_timer_handler); } if (err_code == NRF_SUCCESS) { err_code = app_timer_create(&m_alert_timer_id, APP_TIMER_MODE_REPEATED, alert_timer_handler); } #endif // LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) return err_code; }