bl_mcu_sdk/examples/pwm/pwm_breath_led/main.c
2021-04-27 12:39:22 +08:00

67 lines
2 KiB
C

/**
* @file pwm_breath_led.c
* @brief
*
* Copyright (c) 2021 Bouffalolab team
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#include "hal_pwm.h"
#include "hal_gpio.h"
int main(void)
{
pwm_config_t pwm_cfg = {
1000000,
0,
};
bflb_platform_init(0);
gpio_set_mode(GPIO_PIN_29, GPIO_OUTPUT_PP_MODE);
gpio_set_mode(GPIO_PIN_30, GPIO_OUTPUT_PP_MODE);
gpio_set_mode(GPIO_PIN_31, GPIO_OUTPUT_PP_MODE);
gpio_write(GPIO_PIN_29, 0);
gpio_write(GPIO_PIN_30, 0);
gpio_write(GPIO_PIN_31, 0);
pwm_register(PWM_CH2_INDEX, "led_breath", DEVICE_OFLAG_RDWR);
struct device *led_breath = device_find("led_breath");
if (led_breath)
{
device_open(led_breath, 0);
}
while (1)
{
for (pwm_cfg.dutyCycle = 0; pwm_cfg.dutyCycle < 100; pwm_cfg.dutyCycle++)
{
device_control(led_breath, DEVICE_CTRL_CONFIG, &pwm_cfg);
bflb_platform_delay_ms(10);
}
for (pwm_cfg.dutyCycle = 100; pwm_cfg.dutyCycle > 0; pwm_cfg.dutyCycle--)
{
device_control(led_breath, DEVICE_CTRL_CONFIG, &pwm_cfg);
bflb_platform_delay_ms(10);
}
}
BL_CASE_SUCCESS;
}