no-OS
ltc2688.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef __LTC2688_H__
40 #define __LTC2688_H__
41 
42 #include "no_os_spi.h"
43 #include "no_os_util.h"
44 #include "no_os_delay.h"
45 #include "errno.h"
46 
47 /******************************************************************************/
48 /******************* Macros and Constants Definitions *************************/
49 /******************************************************************************/
50 #define LTC2688_DAC_CHANNELS 16
51 
52 #define LTC2688_CMD_CH_CODE(x) (0x00 + x)
53 #define LTC2688_CMD_CH_SETTING(x) (0x10 + x)
54 #define LTC2688_CMD_CH_OFFSET(x) (0X20 + x)
55 #define LTC2688_CMD_CH_GAIN(x) (0x30 + x)
56 #define LTC2688_CMD_CH_CODE_UPDATE(x) (0x40 + x)
57 #define LTC2688_CMD_CH_CODE_UPDATE_ALL(x) (0x50 + x)
58 #define LTC2688_CMD_CH_UPDATE(x) (0x60 + x)
59 
60 #define LTC2688_CMD_CONFIG_REG 0x70
61 #define LTC2688_CMD_POWERDOWN_REG 0x71
62 #define LTC2688_CMD_A_B_SELECT_REG 0x72
63 #define LTC2688_CMD_SW_TOGGLE_REG 0x73
64 #define LTC2688_CMD_TOGGLE_DITHER_EN_REG 0x74
65 #define LTC2688_CMD_MUX_CTRL_REG 0x75
66 #define LTC2688_CMD_FAULT_REG 0x76
67 #define LTC2688_CMD_CODE_ALL 0x78
68 #define LTC2688_CMD_CODE_UPDATE_ALL 0x79
69 #define LTC2688_CMD_SETTING_ALL 0x7A
70 #define LTC2688_CMD_SETTING_UPDATE_ALL 0x7B
71 #define LTC2688_CMD_UPDATE_ALL 0x7C
72 #define LTC2688_CMD_NOOP 0xFF
73 
74 #define LTC2688_READ_OPERATION 0x80
75 
76 /* Channel Settings */
77 #define LTC2688_CH_SPAN_MSK NO_OS_GENMASK(3, 0)
78 #define LTC2688_CH_SPAN(x) no_os_field_prep(LTC2688_CH_SPAN_MSK, x)
79 #define LTC2688_CH_TD_SEL_MSK NO_OS_GENMASK(5, 4)
80 #define LTC2688_CH_TD_SEL(x) no_os_field_prep(LTC2688_CH_TD_SEL_MSK, x)
81 #define LTC2688_CH_DIT_PER_MSK NO_OS_GENMASK(8, 6)
82 #define LTC2688_CH_DIT_PER(x) no_os_field_prep(LTC2688_CH_DIT_PER_MSK, x)
83 #define LTC2688_CH_DIT_PH_MSK NO_OS_GENMASK(10, 9)
84 #define LTC2688_CH_DIT_PH(x) no_os_field_prep(LTC2688_CH_DIT_PH_MSK, x)
85 #define LTC2688_CH_MODE NO_OS_BIT(11)
86 
87 /* Configuration register */
88 #define LTC2688_CONFIG_RST NO_OS_BIT(15)
89 
90 #define LTC2688_PWDN(x) (1 << ((x) & 0xF))
91 #define LTC2688_DITH_EN(x) (1 << ((x) & 0xF))
92 
93 
94 /******************************************************************************/
95 /*************************** Types Declarations *******************************/
96 /******************************************************************************/
103 };
104 
106  int min;
107  int max;
108 };
109 
116 };
117 
123 };
124 
128 };
129 
135 };
136 
137 struct ltc2688_dev {
139  uint16_t pwd_dac_setting;
141  bool dither_mode[16];
142  uint16_t dac_code[16];
148 };
149 
151  /* SPI */
153  uint16_t pwd_dac_setting;
155  bool dither_mode[16];
161 };
162 /******************************************************************************/
163 /******************************** LTC2688 *************************************/
164 /******************************************************************************/
165 int32_t ltc2688_set_pwr_dac(struct ltc2688_dev *dev, uint16_t setting);
166 int32_t ltc2688_set_dither_toggle(struct ltc2688_dev *dev, uint16_t setting);
167 int32_t ltc2688_set_dither_mode(struct ltc2688_dev *dev, uint8_t channel,
168  bool en);
169 int32_t ltc2688_set_span(struct ltc2688_dev *dev, uint8_t channel,
170  enum ltc2688_voltage_range range);
171 int32_t ltc2688_set_dither_phase(struct ltc2688_dev *dev, uint8_t channel,
172  enum ltc2688_dither_phase phase);
173 int32_t ltc2688_set_dither_period(struct ltc2688_dev *dev, uint8_t channel,
174  enum ltc2688_dither_period period);
175 int32_t ltc2688_select_tg_dith_clk(struct ltc2688_dev *dev, uint8_t channel,
176  enum ltc2688_clk_input clk_input);
177 int32_t ltc2688_select_reg(struct ltc2688_dev *dev, uint8_t channel,
178  enum ltc2688_a_b_register sel_reg);
179 int32_t ltc2688_software_reset(struct ltc2688_dev *dev);
180 int32_t ltc2688_set_voltage(struct ltc2688_dev *dev, uint8_t channel,
181  float voltage);
182 int32_t ltc2688_software_toggle(struct ltc2688_dev *dev, uint8_t channel);
183 int32_t ltc2688_init(struct ltc2688_dev **device,
185 int32_t ltc2688_remove(struct ltc2688_dev *dev);
186 
187 #endif // __LTC2688_H__
LTC2688_VOLTAGE_RANGE_0V_5V
@ LTC2688_VOLTAGE_RANGE_0V_5V
Definition: ltc2688.h:98
ltc2688_software_toggle
int32_t ltc2688_software_toggle(struct ltc2688_dev *dev, uint8_t channel)
Definition: ltc2688.c:336
ltc2688.h
Header file of LTC2688 Driver.
LTC2688_CMD_TOGGLE_DITHER_EN_REG
#define LTC2688_CMD_TOGGLE_DITHER_EN_REG
Definition: ltc2688.h:64
LTC2688_DITH_PHASE_90
@ LTC2688_DITH_PHASE_90
Definition: ltc2688.h:120
LTC2688_DITH_PERIOD_8
@ LTC2688_DITH_PERIOD_8
Definition: ltc2688.h:112
ltc2688_init_param
Definition: ltc2688.h:150
ltc2688_set_dither_mode
int32_t ltc2688_set_dither_mode(struct ltc2688_dev *dev, uint8_t channel, bool en)
Definition: ltc2688.c:183
ltc2688_select_reg
int32_t ltc2688_select_reg(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_a_b_register sel_reg)
Definition: ltc2688.c:287
LTC2688_CH_DIT_PER_MSK
#define LTC2688_CH_DIT_PER_MSK
Definition: ltc2688.h:81
LTC2688_CMD_A_B_SELECT_REG
#define LTC2688_CMD_A_B_SELECT_REG
Definition: ltc2688.h:62
ltc2688_dev::dither_mode
bool dither_mode[16]
Definition: ltc2688.h:141
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:82
ltc2688_dither_phase
ltc2688_dither_phase
Definition: ltc2688.h:118
no_os_spi.h
Header file of SPI Interface.
ltc2688_software_reset
int32_t ltc2688_software_reset(struct ltc2688_dev *dev)
Definition: ltc2688.c:358
ltc2688_init_param::dither_period
enum ltc2688_dither_period dither_period[16]
Definition: ltc2688.h:158
LTC2688_VOLTAGE_RANGE_M10V_10V
@ LTC2688_VOLTAGE_RANGE_M10V_10V
Definition: ltc2688.h:101
ltc2688_select_tg_dith_clk
int32_t ltc2688_select_tg_dith_clk(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_clk_input clk_input)
Definition: ltc2688.c:312
no_os_delay.h
Header file of Delay functions.
ltc2688_select_reg
int32_t ltc2688_select_reg(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_a_b_register sel_reg)
Definition: ltc2688.c:287
LTC2688_CMD_CH_GAIN
#define LTC2688_CMD_CH_GAIN(x)
Definition: ltc2688.h:55
LTC2688_CH_TD_SEL_MSK
#define LTC2688_CH_TD_SEL_MSK
Definition: ltc2688.h:79
LTC2688_CMD_CH_OFFSET
#define LTC2688_CMD_CH_OFFSET(x)
Definition: ltc2688.h:54
ltc2688_set_dither_period
int32_t ltc2688_set_dither_period(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_dither_period period)
Definition: ltc2688.c:262
ltc2688_software_toggle
int32_t ltc2688_software_toggle(struct ltc2688_dev *dev, uint8_t channel)
Definition: ltc2688.c:336
LTC2688_DAC_CHANNELS
#define LTC2688_DAC_CHANNELS
Definition: ltc2688.h:50
device
Definition: ad9361_util.h:75
LTC2688_TGP2
@ LTC2688_TGP2
Definition: ltc2688.h:134
LTC2688_CH_SPAN
#define LTC2688_CH_SPAN(x)
Definition: ltc2688.h:78
LTC2688_SOFT_TGL
@ LTC2688_SOFT_TGL
Definition: ltc2688.h:131
ltc2688_set_dither_mode
int32_t ltc2688_set_dither_mode(struct ltc2688_dev *dev, uint8_t channel, bool en)
Definition: ltc2688.c:183
ltc2688_dev::reg_select
enum ltc2688_a_b_register reg_select[16]
Definition: ltc2688.h:147
LTC2688_CH_DIT_PH_MSK
#define LTC2688_CH_DIT_PH_MSK
Definition: ltc2688.h:83
ltc2688_dither_period
ltc2688_dither_period
Definition: ltc2688.h:110
LTC2688_SELECT_A_REG
@ LTC2688_SELECT_A_REG
Definition: ltc2688.h:126
LTC2688_SELECT_B_REG
@ LTC2688_SELECT_B_REG
Definition: ltc2688.h:127
ltc2688_dev::dither_period
enum ltc2688_dither_period dither_period[16]
Definition: ltc2688.h:145
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
LTC2688_CMD_CONFIG_REG
#define LTC2688_CMD_CONFIG_REG
Definition: ltc2688.h:60
LTC2688_CMD_SW_TOGGLE_REG
#define LTC2688_CMD_SW_TOGGLE_REG
Definition: ltc2688.h:63
ltc2688_clk_input
ltc2688_clk_input
Definition: ltc2688.h:130
no_os_error.h
Error codes definition.
ltc2688_dev::crt_range
enum ltc2688_voltage_range crt_range[16]
Definition: ltc2688.h:143
LTC2688_TGP0
@ LTC2688_TGP0
Definition: ltc2688.h:132
LTC2688_DITH_PHASE_270
@ LTC2688_DITH_PHASE_270
Definition: ltc2688.h:122
ltc2688_set_dither_toggle
int32_t ltc2688_set_dither_toggle(struct ltc2688_dev *dev, uint16_t setting)
Definition: ltc2688.c:162
LTC2688_CH_DIT_PH
#define LTC2688_CH_DIT_PH(x)
Definition: ltc2688.h:84
LTC2688_DITH_PHASE_0
@ LTC2688_DITH_PHASE_0
Definition: ltc2688.h:119
ltc2688_init_param::clk_input
enum ltc2688_clk_input clk_input[16]
Definition: ltc2688.h:159
ltc2688_voltage_range
ltc2688_voltage_range
Definition: ltc2688.h:97
LTC2688_DITH_PERIOD_16
@ LTC2688_DITH_PERIOD_16
Definition: ltc2688.h:113
LTC2688_CH_MODE
#define LTC2688_CH_MODE
Definition: ltc2688.h:85
ltc2688_set_dither_period
int32_t ltc2688_set_dither_period(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_dither_period period)
Definition: ltc2688.c:262
LTC2688_DITH_PERIOD_32
@ LTC2688_DITH_PERIOD_32
Definition: ltc2688.h:114
LTC2688_CMD_UPDATE_ALL
#define LTC2688_CMD_UPDATE_ALL
Definition: ltc2688.h:71
ltc2688_set_dither_phase
int32_t ltc2688_set_dither_phase(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_dither_phase phase)
Definition: ltc2688.c:237
LTC2688_CH_SPAN_MSK
#define LTC2688_CH_SPAN_MSK
Definition: ltc2688.h:77
LTC2688_VOLTAGE_RANGE_M15V_15V
@ LTC2688_VOLTAGE_RANGE_M15V_15V
Definition: ltc2688.h:102
ltc2688_set_pwr_dac
int32_t ltc2688_set_pwr_dac(struct ltc2688_dev *dev, uint16_t setting)
Definition: ltc2688.c:141
LTC2688_READ_OPERATION
#define LTC2688_READ_OPERATION
Definition: ltc2688.h:74
LTC2688_CH_TD_SEL
#define LTC2688_CH_TD_SEL(x)
Definition: ltc2688.h:80
LTC2688_DITH_PERIOD_64
@ LTC2688_DITH_PERIOD_64
Definition: ltc2688.h:115
ltc2688_init_param::pwd_dac_setting
uint16_t pwd_dac_setting
Definition: ltc2688.h:153
ltc2688_set_pwr_dac
int32_t ltc2688_set_pwr_dac(struct ltc2688_dev *dev, uint16_t setting)
Definition: ltc2688.c:141
ltc2688_init_param::dither_toggle_en
uint16_t dither_toggle_en
Definition: ltc2688.h:154
ltc2688_software_reset
int32_t ltc2688_software_reset(struct ltc2688_dev *dev)
Definition: ltc2688.c:358
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
ltc2688_span_tbl::max
int max
Definition: ltc2688.h:107
ltc2688_init_param::crt_range
enum ltc2688_voltage_range crt_range[16]
Definition: ltc2688.h:156
ltc2688_set_span
int32_t ltc2688_set_span(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_voltage_range range)
Definition: ltc2688.c:212
ltc2688_select_tg_dith_clk
int32_t ltc2688_select_tg_dith_clk(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_clk_input clk_input)
Definition: ltc2688.c:312
ltc2688_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: ltc2688.h:138
ltc2688_set_dither_phase
int32_t ltc2688_set_dither_phase(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_dither_phase phase)
Definition: ltc2688.c:237
LTC2688_DITH_PERIOD_4
@ LTC2688_DITH_PERIOD_4
Definition: ltc2688.h:111
ltc2688_init_param::reg_select
enum ltc2688_a_b_register reg_select[16]
Definition: ltc2688.h:160
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:51
ltc2688_init_param::spi_init
no_os_spi_init_param spi_init
Definition: ltc2688.h:152
ltc2688_a_b_register
ltc2688_a_b_register
Definition: ltc2688.h:125
LTC2688_CMD_CH_CODE_UPDATE
#define LTC2688_CMD_CH_CODE_UPDATE(x)
Definition: ltc2688.h:56
ltc2688_set_span
int32_t ltc2688_set_span(struct ltc2688_dev *dev, uint8_t channel, enum ltc2688_voltage_range range)
Definition: ltc2688.c:212
LTC2688_CH_DIT_PER
#define LTC2688_CH_DIT_PER(x)
Definition: ltc2688.h:82
ltc2688_set_voltage
int32_t ltc2688_set_voltage(struct ltc2688_dev *dev, uint8_t channel, float voltage)
Definition: ltc2688.c:374
LTC2688_CMD_POWERDOWN_REG
#define LTC2688_CMD_POWERDOWN_REG
Definition: ltc2688.h:61
LTC2688_DITH_PHASE_180
@ LTC2688_DITH_PHASE_180
Definition: ltc2688.h:121
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ltc2688_dev
Definition: ltc2688.h:137
LTC2688_CMD_CH_SETTING
#define LTC2688_CMD_CH_SETTING(x)
Definition: ltc2688.h:53
ltc2688_dev::dither_toggle_en
uint16_t dither_toggle_en
Definition: ltc2688.h:140
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:70
ltc2688_set_dither_toggle
int32_t ltc2688_set_dither_toggle(struct ltc2688_dev *dev, uint16_t setting)
Definition: ltc2688.c:162
ltc2688_remove
int32_t ltc2688_remove(struct ltc2688_dev *dev)
Free the resources allocated by ltc2688_init().
Definition: ltc2688.c:492
LTC2688_VOLTAGE_RANGE_M5V_5V
@ LTC2688_VOLTAGE_RANGE_M5V_5V
Definition: ltc2688.h:100
ltc2688_dev::dac_code
uint16_t dac_code[16]
Definition: ltc2688.h:142
ltc2688_dev::clk_input
enum ltc2688_clk_input clk_input[16]
Definition: ltc2688.h:146
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:51
ltc2688_span_tbl
Definition: ltc2688.h:105
ltc2688_remove
int32_t ltc2688_remove(struct ltc2688_dev *dev)
Free the resources allocated by ltc2688_init().
Definition: ltc2688.c:492
ltc2688_dev::pwd_dac_setting
uint16_t pwd_dac_setting
Definition: ltc2688.h:139
ltc2688_init_param::dither_mode
bool dither_mode[16]
Definition: ltc2688.h:155
no_os_util.h
Implementation of utility functions.
ltc2688_dev::dither_phase
enum ltc2688_dither_phase dither_phase[16]
Definition: ltc2688.h:144
LTC2688_CONFIG_RST
#define LTC2688_CONFIG_RST
Definition: ltc2688.h:88
LTC2688_TGP1
@ LTC2688_TGP1
Definition: ltc2688.h:133
LTC2688_CMD_NOOP
#define LTC2688_CMD_NOOP
Definition: ltc2688.h:72
ltc2688_span_tbl::min
int min
Definition: ltc2688.h:106
LTC2688_VOLTAGE_RANGE_0V_10V
@ LTC2688_VOLTAGE_RANGE_0V_10V
Definition: ltc2688.h:99
ltc2688_init
int32_t ltc2688_init(struct ltc2688_dev **device, struct ltc2688_init_param init_param)
Definition: ltc2688.c:411
ltc2688_set_voltage
int32_t ltc2688_set_voltage(struct ltc2688_dev *dev, uint8_t channel, float voltage)
Definition: ltc2688.c:374
errno.h
Error macro definition for ARM Compiler.
ltc2688_init_param::dither_phase
enum ltc2688_dither_phase dither_phase[16]
Definition: ltc2688.h:157
ltc2688_init
int32_t ltc2688_init(struct ltc2688_dev **device, struct ltc2688_init_param init_param)
Definition: ltc2688.c:411
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112