Files
microchip-application-bmd38…/main.c
T
2023-05-09 21:00:09 +08:00

146 lines
3.4 KiB
C

#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "app_config.h"
#include "apply_old_config.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "FreeRTOS.h"
#include "task.h"
#ifdef __cplusplus
}
#endif
#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */
static void le_evt_handler(ble_evt_t const *p_ble_evt, void *p_context)
{
switch (p_ble_evt->header.evt_id)
{
ret_code_t err_code;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST: {
NRF_LOG_DEBUG("PHY update request.");
ble_gap_phys_t const phys = {
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
}
break;
default:
break;
}
}
static void le_stack_Init(void)
{
ret_code_t err_code;
uint32_t ram_start = 0;
ble_cfg_t ble_cfg;
memset(&ble_cfg, 0x00, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 8;
err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);
// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);
// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);
APP_ERROR_CHECK(err_code);
// Register a handler for BLE events.
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, le_evt_handler, NULL);
}
void led1_task(void *pArg)
{
nrf_gpio_cfg_output(13);
for (;;)
{
NRF_LOG_INFO("led 1 off");
nrf_gpio_pin_set(13);
vTaskDelay(500);
NRF_LOG_INFO("led 1 on");
nrf_gpio_pin_clear(13);
vTaskDelay(500);
}
}
void led2_task(void *pArg)
{
nrf_gpio_cfg_output(14);
for (;;)
{
NRF_LOG_INFO("led 2 off");
nrf_gpio_pin_set(14);
vTaskDelay(125);
NRF_LOG_INFO("led 2 on");
nrf_gpio_pin_clear(14);
vTaskDelay(125);
}
}
int main(void)
{
NRF_LOG_INIT(NULL, 0);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("%s Build: %s %s", ELITE_DEVICE_NAME, __TIME__, __DATE__);
le_stack_Init();
extern void le_gap_init(const char *device_name, uint16_t usAppearance);
le_gap_init(ELITE_DEVICE_NAME, BLE_APPEARANCE_UNKNOWN);
extern void le_gatt_init(void);
le_gatt_init();
extern void le_srv_init(void);
le_srv_init();
extern void le_adv_init(uint8_t ble_conn_cfg_tag);
le_adv_init(APP_BLE_CONN_CFG_TAG);
nrf_sdh_freertos_init(NULL, NULL);
xTaskCreate(led1_task, "led1_task", 160, NULL, 3, NULL);
xTaskCreate(led2_task, "led2_task", 160, NULL, 3, NULL);
vTaskStartScheduler();
for (;;)
{
__BKPT(255);
}
}