mirror of https://github.com/ArduPilot/ardupilot
added pgm_read_pointer()
this will be used by the menu code to make reading pointers from progmem portable
This commit is contained in:
parent
469b8586ca
commit
d78bbb1a40
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue