tlv320dac3100 0.1.0

A driver for Texas Instruments TLV320DAC3100 module.
Documentation
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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
use embedded_hal as hal;
use hal::i2c::I2c;
use crate::bits::{get_bits, set_bits};
use crate::error::TLV320DAC3100Error;
use crate::registers::*;
use crate::typedefs::*;

pub const I2C_DEVICE_ADDRESS: u8 = 0x18;

pub struct TLV320DAC3100<I2C> {
    i2c: I2C
}

impl<I2C: I2c> TLV320DAC3100<I2C> {
    pub fn new(i2c: I2C) -> Self {
        TLV320DAC3100 { i2c }
    }

    pub fn get_bclk_n_val(&mut self, powered: &mut bool, divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, BCLK_N_VAL)?;
        *powered = get_bits(reg_val, 1, 7) == 1;
        *divider = get_bits(reg_val, 7, 0);
        Ok(())
    }

    pub fn get_beep_cos_x(&mut self, val: &mut u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb = (self.read_reg(0, BEEP_COS_X_MSB)? as u16) << 8;
        let lsb = self.read_reg(0, BEEP_COS_X_LSB)? as u16;
        *val = msb | lsb;
        Ok(())
    }

    pub fn get_beep_cos_x_msb(&mut self, msb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *msb = self.read_reg(0, BEEP_COS_X_MSB)?;
        Ok(())
    }

    pub fn get_beep_cos_x_lsb(&mut self, lsb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *lsb = self.read_reg(0, BEEP_COS_X_LSB)?;
        Ok(())
    }

    pub fn get_beep_length(&mut self, samples: &mut u32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut msb = (self.read_reg(0, BEEP_LENGTH_MSB)? as u32) << 16;
        let mid = (self.read_reg(0, BEEP_LENGTH_MIDDLE_BITS)? as u32) << 8;
        let lsb = self.read_reg(0, BEEP_LENGTH_LSB)? as u32;
        msb |= mid;
        msb |= lsb;
        *samples = msb;
        Ok(())
    }

    pub fn get_beep_length_msb(&mut self, msb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *msb = self.read_reg(0, BEEP_LENGTH_MSB)?;
        Ok(())
    }

    pub fn get_beep_length_middle_bits(&mut self, middle_bits: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *middle_bits = self.read_reg(0, BEEP_LENGTH_MIDDLE_BITS)?;
        Ok(())
    }

    pub fn get_beep_length_lsb(&mut self, lsb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *lsb = self.read_reg(0, BEEP_LENGTH_LSB)?;
        Ok(())
    }

    pub fn get_beep_sin_x(&mut self, val: &mut u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb = (self.read_reg(0, BEEP_SIN_X_MSB)? as u16) << 8;
        let lsb = self.read_reg(0, BEEP_SIN_X_LSB)? as u16;
        *val = msb | lsb;
        Ok(())
    }

    pub fn get_beep_sin_x_msb(&mut self, msb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *msb = self.read_reg(0, BEEP_SIN_X_MSB)?;
        Ok(())
    }

    pub fn get_beep_sin_x_lsb(&mut self, lsb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *lsb = self.read_reg(0, BEEP_SIN_X_LSB)?;
        Ok(())
    }

    pub fn get_class_d_spk_amplifier(&mut self, powered_up: &mut bool, scd: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, CLASS_D_SPEAKER_AMPLIFIER)?;
        *powered_up = get_bits(reg_val, 1, 7) == 1;
        *scd = get_bits(reg_val, 1, 0) == 1;
        Ok(())
    }

    pub fn get_class_d_spk_driver(&mut self, gain: &mut OutputStage, muted: &mut bool, gains_applied: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CLASS_D_SPK_DRIVER)?;
        *gain = get_bits(reg_val, 2, 3).try_into().unwrap();
        *muted = get_bits(reg_val, 1, 2) == 0;
        *gains_applied = get_bits(reg_val, 1, 0) == 1;
        Ok(())
    }

    pub fn get_clkout_m_val(&mut self, powered: &mut bool, divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CLKOUT_M_VAL)?;
        *powered = get_bits(reg_val, 1, 7) == 1;
        *divider = reg_val & 0b0111_1111;
        Ok(())
    }

    pub fn get_clkout_mux(&mut self, cdiv_clkin: &mut CdivClkin) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *cdiv_clkin = get_bits(self.read_reg(0, CLKOUT_MUX)?, 3, 0).try_into().unwrap();
        Ok(())
    }

    pub fn get_clock_gen_muxing(&mut self, pll_clkin: &mut PllClkin, codec_clkin: &mut CodecClkin) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CLOCK_GEN_MUXING)?;
        *pll_clkin = get_bits(reg_val, 2, 2).try_into().unwrap();
        *codec_clkin = get_bits(reg_val, 2, 0).try_into().unwrap();
        Ok(())
    }

    pub fn get_codec_interface_control_1(
        &mut self,
        codec_interface: &mut CodecInterface,
        word_length: &mut CodecInterfaceWordLength,
        bclk_output: &mut bool,
        wclk_output: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CODEC_INTERFACE_CONTROL_1)?;
        *codec_interface = get_bits(reg_val, 2, 6).try_into().unwrap();
        *word_length = get_bits(reg_val, 2, 4).try_into().unwrap();
        *bclk_output = get_bits(reg_val, 1, 3) == 1;
        *wclk_output = get_bits(reg_val, 1, 2) == 1;
        Ok(())
    }

    pub fn get_codec_interface_control_2(
        &mut self,
        bclk_inverted: &mut bool,
        bclk_wclk_always_active: &mut bool,
        bdiv_clkin: &mut BdivClkin
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CODEC_INTERFACE_CONTROL_2)?;
        *bclk_inverted = get_bits(reg_val, 1, 3) == 1;
        *bclk_wclk_always_active = get_bits(reg_val, 1, 2) == 1;
        *bdiv_clkin = get_bits(reg_val, 2, 0).try_into().unwrap();
        Ok(())
    }

    pub fn get_codec_secondary_interface_control_1(
        &mut self,
        bclk_from_gpio1: &mut bool,
        wclk_from_gpio1: &mut bool,
        din_from_gpio1: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_1)?;
        *bclk_from_gpio1 = get_bits(reg_val, 3, 5) == 0;
        *wclk_from_gpio1 = get_bits(reg_val, 3, 2) == 0;
        *din_from_gpio1 = get_bits(reg_val, 2, 0) == 0;
        Ok(())
    }

    pub fn get_codec_secondary_interface_control_2(
        &mut self,
        secondary_bclk: &mut bool,
        secondary_wclk: &mut bool,
        secondary_din: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_2)?;
        *secondary_bclk = get_bits(reg_val, 1, 3) == 1;
        *secondary_wclk = get_bits(reg_val, 1, 2) == 1;
        *secondary_din = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_codec_secondary_interface_control_3(
        &mut self,
        primary_bclk: &mut PrimaryBclkOutput,
        secondary_bclk: &mut SecondaryBclkOutput,
        primary_wclk: &mut PrimaryWclkOutput,
        secondary_wclk: &mut SecondaryWclkOutput
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_3)?;
        *primary_bclk = get_bits(reg_val, 1, 7).try_into().unwrap();
        *secondary_bclk = get_bits(reg_val, 1, 6).try_into().unwrap();
        *primary_wclk = get_bits(reg_val, 2, 4).try_into().unwrap();
        *secondary_wclk = get_bits(reg_val, 2, 2).try_into().unwrap();
        Ok(())
    }

    pub fn get_dac_coefficient_ram_control(
        &mut self,
        adaptive_filtering: &mut bool,
        filter_buffer_a: &mut bool,
        coefficient_buffers_switched: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val: u8 = self.read_reg(8, DAC_COEFFICIENT_RAM_CONTROL)?;
        *adaptive_filtering = get_bits(reg_val, 1, 2) == 1;
        *filter_buffer_a = get_bits(reg_val, 1, 1) == 1;
        *coefficient_buffers_switched = get_bits(reg_val, 1, 0) == 1;
        Ok(())
    }

    pub fn get_dac_data_path_setup(
        &mut self,
        left_powered: &mut bool,
        right_powered: &mut bool,
        left_data_path: &mut LeftDataPath,
        right_data_path: &mut RightDataPath,
        soft_stepping: &mut SoftStepping
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DAC_DATA_PATH_SETUP)?;
        *left_powered = get_bits(reg_val, 1, 7) == 1;
        *right_powered = get_bits(reg_val, 1, 6) == 1;
        *left_data_path = get_bits(reg_val, 2, 4).try_into().unwrap();
        *right_data_path = get_bits(reg_val, 2, 2).try_into().unwrap();
        *soft_stepping = (reg_val & 0b11).try_into().unwrap();
        Ok(())
    }

    pub fn get_dac_dosr_val(&mut self, dosr: &mut u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb = self.read_reg(0, DAC_DOSR_VAL_MSB)?;
        let lsb = self.read_reg(0, DAC_DOSR_VAL_LSB)?;
        *dosr = (msb as u16) << 8 | lsb as u16;
        Ok(())
    }

    pub fn get_dac_dosr_val_msb(&mut self, msb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *msb = self.read_reg(0, DAC_DOSR_VAL_MSB)?;
        Ok(())
    }

    pub fn get_dac_dosr_val_lsb(&mut self, lsb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *lsb = self.read_reg(0, DAC_DOSR_VAL_LSB)?;
        Ok(())
    }

    pub fn get_dac_flag_register_1(
        &mut self,
        dac_left_powered: &mut bool,
        hp_left_powered: &mut bool,
        amp_left_powered: &mut bool,
        dac_right_powered: &mut bool,
        hp_right_powered: &mut bool,
        amp_right_powered: &mut bool,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DAC_FLAG_REGISTER_1)?;
        *dac_left_powered = get_bits(reg_val, 1, 7) == 1;
        *hp_left_powered = get_bits(reg_val, 1, 5) == 1;
        *amp_left_powered = get_bits(reg_val, 1, 4) == 1;
        *dac_right_powered = get_bits(reg_val, 1, 3) == 1;
        *hp_right_powered = get_bits(reg_val, 1, 1) == 1;
        *amp_right_powered = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_dac_flag_register_2(&mut self, left_gain_equiv: &mut bool, right_gain_equiv: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DAC_FLAG_REGISTER_2)?;
        *left_gain_equiv = get_bits(reg_val, 1, 4) == 1;
        *right_gain_equiv = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_dac_interrupt_flags(
        &mut self,
        left_scd: &mut bool,
        right_scd: &mut bool,
        headset_button_pressed: &mut bool,
        headset_insert_removal_detected: &mut bool,
        left_dac_signal_above_drc: &mut bool,
        right_dac_signal_above_drc: &mut bool,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DAC_INTERRUPT_FLAGS_STICKY_BITS)?;
        *left_scd = get_bits(reg_val, 1, 7) == 1;
        *right_scd = get_bits(reg_val, 1, 6) == 1;
        *headset_button_pressed = get_bits(reg_val, 1, 5) == 1;
        *headset_insert_removal_detected = get_bits(reg_val, 1, 4) == 1;
        *left_dac_signal_above_drc = get_bits(reg_val, 1, 3) == 1;
        *right_dac_signal_above_drc = get_bits(reg_val, 1, 2) == 1;
        Ok(())
    }

    pub fn get_dac_l_and_dac_r_output_mixer_routing(
        &mut self,
        left_routing: &mut DacLeftOutputMixerRouting,
        ain1_input_routed_left: &mut bool,
        ain2_input_routed_left: &mut bool,
        right_routing: &mut DacRightOutputMixerRouting,
        ain2_input_routed_right: &mut bool,
        hpl_output_routed_to_hpr: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, DAC_L_AND_DAC_R_OUTPUT_MIXER_ROUTING)?;
        *left_routing = get_bits(reg_val, 2, 6).try_into().unwrap();
        *ain1_input_routed_left = get_bits(reg_val, 1, 5) == 1;
        *ain2_input_routed_left = get_bits(reg_val, 1, 4) == 1;
        *right_routing = get_bits(reg_val, 2, 2).try_into().unwrap();
        *ain2_input_routed_right = get_bits(reg_val, 1, 1) == 1;
        *hpl_output_routed_to_hpr = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_dac_left_volume_control(&mut self, db: &mut f32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *db = ((self.read_reg(0, DAC_LEFT_VOLUME_CONTROL)? as i8) as f32) / 2.0;
        Ok(())
    }

    fn get_dac_xdac_val(&mut self, mdac: bool, powered: &mut bool, divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, if mdac { DAC_MDAC_VAL } else { DAC_NDAC_VAL })?;
        *powered = get_bits(reg_val, 1, 7) == 1;
        *divider = reg_val & 0b111_1111;
        Ok(())
    }

    pub fn get_dac_mdac_val(&mut self, powered: &mut bool, divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_dac_xdac_val(true, powered, divider)
    }

    pub fn get_dac_ndac_val(&mut self, powered: &mut bool, divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_dac_xdac_val(false, powered, divider)
    }

    pub fn get_dac_processing_block_selection(&mut self, prb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *prb = self.read_reg(0, DAC_PROCESSING_BLOCK_SECTION)? & 0b1_1111;
        Ok(())
    }

    pub fn get_dac_right_volume_control(&mut self, db: &mut f32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *db = ((self.read_reg(0, DAC_RIGHT_VOLUME_CONTROL)? as i8) as f32) / 2.0;
        Ok(())
    }

    pub fn get_dac_volume_control(
        &mut self,
        left_muted: &mut bool,
        right_muted: &mut bool,
        control: &mut VolumeControl
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DAC_VOLUME_CONTROL)?;
        *left_muted = get_bits(reg_val, 1, 3) == 1;
        *right_muted = get_bits(reg_val, 1, 2) == 1;
        *control = (reg_val & 0b11).try_into().unwrap();
        Ok(())
    }

    pub fn get_data_slot_offset_programmability(&mut self, offset: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *offset = self.read_reg(0, DATA_SLOT_OFFSET_PROGRAMMABILITY)?;
        Ok(())
    }

    pub fn get_din_control(&mut self, din_control: &mut DinControl, input_buffer: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DIN_CONTROL)?;
        *din_control = get_bits(reg_val, 2, 1).try_into().unwrap();
        *input_buffer = reg_val & 0b1;
        Ok(())
    }

    pub fn get_drc_control_1(
        &mut self,
        left: &mut bool,
        right: &mut bool,
        threshold: &mut u8,
        hysteresis: &mut u8
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DRC_CONTROL_1)?;
        *left = get_bits(reg_val, 1, 6) == 1;
        *right = get_bits(reg_val, 1, 5) == 1;
        *threshold = get_bits(reg_val, 3, 2);
        *hysteresis = reg_val & 0b11;
        Ok(())
    }

    pub fn get_drc_control_2(&mut self, hold_time: &mut HoldTime) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *hold_time = get_bits(self.read_reg(0, DRC_CONTROL_2)?, 4, 3).try_into().unwrap();
        Ok(())
    }


    pub fn get_drc_control_3(
        &mut self,
        attack_rate: &mut u8,
        decay_rate: &mut u8
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, DRC_CONTROL_3)?;
        *attack_rate = get_bits(reg_val, 4, 4);
        *decay_rate = reg_val & 0b1111;
        Ok(())
    }

    pub fn get_gpio1_io_pin_control(
        &mut self,
        mode: &mut Gpio1Mode,
        input_buffer_value: &mut u8,
        output_value: &mut u8
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, GPIO1_IN_OUT_PIN_CONTROL)?;
        *mode = get_bits(reg_val, 4, 2).try_into().unwrap();
        *input_buffer_value = get_bits(reg_val, 1, 1);
        *output_value = reg_val & 0b1;
        Ok(())
    }

    pub fn get_headphone_and_speaker_amplifier_error_control(
        &mut self,
        preserve_spk_ctrl_bits: &mut bool,
        preserve_hp_ctrl_bits: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, HEADPHONE_AND_SPEAKER_AMPLIFIER_ERROR_CONTROL)?;
        *preserve_spk_ctrl_bits = get_bits(reg_val, 1, 1) == 1;
        *preserve_hp_ctrl_bits = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_headset_detection(
        &mut self,
        enabled: &mut bool,
        detected: &mut HeadsetDetected,
        debounce: &mut HeadsetDetectionDebounce,
        button_debounce: &mut HeadsetButtonPressDebounce
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, HEADSET_DETECTION)?;
        *enabled = get_bits(reg_val, 1, 7) == 1;
        *detected = get_bits(reg_val, 2, 5).try_into().unwrap();
        *debounce = get_bits(reg_val, 3, 2).try_into().unwrap();
        *button_debounce = (reg_val & 0b11).try_into().unwrap();
        Ok(())
    }

    pub fn get_headphone_drivers(
        &mut self,
        left_powered: &mut bool,
        right_powered: &mut bool,
        output_voltage: &mut HpOutputVoltage,
        power_down_on_scd: &mut bool,
        scd_detected: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, HEADPHONE_DRIVERS)?;
        *left_powered = get_bits(reg_val, 1, 7) == 1;
        *right_powered = get_bits(reg_val, 1, 6) == 1;
        *output_voltage = get_bits(reg_val, 2, 3).try_into().unwrap();
        *power_down_on_scd = get_bits(reg_val, 1, 1) == 1;
        *scd_detected = reg_val & 0b1 == 1;
        Ok(())
    }

    pub fn get_hp_driver_control(
        &mut self,
        scd_debounce: &mut HpScdDebounce,
        mode: &mut HpMode,
        hpl_lineout: &mut bool,
        hpr_lineout: &mut bool,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, HP_DRIVER_CONTROL)?;
        *scd_debounce = ((reg_val & 0b1110_0000) >> 5).try_into().unwrap();
        *mode = ((reg_val & 0b1_1000) >> 3).try_into().unwrap();
        *hpl_lineout = ((reg_val & 0b100) >> 2) == 1;
        *hpr_lineout = ((reg_val & 0b10) >> 1) == 1;
        Ok(())
    }

    pub fn get_hp_output_drivers_pop_removal_settings(
        &mut self,
        optimize_power_down_pop: &mut bool,
        power_on: &mut HpPowerOn,
        ramp_up: &mut HpRampUp,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, HP_OUTPUT_DRIVERS_POP_REMOVAL_SETTINGS)?;
        *optimize_power_down_pop = (reg_val & 0b1000_0000) == 1;
        *power_on = (reg_val & 0b111_1000).try_into().unwrap();
        *ramp_up = (reg_val & 0b110).try_into().unwrap();
        Ok(())
    }

    pub fn get_hpl_driver(&mut self, pga: &mut u8, hpl_muted: &mut bool, gains_applied: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_hpx_driver(true, pga, hpl_muted, gains_applied)
    }

    pub fn get_hpr_driver(&mut self, pga: &mut u8, hpr_muted: &mut bool, gains_applied: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_hpx_driver(false, pga, hpr_muted, gains_applied)
    }

    fn get_hpx_driver(&mut self, hpl: bool, pga: &mut u8, hpx_muted: &mut bool, gains_applied: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, if hpl { HPL_DRIVER } else { HPR_DRIVER })?;
        *pga = get_bits(reg_val, 4, 3);
        *hpx_muted = get_bits(reg_val, 1, 2) == 1;
        *gains_applied = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_i2c_bus_condition(&mut self, accept_address: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *accept_address = get_bits(self.read_reg(0, I2C_BUS_CONDITION)?, 1, 5) == 1;
        Ok(())
    }

    pub fn get_input_cm_settings(&mut self, ain1_to_cm: &mut bool, ain2_to_cm: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, INPUT_CM_SETTINGS)?;
        *ain1_to_cm = get_bits(reg_val, 1, 7) == 1;
        *ain2_to_cm = get_bits(reg_val, 1, 6) == 1;
        Ok(())
    }

    pub fn get_interrupt_flags_dac(
        &mut self,
        hpl_scd_detected: &mut bool,
        hpr_scd_detected: &mut bool,
        headset_btn_pressed: &mut bool,
        headset_insertion_detected: &mut bool,
        left_signal_gt_drc: &mut bool,
        right_signal_gt_drc: &mut bool,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, INTERRUPT_FLAGS_DAC)?;
        *hpl_scd_detected = get_bits(reg_val, 1, 7) == 1;
        *hpr_scd_detected = get_bits(reg_val, 1, 6) == 1;
        *headset_btn_pressed = get_bits(reg_val, 1, 5) == 1;
        *headset_insertion_detected = get_bits(reg_val, 1, 4) == 1;
        *left_signal_gt_drc = get_bits(reg_val, 1, 3) == 1;
        *right_signal_gt_drc = get_bits(reg_val, 1, 2) == 1;
        Ok(())
    }

    fn get_int_control_register(
        &mut self,
        int1: bool,
        headset_detect: &mut bool,
        button_press: &mut bool,
        use_drc_signal_power: &mut bool,
        short_circuit: &mut bool,
        data_overflow: &mut bool,
        multiple_pulses: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, if int1 { INT1_CONTROL_REGISTER } else { INT2_CONTROL_REGISTER })?;
        *headset_detect = get_bits(reg_val, 1, 7) == 1;
        *button_press = get_bits(reg_val, 1, 6) == 1;
        *use_drc_signal_power = get_bits(reg_val, 1, 5) == 1;
        *short_circuit = get_bits(reg_val, 1, 3) == 1;
        *data_overflow = get_bits(reg_val, 1, 2) == 1;
        *multiple_pulses = (reg_val & 0b1) == 1;
        Ok(())
    }

    pub fn get_int1_control_register(
        &mut self,
        headset_detect: &mut bool,
        button_press: &mut bool,
        use_drc_signal_power: &mut bool,
        short_circuit: &mut bool,
        data_overflow: &mut bool,
        multiple_pulses: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_int_control_register(
            true,
            headset_detect,
            button_press,
            use_drc_signal_power,
            short_circuit,
            data_overflow,
            multiple_pulses
        )
    }

    pub fn get_int2_control_register(
        &mut self,
        headset_detect: &mut bool,
        button_press: &mut bool,
        use_drc_signal_power: &mut bool,
        short_circuit: &mut bool,
        data_overflow: &mut bool,
        multiple_pulses: &mut bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.get_int_control_register(
            false,
            headset_detect,
            button_press,
            use_drc_signal_power,
            short_circuit,
            data_overflow,
            multiple_pulses
        )
    }

    pub fn get_left_analog_volume_to_hpl(&mut self, route_to_hpl: &mut bool, gain: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, LEFT_ANALOG_VOLUME_TO_HPL)?;
        *route_to_hpl = get_bits(reg_val, 1, 7) == 1;
        *gain = (reg_val & 0b111_1111).try_into().unwrap();
        Ok(())
    }

    pub fn get_left_analog_volume_to_spk(&mut self, route_to_class_d: &mut bool, gain: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, LEFT_ANALOG_VOLUME_TO_SPK)?;
        *route_to_class_d = get_bits(reg_val, 1, 7) == 1;
        *gain = reg_val & 0b111_1111;
        Ok(())
    }

    pub fn get_left_beep_generator(&mut self, enabled: &mut bool, volume: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, LEFT_BEEP_GENERATOR)?;
        *enabled = get_bits(reg_val, 1, 7) == 1;
        *volume = reg_val & 0b11_1111;
        Ok(())
    }

    pub fn get_micbias(
        &mut self,
        power_down: &mut bool,
        always_on: &mut bool,
        output: &mut MicBiasOutput
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, MICBIAS)?;
        *power_down = get_bits(reg_val, 1, 7) == 1;
        *always_on = get_bits(reg_val, 1, 3) == 1;
        *output = (reg_val & 0b11).try_into().unwrap();
        Ok(())
    }

    pub fn get_ot_flag(&mut self, ot_flag: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *ot_flag = self.read_reg(0, OT_FLAG)? >> 1 == 0; // active low
        Ok(())
    }

    pub fn get_output_driver_pga_ramp_down_period_control(&mut self, ramp_down: &mut PgaRampDown) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *ramp_down = get_bits(self.read_reg(1, OUTPUT_DRIVER_PGA_RAMP_DOWN_PERIOD_CONTROL)?, 3, 4).try_into().unwrap();
        Ok(())
    }

    pub fn get_overflow_flags(&mut self, left: &mut bool, right: &mut bool, barrel_shifter: &mut bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, OVERFLOW_FLAGS)?;
        *left = get_bits(reg_val, 1, 7) == 1;
        *right = get_bits(reg_val, 1, 6) == 1;
        *barrel_shifter = get_bits(reg_val, 1, 5) == 1;
        Ok(())
    }

    pub fn get_pll_d_value(&mut self, d: &mut u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb = self.read_reg(0, PLL_D_VALUE_MSB)?;
        let lsb = self.read_reg(0, PLL_D_VALUE_LSB)?;
        *d = (msb as u16) << 8 | lsb as u16;
        Ok(())
    }

    pub fn get_pll_d_value_msb(&mut self, msb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *msb = self.read_reg(0, PLL_D_VALUE_MSB)?;
        Ok(())
    }

    pub fn get_pll_d_value_lsb(&mut self, lsb: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *lsb = self.read_reg(0, PLL_D_VALUE_LSB)?;
        Ok(())
    }

    pub fn get_pll_j_value(&mut self, j: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *j = self.read_reg(0, PLL_J_VALUE)? & 0b11_1111;
        Ok(())
    }

    pub fn get_pll_p_and_r_values(&mut self, powered: &mut bool, p: &mut u8, r: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, PLL_P_AND_R_VALUES)?;
        *powered = get_bits(reg_val, 1, 7) == 1;
        *p = get_bits(reg_val, 3, 4);
        *r = 0b1111 & reg_val;
        Ok(())
    }

    pub fn get_right_analog_volume_to_hpr(&mut self, route_to_hpr: &mut bool, gain: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(1, RIGHT_ANALOG_VOLUME_TO_HPR)?;
        *route_to_hpr = get_bits(reg_val, 1, 7) == 1;
        *gain = (reg_val & 0b111_1111).try_into().unwrap();
        Ok(())
    }

    pub fn get_right_beep_generator(&mut self, mode: &mut RightBeepMode, volume: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, RIGHT_BEEP_GENERATOR)?;
        *mode = get_bits(reg_val, 2, 6).try_into().unwrap();
        *volume = reg_val & 0b11_1111;
        Ok(())
    }

    pub fn get_timer_clock_mclk_divider(&mut self, external_mclk: &mut bool, mclk_divider: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(3, TIMER_CLOCK_MCLK_DIVIDER)?;
        *external_mclk = get_bits(reg_val, 1, 7) == 1;
        *mclk_divider = reg_val & 0b111_1111;
        Ok(())
    }

    pub fn get_vol_micdet_pin_gain(&mut self, gain: &mut u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        *gain = self.read_reg(0, VOL_MICDET_PIN_GAIN)?;
        Ok(())
    }

    pub fn get_vol_micdet_pin_sar_adc(&mut self, pin_control: &mut bool, use_mclk: &mut bool, hysteresis: &mut VolumeControlHysteresis, throughput: &mut VolumeControlThroughput) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_val = self.read_reg(0, VOL_MICDET_PIN_SAR_ADC)?;
        *pin_control = get_bits(reg_val, 1, 7) == 1;
        *use_mclk = get_bits(reg_val, 1, 6) == 1;
        *hysteresis = get_bits(reg_val,2, 4).try_into().unwrap();
        *throughput = (reg_val & 0b111).try_into().unwrap();
        Ok(())
    }

    pub fn read_reg(&mut self, page: u8, reg: u8) -> Result<u8, TLV320DAC3100Error<I2C::Error>> {
        self.select_page(page)?;
        let mut buf = [0u8];
        self.i2c.write_read(I2C_DEVICE_ADDRESS, &[reg], &mut buf).map_err(TLV320DAC3100Error::I2C)?;
        Ok(buf[0])
    }

    fn select_page(&mut self, page: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        Ok(self.i2c.write(I2C_DEVICE_ADDRESS, &[PAGE_CONTROL, page]).map_err(TLV320DAC3100Error::I2C)?)
    }

    pub fn set_bclk_n_val(&mut self, powered: bool, divider: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = (powered as u8) << 7;
        if divider < 128 {
            set_bits(&mut reg_val, divider, 0, 0b0111_1111);
        }
        self.write_reg(0, BCLK_N_VAL, reg_val)
    }

    pub fn set_beep_length(&mut self, samples: u32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if samples > 16777215 { return Err(TLV320DAC3100Error::InvalidArgument) }

        self.write_reg(0, BEEP_LENGTH_MSB, ((samples >> 16) & 0xff) as u8)?;
        self.write_reg(0, BEEP_LENGTH_MIDDLE_BITS, ((samples >> 8) & 0xff) as u8)?;
        self.write_reg(0, BEEP_LENGTH_LSB, (samples & 0xff) as u8)
    }

    pub fn set_beep_cos_x(&mut self, val: u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.write_reg(0, BEEP_COS_X_MSB, (val >> 8) as u8)?;
        self.write_reg(0, BEEP_COS_X_LSB, (val & 0xff) as u8)
    }

    pub fn set_beep_sin_x(&mut self, val: u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.write_reg(0, BEEP_SIN_X_MSB, (val >> 8) as u8)?;
        self.write_reg(0, BEEP_SIN_X_LSB, (val & 0xff) as u8)
    }

    pub fn set_class_d_spk_amp(&mut self, powered_up: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, CLASS_D_SPEAKER_AMPLIFIER)?;
        reg_val |= (powered_up as u8) << 7;
        self.write_reg(1, CLASS_D_SPEAKER_AMPLIFIER, reg_val)
    }

    pub fn set_class_d_spk_driver(&mut self, output_stage_gain: OutputStage, driver_muted: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, CLASS_D_SPK_DRIVER)?;
        set_bits(&mut reg_val, output_stage_gain as u8, 3, 0b0001_1000);
        set_bits(&mut reg_val, !driver_muted as u8, 2, 0b0000_0100);
        self.write_reg(1, CLASS_D_SPK_DRIVER, reg_val)
    }

    pub fn set_clock_gen_muxing(&mut self, pll_clkin: PllClkin, codec_clkin: CodecClkin) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = (pll_clkin as u8) << 2;
        reg_val |= codec_clkin as u8;
        self.write_reg(0, CLOCK_GEN_MUXING, reg_val)
    }

    pub fn set_clkout_m_val(&mut self, powered: bool, divider: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if divider == 0 || divider == 128 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = (powered as u8) << 7;
        reg_val |= divider;
        self.write_reg(0, CLKOUT_M_VAL, reg_val)
    }

    pub fn set_clkout_mux(&mut self, cdiv_clkin: CdivClkin) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, CLKOUT_MUX)?;
        set_bits(&mut reg_val, cdiv_clkin as u8, 0, 0b0000_0111);
        self.write_reg(0, CLKOUT_MUX, reg_val)
    }

    pub fn set_codec_interface_control_1(
        &mut self,
        codec_interface: CodecInterface,
        word_length: CodecInterfaceWordLength,
        bclk_output: bool,
        wclk_output: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, CODEC_INTERFACE_CONTROL_1)?;
        set_bits(&mut reg_val, codec_interface as u8, 6, 0b1100_0000);
        set_bits(&mut reg_val, word_length as u8, 4, 0b0011_0000);
        set_bits(&mut reg_val, bclk_output as u8, 3, 0b0000_1000);
        set_bits(&mut reg_val, wclk_output as u8, 2, 0b0000_0100);
        self.write_reg(0, CODEC_INTERFACE_CONTROL_1, reg_val)
    }

    pub fn set_codec_interface_control_2(
        &mut self,
        bclk_inverted: bool,
        bclk_wclk_always_active: bool,
        bdiv_clkin: BdivClkin
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, CODEC_INTERFACE_CONTROL_2)?;
        set_bits(&mut reg_val, bclk_inverted as u8, 3, 0b0000_1000);
        set_bits(&mut reg_val, bclk_wclk_always_active as u8, 2, 0b0000_0100);
        set_bits(&mut reg_val, bdiv_clkin as u8, 0, 0b0000_0011);
        self.write_reg(0, CODEC_INTERFACE_CONTROL_2, reg_val)
    }

    pub fn set_codec_secondary_interface_control_1(
        &mut self,
        bclk_from_gpio1: bool,
        wclk_from_gpio1: bool,
        din_from_gpio1: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = (!bclk_from_gpio1 as u8) << 5;
        set_bits(&mut reg_val, !wclk_from_gpio1 as u8, 2, 0b1100);
        set_bits(&mut reg_val, !din_from_gpio1 as u8, 0, 0b11);
        self.write_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_1, reg_val)
    }

    pub fn set_codec_secondary_interface_control_2(
        &mut self,
        secondary_bclk: bool,
        secondary_wclk: bool,
        secondary_din: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_2)?;
        set_bits(&mut reg_val, secondary_bclk as u8, 3, 0b0000_1000);
        set_bits(&mut reg_val, secondary_wclk as u8, 2, 0b0000_0100);
        set_bits(&mut reg_val, secondary_din as u8, 0, 0b0000_0001);
        self.write_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_2, reg_val)
    }

    pub fn set_codec_secondary_interface_control_3(
        &mut self,
        primary_bclk: PrimaryBclkOutput,
        secondary_bclk: SecondaryBclkOutput,
        primary_wclk: PrimaryWclkOutput,
        secondary_wclk: SecondaryWclkOutput
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_3)?;
        set_bits(&mut reg_val, primary_bclk as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, secondary_bclk as u8, 6, 0b100_0000);
        set_bits(&mut reg_val, primary_wclk as u8, 4, 0b11_0000);
        set_bits(&mut reg_val, secondary_wclk as u8, 2, 0b1100);
        self.write_reg(0, CODEC_SECONDARY_INTERFACE_CONTROL_3, reg_val)
    }

    pub fn set_dac_coefficient_ram_control(
        &mut self,
        adaptive_filtering: bool,
        filter_buffer_a: bool,
        coefficient_buffers_switched: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val: u8 = self.read_reg(8, DAC_COEFFICIENT_RAM_CONTROL)?;
        set_bits(&mut reg_val, adaptive_filtering as u8, 2, 0b100);
        set_bits(&mut reg_val, filter_buffer_a as u8, 1, 0b10);
        set_bits(&mut reg_val, coefficient_buffers_switched as u8, 0, 0b1);
        self.write_reg(8, DAC_COEFFICIENT_RAM_CONTROL, reg_val)
    }

    pub fn set_dac_data_path_setup(
        &mut self,
        left_powered: bool,
        right_powered: bool,
        left_data_path: LeftDataPath,
        right_data_path: RightDataPath,
        soft_stepping: SoftStepping
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val: u8 = (left_powered as u8) << 7;
        reg_val |= (right_powered as u8) << 6;
        reg_val |= (left_data_path as u8) << 4;
        reg_val |= (right_data_path as u8) << 2;
        reg_val |= soft_stepping as u8;
        self.write_reg(0, DAC_DATA_PATH_SETUP, reg_val)
    }

    pub fn set_dac_dosr_val(&mut self, osr: u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb = ((0xff00 & osr) >> 8) as u8;
        if msb > 3 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let lsb: u8 = (0x00ff & osr) as u8;
        if lsb == 1 || lsb == 255 { return Err(TLV320DAC3100Error::InvalidArgument) }

        self.write_reg(0, DAC_DOSR_VAL_MSB, msb)?;
        self.write_reg(0, DAC_DOSR_VAL_LSB, lsb)
    }

    pub fn set_dac_l_and_dac_r_output_mixer_routing(
        &mut self,
        left_routing: DacLeftOutputMixerRouting,
        ain1_input_routed_left: bool,
        ain2_input_routed_left: bool,
        right_routing: DacRightOutputMixerRouting,
        ain2_input_routed_right: bool,
        hpl_output_routed_to_hpr: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, DAC_L_AND_DAC_R_OUTPUT_MIXER_ROUTING)?;
        set_bits(&mut reg_val, left_routing as u8, 6, 0b1100_0000);
        set_bits(&mut reg_val, ain1_input_routed_left as u8, 5, 0b0010_0000);
        set_bits(&mut reg_val, ain2_input_routed_left as u8, 4, 0b0001_0000);
        set_bits(&mut reg_val, right_routing as u8, 2, 0b0000_1100);
        set_bits(&mut reg_val, ain2_input_routed_right as u8, 1, 0b0000_0010);
        set_bits(&mut reg_val, hpl_output_routed_to_hpr as u8, 0, 0b0000_0001);
        self.write_reg(1, DAC_L_AND_DAC_R_OUTPUT_MIXER_ROUTING, reg_val)
    }

    pub fn set_dac_left_volume_control(&mut self, db: f32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.set_dac_channel_volume_control(true, db)
    }

    pub fn set_dac_processing_block_selection(&mut self, prb: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if prb == 0 || prb > 25 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(0, DAC_PROCESSING_BLOCK_SECTION)?;
        set_bits(&mut reg_val, prb, 0, 0b0001_1111);
        self.write_reg(0, DAC_PROCESSING_BLOCK_SECTION, reg_val)
    }

    pub fn set_dac_right_volume_control(&mut self, db: f32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.set_dac_channel_volume_control(false, db)
    }

    pub fn set_dac_mdac_val(&mut self, powered: bool, divider: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if divider == 0 || divider > 128 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = (powered as u8) << 7;
        reg_val |= divider;
        self.write_reg(0, DAC_MDAC_VAL, reg_val)
    }

    pub fn set_dac_ndac_val(&mut self, powered: bool, divider: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if divider == 0 || divider > 128 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = (powered as u8) << 7;
        reg_val |= divider;
        self.write_reg(0, DAC_NDAC_VAL, reg_val)
    }

    pub fn set_dac_volume_control(
        &mut self,
        left_muted: bool,
        right_muted: bool,
        control: VolumeControl
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, DAC_VOLUME_CONTROL)?;
        set_bits(&mut reg_val, left_muted as u8, 3, 0b1000);
        set_bits(&mut reg_val, right_muted as u8, 2, 0b100);
        set_bits(&mut reg_val, control as u8, 0, 0b11);
        self.write_reg(0, DAC_VOLUME_CONTROL, reg_val)
    }

    fn set_dac_channel_volume_control(&mut self, left_channel: bool, db: f32) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if db < -63.5f32 || db > 24.0f32 {
            return Err(TLV320DAC3100Error::InvalidArgument)
        }

        let reg_val = (db * 2.0) as i8;
        self.write_reg(0, if left_channel { DAC_LEFT_VOLUME_CONTROL } else { DAC_RIGHT_VOLUME_CONTROL }, reg_val as u8)
    }

    pub fn set_data_slot_offset_programmability(&mut self, offset: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.write_reg(0, DATA_SLOT_OFFSET_PROGRAMMABILITY, offset)
    }

    pub fn set_din_control(&mut self, din_control: DinControl) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, DIN_CONTROL)?;
        set_bits(&mut reg_val, din_control as u8, 1, 0b0000_0110);
        self.write_reg(0, DIN_CONTROL, reg_val)
    }

    pub fn set_drc_control_1(
        &mut self,
        left: bool,
        right: bool,
        threshold: u8,
        hysteresis: u8
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if threshold > 7 || hysteresis > 3 { return Err(TLV320DAC3100Error::InvalidArgument) }
        let mut reg_val = self.read_reg(0, DRC_CONTROL_1)?;
        set_bits(&mut reg_val, left as u8, 6, 0b0100_0000);
        set_bits(&mut reg_val, right as u8, 5, 0b0010_0000);
        set_bits(&mut reg_val, threshold, 2, 0b0001_1100);
        set_bits(&mut reg_val, hysteresis, 0, 0b0000_0011);
        self.write_reg(0, DRC_CONTROL_1, reg_val)
    }

    pub fn set_drc_control_2(&mut self, hold_time: HoldTime) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, DRC_CONTROL_2)?;
        set_bits(&mut reg_val, hold_time as u8, 3, 0b0111_1000);
        self.write_reg(0, DRC_CONTROL_2, reg_val)
    }

    pub fn set_drc_control_3(&mut self, attack_rate: u8, decay_rate: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if attack_rate > 15 || decay_rate > 15 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(0, DRC_CONTROL_3)?;
        set_bits(&mut reg_val, attack_rate, 4, 0b1111_0000);
        set_bits(&mut reg_val, decay_rate, 0, 0b0000_1111);
        self.write_reg(0, DRC_CONTROL_3, reg_val)
    }

    pub fn set_gpio1_io_pin_control(&mut self, mode: Gpio1Mode) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, GPIO1_IN_OUT_PIN_CONTROL)?;
        set_bits(&mut reg_val, mode as u8, 2, 0b0011_1100);
        self.write_reg(0, GPIO1_IN_OUT_PIN_CONTROL, reg_val)
    }

    pub fn set_headphone_and_speaker_amplifier_error_control(
        &mut self,
        preserve_spk_ctrl_bits: bool,
        preserve_hp_ctrl_bits: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, HEADPHONE_AND_SPEAKER_AMPLIFIER_ERROR_CONTROL)?;
        set_bits(&mut reg_val, preserve_spk_ctrl_bits as u8, 1, 0b10);
        set_bits(&mut reg_val, preserve_hp_ctrl_bits as u8, 0, 0b1);
        self.write_reg(1, HEADPHONE_AND_SPEAKER_AMPLIFIER_ERROR_CONTROL, reg_val)
    }

    pub fn set_headphone_drivers(
        &mut self,
        left_powered: bool,
        right_powered: bool,
        common: HpOutputVoltage,
        power_down_on_scd: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, HEADPHONE_DRIVERS)?;
        set_bits(&mut reg_val, left_powered as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, right_powered as u8, 6, 0b0100_0000);
        set_bits(&mut reg_val, common as u8, 3, 0b0001_1000);
        set_bits(&mut reg_val, power_down_on_scd as u8, 1, 0b0000_0010);
        self.write_reg(1, HEADPHONE_DRIVERS, reg_val)
    }

    pub fn set_headset_detection(&mut self, enabled: bool, debounce: HeadsetDetectionDebounce, button_debounce: HeadsetButtonPressDebounce) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, HEADSET_DETECTION)?;
        set_bits(&mut reg_val, enabled as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, debounce as u8, 2, 0b0001_1100);
        set_bits(&mut reg_val, button_debounce as u8, 0, 0b0001_0011);
        self.write_reg(0, HEADSET_DETECTION, reg_val)
    }

    pub fn set_hp_driver_control(
        &mut self,
        scd_debounce: HpScdDebounce,
        mode: HpMode,
        hpl_lineout: bool,
        hpr_lineout: bool,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, HP_DRIVER_CONTROL)?;
        set_bits(&mut reg_val, scd_debounce as u8, 5, 0b1110_0000);
        set_bits(&mut reg_val, mode as u8, 3, 0b0001_1000);
        set_bits(&mut reg_val, hpl_lineout as u8, 2, 0b0000_0100);
        set_bits(&mut reg_val, hpr_lineout as u8, 1, 0b0000_0010);
        self.write_reg(1, HP_DRIVER_CONTROL, reg_val)
    }

    pub fn set_hp_output_drivers_pop_removal_settings(
        &mut self,
        optimize_power_down_pop: bool,
        power_on: HpPowerOn,
        ramp_up: HpRampUp,
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, HP_OUTPUT_DRIVERS_POP_REMOVAL_SETTINGS)?;
        set_bits(&mut reg_val, optimize_power_down_pop as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, power_on as u8, 3, 0b0111_1000);
        set_bits(&mut reg_val, ramp_up as u8, 1, 0b0000_0110);
        self.write_reg(1, HP_OUTPUT_DRIVERS_POP_REMOVAL_SETTINGS, reg_val)
    }

    pub fn set_hpl_driver(&mut self, pga: u8, hpl_muted: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if pga > 9 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(1, HPL_DRIVER)?;
        set_bits(&mut reg_val, pga, 3, 0b0111_1000);
        set_bits(&mut reg_val, hpl_muted as u8, 2, 0b0000_0100);
        self.write_reg(1, HPL_DRIVER, reg_val)
    }

    pub fn set_hpr_driver(&mut self, pga: u8, hpr_muted: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if pga > 9 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(1, HPR_DRIVER)?;
        set_bits(&mut reg_val, pga, 3, 0b0111_1000);
        set_bits(&mut reg_val, !hpr_muted as u8, 2, 0b0000_0100);
        self.write_reg(1, HPR_DRIVER, reg_val)
    }

    pub fn set_i2c_bus_condition(&mut self, accept_address: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, I2C_BUS_CONDITION)?;
        set_bits(&mut reg_val, accept_address as u8, 5, 0b0010_0000);
        self.write_reg(0, I2C_BUS_CONDITION, reg_val)
    }

    pub fn set_input_cm_settings(&mut self, ain1_to_cm: bool, ain2_to_cm: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, INPUT_CM_SETTINGS)?;
        set_bits(&mut reg_val, ain1_to_cm as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, ain2_to_cm as u8, 6, 0b0100_0000);
        self.write_reg(1, INPUT_CM_SETTINGS, reg_val)
    }

    pub fn set_int_control_register(
        &mut self,
        int1: bool,
        headset_detect: bool,
        button_press: bool,
        use_drc_signal_power: bool,
        short_circuit: bool,
        data_overflow: bool,
        multiple_pulses: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let reg_addr = if int1 { INT1_CONTROL_REGISTER } else { INT2_CONTROL_REGISTER };
        let mut reg_val = self.read_reg(0, reg_addr)?;
        set_bits(&mut reg_val, headset_detect as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, button_press as u8, 6, 0b0100_0000);
        set_bits(&mut reg_val, use_drc_signal_power as u8, 5, 0b010_0000);
        set_bits(&mut reg_val, short_circuit as u8, 3, 0b0000_1000);
        set_bits(&mut reg_val, data_overflow as u8, 2, 0b0000_0100);
        set_bits(&mut reg_val, multiple_pulses as u8, 0, 0b0000_0001);
        self.write_reg(0, reg_addr, reg_val)
    }

    pub fn set_int1_control_register(
        &mut self,
        headset_detect: bool,
        button_press: bool,
        use_drc_signal_power: bool,
        short_circuit: bool,
        data_overflow: bool,
        multiple_pulses: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.set_int_control_register(true, headset_detect, button_press, use_drc_signal_power, short_circuit, data_overflow, multiple_pulses)
    }

    pub fn set_int2_control_register(
        &mut self,
        headset_detect: bool,
        button_press: bool,
        use_drc_signal_power: bool,
        short_circuit: bool,
        data_overflow: bool,
        multiple_pulses: bool
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.set_int_control_register(false, headset_detect, button_press, use_drc_signal_power, short_circuit, data_overflow, multiple_pulses)
    }

    pub fn set_left_analog_volume_to_hpl(&mut self, route_to_hpl: bool, gain: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if gain > 127 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(1, LEFT_ANALOG_VOLUME_TO_HPL)?;
        set_bits(&mut reg_val, route_to_hpl as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, gain, 0, 0b0111_1111);
        self.write_reg(1, LEFT_ANALOG_VOLUME_TO_HPL, reg_val)
    }

    pub fn set_left_beep_generator(&mut self, enabled: bool, volume: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if volume > 63 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(0, LEFT_BEEP_GENERATOR)?;
        set_bits(&mut reg_val, enabled as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, volume, 0, 0b0011_1111);
        self.write_reg(0, LEFT_BEEP_GENERATOR, reg_val)
    }

    pub fn set_left_analog_volume_to_spk(&mut self, route_to_class_d: bool, gain: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if gain > 127 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(1, LEFT_ANALOG_VOLUME_TO_SPK)?;
        set_bits(&mut reg_val, route_to_class_d as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, gain, 0, 0b0111_1111);
        self.write_reg(1, LEFT_ANALOG_VOLUME_TO_SPK, reg_val)
    }

    pub fn set_micbias(
        &mut self,
        power_down: bool,
        always_on: bool,
        output: MicBiasOutput
    ) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, MICBIAS)?;
        set_bits(&mut reg_val, power_down as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, always_on as u8, 3, 0b0000_1000);
        set_bits(&mut reg_val, output as u8, 0, 0b0000_0011);
        self.write_reg(1, MICBIAS, reg_val)
    }

    pub fn set_output_driver_pga_ramp_down_period_control(&mut self, ramp_down: PgaRampDown) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(1, OUTPUT_DRIVER_PGA_RAMP_DOWN_PERIOD_CONTROL)?;
        set_bits(&mut reg_val, ramp_down as u8, 4, 0b0111_0000);
        self.write_reg(1, OUTPUT_DRIVER_PGA_RAMP_DOWN_PERIOD_CONTROL, reg_val)
    }

    pub fn set_pll_d_value(&mut self, d: u16) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let msb: u8 = ((d >> 8) & 0b0011_1111) as u8;
        self.write_reg(0, PLL_D_VALUE_MSB, msb)?;
        self.write_reg(0, PLL_D_VALUE_LSB, (0xff & d) as u8)
    }

    pub fn set_pll_j_value(&mut self, j: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if j == 0 || j > 63 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(0, PLL_J_VALUE)?;
        set_bits(&mut reg_val, j, 0, 0b0011_1111);
        self.write_reg(0, PLL_J_VALUE, reg_val)
    }

    pub fn set_pll_p_and_r_values(&mut self, powered: bool, p: u8, r: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if p == 0 || p > 8 { return Err(TLV320DAC3100Error::InvalidArgument) }
        if r == 0 || r > 16 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = (powered as u8) << 7;
        reg_val |= (if p == 0 { 0x0 } else { p }) << 4;
        reg_val |= if r == 16 { 0x0 } else { r };
        self.write_reg(0, PLL_P_AND_R_VALUES, reg_val)
    }

    pub fn set_right_analog_volume_to_hpr(&mut self, route_to_hpr: bool, gain: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if gain > 127 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(1, RIGHT_ANALOG_VOLUME_TO_HPR)?;
        set_bits(&mut reg_val, route_to_hpr as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, gain, 0, 0b0111_1111);
        self.write_reg(1, RIGHT_ANALOG_VOLUME_TO_HPR, reg_val)
    }

    pub fn set_right_beep_generator(&mut self, mode: RightBeepMode, volume: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if volume > 63 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(0, RIGHT_BEEP_GENERATOR)?;
        set_bits(&mut reg_val, mode as u8, 6, 0b1100_0000);
        set_bits(&mut reg_val, volume, 0, 0b0011_1111);
        self.write_reg(0, RIGHT_BEEP_GENERATOR, reg_val)
    }

    pub fn set_software_reset(&mut self, reset: bool) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.write_reg(0, SOFTWARE_RESET, reset as u8)
    }

    pub fn set_timer_clock_mclk_divider(&mut self, external_mclk: bool, mclk_divider: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        if mclk_divider == 0 || mclk_divider > 128 { return Err(TLV320DAC3100Error::InvalidArgument) }

        let mut reg_val = self.read_reg(3, TIMER_CLOCK_MCLK_DIVIDER)?;
        set_bits(&mut reg_val, external_mclk as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, mclk_divider, 0, 0b0111_1111);
        self.write_reg(3, TIMER_CLOCK_MCLK_DIVIDER, reg_val)
    }

    pub fn set_vol_micdet_pin_sar_adc(&mut self, pin_control: bool, use_mclk: bool, hysteresis: VolumeControlHysteresis, throughput: VolumeControlThroughput) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        let mut reg_val = self.read_reg(0, VOL_MICDET_PIN_SAR_ADC)?;
        set_bits(&mut reg_val, pin_control as u8, 7, 0b1000_0000);
        set_bits(&mut reg_val, use_mclk as u8, 6, 0b0100_0000);
        set_bits(&mut reg_val, hysteresis as u8, 4, 0b0011_0000);
        set_bits(&mut reg_val, throughput as u8, 0, 0b0000_0111);
        self.write_reg(0, VOL_MICDET_PIN_SAR_ADC, reg_val)
    }

    fn write_reg(&mut self, page: u8, reg_addr: u8, reg_val: u8) -> Result<(), TLV320DAC3100Error<I2C::Error>> {
        self.select_page(page)?;
        Ok(self.i2c.write(I2C_DEVICE_ADDRESS, &[reg_addr, reg_val]).map_err(TLV320DAC3100Error::I2C)?)
    }
}