|
创龙工程师,你们好!
我在编写用GPIO接口模拟SPI时序控制OLED时,编译过程中出现“mach/gpio.h: 没有那个文件或目录”的错误。我在内核目录下,没有找到相关头文件,请教这个问题如何解决。具体程序如下所示。
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/platform_device.h>
#include <linux/poll.h>
#include <linux/leds.h>
#include <linux/io.h>
#include <linux/cdev.h>
#include <linux/types.h>
#include <mach/gpio.h>
#include <plat/mux.h>
#include <linux/gpio.h>
#define STATUS_SUCCESS 0
#define STATUS_FAILURE -1
static struct class *spi_oled_class;
static struct device *spi_oled_class_dev;
static char val;
static int major;
static unsigned char TxBuf[24] = {0};
//SPI
#define CSN GPIO_TO_PIN(0,19) /* EQEP0B_IN/GPIO0[19] */
#define CSN_OUT gpio_direction_output(CSN, 1)
#define CSN_L gpio_set_value(CSN, 0)
#define CSN_H gpio_set_value(CSN, 1)
#define RS GPIO_TO_PIN(0,21) /* SPI2_MISO/GPIO0[21] */
#define RS_OUT gpio_direction_output(RS, 1)
#define RS_L gpio_set_value(RS, 0)
#define RS_H gpio_set_value(RS, 1)
#define SCK GPIO_TO_PIN(0,22) /* SPI2_SCLK/GPIO0[22] */
#define SCK_OUT gpio_direction_output(SCK, 1);
#define SCK_L gpio_set_value(SCK, 0)
#define SCK_H gpio_set_value(SCK, 1)
#define MOSI GPIO_TO_PIN(0,20) /* SPI2_MOSI/GPIO0[20] */
#define MOSI_OUT gpio_direction_output(MOSI, 1)
#define MOSI_L gpio_set_value(MOSI, 0)
#define MOSI_H gpio_set_value(MOSI, 1)
#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
static unsigned char SPI_RW(unsigned char tmp)
{
unsigned char bit_ctr;
for(bit_ctr=0 ;bit_ctr<8 ;bit_ctr++) // output 8-bit
{
SCK_L;
if(tmp & 0x80) // output 'tmp', MSB to MOSI
MOSI_H;
else
MOSI_L;
tmp = tmp<<1; // shift next bit into MSB..
ndelay(1);
SCK_H; // ..then set SCK low again
ndelay(1);
}
return(tmp); // return read tmp
}
static unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char uchars)
{
unsigned char status,uint8_ctr;
CSN_L; // Set CSN low, init SPI tranaction
ndelay(60);
status = SPI_RW(reg); // Select register to write to and read status unsigned char
for(uint8_ctr=0;uint8_ctr<uchars;uint8_ctr++)
{
pBuf[uint8_ctr] = SPI_RW(0);
ndelay(20);
}
CSN_H;
ndelay(60);
return(status);
}
static unsigned char SPI_Write_Buf( unsigned char const *pBuf, unsigned char uchars)
{
CSN_L;
SPI_RW(*pBuf);
RS_H;
CSN_H;
return(0);
}
static unsigned char init_oled(void)
{
int result; /* Allocating GPIOs and setting direction */
//spi
result = gpio_request(CSN, "CSN");//usr1
if (result != 0)
printk("gpio_request(CSN) failed!\n");
result = gpio_request(MOSI, "MOSI");//usr1
if (result != 0)
printk("gpio_request(MOSI) failed!\n");
result = gpio_request(SCK, "SCK");//usr1
if (result != 0)
printk("gpio_request(SCK) failed!\n");
result = gpio_request(RS, "RS");//usr1
if (result != 0)
printk("gpio_request(RS) failed!\n");
RS_OUT;
CSN_OUT;
SCK_OUT;
MOSI_OUT;
return (1);
}
static int spi_oled_open(struct inode *inode, struct file *file)
{
unsigned char flag = 0;
flag = init_oled();
mdelay(100);
if(flag == 0)
{
printk("uable to open device!\n");
return -1;
}
printk("open driver\n");
return 0;
}
static ssize_t spi_oled_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
{
printk("read driver\n");
if(copy_to_user(buf, TxBuf, size))
{
printk("read error!\n");
return -EFAULT;
}
else
{
//SPI_Read_Buf(RD_RX_PLOAD, RxBuf,size) ;
return size;
}
return STATUS_SUCCESS;
}
static ssize_t gpio_test(const unsigned char *TxBuf, size_t size)
{
printk("send %c,%d\n",TxBuf[0],TxBuf[1]);
switch(TxBuf[0])
{
case 's':
if(TxBuf[1])
{
CSN_H;
}else{
CSN_L;
}
break;
case 'r':
if(TxBuf[1])
{
RS_H;
}else{
RS_L;
}
break;
case 'c':
if(TxBuf[1])
{
SCK_H;
}else{
SCK_L;
}
break;
case 'm':
if(TxBuf[1])
{
MOSI_H;
}else{
MOSI_L;
}
break;
case 'C':
if(TxBuf[1])
{
SCKIIC_H;
}else{
SCKIIC_L;
}
break;
case 'D':
if(TxBuf[1])
{
SDA_H;
}else{
SDA_L;
}
break;
case 'R':
if(TxBuf[1])
{
RST_H;
}else{
RST_L;
}
break;
case 'N':
if(TxBuf[1])
{
INT_H;
}else{
INT_L;
}
break;
}
return STATUS_SUCCESS;
}
static ssize_t spi_oled_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
{
#if 0
int ret;
ret = copy_from_user(&val, buf, count);
if(ret <0 )
{
printk("ret = %d \n",ret);
return ret;
}
printk("spi_oled_write\n");
return 0;
int ret;
char temp[16];
char status = 0;
memset(temp, 0, 16);
ret = copy_from_user( temp, buf, count );
if(ret <0 )
{
printk("ret = %d \n",ret);
status = EFAULT;
goto err;
}
val = simple_strtoul(temp, NULL, 0);
if(!status)
status = count;
err:
return status;
#endif
if( copy_from_user( TxBuf, buf, size ) )
{
printk("send error!\n");
return -EFAULT;
}
else
{
//gpio_test(TxBuf, size);
SPI_Write_Buf( TxBuf, size);
//printk("Write data :%02x\n",TxBuf[0]);
}
return STATUS_SUCCESS;
}
static ssize_t spi_oled_close(struct inode *inode, struct file *file)
{
printk("close driver\n");
return 0;
}
static long spi_oled_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
switch (cmd)
{
case 0x01 :
{
RS_L; //cmd mode
//printk("set cmd mode\n");
}
break;
case 0x00 :
{
RS_H; //data mode
//printk("set data mode\n");
}
break;
default :
break;
}
return 0;
}
static const struct file_operations oled_ops =
{
.owner = THIS_MODULE,
.open = spi_oled_open,
.read = spi_oled_read,
.write = spi_oled_write,
.release = spi_oled_close,
.unlocked_ioctl = spi_oled_ioctl,
};
static int __init spi_oled_init(void)
{
printk("spi_oled_init!\n");
major = register_chrdev(0, "spi_oled", &oled_ops);
spi_oled_class = class_create(THIS_MODULE, "spi_oled"); /* /sys/class/spi_oled */
spi_oled_class_dev = device_create(spi_oled_class, NULL, MKDEV(major, 0), NULL, "spi_oled"); /* /dev/spi_oled */
return 0;
}
static void __exit spi_oled_exit(void)
{
printk("spi_oled_exit!\n ");
unregister_chrdev(major, "spi_oled");
device_unregister(spi_oled_class_dev);
class_destroy(spi_oled_class);
}
module_init(spi_oled_init);
module_exit(spi_oled_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("XXXX");
MODULE_VERSION("V1.0");
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|