st25r3916_com.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /******************************************************************************
  2. * \attention
  3. *
  4. * <h2><center>&copy; COPYRIGHT 2020 STMicroelectronics</center></h2>
  5. *
  6. * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  7. * You may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * www.st.com/myliberty
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  15. * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. /*
  22. * PROJECT: ST25R3916 firmware
  23. * Revision:
  24. * LANGUAGE: ISO C99
  25. */
  26. /*! \file
  27. *
  28. * \author Gustavo Patricio
  29. *
  30. * \brief Implementation of ST25R3916 communication
  31. *
  32. */
  33. /*
  34. ******************************************************************************
  35. * INCLUDES
  36. ******************************************************************************
  37. */
  38. #include "st25r3916.h"
  39. #include "st25r3916_com.h"
  40. #include "st25r3916_led.h"
  41. #include "st_errno.h"
  42. #include "platform.h"
  43. #include "utils.h"
  44. /*
  45. ******************************************************************************
  46. * LOCAL DEFINES
  47. ******************************************************************************
  48. */
  49. #define ST25R3916_OPTIMIZE true /*!< Optimization switch: false always write value to register */
  50. #define ST25R3916_I2C_ADDR (0xA0U >> 1) /*!< ST25R3916's default I2C address */
  51. #define ST25R3916_REG_LEN 1U /*!< Byte length of a ST25R3916 register */
  52. #define ST25R3916_WRITE_MODE (0U << 6) /*!< ST25R3916 Operation Mode: Write */
  53. #define ST25R3916_READ_MODE (1U << 6) /*!< ST25R3916 Operation Mode: Read */
  54. #define ST25R3916_CMD_MODE (3U << 6) /*!< ST25R3916 Operation Mode: Direct Command */
  55. #define ST25R3916_FIFO_LOAD (0x80U) /*!< ST25R3916 Operation Mode: FIFO Load */
  56. #define ST25R3916_FIFO_READ (0x9FU) /*!< ST25R3916 Operation Mode: FIFO Read */
  57. #define ST25R3916_PT_A_CONFIG_LOAD (0xA0U) /*!< ST25R3916 Operation Mode: Passive Target Memory A-Config Load */
  58. #define ST25R3916_PT_F_CONFIG_LOAD (0xA8U) /*!< ST25R3916 Operation Mode: Passive Target Memory F-Config Load */
  59. #define ST25R3916_PT_TSN_DATA_LOAD (0xACU) /*!< ST25R3916 Operation Mode: Passive Target Memory TSN Load */
  60. #define ST25R3916_PT_MEM_READ (0xBFU) /*!< ST25R3916 Operation Mode: Passive Target Memory Read */
  61. #define ST25R3916_CMD_LEN (1U) /*!< ST25R3916 CMD length */
  62. #define ST25R3916_BUF_LEN (ST25R3916_CMD_LEN+ST25R3916_FIFO_DEPTH) /*!< ST25R3916 communication buffer: CMD + FIFO length */
  63. /*
  64. ******************************************************************************
  65. * MACROS
  66. ******************************************************************************
  67. */
  68. #ifdef RFAL_USE_I2C
  69. #define st25r3916I2CStart() platformI2CStart() /*!< ST25R3916 HAL I2C driver macro to start a I2C transfer */
  70. #define st25r3916I2CStop() platformI2CStop() /*!< ST25R3916 HAL I2C driver macro to stop a I2C transfer */
  71. #define st25r3916I2CRepeatStart() platformI2CRepeatStart() /*!< ST25R3916 HAL I2C driver macro to repeat Start */
  72. #define st25r3916I2CSlaveAddrWR( sA ) platformI2CSlaveAddrWR( sA ) /*!< ST25R3916 HAL I2C driver macro to repeat Start */
  73. #define st25r3916I2CSlaveAddrRD( sA ) platformI2CSlaveAddrRD( sA ) /*!< ST25R3916 HAL I2C driver macro to repeat Start */
  74. #endif /* RFAL_USE_I2C */
  75. #if defined(ST25R_COM_SINGLETXRX) && !defined(RFAL_USE_I2C)
  76. static uint8_t comBuf[ST25R3916_BUF_LEN]; /*!< ST25R3916 communication buffer */
  77. static uint16_t comBufIt; /*!< ST25R3916 communication buffer iterator */
  78. #endif /* ST25R_COM_SINGLETXRX */
  79. /*
  80. ******************************************************************************
  81. * LOCAL FUNCTION PROTOTYPES
  82. ******************************************************************************
  83. */
  84. /*!
  85. ******************************************************************************
  86. * \brief ST25R3916 communication Start
  87. *
  88. * This method performs the required actions to start communications with
  89. * ST25R3916, either by SPI or I2C
  90. ******************************************************************************
  91. */
  92. static void st25r3916comStart( void );
  93. /*!
  94. ******************************************************************************
  95. * \brief ST25R3916 communication Stop
  96. *
  97. * This method performs the required actions to terminate communications with
  98. * ST25R3916, either by SPI or I2C
  99. ******************************************************************************
  100. */
  101. static void st25r3916comStop( void );
  102. /*!
  103. ******************************************************************************
  104. * \brief ST25R3916 communication Repeat Start
  105. *
  106. * This method performs the required actions to repeat start a transmission
  107. * with ST25R3916, either by SPI or I2C
  108. ******************************************************************************
  109. */
  110. #ifdef RFAL_USE_I2C
  111. static void st25r3916comRepeatStart( void );
  112. #else
  113. #define st25r3916comRepeatStart()
  114. #endif /* RFAL_USE_I2C */
  115. /*!
  116. ******************************************************************************
  117. * \brief ST25R3916 communication Tx
  118. *
  119. * This method performs the required actions to transmit the given buffer
  120. * to ST25R3916, either by SPI or I2C
  121. *
  122. * \param[in] txBuf : the buffer to transmit
  123. * \param[in] txLen : the length of the buffer to transmit
  124. * \param[in] last : true if last data to be transmitted
  125. * \param[in] txOnly : true no reception is to be performed
  126. *
  127. ******************************************************************************
  128. */
  129. static void st25r3916comTx( const uint8_t* txBuf, uint16_t txLen, bool last, bool txOnly );
  130. /*!
  131. ******************************************************************************
  132. * \brief ST25R3916 communication Rx
  133. *
  134. * This method performs the required actions to receive from ST25R3916 the given
  135. * amount of bytes, either by SPI or I2C
  136. *
  137. * \param[out] rxBuf : the buffer place the received bytes
  138. * \param[in] rxLen : the length to receive
  139. *
  140. ******************************************************************************
  141. */
  142. static void st25r3916comRx( uint8_t* rxBuf, uint16_t rxLen );
  143. /*!
  144. ******************************************************************************
  145. * \brief ST25R3916 communication Tx Byte
  146. *
  147. * This helper method transmits a byte passed by value and not by reference
  148. *
  149. * \param[in] txByte : the value of the byte to be transmitted
  150. * \param[in] last : true if last byte to be transmitted
  151. * \param[in] txOnly : true no reception is to be performed
  152. *
  153. ******************************************************************************
  154. */
  155. static void st25r3916comTxByte( uint8_t txByte, bool last, bool txOnly );
  156. /*
  157. ******************************************************************************
  158. * LOCAL FUNCTION
  159. ******************************************************************************
  160. */
  161. static void st25r3916comStart( void )
  162. {
  163. /* Make this operation atomic, disabling ST25R3916 interrupt during communications*/
  164. platformProtectST25RComm();
  165. #ifdef RFAL_USE_I2C
  166. /* I2C Start and send Slave Address */
  167. st25r3916I2CStart();
  168. st25r3916I2CSlaveAddrWR( ST25R3916_I2C_ADDR );
  169. #else
  170. /* Perform the chip select */
  171. platformSpiSelect();
  172. #if defined(ST25R_COM_SINGLETXRX)
  173. comBufIt = 0; /* reset local buffer position */
  174. #endif /* ST25R_COM_SINGLETXRX */
  175. #endif /* RFAL_USE_I2C */
  176. }
  177. /*******************************************************************************/
  178. static void st25r3916comStop( void )
  179. {
  180. #ifdef RFAL_USE_I2C
  181. /* Generate Stop signal */
  182. st25r3916I2CStop();
  183. #else
  184. /* Release the chip select */
  185. platformSpiDeselect();
  186. #endif /* RFAL_USE_I2C */
  187. /* reEnable the ST25R3916 interrupt */
  188. platformUnprotectST25RComm();
  189. }
  190. /*******************************************************************************/
  191. #ifdef RFAL_USE_I2C
  192. static void st25r3916comRepeatStart( void )
  193. {
  194. st25r3916I2CRepeatStart();
  195. st25r3916I2CSlaveAddrRD( ST25R3916_I2C_ADDR );
  196. }
  197. #endif /* RFAL_USE_I2C */
  198. /*******************************************************************************/
  199. static void st25r3916comTx( const uint8_t* txBuf, uint16_t txLen, bool last, bool txOnly )
  200. {
  201. NO_WARNING(last);
  202. NO_WARNING(txOnly);
  203. if( txLen > 0U )
  204. {
  205. #ifdef RFAL_USE_I2C
  206. platformI2CTx( txBuf, txLen, last, txOnly );
  207. #else /* RFAL_USE_I2C */
  208. #ifdef ST25R_COM_SINGLETXRX
  209. ST_MEMCPY( &comBuf[comBufIt], txBuf, MIN( txLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* copy tx data to local buffer */
  210. comBufIt += MIN( txLen, (ST25R3916_BUF_LEN - comBufIt) ); /* store position on local buffer */
  211. if( last && txOnly ) /* only perform SPI transaction if no Rx will follow */
  212. {
  213. platformSpiTxRx( comBuf, NULL, comBufIt );
  214. }
  215. #else
  216. platformSpiTxRx( txBuf, NULL, txLen );
  217. #endif /* ST25R_COM_SINGLETXRX */
  218. #endif /* RFAL_USE_I2C */
  219. }
  220. }
  221. /*******************************************************************************/
  222. static void st25r3916comRx( uint8_t* rxBuf, uint16_t rxLen )
  223. {
  224. if( rxLen > 0U )
  225. {
  226. #ifdef RFAL_USE_I2C
  227. platformI2CRx( rxBuf, rxLen );
  228. #else /* RFAL_USE_I2C */
  229. #ifdef ST25R_COM_SINGLETXRX
  230. ST_MEMSET( &comBuf[comBufIt], 0x00, MIN( rxLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* clear outgoing buffer */
  231. platformSpiTxRx( comBuf, comBuf, MIN( (comBufIt + rxLen), ST25R3916_BUF_LEN ) ); /* transceive as a single SPI call */
  232. ST_MEMCPY( rxBuf, &comBuf[comBufIt], MIN( rxLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* copy from local buf to output buffer and skip cmd byte */
  233. #else
  234. if( rxBuf != NULL)
  235. {
  236. ST_MEMSET( rxBuf, 0x00, rxLen ); /* clear outgoing buffer */
  237. }
  238. platformSpiTxRx( NULL, rxBuf, rxLen );
  239. #endif /* ST25R_COM_SINGLETXRX */
  240. #endif /* RFAL_USE_I2C */
  241. }
  242. }
  243. /*******************************************************************************/
  244. static void st25r3916comTxByte( uint8_t txByte, bool last, bool txOnly )
  245. {
  246. uint8_t val = txByte; /* MISRA 17.8: use intermediate variable */
  247. st25r3916comTx( &val, ST25R3916_REG_LEN, last, txOnly );
  248. }
  249. /*
  250. ******************************************************************************
  251. * GLOBAL FUNCTIONS
  252. ******************************************************************************
  253. */
  254. /*******************************************************************************/
  255. ReturnCode st25r3916ReadRegister( uint8_t reg, uint8_t* val )
  256. {
  257. return st25r3916ReadMultipleRegisters( reg, val, ST25R3916_REG_LEN );
  258. }
  259. /*******************************************************************************/
  260. ReturnCode st25r3916ReadMultipleRegisters( uint8_t reg, uint8_t* values, uint8_t length )
  261. {
  262. if( length > 0U )
  263. {
  264. st25r3916comStart();
  265. /* If is a space-B register send a direct command first */
  266. if( (reg & ST25R3916_SPACE_B) != 0U )
  267. {
  268. st25r3916comTxByte( ST25R3916_CMD_SPACE_B_ACCESS, false, false );
  269. }
  270. st25r3916comTxByte( ((reg & ~ST25R3916_SPACE_B) | ST25R3916_READ_MODE), true, false );
  271. st25r3916comRepeatStart();
  272. st25r3916comRx( values, length );
  273. st25r3916comStop();
  274. }
  275. return ERR_NONE;
  276. }
  277. /*******************************************************************************/
  278. ReturnCode st25r3916WriteRegister( uint8_t reg, uint8_t val )
  279. {
  280. uint8_t value = val; /* MISRA 17.8: use intermediate variable */
  281. return st25r3916WriteMultipleRegisters( reg, &value, ST25R3916_REG_LEN );
  282. }
  283. /*******************************************************************************/
  284. ReturnCode st25r3916WriteMultipleRegisters( uint8_t reg, const uint8_t* values, uint8_t length )
  285. {
  286. if( length > 0U )
  287. {
  288. st25r3916comStart();
  289. if( (reg & ST25R3916_SPACE_B) != 0U )
  290. {
  291. st25r3916comTxByte( ST25R3916_CMD_SPACE_B_ACCESS, false, true );
  292. }
  293. st25r3916comTxByte( ((reg & ~ST25R3916_SPACE_B) | ST25R3916_WRITE_MODE), false, true );
  294. st25r3916comTx( values, length, true, true );
  295. st25r3916comStop();
  296. /* Send a WriteMultiReg event to LED handling */
  297. st25r3916ledEvtWrMultiReg( reg, values, length);
  298. }
  299. return ERR_NONE;
  300. }
  301. /*******************************************************************************/
  302. ReturnCode st25r3916WriteFifo( const uint8_t* values, uint16_t length )
  303. {
  304. if( length > ST25R3916_FIFO_DEPTH )
  305. {
  306. return ERR_PARAM;
  307. }
  308. if( length > 0U )
  309. {
  310. st25r3916comStart();
  311. st25r3916comTxByte( ST25R3916_FIFO_LOAD, false, true );
  312. st25r3916comTx( values, length, true, true );
  313. st25r3916comStop();
  314. }
  315. return ERR_NONE;
  316. }
  317. /*******************************************************************************/
  318. ReturnCode st25r3916ReadFifo( uint8_t* buf, uint16_t length )
  319. {
  320. if( length > 0U )
  321. {
  322. st25r3916comStart();
  323. st25r3916comTxByte( ST25R3916_FIFO_READ, true, false );
  324. st25r3916comRepeatStart();
  325. st25r3916comRx( buf, length );
  326. st25r3916comStop();
  327. }
  328. return ERR_NONE;
  329. }
  330. /*******************************************************************************/
  331. ReturnCode st25r3916WritePTMem( const uint8_t* values, uint16_t length )
  332. {
  333. if( length > ST25R3916_PTM_LEN )
  334. {
  335. return ERR_PARAM;
  336. }
  337. if( length > 0U )
  338. {
  339. st25r3916comStart();
  340. st25r3916comTxByte( ST25R3916_PT_A_CONFIG_LOAD, false, true );
  341. st25r3916comTx( values, length, true, true );
  342. st25r3916comStop();
  343. }
  344. return ERR_NONE;
  345. }
  346. /*******************************************************************************/
  347. ReturnCode st25r3916ReadPTMem( uint8_t* values, uint16_t length )
  348. {
  349. uint8_t tmp[ST25R3916_REG_LEN + ST25R3916_PTM_LEN]; /* local buffer to handle prepended byte on I2C and SPI */
  350. if( length > 0U )
  351. {
  352. if( length > ST25R3916_PTM_LEN )
  353. {
  354. return ERR_PARAM;
  355. }
  356. st25r3916comStart();
  357. st25r3916comTxByte( ST25R3916_PT_MEM_READ, true, false );
  358. st25r3916comRepeatStart();
  359. st25r3916comRx( tmp, (ST25R3916_REG_LEN + length) ); /* skip prepended byte */
  360. st25r3916comStop();
  361. /* Copy PTMem content without prepended byte */
  362. ST_MEMCPY( values, (tmp+ST25R3916_REG_LEN), length );
  363. }
  364. return ERR_NONE;
  365. }
  366. /*******************************************************************************/
  367. ReturnCode st25r3916WritePTMemF( const uint8_t* values, uint16_t length )
  368. {
  369. if( length > (ST25R3916_PTM_F_LEN + ST25R3916_PTM_TSN_LEN) )
  370. {
  371. return ERR_PARAM;
  372. }
  373. if( length > 0U )
  374. {
  375. st25r3916comStart();
  376. st25r3916comTxByte( ST25R3916_PT_F_CONFIG_LOAD, false, true );
  377. st25r3916comTx( values, length, true, true );
  378. st25r3916comStop();
  379. }
  380. return ERR_NONE;
  381. }
  382. /*******************************************************************************/
  383. ReturnCode st25r3916WritePTMemTSN( const uint8_t* values, uint16_t length )
  384. {
  385. if( length > ST25R3916_PTM_TSN_LEN )
  386. {
  387. return ERR_PARAM;
  388. }
  389. if(length > 0U)
  390. {
  391. st25r3916comStart();
  392. st25r3916comTxByte( ST25R3916_PT_TSN_DATA_LOAD, false, true );
  393. st25r3916comTx( values, length, true, true );
  394. st25r3916comStop();
  395. }
  396. return ERR_NONE;
  397. }
  398. /*******************************************************************************/
  399. ReturnCode st25r3916ExecuteCommand( uint8_t cmd )
  400. {
  401. st25r3916comStart();
  402. st25r3916comTxByte( (cmd | ST25R3916_CMD_MODE ), true, true );
  403. st25r3916comStop();
  404. /* Send a cmd event to LED handling */
  405. st25r3916ledEvtCmd(cmd);
  406. return ERR_NONE;
  407. }
  408. /*******************************************************************************/
  409. ReturnCode st25r3916ReadTestRegister( uint8_t reg, uint8_t* val )
  410. {
  411. st25r3916comStart();
  412. st25r3916comTxByte( ST25R3916_CMD_TEST_ACCESS, false, false );
  413. st25r3916comTxByte( (reg | ST25R3916_READ_MODE), true, false );
  414. st25r3916comRepeatStart();
  415. st25r3916comRx( val, ST25R3916_REG_LEN );
  416. st25r3916comStop();
  417. return ERR_NONE;
  418. }
  419. /*******************************************************************************/
  420. ReturnCode st25r3916WriteTestRegister( uint8_t reg, uint8_t val )
  421. {
  422. uint8_t value = val; /* MISRA 17.8: use intermediate variable */
  423. st25r3916comStart();
  424. st25r3916comTxByte( ST25R3916_CMD_TEST_ACCESS, false, true );
  425. st25r3916comTxByte( (reg | ST25R3916_WRITE_MODE), false, true );
  426. st25r3916comTx( &value, ST25R3916_REG_LEN, true, true );
  427. st25r3916comStop();
  428. return ERR_NONE;
  429. }
  430. /*******************************************************************************/
  431. ReturnCode st25r3916ClrRegisterBits( uint8_t reg, uint8_t clr_mask )
  432. {
  433. ReturnCode ret;
  434. uint8_t rdVal;
  435. /* Read current reg value */
  436. EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
  437. /* Only perform a Write if value to be written is different */
  438. if( ST25R3916_OPTIMIZE && (rdVal == (uint8_t)(rdVal & ~clr_mask)) )
  439. {
  440. return ERR_NONE;
  441. }
  442. /* Write new reg value */
  443. return st25r3916WriteRegister(reg, (uint8_t)(rdVal & ~clr_mask) );
  444. }
  445. /*******************************************************************************/
  446. ReturnCode st25r3916SetRegisterBits( uint8_t reg, uint8_t set_mask )
  447. {
  448. ReturnCode ret;
  449. uint8_t rdVal;
  450. /* Read current reg value */
  451. EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
  452. /* Only perform a Write if the value to be written is different */
  453. if( ST25R3916_OPTIMIZE && (rdVal == (rdVal | set_mask)) )
  454. {
  455. return ERR_NONE;
  456. }
  457. /* Write new reg value */
  458. return st25r3916WriteRegister(reg, (rdVal | set_mask) );
  459. }
  460. /*******************************************************************************/
  461. ReturnCode st25r3916ChangeRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value )
  462. {
  463. return st25r3916ModifyRegister(reg, valueMask, (valueMask & value) );
  464. }
  465. /*******************************************************************************/
  466. ReturnCode st25r3916ModifyRegister( uint8_t reg, uint8_t clr_mask, uint8_t set_mask )
  467. {
  468. ReturnCode ret;
  469. uint8_t rdVal;
  470. uint8_t wrVal;
  471. /* Read current reg value */
  472. EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
  473. /* Compute new value */
  474. wrVal = (uint8_t)(rdVal & ~clr_mask);
  475. wrVal |= set_mask;
  476. /* Only perform a Write if the value to be written is different */
  477. if( ST25R3916_OPTIMIZE && (rdVal == wrVal) )
  478. {
  479. return ERR_NONE;
  480. }
  481. /* Write new reg value */
  482. return st25r3916WriteRegister(reg, wrVal );
  483. }
  484. /*******************************************************************************/
  485. ReturnCode st25r3916ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value )
  486. {
  487. ReturnCode ret;
  488. uint8_t rdVal;
  489. uint8_t wrVal;
  490. /* Read current reg value */
  491. EXIT_ON_ERR( ret, st25r3916ReadTestRegister(reg, &rdVal) );
  492. /* Compute new value */
  493. wrVal = (uint8_t)(rdVal & ~valueMask);
  494. wrVal |= (uint8_t)(value & valueMask);
  495. /* Only perform a Write if the value to be written is different */
  496. if( ST25R3916_OPTIMIZE && (rdVal == wrVal) )
  497. {
  498. return ERR_NONE;
  499. }
  500. /* Write new reg value */
  501. return st25r3916WriteTestRegister(reg, wrVal );
  502. }
  503. /*******************************************************************************/
  504. bool st25r3916CheckReg( uint8_t reg, uint8_t mask, uint8_t val )
  505. {
  506. uint8_t regVal;
  507. regVal = 0;
  508. st25r3916ReadRegister( reg, &regVal );
  509. return ( (regVal & mask) == val );
  510. }
  511. /*******************************************************************************/
  512. bool st25r3916IsRegValid( uint8_t reg )
  513. {
  514. if( !(( (int16_t)reg >= (int16_t)ST25R3916_REG_IO_CONF1) && (reg <= (ST25R3916_SPACE_B | ST25R3916_REG_IC_IDENTITY)) ))
  515. {
  516. return false;
  517. }
  518. return true;
  519. }