InPlay API
ADC driver

HAL_ADC. More...

Enumerations

enum  adc_ch {
  ADC_CH0 = 0, ADC_CH1, ADC_CH2, ADC_CH3,
  ADC_CH4, ADC_CH5, ADC_CH6, ADC_CH7,
  ADC_CH8, ADC_CH9, ADC_CH10 = 10, ADC_CH11,
  ADC_CH12, ADC_CH13, ADC_CH14 = 14, ADC_CH15 = 15
}
 
enum  adc_vref { ADC_VREF_1P0 = 0, ADC_VREF_1P5 = 1 }
 

Functions

int hal_adc_open (adc_init_t *init)
 Open ADC device. More...
 
void hal_adc_close (void)
 Close ADC device. More...
 
int hal_adc_force_mode_enable_ch (int ch)
 Enable channel in force mode. More...
 
int hal_adc_force_mode_disable_ch (int ch)
 Disable channel in force mode. More...
 
int hal_adc_force_mode_start (int ch, uint16_t *buff, uint16_t sample_num)
 Start force mode. More...
 
int hal_adc_auto_mode_enable_ch (int ch, uint16_t *buf, uint16_t buf_sz)
 Enable channel in auto mode. More...
 
int hal_adc_auto_mode_disable_ch (int ch)
 Disable channel in auto mode. More...
 
int hal_adc_auto_mode_config (uint8_t grp_intv)
 Config auto mode. More...
 
int hal_adc_auto_mode_start (uint16_t sample_num)
 Start auto mode. More...
 
int hal_adc_set_vref (int vref)
 Set ADC reference. Default is internal 1.0v. More...
 
int hal_adc_measure_analog_ch (int ch, float vref, float *vc)
 read analog channel voltage. More...
 
float hal_adc_sample_convert (uint16_t adc_val)
 convert adc sample value to voltage, unit is mV, vref must be 1.0v More...
 
float hal_adc_vbat_sample_convert (uint16_t adc_val)
 convert vbat(channel 14) sample value to voltage, unit is mV More...
 
float hal_adc_temp_sample_convert (uint16_t adc_val)
 convert temperature sample(channel 15) value to temperature, unit is centigrade More...
 
int hal_adc_auto_mode_cap_clk (int ch, uint32_t cap_clk)
 Set capture clock for auto mode. More...
 
int hal_adc_force_mode_cap_clk (uint32_t cap_clk)
 Set capture clock for force mode. More...
 
int hal_adc_measure_temp (uint16_t sample_num, float *temp)
 Read temperature, this function is more accurate than hal_adc_force_mode_start or hal_adc_auto_mode_start. More...
 

Detailed Description

HAL_ADC.

Enumeration Type Documentation

◆ adc_ch

enum adc_ch
Enumerator
ADC_CH0 

ADC_CH_IN.

ADC_CH1 

GPIO_2_9.

ADC_CH2 

GPIO_2_8.

ADC_CH3 

GPIO_2_7.

ADC_CH4 

GPIO_2_6.

ADC_CH5 

GPIO_2_5.

ADC_CH6 

GPIO_2_4.

ADC_CH7 

GPIO_2_3.

ADC_CH8 

GPIO_2_2.

ADC_CH9 

GPIO_2_1.

ADC_CH10 

GPIO_2_0.

ADC_CH11 

GPIO_3_1.

ADC_CH12 

GPIO_3_0.

ADC_CH13 

PMU internal testpoint.

ADC_CH14 

VBAT.

ADC_CH15 

temperature sensor

◆ adc_vref

enum adc_vref
Enumerator
ADC_VREF_1P0 

internal 1.0v

ADC_VREF_1P5 

internal 1.5v

Function Documentation

◆ hal_adc_auto_mode_cap_clk()

int hal_adc_auto_mode_cap_clk ( int  ch,
uint32_t  cap_clk 
)

Set capture clock for auto mode.


Parameters
chchannel
cap_clkcapture clock. Default is about 470KHz.
Returns
See also
enum adc_error for return code.

◆ hal_adc_auto_mode_config()

int hal_adc_auto_mode_config ( uint8_t  grp_intv)

Config auto mode.


