1
1
import time
2
2
from Adafruit_EPD import mcp_sram
3
3
import digitalio
4
- import busio
5
4
from board import *
6
5
7
6
class Adafruit_EPD (object ):
8
- """Base class for EPD displays
9
- """
10
- BLACK = 0
11
- WHITE = 1
12
- INVERSE = 2
13
- RED = 3
14
- DARK = 4
15
- LIGHT = 5
16
-
17
- def __init__ (self , width , height , rst , dc , busy , srcs , cs ,
18
- spi ):
19
- self .width = width
20
- self .height = height
21
-
22
- # Setup reset pin.
23
- self ._rst = rst
24
- self ._rst .direction = digitalio .Direction .OUTPUT
25
-
26
- # Setup busy pin.
27
- self ._busy = busy
28
- self ._busy .direction = digitalio .Direction .INPUT
29
-
30
- # Setup dc pin.
31
- self ._dc = dc
32
- self ._dc .direction = digitalio .Direction .OUTPUT
33
-
34
- # Setup cs pin.
35
- self ._cs = cs
36
- self ._cs .direction = digitalio .Direction .OUTPUT
37
-
38
- self .spi_device = spi
39
-
40
- self .sram = mcp_sram .Adafruit_MCP_SRAM (srcs , spi )
41
-
42
- def begin (self , reset = True ):
43
- self ._cs .value = True
44
- self ._dc .value = False
45
-
46
- if reset :
47
- self ._rst .value = False
48
- time .sleep (.1 )
49
- self ._rst .value = True
50
- time .sleep (.1 )
51
-
52
- def command (self , c , data = None , end = True ):
53
- """Send command byte to display."""
54
- self ._cs .value = True
55
- self ._dc .value = False
56
- self ._cs .value = False
57
- outbuf = bytearray (1 )
58
-
59
- while not self .spi_device .try_lock ():
60
- pass
61
- self .spi_device .write_readinto (bytearray ([c ]), outbuf )
62
-
63
- if data is not None :
64
- self .data (data )
65
-
66
- elif end :
67
- self ._cs .value = True
68
-
69
- self .spi_device .unlock ()
70
- return outbuf [0 ]
71
-
72
- def data (self , d ):
73
- """Send data to display."""
74
- self ._dc .value = True
75
- self .spi_device .write (d )
76
- self ._cs .value = True
77
- self .spi_device .unlock ()
78
-
79
- #framebuf methods
80
- def fill (self , color ):
81
- self .format .fill_rect (self , 0 , 0 , self .width , self .height , color )
82
-
83
- def fill_rect (self , x , y , width , height , color ):
84
- if width < 1 or height < 1 or (x + width ) <= 0 or (y + height ) <= 0 or y >= self .height or x >= self .width :
85
- return
86
- xend = min (self .width , x + width )
87
- yend = min (self .height , y + height )
88
- x = max (x , 0 )
89
- y = max (y , 0 )
90
- for _x in range (xend - x ):
91
- for _y in range (yend - y ):
92
- self .draw_pixel (x + _x , y + _y , color )
93
-
94
- def pixel (self , x , y , color = None ):
95
- if x < 0 or x >= self .width or y < 0 or y >= self .height :
96
- return
97
- if color is None :
98
- return self .get_pixel (self , x , y )
99
- else :
100
- self .draw_pixel (self , x , y , color )
101
-
102
- def hline (self , x , y , width , color ):
103
- self .fill_rect (x , y , width , 1 , color )
104
-
105
- def vline (self , x , y , height , color ):
106
- self .fill_rect (x , y , 1 , height , color )
107
-
108
- def rect (self , x , y , width , height , color ):
109
- self .fill_rect (x , y , width , 1 , color )
110
- self .fill_rect (x , y + height , width , 1 , color )
111
- self .fill_rect (self , x , y , 1 , height , color )
112
- self .fill_rect (self , x + width , y , 1 , height , color )
113
-
114
- def line (self ):
115
- raise NotImplementedError ()
116
-
117
- def blit (self ):
118
- raise NotImplementedError ()
119
-
120
- def scroll (self ):
121
- raise NotImplementedError ()
122
-
123
- def text (self ):
124
- raise NotImplementedError ()
7
+ """Base class for EPD displays
8
+ """
9
+ BLACK = 0
10
+ WHITE = 1
11
+ INVERSE = 2
12
+ RED = 3
13
+ DARK = 4
14
+ LIGHT = 5
15
+
16
+ def __init__ (self , width , height , rst_pin , dc_pin , busy_pin , srcs_pin , cs_pin , spi ):
17
+ self .width = width
18
+ self .height = height
19
+
20
+ # Setup reset pin.
21
+ self ._rst = rst_pin
22
+ self ._rst .direction = digitalio .Direction .OUTPUT
23
+
24
+ # Setup busy pin.
25
+ self ._busy = busy_pin
26
+ self ._busy .direction = digitalio .Direction .INPUT
27
+
28
+ # Setup dc pin.
29
+ self ._dc = dc_pin
30
+ self ._dc .direction = digitalio .Direction .OUTPUT
31
+
32
+ # Setup cs pin.
33
+ self ._cs = cs_pin
34
+ self ._cs .direction = digitalio .Direction .OUTPUT
35
+
36
+ self .spi_device = spi
37
+
38
+ self .sram = mcp_sram .Adafruit_MCP_SRAM (srcs_pin , spi )
39
+
40
+ def begin (self , reset = True ):
41
+ self ._cs .value = True
42
+ self ._dc .value = False
43
+
44
+ if reset :
45
+ self ._rst .value = False
46
+ time .sleep (.1 )
47
+ self ._rst .value = True
48
+ time .sleep (.1 )
49
+
50
+ def command (self , cmd , data = None , end = True ):
51
+ """Send command byte to display."""
52
+ self ._cs .value = True
53
+ self ._dc .value = False
54
+ self ._cs .value = False
55
+ outbuf = bytearray (1 )
56
+
57
+ while not self .spi_device .try_lock ():
58
+ pass
59
+ self .spi_device .write_readinto (bytearray ([cmd ]), outbuf )
60
+
61
+ if data is not None :
62
+ self .data (data )
63
+
64
+ elif end :
65
+ self ._cs .value = True
66
+
67
+ self .spi_device .unlock ()
68
+ return outbuf [0 ]
69
+
70
+ def data (self , dat ):
71
+ """Send data to display."""
72
+ self ._dc .value = True
73
+ self .spi_device .write (dat )
74
+ self ._cs .value = True
75
+ self .spi_device .unlock ()
76
+
77
+ def draw_pixel (self , x , y , color ):
78
+ pass
79
+
80
+ def get_pixel (self , x , y ):
81
+ pass
82
+
83
+ #framebuf methods
84
+ def fill (self , color ):
85
+ self .fill_rect (self , 0 , 0 , self .width , self .height , color )
86
+
87
+ def fill_rect (self , x , y , width , height , color ):
88
+ if width < 1 or height < 1 or (x + width ) <= 0 or (y + height ) <= 0 \
89
+ or y >= self .height or x >= self .width :
90
+ return
91
+ xend = min (self .width , x + width )
92
+ yend = min (self .height , y + height )
93
+ x = max (x , 0 )
94
+ y = max (y , 0 )
95
+ for _x in range (xend - x ):
96
+ for _y in range (yend - y ):
97
+ self .draw_pixel (x + _x , y + _y , color )
98
+ return
99
+
100
+ def pixel (self , x , y , color = None ):
101
+ if x < 0 or x >= self .width or y < 0 or y >= self .height :
102
+ return None
103
+ if color is None :
104
+ return self .get_pixel (self , x , y )
105
+
106
+ self .draw_pixel (self , x , y , color )
107
+ return None
108
+
109
+ def hline (self , x , y , width , color ):
110
+ self .fill_rect (x , y , width , 1 , color )
111
+
112
+ def vline (self , x , y , height , color ):
113
+ self .fill_rect (x , y , 1 , height , color )
114
+
115
+ def rect (self , x , y , width , height , color ):
116
+ self .fill_rect (x , y , width , 1 , color )
117
+ self .fill_rect (x , y + height , width , 1 , color )
118
+ self .fill_rect (self , x , y , 1 , height , color )
119
+ self .fill_rect (self , x + width , y , 1 , height , color )
120
+
121
+ def line (self ):
122
+ raise NotImplementedError ()
123
+
124
+ def blit (self ):
125
+ raise NotImplementedError ()
126
+
127
+ def scroll (self ):
128
+ raise NotImplementedError ()
129
+
130
+ def text (self ):
131
+ raise NotImplementedError ()
0 commit comments