diff --git a/libraries/AP_HAL/AP_HAL_Namespace.h b/libraries/AP_HAL/AP_HAL_Namespace.h index 7c62a191f7..e224339f89 100644 --- a/libraries/AP_HAL/AP_HAL_Namespace.h +++ b/libraries/AP_HAL/AP_HAL_Namespace.h @@ -2,9 +2,31 @@ #ifndef __AP_HAL_NAMESPACE_H__ #define __AP_HAL_NAMESPACE_H__ + #include "string.h" #include "utility/FastDelegate.h" +#if defined(__AVR__) +/* + gcc on AVR doesn't allow for delegates in progmem. It gives a + warning that the progmem area is uninitialised, and fills the area + with zeros. This is a workaround. + */ +#define DELEGATE_FUNCTION_VOID_TYPEDEF(type) typedef void (*type)(const void *) +#define AP_HAL_CLASSPROC_VOID(classptr, func) (void (*)(const void*))func +#else +#define DELEGATE_FUNCTION_VOID_TYPEDEF(type) typedef fastdelegate::FastDelegate0 type +#define AP_HAL_CLASSPROC_VOID(classptr, func) fastdelegate::MakeDelegate(classptr, func) +#endif + +// macros to hide the details of delegate functions using FastDelegate +#define AP_HAL_CLASSPROC(classptr, func) fastdelegate::MakeDelegate(classptr, func) +#define AP_HAL_MEMBERPROC(func) AP_HAL_CLASSPROC(this, func) + +#define DELEGATE_FUNCTION0(rettype) fastdelegate::FastDelegate0 +#define DELEGATE_FUNCTION1(rettype, args...) fastdelegate::FastDelegate1 +#define DELEGATE_FUNCTION2(rettype, args...) fastdelegate::FastDelegate2 + namespace AP_HAL { /* Toplevel pure virtual class Hal.*/ @@ -40,7 +62,7 @@ namespace AP_HAL { which allows us to encapculate a member function as a type */ typedef void(*Proc)(void); - typedef fastdelegate::FastDelegate0<> MemberProc; + typedef DELEGATE_FUNCTION0(void) MemberProc; /** * Global names for all of the existing SPI devices on all platforms. @@ -63,7 +85,4 @@ namespace AP_HAL { } -// macro to hide the details of AP_HAL::MemberProc -#define AP_HAL_MEMBERPROC(func) fastdelegate::MakeDelegate(this, func) - #endif // __AP_HAL_NAMESPACE_H__