@@ -324,6 +324,8 @@ class ssd1351(device):
324
324
:param framebuffer: Framebuffering strategy, currently values of
325
325
``diff_to_previous`` or ``full_frame`` are only supported.
326
326
:type framebuffer: str
327
+ :param bgr: Set to ``True`` if device pixels are BGR order (rather than RGB).
328
+ :type bgr: bool
327
329
:param h_offset: horizontal offset (in pixels) of screen to device memory
328
330
(default: 0)
329
331
:type h_offset: int
@@ -334,16 +336,12 @@ class ssd1351(device):
334
336
.. versionadded:: 2.3.0
335
337
"""
336
338
def __init__ (self , serial_interface = None , width = 128 , height = 128 , rotate = 0 ,
337
- framebuffer = "diff_to_previous" , h_offset = 0 , v_offset = 0 , ** kwargs ):
339
+ framebuffer = "diff_to_previous" , h_offset = 0 , v_offset = 0 ,
340
+ bgr = False , ** kwargs ):
338
341
super (ssd1351 , self ).__init__ (luma .oled .const .common , serial_interface )
339
342
self .capabilities (width , height , rotate , mode = "RGB" )
340
343
self .framebuffer = getattr (luma .core .framebuffer , framebuffer )(self )
341
344
342
- settings = {
343
- (128 , 128 ): dict (width = 0x7F , height = 0x7F , displayoffset = 0x00 , startline = 0x00 , remap = 0x00 ),
344
- (96 , 96 ): dict (width = 0x6F , height = 0x5F , displayoffset = 0x00 , startline = 0x00 , remap = 0x02 )
345
- }.get ((width , height ))
346
-
347
345
if h_offset != 0 or v_offset != 0 :
348
346
def offset (bbox ):
349
347
left , top , right , bottom = bbox
@@ -352,46 +350,31 @@ def offset(bbox):
352
350
else :
353
351
self .apply_offsets = lambda bbox : bbox
354
352
355
- if settings is None :
353
+ if ( width , height ) not in [( 96 , 96 ), ( 128 , 128 )] :
356
354
raise luma .core .error .DeviceDisplayModeError (
357
355
"Unsupported display mode: {0} x {1}" .format (width , height ))
358
356
359
- # Unlock IC MCU interface
360
- self .command (0xFD , 0x12 )
361
- # Command A2,B1,B3,BB,BE,C1 accessible if in unlock state
362
- self .command (0xFD , 0xB1 )
363
- # Display off
364
- self .command (0xAE )
365
- # Clock divider
366
- self .command (0xB3 , 0xF1 )
367
- # Mux ratio
368
- self .command (0xCA , 0x7F )
369
- # Set column address
370
- self .command (0x15 , settings ['displayoffset' ], settings ['width' ])
371
- # Set row address
372
- self .command (0x75 , settings ['displayoffset' ], settings ['height' ])
373
- # Segment remapping - Column address remapping or else everything is mirrored
374
- self .command (0xA0 , 0x74 | settings ['remap' ])
375
- # Set Display start line
376
- self .command (0xA1 , settings ['startline' ])
377
- # Set display offset
378
- self .command (0xA2 , 0x00 )
379
- # Set GPIO
380
- self .command (0xB5 , 0x00 )
381
- # Function select (internal - diode drop)
382
- self .command (0xAB , 0x01 )
383
- # Precharge
384
- self .command (0xB1 , 0x32 )
385
- # Set segment low voltage
386
- self .command (0xB4 , 0xA0 , 0xB5 , 0x55 )
387
- # Set VcomH voltage
388
- self .command (0xBE , 0x05 )
389
- # Contrast master
390
- self .command (0xC7 , 0x0F )
391
- # Precharge2
392
- self .command (0xB6 , 0x01 )
393
- # Normal display
394
- self .command (0xA6 )
357
+ # RGB or BGR order
358
+ order = 0x02 if bgr else 0x00
359
+
360
+ self .command (0xFD , 0x12 ) # Unlock IC MCU interface
361
+ self .command (0xFD , 0xB1 ) # Command A2,B1,B3,BB,BE,C1 accessible if in unlock state
362
+ self .command (0xAE ) # Display off
363
+ self .command (0xB3 , 0xF1 ) # Clock divider
364
+ self .command (0xCA , 0x7F ) # Mux ratio
365
+ self .command (0x15 , 0x00 , width - 1 ) # Set column address
366
+ self .command (0x75 , 0x00 , height - 1 ) # Set row address
367
+ self .command (0xA0 , 0x74 | order ) # Segment remapping
368
+ self .command (0xA1 , 0x00 ) # Set Display start line
369
+ self .command (0xA2 , 0x00 ) # Set display offset
370
+ self .command (0xB5 , 0x00 ) # Set GPIO
371
+ self .command (0xAB , 0x01 ) # Function select (internal - diode drop)
372
+ self .command (0xB1 , 0x32 ) # Precharge
373
+ self .command (0xB4 , 0xA0 , 0xB5 , 0x55 ) # Set segment low voltage
374
+ self .command (0xBE , 0x05 ) # Set VcomH voltage
375
+ self .command (0xC7 , 0x0F ) # Contrast master
376
+ self .command (0xB6 , 0x01 ) # Precharge2
377
+ self .command (0xA6 ) # Normal display
395
378
396
379
self .contrast (0xFF )
397
380
self .clear ()
0 commit comments