Browse Source

AP_IOCMU: added singleton in AP namespace

master
Andrew Tridgell 5 years ago committed by Randy Mackay
parent
commit
6d2d6d7454
  1. 13
      libraries/AP_IOMCU/AP_IOMCU.cpp
  2. 10
      libraries/AP_IOMCU/AP_IOMCU.h

13
libraries/AP_IOMCU/AP_IOMCU.cpp

@ -44,7 +44,9 @@ enum ioevents {
AP_IOMCU::AP_IOMCU(AP_HAL::UARTDriver &_uart) : AP_IOMCU::AP_IOMCU(AP_HAL::UARTDriver &_uart) :
uart(_uart) uart(_uart)
{} {
singleton = this;
}
#define IOMCU_DEBUG_ENABLE 0 #define IOMCU_DEBUG_ENABLE 0
@ -54,6 +56,8 @@ AP_IOMCU::AP_IOMCU(AP_HAL::UARTDriver &_uart) :
#define debug(fmt, args ...) #define debug(fmt, args ...)
#endif #endif
AP_IOMCU *AP_IOMCU::singleton;
/* /*
initialise library, starting thread initialise library, starting thread
*/ */
@ -999,4 +1003,11 @@ void AP_IOMCU::check_iomcu_reset(void)
trigger_event(IOEVENT_SET_DEFAULT_RATE); trigger_event(IOEVENT_SET_DEFAULT_RATE);
} }
namespace AP {
AP_IOMCU *iomcu(void) {
return AP_IOMCU::get_singleton();
}
};
#endif // HAL_WITH_IO_MCU #endif // HAL_WITH_IO_MCU

10
libraries/AP_IOMCU/AP_IOMCU.h

@ -106,6 +106,10 @@ public:
// channel group masks // channel group masks
const uint8_t ch_masks[3] = { 0x03,0x0C,0xF0 }; const uint8_t ch_masks[3] = { 0x03,0x0C,0xF0 };
static AP_IOMCU *get_singleton(void) {
return singleton;
}
private: private:
AP_HAL::UARTDriver &uart; AP_HAL::UARTDriver &uart;
@ -238,6 +242,8 @@ private:
void handle_repeated_failures(); void handle_repeated_failures();
void check_iomcu_reset(); void check_iomcu_reset();
static AP_IOMCU *singleton;
enum { enum {
PROTO_NOP = 0x00, PROTO_NOP = 0x00,
PROTO_OK = 0x10, PROTO_OK = 0x10,
@ -270,4 +276,8 @@ private:
}; };
}; };
namespace AP {
AP_IOMCU *iomcu(void);
};
#endif // HAL_WITH_IO_MCU #endif // HAL_WITH_IO_MCU

Loading…
Cancel
Save