libClearCore/src/SerialBase.cpp
int32_t SerialBase::SpiTransferData(
    uint8_t const *writeBuf, uint8_t *readBuf, int32_t len) {
    if (!m_portOpen || m_portMode != SPI) {
        return 0;
    }

    int32_t iChar;
    for (iChar = 0; iChar < len; iChar++) {
        // Write data into Data register
        m_serPort->SPI.DATA.bit.DATA = writeBuf ? *writeBuf++ : 0;

        while (!m_serPort->SPI.INTFLAG.bit.RXC ||
                !m_serPort->SPI.INTFLAG.bit.TXC) {
            // If the port is not open, bail out
            if (!m_portOpen) {
                return iChar;
            }
            // Wait for it to complete
            continue;
        }

        if (readBuf) {
            *readBuf++ = m_serPort->SPI.DATA.bit.DATA;
        }
        else {
            // Read from the register (value unused).
            (void)m_serPort->SPI.DATA.bit.DATA;
        }
    }

    return iChar;
}
/**
    SPI's multi-byte TX and RX function
**/
SPI's multi-byte TX and RX function
SPI ' s multi - byte TX and RX function
int32_t SerialBase::SpiTransferData(
    uint8_t const *writeBuf, uint8_t *readBuf, int32_t len) {
    if (!m_portOpen || m_portMode != SPI) {
        return 0;
    }
    int32_t iChar;
    for (iChar = 0; iChar < len; iChar++) {
        m_serPort->SPI.DATA.bit.DATA = writeBuf ? *writeBuf++ : 0;
        while (!m_serPort->SPI.INTFLAG.bit.RXC ||
                !m_serPort->SPI.INTFLAG.bit.TXC) {
            if (!m_portOpen) {
                return iChar;
            }
            continue;
        }
        if (readBuf) {
            *readBuf++ = m_serPort->SPI.DATA.bit.DATA;
        }
        else {
            (void)m_serPort->SPI.DATA.bit.DATA;
        }
    }
    return iChar;
}
int32_t SerialBase :: SpiTransferData ( uint8_t const * writeBuf , uint8_t * readBuf , int32_t len ) { if ( ! m_portOpen || m_portMode != SPI ) { return 0 ; } int32_t iChar ; for ( iChar = 0 ; iChar < len ; iChar ++ ) { m_serPort -> SPI . DATA . bit . DATA = writeBuf ? * writeBuf ++ : 0 ; while ( ! m_serPort -> SPI . INTFLAG . bit . RXC || ! m_serPort -> SPI . INTFLAG . bit . TXC ) { if ( ! m_portOpen ) { return iChar ; } continue ; } if ( readBuf ) { * readBuf ++ = m_serPort -> SPI . DATA . bit . DATA ; } else { ( void ) m_serPort -> SPI . DATA . bit . DATA ; } } return iChar ; }
SPI's multi-byte TX and RX function
SPI ' s multi - byte TX and RX function
// Write data into Data register // If the port is not open, bail out // Wait for it to complete // Read from the register (value unused).