Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

help!

i have tried a lot to find the 16*2 lcd driver in the core of uclinux (in the menuconfig).

but until now i can't find such a option.

if somebody knows how to add it to the core ,can you help me?

and i also tried to write a driver of it, but it didnt word well.

i'd like to share it to you , and i hope anybody can point what the problem is in the file.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    #include <linux/module.h># include <linux/errno.h># include <linux/cdev.h># include <linux/config.h># include <linux/types.h># include <linux/errno.h># include <linux/miscdevice.h># include <linux/slab.h># include <linux/ioport.h># include <linux/fcntl.h># include <linux/mc146818rtc.h># include <linux/netdevice.h># include <linux/sched.h># include <linux/delay.h>

    # include <asm/io.h># include <asm/uaccess.h># include <asm/system.h># include <linux/delay.h>

    # define LCD_On 1# define LCD_Off 2# define LCD_Clear 3# define LCD_Reset 4# define LCD_Cursor_Left 5# define LCD_Cursor_Right 6# define LCD_Disp_Left 7# define LCD_Disp_Right 8# define LCD_Get_Cursor 9# define LCD_Set_Cursor 10# define LCD_Home 11# define LCD_Read 12# define LCD_Write 13# define LCD_Cursor_Off 14# define LCD_Cursor_On 15# define LCD_Get_Cursor_Pos 16# define LCD_Set_Cursor_Pos 17# define LCD_Blink_Off 18

    # define kLCD_IR na_lcd_16207_0# define kLCD_DR (na_lcd_16207_0 + 8)

    # define LCDWriteData(x) outl(x , kLCD_DR)# define LCDWriteInst(x) outl(x , kLCD_IR)

    # define LCDReadData inl(kLCD_DR)# define LCDReadInst inl(kLCD_IR)

    # define Major 250

    static int Device_Open = 0;

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg);

    static int lcd_16207_open(struct inode *inode,struct file *filp)

    {

    static int counter = 0;

    if(Device_Open)return -EBUSY;

    Device_Open++;

    printk("You have open the device %d times\n",counter++);

    return 0;

    }

    static int lcd_16207_release(struct inode *inode,struct file *filp)

    {

    Device_Open--;

    printk("You have release the device\n");

    return 0;

    }

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg)

    {

    volatile unsigned long display;

    switch (cmd) {

    case LCD_On:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -EFAULT;

    LCDWriteInst(display);

    break;

    case LCD_Off:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -EFAULT;

    LCDWriteData(display);

    break;

    default:

    return -EINVAL;

    }

    return 0;

    }

    static struct file_operations lcd_16207_fops={

    .ioctl = lcd_16207_ioctl,

    .open = lcd_16207_open,

    .release = lcd_16207_release,

    };

    static int lcd_16207_init(void)

    {

    int ret = register_chrdev(Major,"LCD_PIO",&lcd_16207_fops);

    if(ret<0)

    {

    printk("Registering the device failed with %d\n",Major);

    return Major;

    }

    printk("You have init Device %d\n",Major);

    return 0;

    }

    static void lcd_16207_exit(void)

    {

    if(unregister_chrdev(Major,"LCD_PIO"))

    printk("exit failed");

    }

    module_init(lcd_16207_init);

    module_exit(lcd_16207_exit);

    MODULE_AUTHOR("Andrew Bose");

    MODULE_LICENSE("GPL");
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I am also looking at getting the LCD running, but i have absolute no idea.

    Which ptf do you use ? I use the std_2c35.ptf, is that enough ? Or do i have to use the full featured one ?

    Can you also elaborate how what state the code is in ? Is it working ?

    I need some help and guide here.

    --- Quote Start ---

    originally posted by snail1@Aug 8 2006, 09:06 PM

    #include <linux/module.h># include <linux/errno.h># include <linux/cdev.h># include <linux/config.h># include <linux/types.h># include <linux/errno.h># include <linux/miscdevice.h># include <linux/slab.h># include <linux/ioport.h># include <linux/fcntl.h># include <linux/mc146818rtc.h># include <linux/netdevice.h># include <linux/sched.h># include <linux/delay.h>

    # include <asm/io.h># include <asm/uaccess.h># include <asm/system.h># include <linux/delay.h>

    # define lcd_on 1# define lcd_off 2# define lcd_clear 3# define lcd_reset 4# define lcd_cursor_left 5# define lcd_cursor_right 6# define lcd_disp_left 7# define lcd_disp_right 8# define lcd_get_cursor 9# define lcd_set_cursor 10# define lcd_home 11# define lcd_read 12# define lcd_write 13# define lcd_cursor_off 14# define lcd_cursor_on 15# define lcd_get_cursor_pos 16# define lcd_set_cursor_pos 17# define lcd_blink_off 18

    # define klcd_ir na_lcd_16207_0# define klcd_dr (na_lcd_16207_0 + 8)

    # define lcdwritedata(x) outl(x , klcd_dr)# define lcdwriteinst(x) outl(x , klcd_ir)

    # define lcdreaddata inl(klcd_dr)# define lcdreadinst inl(klcd_ir)

    # define major 250

    static int device_open = 0;

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg);

    static int lcd_16207_open(struct inode *inode,struct file *filp)

    {

    static int counter = 0;

    if(device_open)return -ebusy;

    device_open++;

    printk("you have open the device %d times\n",counter++);

    return 0;

    }

    static int lcd_16207_release(struct inode *inode,struct file *filp)

    {

    device_open--;

    printk("you have release the device\n");

    return 0;

    }

    static int lcd_16207_ioctl(struct inode *inode,struct file *filp,

    unsigned int cmd,unsigned long arg)

    {

    volatile unsigned long display;

    switch (cmd) {

    case lcd_on:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -efault;

    lcdwriteinst(display);

    break;

    case lcd_off:

    if (copy_from_user

    (&display, (unsigned long *) arg,

    sizeof(display)))

    return -efault;

    lcdwritedata(display);

    break;

    default:

    return -einval;

    }

    return 0;

    }

    static struct file_operations lcd_16207_fops={

    .ioctl = lcd_16207_ioctl,

    .open = lcd_16207_open,

    .release = lcd_16207_release,

    };

    static int lcd_16207_init(void)

    {

    int ret = register_chrdev(major,"lcd_pio",&lcd_16207_fops);

    if(ret<0)

    {

    printk("registering the device failed with %d\n",major);

    return major;

    }

    printk("you have init device %d\n",major);

    return 0;

    }

    static void lcd_16207_exit(void)

    {

    if(unregister_chrdev(major,"lcd_pio"))

    printk("exit failed");

    }

    module_init(lcd_16207_init);

    module_exit(lcd_16207_exit);

    module_author("andrew bose");

    module_license("gpl");

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=17462)

    --- quote end ---

    --- Quote End ---