spidevc.h 1.2 KB

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