Contiki 3.x
leds-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, STMicroelectronics.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *
30  */
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \addtogroup stm32nucleo-spirit1-peripherals
34  * @{
35  *
36  * \file
37  * Driver for the stm32nucleo-spirit1 LEDs
38  */
39 /*---------------------------------------------------------------------------*/
40 #include "contiki-conf.h"
41 #include "dev/leds.h"
42 #include "st-lib.h"
43 /*---------------------------------------------------------------------------*/
44 #ifndef X_NUCLEO_IKS01A1
45 /* The Red LED (on SPIRIT1 exp board) is exposed only if the
46  * X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
47  */
48 extern st_lib_gpio_typedef *st_lib_a_led_gpio_port[];
49 extern const uint16_t st_lib_a_led_gpio_pin[];
50 #endif /*X_NUCLEO_IKS01A1*/
51 
52 extern st_lib_gpio_typedef *st_lib_gpio_port[];
53 extern const uint16_t st_lib_gpio_pin[];
54 /*---------------------------------------------------------------------------*/
55 void
57 {
58  /* We have at least one led, the one on the Nucleo (GREEN)*/
59  st_lib_bsp_led_init(LED2);
60  st_lib_bsp_led_off(LED2);
61 
62 #ifndef X_NUCLEO_IKS01A1
63 /* The Red LED (on SPIRIT1 exp board) is exposed only if the
64  * X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
65  */
66  st_lib_radio_shield_led_init(RADIO_SHIELD_LED);
67  st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
68 #endif /*X_NUCLEO_IKS01A1*/
69 }
70 /*---------------------------------------------------------------------------*/
71 unsigned char
72 leds_arch_get(void)
73 {
74  unsigned char ret = 0;
75  if(st_lib_hal_gpio_read_pin(st_lib_gpio_port[LED2], st_lib_gpio_pin[LED2])) {
76  ret |= LEDS_GREEN;
77  }
78 
79 #ifndef X_NUCLEO_IKS01A1
80 /* The Red LED (on SPIRIT1 exp board) is exposed only if the
81  * X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
82  */
83  if(st_lib_hal_gpio_read_pin(st_lib_a_led_gpio_port[RADIO_SHIELD_LED],
84  st_lib_a_led_gpio_pin[RADIO_SHIELD_LED])) {
85  ret |= LEDS_RED;
86  }
87 #endif /*X_NUCLEO_IKS01A1*/
88 
89  return ret;
90 }
91 /*---------------------------------------------------------------------------*/
92 void
93 leds_arch_set(unsigned char leds)
94 {
95  if(leds & LEDS_GREEN) {
96  st_lib_bsp_led_on(LED2);
97  } else {
98  st_lib_bsp_led_off(LED2);
99  }
100 
101 #ifndef X_NUCLEO_IKS01A1
102 /* The Red LED (on SPIRIT1 exp board) is exposed only if the
103  * X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
104  */
105  if(leds & LEDS_RED) {
106  st_lib_radio_shield_led_on(RADIO_SHIELD_LED);
107  } else {
108  st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
109  }
110 #endif /*X_NUCLEO_IKS01A1*/
111 }
112 /*---------------------------------------------------------------------------*/
113 /** @} */
Header file for the STM32Cube HAL APIs.
void leds_arch_init(void)
Leds implementation.
Definition: leds-arch.c:48