epdif.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @filename : epdif.cpp
  3. * @brief : Implements EPD interface functions
  4. * Users have to implement all the functions in epdif.cpp
  5. * @author : Yehui from Waveshare
  6. *
  7. * Copyright (C) Waveshare August 10 2017
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documnetation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #include "epdif.h"
  28. #include <spi.h>
  29. EpdIf::EpdIf() {
  30. };
  31. EpdIf::~EpdIf() {
  32. };
  33. void EpdIf::DigitalWrite(int pin, int value) {
  34. digitalWrite(pin, value);
  35. }
  36. int EpdIf::DigitalRead(int pin) {
  37. return digitalRead(pin);
  38. }
  39. void EpdIf::DelayMs(unsigned int delaytime) {
  40. delay(delaytime);
  41. }
  42. void EpdIf::SpiTransfer(unsigned char data) {
  43. digitalWrite(CS_PIN, LOW);
  44. SPI.transfer(data);
  45. digitalWrite(CS_PIN, HIGH);
  46. }
  47. int EpdIf::IfInit(void) {
  48. pinMode(CS_PIN, OUTPUT);
  49. pinMode(RST_PIN, OUTPUT);
  50. pinMode(DC_PIN, OUTPUT);
  51. pinMode(BUSY_PIN, INPUT);
  52. pinMode(PWR_PIN, OUTPUT);
  53. DigitalWrite(PWR_PIN, 1);
  54. SPI.begin();
  55. SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
  56. return 0;
  57. }