Skip to content

Commit c9c8bf1

Browse files
authored
Merge pull request #95 from hlovdal/pgm_macros
Expand pgm_read_... macros
2 parents d716bee + eb10bee commit c9c8bf1

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212

1313
### Changed
1414
- Unit tests and examples are now executed alphabetically by filename
15+
- The `pgm_read_...` preprocessor macros in cpp/arduino/avr/pgmspace.h now expands to an expression with applicable type.
1516

1617
### Deprecated
1718

cpp/arduino/avr/pgmspace.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@ out.each { |l| puts d(l) }
2929

3030
// everything's a no-op
3131
#define PSTR(s) ((const char *)(s))
32-
#define pgm_read_byte_near(x) (x)
33-
#define pgm_read_word_near(x) (x)
34-
#define pgm_read_dword_near(x) (x)
35-
#define pgm_read_float_near(x) (x)
36-
#define pgm_read_ptr_near(x) (x)
3732

38-
#define pgm_read_byte_far(x) (x)
39-
#define pgm_read_word_far(x) (x)
40-
#define pgm_read_dword_far(x) (x)
41-
#define pgm_read_float_far(x) (x)
42-
#define pgm_read_ptr_far(x) (x)
33+
#define pgm_read_byte_near(address_short) (* (const uint8_t *) (address_short) )
34+
#define pgm_read_word_near(address_short) (* (const uint16_t *) (address_short) )
35+
#define pgm_read_dword_near(address_short) (* (const uint32_t *) (address_short) )
36+
#define pgm_read_float_near(address_short) (* (const float *) (address_short) )
37+
#define pgm_read_ptr_near(address_short) (* (const void *) (address_short) )
4338

39+
#define pgm_read_byte_far(address_long) (* (const uint8_t *) (address_long) )
40+
#define pgm_read_word_far(address_long) (* (const uint16_t *) (address_long) )
41+
#define pgm_read_dword_far(address_long) (* (const uint32_t *) (address_long) )
42+
#define pgm_read_float_far(address_long) (* (const float *) (address_long) )
43+
#define pgm_read_ptr_far(address_long) (* (const void *) (address_long) )
4444

45-
#define pgm_read_byte(addr) (*(const uint8_t *)(addr))
46-
#define pgm_read_word(x) (x)
47-
#define pgm_read_dword(x) (x)
48-
#define pgm_read_float(x) (x)
49-
#define pgm_read_ptr(x) (x)
50-
#define pgm_get_far_address(x) (x)
45+
#define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
46+
#define pgm_read_word(address_short) pgm_read_word_near(address_short)
47+
#define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
48+
#define pgm_read_float(address_short) pgm_read_float_near(address_short)
49+
#define pgm_read_ptr(address_short) pgm_read_ptr_near(address_short)
50+
51+
#define pgm_get_far_address(var) ( (uint_farptr_t) (&(var)) )
5152

5253
#define memchr_P(...) ::memchr(__VA_ARGS__)
5354
#define memcmp_P(...) ::memcmp(__VA_ARGS__)

0 commit comments

Comments
 (0)