added basic pin config for lcd screen

This commit is contained in:
Lauchmelder 2022-06-10 19:07:50 +02:00
parent 7fd5e0fffc
commit 15a4f817f2
4 changed files with 79 additions and 18 deletions

10
pins.txt Normal file
View file

@ -0,0 +1,10 @@
Power - 14
RS - 11
R/W - 09
E - 10
DB4 - 26
DB5 - 19
DB6 - 13
DB7 - 06

View file

@ -24,6 +24,7 @@ ssize_t lcd_write(struct file* filp, const char __user* buf, size_t count, loff_
char* cmd_start = NULL;
char* cmd_end = NULL;
ssize_t retval = 0;
struct lcd_gpio_config* config;
if(down_interruptible(&dev->sem))
return retval;
@ -47,14 +48,18 @@ ssize_t lcd_write(struct file* filp, const char __user* buf, size_t count, loff_
cmd_start = kern_buf;
cmd_end = kern_buf;
config = &dev->config;
while(advance_ptr(kern_buf, count, &cmd_end))
{
*cmd_end = '\0';
if(strcmp(cmd_start, "0") == 0)
gpio_set_value(dev->gpio, 0);
else if(strcmp(cmd_start, "1") == 0)
gpio_set_value(dev->gpio, 1);
gpio_set_value(config->power, 0);
else if(strcmp(cmd_start, "1") == 0) {
printk(KERN_DEBUG "%s: Setting output of gpio %d to 1", THIS_MODULE->name, config->power);
gpio_set_value(config->power, 1);
}
else
printk(KERN_WARNING "%s: Unrecognized command \"%s\"\n", THIS_MODULE->name, cmd_start);

View file

@ -8,19 +8,34 @@
MODULE_LICENSE("GPL");
int lcd_major = LCD_MAJOR;
int lcd_minor = LCD_MINOR;
int lcd_gpio = LCD_GPIO;
static int lcd_major = LCD_MAJOR;
static int lcd_minor = LCD_MINOR;
module_param(lcd_major, int, S_IRUGO);
module_param(lcd_minor, int, S_IRUGO);
module_param(lcd_gpio, int, S_IRUGO);
static int pin_power = LCD_PIN_POWER;
module_param(pin_power, int, S_IRUGO);
static int pin_rs = LCD_PIN_REGISTER_SELECT;
module_param(pin_rs, int, S_IRUGO);
static int pin_rw = LCD_PIN_READ_WRITE;
module_param(pin_rw, int, S_IRUGO);
static int pin_enable = LCD_PIN_ENABLE;
module_param(pin_enable, int, S_IRUGO);
static int pin_data[4] = LCD_PIN_DATA;
static int count;
module_param_array(pin_data, int, &count, S_IRUGO);
static struct lcd_dev lcddev = { 0 };
static int __init lcd_init_cdev(void);
static void __exit lcd_exit_cdev(void);
static int __init lcd_init_cdev(void);
static int __init lcd_init_gpio(void);
static int __init lcd_validate_gpio(void);
static int __init lcd_init_gpio(void);
static void __exit lcd_exit_cdev(void);
static void __exit lcd_exit_gpio(void);
extern loff_t lcd_llseek (struct file*, loff_t, int);
@ -103,17 +118,37 @@ static int __init lcd_init_cdev(void)
return result;
}
static int __init lcd_init_gpio(void)
{
lcd_validate_gpio();
// gpio_direction_output(lcddev.gpio, 0);
return 0;
}
static int __init lcd_validate_gpio(void)
{
struct lcd_gpio_config* config = &lcddev.config;
config->power = pin_power;
config->rs = pin_rs;
config->rw = pin_rw;
config->enable = pin_enable;
memcpy(config->data, pin_data, 4 * sizeof(int));
// TODO: Check if pin configuration is valid
// - no duplicate pins?
// - all pin numbers in range?
return 0;
}
static void __exit lcd_exit_cdev(void)
{
cdev_del(&lcddev.dev);
}
static int __init lcd_init_gpio(void)
{
lcddev.gpio = 18;
gpio_direction_output(lcddev.gpio, 0);
return 0;
}
static void __exit lcd_exit_gpio(void)
{

View file

@ -7,14 +7,25 @@
#define LCD_MAJOR 0
#define LCD_MINOR 0
#define LCD_GPIO 18
#define LCD_PIN_POWER 14
#define LCD_PIN_REGISTER_SELECT 11
#define LCD_PIN_READ_WRITE 9
#define LCD_PIN_ENABLE 10
#define LCD_PIN_DATA { 26, 19, 13, 06 }
struct lcd_gpio_config
{
int power;
int rs, rw, enable;
int data[4];
};
struct lcd_dev
{
dev_t devno;
struct cdev dev;
struct semaphore sem;
int gpio;
struct lcd_gpio_config config;
};
#endif