no-OS
Loading...
Searching...
No Matches
dpot.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file dpot.h
3 * @brief Header file for the digital potentiometer drivers
4********************************************************************************
5 * Copyright 2025(c) Analog Devices, Inc.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of Analog Devices, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
24 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32#ifndef DPOT_H_
33#define DPOT_H_
34
35#include <stdint.h>
36#include <stdbool.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include "no_os_error.h"
40
67#define DPOT_NUM_SUPPORTED_DEVICES DEV_AD5273+1
68
73 /* SPI digital interface */
75 /* I2C digital interface */
77};
78
82 /* Channels applicable in potentiometer mode */
83 DPOT_CHN_RDAC1, /* Use this channel for single channel devices */
87 /* Channel applicable in linear gain setting mode */
88 /* Use R_AW1 and R_WB1 for single channel devices */
98};
99
100
107 /* Potentiometer mode */
109 /* Linear gain setting mode */
111};
112
119 /* Linear increment */
121 /* Linear decrement */
123};
124
131 /* 6dB increment */
133 /* 6dB decrement */
135};
136
142 /* Control bits (DB15:DB12) */
143 uint8_t control;
144 /* Address bits (DB11:DB8) */
145 uint8_t address;
146 /* Data bits (DB7:DB0) */
147 uint8_t data;
148 /* Readback needed (optional response to command) */
150 /* Response (optional, if 'is_readback' is set true) */
151 uint8_t response;
152};
153
158 /* Device Interface type */
160 /* Active device ID */
162 /* Pointer to digipots ops (APIs) structure */
163 const struct dpot_ops *dpot_ops;
164 /* Device specific parameters */
165 void *extra;
166 /* Device operating mode */
168};
169
170
175struct dpot_dev {
176 /* Active device ID */
178 /* Pointer to digipots ops (APIs) structure */
180 /* Device specific parameters */
181 void *extra;
182};
183
188struct dpot_ops {
189 /* Initialize the digital potentiometer */
190 int(*dpot_init)(struct dpot_init_param *init_params, struct dpot_dev **desc);
191 /* Free memory allocated for the digital potentiometer device structure */
192 int(*dpot_remove)(struct dpot_dev *desc);
193 /* Reset digital potentiometer */
194 int(*dpot_reset)(struct dpot_dev *desc);
195 /* Shutdown digital potentiometer channel */
196 int(*dpot_shutdown)(struct dpot_dev *desc, enum dpot_chn_type chn,
197 bool shutdown_enable);
198 /* Set the digital potentiometer operating mode */
200 enum dpot_operating_mode operating_mode);
201 /* Read the digital potentiometer input register */
202 int(*dpot_input_reg_read)(struct dpot_dev *desc,
203 enum dpot_chn_type chn, uint8_t *data);
204 /* Write to digital potentiometer input register */
205 int(*dpot_input_reg_write)(struct dpot_dev *desc,
206 enum dpot_chn_type chn, uint8_t data);
207 /* Copy input register to RDAC (software LRDAC) */
208 int(*dpot_sw_lrdac_update)(struct dpot_dev *desc, enum dpot_chn_type chn);
209 /* Read digital potentiometer channel */
210 int(*dpot_chn_read)(struct dpot_dev *desc,
211 enum dpot_chn_type chn, uint8_t *data);
212 /* Write to digital potentiometer channel */
213 int(*dpot_chn_write)(struct dpot_dev *desc,
214 enum dpot_chn_type chn, uint8_t data);
215 /* Read NVM (non-volatile) memory of digital potentiometer */
216 int(*dpot_nvm_read)(struct dpot_dev *desc,
217 enum dpot_chn_type chn, uint8_t *data);
218 /* Write to NVM (non-volatile) memory of digital potentiometer */
219 int(*dpot_nvm_write)(struct dpot_dev *desc,
220 enum dpot_chn_type chn, uint8_t data);
221 /* Copy RDAC register to NVM/EEPROM */
222 int(*dpot_copy_rdac_to_nvm)(struct dpot_dev *desc, enum dpot_chn_type chn);
223 /* Copy NVM/EEPROM data to RDAC */
224 int (*dpot_copy_nvm_to_rdac)(struct dpot_dev *desc, enum dpot_chn_type chn);
225 /* Perform RDAC linear increment/decrement */
226 int(*dpot_rdac_linear_update)(struct dpot_dev *desc, enum dpot_chn_type chn,
227 enum dpot_rdac_linear_status status);
228 /* Perform RDAC 6dB increment/decrement */
229 int(*dpot_rdac_6db_update)(struct dpot_dev *desc, enum dpot_chn_type chn,
230 enum dpot_rdac_6db_status status);
231 /* Send digital potentiometer command */
232 int(*dpot_send_cmd)(struct dpot_dev *desc, struct dpot_command *cmd);
233 int(*dpot_tolerance_read)(struct dpot_dev *desc, enum dpot_chn_type chn,
234 uint8_t *data);
235
237 enum dpot_chn_type chn,
238 bool isTopScale,
239 uint8_t nEnter);
240 int(*dpot_set_mid_scale)(struct dpot_dev *desc,
241 enum dpot_chn_type chn,
242 bool shutdown_enable);
243};
244
245/* Digipots APIS */
246
247int dpot_init(struct dpot_dev **desc, struct dpot_init_param *pDpotInitParam);
248int dpot_remove(struct dpot_dev *desc);
249int dpot_reset(struct dpot_dev *desc);
250int dpot_shutdown(struct dpot_dev *desc,
251 enum dpot_chn_type chn, bool shutdown_enable);
252int dpot_set_operating_mode(struct dpot_dev *desc,
253 enum dpot_operating_mode operating_mode);
254int dpot_input_reg_read(struct dpot_dev *desc,
255 enum dpot_chn_type chn, uint8_t *data);
256int dpot_input_reg_write(struct dpot_dev *desc,
257 enum dpot_chn_type chn, uint8_t data);
258int dpot_sw_lrdac_update(struct dpot_dev *desc, enum dpot_chn_type chn);
259int dpot_chn_read(struct dpot_dev *desc,
260 enum dpot_chn_type chn, uint8_t *data);
261int dpot_chn_write(struct dpot_dev *desc,
262 enum dpot_chn_type chn, uint8_t data);
263int dpot_nvm_read(struct dpot_dev *desc,
264 enum dpot_chn_type chn, uint8_t *data);
265int dpot_nvm_write(struct dpot_dev *desc,
266 enum dpot_chn_type chn, uint8_t data);
267int dpot_copy_rdac_to_nvm(struct dpot_dev *desc, enum dpot_chn_type chn);
268int dpot_copy_nvm_to_rdac(struct dpot_dev *desc, enum dpot_chn_type chn);
269int dpot_rdac_linear_update(struct dpot_dev *desc, enum dpot_chn_type chn,
270 enum dpot_rdac_linear_status status);
271int dpot_rdac_6db_update(struct dpot_dev *desc, enum dpot_chn_type chn,
272 enum dpot_rdac_6db_status status);
273int dpot_send_cmd(struct dpot_dev *desc, struct dpot_command *cmd);
274int dpot_enable_top_scale(struct dpot_dev *desc, enum dpot_chn_type chn,
275 uint8_t nEnter);
276int dpot_enable_bottom_scale(struct dpot_dev *desc, enum dpot_chn_type chn,
277 uint8_t nEnter);
278int dpot_tolerance_read(struct dpot_dev *desc, enum dpot_chn_type chn,
279 uint8_t *data);
280int dpot_set_mid_scale(struct dpot_dev *desc, enum dpot_chn_type chn,
281 bool shutdown_enable);
282#endif // DPOT_H_
int dpot_nvm_write(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Write data to NVM (non-volatile) memory.
Definition dpot.c:251
int dpot_chn_read(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Read the digital potentiometer channel.
Definition dpot.c:193
int dpot_reset(struct dpot_dev *desc)
Reset the digital potentiometer.
Definition dpot.c:81
int dpot_send_cmd(struct dpot_dev *desc, struct dpot_command *cmd)
Send command word to the digital potentiometer.
Definition dpot.c:379
int dpot_sw_lrdac_update(struct dpot_dev *desc, enum dpot_chn_type chn)
Copy input register to RDAC (software LRDAC).
Definition dpot.c:175
int dpot_enable_top_scale(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t nEnter)
Perform Enter/exit top scale.
Definition dpot.c:326
int dpot_rdac_6db_update(struct dpot_dev *desc, enum dpot_chn_type chn, enum dpot_rdac_6db_status status)
Perform RDAC 6dB increment/decrement.
Definition dpot.c:360
dpot_operating_mode
Digital potentiometer operating mode.
Definition dpot.h:106
@ DPOT_POTENTIOMETER_MODE
Definition dpot.h:108
@ DPOT_LINEAR_GAIN_SETTING_MODE
Definition dpot.h:110
int dpot_rdac_linear_update(struct dpot_dev *desc, enum dpot_chn_type chn, enum dpot_rdac_linear_status status)
Perform RDAC linear increment/decrement.
Definition dpot.c:307
dpot_dev_id
Digital potentiometer device IDs.
Definition dpot.h:44
@ DEV_AD5171
Definition dpot.h:58
@ DEV_AD5242
Definition dpot.h:60
@ DEV_AD5259
Definition dpot.h:64
@ DEV_AD5142
Definition dpot.h:51
@ DEV_AD5122A
Definition dpot.h:47
@ DEV_AD5124
Definition dpot.h:49
@ DEV_AD5123
Definition dpot.h:48
@ DEV_AD5121
Definition dpot.h:45
@ DEV_AD5143
Definition dpot.h:53
@ DEV_AD5144
Definition dpot.h:54
@ DEV_AD5122
Definition dpot.h:46
@ DEV_AD5258
Definition dpot.h:63
@ DEV_AD5161
Definition dpot.h:56
@ DEV_AD5245
Definition dpot.h:61
@ DEV_AD5141
Definition dpot.h:50
@ DEV_AD5165
Definition dpot.h:57
@ DEV_AD5160
Definition dpot.h:55
@ DEV_AD5142A
Definition dpot.h:52
@ DEV_AD5246
Definition dpot.h:62
@ DEV_AD5273
Definition dpot.h:65
@ DEV_AD5241
Definition dpot.h:59
int dpot_remove(struct dpot_dev *desc)
Free the memory allocated by dpot_init().
Definition dpot.c:65
int dpot_input_reg_read(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Read the digital potentiometer input register.
Definition dpot.c:136
int dpot_set_mid_scale(struct dpot_dev *desc, enum dpot_chn_type chn, bool shutdown_enable)
Shutdown the digital potentiometer channel.
Definition dpot.c:417
int dpot_shutdown(struct dpot_dev *desc, enum dpot_chn_type chn, bool shutdown_enable)
Shutdown the digital potentiometer channel.
Definition dpot.c:99
int dpot_copy_rdac_to_nvm(struct dpot_dev *desc, enum dpot_chn_type chn)
Copy RDAC register to NVM/EEPROM.
Definition dpot.c:270
int dpot_copy_nvm_to_rdac(struct dpot_dev *desc, enum dpot_chn_type chn)
Copy NVM/EEPROM data to RDAC.
Definition dpot.c:289
int dpot_input_reg_write(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Write to the digital potentiometer input register.
Definition dpot.c:156
int dpot_chn_write(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Write to the digital potentiometer channel.
Definition dpot.c:211
int dpot_set_operating_mode(struct dpot_dev *desc, enum dpot_operating_mode operating_mode)
Set the digital potentiometer operating mode.
Definition dpot.c:117
dpot_rdac_linear_status
Digital potentiometer RDAC linear update status.
Definition dpot.h:118
@ DPOT_RDAC_LINEAR_INCREMENT
Definition dpot.h:120
@ DPOT_RDAC_LINEAR_DECREMENT
Definition dpot.h:122
int dpot_nvm_read(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Read the NVM (non-volatile) memory data.
Definition dpot.c:231
int dpot_enable_bottom_scale(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t nEnter)
Perform Enter/exit top scale.
Definition dpot.c:343
dpot_rdac_6db_status
Digital potentiometer RDAC 6dB update status.
Definition dpot.h:130
@ DPOT_RDAC_6DB_DECREMENT
Definition dpot.h:134
@ DPOT_RDAC_6DB_INCREMENT
Definition dpot.h:132
dpot_chn_type
Digital potentiometer channel type.
Definition dpot.h:81
@ DPOT_CHN_RDAC1
Definition dpot.h:83
@ DPOT_CHN_R_WB2
Definition dpot.h:92
@ DPOT_CHN_RDAC4
Definition dpot.h:86
@ DPOT_CHN_R_WB3
Definition dpot.h:94
@ DPOT_CHN_R_AW1
Definition dpot.h:89
@ DPOT_CHN_R_AW4
Definition dpot.h:95
@ DPOT_CHN_RDAC3
Definition dpot.h:85
@ DPOT_CHN_RDAC2
Definition dpot.h:84
@ DPOT_CHN_R_WB4
Definition dpot.h:96
@ DPOT_CHN_R_WB1
Definition dpot.h:90
@ DPOT_CHN_R_AW3
Definition dpot.h:93
@ NUM_OF_DPOT_CHN
Definition dpot.h:97
@ DPOT_CHN_R_AW2
Definition dpot.h:91
int dpot_init(struct dpot_dev **desc, struct dpot_init_param *pDpotInitParam)
Initialize the digital potentiometer.
Definition dpot.c:40
int dpot_tolerance_read(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Send command word to the digital potentiometer.
Definition dpot.c:398
dpot_intf_type
digital potentiometer interface type.
Definition dpot.h:72
@ AD_SPI_INTERFACE
Definition dpot.h:74
@ AD_I2C_INTERFACE
Definition dpot.h:76
Error codes definition.
Digital potentiometer command structure.
Definition dpot.h:141
uint8_t control
Definition dpot.h:143
bool is_readback
Definition dpot.h:149
uint8_t data
Definition dpot.h:147
uint8_t address
Definition dpot.h:145
uint8_t response
Definition dpot.h:151
Digital potentiometer device descriptor parameters.
Definition dpot.h:175
struct dpot_ops * dpot_ops
Definition dpot.h:179
void * extra
Definition dpot.h:181
enum dpot_dev_id device_id
Definition dpot.h:177
Digital potentiometer init parameters.
Definition dpot.h:157
const struct dpot_ops * dpot_ops
Definition dpot.h:163
enum dpot_dev_id device_id
Definition dpot.h:161
void * extra
Definition dpot.h:165
enum dpot_intf_type intf_type
Definition dpot.h:159
enum dpot_operating_mode operating_mode
Definition dpot.h:167
Digital potentiometer common APIs.
Definition dpot.h:188
int(* dpot_chn_read)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Definition dpot.h:210
int(* dpot_copy_rdac_to_nvm)(struct dpot_dev *desc, enum dpot_chn_type chn)
Definition dpot.h:222
int(* dpot_remove)(struct dpot_dev *desc)
Definition dpot.h:192
int(* dpot_rdac_linear_update)(struct dpot_dev *desc, enum dpot_chn_type chn, enum dpot_rdac_linear_status status)
Definition dpot.h:226
int(* dpot_sw_lrdac_update)(struct dpot_dev *desc, enum dpot_chn_type chn)
Definition dpot.h:208
int(* dpot_send_cmd)(struct dpot_dev *desc, struct dpot_command *cmd)
Definition dpot.h:232
int(* dpot_input_reg_write)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Definition dpot.h:205
int(* dpot_input_reg_read)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Definition dpot.h:202
int(* dpot_copy_nvm_to_rdac)(struct dpot_dev *desc, enum dpot_chn_type chn)
Definition dpot.h:224
int(* dpot_nvm_read)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Definition dpot.h:216
int(* dpot_reset)(struct dpot_dev *desc)
Definition dpot.h:194
int(* dpot_tolerance_read)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t *data)
Definition dpot.h:233
int(* dpot_shutdown)(struct dpot_dev *desc, enum dpot_chn_type chn, bool shutdown_enable)
Definition dpot.h:196
int(* dpot_set_operating_mode)(struct dpot_dev *desc, enum dpot_operating_mode operating_mode)
Definition dpot.h:199
int(* dpot_enable_top_bottom_scale)(struct dpot_dev *desc, enum dpot_chn_type chn, bool isTopScale, uint8_t nEnter)
Definition dpot.h:236
int(* dpot_set_mid_scale)(struct dpot_dev *desc, enum dpot_chn_type chn, bool shutdown_enable)
Definition dpot.h:240
int(* dpot_rdac_6db_update)(struct dpot_dev *desc, enum dpot_chn_type chn, enum dpot_rdac_6db_status status)
Definition dpot.h:229
int(* dpot_nvm_write)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Definition dpot.h:219
int(* dpot_init)(struct dpot_init_param *init_params, struct dpot_dev **desc)
Definition dpot.h:190
int(* dpot_chn_write)(struct dpot_dev *desc, enum dpot_chn_type chn, uint8_t data)
Definition dpot.h:213