17
17
/* scheduling priority used by each thread */
18
18
#define PRIORITY 7
19
19
20
- /* Change this if you have an LED connected to a custom port */
21
- #ifndef DT_ALIAS_LED0_GPIOS_CONTROLLER
22
- #define DT_ALIAS_LED0_GPIOS_CONTROLLER LED0_GPIO_PORT
23
- #endif
24
- #ifndef DT_ALIAS_LED1_GPIOS_CONTROLLER
25
- #define DT_ALIAS_LED1_GPIOS_CONTROLLER LED1_GPIO_PORT
26
- #endif
27
-
28
- #define PORT0 DT_ALIAS_LED0_GPIOS_CONTROLLER
29
- #define PORT1 DT_ALIAS_LED1_GPIOS_CONTROLLER
30
-
31
-
32
- /* Change this if you have an LED connected to a custom pin */
33
- #define LED0 DT_ALIAS_LED0_GPIOS_PIN
34
- #define LED1 DT_ALIAS_LED1_GPIOS_PIN
35
-
36
20
struct printk_data_t {
37
21
void * fifo_reserved ; /* 1st word reserved for use by fifo */
38
22
u32_t led ;
@@ -41,18 +25,40 @@ struct printk_data_t {
41
25
42
26
K_FIFO_DEFINE (printk_fifo );
43
27
44
- void blink (const char * port , u32_t sleep_ms , u32_t led , u32_t id )
28
+ #ifndef DT_ALIAS_LED0_GPIOS_FLAGS
29
+ #define DT_ALIAS_LED0_GPIOS_FLAGS 0
30
+ #endif
31
+
32
+ #ifndef DT_ALIAS_LED1_GPIOS_FLAGS
33
+ #define DT_ALIAS_LED1_GPIOS_FLAGS 0
34
+ #endif
35
+
36
+ struct led {
37
+ const char * gpio_dev_name ;
38
+ const char * gpio_pin_name ;
39
+ unsigned int gpio_pin ;
40
+ unsigned int gpio_flags ;
41
+ };
42
+
43
+ void blink (const struct led * led , u32_t sleep_ms , u32_t id )
45
44
{
46
- int cnt = 0 ;
47
45
struct device * gpio_dev ;
46
+ int cnt = 0 ;
47
+ int ret ;
48
48
49
- gpio_dev = device_get_binding (port );
50
- __ASSERT_NO_MSG (gpio_dev != NULL );
49
+ gpio_dev = device_get_binding (led -> gpio_dev_name );
50
+ __ASSERT (gpio_dev != NULL , "Error: didn't find %s device\n" ,
51
+ led -> gpio_dev_name );
51
52
52
- gpio_pin_configure (gpio_dev , led , GPIO_DIR_OUT );
53
+ ret = gpio_pin_configure (gpio_dev , led -> gpio_pin , led -> gpio_flags );
54
+ if (ret != 0 ) {
55
+ printk ("Error %d: failed to configure pin %d '%s'\n" ,
56
+ ret , led -> gpio_pin , led -> gpio_pin_name );
57
+ return ;
58
+ }
53
59
54
60
while (1 ) {
55
- gpio_pin_write (gpio_dev , led , cnt % 2 );
61
+ gpio_pin_set (gpio_dev , led -> gpio_pin , cnt % 2 );
56
62
57
63
struct printk_data_t tx_data = { .led = id , .cnt = cnt };
58
64
@@ -71,12 +77,26 @@ void blink(const char *port, u32_t sleep_ms, u32_t led, u32_t id)
71
77
72
78
void blink1 (void )
73
79
{
74
- blink (PORT0 , 100 , LED0 , 0 );
80
+ const struct led led1 = {
81
+ .gpio_dev_name = DT_ALIAS_LED0_GPIOS_CONTROLLER ,
82
+ .gpio_pin_name = DT_ALIAS_LED0_LABEL ,
83
+ .gpio_pin = DT_ALIAS_LED0_GPIOS_PIN ,
84
+ .gpio_flags = GPIO_OUTPUT | DT_ALIAS_LED0_GPIOS_FLAGS ,
85
+ };
86
+
87
+ blink (& led1 , 100 , 0 );
75
88
}
76
89
77
90
void blink2 (void )
78
91
{
79
- blink (PORT1 , 1000 , LED1 , 1 );
92
+ const struct led led2 = {
93
+ .gpio_dev_name = DT_ALIAS_LED1_GPIOS_CONTROLLER ,
94
+ .gpio_pin_name = DT_ALIAS_LED1_LABEL ,
95
+ .gpio_pin = DT_ALIAS_LED1_GPIOS_PIN ,
96
+ .gpio_flags = GPIO_OUTPUT | DT_ALIAS_LED1_GPIOS_FLAGS ,
97
+ };
98
+
99
+ blink (& led2 , 1000 , 1 );
80
100
}
81
101
82
102
void uart_out (void )
0 commit comments