v2.2.1:GPIO extender configuration Guide:

To configure any gpio extender, you have four functions:

1- the function: set_direction(direction, position, length): Used to set the direction of the gpios, we can set one or more gpios starting from the position index.

2- the function: get_direction(position): Used to read the direction of any gpio.

3- the function: set_outvalue(value, position, length): Used to set the value of the gpios, we can set one or more gpios starting from the position index.

4- the function: get_iovalue(position): Used to read the value of any gpio.

Example:

To configure the gpio CLK_SEL0:

from io_extender import PCA9554
from libnxembeddedtools.i2c.i2c_lib import I2cLib
from i2c.i2cllra import I2CLowLevelRegisterAccess

i2c = I2cLib()
i2c.configure()

address = 0x24
extender_24 = I2CLowLevelRegisterAccess(i2c, address)
io_ext24 = PCA9554(extender_24)

#make direction of bit in position 7 to Input
position = 7
#make direction of one bit starting from the 7th bit to Input
length = 1
io_ext24.set_direction("I", position, length)

#make direction of bit in position 4 to Output
position = 4
#make direction of 3 bits starting from the 4th bit to Output
length = 3  #bits 4, 5, 6 to Output
io_ext24.set_direction("O", position, length)
#set value of bit 4, 5, 6 to '0'
io_ext24.set_outvalue(0, position, length)

© NanoXplore 2022