Skip to content

Commit 69c7f55

Browse files
committed
Fixes
1 parent db693cc commit 69c7f55

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

deploy/src/icm42688.jl

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ end
451451
Read raw gyroscope values (X, Y, Z) as signed 16-bit integers.
452452
"""
453453
function read_gyro_raw(imu::ICM42688)
454-
buf = @view imu.rx_buf[1:6]
455-
read_regs!(imu, ICM42688Registers.GYRO_DATA_X1, buf)
456-
gx = parse_int16_be(buf[1], buf[2])
457-
gy = parse_int16_be(buf[3], buf[4])
458-
gz = parse_int16_be(buf[5], buf[6])
454+
read_regs!(imu, ICM42688Registers.GYRO_DATA_X1, 6)
455+
buf = imu.rx_buf
456+
gx = parse_int16_be(buf[2], buf[3])
457+
gy = parse_int16_be(buf[4], buf[5])
458+
gz = parse_int16_be(buf[6], buf[7])
459459
return (gx, gy, gz)
460460
end
461461

@@ -476,9 +476,8 @@ end
476476
Read raw temperature value as a signed 16-bit integer.
477477
"""
478478
function read_temp_raw(imu::ICM42688)
479-
buf = @view imu.rx_buf[1:2]
480-
read_regs!(imu, ICM42688Registers.TEMP_DATA1, buf)
481-
return parse_int16_be(buf[1], buf[2])
479+
read_regs!(imu, ICM42688Registers.TEMP_DATA1, 2)
480+
return parse_int16_be(imu.rx_buf[2], imu.rx_buf[3])
482481
end
483482

484483
"""
@@ -500,17 +499,17 @@ Reads 14 consecutive bytes starting from TEMP_DATA1 (0x1D).
500499
Layout: TEMP(2) + ACCEL(6) + GYRO(6) = 14 bytes.
501500
"""
502501
function read_all_raw(imu::ICM42688)
503-
buf = @view imu.rx_buf[1:14]
504-
read_regs!(imu, ICM42688Registers.TEMP_DATA1, buf)
502+
read_regs!(imu, ICM42688Registers.TEMP_DATA1, 14)
503+
buf = imu.rx_buf # data at indices 2..15
505504

506505
return ICM42688Data(
507-
parse_int16_be(buf[3], buf[4]), # ACCEL_X
508-
parse_int16_be(buf[5], buf[6]), # ACCEL_Y
509-
parse_int16_be(buf[7], buf[8]), # ACCEL_Z
510-
parse_int16_be(buf[1], buf[2]), # TEMP
511-
parse_int16_be(buf[9], buf[10]), # GYRO_X
512-
parse_int16_be(buf[11], buf[12]), # GYRO_Y
513-
parse_int16_be(buf[13], buf[14]) # GYRO_Z
506+
parse_int16_be(buf[4], buf[5]), # ACCEL_X
507+
parse_int16_be(buf[6], buf[7]), # ACCEL_Y
508+
parse_int16_be(buf[8], buf[9]), # ACCEL_Z
509+
parse_int16_be(buf[2], buf[3]), # TEMP
510+
parse_int16_be(buf[10], buf[11]), # GYRO_X
511+
parse_int16_be(buf[12], buf[13]), # GYRO_Y
512+
parse_int16_be(buf[14], buf[15]) # GYRO_Z
514513
)
515514
end
516515

@@ -614,9 +613,8 @@ end
614613
Read the number of bytes currently in the FIFO.
615614
"""
616615
function read_fifo_count(imu::ICM42688)
617-
buf = @view imu.rx_buf[1:2]
618-
read_regs!(imu, ICM42688Registers.FIFO_COUNTH, buf)
619-
return (UInt16(buf[1]) << 8) | UInt16(buf[2])
616+
read_regs!(imu, ICM42688Registers.FIFO_COUNTH, 2)
617+
return (UInt16(imu.rx_buf[2]) << 8) | UInt16(imu.rx_buf[3])
620618
end
621619

622620
"""

deploy/src/shift_driver.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using PIOLib
22

3-
function shift_register_program(; ser_pin::Integer, clk_pin::Integer, rclk_pin::Integer,
3+
function shift_register_program(pio::PIOBlock; ser_pin::Integer, clk_pin::Integer, rclk_pin::Integer,
44
nbits::Integer, clkdiv::Real=1.0f0)
55
1 <= nbits <= 31 || error("nbits must be 1-31 (SET immediate is 5 bits, and 32 encodes as 0 in autopull threshold)")
66

@@ -15,7 +15,7 @@ function shift_register_program(; ser_pin::Integer, clk_pin::Integer, rclk_pin::
1515
Wrap(),
1616
]; sideset_bits=1)
1717

18-
config = SMConfig(;
18+
config = SMConfig(pio;
1919
out_pins=(ser_pin, 1),
2020
set_pins=(rclk_pin, 1),
2121
sideset_pin_base=clk_pin,
@@ -87,13 +87,13 @@ Initialize the PIO and state machine for driving the shift register chain.
8787
Caller is responsible for calling `close` when done.
8888
"""
8989
function open_shift_registers(pio_idx::Integer=0)
90-
prog, config = shift_register_program(
91-
ser_pin=SER_PIN, clk_pin=CLK_PIN, rclk_pin=RCLK_PIN,
92-
nbits=NBITS, clkdiv=CLKDIV,
93-
)
94-
9590
pio = open_pio(pio_idx)
9691
try
92+
prog, config = shift_register_program(pio;
93+
ser_pin=SER_PIN, clk_pin=CLK_PIN, rclk_pin=RCLK_PIN,
94+
nbits=NBITS, clkdiv=CLKDIV,
95+
)
96+
9797
for pin in (SER_PIN, CLK_PIN, RCLK_PIN)
9898
pio_pin_init!(pio, pin)
9999
end

0 commit comments

Comments
 (0)