From 6d2d6d745421bd8d1cbaf26f05e92fd80098af19 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 2 Nov 2019 13:32:48 +1100 Subject: [PATCH] AP_IOCMU: added singleton in AP namespace --- libraries/AP_IOMCU/AP_IOMCU.cpp | 13 ++++++++++++- libraries/AP_IOMCU/AP_IOMCU.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index cf5b965364..399eb302e1 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -44,7 +44,9 @@ enum ioevents { AP_IOMCU::AP_IOMCU(AP_HAL::UARTDriver &_uart) : uart(_uart) -{} +{ + singleton = this; +} #define IOMCU_DEBUG_ENABLE 0 @@ -54,6 +56,8 @@ AP_IOMCU::AP_IOMCU(AP_HAL::UARTDriver &_uart) : #define debug(fmt, args ...) #endif +AP_IOMCU *AP_IOMCU::singleton; + /* initialise library, starting thread */ @@ -999,4 +1003,11 @@ void AP_IOMCU::check_iomcu_reset(void) trigger_event(IOEVENT_SET_DEFAULT_RATE); } + +namespace AP { + AP_IOMCU *iomcu(void) { + return AP_IOMCU::get_singleton(); + } +}; + #endif // HAL_WITH_IO_MCU diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index 06b745decb..b74c8aec04 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -106,6 +106,10 @@ public: // channel group masks const uint8_t ch_masks[3] = { 0x03,0x0C,0xF0 }; + static AP_IOMCU *get_singleton(void) { + return singleton; + } + private: AP_HAL::UARTDriver &uart; @@ -238,6 +242,8 @@ private: void handle_repeated_failures(); void check_iomcu_reset(); + static AP_IOMCU *singleton; + enum { PROTO_NOP = 0x00, PROTO_OK = 0x10, @@ -270,4 +276,8 @@ private: }; }; +namespace AP { + AP_IOMCU *iomcu(void); +}; + #endif // HAL_WITH_IO_MCU