1 这里没有专门写ads7841的驱动,采用的是通用spi用户接口设备文件spidev.c
Device Drivers --->
[*] SPI support --->
<*> McSPI driver for OMAP24xx/OMAP34xx
<*> User mode SPI device driver support
2 参考ads7846触摸屏驱动,在板级程序里面完成ads7841用到spi总线的注册:
static struct omap2_mcspi_device_config spidev_mcspi_config = {
.turbo_mode = 0,
.single_channel = 1,
};
struct spi_board_info omap3stalker_spi_board_info[] = {
[0] = {
.modalias = "ads7846",
.bus_num = 1,
.chip_select = 0,
.max_speed_hz = 1500000,
.controller_data = &ads7846_mcspi_config,
.irq = OMAP_GPIO_IRQ(OMAP3_STALKER_TS_GPIO),
.platform_data = &ads7846_config,
},
[1] = {
.modalias = "spidev", //名字
.bus_num = 3, //所在的spi总线编号
.chip_select = 0,
.max_speed_hz = 200000, //时钟速率
.controller_data = &spidev_mcspi_config, //指向spi_device.controller_data
.mode = SPI_MODE_0, //spi模式
},
};
注:对于max_speed_hz根据的是omap2_mcspi.c中的static int omap2_mcspi_setup_transfer(struct spi_device *spi,
struct spi_transfer *t)函数里计算分频值(见omap3530芯片手册)
if (spi->max_speed_hz) {
while (div <= 15 && (OMAP2_MCSPI_MAX_FREQ / (1 << div))
> spi->max_speed_hz)
div++;
} else
div = 15;
对于mcspi3_simo、mcspi3_somi、mcspi3_cs0、mcspi3_clk四个引脚需要设置成相应的模式
例如:OMAP3_MUX(ETK_D0, OMAP_MUX_MODE1 | OMAP_PIN_INPUT | //mcspi3_simo
OMAP_PIN_OFF_INPUT_PULLUP | OMAP_PIN_OFF_OUTPUT_LOW |
OMAP_PIN_OFF_WAKEUPENABLE),
3 通过测试代码,执行读写操作
先write八位的命令数据,等待busy位由高拉低(这里没有接busy位,采用软件延时,但是有错误,见下文)依次读取12位数据(读两个自己,最高位去掉,最后三位是0,移位即可)
运行,写数据的时候正常,但是读取数据有时会出现RXS timed out的错误,修改omap2_mcspi.c,在设置收发模式后做一微秒的延时即可(原因目前未知):
if (t->tx_buf == NULL)
{
chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY ;
udelay(1);
}
else if (t->rx_buf == NULL)
{
chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY ;
udelay(1);
}