u8g_com_arduino_common.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. u8g_com_arduino_common.c
  3. shared procedures for the arduino communication procedures
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2011, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "u8g.h"
  29. #if defined(ARDUINO)
  30. #if ARDUINO < 100
  31. #include <WProgram.h>
  32. #else
  33. #include <Arduino.h>
  34. #endif
  35. void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value)
  36. {
  37. uint8_t pin;
  38. pin = u8g->pin_list[pin_index];
  39. if ( pin != U8G_PIN_NONE )
  40. digitalWrite(pin, value);
  41. }
  42. /* this procedure does not set the RW pin */
  43. void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g)
  44. {
  45. uint8_t i;
  46. /* skip the RW pin, which is the last pin in the list */
  47. for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ )
  48. {
  49. if ( u8g->pin_list[i] != U8G_PIN_NONE )
  50. {
  51. pinMode(u8g->pin_list[i], OUTPUT);
  52. digitalWrite(u8g->pin_list[i], HIGH);
  53. }
  54. }
  55. }
  56. #endif