first submission

This commit is contained in:
qiyongshuang
2023-02-01 14:19:13 +08:00
parent d534aad004
commit b79c6ac80d
3711 changed files with 745432 additions and 2 deletions
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
*
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*/
#ifndef ANCS_H
#define ANCS_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
#include "config.h"
#include "ancs_client.h"
#include <stdint.h>
/*********************************************************************
* CONSTANTS
*/
// ANCS discovery states
enum
{
DISC_IDLE = 0x00, // Idle state
DISC_ANCS_START = 0x10, // ANCS service
DISC_ANCS_SVC, // Discover service
DISC_ANCS_CHAR, // Discover all characteristics
DISC_ANCS_CCCD, // Discover ANCS CCCD
DISC_FAILED = 0xFF // Discovery failed
};
// ANCS handle cache indexes
enum
{
HDL_ANCS_NTF_NOTIF_START, // ANCS notification characteristic start handle
HDL_ANCS_NTF_NOTIF_END, // ANCS notification characteristic end handle
HDL_ANCS_NTF_CCCD, // ANCS notification CCCD
HDL_ANCS_CTRL_PT_START,
HDL_ANCS_CTRL_PT_END,
HDL_ANCS_DATA_SRC_START, // ANCS data source characteristic start handle
HDL_ANCS_DATA_SRC_END, // ANCS data source characteristic end handle
HDL_ANCS_DATA_SRC_CCCD, // ANCS data source CCCD
HDL_CACHE_LEN
};
/*********************************************************************
* TYPEDEFS
*/
struct bt_ancs_subscribe_cb {
void(*notification_source)(struct bt_ancs_client *ancs_c,
int err, const struct bt_ancs_evt_notif *notif);
void(*data_source)(struct bt_ancs_client *ancs_c,
const struct bt_ancs_attr_response *response);
void(*write_response)(struct bt_ancs_client *ancs_c,
uint8_t err);
};
typedef struct
{
uint16_t connHandle; // Connection handle of current connection
uint16_t connInterval;
uint16_t connSlaveLatency;
uint16_t connTimeout;
} peripheralConnItem_t;
/*********************************************************************
* MACROS
*/
#define START_DEVICE_EVT 0x0001
#define START_SUBSCRIPE_NOTISRC_EVT 0x0002
#define START_SUBSCRIPE_NOTIDATA_EVT 0x0004
#define START_DISCOVER_EVT 0x0008
#define START_PARAM_UPDATE_EVT 0x0010
#define START_PHY_UPDATE_EVT 0x0020
// Handle and 16-bit Bluetooth UUID pair indexes
#define ATT_BT_PAIR_HANDLE_IDX( i ) ( (i) * (2 + ATT_BT_UUID_SIZE) )
#define ATT_BT_PAIR_UUID_IDX( i ) ( ATT_BT_PAIR_HANDLE_IDX( (i) ) + 2 )
#define ATT_BT_PAIR_HANDLE( info, i ) ( BUILD_UINT16( (info)[ATT_BT_PAIR_HANDLE_IDX((i))], \
(info)[ATT_BT_PAIR_HANDLE_IDX((i))+1] ) )
#define ATT_BT_PAIR_UUID( info, i ) ( BUILD_UINT16( (info)[ATT_BT_PAIR_UUID_IDX((i))], \
(info)[ATT_BT_PAIR_UUID_IDX((i))+1] ) )
/*********************************************************************
* GLOBAL
*/
enum
{
CCCD_CONFIG_NOTIF = 0x00,
CCCD_CONFIG_DATA,
CCCD_CONFIG_DONE
};
extern struct bt_ancs_client ancs_c;
extern uint8_t ancs_taskid;
// Handle cache
extern uint16_t Ancs_handleCache[HDL_CACHE_LEN];
/*********************************************************************
* FUNCTIONS
*/
/*
* ANCS service discovery functions.
*/
void peripheral_ancs_client_init(void);
void ancs_subscribe_cb_register(struct bt_ancs_subscribe_cb *cb);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* ANCS_H */
@@ -0,0 +1,37 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_CONF_H
#define __CH32V20x_CONF_H
#include "ch32v20x_adc.h"
#include "ch32v20x_bkp.h"
#include "ch32v20x_can.h"
#include "ch32v20x_crc.h"
#include "ch32v20x_dbgmcu.h"
#include "ch32v20x_dma.h"
#include "ch32v20x_exti.h"
#include "ch32v20x_flash.h"
#include "ch32v20x_gpio.h"
#include "ch32v20x_i2c.h"
#include "ch32v20x_iwdg.h"
#include "ch32v20x_pwr.h"
#include "ch32v20x_rcc.h"
#include "ch32v20x_rtc.h"
#include "ch32v20x_spi.h"
#include "ch32v20x_tim.h"
#include "ch32v20x_usart.h"
#include "ch32v20x_wwdg.h"
#include "ch32v20x_it.h"
#include "ch32v20x_misc.h"
#endif /* __CH32V20x_CONF_H */
@@ -0,0 +1,18 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_it.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : This file contains the headers of the interrupt handlers.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_IT_H
#define __CH32V20x_IT_H
#include "debug.h"
#endif /* __CH32V20x_IT_H */
@@ -0,0 +1,31 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : CH32V20x Device Peripheral Access Layer System Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __SYSTEM_ch32v20x_H
#define __SYSTEM_ch32v20x_H
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
/* System_Exported_Functions */
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /*__CH32V20x_SYSTEM_H */
@@ -0,0 +1,32 @@
#ifndef TIME_UNITS_H
#define TIME_UNITS_H
#include "config.h"
#ifdef CLK_OSC32K
#if (CLK_OSC32K==1)
#define FREQ_RTC 32000
#else
#define FREQ_RTC 32768
#endif
#endif /* CLK_OSC32K */
#define CLK_PER_US (1.0 / ((1.0 / FREQ_RTC) * 1000 * 1000)) // 0.032 clk/us
#define CLK_PER_MS (CLK_PER_US * 1000) // 32clk/ms
#define US_PER_CLK (1.0 / CLK_PER_US) // 31.25us/clk
#define MS_PER_CLK (US_PER_CLK / 1000.0) // 0.03125ms/clk
#define SYS_TO_US(clk) ((uint32_t)((clk) * US_PER_CLK))
#define SYS_TO_MS(clk) ((uint32_t)((clk) * MS_PER_CLK))
#define US_TO_SYS(us) ((uint32_t)((us) * CLK_PER_US))
#define MS_TO_SYS(ms) ((uint32_t)((ms) * CLK_PER_MS ))
static inline uint32_t get_current_time(void)
{
return SYS_TO_MS(RTC_GetCounter());
}
#endif /* TIME_UNITS_H */