blob: ff43f4fa301236082307ba54c4cfed23e1f0b76e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-01-05 Bernard the first version
*/
#include <rtthread.h>
#include <stm32f10x.h>
// led define
#ifdef STM32_SIMULATOR
#define led1_rcc RCC_APB2Periph_GPIOA
#define led1_gpio GPIOA
#define led1_pin (GPIO_Pin_5)
#define led2_rcc RCC_APB2Periph_GPIOA
#define led2_gpio GPIOA
#define led2_pin (GPIO_Pin_6)
#else
#define led1_rcc RCC_APB2Periph_GPIOE
#define led1_gpio GPIOE
#define led1_pin (GPIO_Pin_2)
#define led2_rcc RCC_APB2Periph_GPIOE
#define led2_gpio GPIOE
#define led2_pin (GPIO_Pin_3)
#endif // led define #ifdef STM32_SIMULATOR
void rt_hw_led_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(led1_rcc|led2_rcc,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = led1_pin;
GPIO_Init(led1_gpio, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = led2_pin;
GPIO_Init(led2_gpio, &GPIO_InitStructure);
}
void rt_hw_led_on(rt_uint32_t n)
{
switch (n)
{
case 0:
GPIO_SetBits(led1_gpio, led1_pin);
break;
case 1:
GPIO_SetBits(led2_gpio, led2_pin);
break;
default:
break;
}
}
void rt_hw_led_off(rt_uint32_t n)
{
switch (n)
{
case 0:
GPIO_ResetBits(led1_gpio, led1_pin);
break;
case 1:
GPIO_ResetBits(led2_gpio, led2_pin);
break;
default:
break;
}
}
#ifdef RT_USING_FINSH
#include <finsh.h>
static rt_uint8_t led_inited = 0;
void led(rt_uint32_t led, rt_uint32_t value)
{
/* init led configuration if it's not inited. */
if (!led_inited)
{
rt_hw_led_init();
led_inited = 1;
}
if ( led == 0 )
{
/* set led status */
switch (value)
{
case 0:
rt_hw_led_off(0);
break;
case 1:
rt_hw_led_on(0);
break;
default:
break;
}
}
if ( led == 1 )
{
/* set led status */
switch (value)
{
case 0:
rt_hw_led_off(1);
break;
case 1:
rt_hw_led_on(1);
break;
default:
break;
}
}
}
FINSH_FUNCTION_EXPORT(led, set led[0 - 1] on[1] or off[0].)
#endif
|