RK3568 Development Board OpenHarmony Practice HDF Driver Control LED
RK3568 Development Board OpenHarmony Practice HDF Driver Control LED
Blog Article
RK3568 Development Board OpenHarmony Practice HDF Driver Control LED
In the application code, we implement the following functions:
When the application is started, the command line parameters will be obtained. If the command line has no parameters, the LED light will flash in a loop; if the command line has parameters, the LED light will be turned on or off according to the transmitted parameters. Bind the HDF service of the LED light through HdfIoServiceBind, obtain the HDF space buffer, and write control data to the buffer. Then, send the data to the HDF driver through the LED_WRITE command to control the LED light on and off. At the end of the program, the HDF space buffer and HDF service will be recycled.
Next, write the application test file led_test.c, the complete code is shown below.
The above code is used to build a build script for an executable file called "led_test". It uses the GN (Generate Ninja) build system, which is a meta-build system for generating Ninja build files.
Lines 1-2 define two variables HDF_FRAMEWORKS and HDF_ADAPTER, which point to the paths of the HDF (HardwareDriver Foundation) core framework and adapter respectively. These paths are relative to the project root directory.
Lines 4-5 use import statements to import two GNI (GN Include) files. GNI files are files used by the GN build system to contain variable definitions, functions, and templates. The files imported here may contain some predefined variables, functions, or build rules to support the build process. //build/ohos.gni may contain OpenHarmony-specific build configurations, while $HDF_ADAPTER/uhdf2/uhdf.gni may contain configurations related to uHDF (Unified Hardware Driver Framework).
Line 7 prints a message to the console indicating that the led_test example is being compiled.
Lines 9-40 define an ohos_executable target named led_test, which is a build rule used to generate an executable file. The following is the specific configuration of the target:
sources: Specifies a list of source files, here there is only one file led_test.c.
include_dirs: Specifies a list of header file search paths. These paths are used to find included files (files referenced by the #include directive) at compile time. These paths include multiple subdirectories of the HDF framework, adapters, and header file paths for some third-party libraries and internal tool libraries.
external_deps: Specifies a list of external dependencies. These dependencies are libraries that need to be linked during the build process. Several libraries are listed here, such as c_utils:utils, hdf_core:libhdf_platform, etc. These libraries provide the functions required to build led_test.
cflags: Specifies a list of flags passed to the C compiler. Some common compilation options are included here, such as -Wall (turn on all warnings), -Wextra (turn on additional warnings), -Werror (treat all warnings as errors), and two options for turning off specific warnings.
part_name: Specifies the name of the part to which the build product belongs, here is demos.
install_enable: Set to true to indicate that the build product should be installed. This may mean that after a successful build, the led_test executable file will be copied to a specific directory for easy execution or distribution.