1 Star 0 Fork 5.2K

Cain / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
development.md 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
wenjun 提交于 2020-09-08 10:08 . add OpenHarmony 1.0 baseline

Development

  1. Complete the operations described in Getting Started with Hi3861.

    LED control examples are stored in the file applications/sample/wifi-iot/app/iothardware/led_example.c.

  2. Understand the cable connections by referring to the schematic diagram. The LED is connected to the function multiplexing pin WIFI_IOT_IO_NAME_GPIO_9.

    NOTE: For details about the schematic diagram of the development board, contact the Hi3861 customer service personnel.

  3. Initialize the GPIO pin, specify the pin usage, and create a task to turn on or off the LED periodically so that the LED blinks.

    static void LedExampleEntry(void)
    {
        osThreadAttr_t attr;
    
        /* Initialize the GPIO pin. */
        GpioInit();
        /* Configure GPIO pin 9. */
        IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_GPIO);
        /* Set pin 9 as the output direction. */
        GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_DIR_OUT);
    
        attr.name = "LedTask";
        attr.attr_bits = 0U;
        attr.cb_mem = NULL;
        attr.cb_size = 0U;
        attr.stack_mem = NULL;
        attr.stack_size = LED_TASK_STACK_SIZE;
        attr.priority = LED_TASK_PRIO;
    
        /* Start the task. */
        if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
            printf("[LedExample] Falied to create LedTask!\n");
        }
    }
  4. Use a cyclic task in which the LED periodically turns on and off to implement LED blinking.

    static void *LedTask(const char *arg)
    {
        (void)arg;
        while (1) {
            switch (g_ledState) {
                case LED_ON:
                    GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1);
                    usleep(LED_INTERVAL_TIME_US);
                    break;
                case LED_OFF:
                    GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0);
                    usleep(LED_INTERVAL_TIME_US);
                    break;
                case LED_SPARK:
                    GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 0);
                    usleep(LED_INTERVAL_TIME_US);
                    GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, 1);
                    usleep(LED_INTERVAL_TIME_US);
                    break;
                default:
                    usleep(LED_INTERVAL_TIME_US);
                    break;
            }
        }
        return NULL;
    }
  5. Call SYS_RUN() of OpenHarmony to start the service. (SYS_RUN is defined in the ohos_init.h file.)

    SYS_RUN(LedExampleEntry);
  6. Change the applications/sample/wifi-iot/app/BUILD.gn file to enable led_example.c to participate in compilation.

    import("//build/lite/config/component/lite_component.gni")
    lite_component("app") {
        features = [
            "iothardware:led_example"
        ]
    }
1
https://gitee.com/cain_qin/docs.git
git@gitee.com:cain_qin/docs.git
cain_qin
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891