LCD_Config.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding:UTF-8 -*-
  2. ##
  3. # @filename : DEV_Config.py
  4. # @brief : LCD hardware interface implements (GPIO, SPI)
  5. # @author : Yehui from Waveshare
  6. #
  7. # Copyright (C) Waveshare July 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. import spidev
  28. import RPi.GPIO as GPIO
  29. import time
  30. # Pin definition
  31. LCD_RST_PIN = 27
  32. LCD_DC_PIN = 25
  33. LCD_CS_PIN = 8
  34. LCD_BL_PIN = 24
  35. # SPI device, bus = 0, device = 0
  36. SPI = spidev.SpiDev(0, 0)
  37. def epd_digital_write(pin, value):
  38. GPIO.output(pin, value)
  39. def Driver_Delay_ms(xms):
  40. time.sleep(xms / 1000.0)
  41. def SPI_Write_Byte(data):
  42. SPI.writebytes(data)
  43. def GPIO_Init():
  44. GPIO.setmode(GPIO.BCM)
  45. GPIO.setwarnings(False)
  46. GPIO.setup(LCD_RST_PIN, GPIO.OUT)
  47. GPIO.setup(LCD_DC_PIN, GPIO.OUT)
  48. GPIO.setup(LCD_CS_PIN, GPIO.OUT)
  49. GPIO.setup(LCD_BL_PIN, GPIO.OUT)
  50. SPI.max_speed_hz = 9000000
  51. SPI.mode = 0b00
  52. return 0;
  53. ### END OF FILE ###