Skip to content

Commit 5d1c20f

Browse files
committed
fix(bmi270): correct interrupt pin configuration logic
1 parent 242d690 commit 5d1c20f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

components/bmi270/include/bmi270.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,28 @@ class Bmi270 : public espp::BasePeripheral<uint8_t, Interface == bmi270::Interfa
433433
/// @param ec The error code to set if an error occurs
434434
/// @return True if interrupts were configured successfully, false otherwise
435435
bool configure_interrupts(const InterruptConfig &config, std::error_code &ec) {
436-
// Configure interrupt pin behavior
437-
uint8_t int_io_ctrl =
438-
(static_cast<uint8_t>(config.active_level) << 1) | static_cast<uint8_t>(config.output_type);
439-
440-
if (config.pin == InterruptPin::INT1) {
441-
write_u8_to_register(static_cast<uint8_t>(Register::INT1_IO_CTRL), int_io_ctrl, ec);
442-
} else {
443-
write_u8_to_register(static_cast<uint8_t>(Register::INT2_IO_CTRL), int_io_ctrl, ec);
436+
// Configure interrupt pin electrical behavior (Output Enable | Output Type | Active Level)
437+
// Bit 3 is Output Enable, which must be set to 1 for the pin to drive the line.
438+
uint8_t int_io_ctrl = (1 << 3) |
439+
(static_cast<uint8_t>(config.output_type) << 2) |
440+
(static_cast<uint8_t>(config.active_level) << 1);
441+
442+
auto pin_reg = (config.pin == InterruptPin::INT1) ? Register::INT1_IO_CTRL : Register::INT2_IO_CTRL;
443+
write_u8_to_register(static_cast<uint8_t>(pin_reg), int_io_ctrl, ec);
444+
if (ec) return false;
445+
446+
// Map interrupt features to pins
447+
uint8_t int_map_data = 0;
448+
if (config.enable_data_ready) {
449+
// Map Data Ready interrupt to the selected pin
450+
// Bit 2: Data Ready -> INT1, Bit 6: Data Ready -> INT2
451+
int_map_data |= (config.pin == InterruptPin::INT1) ? (1 << 2) : (1 << 6);
444452
}
445453

446-
return !ec;
454+
write_u8_to_register(static_cast<uint8_t>(Register::INT_MAP_DATA), int_map_data, ec);
455+
if (ec) return false;
456+
457+
return true;
447458
}
448459

449460
protected:

0 commit comments

Comments
 (0)