diff --git a/projects/ad7091r_iio/STM32/.extSettings b/projects/ad7091r_iio/STM32/.extSettings index 175c7950..e25c0f37 100644 --- a/projects/ad7091r_iio/STM32/.extSettings +++ b/projects/ad7091r_iio/STM32/.extSettings @@ -23,4 +23,4 @@ app/libraries/no-OS/iio/=../../../libraries/no-OS/iio/iio.c;../../../libraries/n app/libraries/no-OS/drivers/api/=../../../libraries/no-OS/drivers/api/no_os_gpio.c;../../../libraries/no-OS/drivers/api/no_os_spi.c;../../../libraries/no-OS/drivers/api/no_os_i2c.c;../../../libraries/no-OS/drivers/api/no_os_eeprom.c;../../../libraries/no-OS/drivers/api/no_os_irq.c;../../../libraries/no-OS/drivers/api/no_os_uart.c;../../../libraries/no-OS/drivers/api/no_os_pwm.c;../../../libraries/no-OS/drivers/api/no_os_dma.c; [Others] -Define=_USE_STD_INT_TYPES;TINYIIOD_VERSION_MAJOR;TINYIIOD_VERSION_MINOR;TINYIIOD_VERSION_GIT;IIOD_BUFFER_SIZE;IIO_IGNORE_BUFF_OVERRUN_ERR;ACTIVE_PLATFORM:1;TARGET_SDP_K1 \ No newline at end of file +Define=_USE_STD_INT_TYPES;TINYIIOD_VERSION_MAJOR;TINYIIOD_VERSION_MINOR;TINYIIOD_VERSION_GIT;IIOD_BUFFER_SIZE;USE_PHY_COM_PORT;IIO_IGNORE_BUFF_OVERRUN_ERR;ACTIVE_PLATFORM:1;TARGET_SDP_K1 \ No newline at end of file diff --git a/projects/ad7091r_iio/app/ad7091r_iio.c b/projects/ad7091r_iio/app/ad7091r_iio.c index f099d247..95a2441f 100644 --- a/projects/ad7091r_iio/app/ad7091r_iio.c +++ b/projects/ad7091r_iio/app/ad7091r_iio.c @@ -103,6 +103,9 @@ static int ad7091r_iio_attr_available_set(void *device, /* AD70901r register maximum value */ #define REGISTER_MAX_VAL AD7091R8_REG_CH_HYSTERESIS(7) +/* AD70901r limit register value bit shift */ +#define AD7091R_LIMIT_REG_BIT_SHIFT 3 + /* ADC data buffer size */ #if defined(USE_SDRAM) #define adc_data_buffer SDRAM_START_ADDRESS @@ -406,6 +409,7 @@ static int ad7091r_iio_attr_get(void *device, int ret; uint16_t read_val = 0; enum ad7091r8_alert_type alert; + static uint8_t alert_val[8]; switch (priv) { case ADC_RAW: @@ -427,11 +431,23 @@ static int ad7091r_iio_attr_get(void *device, return sprintf(buf, "%d", offset); case ADC_THRESHOLD_ALERT: + /* Do one read op for threshold alert */ + ret = ad7091r8_read_one_stm(channel->ch_num, &read_val); + if (ret) { + return ret; + } + ret = ad7091r8_get_alert(ad7091r_dev_desc, channel->ch_num, &alert); if (ret) { return ret; } + /* If both alerts are recorded, retrieve the latest alert occured */ + if (alert >= NO_OS_ARRAY_SIZE(ad7091r_thresh_val)) { + alert &= ~alert_val[channel->ch_num]; + } + alert_val[channel->ch_num] = alert; + return sprintf(buf, "%s", ad7091r_thresh_val[alert]); case ADC_LOW_LIMIT_REG: @@ -512,6 +528,7 @@ static int ad7091r_iio_attr_set(void *device, uint8_t val = 0; float ref_val = 0; uint32_t write_val; + enum ad7091r8_limit limit = AD7091R8_LOW_LIMIT; switch (priv) { case ADC_RAW: @@ -532,7 +549,7 @@ static int ad7091r_iio_attr_set(void *device, write_val = no_os_str_to_uint32(buf); ret = ad7091r8_set_limit(ad7091r_dev_desc, AD7091R8_LOW_LIMIT, channel->ch_num, - write_val); + write_val >> AD7091R_LIMIT_REG_BIT_SHIFT); if (ret) { return ret; } @@ -543,7 +560,7 @@ static int ad7091r_iio_attr_set(void *device, write_val = no_os_str_to_uint32(buf); ret = ad7091r8_set_limit(ad7091r_dev_desc, AD7091R8_HIGH_LIMIT, channel->ch_num, - write_val); + write_val >> AD7091R_LIMIT_REG_BIT_SHIFT); if (ret) { return ret; } @@ -554,7 +571,7 @@ static int ad7091r_iio_attr_set(void *device, write_val = no_os_str_to_uint32(buf); ret = ad7091r8_set_limit(ad7091r_dev_desc, AD7091R8_HYSTERESIS, channel->ch_num, - write_val); + write_val >> AD7091R_LIMIT_REG_BIT_SHIFT); if (ret) { return ret; }