Using GPIO and PWM Interfaces in Harmony OS for Peripheral Control
Using the GPIO Interface to Register Interrupt Handlers for USER Button Response (Input)
- Set the internal pull-up/down state with
IoSetPull(if no external pull-up resistor is present, it must be enabled to reliably detect falling edges). - Register the interrupt handler using
GpioRegisterIsrFunc. Refer to the header file comments for specific parameter usage. - For details, see the comments in
wifiiot_gpio.handwifiiot_gpio_ex.h.
Controlling the HiSpark Wi-Fi IoT Development Kit Traffic Light Board
- Use the PWM interface to generate a PWM square wave for buzzer control.
- The GPIO interface usage is similar to the previous example.
- For details, see the comments in
wifiiot_pwm.h.
Pin Mappping Between the Core Board, Traffic Light Board Peripherals, and the Hi3861 MCU
- Core Board
- GPIO_9 – LED (output low to turn on)
- GPIO_5 – Button (interrupt to toggle LED state)
- Traffic Light Board
- GPIO_8 – Buzzer (PWM output for sound)
- GPIO_9 – Button (interrupt to switch active LED and toggle buzzer)
- GPIO_10 – Red LED (output high to turn on)
- GPIO_11 – Green LED (output high to turn on)
- GPIO_12 – Yellow LED (output high to turn on)
How to Build
-
Copy
traffic_light_demo.candBUILD.gnfrom this directory toapplications/sample/wifi-iot/app/iothardwarein the OpenHarmony source tree. -
Modify the
featureslist inapplications/sample/wifi-iot/app/BUILD.gn: ``` features = [ "iothardware:traffic_light_demo", ] -
Run from the top-level directory of the OpenHarmony source: ``` python build.py wifiiot
Build Errors and Solutions
- Error: undefined reference to
hi_pwm_initand otherhi_pwm_functions-
Cause: The PWM configuration option in the hi3861_sdk is disabled by default.
-
Solution: Edit
vendor/hisi/hi3861/hi3861/build/config/usr_config.mkand change the line: ```CONFIG_PWM_SUPPORT is not set
to: ``` CONFIG_PWM_SUPPORT=y
-