TI LDC1000 library.
ldc1000.cpp@0:b9daf55d7586, 2017-04-05 (annotated)
- Committer:
- jonebuckman
- Date:
- Wed Apr 05 20:34:42 2017 +0000
- Revision:
- 0:b9daf55d7586
First release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jonebuckman | 0:b9daf55d7586 | 1 | /** |
jonebuckman | 0:b9daf55d7586 | 2 | * @file ldc1000.cpp |
jonebuckman | 0:b9daf55d7586 | 3 | * |
jonebuckman | 0:b9daf55d7586 | 4 | * @author Jon Buckman |
jonebuckman | 0:b9daf55d7586 | 5 | * |
jonebuckman | 0:b9daf55d7586 | 6 | * @section LICENSE |
jonebuckman | 0:b9daf55d7586 | 7 | * |
jonebuckman | 0:b9daf55d7586 | 8 | * Copyright (c) 2014 Jon Buckman |
jonebuckman | 0:b9daf55d7586 | 9 | * |
jonebuckman | 0:b9daf55d7586 | 10 | * This program is free software: you can redistribute it and/or modify |
jonebuckman | 0:b9daf55d7586 | 11 | * it under the terms of the GNU General Public License as published by |
jonebuckman | 0:b9daf55d7586 | 12 | * the Free Software Foundation, either version 3 of the License, or |
jonebuckman | 0:b9daf55d7586 | 13 | * (at your option) any later version. |
jonebuckman | 0:b9daf55d7586 | 14 | * |
jonebuckman | 0:b9daf55d7586 | 15 | * This program is distributed in the hope that it will be useful, |
jonebuckman | 0:b9daf55d7586 | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
jonebuckman | 0:b9daf55d7586 | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jonebuckman | 0:b9daf55d7586 | 18 | * GNU General Public License for more details. |
jonebuckman | 0:b9daf55d7586 | 19 | * |
jonebuckman | 0:b9daf55d7586 | 20 | * You should have received a copy of the GNU General Public License |
jonebuckman | 0:b9daf55d7586 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
jonebuckman | 0:b9daf55d7586 | 22 | * |
jonebuckman | 0:b9daf55d7586 | 23 | * The above copyright notice and this permission notice shall be included in |
jonebuckman | 0:b9daf55d7586 | 24 | * all copies or substantial portions of the Software. |
jonebuckman | 0:b9daf55d7586 | 25 | * |
jonebuckman | 0:b9daf55d7586 | 26 | * @section DESCRIPTION |
jonebuckman | 0:b9daf55d7586 | 27 | * |
jonebuckman | 0:b9daf55d7586 | 28 | * LDC1000 Inductance to Digital Converter from Texas Instruments. |
jonebuckman | 0:b9daf55d7586 | 29 | * |
jonebuckman | 0:b9daf55d7586 | 30 | * Datasheet: |
jonebuckman | 0:b9daf55d7586 | 31 | * |
jonebuckman | 0:b9daf55d7586 | 32 | * http://www.ti.com/lit/ds/symlink/ldc1000.pdf |
jonebuckman | 0:b9daf55d7586 | 33 | */ |
jonebuckman | 0:b9daf55d7586 | 34 | |
jonebuckman | 0:b9daf55d7586 | 35 | /** |
jonebuckman | 0:b9daf55d7586 | 36 | * Includes |
jonebuckman | 0:b9daf55d7586 | 37 | */ |
jonebuckman | 0:b9daf55d7586 | 38 | #include "ldc1000.h" |
jonebuckman | 0:b9daf55d7586 | 39 | |
jonebuckman | 0:b9daf55d7586 | 40 | /** |
jonebuckman | 0:b9daf55d7586 | 41 | * Defines |
jonebuckman | 0:b9daf55d7586 | 42 | * |
jonebuckman | 0:b9daf55d7586 | 43 | * (Note that all defines here start with an underscore, e.g. '_LDC1000_MODE_UNKNOWN', |
jonebuckman | 0:b9daf55d7586 | 44 | * and are local to this library. The defines in the ldc1000.h file do not start |
jonebuckman | 0:b9daf55d7586 | 45 | * with the underscore, and can be used by code to access this library.) |
jonebuckman | 0:b9daf55d7586 | 46 | */ |
jonebuckman | 0:b9daf55d7586 | 47 | |
jonebuckman | 0:b9daf55d7586 | 48 | typedef enum { |
jonebuckman | 0:b9daf55d7586 | 49 | _LDC1000_MODE_UNKNOWN, |
jonebuckman | 0:b9daf55d7586 | 50 | _LDC1000_MODE_POWER_DOWN, |
jonebuckman | 0:b9daf55d7586 | 51 | _LDC1000_MODE_STANDBY, |
jonebuckman | 0:b9daf55d7586 | 52 | } LDC1000_Mode_Type; |
jonebuckman | 0:b9daf55d7586 | 53 | |
jonebuckman | 0:b9daf55d7586 | 54 | /** |
jonebuckman | 0:b9daf55d7586 | 55 | * Registers |
jonebuckman | 0:b9daf55d7586 | 56 | */ |
jonebuckman | 0:b9daf55d7586 | 57 | #define _LDC1000_DEVICE_ID 0x00 |
jonebuckman | 0:b9daf55d7586 | 58 | #define _LDC1000_RP_MAX 0x01 |
jonebuckman | 0:b9daf55d7586 | 59 | #define _LDC1000_RP_MIN 0x02 |
jonebuckman | 0:b9daf55d7586 | 60 | #define _LDC1000_SENSOR_FREQ 0x03 |
jonebuckman | 0:b9daf55d7586 | 61 | #define _LDC1000_LDC_CONFIG 0x04 |
jonebuckman | 0:b9daf55d7586 | 62 | #define _LDC1000_CLK_CONFIG 0x05 |
jonebuckman | 0:b9daf55d7586 | 63 | #define _LDC1000_CMP_THLD_HI_LSB 0x06 |
jonebuckman | 0:b9daf55d7586 | 64 | #define _LDC1000_CMP_THLD_HI_MSB 0x07 |
jonebuckman | 0:b9daf55d7586 | 65 | #define _LDC1000_CMP_THLD_LO_LSB 0x08 |
jonebuckman | 0:b9daf55d7586 | 66 | #define _LDC1000_CMP_THLD_LO_MSB 0x09 |
jonebuckman | 0:b9daf55d7586 | 67 | #define _LDC1000_INTB_PIN_CONFIG 0x0A |
jonebuckman | 0:b9daf55d7586 | 68 | #define _LDC1000_PWR_CONFIG 0x0B |
jonebuckman | 0:b9daf55d7586 | 69 | #define _LDC1000_STATUS 0x20 |
jonebuckman | 0:b9daf55d7586 | 70 | #define _LDC1000_PRX_DATA_LSB 0x21 |
jonebuckman | 0:b9daf55d7586 | 71 | #define _LDC1000_PRX_DATA_MSB 0x22 |
jonebuckman | 0:b9daf55d7586 | 72 | #define _LDC1000_FREQ_CNT_DATA_LSB 0x23 |
jonebuckman | 0:b9daf55d7586 | 73 | #define _LDC1000_FREQ_CNT_DATA_MIDB 0x24 |
jonebuckman | 0:b9daf55d7586 | 74 | #define _LDC1000_FREQ_CNT_DATA_MSB 0x25 |
jonebuckman | 0:b9daf55d7586 | 75 | |
jonebuckman | 0:b9daf55d7586 | 76 | /** |
jonebuckman | 0:b9daf55d7586 | 77 | * LDC Configuration Masks |
jonebuckman | 0:b9daf55d7586 | 78 | */ |
jonebuckman | 0:b9daf55d7586 | 79 | #define _LDC1000_LDC_CONFIG_MASK_AMP (0x03<<3) |
jonebuckman | 0:b9daf55d7586 | 80 | #define _LDC1000_LDC_CONFIG_MASK_RESP (0x07<<0) |
jonebuckman | 0:b9daf55d7586 | 81 | #define _LDC1000_CLK_CONFIG_MASK_SEL (0x01<<1) |
jonebuckman | 0:b9daf55d7586 | 82 | #define _LDC1000_CLK_CONFIG_MASK_PD (0x01<<0) |
jonebuckman | 0:b9daf55d7586 | 83 | #define _LDC1000_INTB_PIN_CONFIG_MASK_MODE (0x07<<0) |
jonebuckman | 0:b9daf55d7586 | 84 | #define _LDC1000_STATUS_MASK (0x08<<4) |
jonebuckman | 0:b9daf55d7586 | 85 | #define _LDC1000_PWR_CONFIG_MASK (0x01<<0) |
jonebuckman | 0:b9daf55d7586 | 86 | |
jonebuckman | 0:b9daf55d7586 | 87 | /** |
jonebuckman | 0:b9daf55d7586 | 88 | * LDC SPI |
jonebuckman | 0:b9daf55d7586 | 89 | */ |
jonebuckman | 0:b9daf55d7586 | 90 | #define _LDC1000_SPI_CMD_RD_REG 0x80 |
jonebuckman | 0:b9daf55d7586 | 91 | #define _LDC1000_SPI_CMD_WR_REG 0x00 |
jonebuckman | 0:b9daf55d7586 | 92 | #define _LDC1000_REG_ADDRESS_MASK 0x7f |
jonebuckman | 0:b9daf55d7586 | 93 | #define _LDC1000_SPI_CMD_NOP 0xff |
jonebuckman | 0:b9daf55d7586 | 94 | #define _LDC1000_SPI_MAX_DATA_RATE 10000000 |
jonebuckman | 0:b9daf55d7586 | 95 | |
jonebuckman | 0:b9daf55d7586 | 96 | /** |
jonebuckman | 0:b9daf55d7586 | 97 | * LDC Timing |
jonebuckman | 0:b9daf55d7586 | 98 | */ |
jonebuckman | 0:b9daf55d7586 | 99 | #define _LDC1000_TIMING_Tundef2pd_us 100000 // 100mS |
jonebuckman | 0:b9daf55d7586 | 100 | #define _LDC1000_TIMING_Tstby2a_us 130 // 130uS |
jonebuckman | 0:b9daf55d7586 | 101 | #define _LDC1000_TIMING_Thce_us 10 // 10uS |
jonebuckman | 0:b9daf55d7586 | 102 | #define _LDC1000_TIMING_Tpd2stby_us 4500 // 4.5mS worst case |
jonebuckman | 0:b9daf55d7586 | 103 | #define _LDC1000_TIMING_Tpece2csn_us 4 // 4uS |
jonebuckman | 0:b9daf55d7586 | 104 | |
jonebuckman | 0:b9daf55d7586 | 105 | /** |
jonebuckman | 0:b9daf55d7586 | 106 | * Methods |
jonebuckman | 0:b9daf55d7586 | 107 | */ |
jonebuckman | 0:b9daf55d7586 | 108 | LDC1000::LDC1000(PinName mosi, |
jonebuckman | 0:b9daf55d7586 | 109 | PinName miso, |
jonebuckman | 0:b9daf55d7586 | 110 | PinName sck, |
jonebuckman | 0:b9daf55d7586 | 111 | PinName csn, |
jonebuckman | 0:b9daf55d7586 | 112 | PinName irq) : spi_(mosi, miso, sck), nCS_(csn), nIRQ_(irq) { |
jonebuckman | 0:b9daf55d7586 | 113 | |
jonebuckman | 0:b9daf55d7586 | 114 | mode = _LDC1000_MODE_UNKNOWN; |
jonebuckman | 0:b9daf55d7586 | 115 | |
jonebuckman | 0:b9daf55d7586 | 116 | nCS_ = 1; |
jonebuckman | 0:b9daf55d7586 | 117 | |
jonebuckman | 0:b9daf55d7586 | 118 | spi_.frequency(_LDC1000_SPI_MAX_DATA_RATE/5); // 2Mbit, 1/5th the maximum transfer rate for the SPI bus |
jonebuckman | 0:b9daf55d7586 | 119 | spi_.format(8,0); // 8-bit, ClockPhase = 0, ClockPolarity = 0 |
jonebuckman | 0:b9daf55d7586 | 120 | |
jonebuckman | 0:b9daf55d7586 | 121 | wait_us(_LDC1000_TIMING_Tundef2pd_us); // Wait for Power-on reset |
jonebuckman | 0:b9daf55d7586 | 122 | |
jonebuckman | 0:b9daf55d7586 | 123 | setRegister(_LDC1000_PWR_CONFIG, 0); // Power Down |
jonebuckman | 0:b9daf55d7586 | 124 | |
jonebuckman | 0:b9daf55d7586 | 125 | // |
jonebuckman | 0:b9daf55d7586 | 126 | // Setup default configuration |
jonebuckman | 0:b9daf55d7586 | 127 | // |
jonebuckman | 0:b9daf55d7586 | 128 | setSensorFrequency(179); |
jonebuckman | 0:b9daf55d7586 | 129 | |
jonebuckman | 0:b9daf55d7586 | 130 | mode = _LDC1000_MODE_POWER_DOWN; |
jonebuckman | 0:b9daf55d7586 | 131 | |
jonebuckman | 0:b9daf55d7586 | 132 | } |
jonebuckman | 0:b9daf55d7586 | 133 | |
jonebuckman | 0:b9daf55d7586 | 134 | |
jonebuckman | 0:b9daf55d7586 | 135 | int LDC1000::getDeviceID(void) { |
jonebuckman | 0:b9daf55d7586 | 136 | |
jonebuckman | 0:b9daf55d7586 | 137 | int value = getRegister(_LDC1000_DEVICE_ID); |
jonebuckman | 0:b9daf55d7586 | 138 | |
jonebuckman | 0:b9daf55d7586 | 139 | return (value); |
jonebuckman | 0:b9daf55d7586 | 140 | |
jonebuckman | 0:b9daf55d7586 | 141 | } |
jonebuckman | 0:b9daf55d7586 | 142 | |
jonebuckman | 0:b9daf55d7586 | 143 | void LDC1000::setSensorFrequency(int frequency) { |
jonebuckman | 0:b9daf55d7586 | 144 | |
jonebuckman | 0:b9daf55d7586 | 145 | if ( ( frequency < LDC1000_MIN_SENSOR_FREQUENCY ) || ( frequency > LDC1000_MAX_SENSOR_FREQUENCY ) ) { |
jonebuckman | 0:b9daf55d7586 | 146 | |
jonebuckman | 0:b9daf55d7586 | 147 | error( "LDC1000: Invalid Sensor Frequency setting %d\r\n", frequency ); |
jonebuckman | 0:b9daf55d7586 | 148 | return; |
jonebuckman | 0:b9daf55d7586 | 149 | |
jonebuckman | 0:b9daf55d7586 | 150 | } |
jonebuckman | 0:b9daf55d7586 | 151 | |
jonebuckman | 0:b9daf55d7586 | 152 | setRegister(_LDC1000_SENSOR_FREQ, frequency); |
jonebuckman | 0:b9daf55d7586 | 153 | |
jonebuckman | 0:b9daf55d7586 | 154 | } |
jonebuckman | 0:b9daf55d7586 | 155 | |
jonebuckman | 0:b9daf55d7586 | 156 | |
jonebuckman | 0:b9daf55d7586 | 157 | int LDC1000::getSensorFrequency(void) { |
jonebuckman | 0:b9daf55d7586 | 158 | |
jonebuckman | 0:b9daf55d7586 | 159 | int value = getRegister(_LDC1000_SENSOR_FREQ); |
jonebuckman | 0:b9daf55d7586 | 160 | |
jonebuckman | 0:b9daf55d7586 | 161 | return (value); |
jonebuckman | 0:b9daf55d7586 | 162 | |
jonebuckman | 0:b9daf55d7586 | 163 | } |
jonebuckman | 0:b9daf55d7586 | 164 | |
jonebuckman | 0:b9daf55d7586 | 165 | |
jonebuckman | 0:b9daf55d7586 | 166 | void LDC1000::setRpMaximum(int rp) { |
jonebuckman | 0:b9daf55d7586 | 167 | |
jonebuckman | 0:b9daf55d7586 | 168 | if ( ( rp < 0 ) || ( rp > 0x1f ) ) { |
jonebuckman | 0:b9daf55d7586 | 169 | |
jonebuckman | 0:b9daf55d7586 | 170 | error( "LDC1000: Invalid Rp maximum setting %d\r\n", rp ); |
jonebuckman | 0:b9daf55d7586 | 171 | return; |
jonebuckman | 0:b9daf55d7586 | 172 | |
jonebuckman | 0:b9daf55d7586 | 173 | } |
jonebuckman | 0:b9daf55d7586 | 174 | |
jonebuckman | 0:b9daf55d7586 | 175 | setRegister(_LDC1000_RP_MAX, rp); |
jonebuckman | 0:b9daf55d7586 | 176 | |
jonebuckman | 0:b9daf55d7586 | 177 | } |
jonebuckman | 0:b9daf55d7586 | 178 | |
jonebuckman | 0:b9daf55d7586 | 179 | |
jonebuckman | 0:b9daf55d7586 | 180 | int LDC1000::getRpMaximum(void) { |
jonebuckman | 0:b9daf55d7586 | 181 | |
jonebuckman | 0:b9daf55d7586 | 182 | int value = getRegister(_LDC1000_RP_MAX); |
jonebuckman | 0:b9daf55d7586 | 183 | |
jonebuckman | 0:b9daf55d7586 | 184 | return (value); |
jonebuckman | 0:b9daf55d7586 | 185 | |
jonebuckman | 0:b9daf55d7586 | 186 | } |
jonebuckman | 0:b9daf55d7586 | 187 | |
jonebuckman | 0:b9daf55d7586 | 188 | |
jonebuckman | 0:b9daf55d7586 | 189 | void LDC1000::setRpMinimum(int rp) { |
jonebuckman | 0:b9daf55d7586 | 190 | |
jonebuckman | 0:b9daf55d7586 | 191 | if ( ( rp < 0x20 ) || ( rp > 0x3f ) ) { |
jonebuckman | 0:b9daf55d7586 | 192 | |
jonebuckman | 0:b9daf55d7586 | 193 | error( "LDC1000: Invalid Rp minimum setting %d\r\n", rp ); |
jonebuckman | 0:b9daf55d7586 | 194 | return; |
jonebuckman | 0:b9daf55d7586 | 195 | |
jonebuckman | 0:b9daf55d7586 | 196 | } |
jonebuckman | 0:b9daf55d7586 | 197 | |
jonebuckman | 0:b9daf55d7586 | 198 | setRegister(_LDC1000_RP_MIN, rp); |
jonebuckman | 0:b9daf55d7586 | 199 | |
jonebuckman | 0:b9daf55d7586 | 200 | } |
jonebuckman | 0:b9daf55d7586 | 201 | |
jonebuckman | 0:b9daf55d7586 | 202 | |
jonebuckman | 0:b9daf55d7586 | 203 | int LDC1000::getRpMinimum(void) { |
jonebuckman | 0:b9daf55d7586 | 204 | |
jonebuckman | 0:b9daf55d7586 | 205 | int value = getRegister(_LDC1000_RP_MIN); |
jonebuckman | 0:b9daf55d7586 | 206 | |
jonebuckman | 0:b9daf55d7586 | 207 | return (value); |
jonebuckman | 0:b9daf55d7586 | 208 | |
jonebuckman | 0:b9daf55d7586 | 209 | } |
jonebuckman | 0:b9daf55d7586 | 210 | |
jonebuckman | 0:b9daf55d7586 | 211 | |
jonebuckman | 0:b9daf55d7586 | 212 | void LDC1000::setOscAmplitude(int oscamp) { |
jonebuckman | 0:b9daf55d7586 | 213 | |
jonebuckman | 0:b9daf55d7586 | 214 | if ( ( oscamp < 0 ) || ( oscamp > 2 ) ) { |
jonebuckman | 0:b9daf55d7586 | 215 | |
jonebuckman | 0:b9daf55d7586 | 216 | error( "LDC1000: Invalid oscillation amplitude setting %d\r\n", oscamp ); |
jonebuckman | 0:b9daf55d7586 | 217 | return; |
jonebuckman | 0:b9daf55d7586 | 218 | |
jonebuckman | 0:b9daf55d7586 | 219 | } |
jonebuckman | 0:b9daf55d7586 | 220 | |
jonebuckman | 0:b9daf55d7586 | 221 | int value = getRegister(_LDC1000_LDC_CONFIG) & ~_LDC1000_LDC_CONFIG_MASK_AMP; |
jonebuckman | 0:b9daf55d7586 | 222 | |
jonebuckman | 0:b9daf55d7586 | 223 | value |= oscamp; |
jonebuckman | 0:b9daf55d7586 | 224 | |
jonebuckman | 0:b9daf55d7586 | 225 | setRegister(_LDC1000_LDC_CONFIG, value); |
jonebuckman | 0:b9daf55d7586 | 226 | |
jonebuckman | 0:b9daf55d7586 | 227 | } |
jonebuckman | 0:b9daf55d7586 | 228 | |
jonebuckman | 0:b9daf55d7586 | 229 | |
jonebuckman | 0:b9daf55d7586 | 230 | int LDC1000::getOscAmplitude(void) { |
jonebuckman | 0:b9daf55d7586 | 231 | |
jonebuckman | 0:b9daf55d7586 | 232 | int value = getRegister(_LDC1000_LDC_CONFIG) & ~_LDC1000_LDC_CONFIG_MASK_AMP; |
jonebuckman | 0:b9daf55d7586 | 233 | |
jonebuckman | 0:b9daf55d7586 | 234 | return (value); |
jonebuckman | 0:b9daf55d7586 | 235 | |
jonebuckman | 0:b9daf55d7586 | 236 | } |
jonebuckman | 0:b9daf55d7586 | 237 | |
jonebuckman | 0:b9daf55d7586 | 238 | |
jonebuckman | 0:b9daf55d7586 | 239 | void LDC1000::setResponseTime(int resp) { |
jonebuckman | 0:b9daf55d7586 | 240 | |
jonebuckman | 0:b9daf55d7586 | 241 | if ( ( resp < 2 ) || ( resp > 7 ) ) { |
jonebuckman | 0:b9daf55d7586 | 242 | |
jonebuckman | 0:b9daf55d7586 | 243 | error( "LDC1000: Invalid response time setting %d\r\n", resp ); |
jonebuckman | 0:b9daf55d7586 | 244 | return; |
jonebuckman | 0:b9daf55d7586 | 245 | |
jonebuckman | 0:b9daf55d7586 | 246 | } |
jonebuckman | 0:b9daf55d7586 | 247 | |
jonebuckman | 0:b9daf55d7586 | 248 | int value = getRegister(_LDC1000_LDC_CONFIG) & ~_LDC1000_LDC_CONFIG_MASK_RESP; |
jonebuckman | 0:b9daf55d7586 | 249 | |
jonebuckman | 0:b9daf55d7586 | 250 | value |= resp; |
jonebuckman | 0:b9daf55d7586 | 251 | |
jonebuckman | 0:b9daf55d7586 | 252 | setRegister(_LDC1000_LDC_CONFIG, value); |
jonebuckman | 0:b9daf55d7586 | 253 | |
jonebuckman | 0:b9daf55d7586 | 254 | } |
jonebuckman | 0:b9daf55d7586 | 255 | |
jonebuckman | 0:b9daf55d7586 | 256 | |
jonebuckman | 0:b9daf55d7586 | 257 | int LDC1000::getResponseTime(void) { |
jonebuckman | 0:b9daf55d7586 | 258 | |
jonebuckman | 0:b9daf55d7586 | 259 | int value = getRegister(_LDC1000_LDC_CONFIG) & ~_LDC1000_LDC_CONFIG_MASK_RESP; |
jonebuckman | 0:b9daf55d7586 | 260 | |
jonebuckman | 0:b9daf55d7586 | 261 | return (value); |
jonebuckman | 0:b9daf55d7586 | 262 | |
jonebuckman | 0:b9daf55d7586 | 263 | } |
jonebuckman | 0:b9daf55d7586 | 264 | |
jonebuckman | 0:b9daf55d7586 | 265 | |
jonebuckman | 0:b9daf55d7586 | 266 | void LDC1000::setClockSelect(int sel) { |
jonebuckman | 0:b9daf55d7586 | 267 | |
jonebuckman | 0:b9daf55d7586 | 268 | int value = getRegister(_LDC1000_CLK_CONFIG) & ~_LDC1000_CLK_CONFIG_MASK_SEL; |
jonebuckman | 0:b9daf55d7586 | 269 | |
jonebuckman | 0:b9daf55d7586 | 270 | value |= sel; |
jonebuckman | 0:b9daf55d7586 | 271 | |
jonebuckman | 0:b9daf55d7586 | 272 | setRegister(_LDC1000_CLK_CONFIG, value); |
jonebuckman | 0:b9daf55d7586 | 273 | |
jonebuckman | 0:b9daf55d7586 | 274 | } |
jonebuckman | 0:b9daf55d7586 | 275 | |
jonebuckman | 0:b9daf55d7586 | 276 | |
jonebuckman | 0:b9daf55d7586 | 277 | int LDC1000::getClockSelect(void) { |
jonebuckman | 0:b9daf55d7586 | 278 | |
jonebuckman | 0:b9daf55d7586 | 279 | int value = getRegister(_LDC1000_CLK_CONFIG) & ~_LDC1000_CLK_CONFIG_MASK_SEL; |
jonebuckman | 0:b9daf55d7586 | 280 | |
jonebuckman | 0:b9daf55d7586 | 281 | return (value); |
jonebuckman | 0:b9daf55d7586 | 282 | |
jonebuckman | 0:b9daf55d7586 | 283 | } |
jonebuckman | 0:b9daf55d7586 | 284 | |
jonebuckman | 0:b9daf55d7586 | 285 | |
jonebuckman | 0:b9daf55d7586 | 286 | void LDC1000::setClockTimeBase(int pd) { |
jonebuckman | 0:b9daf55d7586 | 287 | |
jonebuckman | 0:b9daf55d7586 | 288 | int value = getRegister(_LDC1000_CLK_CONFIG) & ~_LDC1000_CLK_CONFIG_MASK_PD; |
jonebuckman | 0:b9daf55d7586 | 289 | |
jonebuckman | 0:b9daf55d7586 | 290 | value |= pd; |
jonebuckman | 0:b9daf55d7586 | 291 | |
jonebuckman | 0:b9daf55d7586 | 292 | setRegister(_LDC1000_CLK_CONFIG, value); |
jonebuckman | 0:b9daf55d7586 | 293 | |
jonebuckman | 0:b9daf55d7586 | 294 | } |
jonebuckman | 0:b9daf55d7586 | 295 | |
jonebuckman | 0:b9daf55d7586 | 296 | |
jonebuckman | 0:b9daf55d7586 | 297 | int LDC1000::getClockTimeBase(void) { |
jonebuckman | 0:b9daf55d7586 | 298 | |
jonebuckman | 0:b9daf55d7586 | 299 | int value = getRegister(_LDC1000_CLK_CONFIG) & ~_LDC1000_CLK_CONFIG_MASK_PD; |
jonebuckman | 0:b9daf55d7586 | 300 | |
jonebuckman | 0:b9daf55d7586 | 301 | return (value); |
jonebuckman | 0:b9daf55d7586 | 302 | |
jonebuckman | 0:b9daf55d7586 | 303 | } |
jonebuckman | 0:b9daf55d7586 | 304 | |
jonebuckman | 0:b9daf55d7586 | 305 | |
jonebuckman | 0:b9daf55d7586 | 306 | void LDC1000::setComparatorThresholdHighLSB(int data) { |
jonebuckman | 0:b9daf55d7586 | 307 | |
jonebuckman | 0:b9daf55d7586 | 308 | setRegister(_LDC1000_CMP_THLD_HI_LSB, data); |
jonebuckman | 0:b9daf55d7586 | 309 | |
jonebuckman | 0:b9daf55d7586 | 310 | } |
jonebuckman | 0:b9daf55d7586 | 311 | |
jonebuckman | 0:b9daf55d7586 | 312 | |
jonebuckman | 0:b9daf55d7586 | 313 | int LDC1000::getComparatorThresholdHighLSB(void) { |
jonebuckman | 0:b9daf55d7586 | 314 | |
jonebuckman | 0:b9daf55d7586 | 315 | int value = getRegister(_LDC1000_CMP_THLD_HI_LSB); |
jonebuckman | 0:b9daf55d7586 | 316 | |
jonebuckman | 0:b9daf55d7586 | 317 | return (value); |
jonebuckman | 0:b9daf55d7586 | 318 | |
jonebuckman | 0:b9daf55d7586 | 319 | } |
jonebuckman | 0:b9daf55d7586 | 320 | |
jonebuckman | 0:b9daf55d7586 | 321 | |
jonebuckman | 0:b9daf55d7586 | 322 | void LDC1000::setComparatorThresholdHighMSB(int data) { |
jonebuckman | 0:b9daf55d7586 | 323 | |
jonebuckman | 0:b9daf55d7586 | 324 | setRegister(_LDC1000_CMP_THLD_HI_MSB, data); |
jonebuckman | 0:b9daf55d7586 | 325 | |
jonebuckman | 0:b9daf55d7586 | 326 | } |
jonebuckman | 0:b9daf55d7586 | 327 | |
jonebuckman | 0:b9daf55d7586 | 328 | |
jonebuckman | 0:b9daf55d7586 | 329 | int LDC1000::getComparatorThresholdHighMSB(void) { |
jonebuckman | 0:b9daf55d7586 | 330 | |
jonebuckman | 0:b9daf55d7586 | 331 | int value = getRegister(_LDC1000_CMP_THLD_HI_MSB); |
jonebuckman | 0:b9daf55d7586 | 332 | |
jonebuckman | 0:b9daf55d7586 | 333 | return (value); |
jonebuckman | 0:b9daf55d7586 | 334 | |
jonebuckman | 0:b9daf55d7586 | 335 | } |
jonebuckman | 0:b9daf55d7586 | 336 | |
jonebuckman | 0:b9daf55d7586 | 337 | |
jonebuckman | 0:b9daf55d7586 | 338 | void LDC1000::setComparatorThresholdLowLSB(int data) { |
jonebuckman | 0:b9daf55d7586 | 339 | |
jonebuckman | 0:b9daf55d7586 | 340 | setRegister(_LDC1000_CMP_THLD_LO_LSB, data); |
jonebuckman | 0:b9daf55d7586 | 341 | |
jonebuckman | 0:b9daf55d7586 | 342 | } |
jonebuckman | 0:b9daf55d7586 | 343 | |
jonebuckman | 0:b9daf55d7586 | 344 | |
jonebuckman | 0:b9daf55d7586 | 345 | int LDC1000::getComparatorThresholdLowLSB(void) { |
jonebuckman | 0:b9daf55d7586 | 346 | |
jonebuckman | 0:b9daf55d7586 | 347 | int value = getRegister(_LDC1000_CMP_THLD_LO_LSB); |
jonebuckman | 0:b9daf55d7586 | 348 | |
jonebuckman | 0:b9daf55d7586 | 349 | return (value); |
jonebuckman | 0:b9daf55d7586 | 350 | |
jonebuckman | 0:b9daf55d7586 | 351 | } |
jonebuckman | 0:b9daf55d7586 | 352 | |
jonebuckman | 0:b9daf55d7586 | 353 | |
jonebuckman | 0:b9daf55d7586 | 354 | void LDC1000::setINTBPin(int mode) { |
jonebuckman | 0:b9daf55d7586 | 355 | |
jonebuckman | 0:b9daf55d7586 | 356 | if ( ( mode < 0 ) || ( mode > 4 ) || ( mode == 3 ) ) { |
jonebuckman | 0:b9daf55d7586 | 357 | |
jonebuckman | 0:b9daf55d7586 | 358 | error( "LDC1000: Invalid INTB pin setting %d\r\n", mode ); |
jonebuckman | 0:b9daf55d7586 | 359 | return; |
jonebuckman | 0:b9daf55d7586 | 360 | |
jonebuckman | 0:b9daf55d7586 | 361 | } |
jonebuckman | 0:b9daf55d7586 | 362 | |
jonebuckman | 0:b9daf55d7586 | 363 | int value = getRegister(_LDC1000_INTB_PIN_CONFIG) & ~_LDC1000_INTB_PIN_CONFIG_MASK_MODE; |
jonebuckman | 0:b9daf55d7586 | 364 | |
jonebuckman | 0:b9daf55d7586 | 365 | value |= mode; |
jonebuckman | 0:b9daf55d7586 | 366 | |
jonebuckman | 0:b9daf55d7586 | 367 | setRegister(_LDC1000_INTB_PIN_CONFIG, value); |
jonebuckman | 0:b9daf55d7586 | 368 | |
jonebuckman | 0:b9daf55d7586 | 369 | } |
jonebuckman | 0:b9daf55d7586 | 370 | |
jonebuckman | 0:b9daf55d7586 | 371 | |
jonebuckman | 0:b9daf55d7586 | 372 | int LDC1000::getINTBPin(void) { |
jonebuckman | 0:b9daf55d7586 | 373 | |
jonebuckman | 0:b9daf55d7586 | 374 | int value = getRegister(_LDC1000_INTB_PIN_CONFIG) & ~_LDC1000_INTB_PIN_CONFIG_MASK_MODE; |
jonebuckman | 0:b9daf55d7586 | 375 | |
jonebuckman | 0:b9daf55d7586 | 376 | return (value); |
jonebuckman | 0:b9daf55d7586 | 377 | |
jonebuckman | 0:b9daf55d7586 | 378 | } |
jonebuckman | 0:b9daf55d7586 | 379 | |
jonebuckman | 0:b9daf55d7586 | 380 | |
jonebuckman | 0:b9daf55d7586 | 381 | void LDC1000::setPower(int data) { |
jonebuckman | 0:b9daf55d7586 | 382 | |
jonebuckman | 0:b9daf55d7586 | 383 | setRegister(_LDC1000_PWR_CONFIG, data & ~_LDC1000_PWR_CONFIG_MASK); |
jonebuckman | 0:b9daf55d7586 | 384 | |
jonebuckman | 0:b9daf55d7586 | 385 | } |
jonebuckman | 0:b9daf55d7586 | 386 | |
jonebuckman | 0:b9daf55d7586 | 387 | |
jonebuckman | 0:b9daf55d7586 | 388 | int LDC1000::getPower(void) { |
jonebuckman | 0:b9daf55d7586 | 389 | |
jonebuckman | 0:b9daf55d7586 | 390 | int value = getRegister(_LDC1000_PWR_CONFIG) & ~_LDC1000_PWR_CONFIG_MASK; |
jonebuckman | 0:b9daf55d7586 | 391 | |
jonebuckman | 0:b9daf55d7586 | 392 | return (value); |
jonebuckman | 0:b9daf55d7586 | 393 | |
jonebuckman | 0:b9daf55d7586 | 394 | } |
jonebuckman | 0:b9daf55d7586 | 395 | |
jonebuckman | 0:b9daf55d7586 | 396 | |
jonebuckman | 0:b9daf55d7586 | 397 | int LDC1000::getStatus(void) { |
jonebuckman | 0:b9daf55d7586 | 398 | |
jonebuckman | 0:b9daf55d7586 | 399 | int value = getRegister(_LDC1000_STATUS) & ~_LDC1000_STATUS_MASK; |
jonebuckman | 0:b9daf55d7586 | 400 | |
jonebuckman | 0:b9daf55d7586 | 401 | return (value); |
jonebuckman | 0:b9daf55d7586 | 402 | |
jonebuckman | 0:b9daf55d7586 | 403 | } |
jonebuckman | 0:b9daf55d7586 | 404 | |
jonebuckman | 0:b9daf55d7586 | 405 | |
jonebuckman | 0:b9daf55d7586 | 406 | int LDC1000::getProximityDataLSB(void) { |
jonebuckman | 0:b9daf55d7586 | 407 | |
jonebuckman | 0:b9daf55d7586 | 408 | int value = getRegister(_LDC1000_PRX_DATA_LSB); |
jonebuckman | 0:b9daf55d7586 | 409 | |
jonebuckman | 0:b9daf55d7586 | 410 | return (value); |
jonebuckman | 0:b9daf55d7586 | 411 | |
jonebuckman | 0:b9daf55d7586 | 412 | } |
jonebuckman | 0:b9daf55d7586 | 413 | |
jonebuckman | 0:b9daf55d7586 | 414 | |
jonebuckman | 0:b9daf55d7586 | 415 | int LDC1000::getProximityDataMSB(void) { |
jonebuckman | 0:b9daf55d7586 | 416 | |
jonebuckman | 0:b9daf55d7586 | 417 | int value = getRegister(_LDC1000_PRX_DATA_MSB); |
jonebuckman | 0:b9daf55d7586 | 418 | |
jonebuckman | 0:b9daf55d7586 | 419 | return (value); |
jonebuckman | 0:b9daf55d7586 | 420 | |
jonebuckman | 0:b9daf55d7586 | 421 | } |
jonebuckman | 0:b9daf55d7586 | 422 | |
jonebuckman | 0:b9daf55d7586 | 423 | |
jonebuckman | 0:b9daf55d7586 | 424 | int LDC1000::getFrequencyCounterLSB(void) { |
jonebuckman | 0:b9daf55d7586 | 425 | |
jonebuckman | 0:b9daf55d7586 | 426 | int value = getRegister(_LDC1000_FREQ_CNT_DATA_LSB); |
jonebuckman | 0:b9daf55d7586 | 427 | |
jonebuckman | 0:b9daf55d7586 | 428 | return (value); |
jonebuckman | 0:b9daf55d7586 | 429 | |
jonebuckman | 0:b9daf55d7586 | 430 | } |
jonebuckman | 0:b9daf55d7586 | 431 | |
jonebuckman | 0:b9daf55d7586 | 432 | |
jonebuckman | 0:b9daf55d7586 | 433 | int LDC1000::getFrequencyCounterMIDSB(void) { |
jonebuckman | 0:b9daf55d7586 | 434 | |
jonebuckman | 0:b9daf55d7586 | 435 | int value = getRegister(_LDC1000_FREQ_CNT_DATA_MIDB); |
jonebuckman | 0:b9daf55d7586 | 436 | |
jonebuckman | 0:b9daf55d7586 | 437 | return (value); |
jonebuckman | 0:b9daf55d7586 | 438 | |
jonebuckman | 0:b9daf55d7586 | 439 | } |
jonebuckman | 0:b9daf55d7586 | 440 | |
jonebuckman | 0:b9daf55d7586 | 441 | |
jonebuckman | 0:b9daf55d7586 | 442 | int LDC1000::getFrequencyCounterMSB(void) { |
jonebuckman | 0:b9daf55d7586 | 443 | |
jonebuckman | 0:b9daf55d7586 | 444 | int value = getRegister(_LDC1000_FREQ_CNT_DATA_MSB); |
jonebuckman | 0:b9daf55d7586 | 445 | |
jonebuckman | 0:b9daf55d7586 | 446 | return (value); |
jonebuckman | 0:b9daf55d7586 | 447 | |
jonebuckman | 0:b9daf55d7586 | 448 | } |
jonebuckman | 0:b9daf55d7586 | 449 | |
jonebuckman | 0:b9daf55d7586 | 450 | |
jonebuckman | 0:b9daf55d7586 | 451 | void LDC1000::setRegister(int regAddress, int regData) { |
jonebuckman | 0:b9daf55d7586 | 452 | |
jonebuckman | 0:b9daf55d7586 | 453 | int cn = (_LDC1000_SPI_CMD_WR_REG | (regAddress & _LDC1000_REG_ADDRESS_MASK)); |
jonebuckman | 0:b9daf55d7586 | 454 | |
jonebuckman | 0:b9daf55d7586 | 455 | nCS_ = 0; |
jonebuckman | 0:b9daf55d7586 | 456 | |
jonebuckman | 0:b9daf55d7586 | 457 | int status = spi_.write(cn); |
jonebuckman | 0:b9daf55d7586 | 458 | |
jonebuckman | 0:b9daf55d7586 | 459 | spi_.write(regData & 0xFF); |
jonebuckman | 0:b9daf55d7586 | 460 | |
jonebuckman | 0:b9daf55d7586 | 461 | nCS_ = 1; |
jonebuckman | 0:b9daf55d7586 | 462 | |
jonebuckman | 0:b9daf55d7586 | 463 | wait_us( _LDC1000_TIMING_Tpece2csn_us ); |
jonebuckman | 0:b9daf55d7586 | 464 | |
jonebuckman | 0:b9daf55d7586 | 465 | } |
jonebuckman | 0:b9daf55d7586 | 466 | |
jonebuckman | 0:b9daf55d7586 | 467 | |
jonebuckman | 0:b9daf55d7586 | 468 | int LDC1000::getRegister(int regAddress) { |
jonebuckman | 0:b9daf55d7586 | 469 | |
jonebuckman | 0:b9daf55d7586 | 470 | int cn = (_LDC1000_SPI_CMD_RD_REG | (regAddress & _LDC1000_REG_ADDRESS_MASK)); |
jonebuckman | 0:b9daf55d7586 | 471 | |
jonebuckman | 0:b9daf55d7586 | 472 | nCS_ = 0; |
jonebuckman | 0:b9daf55d7586 | 473 | |
jonebuckman | 0:b9daf55d7586 | 474 | int status = spi_.write(cn); |
jonebuckman | 0:b9daf55d7586 | 475 | |
jonebuckman | 0:b9daf55d7586 | 476 | int dn = spi_.write(_LDC1000_SPI_CMD_NOP); |
jonebuckman | 0:b9daf55d7586 | 477 | |
jonebuckman | 0:b9daf55d7586 | 478 | nCS_ = 1; |
jonebuckman | 0:b9daf55d7586 | 479 | |
jonebuckman | 0:b9daf55d7586 | 480 | return dn; |
jonebuckman | 0:b9daf55d7586 | 481 | |
jonebuckman | 0:b9daf55d7586 | 482 | } |
jonebuckman | 0:b9daf55d7586 | 483 |