Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions examples/Basic/AW9523B_IRQ/AW9523B_IRQ.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include <Arduino.h>
#include <M5StamPLC.h>

#define PIN_IRQ 14

void setup()
{
/* Init M5StamPLC */
M5StamPLC.begin();

/* Enable AW9523B input pins irq */
auto& ioe = M5StamPLC.getIOExpanderB();
std::vector<int> input_pins = {4, 5, 6, 7, 12, 13, 14, 15};
for (const auto& i : input_pins) {
ioe.enableInterrupt(i, true);
}

/* Setup irq pin */
pinMode(PIN_IRQ, INPUT_PULLUP);

printf("Change PLC input state to trigger irq\n");
}

void loop()
{
/* Check irq pin */
if (digitalRead(PIN_IRQ) == LOW) {
printf("AW9523B irq detected\n");

/* Clear irq */
auto& ioe = M5StamPLC.getIOExpanderB();
ioe.resetIrq();

delay(100);
}

delay(20);
}
40 changes: 40 additions & 0 deletions examples/Basic/PI4IOE5V6408_IRQ/PI4IOE5V6408_IRQ.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include <Arduino.h>
#include <M5StamPLC.h>

#define PIN_IRQ 14

void setup()
{
/* Init M5StamPLC */
M5StamPLC.begin();

/* Enable PI4IOE5V6408 irq */
auto& ioe = M5StamPLC.getIOExpanderA();
ioe.enableIrq();

/* Setup irq pin */
pinMode(PIN_IRQ, INPUT_PULLUP);

printf("Press button A/B/C to trigger irq\n");
}

void loop()
{
/* Check irq pin */
if (digitalRead(PIN_IRQ) == LOW) {
printf("PI4IOE5V6408 irq detected\n");

/* Clear irq */
auto& ioe = M5StamPLC.getIOExpanderA();
ioe.resetIrq();

delay(100);
}

delay(20);
}
13 changes: 13 additions & 0 deletions src/M5StamPLC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ void M5_STAMPLC::io_expander_a_init()
ioe.setDirection(6, true);
ioe.setPullMode(6, false);
ioe.setHighImpedance(6, true);

ioe.resetIrq();
ioe.disableIrq();
}

m5::IOExpander_Base& M5_STAMPLC::getIOExpanderA()
{
return M5.getIOExpander(0);
}

void M5_STAMPLC::setBacklight(bool on)
Expand Down Expand Up @@ -138,6 +146,11 @@ void M5_STAMPLC::io_expander_b_init()
}
}

AW9523_Class& M5_STAMPLC::getIOExpanderB()
{
return *_io_expander_b;
}

bool M5_STAMPLC::readPlcInput(const uint8_t& channel)
{
if (_io_expander_b == nullptr) {
Expand Down
14 changes: 14 additions & 0 deletions src/M5StamPLC.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ class M5_STAMPLC {
*/
void noTone();

/**
* @brief Get the IOExpander A, this is the IOExpander that controls the status light and button A/B/C
*
* @return m5::IOExpander_Base&
*/
m5::IOExpander_Base& getIOExpanderA();

/**
* @brief Get the IOExpander B, this is the IOExpander that controls the plc relays and plc inputs
*
* @return AW9523_Class&
*/
AW9523_Class& getIOExpanderB();

protected:
AW9523_Class* _io_expander_b = nullptr; // Controls plc relays, plc inputs
Config_t _config;
Expand Down