mirror of https://github.com/ARMmbed/mbed-os.git
* updated with corrections in Analogue in and out APIs.
parent
fc6a097d43
commit
5079132062
|
@ -69,9 +69,9 @@ void analogout_write(dac_t *obj, float value)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(obj);
|
MBED_ASSERT(obj);
|
||||||
uint16_t count_val = 0;
|
uint16_t count_val = 0;
|
||||||
if (value < 0.0) {
|
if (value < 0.0f) {
|
||||||
count_val = 0;
|
count_val = 0;
|
||||||
} else if (value > 1.0) {
|
} else if (value > 1.0f) {
|
||||||
count_val = MAX_VAL_10BIT;
|
count_val = MAX_VAL_10BIT;
|
||||||
} else {
|
} else {
|
||||||
count_val = (uint16_t)(value * (float)MAX_VAL_10BIT);
|
count_val = (uint16_t)(value * (float)MAX_VAL_10BIT);
|
||||||
|
@ -89,20 +89,22 @@ void analogout_write_u16(dac_t *obj, uint16_t value)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t data_reg_read(dac_t *obj)
|
||||||
|
{
|
||||||
|
Dac *const dac_module = (Dac *)obj->dac;
|
||||||
|
return (uint32_t)dac_module->DATA.reg;
|
||||||
|
}
|
||||||
|
|
||||||
float analogout_read(dac_t *obj)
|
float analogout_read(dac_t *obj)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(obj);
|
MBED_ASSERT(obj);
|
||||||
uint32_t data_val = 0;
|
uint32_t data_val = data_reg_read(obj);
|
||||||
Dac *const dac_module = (Dac *)obj->dac;
|
|
||||||
data_val = dac_module->DATA.reg;
|
|
||||||
return data_val/(float)MAX_VAL_10BIT;
|
return data_val/(float)MAX_VAL_10BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t analogout_read_u16(dac_t *obj)
|
uint16_t analogout_read_u16(dac_t *obj)
|
||||||
{
|
{
|
||||||
MBED_ASSERT(obj);
|
MBED_ASSERT(obj);
|
||||||
uint32_t data_val = 0;
|
uint32_t data_val = data_reg_read(obj);
|
||||||
Dac *const dac_module = (Dac *)obj->dac;
|
|
||||||
data_val = dac_module->DATA.reg;
|
|
||||||
return (uint16_t)((data_val / (float)MAX_VAL_10BIT) * 0xFFFF); /*Normalization to the value 0xFFFF*/
|
return (uint16_t)((data_val / (float)MAX_VAL_10BIT) * 0xFFFF); /*Normalization to the value 0xFFFF*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,10 +161,9 @@ void analogin_init(analogin_t *obj, PinName pin)
|
||||||
adc_init(&adc_instance, ADC, &(obj->config_adc));
|
adc_init(&adc_instance, ADC, &(obj->config_adc));
|
||||||
adc_enable(&adc_instance);
|
adc_enable(&adc_instance);
|
||||||
init_flag = 1;
|
init_flag = 1;
|
||||||
} else { // pin muxing
|
|
||||||
adc_configure_ain_pin(obj->config_adc.positive_input);
|
|
||||||
adc_configure_ain_pin(obj->config_adc.negative_input);
|
|
||||||
}
|
}
|
||||||
|
adc_configure_ain_pin(obj->config_adc.positive_input);
|
||||||
|
adc_configure_ain_pin(obj->config_adc.negative_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t analogin_read_u16(analogin_t *obj)
|
uint16_t analogin_read_u16(analogin_t *obj)
|
||||||
|
|
Loading…
Reference in New Issue