no-OS
ltc268x.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __LTC268X_H__
34 #define __LTC268X_H__
35 
36 #include "no_os_spi.h"
37 #include "no_os_util.h"
38 #include "no_os_delay.h"
39 #include "errno.h"
40 
41 /******************************************************************************/
42 /******************* Macros and Constants Definitions *************************/
43 /******************************************************************************/
44 #define LTC268X_CHANNEL_SEL(x, id) (id ? x : (x << 1))
45 
46 #define LTC268X_CMD_CH_CODE(x, id) (0x00 + LTC268X_CHANNEL_SEL(x, id))
47 #define LTC268X_CMD_CH_SETTING(x, id) (0x10 + LTC268X_CHANNEL_SEL(x, id))
48 #define LTC268X_CMD_CH_OFFSET(x, id) (0X20 + LTC268X_CHANNEL_SEL(x, id))
49 #define LTC268X_CMD_CH_GAIN(x, id) (0x30 + LTC268X_CHANNEL_SEL(x, id))
50 #define LTC268X_CMD_CH_CODE_UPDATE(x, id) (0x40 + LTC268X_CHANNEL_SEL(x, id))
51 #define LTC268X_CMD_CH_CODE_UPDATE_ALL(x, id) (0x50 + LTC268X_CHANNEL_SEL(x, id))
52 #define LTC268X_CMD_CH_UPDATE(x, id) (0x60 + LTC268X_CHANNEL_SEL(x, id))
53 
54 #define LTC268X_CMD_CONFIG_REG 0x70
55 #define LTC268X_CMD_POWERDOWN_REG 0x71
56 #define LTC268X_CMD_A_B_SELECT_REG 0x72
57 #define LTC268X_CMD_SW_TOGGLE_REG 0x73
58 #define LTC268X_CMD_TOGGLE_DITHER_EN_REG 0x74
59 #define LTC268X_CMD_MUX_CTRL_REG 0x75
60 #define LTC268X_CMD_FAULT_REG 0x76
61 #define LTC268X_CMD_CODE_ALL 0x78
62 #define LTC268X_CMD_CODE_UPDATE_ALL 0x79
63 #define LTC268X_CMD_SETTING_ALL 0x7A
64 #define LTC268X_CMD_SETTING_UPDATE_ALL 0x7B
65 #define LTC268X_CMD_UPDATE_ALL 0x7C
66 #define LTC268X_CMD_NOOP 0xFF
67 
68 #define LTC268X_READ_OPERATION 0x80
69 
70 /* Channel Settings */
71 #define LTC268X_CH_SPAN_MSK NO_OS_GENMASK(3, 0)
72 #define LTC268X_CH_SPAN(x) no_os_field_prep(LTC268X_CH_SPAN_MSK, x)
73 #define LTC268X_CH_TD_SEL_MSK NO_OS_GENMASK(5, 4)
74 #define LTC268X_CH_TD_SEL(x) no_os_field_prep(LTC268X_CH_TD_SEL_MSK, x)
75 #define LTC268X_CH_DIT_PER_MSK NO_OS_GENMASK(8, 6)
76 #define LTC268X_CH_DIT_PER(x) no_os_field_prep(LTC268X_CH_DIT_PER_MSK, x)
77 #define LTC268X_CH_DIT_PH_MSK NO_OS_GENMASK(10, 9)
78 #define LTC268X_CH_DIT_PH(x) no_os_field_prep(LTC268X_CH_DIT_PH_MSK, x)
79 #define LTC268X_CH_MODE NO_OS_BIT(11)
80 
81 /* Configuration register */
82 #define LTC268X_CONFIG_RST NO_OS_BIT(15)
83 
84 #define LTC268X_PWDN(x) (1 << ((x) & 0xF))
85 #define LTC268X_DITH_EN(x) (1 << ((x) & 0xF))
86 
87 /******************************************************************************/
88 /*************************** Types Declarations *******************************/
89 /******************************************************************************/
96 };
97 
99  int min;
100  int max;
101 };
102 
109 };
110 
116 };
117 
121 };
122 
128 };
129 
131  LTC2686 = 0,
133 };
134 
135 struct ltc268x_dev {
138  uint16_t pwd_dac_setting;
140  bool dither_mode[16];
141  uint16_t dac_code[16];
142  uint8_t num_channels;
148 };
149 
151  /* SPI */
154  uint16_t pwd_dac_setting;
156  bool dither_mode[16];
162 };
163 /******************************************************************************/
164 /******************************** LTC268X *************************************/
165 /******************************************************************************/
166 int32_t ltc268x_set_pwr_dac(struct ltc268x_dev *dev, uint16_t setting);
167 int32_t ltc268x_set_dither_toggle(struct ltc268x_dev *dev, uint16_t setting);
168 int32_t ltc268x_set_dither_mode(struct ltc268x_dev *dev, uint8_t channel,
169  bool en);
170 int32_t ltc268x_set_span(struct ltc268x_dev *dev, uint8_t channel,
171  enum ltc268x_voltage_range range);
172 int32_t ltc268x_set_dither_phase(struct ltc268x_dev *dev, uint8_t channel,
173  enum ltc268x_dither_phase phase);
174 int32_t ltc268x_set_dither_period(struct ltc268x_dev *dev, uint8_t channel,
175  enum ltc268x_dither_period period);
176 int32_t ltc268x_select_tg_dith_clk(struct ltc268x_dev *dev, uint8_t channel,
177  enum ltc268x_clk_input clk_input);
178 int32_t ltc268x_select_reg(struct ltc268x_dev *dev, uint8_t channel,
179  enum ltc268x_a_b_register sel_reg);
180 int32_t ltc268x_software_reset(struct ltc268x_dev *dev);
181 int32_t ltc268x_set_voltage(struct ltc268x_dev *dev, uint8_t channel,
182  float voltage);
183 int32_t ltc268x_software_toggle(struct ltc268x_dev *dev, uint8_t channel);
184 int32_t ltc268x_init(struct ltc268x_dev **device,
186 int32_t ltc268x_remove(struct ltc268x_dev *dev);
187 
188 #endif // __LTC268X_H__
LTC268X_CMD_CH_OFFSET
#define LTC268X_CMD_CH_OFFSET(x, id)
Definition: ltc268x.h:48
LTC268X_CMD_POWERDOWN_REG
#define LTC268X_CMD_POWERDOWN_REG
Definition: ltc268x.h:55
LTC268X_DITH_PHASE_0
@ LTC268X_DITH_PHASE_0
Definition: ltc268x.h:112
ltc268x_set_voltage
int32_t ltc268x_set_voltage(struct ltc268x_dev *dev, uint8_t channel, float voltage)
Definition: ltc268x.c:374
ltc268x_dev::dac_code
uint16_t dac_code[16]
Definition: ltc268x.h:141
no_os_alloc.h
LTC268X_VOLTAGE_RANGE_M10V_10V
@ LTC268X_VOLTAGE_RANGE_M10V_10V
Definition: ltc268x.h:94
ltc268x_init_param::dither_toggle_en
uint16_t dither_toggle_en
Definition: ltc268x.h:155
LTC268X_CMD_CH_SETTING
#define LTC268X_CMD_CH_SETTING(x, id)
Definition: ltc268x.h:47
ltc268x_set_voltage
int32_t ltc268x_set_voltage(struct ltc268x_dev *dev, uint8_t channel, float voltage)
Definition: ltc268x.c:374
ltc268x_init_param
Definition: ltc268x.h:150
ltc268x_init_param::dither_period
enum ltc268x_dither_period dither_period[16]
Definition: ltc268x.h:159
LTC2686
@ LTC2686
Definition: ltc268x.h:131
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:159
no_os_spi.h
Header file of SPI Interface.
LTC268X_CMD_TOGGLE_DITHER_EN_REG
#define LTC268X_CMD_TOGGLE_DITHER_EN_REG
Definition: ltc268x.h:58
LTC268X_DITH_PERIOD_16
@ LTC268X_DITH_PERIOD_16
Definition: ltc268x.h:106
ltc268x_set_span
int32_t ltc268x_set_span(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_voltage_range range)
Definition: ltc268x.c:208
ltc268x_set_dither_mode
int32_t ltc268x_set_dither_mode(struct ltc268x_dev *dev, uint8_t channel, bool en)
Definition: ltc268x.c:178
LTC268X_CMD_SW_TOGGLE_REG
#define LTC268X_CMD_SW_TOGGLE_REG
Definition: ltc268x.h:57
LTC268X_SELECT_B_REG
@ LTC268X_SELECT_B_REG
Definition: ltc268x.h:120
LTC268X_CH_DIT_PH_MSK
#define LTC268X_CH_DIT_PH_MSK
Definition: ltc268x.h:77
no_os_delay.h
Header file of Delay functions.
LTC268X_SELECT_A_REG
@ LTC268X_SELECT_A_REG
Definition: ltc268x.h:119
ltc268x_select_reg
int32_t ltc268x_select_reg(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_a_b_register sel_reg)
Definition: ltc268x.c:286
ltc268x_set_dither_mode
int32_t ltc268x_set_dither_mode(struct ltc268x_dev *dev, uint8_t channel, bool en)
Definition: ltc268x.c:178
device
Definition: ad9361_util.h:69
LTC268X_SOFT_TGL
@ LTC268X_SOFT_TGL
Definition: ltc268x.h:124
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
ltc268x_select_tg_dith_clk
int32_t ltc268x_select_tg_dith_clk(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_clk_input clk_input)
Definition: ltc268x.c:311
LTC268X_CMD_CONFIG_REG
#define LTC268X_CMD_CONFIG_REG
Definition: ltc268x.h:54
ltc268x_dev::dev_id
enum ltc268x_device_id dev_id
Definition: ltc268x.h:137
ltc268x_remove
int32_t ltc268x_remove(struct ltc268x_dev *dev)
Free the resources allocated by ltc268x_init().
Definition: ltc268x.c:501
LTC268X_CONFIG_RST
#define LTC268X_CONFIG_RST
Definition: ltc268x.h:82
LTC268X_DITH_PHASE_270
@ LTC268X_DITH_PHASE_270
Definition: ltc268x.h:115
LTC268X_CH_MODE
#define LTC268X_CH_MODE
Definition: ltc268x.h:79
ltc268x_init
int32_t ltc268x_init(struct ltc268x_dev **device, struct ltc268x_init_param init_param)
Definition: ltc268x.c:413
ltc268x_dev::pwd_dac_setting
uint16_t pwd_dac_setting
Definition: ltc268x.h:138
ltc268x_voltage_range
ltc268x_voltage_range
Definition: ltc268x.h:90
LTC268X_VOLTAGE_RANGE_0V_10V
@ LTC268X_VOLTAGE_RANGE_0V_10V
Definition: ltc268x.h:92
LTC268X_CH_SPAN_MSK
#define LTC268X_CH_SPAN_MSK
Definition: ltc268x.h:71
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
ltc268x_set_dither_phase
int32_t ltc268x_set_dither_phase(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_dither_phase phase)
Definition: ltc268x.c:234
ltc268x.h
Header file of LTC2686/8 Driver.
no_os_error.h
Error codes definition.
LTC268X_CH_TD_SEL
#define LTC268X_CH_TD_SEL(x)
Definition: ltc268x.h:74
ltc268x_dev::dither_period
enum ltc268x_dither_period dither_period[16]
Definition: ltc268x.h:145
ltc268x_select_reg
int32_t ltc268x_select_reg(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_a_b_register sel_reg)
Definition: ltc268x.c:286
LTC268X_DITH_PHASE_180
@ LTC268X_DITH_PHASE_180
Definition: ltc268x.h:114
ltc268x_init_param::reg_select
enum ltc268x_a_b_register reg_select[16]
Definition: ltc268x.h:161
ltc268x_set_dither_period
int32_t ltc268x_set_dither_period(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_dither_period period)
Definition: ltc268x.c:260
LTC268X_CH_DIT_PER_MSK
#define LTC268X_CH_DIT_PER_MSK
Definition: ltc268x.h:75
ltc268x_a_b_register
ltc268x_a_b_register
Definition: ltc268x.h:118
ltc268x_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ltc268x.h:152
LTC268X_CH_SPAN
#define LTC268X_CH_SPAN(x)
Definition: ltc268x.h:72
ltc268x_init_param::dither_mode
bool dither_mode[16]
Definition: ltc268x.h:156
ltc268x_set_dither_period
int32_t ltc268x_set_dither_period(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_dither_period period)
Definition: ltc268x.c:260
ltc268x_span_tbl::min
int min
Definition: ltc268x.h:99
ltc268x_select_tg_dith_clk
int32_t ltc268x_select_tg_dith_clk(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_clk_input clk_input)
Definition: ltc268x.c:311
LTC268X_TGP2
@ LTC268X_TGP2
Definition: ltc268x.h:127
LTC268X_CMD_A_B_SELECT_REG
#define LTC268X_CMD_A_B_SELECT_REG
Definition: ltc268x.h:56
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:171
ltc268x_set_dither_toggle
int32_t ltc268x_set_dither_toggle(struct ltc268x_dev *dev, uint16_t setting)
Definition: ltc268x.c:157
ltc268x_dev::crt_range
enum ltc268x_voltage_range crt_range[16]
Definition: ltc268x.h:143
ltc268x_init_param::dev_id
enum ltc268x_device_id dev_id
Definition: ltc268x.h:153
ltc268x_init
int32_t ltc268x_init(struct ltc268x_dev **device, struct ltc268x_init_param init_param)
Definition: ltc268x.c:413
ltc268x_set_span
int32_t ltc268x_set_span(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_voltage_range range)
Definition: ltc268x.c:208
LTC268X_CMD_CH_GAIN
#define LTC268X_CMD_CH_GAIN(x, id)
Definition: ltc268x.h:49
ltc268x_init_param::dither_phase
enum ltc268x_dither_phase dither_phase[16]
Definition: ltc268x.h:158
ltc268x_software_toggle
int32_t ltc268x_software_toggle(struct ltc268x_dev *dev, uint8_t channel)
Definition: ltc268x.c:336
ltc268x_clk_input
ltc268x_clk_input
Definition: ltc268x.h:123
LTC268X_VOLTAGE_RANGE_0V_5V
@ LTC268X_VOLTAGE_RANGE_0V_5V
Definition: ltc268x.h:91
ltc268x_init_param::crt_range
enum ltc268x_voltage_range crt_range[16]
Definition: ltc268x.h:157
ltc268x_init_param::pwd_dac_setting
uint16_t pwd_dac_setting
Definition: ltc268x.h:154
ltc268x_dev::dither_toggle_en
uint16_t dither_toggle_en
Definition: ltc268x.h:139
LTC268X_TGP0
@ LTC268X_TGP0
Definition: ltc268x.h:125
LTC268X_CH_DIT_PER
#define LTC268X_CH_DIT_PER(x)
Definition: ltc268x.h:76
LTC268X_DITH_PERIOD_8
@ LTC268X_DITH_PERIOD_8
Definition: ltc268x.h:105
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
ltc268x_set_pwr_dac
int32_t ltc268x_set_pwr_dac(struct ltc268x_dev *dev, uint16_t setting)
Definition: ltc268x.c:136
LTC268X_CH_TD_SEL_MSK
#define LTC268X_CH_TD_SEL_MSK
Definition: ltc268x.h:73
LTC268X_CMD_CH_CODE_UPDATE
#define LTC268X_CMD_CH_CODE_UPDATE(x, id)
Definition: ltc268x.h:50
ltc268x_software_toggle
int32_t ltc268x_software_toggle(struct ltc268x_dev *dev, uint8_t channel)
Definition: ltc268x.c:336
ltc268x_span_tbl
Definition: ltc268x.h:98
LTC268X_CMD_UPDATE_ALL
#define LTC268X_CMD_UPDATE_ALL
Definition: ltc268x.h:65
ltc268x_dev::reg_select
enum ltc268x_a_b_register reg_select[16]
Definition: ltc268x.h:147
LTC268X_VOLTAGE_RANGE_M5V_5V
@ LTC268X_VOLTAGE_RANGE_M5V_5V
Definition: ltc268x.h:93
LTC268X_READ_OPERATION
#define LTC268X_READ_OPERATION
Definition: ltc268x.h:68
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ltc268x_software_reset
int32_t ltc268x_software_reset(struct ltc268x_dev *dev)
Definition: ltc268x.c:358
ltc268x_device_id
ltc268x_device_id
Definition: ltc268x.h:130
ltc268x_set_dither_phase
int32_t ltc268x_set_dither_phase(struct ltc268x_dev *dev, uint8_t channel, enum ltc268x_dither_phase phase)
Definition: ltc268x.c:234
ltc268x_set_dither_toggle
int32_t ltc268x_set_dither_toggle(struct ltc268x_dev *dev, uint16_t setting)
Definition: ltc268x.c:157
LTC268X_CMD_NOOP
#define LTC268X_CMD_NOOP
Definition: ltc268x.h:66
ltc268x_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ltc268x.h:136
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:116
ltc268x_init_param::clk_input
enum ltc268x_clk_input clk_input[16]
Definition: ltc268x.h:160
ltc268x_dither_phase
ltc268x_dither_phase
Definition: ltc268x.h:111
LTC268X_DITH_PERIOD_64
@ LTC268X_DITH_PERIOD_64
Definition: ltc268x.h:108
LTC268X_DITH_PERIOD_4
@ LTC268X_DITH_PERIOD_4
Definition: ltc268x.h:104
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:52
ltc268x_span_tbl::max
int max
Definition: ltc268x.h:100
ltc268x_dev::dither_phase
enum ltc268x_dither_phase dither_phase[16]
Definition: ltc268x.h:144
ltc268x_remove
int32_t ltc268x_remove(struct ltc268x_dev *dev)
Free the resources allocated by ltc268x_init().
Definition: ltc268x.c:501
LTC2688
@ LTC2688
Definition: ltc268x.h:132
no_os_util.h
Header file of utility functions.
ltc268x_dither_period
ltc268x_dither_period
Definition: ltc268x.h:103
LTC268X_CH_DIT_PH
#define LTC268X_CH_DIT_PH(x)
Definition: ltc268x.h:78
LTC268X_DITH_PERIOD_32
@ LTC268X_DITH_PERIOD_32
Definition: ltc268x.h:107
LTC268X_DITH_PHASE_90
@ LTC268X_DITH_PHASE_90
Definition: ltc268x.h:113
ltc268x_dev::dither_mode
bool dither_mode[16]
Definition: ltc268x.h:140
ltc268x_dev
Definition: ltc268x.h:135
ltc268x_set_pwr_dac
int32_t ltc268x_set_pwr_dac(struct ltc268x_dev *dev, uint16_t setting)
Definition: ltc268x.c:136
LTC268X_VOLTAGE_RANGE_M15V_15V
@ LTC268X_VOLTAGE_RANGE_M15V_15V
Definition: ltc268x.h:95
errno.h
Error macro definition for ARM Compiler.
ltc268x_dev::num_channels
uint8_t num_channels
Definition: ltc268x.h:142
LTC268X_TGP1
@ LTC268X_TGP1
Definition: ltc268x.h:126
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:125
ltc268x_dev::clk_input
enum ltc268x_clk_input clk_input[16]
Definition: ltc268x.h:146
ltc268x_software_reset
int32_t ltc268x_software_reset(struct ltc268x_dev *dev)
Definition: ltc268x.c:358