My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SoftwareSerial.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * SoftwareSerial.h (formerly NewSoftSerial.h)
  3. *
  4. * Multi-instance software serial library for Arduino/Wiring
  5. * -- Interrupt-driven receive and other improvements by ladyada
  6. * (http://ladyada.net)
  7. * -- Tuning, circular buffer, derivation from class Print/Stream,
  8. * multi-instance support, porting to 8MHz processors,
  9. * various optimizations, PROGMEM delay tables, inverse logic and
  10. * direct port writing by Mikal Hart (http://www.arduiniana.org)
  11. * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
  12. * -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
  13. * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
  14. *
  15. * This library is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU Lesser General Public
  17. * License as published by the Free Software Foundation; either
  18. * version 2.1 of the License, or (at your option) any later version.
  19. *
  20. * This library is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * Lesser General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Lesser General Public
  26. * License along with this library; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. * The latest version of this library can always be found at
  30. * http://arduiniana.org.
  31. */
  32. #ifndef SOFTWARESERIAL_H
  33. #define SOFTWARESERIAL_H
  34. #include <Arduino.h>
  35. #include <stdint.h>
  36. //#include "serial.h"
  37. #include <Stream.h>
  38. #include <Print.h>
  39. /******************************************************************************
  40. * Definitions
  41. ******************************************************************************/
  42. #define _SS_MAX_RX_BUFF 64 // RX buffer size
  43. class SoftwareSerial : public Stream
  44. {
  45. private:
  46. // per object data
  47. pin_t _receivePin;
  48. pin_t _transmitPin;
  49. // uint32_t _receiveBitMask; // for rx interrupts
  50. uint32_t _receivePort;
  51. uint32_t _receivePortPin;
  52. // Expressed as 4-cycle delays (must never be 0!)
  53. uint16_t _rx_delay_centering;
  54. uint16_t _rx_delay_intrabit;
  55. uint16_t _rx_delay_stopbit;
  56. uint16_t _tx_delay;
  57. uint16_t _buffer_overflow:1;
  58. uint16_t _inverse_logic:1;
  59. // static data
  60. static unsigned char _receive_buffer[_SS_MAX_RX_BUFF];
  61. static volatile uint8_t _receive_buffer_tail;
  62. static volatile uint8_t _receive_buffer_head;
  63. static SoftwareSerial *active_object;
  64. // private methods
  65. void recv();
  66. uint32_t rx_pin_read();
  67. void tx_pin_write(uint8_t pin_state);
  68. void setTX(pin_t transmitPin);
  69. void setRX(pin_t receivePin);
  70. void setRxIntMsk(bool enable);
  71. // private static method for timing
  72. static inline void tunedDelay(uint32_t delay);
  73. public:
  74. // public methods
  75. SoftwareSerial(pin_t receivePin, pin_t transmitPin, bool inverse_logic = false);
  76. ~SoftwareSerial();
  77. void begin(long speed);
  78. bool listen();
  79. void end();
  80. bool isListening() { return this == active_object; }
  81. bool stopListening();
  82. bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; }
  83. int peek();
  84. virtual size_t write(uint8_t byte);
  85. virtual int read();
  86. virtual int available();
  87. virtual void flush();
  88. operator bool() { return true; }
  89. using Print::write;
  90. //using HalSerial::write;
  91. // public only for easy access by interrupt handlers
  92. static inline void handle_interrupt() __attribute__((__always_inline__));
  93. };
  94. // Arduino 0012 workaround
  95. #undef int
  96. #undef char
  97. #undef long
  98. #undef byte
  99. #undef float
  100. #undef abs
  101. #undef round
  102. #endif // SOFTWARESERIAL_H