Re-organize build system

This commit is contained in:
Thomas Klaehn 2020-03-30 11:45:29 +02:00
parent 3093a80f2a
commit 2e01aa6877
22 changed files with 86 additions and 11447 deletions

View File

@ -11,6 +11,9 @@
"nrf52.h": "c",
"system_nrf52.h": "c",
"system_nrf.h": "c",
"driver.h": "c"
"driver.h": "c",
"deque": "cpp",
"string": "cpp",
"vector": "cpp"
}
}

22
.vscode/tasks.json vendored
View File

@ -6,10 +6,9 @@
"env": {
"PLATFORM": "nrf52",
// "PLATFORM": "posix",
// "APPLICATION": "blinky",
// "APPLICATION": "button",
"APPLICATION": "blinky",
// "APPLICATION": "spi",
"APPLICATION": "st7789_lcd",
// "APPLICATION": "st7789_lcd",
},
},
"tasks": [
@ -80,6 +79,23 @@
"kind": "build",
"isDefault": true
}
},
{
"label": "check",
"type":"shell",
"command": "make check",
"problemMatcher": {
"base": "$gcc",
"owner": "gcc",
"fileLocation": [
"relative",
"${workspaceFolder}"
]
},
"group": {
"kind": "build",
"isDefault": true
}
}
],
"presentation": {

View File

@ -10,6 +10,7 @@ CPP = $(CROSS_COMPILE)cpp
CXX = $(CROSS_COMPILE)g++
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
CHECK = cppcheck
SRC_DIR = src
OBJ_DIR = obj/$(PLATFORM)
@ -37,7 +38,7 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
INCLUDES += src/
INCLUDES += interfaces/
INCLUDES += include/
INCLUDES += include/application/$(APPLICATION)
INCLUDES += include/platform/$(PLATFORM)
OPT = 3
C_FLAGS += -O$(OPT) -g$(OPT)
@ -50,11 +51,12 @@ CXX_FLAGS += -Wall -Werror
CXX_FLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CXX_FLAGS += -DPLATFORM_$(PLATFORM)
LIBS += c nosys m
CHECK_FLAGS = $(addprefix -I,$(INCLUDES))
CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force --language=c++
include config/build/$(PLATFORM)/$(APPLICATION)/Makefile.$(APPLICATION)
include build_system/platform/$(PLATFORM)/Makefile.$(PLATFORM)
.PHONY: all install uninstall clean distclean debug
.PHONY: all install uninstall clean distclean debug check
all: $(TARGET)
debug:
@ -67,6 +69,10 @@ clean:
distclean:
rm -rf bin obj
.PHONY:
check: $(C_SRCS)
$(CHECK) $(CHECK_FLAGS) $(CC_SRCS)
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@

View File

@ -1,6 +1,18 @@
CPU = cortex-m4
CROSS_COMPILE ?= arm-none-eabi-
NRF_PATH := nrf5sdk/
INCLUDES += $(NRF_PATH)modules/nrfx/mdk/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/
INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/
INCLUDES += $(NRF_PATH)components/libraries/util/
INCLUDES += $(NRF_PATH)modules/nrfx/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/
INCLUDES += $(NRF_PATH)components/libraries/delay/
INCLUDES += $(NRF_PATH)integration/nrfx/
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c
NRF_C_OBJS = $(patsubst $(NRF_PATH)%,$(OBJ_DIR)/%,$(patsubst %.c,%.o,$(NRF_C_SRCS)))
NRF_A_SRCS = $(NRF_PATH)modules/nrfx/mdk/gcc_startup_nrf52.S
@ -54,11 +66,11 @@ A_FLAGS += -DNRF52832_XXAA
A_FLAGS += -DNRF52_PAN_74
A_FLAGS += -DNRF_SD_BLE_API_VERSION=7
A_FLAGS += -DS132
A_FLAGS += -DSOFTDEVICE_PRESENT
# A_FLAGS += -DSOFTDEVICE_PRESENT
A_FLAGS += -D__HEAP_SIZE=8192
A_FLAGS += -D__HEAP_SIZE=8192
LINKER_SCRIPT = config/build/$(PLATFORM)/$(APPLICATION)/linker.ld
LINKER_SCRIPT = build_system/platform/$(PLATFORM)/$(PLATFORM)_without_sd.ld
# Linker flags
LD_FLAGS += -O$(OPT) -g$(OPT)
@ -68,6 +80,8 @@ LD_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
LD_FLAGS += -Wl,--gc-sections
LD_FLAGS += --specs=nano.specs
LIBS += c nosys m
.PHONY: package flash flash_softdevice erase
package: $(TARGET_HEX)

View File

@ -1,30 +0,0 @@
NRF_PATH := nrf5sdk/
INCLUDES += $(NRF_PATH)components/
INCLUDES += $(NRF_PATH)modules/nrfx/mdk/
INCLUDES += $(NRF_PATH)components/libraries/strerror/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/
INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/
INCLUDES += $(NRF_PATH)components/libraries/util/
INCLUDES += $(NRF_PATH)components/libraries/balloc/
INCLUDES += $(NRF_PATH)components/libraries/ringbuf/
INCLUDES += $(NRF_PATH)modules/nrfx/hal/
INCLUDES += $(NRF_PATH)components/libraries/bsp/
INCLUDES += $(NRF_PATH)components/libraries/log/
INCLUDES += $(NRF_PATH)modules/nrfx/
INCLUDES += $(NRF_PATH)modules/nrfx/drivers/include/
INCLUDES += $(NRF_PATH)components/libraries/experimental_section_vars/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/
INCLUDES += $(NRF_PATH)components/libraries/delay/
INCLUDES += $(NRF_PATH)integration/nrfx/
INCLUDES += $(NRF_PATH)integration/nrfx/legacy/
INCLUDES += $(NRF_PATH)components/libraries/atomic/
INCLUDES += $(NRF_PATH)components/boards/
INCLUDES += $(NRF_PATH)components/libraries/memobj/
INCLUDES += $(NRF_PATH)components/softdevice/common/
INCLUDES += $(NRF_PATH)external/fprintf/
INCLUDES += $(NRF_PATH)components/libraries/log/src/
NRF_C_SRCS += $(NRF_PATH)components/boards/boards.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c
include config/build/$(PLATFORM)/Makefile.$(PLATFORM)

View File

@ -1,33 +0,0 @@
NRF_PATH := nrf5sdk/
INCLUDES += $(NRF_PATH)components/
INCLUDES += $(NRF_PATH)modules/nrfx/mdk/
INCLUDES += $(NRF_PATH)components/libraries/strerror/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/
INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/
INCLUDES += $(NRF_PATH)components/libraries/util/
INCLUDES += $(NRF_PATH)components/libraries/balloc/
INCLUDES += $(NRF_PATH)components/libraries/ringbuf/
INCLUDES += $(NRF_PATH)modules/nrfx/hal/
INCLUDES += $(NRF_PATH)components/libraries/bsp/
INCLUDES += $(NRF_PATH)components/libraries/log/
INCLUDES += $(NRF_PATH)modules/nrfx/
INCLUDES += $(NRF_PATH)modules/nrfx/drivers/include/
INCLUDES += $(NRF_PATH)components/libraries/experimental_section_vars/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/
INCLUDES += $(NRF_PATH)components/libraries/delay/
INCLUDES += $(NRF_PATH)integration/nrfx/
INCLUDES += $(NRF_PATH)integration/nrfx/legacy/
INCLUDES += $(NRF_PATH)components/libraries/atomic/
INCLUDES += $(NRF_PATH)components/boards/
INCLUDES += $(NRF_PATH)components/libraries/memobj/
INCLUDES += $(NRF_PATH)components/softdevice/common/
INCLUDES += $(NRF_PATH)external/fprintf/
INCLUDES += $(NRF_PATH)components/libraries/log/src/
NRF_C_SRCS += $(NRF_PATH)components/boards/boards.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_gpiote.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_weak.c
include config/build/$(PLATFORM)/Makefile.$(PLATFORM)

View File

@ -1,54 +0,0 @@
CPU = cortex-m4
CROSS_COMPILE ?= arm-none-eabi-
NRF_PATH := nrf5sdk/
INCLUDES += $(NRF_PATH)components/
INCLUDES += $(NRF_PATH)modules/nrfx/mdk/
INCLUDES += $(NRF_PATH)components/libraries/strerror/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/
INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/
INCLUDES += $(NRF_PATH)components/libraries/util/
INCLUDES += $(NRF_PATH)components/libraries/balloc/
INCLUDES += $(NRF_PATH)components/libraries/ringbuf/
INCLUDES += $(NRF_PATH)modules/nrfx/hal/
INCLUDES += $(NRF_PATH)components/libraries/bsp/
INCLUDES += $(NRF_PATH)components/libraries/log/
INCLUDES += $(NRF_PATH)modules/nrfx/
INCLUDES += $(NRF_PATH)modules/nrfx/drivers/include/
INCLUDES += $(NRF_PATH)components/libraries/experimental_section_vars/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/
INCLUDES += $(NRF_PATH)components/libraries/delay/
INCLUDES += $(NRF_PATH)integration/nrfx/
INCLUDES += $(NRF_PATH)integration/nrfx/legacy/
INCLUDES += $(NRF_PATH)components/libraries/atomic/
INCLUDES += $(NRF_PATH)components/boards/
INCLUDES += $(NRF_PATH)components/libraries/memobj/
INCLUDES += $(NRF_PATH)components/softdevice/common/
INCLUDES += $(NRF_PATH)external/fprintf/
INCLUDES += $(NRF_PATH)components/libraries/log/src/
NRF_C_SRCS += $(NRF_PATH)components/boards/boards.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_weak.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_spim.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_frontend.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/atomic/nrf_atomic.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_default_backends.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_backend_uart.c
NRF_C_SRCS += $(NRF_PATH)integration/nrfx/legacy/nrf_drv_uart.c
NRF_C_SRCS += $(NRF_PATH)integration/nrfx/legacy/nrf_drv_spi.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_uarte.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/prs/nrfx_prs.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_util_platform.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_uart.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_backend_serial.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/memobj/nrf_memobj.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/balloc/nrf_balloc.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_str_formatter.c
NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf.c
NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf_format.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/ringbuf/nrf_ringbuf.c
include config/build/$(PLATFORM)/Makefile.$(PLATFORM)

View File

@ -1,64 +0,0 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
.log_filter_data :
{
PROVIDE(__start_log_filter_data = .);
KEEP(*(SORT(.log_filter_data*)))
PROVIDE(__stop_log_filter_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.log_backends :
{
PROVIDE(__start_log_backends = .);
KEEP(*(SORT(.log_backends*)))
PROVIDE(__stop_log_backends = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"

View File

@ -1,56 +0,0 @@
CPU = cortex-m4
CROSS_COMPILE ?= arm-none-eabi-
NRF_PATH := nrf5sdk/
INCLUDES += $(NRF_PATH)components/
INCLUDES += $(NRF_PATH)modules/nrfx/mdk/
INCLUDES += $(NRF_PATH)components/libraries/strerror/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/nrf52/
INCLUDES += $(NRF_PATH)components/toolchain/cmsis/include/
INCLUDES += $(NRF_PATH)components/libraries/util/
INCLUDES += $(NRF_PATH)components/libraries/balloc/
INCLUDES += $(NRF_PATH)components/libraries/ringbuf/
INCLUDES += $(NRF_PATH)modules/nrfx/hal/
INCLUDES += $(NRF_PATH)components/libraries/bsp/
INCLUDES += $(NRF_PATH)components/libraries/log/
INCLUDES += $(NRF_PATH)modules/nrfx/
INCLUDES += $(NRF_PATH)modules/nrfx/drivers/include/
INCLUDES += $(NRF_PATH)components/libraries/experimental_section_vars/
INCLUDES += $(NRF_PATH)components/softdevice/s132/headers/
INCLUDES += $(NRF_PATH)components/libraries/delay/
INCLUDES += $(NRF_PATH)integration/nrfx/
INCLUDES += $(NRF_PATH)integration/nrfx/legacy/
INCLUDES += $(NRF_PATH)components/libraries/atomic/
INCLUDES += $(NRF_PATH)components/boards/
INCLUDES += $(NRF_PATH)components/libraries/memobj/
INCLUDES += $(NRF_PATH)components/softdevice/common/
INCLUDES += $(NRF_PATH)external/fprintf/
INCLUDES += $(NRF_PATH)components/libraries/log/src/
NRF_C_SRCS += $(NRF_PATH)components/boards/boards.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/mdk/system_nrf52.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_handler_gcc.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_error_weak.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_spim.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_frontend.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/atomic/nrf_atomic.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_default_backends.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_backend_uart.c
NRF_C_SRCS += $(NRF_PATH)integration/nrfx/legacy/nrf_drv_uart.c
NRF_C_SRCS += $(NRF_PATH)integration/nrfx/legacy/nrf_drv_spi.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_uarte.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/prs/nrfx_prs.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/util/app_util_platform.c
NRF_C_SRCS += $(NRF_PATH)modules/nrfx/drivers/src/nrfx_uart.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_backend_serial.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/memobj/nrf_memobj.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/balloc/nrf_balloc.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/log/src/nrf_log_str_formatter.c
NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf.c
NRF_C_SRCS += $(NRF_PATH)external/fprintf/nrf_fprintf_format.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/ringbuf/nrf_ringbuf.c
NRF_C_SRCS += $(NRF_PATH)components/libraries/strerror/nrf_strerror.c
include config/build/$(PLATFORM)/Makefile.$(PLATFORM)

View File

@ -1,64 +0,0 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
.log_filter_data :
{
PROVIDE(__start_log_filter_data = .);
KEEP(*(SORT(.log_filter_data*)))
PROVIDE(__stop_log_filter_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.log_backends :
{
PROVIDE(__start_log_backends = .);
KEEP(*(SORT(.log_backends*)))
PROVIDE(__stop_log_backends = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,30 @@
#include <array>
#include "delay.h"
#include "platform/hal.h"
using namespace hal;
enum {
PIN_NUMBER_LED_1 = 17,
PIN_NUMBER_LED_2 = 18,
PIN_NUMBER_LED_3 = 19,
PIN_NUMBER_LED_4 = 20
};
hal::Gpio led_1(PIN_NUMBER_LED_1);
hal::Gpio led_2(PIN_NUMBER_LED_2);
hal::Gpio led_3(PIN_NUMBER_LED_3);
hal::Gpio led_4(PIN_NUMBER_LED_4);
std::array<hal::Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};
int main(void)
{
Gpio led_1(17);
while(true) {
delay_ms(200);
led_1.toggle();
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
hal::Gpio * tmp = *it;
tmp->toggle();
delay_ms(500);
}
}
return 0;
}

View File

@ -1,113 +0,0 @@
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
/** @file
* @defgroup pin_change_int_example_main main.c
* @{
* @ingroup pin_change_int_example
* @brief Pin Change Interrupt Example Application main file.
*
* This file contains the source code for a sample application using interrupts triggered by GPIO pins.
*
*/
#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#ifdef BSP_BUTTON_0
#define PIN_IN BSP_BUTTON_0
#endif
#ifndef PIN_IN
#error "Please indicate input pin"
#endif
#ifdef BSP_LED_0
#define PIN_OUT BSP_LED_0
#endif
#ifndef PIN_OUT
#error "Please indicate output pin"
#endif
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_drv_gpiote_out_toggle(PIN_OUT);
}
/**
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
* and configures GPIOTE to give an interrupt on pin change.
*/
static void gpio_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
gpio_init();
while (true)
{
// Do nothing.
}
}
/** @} */

View File

@ -1,7 +1,8 @@
#include "platform/nrf52/gpio.h"
extern "C" {
#include "nrf.h"
#include "nrf52.h"
#include "nrf52_bitfields.h"
NRF_GPIO_Type *const GPIO_REGS = reinterpret_cast<NRF_GPIO_Type *>(NRF_P0_BASE);
}
@ -37,6 +38,11 @@ void Gpio::set_direction(direction dir)
GPIO_REGS->PIN_CNF[pin_number] = direct | input | pull | drive | sense;
}
void Gpio::set_pin_number(uint32_t pin)
{
this->pin_number = pin;
}
uint32_t Gpio::get()
{
uint32_t res = (GPIO_REGS->IN >> pin_number) & 1UL;

View File

@ -8,7 +8,9 @@ namespace platform::nrf52 {
class Gpio : public interfaces::GpioInterface
{
public:
explicit Gpio(uint32_t);
inline Gpio() {}
Gpio(uint32_t);
void set_pin_number(uint32_t);
void set_direction(direction) override;
uint32_t get() override;
void set() override;

View File

@ -3,11 +3,10 @@
#include "platform/nrf52/spi.h"
extern "C" {
#include "nrf.h"
#include "nrf52.h"
#include "nrf52_bitfields.h"
NRF_SPI_Type *SPI_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI0_BASE);
// NRF_SPI_Type *const SPI_1_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI1_BASE);
// NRF_SPI_Type *const SPI_2_REGS = reinterpret_cast<NRF_SPI_Type *>(NRF_SPI2_BASE);
}
using namespace platform::nrf52;
@ -28,9 +27,9 @@ Spi::Spi(uint32_t instance, uint32_t sck, uint32_t mosi, uint32_t miso, interfac
this->chip_select.set();
SPI_REGS->ENABLE = 0;
SPI_REGS->PSELSCK = sck;
SPI_REGS->PSELMOSI = mosi;
SPI_REGS->PSELMISO = miso;
SPI_REGS->PSEL.SCK = sck;
SPI_REGS->PSEL.MOSI = mosi;
SPI_REGS->PSEL.MISO = miso;
SPI_REGS->FREQUENCY = SPI_FREQUENCY_FREQUENCY_M8;
SPI_REGS->CONFIG = (0x03 << 1); //Sample on trailing edge of clock, shift serial data on leading edge, SCK polarity Active low
@ -53,13 +52,11 @@ void Spi::send(const uint8_t * buffer, uint32_t len)
void Spi::recv(uint8_t * buffer, uint32_t len)
{
//FIXME: missing CS handling
this->chip_select.clear();
for(unsigned int i = 0; i < len; i++) {
buffer[i] = this->transfer(buffer[i]);
}
//FIXME: missing CS handling
this->chip_select.set();
}
uint32_t Spi::transfer(uint32_t data)