config.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # /*****************************************************************************
  2. # * | File : config.py
  3. # * | Author : Waveshare team
  4. # * | Function : Hardware underlying interface,for Raspberry pi
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.0
  8. # * | Date : 2020-06-17
  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 smbus
  32. import spidev
  33. import ctypes
  34. # Pin definition
  35. RST_PIN = 27
  36. DC_PIN = 25
  37. CS_PIN = 8
  38. Device_SPI = 1
  39. Device_I2C = 0
  40. if(Device_SPI == 1):
  41. Device = Device_SPI
  42. spi = spidev.SpiDev(0,1)
  43. else :
  44. Device = Device_I2C
  45. address = 0x3c
  46. bus = smbus.SMBus(1)
  47. def delay_ms(delaytime):
  48. time.sleep(delaytime / 1000.0)
  49. def spi_writebyte(data):
  50. spi.writebytes([data[0]])
  51. def i2c_writebyte(reg, value):
  52. bus.write_byte_data(address, reg, value)
  53. def module_init():
  54. #print("module_init")
  55. GPIO.setmode(GPIO.BCM)
  56. GPIO.setwarnings(False)
  57. GPIO.setup(RST_PIN, GPIO.OUT)
  58. GPIO.setup(DC_PIN, GPIO.OUT)
  59. GPIO.setup(CS_PIN, GPIO.OUT)
  60. GPIO.output(RST_PIN, 0)
  61. if(Device == Device_SPI):
  62. spi.max_speed_hz = 1000000
  63. spi.mode = 0b11
  64. GPIO.output(CS_PIN, 0)
  65. GPIO.output(DC_PIN, 0)
  66. return 0
  67. def module_exit():
  68. if(Device == Device_SPI):
  69. spi.close()
  70. else :
  71. bus.close()
  72. GPIO.output(RST_PIN, 0)
  73. GPIO.output(DC_PIN, 0)
  74. GPIO.output(PWR_PIN, 0)
  75. ### END OF FILE ###