]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
begin display work
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 14 Feb 2018 04:35:44 +0000 (23:35 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 14 Feb 2018 04:35:44 +0000 (23:35 -0500)
include/display.h [new file with mode: 0644]
src/display.c [new file with mode: 0644]
src/main.c

diff --git a/include/display.h b/include/display.h
new file mode 100644 (file)
index 0000000..8210656
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef DISPLAY_H_
+#define DISPLAY_H_
+
+#include <stdint.h>
+
+#define LCD_WIDTH  480
+#define LCD_HEIGHT 320
+
+void dsp_write_data(uint8_t data);
+void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
+void dsp_init(void);
+
+#endif // DISPLAY_H_
diff --git a/src/display.c b/src/display.c
new file mode 100644 (file)
index 0000000..b5c4ba0
--- /dev/null
@@ -0,0 +1,144 @@
+#include <display.h>
+
+#include <clock.h>
+#include <gpio.h>
+
+#include <stdint.h>
+
+#define LCD_RD  GPIO_PORT(A, 0)
+#define LCD_WR  GPIO_PORT(A, 1)
+#define LCD_RS  GPIO_PORT(A, 4)
+#define LCD_CS  GPIO_PORT(B, 0)
+#define LCD_RST GPIO_PORT(C, 1)
+#define LCD_D0  GPIO_PORT(A, 9)
+#define LCD_D1  GPIO_PORT(C, 7)
+#define LCD_D2  GPIO_PORT(A, 10)
+#define LCD_D3  GPIO_PORT(B, 3)
+#define LCD_D4  GPIO_PORT(B, 5)
+#define LCD_D5  GPIO_PORT(B, 4)
+#define LCD_D6  GPIO_PORT(B, 10)
+#define LCD_D7  GPIO_PORT(A, 8)
+
+// bbbbbggg gggrrrrr 
+
+void dsp_write_data(uint8_t data)
+{
+       gpio_dout(LCD_D0, data & 0x01);
+       gpio_dout(LCD_D1, data & 0x02);
+       gpio_dout(LCD_D2, data & 0x04);
+       gpio_dout(LCD_D3, data & 0x08);
+       gpio_dout(LCD_D4, data & 0x10);
+       gpio_dout(LCD_D5, data & 0x20);
+       gpio_dout(LCD_D6, data & 0x40);
+       gpio_dout(LCD_D7, data & 0x80);
+       gpio_dout(LCD_WR, 0);
+       gpio_dout(LCD_WR, 1);
+}
+
+void dsp_write_cmd(uint8_t data)
+{
+       gpio_dout(LCD_RS, 0);
+       dsp_write_data(data);
+       gpio_dout(LCD_RS, 1);
+}
+
+void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
+{
+       dsp_write_cmd(0x2A);
+       dsp_write_data(x1 >> 8);
+       dsp_write_data(x1 & 0xFF);
+       dsp_write_data(x2 >> 8);
+       dsp_write_data(x2 & 0xFF);
+       dsp_write_cmd(0x2B);
+       dsp_write_data(y1 >> 8);
+       dsp_write_data(y1 & 0xFF);
+       dsp_write_data(y2 >> 8);
+       dsp_write_data(y2 & 0xFF);
+       dsp_write_cmd(0x2C); // begin writing
+}
+
+void dsp_init(void)
+{
+       gpio_mode(LCD_CS, OUTPUT);
+       gpio_mode(LCD_RS, OUTPUT);
+       gpio_mode(LCD_RD, OUTPUT);
+       gpio_mode(LCD_WR, OUTPUT);
+       gpio_mode(LCD_RST, OUTPUT);
+       gpio_mode(LCD_D0, OUTPUT);
+       gpio_mode(LCD_D1, OUTPUT);
+       gpio_mode(LCD_D2, OUTPUT);
+       gpio_mode(LCD_D3, OUTPUT);
+       gpio_mode(LCD_D4, OUTPUT);
+       gpio_mode(LCD_D5, OUTPUT);
+       gpio_mode(LCD_D6, OUTPUT);
+       gpio_mode(LCD_D7, OUTPUT);
+       gpio_dout(LCD_CS, 1);
+       gpio_dout(LCD_RS, 1);
+       gpio_dout(LCD_RD, 1);
+       gpio_dout(LCD_WR, 1);
+       gpio_dout(LCD_RST, 1);
+       gpio_dout(LCD_D0, 0);
+       gpio_dout(LCD_D1, 0);
+       gpio_dout(LCD_D2, 0);
+       gpio_dout(LCD_D3, 0);
+       gpio_dout(LCD_D4, 0);
+       gpio_dout(LCD_D5, 0);
+       gpio_dout(LCD_D6, 0);
+       gpio_dout(LCD_D7, 0);
+
+       delay(50);
+       gpio_dout(LCD_RST, 0);
+       delay(15);
+       gpio_dout(LCD_RST, 1);
+       delay(15);
+
+       dsp_write_cmd(0x01); // soft reset
+       delay(50);
+
+       dsp_write_cmd(0xD0); // power setting
+       dsp_write_data(0x07);
+       dsp_write_data(0x42);
+       dsp_write_data(0x18);
+       dsp_write_cmd(0xD1); // vcom control
+       dsp_write_data(0x00);
+       dsp_write_data(0x07);
+       dsp_write_data(0x10);
+       dsp_write_cmd(0xD2); // power for normal mode
+       dsp_write_data(0x01);
+       dsp_write_data(0x02);
+       dsp_write_cmd(0xD3);
+       dsp_write_data(0x01);
+       dsp_write_data(0x02);
+       dsp_write_cmd(0xD4);
+       dsp_write_data(0x01);
+       dsp_write_data(0x02);
+       dsp_write_cmd(0xC0); // panel driving setting
+       dsp_write_data(0x10);
+       dsp_write_data(0x3B);
+       dsp_write_data(0x00);
+       dsp_write_data(0x02);
+       dsp_write_data(0x11);
+       dsp_write_cmd(0xC5); // frame rate/inversion ctl
+       dsp_write_data(0x03);
+       dsp_write_cmd(0x36); // rot. and stuff
+       dsp_write_data(0x41);
+       dsp_write_cmd(0x3A); // set pixel format
+       dsp_write_data(0x55);
+       dsp_write_cmd(0x11);
+       delay(150);
+       dsp_write_cmd(0x29); // set display on
+       delay(500);
+       dsp_write_cmd(0x33); // set scroll area
+       dsp_write_data(0x00);
+       dsp_write_data(0x00);
+       dsp_write_data(LCD_HEIGHT >> 8);
+       dsp_write_data((LCD_HEIGHT & 0xFF) - 1);
+       dsp_write_data(0x00);
+       dsp_write_data(0x00);
+       dsp_write_cmd(0x37);
+       dsp_write_data(0x00);
+       dsp_write_data(0x00);
+
+       dsp_set_addr(0, 0, LCD_WIDTH, LCD_HEIGHT);
+}
+
index 520fccdb97f06641f2851f13756311d5c7f5b59c..74b5497fd28b6afcbf88c3c721323a0ef30eb750 100644 (file)
@@ -4,6 +4,7 @@
 #include <task.h>\r
 #include <gpio.h>\r
 #include <lcd.h>\r
+#include <display.h>\r
 #include <initrd.h>\r
 #include <serial.h>\r
 #include <parser.h>\r
@@ -100,9 +101,17 @@ void kmain(void)
 {\r
        asm("cpsie i");\r
 \r
-       task_start(lcd_handler, 128);\r
-       delay(200);\r
-       task_start(task_interpreter, 4096);\r
+       dsp_init();\r
+    dsp_set_addr(0, 0, LCD_WIDTH, LCD_HEIGHT);\r
+    int w = LCD_WIDTH * LCD_HEIGHT;\r
+    do {\r
+        dsp_write_data(0);//c >> 8);\r
+        dsp_write_data(0);//c & 0xFF);\r
+    } while (w--);\r
+\r
+       //task_start(lcd_handler, 128);\r
+       //delay(200);\r
+       //task_start(task_interpreter, 4096);\r
 \r
        //char *s = initrd_getfile("test.txt");\r
 \r