From 59fddc4d9d0a6447ca45ae4e3e8b4c06e129d3a6 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 2 May 2017 14:39:00 -0400 Subject: [PATCH] Adding board types --- Makefile | 15 ++++++------ README.md | 6 ++--- bsp/boards.h | 13 +++++----- bsp/bsp.c | 4 +++- bsp/lesson_tracker.h | 23 ++++++++++++++++++ bsp/{board_sensei.h => rfd77201.h} | 10 ++++---- bsp/shoe_sensor.h | 38 ++++++++++++++++++++++++++++++ pyaci/aci_serial/AciUart.py | 2 +- pyaci/upload.py | 19 ++++++++++----- src/heartbeat.c | 1 - src/leds.h | 11 +++++++++ src/main.c | 11 +++++---- src/scheduler.c | 2 +- src/sensor.c | 11 +++++++++ 14 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 bsp/lesson_tracker.h rename bsp/{board_sensei.h => rfd77201.h} (92%) create mode 100644 bsp/shoe_sensor.h diff --git a/Makefile b/Makefile index 4afff9a..6d3b382 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,8 @@ # Selectable build options #------------------------------------------------------------------------------ -#TARGET_BOARD ?= BOARD_PCA10000 -#TARGET_BOARD ?= BOARD_PCA10001 -#TARGET_BOARD ?= BOARD_PCA10028 -TARGET_BOARD ?= BOARD_SENSEI +TARGET_BOARD ?= BOARD_RFD77201 +#TARGET_BOARD ?= BOARD_SHOE_SENSOR USE_DFU ?= "no" @@ -21,10 +19,11 @@ TEMPLATE_PATH := $(COMPONENTS)/toolchain/gcc SIMBLEE_BASE := /Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2 RBC_MESH := rbc_mesh + LINKER_SCRIPT := $(SIMBLEE_BASE)/variants/Simblee/linker_scripts/gcc/Simblee.ld RFD_LOADER := $(SIMBLEE_BASE)/RFDLoader_osx -SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left -#SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right +#SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left +SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right #SERIAL_PORT := /dev/cu.usbserial-A105RB12 #SERIAL_PORT := /dev/cu.usbserial-FTZ86FTC # tag-connect #SERIAL_PORT := /dev/cu.usbserial-DO00C2G2 # Breadboard setup @@ -95,13 +94,13 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou C_SOURCE_FILES += src/main.c src/config.c src/sensor.c src/app_cmd.c \ src/scheduler.c src/proximity.c src/heartbeat.c src/battery.c src/shoe_accel.c \ - src/app_evt.c + src/app_evt.c bsp/bsp.c C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp CXX_SOURCE_FILES += $(SIMBLEE_BASE)/variants/Simblee/variant.cpp -CFLAGS += -D RBC_MESH_SERIAL=1 +CFLAGS += -DRBC_MESH_SERIAL=1 -DBSP_SIMPLE C_SOURCE_FILES += $(RBC_MESH)/src/serial_handler_uart.c C_SOURCE_FILES += $(RBC_MESH)/src/mesh_aci.c diff --git a/README.md b/README.md index 9ca601f..69238b7 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ # Compile and flash devices -Program a sensor with id 1, turning off serial for power savings +Program a shoe sensor with id 1, turning off serial for power savings -`make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_ID=1 SENSOR_CONFIGURATION_OPTIONS="--no-serial"` +`make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_SHOE_SENSOR SENSOR_ID=1` Program a master listening device that doesn't sleep, and listens all the time. -`make program SERIAL_PORT=/dev/cu.usbserial-DN00D34P SENSOR_ID=3 SENSOR_CONFIGURATION_OPTIONS="--no-sleep"` +`make program SERIAL_PORT=/dev/cu.usbserial-DN00CSZ7 SENSOR_CONFIGURATION_OPTIONS="--no-sleep” TARGET_BOARD=BOARD_RFD77201 SENSOR_ID=51` diff --git a/bsp/boards.h b/bsp/boards.h index 46050b4..81da378 100644 --- a/bsp/boards.h +++ b/bsp/boards.h @@ -44,8 +44,12 @@ #include "arduino_primo.h" #elif defined (BOARD_SENSEI) #include "board_sensei.h" -#elif defined(BOARD_CUSTOM) - #include "custom_board.h" +#elif defined(BOARD_SHOE_SENSOR) + #include "shoe_sensor.h" +#elif defined(BOARD_LESSON_TRACKER) + #include "lesson_tracker.h" +#elif defined(BOARD_RFD77201) + #include "rfd77201.h" #else #error "Board is not defined" @@ -67,11 +71,6 @@ extern "C" { NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \ NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0) -#define LEDS_CONFIGURE(leds_mask) do { uint32_t pin; \ - for (pin = 0; pin < 32; pin++) \ - if ( (leds_mask) & (1 << pin) ) \ - nrf_gpio_cfg_output(pin); } while (0) - #ifdef __cplusplus } diff --git a/bsp/bsp.c b/bsp/bsp.c index d31ad81..f8eb569 100644 --- a/bsp/bsp.c +++ b/bsp/bsp.c @@ -565,14 +565,16 @@ uint32_t bsp_init(uint32_t type, uint32_t ticks_per_100ms, bsp_event_callback_t } #endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE) -#if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) +#if LEDS_NUMBER > 0 if (type & BSP_INIT_LED) { LEDS_OFF(LEDS_MASK); NRF_GPIO->DIRSET = LEDS_MASK; } +#endif +#if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE) // timers module must be already initialized! if (err_code == NRF_SUCCESS) { diff --git a/bsp/lesson_tracker.h b/bsp/lesson_tracker.h new file mode 100644 index 0000000..4e2ecf6 --- /dev/null +++ b/bsp/lesson_tracker.h @@ -0,0 +1,23 @@ +#ifndef BOARD_LESSON_TRACKER_H +#define BOARD_LESSON_TRACKER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define SIMBLEE + +#define LEDS_NUMBER 0 +#define BUTTONS_NUMBER 0 + +#define RX_PIN_NUMBER 0 +#define TX_PIN_NUMBER 1 +//#define CTS_PIN_NUMBER 0xff +//#define RTS_PIN_NUMBER 0xff +#define HWFC false + +#ifdef __cplusplus +} +#endif + +#endif //BOARD_LESSON_TRACKER_H diff --git a/bsp/board_sensei.h b/bsp/rfd77201.h similarity index 92% rename from bsp/board_sensei.h rename to bsp/rfd77201.h index 308da86..aa95bb8 100644 --- a/bsp/board_sensei.h +++ b/bsp/rfd77201.h @@ -9,14 +9,16 @@ * the file. * */ -#ifndef BOARD_SENSEI_H -#define BOARD_SENSEI_H +#ifndef RFD77201_H +#define RFD77201_H #ifdef __cplusplus extern "C" { #endif -// LEDs definitions for PCA10028 +#define SIMBLEE + +// LEDs definitions for RFDuino board with RGB Shield #define LEDS_NUMBER 3 #define LED_START 2 @@ -67,4 +69,4 @@ extern "C" { } #endif -#endif // BOARD_SENSEI_H +#endif // RFD77201_H diff --git a/bsp/shoe_sensor.h b/bsp/shoe_sensor.h new file mode 100644 index 0000000..bfc04ee --- /dev/null +++ b/bsp/shoe_sensor.h @@ -0,0 +1,38 @@ + + +#ifndef SHOE_SENSOR_H +#define SHOE_SENSOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define ACCEL_ADXL337 +#define SIMBLEE + +// LEDs definitions for Sensei shoe sensor board +#define LEDS_NUMBER 0 +#define BUTTONS_NUMBER 0 + + +#define BUTTONS_LIST { BUTTON_1, BUTTON_2 } + +#define BSP_BUTTON_0 BUTTON_1 +#define BSP_BUTTON_1 BUTTON_2 + +#define BSP_BUTTON_0_MASK (1< 0: self.api.upload_obs(flattened_obs) + elif time.time() - self.last_time_sync > Uploader.TIME_SYNC_INTERVAL: + self.sync_time() else: time.sleep(0.5) - if time.time() - self.last_time_sync > Uploader.TIME_SYNC_INTERVAL: - self.sync_time() if __name__ == '__main__': diff --git a/src/heartbeat.c b/src/heartbeat.c index d4c2865..c65c423 100644 --- a/src/heartbeat.c +++ b/src/heartbeat.c @@ -18,7 +18,6 @@ void heartbeat_init(uint8_t channel) { void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t epoch_ms, uint16_t clock_version) { // Send out time sync packet - //TOGGLE_PIN(LED_RED + LED_START); mesh_packet_t *p_packet; if (mesh_packet_acquire(&p_packet)) { diff --git a/src/leds.h b/src/leds.h index 8a81476..c0aa210 100644 --- a/src/leds.h +++ b/src/leds.h @@ -4,12 +4,23 @@ #include "boards.h" #include "gpio_pins.h" + #define LED_RED 0 #define LED_GREEN 1 #define LED_BLUE 2 +#if LEDS_NUMBER > 0 + #define SET_LED(x) SET_PIN(LED_START + x) #define CLEAR_LED(x) CLEAR_PIN(LED_START + x) #define TOGGLE_LED(x) TOGGLE_PIN(LED_START + x) +#else + +#define SET_LED(x) +#define CLEAR_LED(x) +#define TOGGLE_LED(x) + +#endif + #endif // LEDS_H diff --git a/src/main.c b/src/main.c index 1a9a479..cd123be 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,7 @@ #include "scheduler.h" #include "heartbeat.h" #include "handles.h" +#include "bsp.h" #include #include #include @@ -117,8 +118,7 @@ static void packet_peek_cb(rbc_mesh_packet_peek_params_t *params) { int main(void) { - nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLDOWN); - nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLDOWN); + bsp_init(BSP_INIT_BUTTONS & BSP_INIT_LED, 0, 0); /* Enable Softdevice (including sd_ble before framework */ SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SRC, NULL); @@ -130,14 +130,15 @@ int main(void) // Register with the SoftDevice handler module for system events. softdevice_sys_evt_handler_set(sys_evt_dispatch); - LEDS_CONFIGURE(LEDS_MASK); // Debug pins - nrf_gpio_cfg_output(5); - nrf_gpio_cfg_output(6); + // nrf_gpio_cfg_output(5); + // nrf_gpio_cfg_output(6); // Disable simblee's proximityMode +#ifdef SIMBLEE nrf_gpio_cfg_output(31); CLEAR_PIN(31); +#endif // if (NRF_CLOCK->LFCLKSRC == (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)) { // TOGGLE_LED(LED_GREEN); diff --git a/src/scheduler.c b/src/scheduler.c index 5a45ae9..6c30cb3 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -183,7 +183,7 @@ void set_clock_time(int32_t epoch, uint16_t ms, clock_source_t clock_source, int } else if (clock_source == CLOCK_SOURCE_SERIAL) { m_clock_version++; } - TOGGLE_PIN(LED_BLUE + LED_START); + TOGGLE_LED(LED_BLUE); m_boot_time += epoch - m_current_time; m_last_sync = m_current_time = epoch; app_timer_stop(m_periodic_timer_ID); diff --git a/src/sensor.c b/src/sensor.c index 0bc667b..4dd47cd 100644 --- a/src/sensor.c +++ b/src/sensor.c @@ -1,4 +1,5 @@ +#include "boards.h" #include "sensor.h" #include "config.h" #include "rbc_mesh.h" @@ -7,11 +8,14 @@ #include "handles.h" #include "shoe_accel.h" #include +#include static sensor_value_t m_value; void sensor_init() { +#ifdef ACCEL_ADXL337 shoe_accel_init(); +#endif uint32_t error_code; error_code = rbc_mesh_value_enable(SENSOR_HANDLE); @@ -19,20 +23,27 @@ void sensor_init() { } void sensor_warmup_event() { +#ifdef ACCEL_ADXL337 enable_shoe_accel(); +#endif } void gather_sensor_data() { + memset(&m_value, 0, sizeof(sensor_value_t)); m_value.valid_time = get_clock_time(); m_value.battery = get_battery_adc(); //m_value.status = ?? +#ifdef ACCEL_ADXL337 read_shoe_accel(&m_value.accel_x, &m_value.accel_y, &m_value.accel_z); +#endif proximity_get_strongest_signals(m_value.proximity_ids, m_value.proximity_rssi, MAX_PROXIMITY_TRACKING_COUNT); proximity_values_reset(); +#ifdef ACCEL_ADXL337 disable_shoe_accel(); +#endif } void report_sensor_data() {