Skip to content

Commit

Permalink
Merge pull request #22 from hallard/master
Browse files Browse the repository at this point in the history
Added baudRate method to return current speed
  • Loading branch information
plerup authored Jul 1, 2016
2 parents 097712e + 6325ef5 commit e5a329d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ void SoftwareSerial::begin(long speed) {
m_bitTime = ESP.getCpuFreqMHz()*1000000/speed;
}

long SoftwareSerial::baudRate() {
// Use getCycleCount() loop to get as exact timing as possible
long speed = ESP.getCpuFreqMHz()*1000000/m_bitTime;
return speed;
}

void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) {
if (isValidGPIOpin(transmitEnablePin)) {
m_txEnableValid = true;
Expand Down Expand Up @@ -205,3 +211,5 @@ void ICACHE_RAM_ATTR SoftwareSerial::rxRead() {
// it gets set even when interrupts are disabled
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rxPin);
}


2 changes: 2 additions & 0 deletions SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class SoftwareSerial : public Stream
~SoftwareSerial();

void begin(long speed);
long baudRate();
void setTransmitEnablePin(int transmitEnablePin);


int peek();

virtual size_t write(uint8_t byte);
Expand Down

0 comments on commit e5a329d

Please sign in to comment.