Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

HardwareSerial.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. HardwareSerial.h - Hardware serial library for Wiring
  3. Copyright (c) 2006 Nicholas Zambetti. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Modified 28 September 2010 by Mark Sproul
  16. */
  17. #ifndef HardwareSerial_h
  18. #define HardwareSerial_h
  19. #include <inttypes.h>
  20. #include "Stream.h"
  21. struct ring_buffer;
  22. class HardwareSerial : public Stream
  23. {
  24. private:
  25. ring_buffer *_rx_buffer;
  26. ring_buffer *_tx_buffer;
  27. volatile uint8_t *_ubrrh;
  28. volatile uint8_t *_ubrrl;
  29. volatile uint8_t *_ucsra;
  30. volatile uint8_t *_ucsrb;
  31. volatile uint8_t *_udr;
  32. uint8_t _rxen;
  33. uint8_t _txen;
  34. uint8_t _rxcie;
  35. uint8_t _udrie;
  36. uint8_t _u2x;
  37. public:
  38. HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
  39. volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
  40. volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
  41. volatile uint8_t *udr,
  42. uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
  43. void begin(unsigned 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. #if defined(UBRRH) || defined(UBRR0H)
  54. extern HardwareSerial Serial;
  55. #elif defined(USBCON)
  56. #include "USBAPI.h"
  57. // extern HardwareSerial Serial_;
  58. #endif
  59. #if defined(UBRR1H)
  60. extern HardwareSerial Serial1;
  61. #endif
  62. #if defined(UBRR2H)
  63. extern HardwareSerial Serial2;
  64. #endif
  65. #if defined(UBRR3H)
  66. extern HardwareSerial Serial3;
  67. #endif
  68. extern void serialEventRun(void) __attribute__((weak));
  69. #endif