@@ -125,6 +125,7 @@ class Seesaw:
125
125
INPUT = const (0x00 )
126
126
OUTPUT = const (0x01 )
127
127
INPUT_PULLUP = const (0x02 )
128
+ INPUT_PULLDOWN = const (0x03 )
128
129
129
130
def __init__ (self , i2c_bus , addr = 0x49 , drdy = None ):
130
131
self ._drdy = drdy
@@ -186,13 +187,14 @@ def digital_read(self, pin):
186
187
def digital_read_bulk (self , pins ):
187
188
buf = bytearray (4 )
188
189
self .read (_GPIO_BASE , _GPIO_BULK , buf )
190
+ buf [0 ] = buf [0 ] & 0x3F
189
191
ret = struct .unpack (">I" , buf )[0 ]
190
192
return ret & pins
191
193
192
194
def digital_read_bulk_b (self , pins ):
193
195
buf = bytearray (8 )
194
196
self .read (_GPIO_BASE , _GPIO_BULK , buf )
195
- ret = struct .unpack (">II " , buf )[ 1 ]
197
+ ret = struct .unpack (">I " , buf [ 4 :])[ 0 ]
196
198
return ret & pins
197
199
198
200
@@ -235,6 +237,14 @@ def pin_mode_bulk(self, pins, mode):
235
237
self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
236
238
self .write (_GPIO_BASE , _GPIO_BULK_SET , cmd )
237
239
240
+ elif mode == self .INPUT_PULLDOWN :
241
+ self .write (_GPIO_BASE , _GPIO_DIRCLR_BULK , cmd )
242
+ self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
243
+ self .write (_GPIO_BASE , _GPIO_BULK_CLR , cmd )
244
+
245
+ else :
246
+ raise ValueError ("Invalid pin mode" )
247
+
238
248
def pin_mode_bulk_b (self , pins , mode ):
239
249
cmd = bytearray (8 )
240
250
cmd [4 :] = struct .pack (">I" , pins )
@@ -248,6 +258,14 @@ def pin_mode_bulk_b(self, pins, mode):
248
258
self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
249
259
self .write (_GPIO_BASE , _GPIO_BULK_SET , cmd )
250
260
261
+ elif mode == self .INPUT_PULLDOWN :
262
+ self .write (_GPIO_BASE , _GPIO_DIRCLR_BULK , cmd )
263
+ self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
264
+ self .write (_GPIO_BASE , _GPIO_BULK_CLR , cmd )
265
+
266
+ else :
267
+ raise ValueError ("Invalid pin mode" )
268
+
251
269
def digital_write_bulk (self , pins , value ):
252
270
cmd = struct .pack (">I" , pins )
253
271
if value :
0 commit comments