precision-converters-firmware
ltc2488.h
Go to the documentation of this file.
1 /***************************************************************************
2  * @file ltc2488.h
3  * @brief Header file for the LTC2488 Driver
4  *
5 ********************************************************************************
6  * Copyright (c) 2021-22 Analog Devices, Inc.
7  *
8  * All rights reserved.
9  *
10  * This software is proprietary to Analog Devices, Inc. and its licensors.
11  * By using this software you agree to the terms of the associated
12  * Analog Devices Software License Agreement.
13  *
14 *****************************************************************************/
15 
16 #ifndef LTC2488_H
17 #define LTC2488_H
18 
19 /******************************************************************************/
20 /***************************** Include Files **********************************/
21 /******************************************************************************/
22 
23 #include <stdbool.h>
24 #include "no_os_spi.h"
25 #include "no_os_util.h"
26 
27 /******************************************************************************/
28 /********************** Macros and Constants Definitions **********************/
29 
30 #define LTC2488_VREF 4.096 // Reference Volatage
31 #define LTC2488_CHANNEL_CONV_TIME 150 // Timeout in millisends
32 #define LTC2488_CHANNEL_EOC_MASK NO_OS_BIT(23) // EOC bit mask
33 #define LTC2488_CHANNEL_SIGN_BIT_MASK NO_OS_BIT(21) // SIGN bit mask
34 #define LTC2488_CHANNEL_MSB_BIT_MASK NO_OS_BIT(20) // MSB bit mask
35 #define LTC2488_CHANNEL_MASK_17BITS NO_OS_GENMASK(16,0) // 16 bit data + 1 bit sign
36 #define LTC2488_FS_VOLTAGE (LTC2488_VREF*0.5) // Full Scale Range
37 
38 /* Single-Ended Channel Configuration
39 * Channel selection for all Single-Ended Inputs
40 *
41 * MUX ADDRESS CHANNEL SELECTION
42 * SGL OS A2 A1 A0 | 0 1 2 3 COM
43 * 1 0 0 0 0 | IN+ - - - IN-
44 * 1 0 0 0 1 | - - IN+ - IN-
45 * 1 1 0 0 0 | - IN+ - - IN-
46 * 1 1 0 0 1 | - - - IN+ IN-
47 */
48 #define LTC2488_SINGLE_CH0 0xB0
49 #define LTC2488_SINGLE_CH1 0xB8
50 #define LTC2488_SINGLE_CH2 0xB1
51 #define LTC2488_SINGLE_CH3 0xB9
52 
53 // Channel Configuration Enable/Disable Bits
54 #define LTC2488_CHANNEL_CONF_DISABLE 0x80
55 #define LTC2488_CHANNEL_CONF_ENABLE 0xA0
56 
57 // Masks the read only adc code to extract only the status bits.
58 #define LTC2488_INPUT_RANGE(x) \
59  (enum input_status)(((x) & \
60  (LTC2488_CHANNEL_SIGN_BIT_MASK | LTC2488_CHANNEL_MSB_BIT_MASK)) >> 20)
61 
62 // If End Of Conversion status detected returns true
63 #define LTC2488_EOC_DETECT(x) \
64  ((x & LTC2488_CHANNEL_EOC_MASK ) ? false : true)
65 
66 // Masks the read-only adc code to extract only 17 bits conversion result
67 #define LTC2488_GET_ADC_DATA(x) ((x >> 4) & LTC2488_CHANNEL_MASK_17BITS)
68 
69 // Signs extends the 17 bit value to 32 bit value
70 #define LTC2488_SIGN_EXTEND_ADC_DATA(x) \
71  ((x ^(LTC2488_CHANNEL_MSB_BIT_MASK >> 4)) - \
72  (LTC2488_CHANNEL_MSB_BIT_MASK >> 4))
73 
83 };
84 
89 struct ltc2488_dev {
90  // SPI descriptor
91  struct no_os_spi_desc *spi_desc;
92 };
93 
99  // SPI initialization parameters
100  struct no_os_spi_init_param spi_init ;
101 };
102 
103 /******************************************************************************/
104 /********************** Function Declarations *********************************/
105 
106 enum input_status ltc2488_data_process(const uint32_t *adc_code,
107  int32_t *adc_value);
108 
109 float ltc2488_code_to_voltage(const int32_t *adc_data);
110 
111 int32_t ltc2488_init(struct ltc2488_dev **device,
112  struct ltc2488_dev_init *init_param);
113 
114 int32_t ltc2488_remove(struct ltc2488_dev *dev);
115 
116 int32_t ltc2488_read_write(struct no_os_spi_desc *desc,
117  uint8_t buff_cmd,
118  uint32_t *adc_buff);
119 
120 #endif
struct ad5933_dev * device
Definition: main.c:77
enum input_status ltc2488_data_process(const uint32_t *adc_code, int32_t *adc_value)
Extracts the actual 17-Bit ADC value from the ADC code, returns the 32-bit sign extended value along ...
Definition: ltc2488.c:74
int32_t ltc2488_read_write(struct no_os_spi_desc *desc, uint8_t buff_cmd, uint32_t *adc_buff)
Reads/writes data from/to LTC2488 ADC that accepts a 8 bit configuration and returns a 24 bit result.
Definition: ltc2488.c:192
int32_t ltc2488_init(struct ltc2488_dev **device, struct ltc2488_dev_init *init_param)
Initialize the ltc2488 device structure.
Definition: ltc2488.c:132
float ltc2488_code_to_voltage(const int32_t *adc_data)
Calculates the voltage corresponding to an adc code, given the reference voltage (in volts)....
Definition: ltc2488.c:106
int32_t ltc2488_remove(struct ltc2488_dev *dev)
Free any resource used by the driver.
Definition: ltc2488.c:171
input_status
Various Input range.
Definition: ltc2488.h:78
@ POSITIVE_RANGE
Definition: ltc2488.h:81
@ NEGATIVE_RANGE
Definition: ltc2488.h:80
@ UNDER_RANGE
Definition: ltc2488.h:79
@ OVER_RANGE
Definition: ltc2488.h:82
Definition: ad77681.h:497
Device driver initialization parameters.
Definition: ltc2488.h:98
struct no_os_spi_init_param spi_init
Definition: ltc2488.h:100
Device driver structure.
Definition: ltc2488.h:89
struct no_os_spi_desc * spi_desc
Definition: ltc2488.h:91