void spi_free(spi_t *obj) { spi_info_t *p_spi_info = SPI_INFO(obj); if (p_spi_info->master) { nrf_drv_spi_uninit(MASTER_INST(obj)); } else { nrf_drv_spis_uninit(SLAVE_INST(obj)); } p_spi_info->initialized = false; }
void spi_format(spi_t *obj, int bits, int mode, int slave) { if (bits != 8) { error("Only 8-bits SPI is supported\r\n"); } if (mode > 3) { error("SPI format error\r\n"); } spi_info_t *p_spi_info = SPI_INFO(obj); if (slave) { nrf_drv_spis_mode_t spi_modes[4] = { NRF_DRV_SPIS_MODE_0, NRF_DRV_SPIS_MODE_1, NRF_DRV_SPIS_MODE_2, NRF_DRV_SPIS_MODE_3, }; nrf_drv_spis_mode_t new_mode = spi_modes[mode]; // If the peripheral is currently working as a master, the SDK driver // it uses needs to be switched from SPI to SPIS. if (p_spi_info->master) { nrf_drv_spi_uninit(MASTER_INST(obj)); } // I the SPI mode has to be changed, the SDK's SPIS driver needs to be // re-initialized (there is no other way to change its configuration). else if (p_spi_info->spi_mode != (uint8_t)new_mode) { nrf_drv_spis_uninit(SLAVE_INST(obj)); } else { return; } p_spi_info->spi_mode = (uint8_t)new_mode; p_spi_info->master = false; p_spi_info->flag.readable = false; // Initialize SDK's SPIS driver with the new configuration. nrf_drv_spis_config_t config; prepare_slave_config(&config, p_spi_info); (void)nrf_drv_spis_init(SLAVE_INST(obj), &config, m_slave_event_handlers[SPI_IDX(obj)]); // Prepare the slave for transfer. p_spi_info->tx_buf = NRF_DRV_SPIS_DEFAULT_ORC; nrf_drv_spis_buffers_set(SLAVE_INST(obj), (uint8_t const *)&p_spi_info->tx_buf, 1, (uint8_t *)&p_spi_info->rx_buf, 1); } else // master { nrf_drv_spi_mode_t spi_modes[4] = { NRF_DRV_SPI_MODE_0, NRF_DRV_SPI_MODE_1, NRF_DRV_SPI_MODE_2, NRF_DRV_SPI_MODE_3, }; nrf_drv_spi_mode_t new_mode = spi_modes[mode]; // If the peripheral is currently working as a slave, the SDK driver // it uses needs to be switched from SPIS to SPI. if (!p_spi_info->master) { nrf_drv_spis_uninit(SLAVE_INST(obj)); } // I the SPI mode has to be changed, the SDK's SPI driver needs to be // re-initialized (there is no other way to change its configuration). else if (p_spi_info->spi_mode != (uint8_t)new_mode) { nrf_drv_spi_uninit(MASTER_INST(obj)); } else { return; } p_spi_info->spi_mode = (uint8_t)new_mode; p_spi_info->master = true; p_spi_info->flag.busy = false; // Initialize SDK's SPI driver with the new configuration. nrf_drv_spi_config_t config; prepare_master_config(&config, p_spi_info); (void)nrf_drv_spi_init(MASTER_INST(obj), &config, m_master_event_handlers[SPI_IDX(obj)]); } }
/* ser_phy API function */ void ser_phy_close(void) { nrf_drv_spis_uninit(&m_spis); m_ser_phy_callback = NULL; m_trans_state = SPI_RAW_STATE_UNKNOWN; }