mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Importing my changes
This commit is contained in:
@ -120,13 +120,13 @@ uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
|
||||
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
|
||||
|
||||
// send CRC
|
||||
uint8_t crc = 0XFF;
|
||||
if (cmd == CMD0) crc = 0X95; // correct crc for CMD0 with arg 0
|
||||
if (cmd == CMD8) crc = 0X87; // correct crc for CMD8 with arg 0X1AA
|
||||
uint8_t crc = 0xFF;
|
||||
if (cmd == CMD0) crc = 0x95; // correct crc for CMD0 with arg 0
|
||||
if (cmd == CMD8) crc = 0x87; // correct crc for CMD8 with arg 0X1AA
|
||||
spiSend(crc);
|
||||
|
||||
// wait for response
|
||||
for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++)
|
||||
for (uint8_t i = 0; ((status_ = spiRec()) & 0x80) && i != 0xFF; i++)
|
||||
;
|
||||
return status_;
|
||||
}
|
||||
@ -239,7 +239,11 @@ uint8_t Sd2Card::eraseSingleBlockEnable(void) {
|
||||
* the value zero, false, is returned for failure. The reason for failure
|
||||
* can be determined by calling errorCode() and errorData().
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
uint8_t Sd2Card::init(uint32_t sckRateID, uint8_t chipSelectPin) {
|
||||
#else
|
||||
uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
||||
#endif
|
||||
errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;
|
||||
chipSelectPin_ = chipSelectPin;
|
||||
// 16-bit init start time allows over a minute
|
||||
@ -266,7 +270,11 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
||||
SPSR &= ~(1 << SPI2X);
|
||||
#else // USE_SPI_LIB
|
||||
SPI.begin();
|
||||
#ifdef ESP8266
|
||||
settings = SPISettings(SPI_CLOCK_DIV64, MSBFIRST, SPI_MODE0);
|
||||
#else
|
||||
settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
|
||||
#endif
|
||||
#endif // USE_SPI_LIB
|
||||
#endif // SOFTWARE_SPI
|
||||
|
||||
@ -498,11 +506,15 @@ uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) {
|
||||
* \return The value one, true, is returned for success and the value zero,
|
||||
* false, is returned for an invalid value of \a sckRateID.
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
uint8_t Sd2Card::setSckRate(uint32_t sckRateID) {
|
||||
#else
|
||||
uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
|
||||
if (sckRateID > 6) {
|
||||
error(SD_CARD_ERROR_SCK_RATE);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
#ifndef USE_SPI_LIB
|
||||
// see avr processor datasheet for SPI register bit definitions
|
||||
if ((sckRateID & 1) || sckRateID == 6) {
|
||||
@ -514,6 +526,9 @@ uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
|
||||
SPCR |= (sckRateID & 4 ? (1 << SPR1) : 0)
|
||||
| (sckRateID & 2 ? (1 << SPR0) : 0);
|
||||
#else // USE_SPI_LIB
|
||||
#ifdef ESP8266
|
||||
settings = SPISettings(sckRateID, MSBFIRST, SPI_MODE0);
|
||||
#else
|
||||
switch (sckRateID) {
|
||||
case 0: settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;
|
||||
case 1: settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); break;
|
||||
@ -523,6 +538,7 @@ uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
|
||||
case 5: settings = SPISettings(250000, MSBFIRST, SPI_MODE0); break;
|
||||
default: settings = SPISettings(125000, MSBFIRST, SPI_MODE0);
|
||||
}
|
||||
#endif
|
||||
#endif // USE_SPI_LIB
|
||||
return true;
|
||||
}
|
||||
|
@ -25,15 +25,23 @@
|
||||
*/
|
||||
#include "Sd2PinMap.h"
|
||||
#include "SdInfo.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
#include "SPI.h"
|
||||
uint32_t const SPI_FULL_SPEED = SPI_CLOCK_DIV2;
|
||||
uint32_t const SPI_HALF_SPEED = SPI_CLOCK_DIV4;
|
||||
uint32_t const SPI_QUARTER_SPEED = SPI_CLOCK_DIV8;
|
||||
#else
|
||||
/** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */
|
||||
uint8_t const SPI_FULL_SPEED = 0;
|
||||
/** Set SCK rate to F_CPU/4. See Sd2Card::setSckRate(). */
|
||||
uint8_t const SPI_HALF_SPEED = 1;
|
||||
/** Set SCK rate to F_CPU/8. Sd2Card::setSckRate(). */
|
||||
uint8_t const SPI_QUARTER_SPEED = 2;
|
||||
#endif
|
||||
/**
|
||||
* USE_SPI_LIB: if set, use the SPI library bundled with Arduino IDE, otherwise
|
||||
* run with a standalone driver for AVR.
|
||||
* run with a standalone driver for AVR.
|
||||
*/
|
||||
#define USE_SPI_LIB
|
||||
/**
|
||||
@ -181,10 +189,17 @@ class Sd2Card {
|
||||
* and the default SD chip select pin.
|
||||
* See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
uint8_t init(uint32_t sckRateID) {
|
||||
return init(sckRateID, SD_CHIP_SELECT_PIN);
|
||||
}
|
||||
uint8_t init(uint32_t sckRateID, uint8_t chipSelectPin);
|
||||
#else
|
||||
uint8_t init(uint8_t sckRateID) {
|
||||
return init(sckRateID, SD_CHIP_SELECT_PIN);
|
||||
}
|
||||
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin);
|
||||
#endif
|
||||
void partialBlockRead(uint8_t value);
|
||||
/** Returns the current value, true or false, for partial block read. */
|
||||
uint8_t partialBlockRead(void) const {return partialBlockRead_;}
|
||||
@ -205,7 +220,11 @@ class Sd2Card {
|
||||
return readRegister(CMD9, csd);
|
||||
}
|
||||
void readEnd(void);
|
||||
#ifdef ESP8266
|
||||
uint8_t setSckRate(uint32_t sckRateID);
|
||||
#else
|
||||
uint8_t setSckRate(uint8_t sckRateID);
|
||||
#endif
|
||||
/** Return the card type: SD V1, SD V2 or SDHC */
|
||||
uint8_t type(void) const {return type_;}
|
||||
uint8_t writeBlock(uint32_t blockNumber, const uint8_t* src);
|
||||
|
@ -31,6 +31,19 @@ uint8_t const SCK_PIN = SCK;
|
||||
|
||||
#endif // Sd2PinMap_h
|
||||
|
||||
#elif defined(ESP8266) // Other AVR based Boards follows
|
||||
#ifndef Sd2PinMap_h
|
||||
#define Sd2PinMap_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
uint8_t const SS_PIN = SS;
|
||||
uint8_t const MOSI_PIN = MOSI;
|
||||
uint8_t const MISO_PIN = MISO;
|
||||
uint8_t const SCK_PIN = SCK;
|
||||
|
||||
#endif // Sd2PinMap_h
|
||||
|
||||
#elif defined(__AVR__) // Other AVR based Boards follows
|
||||
|
||||
// Warning this file was generated by a program.
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
#include <Arduino.h>
|
||||
#define PRINT_PORT Serial
|
||||
//------------------------------------------------------------------------------
|
||||
// callback function for date/time
|
||||
void (*SdFile::dateTime_)(uint16_t* date, uint16_t* time) = NULL;
|
||||
@ -215,7 +216,7 @@ void SdFile::ls(uint8_t flags, uint8_t indent) {
|
||||
if (!DIR_IS_FILE_OR_SUBDIR(p)) continue;
|
||||
|
||||
// print any indent spaces
|
||||
for (int8_t i = 0; i < indent; i++) Serial.print(' ');
|
||||
for (int8_t i = 0; i < indent; i++) PRINT_PORT.print(' ');
|
||||
|
||||
// print file name with possible blank fill
|
||||
printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0);
|
||||
@ -223,15 +224,15 @@ void SdFile::ls(uint8_t flags, uint8_t indent) {
|
||||
// print modify date/time if requested
|
||||
if (flags & LS_DATE) {
|
||||
printFatDate(p->lastWriteDate);
|
||||
Serial.print(' ');
|
||||
PRINT_PORT.print(' ');
|
||||
printFatTime(p->lastWriteTime);
|
||||
}
|
||||
// print size if requested
|
||||
if (!DIR_IS_SUBDIR(p) && (flags & LS_SIZE)) {
|
||||
Serial.print(' ');
|
||||
Serial.print(p->fileSize);
|
||||
PRINT_PORT.print(' ');
|
||||
PRINT_PORT.print(p->fileSize);
|
||||
}
|
||||
Serial.println();
|
||||
PRINT_PORT.println();
|
||||
|
||||
// list subdirectory content if requested
|
||||
if ((flags & LS_R) && DIR_IS_SUBDIR(p)) {
|
||||
@ -595,18 +596,18 @@ void SdFile::printDirName(const dir_t& dir, uint8_t width) {
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
if (dir.name[i] == ' ')continue;
|
||||
if (i == 8) {
|
||||
Serial.print('.');
|
||||
PRINT_PORT.print('.');
|
||||
w++;
|
||||
}
|
||||
Serial.write(dir.name[i]);
|
||||
PRINT_PORT.write(dir.name[i]);
|
||||
w++;
|
||||
}
|
||||
if (DIR_IS_SUBDIR(&dir)) {
|
||||
Serial.print('/');
|
||||
PRINT_PORT.print('/');
|
||||
w++;
|
||||
}
|
||||
while (w < width) {
|
||||
Serial.print(' ');
|
||||
PRINT_PORT.print(' ');
|
||||
w++;
|
||||
}
|
||||
}
|
||||
@ -618,10 +619,10 @@ void SdFile::printDirName(const dir_t& dir, uint8_t width) {
|
||||
* \param[in] fatDate The date field from a directory entry.
|
||||
*/
|
||||
void SdFile::printFatDate(uint16_t fatDate) {
|
||||
Serial.print(FAT_YEAR(fatDate));
|
||||
Serial.print('-');
|
||||
PRINT_PORT.print(FAT_YEAR(fatDate));
|
||||
PRINT_PORT.print('-');
|
||||
printTwoDigits(FAT_MONTH(fatDate));
|
||||
Serial.print('-');
|
||||
PRINT_PORT.print('-');
|
||||
printTwoDigits(FAT_DAY(fatDate));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -633,9 +634,9 @@ void SdFile::printFatDate(uint16_t fatDate) {
|
||||
*/
|
||||
void SdFile::printFatTime(uint16_t fatTime) {
|
||||
printTwoDigits(FAT_HOUR(fatTime));
|
||||
Serial.print(':');
|
||||
PRINT_PORT.print(':');
|
||||
printTwoDigits(FAT_MINUTE(fatTime));
|
||||
Serial.print(':');
|
||||
PRINT_PORT.print(':');
|
||||
printTwoDigits(FAT_SECOND(fatTime));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@ -648,7 +649,7 @@ void SdFile::printTwoDigits(uint8_t v) {
|
||||
str[0] = '0' + v/10;
|
||||
str[1] = '0' + v % 10;
|
||||
str[2] = 0;
|
||||
Serial.print(str);
|
||||
PRINT_PORT.print(str);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
|
Reference in New Issue
Block a user