Implement and use the new LED HAL (Zoul)

This commit is contained in:
George Oikonomou 2018-02-25 18:57:49 +00:00
parent e39472f7d0
commit ce4caf2c7c
14 changed files with 78 additions and 255 deletions

View File

@ -31,7 +31,7 @@ PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET)
-include $(PLATFORM_ROOT_DIR)/$(BOARD)/Makefile.$(BOARD)
### Include
CONTIKI_TARGET_SOURCEFILES += platform.c
CONTIKI_TARGET_SOURCEFILES += platform.c leds-arch.c
CONTIKI_TARGET_SOURCEFILES += leds.c cc1200-zoul-arch.c
CONTIKI_TARGET_SOURCEFILES += adc-zoul.c button-sensor.c zoul-sensors.c
CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES)

View File

@ -1,17 +1,16 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
* 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 copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
@ -29,45 +28,27 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup zoul
* @{
*
* \defgroup zoul-leds Zoul LED driver
*
* LED driver implementation for the Zoul-based platforms
* @{
*
* \file
* LED driver implementation for the Zoul-based platforms
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "reg.h"
#include "dev/leds.h"
#include "dev/gpio.h"
#include "dev/gpio-hal.h"
#include <stdbool.h>
/*---------------------------------------------------------------------------*/
#define LEDS_GPIO_PIN_MASK LEDS_ALL
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
GPIO_SET_OUTPUT(GPIO_D_BASE, LEDS_GPIO_PIN_MASK);
}
/*---------------------------------------------------------------------------*/
unsigned char
leds_arch_get(void)
{
return GPIO_READ_PIN(GPIO_D_BASE, LEDS_GPIO_PIN_MASK);
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(unsigned char leds)
{
GPIO_WRITE_PIN(GPIO_D_BASE, LEDS_GPIO_PIN_MASK, leds);
}
const leds_t leds_arch_leds[] = {
{
.pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L1_PORT, LEDS_ARCH_L1_PIN),
.negative_logic = false
},
{
.pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L2_PORT, LEDS_ARCH_L2_PIN),
.negative_logic = false
},
{
.pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L3_PORT, LEDS_ARCH_L3_PIN),
.negative_logic = false
},
};
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -1,2 +1,2 @@
MOTELIST_ZOLERTIA = firefly
BOARD_SOURCEFILES += board.c leds-arch.c
BOARD_SOURCEFILES += board.c

View File

@ -98,29 +98,18 @@
* @{
*/
/*---------------------------------------------------------------------------*/
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
#define LEDS_GREEN_PIN 4
#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */
#define LEDS_ARCH_L1_PORT GPIO_D_NUM
#define LEDS_ARCH_L1_PIN 5
#define LEDS_ARCH_L2_PORT GPIO_D_NUM
#define LEDS_ARCH_L2_PIN 4
#define LEDS_ARCH_L3_PORT GPIO_D_NUM
#define LEDS_ARCH_L3_PIN 3
#define LEDS_BLUE_PIN 3
#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */
#define LEDS_CONF_RED 1
#define LEDS_CONF_GREEN 2
#define LEDS_CONF_BLUE 4
#define LEDS_RED_PIN 5
#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */
#define LEDS_GREEN_PORT_BASE GPIO_D_BASE
#define LEDS_BLUE_PORT_BASE GPIO_D_BASE
#define LEDS_RED_PORT_BASE GPIO_D_BASE
#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED)
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
#define LEDS_CONF_COUNT 3
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration

View File

@ -1,2 +1,2 @@
MOTELIST_ZOLERTIA = firefly
BOARD_SOURCEFILES += board.c leds-arch.c
BOARD_SOURCEFILES += board.c

View File

@ -98,29 +98,18 @@
* @{
*/
/*---------------------------------------------------------------------------*/
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
#define LEDS_GREEN_PIN 4
#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */
#define LEDS_ARCH_L1_PORT GPIO_D_NUM
#define LEDS_ARCH_L1_PIN 5
#define LEDS_ARCH_L2_PORT GPIO_D_NUM
#define LEDS_ARCH_L2_PIN 4
#define LEDS_ARCH_L3_PORT GPIO_D_NUM
#define LEDS_ARCH_L3_PIN 3
#define LEDS_BLUE_PIN 3
#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */
#define LEDS_CONF_RED 1
#define LEDS_CONF_GREEN 2
#define LEDS_CONF_BLUE 4
#define LEDS_RED_PIN 5
#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */
#define LEDS_GREEN_PORT_BASE GPIO_D_BASE
#define LEDS_BLUE_PORT_BASE GPIO_D_BASE
#define LEDS_RED_PORT_BASE GPIO_D_BASE
#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED)
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
#define LEDS_CONF_COUNT 3
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration

View File

@ -3,4 +3,4 @@ MODULES += arch/dev/enc28j60
CC2538_ENC28J60_ARCH ?= gpio
WITH_IP64 ?= 1
CFLAGS += -DUIP_FALLBACK_INTERFACE=ip64_uip_fallback_interface
BOARD_SOURCEFILES += board.c enc28j60-arch-$(CC2538_ENC28J60_ARCH).c leds-arch.c
BOARD_SOURCEFILES += board.c enc28j60-arch-$(CC2538_ENC28J60_ARCH).c

View File

@ -67,29 +67,18 @@
* @{
*/
/*---------------------------------------------------------------------------*/
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
#define LEDS_GREEN_PIN 4
#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */
#define LEDS_ARCH_L1_PORT GPIO_D_NUM
#define LEDS_ARCH_L1_PIN 5
#define LEDS_ARCH_L2_PORT GPIO_D_NUM
#define LEDS_ARCH_L2_PIN 4
#define LEDS_ARCH_L3_PORT GPIO_D_NUM
#define LEDS_ARCH_L3_PIN 3
#define LEDS_BLUE_PIN 3
#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */
#define LEDS_CONF_RED 1
#define LEDS_CONF_GREEN 2
#define LEDS_CONF_BLUE 4
#define LEDS_RED_PIN 5
#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */
#define LEDS_GREEN_PORT_BASE GPIO_D_BASE
#define LEDS_BLUE_PORT_BASE GPIO_D_BASE
#define LEDS_RED_PORT_BASE GPIO_D_BASE
#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED)
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
#define LEDS_CONF_COUNT 3
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration

View File

@ -82,7 +82,7 @@
void board_init(void);
/*---------------------------------------------------------------------------*/
static void
fade(unsigned char l)
fade(leds_mask_t l)
{
volatile int i;
int k, j;

View File

@ -1,4 +1,4 @@
MOTELIST_ZOLERTIA = remote
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c leds-arch.c
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c
MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc

View File

@ -102,29 +102,18 @@
* @{
*/
/*---------------------------------------------------------------------------*/
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
#define LEDS_GREEN_PIN 4
#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */
#define LEDS_ARCH_L1_PORT GPIO_D_NUM
#define LEDS_ARCH_L1_PIN 5
#define LEDS_ARCH_L2_PORT GPIO_D_NUM
#define LEDS_ARCH_L2_PIN 4
#define LEDS_ARCH_L3_PORT GPIO_D_NUM
#define LEDS_ARCH_L3_PIN 3
#define LEDS_BLUE_PIN 3
#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */
#define LEDS_CONF_RED 1
#define LEDS_CONF_GREEN 2
#define LEDS_CONF_BLUE 4
#define LEDS_RED_PIN 5
#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */
#define LEDS_GREEN_PORT_BASE GPIO_D_BASE
#define LEDS_BLUE_PORT_BASE GPIO_D_BASE
#define LEDS_RED_PORT_BASE GPIO_D_BASE
#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED)
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
#define LEDS_CONF_COUNT 3
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration

View File

@ -1,4 +1,4 @@
MOTELIST_ZOLERTIA = remote
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c leds-res-arch.c power-mgmt.c
BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c
MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc

View File

@ -105,29 +105,18 @@
* @{
*/
/*---------------------------------------------------------------------------*/
#define LEDS_RED 1 /**< LED1 (Red) -> PD4 */
#define LEDS_RED_PIN 4
#define LEDS_RED_PIN_MASK (1 << LEDS_RED_PIN)
#define LEDS_RED_PORT_BASE GPIO_D_BASE
#define LEDS_ARCH_L1_PORT GPIO_D_NUM
#define LEDS_ARCH_L1_PIN 4
#define LEDS_ARCH_L2_PORT GPIO_B_NUM
#define LEDS_ARCH_L2_PIN 7
#define LEDS_ARCH_L3_PORT GPIO_B_NUM
#define LEDS_ARCH_L3_PIN 6
#define LEDS_GREEN 2 /**< LED2 (Green) -> PB7 */
#define LEDS_GREEN_PIN 7
#define LEDS_GREEN_PIN_MASK (1 << LEDS_GREEN_PIN)
#define LEDS_GREEN_PORT_BASE GPIO_B_BASE
#define LEDS_CONF_RED 1
#define LEDS_CONF_GREEN 2
#define LEDS_CONF_BLUE 4
#define LEDS_BLUE 4 /**< LED3 (Blue) -> PB6 */
#define LEDS_BLUE_PIN 6
#define LEDS_BLUE_PIN_MASK (1 << LEDS_BLUE_PIN)
#define LEDS_BLUE_PORT_BASE GPIO_B_BASE
#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) /* 7 */
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /* 6 */
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /* 3 */
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /* 5 */
#define LEDS_WHITE LEDS_ALL /* 7 */
/* Notify various examples that we have LEDs */
#define PLATFORM_HAS_LEDS 1
#define LEDS_CONF_COUNT 3
/** @} */
/*---------------------------------------------------------------------------*/
/** \name USB configuration

View File

@ -1,103 +0,0 @@
/*
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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 zoul
* @{
*
* \defgroup remote-revb-leds RE-Mote revision B arch LED
*
* LED driver implementation for the RE-Mote revision B
* @{
*
* \file
* LED driver implementation for the RE-Mote revision B
*/
#include "contiki.h"
#include "reg.h"
#include "dev/leds.h"
#include "dev/gpio.h"
#include "dev/ioc.h"
/*---------------------------------------------------------------------------*/
#define LEDS_PORTB_PIN_MASK (LEDS_GREEN_PIN_MASK | LEDS_BLUE_PIN_MASK)
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
/* Initialize LED2 (Green) and LED3 (Blue) */
GPIO_SOFTWARE_CONTROL(GPIO_B_BASE, LEDS_PORTB_PIN_MASK);
GPIO_SET_OUTPUT(GPIO_B_BASE, LEDS_PORTB_PIN_MASK);
GPIO_CLR_PIN(GPIO_B_BASE, LEDS_PORTB_PIN_MASK);
/* Initialize LED1 (Red) */
GPIO_SOFTWARE_CONTROL(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK);
GPIO_SET_OUTPUT(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK);
GPIO_CLR_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK);
}
/*---------------------------------------------------------------------------*/
unsigned char
leds_arch_get(void)
{
uint8_t mask_leds;
mask_leds = GPIO_READ_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK) == 0 ? 0: LEDS_GREEN;
mask_leds |= GPIO_READ_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK) == 0 ? 0 : LEDS_BLUE;
mask_leds |= GPIO_READ_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK) == 0 ? 0 : LEDS_RED;
return mask_leds;
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(unsigned char leds)
{
if(leds & LEDS_GREEN) {
GPIO_SET_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK);
} else {
GPIO_CLR_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK);
}
if(leds & LEDS_BLUE) {
GPIO_SET_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK);
} else {
GPIO_CLR_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK);
}
if(leds & LEDS_RED) {
GPIO_SET_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK);
} else {
GPIO_CLR_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK);
}
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/