Set up SPI. Open the file, and define the configuration.
| 49 | |
| 50 | // Set up SPI. Open the file, and define the configuration. |
| 51 | int spi_setup(){ |
| 52 | spi_file_handle = open(SPIDEV_FILE_NAME, O_RDWR); |
| 53 | |
| 54 | if (spi_file_handle < 0){ |
| 55 | return ERROR_SPI_FILE; |
| 56 | } |
| 57 | |
| 58 | spi_xfer_struct.cs_change = 0; // Keep CS activated |
| 59 | spi_xfer_struct.delay_usecs = 0; // delay in us |
| 60 | spi_xfer_struct.speed_hz = SPI_TARGET_SPEED; // speed |
| 61 | spi_xfer_struct.bits_per_word = 8; // bites per word 8 |
| 62 | |
| 63 | return ERROR_NONE; |
| 64 | } |
| 65 | |
| 66 | // Transfer length number of bytes. Write from outArray, read to inArray. |
| 67 | int spi_transfer_array(uint8_t length, uint8_t *outArray, uint8_t *inArray){ |