Esempio n. 1
0
int spi_transfer(uint8_t *bytes, size_t size)
{
	int pos;
	int sz = FTDI_READ_FIFO_SIZE / 8 / BYTES_PER_BIT;

	digitalWrite(PIN_FCSN, LOW);
	for (pos = 0; pos < size; pos += sz) {
		int cksize = ((size - pos) < sz) ? (size - pos) : sz;

		if (spi_buf_w(bytes + pos, cksize) != cksize) {
			fprintf(stderr, "error writing spi\n");
			digitalWrite(PIN_FCSN, HIGH);
			return pos;
		}

		if (spi_buf_r(bytes + pos, cksize) != cksize) {
			fprintf(stderr, "error reading spi\n");
			digitalWrite(PIN_FCSN, HIGH);
			return pos;
		}
	}

	digitalWrite(PIN_FCSN, HIGH);
	return size;
}
Esempio n. 2
0
int spi_send_packet(uint8_t *bytes, size_t size) {
	int pos;
	int sz = FTDI_READ_FIFO_SIZE / 8 / BYTES_PER_BIT;

	for (pos = 0; pos < size; pos += sz) {
		int cksize = ((size - pos) < sz) ? (size - pos) : sz;

		if (spi_buf_w(bytes + pos, cksize) != cksize) {
			warning("error writing spi\n");
			return pos;
		}

		if (spi_buf_r(bytes + pos, cksize) != cksize) {
			warning("error reading spi\n");
			return pos;
		}
	}

	return size;
}