⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi_driver.c

📁 Samsung S65 LCD Library
💻 C
字号:
/* Mark de Jong Electronics (c) 2005
*
* Project: SPI Driver
*
* Filename: SPI_driver.c
*
*
*/
#ifdef TARGET_C164CI
#include <C164CXSX.H>
#endif

#ifdef TARGET_MM167
#include <C167CS.H>
#endif

#include <stdio.h>
#include <string.h>

#include "SPI_driver_if.h"

struct
{
	unsigned int mode;
	unsigned int busy;
	unsigned int counter;
	unsigned int *word_pointer;
	unsigned char *byte_pointer;
}spi_info;

void SPI_driver_init( unsigned int mode )
{
	memset( &spi_info, 0x00, sizeof(spi_info) );

	SSCEN  = 0x00;
	if( mode == SPI_BYTES )
	{
		SSCCON = 0x5037;
		spi_info.mode = SPI_BYTES;
	}
	else
	{
		SSCCON = 0x503F;
		spi_info.mode = SPI_WORDS;
	}
	SSCBR  = 0x0001;
	SSCEN  = 0x01;
	SSCTIC = 0x0030;
	SSCRIC = 0x0031;
	SSCEIC = 0x0032;
}

void SPI_driver_enable( void )
{
	SSCEN = 0x01;
}

void SPI_driver_disable( void )
{
	SSCEN = 0x00;
}

unsigned int SPI_driver_busy( void )
{
	return( spi_info.busy );
}

void SPI_driver_send_word( unsigned int send_word )
{
	SSCTB = send_word;
	while( SSCBSY );
}

void SPI_driver_send_byte( unsigned char send_byte )
{
	SSCTB = send_byte;
	while( SSCBSY );
}

unsigned int SPI_driver_send_words( unsigned int word_count, unsigned int *send_words )
{
	if( spi_info.busy != SPI_BUSY )
	{
		spi_info.counter = word_count;
		spi_info.word_pointer = send_words;
		spi_info.busy = SPI_BUSY;
		SSCTIE = 0x01;
		SSCTIR = 0x01;
		return( SPI_IDLE );
	}
	return( SPI_BUSY );
}

unsigned int SPI_driver_send_bytes( unsigned int bytes_count, unsigned char *send_bytes )
{
	if( spi_info.busy != SPI_BUSY )
	{
		spi_info.counter = bytes_count;
		spi_info.byte_pointer = send_bytes;
		spi_info.busy = SPI_BUSY;
		SSCTIE = 0x01;
		SSCTIR = 0x01;
		return( SPI_IDLE );
	}
	return( SPI_BUSY );
}

unsigned int SPI_driver_receive_word( void )
{
	SSCTB = 0x00;
	while( SSCBSY );
	return( SSCRB );
}

void SPI_transfer( void ) interrupt 0x2D
{
	if( spi_info.counter > 0 )
	{
		if( spi_info.mode == SPI_BYTES )
		{
			SSCTB = *spi_info.word_pointer++;
		}
		else
		{
			SSCTB = *spi_info.byte_pointer++;
		}
		spi_info.counter--;
	}
	else
	{
		spi_info.busy = SPI_IDLE;	
		SSCTIE = 0x00;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -