Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Using GPIO and PWM Interfaces in Harmony OS for Peripheral Control

Tech May 19 2

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.h and wifiiot_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

  1. Copy traffic_light_demo.c and BUILD.gn from this directory to applications/sample/wifi-iot/app/iothardware in the OpenHarmony source tree.

  2. Modify the features list in applications/sample/wifi-iot/app/BUILD.gn: ``` features = [ "iothardware:traffic_light_demo", ]

  3. Run from the top-level directory of the OpenHarmony source: ``` python build.py wifiiot

    
    
Build Errors and Solutions
  1. Error: undefined reference to hi_pwm_init and other hi_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.mk and change the line: ```

      CONFIG_PWM_SUPPORT is not set

      
      to: ```
      CONFIG_PWM_SUPPORT=y
      
      

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.