In the SPI library, where is hardware() and port() defined?

ahebert

Member
I am learning how to do low-level pin configurations (SRE and DSE) on a Teensy3.5, and I looked at the SPI library for clues:

From SPI.cpp
C++:
void SPIClass::begin()
{
    volatile uint32_t *reg;

    hardware().clock_gate_register |= hardware().clock_gate_mask;
    port().MCR = SPI_MCR_MDIS | SPI_MCR_HALT | SPI_MCR_PCSIS(0x1F);
    port().CTAR0 = SPI_CTAR_FMSZ(7) | SPI_CTAR_PBR(0) | SPI_CTAR_BR(1) | SPI_CTAR_CSSCK(1);
    port().CTAR1 = SPI_CTAR_FMSZ(15) | SPI_CTAR_PBR(0) | SPI_CTAR_BR(1) | SPI_CTAR_CSSCK(1);
    port().MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(0x1F);
    reg = portConfigRegister(hardware().mosi_pin[mosi_pin_index]);
    *reg = hardware().mosi_mux[mosi_pin_index];
    reg = portConfigRegister(hardware().miso_pin[miso_pin_index]);
    *reg= hardware().miso_mux[miso_pin_index];
    reg = portConfigRegister(hardware().sck_pin[sck_pin_index]);
    *reg = hardware().sck_mux[sck_pin_index];
}

My question is, where are the functions or macros defined for hardware() and port() as called in the code above? I am struggling to understand precisely what they do. I looked in the SPI library and the Teensy core source code but I didn't see their definitions anywhere.
 
They are defined in the SPI class For example in

C++:
private:
    IMXRT_LPSPI_t & port() { return *(IMXRT_LPSPI_t *)port_addr; }
    const SPI_Hardware_t & hardware() { return *(const SPI_Hardware_t *)hardware_addr; }

They are used to map the values that are passed in through the constructors to the hardware structure and the pointer to the registers, in
such a way that the constructors can be marked as constexpr. Such that you don't run into the issue about what order are the constructors called in.
 
Back
Top