epdconfig.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # /*****************************************************************************
  2. # * | File : epdconfig.py
  3. # * | Author : Waveshare team
  4. # * | Function : Hardware underlying interface
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.0
  8. # * | Date : 2019-06-06
  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. import Jetson.GPIO as GPIO
  30. import time
  31. import ctypes
  32. # import spidev
  33. # Pin definition
  34. RST_PIN = 17
  35. DC_PIN = 25
  36. CS_PIN = 8
  37. BUSY_PIN = 24
  38. # SPI device, bus = 0, device = 0
  39. # SPI = spidev.SpiDev(0, 0)
  40. clib = ctypes.cdll.LoadLibrary
  41. spi = clib('../lib/sysfs_software_spi.so')
  42. # gpio2 = clib('../lib/sysfs_gpio.so')
  43. def digital_write(pin, value):
  44. GPIO.output(pin, value)
  45. def digital_read(pin):
  46. return GPIO.input(BUSY_PIN)
  47. # return gpio2.SYSFS_GPIO_Read(15)
  48. def delay_ms(delaytime):
  49. time.sleep(delaytime / 1000.0)
  50. def spi_writebyte(data):
  51. # SPI.writebytes(data)
  52. spi.SYSFS_software_spi_transfer(data[0])
  53. def module_init():
  54. # print("module_init")
  55. GPIO.setmode(GPIO.BCM)
  56. GPIO.setwarnings(False)
  57. # print("RST_PIN")
  58. GPIO.setup(RST_PIN, GPIO.OUT)
  59. # print("DC_PIN")
  60. GPIO.setup(DC_PIN, GPIO.OUT)
  61. # print("CS_PIN")
  62. GPIO.setup(CS_PIN, GPIO.OUT)
  63. # print("BUSY_PIN")
  64. GPIO.setup(BUSY_PIN, GPIO.IN)
  65. # SPI.max_speed_hz = 2000000
  66. # SPI.mode = 0b00
  67. # gpio2.SYSFS_GPIO_Export(15)
  68. # gpio2.SYSFS_GPIO_Direction(15, 0)
  69. spi.SYSFS_software_spi_begin()
  70. return 0
  71. def module_exit():
  72. print("spi end")
  73. spi.SYSFS_software_spi_end()
  74. print("close 5V, Module enters 0 power consumption ...")
  75. GPIO.output(RST_PIN, 0)
  76. GPIO.output(DC_PIN, 0)
  77. GPIO.cleanup()
  78. ### END OF FILE ###