Currently, we are developing a system that uses Raspberry Pi as a host and uses FPGA as a slave for SPI communication.
I'm thinking of developing this system in C ++ using two header files, "bcm2835.h" and "wiringPi.h".

■■ The following error message occurred while implementing the function.
Currently, as a result of running the program on Raspberry Pi, I am getting an error because I am using both "bcm2835.h" and "wiringPi.h" at the same time.

I want to achieve
Allow "bcm2835.h" and "wiringPi.h" to be used simultaneously in one program

Error message
/usr/local/include/wiringPi.h:256:21 error: conflicting types for'bcm2835_delayMicroseconds' extern void delayMicroseconds (unsigned int howLong);
/usr/local/include/bcm2835.h:1288:17: note previous declaration of'bcm2835_delayMicroseconds' was here extrn void bcm2835_delayMicroseconds (uint64_t micros);
Corresponding source code
const int spi_count_reset = 21;
int main (int argc, char ** argv) {
    pinMode (spi_count_reset, OUTPUT);
    if (! bcm2835_init ())
        return 1;
    bcm2835_spi_begin ();
    bcm2835_spi_setBitOrder (BCM2835_SPI_BIT_ORDER_MSBFIRST);// The default
    bcm2835_spi_setDataMode (BCM2835_SPI_MODE0);// The default
    bcm2835_spi_setClockDivider (BCM2835_SPI_CLOCK_DIVIDER_16);// The default
    bcm2835_spi_chipSelect (BCM2835_SPI_CS0);// The default
    bcm2835_spi_setChipSelectPolarity (BCM2835_SPI_CS0, HIGH);// the default
    uint8_t send_data = 0x23;
    int i = 0;
    digitalWrite (spi_count_reset, 1);
    digitalWrite (spi_count_reset, 0);
        uint8_t read_data = bcm2835_spi_transfer (send_data);
        // printf ("Sent to SPI: 0x% 02X. Read back from SPI: 0x% 02X. \ N", send_data, read_data);
        // if (send_data! = read_data)
          // printf ("Do you have the loopback from MOSI to MISO connected? \ N");
    bcm2835_spi_end ();
    bcm2835_close ();
    return 0;
What I tried

I updated the bcm2835.h file to a newer version (bcm2835-1.44), but the error did not go away.

Supplementary information (FW/tool version, etc.)

Raspberry Pi 3 model b +
Programming language used: C ++
Library used: WirigPi.h bcm2835.h (version 1.44)

Why i am using wiringPi.h
Because I want to use the pinMode () function, specify a GPIO pin other than the SPI dedicated pin, and send data using the digitalWrite () function.

Why i am using bcm2835.h
Because I want to communicate with SPI by freely setting the clock frequency in MSB first or MSB last with SPI.
Also, because the communication speed is slow in wiringPiSPI.h

  • Answer # 1

    If you look at bcm2835.h, in the comments

    \ version 1.10 Changed the names of the delay functions to bcm2835_delay ()
      and bcm2835_delayMicroseconds () to prevent collisions with wiring Pi.
      Macros to map delay ()->bcm2835_delay () and
      Macros to map delayMicroseconds ()->bcm2835_delayMicroseconds (), which
      can be disabled by defining BCM2835_NO_DELAY_COMPATIBILITY

    There is a passage (near line 361)
    If you look inside the sauce,

    / * Historical name compatibility * /
    #define delay (x) bcm2835_delay (x)
    #define delayMicroseconds (x) bcm2835_delayMicroseconds (x)

    That's right (near line 1161). So why not #define (or -D on the command line) BCM2835_NO_DELAY_COMPATIBILITY?

    Rewriting the header of the library is a last resort in a sense and is not a recommended response.
    Properly on the first line of the source (before including bcm2835.h)
    Add or add to the compile-time command (gcc nachara)-D BCM2835_NO_DELAY_COMPATIBILITYIs it about adding?


    Why you are using wiringPi.h

    If that's all, the bcm2835 library also contains GPIO control instructions, so I think it's a streak to use that.

    The equivalent of pinMode () is the bcm2835_gpio_fsel () function,
    The equivalent of digitalWrite () seems to be the bcm2835_gpio_write () function. It seems that bcm2835_gpio_set () and bcm2835_gpio_clr () can also be used.

    The bcm2835 library itself (I have a Raspberry Pi, but I haven't messed with it much) I haven't used it myself, so I haven't confirmed it.