[HarmonyOS HiSpark AI Camera Trial Serial] Harmony application programming GPIO programming stepping pit notes

   GPIO refers to general-purpose input and output. Generally, GPIO controllers manage GPIO pins in groups. For example, in STM32, GPIOs are usually grouped into groups A, B, and C and managed by different controllers. The corresponding operation on the GPIO pin can be completed by reading and writing the register corresponding to each IO. Including:
1. Set the direction of the IO port: input or output. This Harmony board does not support high-impedance state;
2. Set the mode of the IO port: pull-up, pull-down, floating, etc.;
3. Read and write the power of the IO port Flat value: complete the reading or output of the logic level;
4. Set external interrupt: set the interrupt response function of the IO port and the corresponding trigger mode. The interrupt can also be disabled or enabled.

  Excerpts of commonly used GPIO driver API interfaces in HarmonyOS:

Function classification Interface name description
GPIO read GpioRead Read pin level value
GPIO write GpioWrite Write pin level value
GPIO configuration-1 GpioSetDir Set pin direction
GPIO configuration-2 GpioGetDir Get pin direction
GPIO interrupt setting-1 GpioSetIrq Set the interrupt service function corresponding to the pin
GPIO interrupt setting-2 GpioUnSetIrq Cancel the interrupt service function corresponding to the pin
GPIO interrupt settings-3 GpioEnableIrq Enable pin interrupt
GPIO interrupt setting-4 GpioDisableIrq Disable pin interrupt

Note: The above interface can only be used in the kernel mode, and is not supported in the user mode.

1) How to determine the pin number of
  the IO according to the schematic diagram. The LED pin used this time can be known as GPIO2_3 from the schematic diagram of the development board.
Insert picture description here
Determine the pin ID of the GPIO:
  different SOC chips due to their GPIO controller model, parameters, and control The conversion method of GPIO pin number is different depending on the driver.
Hi3516DV300 controller manages 12 groups of GPIO pins, 8 in each group.
GPIO number = GPIO group index (0~11) * number of GPIO pins in each group (8) + offset in the group
Example: GPIO number of GPIO2_3 = 2* 8 + 3 = 19

2) The use of the GPIO driver API interface function
Insert picture description here
  passed when compiled, but an error occurred during linking, ld.lld:error:undefined symbol:xxxxxx , undefined error.
Reference: https://device.harmonyos.com/cn/docs/develop/drive/oem_drive_gpio_des-0000001050058978 . The GPIO driver API interface is only used in the kernel mode and does not support use in the user mode, so even if the compilation passes If the program is linked, it will fail because there is no relevant definition.

Note: From the electronic enthusiast forum.
My homepage: https://bbs.elecfans.com/user/2105315/

Guess you like

Origin blog.csdn.net/qq_33475105/article/details/110947863