Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #115 from ojousima/v1-backports
Browse files Browse the repository at this point in the history
  • Loading branch information
ojousima authored Apr 19, 2018
2 parents faf4e94 + 8ceea3e commit 4c7063c
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 378 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ ui_*.h

keys

# Build directories

# Build directories, files
_build
*.hex
*.zip

# VisualGDB Makefile

Expand All @@ -70,3 +71,4 @@ nRF5_SDK_12.1.0_0d23e2a.zip
nRF5_SDK_12.2.*
nRF5_SDK_12.3.*
nRF5_SDK_13.*
nRF5_SDK_14.*
8 changes: 7 additions & 1 deletion drivers/bluetooth/ble_event_handlers.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ble_event_handlers.h"
#include "sdk_application_config.h"

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -34,9 +35,11 @@ bool is_ble_connected()
*/
void sys_evt_dispatch(uint32_t sys_evt)
{
#if APP_GATT_PROFILE_ENABLED
// Dispatch the system event to the fstorage module, where it will be
// dispatched to the Flash Data Storage (FDS) module.
fs_sys_event_handler(sys_evt);
#endif

// Dispatch to the Advertising module last, since it will check if there are any
// pending flash operations in fstorage. Let fstorage process system events first,
Expand Down Expand Up @@ -324,11 +327,14 @@ void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
NRF_LOG_DEBUG("Dispatching BLE Event to modules\r\n");
ble_conn_state_on_ble_evt(p_ble_evt);
pm_on_ble_evt(p_ble_evt);
ble_conn_params_on_ble_evt(p_ble_evt);
bsp_btn_ble_on_ble_evt(p_ble_evt);
ble_advertising_on_ble_evt(p_ble_evt);
on_ble_evt(p_ble_evt);
application_on_ble_evt(p_ble_evt);
nrf_ble_qwr_on_ble_evt(&m_qwr, p_ble_evt);

#if PEER_MANAGER_ENABLED
pm_on_ble_evt(p_ble_evt);
#endif
}
23 changes: 16 additions & 7 deletions drivers/bluetooth/bluetooth_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ ble_advdata_t scanresp =
};

static bool advertising = false;
static ble_gap_conn_params_t gap_conn_params;
static ble_gap_conn_sec_mode_t sec_mode;
static ble_advdata_manuf_data_t m_manufacturer_data;

#if APP_GATT_PROFILE_ENABLED
static ble_gap_conn_params_t gap_conn_params;
#endif

/**
* Generate name "BASEXXXX", where Base is human-readable (i.e. Ruuvi) and XXXX is last 4 chars of mac address
*
Expand All @@ -148,7 +151,7 @@ void bluetooth_name_postfix_add(char* name_base, size_t base_length)
{
unsigned int addr0 = NRF_FICR->DEVICEADDR[0];
char postfix[4] = { 0 };
sprintf(postfix,"%x", addr0&0xFFFF);
sprintf(postfix,"%04x", addr0&0xFFFF);
memcpy(name_base + base_length, postfix, sizeof(postfix));
}

Expand Down Expand Up @@ -232,6 +235,7 @@ ret_code_t bluetooth_apply_configuration()
return err_code;
}

#if APP_GATT_PROFILE_ENABLED
/**@brief Function for the GAP initialization.
*
* @details This function will set up all the necessary GAP (Generic Access Profile) parameters of
Expand All @@ -254,7 +258,6 @@ static void gap_params_init(void)
APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the Connection Parameters module.
*/
static void conn_params_init(void)
Expand All @@ -279,6 +282,8 @@ static void conn_params_init(void)
//nrf_delay_ms(10);
APP_ERROR_CHECK(err_code);
}
#endif

