Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign extend AD4170 data when channels are in bipolar configuration #105

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion projects/ad4170_iio/app/ad4170_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "no_os_error.h"
#include "no_os_irq.h"
#include "no_os_delay.h"
#include "no_os_util.h"
#include "common.h"
#include "iio_trigger.h"

Expand Down Expand Up @@ -548,7 +549,7 @@ static int get_adc_raw(void *device,
intptr_t id)
{
int32_t ret;
static uint32_t adc_data_raw = 0;
static int32_t adc_data_raw = 0;
int32_t offset = 0;
uint8_t setup = p_ad4170_dev_inst->config.setup[channel->ch_num].setup_n;
bool bipolar = p_ad4170_dev_inst->config.setups[setup].afe.bipolar;
Expand Down Expand Up @@ -577,6 +578,9 @@ static int get_adc_raw(void *device,
if (ret) {
break;
}
if (channel->scan_type.sign == 's')
adc_data_raw = no_os_sign_extend32(adc_data_raw,
channel->scan_type.realbits - 1);

perform_sensor_measurement_and_update_scale(adc_data_raw, channel->ch_num);
return sprintf(buf, "%d", adc_data_raw);
Expand Down