What is Spi *spi; ?

I was thinking of creating a separate library (USPI) for using the Due's USART0 and USART1 in SPI mode. The idea would be to replicate the way the SPI and extended SPI functions are used (same syntax).

After attaching USPI.h, the user would gain the use of pins 54 and 70 for CS. The setup would look something like this:

USPI.begin(54);
USPI.setClockDivider(54, 21);

In my efforts to create a similar header file, I've found a few things about the original SPI library that are unique to other libraries.

  1. The SPI library is installed in a different folder. If this folder is renamed, the IDE continues to recognize it as SPI but will use the header file(s) within the renamed folder.

  2. The SPI library seems dependent on functions internal to the IDE.

I started with a "clean" slate by creating a new simple header file with similar class names, but prefixed with "U". In its simplest form, what I've found is ...

This compiles:

#ifndef _USPI_H_INCLUDED
#define _USPI_H_INCLUDED
#include "variant.h"

class USPIClass {
  public:
 USPIClass(Spi *_spi);
  private:
  Spi *spi;
};
#endif

This does not:

#ifndef _USPI_H_INCLUDED
#define _USPI_H_INCLUDED
#include "variant.h"

class USPIClass {
  public:
 USPIClass(USpi *_uspi);
  private:
  USpi *uspi;
};
#endif

Note that for the above spi.cpp and spi.c were deleted.

So what is "Spi *spi;"? A handle to some internal function?

USpi *uspi;

declares a pointer to a USpi object.

When the class is initialized it gets a USPI object as parameter, but in fact it gets the address of the object.’

Thank you robtillaart, this is what I thought.

Creating a class like this is beyond my experience level with C, however I'm still wondering why with everything SPI related being deleted (spi.h, spi.c, spi.cpp) that Spi *spi; will compile, my version (using uspi.h) with USpi *uspi; will not. (I'll have to research some more on how object oriented code works in C).

Right now, I'm guessing that the main purpose of using the pointer is to get the initialized spi channel number.