DEV_Config.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*****************************************************************************
  2. * | File : DEV_Config.c
  3. * | Author : Waveshare team
  4. * | Function : Hardware underlying interface
  5. * | Info :
  6. * Used to shield the underlying layers of each master
  7. * and enhance portability
  8. *----------------
  9. * | This version: V2.0
  10. * | Date : 2018-10-30
  11. * | Info :
  12. * 1.add:
  13. * UBYTE\UWORD\UDOUBLE
  14. * 2.Change:
  15. * EPD_RST -> EPD_RST_PIN
  16. * EPD_DC -> EPD_DC_PIN
  17. * EPD_CS -> EPD_CS_PIN
  18. * EPD_BUSY -> EPD_BUSY_PIN
  19. * 3.Remote:
  20. * EPD_RST_1\EPD_RST_0
  21. * EPD_DC_1\EPD_DC_0
  22. * EPD_CS_1\EPD_CS_0
  23. * EPD_BUSY_1\EPD_BUSY_0
  24. * 4.add:
  25. * #define DEV_Digital_Write(_pin, _value) bcm2835_gpio_write(_pin, _value)
  26. * #define DEV_Digital_Read(_pin) bcm2835_gpio_lev(_pin)
  27. * #define DEV_SPI_WriteByte(__value) bcm2835_spi_transfer(__value)
  28. #
  29. # Permission is hereby granted, free of charge, to any person obtaining a copy
  30. # of this software and associated documnetation files (the "Software"), to deal
  31. # in the Software without restriction, including without limitation the rights
  32. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  33. # copies of the Software, and to permit persons to whom the Software is
  34. # furished to do so, subject to the following conditions:
  35. #
  36. # The above copyright notice and this permission notice shall be included in
  37. # all copies or substantial portions of the Software.
  38. #
  39. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  40. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  41. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  42. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  43. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  44. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  45. # THE SOFTWARE.
  46. #
  47. ******************************************************************************/
  48. #include "DEV_Config.h"
  49. /******************************************************************************
  50. function: Initialization pin
  51. parameter:
  52. Info:
  53. ******************************************************************************/
  54. static void DEV_GPIOConfig(void)
  55. {
  56. //output
  57. bcm2835_gpio_fsel(EPD_RST_PIN, BCM2835_GPIO_FSEL_OUTP);
  58. bcm2835_gpio_fsel(EPD_DC_PIN, BCM2835_GPIO_FSEL_OUTP);
  59. bcm2835_gpio_fsel(EPD_CS_PIN, BCM2835_GPIO_FSEL_OUTP);
  60. //intput
  61. bcm2835_gpio_fsel(EPD_BUSY_PIN, BCM2835_GPIO_FSEL_INPT);
  62. }
  63. /******************************************************************************
  64. function: Module Initialize, the BCM2835 library and initialize the pins, SPI protocol
  65. parameter:
  66. Info:
  67. ******************************************************************************/
  68. UBYTE DEV_ModuleInit(void)
  69. {
  70. if(!bcm2835_init()) {
  71. printf("bcm2835 init failed !!! \r\n");
  72. return 1;
  73. } else {
  74. printf("bcm2835 init success !!! \r\n");
  75. }
  76. DEV_GPIOConfig();
  77. bcm2835_spi_begin(); //Start spi interface, set spi pin for the reuse function
  78. bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //High first transmission
  79. bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); //spi mode 0
  80. bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128); //Frequency
  81. bcm2835_spi_chipSelect(BCM2835_SPI_CS0); //set CE0
  82. bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); //enable cs0
  83. return 0;
  84. }
  85. /******************************************************************************
  86. function: Module exits, closes SPI and BCM2835 library
  87. parameter:
  88. Info:
  89. ******************************************************************************/
  90. void DEV_ModuleExit(void)
  91. {
  92. bcm2835_spi_end();
  93. bcm2835_close();
  94. }