rp2040_sdio.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SD card access using SDIO for RP2040 platform.
  2. // This module contains the low-level SDIO bus implementation using
  3. // the PIO peripheral. The high-level commands are in sd_card_sdio.cpp.
  4. #pragma once
  5. #include <stdint.h>
  6. enum sdio_status_t {
  7. SDIO_OK = 0,
  8. SDIO_BUSY = 1,
  9. SDIO_ERR_RESPONSE_TIMEOUT = 2, // Timed out waiting for response from card
  10. SDIO_ERR_RESPONSE_CRC = 3, // Response CRC is wrong
  11. SDIO_ERR_RESPONSE_CODE = 4, // Response command code does not match what was sent
  12. SDIO_ERR_DATA_TIMEOUT = 5, // Timed out waiting for data block
  13. SDIO_ERR_DATA_CRC = 6, // CRC for data packet is wrong
  14. };
  15. // Execute a command that has 48-bit reply (response types R1, R6, R7)
  16. // If response is NULL, does not wait for reply.
  17. sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *response);
  18. // Execute a command that has 136-bit reply (response type R2)
  19. // Response buffer should have space for 16 bytes (the 128 bit payload)
  20. sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t *response);
  21. // Execute a command that has 48-bit reply but without CRC (response R3)
  22. sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *response);
  23. // Start transferring data from SD card to memory buffer
  24. // Transfer block size is always 512 bytes.
  25. sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks);
  26. // Check if reception is complete
  27. // Returns SDIO_BUSY while transferring, SDIO_OK when done and error on failure.
  28. sdio_status_t rp2040_sdio_rx_poll(uint32_t *bytes_complete = nullptr);
  29. // Start transferring data from memory to SD card
  30. sdio_status_t rp2040_sdio_tx_start(const uint8_t *buffer, uint32_t num_blocks);
  31. // Check if transmission is complete
  32. sdio_status_t rp2040_sdio_tx_poll(uint32_t *bytes_complete = nullptr);
  33. // Force everything to idle state
  34. sdio_status_t rp2040_sdio_stop();
  35. // (Re)initialize the SDIO interface
  36. void rp2040_sdio_init();