2020-07-11 10:18:03 +08:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* @brief led<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020, <master_roger@sina.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
*
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
#include "blink.h"
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "public.h"
|
|
|
|
|
#include "led.h"
|
|
|
|
|
|
|
|
|
|
static blink_dev_t led[LED_TYPE_MAX]; /*<2A><><EFBFBD><EFBFBD>led<65>豸 ------------*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ɫLED<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(PB4)
|
|
|
|
|
* @return none
|
|
|
|
|
*/
|
|
|
|
|
static void red_led_ctrl(bool level)
|
|
|
|
|
{
|
|
|
|
|
if (level)
|
2020-07-11 12:34:26 +08:00
|
|
|
|
GPIOC->ODR |= 1 << 4;
|
2020-07-11 10:18:03 +08:00
|
|
|
|
else
|
2020-07-11 12:34:26 +08:00
|
|
|
|
GPIOC->ODR &= ~(1 << 4);
|
2020-07-11 10:18:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ɫLED<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(PB5)
|
|
|
|
|
* @return none
|
|
|
|
|
*/
|
|
|
|
|
static void green_led_ctrl(bool level)
|
|
|
|
|
{
|
|
|
|
|
if (level)
|
2020-07-11 12:34:26 +08:00
|
|
|
|
GPIOC->ODR |= 1 << 5;
|
2020-07-11 10:18:03 +08:00
|
|
|
|
else
|
2020-07-11 12:34:26 +08:00
|
|
|
|
GPIOC->ODR &= ~(1 << 5);
|
2020-07-11 10:18:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ɫLED<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(PB6)
|
|
|
|
|
* @return none
|
|
|
|
|
*/
|
|
|
|
|
static void blue_led_ctrl(bool level)
|
|
|
|
|
{
|
|
|
|
|
if (level)
|
|
|
|
|
GPIOB->ODR |= 1 << 6;
|
|
|
|
|
else
|
|
|
|
|
GPIOB->ODR &= ~(1 << 6);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* @brief led io<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|
|
|
|
* PB4 -> red; PB5 -> green; PB6-> blue;
|
|
|
|
|
* @return none
|
|
|
|
|
*/
|
|
|
|
|
static void led_io_init(void)
|
|
|
|
|
{
|
2020-07-11 12:34:26 +08:00
|
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
|
|
|
|
|
|
2020-07-11 10:18:03 +08:00
|
|
|
|
gpio_conf(GPIOB, GPIO_Mode_OUT, GPIO_PuPd_NOPULL, GPIO_Pin_4);
|
|
|
|
|
gpio_conf(GPIOB, GPIO_Mode_OUT, GPIO_PuPd_NOPULL, GPIO_Pin_5);
|
|
|
|
|
gpio_conf(GPIOB, GPIO_Mode_OUT, GPIO_PuPd_NOPULL, GPIO_Pin_6);
|
|
|
|
|
|
|
|
|
|
blink_dev_create(&led[LED_TYPE_RED], red_led_ctrl);
|
|
|
|
|
blink_dev_create(&led[LED_TYPE_GREEN], green_led_ctrl);
|
|
|
|
|
blink_dev_create(&led[LED_TYPE_BLUE], blue_led_ctrl);
|
2020-07-11 12:34:26 +08:00
|
|
|
|
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33>*/
|
|
|
|
|
led_ctrl(LED_TYPE_RED, LED_MODE_FAST, 3);
|
|
|
|
|
led_ctrl(LED_TYPE_GREEN, LED_MODE_FAST, 3);
|
|
|
|
|
led_ctrl(LED_TYPE_BLUE, LED_MODE_FAST, 3);
|
|
|
|
|
|
2020-07-11 10:18:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @brief led<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param[in] type - led<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(LED_TYPE_XXX)
|
|
|
|
|
* @param[in] mode - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ(LED_MODE_XXX)
|
|
|
|
|
* @param[in] reapeat - <EFBFBD><EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return none
|
|
|
|
|
*/
|
|
|
|
|
void led_ctrl(led_type type, int mode, int reapeat)
|
|
|
|
|
{
|
|
|
|
|
int ontime = 0, offtime = 0;
|
|
|
|
|
|
|
|
|
|
switch (mode) { /*<2A><><EFBFBD>ݹ<EFBFBD><DDB9><EFBFBD>ģʽ<C4A3>õ<EFBFBD>led<65><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---------*/
|
|
|
|
|
case LED_MODE_OFF:
|
|
|
|
|
ontime = offtime = 0;
|
|
|
|
|
break;
|
|
|
|
|
case LED_MODE_ON:
|
|
|
|
|
ontime = 1;
|
|
|
|
|
offtime = 0;
|
|
|
|
|
break;
|
|
|
|
|
case LED_MODE_FAST:
|
|
|
|
|
ontime = 100;
|
|
|
|
|
offtime = 100;
|
|
|
|
|
break;
|
|
|
|
|
case LED_MODE_SLOW:
|
|
|
|
|
ontime = 500;
|
|
|
|
|
offtime = 1000;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
blink_dev_ctrl(&led[type], ontime, offtime, reapeat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
driver_init("led", led_io_init); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>*/
|
2020-07-11 12:34:26 +08:00
|
|
|
|
task_register("led", blink_dev_process, 10); /*led<65><64><EFBFBD><EFBFBD>, 10ms<6D><73>ѯ1<D1AF><31>*/
|