Added datasheets, updated touchsupport.

This commit is contained in:
id101010
2015-05-12 14:32:43 +02:00
parent 3b30f4e84c
commit aec62d4e02
6 changed files with 240820 additions and 240 deletions

View File

@@ -2,7 +2,7 @@
#include "tft.h"
#include "system.h"
#include "touch.h"
#include "screen_main.h"
#include "screen_guitest.h"
#include "filesystem.h"
void app_init() {
@@ -11,7 +11,7 @@ void app_init() {
touch_init();
filesystem_init();
gui_screen_navigate(get_screen_main());
gui_screen_navigate(get_screen_guitest());
}

View File

@@ -29,14 +29,34 @@
* ---------------------- prototypes --------------------------------------------------------------
*/
// init functions
bool ll_fsmc_init();
bool ll_gpio_init();
bool ll_display_init();
/* init functions */
bool ll_tft_init();
static bool display_init();
static bool fsmc_init();
static bool gpio_init();
// display control functions
void ll_tft_write_reg(uint8_t reg_adr, uint16_t reg_value);
uint16_t ll_tft_read_reg(uint8_t reg_adr);
/* display functions */
void ll_tft_clear(uint16_t color);
static void tft_set_cursor(uint16_t xpos, uint16_t ypos);
static void tft_set_backlight(bool state);
static void tft_reset(bool state);
static void tft_write_reg(uint8_t reg_adr, uint16_t reg_value);
static uint16_t tft_read_reg(uint8_t reg_adr);
static void tft_set_window(uint16_t xstart, uint16_t ystart, uint16_t xend, uint16_t yend);void tft_reset_window();
/* draw functions */
void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void ll_tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color);
void ll_tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
/* font functions */
static const char *get_font(uint8_t font);
uint8_t ll_tft_num_fonts();
uint8_t ll_tft_font_height(uint8_t fontnum);
uint8_t ll_tft_font_width(uint8_t fontnum);
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t fontnum, char c);
/*
* ---------------------- defines and makros ------------------------------------------------------
@@ -86,133 +106,129 @@ uint16_t ll_tft_read_reg(uint8_t reg_adr);
/*
* ---------------------- init functions ----------------------------------------------------------
*/
bool ll_tft_init()
{
bool gpio, fsmc, display;
// init gpio
gpio = ll_gpio_init();
// delay
system_delay(TFT_INIT_TIMEOUT);
// init fsmc
fsmc = ll_fsmc_init();
// delay
system_delay(TFT_INIT_TIMEOUT);
// init display
display = ll_display_init();
gpio = gpio_init(); // init gpio
system_delay(TFT_INIT_TIMEOUT); // delay
fsmc = fsmc_init(); // init fsmc
system_delay(TFT_INIT_TIMEOUT); // delay
display = display_init(); // init display
return (gpio & fsmc & display);
}
bool ll_display_init()
static bool display_init()
{
ll_tft_reset(true); // toggle reset
tft_reset(true); // toggle reset
system_delay(TFT_INIT_TIMEOUT);
ll_tft_reset(false);
tft_reset(false);
ll_tft_write_reg(0x0007,0x0021);
tft_write_reg(0x0007,0x0021);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0000,0x0001);
tft_write_reg(0x0000,0x0001);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0007,0x0023);
tft_write_reg(0x0007,0x0023);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0010,0x0000);
tft_write_reg(0x0010,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0007,0x0033);
tft_write_reg(0x0007,0x0033);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(TFT_SSD1289_REG_11,0x6018); // set mode (landscape, portrait)
tft_write_reg(TFT_SSD1289_REG_11,0x6018); // set mode (landscape, portrait)
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0002,0x0600);
tft_write_reg(0x0002,0x0600);
system_delay(TFT_INIT_TIMEOUT);
//ll_tft_write_reg(0x0012,0x6CEB);
//tft_write_reg(0x0012,0x6CEB);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0003,0xA8A4);
tft_write_reg(0x0003,0xA8A4);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x000C,0x0000);
tft_write_reg(0x000C,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x000D,0x080C);
tft_write_reg(0x000D,0x080C);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x000E,0x2B00);
tft_write_reg(0x000E,0x2B00);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x001E,0x00B0);
tft_write_reg(0x001E,0x00B0);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0001,0x2b3F);
tft_write_reg(0x0001,0x2b3F);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0005,0x0000);
tft_write_reg(0x0005,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0006,0x0000);
tft_write_reg(0x0006,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0016,0xEF1C);
tft_write_reg(0x0016,0xEF1C);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0017,0x0103);
tft_write_reg(0x0017,0x0103);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x000B,0x0000);
tft_write_reg(0x000B,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x000F,0x0000);
tft_write_reg(0x000F,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0041,0x0000);
tft_write_reg(0x0041,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0042,0x0000);
tft_write_reg(0x0042,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0048,0x0000);
tft_write_reg(0x0048,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0049,0x013F);
tft_write_reg(0x0049,0x013F);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x004A,0x0000);
tft_write_reg(0x004A,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x004B,0x0000);
tft_write_reg(0x004B,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0044,0xEF00); // horizontal start and end
tft_write_reg(0x0044,0xEF00); // horizontal start and end
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0045,0x0000); // vertical start
tft_write_reg(0x0045,0x0000); // vertical start
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0046,0x013F); // vertical end
tft_write_reg(0x0046,0x013F); // vertical end
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0030,0x0707);
tft_write_reg(0x0030,0x0707);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0031,0x0204);
tft_write_reg(0x0031,0x0204);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0032,0x0204);
tft_write_reg(0x0032,0x0204);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0033,0x0502);
tft_write_reg(0x0033,0x0502);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0034,0x0507);
tft_write_reg(0x0034,0x0507);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0035,0x0204);
tft_write_reg(0x0035,0x0204);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0036,0x0204);
tft_write_reg(0x0036,0x0204);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0037,0x0502);
tft_write_reg(0x0037,0x0502);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x003A,0x0302);
tft_write_reg(0x003A,0x0302);
system_delay(TFT_INIT_TIMEOUT);
//ll_tft_write_reg(0x002F,0x12BE);
//tft_write_reg(0x002F,0x12BE);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x003B,0x0302);
tft_write_reg(0x003B,0x0302);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0023,0x0000);
tft_write_reg(0x0023,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0024,0x0000);
tft_write_reg(0x0024,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x0025,0x8000);
tft_write_reg(0x0025,0x8000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x004f,0x0000);
tft_write_reg(0x004f,0x0000);
system_delay(TFT_INIT_TIMEOUT);
ll_tft_write_reg(0x004e,0x0000);
tft_write_reg(0x004e,0x0000);
system_delay(TFT_INIT_TIMEOUT);
TFT_REG = TFT_SSD1289_REG_22;
return true;
}
bool ll_fsmc_init()
static bool fsmc_init()
{
// generate init structures
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
// clock enable
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
// prepare timing struct
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = TFT_SSD1289_FSMC_AST;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime = 1;
@@ -221,7 +237,8 @@ bool ll_fsmc_init()
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;
// Bank-1 / PSRAM-1
// bank-1 / PSRAM-1
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
@@ -237,6 +254,7 @@ bool ll_fsmc_init()
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
// config FSMC
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
// enable Bank-1 / PSRAM-1
@@ -245,7 +263,7 @@ bool ll_fsmc_init()
return true;
}
bool ll_gpio_init()
static bool gpio_init()
{
// generate init structure
GPIO_InitTypeDef GPIO_InitStructure;
@@ -313,67 +331,60 @@ bool ll_gpio_init()
return true;
}
/*
* ---------------------- GPIO control functions ----------------------------------------------------------
*/
// TODO
/*
* ---------------------- display control functions -------------------------------------------------------
*/
void ll_tft_set_cursor(uint16_t xpos, uint16_t ypos)
{
// set cursor
ll_tft_write_reg(TFT_SSD1289_REG_4E, ypos);
ll_tft_write_reg(TFT_SSD1289_REG_4F, 319-xpos);
TFT_REG = TFT_SSD1289_REG_22;
}
void ll_tft_set_backlight(bool state)
{
if(state){
GPIOB->BSRRH = GPIO_Pin_0;
} else {
GPIOB->BSRRL = GPIO_Pin_0;
}
}
void ll_tft_reset(bool state)
{
if(state){
GPIOB->BSRRH = GPIO_Pin_0;
} else {
GPIOB->BSRRL = GPIO_Pin_0;
}
}
void ll_tft_clear(uint16_t color)
{
uint32_t n = 0;
// set cursor to 0
ll_tft_set_cursor(0,0);
tft_set_cursor(0,0);
for(n = 0; n < TFT_PIXEL; n++) {
TFT_RAM = color;
}
}
void ll_tft_write_reg(uint8_t reg_adr, uint16_t reg_value)
static void tft_set_cursor(uint16_t xpos, uint16_t ypos)
{
// set cursor
tft_write_reg(TFT_SSD1289_REG_4E, ypos);
tft_write_reg(TFT_SSD1289_REG_4F, 319-xpos);
TFT_REG = TFT_SSD1289_REG_22;
}
static void tft_set_backlight(bool state)
{
if(state){
GPIOB->BSRRH = GPIO_Pin_0;
} else {
GPIOB->BSRRL = GPIO_Pin_0;
}
}
static void tft_reset(bool state)
{
if(state){
GPIOB->BSRRH = GPIO_Pin_0;
} else {
GPIOB->BSRRL = GPIO_Pin_0;
}
}
static void tft_write_reg(uint8_t reg_adr, uint16_t reg_value)
{
TFT_REG = reg_adr;
TFT_RAM = reg_value;
}
uint16_t ll_tft_read_reg(uint8_t reg_adr)
static uint16_t tft_read_reg(uint8_t reg_adr)
{
TFT_REG = reg_adr;
return TFT_RAM;
}
void ll_tft_set_window(uint16_t xstart, uint16_t ystart, uint16_t xend, uint16_t yend)
static void tft_set_window(uint16_t xstart, uint16_t ystart, uint16_t xend, uint16_t yend)
{
uint16_t start,end;
uint16_t ystart_end;
@@ -382,16 +393,16 @@ void ll_tft_set_window(uint16_t xstart, uint16_t ystart, uint16_t xend, uint16_t
end = ((yend & 0x00FF) << 8);
ystart_end = (start | end);
ll_tft_write_reg(TFT_SSD1289_REG_44, ystart_end);
ll_tft_write_reg(TFT_SSD1289_REG_45, 319-xend);
ll_tft_write_reg(TFT_SSD1289_REG_46, 319-xstart);
tft_write_reg(TFT_SSD1289_REG_44, ystart_end);
tft_write_reg(TFT_SSD1289_REG_45, 319-xend);
tft_write_reg(TFT_SSD1289_REG_46, 319-xstart);
}
void ll_tft_reset_window()
void tft_reset_window()
{
ll_tft_write_reg(0x44,239<<8);
ll_tft_write_reg(0x45,0);
ll_tft_write_reg(0x46,319);
tft_write_reg(0x44,239<<8);
tft_write_reg(0x45,0);
tft_write_reg(0x46,319);
}
/*
@@ -400,39 +411,37 @@ void ll_tft_reset_window()
void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
if(y1==y2){
if(x2<x1){
ll_tft_set_cursor(x2,y1);
tft_set_cursor(x2,y1);
do{
TFT_RAM = color; //Let Semi away, because of block makro
TFT_RAM = color;
} while(x2++!=x1);
} else {
ll_tft_set_cursor(x1,y1);
tft_set_cursor(x1,y1);
do{
TFT_RAM = color; //Let Semi away, because of block makro
TFT_RAM = color;
} while(x1++!=x2);
}
}
else if(x1==x2){
ll_tft_write_reg(0x11,0x6030); // Change adresspointer direction
tft_write_reg(0x11,0x6030); // Change adresspointer direction
// (is quicker than defining a region)
if(y2<y1)
{
ll_tft_set_cursor(x1,y2);
tft_set_cursor(x1,y2);
do {
TFT_RAM = color; //Let Semi away, because of block makro
TFT_RAM = color;
} while(y2++!=y1);
}
else
{
ll_tft_set_cursor(x1,y1);
tft_set_cursor(x1,y1);
do {
TFT_RAM = color; //Let Semi away, because of block makro
TFT_RAM = color;
}while(y1++!=y2);
}
ll_tft_write_reg(0x11,0x6018); // Set adresspointer direction normal again
tft_write_reg(0x11,0x6018); // Set adresspointer direction normal again
}
else
{
@@ -440,14 +449,13 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
{
//Without floating point!
int deltax = ((int)x2-(int)x1);
int deltay = ((int)y2-(int)y1)<<1; // multiple by 2 to make it easier to round
int deltay = ((int)y2-(int)y1)<<1;
int x = 0;
if (x1>x2)
{
do
{
//y = mx + b (math theory, linear functions)
ll_tft_set_cursor(x1+x,y1+ (((long)deltay*(long)x/deltax+1)>>1)); // Add 1 and divde by 2 = +0.5
tft_set_cursor(x1+x,y1+ (((long)deltay*(long)x/deltax+1)>>1));
TFT_RAM = color;
}
while(x--!=deltax);
@@ -456,7 +464,7 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
{
do
{
ll_tft_set_cursor(x1+x,y1+ (((long)deltay*(long)x/deltax+1)>>1));
tft_set_cursor(x1+x,y1+ (((long)deltay*(long)x/deltax+1)>>1));
TFT_RAM = color;
}
while(x++!=deltax);
@@ -471,7 +479,7 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
{
do
{
ll_tft_set_cursor(x1+ (((long)deltax*(long)y/deltay+1)>>1),y1+ y);
tft_set_cursor(x1+ (((long)deltax*(long)y/deltay+1)>>1),y1+ y);
TFT_RAM = color;
}
while(y--!=deltay);
@@ -480,7 +488,7 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
{
do
{
ll_tft_set_cursor(x1+ (((long)deltax*(long)y/deltay+1)>>1),y1+ y);
tft_set_cursor(x1+ (((long)deltax*(long)y/deltay+1)>>1),y1+ y);
TFT_RAM = color;
}
while(y++!=deltay);
@@ -491,7 +499,7 @@ void ll_tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16
void ll_tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color)
{
ll_tft_set_cursor(x,y);
tft_set_cursor(x,y);
TFT_RAM = color;
}
@@ -514,25 +522,19 @@ void ll_tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, u
i = x1;
ll_tft_set_cursor(x1, y1);
tft_set_cursor(x1, y1);
while(i++ != x2) TFT_RAM = color;
ll_tft_set_cursor(x1,y2);
tft_set_cursor(x1,y2);
while(i-- != x1) TFT_RAM = color;
i = y1;
ll_tft_write_reg(0x11,0x6030); // Change adresspointer direction
ll_tft_set_cursor(x2, y1);
tft_write_reg(0x11,0x6030); // Change adresspointer direction
tft_set_cursor(x2, y1);
while(i++ != y2) TFT_RAM = color;
ll_tft_set_cursor(x1, y1);
tft_set_cursor(x1, y1);
while(i-- != y1) TFT_RAM = color;
ll_tft_write_reg(0x11,0x6018); // Set adresspointer direction normal again
tft_write_reg(0x11,0x6018); // Set adresspointer direction normal again
}
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color)
@@ -541,8 +543,8 @@ void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
uint32_t n;
// set window
ll_tft_set_window(x1, y1, x2, y2);
ll_tft_set_cursor(x1, y1);
tft_set_window(x1, y1, x2, y2);
tft_set_cursor(x1, y1);
// calculate area
area = (x2 - x1 + 1) * (y2 - y1 + 1);
@@ -552,7 +554,7 @@ void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
TFT_RAM = color;
}
ll_tft_reset_window();
tft_reset_window();
}
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat)
@@ -565,7 +567,11 @@ void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
// TODO
}
const char *get_font(uint8_t font)
/*
* ---------------------- font functions -----------------------------------------------------------
*/
static const char *get_font(uint8_t font)
{
switch(font){
case 0: return small_font;
@@ -579,12 +585,14 @@ uint8_t ll_tft_num_fonts()
return 3;
}
uint8_t ll_tft_font_height(uint8_t fontnum) {
uint8_t ll_tft_font_height(uint8_t fontnum)
{
const char *font = get_font(fontnum);
return (uint8_t) font[1];
}
uint8_t ll_tft_font_width(uint8_t fontnum) {
uint8_t ll_tft_font_width(uint8_t fontnum)
{
const char *font = get_font(fontnum);
return (uint8_t) font[0];
}
@@ -603,16 +611,16 @@ void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor,
bool bgIsTrans = (bgcolor == TRANSPARENT);
bool enTrans = 0;
ll_tft_set_window(x, y, x + width - 1, y + height - 1);
ll_tft_set_cursor(x, y);
tft_set_window(x, y, x + width - 1, y + height - 1);
tft_set_cursor(x, y);
for(cnt = (width / 8) * height; cnt > 0; cnt--){
for(bitm = 0x80; bitm > 0; bitm >>= 1){
if((font[ind]) & bitm){
if(enTrans){
enTrans = 0;
ll_tft_write_reg(0x23,0x0000);
ll_tft_write_reg(0x24,0x0000);
tft_write_reg(0x23,0x0000);
tft_write_reg(0x24,0x0000);
TFT_REG = TFT_SSD1289_REG_22;
}
@@ -621,8 +629,8 @@ void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor,
} else {
if(bgIsTrans && !enTrans){
enTrans = 1;
ll_tft_write_reg(0x23,0xFFFF);
ll_tft_write_reg(0x24,0xFFFF);
tft_write_reg(0x23,0xFFFF);
tft_write_reg(0x24,0xFFFF);
TFT_REG = TFT_SSD1289_REG_22;
}
@@ -634,9 +642,9 @@ void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor,
}
if(enTrans){
ll_tft_write_reg(0x23,0x0000);
ll_tft_write_reg(0x24,0x0000);
tft_write_reg(0x23,0x0000);
tft_write_reg(0x24,0x0000);
}
ll_tft_reset_window();
tft_reset_window();
}

View File

@@ -1,21 +1,29 @@
#include "ll_touch.h"
#include"ll_touch.h"
#include<stm32f4xx_spi.h>
#include<stm32f4xx_rcc.h>
void ll_touch_read(const u16 RegisterStartAddress, const u8 NumberOfRegisters, u16 *DataBuffer, const u16 OffsetInBuffer)
#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9)
#define SET_CS GPIO_SetBits(GPIOB,GPIO_Pin_9)
/*
static void touch_read(const uint16_t RegisterStartAddress, const uint8_t NumberOfRegisters, uint16_t *DataBuffer, const uint16_t OffsetInBuffer)
{
u16 ControlValue;
u8 i,j, RegisterIndex;
u16 InputValue;
uint16_t ControlValue;
uint8_t i,j, RegisterIndex;
uint16_t InputValue;
ControlValue = 0xE400 | (RegisterStartAddress & 0x03FF); // Create the 16-bit header
ControlValue = 0xE400 | (RegisterStartAddress & 0x03FF); // Create the 16-bit header
for (i=0;i<100;i++); // delay
for (i=0;i<100;i++); // delay
//Write out the control word
GPIO_ResetBits(GPIOA, GPIO_Pin_4); // CS low
CLEAR_CS;
SPI_I2S_SendData(SPI1, ControlValue);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) != RESET);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
InputValue = SPI_I2S_ReceiveData(SPI1); // Read dummy
InputValue = SPI_I2S_ReceiveData(SPI1); // Read dummy
//Copy each register in the buffer contiguously.
//Read data in.
@@ -23,25 +31,25 @@ void ll_touch_read(const u16 RegisterStartAddress, const u8 NumberOfRegisters, u
SPI_I2S_SendData(SPI1, 0xFFFF);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) != RESET);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
InputValue = SPI_I2S_ReceiveData(SPI1); // read data
*(DataBuffer+OffsetInBuffer+RegisterIndex)=(u16)InputValue;
InputValue = SPI_I2S_ReceiveData(SPI1); // read data
*(DataBuffer+OffsetInBuffer+RegisterIndex)=(uint16_t)InputValue;
}
GPIO_SetBits(GPIOA, GPIO_Pin_4); // CS high
for (j=0;j<5;j++); // delay
SET_CS;
for (j=0;j<5;j++); // delay
}
void ll_touch_send_cmd(const u16 RegisterAddress, const u8 NumberOfRegisters, u16 *DataBuffer, const u8 OffsetInBuffer)
static void touch_send_cmd(const uint16_t RegisterAddress, const uint8_t NumberOfRegisters, uint16_t *DataBuffer, const uint8_t OffsetInBuffer)
{
u16 ControlValue;
u16 ValueToWrite;
u16 RegisterIndex;
u8 j;
uint16_t ControlValue;
uint16_t ValueToWrite;
uint16_t RegisterIndex;
uint8_t j;
ControlValue = 0xE000 | (RegisterAddress & 0x03FF); //Create the 16-bit header
ControlValue = 0xE000 | (RegisterAddress & 0x03FF); //Create the 16-bit header
//Write out the control word
GPIO_ResetBits(GPIOA, GPIO_Pin_4); // CS low
CLEAR_CS;
SPI_I2S_SendData(SPI1, ControlValue);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) != RESET);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
@@ -54,48 +62,82 @@ void ll_touch_send_cmd(const u16 RegisterAddress, const u8 NumberOfRegisters, u1
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
}
GPIO_SetBits(GPIOA, GPIO_Pin_4); // CS high
for (j=0;j<5;j++); // delay
SET_CS;
for (j=0;j<5;j++); // delay
}
*/
static uint8_t touch_send(uint8_t dat)
{
SPI_I2S_SendData(SPI2, dat);
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) != RESET);
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
return SPI_I2S_ReceiveData(SPI2);
}
bool ll_touch_init()
{
//We have a ADS7843 Touch controller
//Datasheet: http://www.ti.com/lit/ds/symlink/ads7843.pdf
return false; //TODO: remove
// init structures
SPI_InitTypeDef SPI_SPI1_InitStructure;
GPIO_InitTypeDef GPIOSPI1_InitStructure;
SPI_InitTypeDef SPI_SPI2_InitStructure;
GPIO_InitTypeDef GPIO_SPI2_InitStructure;
// enable gpio clock TODO: Check if not done already
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// enable spi clock TODO: Check if this is the correct one
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
GPIOSPI1_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; // 5 = SPI1_SCK, 6 = SPI1_MISO, 7 = SPI1_MOSI
GPIOSPI1_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIOSPI1_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIOSPI1_InitStructure);
GPIO_SPI2_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15; // 10 = SPI2_SCK, 14 = SPI2_MISO, 15 = SPI2_MOSI
GPIO_SPI2_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_SPI2_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_SPI2_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_SPI2_InitStructure);
GPIOSPI1_InitStructure.GPIO_Pin = GPIO_Pin_4; // 4 = SPI1_CS
GPIOSPI1_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIOSPI1_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIOSPI1_InitStructure);
GPIO_SPI2_InitStructure.GPIO_Pin = GPIO_Pin_9; // 9 = SPI2_CS
GPIO_SPI2_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_SPI2_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_SPI2_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_SPI2_InitStructure);
// clear spi initialisation
SPI_I2S_DeInit(SPI1);
SPI_I2S_DeInit(SPI2);
// fill spi init structure
SPI_SPI1_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_SPI1_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_SPI1_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_SPI1_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_SPI1_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_SPI1_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_SPI1_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_SPI1_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_SPI1_InitStructure.SPI_CRCPolynomial = 7;
SPI_SPI2_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_SPI2_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_SPI2_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_SPI2_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_SPI2_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_SPI2_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_SPI2_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_SPI2_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
//SPI_SPI2_InitStructure.SPI_CRCPolynomial = 7;
// init spi
SPI_Init(SPI1, &SPI_SPI1_InitStructure);
SPI_Cmd(SPI1, ENABLE);
SPI_Init(SPI2, &SPI_SPI2_InitStructure);
SPI_Cmd(SPI2, ENABLE);
//test
CLEAR_CS;
touch_send(0x90);
for(long i=0; i<1000; i++);
uint16_t buf = ((uint16_t) touch_send(0x00))<<5;
buf|= touch_send(0x00) >> 3;
SET_CS;
return true;
}

