Skip to content

Commit

Permalink
Merge pull request #22 from Links2004/esp8266
Browse files Browse the repository at this point in the history
pull SPI speed fix and uart overflow
  • Loading branch information
ficeto committed May 16, 2015
2 parents fe5c667 + a372da1 commit e730a24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
36 changes: 20 additions & 16 deletions hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,30 +392,34 @@ void uart_ignore_char(char c) {

void uart0_write_char(char c) {
if(&Serial != NULL && Serial.isTxEnabled()) {
if(c == '\n') {
Serial.write('\r');
}
Serial.write(c);
} else {
if(c == '\n') {
USF(0) = '\r';
if(Serial.availableForWrite() > 0) {
if(c == '\n') {
Serial.write('\r');
}
Serial.write(c);
return;
}
USF(0) = c;
}
if(c == '\n') {
USF(0) = '\r';
}
USF(0) = c;
}

void uart1_write_char(char c) {
if(&Serial1 != NULL && Serial1.isTxEnabled()) {
if(c == '\n') {
Serial1.write('\r');
}
Serial1.write(c);
} else {
if(c == '\n') {
USF(1) = '\r';
if(Serial1.availableForWrite() > 0) {
if(c == '\n') {
Serial1.write('\r');
}
Serial1.write(c);
return;
}
USF(1) = c;
}
if(c == '\n') {
USF(1) = '\r';
}
USF(1) = c;
}

static int s_uart_debug_nr = UART0;
Expand Down
6 changes: 3 additions & 3 deletions hardware/esp8266com/esp8266/libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
* @return
*/
static uint32_t ClkRegToFreq(spiClk_t * reg) {
return (F_CPU / ((reg->regPre + 1) * (reg->regN + 1)));
return (SPI_MAX_SPEED / ((reg->regPre + 1) * (reg->regN + 1)));
}

void SPIClass::setFrequency(uint32_t freq) {
static uint32_t lastSetFrequency = 0;
static uint32_t lastSetRegister = 0;

if(freq >= F_CPU) {
if(freq >= SPI_MAX_SPEED) {
setClockDivider(0x80000000);
return;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
reg.regN = calN;

while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
calPre = (((F_CPU / (reg.regN + 1)) / freq) - 1) + calPreVari;
calPre = (((SPI_MAX_SPEED / (reg.regN + 1)) / freq) - 1) + calPreVari;
if(calPre > 0x1FFF) {
reg.regPre = 0x1FFF; // 8191
} else if(calPre <= 0) {
Expand Down
2 changes: 2 additions & 0 deletions hardware/esp8266com/esp8266/libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz
#endif

#define SPI_MAX_SPEED (80000000L)

const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0
Expand Down

0 comments on commit e730a24

Please sign in to comment.