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中。
總結
以上是生活随笔為你收集整理的E8卡 linux 系统 读写 高通 字库芯片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 武汉 一日游 小记
- 下一篇: 换个安逸点儿的英文名,希望以后事业顺遂!