epdconfig.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # /*****************************************************************************
  2. # * | File : epdconfig.py
  3. # * | Author : Waveshare electrices
  4. # * | Function : Hardware underlying interface
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.0
  8. # * | Date : 2019-11-01
  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 time
  30. import os
  31. import logging
  32. import sys
  33. from ctypes import *
  34. import ctypes
  35. EPD_SCK_PIN =11
  36. EPD_MOSI_PIN =10
  37. EPD_CS_M_PIN =8
  38. EPD_CS_S_PIN =7
  39. EPD_DC_PIN =25
  40. EPD_RST_PIN =17
  41. EPD_BUSY_PIN =24
  42. EPD_PWR_PIN =18
  43. find_dirs = [
  44. os.path.dirname(os.path.realpath(__file__)),
  45. '/usr/local/lib',
  46. '/usr/lib',
  47. ]
  48. spi = None
  49. for find_dir in find_dirs:
  50. val = int(os.popen('getconf LONG_BIT').read())
  51. val_1 = os.popen("cat /proc/cpuinfo | grep 'Raspberry Pi 5'").read()
  52. if val == 64:
  53. if val_1 == "":
  54. so_filename = os.path.join(find_dir, 'DEV_Config_64_b.so')
  55. else:
  56. so_filename = os.path.join(find_dir, 'DEV_Config_64_w.so')
  57. else:
  58. if val_1 == "":
  59. so_filename = os.path.join(find_dir, 'DEV_Config_32_b.so')
  60. else:
  61. so_filename = os.path.join(find_dir, 'DEV_Config_32_w.so')
  62. if os.path.exists(so_filename):
  63. spi = CDLL(so_filename)
  64. break
  65. if spi is None:
  66. RuntimeError('Cannot find DEV_Config.so')
  67. def digital_write(pin, value):
  68. spi.DEV_Digital_Write(pin, value)
  69. def digital_read(pin):
  70. return spi.DEV_Digital_Read(pin)
  71. def spi_writebyte(value):
  72. spi.DEV_SPI_SendData(value)
  73. def spi_writebyte2(buf, len):
  74. array_data = (ctypes.c_ubyte * len)(*buf)
  75. spi.DEV_SPI_SendData_nByte(array_data, ctypes.c_ulong(len))
  76. def delay_ms(delaytime):
  77. time.sleep(delaytime / 1000.0)
  78. def module_init():
  79. spi.DEV_ModuleInit()
  80. def module_exit():
  81. spi.DEV_ModuleExit()