GPIO
General Purpose Input Output is referred to as GPIO, or bus extender.
High speed gpio and universal gpio on the K210 On the K210, GPIO has the following characteristics:
High speed GPIO: The high-speed GPIO is GPIOHS, a total of 32. Has the following characteristics: • Configurable input and output signals • Each IO has an independent interrupt source • Interrupt support edge trigger and level trigger • Each IO can be assigned to one of the 48 pins on the FPIOA • Configurable up and down, or high resistance
General GPIO:
There are 8 general-purpose GPIOs with the following characteristics: • 8 IOs use one interrupt source • Configurable input and output signals • Configurable trigger IO total interrupt, edge trigger and level trigger • Each IO can be assigned to one of the 48 pins on the FPIOA
Attention:
Some GPIOHS used by default, don't use these GPIOHS if you don't have to, GPIOHS used as follows:
GPIOHS | Function |
---|---|
GPIOHS31 | LCD_DC |
GPIOHS30 | LCD_RST |
GPIOHS29 | SD_CS |
GPIOHS28 | MIC_LED_CLK |
GPIOHS27 | MIC_LED_DATA |
1. Constructor
Class GPIO(ID, MODE, PULL, VALUE)
Create a new SPI object with the specified parameters
1.1. Parameters
ID
: The GPIO pin used (must be specified using the constants in GPIO)MODE
: GPIO mode• GPIO.IN is the input mode
• GPIO.OUT is the output mode
PULL
: GPIO pull-down mode * • GPIO.PULL_UP pull up• GPIO.PULL_DOWN dropdown
• GPIO.PULL_NONE does not pull up or pull down
2. method
2.1. value
Modify/read GPIO pin status
GPIO.value([value])
Parameters
[value]
: optional parameter, if this parameter is not empty, return the current GPIO pin status
return value
Returns the current GPIO pin status if the [value]
parameter is not empty
2.2. irq
Configure an interrupt handler to call when the pin's trigger source is active. If the pin mode is pin.in, the trigger source is an external value on the pin.
GPIO.irq(CALLBACK_FUNC, TRIGGER_CONDITION, GPIO.WAKEUP_NOT_SUPPORT, PRORITY)
Parameters
CALLBACK_FUNC
: callback function, called when the interrupt is triggered, it has two parameters, GPIO and PIN_NUM• GPIO returns a GPIO object
• PIN_NUM returns the GPIO pin number that triggered the interrupt (only GPIOHS supports interrupts, so the pin number here is also the GPIOHS pin number)
TRIGGER_CONDITION
: Trigger interrupt when GPIO pin is in this state• GPIO.IRQ_RISING rising edge trigger
• GPIO.GPIO.IRQ_FALLING falling edge trigger
• GPIO.IRQ_BOTH is triggered on both rising and falling edges
return value
no
2.3. disirq
Close interrupt
GPIO.disirq()
Parameters
no
return value
no
2.4. mode
GPIO mode
GPIO.mode(MODE)
Parameters
MODE
• GPIO.IN is the input mode
• GPIO.OUT is the output mode
return value
no
2.5. pull
GPIO pull-down mode
GPIO.pull(PULL)
Parameters
PULL
• GPIO.IRQ_RISING rising edge trigger
• GPIO.IRQ_FALLING falling edge trigger
• GPIO.IRQ_BOTH is triggered on both rising and falling edges
return value
no
3. Constant
GPIO0
: GPIO0GPIO1
: GPIO1GPIO2
: GPIO2GPIO3
: GPIO3GPIO4
: GPIO4GPIO5
: GPIO5GPIO6
: GPIO6GPIO7
: GPIO7GPIOHS0
: GPIOHS0GPIOHS1
: GPIOHS1GPIOHS2
: GPIOHS2GPIOHS3
: GPIOHS3GPIOHS4
: GPIOHS4GPIOHS5
: GPIOHS5GPIOHS6
: GPIOHS6GPIOHS7
: GPIOHS7GPIOHS8
: GPIOHS8GPIOHS9
: GPIOHS9GPIOHS10
: GPIOHS10GPIOHS11
: GPIOHS11GPIOHS12
: GPIOHS12GPIOHS13
: GPIOHS13GPIOHS14
: GPIOHS14GPIOHS15
: GPIOHS15GPIOHS16
: GPIOHS16GPIOHS17
: GPIOHS17GPIOHS18
: GPIOHS18GPIOHS19
: GPIOHS19GPIOHS20
: GPIOHS20GPIOHS21
: GPIOHS21GPIOHS22
: GPIOHS22GPIOHS23
: GPIOHS23GPIOHS24
: GPIOHS24GPIOHS25
: GPIOHS25GPIOHS26
: GPIOHS26GPIOHS27
: GPIOHS27GPIOHS28
: GPIOHS28GPIOHS29
: GPIOHS29GPIOHS30
: GPIOHS30GPIOHS31
: GPIOHS31GPIO.IN
: input modeGPIO.OUT
: output modeGPIO.PULL_UP
: Pull upGPIO.PULL_DOWN
: drop downGPIO.PULL_NONE
: does not pull up or pull downGPIO.IRQ_RISING
: rising edge triggerGPIO.IRQ_FALLING
: falling edge triggerGPIO.IRQ_BOTH
: Both rising and falling edges are triggered
3.1. DEMO1
import utime
from Maix import GPIO
fm.register(board_info.LED_R,fm.fpioa.GPIO0)
led_r=GPIO(GPIO.GPIO0,GPIO.OUT)
utime.sleep_ms(500)
led_r.value()
fm.unregister(board_info.LED_R,fm.fpioa.GPIO0)
3.2. DEMO2
import utime
from Maix import GPIO
fm.register(board_info.LED_R,fm.fpioa.GPIO0)
led_r=GPIO(GPIO.GPIO0,GPIO.IN)
utime.sleep_ms(500)
led_r.value()
fm.unregister(board_info.LED_R,fm.fpioa.GPIO0)
3.3. DEMO3
import utime
from Maix import GPIO
def test_irq(GPIO,pin_num):
print("key",pin_num,"\n")
fm.register(board_info.BOOT_KEY,fm.fpioa.GPIOHS0)
key=GPIO(GPIO.GPIOHS0,GPIO.IN,GPIO.PULL_NONE)
utime.sleep_ms(500)
key.value()
key.irq(test_irq,GPIO.IRQ_BOTH,GPIO.WAKEUP_NOT_SUPPORT,7)
key.disirq()
fm.unregister(board_info.BOOT_KEY,fm.fpioa.GPIOHS0)