AM3358 >> C/C++
2.0" IPS 320x240(ILI9335)(GPIO)
main.c
#include <linux/init.h> #include <linux/device.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/timer.h> #include <linux/gpio.h> #include <asm/io.h> #define ILI9335_SLCD_D17 77 #define ILI9335_SLCD_D16 76 #define ILI9335_SLCD_D15 75 #define ILI9335_SLCD_D14 74 #define ILI9335_SLCD_D13 73 #define ILI9335_SLCD_D12 72 #define ILI9335_SLCD_D11 71 #define ILI9335_SLCD_D10 70 #define ILI9335_SLCD_RS 86 #define ILI9335_SLCD_RST 20 #define ILI9335_SLCD_CS 89 #define ILI9335_SLCD_RD 88 #define ILI9335_SLCD_WR 87 #define do_request(pin, name) \ if(gpio_request(pin, name) < 0){ \ printk("failed to request gpio: %s\n", name); \ } \ else{ \ printk("request successfully for gpio: %s\n", name); \ gpio_direction_output(pin, 1); \ } #define do_output(val, pin) \ if(val){ \ gpio_set_value(pin, 1); \ } \ else{ \ gpio_set_value(pin, 0); \ } MODULE_AUTHOR("Steward_Fu"); MODULE_DESCRIPTION("ILI9335 SLCD Driver for BBGW"); MODULE_LICENSE("GPL"); static int g_blink_period=1000; static struct timer_list g_blink_timer; static void ili9335_reset(void) { gpio_set_value(ILI9335_SLCD_RST, 1); mdelay(100); gpio_set_value(ILI9335_SLCD_RST, 0); mdelay(100); gpio_set_value(ILI9335_SLCD_RST, 1); mdelay(100); } static void ili9335_send_command(unsigned int val) { unsigned char i, cmd=0; gpio_set_value(ILI9335_SLCD_RS, 0); gpio_set_value(ILI9335_SLCD_RD, 1); gpio_set_value(ILI9335_SLCD_CS, 0); for(i=0; i<2; i++){ cmd = (i == 0) ? (val >> 8) : val; do_output(cmd & 0x01, ILI9335_SLCD_D10); do_output(cmd & 0x02, ILI9335_SLCD_D11); do_output(cmd & 0x04, ILI9335_SLCD_D12); do_output(cmd & 0x08, ILI9335_SLCD_D13); do_output(cmd & 0x10, ILI9335_SLCD_D14); do_output(cmd & 0x20, ILI9335_SLCD_D15); do_output(cmd & 0x40, ILI9335_SLCD_D16); do_output(cmd & 0x80, ILI9335_SLCD_D17); gpio_set_value(ILI9335_SLCD_WR, 0); gpio_set_value(ILI9335_SLCD_WR, 1); } gpio_set_value(ILI9335_SLCD_CS, 1); } static void ili9335_send_data(unsigned int val) { unsigned char i, dat=0; gpio_set_value(ILI9335_SLCD_RS, 1); gpio_set_value(ILI9335_SLCD_RD, 1); gpio_set_value(ILI9335_SLCD_CS, 0); for(i=0; i<2; i++){ dat = (i == 0) ? (val >> 8) : val; do_output(dat & 0x01, ILI9335_SLCD_D10); do_output(dat & 0x02, ILI9335_SLCD_D11); do_output(dat & 0x04, ILI9335_SLCD_D12); do_output(dat & 0x08, ILI9335_SLCD_D13); do_output(dat & 0x10, ILI9335_SLCD_D14); do_output(dat & 0x20, ILI9335_SLCD_D15); do_output(dat & 0x40, ILI9335_SLCD_D16); do_output(dat & 0x80, ILI9335_SLCD_D17); gpio_set_value(ILI9335_SLCD_WR, 0); gpio_set_value(ILI9335_SLCD_WR, 1); } gpio_set_value(ILI9335_SLCD_CS, 1); } static void ili9335_send_register(unsigned int cmd, unsigned int data) { ili9335_send_command(cmd); ili9335_send_data(data); } static void ili9335_init(void) { ili9335_send_register(0x0001, 0x0100); ili9335_send_register(0x0002, 0x0200); ili9335_send_register(0x0003, 0x1018); ili9335_send_register(0x0008, 0x0202); ili9335_send_register(0x0009, 0x0000); ili9335_send_register(0x000A, 0x0000); ili9335_send_register(0x000C, 0x0000); ili9335_send_register(0x000D, 0x0000); ili9335_send_register(0x0060, 0x2700); ili9335_send_register(0x0061, 0x0000); ili9335_send_register(0x006A, 0x0000); mdelay(10); ili9335_send_register(0x0010, 0x1490); ili9335_send_register(0x0011, 0x0227); mdelay(80); ili9335_send_register(0x0012, 0x000c); mdelay(10); ili9335_send_register(0x0013, 0x1000); ili9335_send_register(0x0029, 0x000b); ili9335_send_register(0x002b, 0x000b); mdelay(10); ili9335_send_register(0x0020, 0x0000); ili9335_send_register(0x0021, 0x0000); ili9335_send_register(0x0030, 0x0000); ili9335_send_register(0x0031, 0x0406); ili9335_send_register(0x0032, 0x0002); ili9335_send_register(0x0035, 0x0402); ili9335_send_register(0x0036, 0x0004); ili9335_send_register(0x0037, 0x0507); ili9335_send_register(0x0038, 0x0103); ili9335_send_register(0x0039, 0x0707); ili9335_send_register(0x003c, 0x0204); ili9335_send_register(0x003d, 0x0004); ili9335_send_register(0x0050, 0x0000); ili9335_send_register(0x0051, 0x00ef); ili9335_send_register(0x0052, 0x0000); ili9335_send_register(0x0053, 0x013f); mdelay(10); ili9335_send_register(0x0007, 0x0133); } static void show_color(unsigned int val) { int i, j; ili9335_send_command(0x0022); for(i=0; i<240; i++){ for(j=0; j<320; j++){ ili9335_send_data(val); } } } void blink_handler(unsigned long unused) { #if 0 static int i=0; unsigned long col[]={0xf800, 0x7e0, 0x1f}; show_color(col[i++ % 3]); #else int i, j; ili9335_send_command(0x0022); for(i=0; i<240; i++){ for(j=0; j<320; j++){ if(i < 80){ ili9335_send_data(0xf800); } else if(i < 160){ ili9335_send_data(0x7e0); } else if(i < 240){ ili9335_send_data(0x1f); } } } #endif mod_timer(&g_blink_timer, jiffies + msecs_to_jiffies(g_blink_period)); } static int __init main_init(void) { do_request(ILI9335_SLCD_WR, "lcd_wr"); do_request(ILI9335_SLCD_RD, "lcd_rd"); do_request(ILI9335_SLCD_CS, "lcd_cs"); do_request(ILI9335_SLCD_RS, "lcd_rs"); do_request(ILI9335_SLCD_RST, "lcd_rst"); do_request(ILI9335_SLCD_D10, "lcd_d10"); do_request(ILI9335_SLCD_D11, "lcd_d11"); do_request(ILI9335_SLCD_D12, "lcd_d12"); do_request(ILI9335_SLCD_D13, "lcd_d13"); do_request(ILI9335_SLCD_D14, "lcd_d14"); do_request(ILI9335_SLCD_D15, "lcd_d15"); do_request(ILI9335_SLCD_D16, "lcd_d16"); do_request(ILI9335_SLCD_D17, "lcd_d17"); ili9335_reset(); ili9335_init(); setup_timer(&g_blink_timer, blink_handler, 0); mod_timer(&g_blink_timer, jiffies + msecs_to_jiffies(g_blink_period)); return 0; } static void __exit main_exit(void) { del_timer(&g_blink_timer); gpio_free(ILI9335_SLCD_WR); gpio_free(ILI9335_SLCD_RD); gpio_free(ILI9335_SLCD_CS); gpio_free(ILI9335_SLCD_RS); gpio_free(ILI9335_SLCD_RST); gpio_free(ILI9335_SLCD_D10); gpio_free(ILI9335_SLCD_D11); gpio_free(ILI9335_SLCD_D12); gpio_free(ILI9335_SLCD_D13); gpio_free(ILI9335_SLCD_D14); gpio_free(ILI9335_SLCD_D15); gpio_free(ILI9335_SLCD_D16); gpio_free(ILI9335_SLCD_D17); } module_init(main_init); module_exit(main_exit);
完成