Fork of the GitHub

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:36:52 2019 +0000
Revision:
0:98fcd1266df0
Fork of the GitHub

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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 Implementation of ST25R3911 communication.
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 #include "st25r3911_com.h"
DiegoOstuni 0:98fcd1266df0 44
DiegoOstuni 0:98fcd1266df0 45
DiegoOstuni 0:98fcd1266df0 46
DiegoOstuni 0:98fcd1266df0 47
DiegoOstuni 0:98fcd1266df0 48
DiegoOstuni 0:98fcd1266df0 49
DiegoOstuni 0:98fcd1266df0 50 /*
DiegoOstuni 0:98fcd1266df0 51 ******************************************************************************
DiegoOstuni 0:98fcd1266df0 52 * GLOBAL FUNCTIONS
DiegoOstuni 0:98fcd1266df0 53 ******************************************************************************
DiegoOstuni 0:98fcd1266df0 54 */
DiegoOstuni 0:98fcd1266df0 55
DiegoOstuni 0:98fcd1266df0 56 void st25r3911ReadTestRegister(uint8_t reg, uint8_t* val, 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 57 {
DiegoOstuni 0:98fcd1266df0 58
DiegoOstuni 0:98fcd1266df0 59
DiegoOstuni 0:98fcd1266df0 60 // uint8_t rx;
DiegoOstuni 0:98fcd1266df0 61 // val rx
DiegoOstuni 0:98fcd1266df0 62 mST25 -> executeCommand(ST25R3911_CMD_TEST_ACCESS, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 63 mST25 -> readRegister( reg, val, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 64
DiegoOstuni 0:98fcd1266df0 65
DiegoOstuni 0:98fcd1266df0 66 return;
DiegoOstuni 0:98fcd1266df0 67 }
DiegoOstuni 0:98fcd1266df0 68
DiegoOstuni 0:98fcd1266df0 69 void st25r3911WriteTestRegister(uint8_t reg, uint8_t val, 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 70 {
DiegoOstuni 0:98fcd1266df0 71
DiegoOstuni 0:98fcd1266df0 72
DiegoOstuni 0:98fcd1266df0 73 mST25 -> executeCommand(ST25R3911_CMD_TEST_ACCESS, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 74 mST25 -> writeRegister( reg, val, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 );
DiegoOstuni 0:98fcd1266df0 75
DiegoOstuni 0:98fcd1266df0 76
DiegoOstuni 0:98fcd1266df0 77 return;
DiegoOstuni 0:98fcd1266df0 78 }
DiegoOstuni 0:98fcd1266df0 79
DiegoOstuni 0:98fcd1266df0 80
DiegoOstuni 0:98fcd1266df0 81 void st25r3911ClrRegisterBits( uint8_t reg, uint8_t clr_mask, 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 82 {
DiegoOstuni 0:98fcd1266df0 83 uint8_t tmp;
DiegoOstuni 0:98fcd1266df0 84
DiegoOstuni 0:98fcd1266df0 85 mST25 -> readRegister( reg, &tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 86 tmp &= ~clr_mask;
DiegoOstuni 0:98fcd1266df0 87 mST25 -> writeRegister( reg, tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 88
DiegoOstuni 0:98fcd1266df0 89 return;
DiegoOstuni 0:98fcd1266df0 90 }
DiegoOstuni 0:98fcd1266df0 91
DiegoOstuni 0:98fcd1266df0 92
DiegoOstuni 0:98fcd1266df0 93 void st25r3911SetRegisterBits( uint8_t reg, uint8_t set_mask, 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 94 {
DiegoOstuni 0:98fcd1266df0 95 uint8_t tmp;
DiegoOstuni 0:98fcd1266df0 96
DiegoOstuni 0:98fcd1266df0 97 mST25 -> readRegister( reg, &tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 98 tmp |= set_mask;
DiegoOstuni 0:98fcd1266df0 99 mST25 -> writeRegister( reg, tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 100
DiegoOstuni 0:98fcd1266df0 101 return;
DiegoOstuni 0:98fcd1266df0 102 }
DiegoOstuni 0:98fcd1266df0 103
DiegoOstuni 0:98fcd1266df0 104 void st25r3911ChangeRegisterBits(uint8_t reg, uint8_t valueMask, uint8_t value, 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 105 {
DiegoOstuni 0:98fcd1266df0 106 st25r3911ModifyRegister(reg, valueMask, (valueMask & value), mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 107 }
DiegoOstuni 0:98fcd1266df0 108
DiegoOstuni 0:98fcd1266df0 109 void st25r3911ModifyRegister(uint8_t reg, uint8_t clr_mask, uint8_t set_mask, 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 110 {
DiegoOstuni 0:98fcd1266df0 111 uint8_t tmp;
DiegoOstuni 0:98fcd1266df0 112
DiegoOstuni 0:98fcd1266df0 113 mST25 -> readRegister( reg, &tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 114
DiegoOstuni 0:98fcd1266df0 115 /* mask out the bits we don't want to change */
DiegoOstuni 0:98fcd1266df0 116 tmp &= ~clr_mask;
DiegoOstuni 0:98fcd1266df0 117 /* set the new value */
DiegoOstuni 0:98fcd1266df0 118 tmp |= set_mask;
DiegoOstuni 0:98fcd1266df0 119 mST25 -> writeRegister( reg, tmp, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 120
DiegoOstuni 0:98fcd1266df0 121 return;
DiegoOstuni 0:98fcd1266df0 122 }
DiegoOstuni 0:98fcd1266df0 123
DiegoOstuni 0:98fcd1266df0 124 void st25r3911ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value, 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 125 {
DiegoOstuni 0:98fcd1266df0 126 uint8_t rdVal;
DiegoOstuni 0:98fcd1266df0 127 uint8_t wrVal;
DiegoOstuni 0:98fcd1266df0 128
DiegoOstuni 0:98fcd1266df0 129 /* Read current reg value */
DiegoOstuni 0:98fcd1266df0 130 st25r3911ReadTestRegister(reg, &rdVal, mST25, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 131
DiegoOstuni 0:98fcd1266df0 132 /* Compute new value */
DiegoOstuni 0:98fcd1266df0 133 wrVal = (rdVal & ~valueMask);
DiegoOstuni 0:98fcd1266df0 134 wrVal |= (value & valueMask);
DiegoOstuni 0:98fcd1266df0 135
DiegoOstuni 0:98fcd1266df0 136 /* Write new reg value */
DiegoOstuni 0:98fcd1266df0 137 st25r3911WriteTestRegister(reg, wrVal, mST25, mspiChannel, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:98fcd1266df0 138
DiegoOstuni 0:98fcd1266df0 139 return;
DiegoOstuni 0:98fcd1266df0 140 }
DiegoOstuni 0:98fcd1266df0 141
DiegoOstuni 0:98fcd1266df0 142
DiegoOstuni 0:98fcd1266df0 143
DiegoOstuni 0:98fcd1266df0 144 bool st25r3911IsRegValid( uint8_t reg )
DiegoOstuni 0:98fcd1266df0 145 {
DiegoOstuni 0:98fcd1266df0 146 if( !(( (int8_t)reg >= ST25R3911_REG_IO_CONF1) && (reg <= ST25R3911_REG_CAPACITANCE_MEASURE_RESULT)) &&
DiegoOstuni 0:98fcd1266df0 147 (reg != ST25R3911_REG_IC_IDENTITY) )
DiegoOstuni 0:98fcd1266df0 148 {
DiegoOstuni 0:98fcd1266df0 149 return false;
DiegoOstuni 0:98fcd1266df0 150 }
DiegoOstuni 0:98fcd1266df0 151 return true;
DiegoOstuni 0:98fcd1266df0 152 }
DiegoOstuni 0:98fcd1266df0 153
DiegoOstuni 0:98fcd1266df0 154 /*
DiegoOstuni 0:98fcd1266df0 155 ******************************************************************************
DiegoOstuni 0:98fcd1266df0 156 * LOCAL FUNCTIONS
DiegoOstuni 0:98fcd1266df0 157 ******************************************************************************
DiegoOstuni 0:98fcd1266df0 158 */
DiegoOstuni 0:98fcd1266df0 159