Beispiel #1
0
/**@brief Handler for SPI0 master events.
 *
 * @param[in] event SPI master event.
 */
void spi_master_0_event_handler(nrf_drv_spi_evt_type_t* event)
{
//    uint32_t err_code = NRF_SUCCESS;
//	  uint32_t c_buff;   // Temporarily store the buffer index of the buffer ready to be compressed

    switch (*event)
    {
			  // Transfer complete; store in buffer.
        case NRF_DRV_SPI_EVENT_DONE:
            
            nrf_drv_spi_uninit(&m_spi_master_0);
            if (buffer_in(&db, &m_rx_data_spi[0]) == BUFFER_FULL) {
              if (buffer_compress(db.buffer, db.item_cnt, transmission_buffer) != BUFFER_SUCCESS) {
							//		buffer_reset(&db);  
									printf("Error compressing data!\n");
              }
              intan_convert_channel++;
              intan_convert_channel = intan_convert_channel % 32;
						}

            m_transfer_completed = true;
            break;

        default:
            // No implementation needed.
            break;
    }
}
Beispiel #2
0
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;
}
Beispiel #3
0
void spi_frequency(spi_t *obj, int hz)
{
    spi_info_t *p_spi_info = SPI_INFO(obj);
    nrf_drv_spi_frequency_t new_frequency = freq_translate(hz);

    if (p_spi_info->master)
    {
        if (p_spi_info->frequency != new_frequency) {
            p_spi_info->frequency = new_frequency;

            nrf_drv_spi_config_t config;
            prepare_master_config(&config, p_spi_info);

            nrf_drv_spi_t const *p_spi = MASTER_INST(obj);
            nrf_drv_spi_uninit(p_spi);
            (void)nrf_drv_spi_init(p_spi, &config,
                m_master_event_handlers[SPI_IDX(obj)]);
        }
    }
    // There is no need to set anything in slaves when it comes to frequency,
    // since slaves just synchronize with the clock provided by a master.
}
Beispiel #4
0
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)]);
    }
}
Beispiel #5
0
static void st7735_uninit(void)
{
    nrf_drv_spi_uninit(&spi);
}
Beispiel #6
0
/**@brief Handler for SPI0 company Intan read events.
 *
 * @param[in] event SPI master event.
 */
void spi_intan_id_read_handler(nrf_drv_spi_evt_type_t* event)
{
    uint32_t err_code = NRF_SUCCESS;
	  //uint32_t c_buff;   // Temporarily store the buffer index of the buffer ready to be compressed

    switch (*event)
    {
			  //while(app_uart_put(73) != NRF_SUCCESS);
			  // Transfer complete; store in buffer.
        case NRF_DRV_SPI_EVENT_DONE:
					
            nrf_drv_spi_uninit(&m_spi_master_0);
				
						printf("%c\r\n",m_rx_data_spi[1]);
				    // Transfer done after this point
						m_transfer_completed = true;
				
				    //printf("Data received\r\n");
				    //while(app_uart_put(69) != NRF_SUCCESS);
				    //printf("%d\r\n", ++counter);

            //err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
            //APP_ERROR_CHECK(err_code);*/
				
				    // All buffers are in use; The just acquired data will be lost.
				    /*if(buffers_ready[active_buffer])
						{
							while(app_uart_put(70) != NRF_SUCCESS);
							//while(app_uart_put(70) != NRF_SUCCESS);
							//printf("All buffers in use. Data lost\r\n");
						}
						
						// Still have space to store data.
						else
						{
							// Current buffer still has space
							if(ab_capacity > 0)
							{
								*(data_buffers[active_buffer] + DATA_BUF_SIZE - ab_capacity) = m_rx_data_spi[0];
								
								// Buffer is filled after this storage.  Set the next buffer as active.  Call compression, if compression is not in progress.
								if(--ab_capacity == 0)
								{
									buffers_ready[active_buffer] = true;
									ab_capacity = DATA_BUF_SIZE;
									if(active_buffer == NUM_DATA_BUFFERS - 1)
									{
										active_buffer = 0;
									}
									
									else
									{
										active_buffer++;
									}
									
									// Compress
									//if(!compression_in_progress)
									//{
										//printf("Compressing\r\n");
										//while(app_uart_put(73) != NRF_SUCCESS);
										//compression_in_progress = true;
										//err_code = app_timer_start(comp_timer, 5, &c_buff);
										//while(app_uart_put(74) != NRF_SUCCESS);
										//printf("%d\r\n", err_code);
										//while(1);
										//APP_ERROR_CHECK(err_code);
										//while(app_uart_put(75) != NRF_SUCCESS);
										//compress(c_buff, DATA_BUF_SIZE);
										//printf("Compress is done\r\n");
										//while(app_uart_put(71) != NRF_SUCCESS);
									//}
								}
							}
						}
						
						// If not all channels have been sampled, continue sampling from the other channels.
						if(intan_convert_channel == NUM_CHANNELS)
						{
							intan_convert_channel = 0;
						}
						else
						{
							sample_data();
						}*/
            break;

        default:
            // No implementation needed.
            break;
    }
}
Beispiel #7
0
static void ili9341_uninit(void)
{
    nrf_drv_spi_uninit(&spi);
}