AP_IOCMU: added singleton in AP namespace

This commit is contained in:
Andrew Tridgell 2019-11-02 13:32:48 +11:00
parent 64aae4f67e
commit a11f2b5cfb
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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