* updated with corrections in Analogue in and out APIs.

pull/1316/head
akhilpanayam 2015-08-18 18:06:37 +05:30 committed by Karthik Purushothaman
parent fc6a097d43
commit 5079132062
2 changed files with 12 additions and 11 deletions

View File

@ -69,9 +69,9 @@ void analogout_write(dac_t *obj, float value)
{
MBED_ASSERT(obj);
uint16_t count_val = 0;
if (value < 0.0) {
if (value < 0.0f) {
count_val = 0;
} else if (value > 1.0) {
} else if (value > 1.0f) {
count_val = MAX_VAL_10BIT;
} else {
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)
{
MBED_ASSERT(obj);
uint32_t data_val = 0;
Dac *const dac_module = (Dac *)obj->dac;
data_val = dac_module->DATA.reg;
uint32_t data_val = data_reg_read(obj);
return data_val/(float)MAX_VAL_10BIT;
}
uint16_t analogout_read_u16(dac_t *obj)
{
MBED_ASSERT(obj);
uint32_t data_val = 0;
Dac *const dac_module = (Dac *)obj->dac;
data_val = dac_module->DATA.reg;
uint32_t data_val = data_reg_read(obj);
return (uint16_t)((data_val / (float)MAX_VAL_10BIT) * 0xFFFF); /*Normalization to the value 0xFFFF*/
}

View File

@ -161,11 +161,10 @@ void analogin_init(analogin_t *obj, PinName pin)
adc_init(&adc_instance, ADC, &(obj->config_adc));
adc_enable(&adc_instance);
init_flag = 1;
} else { // pin muxing
}
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)
{