spi.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * spi.h
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut
  5. * All rights reserved.
  6. *
  7. * LGPL v3+, see LICENSE.lgpl3
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. #pragma once
  24. #include <stdbool.h>
  25. struct spi_xfer_chunk {
  26. uint8_t *data;
  27. unsigned len;
  28. bool write;
  29. bool read;
  30. };
  31. #define SPI_CS_FLASH 0
  32. #define SPI_CS_SRAM 1
  33. void spi_init(void);
  34. void spi_xfer(unsigned cs, struct spi_xfer_chunk *xfer, unsigned n);
  35. void flash_cmd(uint8_t cmd);
  36. void flash_deep_power_down(void);
  37. void flash_wake_up(void);
  38. void flash_write_enable(void);
  39. void flash_write_disable(void);
  40. void flash_manuf_id(void *manuf);
  41. void flash_unique_id(void *id);
  42. uint8_t flash_read_sr(void);
  43. void flash_write_sr(uint8_t sr);
  44. void flash_read(void *dst, uint32_t addr, unsigned len);
  45. void flash_page_program(void *src, uint32_t addr, unsigned len);
  46. void flash_sector_erase(uint32_t addr);