From 152da9c91bad4680d34fde8f0fc27e7d89bbd14b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 7 Nov 2011 20:50:19 +1100 Subject: [PATCH] added pgm_read_pointer() this will be used by the menu code to make reading pointers from progmem portable --- libraries/AP_Common/AP_Common.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index 370cb53e25..71c2f112e1 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -110,6 +110,26 @@ static inline size_t strlcat_P(char *buffer, const prog_char_t *pstr, size_t buf return strlcat_P(buffer, (const prog_char *)pstr, buffer_size); } + +// read something the size of a pointer. This makes the menu code more +// portable +static inline uintptr_t pgm_read_pointer(const void *s) +{ + if (sizeof(uintptr_t) == sizeof(uint16_t)) { + return (uintptr_t)pgm_read_word(s); + } else { + union { + uintptr_t p; + uint8_t a[sizeof(uintptr_t)]; + } u; + uint8_t i; + for (i=0; i< sizeof(uintptr_t); i++) { + u.a[i] = pgm_read_byte(i + (const prog_char *)s); + } + return u.p; + } +} + //@}