spidevc.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * spidevc.h - SPI library for raspberry pi/bitfury chip/board
  3. *
  4. * Copyright (c) 2013 bitfury
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see http://www.gnu.org/licenses/.
  17. */
  18. #ifndef SPIDEVC_H
  19. #define SPIDEVC_H
  20. /* Initialize SPI using this function */
  21. void spi_init(void);
  22. /* TX-RX single frame */
  23. int spi_txrx(const char *wrbuf, char *rdbuf, int bufsz);
  24. /* SPI BUFFER OPS */
  25. void spi_clear_buf(void);
  26. unsigned char *spi_getrxbuf(void);
  27. unsigned char *spi_gettxbuf(void);
  28. unsigned spi_getbufsz(void);
  29. void spi_emit_buf_reverse(const char *str, unsigned sz); /* INTERNAL USE: EMIT REVERSED BYTE SEQUENCE DIRECTLY TO STREAM */
  30. void spi_emit_buf(const char *str, unsigned sz); /* INTERNAL USE: EMIT BYTE SEQUENCE DIRECTLY TO STREAM */
  31. void spi_emit_break(void); /* BREAK CONNECTIONS AFTER RESET */
  32. void spi_emit_fsync(void); /* FEED-THROUGH TO NEXT CHIP SYNCHRONOUSLY (WITH FLIP-FLOP) */
  33. void spi_emit_fasync(int n); /* FEED-THROUGH TO NEXT CHIP ASYNCHRONOUSLY (WITHOUT FLIP-FLOP INTERMEDIATE) */
  34. void spi_emit_nop(int n);
  35. /* TRANSMIT PROGRAMMING SEQUENCE (AND ALSO READ-BACK) */
  36. /* addr is the destination address in bits (16-bit - 0 to 0xFFFF valid ones)
  37. buf is buffer to be transmitted, it will go at position spi_getbufsz()+3
  38. len is length in _bytes_, should be 4 to 128 and be multiple of 4, as smallest
  39. transmission quantum is 32 bits */
  40. void spi_emit_data(unsigned addr, const char *buf, unsigned len);
  41. #endif