- /********************************************************************************************************
- * @file app_att.c
- *
- * @brief This is the source file for BLE SDK
- *
- * @author BLE GROUP
- * @date 06,2020
- *
- * @par Copyright (c) 2020, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Unless for usage inside a TELINK integrated circuit, redistributions
- * in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. Neither the name of TELINK, nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * 4. This software, with or without modification, must only be used with a
- * TELINK integrated circuit. All other usages are subject to written permission
- * from TELINK and different commercial license may apply.
- *
- * 5. Licensee shall be solely responsible for any claim to the extent arising out of or
- * relating to such deletion(s), modification(s) or alteration(s).
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *******************************************************************************************************/
- #include "tl_common.h"
-
- #include "stack/ble/ble.h"
- #include "app.h"
- #include "app_att.h"
-
- typedef struct
- {
- /** Minimum value for the connection event (interval. 0x0006 - 0x0C80 * 1.25 ms) */
- u16 intervalMin;
- /** Maximum value for the connection event (interval. 0x0006 - 0x0C80 * 1.25 ms) */
- u16 intervalMax;
- /** Number of LL latency connection events (0x0000 - 0x03e8) */
- u16 latency;
- /** Connection Timeout (0x000A - 0x0C80 * 10 ms) */
- u16 timeout;
- } gap_periConnectParams_t;
-
- #define CHAR_2_LEN 5//5
- #define CHAR_16_LEN 19//19
-
- static const u16 clientCharacterCfgUUID = GATT_UUID_CLIENT_CHAR_CFG;
-
- static const u16 extReportRefUUID = GATT_UUID_EXT_REPORT_REF;
-
- static const u16 reportRefUUID = GATT_UUID_REPORT_REF;
-
- static const u16 characterPresentFormatUUID = GATT_UUID_CHAR_PRESENT_FORMAT;
-
- static const u16 userdesc_UUID = GATT_UUID_CHAR_USER_DESC;
-
- static const u16 serviceChangeUUID = GATT_UUID_SERVICE_CHANGE;
-
- static const u16 my_primaryServiceUUID = GATT_UUID_PRIMARY_SERVICE;
-
- static const u16 my_characterUUID = GATT_UUID_CHARACTER;
-
- static const u16 my_devServiceUUID = SERVICE_UUID_DEVICE_INFORMATION;
-
- static const u16 my_PnPUUID = CHARACTERISTIC_UUID_PNP_ID;
-
- static const u16 my_devNameUUID = GATT_UUID_DEVICE_NAME;
-
- static const u16 my_gapServiceUUID = SERVICE_UUID_GENERIC_ACCESS;
-
- static const u16 my_appearanceUIID = GATT_UUID_APPEARANCE;
-
- static const u16 my_periConnParamUUID = GATT_UUID_PERI_CONN_PARAM;
-
- static const u16 my_appearance = GAP_APPEARE_UNKNOWN;
-
- static const u16 my_gattServiceUUID = SERVICE_UUID_GENERIC_ATTRIBUTE;
-
- static const gap_periConnectParams_t my_periConnParameters = {20, 40, 0, 1000};
-
- static u16 serviceChangeVal[2] = {0};
-
- static u8 serviceChangeCCC[2] = {0,0};
-
- static const u8 my_devName[] = {'t','S','a','m','p','l','e'};
-
- static const u8 my_PnPtrs [] = {0x02, 0x8a, 0x24, 0x66, 0x82, 0x01, 0x00};
-
- Battery /
- static const u16 my_batServiceUUID = SERVICE_UUID_BATTERY;
- static const u16 my_batCharUUID = CHARACTERISTIC_UUID_BATTERY_LEVEL;
- static u8 batteryValueInCCC[2];
- static u8 my_batVal[1] = {99};
-
- HID /
-
- static const u16 my_hidServiceUUID = SERVICE_UUID_HUMAN_INTERFACE_DEVICE;
-
- static const u16 hidServiceUUID = SERVICE_UUID_HUMAN_INTERFACE_DEVICE;
- static const u16 hidProtocolModeUUID = CHARACTERISTIC_UUID_HID_PROTOCOL_MODE;
- static const u16 hidReportUUID = CHARACTERISTIC_UUID_HID_REPORT;
- static const u16 hidReportMapUUID = CHARACTERISTIC_UUID_HID_REPORT_MAP;
- static const u16 hidbootKeyInReportUUID = CHARACTERISTIC_UUID_HID_BOOT_KEY_INPUT;
- static const u16 hidbootKeyOutReportUUID = CHARACTERISTIC_UUID_HID_BOOT_KEY_OUTPUT;
- //static const u16 hidbootMouseInReportUUID = CHARACTERISTIC_UUID_HID_BOOT_MOUSE_INPUT;
- static const u16 hidinformationUUID = CHARACTERISTIC_UUID_HID_INFORMATION;
- static const u16 hidCtrlPointUUID = CHARACTERISTIC_UUID_HID_CONTROL_POINT;
- static const u16 hidIncludeUUID = GATT_UUID_INCLUDE;
-
-
- //移植鼠标添加区域
- #if 1
- static u8 reportMouseIn[6];
- static u8 reportMouseInCCC[2] = {0, 0};
- static u8 reportRefMouseIn[2] = {3, HID_REPORT_TYPE_INPUT };
- const u8 reportMouseInChar[5] =
- {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY | CHAR_PROP_WRITE,
- HID_MOUSE_REPORT_INPUT_DP_H, 0x00,
- 0x4D, 0x2a,
- };
-
- const u16 hidbootMouseInReportUUID = CHARACTERISTIC_UUID_HID_BOOT_MOUSE_INPUT;
-
- static u8 bootMouseInReport;
- static u8 bootMouseInReportCCC[2] = {0, 0};
- const u8 bootMouseInChar[5] =
- {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY | CHAR_PROP_WRITE,
- HID_BOOT_MOUSE_REPORT_INPUT_DP_H, 0x00,
- 0x33, 0x2a,
- };
- static u8 reportUseIn[4];
- static u8 reportUseInCCC[2] = {0, 0};
- static u8 reportRefUseIn[2] = {REPORT_ID_USER_FEATURE, HID_REPORT_TYPE_FEATURE};
- const u8 reportUseInChar[5] =
- {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY | CHAR_PROP_WRITE,
- HID_USER_REPORT_INPUT_DP_H, 0x00,
- 0x4D, 0x2a,
- };
- int cccWrite(void *p)
- {
- #if 0
- conn_step = SMP_DONE_AAA;
- connect_begin_tick = clock_time() | 1;
-
- //for debug test
- gpio_write(PIN_24G_LED, 1);
- #endif
-
- return 0;
- }
- #endif
-
- static u8 protocolMode = DFLT_HID_PROTOCOL_MODE;
-
- // Key in Report characteristic variables
- static u8 reportKeyIn[8];
- static u8 reportKeyInCCC[2];
- // HID Report Reference characteristic descriptor, key input
- static u8 reportRefKeyIn[2] =
- { HID_REPORT_ID_KEYBOARD_INPUT, HID_REPORT_TYPE_INPUT };
-
- // Key out Report characteristic variables
- static u8 reportKeyOut[1];
- static u8 reportRefKeyOut[2] =
- { HID_REPORT_ID_KEYBOARD_INPUT, HID_REPORT_TYPE_OUTPUT };
-
- // Consumer Control input Report
- static u8 reportConsumerControlIn[2];
- static u8 reportConsumerControlInCCC[2];
- static u8 reportRefConsumerControlIn[2] =
- { HID_REPORT_ID_CONSUME_CONTROL_INPUT, HID_REPORT_TYPE_INPUT };
-
- // Boot Keyboard Input Report
- static u8 bootKeyInReport;
- static u8 bootKeyInReportCCC[2];
-
- // Boot Keyboard Output Report
- static u8 bootKeyOutReport;
-
- // HID Information characteristic
- static const u8 hidInformation[] =
- {
- U16_LO(0x0111), U16_HI(0x0111), // bcdHID (USB HID version)
- 0x00, // bCountryCode
- 0x01 // Flags
- };
-
- // HID Control Point characteristic
- static u8 controlPoint;
-
- // HID Report Map characteristic
- // Keyboard report descriptor (using format for Boot interface descriptor)
-
- static const u8 reportMap[] =
- {
- #if 0
- //keyboard report in
- 0x05, 0x01, // Usage Pg (Generic Desktop)
- 0x09, 0x06, // Usage (Keyboard)
- 0xA1, 0x01, // Collection: (Application)
- 0x85, HID_REPORT_ID_KEYBOARD_INPUT, // Report Id (keyboard)
- //
- 0x05, 0x07, // Usage Pg (Key Codes)
- 0x19, 0xE0, // Usage Min (224) VK_CTRL:0xe0
- 0x29, 0xE7, // Usage Max (231) VK_RWIN:0xe7
- 0x15, 0x00, // Log Min (0)
- 0x25, 0x01, // Log Max (1)
- //
- // Modifier byte
- 0x75, 0x01, // Report Size (1) 1 bit * 8
- 0x95, 0x08, // Report Count (8)
- 0x81, 0x02, // Input: (Data, Variable, Absolute)
- //
- // Reserved byte
- 0x95, 0x01, // Report Count (1)
- 0x75, 0x08, // Report Size (8)
- 0x81, 0x01, // Input: (static constant)
-
- //keyboard output
- //5 bit led ctrl: NumLock CapsLock ScrollLock Compose kana
- 0x95, 0x05, //Report Count (5)
- 0x75, 0x01, //Report Size (1)
- 0x05, 0x08, //Usage Pg (LEDs )
- 0x19, 0x01, //Usage Min
- 0x29, 0x05, //Usage Max
- 0x91, 0x02, //Output (Data, Variable, Absolute)
- //3 bit reserved
- 0x95, 0x01, //Report Count (1)
- 0x75, 0x03, //Report Size (3)
- 0x91, 0x01, //Output (static constant)
-
- // Key arrays (6 bytes)
- 0x95, 0x06, // Report Count (6)
- 0x75, 0x08, // Report Size (8)
- 0x15, 0x00, // Log Min (0)
- 0x25, 0xF1, // Log Max (241)
- 0x05, 0x07, // Usage Pg (Key Codes)
- 0x19, 0x00, // Usage Min (0)
- 0x29, 0xf1, // Usage Max (241)
- 0x81, 0x00, // Input: (Data, Array)
-
- 0xC0, // End Collection
-
- //consumer report in
- 0x05, 0x0C, // Usage Page (Consumer)
- 0x09, 0x01, // Usage (Consumer Control)
- 0xA1, 0x01, // Collection (Application)
- 0x85, HID_REPORT_ID_CONSUME_CONTROL_INPUT, // Report Id
- 0x75,0x10, //global, report size 16 bits
- 0x95,0x01, //global, report count 1
- 0x15,0x01, //global, min 0x01
- 0x26,0x8c,0x02, //global, max 0x28c
- 0x19,0x01, //local, min 0x01
- 0x2a,0x8c,0x02, //local, max 0x28c
- 0x81,0x00, //main, input data varible, absolute
- 0xc0, //main, end collection
- #endif
-
- #if 1
- //mouse report in
- 0x05, 0x01, // Usage Page (Generic Desktop)
- 0x09, 0x02, // Usage (Mouse)
- 0xA1, 0x01, // Collection (Application)
- 0x85, 3, // Report Id
- 0x09, 0x01, // Usage (Pointer)
- 0xA1, 0x00, // Collection (Physical)
- 0x05, 0x09, // Usage Page (Buttons)
- 0x19, 0x01, // Usage Minimum (01) - Button 1
- 0x29, 0x03, // Usage Maximum (03) - Button 3
- 0x15, 0x00, // Logical Minimum (0)
- 0x25, 0x01, // Logical Maximum (1)
- 0x75, 0x01, // Report Size (1)
- 0x95, 0x05, // Report Count (3)
- 0x81, 0x02, // Input (Data, Variable, Absolute) - Button states
- 0x75, 0x03, // Report Size (5)
- 0x95, 0x01, // Report Count (1)
- 0x81, 0x01, // Input (Constant) - Padding or Reserved bits
-
- 0x05, 0x01, // Usage Page (Generic Desktop Control)
- 0x09, 0x30, // Usage (X)
- 0x09, 0x31, // Usage (Y)
-
- //mouse data len 等于6
- 0x16, 0x01, 0x80, // LOGICAL_MINIMUM(0)
- 0x26, 0xff, 0x7f,
- 0x75, 0x10, // Report Size (16)
- 0x95, 0x02, // Report Count (2)
- 0x81, 0x06, // Input (Data, Variable, Relative)
-
- 0x09, 0x38, // Usage (Wheel)
- 0x15, 0x81, // Logical Minimum (-4)
- 0x25, 0x7F, // Logical Maximum (3)
- 0x75, 0x08, // Report Size (3)
- 0x95, 0x01, // Report Count (1)
- 0x81, 0x06, // Input (Data, Variable, Relative)
-
- 0xC0, // End Collection
- 0xC0, // End Collection
-
- 0x06, 0x01, 0xFF,
- 0x09, 0x01,
- 0xA1, 0x01,
- 0x85, 5,
- 0x09, 0x05,
- 0x15, 0x00,
- 0x26, 0xFF, 0x00,
- 0x75, 0x08,
- 0x95, 0x04,
- 0xB1, 0x02,
- 0xC0,
- #endif
- };
-
- // HID External Report Reference Descriptor for report map
- static u16 extServiceUUID;
-
-
- /
- static const u8 my_OtaUUID[16] = WRAPPING_BRACES(TELINK_SPP_DATA_OTA);
- static const u8 my_OtaServiceUUID[16] = WRAPPING_BRACES(TELINK_OTA_UUID_SERVICE);
- static u8 my_OtaData = 0x00;
- static u8 otaDataCCC[2] = {0,0};
-
- static const u8 my_MicName[] = {'M', 'i', 'c'};
- static const u8 my_SpeakerName[] = {'S', 'p', 'e', 'a', 'k', 'e', 'r'};
- static const u8 my_OtaName[] = {'O', 'T', 'A'};
-
-
- // Include attribute (Battery service)
- static const u16 include[3] = {BATT_PS_H, BATT_LEVEL_INPUT_CCB_H, SERVICE_UUID_BATTERY};
-
-
- GAP attribute values
- static const u8 my_devNameCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY,
- U16_LO(GenericAccess_DeviceName_DP_H), U16_HI(GenericAccess_DeviceName_DP_H),
- U16_LO(GATT_UUID_DEVICE_NAME), U16_HI(GATT_UUID_DEVICE_NAME)
- };
- static const u8 my_appearanceCharVal[5] = {
- CHAR_PROP_READ,
- U16_LO(GenericAccess_Appearance_DP_H), U16_HI(GenericAccess_Appearance_DP_H),
- U16_LO(GATT_UUID_APPEARANCE), U16_HI(GATT_UUID_APPEARANCE)
- };
- static const u8 my_periConnParamCharVal[5] = {
- CHAR_PROP_READ,
- U16_LO(CONN_PARAM_DP_H), U16_HI(CONN_PARAM_DP_H),
- U16_LO(GATT_UUID_PERI_CONN_PARAM), U16_HI(GATT_UUID_PERI_CONN_PARAM)
- };
-
-
- GATT attribute values
- static const u8 my_serviceChangeCharVal[5] = {
- CHAR_PROP_INDICATE,
- U16_LO(GenericAttribute_ServiceChanged_DP_H), U16_HI(GenericAttribute_ServiceChanged_DP_H),
- U16_LO(GATT_UUID_SERVICE_CHANGE), U16_HI(GATT_UUID_SERVICE_CHANGE)
- };
-
-
- device Information attribute values
- static const u8 my_PnCharVal[5] = {
- CHAR_PROP_READ,
- U16_LO(DeviceInformation_pnpID_DP_H), U16_HI(DeviceInformation_pnpID_DP_H),
- U16_LO(CHARACTERISTIC_UUID_PNP_ID), U16_HI(CHARACTERISTIC_UUID_PNP_ID)
- };
-
-
- HID attribute values
- static const u8 my_hidProtocolModeCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RSP,
- U16_LO(HID_PROTOCOL_MODE_DP_H), U16_HI(HID_PROTOCOL_MODE_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_PROTOCOL_MODE), U16_HI(CHARACTERISTIC_UUID_HID_PROTOCOL_MODE)
- };
- #if 0
- static const u8 my_hidbootKeyInReporCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY,
- U16_LO(HID_BOOT_KB_REPORT_INPUT_DP_H), U16_HI(HID_BOOT_KB_REPORT_INPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_BOOT_KEY_INPUT), U16_HI(CHARACTERISTIC_UUID_HID_BOOT_KEY_INPUT)
- };
- static const u8 my_hidbootKeyOutReporCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_WRITE | CHAR_PROP_WRITE_WITHOUT_RSP,
- U16_LO(HID_BOOT_KB_REPORT_OUTPUT_DP_H), U16_HI(HID_BOOT_KB_REPORT_OUTPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_BOOT_KEY_OUTPUT), U16_HI(CHARACTERISTIC_UUID_HID_BOOT_KEY_OUTPUT)
- };
- static const u8 my_hidReportCCinCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY,
- U16_LO(HID_CONSUME_REPORT_INPUT_DP_H), U16_HI(HID_CONSUME_REPORT_INPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_REPORT), U16_HI(CHARACTERISTIC_UUID_HID_REPORT)
- };
- static const u8 my_hidReportKEYinCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY,
- U16_LO(HID_NORMAL_KB_REPORT_INPUT_DP_H), U16_HI(HID_NORMAL_KB_REPORT_INPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_REPORT), U16_HI(CHARACTERISTIC_UUID_HID_REPORT)
- };
- static const u8 my_hidReportKEYoutCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_WRITE | CHAR_PROP_WRITE_WITHOUT_RSP,
- U16_LO(HID_NORMAL_KB_REPORT_OUTPUT_DP_H), U16_HI(HID_NORMAL_KB_REPORT_OUTPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_REPORT), U16_HI(CHARACTERISTIC_UUID_HID_REPORT)
- };
- #endif
- static const u8 my_hidReportMapCharVal[5] = {
- CHAR_PROP_READ,
- U16_LO(HID_REPORT_MAP_DP_H), U16_HI(HID_REPORT_MAP_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_REPORT_MAP), U16_HI(CHARACTERISTIC_UUID_HID_REPORT_MAP)
- };
- static const u8 my_hidinformationCharVal[5] = {
- CHAR_PROP_READ,
- U16_LO(HID_INFORMATION_DP_H), U16_HI(HID_INFORMATION_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_INFORMATION), U16_HI(CHARACTERISTIC_UUID_HID_INFORMATION)
- };
- static const u8 my_hidCtrlPointCharVal[5] = {
- CHAR_PROP_WRITE_WITHOUT_RSP,
- U16_LO(HID_CONTROL_POINT_DP_H), U16_HI(HID_CONTROL_POINT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_HID_CONTROL_POINT), U16_HI(CHARACTERISTIC_UUID_HID_CONTROL_POINT)
- };
-
-
- Battery attribute values
- static const u8 my_batCharVal[5] = {
- CHAR_PROP_READ | CHAR_PROP_NOTIFY,
- U16_LO(BATT_LEVEL_INPUT_DP_H), U16_HI(BATT_LEVEL_INPUT_DP_H),
- U16_LO(CHARACTERISTIC_UUID_BATTERY_LEVEL), U16_HI(CHARACTERISTIC_UUID_BATTERY_LEVEL)
- };
-
-
- OTA attribute values
- static const u8 my_OtaCharVal[19] = {
- CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RSP | CHAR_PROP_NOTIFY,
- U16_LO(OTA_CMD_OUT_DP_H), U16_HI(OTA_CMD_OUT_DP_H),
- TELINK_SPP_DATA_OTA,
- };
-
-
- // TM : to modify
- static const attribute_t my_Attributes[] = {
-
- {ATT_END_H - 1, 0,0,0,0,0}, // total num of attribute
-
-
- // 0001 - 0007 gap
- {7,ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_gapServiceUUID), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_devNameCharVal),(u8*)(&my_characterUUID), (u8*)(my_devNameCharVal), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_devName), (u8*)(&my_devNameUUID), (u8*)(my_devName), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_appearanceCharVal),(u8*)(&my_characterUUID), (u8*)(my_appearanceCharVal), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof (my_appearance), (u8*)(&my_appearanceUIID), (u8*)(&my_appearance), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_periConnParamCharVal),(u8*)(&my_characterUUID), (u8*)(my_periConnParamCharVal), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof (my_periConnParameters),(u8*)(&my_periConnParamUUID), (u8*)(&my_periConnParameters), 0},
-
-
- // 0008 - 000b gatt
- {4,ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_gattServiceUUID), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_serviceChangeCharVal),(u8*)(&my_characterUUID), (u8*)(my_serviceChangeCharVal), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof (serviceChangeVal), (u8*)(&serviceChangeUUID), (u8*)(&serviceChangeVal), 0},
- {0,ATT_PERMISSIONS_RDWR,2,sizeof (serviceChangeCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(serviceChangeCCC), 0},
-
-
- // 000c - 000e device Information Service
- {3,ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_devServiceUUID), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_PnCharVal),(u8*)(&my_characterUUID), (u8*)(my_PnCharVal), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof (my_PnPtrs),(u8*)(&my_PnPUUID), (u8*)(my_PnPtrs), 0},
-
-
- /// 4. HID Service /
- // 000f
- //{27, ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_hidServiceUUID), 0},
- {HID_CONTROL_POINT_DP_H - HID_PS_H + 1, ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_hidServiceUUID), 0},
-
- // 0010 include battery service
- //{0,ATT_PERMISSIONS_READ,2,sizeof(include),(u8*)(&hidIncludeUUID), (u8*)(include), 0},
-
- // 0011 - 0012 protocol mode
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidProtocolModeCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidProtocolModeCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_RDWR,2, sizeof(protocolMode),(u8*)(&hidProtocolModeUUID), (u8*)(&protocolMode), 0}, //value
- #if 0
- // 0013 - 0015 boot keyboard input report (char-val-client)
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidbootKeyInReporCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidbootKeyInReporCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2,sizeof(bootKeyInReport),(u8*)(&hidbootKeyInReportUUID), (u8*)(&bootKeyInReport), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(bootKeyInReportCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(bootKeyInReportCCC), 0}, //value
-
- // 0016 - 0017 boot keyboard output report (char-val)
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidbootKeyOutReporCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidbootKeyOutReporCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_RDWR,2, sizeof(bootKeyOutReport), (u8*)(&hidbootKeyOutReportUUID), (u8*)(&bootKeyOutReport), 0}, //value
-
- // 0018 - 001b. consume report in: 4 (char-val-client-ref)
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidReportCCinCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidReportCCinCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2, sizeof(reportConsumerControlIn),(u8*)(&hidReportUUID), (u8*)(reportConsumerControlIn), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportConsumerControlInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(reportConsumerControlInCCC), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportRefConsumerControlIn),(u8*)(&reportRefUUID), (u8*)(reportRefConsumerControlIn), 0}, //value
-
- // 001c - 001f . keyboard report in : 4 (char-val-client-ref)
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidReportKEYinCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidReportKEYinCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2, sizeof(reportKeyIn),(u8*)(&hidReportUUID), (u8*)(reportKeyIn), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportKeyInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(reportKeyInCCC), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportRefKeyIn),(u8*)(&reportRefUUID), (u8*)(reportRefKeyIn), 0}, //value
-
- // 0020 - 0022 . keyboard report out: 3 (char-val-ref)
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidReportKEYoutCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidReportKEYoutCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportKeyOut),(u8*)(&hidReportUUID), (u8*)(reportKeyOut), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(reportRefKeyOut),(u8*)(&reportRefUUID), (u8*)(reportRefKeyOut), 0}, //value
- #endif
-
-
-
- #if 1//鼠标移植
- // 0013 - 0015 boot keyboard input report (char-val-client)
- {0, ATT_PERMISSIONS_READ, 2, CHAR_2_LEN, (u8 *)(&my_characterUUID), (u8 *)(&bootMouseInChar[0]), 0}, //prop
- {0, ATT_PERMISSIONS_READ, 2, sizeof(bootMouseInReport), (u8 *)(&bootMouseInChar[3]), (u8 *)(&bootMouseInReport), 0}, //value
- {0, ATT_PERMISSIONS_RDWR, 2, 2, (u8 *)(&clientCharacterCfgUUID), (u8 *)(bootMouseInReportCCC), 0}, //value
-
- // 001c - 001f . keyboard report in : 4 (char-val-client-ref)
- {0, ATT_PERMISSIONS_READ, 2, CHAR_2_LEN, (u8 *)(&my_characterUUID), (u8 *)(&reportMouseInChar[0]), 0}, //prop
- {0, ATT_PERMISSIONS_RDWR, 2, sizeof(reportMouseIn), (u8 *)(&reportMouseInChar[3]), (u8 *)(reportMouseIn), 0}, //value
- {0, ATT_PERMISSIONS_RDWR, 2, 2, (u8 *)(&clientCharacterCfgUUID), (u8 *)(reportMouseInCCC), &cccWrite}, //value
- {0, ATT_PERMISSIONS_READ, 2, 2, (u8 *)(&reportRefUUID), (u8 *)(reportRefMouseIn), 0}, //value
-
- {0, ATT_PERMISSIONS_READ, 2, CHAR_2_LEN, (u8 *)(&my_characterUUID), (u8 *)(&reportUseInChar[0]), 0}, //prop
- {0, ATT_PERMISSIONS_RDWR, 2, sizeof(reportUseIn), (u8 *)(&reportUseInChar[3]), (u8 *)(reportUseIn), 0}, //value
- {0, ATT_PERMISSIONS_RDWR, 2, 2, (u8 *)(&clientCharacterCfgUUID), (u8 *)(reportUseInCCC), &cccWrite}, //value
- {0, ATT_PERMISSIONS_READ, 2, 2, (u8 *)(&reportRefUUID), (u8 *)(reportRefUseIn), 0}, //value
- #endif
-
-
-
- // 0023 - 0025 . report map: 3
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidReportMapCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidReportMapCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2,sizeof(reportMap),(u8*)(&hidReportMapUUID), (u8*)(reportMap), 0}, //value
- //{0,ATT_PERMISSIONS_RDWR,2,sizeof(extServiceUUID),(u8*)(&extReportRefUUID), (u8*)(&extServiceUUID), 0}, //value
-
- // 0026 - 0027 . hid information: 2
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidinformationCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidinformationCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2, sizeof(hidInformation),(u8*)(&hidinformationUUID), (u8*)(hidInformation), 0}, //value
-
- // 0028 - 0029 . control point: 2
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_hidCtrlPointCharVal),(u8*)(&my_characterUUID), (u8*)(my_hidCtrlPointCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_WRITE,2, sizeof(controlPoint),(u8*)(&hidCtrlPointUUID), (u8*)(&controlPoint), 0}, //value
-
- // Battery Service /
- // 002a - 002d
- {4,ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_batServiceUUID), 0},
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_batCharVal),(u8*)(&my_characterUUID), (u8*)(my_batCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_READ,2,sizeof(my_batVal),(u8*)(&my_batCharUUID), (u8*)(my_batVal), 0}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(batteryValueInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(batteryValueInCCC), 0}, //value
-
- // OTA /
- // 002e - 0032
- {5,ATT_PERMISSIONS_READ, 2,16,(u8*)(&my_primaryServiceUUID), (u8*)(&my_OtaServiceUUID), 0},
- {0,ATT_PERMISSIONS_READ, 2, sizeof(my_OtaCharVal),(u8*)(&my_characterUUID), (u8*)(my_OtaCharVal), 0}, //prop
- {0,ATT_PERMISSIONS_RDWR,16,sizeof(my_OtaData),(u8*)(&my_OtaUUID), (&my_OtaData), &otaWrite, NULL}, //value
- {0,ATT_PERMISSIONS_RDWR,2,sizeof(otaDataCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(otaDataCCC), 0}, //value
- {0,ATT_PERMISSIONS_READ, 2,sizeof (my_OtaName),(u8*)(&userdesc_UUID), (u8*)(my_OtaName), 0},
-
- };
-
-
- /**
- * @brief Initialize the attribute table
- * @param[in] none
- * @return none
- */
- void my_att_init (void)
- {
- bls_att_setAttributeTable ((u8 *)my_Attributes);
- }
-
-
- /********************************************************************************************************
- * @file app_att.h
- *
- * @brief This is the header file for BLE SDK
- *
- * @author BLE GROUP
- * @date 06,2020
- *
- * @par Copyright (c) 2020, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Unless for usage inside a TELINK integrated circuit, redistributions
- * in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. Neither the name of TELINK, nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * 4. This software, with or without modification, must only be used with a
- * TELINK integrated circuit. All other usages are subject to written permission
- * from TELINK and different commercial license may apply.
- *
- * 5. Licensee shall be solely responsible for any claim to the extent arising out of or
- * relating to such deletion(s), modification(s) or alteration(s).
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *******************************************************************************************************/
- #ifndef APP_ATT_H_
- #define APP_ATT_H_
-
-
-
-
- / ATT HANDLER define ///
- typedef enum
- {
- ATT_H_START = 0,
-
-
- Gap
- /**********************************************************************************************/
- GenericAccess_PS_H, //UUID: 2800, VALUE: uuid 1800
- GenericAccess_DeviceName_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- GenericAccess_DeviceName_DP_H, //UUID: 2A00, VALUE: device name
- GenericAccess_Appearance_CD_H, //UUID: 2803, VALUE: Prop: Read
- GenericAccess_Appearance_DP_H, //UUID: 2A01, VALUE: appearance
- CONN_PARAM_CD_H, //UUID: 2803, VALUE: Prop: Read
- CONN_PARAM_DP_H, //UUID: 2A04, VALUE: connParameter
-
-
- gatt
- /**********************************************************************************************/
- GenericAttribute_PS_H, //UUID: 2800, VALUE: uuid 1801
- GenericAttribute_ServiceChanged_CD_H, //UUID: 2803, VALUE: Prop: Indicate
- GenericAttribute_ServiceChanged_DP_H, //UUID: 2A05, VALUE: service change
- GenericAttribute_ServiceChanged_CCB_H, //UUID: 2902, VALUE: serviceChangeCCC
-
-
- device information
- /**********************************************************************************************/
- DeviceInformation_PS_H, //UUID: 2800, VALUE: uuid 180A
- DeviceInformation_pnpID_CD_H, //UUID: 2803, VALUE: Prop: Read
- DeviceInformation_pnpID_DP_H, //UUID: 2A50, VALUE: PnPtrs
-
-
- HID
- /**********************************************************************************************/
- HID_PS_H, //UUID: 2800, VALUE: uuid 1812
-
- //include
- //HID_INCLUDE_H, //UUID: 2802, VALUE: include
-
- //protocol
- HID_PROTOCOL_MODE_CD_H, //UUID: 2803, VALUE: Prop: read | write_without_rsp
- HID_PROTOCOL_MODE_DP_H, //UUID: 2A4E, VALUE: protocolMode
- #if 0
- //boot keyboard input report
- HID_BOOT_KB_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_BOOT_KB_REPORT_INPUT_DP_H, //UUID: 2A22, VALUE: bootKeyInReport
- HID_BOOT_KB_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: bootKeyInReportCCC
-
- //boot keyboard output report
- HID_BOOT_KB_REPORT_OUTPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | write| write_without_rsp
- HID_BOOT_KB_REPORT_OUTPUT_DP_H, //UUID: 2A32, VALUE: bootKeyOutReport
-
- //consume report in
- HID_CONSUME_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_CONSUME_REPORT_INPUT_DP_H, //UUID: 2A4D, VALUE: reportConsumerIn
- HID_CONSUME_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: reportConsumerInCCC
- HID_CONSUME_REPORT_INPUT_REF_H, //UUID: 2908 VALUE: REPORT_ID_CONSUMER, TYPE_INPUT
-
- //keyboard report in
- HID_NORMAL_KB_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_NORMAL_KB_REPORT_INPUT_DP_H, //UUID: 2A4D, VALUE: reportKeyIn
- HID_NORMAL_KB_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: reportKeyInInCCC
- HID_NORMAL_KB_REPORT_INPUT_REF_H, //UUID: 2908 VALUE: REPORT_ID_KEYBOARD, TYPE_INPUT
-
- //keyboard report out
- HID_NORMAL_KB_REPORT_OUTPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | write| write_without_rsp
- HID_NORMAL_KB_REPORT_OUTPUT_DP_H, //UUID: 2A4D, VALUE: reportKeyOut
- HID_NORMAL_KB_REPORT_OUTPUT_REF_H, //UUID: 2908 VALUE: REPORT_ID_KEYBOARD, TYPE_OUTPUT
- #endif
-
- #if 1
- HID_BOOT_MOUSE_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_BOOT_MOUSE_REPORT_INPUT_DP_H, //UUID: 2A22, VALUE: bootKeyInReport
- HID_BOOT_MOUSE_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: bootKeyInReportCCC
-
-
- HID_MOUSE_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_MOUSE_REPORT_INPUT_DP_H, //UUID: 2A4D, VALUE: reportConsumerIn
- HID_MOUSE_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: reportConsumerInCCC
- HID_MOUSE_REPORT_INPUT_REF_H, //UUID: 2908 VALUE: REPORT_ID_CONSUMER, TYPE_INPUT
- HID_USER_REPORT_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- HID_USER_REPORT_INPUT_DP_H, //UUID: 2A4D, VALUE: reportConsumerIn
- HID_USER_REPORT_INPUT_CCB_H, //UUID: 2902, VALUE: reportConsumerInCCC
- HID_USER_REPORT_INPUT_REF_H, //UUID: 2908 VALUE: REPORT_ID_CONSUMER, TYPE_INPUT
- #endif
-
- // report map
- HID_REPORT_MAP_CD_H, //UUID: 2803, VALUE: Prop: Read
- HID_REPORT_MAP_DP_H, //UUID: 2A4B, VALUE: reportKeyIn
- //HID_REPORT_MAP_EXT_REF_H, //UUID: 2907 VALUE: extService
-
- //hid information
- HID_INFORMATION_CD_H, //UUID: 2803, VALUE: Prop: read
- HID_INFORMATION_DP_H, //UUID: 2A4A VALUE: hidInformation
-
- //control point
- HID_CONTROL_POINT_CD_H, //UUID: 2803, VALUE: Prop: write_without_rsp
- HID_CONTROL_POINT_DP_H, //UUID: 2A4C VALUE: controlPoint
-
-
- battery service
- /**********************************************************************************************/
- BATT_PS_H, //UUID: 2800, VALUE: uuid 180f
- BATT_LEVEL_INPUT_CD_H, //UUID: 2803, VALUE: Prop: Read | Notify
- BATT_LEVEL_INPUT_DP_H, //UUID: 2A19 VALUE: batVal
- BATT_LEVEL_INPUT_CCB_H, //UUID: 2902, VALUE: batValCCC
-
-
- Ota
- /**********************************************************************************************/
- OTA_PS_H, //UUID: 2800, VALUE: telink ota service uuid
- OTA_CMD_OUT_CD_H, //UUID: 2803, VALUE: Prop: read | write_without_rsp | Notify
- OTA_CMD_OUT_DP_H, //UUID: telink ota uuid, VALUE: otaData
- OTA_CMD_INPUT_CCB_H, //UUID: 2902, VALUE: otaDataCCC
- OTA_CMD_OUT_DESC_H, //UUID: 2901, VALUE: otaName
-
-
- ATT_END_H,
-
- }ATT_HANDLE;
-
-
- /**
- * @brief Initialize the attribute table
- * @param[in] none
- * @return none
- */
- void my_att_init(void);
-
-
- #endif /* APP_ATT_H_ */
- const u8 tbl_advData[] = {
- #if 1
- #if 0
- 0x05, 0x09, 'V', 'H', 'I', 'D',
- 0x02, 0x01, 0x05, // BLE limited discoverable mode and BR/EDR not supported
- 0x03, 0x19, 0x80, 0x01, // 384, Generic Remote Control, Generic category
- 0x05, 0x02, 0x12, 0x18, 0x0F, 0x18, // incomplete list of service class UUIDs (0x1812, 0x180F)
- #endif
- 0x05, 0x09, 'V', 'H', 'I', 'D',
- 0x02, 0x01, 0x05, // BLE limited discoverable mode and BR/EDR not supported
- 0x03, 0x19, 0xC2, 0x03, // 384, Generic Remote Control, Generic category
- 0x05, 0x02, 0x12, 0x18, 0x0F, 0x18, // incomplete list of service class UUIDs (0x1812, 0x180F)
- #else
- //0x05, 0x09, 'V', 'H', 'I', 'D',
- 0x02, 0x01, 0x05, // BLE limited discoverable mode and BR/EDR not supported
- 0x03, 0x19, 0xc2, 0x03, // 384, Keyboard, Generic category,
- 0x03, 0x03, 0x12, 0x18, // incomplete list of service class UUIDs (0x1812-HID SERVICE, 180F-BATTERY)
- 0x06, 0xff, 0x06, 0x00, 0x03, 0x00, 0x80,
- 12, 0x09,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- #endif
-
- };
- /********************************************************************************************************
- * @file button.c
- *
- * @brief This is the source file for BLE SDK
- *
- * @author BLE GROUP
- * @date 06,2020
- *
- * @par Copyright (c) 2020, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Unless for usage inside a TELINK integrated circuit, redistributions
- * in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. Neither the name of TELINK, nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * 4. This software, with or without modification, must only be used with a
- * TELINK integrated circuit. All other usages are subject to written permission
- * from TELINK and different commercial license may apply.
- *
- * 5. Licensee shall be solely responsible for any claim to the extent arising out of or
- * relating to such deletion(s), modification(s) or alteration(s).
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *******************************************************************************************************/
- #include "tl_common.h"
- #include "drivers.h"
- #include "stack/ble/ble.h"
- #include "application/usbstd/usbkeycode.h"
-
- #include "app.h"
- #include "app_att.h"
- #include "gpio.h"
- #include "mat_log.h"
-
- #include "tl_common.h"
- #include "drivers.h"
- #include "stack/ble/ble.h"
- #include "application/usbstd/usbkeycode.h"
- #include "app.h"
- #include "app_att.h"
-
- #define KEY2 GPIO_PB2
- #define KEY3 GPIO_PB3
- #define KEY4 GPIO_PB4
- #define KEY5 GPIO_PB5
-
- #define LED1 GPIO_PD2
- #define LED2 GPIO_PD3
- #define LED3 GPIO_PD4
- #define LED4 GPIO_PD5
-
- typedef enum
- {
- K1,
- K2,
- K3,
- K4
- }key_t;
-
- typedef struct
- {
- u8 btn;
-
- s16 x;
- s16 y;
-
-
- s8 wheel;
- } mouse_data_t;
-
-
-
-
- void led_init(void)
- {
- gpio_set_func(LED1, AS_GPIO);
- gpio_set_output_en(LED1, 1);
- gpio_write(LED1,0);
-
- gpio_set_func(LED2, AS_GPIO);
- gpio_set_output_en(LED2, 1);
- gpio_write(LED2,0);
-
- gpio_set_func(LED3, AS_GPIO);
- gpio_set_output_en(LED3, 1);
- gpio_write(LED3,0);
-
- gpio_set_func(LED4, AS_GPIO);
- gpio_set_output_en(LED4, 1);
- gpio_write(LED4,0);
- }
- void key_init(void)
- {
- gpio_set_func(KEY2, AS_GPIO);
- gpio_set_input_en(KEY2, ENABLE);
- gpio_setup_up_down_resistor(KEY2, PM_PIN_PULLUP_10K);
-
-
- gpio_set_func(KEY3, AS_GPIO);
- gpio_set_input_en(KEY3, ENABLE);
- gpio_setup_up_down_resistor(KEY3, PM_PIN_PULLUP_10K);
-
-
- gpio_set_func(KEY4, AS_GPIO);
- gpio_set_input_en(KEY4, ENABLE);
- gpio_setup_up_down_resistor(KEY4, PM_PIN_PULLUP_10K);
-
-
- #if 1
- gpio_set_func(KEY5, AS_GPIO);
- gpio_set_input_en(KEY5, ENABLE);
- gpio_setup_up_down_resistor(KEY5, PM_PIN_PULLUP_10K);
-
- #endif
- }
-
- u8 key(GPIO_PinTypeDef key)
- {
- u8 *states;
- u8 ret = 0;
- static u8 k2_states = 0;
- static u8 k3_states = 0;
- static u8 k4_states = 0;
- static u8 k5_states = 0;
-
- if(key == KEY2)
- {
- states = &k2_states;
- }
- if(key == KEY3)
- {
- states = &k3_states;
- }
- if(key == KEY4)
- {
- states = &k4_states;
- }
- if(key == KEY5)
- {
- states = &k5_states;
- }
-
- switch(*states)
- {
- case 0:
- if(gpio_read(key) == 0)
- {
- *states = 1;
- }
- break;
- case 1:
- if(gpio_read(key) == 0)
- {
- *states = 2;
- ret = 1;
- }
- else
- {
- *states = 0;
- }
- break;
-
- case 2:
- if(gpio_read(key) == 0)
- {
- *states = 2;
- ret = 0;
- }
- else
- {
- *states = 0;
- }
- break;
- }
- //LOG_INFO("ret = %d\r\n", ret);
- return ret;
- }
- int key_event(void)
- {
-
- mouse_data_t buf = {0};
- if(key(KEY2) == 1)
- {
- LOG_INFO("key2 press\r\n");
- buf.btn = 1;
- //LOG_INFO("ble state = %d\r\n",blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, 6));
- LOG_INFO("ble state = %d\r\n",bls_att_pushNotifyData (HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, sizeof(mouse_data_t)));
- //bls_ll_terminateConnection(HCI_ERR_REMOTE_USER_TERM_CONN);
-
- }
- if(key(KEY3) == 1)
- {
- LOG_INFO("key3 press\r\n");
- buf.x = 10;
- //LOG_INFO("ble state = %d\r\n",blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, 6));
- LOG_INFO("ble state = %d\r\n",bls_att_pushNotifyData (HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, sizeof(mouse_data_t)));
- //bls_ll_terminateConnection(HCI_ERR_REMOTE_USER_TERM_CONN);
- }
- if(key(KEY4) == 1)
- {
- LOG_INFO("key4 press\r\n");
- buf.y = 20;
- //LOG_INFO("ble state = %d\r\n",blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, 6));
- LOG_INFO("ble state = %d\r\n",bls_att_pushNotifyData (HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, sizeof(mouse_data_t)));
- //bls_ll_terminateConnection(HCI_ERR_REMOTE_USER_TERM_CONN);
- }
- #if 1
- if(key(KEY5) == 1)
- {
- LOG_INFO("key5 press\r\n");
- buf.wheel = 4;
- //LOG_INFO("ble state = %d\r\n",blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, 6));
- LOG_INFO("ble state = %d\r\n",bls_att_pushNotifyData (HID_MOUSE_REPORT_INPUT_DP_H, &buf.btn, sizeof(mouse_data_t)));
- //bls_ll_terminateConnection(HCI_ERR_REMOTE_USER_TERM_CONN);
- }
- #endif
-
- #if 0
- temp++;
- if(temp > 100)
- {
- LOG_INFO("每1s打印一次\r\n");
- temp = 0;
- }
- #endif
-
- return 0;
- }
- int led_event(void)
- {
- #if 1
- static u8 temp = 0;
- temp++;
- if(temp % 4 == 1)
- {
- gpio_toggle(LED1);
- }
- if(temp % 4 == 2)
- {
- gpio_toggle(LED2);
- }
- if(temp % 4 == 3)
- {
- gpio_toggle(LED3);
- }
- if(temp % 4 == 4)
- {
- gpio_toggle(LED4);
- temp = 0;
- }
- #endif
- }
-
-
- #if (UI_BUTTON_ENABLE)
-
-
-
- /
- #define MAX_BTN_SIZE 2
- #define BTN_VALID_LEVEL 0
-
- #define USER_BTN_1 0x01
- #define USER_BTN_2 0x02
-
- _attribute_data_retention_ u32 ctrl_btn[] = {SW1_GPIO, SW2_GPIO};
- _attribute_data_retention_ u8 btn_map[MAX_BTN_SIZE] = {USER_BTN_1, USER_BTN_2};
-
-
-
- _attribute_data_retention_ int button_not_released = 0;
-
- _attribute_data_retention_ static int button0_press_flag;
- _attribute_data_retention_ static u32 button0_press_tick;
- _attribute_data_retention_ static int button1_press_flag;
- _attribute_data_retention_ static u32 button1_press_tick;
-
- _attribute_data_retention_ static int consumer_report = 0;
-
- typedef struct{
- u8 cnt; //count button num
- u8 btn_press;
- u8 keycode[MAX_BTN_SIZE]; //6 btn
- }vc_data_t;
- _attribute_data_retention_ vc_data_t vc_event;
-
- typedef struct{
- u8 btn_history[4]; //vc history btn save
- u8 btn_filter_last;
- u8 btn_not_release;
- u8 btn_new; //new btn flag
- }btn_status_t;
- _attribute_data_retention_ btn_status_t btn_status;
-
-
- /**
- * @brief the function server to debounce the key
- * @param[in] btn_v - the pointer ponit to the button press value
- * @return 1 - key change press effect
- * 0 - key change press no effect
- */
- u8 btn_debounce_filter(u8 *btn_v)
- {
- u8 change = 0;
-
- for(int i=3; i>0; i--){
- btn_status.btn_history[i] = btn_status.btn_history[i-1];
- }
- btn_status.btn_history[0] = *btn_v;
-
- if( btn_status.btn_history[0] == btn_status.btn_history[1] && btn_status.btn_history[1] == btn_status.btn_history[2] && \
- btn_status.btn_history[0] != btn_status.btn_filter_last ){
- change = 1;
-
- btn_status.btn_filter_last = btn_status.btn_history[0];
- }
-
- return change;
- }
-
- /**
- * @brief the function detect wheather or not the key press/release
- * @param[in] read_key - enable or diable store key value in buffer
- * @return 1 - key change press or release
- * 0 - key no change
- */
- u8 vc_detect_button(int read_key)
- {
- u8 btn_changed, i;
- memset(&vc_event,0,sizeof(vc_data_t)); //clear vc_event
- //vc_event.btn_press = 0;
-
- for(i=0; i
- if(BTN_VALID_LEVEL != !gpio_read(ctrl_btn[i])){
- vc_event.btn_press |= BIT(i);
- }
- }
-
- btn_changed = btn_debounce_filter(&vc_event.btn_press);
-
-
- if(btn_changed && read_key){
- for(i=0; i
- if(vc_event.btn_press & BIT(i)){
- vc_event.keycode[vc_event.cnt++] = btn_map[i];
- }
- }
-
- return 1;
- }
-
- return 0;
- }
-
- /**
- * @brief this function is used to detect if button pressed or released.
- * @param[in] e - event type when this function is triggered by LinkLayer event
- * @param[in] p - event callback data pointer for when this function is triggered by LinkLayer event
- * @param[in] n - event callback data length when this function is triggered by LinkLayer event
- * @return none
- */
- void proc_button (u8 e, u8 *p, int n)
- {
- int det_key = vc_detect_button (1);
-
- if (det_key) //key change: press or release
- {
- extern u32 latest_user_event_tick;
- latest_user_event_tick = clock_time();
-
- u8 key0 = vc_event.keycode[0];
- // u8 key1 = vc_event.keycode[1];
-
- button_not_released = 1;
-
- if(vc_event.cnt == 2) //two key press
- {
-
- }
- else if(vc_event.cnt == 1) //one key press
- {
- if(key0 == USER_BTN_1)
- {
- button0_press_flag = 1;
- button0_press_tick = clock_time();
-
- //send "Vol+"
- u16 consumer_key = MKEY_VOL_UP;
- blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_CONSUME_REPORT_INPUT_DP_H, (u8 *)&consumer_key, 2);
- consumer_report = 1;
-
- }
- else if(key0 == USER_BTN_2)
- {
- button1_press_flag = 1;
- button1_press_tick = clock_time();
-
- //send "Vol-"
- u16 consumer_key = MKEY_VOL_DN;
- blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_CONSUME_REPORT_INPUT_DP_H, (u8 *)&consumer_key, 2);
- consumer_report = 1;
- }
- }
- else{ //release
- button_not_released = 0;
-
- button0_press_flag = 0;
- button1_press_flag = 0;
-
- //send release Vol+/Vol-
- if(consumer_report){
- consumer_report = 0;
- u16 consumer_key = 0;
- blc_gatt_pushHandleValueNotify (BLS_CONN_HANDLE, HID_CONSUME_REPORT_INPUT_DP_H, (u8 *)&consumer_key, 2);
- }
- }
-
- }
-
-
- }
- #endif //end of UI_BUTTON_ENABLE
6. main.c
- /********************************************************************************************************
- * @file main.c
- *
- * @brief This is the source file for BLE SDK
- *
- * @author BLE GROUP
- * @date 06,2020
- *
- * @par Copyright (c) 2020, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Unless for usage inside a TELINK integrated circuit, redistributions
- * in binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. Neither the name of TELINK, nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * 4. This software, with or without modification, must only be used with a
- * TELINK integrated circuit. All other usages are subject to written permission
- * from TELINK and different commercial license may apply.
- *
- * 5. Licensee shall be solely responsible for any claim to the extent arising out of or
- * relating to such deletion(s), modification(s) or alteration(s).
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *******************************************************************************************************/
- #include "tl_common.h"
- #include "drivers.h"
- #include "stack/ble/ble.h"
- #include "app.h"
-
- #include "mat_log.h"
- //#include "blt_soft_timer.h"
- /**
- * @brief IRQ handler
- * @param none.
- * @return none.
- */
- _attribute_ram_code_ void irq_handler(void)
- {
-
- irq_blt_sdk_handler ();
-
- }
-
- void MG_GPIO_Init(void)
- {
- gpio_set_func(GPIO_PD2,AS_GPIO);
- gpio_set_output_en(GPIO_PD2,1);
- gpio_write(GPIO_PD2,0);
- gpio_set_func(GPIO_PD3,AS_GPIO);
- gpio_set_output_en(GPIO_PD3,1);
- gpio_write(GPIO_PD3,0);
- gpio_set_func(GPIO_PD4,AS_GPIO);
- gpio_set_output_en(GPIO_PD4,1);
- gpio_write(GPIO_PD4,0);
- }
- /**
- * @brief This is main function
- * @param[in] none
- * @return none
- */
- _attribute_ram_code_ int main (void) //must run in ramcode
- {
-
- DBG_CHN0_LOW; //debug
-
- blc_pm_select_internal_32k_crystal();
-
- #if(MCU_CORE_TYPE == MCU_CORE_825x)
- cpu_wakeup_init();
- #elif(MCU_CORE_TYPE == MCU_CORE_827x)
- cpu_wakeup_init(LDO_MODE,EXTERNAL_XTAL_24M);
- #endif
-
- int deepRetWakeUp = pm_is_MCU_deepRetentionWakeup(); //MCU deep retention wakeUp
-
- rf_drv_init(RF_MODE_BLE_1M);
-
- gpio_init( !deepRetWakeUp ); //analog resistance will keep available in deepSleep mode, so no need initialize again
-
- clock_init(SYS_CLK_TYPE);
-
- if(!deepRetWakeUp){//read flash size
- blc_readFlashSize_autoConfigCustomFlashSector();
- }
-
- blc_app_loadCustomizedParameters(); //load customized freq_offset cap value
-
- if( deepRetWakeUp ){
- user_init_deepRetn ();
- }
- else{
- user_init_normal ();
- }
-
- key_init();
- led_init();
-
-
-
- blt_soft_timer_add(key_event,20000);
- blt_soft_timer_add(led_event,500000);
- irq_enable();
- while (1) {
- #if (MODULE_WATCHDOG_ENABLE)
- wd_clear(); //clear watch dog
- #endif
- main_loop ();
- blt_soft_timer_process(MAINLOOP_ENTRY);//增加周期处理
-
- }
- }
-
7. 这里添加一个头文件
- /*
- * mat_log.h
- *
- * Created on: 2022-8-16
- * Author: YQ19755
- */
-
- #ifndef MAT_LOG_H
- #define MAT_LOG_H
- #include "tl_common.h"
-
- #define DEBUG 1
- #define ERR 1
- #define INFO 1
-
- #if INFO
- #define LOG_INFO(str, ...) printf("[INFO]:"str "\r\n", ##__VA_ARGS__)
- #else
- #define LOG_INFO(str, ...)
- #endif
-
- #if ERR
- #define LOG_ERR(str, ...) printf("[ERR]:"str "\r\n", ##__VA_ARGS__)
- #else
- #define LOG_ERR(str, ...)
- #endif
-
- #if DEBUG
- #define LOG_DEBUG(str, ...) printf("[DEBUG]:"str "\r\n", ##__VA_ARGS__)
- #else
- #define LOG_DEBUG(str, ...)
- #endif
-
- enum
- {
- DISABLE = 0,
- ENABLE = 1
- };
-
-
- //临时借用这个头文件来测试按键
- void key_init(void);
- int key_event(void);
- int led_event(void);
- void led_init(void);
-
- #endif
-
相关阅读:
KubeSphere 社区双周报|2024.02.29-03.14
java计算机毕业设计停车场管理系统源程序+mysql+系统+lw文档+远程调试
20-SpringCloudAlibaba-2
C#设计模式---工厂方法模式
内存管理【C++】
线性表的顺序表示和实现(Java)
用C++元编程实现任意函数签名的回调
Day53【动态规划】1143.最长公共子序列、1035.不相交的线、53.最大子序和
Docker搭建nginx
2022年山东省赛总结
-
原文地址:https://blog.csdn.net/qq_38591801/article/details/126645990