Advertisement
Guest User

Untitled

a guest
Apr 18th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #if USE_SOFTWARE_SERIAL
  2. #ifndef TinySoftwareSerial_h
  3. #define TinySoftwareSerial_h
  4. #include <inttypes.h>
  5. #include "Stream.h"
  6.  
  7. #if !defined(ACSR) && defined(ACSRA)
  8. #define ACSR ACSRA
  9. #endif
  10.  
  11. #if (RAMEND < 250)
  12.   #define SERIAL_BUFFER_SIZE 8
  13. #elif (RAMEND < 500)
  14.   #define SERIAL_BUFFER_SIZE 16
  15. #elif (RAMEND < 1000)
  16.   #define SERIAL_BUFFER_SIZE 32
  17. #else
  18.   #define SERIAL_BUFFER_SIZE 128
  19. #endif
  20. struct soft_ring_buffer
  21. {
  22.   unsigned char buffer[SERIAL_BUFFER_SIZE];
  23.   int head;
  24.   int tail;
  25. };
  26.  
  27. extern "C"{
  28.   void uartDelay() __attribute__ ((naked,used)); //used attribute needed to prevent LTO from throwing it out.
  29.   uint8_t getch();
  30.   void store_char(unsigned char c, soft_ring_buffer *buffer);
  31. }
  32.  
  33. class TinySoftwareSerial : public Stream
  34. {
  35.   public: //should be private but needed by extern "C" {} functions.
  36.   uint8_t _rxmask;
  37.   uint8_t _txmask;
  38.   uint8_t _txunmask;
  39.   soft_ring_buffer *_rx_buffer;
  40.   uint8_t _delayCount;
  41.   public:
  42.     TinySoftwareSerial(soft_ring_buffer *rx_buffer, uint8_t txBit, uint8_t rxBit);
  43.     void begin(long);
  44.     void end();
  45.     virtual int available(void);
  46.     virtual int peek(void);
  47.     virtual int read(void);
  48.     virtual void flush(void);
  49.     virtual size_t write(uint8_t);
  50.     using Print::write; // pull in write(str) and write(buf, size) from Print
  51.     operator bool();
  52. };
  53.  
  54. #if (!defined(UBRRH) && !defined(UBRR0H)) || USE_SOFTWARE_SERIAL
  55.   extern TinySoftwareSerial Serial;
  56. #endif
  57.  
  58. //extern void putch(uint8_t);
  59. #endif
  60. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement