Skip to content

Commit

Permalink
Added baudRate method to return current speed
Browse files Browse the repository at this point in the history
Added baudRate to keep this pull request on SoftSerial

esp8266/Arduino@9aab572
  • Loading branch information
hallard committed May 27, 2016
1 parent 097712e commit 6325ef5
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 6325ef5

Please sign in to comment.