E8卡 linux 系统 读写 高通 字库芯片

在E8卡上通过linux的spi驱动读写高通字库芯片。


spi是分主从的,字库芯片不会主动通过spi发送数据。只有在linux上发起读操作的时候,字库才会把他的数据发送出来。


/*
* spi mode
*/
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
printf("can't set spi mode");


ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
printf("can't get spi mode");


/*
* bits per word
*/
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't set bits per word");


ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't get bits per word");


/*
* max speed hz
*/
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't set max speed hz");


ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't get max speed hz");


printf("spi mode: %d\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

   

     //spi 发送缓冲区

unsigned char tx[1024] = {0};  

//spi 接收缓冲区
unsigned char tx2[1024] = {0};

//字库芯片读命令
tx[0] = 0x03;

//3个字节的地址数据
tx[1] = (unsigned char)((address&0xff0000)>>16); 
tx[2] = (unsigned char)((address&0xff00)>>8); 
tx[3] = (unsigned char)(address&0xFF); 
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,  //发送缓冲区
.rx_buf = (unsigned long)tx2,// 接收缓冲区
.len = 4+buflen,  //buflen 是字库数据的长度,由于在发送前4个字节时,字库芯片是不往主机发送数据。如果想读取buflen长度的字库数据,主机必须再发送长度为buflen的任意数据,

.delay_usecs = delay, 
.speed_hz = speed,
.bits_per_word = bits,
};


ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
接收到的字库数据,就在tx2中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值