Parameters
[in]grp_intvGroup interval.
Returns
See also
enum adc_error for return code.

◆ hal_adc_auto_mode_disable_ch()

int hal_adc_auto_mode_disable_ch ( int  ch)

Disable channel in auto mode.


Parameters
[in]chChannel.
See also
enum adc_ch
Returns
See also
enum adc_error for return code.

◆ hal_adc_auto_mode_enable_ch()

int hal_adc_auto_mode_enable_ch ( int  ch,
uint16_t *  buf,
uint16_t  buf_sz 
)

Enable channel in auto mode.


Parameters
[in]chChannel.
See also
enum adc_ch
Parameters
[in]bufBuffer for this channel.
[in]buf_szBuffer size for this channel
Returns
See also
enum adc_error for return code.

◆ hal_adc_auto_mode_start()

int hal_adc_auto_mode_start ( uint16_t  sample_num)

Start auto mode.


Parameters
[in]sample_numSample number.
Returns
See also
enum adc_error for return code.

◆ hal_adc_close()

void hal_adc_close ( void  )

Close ADC device.


Returns
none

◆ hal_adc_force_mode_cap_clk()

int hal_adc_force_mode_cap_clk ( uint32_t  cap_clk)

Set capture clock for force mode.


Parameters
cap_clkcapture clock. Default is about 470KHz.
Returns
See also
enum adc_error for return code.

◆ hal_adc_force_mode_disable_ch()

int hal_adc_force_mode_disable_ch ( int  ch)

Disable channel in force mode.


Parameters
[in]chChannel.
See also
enum adc_ch
Returns
See also
enum adc_error for return code.

◆ hal_adc_force_mode_enable_ch()

int hal_adc_force_mode_enable_ch ( int  ch)

Enable channel in force mode.


Parameters
[in]chChannel.
See also
enum adc_ch
Returns
See also
enum adc_error for return code.

◆ hal_adc_force_mode_start()

int hal_adc_force_mode_start ( int  ch,
uint16_t *  buff,
uint16_t  sample_num 
)

Start force mode.


Parameters
[in]chchannel.
See also
enum adc_ch
Parameters
[in]buffADC sample value buffer.
[in]sample_numSample number.
Returns
See also
enum adc_error for return code.

◆ hal_adc_measure_analog_ch()

int hal_adc_measure_analog_ch ( int  ch,
float  vref,
float *  vc 
)

read analog channel voltage.


Deprecation

Parameters
[in]chAnalog channel,
See also
adc_ch
Parameters
[in]vrefVref voltage, unit is V.
[out]vcChannel voltage, unit is V.
Returns
See also
enum adc_error for return code.

◆ hal_adc_measure_temp()

int hal_adc_measure_temp ( uint16_t  sample_num,
float *  temp 
)

Read temperature, this function is more accurate than hal_adc_force_mode_start or hal_adc_auto_mode_start.


Parameters
[in]sample_numsample number, recommanded value is 128
[out]temptemperature
Returns
See also
enum adc_error for return code.

◆ hal_adc_open()

int hal_adc_open ( adc_init_t *  init)

Open ADC device.


Parameters
[in]initADC init struct.
See also
adc_init_t
Returns
See also
enum adc_error

◆ hal_adc_sample_convert()

float hal_adc_sample_convert ( uint16_t  adc_val)

convert adc sample value to voltage, unit is mV, vref must be 1.0v


Parameters
adc_valADC sample value
Returns
voltage

◆ hal_adc_set_vref()

int hal_adc_set_vref ( int  vref)

Set ADC reference. Default is internal 1.0v.


Deprecation

Parameters
[in]vref
See also
adc_vref_t
Returns
See also
enum adc_error for return code.

◆ hal_adc_temp_sample_convert()

float hal_adc_temp_sample_convert ( uint16_t  adc_val)

convert temperature sample(channel 15) value to temperature, unit is centigrade


Parameters
adc_valADC sample value
Returns
temperature

◆ hal_adc_vbat_sample_convert()

float hal_adc_vbat_sample_convert ( uint16_t  adc_val)

convert vbat(channel 14) sample value to voltage, unit is mV


Parameters
adc_valADC sample value
Returns
voltage