/ adafruit_rgb_display / ssd1351.py
ssd1351.py
1 # The MIT License (MIT) 2 # 3 # Copyright (c) 2017 Radomir Dopieralski and Adafruit Industries 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 """ 23 `adafruit_rgb_display.ssd1351` 24 ==================================================== 25 26 A simple driver for the SSD1351-based displays. 27 28 * Author(s): Radomir Dopieralski, Michael McWethy 29 """ 30 from micropython import const 31 from adafruit_rgb_display.rgb import DisplaySPI 32 33 __version__ = "0.0.0-auto.0" 34 __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git" 35 36 _SETCOLUMN = const(0x15) 37 _SETROW = const(0x75) 38 _WRITERAM = const(0x5C) 39 _READRAM = const(0x5D) 40 _SETREMAP = const(0xA0) 41 _STARTLINE = const(0xA1) 42 _DISPLAYOFFSET = const(0xA2) 43 _DISPLAYALLOFF = const(0xA4) 44 _DISPLAYALLON = const(0xA5) 45 _NORMALDISPLAY = const(0xA6) 46 _INVERTDISPLAY = const(0xA7) 47 _FUNCTIONSELECT = const(0xAB) 48 _DISPLAYOFF = const(0xAE) 49 _DISPLAYON = const(0xAF) 50 _PRECHARGE = const(0xB1) 51 _DISPLAYENHANCE = const(0xB2) 52 _CLOCKDIV = const(0xB3) 53 _SETVSL = const(0xB4) 54 _SETGPIO = const(0xB5) 55 _PRECHARGE2 = const(0xB6) 56 _SETGRAY = const(0xB8) 57 _USELUT = const(0xB9) 58 _PRECHARGELEVEL = const(0xBB) 59 _VCOMH = const(0xBE) 60 _CONTRASTABC = const(0xC1) 61 _CONTRASTMASTER = const(0xC7) 62 _MUXRATIO = const(0xCA) 63 _COMMANDLOCK = const(0xFD) 64 _HORIZSCROLL = const(0x96) 65 _STOPSCROLL = const(0x9E) 66 _STARTSCROLL = const(0x9F) 67 68 69 class SSD1351(DisplaySPI): 70 """ 71 A simple driver for the SSD1351-based displays. 72 73 >>> import busio 74 >>> import digitalio 75 >>> import board 76 >>> from adafruit_rgb_display import color565 77 >>> import adafruit_rgb_display.ssd1351 as ssd1351 78 >>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) 79 >>> display = ssd1351.SSD1351(spi, cs=digitalio.DigitalInOut(board.GPIO0), 80 ... dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16)) 81 >>> display.fill(0x7521) 82 >>> display.pixel(32, 32, 0) 83 """ 84 85 _COLUMN_SET = _SETCOLUMN 86 _PAGE_SET = _SETROW 87 _RAM_WRITE = _WRITERAM 88 _RAM_READ = _READRAM 89 _INIT = ( 90 (_COMMANDLOCK, b"\x12"), 91 (_COMMANDLOCK, b"\xb1"), 92 (_DISPLAYOFF, b""), 93 (_DISPLAYENHANCE, b"\xa4\x00\x00"), 94 # 7:4 = Oscillator Frequency, 95 # 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16) 96 (_CLOCKDIV, b"\xf0"), 97 (_MUXRATIO, b"\x7f"), # 127 98 (_SETREMAP, b"\x74"), 99 (_STARTLINE, b"\x00"), 100 (_DISPLAYOFFSET, b"\x00"), 101 (_SETGPIO, b"\x00"), 102 (_FUNCTIONSELECT, b"\x01"), 103 (_PRECHARGE, b"\x32"), 104 (_PRECHARGELEVEL, b"\x1f"), 105 (_VCOMH, b"\x05"), 106 (_NORMALDISPLAY, b""), 107 (_CONTRASTABC, b"\xc8\x80\xc8"), 108 (_CONTRASTMASTER, b"\x0a"), 109 (_SETVSL, b"\xa0\xb5\x55"), 110 (_PRECHARGE2, b"\x01"), 111 (_DISPLAYON, b""), 112 ) 113 _ENCODE_PIXEL = ">H" 114 _ENCODE_POS = ">BB" 115 116 # pylint: disable-msg=useless-super-delegation, too-many-arguments 117 def __init__( 118 self, 119 spi, 120 dc, 121 cs, 122 rst=None, 123 width=128, 124 height=128, 125 baudrate=16000000, 126 polarity=0, 127 phase=0, 128 *, 129 x_offset=0, 130 y_offset=0, 131 rotation=0 132 ): 133 if baudrate > 16000000: # Limit to Display Max Baudrate 134 baudrate = 16000000 135 super().__init__( 136 spi, 137 dc, 138 cs, 139 rst, 140 width, 141 height, 142 baudrate=baudrate, 143 polarity=polarity, 144 phase=phase, 145 x_offset=x_offset, 146 y_offset=y_offset, 147 rotation=rotation, 148 )