//TODO: Enable & differentiate slow / fast advertising
static void advertising_init(void)
{
Expand Down Expand Up @@ -336,8 +341,10 @@ ret_code_t bluetooth_stack_init(void)
ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif

#if APP_GATT_PROFILE_ENABLED
//Init filesystem
err_code |= fs_init();
#endif

// Subscribe for BLE events.
err_code |= softdevice_ble_evt_handler_set(ble_evt_dispatch);
Expand All @@ -354,8 +361,9 @@ ret_code_t bluetooth_stack_init(void)
NRF_LOG_INFO("Softdevice enabled, status: %s\r\n", (uint32_t)ERR_TO_STR(err_code));
nrf_delay_ms(10);

//Enable peer manager, erase bonds
peer_manager_init(true);
//Enable peer manager, do not erase bonds
#if APP_GATT_PROFILE_ENABLED
peer_manager_init(false);
NRF_LOG_INFO("Peer manager init \r\n");
nrf_delay_ms(10);

Expand All @@ -365,11 +373,12 @@ ret_code_t bluetooth_stack_init(void)

gap_params_init();
NRF_LOG_INFO("GAP params init\r\n");
//nrf_delay_ms(10);
nrf_delay_ms(10);

conn_params_init();
NRF_LOG_INFO("Conn params init, status\r\n");
//nrf_delay_ms(10);
nrf_delay_ms(10);
#endif

advertising_init();
NRF_LOG_INFO("Advertising init, status\r\n");
Expand Down
89 changes: 43 additions & 46 deletions drivers/init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* This function initializes logging peripherals, and must be called before using NRF_LOG().
* Exact functionality depends on defines at sdk_config.h.
*
*
* @return 0 Operation successful
* @retval 1 Something went wrong
*
Expand Down Expand Up @@ -72,27 +72,27 @@ init_err_code_t init_ble(void)
//Enable DC/DC for BLE
NRF_POWER->DCDCEN = 1;
NRF_LOG_DEBUG("BLE Stack init start\r\n");

//Enable scheduler - required for BLE stack
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
APP_TIMER_APPSH_INIT(RUUVITAG_APP_TIMER_PRESCALER, SCHED_QUEUE_SIZE, true);

//Enable BLE STACK
err_code = bluetooth_stack_init();

// Application Replies are sent by BLE GATT
set_ble_gatt_handler(ble_std_transfer_asynchronous);
set_reply_handler(ble_std_transfer_asynchronous);

NRF_LOG_DEBUG("BLE Stack init done\r\n");
return (NRF_SUCCESS == err_code) ? INIT_SUCCESS : INIT_ERR_UNKNOWN;
}

/**
* Initialize NFC driver
*
*
* Puts NFC on standby, ready to transmit ID of the tag.
*
*
* @return 0 Operation successful
* @retval 1 Something went wrong
*
Expand Down Expand Up @@ -125,10 +125,10 @@ init_err_code_t init_timer(app_timer_id_t main_timer_id, uint32_t main_interval,
// Requires low-frequency clock initialized.
// Create timer
init_err_code_t err_code = app_timer_create(&main_timer_id,
APP_TIMER_MODE_REPEATED,
timer_handler);
APP_TIMER_MODE_REPEATED,
timer_handler);
APP_ERROR_CHECK(err_code);

//Start timer
err_code = app_timer_start(main_timer_id, APP_TIMER_TICKS(main_interval, RUUVITAG_APP_TIMER_PRESCALER), NULL); // 1 event / MAIN_TIMER_INTERVAL
APP_ERROR_CHECK(err_code);
Expand All @@ -145,18 +145,18 @@ init_err_code_t init_timer(app_timer_id_t main_timer_id, uint32_t main_interval,
*/
init_err_code_t init_leds(void)
{
if(LED_RED)
{
nrf_gpio_cfg_output (LED_RED);
nrf_gpio_pin_set(LED_RED);
}
if(LED_GREEN)
{
nrf_gpio_cfg_output (LED_GREEN);
nrf_gpio_pin_set(LED_GREEN);
}
NRF_LOG_DEBUG("LEDs init\r\n");
return INIT_SUCCESS; // Cannot fail under any reasonable circumstance
if (LED_RED)
{
nrf_gpio_cfg_output (LED_RED);
nrf_gpio_pin_set(LED_RED);
}
if (LED_GREEN)
{
nrf_gpio_cfg_output (LED_GREEN);
nrf_gpio_pin_set(LED_GREEN);
}
NRF_LOG_DEBUG("LEDs init\r\n");
return INIT_SUCCESS; // Cannot fail under any reasonable circumstance
}

