Skip to content
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
182bc8f
sensor: adxl345: DTS: add binding for FIFO interrupts
Rubusch Jun 26, 2025
655870d
sensor: adxl345: DTS: set minimum watermark to 2
Rubusch Oct 6, 2025
e4ce8f5
sensor: adxl345: DTS: adjust comment for interrupt binding
Rubusch Oct 8, 2025
eaf2b48
sensor: adxl345: set minimum watermark to 2
Rubusch Oct 8, 2025
f2400ba
sensor: adxl345: rename ADXL345_INT_ENABLE to ADXL345_INT_ENABLE_REG
Rubusch Jul 22, 2025
baf2957
sensor: adxl345: rename ADXL345_INT_MAP to ADXL345_INT_MAP_REG
Rubusch Jul 22, 2025
05ef6ae
sensor: adxl345: rename ADXL345_INT_SOURCE to ADXL345_INT_SOURCE_REG
Rubusch Jul 22, 2025
8901286
sensor: adxl345: rename SAMPLE_SIZE to ADXL345_FIFO_SAMPLE_SIZE
Rubusch Jul 23, 2025
d120c48
sensor: adxl345: rename SAMPLE_MASK to ADXL345_FIFO_SAMPLE_MSK
Rubusch Jul 23, 2025
d075536
sensor: adxl345: rename SAMPLE_NUM to ADXL345_FIFO_CTL_SAMPLES_MSK
Rubusch Jul 22, 2025
6928939
sensor: adxl345: change type of member is_full_res
Rubusch Jul 21, 2025
b634780
sensor: adxl345: change type of member fifo_samples
Rubusch Jul 22, 2025
c742a13
sensor: adxl345: fix function adxl345_write_mask()
Rubusch Jul 21, 2025
013925b
sensor: adxl345: remove unused adxl345_set_op_mode()
Rubusch Jul 21, 2025
d8a9f58
sensor: adxl345: remove unused field op_mode
Rubusch Jul 22, 2025
c177965
sensor: adxl345: control measurement by a dedicated function
Rubusch Jul 22, 2025
adcbc72
sensor: adxl345: split function get_status()
Rubusch Jul 22, 2025
e6718a8
sensor: adxl345: refactor both interrupt lines configurable in device…
Rubusch Jul 22, 2025
da74339
sensor: adxl345: rename local status1 to status
Rubusch Oct 10, 2025
012004e
sensor: adxl345: refactor ODR initialization
Rubusch Jul 22, 2025
a5248fb
sensor: adxl345: init the ADXL345_DATA_FORMAT_REG register
Rubusch Jul 22, 2025
917e51e
sensor: adxl345: fix FIFO default configuration
Rubusch Jul 25, 2025
4b6e074
sensor: adxl345: introduce ADXL345_REG_DATA_XYZ_REGS
Rubusch Jul 27, 2025
8014790
sensor: adxl345: rework FIFO mode and interrupt initialization
Rubusch Jul 22, 2025
6ccabb0
sensor: adxl345: remove unused field fifo_config from the const config
Rubusch Jul 22, 2025
4f3204a
sensor: adxl345: remove unnecessary loop check
Rubusch Jul 22, 2025
a64c486
sensor: adxl345: simplify INT register field defines
Rubusch Jul 26, 2025
2c2df72
sensor: adxl345: simplify event handler registration
Rubusch Jul 22, 2025
ccea5a0
sensor: adxl345: fix fetch and get to correctly read the FIFO samples
Rubusch Jul 27, 2025
23189cd
sensor: adxl345: reorganize stream code
Rubusch Sep 22, 2025
334077b
sensor: adxl345: remove pointless variable fifo_total_bytes
Rubusch Sep 22, 2025
4f92ab8
sensor: adxl345: use a concise naming for fifo related variables
Rubusch Sep 22, 2025
7730503
sensor: adxl345: add watermark configuration through app attribute
Rubusch Jul 21, 2025
6a4d044
sensor: adxl345: rename status1 to reg_int_source
Rubusch Sep 23, 2025
e3e53db
sensor: adxl345: streamline error handling
Rubusch Sep 23, 2025
00a8fe7
sensor: adxl345: provide generic bus access API
Rubusch Sep 23, 2025
98ec77b
sensor: adxl345: factor out initialization of the stream header
Rubusch Sep 23, 2025
d45b662
sensor: adxl345: factor out consumption of CQEs
Rubusch Sep 23, 2025
d0cd81f
sensor: adxl345: move streaming checks to separate function
Rubusch Sep 23, 2025
a2b8770
sensor: adxl345: rework flushing the fifo
Rubusch Sep 23, 2025
f6b7a52
sensor: adxl345: cover watermark and overrun as sensor events
Rubusch Sep 23, 2025
29365ff
sensor: adxl345: distinguish the stream handler from trigger
Rubusch Sep 23, 2025
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
60 changes: 37 additions & 23 deletions drivers/sensor/adi/adxl345/adxl345_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ static void adxl345_fifo_flush_rtio(const struct device *dev);

/* auxiliary functions */

static void adxl345_sqe_done(const struct device *dev,
struct rtio_iodev_sqe *iodev_sqe, int res)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't iodev_sqe already contained in dev->data? Why are we passing it as another argument?

