From 06a223976cc41148e1f6f06fd7f0afec3eb1e042 Mon Sep 17 00:00:00 2001 From: Matias N Date: Wed, 15 Jul 2020 23:11:31 -0300 Subject: [PATCH] initial support for nrf52832-sparkfun board --- boards/Kconfig | 12 ++ boards/arm/nrf52/nrf52832-sparkfun/Kconfig | 8 + boards/arm/nrf52/nrf52832-sparkfun/README.txt | 5 + .../nrf52832-sparkfun/configs/nsh/defconfig | 49 ++++++ .../nrf52/nrf52832-sparkfun/include/board.h | 107 ++++++++++++ .../nrf52/nrf52832-sparkfun/scripts/Make.defs | 91 +++++++++++ .../nrf52832-sparkfun/scripts/flash_config.ld | 121 ++++++++++++++ .../arm/nrf52/nrf52832-sparkfun/src/Makefile | 50 ++++++ .../nrf52832-sparkfun/src/nrf52832-sparkfun.h | 93 +++++++++++ .../nrf52832-sparkfun/src/nrf52_appinit.c | 89 ++++++++++ .../nrf52832-sparkfun/src/nrf52_autoleds.c | 142 ++++++++++++++++ .../nrf52/nrf52832-sparkfun/src/nrf52_boot.c | 96 +++++++++++ .../nrf52832-sparkfun/src/nrf52_bringup.c | 97 +++++++++++ .../nrf52832-sparkfun/src/nrf52_buttons.c | 1 + .../nrf52832-sparkfun/src/nrf52_userleds.c | 154 ++++++++++++++++++ 15 files changed, 1115 insertions(+) create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/Kconfig create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/README.txt create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/configs/nsh/defconfig create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/include/board.h create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/scripts/Make.defs create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/scripts/flash_config.ld create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/Makefile create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52832-sparkfun.h create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_appinit.c create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_autoleds.c create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_boot.c create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_bringup.c create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_buttons.c create mode 100644 boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_userleds.c diff --git a/boards/Kconfig b/boards/Kconfig index 63ad8ec9e7..1449a6a8e3 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -722,6 +722,14 @@ config ARCH_BOARD_NRF52_FEATHER ---help--- This option selects the Adafruit nRF52832 Feather board +config ARCH_BOARD_NRF52832_SPARKFUN + bool "Sparkfun nRF52832 breakout board" + depends on ARCH_CHIP_NRF52 + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + ---help--- + This option selects the Sparkfun nRF52832 breakout board + config ARCH_BOARD_NRF52840_DK bool "Nordic nRF52840 Development Kit (PCA10056)" depends on ARCH_CHIP_NRF52 @@ -2187,6 +2195,7 @@ config ARCH_BOARD default "moteino-mega" if ARCH_BOARD_MOTEINO_MEGA default "ne64badge" if ARCH_BOARD_NE64BADGE default "nrf52-feather" if ARCH_BOARD_NRF52_FEATHER + default "nrf52832-sparkfun" if ARCH_BOARD_NRF52832_SPARKFUN default "nrf52832-dk" if ARCH_BOARD_NRF52832_DK default "nrf52840-dk" if ARCH_BOARD_NRF52840_DK default "nrf52840-dongle" if ARCH_BOARD_NRF52840_DONGLE @@ -2526,6 +2535,9 @@ endif if ARCH_BOARD_NRF52_FEATHER source "boards/arm/nrf52/nrf52-feather/Kconfig" endif +if ARCH_BOARD_NRF52832_SPARKFUN +source "boards/arm/nrf52/nrf52832-sparkfun/Kconfig" +endif if ARCH_BOARD_NRF52832_DK source "boards/arm/nrf52/nrf52832-dk/Kconfig" endif diff --git a/boards/arm/nrf52/nrf52832-sparkfun/Kconfig b/boards/arm/nrf52/nrf52832-sparkfun/Kconfig new file mode 100644 index 0000000000..e735c33633 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/Kconfig @@ -0,0 +1,8 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_NRF52832_SPARKFUN + +endif diff --git a/boards/arm/nrf52/nrf52832-sparkfun/README.txt b/boards/arm/nrf52/nrf52832-sparkfun/README.txt new file mode 100644 index 0000000000..a9fabf3508 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/README.txt @@ -0,0 +1,5 @@ +README +====== + +README for NuttX port to Sparkfun NRF52832 breakout board. + diff --git a/boards/arm/nrf52/nrf52832-sparkfun/configs/nsh/defconfig b/boards/arm/nrf52/nrf52832-sparkfun/configs/nsh/defconfig new file mode 100644 index 0000000000..9b4d2faf08 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/configs/nsh/defconfig @@ -0,0 +1,49 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_FPU is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_PS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="nrf52832-sparkfun" +CONFIG_ARCH_BOARD_NRF52832_SPARKFUN=y +CONFIG_ARCH_CHIP="nrf52" +CONFIG_ARCH_CHIP_NRF52832=y +CONFIG_ARCH_CHIP_NRF52=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_STDARG_H=y +CONFIG_BOARD_LOOPSPERMSEC=5500 +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_MM_REGIONS=2 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NRF52_UART0=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_RAM_SIZE=65535 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=26 +CONFIG_START_MONTH=3 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WDOG_INTRESERVE=0 diff --git a/boards/arm/nrf52/nrf52832-sparkfun/include/board.h b/boards/arm/nrf52/nrf52832-sparkfun/include/board.h new file mode 100644 index 0000000000..deb742ed87 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/include/board.h @@ -0,0 +1,107 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52_feather/include/board.h + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Janne Rosberg + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_INCLUDE_BOARD_H +#define __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NRF52_GPIOTE) +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +#define BOARD_SYSTICK_CLOCK (64000000) + +/* Clocking *****************************************************************/ + +/* A low output illuminates the LED. + * + * LED index values for use with board_userled() + */ + +#define BOARD_LED1 0 +#define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + +#define BOARD_LED1_BIT (1 << BOARD_LED1) + +/* If CONFIG_ARCH_LEDS is defined, the LED will be controlled as follows + * for NuttX debug functionality (where NC means "No Change"). + */ + +#define LED_STARTED 0 /* OFF */ +#define LED_HEAPALLOCATE 0 /* OFF */ +#define LED_IRQSENABLED 0 /* OFF */ +#define LED_STACKCREATED 1 /* ON */ +#define LED_INIRQ 2 /* NC */ +#define LED_SIGNAL 2 /* NC */ +#define LED_ASSERTION 2 /* NC */ +#define LED_PANIC 3 /* Flashing */ + +/* If CONFIG_ARCH_LEDS is not defined, then the LEDs are completely under + * control of the application. The following interfaces are then available + * for application control of the LEDs: + * + * uint32_t board_userled_initialize(void); + * void board_userled(int led, bool ledon); + * void board_userled_all(uint32_t ledset); + */ + +/* Button definitions *******************************************************/ + +/* No buttons on board */ + +/* UART Pins ****************************************************************/ + +/* The following definitions must be provided so that the NRF52 serial + * driver can set up the UART for the serial console properly. + */ + +#define BOARD_UART0_RX_PIN (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(27)) +#define BOARD_UART0_TX_PIN (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(26)) + +#endif /* __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_INCLUDE_BOARD_H */ diff --git a/boards/arm/nrf52/nrf52832-sparkfun/scripts/Make.defs b/boards/arm/nrf52/nrf52832-sparkfun/scripts/Make.defs new file mode 100644 index 0000000000..8902768f6c --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/scripts/Make.defs @@ -0,0 +1,91 @@ +############################################################################ +# boards/arm/nrf52/nrf52832-sparkfun/scripts/Make.defs +# +# Copyright (C) 2014, 2017, 2018 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 NuttX 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 OWNER 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. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs + +LDSCRIPT = flash_config.ld + +ifeq ($(CONFIG_CYGWIN_WINTOOL),y) + ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}" +else + ARCHSCRIPT = -T$(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT) +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +STRIP = $(CROSSDEV)strip --strip-unneeded +AR = $(ARCROSSDEV)ar rcs +NM = $(ARCROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +endif + +ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef +ARCHWARNINGSXX = -Wall -Wshadow -Wundef +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif diff --git a/boards/arm/nrf52/nrf52832-sparkfun/scripts/flash_config.ld b/boards/arm/nrf52/nrf52832-sparkfun/scripts/flash_config.ld new file mode 100644 index 0000000000..d48f4ef697 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/scripts/flash_config.ld @@ -0,0 +1,121 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun/scripts/flash_config.ld + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Janne Rosberg + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +MEMORY +{ + progmem (rx) : ORIGIN = 0x00000000, LENGTH = 512K + datamem (rwx) : ORIGIN = 0x20000000, LENGTH = 64K +} + +OUTPUT_ARCH(arm) +ENTRY(__start) /* Treat __start as the anchor for dead code stripping */ +EXTERN(_vectors) /* Force the vectors to be included in the output */ +SECTIONS +{ + .text : + { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > progmem + + .init_section : + { + _sinit = ABSOLUTE(.); + *(.init_array .init_array.*) + _einit = ABSOLUTE(.); + } > progmem + + .ARM.extab : + { + *(.ARM.extab*) + } > progmem + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : + { + *(.ARM.exidx*) + } > progmem + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + .data : + { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + . = ALIGN(4); + _edata = ABSOLUTE(.); + } > datamem AT > progmem + + /* BSS */ + + .bss : + { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + _ebss = ABSOLUTE(.); + } > datamem + + /* Stabs debugging sections. */ + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/Makefile b/boards/arm/nrf52/nrf52832-sparkfun/src/Makefile new file mode 100644 index 0000000000..91b5720c00 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/Makefile @@ -0,0 +1,50 @@ +############################################################################ +# boards/arm/nrf52/nrf52832-sparkfun.h/src/Makefile +# +# Copyright (C) 2018 Gregory Nutt. All rights reserved. +# Author: Janne Rosberg +# +# 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 NuttX 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 OWNER 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. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = nrf52_boot.c nrf52_bringup.c + +ifeq ($(CONFIG_LIB_BOARDCTL),y) +CSRCS += nrf52_appinit.c +endif + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += nrf52_autoleds.c +else +CSRCS += nrf52_userleds.c +endif + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52832-sparkfun.h b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52832-sparkfun.h new file mode 100644 index 0000000000..8684c8f0ab --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52832-sparkfun.h @@ -0,0 +1,93 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/nrf52832-sparkfun.h + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_SRC_NRF52832_SPARKFUN_H +#define __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_SRC_NRF52832_SPARKFUN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include "nrf52_gpio.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* LED definitions **********************************************************/ + +/* Definitions to configure LED GPIO as outputs */ + +#define GPIO_LED1 (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(7)) + +/* Button definitions *******************************************************/ + +/* No buttons on board */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf52_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int nrf52_bringup(void); + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_NRF52_NRF52832_SPARKFUN_SRC_NRF52832_SPARKFUN_H */ diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_appinit.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_appinit.c new file mode 100644 index 0000000000..1b35c3fc41 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_appinit.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/nrf52_appinit.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Janne Rosberg + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "chip.h" +#include "nrf52832-sparkfun.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform architecture specific initialization + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ +#ifdef CONFIG_BOARD_LATE_INITIALIZE + /* Board initialization already performed by board_late_initialize() */ + + return OK; +#else + /* Perform board-specific initialization */ + + return nrf52_bringup(); +#endif +} diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_autoleds.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_autoleds.c new file mode 100644 index 0000000000..083f3b6bab --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_autoleds.c @@ -0,0 +1,142 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/lpc43_autoleds.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +/* The NRF52 Feather board has 2 user-controllable LEDs: + * + * LED MCU + * LED1 PIN0-17 + * LED2 PIN0-19 + * + * A low output illuminates the LED. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "arm_arch.h" +#include "arm_internal.h" + +#include "nrf52832-sparkfun.h" + +#ifdef CONFIG_ARCH_LEDS + +#define LED_ON 1 +#define LED_OFF 0 + +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1 +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: led_dumppins + ****************************************************************************/ + +#ifdef LED_VERBOSE +static void led_dumppins(FAR const char *msg) +{ + nrf52_pin_dump(PINCONFIG_LED, msg); + nrf52_gpio_dump(GPIO_LED, msg); +} +#else +# define led_dumppins(m) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + int i; + + /* Configure LED pin as a GPIO outputs */ + + led_dumppins("board_autoled_initialize() Entry)"); + + for (i = 0; i < BOARD_NLEDS; i++) + { + nrf52_gpio_config(g_ledcfg[i]); + } + + led_dumppins("board_autoled_initialize() Exit"); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if ((unsigned)led < BOARD_NLEDS) + { + nrf52_gpio_write(g_ledcfg[led], LED_ON); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if ((unsigned)led < BOARD_NLEDS) + { + nrf52_gpio_write(g_ledcfg[led], LED_OFF); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_boot.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_boot.c new file mode 100644 index 0000000000..bfa65e7f3e --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_boot.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/lpc43_boot.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include "arm_arch.h" +#include "arm_internal.h" + +#include "nrf52832-sparkfun.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf52_board_initialize + * + * Description: + * All NRF52xxx architectures must provide the following entry point. + * This entry point is called early in the initialization -- after all + * memory has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void nrf52_board_initialize(void) +{ + /* Configure on-board LEDs if LED support has been selected. */ + +#ifdef CONFIG_ARCH_LEDS + board_autoled_initialize(); +#endif +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board-specific initialization */ + + nrf52_bringup(); +} +#endif diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_bringup.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_bringup.c new file mode 100644 index 0000000000..5100d16b8b --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_bringup.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/nrf53_bringup.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#ifdef CONFIG_NRF52_WDT +# include "nrf52_wdt.h" +#endif + +#ifdef CONFIG_USERLED +# include +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf52_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int nrf52_bringup(void) +{ + int ret; + +#ifdef CONFIG_NRF52_WDT + /* Start Watchdog timer */ + + ret = nrf52_wdt_initialize(CONFIG_WATCHDOG_DEVPATH, 1, 1); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf52_wdt_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize(CONFIG_EXAMPLES_LEDS_DEVPATH); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + + UNUSED(ret); + return OK; +} diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_buttons.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_buttons.c new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_buttons.c @@ -0,0 +1 @@ + diff --git a/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_userleds.c b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_userleds.c new file mode 100644 index 0000000000..3d99cff329 --- /dev/null +++ b/boards/arm/nrf52/nrf52832-sparkfun/src/nrf52_userleds.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * boards/arm/nrf52/nrf52832-sparkfun.h/src/nrf52_userleds.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Janne Rosberg + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "chip.h" +#include "arm_ar.h" +#include "arm_internal.h" + +#include "nrf52832-sparkfun.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* LED definitions **********************************************************/ + +/* If CONFIG_ARCH_LEDS is not defined, then the LEDs are completely under + * control of the application. The following interfaces are then available + * for application control of the LEDs: + * + * uint32_t board_userled_initialize(void); + * void board_userled(int led, bool ledon); + * void board_userled_all(uint32_t ledset); + */ + +#define LED_ON 1 +#define LED_OFF 0 + +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1 +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: led_dumppins + ****************************************************************************/ + +#ifdef LED_VERBOSE +static void led_dumppins(FAR const char *msg) +{ + nrf52_pin_dump(PINCONFIG_LED, msg); + nrf52_gpio_dump(GPIO_LED, msg); +} +#else +# define led_dumppins(m) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + /* Configure LED pin as a GPIO outputs */ + + led_dumppins("board_userled_initialize() Entry)"); + + /* Configure GPIO as an outputs */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + nrf52_gpio_config(g_ledcfg[i]); + } + + led_dumppins("board_userled_initialize() Exit"); + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < BOARD_NLEDS) + { + nrf52_gpio_write(g_ledcfg[led], ledon ? LED_ON : LED_OFF); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + /* Configure LED1-8 GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + nrf52_gpio_write(g_ledcfg[i], (ledset & (1 << i)) ? LED_ON : LED_OFF); + } +} + +#endif /* !CONFIG_ARCH_LEDS */