Example #1
0
void write_cmx865a(unsigned char addr,unsigned short data,unsigned char len)
{
#if GPIO_SPI
	CS(0);
	if(len==0)
		write_spi(addr);
	else
		{
		write_spi(addr);
		if(len==2)
			write_spi((data>>8) & 0xff);
		write_spi(data&0xff);
		}
	CS(1);
#else
	unsigned char tmp[3];
	int count=0;
	if(len==0)
	{
		tmp[0]=addr;
		count=1;
	}
	else
	{
		tmp[0]=addr;
		if(len==2)
		{
			tmp[1]=(data>>8)&0xff;
			tmp[2]=data&0xff;
			count=3;
		}
		else
		{
Example #2
0
int main(void){

	/* Sample data */
	char *data = "REDPITAYA SPI TEST";

	/* Init the spi resources */
	if(init_spi() < 0){
		printf("Initialization of SPI failed. Error: %s\n", strerror(errno));
		return -1;
	}

	/* Write some sample data */
	if(write_spi(data, strlen(data)) < 0){
		printf("Write to SPI failed. Error: %s\n", strerror(errno));
		return -1;
	}

	/* Read flash ID and some sample loopback data */
	if(read_flash_id(spi_fd) < 0){
		printf("Error reading from SPI bus : %s\n", strerror(errno));
		return -1;
	}

	/* Release resources */
	if(release_spi() < 0){
		printf("Relase of SPI resources failed, Error: %s\n", strerror(errno));
		return -1;
	}

	return 0;
}
Example #3
0
void Ad9361WriteReg(int via_fpga, int fd, unsigned short addr, unsigned char data)
{
	if(1 == via_fpga)
		write_spi(fd, addr, data);
	else
		SpiDrvWriteReg(fd, addr, data);
}
Example #4
0
/*
void disp_send(unsigned char cmd, unsigned char type)
	{
    char x;
    if (type!=0)
    	D_C = 1;
    else
       	D_C = 0;
    SCE = 0;
    for(x=0;x<8;x++){       //clock the byte out
        SCLK = 0;
        MOSI = 0;
        if(cmd & 0x80)
            MOSI = 1;
        SCLK = 1;
        cmd <<= 1;
    }
    SCE = 1;
}
*/
void disp_send(unsigned char cmd, unsigned char type)
{
char x;
if (type!=0)
  	D_C = 1;
else
   	D_C = 0;
SCE = 0;
write_spi(cmd);
SCE = 1;
}
SpiGui::SpiGui(MainWidgetFrame *parent) : QWidget(parent)
{
	this->parent=parent;

	QLabel *file_label = new QLabel("File: ");
	QLabel *log_label = new QLabel("Log: ");

	QPushButton *read_btn = new QPushButton("Read SPI");
	QPushButton *write_btn = new QPushButton("Write SPI");
	QPushButton *chip_id_btn = new QPushButton("SPI Chip ID");

	file = new QLineEdit;
	msglog = new QTextEdit;
	msglog->setReadOnly(true);

	QVBoxLayout *vlayout = new QVBoxLayout;
	QHBoxLayout *hlayout = new QHBoxLayout;

	connect(read_btn, SIGNAL(clicked()), this, SLOT(read_spi()));
	connect(write_btn, SIGNAL(clicked()), this, SLOT(write_spi()));
	connect(chip_id_btn, SIGNAL(clicked()), this, SLOT(spi_chip_id()));

	vlayout->addWidget(file_label);
	vlayout->addWidget(file);

	hlayout->addWidget(read_btn);
	hlayout->addWidget(write_btn);
	hlayout->addWidget(chip_id_btn);
	
	vlayout->addLayout(hlayout);
	vlayout->addSpacing(50);
	vlayout->addWidget(log_label);
	vlayout->addWidget(msglog);

	setLayout(vlayout);
}