43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
#ifndef SDSPI_H
|
|
#define SDSPI_H
|
|
|
|
#include "esp_err.h"
|
|
#include "driver/spi_master.h"
|
|
#include "driver/sdspi_host.h"
|
|
#include "sdmmc_cmd.h"
|
|
#include <cstring>
|
|
#include <string>
|
|
#define SD_SPI_HOST SPI2_HOST
|
|
#define SD_MOUNT_POINT "/sdCard"
|
|
|
|
// 匹配原理图SPI引脚
|
|
#define SD_SCK_PIN GPIO_NUM_10
|
|
#define SD_MOSI_PIN GPIO_NUM_9
|
|
#define SD_MISO_PIN GPIO_NUM_7
|
|
#define SD_CS_PIN GPIO_NUM_11
|
|
|
|
class SdSpiCard
|
|
{
|
|
public:
|
|
SdSpiCard();
|
|
~SdSpiCard();
|
|
|
|
// 初始化SPI总线+挂载SD卡
|
|
esp_err_t init();
|
|
// 卸载SD卡、释放SPI
|
|
esp_err_t deinit();
|
|
bool is_mounted();
|
|
|
|
// 文件读写接口
|
|
esp_err_t write_file(const std::string& path, const uint8_t* data, size_t len);
|
|
esp_err_t read_file(const std::string& path, uint8_t* buf, size_t buf_max, size_t& read_len);
|
|
esp_err_t del_file(const std::string& path);
|
|
esp_err_t copy_file_to_sd(const std::string& src_local_path, const std::string& dst_sd_path);
|
|
private:
|
|
spi_device_handle_t _spi_hdl;
|
|
sdmmc_card_t* _card;
|
|
bool _mounted;
|
|
};
|
|
|
|
#endif
|