/** @brief main function */ int main(void) { /* Enable Softdevice (including sd_ble before framework */ uint32_t error_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_handler); APP_ERROR_CHECK(error_code); ble_enable_params_t ble_enable_params; ble_enable_params.gatts_enable_params.service_changed = 0; error_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(error_code); /* init leds and pins */ gpio_init(); #ifdef RBC_MESH_SERIAL /* only want to enable serial interface, and let external host setup the framework */ mesh_aci_init(); #else /* Enable mesh framework on channel 37, min adv interval at 100ms, 2 characteristics */ rbc_mesh_init_params_t init_params; init_params.access_addr = 0xA541A68F; init_params.adv_int_ms = 100; init_params.channel = 38; init_params.handle_count = 2; init_params.packet_format = RBC_MESH_PACKET_FORMAT_ORIGINAL; init_params.radio_mode = RBC_MESH_RADIO_MODE_BLE_1MBIT; error_code = rbc_mesh_init(init_params); APP_ERROR_CHECK(error_code); /* request values for both LEDs on the mesh */ error_code = rbc_mesh_value_enable(1); APP_ERROR_CHECK(error_code); error_code = rbc_mesh_value_enable(2); APP_ERROR_CHECK(error_code); /* init BLE gateway softdevice application: */ nrf_adv_conn_init(); #endif /* enable softdevice IRQ */ sd_nvic_EnableIRQ(SD_EVT_IRQn); /* sleep */ while (true) { sd_app_evt_wait(); } }
int main(void) { uint32_t error_code; (void) error_code; uart_init(); PUTS("LED Mesh initializing"); error_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_handler); test_app_init(); #ifdef RBC_MESH_SERIAL mesh_aci_init(); #else PUTS("mesh service init"); rbc_mesh_init_params_t init_params; init_params.access_addr = 0xA541A68F; init_params.adv_int_ms = 100; init_params.channel = 38; init_params.handle_count = 2; init_params.packet_format = RBC_MESH_PACKET_FORMAT_ORIGINAL; init_params.radio_mode = RBC_MESH_RADIO_MODE_BLE_1MBIT; error_code = rbc_mesh_init(init_params); APP_ERROR_CHECK(error_code); error_code = rbc_mesh_value_enable(1); APP_ERROR_CHECK(error_code); error_code = rbc_mesh_value_enable(2); APP_ERROR_CHECK(error_code); #endif sd_nvic_EnableIRQ(SD_EVT_IRQn); /* sleep */ while (true) { sd_app_evt_wait(); } }
/***************************************************************************** * Interface functions *****************************************************************************/ void bootloader_init(void) { rtc_init(); memset(&m_flash_fifo, 0, sizeof(fifo_t)); m_flash_fifo.elem_array = m_flash_fifo_buf; m_flash_fifo.elem_size = sizeof(flash_queue_entry_t); m_flash_fifo.array_len = FLASH_FIFO_SIZE; fifo_init(&m_flash_fifo); NVIC_SetPriority(FLASH_HANDLER_IRQn, 3); NVIC_EnableIRQ(FLASH_HANDLER_IRQn); bootloader_app_bridge_init(); bl_cmd_t init_cmd; init_cmd.type = BL_CMD_TYPE_INIT; init_cmd.params.init.bl_if_version = BL_IF_VERSION; init_cmd.params.init.event_callback = bl_evt_handler; init_cmd.params.init.timer_count = 1; init_cmd.params.init.tx_slots = TRANSPORT_TX_SLOTS; init_cmd.params.init.in_app = false; APP_ERROR_CHECK(bl_cmd_handler(&init_cmd)); #ifdef RBC_MESH_SERIAL mesh_aci_init(); #endif transport_init(rx_cb, RBC_MESH_ACCESS_ADDRESS_BLE_ADV); bool dfu_bank_flash_start; dfu_bank_scan(&dfu_bank_flash_start); if (dfu_bank_flash_start) { /* A bank is to be flashed. Attempt to go to app if possible. */ NRF_POWER->GPREGRET = RBC_MESH_GPREGRET_CODE_GO_TO_APP; } }
/** @brief main function */ int main(void) { uart_init(); PUTS("LED Mesh initializing"); /* Enable Softdevice (including sd_ble before framework */ uint32_t error_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_handler); APP_ERROR_CHECK(error_code); ble_enable_params_t ble_enable_params; memset(&ble_enable_params, 0, sizeof(ble_enable_params)); ble_enable_params.gatts_enable_params.service_changed = 0; ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; error_code = sd_ble_enable(&ble_enable_params); APP_ERROR_CHECK(error_code); /* init leds and pins */ gpio_init(); #ifdef RBC_MESH_SERIAL /* only want to enable serial interface, and let external host setup the framework */ mesh_aci_init(); #else /* Enable mesh framework on channel 37, min adv interval at 100ms, 2 characteristics */ rbc_mesh_init_params_t init_params; init_params.access_addr = 0xA541A68F; init_params.adv_int_ms = 100; init_params.channel = 38; init_params.handle_count = 2; init_params.packet_format = RBC_MESH_PACKET_FORMAT_ORIGINAL; init_params.radio_mode = RBC_MESH_RADIO_MODE_BLE_1MBIT; error_code = rbc_mesh_init(init_params); APP_ERROR_CHECK(error_code); /* request values for both LEDs on the mesh */ error_code = rbc_mesh_value_enable(1); APP_ERROR_CHECK(error_code); error_code = rbc_mesh_value_enable(2); APP_ERROR_CHECK(error_code); /* init BLE gateway softdevice application: */ nrf_adv_conn_init(); #endif /* enable softdevice IRQ */ error_code = sd_nvic_EnableIRQ(SD_EVT_IRQn); #ifndef BUTTONS /* sleep */ while (true) { sd_app_evt_wait(); } #else uint8_t mesh_data[16] = {0,0}; while (true) { // red off if(nrf_gpio_pin_read(BUTTON_1) == 0) { PUTS("BUTTON_1 pressed"); while(nrf_gpio_pin_read(BUTTON_1) == 0); mesh_data[0] = 0; rbc_mesh_value_set(1, mesh_data, 1); } // red on if(nrf_gpio_pin_read(BUTTON_2) == 0) { PUTS("BUTTON_1 pressed"); while(nrf_gpio_pin_read(BUTTON_2) == 0); mesh_data[0] = 1; rbc_mesh_value_set(1, mesh_data, 1); } // green off if(nrf_gpio_pin_read(BUTTON_3) == 0) { PUTS("BUTTON_3 pressed"); while(nrf_gpio_pin_read(BUTTON_3) == 0); mesh_data[0] = 0; rbc_mesh_value_set(2, mesh_data, 1); } // green on if(nrf_gpio_pin_read(BUTTON_4) == 0) { PUTS("BUTTON_4 pressed"); while(nrf_gpio_pin_read(BUTTON_4) == 0); mesh_data[0] = 1; rbc_mesh_value_set(2, mesh_data, 1); } } #endif }