if (res < 0) {
LOG_WRN("res == %d < 0)", res);
rtio_iodev_sqe_err(iodev_sqe, res);
} else {
rtio_iodev_sqe_ok(iodev_sqe, res);
}
adxl345_set_gpios_en(dev, true);
}

/* streaming callbacks and calls */

Expand All @@ -36,11 +47,7 @@ static void adxl345_fifo_read_cb(struct rtio *rtio_ctx, const struct rtio_sqe *s
struct adxl345_dev_data *data = (struct adxl345_dev_data *) dev->data;
struct rtio_iodev_sqe *iodev_sqe = sqe->userdata;

if (data->fifo_entries == 0) {
rtio_iodev_sqe_ok(iodev_sqe, 0);
adxl345_set_gpios_en(dev, true);
}

adxl345_sqe_done(dev, iodev_sqe, data->fifo_entries);
}

static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sqe *sqe,
Expand Down Expand Up @@ -74,9 +81,7 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq

if (rtio_sqe_rx_buf(current_sqe, min_read_size, ideal_read_size, &buf, &buf_len) != 0) {
LOG_ERR("Failed to get buffer");
rtio_iodev_sqe_err(current_sqe, -ENOMEM);
adxl345_set_gpios_en(dev, true);
return;
goto err;
}
LOG_DBG("Requesting buffer [%u, %u] got %u", (unsigned int)min_read_size,
(unsigned int)ideal_read_size, buf_len);
Expand Down Expand Up @@ -125,8 +130,7 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq

/* Bail/cancel attempt to read sensor on any error */
if (res != 0) {
rtio_iodev_sqe_err(current_sqe, res);
return;
goto err;
}


Expand Down Expand Up @@ -157,6 +161,11 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
rtio_submit(data->rtio_ctx, 0);
ARG_UNUSED(rtio_cqe_consume(data->rtio_ctx));
}

return;
err:
LOG_WRN("Failed.");
adxl345_sqe_done(dev, current_sqe, -ENOMEM);
}

static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sqe,
Expand All @@ -178,11 +187,11 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq
read_config = (struct sensor_read_config *)data->sqe->sqe.iodev->data;

if (read_config == NULL) {
return;
goto err;
}

if (read_config->is_streaming == false) {
return;
goto err;
}

adxl345_set_gpios_en(dev, false);
Expand All @@ -203,8 +212,7 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq
}

if (!fifo_full_irq) {
adxl345_set_gpios_en(dev, true);
return;
goto err;
}

/* Flush completions */
Expand All @@ -224,8 +232,7 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq

/* Bail/cancel attempt to read sensor on any error */
if (res != 0) {
rtio_iodev_sqe_err(current_sqe, res);
return;
goto err;
}

enum sensor_stream_data_opt data_opt;
Expand All @@ -242,9 +249,7 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq
data->sqe = NULL;
if (rtio_sqe_rx_buf(current_sqe, sizeof(struct adxl345_fifo_data),
sizeof(struct adxl345_fifo_data), &buf, &buf_len) != 0) {
rtio_iodev_sqe_err(current_sqe, -ENOMEM);
adxl345_set_gpios_en(dev, true);
return;
goto err;
}

struct adxl345_fifo_data *rx_data = (struct adxl345_fifo_data *)buf;
Expand All @@ -254,14 +259,13 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq
rx_data->timestamp = data->timestamp;
rx_data->int_status = status1;
rx_data->fifo_byte_count = 0;
rtio_iodev_sqe_ok(current_sqe, 0);

if (data_opt == SENSOR_STREAM_DATA_DROP) {
/* Flush the FIFO by disabling it. Save current mode for after the reset. */
adxl345_fifo_flush_rtio(dev);
}

adxl345_set_gpios_en(dev, true);
adxl345_sqe_done(dev, current_sqe, 0);
return;
}

Expand All @@ -282,6 +286,11 @@ static void adxl345_process_status1_cb(struct rtio *r, const struct rtio_sqe *sq
current_sqe);

rtio_submit(data->rtio_ctx, 0);

return;
err:
LOG_WRN("Failed.");
adxl345_sqe_done(dev, current_sqe, -ENOMEM);
}

static void adxl345_fifo_flush_rtio(const struct device *dev)
Expand Down Expand Up @@ -366,6 +375,7 @@ void adxl345_stream_irq_handler(const struct device *dev)
{
struct adxl345_dev_data *data = (struct adxl345_dev_data *) dev->data;
const struct adxl345_dev_config *cfg = (const struct adxl345_dev_config *) dev->config;
struct rtio_iodev_sqe *current_sqe = data->sqe;
uint64_t cycles;
int rc;

Expand All @@ -376,8 +386,7 @@ void adxl345_stream_irq_handler(const struct device *dev)
rc = sensor_clock_get_cycles(&cycles);
if (rc != 0) {
LOG_ERR("Failed to get sensor clock cycles");
rtio_iodev_sqe_err(data->sqe, rc);
return;
goto err;
}

data->timestamp = sensor_clock_cycles_to_ns(cycles);
Expand All @@ -399,4 +408,9 @@ void adxl345_stream_irq_handler(const struct device *dev)
}
rtio_sqe_prep_callback(check_status_reg, adxl345_process_status1_cb, (void *)dev, NULL);
rtio_submit(data->rtio_ctx, 0);

return;
err:
LOG_WRN("Failed.");
adxl345_sqe_done(dev, current_sqe, -ENOMEM);
}