epdif.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @filename : epdif.c
  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 July 7 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 "luat_gpio.h"
  29. #include "luat_spi.h"
  30. //#include "main.h"
  31. // #define SPI_CS_GPIO_Port 0
  32. // #define RST_GPIO_Port 0
  33. // #define DC_GPIO_Port 0
  34. // #define BUSY_GPIO_Port 0
  35. // #define BUSY_Pin (18)
  36. // #define RST_Pin (7)
  37. // #define DC_Pin (9)
  38. // #define SPI_CS_Pin (16)
  39. // #define SPI_ID (0)
  40. //extern SPI_HandleTypeDef hspi1;
  41. // EPD_Pin epd_cs_pin = {
  42. // SPI_CS_GPIO_Port
  43. // };
  44. // EPD_Pin epd_rst_pin = {
  45. // RST_GPIO_Port
  46. // };
  47. // EPD_Pin epd_dc_pin = {
  48. // DC_GPIO_Port
  49. // };
  50. // EPD_Pin epd_busy_pin = {
  51. // BUSY_GPIO_Port
  52. // };
  53. EPD_Pin pins[4];
  54. void EpdDigitalWriteCallback(int pin_num, int value) {
  55. if (value == HIGH) {
  56. // HAL_GPIO_WritePin((GPIO_TypeDef*)pins[pin_num].port, pins[pin_num].pin, GPIO_PIN_SET);
  57. luat_gpio_set(pins[pin_num].port, Luat_GPIO_HIGH);
  58. } else {
  59. // HAL_GPIO_WritePin((GPIO_TypeDef*)pins[pin_num].port, pins[pin_num].pin, GPIO_PIN_RESET);
  60. luat_gpio_set(pins[pin_num].port, Luat_GPIO_LOW);
  61. }
  62. }
  63. int EpdDigitalReadCallback(int pin_num) {
  64. // if (HAL_GPIO_ReadPin(pins[pin_num].port, pins[pin_num].pin) == GPIO_PIN_SET) {
  65. // return HIGH;
  66. // } else {
  67. // return LOW;
  68. // }
  69. if (luat_gpio_get(pins[pin_num].port) == Luat_GPIO_HIGH) {
  70. return HIGH;
  71. } else {
  72. return LOW;
  73. }
  74. }
  75. void EpdDelayMsCallback(unsigned int delaytime) {
  76. // HAL_Delay(delaytime);
  77. while(delaytime--)
  78. {
  79. luat_timer_us_delay(1000);
  80. }
  81. }
  82. void EpdSpiTransferCallback(unsigned char data) {
  83. // HAL_GPIO_WritePin((GPIO_TypeDef*)pins[CS_PIN].port, pins[CS_PIN].pin, GPIO_PIN_RESET);
  84. // HAL_SPI_Transmit(&hspi1, &data, 1, 1000);
  85. // HAL_GPIO_WritePin((GPIO_TypeDef*)pins[CS_PIN].port, pins[CS_PIN].pin, GPIO_PIN_SET);
  86. luat_gpio_set(pins[CS_PIN].port, Luat_GPIO_LOW);
  87. luat_spi_send(EPD_SPI_ID, (char *)&data, 1);
  88. luat_gpio_set(pins[CS_PIN].port, Luat_GPIO_HIGH);
  89. }
  90. int EpdInitCallback(void) {
  91. pins[CS_PIN].port = EPD_CS_PIN;
  92. pins[RST_PIN].port = EPD_RST_PIN;
  93. pins[DC_PIN].port = EPD_DC_PIN;
  94. pins[BUSY_PIN].port = EPD_BUSY_PIN;
  95. return 0;
  96. }