Compare commits

...

2 Commits

Author SHA1 Message Date
d991959bff Fixed workaround with correct macro 2019-08-15 17:37:13 +02:00
1265702325 Changed git ignore to ignore make output 2019-08-11 10:03:47 +02:00
2 changed files with 21 additions and 19 deletions

7
.gitignore vendored
View File

@@ -2,3 +2,10 @@
Release
Debug
*.componentinfo.xml
*.elf
*.o
*.hex
*.srec
*.eeprom
*.lss
*.map

33
io.hpp
View File

@@ -131,16 +131,13 @@ The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are no
constexpr auto *foo = ptr;
Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site
For this to work we need to temporarily disable the _SFR_IO8 macro so that the register macro just gives the address
For this the sfr_defs.h provides a macro which returns the address of a register
*/
#undef _SFR_IO8
#define _SFR_IO8
#ifdef PORT_A_AVAILABLE
static constexpr uintptr_t PORT_A_DIR_REG_ADDR = DDRA + __SFR_OFFSET;
static constexpr uintptr_t PORT_A_OUTPUT_REG_ADDR = PORTA + __SFR_OFFSET;
static constexpr uintptr_t PORT_A_INPUT_REG_ADDR = PINA + __SFR_OFFSET;
static constexpr uintptr_t PORT_A_DIR_REG_ADDR = _SFR_ADDR(DDRA);
static constexpr uintptr_t PORT_A_OUTPUT_REG_ADDR = _SFR_ADDR(PORTA);
static constexpr uintptr_t PORT_A_INPUT_REG_ADDR = _SFR_ADDR(PINA);
#else
static constexpr uintptr_t PORT_A_DIR_REG_ADDR = 0;
static constexpr uintptr_t PORT_A_OUTPUT_REG_ADDR = 0;
@@ -148,9 +145,10 @@ static constexpr uintptr_t PORT_A_INPUT_REG_ADDR = 0;
#endif
#ifdef PORT_B_AVAILABLE
static constexpr uintptr_t PORT_B_DIR_REG_ADDR = DDRB + __SFR_OFFSET;
static constexpr uintptr_t PORT_B_OUTPUT_REG_ADDR = PORTB + __SFR_OFFSET;
static constexpr uintptr_t PORT_B_INPUT_REG_ADDR = PINB + __SFR_OFFSET;
static constexpr uintptr_t PORT_B_DIR_REG_ADDR = _SFR_ADDR(DDRB);
static constexpr uintptr_t PORT_B_OUTPUT_REG_ADDR = _SFR_ADDR(PORTB);
static constexpr uintptr_t PORT_B_INPUT_REG_ADDR = _SFR_ADDR(PINB);
#else
static constexpr uintptr_t PORT_B_DIR_REG_ADDR = 0;
static constexpr uintptr_t PORT_B_OUTPUT_REG_ADDR = 0;
@@ -158,9 +156,9 @@ static constexpr uintptr_t PORT_B_INPUT_REG_ADDR = 0;
#endif
#ifdef PORT_C_AVAILABLE
static constexpr uintptr_t PORT_C_DIR_REG_ADDR = DDRC + __SFR_OFFSET;
static constexpr uintptr_t PORT_C_OUTPUT_REG_ADDR = PORTC + __SFR_OFFSET;
static constexpr uintptr_t PORT_C_INPUT_REG_ADDR = PINC + __SFR_OFFSET;
static constexpr uintptr_t PORT_C_DIR_REG_ADDR = _SFR_ADDR(DDRC);
static constexpr uintptr_t PORT_C_OUTPUT_REG_ADDR = _SFR_ADDR(PORTC);
static constexpr uintptr_t PORT_C_INPUT_REG_ADDR = _SFR_ADDR(PINC);
#else
static constexpr uintptr_t PORT_C_DIR_REG_ADDR = 0;
static constexpr uintptr_t PORT_C_OUTPUT_REG_ADDR = 0;
@@ -168,18 +166,15 @@ static constexpr uintptr_t PORT_C_INPUT_REG_ADDR = 0;
#endif
#ifdef PORT_D_AVAILABLE
static constexpr uintptr_t PORT_D_DIR_REG_ADDR = DDRD + __SFR_OFFSET;
static constexpr uintptr_t PORT_D_OUTPUT_REG_ADDR = PORTD + __SFR_OFFSET;
static constexpr uintptr_t PORT_D_INPUT_REG_ADDR = PIND + __SFR_OFFSET;
static constexpr uintptr_t PORT_D_DIR_REG_ADDR = _SFR_ADDR(DDRD);
static constexpr uintptr_t PORT_D_OUTPUT_REG_ADDR = _SFR_ADDR(PORTD);
static constexpr uintptr_t PORT_D_INPUT_REG_ADDR = _SFR_ADDR(PIND);
#else
static constexpr uintptr_t PORT_D_DIR_REG_ADDR = 0;
static constexpr uintptr_t PORT_D_OUTPUT_REG_ADDR = 0;
static constexpr uintptr_t PORT_D_INPUT_REG_ADDR = 0;
#endif
#undef _SFR_IO8
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
static constexpr auto getBus(const P pin)
{
// Upper 4 bits of pin encode which port this pin is on