From bcbd3fa089b47a11b8d8fd11fcd47704f6cfd4f9 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Apr 2019 12:03:26 +0700 Subject: [PATCH] enhance board management --- Makefile | 42 ++----------- src/boards.c | 10 ++++ src/boards.h | 14 +---- .../board.h} | 60 ++++++++----------- .../board.h} | 6 +- .../board.h} | 6 +- .../board.h} | 0 .../board.h} | 6 +- .../board.h} | 0 .../board.h} | 0 .../board.h} | 0 src/boards/{pca10056.h => pca10056/board.h} | 0 src/boards/{pca10059.h => pca10059/board.h} | 0 tools/build_all.py | 6 +- 14 files changed, 54 insertions(+), 96 deletions(-) rename src/boards/{electronut_labs_papyr.h => electronut_labs_papyr/board.h} (66%) rename src/boards/{feather_nrf52832.h => feather_nrf52832/board.h} (93%) rename src/boards/{feather_nrf52840_express.h => feather_nrf52840_express/board.h} (94%) rename src/boards/{mdk_nrf52840_dongle.h => mdk_nrf52840_dongle/board.h} (100%) rename src/boards/{metro_nrf52840_express.h => metro_nrf52840_express/board.h} (95%) rename src/boards/{particle_argon.h => particle_argon/board.h} (100%) rename src/boards/{particle_boron.h => particle_boron/board.h} (100%) rename src/boards/{particle_xenon.h => particle_xenon/board.h} (100%) rename src/boards/{pca10056.h => pca10056/board.h} (100%) rename src/boards/{pca10059.h => pca10059/board.h} (100%) diff --git a/Makefile b/Makefile index 6dbaf98..4d3b2e9 100644 --- a/Makefile +++ b/Makefile @@ -80,22 +80,15 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou #********************************* # Select the board to build #********************************* -BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*.h)))) +BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*)))) NRF52832_BOARDLIST = feather_nrf52832 IS_52832 = $(filter $(BOARD),$(NRF52832_BOARDLIST)) -ifeq ($(filter $(MAKECMDGOALS),all-board help),) - ifeq ($(BOARD),) - $(info You must provide a BOARD parameter with 'BOARD=') - $(info Supported boards are: $(BOARD_LIST)) - $(info Run 'make help' for usage) - $(error BOARD not defined) - else - ifeq ($(filter $(BOARD),$(BOARD_LIST)),) - $(error Invalid BOARD specified) - endif - endif +ifeq ($(filter $(BOARD),$(BOARD_LIST)),) + $(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:) + $(info $(BOARD_LIST)) + $(error Invalid BOARD specified) endif BUILD = _build-$(BOARD) @@ -267,7 +260,7 @@ CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096 CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"' CFLAGS += -DBOARD_$(shell echo $(BOARD) | tr '[:lower:]' '[:upper:]') -CFLAGS += -DBOARD_HEADER_FILE='"$(BOARD).h"' +CFLAGS += -DBOARD_HEADER_FILE='"$(BOARD)/board.h"' ifneq ($(IS_52832),) CFLAGS += -DNRF52 @@ -348,29 +341,6 @@ endif # default target to build all: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out size -# Rule using BOARD_LIST, nl is newline -define nl - - -endef - -_make_board = $(MAKE) -s -f $(MAKEFILE_LIST) -e BOARD=$1 $2 $(nl) -_make_all_board = $(foreach b,$(BOARD_LIST), $(call _make_board,$b,$1)) - -# build all the boards -all-board: - $(call _make_all_board,clean all) - -help: - @echo To compile and build the current code for a board - @echo $$ make BOARD=feather_nrf52840_express all - @echo - @echo To flash current code using Jlink - @echo $$ make BOARD=feather_nrf52840_express flash - @echo - @echo To flash current code using existing bootloader dfu - @echo $$ make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash - #******************* Flash target ******************* check_defined = \ diff --git a/src/boards.c b/src/boards.c index 22e36f5..44890ed 100644 --- a/src/boards.c +++ b/src/boards.c @@ -38,6 +38,16 @@ #endif //------------- IMPLEMENTATION -------------// +void button_init(uint32_t pin) +{ + nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); +} + +bool button_pressed(uint32_t pin) +{ + return (nrf_gpio_pin_read(pin) == 0) ? true : false; +} + void board_init(void) { // stop LF clock just in case we jump from application without reset diff --git a/src/boards.h b/src/boards.h index 01435a5..1358df0 100644 --- a/src/boards.h +++ b/src/boards.h @@ -30,6 +30,7 @@ #include #include "nrf_gpio.h" + #include BOARD_HEADER_FILE #ifndef BUTTON_DFU @@ -68,8 +69,6 @@ void board_teardown(void); // LED //--------------------------------------------------------------------+ -#define bit(b) (1UL << (b)) - enum { STATE_BOOTLOADER_STARTED = 0, STATE_USB_MOUNTED, @@ -97,15 +96,8 @@ void led_tick(void); #error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')" #endif -static inline void button_init(uint32_t pin) -{ - nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); -} - -static inline bool button_pressed(uint32_t pin) -{ - return (nrf_gpio_pin_read(pin) == 0) ? true : false; -} +void button_init(uint32_t pin); +bool button_pressed(uint32_t pin); bool is_ota(void); diff --git a/src/boards/electronut_labs_papyr.h b/src/boards/electronut_labs_papyr/board.h similarity index 66% rename from src/boards/electronut_labs_papyr.h rename to src/boards/electronut_labs_papyr/board.h index 8911584..ab7588c 100644 --- a/src/boards/electronut_labs_papyr.h +++ b/src/boards/electronut_labs_papyr/board.h @@ -1,38 +1,28 @@ -/**************************************************************************/ -/*! - @file elelctronutlabs_papyr.h - @author Tavish Naruka - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2017, Adafruit Industries (adafruit.com) - 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 holders 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 ''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 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 MIT License (MIT) + * + * @author Tavish Naruka + * + * Copyright (c) 2018 Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef PAPYR_H #define PAPYR_H diff --git a/src/boards/feather_nrf52832.h b/src/boards/feather_nrf52832/board.h similarity index 93% rename from src/boards/feather_nrf52832.h rename to src/boards/feather_nrf52832/board.h index 99e2500..ee70cdc 100644 --- a/src/boards/feather_nrf52832.h +++ b/src/boards/feather_nrf52832/board.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef _FEATHER52832_H -#define _FEATHER52832_H +#ifndef _FEATHER_NRF52832_H +#define _FEATHER_NRF52832_H /*------------------------------------------------------------------*/ /* LED @@ -56,4 +56,4 @@ #define PRODUCT_NAME "Adafruit Bluefruit Feather nRF52832" -#endif // _FEATHER52832_H +#endif // _FEATHER_NRF52832_H diff --git a/src/boards/feather_nrf52840_express.h b/src/boards/feather_nrf52840_express/board.h similarity index 94% rename from src/boards/feather_nrf52840_express.h rename to src/boards/feather_nrf52840_express/board.h index a5cf389..9b9631e 100644 --- a/src/boards/feather_nrf52840_express.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef _FEATHER52840_H -#define _FEATHER52840_H +#ifndef _FEATHER_NRF52840_H +#define _FEATHER_NRF52840_H #define _PINNUM(port, pin) ((port)*32 + (pin)) @@ -61,4 +61,4 @@ #define PRODUCT_NAME "Adafruit Feather nRF52840 Express" #define VOLUME_LABEL "FTHR840BOOT" -#endif // _FEATHER52840_H +#endif // _FEATHER_NRF52840_H diff --git a/src/boards/mdk_nrf52840_dongle.h b/src/boards/mdk_nrf52840_dongle/board.h similarity index 100% rename from src/boards/mdk_nrf52840_dongle.h rename to src/boards/mdk_nrf52840_dongle/board.h diff --git a/src/boards/metro_nrf52840_express.h b/src/boards/metro_nrf52840_express/board.h similarity index 95% rename from src/boards/metro_nrf52840_express.h rename to src/boards/metro_nrf52840_express/board.h index d7f2afc..1fc5b02 100644 --- a/src/boards/metro_nrf52840_express.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef _METRO_NRF52840_EXPRESS_H_ -#define _METRO_NRF52840_EXPRESS_H_ +#ifndef _METRO_NRF52840_H_ +#define _METRO_NRF52840_H_ #define _PINNUM(port, pin) ((port)*32 + (pin)) @@ -62,4 +62,4 @@ #define VOLUME_LABEL "METR840BOOT" -#endif /* _METRO_NRF52840_EXPRESS_H_ */ +#endif /* _METRO_NRF52840_H_ */ diff --git a/src/boards/particle_argon.h b/src/boards/particle_argon/board.h similarity index 100% rename from src/boards/particle_argon.h rename to src/boards/particle_argon/board.h diff --git a/src/boards/particle_boron.h b/src/boards/particle_boron/board.h similarity index 100% rename from src/boards/particle_boron.h rename to src/boards/particle_boron/board.h diff --git a/src/boards/particle_xenon.h b/src/boards/particle_xenon/board.h similarity index 100% rename from src/boards/particle_xenon.h rename to src/boards/particle_xenon/board.h diff --git a/src/boards/pca10056.h b/src/boards/pca10056/board.h similarity index 100% rename from src/boards/pca10056.h rename to src/boards/pca10056/board.h diff --git a/src/boards/pca10059.h b/src/boards/pca10059/board.h similarity index 100% rename from src/boards/pca10059.h rename to src/boards/pca10059/board.h diff --git a/tools/build_all.py b/tools/build_all.py index 1d5419a..5411a76 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -17,11 +17,7 @@ exit_status = 0 all_boards = [] for entry in os.scandir("src/boards"): - if not entry.name.endswith(".h"): - print("Misplaced file in src/boards: {}\n".format(entry.name)) - exit_status = 1 - continue - all_boards.append(entry.name[:-2]) + all_boards.append(entry.name) #sha, version = build_info.get_version_info()