Fork for the GitHub

Committer:
DiegoOstuni
Date:
Thu Nov 14 10:34:11 2019 +0000
Revision:
0:de13951f30f6
Add files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:de13951f30f6 1 /**
DiegoOstuni 0:de13951f30f6 2 ******************************************************************************
DiegoOstuni 0:de13951f30f6 3 * @file lib_NDEF_MyApp.c
DiegoOstuni 0:de13951f30f6 4 * @author MMY Application Team
DiegoOstuni 0:de13951f30f6 5 * @version $Revision: 2762 $
DiegoOstuni 0:de13951f30f6 6 * @date $Date: 2016-08-10 16:40:40 +0200 (Wed, 10 Aug 2016) $
DiegoOstuni 0:de13951f30f6 7 * @brief This file help to manage the NDEF file of a private application.
DiegoOstuni 0:de13951f30f6 8 ******************************************************************************
DiegoOstuni 0:de13951f30f6 9 * @attention
DiegoOstuni 0:de13951f30f6 10 *
DiegoOstuni 0:de13951f30f6 11 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
DiegoOstuni 0:de13951f30f6 12 *
DiegoOstuni 0:de13951f30f6 13 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:de13951f30f6 14 * You may not use this file except in compliance with the License.
DiegoOstuni 0:de13951f30f6 15 * You may obtain a copy of the License at:
DiegoOstuni 0:de13951f30f6 16 *
DiegoOstuni 0:de13951f30f6 17 * http://www.st.com/myliberty
DiegoOstuni 0:de13951f30f6 18 *
DiegoOstuni 0:de13951f30f6 19 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:de13951f30f6 20 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:de13951f30f6 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:de13951f30f6 22 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:de13951f30f6 23 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:de13951f30f6 24 * See the License for the specific language governing permissions and
DiegoOstuni 0:de13951f30f6 25 * limitations under the License.
DiegoOstuni 0:de13951f30f6 26 *
DiegoOstuni 0:de13951f30f6 27 ******************************************************************************
DiegoOstuni 0:de13951f30f6 28 */
DiegoOstuni 0:de13951f30f6 29
DiegoOstuni 0:de13951f30f6 30 /* Includes ------------------------------------------------------------------*/
DiegoOstuni 0:de13951f30f6 31 #include "lib_NDEF_MyApp.h"
DiegoOstuni 0:de13951f30f6 32
DiegoOstuni 0:de13951f30f6 33
DiegoOstuni 0:de13951f30f6 34 /** @addtogroup NFC_libraries
DiegoOstuni 0:de13951f30f6 35 * @{
DiegoOstuni 0:de13951f30f6 36 * @brief <b>This is the library used to manage the content of the TAG (data)
DiegoOstuni 0:de13951f30f6 37 * But also the specific feature of the tag, for instance
DiegoOstuni 0:de13951f30f6 38 * password, gpio... </b>
DiegoOstuni 0:de13951f30f6 39 */
DiegoOstuni 0:de13951f30f6 40
DiegoOstuni 0:de13951f30f6 41
DiegoOstuni 0:de13951f30f6 42 /** @addtogroup libNFC_FORUM
DiegoOstuni 0:de13951f30f6 43 * @{
DiegoOstuni 0:de13951f30f6 44 * @brief This part of the library manage data which follow NFC forum organisation.
DiegoOstuni 0:de13951f30f6 45 */
DiegoOstuni 0:de13951f30f6 46
DiegoOstuni 0:de13951f30f6 47 /**
DiegoOstuni 0:de13951f30f6 48 * @brief This buffer contains the data send/received by TAG
DiegoOstuni 0:de13951f30f6 49 */
DiegoOstuni 0:de13951f30f6 50 extern uint8_t NDEF_Buffer [];
DiegoOstuni 0:de13951f30f6 51
DiegoOstuni 0:de13951f30f6 52 /** @defgroup libMyApp_Private_Functions
DiegoOstuni 0:de13951f30f6 53 * @{
DiegoOstuni 0:de13951f30f6 54 */
DiegoOstuni 0:de13951f30f6 55
DiegoOstuni 0:de13951f30f6 56 static void NDEF_Extract_M24SRDiscoveryApp_Input( sRecordInfo_t *pRecordStruct, sMyAppInfo *pMyAppStruct );
DiegoOstuni 0:de13951f30f6 57
DiegoOstuni 0:de13951f30f6 58 /**
DiegoOstuni 0:de13951f30f6 59 * @brief This function read the NDEF file and store application data in a structure.
DiegoOstuni 0:de13951f30f6 60 * @param pRecordStruct : Pointer on the record structure.
DiegoOstuni 0:de13951f30f6 61 * @param pMyAppStruct : pointer on the structure to fill.
DiegoOstuni 0:de13951f30f6 62 */
DiegoOstuni 0:de13951f30f6 63 static void NDEF_Extract_M24SRDiscoveryApp_Input( sRecordInfo_t *pRecordStruct, sMyAppInfo *pMyAppStruct )
DiegoOstuni 0:de13951f30f6 64 {
DiegoOstuni 0:de13951f30f6 65 uint8_t* pPayload;
DiegoOstuni 0:de13951f30f6 66 uint8_t* pLook4Word;
DiegoOstuni 0:de13951f30f6 67 uint16_t BackGroundColor, FontColor;
DiegoOstuni 0:de13951f30f6 68 uint8_t i;
DiegoOstuni 0:de13951f30f6 69
DiegoOstuni 0:de13951f30f6 70 /* Read record header */
DiegoOstuni 0:de13951f30f6 71 pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd);
DiegoOstuni 0:de13951f30f6 72
DiegoOstuni 0:de13951f30f6 73 /* initialize struct in case not matching found */
DiegoOstuni 0:de13951f30f6 74 for( i = 0; i < 8; i++ )
DiegoOstuni 0:de13951f30f6 75 {
DiegoOstuni 0:de13951f30f6 76 /* Set the Back Color */
DiegoOstuni 0:de13951f30f6 77 pMyAppStruct->LineX[i].BackGroundColor = 0xFFFF;
DiegoOstuni 0:de13951f30f6 78 /* Set the Text Color */
DiegoOstuni 0:de13951f30f6 79 pMyAppStruct->LineX[i].FontColor = 0x0000;
DiegoOstuni 0:de13951f30f6 80 /* Set the line number */
DiegoOstuni 0:de13951f30f6 81 pMyAppStruct->LineX[i].LineNb = i + 1;
DiegoOstuni 0:de13951f30f6 82 /* Set the line content */
DiegoOstuni 0:de13951f30f6 83 memcpy( pMyAppStruct->LineX[i].String, " ", 20 );
DiegoOstuni 0:de13951f30f6 84 }
DiegoOstuni 0:de13951f30f6 85
DiegoOstuni 0:de13951f30f6 86 pLook4Word = pPayload;
DiegoOstuni 0:de13951f30f6 87
DiegoOstuni 0:de13951f30f6 88 for( i = 0; i < 4; i++ )
DiegoOstuni 0:de13951f30f6 89 {
DiegoOstuni 0:de13951f30f6 90 pMyAppStruct->LedBlinkConf.LedConf[i] = *pLook4Word;
DiegoOstuni 0:de13951f30f6 91 pLook4Word++;
DiegoOstuni 0:de13951f30f6 92 }
DiegoOstuni 0:de13951f30f6 93 pMyAppStruct->LedBlinkConf.Speed = *pLook4Word;
DiegoOstuni 0:de13951f30f6 94 pLook4Word++;
DiegoOstuni 0:de13951f30f6 95
DiegoOstuni 0:de13951f30f6 96 for( i = 0; i < 8; i++ )
DiegoOstuni 0:de13951f30f6 97 {
DiegoOstuni 0:de13951f30f6 98 /* Set the line number */
DiegoOstuni 0:de13951f30f6 99 pMyAppStruct->LineX[i].LineNb = *pLook4Word;
DiegoOstuni 0:de13951f30f6 100 pLook4Word++;
DiegoOstuni 0:de13951f30f6 101 /* Set the Back Color */
DiegoOstuni 0:de13951f30f6 102 BackGroundColor = (uint16_t)(*pLook4Word << 8);
DiegoOstuni 0:de13951f30f6 103 BackGroundColor = BackGroundColor | (uint16_t)(*++pLook4Word );
DiegoOstuni 0:de13951f30f6 104 pMyAppStruct->LineX[i].BackGroundColor = BackGroundColor;
DiegoOstuni 0:de13951f30f6 105 pLook4Word++;
DiegoOstuni 0:de13951f30f6 106 /* Set the Text Color */
DiegoOstuni 0:de13951f30f6 107 FontColor = (uint16_t)(*pLook4Word << 8);
DiegoOstuni 0:de13951f30f6 108 FontColor = FontColor | (uint16_t)(*++pLook4Word);
DiegoOstuni 0:de13951f30f6 109 pMyAppStruct->LineX[i].FontColor = FontColor;
DiegoOstuni 0:de13951f30f6 110 pLook4Word++;
DiegoOstuni 0:de13951f30f6 111 /* Set the line content */
DiegoOstuni 0:de13951f30f6 112 memcpy( pMyAppStruct->LineX[i].String, (char*)pLook4Word, 20 );
DiegoOstuni 0:de13951f30f6 113 pLook4Word += 20;
DiegoOstuni 0:de13951f30f6 114 }
DiegoOstuni 0:de13951f30f6 115
DiegoOstuni 0:de13951f30f6 116 }
DiegoOstuni 0:de13951f30f6 117
DiegoOstuni 0:de13951f30f6 118 /**
DiegoOstuni 0:de13951f30f6 119 * @}
DiegoOstuni 0:de13951f30f6 120 */
DiegoOstuni 0:de13951f30f6 121
DiegoOstuni 0:de13951f30f6 122 /** @defgroup libMyApp_Public_Functions
DiegoOstuni 0:de13951f30f6 123 * @{
DiegoOstuni 0:de13951f30f6 124 * @brief This file is used to manage proprietary NDEF (stored or loaded in tag)
DiegoOstuni 0:de13951f30f6 125 */
DiegoOstuni 0:de13951f30f6 126
DiegoOstuni 0:de13951f30f6 127 /**
DiegoOstuni 0:de13951f30f6 128 * @brief This function read NDEF and retrieve Application information if any.
DiegoOstuni 0:de13951f30f6 129 * @param pRecordStruct : Pointer on the record structure.
DiegoOstuni 0:de13951f30f6 130 * @param pMyAppStruct : pointer on the structure to fill.
DiegoOstuni 0:de13951f30f6 131 * @retval NDEF_OK : NDEF file data read in the tag.
DiegoOstuni 0:de13951f30f6 132 * @retval NDEF_ERROR : not able to read NDEF in tag.
DiegoOstuni 0:de13951f30f6 133 */
DiegoOstuni 0:de13951f30f6 134 uint16_t NDEF_ReadMyApp( sRecordInfo_t *pRecordStruct, sMyAppInfo *pMyAppStruct )
DiegoOstuni 0:de13951f30f6 135 {
DiegoOstuni 0:de13951f30f6 136 uint16_t status = NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 137
DiegoOstuni 0:de13951f30f6 138 if( pRecordStruct->NDEF_Type == M24SR_DISCOVERY_APP_TYPE )
DiegoOstuni 0:de13951f30f6 139 {
DiegoOstuni 0:de13951f30f6 140 NDEF_Extract_M24SRDiscoveryApp_Input( pRecordStruct, pMyAppStruct );
DiegoOstuni 0:de13951f30f6 141 status = NDEF_OK;
DiegoOstuni 0:de13951f30f6 142 }
DiegoOstuni 0:de13951f30f6 143 else
DiegoOstuni 0:de13951f30f6 144 {
DiegoOstuni 0:de13951f30f6 145 status = NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 146 }
DiegoOstuni 0:de13951f30f6 147
DiegoOstuni 0:de13951f30f6 148 return status;
DiegoOstuni 0:de13951f30f6 149 }
DiegoOstuni 0:de13951f30f6 150
DiegoOstuni 0:de13951f30f6 151 /**
DiegoOstuni 0:de13951f30f6 152 * @brief This function write the NDEF file with the Application data given in the structure.
DiegoOstuni 0:de13951f30f6 153 * @brief Only used for debug purpose in this firmware version.
DiegoOstuni 0:de13951f30f6 154 * @param pMyAppStruct : pointer on structure that contain the application information.
DiegoOstuni 0:de13951f30f6 155 * @retval NDEF_OK : NDEF file data written in the tag.
DiegoOstuni 0:de13951f30f6 156 * @retval NDEF_ERROR : not able to store NDEF in tag.
DiegoOstuni 0:de13951f30f6 157 * @retval NDEF_ERROR_MEMORY_INTERNAL : Cannot write to tag.
DiegoOstuni 0:de13951f30f6 158 * @retval NDEF_ERROR_NOT_FORMATED : CCFile data not supported or not present.
DiegoOstuni 0:de13951f30f6 159 * @retval NDEF_ERROR_MEMORY_TAG : Size not compatible with memory.
DiegoOstuni 0:de13951f30f6 160 * @retval NDEF_ERROR_LOCKED : Tag locked, cannot be write.
DiegoOstuni 0:de13951f30f6 161 */
DiegoOstuni 0:de13951f30f6 162 uint16_t NDEF_WriteMyApp( sMyAppInfo *pMyAppStruct, I2C * mi2cChannel )
DiegoOstuni 0:de13951f30f6 163 {
DiegoOstuni 0:de13951f30f6 164 uint16_t status = NDEF_ERROR;
DiegoOstuni 0:de13951f30f6 165 uint16_t DataSize;
DiegoOstuni 0:de13951f30f6 166 uint32_t PayloadSize;
DiegoOstuni 0:de13951f30f6 167 uint8_t i;
DiegoOstuni 0:de13951f30f6 168 uint8_t* pPayload;
DiegoOstuni 0:de13951f30f6 169
DiegoOstuni 0:de13951f30f6 170
DiegoOstuni 0:de13951f30f6 171 /* External Type Record Header */
DiegoOstuni 0:de13951f30f6 172 /************************************/
DiegoOstuni 0:de13951f30f6 173 /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */
DiegoOstuni 0:de13951f30f6 174 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 175 /* MB ME CF SR IL TNF */ /* <---- IL=0, CF=0 and SR=1 TNF=4 NFC Forum external type*/
DiegoOstuni 0:de13951f30f6 176 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 177 /* TYPE LENGTH */
DiegoOstuni 0:de13951f30f6 178 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 179 /* PAYLOAD LENGTH 3 */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 180 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 181 /* PAYLOAD LENGTH 2 */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 182 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 183 /* PAYLOAD LENGTH 1 */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 184 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 185 /* PAYLOAD LENGTH 0 */ /* The payload will always be 5 + 25*8=205 bytes for this application */
DiegoOstuni 0:de13951f30f6 186 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 187 /* ID LENGTH */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 188 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 189 /* TYPE */ /* st.com:m24sr_discovery_democtrl */
DiegoOstuni 0:de13951f30f6 190 /*----------------------------------*/
DiegoOstuni 0:de13951f30f6 191 /* ID */ /* <---- Not Used */
DiegoOstuni 0:de13951f30f6 192 /************************************/
DiegoOstuni 0:de13951f30f6 193
DiegoOstuni 0:de13951f30f6 194
DiegoOstuni 0:de13951f30f6 195 /* fill URI record header */
DiegoOstuni 0:de13951f30f6 196 NDEF_Buffer[0] = 0xD4; /* Record Flag */
DiegoOstuni 0:de13951f30f6 197 NDEF_Buffer[1] = M24SR_DISCOVERY_APP_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 198 NDEF_Buffer[2] = 0x00; /* Will be filled at the end when payload size is known */
DiegoOstuni 0:de13951f30f6 199
DiegoOstuni 0:de13951f30f6 200 memcpy( &NDEF_Buffer[3], M24SR_DISCOVERY_APP_STRING, M24SR_DISCOVERY_APP_STRING_LENGTH );
DiegoOstuni 0:de13951f30f6 201
DiegoOstuni 0:de13951f30f6 202 pPayload = &NDEF_Buffer[ 3 + M24SR_DISCOVERY_APP_STRING_LENGTH];
DiegoOstuni 0:de13951f30f6 203 PayloadSize = 0;
DiegoOstuni 0:de13951f30f6 204
DiegoOstuni 0:de13951f30f6 205 /**************************************************************/
DiegoOstuni 0:de13951f30f6 206 /* BLINK CONFIG data */
DiegoOstuni 0:de13951f30f6 207
DiegoOstuni 0:de13951f30f6 208 /* led 1 blinking */
DiegoOstuni 0:de13951f30f6 209 *pPayload = 0x03;
DiegoOstuni 0:de13951f30f6 210 pPayload++;
DiegoOstuni 0:de13951f30f6 211 /* led 2 blinking */
DiegoOstuni 0:de13951f30f6 212 *pPayload = 0x02;
DiegoOstuni 0:de13951f30f6 213 pPayload++;
DiegoOstuni 0:de13951f30f6 214 /* led 3 blinking */
DiegoOstuni 0:de13951f30f6 215 *pPayload = 0x02;
DiegoOstuni 0:de13951f30f6 216 pPayload++;
DiegoOstuni 0:de13951f30f6 217 /* led 4 blinking */
DiegoOstuni 0:de13951f30f6 218 *pPayload = 0x03;
DiegoOstuni 0:de13951f30f6 219 pPayload++;
DiegoOstuni 0:de13951f30f6 220 /* speed */
DiegoOstuni 0:de13951f30f6 221 *pPayload = 0x03;
DiegoOstuni 0:de13951f30f6 222 pPayload++;
DiegoOstuni 0:de13951f30f6 223
DiegoOstuni 0:de13951f30f6 224 PayloadSize += 5;
DiegoOstuni 0:de13951f30f6 225
DiegoOstuni 0:de13951f30f6 226 /**************************************************************/
DiegoOstuni 0:de13951f30f6 227
DiegoOstuni 0:de13951f30f6 228 /**************************************************************/
DiegoOstuni 0:de13951f30f6 229 /* SCREEN config data */
DiegoOstuni 0:de13951f30f6 230 for( i = 0; i < 8; i++ )
DiegoOstuni 0:de13951f30f6 231 {
DiegoOstuni 0:de13951f30f6 232 /* Line number */
DiegoOstuni 0:de13951f30f6 233 *pPayload = (uint8_t)(i + 1);
DiegoOstuni 0:de13951f30f6 234 pPayload++;
DiegoOstuni 0:de13951f30f6 235 /* Background color */
DiegoOstuni 0:de13951f30f6 236 *pPayload = 0xFF - (0xFF/i);
DiegoOstuni 0:de13951f30f6 237 pPayload++;
DiegoOstuni 0:de13951f30f6 238 *pPayload = 0xFF - (0xFF/i);
DiegoOstuni 0:de13951f30f6 239 pPayload++;
DiegoOstuni 0:de13951f30f6 240 /* Font Color */
DiegoOstuni 0:de13951f30f6 241 *pPayload = 0xFF/i;
DiegoOstuni 0:de13951f30f6 242 pPayload++;
DiegoOstuni 0:de13951f30f6 243 *pPayload = 0xFF/i;
DiegoOstuni 0:de13951f30f6 244 pPayload++;
DiegoOstuni 0:de13951f30f6 245 /* String */
DiegoOstuni 0:de13951f30f6 246 memcpy( pPayload, "ABCDEFGHIJKLMNOPQRST", 20 );
DiegoOstuni 0:de13951f30f6 247 pPayload += 20;
DiegoOstuni 0:de13951f30f6 248
DiegoOstuni 0:de13951f30f6 249 PayloadSize += 25;
DiegoOstuni 0:de13951f30f6 250
DiegoOstuni 0:de13951f30f6 251 }
DiegoOstuni 0:de13951f30f6 252
DiegoOstuni 0:de13951f30f6 253 NDEF_Buffer[2] = PayloadSize & 0x000000FF;
DiegoOstuni 0:de13951f30f6 254
DiegoOstuni 0:de13951f30f6 255 DataSize = PayloadSize + 5 + M24SR_DISCOVERY_APP_STRING_LENGTH;
DiegoOstuni 0:de13951f30f6 256
DiegoOstuni 0:de13951f30f6 257 /* Write NDEF */
DiegoOstuni 0:de13951f30f6 258 status = NfcTag_WriteNDEF( DataSize, NDEF_Buffer, mi2cChannel );
DiegoOstuni 0:de13951f30f6 259
DiegoOstuni 0:de13951f30f6 260
DiegoOstuni 0:de13951f30f6 261 return status;
DiegoOstuni 0:de13951f30f6 262 }
DiegoOstuni 0:de13951f30f6 263
DiegoOstuni 0:de13951f30f6 264
DiegoOstuni 0:de13951f30f6 265 /**
DiegoOstuni 0:de13951f30f6 266 * @}
DiegoOstuni 0:de13951f30f6 267 */
DiegoOstuni 0:de13951f30f6 268
DiegoOstuni 0:de13951f30f6 269 /**
DiegoOstuni 0:de13951f30f6 270 * @}
DiegoOstuni 0:de13951f30f6 271 */
DiegoOstuni 0:de13951f30f6 272
DiegoOstuni 0:de13951f30f6 273 /**
DiegoOstuni 0:de13951f30f6 274 * @}
DiegoOstuni 0:de13951f30f6 275 */
DiegoOstuni 0:de13951f30f6 276
DiegoOstuni 0:de13951f30f6 277 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/