aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2023-12-17 17:17:16 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-01-07 11:59:59 -0500
commit84aa3caa45bd18363bef9683981215ca3b169654 (patch)
tree888445a22dd36cfce24b8c43680617bf27a0082e /src
parent49315b3cc40443be08e1f1c77a656fc103337a33 (diff)
downloadkutter-84aa3caa45bd18363bef9683981215ca3b169654.tar.gz
kutter-84aa3caa45bd18363bef9683981215ca3b169654.tar.xz
kutter-84aa3caa45bd18363bef9683981215ca3b169654.zip
sensor_mpu9250: Simplify mp9250_query()
The mpu9250 code always reads from the sensor in 48 byte chunks and always sends an mpu9250_data message immediately after that. Make that more clear in the querying code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/sensor_mpu9250.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/sensor_mpu9250.c b/src/sensor_mpu9250.c
index 86508a6e..68dd502f 100644
--- a/src/sensor_mpu9250.c
+++ b/src/sensor_mpu9250.c
@@ -40,6 +40,7 @@
#define FIFO_OVERFLOW_INT 0x10
#define BYTES_PER_FIFO_ENTRY 6
+#define BYTES_PER_BLOCK 48
struct mpu9250 {
struct timer timer;
@@ -49,7 +50,7 @@ struct mpu9250 {
uint8_t flags, data_count;
// msg size must be <= 255 due to Klipper api
// = SAMPLES_PER_BLOCK (from mpu9250.py) * BYTES_PER_FIFO_ENTRY + 1
- uint8_t data[48];
+ uint8_t data[BYTES_PER_BLOCK];
};
enum {
@@ -126,28 +127,23 @@ mp9250_reschedule_timer(struct mpu9250 *mp)
static void
mp9250_query(struct mpu9250 *mp, uint8_t oid)
{
- // Find remaining space in report buffer
- uint8_t data_space = sizeof(mp->data) - mp->data_count;
-
// If not enough bytes to fill report read MPU FIFO's fill
- if (mp->fifo_pkts_bytes < data_space) {
- mp->fifo_pkts_bytes = get_fifo_status(mp) / BYTES_PER_FIFO_ENTRY
- * BYTES_PER_FIFO_ENTRY;
- }
+ if (mp->fifo_pkts_bytes < BYTES_PER_BLOCK)
+ mp->fifo_pkts_bytes = get_fifo_status(mp);
// If we have enough bytes to fill the buffer do it and send report
- if (mp->fifo_pkts_bytes >= data_space) {
+ if (mp->fifo_pkts_bytes >= BYTES_PER_BLOCK) {
uint8_t reg = AR_FIFO;
- i2c_read(mp->i2c->i2c_config, sizeof(reg), &reg,
- data_space, &mp->data[mp->data_count]);
- mp->data_count += data_space;
- mp->fifo_pkts_bytes -= data_space;
+ i2c_read(mp->i2c->i2c_config, sizeof(reg), &reg
+ , BYTES_PER_BLOCK, &mp->data[0]);
+ mp->data_count = BYTES_PER_BLOCK;
+ mp->fifo_pkts_bytes -= BYTES_PER_BLOCK;
mp9250_report(mp, oid);
}
// If we have enough bytes remaining to fill another report wake again
// otherwise schedule timed wakeup
- if (mp->fifo_pkts_bytes > data_space) {
+ if (mp->fifo_pkts_bytes >= BYTES_PER_BLOCK) {
sched_wake_task(&mpu9250_wake);
} else if (mp->flags & AX_RUNNING) {
sched_del_timer(&mp->timer);