コード例 #1
0
ファイル: main.c プロジェクト: jrlitzenberger/pocketLab2
////////////////////////////////////////////////////////////////////////////////
// TWI (with transaction manager) initialization.
//
static void twi_config(void)
{
    uint32_t err_code;

    nrf_drv_twi_config_t const config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_LOW
    };

    APP_TWI_INIT(&m_app_twi, &config, MAX_PENDING_TRANSACTIONS, err_code);
    APP_ERROR_CHECK(err_code);
}
コード例 #2
0
ファイル: main.c プロジェクト: t21/HomeHub
/**@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);
}