You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

115 lines
4.4 KiB

#pragma once
#include <stdint.h>
#include <string.h>
#include <time.h>
//
#include "app_scheduler.h"
#include "app_timer.h"
#include "app_uart.h"
#include "app_util_platform.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_conn_params.h"
#include "ble_hci.h"
#include "ble_nus.h"
#include "bsp_btn_ble.h"
#include "diskio_blkdev.h"
#include "ff.h"
#include "nordic_common.h"
#include "nrf.h"
#include "nrf_ble_gatt.h"
#include "nrf_ble_qwr.h"
#include "nrf_block_dev_sdc.h"
#include "nrf_delay.h"
#include "nrf_drv_pwm.h"
#include "nrf_drv_saadc.h"
#include "nrf_drv_spi.h"
#include "nrf_drv_twi.h"
#include "nrf_drv_wdt.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
//
#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
// #define ZNORDIC_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE) APP_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE)
/*******************************************************************************
* UTILS *
*******************************************************************************/
typedef struct tm ztm_t;
void znordic_init();
void znordic_loop();
void znrf_gpio_cfg_output(uint32_t pin_number, nrf_gpio_pin_pull_t pull);
int16_t znrf_adc_channel_read_val(uint16_t channel);
void znordic_set_uart_log_pin(uint32_t pin_number);
void znordic_rtc_settime_s(uint32_t timestamp_s);
uint32_t znordic_rtc_gettime_s(void);
uint32_t znordic_getpower_on_s(void); // »ñµÃÉϵçʱ¼ä
uint32_t znordic_getpower_on_ms(void); // ×îС¾«¶È125ms
uint32_t znordic_haspassed_ms(uint32_t last);
void znordic_rtc_gettime(ztm_t* now);
void znordic_rtc_settime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec);
void znordic_force_flush_log();
const char* fmt(const char* fmt, ...);
const char* hex2str(const uint8_t* data, uint16_t len);
/*******************************************************************************
* LOG *
*******************************************************************************/
#define ZLOGI(...) NRF_LOG_INFO(__VA_ARGS__)
#define ZLOGE(...) NRF_LOG_ERROR(__VA_ARGS__)
#define ZLOGW(...) NRF_LOG_WARNING(__VA_ARGS__)
#define ZLOGD(...) NRF_LOG_DEBUG(__VA_ARGS__)
#define ZLOGI_BLOCK(...) \
{ \
NRF_LOG_INFO(__VA_ARGS__); \
znordic_force_flush_log(); \
}
#define ZLOGE_BLOCK(...) \
{ \
NRF_LOG_ERROR(__VA_ARGS__); \
znordic_force_flush_log(); \
}
#define ZLOGW_BLOCK(...) \
{ \
NRF_LOG_WARNING(__VA_ARGS__); \
znordic_force_flush_log(); \
}
#define ZLOGD_BLOCK(...) \
{ \
NRF_LOG_DEBUG(__VA_ARGS__); \
znordic_force_flush_log(); \
}
#define ZARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#define ZPIN(port, num) NRF_GPIO_PIN_MAP(port, num)
#define ZERROR_CHECK(err_code) \
do { \
const uint32_t LOCAL_ERR_CODE = (err_code); \
if (LOCAL_ERR_CODE != NRF_SUCCESS) { \
ZLOGI("%s:%d ZERROR_CHECK(%s) fail:%d", __FILE__, __LINE__, #err_code, LOCAL_ERR_CODE); \
NRF_LOG_PROCESS(); \
APP_ERROR_CHECK(LOCAL_ERR_CODE); \
} \
} while (0)
#define ZASSERT(expr) \
do { \
if (!(expr)) { \
ZLOGI("%s:%d ZASSERT(%s) fail", __FILE__, __LINE__, #expr); \
NRF_LOG_PROCESS(); \
APP_ERROR_CHECK_BOOL(false); \
} \
} while (0)