Esempio n. 1
0
void TM_ILI9341_SendCommand(uint8_t data)
{
	ILI9341_WRX_RESET;
	ILI9341_CS_RESET;
	//TM_SPI_Send(ILI9341_SPI, data);
	SPI_Transfer(data);
	ILI9341_CS_SET;
}
Esempio n. 2
0
/***********************************************************************
DESC:  Sends command and argument to SPI
INPUT: one byte command number and 4 byte argument
RETURNS: one byte error status (NO_ERRORS, SPI_ERROR, ILLEGAL_COMMAND)
CAUTION: 
************************************************************************/
uint8 send_command(uint8 command, uint32 argument)
{
	uint8 SPI_send, return_val;
	uint16 SPI_return;
	return_val = NO_ERRORS;
	if(command < 64) // less than 7 bits
	{
		/********
		 * Byte 1
		 ********/
		SPI_send = command | 0x40;
		SPI_return = SPI_Transfer(SPI_send);

		/********
		 * Byte 2
		 ********/
		if((SPI_return & 0xF000) == 0) // Check errors, 0 means no errors
		{
			SPI_send = argument >> 24; // MSB of argument
			SPI_return = SPI_Transfer(SPI_send);
		}
static void TimerTick()
{
	SPI_Transfer(&spiConfig, commandBuffer, replyBuffer, 3);
}
/*---------------------------------------------------------------------------*
 * Routine:  GainSpan_SPI_Update
 *---------------------------------------------------------------------------*
 * Description:
 *      Update the state of the GainSpan SPI driver.  It first determines
 *      if any data has just been received and if so, processes it.
 *      If SPI is not busy (and a transfer is no longer active), the
 *      outgoing FIFO is checked to see if bytes can be sent out over
 *      SPI.  If so, those bytes are scheduled to send out.
 *      If no bytes are to be sent, but the module has data to send us,
 *      we'll put an IDLE character in the FIFO and request for more
 *      to come in.
 * Inputs:
 *      void
 * Outputs:
 *      void
 *---------------------------------------------------------------------------*/
void GainSpan_SPI_Update(uint8_t channel)
{
    uint16_t numBytes;

    /* Process any incoming bytes that were just sent */
    if (G_GainSpan_SPI_IsTransferComplete) {
        G_GainSpan_SPI_IsTransferComplete = false;
        GainSpan_SPI_ProcessIncoming();
        G_GainSpan_SPI_IsTransferActive = false;
    } else {
        /* Is the SPI bus busy? We cannot start a transfer until it is free. */
        if ((!SPI_IsBusy(channel)) && (!G_GainSpan_SPI_IsTransferActive)) {
            /* The SPI bus is now free to start another transfer */
            /* Try to send more data */
            /* Are we allowed to send data? (XON/XOFF) */
            if (G_GainSpan_SPI_CanTransmit) {
                /* Is there more data to send? */
                if (G_GainSpan_SPI_TXIn != G_GainSpan_SPI_TXOut) {
                    /* There is data to send, how many contiguous bytes can we send */
#if 0
                    if (G_GainSpan_SPI_TXIn > G_GainSpan_SPI_TXOut) {
                        numBytes = G_GainSpan_SPI_TXIn - G_GainSpan_SPI_TXOut;
                    } else {
                        numBytes = GAINSPAN_SPI_TX_BUFFER_SIZE
                                - G_GainSpan_SPI_TXOut;
                    }
#endif

                    // NOTE: the module wants only 1 byte per chip select cycle
                    numBytes = 1;

                    /* Remember how many bytes were sent in this transfer so */
                    /* the returned bytes can be processed later */
                    G_GainSpan_SPI_NumSent = numBytes;
                    G_GainSpan_SPI_IsTransferActive = true;

                    /* Tell the SPI to send out this group of characters */
                    SPI_Transfer(GAINSPAN_SPI_CHANNEL, numBytes,
                            G_GainSpan_SPI_TXBuffer + G_GainSpan_SPI_TXOut,
                            G_GainSpan_SPI_TXBuffer + G_GainSpan_SPI_TXOut,
                            IGainSpan_SPI_TransferComplete);
                    //MSTimerDelay(1);
                } else {
                    /* Nothing is being sent currently. */
                    /* Is the GainSpan module ready with data to return?  If so, send an IDLE character */
                    /* to start feeding out the data */
                    if (GainSpan_SPI_IsDataReady(GAINSPAN_SPI_CHANNEL)) {
                        GainSpan_SPI_SendByteLowLevel(GAINSPAN_SPI_CHAR_IDLE);
                    }
                }
            } else {
                /* XON is active.  We can send IDLE characters when data is ready */
                if (GainSpan_SPI_IsDataReady(GAINSPAN_SPI_CHANNEL)) {
                    // Send an IDLE character to look for the XON/XOFF */
                    G_GainSpan_SPI_XONIdleChar = GAINSPAN_SPI_CHAR_IDLE;
                    // No bytes from the buffer are being sent
                    G_GainSpan_SPI_NumSent = 0;
                    G_GainSpan_SPI_IsTransferActive = true;
                    SPI_Transfer(GAINSPAN_SPI_CHANNEL, 1,
                            &G_GainSpan_SPI_XONIdleChar,
                            &G_GainSpan_SPI_XONIdleChar,
                            IGainSpan_SPI_TransferComplete);
                }
            }
        }
    }
}