| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | # /***************************************************************************** | 
					
						
							|  |  |  | # * | File        :	  epdconfig.py | 
					
						
							|  |  |  | # * | Author      :   Waveshare electrices | 
					
						
							|  |  |  | # * | Function    :   Hardware underlying interface | 
					
						
							|  |  |  | # * | Info        : | 
					
						
							|  |  |  | # *---------------- | 
					
						
							|  |  |  | # * |	This version:   V1.0 | 
					
						
							|  |  |  | # * | Date        :   2019-11-01 | 
					
						
							|  |  |  | # * | Info        :    | 
					
						
							|  |  |  | # ******************************************************************************/ | 
					
						
							|  |  |  | # Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  | # of this software and associated documnetation files (the "Software"), to deal | 
					
						
							|  |  |  | # in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  | # copies of the Software, and to permit persons to  whom the Software is | 
					
						
							|  |  |  | # furished to do so, subject to the following conditions: | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  | # all copies or substantial portions of the Software. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  | # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  | # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  | # THE SOFTWARE. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | import RPi.GPIO as GPIO | 
					
						
							|  |  |  | import time | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import logging | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from ctypes import * | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | EPD_SCK_PIN = 11 | 
					
						
							|  |  |  | EPD_MOSI_PIN = 10 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EPD_M1_CS_PIN = 8 | 
					
						
							|  |  |  | EPD_S1_CS_PIN = 7 | 
					
						
							|  |  |  | EPD_M2_CS_PIN = 17 | 
					
						
							|  |  |  | EPD_S2_CS_PIN = 18 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EPD_M1S1_DC_PIN = 13 | 
					
						
							|  |  |  | EPD_M2S2_DC_PIN = 22 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EPD_M1S1_RST_PIN = 6 | 
					
						
							|  |  |  | EPD_M2S2_RST_PIN = 23 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EPD_M1_BUSY_PIN = 5 | 
					
						
							|  |  |  | EPD_S1_BUSY_PIN = 19 | 
					
						
							|  |  |  | EPD_M2_BUSY_PIN = 27 | 
					
						
							|  |  |  | EPD_S2_BUSY_PIN = 24 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | find_dirs = [ | 
					
						
							|  |  |  |     os.path.dirname(os.path.realpath(__file__)), | 
					
						
							|  |  |  |     '/usr/local/lib', | 
					
						
							|  |  |  |     '/usr/lib', | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | spi = None | 
					
						
							|  |  |  | for find_dir in find_dirs: | 
					
						
							|  |  |  |     so_filename = os.path.join(find_dir, 'epd_12_in_48_lib.so') | 
					
						
							|  |  |  |     if os.path.exists(so_filename): | 
					
						
							|  |  |  |         spi = CDLL(so_filename) | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  | if spi is None: | 
					
						
							|  |  |  |     RuntimeError('Cannot find epd_12_in_48_lib.so') | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def digital_write(pin, value): | 
					
						
							|  |  |  |     GPIO.output(pin, value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def digital_read(pin): | 
					
						
							|  |  |  |     return GPIO.input(pin) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def spi_writebyte(value): | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     spi.DEV_SPI_WriteByte(value) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def delay_ms(delaytime): | 
					
						
							|  |  |  |     time.sleep(delaytime / 1000.0) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def module_init(): | 
					
						
							|  |  |  |     GPIO.setmode(GPIO.BCM) | 
					
						
							|  |  |  |     GPIO.setwarnings(False) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |     GPIO.setup(EPD_SCK_PIN, GPIO.OUT) | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     GPIO.setup(EPD_MOSI_PIN, GPIO.OUT) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     logging.debug("python call wiringPi Lib") | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     GPIO.setup(EPD_M2S2_RST_PIN, GPIO.OUT) | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     GPIO.setup(EPD_M1S1_RST_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M2S2_DC_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M1S1_DC_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_S1_CS_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_S2_CS_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M1_CS_PIN, GPIO.OUT) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M2_CS_PIN, GPIO.OUT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     GPIO.setup(EPD_S1_BUSY_PIN, GPIO.IN) | 
					
						
							|  |  |  |     GPIO.setup(EPD_S2_BUSY_PIN, GPIO.IN) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M1_BUSY_PIN, GPIO.IN) | 
					
						
							|  |  |  |     GPIO.setup(EPD_M2_BUSY_PIN, GPIO.IN) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     digital_write(EPD_M1_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_S1_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_M2_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_S2_CS_PIN, 1) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     digital_write(EPD_M2S2_RST_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_M1S1_RST_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_M2S2_DC_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_M1S1_DC_PIN, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     spi.DEV_ModuleInit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def module_exit(): | 
					
						
							|  |  |  |     digital_write(EPD_M2S2_RST_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_M1S1_RST_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_M2S2_DC_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_M1S1_DC_PIN, 0) | 
					
						
							|  |  |  |     digital_write(EPD_S1_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_S2_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_M1_CS_PIN, 1) | 
					
						
							|  |  |  |     digital_write(EPD_M2_CS_PIN, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def spi_readbyte(Reg): | 
					
						
							|  |  |  |     GPIO.setup(EPD_MOSI_PIN, GPIO.IN) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |     j = 0 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |     # time.sleep(0.01) | 
					
						
							|  |  |  |     for i in range(0, 8): | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |         GPIO.output(EPD_SCK_PIN, GPIO.LOW) | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |         # time.sleep(0.01)  | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |         j = j << 1 | 
					
						
							|  |  |  |         if (GPIO.input(EPD_MOSI_PIN) == GPIO.HIGH): | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |             j |= 0x01 | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |             j &= 0xfe | 
					
						
							|  |  |  |             # time.sleep(0.01) | 
					
						
							|  |  |  |         GPIO.output(EPD_SCK_PIN, GPIO.HIGH) | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  |         # time.sleep(0.01)   | 
					
						
							|  |  |  |     GPIO.setup(EPD_MOSI_PIN, GPIO.OUT) | 
					
						
							| 
									
										
										
										
											2023-01-10 22:58:01 +01:00
										 |  |  |     return j | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 17:46:30 +02:00
										 |  |  | def delay_ms(delaytime): | 
					
						
							|  |  |  |     time.sleep(delaytime / 1000.0) |