Sifli Component Usage - Sensor Component Example

1. Introduction

SiFli Component Registry Documentation
SiFli Component Registry Homepage
Documentation for Packaging and Uploading Components
SiFli Package Registry

The goal of this article is to introduce how to use SiFli components.
We will use the sensor-algorithm component from the component registry to implement a motion sensor function.
Ultimately, we can observe the angle output data from the LSM6DSL sensor.
The development board used here is Huangshanpai (as it comes with an integrated LSM6DSL sensor).

2. Component Overview

You can find the required components on the SiFli Component Registry Homepage.
Click on a component to view its functionality and usage instructions.

The webpage includes package information. The entry under Add to conanfile.py requires, specifically sensor-algorithm/[^0.1]@nuoning, is the component information we need.

3. Adding a Component

SiFli Component Registry Documentation

No user registration is required to use components.
Here, we demonstrate adding the sensor-algorithm component to the hello_world project.

1. Initialize Dependencies

Navigate into the project’s project directory and run: sdk.py sf-pkg init
Upon success, a conanfile.py file will be generated with default content as shown below:

2. Search for Components

In addition to searching via the component registry website, you can also use the command:
sdk.py sf-pkg search <package_name> to find components.
Example: sdk.py sf-pkg search tf_hot_plug

3. Add Dependency

Add the component reference sensor-algorithm/[^0.1]@nuoning (from earlier) to the requires field, as shown in the image:

4. Install Dependencies

Run sdk.py sf-pkg install to install dependencies.
Upon successful installation, you will see the message Packages installed successfully, and a new folder named sf-pkgs will appear under the project directory.
The sf-pkgs folder contains the driver code provided by the component. At this point, component installation is complete.

5. Dependency Management

All installed dependencies are managed within the sf-pkgs folder.

Component pages on the web usually include usage instructions and API documentation. Installed component libraries also contain a README.md file.
To use the component, simply include the relevant header file to access the APIs. There’s no need to specify absolute paths when including headers—Conan automatically handles path configuration.
Any additional Kconfig options defined by the component are automatically added to the menuconfig under SiFli External Components.

4. Using the Component

1. menuconfig Configuration

Enter the project directory of the hello_world project and enable LSM6DSL-related settings in menuconfig.

2. Component-specific menuconfig Settings

Some components include configurable options defined in their Kconfig file during creation.
When using such components, their Kconfig entries are automatically integrated into menuconfig. You can configure them under SiFli External Components in menuconfig.
Here, we set the sensor’s full scale range to ±2g (acceleration), ±125dps (angular rate), and the sampling rate to 200Hz.

3. Function Call in main.c

Add the header: #include "sf_lsm6dsl.h"
Call the component functions within the main function. Refer to the component documentation for details.

#include "rtthread.h"
#include "bf0_hal.h"
#include "drv_io.h"
#include "stdio.h"
#include "string.h"

#include "sf_lsm6dsl.h"

int main(void)
{
    /* Output a message on console using printf function */
    rt_kprintf("Hello world!\n");

    struct rt_sensor_config cfg;
    rt_device_t lsm6d_dev, lsm6d_gyro_dev;
    sf_lsm6dsl_runner_t runner;
    sensors_init(&cfg, &lsm6d_dev, &lsm6d_gyro_dev);
    sf_lsm6dsl_runner_init(&runner, lsm6d_dev, lsm6d_gyro_dev);
    sf_lsm6dsl_runner_start(&runner, sf_lsm6dsl_sample_period_ticks()); 
    /* Infinite loop */
    while (1)
    {
        // Delay for 1000 ms to yield CPU time to other threads
        rt_thread_mdelay(1000);
    }
    return 0;
}

4. Build and Flash

Build command: scons --board=sf32lb52-lchspi-ulp -j8
Flash command: .\build_sf32lb52-lchspi-ulp_hcpu\uart_download.bat

View output:

5. Summary

This article briefly explains how to use dependencies from the SiFli Component Registry, using sensor-algorithm as an example to walk through the entire process.
Additionally, users are encouraged to share and upload their own components. Future updates will cover how to package and upload your own components.
If you have any questions or issues, feel free to leave a comment below—let’s improve together.

Documentation for Packaging and Uploading Components