This commit is contained in:
Thomas Klaehn 2020-03-12 15:30:53 +01:00
parent df2d84dee1
commit 2bea1ae46a
4 changed files with 172 additions and 36 deletions

View File

@ -59,11 +59,11 @@ $(TARGET_HEX): $(TARGET) $(THIS_MAKEFILE)
$(OBJCOPY) -O ihex $(TARGET) $(TARGET_HEX)
ln -sf $(shell pwd)/$@ $(shell pwd)/bin/firmware.hex
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(SRC_DIR)/%.c,$@)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CC) -c $(CPP_FLAGS) $(C_FLAGS) $< -o $@

View File

@ -14,10 +14,12 @@ 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/
@ -27,6 +29,10 @@ 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
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
@ -78,15 +84,15 @@ LD_FLAGS += --specs=nano.specs
.PHONY: package flash flash_softdevice erase
package: $(TARGET_HEX) $(THIS_MAKEFILE)
package: $(TARGET_HEX)
nrfutil pkg generate --hw-version 52 --application-version 1 --application $(TARGET_HEX) --sd-req 0xCB --sd-id 0xCB --key-file keys/private.key $(TARGET_PACKAGE)
flash: $(TARGET_HEX) $(THIS_MAKEFILE)
flash: $(TARGET_HEX)
@echo Flashing: $(TARGET_HEX)
nrfjprog -f nrf52 --program $(TARGET_HEX) --sectorerase
nrfjprog -f nrf52 --reset
flash_softdevice:
flash_softdevice: $(THIS_MAKEFILE)
@echo Flashing: $(NRF_PATH)/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex
nrfjprog -f nrf52 --program $(NRF_PATH)/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex --sectorerase
nrfjprog -f nrf52 --reset
@ -94,15 +100,15 @@ flash_softdevice:
erase:
nrfjprog -f nrf52 --eraseall
$(OBJ_DIR)/%.d: $(NRF_PATH)/%.S
$(OBJ_DIR)/%.d: $(NRF_PATH)/%.S $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CPP) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(CPP_FLAGS) $(patsubst $(OBJ_DIR)/%.d,$(NRF_PATH)/%.S,$@)
$(OBJ_DIR)/%.o: $(NRF_PATH)/%.c
$(OBJ_DIR)/%.o: $(NRF_PATH)/%.c $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CC) -std=c99 -MP -MD -c -o $@ $< $(C_FLAGS) $(CPP_FLAGS)
$(OBJ_DIR)/%.o: $(NRF_PATH)/%.S
$(OBJ_DIR)/%.o: $(NRF_PATH)/%.S $(THIS_MAKEFILE)
@mkdir -p $(dir $@)
$(CC) -c $(ASMFLAGS) $< -o $@

View File

@ -46,6 +46,119 @@
#ifdef USE_APP_CONFIG
#include "app_config.h"
#endif
// <h> nRF_Drivers
//==========================================================
// <e> GPIOTE_ENABLED - nrf_drv_gpiote - GPIOTE peripheral driver - legacy layer
//==========================================================
#ifndef GPIOTE_ENABLED
#define GPIOTE_ENABLED 1
#endif
// <o> GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins
#ifndef GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
#define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
#endif
// <o> GPIOTE_CONFIG_IRQ_PRIORITY - Interrupt priority
// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef GPIOTE_CONFIG_IRQ_PRIORITY
#define GPIOTE_CONFIG_IRQ_PRIORITY 6
#endif
// </e>
// <e> NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver
//==========================================================
#ifndef NRFX_GPIOTE_ENABLED
#define NRFX_GPIOTE_ENABLED 1
#endif
// <o> NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins
#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
#endif
// <o> NRFX_GPIOTE_CONFIG_IRQ_PRIORITY - Interrupt priority
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY
#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 6
#endif
// <e> NRFX_GPIOTE_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED
#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0
#endif
// <o> NRFX_GPIOTE_CONFIG_LOG_LEVEL - Default Severity level
// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug
#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL
#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3
#endif
// <o> NRFX_GPIOTE_CONFIG_INFO_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_GPIOTE_CONFIG_INFO_COLOR
#define NRFX_GPIOTE_CONFIG_INFO_COLOR 0
#endif
// <o> NRFX_GPIOTE_CONFIG_DEBUG_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_GPIOTE_CONFIG_DEBUG_COLOR
#define NRFX_GPIOTE_CONFIG_DEBUG_COLOR 0
#endif
// </e>
// </e>
// </h>
//==========================================================
// <h> nRF_Libraries
//==========================================================

View File

@ -1,34 +1,51 @@
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#include "board.h"
#include "driver.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);
}
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);
}
int main(void)
{
// bsp_board_init(BSP_INIT_LEDS);
drv_open(&led_1);
drv_open(&led_2);
drv_open(&led_3);
drv_open(&led_4);
drv_open(&button_1);
drv_open(&button_2);
drv_open(&button_3);
drv_open(&button_4);
while(true) {
char x;
drv_read(&button_1, &x, 1);
drv_write(&led_1, &x, 1);
drv_read(&button_2, &x, 1);
drv_write(&led_2, &x, 1);
drv_read(&button_3, &x, 1);
drv_write(&led_3, &x, 1);
drv_read(&button_4, &x, 1);
drv_write(&led_4, &x, 1);
}
gpio_init();
while(true) {}
}