DEV_Config.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*****************************************************************************
  2. * | File : DEV_Config.c
  3. * | Author : Waveshare team
  4. * | Function : Hardware underlying interface
  5. * | Info :
  6. *----------------
  7. * | This version: V1.0
  8. * | Date : 2020-02-19
  9. * | Info :
  10. #
  11. # Permission is hereby granted, free of charge, to any person obtaining a copy
  12. # of this software and associated documnetation files (the "Software"), to deal
  13. # in the Software without restriction, including without limitation the rights
  14. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. # copies of the Software, and to permit persons to whom the Software is
  16. # furished to do so, subject to the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included in
  19. # all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. # THE SOFTWARE.
  28. #
  29. ******************************************************************************/
  30. #include "DEV_Config.h"
  31. void GPIO_Config(void)
  32. {
  33. pinMode(EPD_BUSY_PIN, INPUT);
  34. pinMode(EPD_RST_PIN , OUTPUT);
  35. pinMode(EPD_DC_PIN , OUTPUT);
  36. pinMode(EPD_SCK_PIN, OUTPUT);
  37. pinMode(EPD_MOSI_PIN, OUTPUT);
  38. pinMode(EPD_CS_PIN , OUTPUT);
  39. digitalWrite(EPD_CS_PIN , HIGH);
  40. digitalWrite(EPD_SCK_PIN, LOW);
  41. }
  42. void GPIO_Mode(UWORD GPIO_Pin, UWORD Mode)
  43. {
  44. if(Mode == 0) {
  45. pinMode(GPIO_Pin , INPUT);
  46. } else {
  47. pinMode(GPIO_Pin , OUTPUT);
  48. }
  49. }
  50. /******************************************************************************
  51. function: Module Initialize, the BCM2835 library and initialize the pins, SPI protocol
  52. parameter:
  53. Info:
  54. ******************************************************************************/
  55. UBYTE DEV_Module_Init(void)
  56. {
  57. //gpio
  58. GPIO_Config();
  59. //serial printf
  60. Serial.begin(115200);
  61. // spi
  62. // SPI.setDataMode(SPI_MODE0);
  63. // SPI.setBitOrder(MSBFIRST);
  64. // SPI.setClockDivider(SPI_CLOCK_DIV4);
  65. // SPI.begin();
  66. return 0;
  67. }
  68. /******************************************************************************
  69. function:
  70. SPI read and write
  71. ******************************************************************************/
  72. void DEV_SPI_WriteByte(UBYTE data)
  73. {
  74. //SPI.beginTransaction(spi_settings);
  75. digitalWrite(EPD_CS_PIN, GPIO_PIN_RESET);
  76. for (int i = 0; i < 8; i++)
  77. {
  78. if ((data & 0x80) == 0) digitalWrite(EPD_MOSI_PIN, GPIO_PIN_RESET);
  79. else digitalWrite(EPD_MOSI_PIN, GPIO_PIN_SET);
  80. data <<= 1;
  81. digitalWrite(EPD_SCK_PIN, GPIO_PIN_SET);
  82. digitalWrite(EPD_SCK_PIN, GPIO_PIN_RESET);
  83. }
  84. //SPI.transfer(data);
  85. digitalWrite(EPD_CS_PIN, GPIO_PIN_SET);
  86. //SPI.endTransaction();
  87. }
  88. UBYTE DEV_SPI_ReadByte()
  89. {
  90. UBYTE j=0xff;
  91. GPIO_Mode(EPD_MOSI_PIN, 0);
  92. digitalWrite(EPD_CS_PIN, GPIO_PIN_RESET);
  93. for (int i = 0; i < 8; i++)
  94. {
  95. j = j << 1;
  96. if (digitalRead(EPD_MOSI_PIN)) j = j | 0x01;
  97. else j = j & 0xfe;
  98. digitalWrite(EPD_SCK_PIN, GPIO_PIN_SET);
  99. digitalWrite(EPD_SCK_PIN, GPIO_PIN_RESET);
  100. }
  101. digitalWrite(EPD_CS_PIN, GPIO_PIN_SET);
  102. GPIO_Mode(EPD_MOSI_PIN, 1);
  103. return j;
  104. }
  105. void DEV_SPI_Write_nByte(UBYTE *pData, UDOUBLE len)
  106. {
  107. for (int i = 0; i < len; i++)
  108. DEV_SPI_WriteByte(pData[i]);
  109. }
  110. void DEV_Module_Exit(void)
  111. {
  112. }