Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
progmem.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 
5 #ifdef __AVR__
6 #include <avr/pgmspace.h>
7 #else
8 #define PROGMEM // ignored
9 #endif
10 
11 namespace hal {
12 
14 namespace progmem {
15 
17 static inline uint16_t read_word(const uint16_t *addr) {
18 #ifndef __AVR__
19  return *addr;
20 #else
21  return (uint16_t)pgm_read_word(addr);
22 #endif
23 }
24 
26 static inline uint8_t read_byte(const uint8_t *addr) {
27 #ifndef __AVR__
28  return *addr;
29 #else
30  return (uint8_t)pgm_read_byte(addr);
31 #endif
32 }
33 
38 template <typename RT>
39 static inline RT read_ptr(const void *addr) {
40 #ifndef __AVR__
41  return reinterpret_cast<RT>(*reinterpret_cast<const uint64_t *>(addr));
42 #else
43  return reinterpret_cast<RT>(pgm_read_ptr(addr));
44 #endif
45 }
46 
47 } // namespace progmem
48 } // namespace hal
static RT read_ptr(const void *addr)
Definition: progmem.h:39
static uint8_t read_byte(const uint8_t *addr)
read a 8bit byte from PROGMEM
Definition: progmem.h:26
static uint16_t read_word(const uint16_t *addr)
read a 16bit word from PROGMEM
Definition: progmem.h:17