Advertisement
Guest User

MicroPython driver for Waveshare 1.54" BWR e-Paper display for NUCLEO-F767ZI

a guest
Jul 25th, 2021
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.14 KB | None | 0 0
  1. #!/bin/sh
  2. # This is a shell archive (produced by GNU sharutils 4.15.2).
  3. # To extract the files from this archive, save it to some FILE, remove
  4. # everything before the '#!/bin/sh' line above, then type 'sh FILE'.
  5. #
  6. lock_dir=_sh14997
  7. # Made on 2021-07-25 20:00 CEST by <emb@WZabHP>.
  8. # Source directory was '/home/emb/ePaper/wz'.
  9. #
  10. # Existing files will *not* be overwritten, unless '-c' is specified.
  11. #
  12. # This shar contains:
  13. # length mode name
  14. # ------ ---------- ------------------------------------------
  15. # 6327 -rw-r--r-- epd1in54b_V2.py
  16. # 2361 -rw-r--r-- epdconfig.py
  17. # 831 -rw-r--r-- epd_test.py
  18. #
  19. MD5SUM=${MD5SUM-md5sum}
  20. f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
  21. test -n "${f}" && md5check=true || md5check=false
  22. ${md5check} || \
  23. echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
  24. if test "X$1" = "X-c"
  25. then keep_file=''
  26. else keep_file=true
  27. fi
  28. echo=echo
  29. save_IFS="${IFS}"
  30. IFS="${IFS}:"
  31. gettext_dir=
  32. locale_dir=
  33. set_echo=false
  34.  
  35. for dir in $PATH
  36. do
  37. if test -f $dir/gettext \
  38. && ($dir/gettext --version >/dev/null 2>&1)
  39. then
  40. case `$dir/gettext --version 2>&1 | sed 1q` in
  41. *GNU*) gettext_dir=$dir
  42. set_echo=true
  43. break ;;
  44. esac
  45. fi
  46. done
  47.  
  48. if ${set_echo}
  49. then
  50. set_echo=false
  51. for dir in $PATH
  52. do
  53. if test -f $dir/shar \
  54. && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  55. then
  56. locale_dir=`$dir/shar --print-text-domain-dir`
  57. set_echo=true
  58. break
  59. fi
  60. done
  61.  
  62. if ${set_echo}
  63. then
  64. TEXTDOMAINDIR=$locale_dir
  65. export TEXTDOMAINDIR
  66. TEXTDOMAIN=sharutils
  67. export TEXTDOMAIN
  68. echo="$gettext_dir/gettext -s"
  69. fi
  70. fi
  71. IFS="$save_IFS"
  72. if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
  73. then if (echo -n test; echo 1,2,3) | grep n >/dev/null
  74. then shar_n= shar_c='
  75. '
  76. else shar_n=-n shar_c= ; fi
  77. else shar_n= shar_c='\c' ; fi
  78. f=shar-touch.$$
  79. st1=200112312359.59
  80. st2=123123592001.59
  81. st2tr=123123592001.5 # old SysV 14-char limit
  82. st3=1231235901
  83.  
  84. if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
  85. test ! -f ${st1} && test -f ${f}; then
  86. shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
  87.  
  88. elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
  89. test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
  90. shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
  91.  
  92. elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
  93. test ! -f ${st3} && test -f ${f}; then
  94. shar_touch='touch -am $3$4$5$6$2 "$8"'
  95.  
  96. else
  97. shar_touch=:
  98. echo
  99. ${echo} 'WARNING: not restoring timestamps. Consider getting and
  100. installing GNU '\''touch'\'', distributed in GNU coreutils...'
  101. echo
  102. fi
  103. rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
  104. #
  105. if test ! -d ${lock_dir} ; then :
  106. else ${echo} "lock directory ${lock_dir} exists"
  107. exit 1
  108. fi
  109. if mkdir ${lock_dir}
  110. then ${echo} "x - created lock directory ${lock_dir}."
  111. else ${echo} "x - failed to create lock directory ${lock_dir}."
  112. exit 1
  113. fi
  114. # ============= epd1in54b_V2.py ==============
  115. if test -n "${keep_file}" && test -f 'epd1in54b_V2.py'
  116. then
  117. ${echo} "x - SKIPPING epd1in54b_V2.py (file already exists)"
  118.  
  119. else
  120. ${echo} "x - extracting epd1in54b_V2.py (text)"
  121. sed 's/^X//' << 'SHAR_EOF' > 'epd1in54b_V2.py' &&
  122. # *****************************************************************************
  123. # * | File : epd1in54b.py
  124. # * | Author : Waveshare team
  125. # * | Function : Electronic paper driver
  126. # * | Info :
  127. # *----------------
  128. # * | This version: V4.0
  129. # * | Date : 2019-06-20
  130. # # | Info : python demo
  131. # -----------------------------------------------------------------------------
  132. # Permission is hereby granted, free of charge, to any person obtaining a copy
  133. # of this software and associated documnetation files (the "Software"), to deal
  134. # in the Software without restriction, including without limitation the rights
  135. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  136. # copies of the Software, and to permit persons to whom the Software is
  137. # furished to do so, subject to the following conditions:
  138. #
  139. # The above copyright notice and this permission notice shall be included in
  140. # all copies or substantial portions of the Software.
  141. #
  142. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  143. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  144. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  145. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  146. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  147. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  148. # THE SOFTWARE.
  149. #
  150. X
  151. #import logging
  152. import epdconfig
  153. epdconfig = epdconfig.F767()
  154. # Display resolution
  155. EPD_WIDTH = 200
  156. EPD_HEIGHT = 200
  157. X
  158. class EPD:
  159. X def __init__(self):
  160. X self.reset_pin = epdconfig.RST_PIN
  161. X self.dc_pin = epdconfig.DC_PIN
  162. X self.busy_pin = epdconfig.BUSY_PIN
  163. X self.cs_pin = epdconfig.CS_PIN
  164. X self.width = EPD_WIDTH
  165. X self.height = EPD_HEIGHT
  166. X
  167. X
  168. X # Hardware reset
  169. X def reset(self):
  170. X epdconfig.digital_write(self.reset_pin, 1)
  171. X epdconfig.delay_ms(200)
  172. X epdconfig.digital_write(self.reset_pin, 0) # module reset
  173. X epdconfig.delay_ms(5)
  174. X epdconfig.digital_write(self.reset_pin, 1)
  175. X epdconfig.delay_ms(200)
  176. X
  177. X def send_command(self, command):
  178. X epdconfig.digital_write(self.dc_pin, 0)
  179. X epdconfig.digital_write(self.cs_pin, 0)
  180. X epdconfig.spi_writebyte([command])
  181. X epdconfig.digital_write(self.cs_pin, 1)
  182. X
  183. X def send_data(self, data):
  184. X epdconfig.digital_write(self.dc_pin, 1)
  185. X epdconfig.digital_write(self.cs_pin, 0)
  186. X epdconfig.spi_writebyte([data])
  187. X epdconfig.digital_write(self.cs_pin, 1)
  188. X
  189. X def ReadBusy(self):
  190. X #logging.debug("e-Paper busy")
  191. X while(epdconfig.digital_read(self.busy_pin) == 1):
  192. X epdconfig.delay_ms(100)
  193. X #logging.debug("e-Paper busy release")
  194. X
  195. X def init(self):
  196. X if (epdconfig.module_init() != 0):
  197. X return -1
  198. X # EPD hardware init start
  199. X self.reset()
  200. X
  201. X self.ReadBusy()
  202. X self.send_command(0x12) #SWRESET
  203. X self.ReadBusy()
  204. X
  205. X self.send_command(0x01) #Driver output control
  206. X self.send_data(0xC7)
  207. X self.send_data(0x00)
  208. X self.send_data(0x01)
  209. X
  210. X self.send_command(0x11) #data entry mode
  211. X self.send_data(0x01)
  212. X
  213. X self.send_command(0x44) #set Ram-X address start/end position
  214. X self.send_data(0x00)
  215. X self.send_data(0x18) #0x18-->(24+1)*8=200
  216. X
  217. X self.send_command(0x45) #set Ram-Y address start/end position
  218. X self.send_data(0xC7) #0xC7-->(199+1)=200
  219. X self.send_data(0x00)
  220. X self.send_data(0x00)
  221. X self.send_data(0x00)
  222. X
  223. X self.send_command(0x3C) #BorderWavefrom
  224. X self.send_data(0x05)
  225. X
  226. X self.send_command(0x18) #Read built-in temperature sensor
  227. X self.send_data(0x80)
  228. X
  229. X self.send_command(0x4E) # set RAM x address count to 0
  230. X self.send_data(0x00)
  231. X self.send_command(0x4F) # set RAM y address count to 0X199
  232. X self.send_data(0xC7)
  233. X self.send_data(0x00)
  234. X self.ReadBusy()
  235. X return 0
  236. X
  237. X def getbuffer(self, image):
  238. X buf = [0xFF] * int(self.width * self.height / 8)
  239. X # Set buffer to value of Python Imaging Library image.
  240. X # Image must be in mode 1.
  241. X image_monocolor = image.convert('1')
  242. X imwidth, imheight = image_monocolor.size
  243. X if imwidth != self.width or imheight != self.height:
  244. X raise ValueError('Image must be same dimensions as display \
  245. X ({0}x{1}).' .format(self.width, self.height))
  246. X
  247. X pixels = image_monocolor.load()
  248. X for y in range(self.height):
  249. X for x in range(self.width):
  250. X # Set the bits for the column of pixels at the current position.
  251. X if pixels[x, y] == 0:
  252. X buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8))
  253. X return buf
  254. X
  255. X def display(self, blackimage, redimage):
  256. X # send black data
  257. X if (blackimage != None):
  258. X self.send_command(0x24) # DATA_START_TRANSMISSION_1
  259. X for i in range(0, int(self.width * self.height / 8)):
  260. X self.send_data(blackimage[i])
  261. X
  262. X # send red data
  263. X if (redimage != None):
  264. X self.send_command(0x26) # DATA_START_TRANSMISSION_2
  265. X for i in range(0, int(self.width * self.height / 8)):
  266. X self.send_data(~redimage[i])
  267. X
  268. X self.send_command(0x22) # DISPLAY_REFRESH
  269. X self.send_data(0xF7)
  270. X self.send_command(0x20) # DISPLAY_REFRESH
  271. X self.ReadBusy()
  272. X
  273. X def Clear(self):
  274. X self.send_command(0x24) # DATA_START_TRANSMISSION_1
  275. X for i in range(0, int(self.width * self.height / 8)):
  276. X self.send_data(0xFF)
  277. X
  278. X self.send_command(0x26) # DATA_START_TRANSMISSION_2
  279. X for i in range(0, int(self.width * self.height / 8)):
  280. X self.send_data(0x00)
  281. X
  282. X self.send_command(0x22) # DISPLAY_REFRESH
  283. X self.send_data(0xF7)
  284. X self.send_command(0x20) # DISPLAY_REFRESH
  285. X self.ReadBusy()
  286. X
  287. X
  288. X def sleep(self):
  289. X self.send_command(0x10) #enter deep sleep
  290. X self.send_data(0x01)
  291. X
  292. X epdconfig.delay_ms(2000)
  293. X epdconfig.module_exit()
  294. X
  295. ### END OF FILE ###
  296. SHAR_EOF
  297. (set 20 21 07 25 19 50 18 'epd1in54b_V2.py'
  298. eval "${shar_touch}") && \
  299. chmod 0644 'epd1in54b_V2.py'
  300. if test $? -ne 0
  301. then ${echo} "restore of epd1in54b_V2.py failed"
  302. fi
  303. if ${md5check}
  304. then (
  305. ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'epd1in54b_V2.py': 'MD5 check failed'
  306. ) << \SHAR_EOF
  307. 14c986a2a491db78ff7b1d88d5e6da82 epd1in54b_V2.py
  308. SHAR_EOF
  309.  
  310. else
  311. test `LC_ALL=C wc -c < 'epd1in54b_V2.py'` -ne 6327 && \
  312. ${echo} "restoration warning: size of 'epd1in54b_V2.py' is not 6327"
  313. fi
  314. fi
  315. # ============= epdconfig.py ==============
  316. if test -n "${keep_file}" && test -f 'epdconfig.py'
  317. then
  318. ${echo} "x - SKIPPING epdconfig.py (file already exists)"
  319.  
  320. else
  321. ${echo} "x - extracting epdconfig.py (text)"
  322. sed 's/^X//' << 'SHAR_EOF' > 'epdconfig.py' &&
  323. # /*****************************************************************************
  324. # * | File : epdconfig.py
  325. # * | Author : Waveshare team
  326. # * | Function : Hardware underlying interface
  327. # * | Info :
  328. # *----------------
  329. # * | This version: V1.0
  330. # * | Date : 2019-06-21
  331. # * | Info :
  332. # ******************************************************************************
  333. # Permission is hereby granted, free of charge, to any person obtaining a copy
  334. # of this software and associated documnetation files (the "Software"), to deal
  335. # in the Software without restriction, including without limitation the rights
  336. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  337. # copies of the Software, and to permit persons to whom the Software is
  338. # furished to do so, subject to the following conditions:
  339. #
  340. # The above copyright notice and this permission notice shall be included in
  341. # all copies or substantial portions of the Software.
  342. #
  343. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  344. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  345. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  346. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  347. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  348. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  349. # THE SOFTWARE.
  350. #
  351. X
  352. import machine as m
  353. import pyb
  354. import time
  355. X
  356. class F767:
  357. X # Pin definition
  358. X RST_PIN = m.Pin(m.Pin.cpu.F8,m.Pin.OUT_PP)
  359. X DC_PIN = m.Pin(m.Pin.cpu.E3,m.Pin.OUT_PP)
  360. X CS_PIN = m.Pin(m.Pin.cpu.E6,m.Pin.OUT_PP)
  361. X BUSY_PIN = m.Pin(m.Pin.cpu.F7,m.Pin.IN)
  362. X
  363. X def __init__(self):
  364. X self.SPI=pyb.SPI(3,pyb.SPI.MASTER, baudrate=4000000, polarity=0, phase=0)
  365. X
  366. X def digital_write(self, pin, value):
  367. X pin(value)
  368. X
  369. X def digital_read(self, pin):
  370. X return pin.value()
  371. X
  372. X def delay_ms(self, delaytime):
  373. X time.sleep(delaytime / 1000.0)
  374. X
  375. X def spi_writebyte(self, data):
  376. X self.SPI.write(bytearray(data))
  377. X
  378. X def module_init(self):
  379. X self.RST_PIN(1)
  380. X self.CS_PIN(1)
  381. X self.DC_PIN(0)
  382. X self.SPI.init(pyb.SPI.MASTER, baudrate=4000000, polarity=0, phase=0)
  383. X
  384. X def module_exit(self):
  385. X self.SPI.deinit()
  386. SHAR_EOF
  387. (set 20 21 07 25 19 53 57 'epdconfig.py'
  388. eval "${shar_touch}") && \
  389. chmod 0644 'epdconfig.py'
  390. if test $? -ne 0
  391. then ${echo} "restore of epdconfig.py failed"
  392. fi
  393. if ${md5check}
  394. then (
  395. ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'epdconfig.py': 'MD5 check failed'
  396. ) << \SHAR_EOF
  397. debb92ff18a3ba416773e7f23a6acf69 epdconfig.py
  398. SHAR_EOF
  399.  
  400. else
  401. test `LC_ALL=C wc -c < 'epdconfig.py'` -ne 2361 && \
  402. ${echo} "restoration warning: size of 'epdconfig.py' is not 2361"
  403. fi
  404. fi
  405. # ============= epd_test.py ==============
  406. if test -n "${keep_file}" && test -f 'epd_test.py'
  407. then
  408. ${echo} "x - SKIPPING epd_test.py (file already exists)"
  409.  
  410. else
  411. ${echo} "x - extracting epd_test.py (text)"
  412. sed 's/^X//' << 'SHAR_EOF' > 'epd_test.py' &&
  413. import epd1in54b_V2 as ep
  414. epd=ep.EPD()
  415. epd.init()
  416. epd.Clear()
  417. h = 200; w = 200 # e-paper heigth and width.
  418. X
  419. buf_black = bytearray(w * h // 8) # used by frame buffer (landscape)
  420. buf_red = bytearray(w * h // 8) # used by frame buffer (landscape)
  421. X
  422. import framebuf
  423. fb_black = framebuf.FrameBuffer(buf_black, w, h, framebuf.MONO_HLSB)
  424. fb_red = framebuf.FrameBuffer(buf_red, w, h, framebuf.MONO_HLSB)
  425. black_red = 0 # will be black on buf_black, red on buf_red
  426. white = 1
  427. X
  428. #clear red & black screens, write in black on top left and in red bootom right
  429. fb_black.fill(white)
  430. fb_red.fill(white)
  431. fb_black.text('Hello world!', 0, 0,black_red)
  432. fb_red.text('Hello world!', 110, 90,black_red)
  433. fb_black.fill_rect(5,20,170,20,black_red)
  434. fb_red.fill_rect(5,150,150,30,black_red)
  435. epd.display(buf_black, buf_red)
  436. epd.sleep()
  437. X
  438. X
  439. SHAR_EOF
  440. (set 20 21 07 25 19 48 23 'epd_test.py'
  441. eval "${shar_touch}") && \
  442. chmod 0644 'epd_test.py'
  443. if test $? -ne 0
  444. then ${echo} "restore of epd_test.py failed"
  445. fi
  446. if ${md5check}
  447. then (
  448. ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'epd_test.py': 'MD5 check failed'
  449. ) << \SHAR_EOF
  450. f9ffc0a461f428c44a297ae321cbce62 epd_test.py
  451. SHAR_EOF
  452.  
  453. else
  454. test `LC_ALL=C wc -c < 'epd_test.py'` -ne 831 && \
  455. ${echo} "restoration warning: size of 'epd_test.py' is not 831"
  456. fi
  457. fi
  458. if rm -fr ${lock_dir}
  459. then ${echo} "x - removed lock directory ${lock_dir}."
  460. else ${echo} "x - failed to remove lock directory ${lock_dir}."
  461. exit 1
  462. fi
  463. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement