For suitable output, we recommend to use Google Chrome (15+) or Microsoft Edge (79+).
As of 2025-07-24General Purpose Digital IO
Functions to handle DIO ports
The following functions are used to operate General Purpose Digital IO (DIO).
pinMode()
digitalWrite()
digitalRead()
attachIntDio()
detachIntDio()
Constants
Pin Names and Numbers
Definition | Name |
---|
const uint8_t PIN_DIGITAL::DIO0 .. 19 | DIO pins 0 to 19 |
const uint8_t PIN_DIGITAL::DO0 .. 1 | DO pins 0,1 |
Pin Modes (DIO0..19)
The following enumerated values are handled by the type E_PIN_MODE
.
Definition | Pull-up | Name |
---|
PIN_MODE::INPUT | No | Input |
PIN_MODE::OUTPUT | No | Output |
PIN_MODE::INPUT_PULLUP | Yes | Input with Pull-up |
PIN_MODE::OUTPUT_INIT_HIGH | No | Output (initial state HIGH) |
PIN_MODE::OUTPUT_INIT_LOW | No | Output (initial state LOW) |
PIN_MODE::WAKE_FALLING | No | Input, wake pin, falling edge |
PIN_MODE::WAKE_RISING | No | Input, wake pin, rising edge |
PIN_MODE::WAKE_FALLING_PULLUP | Yes | Input, wake pin, falling edge with pull-up |
PIN_MODE::WAKE_RISING_PULLUP | Yes | Input, wake pin, rising edge with pull-up |
PIN_MODE::DISABLE_OUTPUT | Yes | Return to input state |
Pin Modes (DO0,1)
The following enumerated values are handled by the type E_PIN_MODE
.
Definition | Name |
---|
PIN_MODE::OUTPUT | Output |
PIN_MODE::OUTPUT_INIT_HIGH | Output (initial state HIGH) |
PIN_MODE::OUTPUT_INIT_LOW | Output (initial state LOW) |
PIN_MODE::DISABLE_OUTPUT | Stop output setting |
Pin States
The following enumerated values are handled by the type E_PIN_STATE
.
Definition | Value | Name |
---|
PIN_STATE::HIGH | 1 | HIGH level (=Vcc level) |
PIN_STATE::LOW | 0 | LOW level (=GND level) |
Pin Rising and Falling Edges
The following enumerated values are handled by the type E_PIN_INT_MODE
.
Definition | Name |
---|
PIN_INT_MODE::FALLING | Falling edge |
PIN_INT_MODE::RISING | Rising edge |
1 - pinMode()
Initialization function
Configures the settings for DIO (General Purpose Digital IO) pins.
void pinMode(uint8_t u8pin, E_PIN_MODE mode)
This function allows configuration of the states of DIO0 to DIO19 and DO0,1 pins. For details on the configuration values, refer to the enumerated values of E_PIN_MODE
in the DIO explanation and the DO explanation.
DO0 and DO1 are special-purpose pins and are generally used for other functions, but they can also be configured for output. However, these pins have hardware constraints, so caution is required when using them.
Both pins must be held at a HIGH level upon power-up. If the circuit configuration causes unstable voltage levels, it may result in the module failing to start.
2 - digitalWrite()
Digital output function
Changes the setting of a digital output pin.
static inline void digitalWrite(uint8_t u8pin, E_PIN_STATE ulVal)
Beforehand, set the target pin as output using pinMode()
. The first parameter specifies the pin number to be set. The second parameter specifies either HIGH
or LOW
.
The input is of type E_PIN_STATE
. A conversion operator from E_PIN_STATE
to int
is not defined, so direct input by numeric value is not allowed.
3 - digitalRead()
Digital input function
Reads the value of a port configured as input.
static inline E_PIN_STATE digitalRead(uint8_t u8pin)
You can get the input value of a pin previously configured as input as LOW
or HIGH
.
Since the conversion operator from E_PIN_STATE
type to int
type is not defined, direct assignment to a numeric type is not possible.
4 - attachIntDio()
Function to register a DIO interrupt handler
Registers a DIO interrupt handler.
void attachIntDio(uint8_t u8pin, E_PIN_INT_MODE mode)
For a pin configured as input beforehand, the first parameter is the pin number for which you want to enable the interrupt, and the second parameter specifies the interrupt direction (rising edge, falling edge).
Descriptions of interrupt handlers and event handlers are done in
behaviors.
Example
Sets up an interrupt that triggers when the DIO5 pin changes from HIGH to LOW.
void setup() {
the_twelite.app.use<myAppClass>();
pinMode(PIN_DIGITAL::DIO5, PIN_MODE::INPUT_PULLUP);
attachIntDio(PIN_DIGITAL::DIO5, PIN_INT_MODE::FALLING);
}
void loop() {
;
}
myAppClass.hpp
class myAppClass: public mwx::BrdPal, MWX_APPDEFS_CRTP(myAppClasslMot)
{
};
Basic definition of the behavior myAppClass
. Details are omitted.
myAppClass.cpp
/*****************************************************************/
// MUST DEFINE CLASS NAME HERE
##define __MWX_APP_CLASS_NAME myAppClass
##include "_mwx_cbs_cpphead.hpp"
/*****************************************************************/
MWX_DIO_INT(PIN_DIGITAL::DIO5, uint32_t arg, uint8_t& handled) {
static uint8_t ct;
digitalWrite(PIN_DIGITAL::DIO12, (++ct & 1) ? HIGH : LOW);
handled = false; // if true, no further event.
}
MWX_DIO_EVENT(PIN_DIGITAL::DIO5, uint32_t arg) {
Serial << '*';
}
/*****************************************************************/
// common procedure (DO NOT REMOVE)
##include "_mwx_cbs_cpptail.cpp"
// MUST UNDEF CLASS NAME HERE
##undef __MWX_APP_CLASS_NAME
} // mwx
/*****************************************************************/
Interrupt handler description for the behavior myAppClass
. When an interrupt occurs on DIO5, it toggles the output setting of DIO12, and after the interrupt handler finishes, an event occurs that prints *
to the serial port Serial
.
5 - detachIntDio()
Function to unregister a DIO interrupt handler
Unregisters a DIO interrupt handler.
void detachIntDio(uint8_t u8pin)
6 - digitalReadBitmap()
Digital input function (batch)
Reads the values of the input-configured ports in batch.
Included in MWX library version 0.1.4 and later.
uint32_t digitalReadBitmap()
Values are stored in order from the LSB side: DIO0 … DIO19.
Pins on the HIGH
side are set to 1, and pins on the LOW
side are set to 0.