HardwareSerial.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. HarwareSerial.cpp - 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 23 November 2006 by David A. Mellis
  16. Modified 29 January 2009, Marius Kintel for Sanguino - http://www.sanguino.cc/
  17. */
  18. #include "WProgram.h"
  19. #include "wiring.h"
  20. #include "HardwareSerial.h"
  21. // Constructors ////////////////////////////////////////////////////////////////
  22. HardwareSerial::HardwareSerial(uint8_t uart)
  23. :_uart(uart)
  24. {
  25. }
  26. // Public Methods //////////////////////////////////////////////////////////////
  27. void HardwareSerial::begin(long speed)
  28. {
  29. beginSerial(_uart, speed);
  30. }
  31. uint8_t HardwareSerial::available(void)
  32. {
  33. return serialAvailable(_uart);
  34. }
  35. int HardwareSerial::read(void)
  36. {
  37. return serialRead(_uart);
  38. }
  39. void HardwareSerial::flush()
  40. {
  41. serialFlush(_uart);
  42. }
  43. void HardwareSerial::write(uint8_t b) {
  44. serialWrite(_uart, b);
  45. }
  46. // Preinstantiate Objects //////////////////////////////////////////////////////
  47. HardwareSerial Serial = HardwareSerial(0);
  48. #if defined(__AVR_ATmega644P__)
  49. HardwareSerial Serial1 = HardwareSerial(1);
  50. #endif