Skip to content

Commit 6117e1e

Browse files
author
moyongming
committed
Merge Arduino begin() overloads and rename parameter 'mode' to 'intMode' to fix ambiguous call error.
1 parent 9ddcbd6 commit 6117e1e

2 files changed

Lines changed: 50 additions & 75 deletions

File tree

src/M5IOE1.cpp

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ M5IOE1::~M5IOE1() {
208208

209209
#ifdef ARDUINO
210210

211-
bool M5IOE1::begin(TwoWire *wire, uint8_t addr, uint8_t sda, uint8_t scl, uint32_t speed, m5ioe1_int_mode_t mode) {
211+
bool M5IOE1::begin(TwoWire *wire, uint8_t addr, uint8_t sda, uint8_t scl, uint32_t speed, int8_t intPin, m5ioe1_int_mode_t intMode) {
212212
_wire = wire;
213213
_addr = addr;
214214
_sda = sda; // 保存 SDA 引脚用于 I2C 重新初始化
215215
_scl = scl; // 保存 SCL 引脚用于 I2C 重新初始化
216-
_intPin = -1;
216+
_intPin = intPin;
217217

218218
// 验证 I2C 频率 - M5IOE1 仅支持 100KHz 或 400KHz
219219
// Validate I2C frequency - M5IOE1 only supports 100KHz or 400KHz
@@ -306,31 +306,21 @@ bool M5IOE1::begin(TwoWire *wire, uint8_t addr, uint8_t sda, uint8_t scl, uint32
306306

307307
M5IOE1_LOG_I(TAG, "M5IOE1 initialized at address 0x%02X (I2C: %lu Hz)", _addr, _requestedSpeed);
308308

309-
// 如果未禁用,设置中断模式
310-
// Set interrupt mode if not disabled
311-
if (mode != M5IOE1_INT_MODE_DISABLED) {
312-
setInterruptMode(mode);
309+
// 步骤7: 设置中断模式
310+
// Step 7: Set interrupt mode
311+
if (intMode != M5IOE1_INT_MODE_DISABLED) {
312+
setInterruptMode(intMode);
313313
}
314314

315315
return true;
316316
}
317317

318-
bool M5IOE1::begin(TwoWire *wire, uint8_t addr, uint8_t sda, uint8_t scl, uint32_t speed, int8_t intPin, m5ioe1_int_mode_t mode) {
319-
if (!begin(wire, addr, sda, scl, speed, M5IOE1_INT_MODE_DISABLED)) return false;
320-
321-
_intPin = intPin;
322-
if (_intPin >= 0) {
323-
return setInterruptMode(mode);
324-
}
325-
return true;
326-
}
327-
328318
#else // ESP-IDF
329319

330320
// =====================================================
331321
// Type 1A: Self-created I2C bus, no hardware interrupt
332322
// =====================================================
333-
bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t speed, m5ioe1_int_mode_t mode) {
323+
bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t speed, m5ioe1_int_mode_t intMode) {
334324
_addr = addr;
335325
_busExternal = false;
336326
_i2cDriverType = M5IOE1_I2C_DRIVER_SELF_CREATED;
@@ -476,8 +466,8 @@ bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t spe
476466

477467
// 如果未禁用,设置中断模式
478468
// Set interrupt mode if not disabled
479-
if (mode != M5IOE1_INT_MODE_DISABLED) {
480-
setInterruptMode(mode);
469+
if (intMode != M5IOE1_INT_MODE_DISABLED) {
470+
setInterruptMode(intMode);
481471
}
482472

483473
return true;
@@ -486,22 +476,22 @@ bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t spe
486476
// =====================================================
487477
// Type 1B: Self-created I2C bus, with hardware interrupt
488478
// =====================================================
489-
bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t speed, int intPin, m5ioe1_int_mode_t mode) {
479+
bool M5IOE1::begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t speed, int intPin, m5ioe1_int_mode_t intMode) {
490480
if (!begin(port, addr, sda, scl, speed, M5IOE1_INT_MODE_DISABLED)) {
491481
return false;
492482
}
493-
483+
494484
_intPin = intPin;
495485
if (_intPin >= 0) {
496-
return setInterruptMode(mode);
486+
return setInterruptMode(intMode);
497487
}
498488
return true;
499489
}
500490

501491
// =====================================================
502492
// Type 2A: Existing i2c_master_bus_handle_t, no hardware interrupt
503493
// =====================================================
504-
bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_int_mode_t mode) {
494+
bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_int_mode_t intMode) {
505495
_addr = addr;
506496
_busExternal = true;
507497
_i2cDriverType = M5IOE1_I2C_DRIVER_MASTER;
@@ -616,8 +606,8 @@ bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, m5
616606

617607
M5IOE1_LOG_I(TAG, "M5IOE1 initialized at address 0x%02X (I2C: %lu Hz)", _addr, _requestedSpeed);
618608

619-
if (mode != M5IOE1_INT_MODE_DISABLED) {
620-
setInterruptMode(mode);
609+
if (intMode != M5IOE1_INT_MODE_DISABLED) {
610+
setInterruptMode(intMode);
621611
}
622612

623613
return true;
@@ -626,22 +616,22 @@ bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, m5
626616
// =====================================================
627617
// Type 2B: Existing i2c_master_bus_handle_t, with hardware interrupt
628618
// =====================================================
629-
bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, int intPin, m5ioe1_int_mode_t mode) {
619+
bool M5IOE1::begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed, int intPin, m5ioe1_int_mode_t intMode) {
630620
if (!begin(bus, addr, speed, M5IOE1_INT_MODE_DISABLED)) {
631621
return false;
632622
}
633-
623+
634624
_intPin = intPin;
635625
if (_intPin >= 0) {
636-
return setInterruptMode(mode);
626+
return setInterruptMode(intMode);
637627
}
638628
return true;
639629
}
640630

641631
// =====================================================
642632
// Type 3A: Existing i2c_bus_handle_t, no hardware interrupt
643633
// =====================================================
644-
bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_int_mode_t mode) {
634+
bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_int_mode_t intMode) {
645635
_addr = addr;
646636
_busExternal = true;
647637
_i2cDriverType = M5IOE1_I2C_DRIVER_BUS;
@@ -734,8 +724,8 @@ bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_in
734724

735725
M5IOE1_LOG_I(TAG, "M5IOE1 initialized at address 0x%02X (I2C: %lu Hz)", _addr, _requestedSpeed);
736726

737-
if (mode != M5IOE1_INT_MODE_DISABLED) {
738-
setInterruptMode(mode);
727+
if (intMode != M5IOE1_INT_MODE_DISABLED) {
728+
setInterruptMode(intMode);
739729
}
740730

741731
return true;
@@ -744,28 +734,28 @@ bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, m5ioe1_in
744734
// =====================================================
745735
// Type 3B: Existing i2c_bus_handle_t, with hardware interrupt
746736
// =====================================================
747-
bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, int intPin, m5ioe1_int_mode_t mode) {
737+
bool M5IOE1::begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed, int intPin, m5ioe1_int_mode_t intMode) {
748738
if (!begin(bus, addr, speed, M5IOE1_INT_MODE_DISABLED)) {
749739
return false;
750740
}
751-
741+
752742
_intPin = intPin;
753743
if (_intPin >= 0) {
754-
return setInterruptMode(mode);
744+
return setInterruptMode(intMode);
755745
}
756746
return true;
757747
}
758748

759749
#endif
760750

761-
bool M5IOE1::setInterruptMode(m5ioe1_int_mode_t mode, uint32_t pollingIntervalMs) {
762-
_intMode = mode;
751+
bool M5IOE1::setInterruptMode(m5ioe1_int_mode_t intMode, uint32_t pollingIntervalMs) {
752+
_intMode = intMode;
763753
_pollingInterval = pollingIntervalMs;
764754

765755
#ifdef ARDUINO
766756
_cleanupPollingArduino();
767757

768-
if (mode == M5IOE1_INT_MODE_POLLING) {
758+
if (intMode == M5IOE1_INT_MODE_POLLING) {
769759
return _setupPollingArduino();
770760
}
771761
// Arduino 上的硬件中断模式需要 attachInterrupt
@@ -775,9 +765,9 @@ bool M5IOE1::setInterruptMode(m5ioe1_int_mode_t mode, uint32_t pollingIntervalMs
775765
#else
776766
_cleanupInterrupt();
777767

778-
if (mode == M5IOE1_INT_MODE_POLLING) {
768+
if (intMode == M5IOE1_INT_MODE_POLLING) {
779769
return _setupPolling();
780-
} else if (mode == M5IOE1_INT_MODE_HARDWARE) {
770+
} else if (intMode == M5IOE1_INT_MODE_HARDWARE) {
781771
if (_intPin < 0) {
782772
M5IOE1_LOG_E(TAG, "Hardware interrupt mode requires interrupt pin");
783773
return false;

src/M5IOE1.h

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,9 @@ class M5IOE1 {
436436
// ========================
437437
#ifdef ARDUINO
438438
/**
439-
* @brief Initialize the device without hardware interrupt pin (Arduino)
440-
* @note Without intPin: Only POLLING and DISABLED modes are supported
441-
* @note POLLING mode: Periodically reads GPIO_IS registers (0x11-0x12). Non-zero indicates one or more pins triggered
442-
* @param wire Pointer to TwoWire instance
443-
* @param addr I2C address (default 0x6F)
444-
* @param sda SDA pin (default -1, uses default I2C pins)
445-
* @param scl SCL pin (default -1, uses default I2C pins)
446-
* @param speed I2C speed in Hz (default 100000)
447-
* @param mode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
448-
* @return true if successful
449-
*/
450-
bool begin(TwoWire *wire, uint8_t addr = M5IOE1_DEFAULT_ADDR,
451-
uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 100000,
452-
m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_POLLING);
453-
454-
/**
455-
* @brief Initialize with hardware interrupt pin (Arduino)
456-
* @note With intPin: Supports HARDWARE, POLLING, and DISABLED modes
439+
* @brief Initialize the M5IOE1 device (Arduino)
440+
* @note Without intPin (or intPin=-1): Only POLLING and DISABLED modes are supported
441+
* @note With intPin >= 0: Supports HARDWARE, POLLING, and DISABLED modes
457442
* @note HARDWARE mode: Configures intPin as input without internal pull-up. Waits for falling edge, then reads GPIO_IS registers (0x11-0x12)
458443
* @note POLLING mode: Periodically reads GPIO_IS registers (0x11-0x12). Non-zero indicates one or more pins triggered
459444
* @note DISABLED mode: No interrupt handling
@@ -462,13 +447,13 @@ class M5IOE1 {
462447
* @param sda SDA pin (default -1, uses default I2C pins)
463448
* @param scl SCL pin (default -1, uses default I2C pins)
464449
* @param speed I2C speed in Hz (default 100000)
465-
* @param intPin Hardware interrupt pin. Must be valid GPIO for HARDWARE mode
466-
* @param mode Interrupt mode: M5IOE1_INT_MODE_HARDWARE (default), M5IOE1_INT_MODE_POLLING, or M5IOE1_INT_MODE_DISABLED
450+
* @param intPin Hardware interrupt pin (-1 = no hardware interrupt, default -1)
451+
* @param intMode Interrupt mode (default M5IOE1_INT_MODE_POLLING)
467452
* @return true if successful
468453
*/
469454
bool begin(TwoWire *wire, uint8_t addr = M5IOE1_DEFAULT_ADDR,
470-
uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 100000,
471-
int8_t intPin = -1, m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_HARDWARE);
455+
uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 100000,
456+
int8_t intPin = -1, m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_POLLING);
472457
#else // ESP-IDF
473458
// =====================================================
474459
// Type 1A: Self-created I2C bus, no hardware interrupt
@@ -480,12 +465,12 @@ class M5IOE1 {
480465
* @param sda SDA pin (default 21)
481466
* @param scl SCL pin (default 22)
482467
* @param speed I2C speed in Hz (only 100000 or 400000 supported)
483-
* @param mode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
468+
* @param intMode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
484469
* @return true if successful
485470
*/
486471
bool begin(i2c_port_t port = I2C_NUM_0, uint8_t addr = M5IOE1_DEFAULT_ADDR,
487472
int sda = 21, int scl = 22, uint32_t speed = M5IOE1_I2C_FREQ_100K,
488-
m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_POLLING);
473+
m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_POLLING);
489474

490475
// =====================================================
491476
// Type 1B: Self-created I2C bus, with hardware interrupt
@@ -498,11 +483,11 @@ class M5IOE1 {
498483
* @param scl SCL pin
499484
* @param speed I2C speed in Hz
500485
* @param intPin Hardware interrupt GPIO pin
501-
* @param mode Interrupt mode: M5IOE1_INT_MODE_HARDWARE, POLLING, or DISABLED
486+
* @param intMode Interrupt mode: M5IOE1_INT_MODE_HARDWARE, POLLING, or DISABLED
502487
* @return true if successful
503488
*/
504489
bool begin(i2c_port_t port, uint8_t addr, int sda, int scl, uint32_t speed,
505-
int intPin, m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_HARDWARE);
490+
int intPin, m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_HARDWARE);
506491

507492
// =====================================================
508493
// Type 2A: Existing i2c_master_bus_handle_t, no hardware interrupt
@@ -512,12 +497,12 @@ class M5IOE1 {
512497
* @param bus Existing i2c_master_bus_handle_t
513498
* @param addr I2C address (default 0x6F)
514499
* @param speed I2C speed in Hz (for device handle creation)
515-
* @param mode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
500+
* @param intMode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
516501
* @return true if successful
517502
*/
518503
bool begin(i2c_master_bus_handle_t bus, uint8_t addr = M5IOE1_DEFAULT_ADDR,
519504
uint32_t speed = M5IOE1_I2C_FREQ_100K,
520-
m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_POLLING);
505+
m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_POLLING);
521506

522507
// =====================================================
523508
// Type 2B: Existing i2c_master_bus_handle_t, with hardware interrupt
@@ -528,11 +513,11 @@ class M5IOE1 {
528513
* @param addr I2C address
529514
* @param speed I2C speed in Hz
530515
* @param intPin Hardware interrupt GPIO pin
531-
* @param mode Interrupt mode
516+
* @param intMode Interrupt mode
532517
* @return true if successful
533518
*/
534519
bool begin(i2c_master_bus_handle_t bus, uint8_t addr, uint32_t speed,
535-
int intPin, m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_HARDWARE);
520+
int intPin, m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_HARDWARE);
536521

537522
// =====================================================
538523
// Type 3A: Existing i2c_bus_handle_t, no hardware interrupt
@@ -542,12 +527,12 @@ class M5IOE1 {
542527
* @param bus Existing i2c_bus_handle_t
543528
* @param addr I2C address (default 0x6F)
544529
* @param speed I2C speed in Hz (for device handle creation)
545-
* @param mode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
530+
* @param intMode Interrupt mode: M5IOE1_INT_MODE_POLLING or M5IOE1_INT_MODE_DISABLED
546531
* @return true if successful
547532
*/
548533
bool begin(i2c_bus_handle_t bus, uint8_t addr = M5IOE1_DEFAULT_ADDR,
549534
uint32_t speed = M5IOE1_I2C_FREQ_100K,
550-
m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_POLLING);
535+
m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_POLLING);
551536

552537
// =====================================================
553538
// Type 3B: Existing i2c_bus_handle_t, with hardware interrupt
@@ -558,20 +543,20 @@ class M5IOE1 {
558543
* @param addr I2C address
559544
* @param speed I2C speed in Hz
560545
* @param intPin Hardware interrupt GPIO pin
561-
* @param mode Interrupt mode
546+
* @param intMode Interrupt mode
562547
* @return true if successful
563548
*/
564549
bool begin(i2c_bus_handle_t bus, uint8_t addr, uint32_t speed,
565-
int intPin, m5ioe1_int_mode_t mode = M5IOE1_INT_MODE_HARDWARE);
550+
int intPin, m5ioe1_int_mode_t intMode = M5IOE1_INT_MODE_HARDWARE);
566551
#endif
567552

568553
/**
569554
* @brief Set interrupt handling mode
570-
* @param mode Interrupt mode (DISABLED, POLLING, HARDWARE)
555+
* @param intMode Interrupt mode (DISABLED, POLLING, HARDWARE)
571556
* @param pollingIntervalMs Polling interval in ms (for polling mode, default 5000ms)
572557
* @return true if successful
573558
*/
574-
bool setInterruptMode(m5ioe1_int_mode_t mode, uint32_t pollingIntervalMs = 5000);
559+
bool setInterruptMode(m5ioe1_int_mode_t intMode, uint32_t pollingIntervalMs = 5000);
575560

576561
/**
577562
* @brief Set polling interval for POLLING mode

0 commit comments

Comments
 (0)