sdmmc_cmd.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stdio.h>
  16. #include "esp_err.h"
  17. #include "driver/sdmmc_types.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * Probe and initialize SD/MMC card using given host
  23. *
  24. * @note Only SD cards (SDSC and SDHC/SDXC) are supported now.
  25. * Support for MMC/eMMC cards will be added later.
  26. *
  27. * @param host pointer to structure defining host controller
  28. * @param out_card pointer to structure which will receive information about the card when the function completes
  29. * @return
  30. * - ESP_OK on success
  31. * - One of the error codes from SDMMC host controller
  32. */
  33. esp_err_t sdmmc_card_init(const sdmmc_host_t* host,
  34. sdmmc_card_t* out_card);
  35. /**
  36. * @brief Print information about the card to a stream
  37. * @param stream stream obtained using fopen or fdopen
  38. * @param card card information structure initialized using sdmmc_card_init
  39. */
  40. void sdmmc_card_print_info(FILE* stream, const sdmmc_card_t* card);
  41. /**
  42. * Write given number of sectors to SD/MMC card
  43. *
  44. * @param card pointer to card information structure previously initialized using sdmmc_card_init
  45. * @param src pointer to data buffer to read data from; data size must be equal to sector_count * card->csd.sector_size
  46. * @param start_sector sector where to start writing
  47. * @param sector_count number of sectors to write
  48. * @return
  49. * - ESP_OK on success
  50. * - One of the error codes from SDMMC host controller
  51. */
  52. esp_err_t sdmmc_write_sectors(sdmmc_card_t* card, const void* src,
  53. size_t start_sector, size_t sector_count);
  54. /**
  55. * Write given number of sectors to SD/MMC card
  56. *
  57. * @param card pointer to card information structure previously initialized using sdmmc_card_init
  58. * @param dst pointer to data buffer to write into; buffer size must be at least sector_count * card->csd.sector_size
  59. * @param start_sector sector where to start reading
  60. * @param sector_count number of sectors to read
  61. * @return
  62. * - ESP_OK on success
  63. * - One of the error codes from SDMMC host controller
  64. */
  65. esp_err_t sdmmc_read_sectors(sdmmc_card_t* card, void* dst,
  66. size_t start_sector, size_t sector_count);
  67. #ifdef __cplusplus
  68. }
  69. #endif