mirror of https://github.com/arendst/Tasmota.git
Fix software serial on RISCV cpus. (#20793)
* fix software serial for riscv * fix softwareserial on riscv
This commit is contained in:
parent
ae01d4ccd5
commit
9608bc5799
|
@ -256,7 +256,11 @@ SML_ESP32_SERIAL::~SML_ESP32_SERIAL(void) {
|
|||
}
|
||||
|
||||
void SML_ESP32_SERIAL::setbaud(uint32_t speed) {
|
||||
#ifdef __riscv
|
||||
m_bit_time = 1000000 / speed;
|
||||
#else
|
||||
m_bit_time = ESP.getCpuFreqMHz() * 1000000 / speed;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SML_ESP32_SERIAL::end(void) {
|
||||
|
@ -366,13 +370,21 @@ void IRAM_ATTR SML_ESP32_SERIAL::rxRead(void) {
|
|||
|
||||
if (!level && !ss_index) {
|
||||
// start condition
|
||||
#ifdef __riscv
|
||||
ss_bstart = micros() - (m_bit_time / 4);
|
||||
#else
|
||||
ss_bstart = ESP.getCycleCount() - (m_bit_time / 4);
|
||||
#endif
|
||||
ss_byte = 0;
|
||||
ss_index++;
|
||||
} else {
|
||||
// now any bit changes go here
|
||||
// calc bit number
|
||||
#ifdef __riscv
|
||||
diff = (micros() - ss_bstart) / m_bit_time;
|
||||
#else
|
||||
diff = (ESP.getCycleCount() - ss_bstart) / m_bit_time;
|
||||
#endif
|
||||
|
||||
if (!level && diff > SML_LASTBIT) {
|
||||
// start bit of next byte, store and restart
|
||||
|
@ -385,8 +397,11 @@ void IRAM_ATTR SML_ESP32_SERIAL::rxRead(void) {
|
|||
m_buffer[m_in_pos] = ss_byte >> 1;
|
||||
m_in_pos = next;
|
||||
}
|
||||
|
||||
#ifdef __riscv
|
||||
ss_bstart = micros() - (m_bit_time / 4);
|
||||
#else
|
||||
ss_bstart = ESP.getCycleCount() - (m_bit_time / 4);
|
||||
#endif
|
||||
ss_byte = 0;
|
||||
ss_index = 1;
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue