From abf16ef6582bd6887ef3a590b9d634287ccb401a Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Mon, 5 Feb 2018 23:42:21 +0100 Subject: [PATCH] boards: sltb001a: adapt to common board files. --- boards/sltb001a/Makefile | 2 + boards/sltb001a/Makefile.dep | 4 +- boards/sltb001a/Makefile.include | 11 ++++- boards/sltb001a/board.c | 78 ++++++-------------------------- 4 files changed, 28 insertions(+), 67 deletions(-) diff --git a/boards/sltb001a/Makefile b/boards/sltb001a/Makefile index f8fcbb53a0..39108f4589 100644 --- a/boards/sltb001a/Makefile +++ b/boards/sltb001a/Makefile @@ -1,3 +1,5 @@ MODULE = board +DIRS = $(RIOTBOARD)/common/silabs + include $(RIOTBASE)/Makefile.base diff --git a/boards/sltb001a/Makefile.dep b/boards/sltb001a/Makefile.dep index 1451bdeab5..ba9ffda054 100644 --- a/boards/sltb001a/Makefile.dep +++ b/boards/sltb001a/Makefile.dep @@ -4,7 +4,7 @@ ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += si7021 endif -# i2c is required for environmental sensors -USEMODULE += periph_i2c +# include board common dependencies +include $(RIOTBOARD)/common/silabs/Makefile.dep include $(RIOTCPU)/efm32/Makefile.dep diff --git a/boards/sltb001a/Makefile.include b/boards/sltb001a/Makefile.include index b7ba1de1b5..69d13e8fa4 100644 --- a/boards/sltb001a/Makefile.include +++ b/boards/sltb001a/Makefile.include @@ -6,9 +6,16 @@ export CPU_MODEL = efr32mg1p132f256gm48 PORT_LINUX ?= /dev/ttyACM0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) +# setup serial terminal +include $(RIOTMAKE)/tools/serial.inc.mk + # setup JLink for flashing export JLINK_DEVICE := EFR32MG1PxxxF256 include $(RIOTMAKE)/tools/jlink.inc.mk -# setup serial terminal -include $(RIOTMAKE)/tools/serial.inc.mk +# add board common drivers +USEMODULE += boards_common_silabs +USEMODULE += silabs_pic + +# include board common +include $(RIOTBOARD)/common/silabs/Makefile.include diff --git a/boards/sltb001a/board.c b/boards/sltb001a/board.c index c4ec0fe0f9..a53862753c 100644 --- a/boards/sltb001a/board.c +++ b/boards/sltb001a/board.c @@ -20,91 +20,43 @@ */ #include "board.h" -#include "cpu.h" +#include "board_common.h" +#include "pic.h" #include "periph/gpio.h" -#include "periph/i2c.h" - -#if BMP280_ENABLED || CCS811_ENABLED || ICM_20648_ENABLED || \ - SI1133_ENABLED || SI7021_ENABLED || SI7210A_ENABLED || \ - RGB_LED1_ENABLED || RGB_LED2_ENABLED || RGB_LED3_ENABLED || \ - RGB_LED4_ENABLED -static inline void board_usleep(uint32_t delay) -{ - /* decrement + compare take two cycles, therefore divide by two */ - uint32_t count = (delay * (SystemCoreClock / 1000 / 1000)) / 2; - - while (count--) {} -} - -static void board_pic_init(void) -{ - gpio_init(PIC_INT_WAKE_PIN, GPIO_OD); - gpio_set(PIC_INT_WAKE_PIN); - - i2c_init_master(PIC_I2C, I2C_SPEED_NORMAL); -} - -static void board_pic_write(uint8_t addr, uint8_t value) -{ - /* toggle the pin for 4 us */ - gpio_clear(PIC_INT_WAKE_PIN); - board_usleep(4); - - /* write to gpio expander */ - i2c_acquire(PIC_I2C); - uint8_t bytes[] = { addr, value }; - i2c_write_bytes(PIC_I2C, PIC_I2C_ADDR, bytes, 2); - i2c_release(PIC_I2C); - - /* put PIC in sleep mode again */ - gpio_set(PIC_INT_WAKE_PIN); -} -#endif void board_init(void) { /* initialize the CPU */ cpu_init(); - /* initialize the LEDs */ - gpio_init(LED0_PIN, GPIO_OUT); - gpio_init(LED1_PIN, GPIO_OUT); - - /* initialize the push buttons */ - gpio_init(PB0_PIN, GPIO_IN); - gpio_init(PB1_PIN, GPIO_IN); - - /* initialize the environmental sensors (multiple ones) */ -#if BMP280_ENABLED || CCS811_ENABLED || ICM_20648_ENABLED || \ - SI1133_ENABLED || SI7021_ENABLED || SI7210A_ENABLED || \ - RGB_LED1_ENABLED || RGB_LED2_ENABLED || RGB_LED3_ENABLED || \ - RGB_LED4_ENABLED - board_pic_init(); -#endif + /* perform common board initialization */ + board_common_init(); +#ifdef MODULE_SILABS_PIC /* enable the CCS811 air quality/gas sensor */ #if CCS811_ENABLED - board_pic_write(CCS811_PIC_ADDR, (1 << CCS811_PIC_EN_BIT) | (1 << CCS811_PIC_WAKE_BIT)); + pic_write(CCS811_PIC_ADDR, (1 << CCS811_PIC_EN_BIT) | (1 << CCS811_PIC_WAKE_BIT)); #endif /* enable the IMU sensor */ #if ICM_20648_ENABLED - board_pic_write(ICM20648_PIC_ADDR, 1 << ICM20648_PIC_EN_BIT); + pic_write(ICM20648_PIC_ADDR, 1 << ICM20648_PIC_EN_BIT); #endif /* enable the environmental sensors */ #if BMP280_ENABLED || SI1133_ENABLED || SI7021_ENABLED || SI7210A_ENABLED - board_pic_write(ENV_SENSE_PIC_ADDR, 1 << ENV_SENSE_PIC_BIT); + pic_write(ENV_SENSE_PIC_ADDR, 1 << ENV_SENSE_PIC_BIT); #endif /* enable the RGB leds */ #if RGB_LED1_ENABLED || RGB_LED2_ENABLED || RGB_LED3_ENABLED || RGB_LED4_ENABLED - board_pic_write(RGB_LED_ADDR, - (1 << RGB_LED_EN_BIT) | - (RGB_LED1_ENABLED << RGB_LED1_EN_BIT) | - (RGB_LED2_ENABLED << RGB_LED2_EN_BIT) | - (RGB_LED3_ENABLED << RGB_LED3_EN_BIT) | - (RGB_LED4_ENABLED << RGB_LED4_EN_BIT)); + pic_write(RGB_LED_ADDR, + (1 << RGB_LED_EN_BIT) | + (RGB_LED1_ENABLED << RGB_LED1_EN_BIT) | + (RGB_LED2_ENABLED << RGB_LED2_EN_BIT) | + (RGB_LED3_ENABLED << RGB_LED3_EN_BIT) | + (RGB_LED4_ENABLED << RGB_LED4_EN_BIT)); +#endif #endif }