diff --git a/include/digio.h b/include/digio.h index 61fdb80..0d5ebb1 100644 --- a/include/digio.h +++ b/include/digio.h @@ -19,9 +19,15 @@ #ifndef DIGIO_H_INCLUDED #define DIGIO_H_INCLUDED + #include #include "digio_prj.h" +#if __has_include("busio.h") + #include "busio.h" + #define BUSIO_ENABLED +#endif + namespace PinMode { enum PinMode { @@ -39,12 +45,22 @@ namespace PinMode { }; } + class DigIo { public: - #define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name; - DIG_IO_LIST - #undef DIG_IO_ENTRY + #define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name; + +#ifdef BUSIO_ENABLED + #define BUS_IO_ENTRY(name, type, channel, mode) static BusIo name; +#endif + + DIG_IO_LIST // expands all real & MCP pins into static members + #undef DIG_IO_ENTRY + +#ifdef BUSIO_ENABLED + #undef BUS_IO_ENTRY +#endif /** Map GPIO pin object to hardware pin. * @param[in] port port to use for this pin @@ -54,7 +70,6 @@ class DigIo */ void Configure(uint32_t port, uint16_t pin, PinMode::PinMode pinMode); - /** * Get pin value * @@ -89,8 +104,14 @@ class DigIo uint16_t _pin; bool _invert; }; -//Configure all digio objects from the given list + +//Configure all digio and (optionally busio) objects from the given list #define DIG_IO_ENTRY(name, port, pin, mode) DigIo::name.Configure(port, pin, mode); + +#ifdef BUSIO_ENABLED +#define BUS_IO_ENTRY(name, busType, channel, mode) DigIo::name.Configure(busType, channel, mode); +#endif + #define DIG_IO_CONFIGURE(l) l #endif // DIGIO_H_INCLUDED diff --git a/src/digio.cpp b/src/digio.cpp index 3af5ebb..5f7f580 100644 --- a/src/digio.cpp +++ b/src/digio.cpp @@ -25,6 +25,12 @@ #undef DIG_IO_ENTRY #define DIG_IO_ENTRY(name, port, pin, mode) DigIo DigIo::name; + +#ifdef BUSIO_ENABLED +#undef BUS_IO_ENTRY +#define BUS_IO_ENTRY(name, busType, channel, mode) BusIo DigIo::name; +#endif + DIG_IO_LIST void DigIo::Configure(uint32_t port, uint16_t pin, PinMode::PinMode pinMode)