test

Committer:
etiene32
Date:
Wed Mar 06 14:01:46 2019 +0000
Revision:
0:cf2317282e61
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
etiene32 0:cf2317282e61 1 /**************************************************************************/
etiene32 0:cf2317282e61 2 /*!
etiene32 0:cf2317282e61 3 @file Adafruit_ADS1015.cpp
etiene32 0:cf2317282e61 4 @author K.Townsend (Adafruit Industries)
etiene32 0:cf2317282e61 5 @license BSD (see LICENSE.txt)
etiene32 0:cf2317282e61 6
etiene32 0:cf2317282e61 7 Ported to mbed by Arve Seljebu - arve0.github.io
etiene32 0:cf2317282e61 8
etiene32 0:cf2317282e61 9 Driver for the ADS1015/ADS1115 ADC
etiene32 0:cf2317282e61 10
etiene32 0:cf2317282e61 11 This is a library for the Adafruit MPL115A2 breakout
etiene32 0:cf2317282e61 12 ----> https://www.adafruit.com/products/1083
etiene32 0:cf2317282e61 13
etiene32 0:cf2317282e61 14 Adafruit invests time and resources providing this open source code,
etiene32 0:cf2317282e61 15 please support Adafruit and open-source hardware by purchasing
etiene32 0:cf2317282e61 16 products from Adafruit!
etiene32 0:cf2317282e61 17
etiene32 0:cf2317282e61 18 @section HISTORY
etiene32 0:cf2317282e61 19
etiene32 0:cf2317282e61 20 v1.0 - First release
etiene32 0:cf2317282e61 21 v1.1.1 - Ported to mbed
etiene32 0:cf2317282e61 22 */
etiene32 0:cf2317282e61 23 /**************************************************************************/
etiene32 0:cf2317282e61 24
etiene32 0:cf2317282e61 25 #include <mbed.h>
etiene32 0:cf2317282e61 26 #include "Adafruit_ADS1015.h"
etiene32 0:cf2317282e61 27
etiene32 0:cf2317282e61 28 /**************************************************************************/
etiene32 0:cf2317282e61 29 /*!
etiene32 0:cf2317282e61 30 @brief Writes 16-bits to the specified destination register
etiene32 0:cf2317282e61 31 */
etiene32 0:cf2317282e61 32 /**************************************************************************/
etiene32 0:cf2317282e61 33 void Adafruit_ADS1015::writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value)
etiene32 0:cf2317282e61 34 {
etiene32 0:cf2317282e61 35 char cmd[3];
etiene32 0:cf2317282e61 36 cmd[0] = (char)reg;
etiene32 0:cf2317282e61 37 cmd[1] = (char)(value>>8);
etiene32 0:cf2317282e61 38 cmd[2] = (char)(value & 0xFF);
etiene32 0:cf2317282e61 39 m_i2c->write(i2cAddress, cmd, 3);
etiene32 0:cf2317282e61 40 }
etiene32 0:cf2317282e61 41
etiene32 0:cf2317282e61 42 /**************************************************************************/
etiene32 0:cf2317282e61 43 /*!
etiene32 0:cf2317282e61 44 @brief Reads 16-bits from the specified register
etiene32 0:cf2317282e61 45 */
etiene32 0:cf2317282e61 46 /**************************************************************************/
etiene32 0:cf2317282e61 47 uint16_t Adafruit_ADS1015::readRegister(uint8_t i2cAddress, uint8_t reg)
etiene32 0:cf2317282e61 48 {
etiene32 0:cf2317282e61 49 char data[2];
etiene32 0:cf2317282e61 50 data[0] = reg; // temporary use this to send address to conversion register
etiene32 0:cf2317282e61 51 m_i2c->write(i2cAddress, data, 1);
etiene32 0:cf2317282e61 52 m_i2c->read(i2cAddress, data, 2);
etiene32 0:cf2317282e61 53 return (data[0] << 8 | data [1]);
etiene32 0:cf2317282e61 54 }
etiene32 0:cf2317282e61 55
etiene32 0:cf2317282e61 56 /**************************************************************************/
etiene32 0:cf2317282e61 57 /*!
etiene32 0:cf2317282e61 58 @brief Instantiates a new ADS1015 class w/appropriate properties
etiene32 0:cf2317282e61 59 */
etiene32 0:cf2317282e61 60 /**************************************************************************/
etiene32 0:cf2317282e61 61 Adafruit_ADS1015::Adafruit_ADS1015(I2C* i2c, uint8_t i2cAddress)
etiene32 0:cf2317282e61 62 {
etiene32 0:cf2317282e61 63 // shift 7 bit address 1 left: read expects 8 bit address, see I2C.h
etiene32 0:cf2317282e61 64 m_i2cAddress = i2cAddress << 1;
etiene32 0:cf2317282e61 65 m_conversionDelay = ADS1015_CONVERSIONDELAY;
etiene32 0:cf2317282e61 66 m_bitShift = 4;
etiene32 0:cf2317282e61 67 m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
etiene32 0:cf2317282e61 68 m_i2c = i2c;
etiene32 0:cf2317282e61 69 }
etiene32 0:cf2317282e61 70
etiene32 0:cf2317282e61 71 /**************************************************************************/
etiene32 0:cf2317282e61 72 /*!
etiene32 0:cf2317282e61 73 @brief Instantiates a new ADS1115 class w/appropriate properties
etiene32 0:cf2317282e61 74 */
etiene32 0:cf2317282e61 75 /**************************************************************************/
etiene32 0:cf2317282e61 76 Adafruit_ADS1115::Adafruit_ADS1115(I2C* i2c, uint8_t i2cAddress)
etiene32 0:cf2317282e61 77 {
etiene32 0:cf2317282e61 78 // shift 7 bit address 1 left: read expects 8 bit address, see mbed's I2C.h
etiene32 0:cf2317282e61 79 m_i2cAddress = i2cAddress << 1;
etiene32 0:cf2317282e61 80 m_conversionDelay = ADS1115_CONVERSIONDELAY;
etiene32 0:cf2317282e61 81 m_bitShift = 0;
etiene32 0:cf2317282e61 82 m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
etiene32 0:cf2317282e61 83 m_i2c = i2c;
etiene32 0:cf2317282e61 84 }
etiene32 0:cf2317282e61 85
etiene32 0:cf2317282e61 86 /**************************************************************************/
etiene32 0:cf2317282e61 87 /*!
etiene32 0:cf2317282e61 88 @brief Sets the gain and input voltage range
etiene32 0:cf2317282e61 89 */
etiene32 0:cf2317282e61 90 /**************************************************************************/
etiene32 0:cf2317282e61 91 void Adafruit_ADS1015::setGain(adsGain_t gain)
etiene32 0:cf2317282e61 92 {
etiene32 0:cf2317282e61 93 m_gain = gain;
etiene32 0:cf2317282e61 94 }
etiene32 0:cf2317282e61 95
etiene32 0:cf2317282e61 96 /**************************************************************************/
etiene32 0:cf2317282e61 97 /*!
etiene32 0:cf2317282e61 98 @brief Gets a gain and input voltage range
etiene32 0:cf2317282e61 99 */
etiene32 0:cf2317282e61 100 /**************************************************************************/
etiene32 0:cf2317282e61 101 adsGain_t Adafruit_ADS1015::getGain()
etiene32 0:cf2317282e61 102 {
etiene32 0:cf2317282e61 103 return m_gain;
etiene32 0:cf2317282e61 104 }
etiene32 0:cf2317282e61 105
etiene32 0:cf2317282e61 106 /**************************************************************************/
etiene32 0:cf2317282e61 107 /*!
etiene32 0:cf2317282e61 108 @brief Gets a single-ended ADC reading from the specified channel
etiene32 0:cf2317282e61 109 */
etiene32 0:cf2317282e61 110 /**************************************************************************/
etiene32 0:cf2317282e61 111 uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel)
etiene32 0:cf2317282e61 112 {
etiene32 0:cf2317282e61 113 if (channel > 3) {
etiene32 0:cf2317282e61 114 return 0;
etiene32 0:cf2317282e61 115 }
etiene32 0:cf2317282e61 116
etiene32 0:cf2317282e61 117 // Start with default values
etiene32 0:cf2317282e61 118 uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
etiene32 0:cf2317282e61 119 ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
etiene32 0:cf2317282e61 120 ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
etiene32 0:cf2317282e61 121 ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
etiene32 0:cf2317282e61 122 ADS1015_REG_CONFIG_DR_1600SPS | // 1600(ADS1015) or 250(ADS1115) samples per second (default)
etiene32 0:cf2317282e61 123 ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
etiene32 0:cf2317282e61 124
etiene32 0:cf2317282e61 125 // Set PGA/voltage range
etiene32 0:cf2317282e61 126 config |= m_gain;
etiene32 0:cf2317282e61 127
etiene32 0:cf2317282e61 128 // Set single-ended input channel
etiene32 0:cf2317282e61 129 switch (channel) {
etiene32 0:cf2317282e61 130 case (0):
etiene32 0:cf2317282e61 131 config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
etiene32 0:cf2317282e61 132 break;
etiene32 0:cf2317282e61 133 case (1):
etiene32 0:cf2317282e61 134 config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
etiene32 0:cf2317282e61 135 break;
etiene32 0:cf2317282e61 136 case (2):
etiene32 0:cf2317282e61 137 config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
etiene32 0:cf2317282e61 138 break;
etiene32 0:cf2317282e61 139 case (3):
etiene32 0:cf2317282e61 140 config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
etiene32 0:cf2317282e61 141 break;
etiene32 0:cf2317282e61 142 }
etiene32 0:cf2317282e61 143
etiene32 0:cf2317282e61 144 // Set 'start single-conversion' bit
etiene32 0:cf2317282e61 145 config |= ADS1015_REG_CONFIG_OS_SINGLE;
etiene32 0:cf2317282e61 146
etiene32 0:cf2317282e61 147 // Write config register to the ADC
etiene32 0:cf2317282e61 148 writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
etiene32 0:cf2317282e61 149
etiene32 0:cf2317282e61 150 // Wait for the conversion to complete
etiene32 0:cf2317282e61 151 wait_ms(m_conversionDelay);
etiene32 0:cf2317282e61 152
etiene32 0:cf2317282e61 153 // Read the conversion results
etiene32 0:cf2317282e61 154 // Shift 12-bit results right 4 bits for the ADS1015
etiene32 0:cf2317282e61 155 return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
etiene32 0:cf2317282e61 156 }
etiene32 0:cf2317282e61 157
etiene32 0:cf2317282e61 158 /**************************************************************************/
etiene32 0:cf2317282e61 159 /*!
etiene32 0:cf2317282e61 160 @brief Reads the conversion results, measuring the voltage
etiene32 0:cf2317282e61 161 difference between the P (AIN0) and N (AIN1) input. Generates
etiene32 0:cf2317282e61 162 a signed value since the difference can be either
etiene32 0:cf2317282e61 163 positive or negative.
etiene32 0:cf2317282e61 164 */
etiene32 0:cf2317282e61 165 /**************************************************************************/
etiene32 0:cf2317282e61 166 int16_t Adafruit_ADS1015::readADC_Differential_0_1()
etiene32 0:cf2317282e61 167 {
etiene32 0:cf2317282e61 168 // Start with default values
etiene32 0:cf2317282e61 169 uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
etiene32 0:cf2317282e61 170 ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
etiene32 0:cf2317282e61 171 ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
etiene32 0:cf2317282e61 172 ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
etiene32 0:cf2317282e61 173 ADS1015_REG_CONFIG_DR_1600SPS | // 1600(ADS1015) or 250(ADS1115) samples per second (default)
etiene32 0:cf2317282e61 174 ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
etiene32 0:cf2317282e61 175
etiene32 0:cf2317282e61 176 // Set PGA/voltage range
etiene32 0:cf2317282e61 177 config |= m_gain;
etiene32 0:cf2317282e61 178
etiene32 0:cf2317282e61 179 // Set channels
etiene32 0:cf2317282e61 180 config |= ADS1015_REG_CONFIG_MUX_DIFF_0_1; // AIN0 = P, AIN1 = N
etiene32 0:cf2317282e61 181
etiene32 0:cf2317282e61 182 // Set 'start single-conversion' bit
etiene32 0:cf2317282e61 183 config |= ADS1015_REG_CONFIG_OS_SINGLE;
etiene32 0:cf2317282e61 184
etiene32 0:cf2317282e61 185 // Write config register to the ADC
etiene32 0:cf2317282e61 186 writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
etiene32 0:cf2317282e61 187
etiene32 0:cf2317282e61 188 // Wait for the conversion to complete
etiene32 0:cf2317282e61 189 wait_ms(m_conversionDelay);
etiene32 0:cf2317282e61 190
etiene32 0:cf2317282e61 191 // Read the conversion results
etiene32 0:cf2317282e61 192 uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
etiene32 0:cf2317282e61 193 if (m_bitShift == 0) {
etiene32 0:cf2317282e61 194 return (int16_t)res;
etiene32 0:cf2317282e61 195 } else {
etiene32 0:cf2317282e61 196 // Shift 12-bit results right 4 bits for the ADS1015,
etiene32 0:cf2317282e61 197 // making sure we keep the sign bit intact
etiene32 0:cf2317282e61 198 if (res > 0x07FF) {
etiene32 0:cf2317282e61 199 // negative number - extend the sign to 16th bit
etiene32 0:cf2317282e61 200 res |= 0xF000;
etiene32 0:cf2317282e61 201 }
etiene32 0:cf2317282e61 202 return (int16_t)res;
etiene32 0:cf2317282e61 203 }
etiene32 0:cf2317282e61 204 }
etiene32 0:cf2317282e61 205
etiene32 0:cf2317282e61 206 /**************************************************************************/
etiene32 0:cf2317282e61 207 /*!
etiene32 0:cf2317282e61 208 @brief Reads the conversion results, measuring the voltage
etiene32 0:cf2317282e61 209 difference between the P (AIN2) and N (AIN3) input. Generates
etiene32 0:cf2317282e61 210 a signed value since the difference can be either
etiene32 0:cf2317282e61 211 positive or negative.
etiene32 0:cf2317282e61 212 */
etiene32 0:cf2317282e61 213 /**************************************************************************/
etiene32 0:cf2317282e61 214 int16_t Adafruit_ADS1015::readADC_Differential_2_3()
etiene32 0:cf2317282e61 215 {
etiene32 0:cf2317282e61 216 // Start with default values
etiene32 0:cf2317282e61 217 uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
etiene32 0:cf2317282e61 218 ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
etiene32 0:cf2317282e61 219 ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
etiene32 0:cf2317282e61 220 ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
etiene32 0:cf2317282e61 221 ADS1015_REG_CONFIG_DR_1600SPS | // 1600(ADS1015) or 250(ADS1115) samples per second (default)
etiene32 0:cf2317282e61 222 ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
etiene32 0:cf2317282e61 223
etiene32 0:cf2317282e61 224 // Set PGA/voltage range
etiene32 0:cf2317282e61 225 config |= m_gain;
etiene32 0:cf2317282e61 226
etiene32 0:cf2317282e61 227 // Set channels
etiene32 0:cf2317282e61 228 config |= ADS1015_REG_CONFIG_MUX_DIFF_2_3; // AIN2 = P, AIN3 = N
etiene32 0:cf2317282e61 229
etiene32 0:cf2317282e61 230 // Set 'start single-conversion' bit
etiene32 0:cf2317282e61 231 config |= ADS1015_REG_CONFIG_OS_SINGLE;
etiene32 0:cf2317282e61 232
etiene32 0:cf2317282e61 233 // Write config register to the ADC
etiene32 0:cf2317282e61 234 writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
etiene32 0:cf2317282e61 235
etiene32 0:cf2317282e61 236 // Wait for the conversion to complete
etiene32 0:cf2317282e61 237 wait_ms(m_conversionDelay);
etiene32 0:cf2317282e61 238
etiene32 0:cf2317282e61 239 // Read the conversion results
etiene32 0:cf2317282e61 240 uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
etiene32 0:cf2317282e61 241 if (m_bitShift == 0) {
etiene32 0:cf2317282e61 242 return (int16_t)res;
etiene32 0:cf2317282e61 243 } else {
etiene32 0:cf2317282e61 244 // Shift 12-bit results right 4 bits for the ADS1015,
etiene32 0:cf2317282e61 245 // making sure we keep the sign bit intact
etiene32 0:cf2317282e61 246 if (res > 0x07FF) {
etiene32 0:cf2317282e61 247 // negative number - extend the sign to 16th bit
etiene32 0:cf2317282e61 248 res |= 0xF000;
etiene32 0:cf2317282e61 249 }
etiene32 0:cf2317282e61 250 return (int16_t)res;
etiene32 0:cf2317282e61 251 }
etiene32 0:cf2317282e61 252 }
etiene32 0:cf2317282e61 253
etiene32 0:cf2317282e61 254 /**************************************************************************/
etiene32 0:cf2317282e61 255 /*!
etiene32 0:cf2317282e61 256 @brief Sets up the comparator to operate in basic mode, causing the
etiene32 0:cf2317282e61 257 ALERT/RDY pin to assert (go from high to low) when the ADC
etiene32 0:cf2317282e61 258 value exceeds the specified threshold.
etiene32 0:cf2317282e61 259
etiene32 0:cf2317282e61 260 This will also set the ADC in continuous conversion mode.
etiene32 0:cf2317282e61 261 */
etiene32 0:cf2317282e61 262 /**************************************************************************/
etiene32 0:cf2317282e61 263 void Adafruit_ADS1015::startComparator_SingleEnded(uint8_t channel, int16_t threshold)
etiene32 0:cf2317282e61 264 {
etiene32 0:cf2317282e61 265 // Start with default values
etiene32 0:cf2317282e61 266 uint16_t config = ADS1015_REG_CONFIG_CQUE_1CONV | // Comparator enabled and asserts on 1 match
etiene32 0:cf2317282e61 267 ADS1015_REG_CONFIG_CLAT_LATCH | // Latching mode
etiene32 0:cf2317282e61 268 ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
etiene32 0:cf2317282e61 269 ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
etiene32 0:cf2317282e61 270 ADS1015_REG_CONFIG_DR_1600SPS | // 1600(ADS1015) or 250(ADS1115) samples per second (default)
etiene32 0:cf2317282e61 271 ADS1015_REG_CONFIG_MODE_CONTIN | // Continuous conversion mode
etiene32 0:cf2317282e61 272 ADS1015_REG_CONFIG_MODE_CONTIN; // Continuous conversion mode
etiene32 0:cf2317282e61 273
etiene32 0:cf2317282e61 274 // Set PGA/voltage range
etiene32 0:cf2317282e61 275 config |= m_gain;
etiene32 0:cf2317282e61 276
etiene32 0:cf2317282e61 277 // Set single-ended input channel
etiene32 0:cf2317282e61 278 switch (channel) {
etiene32 0:cf2317282e61 279 case (0):
etiene32 0:cf2317282e61 280 config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
etiene32 0:cf2317282e61 281 break;
etiene32 0:cf2317282e61 282 case (1):
etiene32 0:cf2317282e61 283 config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
etiene32 0:cf2317282e61 284 break;
etiene32 0:cf2317282e61 285 case (2):
etiene32 0:cf2317282e61 286 config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
etiene32 0:cf2317282e61 287 break;
etiene32 0:cf2317282e61 288 case (3):
etiene32 0:cf2317282e61 289 config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
etiene32 0:cf2317282e61 290 break;
etiene32 0:cf2317282e61 291 }
etiene32 0:cf2317282e61 292
etiene32 0:cf2317282e61 293 // Set the high threshold register
etiene32 0:cf2317282e61 294 // Shift 12-bit results left 4 bits for the ADS1015
etiene32 0:cf2317282e61 295 writeRegister(m_i2cAddress, ADS1015_REG_POINTER_HITHRESH, threshold << m_bitShift);
etiene32 0:cf2317282e61 296
etiene32 0:cf2317282e61 297 // Write config register to the ADC
etiene32 0:cf2317282e61 298 writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
etiene32 0:cf2317282e61 299 }
etiene32 0:cf2317282e61 300
etiene32 0:cf2317282e61 301 /**************************************************************************/
etiene32 0:cf2317282e61 302 /*!
etiene32 0:cf2317282e61 303 @brief In order to clear the comparator, we need to read the
etiene32 0:cf2317282e61 304 conversion results. This function reads the last conversion
etiene32 0:cf2317282e61 305 results without changing the config value.
etiene32 0:cf2317282e61 306 */
etiene32 0:cf2317282e61 307 /**************************************************************************/
etiene32 0:cf2317282e61 308 int16_t Adafruit_ADS1015::getLastConversionResults()
etiene32 0:cf2317282e61 309 {
etiene32 0:cf2317282e61 310 // Wait for the conversion to complete
etiene32 0:cf2317282e61 311 wait_ms(m_conversionDelay);
etiene32 0:cf2317282e61 312
etiene32 0:cf2317282e61 313 // Read the conversion results
etiene32 0:cf2317282e61 314 uint16_t res = readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
etiene32 0:cf2317282e61 315 if (m_bitShift == 0) {
etiene32 0:cf2317282e61 316 return (int16_t)res;
etiene32 0:cf2317282e61 317 } else {
etiene32 0:cf2317282e61 318 // Shift 12-bit results right 4 bits for the ADS1015,
etiene32 0:cf2317282e61 319 // making sure we keep the sign bit intact
etiene32 0:cf2317282e61 320 if (res > 0x07FF) {
etiene32 0:cf2317282e61 321 // negative number - extend the sign to 16th bit
etiene32 0:cf2317282e61 322 res |= 0xF000;
etiene32 0:cf2317282e61 323 }
etiene32 0:cf2317282e61 324 return (int16_t)res;
etiene32 0:cf2317282e61 325 }
etiene32 0:cf2317282e61 326 }