-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ad5686.c
765 lines (716 loc) · 23.4 KB
/
ad5686.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/***************************************************************************//**
* @file ad5686.c
* @brief Implementation of AD5686 Driver.
* @author Istvan Csomortani (istvan.csomortani@analog.com)
*******************************************************************************
* Copyright 2013, 2020(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification,
* are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
******************************************************************************/
/*****************************************************************************/
/***************************** Include Files *********************************/
/*****************************************************************************/
#include <stdlib.h>
#include "ad5686.h"
#include "no_os_alloc.h"
/*****************************************************************************/
/***************************** Constant definition ***************************/
/*****************************************************************************/
static const uint32_t ad5683_channel_addr [] = {
[AD5686_CH_0] = 0,
};
static const uint32_t ad5689_channel_addr[] = {
[AD5686_CH_0] = 1,
[AD5686_CH_1] = 8,
};
static const uint32_t ad5686_channel_addr[] = {
[AD5686_CH_0] = 1,
[AD5686_CH_1] = 2,
[AD5686_CH_2] = 4,
[AD5686_CH_3] = 8,
};
static const uint32_t ad5676_channel_addr[] = {
[AD5686_CH_0] = 0,
[AD5686_CH_1] = 1,
[AD5686_CH_2] = 2,
[AD5686_CH_3] = 3,
[AD5686_CH_4] = 4,
[AD5686_CH_5] = 5,
[AD5686_CH_6] = 6,
[AD5686_CH_7] = 7,
};
static const uint32_t ad5679_channel_addr[] = {
[AD5686_CH_0] = 0,
[AD5686_CH_1] = 1,
[AD5686_CH_2] = 2,
[AD5686_CH_3] = 3,
[AD5686_CH_4] = 4,
[AD5686_CH_5] = 5,
[AD5686_CH_6] = 6,
[AD5686_CH_7] = 7,
[AD5686_CH_8] = 8,
[AD5686_CH_9] = 9,
[AD5686_CH_10] = 10,
[AD5686_CH_11] = 11,
[AD5686_CH_12] = 12,
[AD5686_CH_13] = 13,
[AD5686_CH_14] = 14,
[AD5686_CH_15] = 15,
};
static const struct ad5686_chip_info chip_info[] = {
[ID_AD5671R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5676_channel_addr,
},
[ID_AD5672R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5676_channel_addr,
},
[ID_AD5673R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5674] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5674R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5675R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5676_channel_addr,
},
[ID_AD5676] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5676_channel_addr,
},
[ID_AD5676R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5676_channel_addr,
},
[ID_AD5677R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5679] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5679R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5679_channel_addr,
},
[ID_AD5684R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5685R] = {
.resolution = 14,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5686] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5686R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5687] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5689_channel_addr,
},
[ID_AD5687R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5689_channel_addr,
},
[ID_AD5689] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5689_channel_addr,
},
[ID_AD5689R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = SPI,
.channel_addr = ad5689_channel_addr,
},
[ID_AD5697R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5689_channel_addr,
},
[ID_AD5694] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5694R] = {
.resolution = 12,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5695R] = {
.resolution = 14,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5696] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5696R] = {
.resolution = 16,
.register_map = AD5686_REG_MAP,
.communication = I2C,
.channel_addr = ad5686_channel_addr,
},
[ID_AD5681R] = {
.resolution = 12,
.register_map = AD5683_REG_MAP,
.communication = SPI,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5682R] = {
.resolution = 14,
.register_map = AD5683_REG_MAP,
.communication = SPI,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5683R] = {
.resolution = 16,
.register_map = AD5683_REG_MAP,
.communication = SPI,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5683] = {
.resolution = 16,
.register_map = AD5683_REG_MAP,
.communication = SPI,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5691R] = {
.resolution = 12,
.register_map = AD5683_REG_MAP,
.communication = I2C,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5692R] = {
.resolution = 14,
.register_map = AD5683_REG_MAP,
.communication = I2C,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5693R] = {
.resolution = 16,
.register_map = AD5683_REG_MAP,
.communication = I2C,
.channel_addr = ad5683_channel_addr,
},
[ID_AD5693] = {
.resolution = 16,
.register_map = AD5683_REG_MAP,
.communication = I2C,
.channel_addr = ad5683_channel_addr,
}
};
/***************************************************************************//**
* @brief Initializes the communication peripheral and the initial Values for
* AD5686 Board.
*
* @param device - The device structure.
* @param init_param - The structure that contains the device initial
* parameters.
*
* @return ret - The result of the initialization procedure.
* Example: -1 - I2C peripheral was not initialized or the
* device is not present.
* 0 - I2C peripheral was initialized and the
* device is present.
*******************************************************************************/
int32_t ad5686_init(struct ad5686_dev **device,
struct ad5686_init_param init_param)
{
struct ad5686_dev *dev;
int32_t ret;
dev = (struct ad5686_dev *)no_os_malloc(sizeof(*dev));
if (!dev)
return -1;
dev->act_device = init_param.act_device;
dev->power_down_mask = 0;
dev->ldac_mask = 0;
if (chip_info[dev->act_device].communication == SPI)
ret = no_os_spi_init(&dev->spi_desc, &init_param.spi_init);
else
ret = no_os_i2c_init(&dev->i2c_desc, &init_param.i2c_init);
/* GPIO */
ret |= no_os_gpio_get(&dev->gpio_reset, &init_param.gpio_reset);
ret |= no_os_gpio_get(&dev->gpio_ldac, &init_param.gpio_ldac);
ret |= no_os_gpio_get(&dev->gpio_gain, &init_param.gpio_gain);
if (dev->gpio_ldac)
ret |= no_os_gpio_direction_output(dev->gpio_ldac, NO_OS_GPIO_LOW);
if (dev->gpio_reset)
ret |= no_os_gpio_direction_output(dev->gpio_reset, NO_OS_GPIO_HIGH);
if (dev->gpio_gain)
ret |= no_os_gpio_direction_output(dev->gpio_gain, NO_OS_GPIO_LOW);
*device = dev;
return ret;
}
/***************************************************************************//**
* @brief Free the resources allocated by ad5686_init().
*
* @param dev - The device structure.
*
* @return ret - The result of the remove procedure.
*******************************************************************************/
int32_t ad5686_remove(struct ad5686_dev *dev)
{
int32_t ret;
if (chip_info[dev->act_device].communication == SPI)
ret = no_os_spi_remove(dev->spi_desc);
else
ret = no_os_i2c_remove(dev->i2c_desc);
if (dev->gpio_ldac)
ret |= no_os_gpio_remove(dev->gpio_ldac);
if (dev->gpio_reset)
ret |= no_os_gpio_remove(dev->gpio_reset);
if (dev->gpio_gain)
ret |= no_os_gpio_remove(dev->gpio_gain);
no_os_free(dev);
return ret;
}
/**************************************************************************//**
* @brief Write to input shift register.
*
* @param dev - The device structure.
* @param command - Command control bits.
* @param address - The address bits.
* @param data - Data to be written in input register.
*
* @return read_back_data - value read from register.
******************************************************************************/
uint16_t ad5686_set_shift_reg(struct ad5686_dev *dev,
uint8_t command,
uint8_t address,
uint16_t data)
{
uint8_t data_buff [ PKT_LENGTH ] = {0, 0, 0};
uint16_t read_back_data = 0;
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP) {
data_buff[0] = ((command & AD5686_CMD_MASK) << CMD_OFFSET) | \
(address & ADDR_MASK);
data_buff[1] = (data & AD5686_MSB_MASK) >> AD5686_MSB_OFFSET;
data_buff[2] = (data & AD5686_LSB_MASK);
} else {
data_buff[0] = ((command & AD5683_CMD_MASK) << CMD_OFFSET) |
((data >> AD5683_MSB_OFFSET) & AD5683_MSB_MASK);
data_buff[1] = (data >> AD5683_MIDB_OFFSET) & AD5683_MIDB_MASK;
data_buff[2] = (data & AD5683_LSB_MASK) << AD5683_LSB_OFFSET;
}
if(chip_info[dev->act_device].communication == SPI) {
no_os_spi_write_and_read(dev->spi_desc, data_buff, PKT_LENGTH);
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP)
read_back_data = (data_buff[1] << AD5686_MSB_OFFSET) | data_buff[2];
else
read_back_data = (data_buff[0] & AD5683_CMD_MASK) << AD5683_MSB_OFFSET |
data_buff[1] << AD5683_MIDB_OFFSET |
data_buff[2] >> AD5683_LSB_OFFSET;
} else
no_os_i2c_write(dev->i2c_desc, data_buff, PKT_LENGTH, 1);
return read_back_data;
}
/**************************************************************************//**
* @brief Write to Input Register n (dependent on LDAC)
*
* @param dev - The device structure.
* @param channel - The chosen channel to write to.
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @param data - desired value to be written in register.
*
* @return None.
******************************************************************************/
void ad5686_write_register(struct ad5686_dev *dev,
enum ad5686_dac_channels channel,
uint16_t data)
{
uint8_t data_offset = MAX_RESOLUTION - \
chip_info[dev->act_device].resolution;
uint8_t address = chip_info[dev->act_device].channel_addr[channel];
ad5686_set_shift_reg(dev, AD5686_CTRL_WRITE, address,
data << data_offset);
}
/**************************************************************************//**
* @brief Update DAC Register n with contents of Input Register n
*
* @param dev - The device structure.
* @param channel - The chosen channel to write to.
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @return None.
******************************************************************************/
void ad5686_update_register(struct ad5686_dev *dev,
enum ad5686_dac_channels channel)
{
uint8_t address = chip_info[dev->act_device].channel_addr[channel];
ad5686_set_shift_reg(dev, AD5686_CTRL_UPDATE, address, 0);
}
/**************************************************************************//**
* @brief Write to and update DAC channel n
*
* @param dev - The device structure.
* @param channel - The chosen channel to write to.
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @param data - Desired value to be written in register.
*
* @return None.
******************************************************************************/
void ad5686_write_update_register(struct ad5686_dev *dev,
enum ad5686_dac_channels channel,
uint16_t data)
{
uint8_t data_offset = MAX_RESOLUTION - \
chip_info[dev->act_device].resolution;
uint8_t address = chip_info[dev->act_device].channel_addr[channel];
ad5686_set_shift_reg(dev, AD5686_CTRL_WRITEUPDATE, address,
data << data_offset);
}
/**************************************************************************//**
* @brief Read back Input Register n
*
* @param dev - The device structure.
* @param channel - The channel which will be read back. Note: only one
* channel should be selected, if there will be selected
* more than one channel, the channel A will be read back
* by default
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @return read_back_data - value read from register.
******************************************************************************/
uint16_t ad5686_read_back_register(struct ad5686_dev *dev,
enum ad5686_dac_channels channel)
{
uint16_t read_back_data = 0;
uint16_t offset = MAX_RESOLUTION - \
chip_info[dev->act_device].resolution;
uint8_t address = chip_info[dev->act_device].channel_addr[channel];
uint8_t rb_data_i2c[3] = { 0 };
if(chip_info[dev->act_device].communication == SPI) {
ad5686_set_shift_reg(dev, AD5686_CTRL_RB_REG, address, 0);
read_back_data = ad5686_set_shift_reg(dev, AD5686_CTRL_NOP, 0,
0);
read_back_data >>= offset;
} else {
if (chip_info[dev->act_device].register_map == AD5683_REG_MAP)
rb_data_i2c[0] = (AD5683_CTRL_RB_REG << CMD_OFFSET) |
address;
else
rb_data_i2c[0] = (AD5686_CTRL_RB_REG << CMD_OFFSET) |
address;
no_os_i2c_write(dev->i2c_desc, rb_data_i2c, 3, 0);
no_os_i2c_read(dev->i2c_desc, rb_data_i2c, 2, 1);
read_back_data = (rb_data_i2c[0] << 8) | rb_data_i2c[1];
}
return read_back_data;
}
/**************************************************************************//**
* @brief Set Power-down mode for DAC channel n
*
* @param dev - The device structure.
* @param channel - The chosen channel to change the power-down mode.
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @param mode - Power-down operation modes.
* Accepted values:
* 'AD5686_PWRM_NORMAL' - Normal Mode
* 'AD5686_PWRM_1K' - Power-down mode 1kOhm to GND
* 'AD5686_PWRM_100K' - Power-down mode 100kOhm to GND
* 'AD5686_PWRM_THREESTATE' - Three-State
* 'AD5686_PWRM_100K' is not available for AD5674R/AD5679R.
*
* @return None.
******************************************************************************/
void ad5686_power_mode(struct ad5686_dev *dev,
enum ad5686_dac_channels channel,
uint8_t mode)
{
uint8_t address = chip_info[dev->act_device].channel_addr[channel];
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP) {
/* AD5674R/AD5679R have 16 channels and 2 powerdown registers */
if (channel > AD5686_CH_7)
channel -= AD5686_CH_7 + 1;
dev->power_down_mask &= ~(0x3 << (channel *2));
dev->power_down_mask |= (mode << (channel *2));
ad5686_set_shift_reg(dev, AD5686_CTRL_PWR, address,
dev->power_down_mask);
} else {
ad5686_set_shift_reg(dev, AD5683_CMD_WR_CTRL_REG, address,
AD5683_CTRL_PWRM(mode));
}
}
/**************************************************************************//**
* @brief Set hardware LDAC mask register
*
* @param dev - The device structure.
* @param channel - In case of which channel ignore transitions on the LDAC
* pin.
* Accepted values: AD5686_CH_0
* AD5686_CH_1
* AD5686_CH_2
* AD5686_CH_3
* AD5686_CH_4
* AD5686_CH_5
* AD5686_CH_6
* AD5686_CH_7
* AD5686_CH_8
* AD5686_CH_9
* AD5686_CH_10
* AD5686_CH_11
* AD5686_CH_12
* AD5686_CH_13
* AD5686_CH_14
* AD5686_CH_15
* @param enable - Enable/disable channel.
* @return None.
******************************************************************************/
void ad5686_ldac_mask(struct ad5686_dev *dev,
enum ad5686_dac_channels channel,
uint8_t enable)
{
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP) {
dev->ldac_mask &= ~(0x1 << channel);
dev->ldac_mask |= (enable << channel);
ad5686_set_shift_reg(dev, AD5686_CTRL_LDAC_MASK, 0, dev->ldac_mask);
}
}
/**************************************************************************//**
* @brief Software reset (power-on reset)
*
* @param dev - The device structure.
*
* @return None.
******************************************************************************/
void ad5686_software_reset(struct ad5686_dev *dev)
{
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP)
ad5686_set_shift_reg(dev, AD5686_CTRL_SWRESET, 0, 0);
else
ad5686_set_shift_reg(dev, AD5683_CMD_WR_CTRL_REG, 0, AD5683_SW_RESET);
}
/**************************************************************************//**
* @brief Write to Internal reference setup register
*
* @param dev - The device structure.
* @param value - The internal reference register value
* Example : 'AD5686_INTREF_EN' - enable internal reference
* 'AD5686_INTREF_DIS' - disable internal reference
*
* @return None.
******************************************************************************/
void ad5686_internal_reference(struct ad5686_dev *dev,
uint8_t value)
{
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP)
ad5686_set_shift_reg(dev, AD5686_CTRL_IREF_REG, 0, value);
else
ad5686_set_shift_reg(dev, AD5683_CMD_WR_CTRL_REG, 0,
AD5683_CTRL_INT_REF(value));
}
/**************************************************************************//**
* @brief Set up DCEN register (daisy-chain enable)
*
* @param dev - The device structure.
* @param value - Enable or disable daisy-chain mode
* Example : 'AD5686_DC_EN' - daisy-chain enable
* 'AD5686_DC_DIS' - daisy-chain disable
*
* @return None.
******************************************************************************/
void ad5686_daisy_chain_en(struct ad5686_dev *dev,
uint8_t value)
{
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP)
ad5686_set_shift_reg(dev, AD5686_CTRL_DCEN, 0, value);
else
ad5686_set_shift_reg(dev, AD5683_CMD_WR_CTRL_REG, 0, AD5683_CTRL_DCEN(value));
}
/**************************************************************************//**
* @brief Set up readback register (readback enable)
*
* @param dev - The device structure.
* @param value - Enable or disable daisy-chain mode
* Example : 'AD5686_RB_EN' - daisy-chain enable
* 'AD5686_RB_DIS' - daisy-chain disable
*
* @return None.
******************************************************************************/
void ad5686_read_back_en(struct ad5686_dev *dev,
uint8_t value)
{
if(chip_info[dev->act_device].register_map == AD5686_REG_MAP)
ad5686_set_shift_reg(dev, AD5686_CTRL_RB_REG, 0, value);
}
/**************************************************************************//**
* @brief Set Gain mode
*
* @param dev - The device structure.
* @param value - Gain modes.
* Accepted values:
* Example : 'AD5683_GB_VREF' - 0V to VREF
* 'AD5683_GB_2VREF' - 0V to 2xVREF
*
* @return None.
******************************************************************************/
int32_t ad5686_gain_mode(struct ad5686_dev *dev, uint8_t value)
{
if(chip_info[dev->act_device].register_map == AD5683_REG_MAP)
return ad5686_set_shift_reg(dev, AD5683_CMD_WR_CTRL_REG, 0,
AD5683_CTRL_GM(value));
return -1;
}