freemyipod r974 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r973‎ | r974 | r975 >
Date:21:09, 8 March 2017
Author:user890104
Status:new
Tags:
Comment:
Add script for sending commands to the LCD, useful when developing LCD drivers
Modified paths:
  • /emcore/trunk/tools/lcdtest.py (added) (history)

Diff [purge]

Index: emcore/trunk/tools/lcdtest.py
@@ -0,0 +1,476 @@
 2+#!/usr/bin/env python
 3+
 4+import sys
 5+import os
 6+import time
 7+import struct
 8+import locale
 9+
 10+from functools import wraps
 11+
 12+import libemcore
 13+import libemcoredata
 14+from misc import Error, ArgumentError, ArgumentTypeError, Logger, getfuncdoc, gethwname, to_bool, to_int
 15+
 16+class Interface(object):
 17+ def __init__(self):
 18+ self.logger = Logger()
 19+ try:
 20+ self.emcore = libemcore.Emcore(logger = self.logger)
 21+ except libemcore.DeviceNotFoundError:
 22+ self.logger.error("No emCORE device found!\n")
 23+ exit(1)
 24+ def lcdcmd(self, cmd):
 25+ data = struct.pack("<I", cmd)
 26+ self.emcore.write(0x38300004, data)
 27+ def lcddata(self, data):
 28+ data = struct.pack("<I", data)
 29+ self.emcore.write(0x38300040, data)
 30+
 31+if __name__ == "__main__":
 32+ try:
 33+ interface = Interface()
 34+ interface.emcore.write(0x38300000, struct.pack("<I", 0x41000c20))
 35+# interface.emcore.write(0x38300000, struct.pack("<I", 0x41100db8))
 36+ interface.emcore.i2cwrite(0, 0xe6, 0x30, struct.pack("B", 200))
 37+ if len(sys.argv) > 1:
 38+ interface.lcdcmd(int(sys.argv[1], 16))
 39+ for i in range(2, len(sys.argv)):
 40+ interface.lcddata(int(sys.argv[1], 16))
 41+ exit(0)
 42+# '''
 43+ print("Software Reset?")
 44+ raw_input()
 45+ interface.lcdcmd(0x01)
 46+ print("Sleep Out?")
 47+ raw_input()
 48+ interface.lcdcmd(0x11)
 49+ print("Display ON?")
 50+ raw_input()
 51+ interface.lcdcmd(0x29)
 52+ print("Power Control 1?")
 53+ raw_input()
 54+ interface.lcdcmd(0xc0)
 55+ print("Data: 00 (unknown)?")
 56+ raw_input()
 57+ interface.lcddata(0x00)
 58+ print("Power Control 2?")
 59+ raw_input()
 60+ interface.lcdcmd(0xc1)
 61+ print("Data: 03 (unknown)?")
 62+ raw_input()
 63+ interface.lcddata(0x03)
 64+ print("Power Control 3?")
 65+ raw_input()
 66+ interface.lcdcmd(0xc2)
 67+ print("Data: 34 (unknown)?")
 68+ raw_input()
 69+ interface.lcddata(0x34)
 70+ print("Power Control 4?")
 71+ raw_input()
 72+ interface.lcdcmd(0xc3)
 73+ print("Data: 72 (unknown)?")
 74+ raw_input()
 75+ interface.lcddata(0x72)
 76+ print("Data: 03 (unknown)?")
 77+ raw_input()
 78+ interface.lcddata(0x03)
 79+ print("Power Control 5?")
 80+ raw_input()
 81+ interface.lcdcmd(0xc4)
 82+ print("Data: 73 (unknown)?")
 83+ raw_input()
 84+ interface.lcddata(0x73)
 85+ print("Data: 03 (unknown)?")
 86+ raw_input()
 87+ interface.lcddata(0x03)
 88+ print("VCOM Control 1?")
 89+ raw_input()
 90+ interface.lcdcmd(0xc5)
 91+ print("Data: 3c (unknown)?")
 92+ raw_input()
 93+ interface.lcddata(0x3c)
 94+ print("Data: 3c (unknown)?")
 95+ raw_input()
 96+ interface.lcddata(0x3c)
 97+ print("Command: fe (unknown)?")
 98+ raw_input()
 99+ interface.lcdcmd(0xfe)
 100+ print("Data: 00 (unknown)?")
 101+ raw_input()
 102+ interface.lcddata(0x00)
 103+ print("Command: b1 (unknown)?")
 104+ raw_input()
 105+ interface.lcdcmd(0xb1)
 106+ print("Data: 6a (unknown)?")
 107+ raw_input()
 108+ interface.lcddata(0x6a)
 109+ print("Data: 15 (unknown)?")
 110+ raw_input()
 111+ interface.lcddata(0x15)
 112+ print("Command: b2 (unknown)?")
 113+ raw_input()
 114+ interface.lcdcmd(0xb2)
 115+ print("Data: 6a (unknown)?")
 116+ raw_input()
 117+ interface.lcddata(0x00)
 118+ print("Data: 15 (unknown)?")
 119+ raw_input()
 120+ interface.lcddata(0x15)
 121+ print("Command: b3 (unknown)?")
 122+ raw_input()
 123+ interface.lcdcmd(0xb3)
 124+ print("Data: 6a (unknown)?")
 125+ raw_input()
 126+ interface.lcddata(0x00)
 127+ print("Data: 15 (unknown)?")
 128+ raw_input()
 129+ interface.lcddata(0x15)
 130+ print("Command: b4 (unknown)?")
 131+ raw_input()
 132+ interface.lcdcmd(0xb4)
 133+ print("Data: 02 (unknown)?")
 134+ raw_input()
 135+ interface.lcddata(0x02)
 136+ print("Command: b6 (unknown)?")
 137+ raw_input()
 138+ interface.lcdcmd(0xb6)
 139+ print("Data: 12 (unknown)?")
 140+ raw_input()
 141+ interface.lcddata(0x12)
 142+ print("Data: 02 (unknown)?")
 143+ raw_input()
 144+ interface.lcddata(0x02)
 145+ print("Command: 35 (unknown)?")
 146+ raw_input()
 147+ interface.lcdcmd(0x35)
 148+ print("Data: 00 (unknown)?")
 149+ raw_input()
 150+ interface.lcddata(0x00)
 151+ print("Command: 26 (unknown)?")
 152+ raw_input()
 153+ interface.lcdcmd(0x26)
 154+ print("Data: 10 (unknown)?")
 155+ raw_input()
 156+ interface.lcddata(0x10)
 157+ print("Command: e0 (unknown)?")
 158+ raw_input()
 159+ interface.lcdcmd(0xe0)
 160+ print("Data: 77 (unknown)?")
 161+ raw_input()
 162+ interface.lcddata(0x77)
 163+ print("Data: 52 (unknown)?")
 164+ raw_input()
 165+ interface.lcddata(0x52)
 166+ print("Data: 76 (unknown)?")
 167+ raw_input()
 168+ interface.lcddata(0x76)
 169+ print("Data: 53 (unknown)?")
 170+ raw_input()
 171+ interface.lcddata(0x53)
 172+ print("Data: 03 (unknown)?")
 173+ raw_input()
 174+ interface.lcddata(0x03)
 175+ print("Data: 03 (unknown)?")
 176+ raw_input()
 177+ interface.lcddata(0x03)
 178+ print("Data: 57 (unknown)?")
 179+ raw_input()
 180+ interface.lcddata(0x57)
 181+ print("Data: 42 (unknown)?")
 182+ raw_input()
 183+ interface.lcddata(0x42)
 184+ print("Data: 10 (unknown)?")
 185+ raw_input()
 186+ interface.lcddata(0x10)
 187+ print("Data: 18 (unknown)?")
 188+ raw_input()
 189+ interface.lcddata(0x18)
 190+ print("Data: 09 (unknown)?")
 191+ raw_input()
 192+ interface.lcddata(0x09)
 193+ print("Command: e1 (unknown)?")
 194+ raw_input()
 195+ interface.lcdcmd(0xe1)
 196+ print("Data: 0d (unknown)?")
 197+ raw_input()
 198+ interface.lcddata(0x0d)
 199+ print("Data: 00 (unknown)?")
 200+ raw_input()
 201+ interface.lcddata(0x00)
 202+ print("Data: 23 (unknown)?")
 203+ raw_input()
 204+ interface.lcddata(0x23)
 205+ print("Data: 66 (unknown)?")
 206+ raw_input()
 207+ interface.lcddata(0x66)
 208+ print("Data: 0f (unknown)?")
 209+ raw_input()
 210+ interface.lcddata(0x0f)
 211+ print("Data: 15 (unknown)?")
 212+ raw_input()
 213+ interface.lcddata(0x15)
 214+ print("Data: 4d (unknown)?")
 215+ raw_input()
 216+ interface.lcddata(0x4d)
 217+ print("Data: 85 (unknown)?")
 218+ raw_input()
 219+ interface.lcddata(0x85)
 220+ print("Data: 08 (unknown)?")
 221+ raw_input()
 222+ interface.lcddata(0x08)
 223+ print("Data: 02 (unknown)?")
 224+ raw_input()
 225+ interface.lcddata(0x02)
 226+ print("Data: 10 (unknown)?")
 227+ raw_input()
 228+ interface.lcddata(0x10)
 229+ print("Command: e2 (unknown)?")
 230+ raw_input()
 231+ interface.lcdcmd(0xe2)
 232+ print("Data: 39 (unknown)?")
 233+ raw_input()
 234+ interface.lcddata(0x39)
 235+ print("Data: 60 (unknown)?")
 236+ raw_input()
 237+ interface.lcddata(0x60)
 238+ print("Data: 77 (unknown)?")
 239+ raw_input()
 240+ interface.lcddata(0x77)
 241+ print("Data: 05 (unknown)?")
 242+ raw_input()
 243+ interface.lcddata(0x05)
 244+ print("Data: 03 (unknown)?")
 245+ raw_input()
 246+ interface.lcddata(0x03)
 247+ print("Data: 07 (unknown)?")
 248+ raw_input()
 249+ interface.lcddata(0x07)
 250+ print("Data: 96 (unknown)?")
 251+ raw_input()
 252+ interface.lcddata(0x96)
 253+ print("Data: 64 (unknown)?")
 254+ raw_input()
 255+ interface.lcddata(0x64)
 256+ print("Data: 0d (unknown)?")
 257+ raw_input()
 258+ interface.lcddata(0x0d)
 259+ print("Data: 1a (unknown)?")
 260+ raw_input()
 261+ interface.lcddata(0x1a)
 262+ print("Data: 0a (unknown)?")
 263+ raw_input()
 264+ interface.lcddata(0x0a)
 265+ print("Command: e3 (unknown)?")
 266+ raw_input()
 267+ interface.lcdcmd(0xe3)
 268+ print("Data: 3f (unknown)?")
 269+ raw_input()
 270+ interface.lcddata(0x3f)
 271+ print("Data: 10 (unknown)?")
 272+ raw_input()
 273+ interface.lcddata(0x10)
 274+ print("Data: 16 (unknown)?")
 275+ raw_input()
 276+ interface.lcddata(0x16)
 277+ print("Data: 44 (unknown)?")
 278+ raw_input()
 279+ interface.lcddata(0x44)
 280+ print("Data: 0e (unknown)?")
 281+ raw_input()
 282+ interface.lcddata(0x0e)
 283+ print("Data: 04 (unknown)?")
 284+ raw_input()
 285+ interface.lcddata(0x04)
 286+ print("Data: 6c (unknown)?")
 287+ raw_input()
 288+ interface.lcddata(0x6c)
 289+ print("Data: 44 (unknown)?")
 290+ raw_input()
 291+ interface.lcddata(0x44)
 292+ print("Data: 04 (unknown)?")
 293+ raw_input()
 294+ interface.lcddata(0x04)
 295+ print("Data: 03 (unknown)?")
 296+ raw_input()
 297+ interface.lcddata(0x03)
 298+ print("Data: 0b (unknown)?")
 299+ raw_input()
 300+ interface.lcddata(0x0b)
 301+ print("Command: e4 (unknown)?")
 302+ raw_input()
 303+ interface.lcdcmd(0xe4)
 304+ print("Data: 00 (unknown)?")
 305+ raw_input()
 306+ interface.lcddata(0x00)
 307+ print("Data: 61 (unknown)?")
 308+ raw_input()
 309+ interface.lcddata(0x61)
 310+ print("Data: 77 (unknown)?")
 311+ raw_input()
 312+ interface.lcddata(0x77)
 313+ print("Data: 04 (unknown)?")
 314+ raw_input()
 315+ interface.lcddata(0x04)
 316+ print("Data: 02 (unknown)?")
 317+ raw_input()
 318+ interface.lcddata(0x02)
 319+ print("Data: 04 (unknown)?")
 320+ raw_input()
 321+ interface.lcddata(0x04)
 322+ print("Data: 72 (unknown)?")
 323+ raw_input()
 324+ interface.lcddata(0x72)
 325+ print("Data: 32 (unknown)?")
 326+ raw_input()
 327+ interface.lcddata(0x32)
 328+ print("Data: 09 (unknown)?")
 329+ raw_input()
 330+ interface.lcddata(0x09)
 331+ print("Data: 19 (unknown)?")
 332+ raw_input()
 333+ interface.lcddata(0x19)
 334+ print("Data: 06 (unknown)?")
 335+ raw_input()
 336+ interface.lcddata(0x06)
 337+ print("Command: e5 (unknown)?")
 338+ raw_input()
 339+ interface.lcdcmd(0xe5)
 340+ print("Data: 4f (unknown)?")
 341+ raw_input()
 342+ interface.lcddata(0x4f)
 343+ print("Data: 42 (unknown)?")
 344+ raw_input()
 345+ interface.lcddata(0x42)
 346+ print("Data: 27 (unknown)?")
 347+ raw_input()
 348+ interface.lcddata(0x27)
 349+ print("Data: 67 (unknown)?")
 350+ raw_input()
 351+ interface.lcddata(0x67)
 352+ print("Data: 0f (unknown)?")
 353+ raw_input()
 354+ interface.lcddata(0x0f)
 355+ print("Data: 03 (unknown)?")
 356+ raw_input()
 357+ interface.lcddata(0x03)
 358+ print("Data: 26 (unknown)?")
 359+ raw_input()
 360+ interface.lcddata(0x26)
 361+ print("Data: 33 (unknown)?")
 362+ raw_input()
 363+ interface.lcddata(0x33)
 364+ print("Data: 01 (unknown)?")
 365+ raw_input()
 366+ interface.lcddata(0x01)
 367+ print("Data: 03 (unknown)?")
 368+ raw_input()
 369+ interface.lcddata(0x03)
 370+ print("Data: 09 (unknown)?")
 371+ raw_input()
 372+ interface.lcddata(0x09)
 373+# print("Command: 3a (unknown)?")
 374+# raw_input()
 375+# interface.lcdcmd(0x3a)
 376+# print("Data: 66 (unknown)?")
 377+# raw_input()
 378+# interface.lcddata(0x66)
 379+ print("Command: 36 (unknown)?")
 380+ raw_input()
 381+ interface.lcdcmd(0x36)
 382+ print("Data: 00 (unknown)?")
 383+ raw_input()
 384+ interface.lcddata(0x00)
 385+ print("Sleep Out?")
 386+ raw_input()
 387+ interface.lcdcmd(0x11)
 388+ print("Display ON?")
 389+ raw_input()
 390+ interface.lcdcmd(0x29)
 391+# '''
 392+ print("Write pattern?")
 393+ raw_input()
 394+ interface.emcore.write(0x38300000, struct.pack("<I", 0x41100db8))
 395+ interface.lcdcmd(0x2a)
 396+ interface.lcddata(64)
 397+ interface.lcddata(191)
 398+ interface.lcdcmd(0x2b)
 399+ interface.lcddata(8)
 400+ interface.lcddata(0x237)
 401+ interface.lcdcmd(0x2c)
 402+# interface.emcore.write(0x38300000, struct.pack("<I", 0x41000c20))
 403+# interface.lcdcmd(0x210)
 404+# interface.lcddata(64)
 405+# interface.lcdcmd(0x211)
 406+# interface.lcddata(191)
 407+# interface.lcdcmd(0x212)
 408+# interface.lcddata(8)
 409+# interface.lcdcmd(0x213)
 410+# interface.lcddata(239)
 411+# interface.lcdcmd(0x2c)
 412+# interface.lcdcmd(0x200)
 413+# interface.lcddata(64)
 414+# interface.lcdcmd(0x201)
 415+# interface.lcddata(8)
 416+# interface.lcdcmd(0x202)
 417+ interface.emcore.write(0x38300000, struct.pack("<I", 0x41104eb8))
 418+ for r in range(8):
 419+ for y in range(32):
 420+ for x in range(32):
 421+ interface.lcddata(1 << (r + 24))
 422+ for x in range(32):
 423+ interface.lcddata(1 << (r + 16))
 424+ for x in range(32):
 425+ interface.lcddata(1 << (r + 8))
 426+ for x in range(32):
 427+ interface.lcddata(1 << r)
 428+ for y in range(32):
 429+ for x in range(32):
 430+ interface.lcddata(0xff000000)
 431+ for x in range(32):
 432+ interface.lcddata(0xff0000)
 433+ for x in range(32):
 434+ interface.lcddata(0xff00)
 435+ for x in range(32):
 436+ interface.lcddata(0xff)
 437+ interface.emcore.write(0x38300000, struct.pack("<I", 0x41100db8))
 438+ interface.lcdcmd(0x2a)
 439+ interface.lcddata(8)
 440+ interface.lcddata(63)
 441+ interface.lcdcmd(0x2b)
 442+ interface.lcddata(8)
 443+ interface.lcddata(0x237)
 444+ interface.lcdcmd(0x2c)
 445+# interface.emcore.write(0x38300000, struct.pack("<I", 0x41000da8))
 446+# interface.lcdcmd(0x210)
 447+# interface.lcddata(8)
 448+# interface.lcdcmd(0x211)
 449+# interface.lcddata(63)
 450+# interface.lcdcmd(0x212)
 451+# interface.lcddata(8)
 452+# interface.lcdcmd(0x213)
 453+# interface.lcddata(239)
 454+# interface.lcdcmd(0x2c)
 455+# interface.lcdcmd(0x200)
 456+# interface.lcddata(8)
 457+# interface.lcdcmd(0x201)
 458+# interface.lcddata(8)
 459+# interface.lcdcmd(0x202)
 460+ interface.emcore.write(0x38300000, struct.pack("<I", 0x41104eb8))
 461+ for y in range(256):
 462+ for k in range(8):
 463+ interface.lcddata(y << 16)
 464+ for k in range(8):
 465+ interface.lcddata(y << 8)
 466+ for k in range(8):
 467+ interface.lcddata(y)
 468+ for k in range(8):
 469+ interface.lcddata((y << 8) | y)
 470+ for k in range(8):
 471+ interface.lcddata((y << 16) | y)
 472+ for k in range(8):
 473+ interface.lcddata((y << 16) | (y << 8))
 474+ for k in range(8):
 475+ interface.lcddata((y << 16) | (y << 8) | y)
 476+ except KeyboardInterrupt:
 477+ sys.exit()
\ No newline at end of file