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 23, 2024
1 parent 739ff40 commit 1afc6ba
Show file tree
Hide file tree
Showing 2 changed files with 20 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
22 changes: 19 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 @@ -532,7 +548,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 +559,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 +570,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 1afc6ba

Please sign in to comment.