3
3
import time
4
4
import framebuf
5
5
6
+
6
7
# register definitions
7
8
SET_CONTRAST = const (0x81 )
8
9
SET_ENTIRE_ON = const (0xa4 )
22
23
SET_VCOM_DESEL = const (0xdb )
23
24
SET_CHARGE_PUMP = const (0x8d )
24
25
26
+
25
27
class SSD1306 :
26
28
def __init__ (self , height , external_vcc ):
27
29
self .width = 128
@@ -91,6 +93,7 @@ def scroll(self, dx, dy):
91
93
def text (self , string , x , y , col = 1 ):
92
94
self .framebuf .text (string , x , y , col )
93
95
96
+
94
97
class SSD1306_I2C (SSD1306 ):
95
98
def __init__ (self , height , i2c , addr = 0x3c , external_vcc = False ):
96
99
self .i2c = i2c
@@ -114,32 +117,38 @@ def write_data(self, buf):
114
117
def poweron (self ):
115
118
pass
116
119
117
- # TODO convert this class to use the new hardware API
120
+
118
121
class SSD1306_SPI (SSD1306 ):
119
- def __init__ (self , height , spi , dc , res , cs = None , external_vcc = False ):
120
- rate = 10 * 1024 * 1024
121
- spi .init (spi .MASTER , baudrate = rate , polarity = 0 , phase = 0 )
122
- dc .init (dc .OUT , dc .PULL_NONE , value = 0 )
123
- res .init (res .OUT , dc .PULL_NONE , value = 0 )
124
- if cs is not None :
125
- cs .init (cs .OUT , cs .PULL_NONE , value = 0 )
122
+ def __init__ (self , height , spi , dc , res , cs , external_vcc = False ):
123
+ self .rate = 10 * 1024 * 1024
124
+ dc .init (dc .OUT , value = 0 )
125
+ res .init (res .OUT , value = 0 )
126
+ cs .init (cs .OUT , value = 1 )
126
127
self .spi = spi
127
128
self .dc = dc
128
129
self .res = res
130
+ self .cs = cs
129
131
super ().__init__ (height , external_vcc )
130
132
131
133
def write_cmd (self , cmd ):
134
+ self .spi .init (baudrate = self .rate , polarity = 0 , phase = 0 )
135
+ self .cs .high ()
132
136
self .dc .low ()
133
- self .spi .send (cmd )
137
+ self .cs .low ()
138
+ self .spi .write (bytearray ([cmd ]))
139
+ self .cs .high ()
134
140
135
141
def write_data (self , buf ):
142
+ self .spi .init (baudrate = self .rate , polarity = 0 , phase = 0 )
143
+ self .cs .high ()
136
144
self .dc .high ()
137
- self .spi .send (buf )
145
+ self .cs .low ()
146
+ self .spi .write (buf )
147
+ self .cs .high ()
138
148
139
149
def poweron (self ):
140
150
self .res .high ()
141
151
time .sleep_ms (1 )
142
152
self .res .low ()
143
153
time .sleep_ms (10 )
144
154
self .res .high ()
145
- time .sleep_ms (10 )
0 commit comments