| } | } | ||||
| /** Opens the next file or folder in a directory. | /** Opens the next file or folder in a directory. | ||||
| * | * | ||||
| * \param[in] mode open mode flags. | |||||
| * \param[in] oflag open oflag flags. | |||||
| * \return a File object. | * \return a File object. | ||||
| */ | */ | ||||
| File openNextFile(uint8_t mode = O_RDONLY) { | |||||
| File openNextFile(oflag_t oflag = O_RDONLY) { | |||||
| File tmpFile; | File tmpFile; | ||||
| tmpFile.openNext(this, mode); | |||||
| tmpFile.openNext(this, oflag); | |||||
| return tmpFile; | return tmpFile; | ||||
| } | } | ||||
| /** Read the next byte from a file. | /** Read the next byte from a file. |
| DBG_FAIL_MACRO; | DBG_FAIL_MACRO; | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| if (!open(dirFile, path, O_CREAT | O_EXCL | O_RDWR)) { | |||||
| if (!open(dirFile, path, O_RDWR | O_CREAT | O_EXCL)) { | |||||
| DBG_FAIL_MACRO; | DBG_FAIL_MACRO; | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| // create a normal file | // create a normal file | ||||
| if (!open(parent, fname, O_CREAT | O_EXCL | O_RDWR)) { | |||||
| if (!open(parent, fname, O_RDWR | O_CREAT | O_EXCL)) { | |||||
| DBG_FAIL_MACRO; | DBG_FAIL_MACRO; | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| // convert file to directory | // convert file to directory | ||||
| m_flags = O_RDONLY; | |||||
| m_flags = F_READ; | |||||
| m_attr = FILE_ATTR_SUBDIR; | m_attr = FILE_ATTR_SUBDIR; | ||||
| // allocate and zero first cluster | // allocate and zero first cluster | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| // seek to end of file if append flag | // seek to end of file if append flag | ||||
| if ((m_flags & O_APPEND)) { | |||||
| if ((m_flags & F_APPEND)) { | |||||
| if (!seekSet(m_fileSize)) { | if (!seekSet(m_fileSize)) { | ||||
| DBG_FAIL_MACRO; | DBG_FAIL_MACRO; | ||||
| goto fail; | goto fail; | ||||
| m_flags |= F_FILE_DIR_DIRTY; | m_flags |= F_FILE_DIR_DIRTY; | ||||
| } | } | ||||
| if (m_flags & O_SYNC) { | |||||
| if (m_flags & F_SYNC) { | |||||
| if (!sync()) { | if (!sync()) { | ||||
| DBG_FAIL_MACRO; | DBG_FAIL_MACRO; | ||||
| goto fail; | goto fail; |
| */ | */ | ||||
| void SdSpiAltDriver::begin(uint8_t csPin) { | void SdSpiAltDriver::begin(uint8_t csPin) { | ||||
| m_csPin = csPin; | m_csPin = csPin; | ||||
| m_spi->begin(m_csPin); | |||||
| // Next line is redundant - begin(m_csPin) sets csPin to output mode. | |||||
| pinMode(m_csPin, OUTPUT); | pinMode(m_csPin, OUTPUT); | ||||
| digitalWrite(m_csPin, HIGH); | digitalWrite(m_csPin, HIGH); | ||||
| m_spi->begin(); | |||||
| } | } | ||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||
| /** | /** | ||||
| */ | */ | ||||
| uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { | uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { | ||||
| SPI_DMA_TransferCompleted = false; | SPI_DMA_TransferCompleted = false; | ||||
| m_spi->transfer(0, buf, n, SD_SPI_DMA_TransferComplete_Callback); | |||||
| m_spi->transfer(nullptr, buf, n, SD_SPI_DMA_TransferComplete_Callback); | |||||
| while (!SPI_DMA_TransferCompleted) {} | while (!SPI_DMA_TransferCompleted) {} | ||||
| return 0; | |||||
| return 0; | |||||
| } | } | ||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||
| /** Send a byte. | /** Send a byte. | ||||
| void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { | void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { | ||||
| SPI_DMA_TransferCompleted = false; | SPI_DMA_TransferCompleted = false; | ||||
| m_spi->transfer(const_cast<uint8_t*>(buf), 0, n, | |||||
| m_spi->transfer(const_cast<uint8_t*>(buf), nullptr, n, | |||||
| SD_SPI_DMA_TransferComplete_Callback); | SD_SPI_DMA_TransferComplete_Callback); | ||||
| while (!SPI_DMA_TransferCompleted) {} | while (!SPI_DMA_TransferCompleted) {} |
| */ | */ | ||||
| uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { | uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) { | ||||
| #if USE_STM32_DMA | #if USE_STM32_DMA | ||||
| return m_spi->dmaTransfer(0, buf, n); | |||||
| return m_spi->dmaTransfer(nullptr, buf, n); | |||||
| #else // USE_STM32_DMA | #else // USE_STM32_DMA | ||||
| m_spi->read(buf, n); | m_spi->read(buf, n); | ||||
| return 0; | return 0; | ||||
| */ | */ | ||||
| void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { | void SdSpiAltDriver::send(const uint8_t* buf , size_t n) { | ||||
| #if USE_STM32_DMA | #if USE_STM32_DMA | ||||
| m_spi->dmaTransfer(const_cast<uint8*>(buf), 0, n); | |||||
| m_spi->dmaTransfer(const_cast<uint8*>(buf), nullptr, n); | |||||
| #else // USE_STM32_DMA | #else // USE_STM32_DMA | ||||
| m_spi->write(const_cast<uint8*>(buf), n); | m_spi->write(const_cast<uint8*>(buf), n); | ||||
| #endif // USE_STM32_DMA | #endif // USE_STM32_DMA |