перенесла настройку прерываний в setRx

This commit is contained in:
klassents committed 2024-10-08 14:10:14 +07:00
1 parent 8f2f29987b
commit 21df57e980
1 file changed
+14 -16
+14 -16
View File
@@ -202,6 +202,14 @@ void SoftwareSerial::setRX(uint8_t rx)
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
else
pinMode(rx, INPUT);
// Save gpio_line for turning on/off interrupts
_int_maskLine = digitalPinToGpioIntLine(_receivePin);
// Init interrupt line
HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config)digitalPinToGpioIntMux(_receivePin),
_inverse_logic ? GPIO_INT_MODE_RISING : GPIO_INT_MODE_FALLING);
GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int line (it turning on while line init)
HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
}
uint32_t SoftwareSerial::subtract_cap(uint32_t num, uint16_t sub)
@@ -217,10 +225,7 @@ uint32_t SoftwareSerial::subtract_cap(uint32_t num, uint16_t sub)
//
void SoftwareSerial::begin(long speed)
{
// set pins config
setRX(_receivePin);
setTX(_transmitPin);
// delays are empirical values here
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
// limit speed
@@ -230,14 +235,15 @@ void SoftwareSerial::begin(long speed)
// Precalculate the various delays in number of ticks
uint32_t bit_delay = F_CPU / speed;
// delays are empirical values here
// 1 bit delay while transmitting data
_tx_delay = subtract_cap(bit_delay, 35);
setTX(_transmitPin);
_tx_delay = subtract_cap(bit_delay, 35); // 1 bit delay while transmitting data
// Only setup rx when we have a valid INT for this pin
if (digitalPinToInterrupt(_receivePin) != NOT_AN_INTERRUPT)
{
// set pin config
setRX(_receivePin);
// We want to have a total delay of 1.5 bit time from start bit. Inside the loop, we already
// wait for 1 bit time, so here we wait for 0.5 bit time
_rx_delay_centering = subtract_cap(bit_delay / 2, 315);
@@ -248,14 +254,6 @@ void SoftwareSerial::begin(long speed)
// This delay aims at 3/4 of a bit time, meaning the end of the delay will be at 1/4th of the stopbit.
// This allows some extra time for ISR cleanup, which makes 115200 baud at 16Mhz work more reliably
_rx_delay_stopbit = subtract_cap(bit_delay * 3 / 4, 142);
// Save gpio_line for turning on/off interrupts
_int_maskLine = digitalPinToGpioIntLine(_receivePin);
// Init interrupt line
HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config)digitalPinToGpioIntMux(_receivePin),
_inverse_logic ? GPIO_INT_MODE_RISING : GPIO_INT_MODE_FALLING);
GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int line (it turning on while line init)
HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
}
else
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");