Fix software serial on RISCV cpus. (#20793)

* fix software serial for riscv

* fix softwareserial on riscv
This commit is contained in:
gemu 2024-02-24 09:45:13 +01:00 committed by GitHub
parent ae01d4ccd5
commit 9608bc5799
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -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;