I'm trying to set a library in C++ for AVR. The idea is to have an easy way of configuring what pins you use on each device. This is the library:
class PINS{
public:
//ATTRIBUTES
uint8_t* DDRaddr;
uint8_t* PORTaddr;
uint8_t* PINaddr;
int pinnum;
//METHODS
void usepin(volatile uint8_t *pin, int num);};
void PINS::usepin(volatile uint8_t *pin, int num){
this->pinnum=num;
if(pin==&PORTB){
this->DDRaddr=&DDRB;
this->PINaddr=&PINB;
this->PORTaddr=&PORTB;}
if(pin==&PORTC){
this->DDRaddr=&DDRC;
this->PINaddr=&PINC;
this->PORTaddr=&PORTC;}
if(pin==&PORTD){
this->DDRaddr=&DDRD;
this->PINaddr=&PIND;
this->PORTaddr=&PORTD;}
return;}
And this is what calls for it:
PINS RS;
RS.usepin(&PORTC, 0);
Now this is how I thought it would work:
- Write e.g. "PINS RS;" to create an instance of class PINS; a new pin with the name RS.
- Write "RS.usepin(PORTB,0);" to configure RS pin to PORTB0 of MCU.
- Use RS.DDRaddr for DDR, RS.PINaddr for PIN and RS.PORTaddr for PORT register
- Use RS.pinnum for the pin number; eg: RS.DDRaddr|=(1<
When I try to build it in Atmel Studio I have the following error for every line like this: "this->DDRaddr=&DDRB;" The error says:
Error 1 invalid conversion from volatile uint8_t* to uint8_t*
It used to work before I made uint8_t* DDRaddr a class member. I can't understand what is the problem, i couldn't make a conclusion from similar - but yet not quite the same - questions. Is there anyone who could have an idea of what is wrong with this specific code?