DEV_Config.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 : 2019-06-05
  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. /******************************************************************************
  32. function: Initialization pin
  33. parameter:
  34. Info:
  35. ******************************************************************************/
  36. static void DEV_GPIOConfig(void)
  37. {
  38. SYSFS_GPIO_Export(EPD_CS_PIN);
  39. SYSFS_GPIO_Export(EPD_DC_PIN);
  40. SYSFS_GPIO_Export(EPD_RST_PIN);
  41. SYSFS_GPIO_Export(EPD_BUSY_PIN);
  42. SYSFS_GPIO_Direction(EPD_CS_PIN, OUT);
  43. SYSFS_GPIO_Direction(EPD_DC_PIN, OUT);
  44. SYSFS_GPIO_Direction(EPD_RST_PIN, OUT);
  45. SYSFS_GPIO_Direction(EPD_BUSY_PIN, IN);
  46. }
  47. void DEV_Delay_us(UWORD xus)
  48. {
  49. for(int j=xus; j > 0; j--);
  50. }
  51. void DEV_Delay_ms(UWORD xms)
  52. {
  53. for(int j=xms; j > 0; j--)
  54. for(int j=xms; j > 0; j--);
  55. }
  56. /******************************************************************************
  57. function: Module Initialize, the BCM2835 library and initialize the pins, SPI protocol
  58. parameter:
  59. Info:
  60. ******************************************************************************/
  61. UBYTE DEV_Module_Init(void)
  62. {
  63. DEV_GPIOConfig();
  64. SYSFS_software_spi_begin();
  65. SYSFS_software_spi_setBitOrder(SOFTWARE_SPI_MSBFIRST);
  66. SYSFS_software_spi_setDataMode(SOFTWARE_SPI_Mode0);
  67. SYSFS_software_spi_setClockDivider(SOFTWARE_SPI_CLOCK_DIV4);
  68. return 0;
  69. }
  70. void DEV_SPI_WriteByte(UBYTE value)
  71. {
  72. SYSFS_software_spi_transfer(value);
  73. }
  74. /******************************************************************************
  75. function: Module exits, closes SPI and BCM2835 library
  76. parameter:
  77. Info:
  78. ******************************************************************************/
  79. void DEV_Module_Exit(void)
  80. {
  81. SYSFS_software_spi_end();
  82. SYSFS_GPIO_Write(EPD_CS_PIN, LOW);
  83. SYSFS_GPIO_Write(EPD_DC_PIN, LOW);
  84. SYSFS_GPIO_Write(EPD_RST_PIN, LOW);
  85. SYSFS_GPIO_Unexport(EPD_CS_PIN);
  86. SYSFS_GPIO_Unexport(EPD_DC_PIN);
  87. SYSFS_GPIO_Unexport(EPD_RST_PIN);
  88. SYSFS_GPIO_Unexport(EPD_BUSY_PIN);
  89. }