Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from glob import glob
- from pathlib import Path
- import errno
- def pinmux_path( name ):
- paths = glob( '/sys/bus/platform/drivers/bone-pinmux-helper/*%s*/state' % name )
- if len(paths) == 0:
- raise KeyError( 'Pinmux node not found: ' + name )
- if len(paths) > 1:
- raise KeyError( 'Pinmux node ambiguous: ' + name )
- return Path( paths[0] )
- def get_pinmux_state( name ):
- return pinmux_path( name ).read_text().rstrip()
- def set_pinmux_state( name, state ):
- try:
- pinmux_path( name ).write_text( state )
- except OSError as err:
- if err.errno == errno.ENODEV:
- raise ValueError( 'Invalid state for ' + name + ': ' + state ) from None
- else:
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement