API for DIO (General-purpose digital IO)
The following functions are used for general-purpose digital IO (DIO) operations.
pinMode()
digitalWrite()
digitalRead()
attachIntDio()
detachIntDio()
const uint8_t PIN_DIGITAL::DIO0 .. 19
DIO pins 0 to 19
const uint8_t PIN_DIGITAL::DO0 .. 1
DO pin 0,1
The following enumeration values are handled with the type name E_PIN_MODE
.
PIN_MODE::INPUT
None
Input
PIN_MODE::OUTPUT
None
Output
PIN_MODE::INPUT_PULLUP
Yes
Input
PIN_MODE::OUTPUT_INIT_HIGH
None
Output(init HIGH)
PIN_MODE::OUTPUT_INIT_LOW
None
Output(init LOW)
PIN_MODE::WAKE_FALLING
None
Input, raised pin, falling
PIN_MODE::WAKE_RISING
None
Input, rising pin, rising
PIN_MODE::WAKE_FALLING_PULLUP
Yes
Input, raised pin, falling
PIN_MODE::WAKE_RISING_PULLUP
Yes
Input, rising pin, rising
PIN_MODE::DISABLE_OUTPUT
Yes
return to the input state
The following enumeration values are handled with the type name E_PIN_MODE
.
PIN_MODE::OUTPUT
Contribute
PIN_MODE::OUTPUT_INIT_HIGH
Output (initial state HIGH)
PIN_MODE::OUTPUT_INIT_LOW
Output (initial state LOW)
PIN_MODE::DISABLE_OUTPUT
Stop setting output
The following enumeration values are handled with the type name E_PIN_STATE
.
PIN_STATE::HIGH
1
HIGH(=Vcc) level
PIN_STATE::LOW
0
LOW(=GND) level
The following enumeration values are handled with the type name E_PIN_INT_MODE
.
PIN_INT_MODE::FALLING
falling edge
PIN_INT_MODE::RISING
rising edge
Sets the DIO (general-purpose digital IO) pin.
Sets the DIO (general-purpose digital IO) pin.
void pinMode(uint8_t u8pin, E_PIN_MODE mode)
This function allows you to change the state of DIO0..19 and the pins DO0,1. The setting contents are described in the enumeration value of E_PIN_MODE
, description of DIO and Description of DO.
DO0,1 are special pins, which in principle are used for other purposes, but can also be configured as outputs. However, these pins have hardware restrictions, so care must be taken when using them.
Both pins must be guaranteed to be at a HIGH level when power is applied. If the circuit is configured to take unstable voltages, the module will not start up.
Change the setting of the digital output pins.
Change the setting of the digital output pins.
static inline void digitalWrite(uint8_t u8pin, E_PIN_STATE ulVal)
The first parameter specifies the pin number to be set, and the second parameter specifies either HIGH
or LOW
.
Reads the value of the port of the input configuration.
Reads the value of the port of the input configuration.
static inline E_PIN_STATE digitalRead(uint8_t u8pin)
Get the input value of a pin that has been previously set as an input, either LOW
or HIGH
.
to enable DIO interrupt.
Enables DIO interrupts.
void attachIntDio(uint8_t u8pin, E_PIN_INT_MODE mode)
For a preconfigured pin, the first parameter is the pin number for which you want to enable interrupts, the second is the interrupt direction (rising, falling.
Set up an interrupt to be generated 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() {
;
}
class myAppClass: public mwx::BrdPal, MWX_APPDEFS_CRTP(myAppClasslMot)
{
};
Basic definition of the application behavior myAppClass
. Details are omitted.
/*****************************************************************/
// 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
/*****************************************************************/
Description of the interrupt handler of the application behavior myAppClass
, which inverts the output setting of DIO12 when an interrupt of DIO5 is generated and displays *
on the serial port Serial
for events occurring after the interrupt handler is finished.
to unregister the interrupt handler.
Unregisters the interrupt handler.
void detachIntDio(uint8_t u8pin)
Reads the values of all ports in the input settings at once.
Included in mwx library 0.1.4 or later
Reads the values of all ports in the input settings at once.
uint32_t digitalReadBitmap()
The values are stored in the order of DIO0 ... DIO19 from the LSB side. DIO19 are stored in this order.
The pins on the HIGH side are set to 1 and the pins on the LOW side are set to 0.