adc.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file adc.h
3  *
4  * @brief This is the ADC driver header file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2018, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 #pragma once
27 #include "bsp.h"
28 #include "analog.h"
29 #include "register.h"
30 #include "gpio_8258.h"
31 //ADC reference voltage cfg
32 typedef struct {
33  unsigned short adc_vref; //default: 1175 mV
34  unsigned short adc_calib_en;
36 
38 
39 extern GPIO_PinTypeDef ADC_GPIO_tab[10];
40 
44 typedef enum{
50 
54 typedef enum{
60 
64 typedef enum {
66  B0N,
67  B1N,
68  B2N,
69  B3N,
70  B4N,
71  B5N,
72  B6N,
73  B7N,
74  C4N,
75  C5N,
80  GND,
82 
86 typedef enum {
88  B0P,
89  B1P,
90  B2P,
91  B3P,
92  B4P,
93  B5P,
94  B6P,
95  B7P,
96  C4P,
97  C5P,
104 
108 typedef enum{
114 
118 typedef enum{
119  SINGLE_ENDED_MODE = 0, //single-ended mode
120  DIFFERENTIAL_MODE = 1, //differential mode
122 
126 typedef enum{
144 
148 typedef enum{
154 
158 typedef enum{
164 
168 typedef enum{
174 
175 
176 typedef enum{
182 
186 typedef enum{
190 
194 typedef enum {
201 
202 
203 typedef enum {
207 
213 static inline void adc_calib_vref_enable(unsigned char en)
214 {
216 }
217 
218 
224 static inline void adc_reset_adc_module (void)
225 {
227  reg_rst1 = 0;
228 }
229 
235 static inline void adc_enable_clk_24m_to_sar_adc (unsigned int en)
236 {
237  if(en)
238  {
240  }
241  else
242  {
244  }
245 }
246 /**************************************************************************************
247 afe_0xF4
248  BIT<2:0> adc_clk_div
249  ADC clock(derive from external 24M crystal)
250  ADC clk frequency = 24M/(adc_clk_div + 1)
251  BIT<7:3> reserved
252  *************************************************************************************/
253 #define areg_adc_sampling_clk_div 0xf4
254 enum{
256 };
257 
263 static inline void adc_set_sample_clk(unsigned char div)
264 {
265  //afe_0xF4<7:3> is reserved, so no need to care its value (confirmed by junwei & congqing 20190805)
267 }
268 
269 /**************************************************************************************
270 afe_0xE7
271  BIT<1:0> adc_vrefl, Select VREF for left channel
272  BIT<3:2> adc_vrefr, Select VREF for right channel
273  BIT<5:4> adc_vrefm, Select VREF for Misc channel
274  0x0: 0.6V
275  0x1: 0.9V
276  0x2: 1.2V
277  0x3: VBAT/N (N=2/3/4, when afe_0xF9<3:2> is set as 0x3/0x2/0x1).
278 
279  notice that: when choose ADC_VREF_VBAT_N, must use adc_set_vref_vbat_divider to config N(1/2/3/4)
280 
281 afe_0xF9
282  BIT<3:2> adc_vbat_div
283  Vbat divider select (see adc_vref)
284  0x0: OFF
285  0x1: VBAT/4
286  0x2: VBAT/3
287  0x3: VBAT/2
288  *************************************************************************************/
289 #define areg_adc_vref 0xe7
290 enum{
294 };
295 
303 static inline void adc_set_vref(ADC_RefVolTypeDef vRef_L, ADC_RefVolTypeDef vRef_R, ADC_RefVolTypeDef vRef_M)
304 {
305  analog_write(areg_adc_vref, vRef_L | vRef_R<<2 | vRef_M<<4);
306 }
307 
313 static inline void adc_set_vref_chn_left(ADC_RefVolTypeDef v_ref)
314 {
316 }
317 
323 static inline void adc_set_vref_chn_right(ADC_RefVolTypeDef v_ref)
324 
325 {
327 }
328 
334 static inline void adc_set_vref_chn_misc(ADC_RefVolTypeDef v_ref)
335 
336 {
338 }
339 
347 
348 
349 
350 #define areg_adc_vref_vbat_div 0xf9
351 enum{
353 };
359 static inline void adc_set_vref_vbat_divider(ADC_VbatDivTypeDef vbat_div)
360 {
362 }
363 
364 
365 
366 /**************************************************************************************
367 afe_0xE8
368  BIT<3:0> Select negative input for Misc channel
369  BIT<7:4> Select positive input for Misc channel
370 
371 afe_0xE9
372  BIT<3:0> Select negative input for left channel
373  BIT<7:4> Select positive input for left channel
374 
375 afe_0xEA
376  BIT<3:0> Select negative input for right channel
377  BIT<7:4> Select positive input for right channel
378 
379  negative input:
380  0x0: No input
381  0x1: B<0>
382  0x2: B<1>
383  ...
384  0x8: B<7>
385  0x9: C<4>
386  0xa: C<5>
387  0xb: pga_n<0> (PGA left-channel negative output)
388  0xc: pga_n<1> (PGA right-channel negative output)
389  0xd: tempsensor_n (Temperature sensor negative output)
390  0xe: rsvd //spec "GND" is wrong
391  0xf: Ground
392 
393  positive input:
394  0x0: No input
395  0x1: B<0>
396  0x2: B<1>
397  ...
398  0x8: B<7>
399  0x9: C<4>
400  0xa: C<5>
401  0xb: pga_p<0> (PGA left-channel positive output)
402  0xc: pga_p<1> (PGA right-channel positive output)
403  0xd: tempsensor_p (Temperature sensor positive output)
404  0xe: rsvd
405  0xf: Vbat (Battery voltage)
406  *************************************************************************************/
407 #define areg_adc_ain_chn_misc 0xe8
408 #define areg_adc_ain_chn_left 0xe9
409 #define areg_adc_ain_chn_right 0xea
410 enum{
413 };
414 
422 
423 {
424  analog_write (areg_adc_ain_chn_misc , n_ain | p_ain<<4 );
425 }
426 
434 
435 {
436  analog_write (areg_adc_ain_chn_left, n_ain | p_ain<<4 );
437 }
438 
446 
447 {
448  analog_write (areg_adc_ain_chn_right, n_ain | p_ain<<4 );
449 }
450 
457 
458 {
460 }
467 
468 {
470 }
471 
478 
479 {
481 }
482 
490 
491 {
493 }
494 
502 
503 {
505 }
506 
513 
514 {
516 }
517 
518 /**************************************************************************************
519 afe_0xEB
520  BIT<1:0> adc_resl, Set resolution for left channel
521  BIT<5:4> adc_resr, Set resolution for right channel
522 
523 afe_0xEC
524  BIT<1:0> adc_resm, Set resolution for Misc channel
525 
526  If RNS mode is set, resolution is set to 1. Otherwise ADC mode setting is:
527  0x0: 8bits
528  0x1: 10bits
529  0x2: 12bits
530  0x3: 14bits
531 
532  BIT<3:2> Reserved
533  BIT<4> adc_en_diffl, Select single-end or differential input mode for left channel.
534  BIT<5> adc_en_diffr, Select single-end or differential input mode for right channel.
535  BIT<6> adc_en_diffm, Select single-end or differential input mode for Misc channel.
536  BIT<7> Reserved
537  *************************************************************************************/
538 #define areg_adc_res_l_r 0xeb
539 enum{
542 };
543 
550 {
552 }
553 
560 
561 {
563 }
564 
565 
566 
574 
575 
576 
577 #define anareg_adc_res_m 0xec
578 enum{
583 };
590 {
592 }
593 
600 {
601  if(m_input){ //differential mode
603  }
604  else{ //single-ended mode
606  }
607 }
608 
615 
616 {
617  if(m_input){ //differential mode
619  }
620  else{ //single-ended mode
622  }
623 }
624 
631 {
632  if(m_input){ //differential mode
634  }
635  else{ //single-ended mode
637  }
638 }
639 
647 
648 
649 #define areg_adc_tsmaple_m 0xee
650 enum{
652 };
653 
660 {
661  //ana_ee<7:4> is reserved, so no need care its value (confirmed by junwei & congqing 20190805)
662  //analog_write(areg_adc_tsmaple_m, (analog_read(areg_adc_tsmaple_m)&(~FLD_ADC_TSAMPLE_CYCLE_CHN_M)) | (adcST) );
663  analog_write(areg_adc_tsmaple_m, adcST ); //optimize, <7:4> not cared
664 }
665 
666 /**************************************************************************************
667 afe_0xED
668  BIT<3:0> adc_tsampl, Number of ADC clock cycles in sampling phase for left channel to stabilize the input before sampling
669  BIT<7:4> adc_tsampr, Number of ADC clock cycles in sampling phase for right channel to stabilize the input before sampling
670 
671 afe_0xEE
672  BIT<3:0> adc_tsampm, Number of ADC clock cycles in sampling phase for Misc channel to stabilize the input before sampling
673 
674  0x0: 3 cycles (RNS mode default)
675  0x1: 6 cycles
676  0x2: 9 cycles
677  0x3: 12 cycles
678  ......
679  0xf: 48 cycles
680  *************************************************************************************/
681 #define areg_adc_tsmaple_l_r 0xed
682 enum{
685 };
686 
693 
694 {
696 }
697 
704 {
706 }
707 
715 
716 /**************************************************************************************
717 afe_0xEF<7:0> r_max_mc[7:0]
718 afe_0xF0<7:0> r_max_c[7:0]
719 afe_0xF1
720  <3:0> r_max_s
721  <5:4> r_max_c[9:8]
722  <7:6> r_max_mc[9:8]
723 
724  r_max_mc[9:0]: serves to set length of ¡°capture¡± state for RNS and Misc channel.
725  r_max_c[9:0]: serves to set length of ¡°capture¡± state for left and right channel.
726  r_max_s: serves to set length of ¡°set¡± state for left, right and Misc channel.
727 
728  Note: State length indicates number of 24M clock cycles occupied by the state.
729  *************************************************************************************/
730 #define areg_r_max_mc 0xef
731 enum{
732  FLD_R_MAX_MC0 = BIT_RNG(0,7),//0xef<7:0> r_max_mc[7:0]
733 };
734 #define areg_r_max_c 0xf0
735 enum{
736  FLD_R_MAX_C0 = BIT_RNG(0,7),//0xf0<7:0> r_max_c[7:0]
737 };
738 
739 #define areg_r_max_s 0xf1
740 enum{
741  FLD_R_MAX_S = BIT_RNG(0,3),//0xf1<3:0> r_max_s
742  FLD_R_MAX_C1 = BIT_RNG(4,5),//0xf1<5:4> r_max_c[9:8]
743  FLD_R_MAX_MC1 = BIT_RNG(6,7),//0xf1<7:6> r_max_mc[9:8]
744 };
745 
751 static inline void adc_set_length_set_state (unsigned char r_max_s)
752 {
754 }
755 
763 static inline void adc_set_length_capture_state_for_chn_misc_rns (unsigned short r_max_mc)
764 {
765  analog_write(areg_r_max_mc, (r_max_mc & 0x0ff));
766  analog_write(areg_r_max_s, ((analog_read(areg_r_max_s)&(~FLD_R_MAX_MC1)) | ((r_max_mc&0x3ff)>>8)<<6 ));
767 }
768 
776 static inline void adc_set_length_capture_state_for_chn_left_right(unsigned short r_max_c)
777 {
778  analog_write(areg_r_max_c , r_max_c & 0xff);
779  analog_write(areg_r_max_s, (analog_read(areg_r_max_s)&(~FLD_R_MAX_C1)) | (((r_max_c&0x3ff)>>8)<<4));
780 }
781 
789 static inline void adc_set_state_length(unsigned short R_max_mc, unsigned short R_max_c,unsigned char R_max_s)
790 {
791  analog_write(areg_r_max_mc, R_max_mc);
792  analog_write(areg_r_max_c, R_max_c);
793  analog_write(areg_r_max_s, ((R_max_mc>>8)<<6) | ((R_max_c>>8)<<4) | (R_max_s & FLD_R_MAX_S) );
794 }
795 
796 /***************************************************************************************
797 afe_0xF2
798  BIT<0> r_en_left Enable left channel. 1: enable; 0: disable
799  BIT<1> r_en_right Enable right channel. 1: enable; 0: disable
800  BIT<2> r_en_Misc Enable Misc channel. 1: enable; 0: disable
801  BIT<3> r_en_rns Enable RNS sampling. 1: enable; 0: disable
802  BIT<6:4> r_max_scnt Set total length for sampling state machine (i.e. max state index)
803  *************************************************************************************/
804 #define areg_adc_chn_en 0xf2
805 enum{
811 };
817 static inline void adc_set_chn_enable(ADC_ChTypeDef ad_ch)
818 {
820 }
821 
828 static inline void adc_set_chn_enable_and_max_state_cnt(ADC_ChTypeDef ad_ch, unsigned char s_cnt)
829 {
830  analog_write(areg_adc_chn_en, ad_ch | ((s_cnt&0x07)<<4) );
831 }
832 
838 static inline void adc_set_max_state_cnt(unsigned char s_cnt)
839 {
841 }
842 
843 /**************************************************************************************
844 afe_0xFA
845  BIT<1:0> adc_itrim_preamp, Comparator preamp bias current trimming
846  BIT<3:2> adc_itrim_vrefbuf, Vref buffer bias current trimming
847  BIT<5:4> adc_itrim_vcmbuf, Vref buffer bias current trimming
848 
849  BIT<7:6> Analog input pre-scaling select
850  sel_ai_scale[1:0]: scaling factor
851  0x0: 1
852  0x1: 1/2
853  0x2: 1/4
854  0x3: 1/8
855 
856  *************************************************************************************/
857 #define areg_ain_scale 0xfa
858 enum{
863 };
864 
871 {
873 }
874 
881 {
883 }
884 
891 {
893 }
894 
895 /**************************************************************************************
896 afe_0xFB
897  BIT<5:4> pga_itrim_boost_l
898  BIT<7:6> pga_itrim_boost_r
899  0x0 : 75%
900  0x1 : 100%
901  0x2 : 125%
902  0x3 : 150%
903 
904 afe_0xFC
905  BIT<1:0> pga_itrim_gain_l
906  BIT<3:2> pga_itrim_gain_r
907  0x0 : 75%
908  0x1 : 100%
909  0x2 : 125%
910  0x3 : 150%
911 
912  BIT<4> adc_mode
913  0: normal mode
914  1: rsvd (RNS mode)
915  BIT<5> adc_pd, Power down ADC
916  1: Power down
917  0: Power up
918  BIT<6> pga_pd_l, power down left channel pga
919  1: Power down
920  0: Power up
921  BIT<7> pga_pd_r, power down right channel pga
922  1: Power down
923  0: Power up
924  *************************************************************************************/
925 #define areg_adc_pga_boost 0xfb
926 enum{
931 };
932 
939 {
941 }
942 
949 {
951 }
952 
953 #define areg_adc_pga_ctrl 0xfc
954 enum{
961 };
962 
970 {
971  analog_write(areg_adc_pga_ctrl, (analog_read(areg_adc_pga_ctrl) & 0xf0) | (bias_L | bias_R<<2) );
972 }
973 
980 {
982 }
983 
990 {
992 }
993 
999 static inline void adc_set_mode(ADC_ModeTypeDef adc_m)
1000 {
1002 }
1003 
1010 static inline void adc_power_on_sar_adc (unsigned char on_off)
1011 {
1013 }
1014 
1020 static inline void pga_left_chn_power_on(unsigned char on_off)
1021 {
1023 }
1024 
1030 static inline void pga_right_chn_power_on(unsigned char on_off)
1031 {
1033 }
1034 
1035 #define areg_fe 0xfe//0xfe default value is 0xe5,for output audio, mast claer 0xfe<7:5>
1036 
1043 static inline void RNG_Set(RNG_SrcTypeDef src,RNG_UpdataTypeDef update_type)
1044 {
1045  WriteAnalogReg(0xfe, src|update_type);//Set
1046 }
1047 
1048 /**************************************************************************************
1049 afe_0xF5<7:0> rng[7:0] Read only, random number [7:0]
1050 afe_0xF6<7:0> rng[15:8] Read only, random number [15:8]
1051 afe_0xF7<7:0> adc_dat[7:0] Read only, Misc adc dat[7:0]
1052 afe_0xF8<7:0> adc_dat[15:8] Read only
1053  [7]: vld, ADC data valid status bit (This bit will be set as 1 at the end of capture state to indicate the ADC data is valid, and will be cleared when set state starts.)
1054  [6:0]: Misc adc_dat[14:8]
1055 
1056  *************************************************************************************/
1057 #define areg_adc_rng_l 0xf5
1058 #define areg_adc_rng_h 0xf6
1059 #define areg_adc_misc_l 0xf7
1060 #define areg_adc_misc_h 0xf8
1061 enum{
1064 };
1065 
1071 static inline unsigned short RNG_Read(void)
1072 {
1073  #if 1
1075  #else
1076  unsigned short tmp1,tmp2,RngValue;
1077  tmp2 = ReadAnalogReg(0xf5);
1078  tmp1 = ReadAnalogReg(0xf6); //read
1079  RngValue = (tmp1<<8) + tmp2;
1080  return RngValue;
1081  #endif
1082 }
1083 
1091 
1100 
1107 
1108 
1114 void adc_init(void );
1115 
1122 
1129 
1135 void adc_base_init(GPIO_PinTypeDef pin);
1136 
1137 
1138 
1144 void adc_vbat_init(GPIO_PinTypeDef pin);
1145 
1146 
1152 unsigned int adc_sample_and_get_result(void);
1153 
1154  //end of GP1
1216 
1217 
unsigned char analog_read(unsigned char addr)
This function serves to analog register read.
#define areg_adc_res_l_r
Definition: adc.h:538
static void adc_set_vref_vbat_divider(ADC_VbatDivTypeDef vbat_div)
This function select Vbat voltage divider.
Definition: adc.h:359
Definition: adc.h:172
static unsigned short RNG_Read(void)
This function serves to read random number.
Definition: adc.h:1071
static void adc_set_left_gain_bias(ADC_Gain_BiasTypeDef bias)
This function gets left gain bias with PGA enable.
Definition: adc.h:979
void adc_base_init(GPIO_PinTypeDef pin)
This function is used for ADC configuration of ADC IO voltage sampling.
void adc_vbat_pin_init(GPIO_PinTypeDef pin)
This function is used for IO port configuration of ADC supply voltage sampling.
Definition: adc.h:929
Definition: adc.h:128
Definition: adc.h:743
Definition: adc.h:100
Definition: adc.h:162
ADC_RefVolTypeDef
Definition: adc.h:44
static void adc_set_input_mode_chn_left(ADC_InputModeTypeDef m_input)
This function sets ADC input mode for the L channel.
Definition: adc.h:599
#define areg_r_max_c
Definition: adc.h:734
Definition: adc.h:74
Definition: adc.h:66
static void adc_set_max_state_cnt(unsigned char s_cnt)
This function sets total state index for sampling state.
Definition: adc.h:838
unsigned short adc_vref
Definition: adc.h:33
void adc_set_ref_voltage(ADC_ChTypeDef ch_n, ADC_RefVolTypeDef v_ref)
This function serves to set the channel reference voltage.
static void adc_set_input_mode_chn_right(ADC_InputModeTypeDef m_input)
This function sets ADC input mode for the R channel.
Definition: adc.h:614
static void adc_set_mode(ADC_ModeTypeDef adc_m)
This function serves to set mode for ADC.
Definition: adc.h:999
Definition: adc.h:291
Definition: adc.h:73
Definition: adc.h:134
Definition: adc.h:152
Definition: adc.h:109
Definition: adc.h:159
Definition: adc.h:540
static void adc_set_tsample_cycle_chn_right(ADC_SampCycTypeDef adcST)
This function sets ADC sample time(the number of adc clocks for sample cycles) for the R channel...
Definition: adc.h:703
unsigned int adc_sample_and_get_result(void)
This function serves to set adc sampling and get results.
static void adc_set_ain_negative_chn_right(ADC_InputNchTypeDef v_ain)
This function sets ADC analog negative input channel for the R channel.
Definition: adc.h:501
void adc_set_ain_pre_scaler(ADC_PreScalingTypeDef v_scl)
This function serves to set pre_scaling.
Definition: adc.h:412
Definition: adc.h:133
Definition: adc.h:96
static void adc_set_input_mode_chn_misc(ADC_InputModeTypeDef m_input)
This function sets ADC input mode for the MISC channel.
Definition: adc.h:630
#define areg_adc_rng_h
Definition: adc.h:1058
static void adc_set_right_gain_bias(ADC_Gain_BiasTypeDef bias)
This function gets right_gain_bias with PGA enable.
Definition: adc.h:989
Definition: adc.h:139
Definition: adc.h:741
static void adc_set_itrim_preamp(ADC_Cur_TrimTypeDef bias)
This function sets pre-scaling for comparator preamp bias current trimming.
Definition: adc.h:870
static void pga_left_chn_power_on(unsigned char on_off)
This function sets PGA-Left-channel power.
Definition: adc.h:1020
Definition: adc.h:178
static void adc_set_itrim_vrefbuf(ADC_Cur_TrimTypeDef bias)
This function sets pre-scaling for Vref buffer bias current trimming.
Definition: adc.h:880
Definition: adc.h:141
Definition: adc.h:580
Definition: adc.h:808
Definition: adc.h:180
#define areg_r_max_s
Definition: adc.h:739
Definition: adc.h:45
static void adc_set_chn_enable_and_max_state_cnt(ADC_ChTypeDef ad_ch, unsigned char s_cnt)
This function sets total state index for the channel.
Definition: adc.h:828
#define areg_adc_ain_chn_right
Definition: adc.h:409
Definition: adc.h:131
Definition: adc.h:161
static void adc_set_vref_chn_left(ADC_RefVolTypeDef v_ref)
This function sets ADC reference voltage for the L channel.
Definition: adc.h:313
Definition: adc.h:136
Definition: adc.h:80
static void adc_set_ain_chn_right(ADC_InputPchTypeDef p_ain, ADC_InputNchTypeDef n_ain)
This function serves to set input channel for the right channel.
Definition: adc.h:445
Definition: adc.h:32
Definition: adc.h:1062
static void adc_set_ain_negative_chn_left(ADC_InputNchTypeDef v_ain)
This function sets ADC analog negative input channel for the L channel.
Definition: adc.h:477
Definition: adc.h:65
#define areg_adc_ain_chn_misc
Definition: adc.h:407
static void adc_set_ain_positive_chn_misc(ADC_InputPchTypeDef v_ain)
This function sets ADC analog positive input channel for the MISC channel.
Definition: adc.h:466
Definition: adc.h:806
Definition: adc.h:130
Definition: adc.h:88
static void adc_set_left_boost_bias(ADC_Gain_BiasTypeDef bias)
This function sets left boost bias with PGA enable.
Definition: adc.h:938
#define areg_adc_tsmaple_m
Definition: adc.h:649
static void adc_set_ain_chn_left(ADC_InputPchTypeDef p_ain, ADC_InputNchTypeDef n_ain)
This function serves to set input channel for the left channel.
Definition: adc.h:433
#define WriteAnalogReg
Definition: analog.h:66
Definition: adc.h:67
ADC_PreScalingTypeDef
Definition: adc.h:158
Definition: adc.h:928
#define areg_ain_scale
Definition: adc.h:857
void adc_vbat_init(GPIO_PinTypeDef pin)
This function is used for ADC configuration of ADC supply voltage sampling.
static void adc_set_vref(ADC_RefVolTypeDef vRef_L, ADC_RefVolTypeDef vRef_R, ADC_RefVolTypeDef vRef_M)
This function sets ADC reference voltage for L,R and Mic channel.
Definition: adc.h:303
Definition: adc.h:177
Definition: adc.h:732
Definition: adc.h:198
Definition: adc.h:78
ADC_InputModeTypeDef
Definition: adc.h:118
Definition: adc.h:79
Definition: adc.h:957
ADC_ResTypeDef
Definition: adc.h:108
static void adc_set_right_boost_bias(ADC_Gain_BiasTypeDef bias)
This function sets right boost bias with PGA enable.
Definition: adc.h:948
Definition: adc.h:169
#define areg_adc_vref
Definition: adc.h:289
ADC_ModeTypeDef
Definition: adc.h:186
Definition: adc.h:102
#define areg_adc_rng_l
Definition: adc.h:1057
ADC_InputNchTypeDef
Definition: adc.h:64
Definition: adc.h:199
void adc_set_ain_channel_single_ended_input_mode(ADC_ChTypeDef ch_n, ADC_InputPchTypeDef InPCH)
This function serves to set input channel in single_ended_input_mode.
Definition: adc.h:47
static void adc_set_length_capture_state_for_chn_misc_rns(unsigned short r_max_mc)
This function sets length of each "capture" state for MISC channel.
Definition: adc.h:763
#define BIT(n)
Definition: bsp.h:33
static void adc_set_vref_chn_right(ADC_RefVolTypeDef v_ref)
This function sets ADC reference voltage for the R channel.
Definition: adc.h:323
static void adc_enable_clk_24m_to_sar_adc(unsigned int en)
This function enable adc source clock: external 24M.
Definition: adc.h:235
Definition: adc.h:77
Definition: adc.h:137
static void adc_set_left_right_gain_bias(ADC_Gain_BiasTypeDef bias_L, ADC_Gain_BiasTypeDef bias_R)
This function gets left gain bias with PGA enable.
Definition: adc.h:969
static void adc_set_ain_positive_chn_right(ADC_InputPchTypeDef v_ain)
This function sets ADC analog positive input channel for the R channel.
Definition: adc.h:512
Definition: adc.h:582
Definition: adc.h:75
static void adc_set_resolution_chn_left(ADC_ResTypeDef v_res)
This function sets ADC resolution for the L channel.
Definition: adc.h:549
Definition: adc.h:292
Definition: adc.h:683
static void adc_set_resolution_chn_right(ADC_ResTypeDef v_res)
This function sets ADC resolution for the R channel.
Definition: adc.h:559
Definition: adc.h:138
static void adc_set_length_capture_state_for_chn_left_right(unsigned short r_max_c)
This function sets length of each "capture" state for R and L channel.
Definition: adc.h:776
Definition: adc.h:132
unsigned short adc_calib_en
Definition: adc.h:34
Definition: adc.h:150
Definition: adc.h:651
Definition: adc.h:70
GPIO_PinTypeDef ADC_GPIO_tab[10]
Definition: adc.h:72
Definition: adc.h:179
Definition: adc.h:91
Definition: adc.h:160
static void adc_set_chn_enable(ADC_ChTypeDef ad_ch)
This function sets ADC input channel.
Definition: adc.h:817
Definition: adc.h:94
ADC_Cur_TrimTypeDef
Definition: adc.h:168
#define areg_adc_tsmaple_l_r
Definition: adc.h:681
Definition: adc.h:101
Definition: adc.h:56
Definition: adc.h:119
static void adc_reset_adc_module(void)
This function reset adc module.
Definition: adc.h:224
Definition: adc.h:959
static void adc_set_tsample_cycle_chn_left(ADC_SampCycTypeDef adcST)
This function sets ADC sample time(the number of adc clocks for sample cycles) for the L channel...
Definition: adc.h:692
Definition: adc.h:151
Definition: adc.h:196
Definition: adc.h:581
static void adc_set_sample_clk(unsigned char div)
This function sets adc sample clk. adc sample clk = 24M/(1+div) div: 0~7.
Definition: adc.h:263
Definition: adc.h:99
Definition: adc.h:142
Definition: adc.h:57
Definition: adc.h:860
void adc_init(void)
This function serves to ADC init.
void adc_set_tsample_cycle(ADC_ChTypeDef ch_n, ADC_SampCycTypeDef adcST)
This function serves to set sample_cycle.
Definition: adc.h:93
Definition: adc.h:742
Definition: adc.h:197
Definition: adc.h:809
RNG_SrcTypeDef
Definition: adc.h:194
static void adc_set_itrim_vcmbuf(ADC_Cur_TrimTypeDef bias)
This function sets pre-scaling for Vref(Vcmbuf) buffer bias current trimming.
Definition: adc.h:890
GPIO_PinTypeDef
Define GPIO types.
Definition: gpio_8258.h:38
static void pga_right_chn_power_on(unsigned char on_off)
This function sets PGA Right channel power.
Definition: adc.h:1030
Definition: adc.h:90
static void adc_power_on_sar_adc(unsigned char on_off)
This function sets sar_adc power.
Definition: adc.h:1010
Definition: adc.h:293
Definition: adc.h:140
Definition: adc.h:862
Definition: adc.h:120
static void adc_set_ain_chn_misc(ADC_InputPchTypeDef p_ain, ADC_InputNchTypeDef n_ain)
This function serves to set input channel for the MISC channel.
Definition: adc.h:421
Definition: adc.h:111
Definition: adc.h:195
#define areg_adc_sampling_clk_div
Definition: adc.h:253
#define areg_adc_chn_en
Definition: adc.h:804
ADC_SampCycTypeDef
Definition: adc.h:126
Definition: adc.h:187
Definition: adc.h:48
static void adc_calib_vref_enable(unsigned char en)
This function enable adc reference voltage calibration.
Definition: adc.h:213
Definition: adc.h:135
static void adc_set_vref_chn_misc(ADC_RefVolTypeDef v_ref)
This function sets ADC reference voltage for the MISC channel.
Definition: adc.h:334
Definition: adc.h:352
void adc_set_resolution(ADC_ChTypeDef ch_n, ADC_ResTypeDef v_res)
This function serves to set resolution.
void adc_base_pin_init(GPIO_PinTypeDef pin)
This function is used for IO port configuration of ADC IO port voltage sampling.
Definition: adc.h:736
Definition: adc.h:76
Definition: adc.h:110
void analog_write(unsigned char addr, unsigned char v)
This function serves to analog register write.
Definition: adc.h:930
static void adc_set_ain_positive_chn_left(ADC_InputPchTypeDef v_ain)
This function sets ADC analog positive input channel for the L channel.
Definition: adc.h:489
Definition: register_8258.h:161
static void RNG_Set(RNG_SrcTypeDef src, RNG_UpdataTypeDef update_type)
This function sets ADC RNS channel source and random updata type.
Definition: adc.h:1043
static void adc_set_ain_negative_chn_misc(ADC_InputNchTypeDef v_ain)
This function sets ADC analog negative input channel for the MISC channel.
Definition: adc.h:456
Definition: adc.h:255
Definition: adc.h:541
RNG_UpdataTypeDef
Definition: adc.h:203
Definition: adc.h:89
#define areg_adc_pga_ctrl
Definition: adc.h:953
Definition: adc.h:58
#define reg_rst1
Definition: register_8258.h:154
Definition: adc.h:127
Definition: adc.h:861
void adc_set_input_mode(ADC_ChTypeDef ch_n, ADC_InputModeTypeDef m_input)
This function serves to set input_mode.
Definition: adc.h:960
static void adc_set_length_set_state(unsigned char r_max_s)
This function sets length of each ¡°set¡± state.
Definition: adc.h:751
#define areg_r_max_mc
Definition: adc.h:730
ADC_Gain_BiasTypeDef
Definition: adc.h:176
Definition: adc.h:956
Definition: adc.h:955
Definition: adc.h:92
Definition: adc.h:170
Definition: adc.h:1063
Definition: adc.h:204
Definition: adc.h:71
Definition: adc.h:149
Definition: adc.h:171
#define BIT_RNG(s, e)
Definition: bsp.h:35
Definition: adc.h:205
Definition: adc.h:411
Definition: adc.h:97
#define areg_adc_vref_vbat_div
Definition: adc.h:350
Definition: adc.h:68
Definition: adc.h:927
#define ReadAnalogReg
Definition: analog.h:67
Definition: adc.h:807
#define areg_clk_setting
Definition: register_8258.h:1296
Definition: adc.h:98
Definition: adc.h:95
static void adc_set_tsample_cycle_chn_misc(ADC_SampCycTypeDef adcST)
This function sets ADC sample time(the number of adc clocks for sample cycles) for the MISC channel...
Definition: adc.h:659
Definition: adc.h:112
Definition: adc.h:129
Definition: adc.h:684
Definition: adc.h:810
Definition: adc.h:69
ADC_InputPchTypeDef
Definition: adc.h:86
ADC_VbatDivTypeDef
Definition: adc.h:54
Definition: adc.h:958
void adc_set_ain_channel_differential_mode(ADC_ChTypeDef ch_n, ADC_InputPchTypeDef InPCH, ADC_InputNchTypeDef InNCH)
This function serves to set input channel in differential_mode.
adc_vref_ctr_t adc_vref_cfg
Definition: register_8258.h:1301
Definition: adc.h:55
Definition: adc.h:859
Definition: adc.h:46
Definition: adc.h:87
#define areg_adc_pga_boost
Definition: adc.h:925
ADC_ChTypeDef
Definition: adc.h:148
static void adc_set_resolution_chn_misc(ADC_ResTypeDef v_res)
This function sets ADC resolution for the MISC channel.
Definition: adc.h:589
static void adc_set_state_length(unsigned short R_max_mc, unsigned short R_max_c, unsigned char R_max_s)
This function serves to set state and capture_state length.
Definition: adc.h:789
Definition: adc.h:188
#define areg_adc_ain_chn_left
Definition: adc.h:408
Definition: adc.h:579
#define anareg_adc_res_m
Definition: adc.h:577