/**
Expand Down Expand Up @@ -187,7 +187,7 @@ init_err_code_t init_lis2dh12(void)
{
NRF_LOG_ERROR("LIS2DH12 init Failed: Error Code: %d\r\n", (int32_t)err_code);
}
return err_code;
return err_code;
}

init_err_code_t init_bme280(void)
Expand All @@ -197,7 +197,7 @@ init_err_code_t init_bme280(void)
err_code = bme280_init();
if (INIT_SUCCESS != err_code)
{
return (BME280_RET_ERROR_SELFTEST == (BME280_Ret)err_code) ? INIT_ERR_SELFTEST : INIT_ERR_NO_RESPONSE;
return (BME280_RET_ERROR_SELFTEST == (BME280_Ret)err_code) ? INIT_ERR_SELFTEST : INIT_ERR_NO_RESPONSE;
}
//TODO: reset
bme280_set_mode(BME280_MODE_SLEEP); //Set sleep mode to allow configuration, sensor might have old config in internal RAM
Expand All @@ -213,7 +213,7 @@ init_err_code_t init_bme280(void)
}
else
{
NRF_LOG_ERROR("BME280 init Failed: Error Code: %d\r\n", (uint32_t)err_code);
NRF_LOG_ERROR("BME280 init Failed: Error Code: %d\r\n", (uint32_t)err_code);
}

return err_code;
Expand All @@ -223,7 +223,7 @@ init_err_code_t init_bme280(void)
* Initialize sensors
*
* This function initializes the sensor drivers.
* It should be called even if sensors are not used,
* It should be called even if sensors are not used,
* since initialization will put sensors in low-power mode
*
*
Expand All @@ -247,8 +247,8 @@ init_err_code_t init_sensors(void)
*/
init_err_code_t init_pwm(void)
{
pwm_init(200, LED_RED, LED_GREEN, 0, 0);
return INIT_SUCCESS;
pwm_init(200, LED_RED, LED_GREEN, 0, 0);
return INIT_SUCCESS;
}

/**
Expand All @@ -259,37 +259,34 @@ init_err_code_t init_pwm(void)
*/
init_err_code_t init_watchdog(watchdog_event_handler_t handler)
{
if(NULL == handler) { handler = watchdog_default_handler; }
init_err_code_t err_code = INIT_SUCCESS;
err_code |= watchdog_init(handler);
watchdog_enable();
return err_code;
if (NULL == handler) { handler = watchdog_default_handler; }
init_err_code_t err_code = INIT_SUCCESS;
err_code |= watchdog_init(handler);
watchdog_enable();
return err_code;

}

/**
* Display init status
* Blinks 10 times if there was error in init and returns.
*
* This function checks the init status from previous
* init operations, and blinks the led in infinite loop
* if there was error.
*
* @param init_status number of errors occured in init, 0 on successful init.
*/
init_err_code_t init_blink_status(uint8_t init_status)
{
nrf_gpio_pin_clear(LED_RED);
do
if (init_status)
{
for(uint8_t ii = 0; ii < init_status * 2; ii++)
{
nrf_gpio_pin_clear(LED_RED);

for (uint8_t ii = 0; ii < 10 * 2; ii++)
{
nrf_gpio_pin_toggle(LED_RED);
nrf_delay_ms(150u);//Delay prevents power saving, use with care
nrf_delay_ms(250u);//Delay prevents power saving, use with care
}//infinite loop if there is error

nrf_delay_ms(1000u); // Gives user time to count the blinks
}while(init_status);
nrf_gpio_pin_set(LED_RED);

nrf_gpio_pin_set(LED_RED);
}

return INIT_SUCCESS;
}
Loading

0 comments on commit 4c7063c

Please sign in to comment.