перенесла настройку прерываний в setRx
This commit is contained in:
1 parent
8f2f29987b
commit
21df57e980
1 file changed
+15
-17
@@ -202,6 +202,14 @@ void SoftwareSerial::setRX(uint8_t rx)
|
|||||||
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
|
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
|
||||||
else
|
else
|
||||||
pinMode(rx, INPUT);
|
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)
|
uint32_t SoftwareSerial::subtract_cap(uint32_t num, uint16_t sub)
|
||||||
@@ -216,11 +224,8 @@ uint32_t SoftwareSerial::subtract_cap(uint32_t num, uint16_t sub)
|
|||||||
// Public methods
|
// Public methods
|
||||||
//
|
//
|
||||||
void SoftwareSerial::begin(long speed)
|
void SoftwareSerial::begin(long speed)
|
||||||
{
|
{
|
||||||
// set pins config
|
// delays are empirical values here
|
||||||
setRX(_receivePin);
|
|
||||||
setTX(_transmitPin);
|
|
||||||
|
|
||||||
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
||||||
|
|
||||||
// limit speed
|
// limit speed
|
||||||
@@ -230,14 +235,15 @@ void SoftwareSerial::begin(long speed)
|
|||||||
// Precalculate the various delays in number of ticks
|
// Precalculate the various delays in number of ticks
|
||||||
uint32_t bit_delay = F_CPU / speed;
|
uint32_t bit_delay = F_CPU / speed;
|
||||||
|
|
||||||
// delays are empirical values here
|
setTX(_transmitPin);
|
||||||
|
_tx_delay = subtract_cap(bit_delay, 35); // 1 bit delay while transmitting data
|
||||||
// 1 bit delay while transmitting data
|
|
||||||
_tx_delay = subtract_cap(bit_delay, 35);
|
|
||||||
|
|
||||||
// Only setup rx when we have a valid INT for this pin
|
// Only setup rx when we have a valid INT for this pin
|
||||||
if (digitalPinToInterrupt(_receivePin) != NOT_AN_INTERRUPT)
|
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
|
// 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
|
// wait for 1 bit time, so here we wait for 0.5 bit time
|
||||||
_rx_delay_centering = subtract_cap(bit_delay / 2, 315);
|
_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 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
|
// 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);
|
_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
|
else
|
||||||
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
|
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
|
||||||
|
|||||||
Reference in new issue
Block a user