Skip to content
Open
Show file tree
Hide file tree
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
45 changes: 39 additions & 6 deletions drivers/sensor/adi/adxl345/adxl345.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,32 @@ static int adxl345_attr_set_odr(const struct device *dev,
ADXL345_ODR_MODE(odr));
}

#if !defined(CONFIG_ADXL345_STREAM)
/*
* In RTIO the watermark i.e. FIFO entries, will be used to lay out the memory
* pool for elements to hold. Thus watermark needs to be defined in the
* devicetree. If by attriute setting a greater number of entries will be set,
* it would crash.
*/
static int adxl345_attr_set_watermark(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
{
struct adxl345_dev_data *data = dev->data;
uint8_t wm = val->val1;

if (wm < 1 || wm > ADXL345_MAX_FIFO_SIZE) {
return -EINVAL;
}

data->fifo_config.fifo_samples = wm;

return adxl345_reg_write_mask(dev, ADXL345_FIFO_CTL_REG,
ADXL345_FIFO_CTL_SAMPLES_MSK, wm);
}
#endif

static int adxl345_attr_set(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
Expand All @@ -273,6 +299,10 @@ static int adxl345_attr_set(const struct device *dev,
return adxl345_attr_set_odr(dev, chan, attr, val);
case SENSOR_ATTR_UPPER_THRESH:
return adxl345_reg_write_byte(dev, ADXL345_THRESH_ACT_REG, val->val1);
#if !defined(CONFIG_ADXL345_STREAM)
case SENSOR_ATTR_MAX:
return adxl345_attr_set_watermark(dev, chan, attr, val);
#endif
default:
return -ENOTSUP;
}
Expand Down Expand Up @@ -435,6 +465,7 @@ static int adxl345_init(const struct device *dev)
enum adxl345_fifo_mode fifo_mode;
uint8_t dev_id;
uint8_t int_en;
uint8_t fifo_samples;
uint8_t regval;
int rc;

Expand Down Expand Up @@ -483,6 +514,7 @@ static int adxl345_init(const struct device *dev)
}

fifo_mode = ADXL345_FIFO_BYPASSED;
fifo_samples = 0;
int_en = 0x00;
#if defined(CONFIG_ADXL345_TRIGGER) || defined(CONFIG_ADXL345_STREAM)
if (adxl345_init_interrupt(dev)) {
Expand All @@ -491,6 +523,7 @@ static int adxl345_init(const struct device *dev)
} else {
LOG_INF("Set FIFO STREAMED mode");
fifo_mode = ADXL345_FIFO_STREAMED;
fifo_samples = cfg->fifo_samples;

/*
* Currently, map all interrupts to the (same) gpio line
Expand All @@ -508,8 +541,7 @@ static int adxl345_init(const struct device *dev)
}
}
#endif
rc = adxl345_configure_fifo(dev, fifo_mode, ADXL345_INT_UNSET,
ADXL345_FIFO_CTL_SAMPLES_MSK);
rc = adxl345_configure_fifo(dev, fifo_mode, ADXL345_INT_UNSET, fifo_samples);
if (rc) {
return rc;
}
Expand All @@ -525,7 +557,8 @@ static int adxl345_init(const struct device *dev)
#define ADXL345_CFG_IRQ(inst) \
.gpio_int1 = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, {0}), \
.gpio_int2 = GPIO_DT_SPEC_INST_GET_OR(inst, int2_gpios, {0}), \
.drdy_pad = DT_INST_PROP_OR(inst, drdy_pin, -1),
.drdy_pad = DT_INST_PROP_OR(inst, drdy_pin, -1), \
.fifo_samples = DT_INST_PROP_OR(inst, fifo_watermark, 1),
#else
#define ADXL345_CFG_IRQ(inst)
#endif /* CONFIG_ADXL345_TRIGGER */
Expand Down Expand Up @@ -562,9 +595,9 @@ static int adxl345_init(const struct device *dev)
COND_CODE_1(DT_INST_ON_BUS(inst, i2c), \
(ADXL345_RTIO_I2C_DEFINE(inst)), \
()) \
RTIO_DEFINE(adxl345_rtio_ctx_##inst, \
2 * DT_INST_PROP(inst, fifo_watermark) + 2, \
2 * DT_INST_PROP(inst, fifo_watermark) + 2);
RTIO_DEFINE(adxl345_rtio_ctx_##inst, \
4 * ADXL345_MAX_FIFO_SIZE, \
4 * ADXL345_MAX_FIFO_SIZE);
Comment on lines -547 to +737
Copy link
Member

Choose a reason for hiding this comment

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

Why from 2X+2 to 4X?


#define ADXL345_CONFIG(inst) \
.odr = DT_INST_PROP_OR(inst, odr, ADXL345_RATE_25HZ),
Expand Down
1 change: 0 additions & 1 deletion drivers/sensor/adi/adxl345/adxl345.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ struct adxl345_dev_data {
uint8_t reg_fifo_status; /* FIFO status register */
uint64_t timestamp;
struct rtio *r_cb;
uint8_t fifo_watermark_irq;
#endif /* CONFIG_ADXL345_STREAM */
};

Expand Down
20 changes: 7 additions & 13 deletions drivers/sensor/adi/adxl345/adxl345_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ void adxl345_submit_stream(const struct device *dev, struct rtio_iodev_sqe *iode
const struct sensor_read_config *cfg =
(const struct sensor_read_config *)iodev_sqe->sqe.iodev->data;
struct adxl345_dev_data *data = (struct adxl345_dev_data *)dev->data;
uint8_t int_value = (uint8_t)~ADXL345_INT_WATERMARK;
uint8_t fifo_watermark_irq = 0;
uint8_t status;
int rc;

if (adxl345_set_gpios_en(dev, false)) {
Expand All @@ -333,17 +332,12 @@ void adxl345_submit_stream(const struct device *dev, struct rtio_iodev_sqe *iode

for (size_t i = 0; i < cfg->count; i++) {
if (cfg->triggers[i].trigger == SENSOR_TRIG_FIFO_WATERMARK) {
int_value = ADXL345_INT_WATERMARK;
fifo_watermark_irq = 1;
}
}
uint8_t status;
if (fifo_watermark_irq != data->fifo_watermark_irq) {
data->fifo_watermark_irq = fifo_watermark_irq;
rc = adxl345_reg_write_mask(dev, ADXL345_INT_MAP_REG,
ADXL345_INT_WATERMARK, int_value);
if (rc < 0) {
return;
rc = adxl345_reg_assign_bits(dev, ADXL345_INT_ENABLE_REG,
ADXL345_INT_WATERMARK, true);
if (rc) {
LOG_WRN("adxl345_reg_assign_bits() failed");
return;
}
}

/* Flush the FIFO by disabling it. Save current mode for after the reset. */
Expand Down