YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
sd_spi_drv.h
1
2#ifndef _SD_SPI_DRV_H_
3#define _SD_SPI_DRV_H_
4
5#include "block_io_interface.h"
6#include "spi_interface.h"
7
9{
10public:
12
13 blockio_status_t initialize() override;
14 blockio_status_t status() override;
15
16 BLOCKIO::result_t readBlock (uint8_t* buff, uint32_t block, uint16_t count) override;
17 BLOCKIO::result_t writeBlock(const uint8_t* buff, uint32_t block, uint16_t count) override;
18
19 uint32_t getBlockCount() override;
20
21 // We do not use buffers, so there is nothing to sync...
22 BLOCKIO::result_t sync() override { return BLOCKIO::OK; }
23
24private:
25
26 spi_interface & _spi;
27 bool _initialized;
28 bool _isV200;
29 bool _isSDHC;
30 uint32_t _blockCount;
31
32 uint16_t _sd_status;
33 uint8_t _cid[16];
34 uint8_t _csd[16];
35
36 int sd_init();
37 int sd_read_status();
38 int sd_read_cid();
39 int sd_read_csd();
40
41 // Send Command command to SD card with argument
42 void sd_cmd(uint8_t cmd, uint32_t arg);
43 uint8_t sd_get_r1();
44 uint16_t sd_get_r2();
45 uint8_t sd_get_r37(uint32_t *r7);
46 int sd_get_data(uint8_t *buf, int len);
47 int sd_put_data(const uint8_t *buf, int len);
48
49 void sd_nec();
50
51 // Transmit a single byte and return the received byte
52 uint8_t spi_txrx(uint8_t data);
53
54 uint8_t crc7_one(uint8_t t, uint8_t data);
55 uint16_t crc16(const uint8_t *p, int len);
56 uint16_t crc16_ccitt(uint16_t crc, uint8_t ser_data);
57
58 int sd_readsector (uint32_t address, uint8_t *buf);
59 int sd_writesector(uint32_t address, const uint8_t *buf);
60};
61
62#endif // _SD_SPI_DRV_H_