spidevc.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef SPIDEVC_H
  2. #define SPIDEVC_H
  3. #include <stdbool.h>
  4. #include <unistd.h>
  5. /* Initialize SPI using this function */
  6. bool spi_init(void);
  7. /* TX-RX single frame */
  8. int spi_txrx(const void *wrbuf, void *rdbuf, size_t bufsz);
  9. /* SPI BUFFER OPS */
  10. void spi_clear_buf(void);
  11. unsigned char *spi_getrxbuf(void);
  12. unsigned char *spi_gettxbuf(void);
  13. unsigned spi_getbufsz(void);
  14. void spi_emit_buf_reverse(const char *str, unsigned sz); /* INTERNAL USE: EMIT REVERSED BYTE SEQUENCE DIRECTLY TO STREAM */
  15. void spi_emit_buf(void *str, unsigned sz); /* INTERNAL USE: EMIT BYTE SEQUENCE DIRECTLY TO STREAM */
  16. void spi_emit_break(void); /* BREAK CONNECTIONS AFTER RESET */
  17. void spi_emit_fsync(void); /* FEED-THROUGH TO NEXT CHIP SYNCHRONOUSLY (WITH FLIP-FLOP) */
  18. void spi_emit_fasync(int n); /* FEED-THROUGH TO NEXT CHIP ASYNCHRONOUSLY (WITHOUT FLIP-FLOP INTERMEDIATE) */
  19. void spi_emit_nop(int n);
  20. /* TRANSMIT PROGRAMMING SEQUENCE (AND ALSO READ-BACK) */
  21. /* addr is the destination address in bits (16-bit - 0 to 0xFFFF valid ones)
  22. buf is buffer to be transmitted, it will go at position spi_getbufsz()+3
  23. len is length in _bytes_, should be 4 to 128 and be multiple of 4, as smallest
  24. transmission quantum is 32 bits */
  25. void spi_emit_data(unsigned addr, const char *buf, unsigned len);
  26. #endif