Manuel Caballero / ADS111X
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADS111X.cpp Source File

ADS111X.cpp

00001 /**
00002  * @brief       ADS111X.cpp
00003  * @details     Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs With Internal Reference, Oscillator, and Programmable Comparator.
00004  *              Function file.
00005  *
00006  *
00007  * @return      N/A
00008  *
00009  * @author      Manuel Caballero
00010  * @date        18/June/2020
00011  * @version     18/June/2020    The ORIGIN
00012  * @pre         N/A.
00013  * @warning     N/A
00014  * @pre         This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
00015  */
00016 
00017 #include "ADS111X.h"
00018 
00019 
00020 ADS111X::ADS111X ( PinName sda, PinName scl, uint32_t addr, uint32_t freq, ADS111X_device_t device )
00021     : _i2c          ( sda, scl )
00022     , _ADS111X_Addr ( addr )
00023     , _device       ( device )
00024 {
00025     _i2c.frequency( freq );
00026 }
00027 
00028 
00029 ADS111X::~ADS111X()
00030 {
00031 }
00032 
00033 
00034 /**
00035  * @brief       ADS111X_StartSingleConversion ( void );
00036  *
00037  * @details     It starts a new single conversion.
00038  *
00039  * @param[in]    N/A.
00040  *
00041  * @param[out]   N/A.
00042  *
00043  *
00044  * @return       Status of ADS111X_StartSingleConversion.
00045  *
00046  *
00047  * @author      Manuel Caballero
00048  * @date        18/June/2020
00049  * @version     18/June/2020   The ORIGIN
00050  * @pre         This function can only be used when in power-down state and has no effect 
00051  *              when a conversion is ongoing.
00052  * @warning     N/A.
00053  */
00054 ADS111X::ADS111X_status_t ADS111X::ADS111X_StartSingleConversion ( void )
00055 {
00056   char     cmd[3]   =  { 0U };
00057   uint16_t myConfig =  0U;
00058   uint32_t aux      =  I2C_SUCCESS ;
00059   
00060   /* Read the register to mask it  */
00061   cmd[0]   =   ADS111X_CONFIG ;
00062   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00063   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00064   
00065   /* Mask it and update the register   */
00066   myConfig   =   cmd[1];
00067   myConfig <<=   8U;
00068   myConfig  |=   cmd[2];
00069 
00070   myConfig  |=   CONFIG_OS_BUSY ;
00071   cmd[1]     =   (char)( myConfig >> 8U );
00072   cmd[2]     =   (char)( myConfig );
00073   aux       |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00074 
00075 
00076 
00077   if ( aux == I2C_SUCCESS  )
00078   {
00079     return   ADS111X_SUCCESS ;
00080   }
00081   else
00082   {
00083     return   ADS111X_FAILURE ;
00084   }
00085 }
00086 
00087 
00088 
00089 /**
00090  * @brief       ADS111X_GetOS ( ADS111X_config_t* );
00091  *
00092  * @details     It checks if the device is not currently performing a conversion.
00093  *
00094  * @param[in]    N/A.
00095  *
00096  * @param[out]   myADS111X:       Operational status flag.
00097  *
00098  *
00099  * @return       Status of ADS111X_GetOS.
00100  *
00101  *
00102  * @author      Manuel Caballero
00103  * @date        18/June/2020
00104  * @version     18/June/2020   The ORIGIN
00105  * @pre         N/A
00106  * @warning     N/A.
00107  */
00108 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetOS ( ADS111X_config_t* myADS111X )
00109 {
00110   char     cmd[2]   =  { 0U };
00111   uint16_t myConfig =  0U;
00112   uint32_t aux      =  I2C_SUCCESS ;
00113 
00114   /* Read the register to mask it  */
00115   cmd[0]   =   ADS111X_CONFIG ;
00116   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00117   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00118 
00119   /* Parse it   */
00120   myConfig       =   cmd[0];
00121   myConfig     <<=   8U;
00122   myConfig      |=   cmd[1];
00123   myADS111X->os  =   (ADS111X_config_os_t)( myConfig & CONFIG_OS_MASK  );
00124 
00125 
00126 
00127   if ( aux == I2C_SUCCESS  )
00128   {
00129     return   ADS111X_SUCCESS ;
00130   }
00131   else
00132   {
00133     return   ADS111X_FAILURE ;
00134   }
00135 }
00136 
00137 
00138 
00139 /**
00140  * @brief       ADS111X_SetMux ( ADS111X_data_t );
00141  *
00142  * @details     It sets input multiplexer configuration.
00143  *
00144  * @param[in]    myADS111X:       Input multiplexer configuration.
00145  *
00146  * @param[out]   N/A.
00147  *
00148  *
00149  * @return       Status of ADS111X_SetMux.
00150  *
00151  *
00152  * @author      Manuel Caballero
00153  * @date        18/June/2020
00154  * @version     18/June/2020   The ORIGIN
00155  * @pre         N/A
00156  * @warning     ADS1115 only.
00157  */
00158 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetMux ( ADS111X_data_t myADS111X )
00159 {
00160   char     cmd[3]   =  { 0U };
00161   uint16_t myConfig =  0U;
00162   uint32_t aux      =  I2C_SUCCESS ;
00163 
00164   /* Only ADS1015 supports this functionality    */
00165   if ( _device == DEVICE_ADS1115  )
00166   {
00167     /* Read the register to mask it  */
00168     cmd[0]   =   ADS111X_CONFIG ;
00169     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00170     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00171 
00172     /* Mask it and update the register   */
00173     myConfig    =   cmd[1];
00174     myConfig  <<=   8U;
00175     myConfig   |=   cmd[2];
00176 
00177     myConfig   &=  ~CONFIG_MUX_MASK ;
00178     myConfig   |=   myADS111X.config.mux;
00179     cmd[1]      =   (char)( myConfig >> 8U );
00180     cmd[2]      =   (char)( myConfig );
00181     aux        |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00182   }
00183   else
00184   {
00185     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00186   }
00187 
00188 
00189   if ( aux == I2C_SUCCESS  )
00190   {
00191     return   ADS111X_SUCCESS ;
00192   }
00193   else
00194   {
00195     return   ADS111X_FAILURE ;
00196   }
00197 }
00198 
00199 
00200 
00201 /**
00202  * @brief       ADS111X_GetMux ( ADS111X_data_t* );
00203  *
00204  * @details     It gets input multiplexer configuration.
00205  *
00206  * @param[in]    N/A.
00207  *
00208  * @param[out]   myADS111X:       Input multiplexer configuration..
00209  *
00210  *
00211  * @return       Status of ADS111X_GetMux.
00212  *
00213  *
00214  * @author      Manuel Caballero
00215  * @date        18/June/2020
00216  * @version     18/June/2020   The ORIGIN
00217  * @pre         N/A
00218  * @warning     ADS1015 only.
00219  */
00220 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetMux ( ADS111X_data_t* myADS111X )
00221 {
00222   char     cmd[2]   =  { 0U };
00223   uint16_t myConfig =  0U;
00224   uint32_t aux      =  I2C_SUCCESS ;
00225 
00226   /* Only ADS1115 supports this functionality    */
00227   if ( _device == DEVICE_ADS1115  )
00228   {
00229     /* Read the register to mask it  */
00230     cmd[0]   =   ADS111X_CONFIG ;
00231     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00232     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00233 
00234     /* Parse the data   */
00235     myConfig         =   cmd[0];
00236     myConfig       <<=   8U;
00237     myConfig        |=   cmd[1];
00238     myADS111X->config.mux   =   (ADS111X_config_mux_t )( myConfig & CONFIG_MUX_MASK  );
00239   }
00240   else
00241   {
00242     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00243   }
00244 
00245 
00246   if ( aux == I2C_SUCCESS  )
00247   {
00248     return   ADS111X_SUCCESS ;
00249   }
00250   else
00251   {
00252     return   ADS111X_FAILURE ;
00253   }
00254 }
00255 
00256 
00257 
00258 /**
00259  * @brief       ADS111X_SetGain ( ADS111X_data_t );
00260  *
00261  * @details     It sets programmable gain amplifier.
00262  *
00263  * @param[in]    myPGA:           Programmable gain.
00264  *
00265  * @param[out]   N/A.
00266  *
00267  *
00268  * @return       Status of ADS111X_SetGain.
00269  *
00270  *
00271  * @author      Manuel Caballero
00272  * @date        18/June/2020
00273  * @version     18/June/2020   The ORIGIN
00274  * @pre         N/A
00275  * @warning     Not ADS1113.
00276  */
00277 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetGain ( ADS111X_data_t myPGA )
00278 {
00279   char     cmd[3]   =  { 0U };
00280   uint16_t myConfig =  0U;
00281   uint32_t aux      =  I2C_SUCCESS ;
00282 
00283   /* Only ADS1115/ADS1114 supports this functionality    */
00284   if ( _device != DEVICE_ADS1113  )
00285   {
00286     /* Read the register to mask it  */
00287     cmd[0]   =   ADS111X_CONFIG ;
00288     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00289     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00290 
00291     /* Mask it and update the register   */
00292     myConfig    =   cmd[1];
00293     myConfig  <<=   8U;
00294     myConfig   |=   cmd[2];
00295 
00296     myConfig   &=  ~CONFIG_PGA_MASK ;
00297     myConfig   |=   myPGA.config.pga;
00298     cmd[1]      =   (char)( myConfig >> 8U );
00299     cmd[2]      =   (char)( myConfig );
00300     aux        |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00301   }
00302   else
00303   {
00304     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00305   }
00306 
00307 
00308   if ( aux == I2C_SUCCESS  )
00309   {
00310     return   ADS111X_SUCCESS ;
00311   }
00312   else
00313   {
00314     return   ADS111X_FAILURE ;
00315   }
00316 }
00317 
00318 
00319 
00320 /**
00321  * @brief       ADS111X_GetGain ( ADS111X_data_t* );
00322  *
00323  * @details     It gets programmable gain amplifier.
00324  *
00325  * @param[in]    N/A.
00326  *
00327  * @param[out]   myPGA:           Programmable gain.
00328  *
00329  *
00330  * @return       Status of ADS111X_GetGain.
00331  *
00332  *
00333  * @author      Manuel Caballero
00334  * @date        18/June/2020
00335  * @version     18/June/2020   The ORIGIN
00336  * @pre         N/A
00337  * @warning     Not ADS1113.
00338  */
00339 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetGain ( ADS111X_data_t* myPGA )
00340 {
00341   char     cmd[2]   =  { 0U };
00342   uint16_t myConfig =  0U;
00343   uint32_t aux      =  I2C_SUCCESS ;
00344 
00345   /* Only ADS1115/ADS1114 supports this functionality    */
00346   if ( _device != DEVICE_ADS1113  )
00347   {
00348     /* Read the register to mask it  */
00349     cmd[0]   =   ADS111X_CONFIG ;
00350     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00351     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00352 
00353     /* Parse the data   */
00354     myConfig     =   cmd[0];
00355     myConfig   <<=   8U;
00356     myConfig    |=   cmd[1];
00357     myPGA->config.pga   =   (ADS111X_config_pga_t )( myConfig & CONFIG_PGA_MASK  );
00358   }
00359   else
00360   {
00361     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00362   }
00363 
00364 
00365   if ( aux == I2C_SUCCESS  )
00366   {
00367     return   ADS111X_SUCCESS ;
00368   }
00369   else
00370   {
00371     return   ADS111X_FAILURE ;
00372   }
00373 }
00374 
00375 
00376 
00377 /**
00378  * @brief       ADS111X_SetMode ( ADS111X_config_t );
00379  *
00380  * @details     It sets the device operating mode.
00381  *
00382  * @param[in]    myMode:          Continuous/Single-shot mode conversion.
00383  *
00384  * @param[out]   N/A.
00385  *
00386  *
00387  * @return       Status of ADS111X_SetMode.
00388  *
00389  *
00390  * @author      Manuel Caballero
00391  * @date        18/June/2020
00392  * @version     18/June/2020   The ORIGIN
00393  * @pre         N/A
00394  * @warning     N/A.
00395  */
00396 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetMode ( ADS111X_config_t myMode )
00397 {
00398   char     cmd[3]   =  { 0U };
00399   uint16_t myConfig =  0U;
00400   uint32_t aux      =  I2C_SUCCESS ;
00401 
00402   /* Read the register to mask it  */
00403   cmd[0]   =   ADS111X_CONFIG ;
00404   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00405   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00406 
00407   /* Mask it and update the register   */
00408   myConfig    =   cmd[1];
00409   myConfig  <<=   8U;
00410   myConfig   |=   cmd[2];
00411 
00412   myConfig   &=  ~CONFIG_MODE_MASK ;
00413   myConfig   |=   myMode.mode;
00414   cmd[1]      =   (char)( myConfig >> 8U );
00415   cmd[2]      =   (char)( myConfig );
00416   aux        |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00417 
00418 
00419 
00420   if ( aux == I2C_SUCCESS  )
00421   {
00422     return   ADS111X_SUCCESS ;
00423   }
00424   else
00425   {
00426     return   ADS111X_FAILURE ;
00427   }
00428 }
00429 
00430 
00431 
00432 /**
00433  * @brief       ADS111X_GetMode ( ADS111X_config_t* );
00434  *
00435  * @details     It gets the device operating mode.
00436  *
00437  * @param[in]    N/A
00438  *
00439  * @param[out]   myMode:          Continuous/Single-shot mode conversion.
00440  *
00441  *
00442  * @return       Status of ADS111X_GetMode.
00443  *
00444  *
00445  * @author      Manuel Caballero
00446  * @date        18/June/2020
00447  * @version     18/June/2020   The ORIGIN
00448  * @pre         N/A
00449  * @warning     N/A.
00450  */
00451 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetMode ( ADS111X_config_t* myMode )
00452 {
00453   char     cmd[2]   =  { 0U };
00454   uint16_t myConfig =  0U;
00455   uint32_t aux      =  I2C_SUCCESS ;
00456 
00457   /* Read the register to mask it  */
00458   cmd[0]   =   ADS111X_CONFIG ;
00459   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00460   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00461 
00462   /* Parse the data   */
00463   myConfig       =   cmd[0];
00464   myConfig     <<=   8U;
00465   myConfig      |=   cmd[1];
00466   myMode->mode   =   (ADS111X_config_mode_t )( myConfig & CONFIG_MODE_MASK  );
00467 
00468 
00469 
00470   if ( aux == I2C_SUCCESS  )
00471   {
00472     return   ADS111X_SUCCESS ;
00473   }
00474   else
00475   {
00476     return   ADS111X_FAILURE ;
00477   }
00478 }
00479 
00480 
00481 
00482 /**
00483  * @brief       ADS111X_SetDataRate ( ADS111X_config_t );
00484  *
00485  * @details     It sets the data rate.
00486  *
00487  * @param[in]    myDR:            Data rate.
00488  *
00489  * @param[out]   N/A.
00490  *
00491  *
00492  * @return       Status of ADS111X_SetDataRate.
00493  *
00494  *
00495  * @author      Manuel Caballero
00496  * @date        18/June/2020
00497  * @version     18/June/2020   The ORIGIN
00498  * @pre         N/A
00499  * @warning     N/A.
00500  */
00501 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetDataRate ( ADS111X_config_t myDR )
00502 {
00503   char     cmd[3]   =  { 0U };
00504   uint16_t myConfig =  0U;
00505   uint32_t aux      =  I2C_SUCCESS ;
00506 
00507   /* Read the register to mask it  */
00508   cmd[0]   =   ADS111X_CONFIG ;
00509   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00510   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00511 
00512   /* Mask it and update the register   */
00513   myConfig    =   cmd[1];
00514   myConfig  <<=   8U;
00515   myConfig   |=   cmd[2];
00516 
00517   myConfig   &=  ~CONFIG_DR_MASK ;
00518   myConfig   |=   myDR.dr;
00519   cmd[1]      =   (char)( myConfig >> 8U );
00520   cmd[2]      =   (char)( myConfig );
00521   aux        |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00522 
00523 
00524 
00525   if ( aux == I2C_SUCCESS  )
00526   {
00527     return   ADS111X_SUCCESS ;
00528   }
00529   else
00530   {
00531     return   ADS111X_FAILURE ;
00532   }
00533 }
00534 
00535 
00536 
00537 /**
00538  * @brief       ADS111X_GetDataRate ( ADS111X_config_t* );
00539  *
00540  * @details     It gets the data rate.
00541  *
00542  * @param[in]    N/A.
00543  *
00544  * @param[out]   myDR:            Data rate.
00545  *
00546  *
00547  * @return       Status of ADS111X_GetDataRate.
00548  *
00549  *
00550  * @author      Manuel Caballero
00551  * @date        18/June/2020
00552  * @version     18/June/2020   The ORIGIN
00553  * @pre         N/A
00554  * @warning     N/A.
00555  */
00556 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetDataRate ( ADS111X_config_t* myDR )
00557 {
00558   char     cmd[2]   =  { 0U };
00559   uint16_t myConfig =  0U;
00560   uint32_t aux      =  I2C_SUCCESS ;
00561 
00562   /* Read the register to mask it  */
00563   cmd[0]   =   ADS111X_CONFIG ;
00564   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00565   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00566 
00567   /* Parse the data   */
00568   myConfig   =   cmd[0];
00569   myConfig <<=   8U;
00570   myConfig  |=   cmd[1];
00571   myDR->dr   =   (ADS111X_config_dr_t )( myConfig & CONFIG_DR_MASK  );
00572 
00573 
00574 
00575   if ( aux == I2C_SUCCESS  )
00576   {
00577     return   ADS111X_SUCCESS ;
00578   }
00579   else
00580   {
00581     return   ADS111X_FAILURE ;
00582   }
00583 }
00584 
00585 
00586 
00587 /**
00588  * @brief       ADS111X_SetComparator ( ADS111X_data_t );
00589  *
00590  * @details     It sets the comparator configuration.
00591  *
00592  * @param[in]    myCOMP:          Comparator Mode/Polarity/Latching/Queue and disable.
00593  *
00594  * @param[out]   N/A.
00595  *
00596  *
00597  * @return       Status of ADS111X_SetComparator.
00598  *
00599  *
00600  * @author      Manuel Caballero
00601  * @date        18/June/2020
00602  * @version     18/June/2020   The ORIGIN
00603  * @pre         N/A
00604  * @warning     ADS1114 and ADS1115 only.
00605  */
00606 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetComparator ( ADS111X_data_t myCOMP )
00607 {
00608   char     cmd[3]   =  { 0U };
00609   uint16_t myConfig =  0U;
00610   uint32_t aux      =  I2C_SUCCESS ;
00611 
00612   /* Only ADS1115/ADS1114 supports this functionality    */
00613   if ( _device != DEVICE_ADS1113  )
00614   {
00615     /* Read the register to mask it  */
00616     cmd[0]   =   ADS111X_CONFIG ;
00617     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00618     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[1], 2U );
00619 
00620     /* Mask it and update the register   */
00621     myConfig    =   cmd[1];
00622     myConfig  <<=   8U;
00623     myConfig   |=   cmd[2];
00624 
00625     myConfig   &=  ~( CONFIG_COMP_MODE_MASK  | CONFIG_COMP_POL_MASK  | CONFIG_COMP_LAT_MASK  | CONFIG_COMP_QUE_MASK  );
00626     myConfig   |=   ( myCOMP.config.comp_mode | myCOMP.config.comp_pol | myCOMP.config.comp_lat | myCOMP.config.comp_que );
00627     cmd[1]      =   (char)( myConfig >> 8U );
00628     cmd[2]      =   (char)( myConfig );
00629     aux        |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00630   }
00631   else
00632   {
00633     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00634   }
00635 
00636 
00637   if ( aux == I2C_SUCCESS  )
00638   {
00639     return   ADS111X_SUCCESS ;
00640   }
00641   else
00642   {
00643     return   ADS111X_FAILURE ;
00644   }
00645 }
00646 
00647 
00648 
00649 /**
00650  * @brief       ADS111X_GetComparator ( ADS111X_data_t* );
00651  *
00652  * @details     It gets the comparator configuration.
00653  *
00654  * @param[in]    N/A.
00655  *
00656  * @param[out]   myCOMP:          Comparator Mode/Polarity/Latching/Queue and disable.
00657  *
00658  *
00659  * @return       Status of ADS111X_GetComparator.
00660  *
00661  *
00662  * @author      Manuel Caballero
00663  * @date        18/June/2020
00664  * @version     18/June/2020   The ORIGIN
00665  * @pre         N/A
00666  * @warning     ADS1114 and ADS1115 only.
00667  */
00668 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetComparator ( ADS111X_data_t* myCOMP )
00669 {
00670   char     cmd[2]   =  { 0U };
00671   uint16_t myConfig =  0U;
00672   uint32_t aux      =  I2C_SUCCESS ;
00673 
00674   /* Only ADS1115/ADS1114 supports this functionality    */
00675   if ( _device != DEVICE_ADS1113  )
00676   {
00677     /* Read the register to mask it  */
00678     cmd[0]   =   ADS111X_CONFIG ;
00679     aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00680     aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00681 
00682     /* Parse the data   */
00683     myConfig           =   cmd[0];
00684     myConfig         <<=   8U;
00685     myConfig          |=   cmd[1];
00686 
00687     myCOMP->config.comp_mode  =   (ADS111X_config_comp_mode_t )( myConfig & CONFIG_COMP_MODE_MASK  );
00688     myCOMP->config.comp_pol   =   (ADS111X_config_comp_pol_t )( myConfig & CONFIG_COMP_POL_MASK  );
00689     myCOMP->config.comp_lat   =   (ADS111X_config_comp_lat_t )( myConfig & CONFIG_COMP_LAT_MASK  );
00690     myCOMP->config.comp_que   =   (ADS111X_config_comp_que_t )( myConfig & CONFIG_COMP_QUE_MASK  );
00691   }
00692   else
00693   {
00694     return  ADS111X_DEVICE_NOT_SUPPORTED ;
00695   }
00696 
00697 
00698   if ( aux == I2C_SUCCESS  )
00699   {
00700     return   ADS111X_SUCCESS ;
00701   }
00702   else
00703   {
00704     return   ADS111X_FAILURE ;
00705   }
00706 }
00707 
00708 
00709 
00710 /**
00711  * @brief       ADS111X_SetLowThresholdValue ( ADS111X_thresh_t );
00712  *
00713  * @details     It sets the low threshold value.
00714  *
00715  * @param[in]    myLoThres:       low threshold value.
00716  *
00717  * @param[out]   N/A.
00718  *
00719  *
00720  * @return       Status of ADS111X_SetLowThresholdValue.
00721  *
00722  *
00723  * @author      Manuel Caballero
00724  * @date        18/June/2020
00725  * @version     18/June/2020   The ORIGIN
00726  * @pre         N/A
00727  * @warning     N/A.
00728  */
00729 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetLowThresholdValue ( ADS111X_thresh_t myLoThres )
00730 {
00731   char     cmd[3]  =  { 0U };
00732   uint32_t aux     =  I2C_SUCCESS ;
00733 
00734   /* Update the register   */
00735    myLoThres.lo_thresh <<= 4U;
00736 
00737    cmd[0]   =   ADS111X_LO_THRESH ;
00738    cmd[1]   =   (char)( myLoThres.lo_thresh >> 8U );
00739    cmd[2]   =   (char)( myLoThres.lo_thresh );
00740    aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00741 
00742 
00743   if ( aux == I2C_SUCCESS  )
00744   {
00745     return   ADS111X_SUCCESS ;
00746   }
00747   else
00748   {
00749     return   ADS111X_FAILURE ;
00750   }
00751 }
00752 
00753 
00754 
00755 /**
00756  * @brief       ADS111X_GetLowThresholdValue ( ADS111X_thresh_t );
00757  *
00758  * @details     It gets the low threshold value.
00759  *
00760  * @param[in]    N/A.
00761  *
00762  * @param[out]   myLoThres:       low threshold value.
00763  *
00764  *
00765  * @return       Status of ADS111X_GetLowThresholdValue.
00766  *
00767  *
00768  * @author      Manuel Caballero
00769  * @date        18/June/2020
00770  * @version     18/June/2020   The ORIGIN
00771  * @pre         N/A
00772  * @warning     N/A.
00773  */
00774 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetLowThresholdValue ( ADS111X_thresh_t* myLoThres )
00775 {
00776   char     cmd[2]   =  { 0U };
00777   uint32_t aux      =  I2C_SUCCESS ;
00778 
00779   /* Read the register to mask it  */
00780   cmd[0]   =   ADS111X_LO_THRESH ;
00781   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00782   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00783 
00784   /* Parse the data  */
00785   myLoThres->lo_thresh    =   cmd[0];
00786   myLoThres->lo_thresh  <<=   8U;
00787   myLoThres->lo_thresh   |=   cmd[1];
00788 
00789 
00790 
00791   if ( aux == I2C_SUCCESS  )
00792   {
00793     return   ADS111X_SUCCESS ;
00794   }
00795   else
00796   {
00797     return   ADS111X_FAILURE ;
00798   }
00799 }
00800 
00801 
00802 
00803 /**
00804  * @brief       ADS111X_SetHighThresholdValue ( ADS111X_thresh_t );
00805  *
00806  * @details     It sets the high threshold value.
00807  *
00808  * @param[in]    myHiThres:       High threshold value.
00809  *
00810  * @param[out]   N/A.
00811  *
00812  *
00813  * @return       Status of ADS111X_SetHighThresholdValue.
00814  *
00815  *
00816  * @author      Manuel Caballero
00817  * @date        18/June/2020
00818  * @version     18/June/2020   The ORIGIN
00819  * @pre         N/A
00820  * @warning     N/A.
00821  */
00822 ADS111X::ADS111X_status_t ADS111X::ADS111X_SetHighThresholdValue ( ADS111X_thresh_t myHiThres )
00823 {
00824   char     cmd[3]  =  { 0U };
00825   uint32_t aux     =  I2C_SUCCESS ;
00826 
00827   /* Update the register   */
00828   myHiThres.hi_thresh <<= 4U;
00829 
00830   cmd[0]   =   ADS111X_HI_THRESH ;
00831   cmd[1]   =   (char)( myHiThres.hi_thresh >> 8U );
00832   cmd[2]   =   (char)( myHiThres.hi_thresh );
00833   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ), false );
00834 
00835 
00836 
00837   if ( aux == I2C_SUCCESS  )
00838   {
00839     return   ADS111X_SUCCESS ;
00840   }
00841   else
00842   {
00843     return   ADS111X_FAILURE ;
00844   }
00845 }
00846 
00847 
00848 
00849 /**
00850  * @brief       ADS111X_GetHighThresholdValue ( ADS111X_thresh_t );
00851  *
00852  * @details     It gets the high threshold value.
00853  *
00854  * @param[in]    N/A.
00855  *
00856  * @param[out]   myHiThres:       High threshold value.
00857  *
00858  *
00859  * @return       Status of ADS111X_GetHighThresholdValue.
00860  *
00861  *
00862  * @author      Manuel Caballero
00863  * @date        18/June/2020
00864  * @version     18/June/2020   The ORIGIN
00865  * @pre         N/A
00866  * @warning     N/A.
00867  */
00868 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetHighThresholdValue ( ADS111X_thresh_t* myHiThres )
00869 {
00870   char     cmd[2]   =  { 0U };
00871   uint32_t aux      =  I2C_SUCCESS ;
00872 
00873   /* Read the register to mask it  */
00874   cmd[0]   =   ADS111X_HI_THRESH ;
00875   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00876   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00877 
00878   /* Parse the data  */
00879   myHiThres->hi_thresh    =   cmd[0];
00880   myHiThres->hi_thresh  <<=   8U;
00881   myHiThres->hi_thresh   |=   cmd[1];
00882 
00883 
00884 
00885   if ( aux == I2C_SUCCESS  )
00886   {
00887     return   ADS111X_SUCCESS ;
00888   }
00889   else
00890   {
00891     return   ADS111X_FAILURE ;
00892   }
00893 }
00894 
00895 
00896 
00897 /**
00898  * @brief       ADS111X_GetRawConversion ( ADS111X_conversion_t* );
00899  *
00900  * @details     It gets the raw conversion value
00901  *
00902  * @param[in]    N/A.
00903  *
00904  * @param[out]   myRawD:          Raw conversion value.
00905  *
00906  *
00907  * @return       Status of ADS111X_GetRawConversion.
00908  *
00909  *
00910  * @author      Manuel Caballero
00911  * @date        18/June/2020
00912  * @version     18/June/2020   The ORIGIN
00913  * @pre         N/A
00914  * @warning     N/A.
00915  */
00916 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetRawConversion ( ADS111X_conversion_t* myRawD )
00917 {
00918   char     cmd[2]   =  { 0U };
00919   uint32_t aux      =  I2C_SUCCESS ;
00920 
00921   /* Read the register to mask it  */
00922   cmd[0]   =   ADS111X_CONVERSION ;
00923   aux     |=   _i2c.write ( _ADS111X_Addr, &cmd[0], 1U, true );
00924   aux     |=   _i2c.read  ( _ADS111X_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
00925 
00926   /* Parse the data  */
00927   myRawD->raw_conversion    =   cmd[0];
00928   myRawD->raw_conversion  <<=   8U;
00929   myRawD->raw_conversion   |=   cmd[1];
00930 
00931 
00932 
00933   if ( aux == I2C_SUCCESS  )
00934   {
00935     return   ADS111X_SUCCESS ;
00936   }
00937   else
00938   {
00939     return   ADS111X_FAILURE ;
00940   }
00941 }
00942 
00943 
00944 
00945 /**
00946  * @brief       ADS111X_GetConversion ( ADS111X_data_t* );
00947  *
00948  * @details     It gets the conversion value
00949  *
00950  * @param[in]    N/A.
00951  *
00952  * @param[out]   myD:             Conversion value.
00953  *
00954  *
00955  * @return       Status of ADS111X_GetConversion.
00956  *
00957  *
00958  * @author      Manuel Caballero
00959  * @date        18/June/2020
00960  * @version     18/June/2020   The ORIGIN
00961  * @pre         N/A
00962  * @warning     N/A.
00963  */
00964 ADS111X::ADS111X_status_t ADS111X::ADS111X_GetConversion ( ADS111X_data_t* myD )
00965 {
00966   float             myGain    =  0.0;
00967   float             myFactor  =  0.0;
00968   ADS111X_status_t  aux       =  ADS111X_SUCCESS ;
00969 
00970   /* Get the raw conversion value   */
00971   aux  =   ADS111X::ADS111X_GetRawConversion ( &myD->conversion );
00972 
00973   /* Set up the gain accordingly   */
00974   switch ( _device )
00975   {
00976     case DEVICE_ADS1113 :
00977       myGain   =   2.048;
00978       break;
00979 
00980     default:
00981     case DEVICE_ADS1114 :
00982     case DEVICE_ADS1115 :
00983       switch ( myD->config.pga )
00984       {
00985         case CONFIG_PGA_FSR_6_144_V :
00986           myGain   =   6.144;
00987           break;
00988 
00989         case CONFIG_PGA_FSR_4_096_V :
00990           myGain   =   4.096;
00991           break;
00992 
00993         default:
00994         case CONFIG_PGA_FSR_2_048_V :
00995           myGain   =   2.048;
00996           break;
00997 
00998         case CONFIG_PGA_FSR_1_024_V :
00999           myGain   =   1.024;
01000           break;
01001 
01002         case CONFIG_PGA_FSR_0_512_V :
01003           myGain   =   0.512;
01004           break;
01005 
01006         case CONFIG_PGA_FSR_0_256_V :
01007           myGain   =   0.256;
01008           break;
01009       }
01010       break;
01011   }
01012 
01013 
01014   /* Check the scale     */
01015   if ( myD->conversion.raw_conversion == 0x8000 )
01016   {
01017       myFactor  =   myGain;
01018       myD->conversion.conversion  =   (float)( -myFactor );
01019   }
01020   else if ( myD->conversion.raw_conversion == 0x7FFF )
01021   {
01022       myFactor  =   ( myGain * ( 32768.0 - 1.0 ) ) / 32768.0;
01023       myD->conversion.conversion  =   (float)( myFactor );
01024   }
01025   else
01026   {
01027       myFactor  =   (float)( myGain / 32768.0 );
01028       myD->conversion.conversion  =   (float)( myFactor * myD->conversion.raw_conversion );
01029   }
01030 
01031 
01032 
01033   return   aux;
01034 }
01035 
01036 
01037 
01038 /**
01039  * @brief       ADS111X_SoftReset ( void );
01040  *
01041  * @details     It triggers a softreset.
01042  *
01043  * @param[in]    N/A.
01044  *
01045  * @param[out]   N/A.
01046  *
01047  *
01048  * @return       Status of ADS111X_SoftReset.
01049  *
01050  *
01051  * @author      Manuel Caballero
01052  * @date        18/June/2020
01053  * @version     18/June/2020   The ORIGIN
01054  * @pre         N/A
01055  * @warning     N/A.
01056  */
01057 ADS111X::ADS111X_status_t ADS111X::ADS111X_SoftReset ( void )
01058 {
01059   char     cmd  =  0U;
01060   uint32_t aux  =  I2C_SUCCESS ;
01061 
01062 
01063   /* Update the register   */
01064   cmd  =   ADS111X_RESET_COMMAND ;
01065   aux |=   _i2c.write ( 0x00, &cmd, 1U, false );
01066 
01067 
01068 
01069   if ( aux == I2C_SUCCESS  )
01070   {
01071     return   ADS111X_SUCCESS ;
01072   }
01073   else
01074   {
01075     return   ADS111X_FAILURE ;
01076   }
01077 }