diff options
author | Claudio Takahasi <claudio.takahasi@gmail.com> | 2013-12-27 11:03:38 -0300 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@gmail.com> | 2013-12-27 14:18:03 -0300 |
commit | a36a7a64647f8b971d5e29c70ff468aaecd2f87d (patch) | |
tree | 369692fecfdece64173e0c757b06b07b6601d3ad | |
parent | 0763e90ce9a3e864909ad02fad1e3020c415ef03 (diff) |
build: Add PIR example
This patch adds the initial files to implement a PIR-based motion
detector application. When motion is detected, the application will
inform through advertising data using GAP Broadcast role.
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | configure.nrf | 1 | ||||
-rw-r--r-- | examples/PIR/Makefile.am | 40 | ||||
-rw-r--r-- | examples/PIR/flash.jlink | 8 | ||||
-rw-r--r-- | examples/PIR/main.c | 98 |
5 files changed, 152 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 42fc4b9..b1d550c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,11 @@ MAINTAINERCLEANFILES = # NRF51822 examples & projects if PLATFORM_NRF -SUBDIRS = stack platform/nrf51822 examples/helloworld examples/logging +SUBDIRS = stack \ + platform/nrf51822 \ + examples/helloworld \ + examples/logging \ + examples/PIR endif # TODO: Define SUBDIRS for Ubertooth examples & projects diff --git a/configure.nrf b/configure.nrf index eb39b4d..0a035a8 100644 --- a/configure.nrf +++ b/configure.nrf @@ -38,4 +38,5 @@ AC_OUTPUT([ Makefile platform/nrf51822/Makefile examples/helloworld/Makefile examples/logging/Makefile + examples/PIR/Makefile ]) diff --git a/examples/PIR/Makefile.am b/examples/PIR/Makefile.am new file mode 100644 index 0000000..ca47348 --- /dev/null +++ b/examples/PIR/Makefile.am @@ -0,0 +1,40 @@ +AM_CFLAGS=-mcpu=cortex-m0 -mthumb +AM_LDFLAGS=--specs=nano.specs -mabi=aapcs -Xlinker -Map=pir.map \ + -T$(top_builddir)/platform/nrf51822/gcc_nrf51_blank_xxaa.ld \ + -L$(SDK_DIR)/Nordic/nrf51822/Source/templates/gcc + +PLATFORM_LIBS = $(top_builddir)/stack/libblestack.a \ + $(top_builddir)/platform/nrf51822/libnrf.a + +AM_CPPFLAGS = -I$(top_builddir)/stack \ + -I$(top_builddir)/platform/nrf51822 \ + -I$(SDK_DIR)/Nordic/nrf51822/Include \ + -I$(SDK_DIR)/Nordic/nrf51822/Include/gcc \ + -I$(SDK_DIR)/Nordic/nrf51822/Include/ble/softdevice + +PIR_SOURCE_FILES = main.c +PIR_OBJECT_FILES = $(PIR_SOURCE_FILES:.c=.o) + +all: pir.bin + +pir.bin: pir.out + $(OBJCOPY) -Obinary pir.out $@ + +pir.out: $(PIR_OBJECT_FILES) + + $(CC) $(AM_LDFLAGS) $(AM_CFLAGS) $(PIR_OBJECT_FILES) $(PLATFORM_LIBS) -o $@ + + $(OBJDUMP) -h pir.out + +# Build object files from C source files +%.o: %.c + $(CC) -c $(CFLAGS) $(AM_CPPFLAGS) -o $@ $< + +MAINTAINERCLEANFILES = Makefile.in \ + pir.bin \ + pir.out \ + pir.map + +clean-local: + $(RM) -rf $(MAINTAINERCLEANFILES) + $(RM) *.o diff --git a/examples/PIR/flash.jlink b/examples/PIR/flash.jlink new file mode 100644 index 0000000..8e630a2 --- /dev/null +++ b/examples/PIR/flash.jlink @@ -0,0 +1,8 @@ +device nrf51822 +speed 1000 +w4 4001e504 1 +loadbin /osd/work/iot/blestack.git/examples/PIR/pir.bin 0 +sleep 100 +r +g +q diff --git a/examples/PIR/main.c b/examples/PIR/main.c new file mode 100644 index 0000000..a1d4982 --- /dev/null +++ b/examples/PIR/main.c @@ -0,0 +1,98 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013 Paulo B. de Oliveira Filho <pauloborgesfilho@gmail.com> + * Copyright (c) 2013 Claudio Takahasi <claudio.takahasi@gmail.com> + * Copyright (c) 2013 João Paulo Rechi Vita <jprvita@gmail.com> + * + * 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. + */ + +#include <stdint.h> +#include <string.h> + +/* Platform specific headers */ +#include <nrf51.h> +#include <boards.h> +#include <nrf_gpio.h> +#include <nrf_delay.h> + +#include <app_common/app_gpiote.h> + +/* Project headers */ +#include "log.h" + +#define GPIOTE_MAX_USERS 1 +#define MOTION_PIN 0 + +static __inline void gpiote_init(void) +{ + GPIO_LED_CONFIG(LED0); + GPIO_LED_CONFIG(LED1); + + /* + * Allocate the buffer needed by the GPIOTE module + * (including aligning the buffer correctly). + */ + APP_GPIOTE_INIT(GPIOTE_MAX_USERS); +} + +static __inline void motion_evt_handler(uint32_t low, uint32_t high) +{ + if (high) { + DBG("Motion: HIGH"); + nrf_gpio_pin_set(LED0); + } else if (low) { + DBG("Motion: LOW"); + nrf_gpio_pin_clear(LED0); + } +} + +static __inline void pir_init(void) +{ + uint32_t err_code; + uint32_t pin_mask = 1 << MOTION_PIN; + app_gpiote_user_id_t id; + + GPIO_BUTTON_CONFIG(MOTION_PIN); + + err_code = app_gpiote_user_register(&id, pin_mask, pin_mask, + motion_evt_handler); + APP_ERROR_CHECK(err_code); + + err_code = app_gpiote_user_enable(id); + APP_ERROR_CHECK(err_code); +} + +int main(void) +{ + log_init(); + + DBG("PIR: setup"); + + gpiote_init(); + pir_init(); + + DBG("PIR: waiting events ..."); + + while (1) + __WFI(); + + return 0; +} |