/* Send a sequence of bytes to an SPI device. 
Received bytes on the SPI bus are discarded. */
status_code_t spi_write_packet(Spi *p_spi, const uint8_t *data, size_t len)
/* Send a sequence of bytes to an SPI device. 
Received bytes on the SPI bus are discarded. */
status_code_t spi_write_packet(Spi *p_spi, const uint8_t *data, size_t len)
{
	uint32_t timeout = SPI_TIMEOUT;
	uint32_t i = 0;
	uint8_t val;
	while (len) {
		timeout = SPI_TIMEOUT;
		while (!spi_is_tx_ready(p_spi)) {
			if (!timeout--) {
				return ERR_TIMEOUT;
			}
		}
		val = data[i];
		spi_write_single(p_spi, val);
		i++;
		len--;
	}
	return STATUS_OK;
}