123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- """
- This is a clone of the 'gpio/WiringPi' project, written specifically for the
- OrangePi i96.
- Not all of gpio is re-implemented. The 'mode' command allows the user to
- select any pin a GPIO or its special-funtion (i2c, spi, uart, pcm, etc)
- Pat Beirne <patb@pbeirne.com>
- Implemented:
- gpio read <gpio pin number> => displays a value, returns 0 on success
- gpio write <gpio pin number> <value> # set a pin high or low
- gpio mode [in | out | alt] # set the pin for in/out or special-function
- gpio readall # display all current pin settings
- # and the pin assignments on the 40 pin i96
- gpio readallx # similar to above, but shows RDA pinout
- gpio exports # simply dump the state of all the exports
- # which exist
- gpio leds # like readall, but for LEDs, switches
- # and other on-board devices
- NOTE: pin numbers are always gpio numbers.
- use 'readall' to see the connector assignment
- By default, the 'mode' function will create/delete an export. By default,
- the 'read' and 'write' function will set the mode and create an export.
- To disable this default, use the '-d' option.
- Variable plan: functions which are "is_" or "has_" return boolean
- functions which involve 'in' 'out' 'alt' pass-&-return strings
- functions which involve values pass-&-return ints....-1 means invalid
- gpio is always a short int
- Attack plan:
- mode set: check iomux, then create-&-use export
- -d set: check iomux, then low-level set
- read: check iomux, then check export, then use export
- -d: check iomux, then low-level read
- write: check iomux, then check export then set mode=out then use export
- -d: check iomux, then set direction=out, tne low-level write
- NOTE: 'read' and 'write' will auto-set the GPIO mode and disable 'alt'
- NOTE: 'read' and 'write' will auto-set the GPIO mode and disable 'alt'
-
- Classes: GPIO to access a pin through the export-gpio methods
- GPIO_DIRECT to access only through low-level calls
- read/write/mode will use GPIO unless the -d flag is used
- exports will always use GPIO
- readall/readallx/leds will use GPIO_DIRECT
- """
- from mmap import mmap
- from struct import pack, unpack
- import os, sys, argparse, pathlib, re, logging
- class Board:
- def __init__(self,full_name,short_name):
- self.name = full_name
- self.short_name = short_name
- def __repr__(self):
- return self.name
- board_i96 = Board("OrangePi i96", "OrangePi i96")
- board_2g = Board("OrangePi 2G-IOT","OrgPi 2G-iot")
- board_i96.PINS = (
- ("GND", "", -1, "", ""),
- ("GND", "", -1, "", ""),
- ("UART2.CTS", "B8", 40, "CTS", "ttyS1.cts"),
- ("PWR_BTN_N", "", -1, "", ""),
- ("UART2.TX", "C8", 104, "TX", "ttyS1.tx"),
- ("RST_BTN_N", "", -1, "1.4v", ""),
- ("UART2.RX", "C7", 103, "RX", "ttyS1.rx"),
- ("SPI2.CLK", "A2", 2, "CLK","spi2.clk"),
- ("UART2.RTS", "B9", 41, "RTS","ttyS1.rts"),
- ("SPI2.DI", "A4", 4, "DI", "spi2.di"),
- ("UART1.TX", "A14", 14, "TX", "ttyS0.tx"),
- ("SPI2.CS", "A6", 6, "CS", "spi2.cs"),
- ("UART1.RX", "C6", 102, "RX", "ttyS0.rx"),
- ("SPI2.DO", "A3", 3, "DO", "spi2.do"),
- ("I2C2.SCL", "A0", 0, "SCL", "i2c-1.scl"),
- ("I2S.LRCK", "A10", 10, "LRCK", "pcm.fp"),
- ("I2C2.SDA", "A1", 1, "SDA", "i2c-1.sda"),
- ("I2S.BCK", "A9", 9, "BCK", "pcm.clk"),
- ("I2C3.SCL", "B6", 38, "SCL", "i2c-2.scl"),
- ("I2S.DO", "A13", 13, "DO", "pcm.do"),
- ("I2C3.SDA", "B7", 39, "SDA", "i2c-2.sda"),
- ("I2S.DI", "A11", 11, "DI", "pcm.di"),
- ("GPIO.A", "A15", 15, "CTS", "ttyS0.cts"),
- ("GPIO.B", "A20", 20, "LCD", "lcd"),
- ("GPIO.C", "B24", 56, "ROM", "n/a"),
- ("GPIO.D", "D2", 66, "CTS", "ttyS2.cts"),
- ("GPIO.E", "D3", 67, "RTS", "ttyS2.rts"),
- ("GPIO.F", "A22", 22, "LCD", "lcd"),
- ("GPIO.G", "A30", 30, "LCD", "lcd"),
- ("GPIO.H", "A29", 29, "LCD", "lcd"),
- ("GPIO.I", "A28", 28, "LCD", "lcd"),
- ("GPIO.J", "A27", 27, "LCD", "lcd"),
- ("GPIO.K", "A26", 26, "LCD", "lcd"),
- ("GPIO.L", "A25", 25, "LCD", "lcd"),
- ("V_PAD", "", -1, "1.8v", ""),
- ("SYS_DCIN", "", -1, "n/c", ""),
- ("VDD_IN", "", -1, "5V", ""),
- ("SYS_DCIN", "", -1, "n/c", ""),
- ("GND", "", -1, "", ""),
- ("GND", "", -1, "", "")
- )
- deleted_board_2g_14_PINS = (
- ("VCC", "", -1,""),
- ("I2C1.SDA", "B31", 63, "SDA"),
- ("I2C1.SCL", "B30", 62, "SCL"),
- ("GPIO.B24", "B24", 56, ""),
- ("GND", "", -1, ""),
- ("UART1.RX", "C6", 102, "RX"),
- ("UART1.TX", "A14", 14, "TX"),
- ("UART1.CT", "A15", 15,"CTS"),
- ("VCC", "", -1,""),
- ("SPI2.DI", "A4", 4, "DI"),
- ("SPI2.DIO", "A3", 3, "DIO"),
- ("SPI2.CLK", "A2", 2, "CLK"),
- ("GND", "", -1, ""),
- ("I2C2.SDA", "A1", 1, ""),
- ("GPIO.C26", "C26", 122, "SIM"),
- ("GPIO.C27", "C27", 123, "SIM"),
- ("GPIO.C28", "C28", 124, "LCD"),
- ("GPIO.C29", "C29", 125, "LCD"),
- ("GPIO.C30", "C30", 126, "LCD"),
- ("GND", "", -1, ""),
- ("I2C3.SDA", "B7", 39, "SDA"),
- ("I2C3.SCL", "B6", 38, "SCL"),
- ("UART2.CT", "B8", 40, "CTS"),
- ("GND", "", -1, ""),
- ("UART2.RT", "B9", 41, "RTS"),
- ("GND", "", -1, ""),
- ("I2C2.SCL", "A0", 0, "SCL"),
- ("SPI2.CS0", "A5", 5, "CS0"),
- ("SPI2.CS1", "A6", 6, "CS1"),
- ("UART1.RT", "A16", 16, "RTS"),
- ("GND", "", -1, ""),
- ("GPIO.C25", "C25", 121, "SIM"),
- ("GPIO.C5", "C5", 101, ""),
- ("GND", "", -1, ""),
- ("GPIO.B5", "B5", 37, ""),
- ("UART2.RX", "C7", 103,""),
- ("UART2.TX", "C8", 104,""),
- ("GND", "", -1, ""),
- ("VCC", "", -1,""),
- ("VCC", "", -1,""),
- )
- board_2g.PINS = (
- ("V_PAD", "", -1, "2.8v", ""),
- ("VDD_IN", "", -1, "5V", ""),
- ("I2C1.SDA", "B31", 63, "SDA","i2c-0.sda"),
- ("VDD_IN", "", -1, "5V", ""),
- ("I2C1.SCL", "B30", 62, "SCL", "i2c-0.scl"),
- ("GND", "", -1, "", ""),
- ("GPIO.B24", "B24", 56, "", ""),
- ("UART2.TX", "C8", 104,"", "ttyS1.tx"),
- ("GND", "", -1, "", ""),
- ("UART2.RX", "C7", 103,"", "ttyS1.rx"),
- ("UART1.RX", "C6", 102, "RX", "ttyS0.rx"),
- ("GPIO.B5", "B5", 37, "", ""),
- ("UART1.TX", "A14", 14, "TX", "ttyS0.tx"),
- ("GND", "", -1, "", ""),
- ("UART1.CT", "A15", 15,"CTS", "ttyS0.cts"),
- ("GPIO.C5", "C5", 101, "", "",""),
- ("V_PAD", "", -1, "2.8v", ""),
- ("GPIO.C25", "C25", 121, "SIM", ""),
- ("SPI2.DI", "A4", 4, "DI", "spi-1.di"),
- ("GND", "", -1, "", ""),
- ("SPI2.DIO", "A3", 3, "DIO", "spi-1.do"),
- ("UART1.RT", "A16", 16, "RTS", "ttyS0.rts"),
- ("SPI2.CLK", "A2", 2, "CLK", "spi-1.clk"),
- ("SPI2.CS0", "A5", 5, "CS0", "spi-1.cs"),
- ("GND", "", -1, "", ""),
- ("SPI2.CS1", "A6", 6, "CS1", "spi-1.cs1"),
- ("I2C2.SDA", "A1", 1, "", "i2c-1.sda"),
- ("I2C2.SCL", "A0", 0, "SCL", "i2c-1.scl"),
- ("GPIO.C26", "C26", 122, "SIM", ""),
- ("GND", "", -1, "", ""),
- ("GPIO.C27", "C27", 123, "SIM", ""),
- ("UART2.RT", "B9", 41, "RTS", "ttyS1.rts"),
- ("GPIO.C28", "C28", 124, "LCD", "lcd"),
- ("GND", "", -1, "", ""),
- ("GPIO.C29", "C29", 125, "LCD", "lcd"),
- ("UART2.CT", "B8", 40, "CTS", "ttyS1.cts"),
- ("GPIO.C30", "C30", 126, "LCD", "lcd"),
- ("I2C3.SCL", "B6", 38, "SCL", "i2c2-scl"),
- ("GND", "", -1, "", ""),
- ("I2C3.SDA", "B7", 39, "SDA", "i2c2-sda"),
- )
- board_2g.other = (
- )
- board_i96.other = (
- ("LED2", "C30", 126, ""),
- ("LED3", "C29", 125, ""),
- ("LED5", "C5", 101, ""),
- ("J2", "C2", 98, "boot sd"),
- ("OTGPWR","A17",17,""),
- )
- class Cpu:
- def __init__(self,name):
- self.name = name
- RDA_PORTC_IOMUX = 0x11a09008
- RDA_PORTA_IOMUX = 0x11a0900c
- RDA_PORTB_IOMUX = 0x11a09010
- RDA_PORTD_IOMUX = 0x11a09014
- cpu_rda = Cpu("RDA8810")
- cpu_rda.IOMUX_ADDRESSES = (RDA_PORTA_IOMUX, RDA_PORTB_IOMUX, RDA_PORTD_IOMUX, RDA_PORTC_IOMUX)
- cpu = cpu_rda
- board = board_i96
- GPIO_PER_PORT = 32
- PAGE_MASK = ~0xFFF
- PAGE_OFFSET = 0xFFF
- SYS_PATH = "/sys/class/gpio/"
- def pin_has_export(gpio):
- return pathlib.Path('/sys/class/gpio/gpio{}'.format(gpio)).exists()
- def mem_set(address, bitmask, value):
- try:
- with open("/dev/mem","w+b") as m:
- mem = mmap(m.fileno(), 32, offset = address & PAGE_MASK)
- address &= PAGE_OFFSET
- data = unpack("<L",mem[address:address+4])[0]
- logging.debug("mem_set: current data is {} mask is {} value is {}".format(hex(data),hex(bitmask),value))
- if value:
- logging.debug("!! wtf? value is {} {} {}".format(value,bool(value),type(value)))
- data |= bitmask
- else:
- data &= ~bitmask
- logging.debug("mem_set: resulting data is {} ~mask is {} {}".format(hex(data),hex(~bitmask),hex(data & ~bitmask)))
- mem[address:address+4] = pack("<L",data)
- except PermissionError:
- print("failed to open /dev/mem.....you must execute this script as root")
- def mem_get(address, bitmask):
- try:
- with open("/dev/mem","r+b") as m:
- mem = mmap(m.fileno(), 32, offset = address & PAGE_MASK)
- address &= PAGE_OFFSET
- return unpack("<L",mem[address:address+4])[0] & bitmask
- except PermissionError:
- print("failed to open /dev/mem.....you must execute this script as root")
- """ decide which kind of GPIO """
- def GPIO_factory(gpio,direct):
- if direct:
- return GPIO_DIRECT(gpio)
- else:
- return GPIO(gpio)
- """ via the gpio/export system """
- class GPIO:
- ''' this object owns a pin, assures it has an export and accesses it through the gpio-export mechanism'''
- def __init__(self, gpio):
- self.gpio = gpio
- self.set_iomux(True)
- create_export(gpio)
- def get(self):
- logging.debug("GPIO.get")
-
- with open(SYS_PATH + "gpio{}/value".format(self.gpio)) as f:
- r = int(f.read())
- logging.debug("pin_read of {} returns {}".format(self.gpio,r))
- return r
- def set(self, value):
- logging.debug("GPIO.set {} {}".format(self.gpio, value))
- self.set_mode('out')
- with open(SYS_PATH + "gpio{}/value".format(self.gpio),"w+b") as f:
- f.write(bytes(str(value),"utf-8"))
- def set_mode(self,mode_string):
- with open('/sys/class/gpio/gpio{}/direction'.format(self.gpio),'w') as f:
- f.write(mode_string)
- def get_mode_value(self):
- with open('/sys/class/gpio/gpio{}/direction'.format(self.gpio)) as f:
- return f.read().strip(), self.get()
- def set_iomux(self, gpio_mode):
- ''' set value=True for this pin to be GPIO,
- False for this pin to be special function'''
- logging.debug("GPIO: set iomux for pin {} to {}".format(self.gpio,gpio_mode))
- port_group = self.gpio // GPIO_PER_PORT
- port_offset = self.gpio % GPIO_PER_PORT
- mem_set(cpu.IOMUX_ADDRESSES[port_group], 1 << port_offset, gpio_mode)
- if gpio_mode == False:
- logging.debug("GPIO.set_iomux with mode {}".format(gpio_mode))
- remove_export(self.gpio)
- def get_iomux(self):
- ''' returns 1 when it's in GPIO mode, 0 for alt mode '''
- logging.debug("GPIO check the IOMUX for gpio {}".format(self.gpio))
- port_group = self.gpio // GPIO_PER_PORT
- port_offset = self.gpio % GPIO_PER_PORT
- logging.debug("check IOMUX at address {}".format(hex(cpu.IOMUX_ADDRESSES[port_group])))
- return mem_get(cpu.IOMUX_ADDRESSES[port_group], 1 << port_offset)
-
- def __repr__(self):
- return("gpio"+str(self.gpio))
- class GPIO_DIRECT(GPIO):
- def __init__(self,gpio):
- self.gpio = gpio
- def set(self,value):
- logging.debug("GPIO_DIRECT.set {} value: {}".format(self.gpio,value))
- if self.get_iomux()==0:
- self.set_iomux(1)
- self.set_mode('out')
- low_level_write(self.gpio,IO_DATA,value)
- def get(self):
- if self.get_iomux() == 0:
- self.set_iomux(1)
- self.set_mode('in')
- return low_level_read(self.gpio,IO_DATA)
- def get_mode_value(self):
- iomux = self.get_iomux()
- if not iomux:
- return 'alt','?'
- d = low_level_read(self.gpio, IO_DIR)
- m = 'in' if d else 'out'
- if not pin_has_export(self.gpio):
- m = m+'*'
- return m, low_level_read(self.gpio,IO_DATA)
- def set_mode(self, mode_string):
- low_level_set_mode(self.gpio, mode_string);
- def set_iomux(self, gpio_mode):
- super().set_iomux(gpio_mode)
- def create_export(gpio):
- ''' make sure this gpio has an export set in the /sys/class/gpio dir '''
- if not pin_has_export(gpio):
- with open(SYS_PATH + 'export','w') as f:
- f.write(str(gpio))
- if not pin_has_export(gpio):
- print("could not create the gpio-export for pin {}".format(gpio))
- print("perhaps you should run this program as root")
- sys.exit(1)
- return
- def remove_export(gpio):
- if pin_has_export(gpio):
- with open(SYS_PATH + 'unexport','w') as f:
- f.write(str(gpio))
- return
-
- """ bypass the gpio/export system """
- PORTA_IOBASE = 0x20930000
- PORTB_IOBASE = 0x20931000
- PORTC_IOBASE = 0x11a08000
- PORTD_IOBASE = 0x20932000
- IOBASE_ADDRESSES = (PORTA_IOBASE, PORTB_IOBASE, PORTD_IOBASE, PORTC_IOBASE)
- IO_DIR = 0
- IO_DATA = 0xc
- def low_level_read(gpio, address_offset):
- port_group = gpio // GPIO_PER_PORT
- port_offset = gpio % GPIO_PER_PORT
- address = IOBASE_ADDRESSES[port_group] + address_offset
- r = mem_get(address, 1 << port_offset)
- logging.debug("low_level_read of address {} and bit {} returns {}".format(hex(address),port_offset,hex(r)))
- return 1 if r else 0
- def low_level_write(gpio, address_offset, data):
- port_group = gpio // GPIO_PER_PORT
- port_offset = gpio % GPIO_PER_PORT
- address = IOBASE_ADDRESSES[port_group] + address_offset
- mem_set(address, 1 << port_offset, data)
-
- def low_level_set_mode(gpio, mode):
- if mode == 'alt':
- print("illegal call to low_level_set_mode")
- sys.exit(1)
- low_level_write(gpio, IO_DIR, 0 if mode=='out' else 1)
-
- def low_level_get_mode(gpio):
- return low_level_read(gpio, IO_DIR)
- def do_readall():
- exports_dirty = False
- print("""
- +-----+-----+----------+------+-+ {} +-+------+----------+-----+-----+
- | gpio| alt | i96 Name | Mode | V | Physical | V | Mode | i96 Name | alt | gpio|
- +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+""".format(
- board.short_name))
- for i in range(20):
- left_gpio = board.PINS[2*i][2]
- if left_gpio != -1:
- left_g = GPIO_DIRECT(left_gpio)
- left_mode, left_value = left_g.get_mode_value()
- left_gpio_str = str(left_gpio)
- if '*' in left_mode: exports_dirty = True
- else:
- left_gpio_str = left_mode = left_value = ""
- right_gpio = board.PINS[2*i+1][2]
- if right_gpio != -1:
- right_g = GPIO_DIRECT(right_gpio)
- right_mode, right_value = right_g.get_mode_value()
- right_gpio_str = str(right_gpio)
- if '*' in right_mode: exports_dirty = True
- else:
- right_gpio_str = right_mode = right_value = ""
- left_value,right_value = str(left_value),str(right_value)
- print("| {:3s} | {:4s}| {:9s}| {:4s} | {:1s} | {:2d} || {:2d} | {:1s} | {:4s} | {:9s}| {:4s}| {:3s} |".format(
- left_gpio_str,board.PINS[2*i][3],board.PINS[2*i][0],
- left_mode,left_value,2*i+1,
- 2*i+2,right_value,right_mode,board.PINS[2*i+1][0],
- board.PINS[2*i+1][3],right_gpio_str))
- print("+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+")
- if exports_dirty:
- print("Note: *these pins are set to GPIO mode but do NOT have exports in /sys/class/gpio")
- def do_exports():
- print("GPIO Pins Mode Value Located")
- for f in os.listdir(SYS_PATH):
- if re.match('gpio\d',f):
- gpio = GPIO(int(f[4:]))
- m,v = gpio.get_mode_value()
- iop = ""
- for i in range(len(board.PINS)):
- if board.PINS[i][2]==gpio.gpio:
- iop = (board.short_name + " I/O: {}").format(i+1)
- break
- for i in range(len(board.other)):
- if board.other[i][2]==gpio:
- iop = board.other[i][0]
- break
- print("{:>9s} {:3} {:<6} {}".format(f,m,v,iop))
- def do_leds():
- print("+------+-------+------+-----+")
- print("| gpio | func | mode |value|")
- print("+------+-------+------+-----+")
- for p in board.other:
-
- g = GPIO_DIRECT(p[2])
- m,v = g.get_mode_value()
- print("| {:3} | {:6}| {:4} | {:1} |".format(
- p[2],p[0],m,v))
- print("+------+-------+------+-----+")
- def do_read():
- logging.debug("do_read: %d",args.gpio)
- gpio = args.gpio
- g = GPIO_factory(gpio,args.direct)
- print(g.get())
- def do_write():
- logging.debug("do_write: %d %s",args.gpio, args.extra)
- gpio = args.gpio
- g = GPIO_factory(gpio, args.direct)
- if args.extra in ('1', 'on', 'ON'):
- v = 1
- elif args.extra in ('0', 'off', 'OFF'):
- v = 0
- else:
- print("the 'write' command requires a 2nd argument, either 0 or 1")
- sys.exit(1)
- g.set(v)
- def do_mode():
- logging.info("do_mode %d %s", args.gpio, args.extra)
- logging.info("the -d flag is {}".format(args.direct))
- if not args.gpio or args.gpio<0 or args.gpio>127:
- print("the {} command requires a gpio number".format(args.cmd))
- sys.exit(1)
- if args.extra == None:
- m,v = GPIO_DIRECT(args.gpio).get_mode_value()
- print(m)
- return
- if args.extra == "alt":
- args.direct = True
- gpio = GPIO_factory(args.gpio,args.direct)
- if args.extra in ('in','out'):
- logging.info("set mode: %s",args.extra)
- gpio.set_iomux(True)
- gpio.set_mode(args.extra)
- elif args.extra=='alt':
- logging.info("set alt mode")
- gpio.set_iomux(False)
- def do_readallx():
- exports_dirty = False
- print("""
- +-----+-----+----------+------+-+ {} +-+------+----------+-----+-----+
- | gpio| RDA | alt name | Mode | V | Physical | V | Mode | alt name | RDA | gpio|
- +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+""".format(
- board.short_name))
- for i in range(20):
- left_gpio = board.PINS[2*i][2]
- if left_gpio != -1:
- left_g = GPIO_DIRECT(left_gpio)
- left_mode, left_value = left_g.get_mode_value()
- left_gpio_str = str(left_gpio)
- if '*' in left_mode: exports_dirty = True
- else:
- left_gpio_str = left_mode = left_value = ""
- right_gpio = board.PINS[2*i+1][2]
- if right_gpio != -1:
- right_g = GPIO_DIRECT(right_gpio)
- right_mode, right_value = right_g.get_mode_value()
- right_gpio_str = str(right_gpio)
- if '*' in right_mode: exports_dirty = True
- else:
- right_gpio_str = right_mode = right_value = ""
- left_value,right_value = str(left_value),str(right_value)
- print("| {:3s} | {:4s}| {:9s}| {:4s} | {:1s} | {:2d} || {:2d} | {:1s} | {:4s} | {:9s}| {:4s}| {:3s} |".format(
- left_gpio_str,board.PINS[2*i][1],board.PINS[2*i][4],
- left_mode,left_value,2*i+1,
- 2*i+2,right_value,right_mode,board.PINS[2*i+1][4],
- board.PINS[2*i+1][1],right_gpio_str))
- print("+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+")
- if exports_dirty:
- print("Note: *these pins are set to GPIO mode but do NOT have exports in /sys/class/gpio")
- print("Note: the alt names are based on the Linux naming scheme")
- args = None
- if __name__ == "__main__":
-
-
- parser = argparse.ArgumentParser()
- parser.add_argument('-v','--version', action='version', version='gpio 2.0\n python rewrite by Pat Beirne')
- parser.add_argument('cmd',help="one of: read, write, mode, readall, readallx")
- parser.add_argument('gpio',nargs='?',type=int,help="gpio number 0...126")
- parser.add_argument('extra',nargs='?')
- parser.add_argument('-d',"--direct",help="use low-level access",action="store_true")
- parser.add_argument('-2',"--op2giot",help="configure for OrangePi 2G-iot",action="store_true")
- args = parser.parse_args()
- if pathlib.Path('/etc/OrangePi_2G_IOT').exists():
- board = board_2g
- if args.op2giot:
- board = board_2g
-
- switcher = {"readall":do_readall,
- "readallx":do_readallx,
- "status":do_readall,
- "statusx":do_readallx,
- "leds":do_leds,
- "mode":do_mode,
- "read":do_read,
- "write":do_write,
- "exports":do_exports}
- f = switcher.get(args.cmd)
- if not f:
- print("the available commands are:", ", ".join(sorted(list(switcher.keys()))))
- print("function",args.cmd,"not found")
- sys.exit(1)
- f()
-
|