@@ -253,8 +253,9 @@ def moisture_read(self):
253
253
254
254
return ret
255
255
256
- def pin_mode_bulk (self , pins , mode ):
257
- cmd = struct .pack (">I" , pins )
256
+ def _pin_mode_bulk_x (self , capacity , offset , pins , mode ):
257
+ cmd = bytearray (capacity )
258
+ cmd [offset :] = struct .pack (">I" , pins )
258
259
if mode == self .OUTPUT :
259
260
self .write (_GPIO_BASE , _GPIO_DIRSET_BULK , cmd )
260
261
elif mode == self .INPUT :
@@ -273,26 +274,11 @@ def pin_mode_bulk(self, pins, mode):
273
274
else :
274
275
raise ValueError ("Invalid pin mode" )
275
276
276
- def pin_mode_bulk_b (self , pins , mode ):
277
- cmd = bytearray (8 )
278
- cmd [4 :] = struct .pack (">I" , pins )
279
- if mode == self .OUTPUT :
280
- self .write (_GPIO_BASE , _GPIO_DIRSET_BULK , cmd )
281
- elif mode == self .INPUT :
282
- self .write (_GPIO_BASE , _GPIO_DIRCLR_BULK , cmd )
283
-
284
- elif mode == self .INPUT_PULLUP :
285
- self .write (_GPIO_BASE , _GPIO_DIRCLR_BULK , cmd )
286
- self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
287
- self .write (_GPIO_BASE , _GPIO_BULK_SET , cmd )
288
-
289
- elif mode == self .INPUT_PULLDOWN :
290
- self .write (_GPIO_BASE , _GPIO_DIRCLR_BULK , cmd )
291
- self .write (_GPIO_BASE , _GPIO_PULLENSET , cmd )
292
- self .write (_GPIO_BASE , _GPIO_BULK_CLR , cmd )
277
+ def pin_mode_bulk (self , pins , mode ):
278
+ self ._pin_mode_bulk_x (4 , 0 , pins , mode )
293
279
294
- else :
295
- raise ValueError ( "Invalid pin mode" )
280
+ def pin_mode_bulk_b ( self , pins , mode ) :
281
+ self . _pin_mode_bulk_x ( 8 , 4 , pins , mode )
296
282
297
283
def digital_write_bulk (self , pins , value ):
298
284
cmd = struct .pack (">I" , pins )
0 commit comments