ST25R3911 library for the STMicroelectronics X-NUCLEO-NFC05A1
ST25R3911.cpp@0:98fcd1266df0, 2019-11-14 (annotated)
- Committer:
- DiegoOstuni
- Date:
- Thu Nov 14 14:36:52 2019 +0000
- Revision:
- 0:98fcd1266df0
Fork of the GitHub
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoOstuni | 0:98fcd1266df0 | 1 | |
DiegoOstuni | 0:98fcd1266df0 | 2 | /****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 3 | * @attention |
DiegoOstuni | 0:98fcd1266df0 | 4 | * |
DiegoOstuni | 0:98fcd1266df0 | 5 | * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> |
DiegoOstuni | 0:98fcd1266df0 | 6 | * |
DiegoOstuni | 0:98fcd1266df0 | 7 | * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); |
DiegoOstuni | 0:98fcd1266df0 | 8 | * You may not use this file except in compliance with the License. |
DiegoOstuni | 0:98fcd1266df0 | 9 | * You may obtain a copy of the License at: |
DiegoOstuni | 0:98fcd1266df0 | 10 | * |
DiegoOstuni | 0:98fcd1266df0 | 11 | * http://www.st.com/myliberty |
DiegoOstuni | 0:98fcd1266df0 | 12 | * |
DiegoOstuni | 0:98fcd1266df0 | 13 | * Unless required by applicable law or agreed to in writing, software |
DiegoOstuni | 0:98fcd1266df0 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
DiegoOstuni | 0:98fcd1266df0 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
DiegoOstuni | 0:98fcd1266df0 | 16 | * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
DiegoOstuni | 0:98fcd1266df0 | 17 | * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
DiegoOstuni | 0:98fcd1266df0 | 18 | * See the License for the specific language governing permissions and |
DiegoOstuni | 0:98fcd1266df0 | 19 | * limitations under the License. |
DiegoOstuni | 0:98fcd1266df0 | 20 | * |
DiegoOstuni | 0:98fcd1266df0 | 21 | ******************************************************************************/ |
DiegoOstuni | 0:98fcd1266df0 | 22 | |
DiegoOstuni | 0:98fcd1266df0 | 23 | |
DiegoOstuni | 0:98fcd1266df0 | 24 | /* |
DiegoOstuni | 0:98fcd1266df0 | 25 | * PROJECT: ST25R3911 firmware |
DiegoOstuni | 0:98fcd1266df0 | 26 | * $Revision: $ |
DiegoOstuni | 0:98fcd1266df0 | 27 | * LANGUAGE: ISO C99 |
DiegoOstuni | 0:98fcd1266df0 | 28 | */ |
DiegoOstuni | 0:98fcd1266df0 | 29 | |
DiegoOstuni | 0:98fcd1266df0 | 30 | /*! \file |
DiegoOstuni | 0:98fcd1266df0 | 31 | * |
DiegoOstuni | 0:98fcd1266df0 | 32 | * \author Ulrich Herrmann |
DiegoOstuni | 0:98fcd1266df0 | 33 | * |
DiegoOstuni | 0:98fcd1266df0 | 34 | * \brief ST25R3911 high level interface |
DiegoOstuni | 0:98fcd1266df0 | 35 | * |
DiegoOstuni | 0:98fcd1266df0 | 36 | */ |
DiegoOstuni | 0:98fcd1266df0 | 37 | |
DiegoOstuni | 0:98fcd1266df0 | 38 | /* |
DiegoOstuni | 0:98fcd1266df0 | 39 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 40 | * INCLUDES |
DiegoOstuni | 0:98fcd1266df0 | 41 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 42 | */ |
DiegoOstuni | 0:98fcd1266df0 | 43 | |
DiegoOstuni | 0:98fcd1266df0 | 44 | #include "ST25R3911.h" |
DiegoOstuni | 0:98fcd1266df0 | 45 | #include "st25r3911_com.h" |
DiegoOstuni | 0:98fcd1266df0 | 46 | #include "st25r3911_interrupt.h" |
DiegoOstuni | 0:98fcd1266df0 | 47 | |
DiegoOstuni | 0:98fcd1266df0 | 48 | |
DiegoOstuni | 0:98fcd1266df0 | 49 | |
DiegoOstuni | 0:98fcd1266df0 | 50 | #include "stdio.h" |
DiegoOstuni | 0:98fcd1266df0 | 51 | #include <limits.h> |
DiegoOstuni | 0:98fcd1266df0 | 52 | |
DiegoOstuni | 0:98fcd1266df0 | 53 | |
DiegoOstuni | 0:98fcd1266df0 | 54 | |
DiegoOstuni | 0:98fcd1266df0 | 55 | |
DiegoOstuni | 0:98fcd1266df0 | 56 | /* |
DiegoOstuni | 0:98fcd1266df0 | 57 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 58 | * LOCAL VARIABLES |
DiegoOstuni | 0:98fcd1266df0 | 59 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 60 | */ |
DiegoOstuni | 0:98fcd1266df0 | 61 | static uint32_t st25r3911NoResponseTime_64fcs; |
DiegoOstuni | 0:98fcd1266df0 | 62 | typedef uint16_t ReturnCode; //eeeee.... st_errno.h |
DiegoOstuni | 0:98fcd1266df0 | 63 | #ifdef ST25R391X_COM_SINGLETXRX |
DiegoOstuni | 0:98fcd1266df0 | 64 | static uint8_t comBuf[ST25R3911_BUF_LEN]; |
DiegoOstuni | 0:98fcd1266df0 | 65 | #endif /* ST25R391X_COM_SINGLETXRX */ |
DiegoOstuni | 0:98fcd1266df0 | 66 | |
DiegoOstuni | 0:98fcd1266df0 | 67 | /* |
DiegoOstuni | 0:98fcd1266df0 | 68 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 69 | * LOCAL FUNCTION PROTOTYPES |
DiegoOstuni | 0:98fcd1266df0 | 70 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 71 | */ |
DiegoOstuni | 0:98fcd1266df0 | 72 | static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ); |
DiegoOstuni | 0:98fcd1266df0 | 73 | |
DiegoOstuni | 0:98fcd1266df0 | 74 | |
DiegoOstuni | 0:98fcd1266df0 | 75 | static inline void st25r3911CheckFieldSetLED(uint8_t val, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 76 | { |
DiegoOstuni | 0:98fcd1266df0 | 77 | if (ST25R3911_REG_OP_CONTROL_tx_en & val) |
DiegoOstuni | 0:98fcd1266df0 | 78 | { |
DiegoOstuni | 0:98fcd1266df0 | 79 | fieldLED_06 -> write(1); |
DiegoOstuni | 0:98fcd1266df0 | 80 | |
DiegoOstuni | 0:98fcd1266df0 | 81 | } |
DiegoOstuni | 0:98fcd1266df0 | 82 | else |
DiegoOstuni | 0:98fcd1266df0 | 83 | { |
DiegoOstuni | 0:98fcd1266df0 | 84 | fieldLED_06 -> write(0); |
DiegoOstuni | 0:98fcd1266df0 | 85 | } |
DiegoOstuni | 0:98fcd1266df0 | 86 | |
DiegoOstuni | 0:98fcd1266df0 | 87 | } |
DiegoOstuni | 0:98fcd1266df0 | 88 | /* |
DiegoOstuni | 0:98fcd1266df0 | 89 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 90 | * GLOBAL FUNCTIONS |
DiegoOstuni | 0:98fcd1266df0 | 91 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 92 | */ |
DiegoOstuni | 0:98fcd1266df0 | 93 | |
DiegoOstuni | 0:98fcd1266df0 | 94 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 95 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 96 | * \brief Returns the content of a register within the ST25R3911 |
DiegoOstuni | 0:98fcd1266df0 | 97 | * |
DiegoOstuni | 0:98fcd1266df0 | 98 | * This function is used to read out the content of ST25R3911 registers. |
DiegoOstuni | 0:98fcd1266df0 | 99 | * |
DiegoOstuni | 0:98fcd1266df0 | 100 | * \param[in] reg: Address of register to read. |
DiegoOstuni | 0:98fcd1266df0 | 101 | * \param[out] val: Returned value. |
DiegoOstuni | 0:98fcd1266df0 | 102 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 103 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 104 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 105 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 106 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 107 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 108 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 109 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 110 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 111 | * |
DiegoOstuni | 0:98fcd1266df0 | 112 | * |
DiegoOstuni | 0:98fcd1266df0 | 113 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 114 | */ |
DiegoOstuni | 0:98fcd1266df0 | 115 | |
DiegoOstuni | 0:98fcd1266df0 | 116 | void ST25R3911::readRegister(uint8_t reg, uint8_t* val, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 117 | { |
DiegoOstuni | 0:98fcd1266df0 | 118 | |
DiegoOstuni | 0:98fcd1266df0 | 119 | uint8_t buf[2]; |
DiegoOstuni | 0:98fcd1266df0 | 120 | uint8_t buf_rx[2]; |
DiegoOstuni | 0:98fcd1266df0 | 121 | buf_rx[0] = 0; |
DiegoOstuni | 0:98fcd1266df0 | 122 | buf_rx[1] = 0; |
DiegoOstuni | 0:98fcd1266df0 | 123 | |
DiegoOstuni | 0:98fcd1266df0 | 124 | |
DiegoOstuni | 0:98fcd1266df0 | 125 | buf[0] = (reg | ST25R3911_READ_MODE); |
DiegoOstuni | 0:98fcd1266df0 | 126 | buf[1] = 0; |
DiegoOstuni | 0:98fcd1266df0 | 127 | |
DiegoOstuni | 0:98fcd1266df0 | 128 | IRQ->disable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 129 | *gpio_cs = 0; |
DiegoOstuni | 0:98fcd1266df0 | 130 | wait_us(50); |
DiegoOstuni | 0:98fcd1266df0 | 131 | mspiChannel -> write((const char *)(buf) ,2 , (char*)(buf_rx) , 2); |
DiegoOstuni | 0:98fcd1266df0 | 132 | *gpio_cs = 1; |
DiegoOstuni | 0:98fcd1266df0 | 133 | IRQ->enable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 134 | |
DiegoOstuni | 0:98fcd1266df0 | 135 | |
DiegoOstuni | 0:98fcd1266df0 | 136 | |
DiegoOstuni | 0:98fcd1266df0 | 137 | if(val != NULL) |
DiegoOstuni | 0:98fcd1266df0 | 138 | { |
DiegoOstuni | 0:98fcd1266df0 | 139 | *val = buf_rx[1]; |
DiegoOstuni | 0:98fcd1266df0 | 140 | } |
DiegoOstuni | 0:98fcd1266df0 | 141 | |
DiegoOstuni | 0:98fcd1266df0 | 142 | } |
DiegoOstuni | 0:98fcd1266df0 | 143 | |
DiegoOstuni | 0:98fcd1266df0 | 144 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 145 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 146 | * \brief Writes a given value to a register within the ST25R3911 |
DiegoOstuni | 0:98fcd1266df0 | 147 | * |
DiegoOstuni | 0:98fcd1266df0 | 148 | * This function is used to write \a val to address \a reg within the ST25R3911. |
DiegoOstuni | 0:98fcd1266df0 | 149 | * |
DiegoOstuni | 0:98fcd1266df0 | 150 | * \param[in] reg: Address of the register to write. |
DiegoOstuni | 0:98fcd1266df0 | 151 | * \param[in] val: Value to be written. |
DiegoOstuni | 0:98fcd1266df0 | 152 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 153 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 154 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 155 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 156 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 157 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 158 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 159 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 160 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 161 | * |
DiegoOstuni | 0:98fcd1266df0 | 162 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 163 | */ |
DiegoOstuni | 0:98fcd1266df0 | 164 | |
DiegoOstuni | 0:98fcd1266df0 | 165 | |
DiegoOstuni | 0:98fcd1266df0 | 166 | void ST25R3911::writeRegister(uint8_t reg, uint8_t val, SPI * mspiChannel, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 167 | { |
DiegoOstuni | 0:98fcd1266df0 | 168 | |
DiegoOstuni | 0:98fcd1266df0 | 169 | uint8_t buf[2]; |
DiegoOstuni | 0:98fcd1266df0 | 170 | |
DiegoOstuni | 0:98fcd1266df0 | 171 | buf[0] = reg | ST25R3911_WRITE_MODE; |
DiegoOstuni | 0:98fcd1266df0 | 172 | buf[1] = val; |
DiegoOstuni | 0:98fcd1266df0 | 173 | |
DiegoOstuni | 0:98fcd1266df0 | 174 | if (ST25R3911_REG_OP_CONTROL == reg) |
DiegoOstuni | 0:98fcd1266df0 | 175 | { |
DiegoOstuni | 0:98fcd1266df0 | 176 | st25r3911CheckFieldSetLED(val, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 177 | } |
DiegoOstuni | 0:98fcd1266df0 | 178 | |
DiegoOstuni | 0:98fcd1266df0 | 179 | IRQ->disable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 180 | *gpio_cs = 0; |
DiegoOstuni | 0:98fcd1266df0 | 181 | wait_us(50); |
DiegoOstuni | 0:98fcd1266df0 | 182 | mspiChannel -> write((const char *)(buf) ,2, NULL , NULL); |
DiegoOstuni | 0:98fcd1266df0 | 183 | *gpio_cs = 1; |
DiegoOstuni | 0:98fcd1266df0 | 184 | IRQ->enable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 185 | |
DiegoOstuni | 0:98fcd1266df0 | 186 | |
DiegoOstuni | 0:98fcd1266df0 | 187 | } |
DiegoOstuni | 0:98fcd1266df0 | 188 | |
DiegoOstuni | 0:98fcd1266df0 | 189 | |
DiegoOstuni | 0:98fcd1266df0 | 190 | |
DiegoOstuni | 0:98fcd1266df0 | 191 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 192 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 193 | * \brief Reads from multiple ST25R3911 registers |
DiegoOstuni | 0:98fcd1266df0 | 194 | * |
DiegoOstuni | 0:98fcd1266df0 | 195 | * This function is used to read from multiple registers using the |
DiegoOstuni | 0:98fcd1266df0 | 196 | * auto-increment feature. That is, after each read the address pointer |
DiegoOstuni | 0:98fcd1266df0 | 197 | * inside the ST25R3911 gets incremented automatically. |
DiegoOstuni | 0:98fcd1266df0 | 198 | * |
DiegoOstuni | 0:98fcd1266df0 | 199 | * \param[in] reg: Address of the frist register to read from. |
DiegoOstuni | 0:98fcd1266df0 | 200 | * \param[in] values: pointer to a buffer where the result shall be written to. |
DiegoOstuni | 0:98fcd1266df0 | 201 | * \param[in] length: Number of registers to be read out. |
DiegoOstuni | 0:98fcd1266df0 | 202 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 203 | * \param[in] mST25: Object of the ST25 chip |
DiegoOstuni | 0:98fcd1266df0 | 204 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 205 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 206 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 207 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 208 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 209 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 210 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 211 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 212 | * |
DiegoOstuni | 0:98fcd1266df0 | 213 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 214 | */ |
DiegoOstuni | 0:98fcd1266df0 | 215 | |
DiegoOstuni | 0:98fcd1266df0 | 216 | |
DiegoOstuni | 0:98fcd1266df0 | 217 | void ST25R3911::readMultipleRegisters(uint8_t reg, uint8_t* val, uint8_t length, SPI * mspiChannel, ST25R3911* mST25, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 218 | { |
DiegoOstuni | 0:98fcd1266df0 | 219 | |
DiegoOstuni | 0:98fcd1266df0 | 220 | uint8_t cmd = (reg | ST25R3911_READ_MODE); |
DiegoOstuni | 0:98fcd1266df0 | 221 | uint8_t index = 0; |
DiegoOstuni | 0:98fcd1266df0 | 222 | |
DiegoOstuni | 0:98fcd1266df0 | 223 | |
DiegoOstuni | 0:98fcd1266df0 | 224 | if (length > 0) |
DiegoOstuni | 0:98fcd1266df0 | 225 | { |
DiegoOstuni | 0:98fcd1266df0 | 226 | /* make this operation atomic */ |
DiegoOstuni | 0:98fcd1266df0 | 227 | for(index = 0; index < length; index ++) |
DiegoOstuni | 0:98fcd1266df0 | 228 | { |
DiegoOstuni | 0:98fcd1266df0 | 229 | |
DiegoOstuni | 0:98fcd1266df0 | 230 | mST25 -> readRegister(cmd + index, (val + index), mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 231 | |
DiegoOstuni | 0:98fcd1266df0 | 232 | } |
DiegoOstuni | 0:98fcd1266df0 | 233 | } |
DiegoOstuni | 0:98fcd1266df0 | 234 | |
DiegoOstuni | 0:98fcd1266df0 | 235 | |
DiegoOstuni | 0:98fcd1266df0 | 236 | } |
DiegoOstuni | 0:98fcd1266df0 | 237 | |
DiegoOstuni | 0:98fcd1266df0 | 238 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 239 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 240 | * \brief Writes multiple values to ST25R3911 registers |
DiegoOstuni | 0:98fcd1266df0 | 241 | * |
DiegoOstuni | 0:98fcd1266df0 | 242 | * This function is used to write multiple values to the ST25R3911 using the |
DiegoOstuni | 0:98fcd1266df0 | 243 | * auto-increment feature. That is, after each write the address pointer |
DiegoOstuni | 0:98fcd1266df0 | 244 | * inside the ST25R3911 gets incremented automatically. |
DiegoOstuni | 0:98fcd1266df0 | 245 | * |
DiegoOstuni | 0:98fcd1266df0 | 246 | * \param[in] reg: Address of the frist register to write. |
DiegoOstuni | 0:98fcd1266df0 | 247 | * \param[in] values: pointer to a buffer containing the values to be written. |
DiegoOstuni | 0:98fcd1266df0 | 248 | * \param[in] length: Number of values to be written. |
DiegoOstuni | 0:98fcd1266df0 | 249 | * \param[in] mST25: Object of the ST25 chip |
DiegoOstuni | 0:98fcd1266df0 | 250 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 251 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 252 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 253 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 254 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 255 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 256 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 257 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 258 | * |
DiegoOstuni | 0:98fcd1266df0 | 259 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 260 | */ |
DiegoOstuni | 0:98fcd1266df0 | 261 | |
DiegoOstuni | 0:98fcd1266df0 | 262 | void ST25R3911::writeMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length, SPI * mspiChannel, ST25R3911* mST25, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 263 | { |
DiegoOstuni | 0:98fcd1266df0 | 264 | |
DiegoOstuni | 0:98fcd1266df0 | 265 | uint8_t cmd = (reg | ST25R3911_WRITE_MODE); |
DiegoOstuni | 0:98fcd1266df0 | 266 | uint8_t index = 0; |
DiegoOstuni | 0:98fcd1266df0 | 267 | |
DiegoOstuni | 0:98fcd1266df0 | 268 | if (reg <= ST25R3911_REG_OP_CONTROL && reg+length >= ST25R3911_REG_OP_CONTROL) |
DiegoOstuni | 0:98fcd1266df0 | 269 | { |
DiegoOstuni | 0:98fcd1266df0 | 270 | st25r3911CheckFieldSetLED(values[ST25R3911_REG_OP_CONTROL-reg], fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 271 | } |
DiegoOstuni | 0:98fcd1266df0 | 272 | |
DiegoOstuni | 0:98fcd1266df0 | 273 | if (length > 0) |
DiegoOstuni | 0:98fcd1266df0 | 274 | { |
DiegoOstuni | 0:98fcd1266df0 | 275 | /* make this operation atomic */ |
DiegoOstuni | 0:98fcd1266df0 | 276 | for(index = 0; index < length; index ++) |
DiegoOstuni | 0:98fcd1266df0 | 277 | { |
DiegoOstuni | 0:98fcd1266df0 | 278 | mST25 -> writeRegister(cmd + index, *(values + index), mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 279 | } |
DiegoOstuni | 0:98fcd1266df0 | 280 | } |
DiegoOstuni | 0:98fcd1266df0 | 281 | |
DiegoOstuni | 0:98fcd1266df0 | 282 | } |
DiegoOstuni | 0:98fcd1266df0 | 283 | |
DiegoOstuni | 0:98fcd1266df0 | 284 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 285 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 286 | * \brief Execute a direct command |
DiegoOstuni | 0:98fcd1266df0 | 287 | * |
DiegoOstuni | 0:98fcd1266df0 | 288 | * This function is used to start so-called direct command. These commands |
DiegoOstuni | 0:98fcd1266df0 | 289 | * are implemented inside the chip and each command has unique code (see |
DiegoOstuni | 0:98fcd1266df0 | 290 | * datasheet). |
DiegoOstuni | 0:98fcd1266df0 | 291 | * |
DiegoOstuni | 0:98fcd1266df0 | 292 | * \param[in] cmd : code of the direct command to be executed. |
DiegoOstuni | 0:98fcd1266df0 | 293 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 294 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 295 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 296 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 297 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 298 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 299 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 300 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 301 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 302 | * |
DiegoOstuni | 0:98fcd1266df0 | 303 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 304 | */ |
DiegoOstuni | 0:98fcd1266df0 | 305 | |
DiegoOstuni | 0:98fcd1266df0 | 306 | void ST25R3911::executeCommand(uint8_t cmd, SPI* mspiChannel, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 307 | { |
DiegoOstuni | 0:98fcd1266df0 | 308 | |
DiegoOstuni | 0:98fcd1266df0 | 309 | uint8_t reg[1]; |
DiegoOstuni | 0:98fcd1266df0 | 310 | reg[0] = cmd; |
DiegoOstuni | 0:98fcd1266df0 | 311 | |
DiegoOstuni | 0:98fcd1266df0 | 312 | if ( cmd >= ST25R3911_CMD_TRANSMIT_WITH_CRC && cmd <= ST25R3911_CMD_RESPONSE_RF_COLLISION_0) |
DiegoOstuni | 0:98fcd1266df0 | 313 | { |
DiegoOstuni | 0:98fcd1266df0 | 314 | fieldLED_06 -> write(0); |
DiegoOstuni | 0:98fcd1266df0 | 315 | } |
DiegoOstuni | 0:98fcd1266df0 | 316 | |
DiegoOstuni | 0:98fcd1266df0 | 317 | IRQ->disable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 318 | *gpio_cs = 0; |
DiegoOstuni | 0:98fcd1266df0 | 319 | wait_us(50); |
DiegoOstuni | 0:98fcd1266df0 | 320 | mspiChannel -> write(( const char *)(reg), ST25R3911_CMD_LEN, NULL , NULL); |
DiegoOstuni | 0:98fcd1266df0 | 321 | *gpio_cs = 1; |
DiegoOstuni | 0:98fcd1266df0 | 322 | IRQ->enable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 323 | |
DiegoOstuni | 0:98fcd1266df0 | 324 | |
DiegoOstuni | 0:98fcd1266df0 | 325 | return; |
DiegoOstuni | 0:98fcd1266df0 | 326 | } |
DiegoOstuni | 0:98fcd1266df0 | 327 | |
DiegoOstuni | 0:98fcd1266df0 | 328 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 329 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 330 | * \brief Execute several direct commands |
DiegoOstuni | 0:98fcd1266df0 | 331 | * |
DiegoOstuni | 0:98fcd1266df0 | 332 | * This function is used to start so-called direct command. These commands |
DiegoOstuni | 0:98fcd1266df0 | 333 | * are implemented inside the chip and each command has unique code (see |
DiegoOstuni | 0:98fcd1266df0 | 334 | * datasheet). |
DiegoOstuni | 0:98fcd1266df0 | 335 | * |
DiegoOstuni | 0:98fcd1266df0 | 336 | * \param[in] cmds : codes of the direct command to be executed. |
DiegoOstuni | 0:98fcd1266df0 | 337 | * \param[in] length : number of commands to be executed |
DiegoOstuni | 0:98fcd1266df0 | 338 | * \param[in] mST25: Object of the ST25 chip |
DiegoOstuni | 0:98fcd1266df0 | 339 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 340 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 341 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 342 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 343 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 344 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 345 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 346 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 347 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 348 | * |
DiegoOstuni | 0:98fcd1266df0 | 349 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 350 | */ |
DiegoOstuni | 0:98fcd1266df0 | 351 | |
DiegoOstuni | 0:98fcd1266df0 | 352 | |
DiegoOstuni | 0:98fcd1266df0 | 353 | void ST25R3911::executeCommands(uint8_t *cmds, uint8_t length, ST25R3911* mST25, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 354 | { |
DiegoOstuni | 0:98fcd1266df0 | 355 | |
DiegoOstuni | 0:98fcd1266df0 | 356 | uint8_t index; |
DiegoOstuni | 0:98fcd1266df0 | 357 | |
DiegoOstuni | 0:98fcd1266df0 | 358 | for(index = 0; index < length; index++) |
DiegoOstuni | 0:98fcd1266df0 | 359 | { |
DiegoOstuni | 0:98fcd1266df0 | 360 | mST25 -> executeCommand(*cmds, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 361 | *cmds++; |
DiegoOstuni | 0:98fcd1266df0 | 362 | } |
DiegoOstuni | 0:98fcd1266df0 | 363 | |
DiegoOstuni | 0:98fcd1266df0 | 364 | return; |
DiegoOstuni | 0:98fcd1266df0 | 365 | } |
DiegoOstuni | 0:98fcd1266df0 | 366 | |
DiegoOstuni | 0:98fcd1266df0 | 367 | |
DiegoOstuni | 0:98fcd1266df0 | 368 | |
DiegoOstuni | 0:98fcd1266df0 | 369 | |
DiegoOstuni | 0:98fcd1266df0 | 370 | |
DiegoOstuni | 0:98fcd1266df0 | 371 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 372 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 373 | * \brief Writes values to ST25R3911 FIFO |
DiegoOstuni | 0:98fcd1266df0 | 374 | * |
DiegoOstuni | 0:98fcd1266df0 | 375 | * This function needs to be called in order to write to the ST25R3911 FIFO. |
DiegoOstuni | 0:98fcd1266df0 | 376 | * |
DiegoOstuni | 0:98fcd1266df0 | 377 | * \param[in] values: pointer to a buffer containing the values to be written |
DiegoOstuni | 0:98fcd1266df0 | 378 | * to the FIFO. |
DiegoOstuni | 0:98fcd1266df0 | 379 | * \param[in] length: Number of values to be written. |
DiegoOstuni | 0:98fcd1266df0 | 380 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 381 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 382 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 383 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 384 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 385 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 386 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 387 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 388 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 389 | * |
DiegoOstuni | 0:98fcd1266df0 | 390 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 391 | */ |
DiegoOstuni | 0:98fcd1266df0 | 392 | |
DiegoOstuni | 0:98fcd1266df0 | 393 | |
DiegoOstuni | 0:98fcd1266df0 | 394 | |
DiegoOstuni | 0:98fcd1266df0 | 395 | void ST25R3911::writeFifo(const uint8_t* val, uint8_t length, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 396 | { |
DiegoOstuni | 0:98fcd1266df0 | 397 | |
DiegoOstuni | 0:98fcd1266df0 | 398 | if (length > 0) |
DiegoOstuni | 0:98fcd1266df0 | 399 | { |
DiegoOstuni | 0:98fcd1266df0 | 400 | |
DiegoOstuni | 0:98fcd1266df0 | 401 | uint8_t cmd = ST25R3911_FIFO_LOAD; |
DiegoOstuni | 0:98fcd1266df0 | 402 | uint8_t values[length + 1]; |
DiegoOstuni | 0:98fcd1266df0 | 403 | values[0] = cmd; |
DiegoOstuni | 0:98fcd1266df0 | 404 | for(int i = 0 ; i < length; i++) |
DiegoOstuni | 0:98fcd1266df0 | 405 | values[i + 1] = *(val + i); |
DiegoOstuni | 0:98fcd1266df0 | 406 | |
DiegoOstuni | 0:98fcd1266df0 | 407 | IRQ->disable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 408 | *gpio_cs = 0; |
DiegoOstuni | 0:98fcd1266df0 | 409 | wait_us(50); |
DiegoOstuni | 0:98fcd1266df0 | 410 | mspiChannel -> write( (const char *)values , length + 1, NULL , NULL); |
DiegoOstuni | 0:98fcd1266df0 | 411 | *gpio_cs = 1; |
DiegoOstuni | 0:98fcd1266df0 | 412 | IRQ->enable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 413 | |
DiegoOstuni | 0:98fcd1266df0 | 414 | } |
DiegoOstuni | 0:98fcd1266df0 | 415 | |
DiegoOstuni | 0:98fcd1266df0 | 416 | return; |
DiegoOstuni | 0:98fcd1266df0 | 417 | } |
DiegoOstuni | 0:98fcd1266df0 | 418 | |
DiegoOstuni | 0:98fcd1266df0 | 419 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 420 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 421 | * \brief Read values from ST25R3911 FIFO |
DiegoOstuni | 0:98fcd1266df0 | 422 | * |
DiegoOstuni | 0:98fcd1266df0 | 423 | * This function needs to be called in order to read from ST25R3911 FIFO. |
DiegoOstuni | 0:98fcd1266df0 | 424 | * |
DiegoOstuni | 0:98fcd1266df0 | 425 | * \param[out] buf: pointer to a buffer where the FIFO content shall be |
DiegoOstuni | 0:98fcd1266df0 | 426 | * written to. |
DiegoOstuni | 0:98fcd1266df0 | 427 | * \param[in] length: Number of bytes to read. (= size of \a buf) |
DiegoOstuni | 0:98fcd1266df0 | 428 | * \note: This function doesn't check whether \a length is really the |
DiegoOstuni | 0:98fcd1266df0 | 429 | * number of available bytes in FIFO |
DiegoOstuni | 0:98fcd1266df0 | 430 | * \param[in] mspiChannel: Channel of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 431 | * \param[in] gpio_cs: Chip Select of the SPI |
DiegoOstuni | 0:98fcd1266df0 | 432 | * \param[in] IRQ: Interrupt line. Not implemented, It is a polling application. |
DiegoOstuni | 0:98fcd1266df0 | 433 | * \param[out] fieldLED_01: Digital Output of the LED1 |
DiegoOstuni | 0:98fcd1266df0 | 434 | * \param[out] fieldLED_02: Digital Output of the LED2 |
DiegoOstuni | 0:98fcd1266df0 | 435 | * \param[out] fieldLED_03: Digital Output of the LED3 |
DiegoOstuni | 0:98fcd1266df0 | 436 | * \param[out] fieldLED_04: Digital Output of the LED4 |
DiegoOstuni | 0:98fcd1266df0 | 437 | * \param[out] fieldLED_05: Digital Output of the LED5 |
DiegoOstuni | 0:98fcd1266df0 | 438 | * \param[out] fieldLED_06: Digital Output of the LED6 |
DiegoOstuni | 0:98fcd1266df0 | 439 | * |
DiegoOstuni | 0:98fcd1266df0 | 440 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 441 | */ |
DiegoOstuni | 0:98fcd1266df0 | 442 | |
DiegoOstuni | 0:98fcd1266df0 | 443 | void ST25R3911::readFifo(uint8_t* buf, uint8_t length, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 444 | { |
DiegoOstuni | 0:98fcd1266df0 | 445 | if (length > 0) |
DiegoOstuni | 0:98fcd1266df0 | 446 | { |
DiegoOstuni | 0:98fcd1266df0 | 447 | |
DiegoOstuni | 0:98fcd1266df0 | 448 | uint8_t cmd[2]; |
DiegoOstuni | 0:98fcd1266df0 | 449 | cmd[0] = ST25R3911_FIFO_READ; |
DiegoOstuni | 0:98fcd1266df0 | 450 | cmd[1] = 0; |
DiegoOstuni | 0:98fcd1266df0 | 451 | |
DiegoOstuni | 0:98fcd1266df0 | 452 | IRQ->disable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 453 | *gpio_cs = 0; |
DiegoOstuni | 0:98fcd1266df0 | 454 | wait_us(50); |
DiegoOstuni | 0:98fcd1266df0 | 455 | mspiChannel -> write((const char *)cmd, ST25R3911_CMD_LEN, NULL, NULL); |
DiegoOstuni | 0:98fcd1266df0 | 456 | mspiChannel -> write(NULL, NULL, (char *)buf, length); |
DiegoOstuni | 0:98fcd1266df0 | 457 | *gpio_cs = 1; |
DiegoOstuni | 0:98fcd1266df0 | 458 | IRQ->enable_irq(); |
DiegoOstuni | 0:98fcd1266df0 | 459 | |
DiegoOstuni | 0:98fcd1266df0 | 460 | } |
DiegoOstuni | 0:98fcd1266df0 | 461 | |
DiegoOstuni | 0:98fcd1266df0 | 462 | |
DiegoOstuni | 0:98fcd1266df0 | 463 | |
DiegoOstuni | 0:98fcd1266df0 | 464 | return ; |
DiegoOstuni | 0:98fcd1266df0 | 465 | } |
DiegoOstuni | 0:98fcd1266df0 | 466 | |
DiegoOstuni | 0:98fcd1266df0 | 467 | |
DiegoOstuni | 0:98fcd1266df0 | 468 | |
DiegoOstuni | 0:98fcd1266df0 | 469 | //////////////////////////////// |
DiegoOstuni | 0:98fcd1266df0 | 470 | void st25r3911TxRxOn( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 471 | { |
DiegoOstuni | 0:98fcd1266df0 | 472 | st25r3911SetRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 473 | } |
DiegoOstuni | 0:98fcd1266df0 | 474 | |
DiegoOstuni | 0:98fcd1266df0 | 475 | void st25r3911TxRxOff( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 476 | { |
DiegoOstuni | 0:98fcd1266df0 | 477 | st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 478 | } |
DiegoOstuni | 0:98fcd1266df0 | 479 | |
DiegoOstuni | 0:98fcd1266df0 | 480 | |
DiegoOstuni | 0:98fcd1266df0 | 481 | void st25r3911OscOn( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 482 | { |
DiegoOstuni | 0:98fcd1266df0 | 483 | uint8_t reg = 0; |
DiegoOstuni | 0:98fcd1266df0 | 484 | |
DiegoOstuni | 0:98fcd1266df0 | 485 | /* Make sure that oscillator is turned on and stable */ |
DiegoOstuni | 0:98fcd1266df0 | 486 | mST25 -> readRegister( ST25R3911_REG_OP_CONTROL, ®, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 487 | |
DiegoOstuni | 0:98fcd1266df0 | 488 | /* Use ST25R3911_REG_OP_CONTROL_en instead of ST25R3911_REG_AUX_DISPLAY_osc_ok to be on the safe side */ |
DiegoOstuni | 0:98fcd1266df0 | 489 | if (!(ST25R3911_REG_OP_CONTROL_en & reg)) |
DiegoOstuni | 0:98fcd1266df0 | 490 | { |
DiegoOstuni | 0:98fcd1266df0 | 491 | /* enable oscillator frequency stable interrupt */ |
DiegoOstuni | 0:98fcd1266df0 | 492 | st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_OSC, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 493 | |
DiegoOstuni | 0:98fcd1266df0 | 494 | /* enable oscillator and regulator output */ |
DiegoOstuni | 0:98fcd1266df0 | 495 | st25r3911ModifyRegister(ST25R3911_REG_OP_CONTROL, 0x00, ST25R3911_REG_OP_CONTROL_en, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 496 | |
DiegoOstuni | 0:98fcd1266df0 | 497 | /* wait for the oscillator interrupt */ |
DiegoOstuni | 0:98fcd1266df0 | 498 | st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_OSC, ST25R3911_OSC_STABLE_TIMEOUT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 499 | st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_OSC, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 500 | } |
DiegoOstuni | 0:98fcd1266df0 | 501 | |
DiegoOstuni | 0:98fcd1266df0 | 502 | } /* st25r3911OscOn() */ |
DiegoOstuni | 0:98fcd1266df0 | 503 | |
DiegoOstuni | 0:98fcd1266df0 | 504 | |
DiegoOstuni | 0:98fcd1266df0 | 505 | void st25r3911Initialize(SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 506 | { |
DiegoOstuni | 0:98fcd1266df0 | 507 | |
DiegoOstuni | 0:98fcd1266df0 | 508 | |
DiegoOstuni | 0:98fcd1266df0 | 509 | uint16_t vdd_mV; |
DiegoOstuni | 0:98fcd1266df0 | 510 | |
DiegoOstuni | 0:98fcd1266df0 | 511 | |
DiegoOstuni | 0:98fcd1266df0 | 512 | |
DiegoOstuni | 0:98fcd1266df0 | 513 | /* first, reset the st25r3911 */ |
DiegoOstuni | 0:98fcd1266df0 | 514 | mST25 -> executeCommand(ST25R3911_CMD_SET_DEFAULT, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 515 | |
DiegoOstuni | 0:98fcd1266df0 | 516 | |
DiegoOstuni | 0:98fcd1266df0 | 517 | /* enable pull downs on miso line */ |
DiegoOstuni | 0:98fcd1266df0 | 518 | st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2, 0, |
DiegoOstuni | 0:98fcd1266df0 | 519 | ST25R3911_REG_IO_CONF2_miso_pd1 | |
DiegoOstuni | 0:98fcd1266df0 | 520 | ST25R3911_REG_IO_CONF2_miso_pd2, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 521 | |
DiegoOstuni | 0:98fcd1266df0 | 522 | /* after reset all interrupts are enabled. so disable them at first */ |
DiegoOstuni | 0:98fcd1266df0 | 523 | st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 524 | /* and clear them, just to be sure... */ |
DiegoOstuni | 0:98fcd1266df0 | 525 | st25r3911ClearInterrupts( mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 526 | |
DiegoOstuni | 0:98fcd1266df0 | 527 | /* trim settings for VHBR board, will anyway changed later on */ |
DiegoOstuni | 0:98fcd1266df0 | 528 | mST25 -> writeRegister(ST25R3911_REG_ANT_CAL_TARGET, 0x80, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 529 | |
DiegoOstuni | 0:98fcd1266df0 | 530 | st25r3911OscOn( mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 531 | |
DiegoOstuni | 0:98fcd1266df0 | 532 | /* Measure vdd and set sup3V bit accordingly */ |
DiegoOstuni | 0:98fcd1266df0 | 533 | vdd_mV = st25r3911MeasureVoltage(ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 534 | |
DiegoOstuni | 0:98fcd1266df0 | 535 | st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2, |
DiegoOstuni | 0:98fcd1266df0 | 536 | ST25R3911_REG_IO_CONF2_sup3V, |
DiegoOstuni | 0:98fcd1266df0 | 537 | (vdd_mV < 3600)?ST25R3911_REG_IO_CONF2_sup3V:0, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 538 | |
DiegoOstuni | 0:98fcd1266df0 | 539 | /* Make sure Transmitter and Receiver are disabled */ |
DiegoOstuni | 0:98fcd1266df0 | 540 | st25r3911TxRxOff( mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 541 | |
DiegoOstuni | 0:98fcd1266df0 | 542 | return; |
DiegoOstuni | 0:98fcd1266df0 | 543 | } |
DiegoOstuni | 0:98fcd1266df0 | 544 | |
DiegoOstuni | 0:98fcd1266df0 | 545 | void st25r3911Deinitialize(SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 546 | { |
DiegoOstuni | 0:98fcd1266df0 | 547 | st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 548 | |
DiegoOstuni | 0:98fcd1266df0 | 549 | /* Disabe Tx and Rx, Keep OSC */ |
DiegoOstuni | 0:98fcd1266df0 | 550 | st25r3911TxRxOff( mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 551 | |
DiegoOstuni | 0:98fcd1266df0 | 552 | return; |
DiegoOstuni | 0:98fcd1266df0 | 553 | } |
DiegoOstuni | 0:98fcd1266df0 | 554 | |
DiegoOstuni | 0:98fcd1266df0 | 555 | ReturnCode st25r3911AdjustRegulators(uint16_t* result_mV, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 556 | { |
DiegoOstuni | 0:98fcd1266df0 | 557 | uint8_t result; |
DiegoOstuni | 0:98fcd1266df0 | 558 | uint8_t io_conf2; |
DiegoOstuni | 0:98fcd1266df0 | 559 | ReturnCode err = ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 560 | |
DiegoOstuni | 0:98fcd1266df0 | 561 | /* first check the status of the reg_s bit in ST25R3911_REG_VREG_DEF register. |
DiegoOstuni | 0:98fcd1266df0 | 562 | if this bit is set adjusting the regulators is not allowed */ |
DiegoOstuni | 0:98fcd1266df0 | 563 | mST25 -> readRegister(ST25R3911_REG_REGULATOR_CONTROL, &result, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 564 | |
DiegoOstuni | 0:98fcd1266df0 | 565 | if (result & ST25R3911_REG_REGULATOR_CONTROL_reg_s) |
DiegoOstuni | 0:98fcd1266df0 | 566 | { |
DiegoOstuni | 0:98fcd1266df0 | 567 | return ERR_REQUEST; |
DiegoOstuni | 0:98fcd1266df0 | 568 | } |
DiegoOstuni | 0:98fcd1266df0 | 569 | |
DiegoOstuni | 0:98fcd1266df0 | 570 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_ADJUST_REGULATORS, |
DiegoOstuni | 0:98fcd1266df0 | 571 | ST25R3911_REG_REGULATOR_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 572 | 5, |
DiegoOstuni | 0:98fcd1266df0 | 573 | &result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 574 | mST25 -> readRegister(ST25R3911_REG_IO_CONF2, &io_conf2, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 575 | |
DiegoOstuni | 0:98fcd1266df0 | 576 | result >>= ST25R3911_REG_REGULATOR_RESULT_shift_reg; |
DiegoOstuni | 0:98fcd1266df0 | 577 | result -= 5; |
DiegoOstuni | 0:98fcd1266df0 | 578 | if (result_mV) |
DiegoOstuni | 0:98fcd1266df0 | 579 | { |
DiegoOstuni | 0:98fcd1266df0 | 580 | if(io_conf2 & ST25R3911_REG_IO_CONF2_sup3V) |
DiegoOstuni | 0:98fcd1266df0 | 581 | { |
DiegoOstuni | 0:98fcd1266df0 | 582 | *result_mV = 2400; |
DiegoOstuni | 0:98fcd1266df0 | 583 | *result_mV += result * 100; |
DiegoOstuni | 0:98fcd1266df0 | 584 | } |
DiegoOstuni | 0:98fcd1266df0 | 585 | else |
DiegoOstuni | 0:98fcd1266df0 | 586 | { |
DiegoOstuni | 0:98fcd1266df0 | 587 | *result_mV = 3900; |
DiegoOstuni | 0:98fcd1266df0 | 588 | *result_mV += result * 120; |
DiegoOstuni | 0:98fcd1266df0 | 589 | } |
DiegoOstuni | 0:98fcd1266df0 | 590 | } |
DiegoOstuni | 0:98fcd1266df0 | 591 | return err; |
DiegoOstuni | 0:98fcd1266df0 | 592 | } |
DiegoOstuni | 0:98fcd1266df0 | 593 | |
DiegoOstuni | 0:98fcd1266df0 | 594 | void st25r3911MeasureRF(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 595 | { |
DiegoOstuni | 0:98fcd1266df0 | 596 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_AMPLITUDE, |
DiegoOstuni | 0:98fcd1266df0 | 597 | ST25R3911_REG_AD_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 598 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 599 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 600 | } |
DiegoOstuni | 0:98fcd1266df0 | 601 | |
DiegoOstuni | 0:98fcd1266df0 | 602 | void st25r3911MeasureCapacitance(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 603 | { |
DiegoOstuni | 0:98fcd1266df0 | 604 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_CAPACITANCE, |
DiegoOstuni | 0:98fcd1266df0 | 605 | ST25R3911_REG_AD_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 606 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 607 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 608 | } |
DiegoOstuni | 0:98fcd1266df0 | 609 | |
DiegoOstuni | 0:98fcd1266df0 | 610 | void st25r3911MeasureAntennaResonance(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 611 | { |
DiegoOstuni | 0:98fcd1266df0 | 612 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_PHASE, |
DiegoOstuni | 0:98fcd1266df0 | 613 | ST25R3911_REG_AD_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 614 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 615 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 616 | } |
DiegoOstuni | 0:98fcd1266df0 | 617 | |
DiegoOstuni | 0:98fcd1266df0 | 618 | void st25r3911CalibrateAntenna(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 619 | { |
DiegoOstuni | 0:98fcd1266df0 | 620 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_ANTENNA, |
DiegoOstuni | 0:98fcd1266df0 | 621 | ST25R3911_REG_ANT_CAL_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 622 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 623 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 624 | } |
DiegoOstuni | 0:98fcd1266df0 | 625 | |
DiegoOstuni | 0:98fcd1266df0 | 626 | void st25r3911CalibrateModulationDepth(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 627 | { |
DiegoOstuni | 0:98fcd1266df0 | 628 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_MODULATION, |
DiegoOstuni | 0:98fcd1266df0 | 629 | ST25R3911_REG_AM_MOD_DEPTH_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 630 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 631 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 632 | } |
DiegoOstuni | 0:98fcd1266df0 | 633 | |
DiegoOstuni | 0:98fcd1266df0 | 634 | |
DiegoOstuni | 0:98fcd1266df0 | 635 | void st25r3911CalibrateCapacitiveSensor(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 636 | { |
DiegoOstuni | 0:98fcd1266df0 | 637 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_C_SENSOR, |
DiegoOstuni | 0:98fcd1266df0 | 638 | ST25R3911_REG_CAP_SENSOR_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 639 | 10, |
DiegoOstuni | 0:98fcd1266df0 | 640 | result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 641 | } |
DiegoOstuni | 0:98fcd1266df0 | 642 | |
DiegoOstuni | 0:98fcd1266df0 | 643 | |
DiegoOstuni | 0:98fcd1266df0 | 644 | ReturnCode st25r3911SetBitrate(uint8_t txRate, uint8_t rxRate, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 645 | { |
DiegoOstuni | 0:98fcd1266df0 | 646 | uint8_t reg; |
DiegoOstuni | 0:98fcd1266df0 | 647 | |
DiegoOstuni | 0:98fcd1266df0 | 648 | mST25 -> readRegister(ST25R3911_REG_BIT_RATE, ®, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 649 | if (rxRate != ST25R3911_BR_DO_NOT_SET) |
DiegoOstuni | 0:98fcd1266df0 | 650 | { |
DiegoOstuni | 0:98fcd1266df0 | 651 | if(rxRate > ST25R3911_BR_3390) |
DiegoOstuni | 0:98fcd1266df0 | 652 | { |
DiegoOstuni | 0:98fcd1266df0 | 653 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 654 | } |
DiegoOstuni | 0:98fcd1266df0 | 655 | else |
DiegoOstuni | 0:98fcd1266df0 | 656 | { |
DiegoOstuni | 0:98fcd1266df0 | 657 | reg &= ~ST25R3911_REG_BIT_RATE_mask_rxrate; |
DiegoOstuni | 0:98fcd1266df0 | 658 | reg |= rxRate << ST25R3911_REG_BIT_RATE_shift_rxrate; |
DiegoOstuni | 0:98fcd1266df0 | 659 | } |
DiegoOstuni | 0:98fcd1266df0 | 660 | } |
DiegoOstuni | 0:98fcd1266df0 | 661 | if (txRate != ST25R3911_BR_DO_NOT_SET) |
DiegoOstuni | 0:98fcd1266df0 | 662 | { |
DiegoOstuni | 0:98fcd1266df0 | 663 | if(txRate > ST25R3911_BR_6780) |
DiegoOstuni | 0:98fcd1266df0 | 664 | { |
DiegoOstuni | 0:98fcd1266df0 | 665 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 666 | } |
DiegoOstuni | 0:98fcd1266df0 | 667 | else |
DiegoOstuni | 0:98fcd1266df0 | 668 | { |
DiegoOstuni | 0:98fcd1266df0 | 669 | reg &= ~ST25R3911_REG_BIT_RATE_mask_txrate; |
DiegoOstuni | 0:98fcd1266df0 | 670 | reg |= txRate<<ST25R3911_REG_BIT_RATE_shift_txrate; |
DiegoOstuni | 0:98fcd1266df0 | 671 | } |
DiegoOstuni | 0:98fcd1266df0 | 672 | } |
DiegoOstuni | 0:98fcd1266df0 | 673 | mST25 -> writeRegister(ST25R3911_REG_BIT_RATE, reg, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 674 | |
DiegoOstuni | 0:98fcd1266df0 | 675 | return ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 676 | } |
DiegoOstuni | 0:98fcd1266df0 | 677 | |
DiegoOstuni | 0:98fcd1266df0 | 678 | |
DiegoOstuni | 0:98fcd1266df0 | 679 | uint16_t st25r3911MeasureVoltage(uint8_t mpsv,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 680 | { |
DiegoOstuni | 0:98fcd1266df0 | 681 | uint8_t result; |
DiegoOstuni | 0:98fcd1266df0 | 682 | uint16_t mV; |
DiegoOstuni | 0:98fcd1266df0 | 683 | |
DiegoOstuni | 0:98fcd1266df0 | 684 | mpsv &= ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv; |
DiegoOstuni | 0:98fcd1266df0 | 685 | |
DiegoOstuni | 0:98fcd1266df0 | 686 | st25r3911ModifyRegister(ST25R3911_REG_REGULATOR_CONTROL, |
DiegoOstuni | 0:98fcd1266df0 | 687 | ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv, |
DiegoOstuni | 0:98fcd1266df0 | 688 | mpsv, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 689 | |
DiegoOstuni | 0:98fcd1266df0 | 690 | st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_VDD, |
DiegoOstuni | 0:98fcd1266df0 | 691 | ST25R3911_REG_AD_RESULT, |
DiegoOstuni | 0:98fcd1266df0 | 692 | 100, |
DiegoOstuni | 0:98fcd1266df0 | 693 | &result, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ); |
DiegoOstuni | 0:98fcd1266df0 | 694 | mV = ((uint16_t)result) * 23; |
DiegoOstuni | 0:98fcd1266df0 | 695 | mV += ((((uint16_t)result) * 438) + 500) / 1000; |
DiegoOstuni | 0:98fcd1266df0 | 696 | |
DiegoOstuni | 0:98fcd1266df0 | 697 | return mV; |
DiegoOstuni | 0:98fcd1266df0 | 698 | } |
DiegoOstuni | 0:98fcd1266df0 | 699 | |
DiegoOstuni | 0:98fcd1266df0 | 700 | |
DiegoOstuni | 0:98fcd1266df0 | 701 | uint8_t st25r3911GetNumFIFOLastBits( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 702 | { |
DiegoOstuni | 0:98fcd1266df0 | 703 | uint8_t reg; |
DiegoOstuni | 0:98fcd1266df0 | 704 | |
DiegoOstuni | 0:98fcd1266df0 | 705 | mST25 -> readRegister( ST25R3911_REG_FIFO_RX_STATUS2, ®, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 706 | |
DiegoOstuni | 0:98fcd1266df0 | 707 | return ((reg & ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb) >> ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb); |
DiegoOstuni | 0:98fcd1266df0 | 708 | } |
DiegoOstuni | 0:98fcd1266df0 | 709 | |
DiegoOstuni | 0:98fcd1266df0 | 710 | uint32_t st25r3911GetNoResponseTime_64fcs() |
DiegoOstuni | 0:98fcd1266df0 | 711 | { |
DiegoOstuni | 0:98fcd1266df0 | 712 | return st25r3911NoResponseTime_64fcs; |
DiegoOstuni | 0:98fcd1266df0 | 713 | } |
DiegoOstuni | 0:98fcd1266df0 | 714 | |
DiegoOstuni | 0:98fcd1266df0 | 715 | void st25r3911StartGPTimer_8fcs(uint16_t gpt_8fcs, uint8_t trigger_source, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 716 | { |
DiegoOstuni | 0:98fcd1266df0 | 717 | st25r3911SetGPTime_8fcs(gpt_8fcs, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 718 | |
DiegoOstuni | 0:98fcd1266df0 | 719 | st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL, |
DiegoOstuni | 0:98fcd1266df0 | 720 | ST25R3911_REG_GPT_CONTROL_gptc_mask, |
DiegoOstuni | 0:98fcd1266df0 | 721 | trigger_source, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 722 | if (!trigger_source) |
DiegoOstuni | 0:98fcd1266df0 | 723 | mST25 -> executeCommand(ST25R3911_CMD_START_GP_TIMER, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 724 | |
DiegoOstuni | 0:98fcd1266df0 | 725 | return; |
DiegoOstuni | 0:98fcd1266df0 | 726 | } |
DiegoOstuni | 0:98fcd1266df0 | 727 | |
DiegoOstuni | 0:98fcd1266df0 | 728 | void st25r3911SetGPTime_8fcs(uint16_t gpt_8fcs, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 729 | { |
DiegoOstuni | 0:98fcd1266df0 | 730 | mST25 -> writeRegister(ST25R3911_REG_GPT1, gpt_8fcs >> 8, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 731 | mST25 -> writeRegister(ST25R3911_REG_GPT2, gpt_8fcs & 0xff, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 732 | |
DiegoOstuni | 0:98fcd1266df0 | 733 | return; |
DiegoOstuni | 0:98fcd1266df0 | 734 | } |
DiegoOstuni | 0:98fcd1266df0 | 735 | |
DiegoOstuni | 0:98fcd1266df0 | 736 | bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t val, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 737 | { |
DiegoOstuni | 0:98fcd1266df0 | 738 | uint8_t regVal; |
DiegoOstuni | 0:98fcd1266df0 | 739 | |
DiegoOstuni | 0:98fcd1266df0 | 740 | regVal = 0; |
DiegoOstuni | 0:98fcd1266df0 | 741 | mST25 -> readRegister( reg, ®Val, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 742 | |
DiegoOstuni | 0:98fcd1266df0 | 743 | return ((regVal & mask) == val ); |
DiegoOstuni | 0:98fcd1266df0 | 744 | } |
DiegoOstuni | 0:98fcd1266df0 | 745 | |
DiegoOstuni | 0:98fcd1266df0 | 746 | |
DiegoOstuni | 0:98fcd1266df0 | 747 | bool st25r3911CheckChipID( uint8_t *rev, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 748 | { |
DiegoOstuni | 0:98fcd1266df0 | 749 | uint8_t ID; |
DiegoOstuni | 0:98fcd1266df0 | 750 | |
DiegoOstuni | 0:98fcd1266df0 | 751 | |
DiegoOstuni | 0:98fcd1266df0 | 752 | mST25 -> readRegister(ST25R3911_REG_IC_IDENTITY, &ID, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 753 | |
DiegoOstuni | 0:98fcd1266df0 | 754 | /* Check if IC Identity Register contains ST25R3911's IC type code */ |
DiegoOstuni | 0:98fcd1266df0 | 755 | if( (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_type) != (ST25R3911_REG_IC_IDENTITY_ic_type) ) |
DiegoOstuni | 0:98fcd1266df0 | 756 | { |
DiegoOstuni | 0:98fcd1266df0 | 757 | return false; |
DiegoOstuni | 0:98fcd1266df0 | 758 | } |
DiegoOstuni | 0:98fcd1266df0 | 759 | |
DiegoOstuni | 0:98fcd1266df0 | 760 | |
DiegoOstuni | 0:98fcd1266df0 | 761 | if(rev != NULL) |
DiegoOstuni | 0:98fcd1266df0 | 762 | { |
DiegoOstuni | 0:98fcd1266df0 | 763 | *rev = (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_rev); |
DiegoOstuni | 0:98fcd1266df0 | 764 | } |
DiegoOstuni | 0:98fcd1266df0 | 765 | |
DiegoOstuni | 0:98fcd1266df0 | 766 | return true; |
DiegoOstuni | 0:98fcd1266df0 | 767 | } |
DiegoOstuni | 0:98fcd1266df0 | 768 | |
DiegoOstuni | 0:98fcd1266df0 | 769 | ReturnCode st25r3911SetNoResponseTime_64fcs(uint32_t nrt_64fcs, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 770 | { |
DiegoOstuni | 0:98fcd1266df0 | 771 | ReturnCode err = ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 772 | uint8_t nrt_step = 0; |
DiegoOstuni | 0:98fcd1266df0 | 773 | |
DiegoOstuni | 0:98fcd1266df0 | 774 | st25r3911NoResponseTime_64fcs = nrt_64fcs; |
DiegoOstuni | 0:98fcd1266df0 | 775 | if (nrt_64fcs > USHRT_MAX) |
DiegoOstuni | 0:98fcd1266df0 | 776 | { |
DiegoOstuni | 0:98fcd1266df0 | 777 | nrt_step = ST25R3911_REG_GPT_CONTROL_nrt_step; |
DiegoOstuni | 0:98fcd1266df0 | 778 | nrt_64fcs = (nrt_64fcs + 63) / 64; |
DiegoOstuni | 0:98fcd1266df0 | 779 | if (nrt_64fcs > USHRT_MAX) |
DiegoOstuni | 0:98fcd1266df0 | 780 | { |
DiegoOstuni | 0:98fcd1266df0 | 781 | nrt_64fcs = USHRT_MAX; |
DiegoOstuni | 0:98fcd1266df0 | 782 | err = ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 783 | } |
DiegoOstuni | 0:98fcd1266df0 | 784 | st25r3911NoResponseTime_64fcs = 64 * nrt_64fcs; |
DiegoOstuni | 0:98fcd1266df0 | 785 | } |
DiegoOstuni | 0:98fcd1266df0 | 786 | |
DiegoOstuni | 0:98fcd1266df0 | 787 | st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_step, nrt_step, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 788 | mST25 -> writeRegister(ST25R3911_REG_NO_RESPONSE_TIMER1, nrt_64fcs >> 8, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 789 | mST25 -> writeRegister(ST25R3911_REG_NO_RESPONSE_TIMER2, nrt_64fcs & 0xff, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 790 | |
DiegoOstuni | 0:98fcd1266df0 | 791 | return err; |
DiegoOstuni | 0:98fcd1266df0 | 792 | } |
DiegoOstuni | 0:98fcd1266df0 | 793 | |
DiegoOstuni | 0:98fcd1266df0 | 794 | ReturnCode st25r3911SetStartNoResponseTime_64fcs(uint32_t nrt_64fcs, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 795 | { |
DiegoOstuni | 0:98fcd1266df0 | 796 | ReturnCode err; |
DiegoOstuni | 0:98fcd1266df0 | 797 | |
DiegoOstuni | 0:98fcd1266df0 | 798 | err = st25r3911SetNoResponseTime_64fcs( nrt_64fcs, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 799 | if(err == ERR_NONE) |
DiegoOstuni | 0:98fcd1266df0 | 800 | { |
DiegoOstuni | 0:98fcd1266df0 | 801 | mST25 -> executeCommand(ST25R3911_CMD_START_NO_RESPONSE_TIMER, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 802 | } |
DiegoOstuni | 0:98fcd1266df0 | 803 | |
DiegoOstuni | 0:98fcd1266df0 | 804 | return err; |
DiegoOstuni | 0:98fcd1266df0 | 805 | } |
DiegoOstuni | 0:98fcd1266df0 | 806 | |
DiegoOstuni | 0:98fcd1266df0 | 807 | ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 808 | { |
DiegoOstuni | 0:98fcd1266df0 | 809 | uint8_t treMask; |
DiegoOstuni | 0:98fcd1266df0 | 810 | uint32_t irqs; |
DiegoOstuni | 0:98fcd1266df0 | 811 | |
DiegoOstuni | 0:98fcd1266df0 | 812 | if( (FieldONCmd != ST25R3911_CMD_INITIAL_RF_COLLISION) && |
DiegoOstuni | 0:98fcd1266df0 | 813 | (FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_0) && |
DiegoOstuni | 0:98fcd1266df0 | 814 | (FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_N) ) |
DiegoOstuni | 0:98fcd1266df0 | 815 | { |
DiegoOstuni | 0:98fcd1266df0 | 816 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 817 | } |
DiegoOstuni | 0:98fcd1266df0 | 818 | |
DiegoOstuni | 0:98fcd1266df0 | 819 | /* Check if new thresholds are to be applied */ |
DiegoOstuni | 0:98fcd1266df0 | 820 | if( (pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) || (caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) ) |
DiegoOstuni | 0:98fcd1266df0 | 821 | { |
DiegoOstuni | 0:98fcd1266df0 | 822 | treMask = 0; |
DiegoOstuni | 0:98fcd1266df0 | 823 | |
DiegoOstuni | 0:98fcd1266df0 | 824 | if(pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) |
DiegoOstuni | 0:98fcd1266df0 | 825 | { |
DiegoOstuni | 0:98fcd1266df0 | 826 | treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_trg; |
DiegoOstuni | 0:98fcd1266df0 | 827 | } |
DiegoOstuni | 0:98fcd1266df0 | 828 | |
DiegoOstuni | 0:98fcd1266df0 | 829 | if(caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) |
DiegoOstuni | 0:98fcd1266df0 | 830 | { |
DiegoOstuni | 0:98fcd1266df0 | 831 | treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_rfe; |
DiegoOstuni | 0:98fcd1266df0 | 832 | } |
DiegoOstuni | 0:98fcd1266df0 | 833 | |
DiegoOstuni | 0:98fcd1266df0 | 834 | /* Set Detection Threshold and|or Collision Avoidance Threshold */ |
DiegoOstuni | 0:98fcd1266df0 | 835 | st25r3911ChangeRegisterBits( ST25R3911_REG_FIELD_THRESHOLD, treMask, (pdThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_trg) | (caThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_rfe ), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 836 | } |
DiegoOstuni | 0:98fcd1266df0 | 837 | |
DiegoOstuni | 0:98fcd1266df0 | 838 | /* Set n x TRFW */ |
DiegoOstuni | 0:98fcd1266df0 | 839 | st25r3911ModifyRegister(ST25R3911_REG_AUX, ST25R3911_REG_AUX_mask_nfc_n, (nTRFW & ST25R3911_REG_AUX_mask_nfc_n), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 840 | |
DiegoOstuni | 0:98fcd1266df0 | 841 | /* Enable and clear CA specific interrupts and execute command */ |
DiegoOstuni | 0:98fcd1266df0 | 842 | st25r3911EnableInterrupts( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 843 | st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 844 | |
DiegoOstuni | 0:98fcd1266df0 | 845 | mST25 -> executeCommand(FieldONCmd, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 846 | |
DiegoOstuni | 0:98fcd1266df0 | 847 | irqs = st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT, ST25R3911_CA_TIMEOUT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 848 | |
DiegoOstuni | 0:98fcd1266df0 | 849 | /* Clear any previous External Field events and disable CA specific interrupts */ |
DiegoOstuni | 0:98fcd1266df0 | 850 | st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_EON), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 851 | st25r3911DisableInterrupts((ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ); |
DiegoOstuni | 0:98fcd1266df0 | 852 | |
DiegoOstuni | 0:98fcd1266df0 | 853 | |
DiegoOstuni | 0:98fcd1266df0 | 854 | if(ST25R3911_IRQ_MASK_CAC & irqs) /* Collision occurred */ |
DiegoOstuni | 0:98fcd1266df0 | 855 | { |
DiegoOstuni | 0:98fcd1266df0 | 856 | return ERR_RF_COLLISION; |
DiegoOstuni | 0:98fcd1266df0 | 857 | } |
DiegoOstuni | 0:98fcd1266df0 | 858 | |
DiegoOstuni | 0:98fcd1266df0 | 859 | if(ST25R3911_IRQ_MASK_CAT & irqs) /* No Collision detected, Field On */ |
DiegoOstuni | 0:98fcd1266df0 | 860 | { |
DiegoOstuni | 0:98fcd1266df0 | 861 | return ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 862 | } |
DiegoOstuni | 0:98fcd1266df0 | 863 | |
DiegoOstuni | 0:98fcd1266df0 | 864 | /* No interrupt detected */ |
DiegoOstuni | 0:98fcd1266df0 | 865 | return ERR_INTERNAL; |
DiegoOstuni | 0:98fcd1266df0 | 866 | } |
DiegoOstuni | 0:98fcd1266df0 | 867 | |
DiegoOstuni | 0:98fcd1266df0 | 868 | ReturnCode st25r3911GetRegsDump(uint8_t* resRegDump, uint8_t* sizeRegDump, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 869 | { |
DiegoOstuni | 0:98fcd1266df0 | 870 | uint8_t regIt; |
DiegoOstuni | 0:98fcd1266df0 | 871 | uint8_t regDump[ST25R3911_REG_IC_IDENTITY+1]; |
DiegoOstuni | 0:98fcd1266df0 | 872 | |
DiegoOstuni | 0:98fcd1266df0 | 873 | if(!sizeRegDump || !resRegDump) |
DiegoOstuni | 0:98fcd1266df0 | 874 | { |
DiegoOstuni | 0:98fcd1266df0 | 875 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 876 | } |
DiegoOstuni | 0:98fcd1266df0 | 877 | |
DiegoOstuni | 0:98fcd1266df0 | 878 | for( regIt = ST25R3911_REG_IO_CONF1; regIt < SIZEOF_ARRAY(regDump); regIt++ ) |
DiegoOstuni | 0:98fcd1266df0 | 879 | { |
DiegoOstuni | 0:98fcd1266df0 | 880 | mST25 -> readRegister(regIt, ®Dump[regIt], mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 881 | } |
DiegoOstuni | 0:98fcd1266df0 | 882 | |
DiegoOstuni | 0:98fcd1266df0 | 883 | *sizeRegDump = MIN(*sizeRegDump, regIt); |
DiegoOstuni | 0:98fcd1266df0 | 884 | ST_MEMCPY(resRegDump, regDump, *sizeRegDump ); |
DiegoOstuni | 0:98fcd1266df0 | 885 | |
DiegoOstuni | 0:98fcd1266df0 | 886 | return ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 887 | } |
DiegoOstuni | 0:98fcd1266df0 | 888 | |
DiegoOstuni | 0:98fcd1266df0 | 889 | |
DiegoOstuni | 0:98fcd1266df0 | 890 | void st25r3911SetNumTxBits( uint32_t nBits, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 891 | { |
DiegoOstuni | 0:98fcd1266df0 | 892 | mST25 -> writeRegister(ST25R3911_REG_NUM_TX_BYTES2, (uint8_t)((nBits >> 0) & 0xff), mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 893 | mST25 -> writeRegister(ST25R3911_REG_NUM_TX_BYTES1, (uint8_t)((nBits >> 8) & 0xff), mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 894 | } |
DiegoOstuni | 0:98fcd1266df0 | 895 | |
DiegoOstuni | 0:98fcd1266df0 | 896 | |
DiegoOstuni | 0:98fcd1266df0 | 897 | bool st25r3911IsCmdValid( uint8_t cmd ) |
DiegoOstuni | 0:98fcd1266df0 | 898 | { |
DiegoOstuni | 0:98fcd1266df0 | 899 | if( !((cmd >= ST25R3911_CMD_SET_DEFAULT) && (cmd <= ST25R3911_CMD_ANALOG_PRESET)) && |
DiegoOstuni | 0:98fcd1266df0 | 900 | !((cmd >= ST25R3911_CMD_MASK_RECEIVE_DATA) && (cmd <= ST25R3911_CMD_CLEAR_RSSI)) && |
DiegoOstuni | 0:98fcd1266df0 | 901 | !((cmd >= ST25R3911_CMD_TRANSPARENT_MODE) && (cmd <= ST25R3911_CMD_START_NO_RESPONSE_TIMER)) && |
DiegoOstuni | 0:98fcd1266df0 | 902 | !((cmd >= ST25R3911_CMD_TEST_CLEARA) && (cmd <= ST25R3911_CMD_FUSE_PPROM)) ) |
DiegoOstuni | 0:98fcd1266df0 | 903 | { |
DiegoOstuni | 0:98fcd1266df0 | 904 | return false; |
DiegoOstuni | 0:98fcd1266df0 | 905 | } |
DiegoOstuni | 0:98fcd1266df0 | 906 | return true; |
DiegoOstuni | 0:98fcd1266df0 | 907 | } |
DiegoOstuni | 0:98fcd1266df0 | 908 | |
DiegoOstuni | 0:98fcd1266df0 | 909 | ReturnCode st25r3911StreamConfigure(const struct st25r3911StreamConfig *config, SPI* mspiChannel, ST25R3911* mST25, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 910 | { |
DiegoOstuni | 0:98fcd1266df0 | 911 | uint8_t smd = 0; |
DiegoOstuni | 0:98fcd1266df0 | 912 | uint8_t mode; |
DiegoOstuni | 0:98fcd1266df0 | 913 | |
DiegoOstuni | 0:98fcd1266df0 | 914 | if (config->useBPSK) |
DiegoOstuni | 0:98fcd1266df0 | 915 | { |
DiegoOstuni | 0:98fcd1266df0 | 916 | mode = ST25R3911_REG_MODE_om_bpsk_stream; |
DiegoOstuni | 0:98fcd1266df0 | 917 | if (config->din<2 || config->din>4) /* not in fc/4 .. fc/16 */ |
DiegoOstuni | 0:98fcd1266df0 | 918 | { |
DiegoOstuni | 0:98fcd1266df0 | 919 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 920 | } |
DiegoOstuni | 0:98fcd1266df0 | 921 | smd |= (4 - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf; |
DiegoOstuni | 0:98fcd1266df0 | 922 | |
DiegoOstuni | 0:98fcd1266df0 | 923 | } |
DiegoOstuni | 0:98fcd1266df0 | 924 | else |
DiegoOstuni | 0:98fcd1266df0 | 925 | { |
DiegoOstuni | 0:98fcd1266df0 | 926 | mode = ST25R3911_REG_MODE_om_subcarrier_stream; |
DiegoOstuni | 0:98fcd1266df0 | 927 | if (config->din<3 || config->din>6) /* not in fc/8 .. fc/64 */ |
DiegoOstuni | 0:98fcd1266df0 | 928 | { |
DiegoOstuni | 0:98fcd1266df0 | 929 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 930 | } |
DiegoOstuni | 0:98fcd1266df0 | 931 | smd |= (6 - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf; |
DiegoOstuni | 0:98fcd1266df0 | 932 | if (config->report_period_length == 0) |
DiegoOstuni | 0:98fcd1266df0 | 933 | { |
DiegoOstuni | 0:98fcd1266df0 | 934 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 935 | } |
DiegoOstuni | 0:98fcd1266df0 | 936 | } |
DiegoOstuni | 0:98fcd1266df0 | 937 | |
DiegoOstuni | 0:98fcd1266df0 | 938 | if (config->dout<1 || config->dout>7) /* not in fc/2 .. fc/128 */ |
DiegoOstuni | 0:98fcd1266df0 | 939 | { |
DiegoOstuni | 0:98fcd1266df0 | 940 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 941 | } |
DiegoOstuni | 0:98fcd1266df0 | 942 | smd |= (7 - config->dout) << ST25R3911_REG_STREAM_MODE_shift_stx; |
DiegoOstuni | 0:98fcd1266df0 | 943 | |
DiegoOstuni | 0:98fcd1266df0 | 944 | if (config->report_period_length > 3) |
DiegoOstuni | 0:98fcd1266df0 | 945 | { |
DiegoOstuni | 0:98fcd1266df0 | 946 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 947 | } |
DiegoOstuni | 0:98fcd1266df0 | 948 | smd |= config->report_period_length << ST25R3911_REG_STREAM_MODE_shift_scp; |
DiegoOstuni | 0:98fcd1266df0 | 949 | |
DiegoOstuni | 0:98fcd1266df0 | 950 | mST25 -> writeRegister(ST25R3911_REG_STREAM_MODE, smd, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 951 | st25r3911ChangeRegisterBits(ST25R3911_REG_MODE, ST25R3911_REG_MODE_mask_om, mode, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 952 | |
DiegoOstuni | 0:98fcd1266df0 | 953 | return ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 954 | } |
DiegoOstuni | 0:98fcd1266df0 | 955 | |
DiegoOstuni | 0:98fcd1266df0 | 956 | bool st25r3911IrqIsWakeUpCap( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 957 | { |
DiegoOstuni | 0:98fcd1266df0 | 958 | return ( st25r3911GetInterrupt( ST25R3911_IRQ_MASK_WCAP, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ? true : false ); |
DiegoOstuni | 0:98fcd1266df0 | 959 | } |
DiegoOstuni | 0:98fcd1266df0 | 960 | |
DiegoOstuni | 0:98fcd1266df0 | 961 | |
DiegoOstuni | 0:98fcd1266df0 | 962 | bool st25r3911IrqIsWakeUpPhase( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 963 | { |
DiegoOstuni | 0:98fcd1266df0 | 964 | return ( st25r3911GetInterrupt( ST25R3911_IRQ_MASK_WPH, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ? true : false ); |
DiegoOstuni | 0:98fcd1266df0 | 965 | } |
DiegoOstuni | 0:98fcd1266df0 | 966 | |
DiegoOstuni | 0:98fcd1266df0 | 967 | |
DiegoOstuni | 0:98fcd1266df0 | 968 | bool st25r3911IrqIsWakeUpAmplitude( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 969 | { |
DiegoOstuni | 0:98fcd1266df0 | 970 | return ( st25r3911GetInterrupt( ST25R3911_IRQ_MASK_WAM, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ? true : false ); |
DiegoOstuni | 0:98fcd1266df0 | 971 | } |
DiegoOstuni | 0:98fcd1266df0 | 972 | |
DiegoOstuni | 0:98fcd1266df0 | 973 | /* |
DiegoOstuni | 0:98fcd1266df0 | 974 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 975 | * LOCAL FUNCTIONS |
DiegoOstuni | 0:98fcd1266df0 | 976 | ****************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 977 | */ |
DiegoOstuni | 0:98fcd1266df0 | 978 | /*! |
DiegoOstuni | 0:98fcd1266df0 | 979 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 980 | * \brief Executes a direct command and returns the result |
DiegoOstuni | 0:98fcd1266df0 | 981 | * |
DiegoOstuni | 0:98fcd1266df0 | 982 | * This function executes the direct command given by \a cmd waits for |
DiegoOstuni | 0:98fcd1266df0 | 983 | * \a sleeptime and returns the result read from register \a resreg. |
DiegoOstuni | 0:98fcd1266df0 | 984 | * |
DiegoOstuni | 0:98fcd1266df0 | 985 | * \param[in] cmd: direct command to execute. |
DiegoOstuni | 0:98fcd1266df0 | 986 | * \param[in] resreg: Address of the register containing the result. |
DiegoOstuni | 0:98fcd1266df0 | 987 | * \param[in] sleeptime: time in milliseconds to wait before reading the result. |
DiegoOstuni | 0:98fcd1266df0 | 988 | * \param[out] result: 8 bit long result |
DiegoOstuni | 0:98fcd1266df0 | 989 | * |
DiegoOstuni | 0:98fcd1266df0 | 990 | ***************************************************************************** |
DiegoOstuni | 0:98fcd1266df0 | 991 | */ |
DiegoOstuni | 0:98fcd1266df0 | 992 | static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:98fcd1266df0 | 993 | { |
DiegoOstuni | 0:98fcd1266df0 | 994 | |
DiegoOstuni | 0:98fcd1266df0 | 995 | if ( (cmd >= ST25R3911_CMD_INITIAL_RF_COLLISION && cmd <= ST25R3911_CMD_RESPONSE_RF_COLLISION_0) |
DiegoOstuni | 0:98fcd1266df0 | 996 | || (cmd == ST25R3911_CMD_MEASURE_AMPLITUDE) |
DiegoOstuni | 0:98fcd1266df0 | 997 | || (cmd >= ST25R3911_CMD_ADJUST_REGULATORS && cmd <= ST25R3911_CMD_MEASURE_PHASE) |
DiegoOstuni | 0:98fcd1266df0 | 998 | || (cmd >= ST25R3911_CMD_CALIBRATE_C_SENSOR && cmd <= ST25R3911_CMD_MEASURE_VDD) |
DiegoOstuni | 0:98fcd1266df0 | 999 | || (cmd >= 0xFD && cmd <= 0xFE ) |
DiegoOstuni | 0:98fcd1266df0 | 1000 | ) |
DiegoOstuni | 0:98fcd1266df0 | 1001 | { |
DiegoOstuni | 0:98fcd1266df0 | 1002 | st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_DCT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1003 | st25r3911GetInterrupt(ST25R3911_IRQ_MASK_DCT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1004 | mST25 -> executeCommand(cmd, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1005 | st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_DCT, sleeptime, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1006 | st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_DCT, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1007 | } |
DiegoOstuni | 0:98fcd1266df0 | 1008 | else |
DiegoOstuni | 0:98fcd1266df0 | 1009 | { |
DiegoOstuni | 0:98fcd1266df0 | 1010 | return ERR_PARAM; |
DiegoOstuni | 0:98fcd1266df0 | 1011 | } |
DiegoOstuni | 0:98fcd1266df0 | 1012 | |
DiegoOstuni | 0:98fcd1266df0 | 1013 | /* read out the result if the pointer is not NULL */ |
DiegoOstuni | 0:98fcd1266df0 | 1014 | if (result) |
DiegoOstuni | 0:98fcd1266df0 | 1015 | mST25 -> readRegister(resreg, result, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:98fcd1266df0 | 1016 | |
DiegoOstuni | 0:98fcd1266df0 | 1017 | return ERR_NONE; |
DiegoOstuni | 0:98fcd1266df0 | 1018 | |
DiegoOstuni | 0:98fcd1266df0 | 1019 | } |