contiki/platform/stm32nucleo-spirit1/dev/leds-arch.c

114 lines
4.1 KiB
C
Raw Normal View History

2015-10-09 17:40:39 +00:00
/*
* Copyright (c) 2012, STMicroelectronics.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup stm32nucleo-spirit1-peripherals
* @{
*
* \file
* Driver for the stm32nucleo-spirit1 LEDs
*/
/*---------------------------------------------------------------------------*/
2015-07-24 14:30:10 +00:00
#include "contiki-conf.h"
#include "dev/leds.h"
#include "st-lib.h"
/*---------------------------------------------------------------------------*/
#ifndef X_NUCLEO_IKS01A1
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
*/
2015-10-09 17:40:39 +00:00
extern st_lib_gpio_typedef *st_lib_a_led_gpio_port[];
extern const uint16_t st_lib_a_led_gpio_pin[];
#endif /*X_NUCLEO_IKS01A1*/
2015-07-24 14:30:10 +00:00
2015-10-09 17:40:39 +00:00
extern st_lib_gpio_typedef *st_lib_gpio_port[];
extern const uint16_t st_lib_gpio_pin[];
2015-07-24 14:30:10 +00:00
/*---------------------------------------------------------------------------*/
2015-10-09 17:40:39 +00:00
void
leds_arch_init(void)
2015-07-24 14:30:10 +00:00
{
/* We have at least one led, the one on the Nucleo (GREEN)*/
st_lib_bsp_led_init(LED2);
st_lib_bsp_led_off(LED2);
2015-07-24 14:30:10 +00:00
#ifndef X_NUCLEO_IKS01A1
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
*/
st_lib_radio_shield_led_init(RADIO_SHIELD_LED);
st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
#endif /*X_NUCLEO_IKS01A1*/
2015-07-24 14:30:10 +00:00
}
/*---------------------------------------------------------------------------*/
2015-10-09 17:40:39 +00:00
unsigned char
leds_arch_get(void)
2015-07-24 14:30:10 +00:00
{
2015-10-09 17:40:39 +00:00
unsigned char ret = 0;
if(st_lib_hal_gpio_read_pin(st_lib_gpio_port[LED2], st_lib_gpio_pin[LED2])) {
2015-07-24 14:30:10 +00:00
ret |= LEDS_GREEN;
}
#ifndef X_NUCLEO_IKS01A1
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
*/
2015-10-09 17:40:39 +00:00
if(st_lib_hal_gpio_read_pin(st_lib_a_led_gpio_port[RADIO_SHIELD_LED],
st_lib_a_led_gpio_pin[RADIO_SHIELD_LED])) {
2015-07-24 14:30:10 +00:00
ret |= LEDS_RED;
}
#endif /*X_NUCLEO_IKS01A1*/
2015-07-24 14:30:10 +00:00
return ret;
}
/*---------------------------------------------------------------------------*/
2015-10-09 17:40:39 +00:00
void
leds_arch_set(unsigned char leds)
2015-07-24 14:30:10 +00:00
{
2015-10-09 17:40:39 +00:00
if(leds & LEDS_GREEN) {
st_lib_bsp_led_on(LED2);
} else {
st_lib_bsp_led_off(LED2);
2015-07-24 14:30:10 +00:00
}
#ifndef X_NUCLEO_IKS01A1
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
*/
2015-10-09 17:40:39 +00:00
if(leds & LEDS_RED) {
st_lib_radio_shield_led_on(RADIO_SHIELD_LED);
} else {
st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
2015-07-24 14:30:10 +00:00
}
#endif /*X_NUCLEO_IKS01A1*/
2015-07-24 14:30:10 +00:00
}
/*---------------------------------------------------------------------------*/
/** @} */