/* * Read from the switch registers * */ int switch_read(uint8_t param1) { uint8_t reg[2]; if (param1 < 128) { reg[0] = 96; } else { reg[0] = 97; } reg[1] = param1 << 1; /* Select the DF memory to check. */ usart_spi_select_device(USART_SPI, &USART_SPI_DEVICE); /* Send the Manufacturer ID Read command. */ usart_spi_write_packet(USART_SPI, reg, 2); /* Receive Manufacturer ID. */ usart_spi_read_packet(USART_SPI, reg, 1); /* Deselect the checked DF memory. */ usart_spi_deselect_device(USART_SPI, &USART_SPI_DEVICE); return reg[0]; }
/** * \internal * \brief Helper function to read a byte from an arbitrary interface * * This function is used to hide what interface is used by the driver, e.g. * the driver does not need to know if USART in SPI mode is used or the native * SPI module. */ __always_inline static uint8_t hx8347a_read_byte(void) { uint8_t data; #if defined(CONF_HX8347A_USART_SPI) # if UC3 /* A workaround for optimizing data transfer had to be done for the * XMEGA in order for the display to work correctly at all SPI clock * clock speeds */ /* This function could also be used for XMEGA but results in a very slow * framerate, hence a workaround has been implemented for the XMEGA */ usart_spi_read_packet(CONF_HX8347A_USART_SPI, &data, 1); # elif XMEGA usart_spi_read_single(CONF_HX8347A_USART_SPI, &data); # endif #elif defined(CONF_HX8347A_SPI) spi_write_single(CONF_HX8347A_SPI, 0xFF); /* Wait for RX to complete */ while (!spi_is_rx_full(CONF_HX8347A_SPI)) { /* Do nothing */ } spi_read_single(CONF_HX8347A_SPI, &data); #endif return data; }
/*! \brief SPI slave tranfers data to Usart SPI master */ static bool spi_slave_transfer(void) { /* Select the Slave device */ usart_spi_select_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE); /* Put the slave read command in master tx buffer */ data_master_tx[0] = SLAVE_RD_CMD; count = 0; /* Send the Read command */ usart_spi_write_packet(USART_SPI_EXAMPLE, data_master_tx, 1); /* Receive data from slave */ usart_spi_read_packet(USART_SPI_EXAMPLE, data_master_rx, DATA_BUFFER_SIZE); /* Deselect the Slave device */ usart_spi_deselect_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE); /* Check the master received data with slave tx data */ for (uint8_t i = 0; i < DATA_BUFFER_SIZE; i++) { if (data_master_rx[i] == data_slave_tx[i]) { continue; } else { return false; } } return true; }
/** * \brief Receive a sequence of bytes from a SerialFlash. * * \param data Data buffer to read * \param len Length of data * \pre The SerialFlash should be selected first using at25dfx_spi_select_device */ status_code_t at25dfx_spi_read_packet(void const *data, size_t len) { #if defined( AT25DFX_USES_SPI_MASTER_SERVICE) return spi_read_packet(AT25DFX_SPI_MODULE, (uint8_t*)data, len); /* Implementation with USART in SPI mode service */ #elif defined(AT25DFX_USES_USART_SPI_SERVICE) return usart_spi_read_packet(AT25DFX_SPI_MODULE, (uint8_t*)data, len); #endif }
static bool usart_spi_at45dbx_mem_check(void) { /* Select the DF memory to check. */ usart_spi_select_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE); /* Send the Manufacturer ID Read command. */ usart_spi_write_packet(USART_SPI_EXAMPLE, data, 1); /* Receive Manufacturer ID. */ usart_spi_read_packet(USART_SPI_EXAMPLE, data, DATA_BUFFER_SIZE); /* Extract the Manufacturer ID. */ manufacturer_id = data[0]; /* Deselect the checked DF memory. */ usart_spi_deselect_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE); /* Check the Manufacturer id. */ if (manufacturer_id == ATMEL_MANUFACTURER_ID) { return true; } else { return false; } }