uaa

SoftwareSerial.cpp diff with ArduinoCore-avr 1.8.3

uaa
Jul 19th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. --- /home/uaa/ArduinoCore-avr/libraries/SoftwareSerial/src/SoftwareSerial.cpp Sun Jul 19 07:27:55 2020
  2. +++ SoftwareSerial.cpp Sat Jul 18 05:17:07 2020
  3. @@ -42,8 +42,29 @@ http://arduiniana.org.
  4. #include <avr/pgmspace.h>
  5. #include <Arduino.h>
  6. #include <SoftwareSerial.h>
  7. -#include <util/delay_basic.h>
  8. +// #include <util/delay_basic.h>
  9. +// replace modified _delay_loop_2() for LGT8F328P
  10. +/*
  11. + Delay loop using a 16-bit counter \c __count, so up to 65536
  12. + iterations are possible. (The value 65536 would have to be
  13. + passed as 0.) The loop executes four CPU cycles per iteration,
  14. + not including the overhead the compiler requires to setup the
  15. + counter register pair.
  16.  
  17. + Thus, at a CPU speed of 1 MHz, delays of up to about 262.1
  18. + milliseconds can be achieved.
  19. + */
  20. +static void SoftwareSerial::_delay_loop_2(uint16_t __count)
  21. +{
  22. + __asm__ volatile (
  23. + "1: sbiw %0,1" "\n\t"
  24. + "nop" "\n\t" // LGT8F328P's SBIW takes 1 clock, adjust
  25. + "brne 1b"
  26. + : "=w" (__count)
  27. + : "0" (__count)
  28. + );
  29. +}
  30. +
  31. //
  32. // Statics
  33. //
  34. @@ -301,6 +322,31 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, ui
  35. // Public methods
  36. //
  37.  
  38. +void SoftwareSerial::begin(uint16_t rxcenter, uint16_t rxintra, uint16_t rxstop, uint16_t tx)
  39. +{
  40. + _rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = 0;
  41. + _tx_delay = tx;
  42. +
  43. + // Only setup rx when we have a valid PCINT for this pin
  44. + if (digitalPinToPCICR((int8_t)_receivePin)) {
  45. + _rx_delay_centering = rxcenter;
  46. + _rx_delay_intrabit = rxintra;
  47. + _rx_delay_stopbit = rxstop;
  48. +
  49. + *digitalPinToPCICR((int8_t)_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
  50. + _pcint_maskreg = digitalPinToPCMSK(_receivePin);
  51. + _pcint_maskvalue = _BV(digitalPinToPCMSKbit(_receivePin));
  52. +
  53. + tunedDelay(_tx_delay); // if we were low this establishes the end
  54. + }
  55. +
  56. +#if _DEBUG
  57. + pinMode(_DEBUG_PIN1, OUTPUT);
  58. + pinMode(_DEBUG_PIN2, OUTPUT);
  59. +#endif
  60. +
  61. + listen();
  62. +}
  63. void SoftwareSerial::begin(long speed)
  64. {
  65. _rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
Add Comment
Please, Sign In to add comment