void i2c_reset(i2c_t *obj) { twi_info_t *twi_info = TWI_INFO(obj); NRF_TWI_Type *twi = m_twi_instances[TWI_IDX(obj)]; nrf_twi_disable(twi); nrf_twi_pins_set(twi, twi_info->pselscl, twi_info->pselsda); nrf_twi_frequency_set(twi, twi_info->frequency); nrf_twi_enable(twi); }
ret_code_t nrf_drv_twi_init(nrf_drv_twi_t const * const p_instance, nrf_drv_twi_config_t const * p_config, nrf_drv_twi_evt_handler_t event_handler) { if (m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED) { return NRF_ERROR_INVALID_STATE; } if (p_config == NULL) { p_config = &m_default_config[p_instance->instance_id]; } m_handlers[p_instance->instance_id] = event_handler; m_instances[p_instance->instance_id] = (nrf_drv_twi_t *)p_instance; twi_clear_bus(p_instance, p_config); /* To secure correct signal levels on the pins used by the TWI master when the system is in OFF mode, and when the TWI master is disabled, these pins must be configured in the GPIO peripheral. */ NRF_GPIO->PIN_CNF[p_config->scl] = SCL_PIN_CONF; NRF_GPIO->PIN_CNF[p_config->sda] = SDA_PIN_CONF; nrf_twi_frequency_set(p_instance->p_reg, p_config->frequency); nrf_twi_pins_set(p_instance->p_reg, p_config->scl, p_config->sda); if (m_handlers[p_instance->instance_id]) { nrf_drv_common_irq_enable(p_instance->irq, p_config->interrupt_priority); } m_cb[p_instance->instance_id].state = NRF_DRV_STATE_INITIALIZED; return NRF_SUCCESS; }