@@ -305,6 +305,63 @@ def cleanup(self, pin=None):
305305 else :
306306 self .bbio_gpio .cleanup (pin )
307307
308+ class AdafruitMinnowAdapter (BaseGPIO ):
309+ """GPIO implementation for the Minnowboard + MAX using the mraa library"""
310+
311+ def __init__ (self ,mraa_gpio ):
312+ self .mraa_gpio = mraa_gpio
313+ # Define mapping of Adafruit GPIO library constants to mraa constants
314+ self ._dir_mapping = { OUT : self .mraa_gpio .DIR_OUT ,
315+ IN : self .mraa_gpio .DIR_IN }
316+ self ._pud_mapping = { PUD_OFF : self .mraa_gpio .MODE_STRONG ,
317+ PUD_UP : self .mraa_gpio .MODE_HIZ ,
318+ PUD_DOWN : self .mraa_gpio .MODE_PULLDOWN }
319+ self ._edge_mapping = { RISING : self .mraa_gpio .EDGE_RISING ,
320+ FALLING : self .mraa_gpio .EDGE_FALLING ,
321+ BOTH : self .mraa_gpio .EDGE_BOTH }
322+
323+ def setup (self ,pin ,mode ):
324+ """Set the input or output mode for a specified pin. Mode should be
325+ either DIR_IN or DIR_OUT.
326+ """
327+ self .mraa_gpio .Gpio .dir (self .mraa_gpio .Gpio (pin ),self ._dir_mapping [mode ])
328+
329+ def output (self ,pin ,value ):
330+ """Set the specified pin the provided high/low value. Value should be
331+ either 1 (ON or HIGH), or 0 (OFF or LOW) or a boolean.
332+ """
333+ self .mraa_gpio .Gpio .write (self .mraa_gpio .Gpio (pin ), value )
334+
335+ def input (self ,pin ):
336+ """Read the specified pin and return HIGH/true if the pin is pulled high,
337+ or LOW/false if pulled low.
338+ """
339+ return self .mraa_gpio .Gpio .read (self .mraa_gpio .Gpio (pin ))
340+
341+ def add_event_detect (self , pin , edge , callback = None , bouncetime = - 1 ):
342+ """Enable edge detection events for a particular GPIO channel. Pin
343+ should be type IN. Edge must be RISING, FALLING or BOTH. Callback is a
344+ function for the event. Bouncetime is switch bounce timeout in ms for
345+ callback
346+ """
347+ kwargs = {}
348+ if callback :
349+ kwargs ['callback' ]= callback
350+ if bouncetime > 0 :
351+ kwargs ['bouncetime' ]= bouncetime
352+ self .mraa_gpio .Gpio .isr (self .mraa_gpio .Gpio (pin ), self ._edge_mapping [edge ], ** kwargs )
353+
354+ def remove_event_detect (self , pin ):
355+ """Remove edge detection for a particular GPIO channel. Pin should be
356+ type IN.
357+ """
358+ self .mraa_gpio .Gpio .isrExit (self .mraa_gpio .Gpio (pin ))
359+
360+ def wait_for_edge (self , pin , edge ):
361+ """Wait for an edge. Pin should be type IN. Edge must be RISING,
362+ FALLING or BOTH.
363+ """
364+ self .bbio_gpio .wait_for_edge (self .mraa_gpio .Gpio (pin ), self ._edge_mapping [edge ])
308365
309366def get_platform_gpio (** keywords ):
310367 """Attempt to return a GPIO instance for the platform which the code is being
@@ -320,5 +377,8 @@ def get_platform_gpio(**keywords):
320377 elif plat == Platform .BEAGLEBONE_BLACK :
321378 import Adafruit_BBIO .GPIO
322379 return AdafruitBBIOAdapter (Adafruit_BBIO .GPIO , ** keywords )
380+ elif plat == Platform .MINNOWBOARD :
381+ import mraa
382+ return AdafruitMinnowAdapter (mraa , ** keywords )
323383 elif plat == Platform .UNKNOWN :
324384 raise RuntimeError ('Could not determine platform.' )
0 commit comments