1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- from mmap import mmap
- import os, sys, time, struct
- PORTC_GPIO_MASK = 0
- PORTA_GPIO_MASK = 0x7e508000
- PORTB_GPIO_MASK = 0
- PORTD_GPIO_MASK = 0xc
- PORTB_GPIO_MASK_NO_CTSRTS = 0x300
- PORTC_SF_MASK = 0xfffffe3f
- PORTA_SF_MASK = 0xffff91a0
- PORTB_SF_MASK = 0xfffffc3f
- PORTD_SF_MASK = 0xFFFFFFFF
- PORTC_IOMUX = 0x11a09008
- PORTA_IOMUX = 0x11a0900c
- PORTB_IOMUX = 0x11a09010
- PORTD_IOMUX = 0x11a09014
- PAGE_MASK = ~0xFFF
- PAGE_OFFSET = 0xFFF
- def get_word(mapfile, address):
- address &= PAGE_OFFSET
- return struct.unpack("<L", mapfile[address:address+4])[0]
- def put_word(mapfile, address, data):
- address &= PAGE_OFFSET
- mapfile[address:address+4] = struct.pack("<L",data)
- if __name__ == "__main__":
- print("OrangePi-i96 fixup GPIO pins")
- print("Version 1.0")
- try:
- with open("/dev/mem","r+b") as m:
- mem = mmap(m.fileno(), 32, offset = PORTC_IOMUX & PAGE_MASK)
-
- put_word(mem, PORTC_IOMUX, get_word(mem, PORTC_IOMUX) | PORTC_GPIO_MASK)
- put_word(mem, PORTA_IOMUX, get_word(mem, PORTA_IOMUX) | PORTA_GPIO_MASK)
- put_word(mem, PORTB_IOMUX, get_word(mem, PORTB_IOMUX) | PORTB_GPIO_MASK)
- put_word(mem, PORTD_IOMUX, get_word(mem, PORTD_IOMUX) | PORTD_GPIO_MASK)
-
- put_word(mem, PORTC_IOMUX, get_word(mem, PORTC_IOMUX) & PORTC_SF_MASK)
- put_word(mem, PORTA_IOMUX, get_word(mem, PORTA_IOMUX) & PORTA_SF_MASK)
- put_word(mem, PORTB_IOMUX, get_word(mem, PORTB_IOMUX) & PORTB_SF_MASK)
- print("GPIO pins corrected to agree with the i96 bus spec")
- except PermissionError:
- print("failed to open /dev/mem......you must execute this script as root")
- exit(2)
|