View File

@@ -2,45 +2,43 @@
DISPLAY
-------
PB0 -> LED-A (19) (Backlight) (Driver needed or LED-A Pin via 100Ohm to VCC)
PE3 -> LCD_RS (4)
PD5 -> LCD_WR (5)
PD4 -> LCD_RD (6)
PD7 -> LCD_CS (15)
PD14 -> LCD_D0 (21)
PD15 -> LCD_D1 (22)
PD0 -> LCD_D2 (23)
PD1 -> LCD_D3 (24)
PE7 -> LCD_D4 (25)
PE8 -> LCD_D5 (26)
PE9 -> LCD_D6 (27)
PE10 -> LCD_D7 (28)
PE11 -> LCD_D8 (7)
PE12 -> LCD_D9 (8)
PE13 -> LCD_D10 (9)
PE14 -> LCD_D11 (10)
PE15 -> LCD_D12 (11)
PD8 -> LCD_D13 (12)
PD9 -> LCD_D14 (13)
PD10 -> LCD_D15 (14)
PB0 -> LED-A (19) (Backlight) (Driver needed or LED-A Pin via 100Ohm to VCC)
PE3 -> LCD_RS (4)
PD5 -> LCD_WR (5)
PD4 -> LCD_RD (6)
PD7 -> LCD_CS (15)
PD14 -> LCD_D0 (21)
PD15 -> LCD_D1 (22)
PD0 -> LCD_D2 (23)
PD1 -> LCD_D3 (24)
PE7 -> LCD_D4 (25)
PE8 -> LCD_D5 (26)
PE9 -> LCD_D6 (27)
PE10 -> LCD_D7 (28)
PE11 -> LCD_D8 (7)
PE12 -> LCD_D9 (8)
PE13 -> LCD_D10 (9)
PE14 -> LCD_D11 (10)
PE15 -> LCD_D12 (11)
PD8 -> LCD_D13 (12)
PD9 -> LCD_D14 (13)
PD10 -> LCD_D15 (14)
SD-Karte
--------
PA4 -> SD_CS (38)
PA5 -> SD_SCK (36)
PA6 -> SD_DIN ? (37)
PA7 -> SD_OUT ? (35)
PA4 -> SD_CS (38)
PA5 -> SD_SCK (36)
PA6 (MISO) -> SD_OUT (35)
PA7 (MOSI) -> SD_DIN (37)
Touch Controller
----------------
PB9 -> D_CS (30)
PB10 -> D_CLK (29)
PB14 -> D_DIN ? (31)
PB15 -> D_OUT ? (33)
PB9 -> D_CS (30)
PB10 -> D_CLK (29)
PB14 (MISO) -> D_OUT (33)
PB15 (MOSI) -> D_DIN (31)
Interrupts
----------
PA0 -> D_Penirq (34)
PB2 -> D_BUSY (32)
PA0 -> D_Penirq (34)
PB2 -> D_BUSY (32)

BIN
doc/datasheet_ads7843.pdf Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long