Vitaliy Loginov / PGA280_ADS1259

Dependents:   Chromatograph_Mobile Chromatograph_Mobile

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PGA280.h Source File

PGA280.h

00001 #ifndef _PGA280_ARDUINO_H    /* Guard against multiple inclusion */
00002 #define _PGA280_ARDUINO_H
00003 #include <stdint.h>
00004 #include "PerifConfig.h"
00005 //#include <stdbool.h>
00006 //#include <stddef.h>
00007 //#include <stdlib.h>
00008 
00009 /* Provide C++ Compatibility */
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 // commands
00015 #define WRITE_BUF_PGA280      0x60
00016 #define WRITE_PGA280          0x40
00017 #define READ_PGA280           0x80
00018 #define CS_DIRECT_BUF_PGA280  0xE0
00019 #define CS_DIRECT_PGA280      0xC0
00020 
00021 // registers адреса регистров
00022 #define PGA280_MUX_GAIN_ADR       0x00
00023 #define PGA280_RESET_ADR          0x01
00024 #define PGA280_SPI_MODE_ADR       0x02
00025 #define PGA280_BUF_TIMEOUT_ADR    0x03
00026 #define PGA280_ERROR_ADR          0x04
00027 #define PGA280_GPIO_DATA_ADR      0x05
00028 #define PGA280_INPUT_SWITCH0_ADR  0x06
00029 #define PGA280_INPUT_SWITCH1_ADR  0x07
00030 #define PGA280_GPIO_DIR_ADR       0x08
00031 #define PGA280_CS_MODE_ADR        0x09
00032 #define PGA280_CONFIG0_ADR        0x0A
00033 #define PGA280_CONFIG1_ADR        0x0B
00034 #define PGA280_SP_FUNCTION_ADR    0x0C
00035 
00036 // Gain
00037 #define GAIN_1_8_PGA280       0x00       
00038 #define GAIN_1_4_PGA280       0x01
00039 #define GAIN_1_2_PGA280       0x02
00040 #define GAIN_1_PGA280         0x03
00041 #define GAIN_2_PGA280         0x04
00042 #define GAIN_4_PGA280         0x05
00043 #define GAIN_8_PGA280         0x06
00044 #define GAIN_16_PGA280        0x07
00045 #define GAIN_32_PGA280        0x08
00046 #define GAIN_64_PGA280        0x09
00047 #define GAIN_128_PGA280       0x0A
00048 
00049 namespace pga280{};
00050 using namespace pga280;
00051 
00052 /*Удобное обращение к регистрам если не требуется высокая скорость*/
00053 
00054 //Register 0 - Gain and Optional MUX Register (название из даташита)
00055 typedef union {
00056     struct {
00057         uint8_t
00058          MUX0:1,
00059          MUX1:1,
00060          MUX2:1,
00061          G0:1,
00062          G1:1,
00063          G2:1,
00064          G3:1,
00065          G4:1;
00066     };
00067     struct {
00068         uint8_t MUX:3;
00069         uint8_t GAIN:4;
00070         uint8_t :1;
00071     };    
00072     uint8_t w;
00073     
00074 }__PGA280_MUX_GAIN_t;                          //это объявление типа.
00075 extern __PGA280_MUX_GAIN_t PGA280_MUX_GAIN;            //объявление переменной
00076 
00077 //Register 2 - SPI: MODE Selection to GPIO-Pin (название из даташита)
00078 typedef union {
00079     struct {
00080         uint8_t
00081          CP0:1,
00082          CP1:1,
00083          CP2:1,
00084          CP3:1,
00085          CP4:1,
00086          CP5:1,
00087          CP6:1,
00088          :1;
00089     };
00090     struct {
00091         uint8_t CP:7;
00092         uint8_t :1;
00093     };
00094     struct {
00095         uint8_t w:8;
00096     };
00097 }__PGA280_SPI_MODE_t;                          //это объявление типа.
00098 extern __PGA280_SPI_MODE_t PGA280_SPI_MODE;            //объявление переменной
00099 
00100 //Register 3 - BUF Timeout Register (название из даташита)
00101 typedef union {
00102     struct {
00103         uint8_t
00104          BUFTIM0:1,
00105          BUFTIM1:1,
00106          BUFTIM2:1,
00107          BUFTIM3:1,
00108          BUFTIM4:1,
00109          BUFTIM5:1,
00110          :2;
00111     };
00112     struct {
00113         uint8_t BUFTIM:6;
00114         uint8_t :2;
00115     };
00116     struct {
00117         uint8_t w:8;
00118     };
00119 }__PGA280_BUF_TIMEOUT_t;                          //это объявление типа.
00120 extern __PGA280_BUF_TIMEOUT_t PGA280_BUF_TIMEOUT;            //объявление переменной
00121 
00122 //Register 4 -  Error Register (название из даташита)
00123 typedef union {
00124     struct {
00125         uint8_t
00126          IOVerr:1,                          //Input Overvoltage
00127          GAINerr:1,                         //Gain Network Overload
00128          OUTerr:1,                          //Output Stage Error (allow approximately 6µs activation delay).
00129          EF:1,                              //Error Flag. Logic OR combination of error bits of Register 10. This bit can be connected to GPIO3 pin if the bit is configured for output (Register 8) and as a special function (Register 12).
00130          ICAerr:1,                          //Input Clamp Active
00131          BUFA:1,                            // Buffer Active
00132          IARerr:1,                          //Input Amplifier Saturation
00133          CHKerr:1;                          //Checksum error in SPI. This bit is only active if checksum is enabled.
00134                                             //This bit is set to 1 when the checksum byte is incorrect.
00135     };    
00136     struct {
00137         uint8_t ERR:8;
00138     };
00139 }__PGA280_ERROR_t;                          //это объявление типа.
00140 extern __PGA280_ERROR_t PGA280_ERROR;            //объявление переменной
00141 
00142 //Register 5 -  GPIO Register (название из даташита)
00143 typedef union {
00144     struct {
00145         uint8_t
00146          GPIO0:1,
00147          GPIO1:1,
00148          GPIO2:1,
00149          GPIO3:1,
00150          GPIO4:1,
00151          GPIO5:1,
00152          GPIO6:1,
00153          :1;
00154     };
00155     struct {
00156         uint8_t GPIO:7;
00157         uint8_t :1;
00158     };
00159     struct {
00160         uint8_t w:8;
00161     };
00162 }__PGA280_GPIO_t;                       //это объявление типа.
00163 extern __PGA280_GPIO_t PGA280_GPIO;            //объявление переменной
00164 
00165 //Register 6 -  Input Switch Control Register 1 (название из даташита)
00166 typedef union {
00167     struct {
00168         uint8_t
00169          SW_D12:1,
00170          SW_C2:1,
00171          SW_C1:1,
00172          SW_B2:1,
00173          SW_B1:1,
00174          SW_A2:1,
00175          SW_A1:1,
00176          :1;
00177     };
00178     struct {
00179         uint8_t SWCR0:7;
00180         uint8_t :1;
00181     };
00182     struct {
00183         uint8_t w:8;
00184     };
00185 }__PGA280_INPUT_SWITCH0_t;                       //это объявление типа.
00186 extern __PGA280_INPUT_SWITCH0_t PGA280_INPUT_SWITCH0;            //объявление переменной
00187 
00188 //Register 7 -  Input Switch Control Register 2 (название из даташита)
00189 typedef union {
00190     struct {
00191         uint8_t
00192          SW_G2:1,
00193          SW_G1:1,
00194          SW_F2:1,
00195          SW_F1:1,
00196          :4;
00197     };
00198     struct {
00199         uint8_t SWCR1:4;
00200         uint8_t :4;
00201     };
00202     struct {
00203         uint8_t w:8;
00204     };
00205 }__PGA280_INPUT_SWITCH1_t;                       //это объявление типа.
00206 extern __PGA280_INPUT_SWITCH1_t PGA280_INPUT_SWITCH1;            //объявление переменной
00207 
00208 //Register 8 -  GPIO Configuration Register (название из даташита)
00209 typedef union {
00210     struct {
00211         uint8_t
00212          DIR0:1,
00213          DIR1:1,
00214          DIR2:1,
00215          DIR3:1,
00216          DIR4:1,
00217          DIR5:1,
00218          DIR6:1,
00219          :1;
00220     };
00221     struct {
00222         uint8_t DIR:7;
00223         uint8_t :1;
00224     };
00225     struct {
00226         uint8_t w:8;
00227     };
00228 }__PGA280_GPIO_DIR_t;                       //это объявление типа.
00229 extern __PGA280_GPIO_DIR_t PGA280_GPIO_DIR;        //объявление переменной
00230 
00231 //Register 9 -  CS Configuration Mode Register (название из даташита)
00232 typedef union {
00233     struct {
00234         uint8_t
00235          ECS0:1,
00236          ECS1:1,
00237          ECS2:1,
00238          ECS3:1,
00239          ECS4:1,
00240          ECS5:1,
00241          ECS6:1,
00242          :1;
00243     };
00244     struct {
00245         uint8_t ECS:7;
00246         uint8_t :1;
00247     };
00248     struct {
00249         uint8_t w:8;
00250     };
00251 }__PGA280_CS_MODE_t;                       //это объявление типа.
00252 extern __PGA280_CS_MODE_t PGA280_CS_MODE;        //объявление переменной
00253 
00254 //Register 10 -  Configuration Register 1 (название из даташита)
00255 typedef union {
00256     struct {
00257         uint8_t
00258          IOVerr:1,                          //Input Overvoltage
00259          GAINerr:1,                         //Gain Network Overload
00260          OUTerr:1,                          //Output Stage Error (allow approximately 6µs activation delay).
00261          EDBUFA:1,                         
00262          ICAerr:1,                          //Input Clamp Active
00263          BUFAPOL:1,                        
00264          IARerr:1,                          //Input Amplifier Saturation
00265          MUX_D:1;                     
00266     };    
00267     struct {
00268         uint8_t CFG0:8;
00269     };
00270 }__PGA280_CONFIG0_t;                          //это объявление типа.
00271 extern __PGA280_CONFIG0_t PGA280_CONFIG0;            //объявление переменной
00272 
00273 //Register 11 -  Configuration Register 1 (название из даташита)
00274 typedef union {
00275     struct {
00276         uint8_t
00277          CHKsumE:1,
00278          :1,       
00279          FLGTIM0:1,                         
00280          FLGTIM1:1,                         
00281          FLGTIM2:1,                         
00282          FLGTIM3:1,                   
00283          :1,                          
00284          LTD:1;                          
00285                                            
00286     };
00287     struct {
00288         uint8_t
00289         :2,
00290         FLGTIM:4,
00291         :2;
00292     };
00293     struct {
00294         uint8_t CFG1:8;
00295     };
00296 }__PGA280_CONFIG1_t;                          //это объявление типа.
00297 extern __PGA280_CONFIG1_t PGA280_CONFIG1;            //объявление переменной
00298 
00299 //Register 12 - Special Functions Register (название из даташита)
00300 typedef union {
00301     struct {
00302         uint8_t
00303         /*If the GPIO pins are configured as outputs and these bits are set to 1, the GPIO pins are
00304         *controlled from Register 0 (if MUX-D = 0).*/
00305         MUX0:1,
00306         MUX1:1,
00307         MUX2:1,
00308         
00309         /*A logic OR combination of error bits; see Register 10. This flag can control GPIO3 if this pin is
00310         *configured as an output and EFout = 1.*/
00311         EFout:1,
00312         
00313         /*The current buffer can be triggered externally by pin GPIO4, if configured as an input. The low-to-
00314         *high edge of a pulse starts the buffer with a delay of three to four clock cycles. If held high, the buffer [BUFA]
00315         *remains active. The active time is extended by a minimum of three to four clock cycles plus the time set with FLAGTIM.*/
00316         BUFTin:1,
00317         
00318         /*Pin GPIO5 indicates a buffer active condition (if configured as an output). The BUFA output signal
00319         * is active high by default, but can be inverted to active low by BUFA Pol.*/
00320         BUFAout:1,
00321         
00322         //External connection for external oscillator input to pin GPIO6 (GPIO6 configured as an input).
00323         SYNCin:1,                      
00324         
00325         //Internal oscillator connected to pin GPIO6 for output (GPIO6 configured as an output).
00326         OSCout:1;
00327     };
00328     struct {
00329         uint8_t MUX:3;
00330         uint8_t :5;
00331     };
00332     struct {
00333         uint8_t w:8;
00334     };
00335 }__PGA280_SP_FUNCTION_t;                          //это объявление типа.
00336 extern __PGA280_SP_FUNCTION_t PGA280_SP_FUNCTION;        //объявление переменной
00337 
00338 void pga280_setAdress ( unsigned char adr );
00339 void pga280_resetAdress ( void );
00340 char pga280_sendCommandDevice ( unsigned char command, unsigned char adr );
00341 unsigned char pga280_readOneRegisterDevice ( unsigned char reg, unsigned char adr );
00342 void pga280_writeOneRegisterDevice ( unsigned char reg, unsigned char data, unsigned char adr );
00343 void pga280_writeBufOneRegisterDevice ( unsigned char reg, unsigned char data, unsigned char adr );
00344 void pga280_directCS ( unsigned char ex_cs, unsigned char adr );
00345 void pga280_resetDevice ( unsigned char adr );
00346 void pga280_setMUX (unsigned char mux, unsigned char adr );
00347 void pga280_setGAIN ( unsigned char gain, unsigned char adr );
00348 void pga280_directCsBegin ( unsigned char exCS, unsigned char adr );
00349 void pga280_directCsEnd ( void );
00350 void pga280_setGPIO ( unsigned char num, unsigned char adr );
00351 void pga280_resetGPIO ( unsigned char num, unsigned char adr );
00352 
00353     
00354     /* Provide C++ Compatibility */
00355 #ifdef __cplusplus
00356 }
00357 #endif
00358 
00359 #endif /* _EXAMPLE_FILE_NAME_H */
00360 
00361 /* *****************************************************************************
00362  End of File
00363  */