Skip to content

Commit

Permalink
drivers: sensor: qdec: fix QDEC overflow handling
Browse files Browse the repository at this point in the history
QDEC sensor driver fails to inform user of the overflow in the
ACC register, which makes the most recently fetched data invalid.
An error code return has been added to nrfx_qdec_sample_fetch(),
that indicates that an overflow has occured, based on oveflow flag.
Also, raw_acc field was added in the qdec_nrfx_data structure, to
adjust QDEC to sensor API rules - two subsequent sensor_channel_get()
calls should will yield the same values.

Signed-off-by: Michał Stasiak <[email protected]>
  • Loading branch information
mstasiaknordic committed Jul 12, 2024
1 parent 42d6cd8 commit a7c889e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/sensor/nordic/qdec_nrfx/qdec_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ LOG_MODULE_REGISTER(qdec_nrfx, CONFIG_SENSOR_LOG_LEVEL);
#define ACC_MAX (INT_MAX / FULL_ANGLE)
#define ACC_MIN (INT_MIN / FULL_ANGLE)

#define ACC_REG_MAX 1023
#define ACC_REG_MIN -1024


struct qdec_nrfx_data {
int32_t raw_acc;
Expand Down Expand Up @@ -60,7 +57,7 @@ static void accumulate(struct qdec_nrfx_data *data, int32_t acc)
}

static int qdec_nrfx_sample_fetch(const struct device *dev,
enum sensor_channel chan)
enum sensor_channel chan)
{
const struct qdec_nrfx_config *config = dev->config;
struct qdec_nrfx_data *data = dev->data;
Expand All @@ -73,6 +70,7 @@ static int qdec_nrfx_sample_fetch(const struct device *dev,

if (data->overflow) {
data->overflow = 0;
data->raw_acc = 0;
return -EOVERFLOW;
}

Expand Down Expand Up @@ -101,7 +99,6 @@ static int qdec_nrfx_channel_get(const struct device *dev,

key = irq_lock();
acc = data->acc;
//data->acc = 0;
irq_unlock(key);

val->val1 = (acc * FULL_ANGLE) / config->steps;
Expand Down

0 comments on commit a7c889e

Please sign in to comment.