This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Preprocessor gurus help requested!

Hello preprocessor masters/gurus,

I am trying to make a piece of software as easily configurable as possible, by only indicting which port/pin combination controls the hardware:

// SPI master/slave arbitration
#define SPI_MASTER_IO_PORT                      0
#define SPI_MASTER_IO_PIN                       19

#define FIO_PORT_PIN(x)                         FIO##x##PIN

#define SPI_MASTER_REQUEST_IO_BIT_STATUS          ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)>>SPI_MASTER_IO_PIN)&1)

The result I want is this:

((FIO0PIN>>19)&1)

but this yields the following error message:

..\src\spi.c(341): error:  #20: identifier "FIOSPI_MASTER_IO_PORTCLR" is undefined</ptr>

Are there ways around the apparent failure of the double replacement required here...?

Thanks in advance


Parents
  • So the final macros look like this:

    // SPI master/slave arbitration
    #define SPI_MASTER_IO_PORT                      0
    #define SPI_MASTER_IO_PIN                       19
    
    #define SPI_MASTER_DISPLAY_PORT         0
    #define SPI_MASTER_DISPLAY_PIN          5
    
    #define FIO_PORT_PIN_TEMP(x)            FIO##x##PIN
    #define FIO_PORT_PIN(x)                         FIO_PORT_PIN_TEMP(x)
    #define FIO_PORT_CLR_TEMP(x)            FIO##x##CLR
    #define FIO_PORT_CLR(x)                         FIO_PORT_CLR_TEMP(x)
    #define FIO_PORT_SET_TEMP(x)            FIO##x##SET
    #define FIO_PORT_SET(x)                         FIO_PORT_SET_TEMP(x)
    
    #define SPI_MASTER_REQUEST_IO_IS_MASTER                   ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)>>SPI_MASTER_IO_PIN)&1) == 0)
    #define SPI_MASTER_REQUEST_IO_NOT_MASTER                  ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)>>SPI_MASTER_IO_PIN)&1) == 1)
    #define SPI_MASTER_REQUEST_IO_BIT_SET                     FIO_PORT_CLR(SPI_MASTER_IO_PORT) |= (1<<SPI_MASTER_IO_PIN) ;
    #define SPI_MASTER_REQUEST_IO_BIT_RESET                   FIO_PORT_SET(SPI_MASTER_IO_PORT) |= (1<<SPI_MASTER_IO_PIN) ;
    
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_IS_MASTER  ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)>>SPI_MASTER_DISPLAY_PIN)&1) == 0)
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_NOT_MASTER ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)>>SPI_MASTER_DISPLAY_PIN)&1) == 1)
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_SET        FIO_PORT_CLR(SPI_MASTER_DISPLAY_PORT) |= (1<<SPI_MASTER_DISPLAY_PIN) ;
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_RESET      FIO_PORT_SET(SPI_MASTER_DISPLAY_PORT) |= (1<<SPI_MASTER_DISPLAY_PIN) ;
    

Reply
  • So the final macros look like this:

    // SPI master/slave arbitration
    #define SPI_MASTER_IO_PORT                      0
    #define SPI_MASTER_IO_PIN                       19
    
    #define SPI_MASTER_DISPLAY_PORT         0
    #define SPI_MASTER_DISPLAY_PIN          5
    
    #define FIO_PORT_PIN_TEMP(x)            FIO##x##PIN
    #define FIO_PORT_PIN(x)                         FIO_PORT_PIN_TEMP(x)
    #define FIO_PORT_CLR_TEMP(x)            FIO##x##CLR
    #define FIO_PORT_CLR(x)                         FIO_PORT_CLR_TEMP(x)
    #define FIO_PORT_SET_TEMP(x)            FIO##x##SET
    #define FIO_PORT_SET(x)                         FIO_PORT_SET_TEMP(x)
    
    #define SPI_MASTER_REQUEST_IO_IS_MASTER                   ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)>>SPI_MASTER_IO_PIN)&1) == 0)
    #define SPI_MASTER_REQUEST_IO_NOT_MASTER                  ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)>>SPI_MASTER_IO_PIN)&1) == 1)
    #define SPI_MASTER_REQUEST_IO_BIT_SET                     FIO_PORT_CLR(SPI_MASTER_IO_PORT) |= (1<<SPI_MASTER_IO_PIN) ;
    #define SPI_MASTER_REQUEST_IO_BIT_RESET                   FIO_PORT_SET(SPI_MASTER_IO_PORT) |= (1<<SPI_MASTER_IO_PIN) ;
    
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_IS_MASTER  ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)>>SPI_MASTER_DISPLAY_PIN)&1) == 0)
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_NOT_MASTER ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)>>SPI_MASTER_DISPLAY_PIN)&1) == 1)
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_SET        FIO_PORT_CLR(SPI_MASTER_DISPLAY_PORT) |= (1<<SPI_MASTER_DISPLAY_PIN) ;
    #define SPI_MASTER_REQUEST_DISPLAY_BIT_RESET      FIO_PORT_SET(SPI_MASTER_DISPLAY_PORT) |= (1<<SPI_MASTER_DISPLAY_PIN) ;
    

Children
No data