I'm trying out c++ and I can't figure this one out.
I'm trying to create a driver for the MAX7219 with classes. The MAX7219 inherits a SPI class and a GPIO class, but the GPIO class is causing a lot of problems by using indirect instructions rather the SBI/CBI instructions, and even worse is that it sometimes calls the gpio functions rather inline them.
Without the MAX7219 being created the GPIO class works as intended, but once it's created everything goes out the window. Somehow the first gpio function is able to work with SBI/CBI after the GPIO object is created though.
I'm really not sure what I'm doing to cause this issue.
Some sample dissassembly code I'm getting:
GPIO(volatile uint8_t *port, const uint8_t pins) : port(port), pins(pins) 00000059 LDI R24,0x25 Load immediate 0000005A LDI R25,0x00 Load immediate 0000005B STD Y+24,R25 Store indirect with displacement 0000005C STD Y+23,R24 Store indirect with displacement 0000005D LDI R24,0x24 Load immediate 0000005E LDI R25,0x00 Load immediate 0000005F STD Y+26,R25 Store indirect with displacement 00000060 STD Y+25,R24 Store indirect with displacement 00000061 LDI R24,0x23 Load immediate 00000062 LDI R25,0x00 Load immediate 00000063 STD Y+28,R25 Store indirect with displacement 00000064 STD Y+27,R24 Store indirect with displacement 00000065 LDI R24,0x02 Load immediate 00000066 STD Y+29,R24 Store indirect with displacement *(pin) |= pins; 00000067 SBI 0x03,1 Set bit in I/O register *(port-1) |= pins; 00000068 LDD R30,Y+23 Load indirect with displacement 00000069 LDD R31,Y+24 Load indirect with displacement 0000006A LD R25,-Z Load indirect and predecrement 0000006B LDD R24,Y+29 Load indirect with displacement 0000006C OR R24,R25 Logical OR 0000006D STD Z+0,R24 Store indirect with displacement *(port) &=~ pins; 0000006E LDD R30,Y+23 Load indirect with displacement 0000006F LDD R31,Y+24 Load indirect with displacement 00000070 LDD R25,Z+0 Load indirect with displacement 00000071 LDD R24,Y+29 Load indirect with displacement 00000072 COM R24 One's complement 00000073 AND R24,R25 Logical AND 00000074 STD Z+0,R24 Store indirect with displacement *(pin) |= pins; 00000075 LDD R30,Y+27 Load indirect with displacement 00000076 LDD R31,Y+28 Load indirect with displacement 00000077 LDD R25,Z+0 Load indirect with displacement 00000078 LDD R24,Y+29 Load indirect with displacement 00000079 OR R24,R25 Logical OR 0000007A STD Z+0,R24 Store indirect with displacement