Skip to content

Commit

Permalink
projects: ad7091r: Add minor updates
Browse files Browse the repository at this point in the history
Update limit registers attribute setter functions.
Get the latest alert recorded when both occur.
Do a read op to record if any alert is occured.
Revert back active com port to phy com port.

Signed-off-by: SGudla <[email protected]>
  • Loading branch information
SaikiranGudla committed Dec 19, 2024
1 parent 18cd58e commit 3942b95
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projects/ad7091r_iio/STM32/.extSettings
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
23 changes: 20 additions & 3 deletions projects/ad7091r_iio/app/ad7091r_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 3942b95

Please sign in to comment.