dev_beta_softSerial #4
No files matched your search
@@ -202,7 +202,7 @@ void SoftwareSerial::recv()
|
||||
|
||||
uint8_t SoftwareSerial::rx_pin_read()
|
||||
{
|
||||
return (uint8_t)HAL_GPIO_ReadPin((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receivePin);
|
||||
return (uint8_t)HAL_GPIO_ReadPin((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -236,8 +236,8 @@ SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inv
|
||||
_buffer_overflow(false),
|
||||
_inverse_logic(inverse_logic)
|
||||
{
|
||||
setTX(transmitPin);
|
||||
setRX(receivePin);
|
||||
_transmitPin = transmitPin;
|
||||
_receivePin = receivePin;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -250,12 +250,9 @@ SoftwareSerial::~SoftwareSerial()
|
||||
|
||||
void SoftwareSerial::setTX(uint8_t tx)
|
||||
{
|
||||
// First write, then set output. If we do this the other way around,
|
||||
// the pin would be output low for a short while before switching to
|
||||
// output high. Now, it is input with pullup for a short while, which
|
||||
// is fine. With inverse logic, either order is fine.
|
||||
digitalWrite(tx, _inverse_logic ? LOW : HIGH); // todo проверить, что правда выставляется до конфигурации
|
||||
// First configure then write because writing pin didn't work until config is applied
|
||||
pinMode(tx, OUTPUT);
|
||||
digitalWrite(tx, _inverse_logic ? LOW : HIGH);
|
||||
_transmitBitMask = (uint16_t)digitalPinToBitMask(tx); // save tx bit mask
|
||||
_transmitPortRegister = (uint32_t)digitalPinToPort(tx); // save tx port adress
|
||||
}
|
||||
@@ -266,7 +263,6 @@ void SoftwareSerial::setRX(uint8_t rx)
|
||||
pinMode(rx, INPUT_PULLUP); // pullup for normal logic
|
||||
else
|
||||
pinMode(rx, INPUT);
|
||||
_receivePin = rx; // save rx digital pin number
|
||||
_receiveBitMask = (uint16_t)digitalPinToBitMask(rx); // save rx bit mask
|
||||
_receivePortRegister = (uint32_t)digitalPinToPort(rx); // save rx port adress
|
||||
}
|
||||
@@ -284,6 +280,10 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, uint16_t sub)
|
||||
//
|
||||
void SoftwareSerial::begin(long speed)
|
||||
{
|
||||
// set pins config
|
||||
setRX(_receivePin);
|
||||
setTX(_transmitPin);
|
||||
|
||||
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
|
||||
|
||||
// limit speed
|
||||
@@ -357,6 +357,8 @@ void SoftwareSerial::begin(long speed)
|
||||
|
||||
tunedDelay(_tx_delay); // if we were low this establishes the end
|
||||
}
|
||||
else
|
||||
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
|
||||
|
||||
// #if _DEBUG
|
||||
// pinMode(_DEBUG_PIN1, OUTPUT);
|
||||
@@ -430,12 +432,9 @@ size_t SoftwareSerial::write(uint8_t byte)
|
||||
|
||||
// Write the start bit
|
||||
if (inv)
|
||||
// todo проверить, можно ли так выставлять через адрес порта
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||
// *reg |= reg_mask; // бит tx в 1
|
||||
else
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||
// *reg &= inv_mask; // бит tx в 0
|
||||
|
||||
tunedDelay(delay);
|
||||
|
||||
@@ -443,10 +442,8 @@ size_t SoftwareSerial::write(uint8_t byte)
|
||||
for (uint8_t i = 8; i > 0; --i)
|
||||
{
|
||||
if (byte & 1) // choose bit
|
||||
// *reg |= reg_mask; // send 1
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||
else
|
||||
// *reg &= inv_mask; // send 0
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||
|
||||
tunedDelay(delay);
|
||||
@@ -456,10 +453,8 @@ size_t SoftwareSerial::write(uint8_t byte)
|
||||
// restore pin to natural state
|
||||
if (inv)
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_LOW);
|
||||
// *reg &= inv_mask; // бит tx в 0
|
||||
else
|
||||
HAL_GPIO_WritePin((GPIO_TypeDef *)_transmitPortRegister, (HAL_PinsTypeDef)bit_mask, GPIO_PIN_HIGH);
|
||||
// *reg |= reg_mask; // бит tx в 1
|
||||
|
||||
interrupts(); // enable interrupts
|
||||
tunedDelay(_tx_delay);
|
||||
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
uint8_t _receivePin;
|
||||
uint16_t _receiveBitMask;
|
||||
uint32_t _receivePortRegister;
|
||||
uint8_t _transmitPin;
|
||||
uint16_t _transmitBitMask;
|
||||
uint32_t _transmitPortRegister;
|
||||
uint8_t _int_maskMux;
|
||||
|
||||
Reference in new issue
Block a user