├── 365calendar.py ├── 365calendar.sh ├── Makefile ├── README.md ├── bing_wallpaper.py ├── bing_wallpaper.sh ├── demo.c ├── draw.c ├── draw1.txt ├── draw2.txt ├── driver ├── ili9225.c ├── ili9225.h ├── ili9320.c ├── ili9320.h ├── ili9325.c ├── ili9325.h ├── ili9327.c ├── ili9327.h ├── ili9341.c ├── ili9341.h ├── ili9342.c ├── ili9342.h ├── ili9481.c ├── ili9481.h ├── ili9486.c ├── ili9486.h ├── ili9488.c ├── ili9488.h ├── lgdp4532.c ├── lgdp4532.h ├── r61509.c ├── r61509.h ├── s6d1121.c ├── s6d1121.h ├── st7781.c └── st7781.h ├── fontx.c ├── fontx.h ├── fontx ├── ILGH16XB.FNT ├── ILGH24XB.FNT ├── ILGH32XB.FNT ├── ILGZ16XB.FNT ├── ILGZ16XF.FNT ├── ILGZ24XB.FNT ├── ILGZ32XB.FNT ├── ILMH16XB.FNT ├── ILMH24XB.FNT ├── ILMH24XF.FNT ├── ILMH32XB.FNT ├── ILMH32XF.FNT ├── ILMZ16XB.FNT ├── ILMZ16XF.FNT ├── ILMZ24XB.FNT ├── ILMZ24XF.FNT ├── ILMZ32XB.FNT └── ILMZ32XF.FNT ├── images ├── RaspberryPi_logo.jpeg ├── RaspberryPi_logo.png ├── Ubuntu_log.jpeg └── Ubuntu_log.png ├── jpegtest.c ├── me.sh ├── pin.conf ├── pin.conf.26pin ├── pin.conf.40pin ├── pngle ├── decode_png.c ├── decode_png.h ├── miniz.c ├── miniz.h ├── pngle.c └── pngle.h ├── pngtest.c ├── rgb2color.c ├── tft_lib.c ├── tft_lib.h ├── tjpgd2 ├── decode_jpeg.c ├── decode_jpeg.h ├── tjpgd.c ├── tjpgd.h └── tjpgdcnf.h ├── touch.c ├── xpt.c ├── xpt2046.c └── xpt2046.h /365calendar.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | import sys 5 | import datetime 6 | import shutil 7 | import inspect 8 | 9 | #python2 10 | #import urllib2 11 | #from HTMLParser import HTMLParser 12 | 13 | #python3 14 | import urllib.request 15 | from html.parser import HTMLParser 16 | 17 | # How to Install Pillow 18 | # sudo apt install libtiff5 19 | # python -m pip install -U Pillow 20 | from PIL import Image, ImageFilter 21 | 22 | 23 | DEBUG = 0 24 | 25 | def downloadImage(url, savename): 26 | function_name = inspect.currentframe().f_code.co_name 27 | if DEBUG: print("{} url={} savename={}".format(function_name,url,savename)) 28 | print("Downloading from {}".format(url)) 29 | #img = urllib.urlopen(url) 30 | img = urllib.request.urlopen(url) 31 | localfile = open(savename, 'wb') 32 | localfile.write(img.read()) 33 | img.close() 34 | localfile.close() 35 | 36 | def rotateImage(filename): 37 | function_name = inspect.currentframe().f_code.co_name 38 | tmpfile = os.path.join(os.getcwd(), "__temp.jpeg") 39 | if DEBUG: print("{} tmpfile={}".format(function_name,tmpfile)) 40 | shutil.copyfile(filename, tmpfile) 41 | im = Image.open(tmpfile) 42 | im_rotate = im.rotate(90, expand=True) 43 | im_rotate.save(filename) 44 | os.remove(tmpfile) 45 | 46 | 47 | def get_url_root(url): 48 | if("http://" in url): 49 | url_delet_http = url.lstrip("http://") 50 | if("/" in url_delet_http): 51 | url_root = "http://" + url_delet_http[0:url_delet_http.find("/")] 52 | return url_root 53 | elif("https://" in url): 54 | url_delet_http = url.lstrip("https://") 55 | if("/" in url_delet_http): 56 | url_root = "http://" + url_delet_http[0:url_delet_http.find("/")] 57 | return url_root 58 | return 0 59 | 60 | class imgParser(HTMLParser): 61 | 62 | def __init__(self): 63 | HTMLParser.__init__(self) 64 | 65 | def handle_starttag(self,tagname,attribute): 66 | if tagname.lower() == "img": 67 | for i in attribute: 68 | if i[0].lower() == "src": 69 | img_url=i[1] 70 | # 取得した写真のURLを集めたファイルの作成 71 | f = open("collection_url.txt","a") 72 | f.write("%s\t"%img_url) 73 | f.close() 74 | 75 | if __name__ == "__main__": 76 | argvs = sys.argv 77 | argc = len(argvs) 78 | if argc == 1: 79 | print("{0:s} SaveFileName id year".format(argvs[0])) 80 | sys.exit(1) 81 | 82 | savefile = argvs[1] 83 | id = argvs[2] 84 | year = argvs[3] 85 | #print("id={:s} year={:s}{}".format(id, year, type(year))) 86 | date_file = os.path.dirname(savefile) + "/date.gif" 87 | month_file = os.path.dirname(savefile) + "/month.gif" 88 | 89 | NowDate = datetime.datetime.now() 90 | #print("{:04d} {:02d} {:02d}".format(NowDate.year, NowDate.month, NowDate.day)) 91 | #input_url = "http://www.365calendar.net/index?action=user_calendar_detail&calendar_id={0:s}&target={1:%Y%m%d}".format(id,NowDate) 92 | input_url = "http://www.365calendar.net/index?action=user_calendar_detail&calendar_id={:s}&target={:s}{:02d}{:02d}".format(id,year,NowDate.month,NowDate.day) 93 | if DEBUG: print("input_url={}".format(input_url)) 94 | serch_url = input_url 95 | #htmldata = urllib2.urlopen(serch_url) 96 | htmldata = urllib.request.urlopen(serch_url) 97 | 98 | date_url = "http://www.365calendar.net/lib_image/calendar/img_num{0:%-d}.gif".format(NowDate) 99 | if DEBUG: print("date_url={}".format(date_url)) 100 | 101 | month_url = "http://www.365calendar.net/lib_image/calendar/img_num{0:%-m}.gif".format(NowDate) 102 | if DEBUG: print("month_url={}".format(month_url)) 103 | 104 | parser = imgParser() 105 | data = htmldata.read() 106 | #print("type(data)={}".format(type(data))) 107 | data = data.decode() 108 | #print("type(data)={}".format(type(data))) 109 | #parser.feed(htmldata.read()) 110 | parser.feed(data) 111 | 112 | parser.close() 113 | htmldata.close() 114 | 115 | # 生成したファイルの読み込み 116 | f = open("collection_url.txt","r") 117 | for row in f: 118 | row_url = row.split('\t') 119 | len_url = len(row_url) 120 | f.close() 121 | 122 | number_url = [] 123 | if(DEBUG): print("len_url={}".format(len_url)) 124 | 125 | for i in range(0,(len_url-1)): 126 | number_url.append(row_url[i]) 127 | 128 | rcode = 1 129 | for j in range(0,(len_url-1)): 130 | url = number_url[j] 131 | if DEBUG: print("url={}".format(url)) 132 | if not "user_photo.php" in url: 133 | continue 134 | 135 | root_url = get_url_root(serch_url) 136 | if DEBUG: print("root_url={}".format(root_url)) 137 | downloadImage(root_url + url, savefile) 138 | rotateImage(savefile) 139 | #downloadImage(date_url, date_file) 140 | #downloadImage(month_url, month_file) 141 | rcode = 0 142 | 143 | 144 | # ファイルの削除 145 | os.remove("collection_url.txt") 146 | sys.exit(rcode) 147 | -------------------------------------------------------------------------------- /365calendar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | #for debug 5 | function __echo () { 6 | echo $1 7 | echo $1 >> $DrawFile 8 | } 9 | 10 | function _echo () { 11 | echo $1 >> $DrawFile 12 | } 13 | 14 | # download image from https://www.365calendar.net/ 15 | # List is here https://www.365calendar.net/calendar/list.html#dogBlock 16 | # download from https://www.365calendar.net/index?action=user_calendar_detail&calendar_id=${id}&target=${YYMMDD} 17 | # https://www.365calendar.net/index?action=user_calendar_detail&calendar_id=1184&target=20210101 18 | # id = 1166 : 2021 welshcorgi 19 | # id = 1167 : 2021 shetlandsheepdog 20 | # id = 1168 : 2021 pekingese 21 | # id = 1170 : 2021 miniatureschnauzer 22 | # id = 1172 : 2021 dachshund 23 | # id = 1173 : 2021 cavalierkingcharles 24 | # id = 1175 : 2021 maltese 25 | # id = 1178 : 2021 pomeranian 26 | # id = 1185 : 2021 nihonken 27 | # id = 1191 : 2021 papillon 28 | imageFile="images/dailyImage.jpeg" 29 | #python 365calendar.py ${imageFile} 1131 30 | 31 | second=`date "+%S"` 32 | second=$((second%10)) 33 | if [ $second = 0 ]; then 34 | python 365calendar.py ${imageFile} 1166 2021 35 | elif [ $second = 1 ]; then 36 | python 365calendar.py ${imageFile} 1167 2021 37 | elif [ $second = 2 ]; then 38 | python 365calendar.py ${imageFile} 1168 2021 39 | elif [ $second = 3 ]; then 40 | python 365calendar.py ${imageFile} 1170 2021 41 | elif [ $second = 4 ]; then 42 | python 365calendar.py ${imageFile} 1172 2021 43 | elif [ $second = 5 ]; then 44 | python 365calendar.py ${imageFile} 1173 2021 45 | elif [ $second = 6 ]; then 46 | python 365calendar.py ${imageFile} 1175 2021 47 | elif [ $second = 7 ]; then 48 | python 365calendar.py ${imageFile} 1178 2021 49 | elif [ $second = 8 ]; then 50 | python 365calendar.py ${imageFile} 1185 2021 51 | elif [ $second = 9 ]; then 52 | python 365calendar.py ${imageFile} 1191 2021 53 | fi 54 | 55 | DrawFile="./draw.txt" 56 | if [ -f ${DrawFile} ]; then 57 | rm $DrawFile 58 | fi 59 | 60 | #Inquiry tft information 61 | screen_width=`./draw width` 62 | screen_height=`./draw height` 63 | driver_name=`./draw driver` 64 | echo -n "Your TFT is " 65 | echo -n ${driver_name} 66 | echo -n " " 67 | echo -n ${screen_width} 68 | echo -n "x" 69 | echo ${screen_height} 70 | 71 | #Black(0x000000) 72 | _echo "FillScrren,0x0000" 73 | _echo "JPEG,${imageFile}" 74 | 75 | ./draw $DrawFile > /dev/null 76 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DRIVER_LIB = driver.a 2 | DRIVER_DIR = driver 3 | DRIVER_SRCS = $(wildcard $(DRIVER_DIR)/*.c) 4 | DRIVER_OBJS = $(subst .c,.o,$(DRIVER_SRCS)) 5 | 6 | JPEG_LIB = jpeg.a 7 | JPEG_DIR = tjpgd2 8 | JPEG_SRCS = $(wildcard $(JPEG_DIR)/*.c) 9 | JPEG_OBJS = $(subst .c,.o,$(JPEG_SRCS)) 10 | 11 | PNG_LIB = png.a 12 | PNG_DIR = pngle 13 | PNG_SRCS = $(wildcard $(PNG_DIR)/*.c) 14 | PNG_OBJS = $(subst .c,.o,$(PNG_SRCS)) 15 | 16 | ARFLAG = crv 17 | 18 | SRCS = demo.c draw.c rgb2color.c fontx.c tft_lib.c $(DRIVER_LIB) $(JPEG_LIB) $(PNG_LIB) 19 | LIBS = $(DRIVER_LIB) $(JPEG_LIB) $(PNG_LIB) 20 | 21 | $(DRIVER_LIB) : $(DRIVER_OBJS) $(DRIVER_SRCS) 22 | $(AR) $(ARFLAG) $(DRIVER_LIB) $(DRIVER_OBJS) 23 | @rm -f $(DRIVER_OBJS) 24 | @echo "$(DRIVER_LIB) make success" 25 | 26 | $(JPEG_LIB) : $(JPEG_OBJS) $(JPEG_SRCS) 27 | $(AR) $(ARFLAG) $(JPEG_LIB) $(JPEG_OBJS) 28 | @rm -f $(JPEG_OBJS) 29 | @echo "$(JPEG_LIB) make success" 30 | 31 | $(PNG_LIB) : $(PNG_OBJS) $(PNG_SRCS) 32 | $(AR) $(ARFLAG) $(PNG_LIB) $(PNG_OBJS) 33 | @rm -f $(PNG_OBJS) 34 | @echo "$(PNG_LIB) make success" 35 | 36 | 37 | ILI9225 : $(SRCS) 38 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 39 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 40 | cc -o rgb2color rgb2color.c 41 | 42 | ILI9320 : $(SRCS) 43 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 44 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 45 | cc -o rgb2color rgb2color.c 46 | 47 | ILI9325 : $(SRCS) 48 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 49 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 50 | cc -o rgb2color rgb2color.c 51 | 52 | ILI9327 : $(SRCS) 53 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 54 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 55 | cc -o rgb2color rgb2color.c 56 | 57 | ILI9341 : $(SRCS) 58 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 59 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 60 | cc -o rgb2color rgb2color.c 61 | cc -o jpegtest jpegtest.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 62 | cc -o pngtest pngtest.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 63 | 64 | ILI9342 : $(SRCS) 65 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 66 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 67 | cc -o rgb2color rgb2color.c 68 | 69 | ILI9481 : $(SRCS) 70 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 71 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 72 | cc -o rgb2color rgb2color.c 73 | 74 | ILI9486 : $(SRCS) 75 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 76 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 77 | cc -o rgb2color rgb2color.c 78 | 79 | ILI9488 : $(SRCS) 80 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 81 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 82 | cc -o rgb2color rgb2color.c 83 | 84 | ILI9488-INVERT : $(SRCS) 85 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -DILI9488 -DINVERT 86 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -DILI9488 -DINVERT 87 | cc -o rgb2color rgb2color.c 88 | 89 | SPFD5408 : $(SRCS) 90 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 91 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 92 | cc -o rgb2color rgb2color.c 93 | 94 | R61505U : $(SRCS) 95 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 96 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 97 | cc -o rgb2color rgb2color.c 98 | 99 | R61509V : $(SRCS) 100 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 101 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 102 | cc -o rgb2color rgb2color.c 103 | 104 | S6D1121 : $(SRCS) 105 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 106 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 107 | cc -o rgb2color rgb2color.c 108 | 109 | ST7775 : $(SRCS) 110 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 111 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 112 | cc -o rgb2color rgb2color.c 113 | 114 | ST7781 : $(SRCS) 115 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 116 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 117 | cc -o rgb2color rgb2color.c 118 | 119 | ST7783 : $(SRCS) 120 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 121 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 122 | cc -o rgb2color rgb2color.c 123 | 124 | ST7793 : $(SRCS) 125 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 126 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 127 | cc -o rgb2color rgb2color.c 128 | 129 | ST7796 : $(SRCS) 130 | cc -o demo demo.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 131 | cc -o draw draw.c fontx.c tft_lib.c $(LIBS) -lwiringPi -lm -lpthread -D$@ 132 | cc -o rgb2color rgb2color.c 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 8Bit/16Bit Parallel TFT Library for WiringPi 2 | 3 | This is library for RaspberryPi. 4 | You can use a TFT Shield for UNO R3. 5 | This library can show a chart to TFT Shield. 6 | 7 | ![TFT-Shield](https://user-images.githubusercontent.com/6020549/104253960-10a71380-54b9-11eb-8789-a12c2c769ab4.JPG) 8 | 9 | Primarily, these TFT Shiled is the one for Arduino. 10 | This may works with other boards like OrangePi/NanoPi. 11 | 12 | # Supported TFT controllers: 13 | 14 | ## Generic 8bit Sheild 15 | - ILI9320(240x320) 16 | - ILI9325(240x320) 17 | - ILI9341(240x320) 18 | - ILI9342(240x320) 19 | - ILI9481(320x480) 20 | - ILI9486(320x480) 21 | - ILI9488(320x480) 22 | - SPFD5408(240x320 Same as ILI9320) 23 | - R61505U(240x320 Same as ILI9320) 24 | - R61509V(240x400) 25 | - ST7781(240x320) 26 | - ST7783(240x320 Same as ST7781) 27 | - ST7793(240x400 Same as R61509) 28 | - ST7796(320x480 Same as ILI9486) 29 | 30 | ## Generic 16bit Sheild 31 | - ILI9341(240x320) 32 | 33 | ## OPEN-SMART Products 34 | - OPEN-SMART ILI9225 TFT-Shield(176x220) 35 | - OPEN-SMART ILI9327 TFT-Shield(240x400) 36 | - OPEN-SMART ILI9340 TFT-Shield(240x320) 37 | - OPEN-SMART S6D1121 16Pin-Parallel(240x320) 38 | - OPEN-SMART ST7775 16Pin-Parallel(176x220 Same as ILI9225) 39 | - OPEN-SMART ST7783 16Pin-Parallel(240x320) 40 | - OPEN-SMART R61509V 16Pin-Parallel(240x400) 41 | - OPEN-SMART ILI9488 16Pin-Parallel(320x400 Color inversion) 42 | 43 | These are all 2.4 inch, 320x240 TFTs. 44 | ![TFT-SHIELD-2](https://user-images.githubusercontent.com/6020549/104244320-873a1600-54a5-11eb-93c0-9fad671fdfed.JPG) 45 | 46 | 3.95 inches is almost twice as large as 2.4 inches. 47 | ![TFT-SHIELD-3](https://user-images.githubusercontent.com/6020549/104244328-8903d980-54a5-11eb-8c9a-d26408e04f92.JPG) 48 | 49 | These are OPEN-SMART 16Pin-Parallel Products. 50 | ![OPEN-SMART-16Pin](https://user-images.githubusercontent.com/6020549/110071604-ad9e7280-7dbf-11eb-8e09-a9ebfacfd795.JPG) 51 | 52 | ---- 53 | 54 | # Software requirement 55 | - WiringPi Library 56 | This project uses the wiringPiSetup() function to initialize GPIOs. 57 | If you use it on a board other than the RPI board, you may need to change the GPIO number. 58 | As far as I know, there are these libraries. 59 | - WiringPi for OrangePi 60 | - WiringPi for OrangePi Zero 61 | - WiringPi for OrangePi3 62 | - WiringPi for BananaPi 63 | - WiringPi for NanoPi 64 | - WiringPi for Pine-64 65 | 66 | ---- 67 | 68 | # Wirering for 8Bit Parallel 69 | 70 | |TFT||RPI| 71 | |:-:|:-:|:-:| 72 | |LCD_RST|--|Pin#7| 73 | |LCD_CS|--|Pin#3| 74 | |LCD_RS|--|Pin#5| 75 | |LCD_WR|--|Pin#26| 76 | |LCD_RD|--|Pin#28| 77 | |LCD_D0|--|Pin#29| 78 | |LCD_D1|--|Pin#31| 79 | |LCD_D2|--|Pin#33| 80 | |LCD_D3|--|Pin#35| 81 | |LCD_D4|--|Pin#37| 82 | |LCD_D5|--|Pin#32| 83 | |LCD_D6|--|Pin#36| 84 | |LCD_D7|--|Pin#38| 85 | |5V|--|5V(*)| 86 | |3.3V|--|3.3V(*)| 87 | |GND|--|GND| 88 | 89 | \*When a regulator(It's often AMS1117) is mounted on the back, it's operated 5V. 90 | \*When a regulator is NOT mounted on the back, it's operated 3.3V. 91 | 92 | __NOTE__ 93 | My R61509V has a regulator on the back. 94 | Normally, a TFT with a regulator works at 5V, but my R61509V doesn't work unless I supply both 5V and 3.3V. 95 | 96 | __NOTE__ 97 | You can change any pin. 98 | Pin define is "pin.conf". 99 | If you use a 26-pin header, you can use "pin.conf.26pin" instead of "pin.conf". 100 | 101 | ---- 102 | 103 | # Build 104 | 105 | - for ILI9225 106 | `make ILI9225` 107 | 108 | - for ILI9320 109 | `make ILI9320` 110 | 111 | - for ILI9325 112 | `make ILI9325` 113 | 114 | - for ILI9327 115 | `make ILI9327` 116 | 117 | - for ILI9341 118 | `make ILI9341` 119 | 120 | - for ILI9342 121 | `make ILI9342` 122 | 123 | - for ILI9481 124 | `make ILI9481` 125 | 126 | - for ILI9486 127 | `make ILI9486` 128 | 129 | - for ILI9488 130 | `make ILI9488` 131 | 132 | - for ILI9488 Inversion Color 133 | `make ILI9488-INVERT` 134 | 135 | - for SPFD5408 136 | `make SPFD5408` 137 | 138 | - for R61505U 139 | `make R61505U` 140 | 141 | - for R61509V 142 | `make R61509V` 143 | 144 | - for S6D1121 145 | `make S6D1121` 146 | 147 | - for ST7775 148 | `make ST7775` 149 | 150 | - for ST7781 151 | `make ST7781` 152 | 153 | - for ST7783 154 | `make ST7783` 155 | 156 | - for ST7793 157 | `make ST7793` 158 | 159 | - for ST7796 160 | `make ST7796` 161 | 162 | ---- 163 | 164 | # How to find the TFT driver name 165 | ![](https://img.shields.io/badge/_IMPORTANT-important) 166 | The information provided by sellers on Ebay or AliExpress is largely incorrect. 167 | You waste time if you don't choose the right driver. 168 | There are many [variations](http://domoticx.com/arduino-shield-2-4-tft-lcd-touch/) of the 2.4 inch shield. 169 | You can use [this](https://github.com/prenticedavid/MCUFRIEND_kbv/tree/master/examples/LCD_ID_readreg) to find out your driver. 170 | This is for Arduino UNO. 171 | Do not use this on the RPI as the GPIO on the RPI is not 5V tolerant. 172 | __Never believe the seller's information.__ 173 | 174 | ---- 175 | 176 | # Graphic support 177 | ![ILI9341-10](https://user-images.githubusercontent.com/6020549/59558184-52df4900-9027-11e9-8e80-7c85fdb4213c.JPG) 178 | ![ILI9341-12](https://user-images.githubusercontent.com/6020549/59558186-5377df80-9027-11e9-88a8-4c8c4df9a830.JPG) 179 | ![ILI9341-13](https://user-images.githubusercontent.com/6020549/59558187-5377df80-9027-11e9-8f72-a7ebbbe57c0b.JPG) 180 | ![ILI9341-14](https://user-images.githubusercontent.com/6020549/59558188-5377df80-9027-11e9-99f7-de3c8b1878dd.JPG) 181 | ![ILI9341-18](https://user-images.githubusercontent.com/6020549/59558192-54107600-9027-11e9-946c-39443ae83053.JPG) 182 | 183 | # Fonts support 184 | ![ILI9341-11](https://user-images.githubusercontent.com/6020549/59558185-52df4900-9027-11e9-84d6-cf6e69051ce8.JPG) 185 | ![ILI9341-15](https://user-images.githubusercontent.com/6020549/59558189-54107600-9027-11e9-89eb-39e8f2cbeab2.JPG) 186 | ![ILI9341-16](https://user-images.githubusercontent.com/6020549/59558190-54107600-9027-11e9-9d23-d71c3997a3d0.JPG) 187 | ![ILI9341-17](https://user-images.githubusercontent.com/6020549/59558191-54107600-9027-11e9-888c-a1485758e943.JPG) 188 | ![ILI9341-19](https://user-images.githubusercontent.com/6020549/59558183-52df4900-9027-11e9-9a79-8969d47f902e.JPG) 189 | 190 | # Image support 191 | JPEG file 192 | ![ILI9341-JPEG](https://user-images.githubusercontent.com/6020549/118343557-c2884680-b564-11eb-9009-cd29ff6c0bdb.JPG) 193 | PNG file 194 | ![ILI9341-PNG](https://user-images.githubusercontent.com/6020549/118343563-cddb7200-b564-11eb-983f-8d09fc5c52cd.JPG) 195 | 196 | ---- 197 | 198 | # Start Auto Demo 199 | ./demo 200 | 201 | # Start Interpreter mode 202 | You can change draw1.txt & draw2.txt & me.sh 203 | 204 | `./draw draw1.txt` 205 | `./draw draw2.txt` 206 | `bash ./me.sh` 207 | 208 | ![me_sh](https://user-images.githubusercontent.com/6020549/118217481-8398b900-b4b0-11eb-91b7-1d7e14ef6ab8.JPG) 209 | 210 | ## Take animal picture from www.365calendar.net and display. 211 | To use this, you need python3 and Pillow. 212 | And reduce the security level of OpenSSL encryption. 213 | ``` 214 | $ sudo apt install libtiff5 libopenjp2-7 215 | $ python -m pip install -U Pillow 216 | $ sudo cp /usr/lib/ssl/openssl.cnf /usr/lib/ssl/openssl.cnf.old 217 | $ sudo vi /usr/lib/ssl/openssl.cnf 218 | #CipherString = DEFAULT@SECLEVEL=2 219 | CipherString = DEFAULT@SECLEVEL=1 220 | $ bash ./365calendar.sh 221 | ``` 222 | 223 | ![365calendar](https://user-images.githubusercontent.com/6020549/130392539-d335b6ee-c335-4305-8830-887833b2e61d.JPG) 224 | 225 | ## Take wallpaper from bing and display 226 | To use this, you need python3 and imagemagick. 227 | ``` 228 | $ sudo apt install imagemagick 229 | $ bash ./bing_wallpaper.sh 230 | ``` 231 | 232 | ![bing_wallpaper](https://user-images.githubusercontent.com/6020549/130392570-7da882dc-a357-4370-8c24-5b238456066a.JPG) 233 | 234 | ---- 235 | 236 | # Wirering for 16Bit Parallel 237 | |TFT||RPI| 238 | |:-:|:-:|:-:| 239 | |LCD_RST|--|Pin#7| 240 | |LCD_CS|--|Pin#3| 241 | |LCD_RS|--|Pin#5| 242 | |LCD_WR|--|Pin#26| 243 | |LCD_RD|--|Pin#28| 244 | |LCD_D0|--|Pin#29| 245 | |LCD_D1|--|Pin#31| 246 | |LCD_D2|--|Pin#33| 247 | |LCD_D3|--|Pin#35| 248 | |LCD_D4|--|Pin#37| 249 | |LCD_D5|--|Pin#32| 250 | |LCD_D6|--|Pin#36| 251 | |LCD_D7|--|Pin#38| 252 | |LCD_D8|--|Pin#13| 253 | |LCD_D9|--|Pin#15| 254 | |LCD_D10|--|Pin#16| 255 | |LCD_D11|--|Pin#18| 256 | |LCD_D12|--|Pin#8| 257 | |LCD_D13|--|Pin#10| 258 | |LCD_D14|--|Pin#40| 259 | |LCD_D15|--|Pin#27| 260 | |5V|--|5V(*)| 261 | |3.3V|--|3.3V(*)| 262 | |GND|--|GND| 263 | 264 | \*When a regulator(It's often AMS1117) is mounted on the back, it's operated 5V. 265 | \*When a regulator is NOT mounted on the back, it's operated 3.3V. 266 | 267 | __NOTE__ 268 | You can change any pin. 269 | Pin define is "pin.conf". 270 | 271 | ---- 272 | 273 | # Build 274 | `cc -o demo demo.c fontx.c tft_lib.c driver/*.c -lwiringPi -lm -lpthread -DILI9341 -DP16BIT` 275 | `cc -o draw draw.c fontx.c tft_lib.c driver/*.c -lwiringPi -lm -lpthread -DILI9341 -DP16BIT` 276 | 277 | ---- 278 | 279 | # Start Auto Demo 280 | `./demo` 281 | 282 | ![ili9341-16bit-1](https://user-images.githubusercontent.com/6020549/42122957-c62b7b66-7c84-11e8-8619-5c4ab0d624f5.JPG) 283 | 284 | ![ili9341-16bit-2](https://user-images.githubusercontent.com/6020549/42122960-c92f25e2-7c84-11e8-970b-11f0f08a88cd.JPG) 285 | 286 | ---- 287 | 288 | # SPI Touch Sensor 289 | ![ili9341-16bit-2](https://user-images.githubusercontent.com/6020549/42122960-c92f25e2-7c84-11e8-970b-11f0f08a88cd.JPG) 290 | This module has SPI Touch Sensor. 291 | So you can read touch position. 292 | Use raspi-config to enable SPI. 293 | 294 | Wirering for SPI-Touch sensor 295 | 296 | |TFT||RPI| 297 | |:-:|:-:|:-:| 298 | |PEN|--|Pin#22(\*\*)| 299 | |T_CS|--|Pin#24(\*\*)| 300 | |MOSI|--|Pin#19(\*\*\*)| 301 | |MISO|--|Pin#21(\*\*\*)| 302 | |CLK|--|Pin#23(\*\*\*)| 303 | 304 | 305 | \*\*It's defined in the source code. 306 | #define SPI_CHANNEL 0 // /dev/spidev0.0 307 | //#define SPI_CHANNEL 1 // /dev/spidev0.1 308 | #define GPIO_PEN 6 309 | 310 | \*\*\*Can't change 311 | 312 | ``` 313 | cc -o xpt xpt.c xpt2046.c -lwiringPi -lm -lpthread 314 | sudo ./xpt 315 | ``` 316 | 317 | ![touch-1](https://user-images.githubusercontent.com/6020549/42130602-8710a000-7d24-11e8-9b8e-b1819301bc0f.jpg) 318 | 319 | 320 | And you can operate Pi using touch sensor. 321 | ``` 322 | cc -o touch touch.c fontx.c tft_lib.c driver/ili9341.c xpt2046.c -lwiringPi -lm -lpthread -DILI9341 -DP16BIT 323 | sudo ./touch 324 | ``` 325 | 326 | 327 | ![touch-2](https://user-images.githubusercontent.com/6020549/42130606-8b7c0ed6-7d24-11e8-97e8-41f7cf18d4bc.JPG) 328 | 329 | ---- 330 | 331 | # 4-wire resistive touch screen 332 | OPEN SMART products have 4-wire resistive touch screen, but Pi cannot use this because Pi cannot input analog. 333 | 334 | --- 335 | 336 | # JPEG Decoder 337 | This project uses [this](http://elm-chan.org/fsw/tjpgd/00index.html) JPEG library. 338 | This can reduce the image to 1/2 1/4 1/8. 339 | 340 | --- 341 | 342 | # PNG Decoder 343 | I ported the pngle library from [here](https://github.com/kikuchan/pngle). 344 | This can reduce the image to any size. 345 | 346 | --- 347 | 348 | -------------------------------------------------------------------------------- /bing_wallpaper.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python3 2 | # Author: Maximilian Muth 3 | # https://github.com/mammuth/bing-wallpaper 4 | # Version: 1.0 5 | # License: GPL-2.0 6 | # Description: Downloads the Bing picture of the Day and sets it as wallpaper (Linux / Windows). 7 | 8 | import datetime 9 | from urllib.request import urlopen, urlretrieve 10 | from xml.dom import minidom 11 | import os 12 | import sys 13 | 14 | import shutil 15 | import inspect 16 | 17 | # How to Install Pillow 18 | # sudo apt install libtiff5 19 | # python -m pip install -U Pillow 20 | from PIL import Image, ImageFilter 21 | 22 | 23 | def rotateImage(filename): 24 | function_name = inspect.currentframe().f_code.co_name 25 | tmpfile = os.path.join(os.getcwd(), "__temp.jpeg") 26 | #print("{} tmpfile={}".format(function_name,tmpfile)) 27 | shutil.copyfile(filename, tmpfile) 28 | im = Image.open(tmpfile) 29 | im_rotate = im.rotate(90, expand=True) 30 | im_rotate.save(filename) 31 | os.remove(tmpfile) 32 | 33 | 34 | """ 35 | def join_path(*args): 36 | # Takes an list of values or multiple values and returns an valid path. 37 | if isinstance(args[0], list): 38 | path_list = args[0] 39 | else: 40 | path_list = args 41 | val = [str(v).strip(' ') for v in path_list] 42 | return os.path.normpath('/'.join(val)) 43 | """ 44 | 45 | 46 | def download_wallpaper(idx, pic_path): 47 | # Getting the XML File 48 | try: 49 | usock = urlopen(''.join(['http://www.bing.com/HPImageArchive.aspx?format=xml&idx=', 50 | str(idx), '&n=1&mkt=ru-RU'])) # ru-RU, because they always have 1920x1200 resolution 51 | except Exception as e: 52 | print('Error while downloading #', idx, e) 53 | return 54 | try: 55 | xmldoc = minidom.parse(usock) 56 | # This is raised when there is trouble finding the image url. 57 | except Exception as e: 58 | print('Error while processing XML index #', idx, e) 59 | return 60 | # Parsing the XML File 61 | for element in xmldoc.getElementsByTagName('url'): 62 | url = 'http://www.bing.com' + element.firstChild.nodeValue 63 | #print("url={}".format(url)) 64 | # Get Current Date as fileName for the downloaded Picture 65 | now = datetime.datetime.now() 66 | date = now - datetime.timedelta(days=int(idx)) 67 | #print('Downloading: ', date.strftime('%d-%m-%Y'), 'index #', idx) 68 | 69 | # Download and Save the Picture 70 | # Get a higher resolution by replacing the file name 71 | urlretrieve(url.replace('_1366x768', '_1920x1200'), pic_path) 72 | print("Downloading from {}".format(url)) 73 | rotateImage(pic_path) 74 | 75 | if __name__ == "__main__": 76 | args = sys.argv 77 | argc = len(args) 78 | #print("args[1]={}".format(args[1])) 79 | #download_wallpaper(0, "./images/bing_wall_paper.jpeg") 80 | download_wallpaper(0, args[1]) 81 | -------------------------------------------------------------------------------- /bing_wallpaper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Software requirment 4 | # sudo apt install imagemagick 5 | # 6 | 7 | #set -x 8 | 9 | #for debug 10 | function __echo () { 11 | echo $1 12 | echo $1 >> $DrawFile 13 | } 14 | 15 | function _echo () { 16 | echo $1 >> $DrawFile 17 | } 18 | 19 | # download image from https://blog.atwork.at/post/Use-the-Daily-Bing-picture-in-Teams-calls 20 | ImageFile="images/dailyImage.jpeg" 21 | python bing_wallpaper.py ${ImageFile} 22 | 23 | DrawFile="./draw.txt" 24 | if [ -f ${DrawFile} ]; then 25 | rm $DrawFile 26 | fi 27 | 28 | #Inquiry tft information 29 | screen_width=`./draw width` 30 | screen_height=`./draw height` 31 | driver_name=`./draw driver` 32 | echo -n "Your TFT is " 33 | echo -n ${driver_name} 34 | echo -n " " 35 | echo -n ${screen_width} 36 | echo -n "x" 37 | echo ${screen_height} 38 | 39 | #resize image using convert 40 | finalImageFile="images/dailyImage2.jpeg" 41 | cp ${ImageFile} ${finalImageFile} 42 | install=`which convert | grep -c convert` 43 | if [ $install = 1 ]; then 44 | convert -resize ${screen_width}x${screen_height} ${ImageFile} ${finalImageFile} 45 | echo "convert -resize ${screen_width}x${screen_height} ${ImageFile} ${finalImageFile}" 46 | else 47 | echo "imagemagick not install. sudo apt install imagemagick" 48 | fi 49 | 50 | #Black(0x000000) 51 | _echo "FillScrren,0x0000" 52 | _echo "JPEG,${finalImageFile}" 53 | 54 | ./draw $DrawFile > /dev/null 55 | -------------------------------------------------------------------------------- /draw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "tft_lib.h" 12 | 13 | #include "tjpgd2/tjpgd.h" 14 | #include "tjpgd2/decode_jpeg.h" 15 | 16 | #include "pngle/pngle.h" 17 | #include "pngle/decode_png.h" 18 | 19 | #ifdef ILI9225 20 | #include "driver/ili9225.h" 21 | #define DRIVER_NAME "ILI9225" 22 | #define SCREEN_WIDTH 240 23 | #define SCREEN_HEIGHT 320 24 | #define OFFSET_X 0 25 | #define OFFSET_Y 0 26 | #define INIT_FUNCTION(a, b, c, d, e) ili9225_lcdInit(a, b, c, d, e) 27 | 28 | #elif ILI9320 29 | #include "driver/ili9320.h" 30 | #define DRIVER_NAME "ILI9320" 31 | #define SCREEN_WIDTH 240 32 | #define SCREEN_HEIGHT 320 33 | #define OFFSET_X 0 34 | #define OFFSET_Y 0 35 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 36 | 37 | #elif ILI9325 38 | #include "driver/ili9325.h" 39 | #define DRIVER_NAME "ILI9325" 40 | #define SCREEN_WIDTH 240 41 | #define SCREEN_HEIGHT 320 42 | #define OFFSET_X 0 43 | #define OFFSET_Y 0 44 | #define INIT_FUNCTION(a, b, c, d, e) ili9325_lcdInit(a, b, c, d, e) 45 | 46 | #elif ILI9327 47 | #include "driver/ili9327.h" 48 | #define DRIVER_NAME "ILI9327" 49 | #define SCREEN_WIDTH 240 50 | #define SCREEN_HEIGHT 400 51 | #define OFFSET_X 0 52 | #define OFFSET_Y 0 53 | #define INIT_FUNCTION(a, b, c, d, e) ili9327_lcdInit(a, b, c, d, e) 54 | 55 | 56 | #elif ILI9341 57 | #include "driver/ili9341.h" 58 | #ifndef P16BIT 59 | #define DRIVER_NAME "ILI9341" 60 | #else 61 | #define DRIVER_NAME "ILI9341(16Bit)" 62 | #endif 63 | #define SCREEN_WIDTH 240 64 | #define SCREEN_HEIGHT 320 65 | #define OFFSET_X 0 66 | #define OFFSET_Y 0 67 | #define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e) 68 | 69 | #elif ILI9342 70 | #include "driver/ili9342.h" 71 | #define DRIVER_NAME "ILI9342" 72 | #define SCREEN_WIDTH 240 73 | #define SCREEN_HEIGHT 320 74 | #define OFFSET_X 0 75 | #define OFFSET_Y 0 76 | #define INIT_FUNCTION(a, b, c, d, e) ili9342_lcdInit(a, b, c, d, e) 77 | 78 | #elif ILI9481 79 | #include "driver/ili9481.h" 80 | #define DRIVER_NAME "ILI9481" 81 | #define SCREEN_WIDTH 320 82 | #define SCREEN_HEIGHT 480 83 | #define OFFSET_X 0 84 | #define OFFSET_Y 0 85 | #define INIT_FUNCTION(a, b, c, d, e) ili9481_lcdInit(a, b, c, d, e) 86 | 87 | #elif ILI9486 88 | #include "driver/ili9486.h" 89 | #define DRIVER_NAME "ILI9486" 90 | #define SCREEN_WIDTH 320 91 | #define SCREEN_HEIGHT 480 92 | #define OFFSET_X 0 93 | #define OFFSET_Y 0 94 | #define INIT_FUNCTION(a, b, c, d, e) ili9486_lcdInit(a, b, c, d, e) 95 | 96 | #elif ILI9488 97 | #include "driver/ili9488.h" 98 | #define DRIVER_NAME "ILI9488" 99 | #define SCREEN_WIDTH 320 100 | #define SCREEN_HEIGHT 480 101 | #define OFFSET_X 0 102 | #define OFFSET_Y 0 103 | #define INIT_FUNCTION(a, b, c, d, e) ili9488_lcdInit(a, b, c, d, e) 104 | 105 | #elif SPFD5408 106 | #include "driver/ili9320.h" 107 | #define DRIVER_NAME "SPFD5408" 108 | #define SCREEN_WIDTH 240 109 | #define SCREEN_HEIGHT 320 110 | #define OFFSET_X 0 111 | #define OFFSET_Y 0 112 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 113 | 114 | #elif R61505U 115 | #include "driver/ili9320.h" 116 | #define DRIVER_NAME "R61505U" 117 | #define SCREEN_WIDTH 240 118 | #define SCREEN_HEIGHT 320 119 | #define OFFSET_X 0 120 | #define OFFSET_Y 0 121 | #define INIT_FUNCTION(a, b, c, d, e) ili9320_lcdInit(a, b, c, d, e) 122 | 123 | #elif R61509V 124 | #include "driver/r61509.h" 125 | #define DRIVER_NAME "R61509V" 126 | #define SCREEN_WIDTH 240 127 | #define SCREEN_HEIGHT 400 128 | #define OFFSET_X 0 129 | #define OFFSET_Y 0 130 | #define INIT_FUNCTION(a, b, c, d, e) r61509_lcdInit(a, b, c, d, e) 131 | 132 | #elif S6D1121 133 | #include "driver/s6d1121.h" 134 | #define DRIVER_NAME "S6D1121" 135 | #define SCREEN_WIDTH 240 136 | #define SCREEN_HEIGHT 320 137 | #define OFFSET_X 0 138 | #define OFFSET_Y 0 139 | #define INIT_FUNCTION(a, b, c, d, e) s6d1121_lcdInit(a, b, c, d, e) 140 | 141 | #elif ST7775 142 | #include "driver/ili9225.h" 143 | #define DRIVER_NAME "ST7775" 144 | #define SCREEN_WIDTH 176 145 | #define SCREEN_HEIGHT 220 146 | #define OFFSET_X 0 147 | #define OFFSET_Y 0 148 | #define INIT_FUNCTION(a, b, c, d, e) ili9225_lcdInit(a, b, c, d, e) 149 | 150 | #elif ST7781 151 | #include "driver/st7781.h" 152 | #define DRIVER_NAME "ST7781" 153 | #define SCREEN_WIDTH 240 154 | #define SCREEN_HEIGHT 320 155 | #define OFFSET_X 0 156 | #define OFFSET_Y 0 157 | #define INIT_FUNCTION(a, b, c, d, e) st7781_lcdInit(a, b, c, d, e) 158 | 159 | #elif ST7783 160 | #include "driver/st7781.h" 161 | #define DRIVER_NAME "ST7783" 162 | #define SCREEN_WIDTH 240 163 | #define SCREEN_HEIGHT 320 164 | #define OFFSET_X 0 165 | #define OFFSET_Y 0 166 | #define INIT_FUNCTION(a, b, c, d, e) st7781_lcdInit(a, b, c, d, e) 167 | 168 | #elif ST7793 169 | #include "driver/r61509.h" 170 | #define DRIVER_NAME "ST7793" 171 | #define SCREEN_WIDTH 240 172 | #define SCREEN_HEIGHT 400 173 | #define OFFSET_X 0 174 | #define OFFSET_Y 0 175 | #define INIT_FUNCTION(a, b, c, d, e) r61509_lcdInit(a, b, c, d, e) 176 | 177 | #elif ST7796 178 | #include "driver/ili9486.h" 179 | #define DRIVER_NAME "ST7796" 180 | #define SCREEN_WIDTH 320 181 | #define SCREEN_HEIGHT 480 182 | #define OFFSET_X 0 183 | #define OFFSET_Y 0 184 | #define INIT_FUNCTION(a, b, c, d, e) ili9486_lcdInit(a, b, c, d, e) 185 | 186 | #endif 187 | 188 | typedef struct { 189 | char name[32]; 190 | char font[32]; 191 | char file[64]; 192 | unsigned char utf[32]; 193 | uint16_t x1; 194 | uint16_t y1; 195 | uint16_t x2; 196 | uint16_t y2; 197 | uint16_t r; 198 | uint16_t t; 199 | uint16_t color; 200 | uint16_t dir; 201 | } cmd_t; 202 | 203 | #define _DEBUG_ 0 204 | 205 | int cmdParse(char * buf, cmd_t * hoge) { 206 | int pos=0; 207 | int index=0; 208 | int i; 209 | char wk[10][64]; 210 | for(i=0;iname,wk[0]); 233 | hoge->x1 = strtol(wk[1],NULL,0); 234 | hoge->y1 = strtol(wk[2],NULL,0); 235 | hoge->color = strtol(wk[3],NULL,0); 236 | return 1; 237 | 238 | } else if (strcmp(wk[0],"DrawRect") == 0 || 239 | strcmp(wk[0],"DrawFillRect") == 0) { 240 | strcpy(hoge->name,wk[0]); 241 | hoge->x1 = strtol(wk[1],NULL,0); 242 | hoge->y1 = strtol(wk[2],NULL,0); 243 | hoge->x2 = strtol(wk[3],NULL,0); 244 | hoge->y2 = strtol(wk[4],NULL,0); 245 | hoge->color = strtol(wk[5],NULL,0); 246 | return 1; 247 | 248 | } else if (strcmp(wk[0],"DrawRoundRect") == 0) { 249 | strcpy(hoge->name,wk[0]); 250 | hoge->x1 = strtol(wk[1],NULL,0); 251 | hoge->y1 = strtol(wk[2],NULL,0); 252 | hoge->x2 = strtol(wk[3],NULL,0); 253 | hoge->y2 = strtol(wk[4],NULL,0); 254 | hoge->r = strtol(wk[5],NULL,0); 255 | hoge->color = strtol(wk[6],NULL,0); 256 | return 1; 257 | 258 | } else if (strcmp(wk[0],"FillScrren") == 0) { 259 | strcpy(hoge->name,wk[0]); 260 | hoge->color = strtol(wk[1],NULL,0); 261 | return 1; 262 | 263 | } else if (strcmp(wk[0],"DrawLine") == 0) { 264 | strcpy(hoge->name,wk[0]); 265 | hoge->x1 = strtol(wk[1],NULL,0); 266 | hoge->y1 = strtol(wk[2],NULL,0); 267 | hoge->x2 = strtol(wk[3],NULL,0); 268 | hoge->y2 = strtol(wk[4],NULL,0); 269 | hoge->color = strtol(wk[5],NULL,0); 270 | return 1; 271 | 272 | } else if (strcmp(wk[0],"DrawCircle") == 0 || 273 | strcmp(wk[0],"DrawFillCircle") == 0) { 274 | strcpy(hoge->name,wk[0]); 275 | hoge->x1 = strtol(wk[1],NULL,0); 276 | hoge->y1 = strtol(wk[2],NULL,0); 277 | hoge->r = strtol(wk[3],NULL,0); 278 | hoge->color = strtol(wk[4],NULL,0); 279 | return 1; 280 | 281 | } else if (strcmp(wk[0],"DrawArrow") == 0 || 282 | strcmp(wk[0],"DrawFillArrow") == 0) { 283 | strcpy(hoge->name,wk[0]); 284 | hoge->x1 = strtol(wk[1],NULL,0); 285 | hoge->y1 = strtol(wk[2],NULL,0); 286 | hoge->x2 = strtol(wk[3],NULL,0); 287 | hoge->y2 = strtol(wk[4],NULL,0); 288 | hoge->t = strtol(wk[5],NULL,0); 289 | hoge->color = strtol(wk[6],NULL,0); 290 | return 1; 291 | 292 | } else if (strcmp(wk[0],"DrawUTF8String") == 0) { 293 | strcpy(hoge->name,wk[0]); 294 | strcpy(hoge->font,wk[1]); 295 | hoge->x1 = strtol(wk[2],NULL,0); 296 | hoge->y1 = strtol(wk[3],NULL,0); 297 | strcpy((char *)hoge->utf,wk[4]); 298 | hoge->color = strtol(wk[5],NULL,0); 299 | return 1; 300 | 301 | } else if (strcmp(wk[0],"SetFontDirection") == 0) { 302 | strcpy(hoge->name,wk[0]); 303 | hoge->dir = strtol(wk[1],NULL,0); 304 | return 1; 305 | 306 | } else if (strcmp(wk[0],"SetFontFill") == 0 || 307 | strcmp(wk[0],"SetFontUnderLine") == 0) { 308 | strcpy(hoge->name,wk[0]); 309 | hoge->color = strtol(wk[1],NULL,0); 310 | return 1; 311 | 312 | } else if (strcmp(wk[0],"UnsetFontFill") == 0 || 313 | strcmp(wk[0],"UnsetFontUnderLine") == 0) { 314 | strcpy(hoge->name,wk[0]); 315 | return 1; 316 | 317 | } else if (strcmp(wk[0],"JPEG") == 0) { 318 | strcpy(hoge->name,wk[0]); 319 | strcpy(hoge->file,wk[1]); 320 | 321 | } else if (strcmp(wk[0],"PNG") == 0) { 322 | strcpy(hoge->name,wk[0]); 323 | strcpy(hoge->file,wk[1]); 324 | 325 | } else { 326 | return 0; 327 | } 328 | } 329 | 330 | 331 | void cmdDump(cmd_t hoge) { 332 | printf("name=%s\n",hoge.name); 333 | printf("font=[%s] ",hoge.font); 334 | printf("file=[%s] ",hoge.file); 335 | printf("x1=%d ",hoge.x1); 336 | printf("y1=%d ",hoge.y1); 337 | printf("x2=%d ",hoge.x2); 338 | printf("y2=%d ",hoge.y2); 339 | printf("r=%d ",hoge.r); 340 | printf("t=%d ",hoge.t); 341 | printf("utf=%s ",hoge.utf); 342 | printf("dir=%d ",hoge.dir); 343 | printf("color=%x\n",hoge.color); 344 | } 345 | 346 | int JPEGTest(TFT_t * dev, char * file, int width, int height) { 347 | //struct timeval startTime, endTime; 348 | //gettimeofday(&startTime, NULL); 349 | 350 | //lcdFillScreen(dev, BLACK); 351 | 352 | int _width = width; 353 | if (width > 240) _width = 240; 354 | int _height = height; 355 | if (height > 320) _height = 320; 356 | 357 | pixel_s **pixels; 358 | uint16_t imageWidth; 359 | uint16_t imageHeight; 360 | uint16_t err = decode_image(&pixels, file, width, height, &imageWidth, &imageHeight); 361 | if (err == ESP_OK) { 362 | //printf("imageWidth=%d imageHeight=%d\n", imageWidth, imageHeight); 363 | 364 | uint16_t jpegWidth = width; 365 | uint16_t offsetX = 0; 366 | if (width > imageWidth) { 367 | jpegWidth = imageWidth; 368 | offsetX = (width - imageWidth) / 2; 369 | } 370 | //printf("jpegWidth=%d offsetX=%d\n", jpegWidth, offsetX); 371 | 372 | uint16_t jpegHeight = height; 373 | uint16_t offsetY = 0; 374 | if (height > imageHeight) { 375 | jpegHeight = imageHeight; 376 | offsetY = (height - imageHeight) / 2; 377 | } 378 | //printf("jpegHeight=%d offsetY=%d\n", jpegHeight, offsetY); 379 | uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * jpegWidth); 380 | 381 | int ypos = (height-1) - offsetY; 382 | for(int y = 0; y < jpegHeight; y++){ 383 | for(int x = 0;x < jpegWidth; x++){ 384 | pixel_s pixel = pixels[y][x]; 385 | uint16_t color = rgb565_conv(pixel.red, pixel.green, pixel.blue); 386 | //lcdDrawPixel(dev, x+offsetX, y+offsetY, color); 387 | lcdDrawPixel(dev, x+offsetX, ypos, color); 388 | } 389 | ypos--; 390 | } 391 | 392 | free(colors); 393 | release_image(&pixels, _width, _height); 394 | //printf("Finish\n"); 395 | } else { 396 | printf("decode_image err=%d imageWidth=%d imageHeight=%d\n", err, imageWidth, imageHeight); 397 | } 398 | 399 | //gettimeofday(&endTime, NULL); 400 | //time_t diff = elapsedTime(startTime, endTime); 401 | //printf("%s elapsed time[ms]=%ld\n",__func__, diff); 402 | //return diff; 403 | return 0; 404 | } 405 | 406 | 407 | int PNGTest(TFT_t * dev, char * file, int width, int height) { 408 | //struct timeval startTime, endTime; 409 | //gettimeofday(&startTime, NULL); 410 | 411 | //lcdFillScreen(dev, BLACK); 412 | 413 | int _width = width; 414 | if (width > 240) _width = 240; 415 | int _height = height; 416 | if (height > 320) _height = 320; 417 | 418 | // open PNG file 419 | FILE* fp = fopen(file, "rb"); 420 | if (fp == NULL) { 421 | printf("File not found [%s]\n", file); 422 | return 0; 423 | } 424 | 425 | char buf[1024]; 426 | size_t remain = 0; 427 | int len; 428 | 429 | pngle_t *pngle = pngle_new(_width, _height); 430 | 431 | pngle_set_init_callback(pngle, png_init); 432 | pngle_set_draw_callback(pngle, png_draw); 433 | pngle_set_done_callback(pngle, png_finish); 434 | 435 | double display_gamma = 2.2; 436 | pngle_set_display_gamma(pngle, display_gamma); 437 | 438 | 439 | while (!feof(fp)) { 440 | if (remain >= sizeof(buf)) { 441 | printf("Buffer exceeded\n"); 442 | return 0; 443 | } 444 | 445 | len = fread(buf + remain, 1, sizeof(buf) - remain, fp); 446 | if (len <= 0) { 447 | //printf("EOF\n"); 448 | break; 449 | } 450 | 451 | int fed = pngle_feed(pngle, buf, remain + len); 452 | if (fed < 0) { 453 | printf("ERROR; %s\n", pngle_error(pngle)); 454 | return 0; 455 | } 456 | 457 | remain = remain + len - fed; 458 | if (remain > 0) memmove(buf, buf + fed, remain); 459 | } 460 | 461 | fclose(fp); 462 | 463 | uint16_t pngWidth = width; 464 | uint16_t offsetX = 0; 465 | if (width > pngle->imageWidth) { 466 | pngWidth = pngle->imageWidth; 467 | offsetX = (width - pngle->imageWidth) / 2; 468 | } 469 | printf("pngWidth=%d offsetX=%d", pngWidth, offsetX); 470 | 471 | uint16_t pngHeight = height; 472 | uint16_t offsetY = 0; 473 | if (height > pngle->imageHeight) { 474 | pngHeight = pngle->imageHeight; 475 | offsetY = (height - pngle->imageHeight) / 2; 476 | } 477 | printf("pngHeight=%d offsetY=%d\n", pngHeight, offsetY); 478 | uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * pngWidth); 479 | 480 | int ypos = (height-1) - offsetY; 481 | for(int y = 0; y < pngHeight; y++){ 482 | for(int x = 0;x < pngWidth; x++){ 483 | pixel_png pixel = pngle->pixels[y][x]; 484 | uint16_t color = rgb565_conv(pixel.red, pixel.green, pixel.blue); 485 | //lcdDrawPixel(dev, x+offsetX, y+offsetY, color); 486 | lcdDrawPixel(dev, x+offsetX, ypos, color); 487 | } 488 | ypos--; 489 | } 490 | 491 | 492 | free(colors); 493 | pngle_destroy(pngle, _width, _height); 494 | 495 | //gettimeofday(&endTime, NULL); 496 | //time_t diff = elapsedTime(startTime, endTime); 497 | //printf("%s elapsed time[ms]=%ld\n",__func__, diff); 498 | //return diff; 499 | return 0; 500 | } 501 | 502 | /* 503 | Width inquiry : draw width 504 | Height inquiry : draw height 505 | Driver inquiry : draw driver 506 | Execute draw : draw file filename 507 | */ 508 | int main(int argc, char **argv){ 509 | int i; 510 | 511 | if(_DEBUG_)printf("argc=%d\n",argc); 512 | if (argc < 2) { 513 | printf("%s draw_file_name\n",argv[0]); 514 | return 1; 515 | } 516 | 517 | if (argc == 2) { 518 | if (strcmp(argv[1],"width") == 0) { 519 | printf("%d\n", SCREEN_WIDTH); 520 | return 0; 521 | } else if (strcmp(argv[1],"height") == 0) { 522 | printf("%d\n", SCREEN_HEIGHT); 523 | return 0; 524 | } else if (strcmp(argv[1],"driver") == 0) { 525 | printf("%s\n", DRIVER_NAME); 526 | return 0; 527 | } 528 | } 529 | 530 | if(wiringPiSetup() == -1) { 531 | printf("Setup Fail\n"); 532 | return 1; 533 | } 534 | 535 | char base[128]; 536 | strcpy(base, argv[0]); 537 | for(i=strlen(base);i>0;i--) { 538 | if (base[i-1] == '/') { 539 | base[i] = 0; 540 | break; 541 | } 542 | } 543 | if(_DEBUG_)printf("base=%s\n",base); 544 | 545 | 546 | // You can change font file 547 | // 32Dot Gothic 548 | char G32[2][128]; 549 | strcpy(G32[0],base); 550 | strcpy(G32[1],base); 551 | strcat(G32[0],"fontx/ILGH32XB.FNT"); 552 | strcat(G32[1],"fontx/ILGZ32XB.FNT"); 553 | FontxFile fxG32[2]; 554 | Fontx_init(fxG32,G32[0],G32[1]); 555 | 556 | // 32Dot Mincho 557 | char M32[2][128]; 558 | strcpy(M32[0],base); 559 | strcpy(M32[1],base); 560 | strcat(M32[0],"fontx/ILMH32XF.FNT"); 561 | strcat(M32[1],"fontx/ILMZ32XF.FNT"); 562 | FontxFile fxM32[2]; 563 | Fontx_init(fxM32,M32[0],M32[1]); 564 | 565 | // 24Dot Gothic 566 | char G24[2][128]; 567 | strcpy(G24[0],base); 568 | strcpy(G24[1],base); 569 | strcat(G24[0],"fontx/ILGH24XB.FNT"); 570 | strcat(G24[1],"fontx/ILGZ24XB.FNT"); 571 | FontxFile fxG24[2]; 572 | Fontx_init(fxG24,G24[0],G24[1]); 573 | 574 | // 24Dot Mincho 575 | char M24[2][128]; 576 | strcpy(M24[0],base); 577 | strcpy(M24[1],base); 578 | strcat(M24[0],"fontx/ILMH24XF.FNT"); 579 | strcat(M24[1],"fontx/ILMZ24XF.FNT"); 580 | FontxFile fxM24[2]; 581 | Fontx_init(fxM24,M24[0],M24[1]); 582 | 583 | // 16Dot Gothic 584 | char G16[2][128]; 585 | strcpy(G16[0],base); 586 | strcpy(G16[1],base); 587 | strcat(G16[0],"fontx/ILGH16XB.FNT"); 588 | strcat(G16[1],"fontx/ILGZ16XB.FNT"); 589 | FontxFile fxG16[2]; 590 | Fontx_init(fxG16,G16[0],G16[1]); 591 | 592 | // 16Dot Mincho 593 | char M16[2][128]; 594 | strcpy(M16[0],base); 595 | strcpy(M16[1],base); 596 | strcat(M16[0],"fontx/ILMH16XB.FNT"); 597 | strcat(M16[1],"fontx/ILMZ16XB.FNT"); 598 | FontxFile fxM16[2]; 599 | Fontx_init(fxM16,M16[0],M16[1]); 600 | 601 | 602 | #if 0 603 | Fontx_dump(fxG32); 604 | Fontx_dump(fxG24); 605 | Fontx_dump(fxM32); 606 | Fontx_dump(fxM24); 607 | Fontx_dump(fxM16); 608 | Fontx_dump(fxM16); 609 | #endif 610 | 611 | // set full path of pin.conf 612 | char ppath[128]; 613 | strcpy(ppath,base); 614 | strcat(ppath,"pin.conf"); 615 | if(_DEBUG_)printf("ppath=%s\n",ppath); 616 | struct stat buffer; 617 | if (stat(ppath, &buffer) != 0) { 618 | printf("pin.conf [%s] not found\n",ppath); 619 | return 1; 620 | } 621 | 622 | // set full path of draw file 623 | char dpath[128]; 624 | FILE *fp; 625 | strcpy(dpath,base); 626 | strcat(dpath,argv[1]); 627 | if(_DEBUG_)printf("dpath=%s\n",dpath); 628 | if ((fp = fopen(dpath, "r")) == NULL) { 629 | printf("draw file [%s] not found\n",dpath); 630 | return 1; 631 | } 632 | 633 | TFT_t dev; 634 | lcdInterface(&dev, ppath); 635 | lcdReset(&dev); 636 | INIT_FUNCTION(&dev, SCREEN_WIDTH, SCREEN_HEIGHT, OFFSET_X, OFFSET_Y); 637 | 638 | #ifdef INVERT 639 | lcdInversionOn(&dev); 640 | #endif 641 | 642 | printf("Your TFT controller is %s.\n",DRIVER_NAME); 643 | printf("TFT resolution is %d x %d.\n",SCREEN_WIDTH, SCREEN_HEIGHT); 644 | 645 | char buf[64]; 646 | cmd_t cmd; 647 | int blen; 648 | 649 | while ( fgets(buf, sizeof(buf), fp) != NULL ) { 650 | blen = strlen(buf); 651 | buf[blen-1] = 0; 652 | if(_DEBUG_)printf("buf=[%s]\n",buf); 653 | if (strlen(buf) == 0) continue; 654 | if (cmdParse(buf,&cmd) == 0) continue; 655 | if(_DEBUG_)cmdDump(cmd); 656 | if (strcmp(cmd.name,"DrawPixel") == 0) { 657 | lcdDrawPixel(&dev, cmd.x1, cmd.y1, cmd.color); 658 | } else if (strcmp(cmd.name,"DrawFillRect") == 0) { 659 | lcdDrawFillRect(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.color); 660 | } else if (strcmp(cmd.name,"FillScrren") == 0) { 661 | lcdFillScreen(&dev, cmd.color); 662 | } else if (strcmp(cmd.name,"DrawLine") == 0) { 663 | lcdDrawLine(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.color); 664 | } else if (strcmp(cmd.name,"DrawRect") == 0) { 665 | lcdDrawRect(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.color); 666 | } else if (strcmp(cmd.name,"DrawCircle") == 0) { 667 | lcdDrawCircle(&dev, cmd.x1, cmd.y1, cmd.r, cmd.color); 668 | } else if (strcmp(cmd.name,"DrawFillCircle") == 0) { 669 | lcdDrawFillCircle(&dev, cmd.x1, cmd.y1, cmd.r, cmd.color); 670 | } else if (strcmp(cmd.name,"DrawRoundRect") == 0) { 671 | lcdDrawRoundRect(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.r, cmd.color); 672 | } else if (strcmp(cmd.name,"DrawArrow") == 0) { 673 | lcdDrawArrow(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.t, cmd.color); 674 | } else if (strcmp(cmd.name,"DrawFillArrow") == 0) { 675 | lcdDrawFillArrow(&dev, cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.t, cmd.color); 676 | } else if (strcmp(cmd.name,"DrawUTF8String") == 0) { 677 | if (strcmp(cmd.font,"G32") == 0) 678 | lcdDrawUTF8String(&dev, fxG32, cmd.x1, cmd.y1, cmd.utf, cmd.color); 679 | if (strcmp(cmd.font,"G24") == 0) 680 | lcdDrawUTF8String(&dev, fxG24, cmd.x1, cmd.y1, cmd.utf, cmd.color); 681 | if (strcmp(cmd.font,"G16") == 0) 682 | lcdDrawUTF8String(&dev, fxG16, cmd.x1, cmd.y1, cmd.utf, cmd.color); 683 | 684 | if (strcmp(cmd.font,"M32") == 0) 685 | lcdDrawUTF8String(&dev, fxM32, cmd.x1, cmd.y1, cmd.utf, cmd.color); 686 | if (strcmp(cmd.font,"M24") == 0) 687 | lcdDrawUTF8String(&dev, fxM24, cmd.x1, cmd.y1, cmd.utf, cmd.color); 688 | if (strcmp(cmd.font,"M16") == 0) 689 | lcdDrawUTF8String(&dev, fxM16, cmd.x1, cmd.y1, cmd.utf, cmd.color); 690 | } else if (strcmp(cmd.name,"SetFontDirection") == 0) { 691 | lcdSetFontDirection(&dev, cmd.dir); 692 | } else if (strcmp(cmd.name,"SetFontFill") == 0) { 693 | lcdSetFontFill(&dev, cmd.color); 694 | } else if (strcmp(cmd.name,"UnsetFontFill") == 0) { 695 | lcdUnsetFontFill(&dev); 696 | } else if (strcmp(cmd.name,"SetFontUnderLine") == 0) { 697 | lcdSetFontUnderLine(&dev, cmd.color); 698 | } else if (strcmp(cmd.name,"UnsetFontUnderLine") == 0) { 699 | lcdUnsetFontUnderLine(&dev); 700 | } else if (strcmp(cmd.name,"JPEG") == 0) { 701 | JPEGTest(&dev, cmd.file, SCREEN_WIDTH, SCREEN_HEIGHT); 702 | } else if (strcmp(cmd.name,"PNG") == 0) { 703 | PNGTest(&dev, cmd.file, SCREEN_WIDTH, SCREEN_HEIGHT); 704 | } 705 | 706 | } // end while 707 | fclose(fp); 708 | return 0; 709 | } 710 | -------------------------------------------------------------------------------- /draw1.txt: -------------------------------------------------------------------------------- 1 | #example draw file 2 | 3 | FillScrren,0xffff 4 | 5 | DrawFillRect,0,0,20,20,0xf800 6 | DrawFillRect,20,20,40,40,0x07e0 7 | DrawFillRect,40,40,60,60,0x001f 8 | 9 | DrawRect,80,80,100,100,0xf800 10 | DrawRect,100,100,120,120,0x07e0 11 | DrawRect,120,120,140,140,0x001f 12 | 13 | DrawRoundRect,160,160,180,180,5,0xf800 14 | DrawRoundRect,180,180,200,200,5,0x07e0 15 | DrawRoundRect,200,200,220,220,5,0x001f 16 | 17 | DrawLine,120,20,120,60,0x0000 18 | DrawLine,120,60,160,40,0x0000 19 | DrawLine,160,40,120,20,0x0000 20 | 21 | DrawCircle,200,40,5,0xf800 22 | DrawCircle,200,40,10,0xf800 23 | DrawCircle,200,40,15,0xf800 24 | DrawCircle,200,40,20,0xf800 25 | DrawFillCircle,200,80,20,0x07e0 26 | 27 | DrawArrow,90,190,80,190,10,0xf800 28 | DrawArrow,100,200,100,210,10,0x07e0 29 | 30 | DrawFillArrow,110,190,120,190,10,0x8000 31 | DrawFillArrow,100,180,100,170,10,0x07e0 32 | -------------------------------------------------------------------------------- /draw2.txt: -------------------------------------------------------------------------------- 1 | #example draw file 2 | 3 | FillScrren,0xffff 4 | SetFontDirection,0 5 | DrawUTF8String,G24,100,100,Dir=0,0xf800 6 | SetFontDirection,1 7 | DrawUTF8String,G24,100,100,Dir=1,0xf800 8 | SetFontDirection,2 9 | DrawUTF8String,G24,100,100,Dir=2,0xf800 10 | SetFontDirection,3 11 | DrawUTF8String,G24,100,100,Dir=3,0xf800 12 | 13 | SetFontDirection,0 14 | DrawUTF8String,G16,20,180,16dot,0xf800 15 | DrawUTF8String,G24,20,200,24dot,0xf800 16 | SetFontUnderLine,0x07FF 17 | DrawUTF8String,G24,20,220,24dot,0xf800 18 | UnsetFontUnderLine 19 | SetFontFill,0x07FF 20 | DrawUTF8String,G24,20,240,24dot,0xf800 21 | UnsetFontFill 22 | DrawUTF8String,G32,20,260,32dot,0xf800 23 | 24 | SetFontDirection,0 25 | DrawUTF8String,M16,120,180,16dot,0xf800 26 | DrawUTF8String,M24,120,200,24dot,0xf800 27 | SetFontUnderLine,0x07FF 28 | DrawUTF8String,M24,120,220,24dot,0xf800 29 | UnsetFontUnderLine 30 | SetFontFill,0x07FF 31 | DrawUTF8String,M24,120,240,24dot,0xf800 32 | UnsetFontFill 33 | DrawUTF8String,M32,120,260,32dot,0xf800 34 | -------------------------------------------------------------------------------- /driver/ili9225.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9225.h" 6 | 7 | void ili9225_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9225, width, height, offsetx, offsety); 9 | //printf("ili9225_lcdInit _model=%x\n", dev->_model); 10 | 11 | static const uint16_t regValues[] = { 12 | /* Set SS bit and direction output from S528 to S1 */ 13 | 0x10, 0x0000, // Set SAP,DSTB,STB 14 | 0x11, 0x0000, // Set APON,PON,AON,VCI1EN,VC 15 | 0x12, 0x0000, // Set BT,DC1,DC2,DC3 16 | 0x13, 0x0000, // Set GVDD 17 | 0x14, 0x0000, // Set VCOMH/VCOML voltage 18 | TFTLCD_DELAY16, 40, 19 | 20 | // Power-on sequence 21 | 0x11, 0x0018, // Set APON,PON,AON,VCI1EN,VC 22 | 0x12, 0x6121, // Set BT,DC1,DC2,DC3 23 | 0x13, 0x006F, // Set GVDD /*007F 0088 */ 24 | 0x14, 0x495F, // Set VCOMH/VCOML voltage 25 | 0x10, 0x0800, // Set SAP,DSTB,STB 26 | TFTLCD_DELAY16, 10, 27 | 0x11, 0x103B, // Set APON,PON,AON,VCI1EN,VC 28 | TFTLCD_DELAY16, 50, 29 | 30 | //0x01, 0x011C, // set the display line number and display direction 31 | 0x01, 0x001C, // set the display line number and display direction 32 | //0x01, 0x021C, // set the display line number and display direction 33 | 0x02, 0x0100, // set 1 line inversion 34 | 0x03, 0x1010, // set GRAM write direction and BGR=1. 35 | //0x03, 0x1030, // set GRAM write direction and BGR=1. 36 | 0x07, 0x0000, // Display off 37 | 0x08, 0x0808, // set the back porch and front porch 38 | 0x0B, 0x1100, // set the clocks number per line 39 | 0x0C, 0x0000, // CPU interface 40 | 0x0F, 0x0D01, // Set Osc /*0e01*/ 41 | 0x15, 0x0020, // Set VCI recycling 42 | 0x20, 0x0000, // Horizontal GRAM Address Set 43 | 0x21, 0x0000, // Vertical GRAM Address Set 44 | 45 | /* Set GRAM area */ 46 | 0x30, 0x0000, 47 | 0x31, 0x00DB, 48 | 0x32, 0x0000, 49 | 0x33, 0x0000, 50 | 0x34, 0x00DB, 51 | 0x35, 0x0000, 52 | 0x36, 0x00AF, 53 | 0x37, 0x0000, 54 | 0x38, 0x00DB, 55 | 0x39, 0x0000, 56 | 57 | /* Set GAMMA curve */ 58 | 0x50, 0x0000, 59 | 0x51, 0x0808, 60 | 0x52, 0x080A, 61 | 0x53, 0x000A, 62 | 0x54, 0x0A08, 63 | 0x55, 0x0808, 64 | 0x56, 0x0000, 65 | 0x57, 0x0A00, 66 | 0x58, 0x0710, 67 | 0x59, 0x0710, 68 | 69 | 0x07, 0x0012, 70 | TFTLCD_DELAY16, 50, 71 | 0x07, 0x1017, 72 | }; 73 | lcdInitTable16(dev, regValues, sizeof(regValues)); 74 | 75 | // ili9225 custom function 76 | DrawPixel = ili9225_lcdDrawPixel; 77 | DrawFillRect = ili9225_lcdDrawFillRect; 78 | DisplayOff = ili9225_lcdDisplayOff; 79 | DisplayOn = ili9225_lcdDisplayOn; 80 | InversionOff = ili9225_lcdInversionOff; 81 | InversionOn = ili9225_lcdInversionOn; 82 | } 83 | 84 | // Draw pixel 85 | // x:X coordinate 86 | // y:Y coordinate 87 | // color:color 88 | void ili9225_lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color) { 89 | if (x >= dev->_width) return; 90 | if (y >= dev->_height) return; 91 | 92 | uint16_t _x = x + dev->_offsetx; 93 | uint16_t _y = y + dev->_offsety; 94 | 95 | lcdWriteRegisterWord(dev, 0x0020, _x); // RAM Address Set 1 96 | lcdWriteRegisterWord(dev, 0x0021, _y); // RAM Address Set 2 97 | lcdWriteRegisterWord(dev, 0x0022, color); // Write Data to GRAM 98 | } 99 | 100 | // Draw rectangule of filling 101 | // x1:Start X coordinate 102 | // y1:Start Y coordinate 103 | // x2:End X coordinate 104 | // y2:End Y coordinate 105 | // color:color 106 | void ili9225_lcdDrawFillRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color){ 107 | if (x1 >= dev->_width) return; 108 | if (x2 >= dev->_width) x2 = dev->_width-1; 109 | if (y1 >= dev->_height) return; 110 | if (y2 >= dev->_height) y2 = dev->_height-1; 111 | 112 | uint16_t _x1 = x1 + dev->_offsetx; 113 | uint16_t _x2 = x2 + dev->_offsetx; 114 | uint16_t _y1 = y1 + dev->_offsety; 115 | uint16_t _y2 = y2 + dev->_offsety; 116 | 117 | for(int _y=_y1;_y<=_y2;_y++){ 118 | lcdWriteRegisterWord(dev, 0x0020, _x1); // RAM Address Set 1 119 | lcdWriteRegisterWord(dev, 0x0021, _y); // RAM Address Set 2 120 | lcdWriteCommandWord(dev, 0x0022); // Write Data to GRAM 121 | for(int _x=_x1;_x<=_x2;_x++){ 122 | //lcdWriteRegisterWord(dev, 0x0020, _x); // RAM Address Set 1 123 | //lcdWriteRegisterWord(dev, 0x0021, _y); // RAM Address Set 2 124 | //lcdWriteCommandWord(dev, 0x0022); // Write Data to GRAM 125 | lcdWriteDataWord(dev, color); // Write Data to GRAM 126 | } 127 | } 128 | } 129 | 130 | // Display OFF 131 | void ili9225_lcdDisplayOff(TFT_t *dev) { 132 | lcdWriteRegisterWord(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 133 | } 134 | 135 | // Display ON 136 | void ili9225_lcdDisplayOn(TFT_t *dev) { 137 | lcdWriteRegisterWord(dev, 0x0007, 0x1017); // Set GON=1 DTE=1 D1=1, D0=1 138 | } 139 | 140 | // Display Inversion OFF 141 | void ili9225_lcdInversionOff(TFT_t * dev) { 142 | lcdWriteRegisterWord(dev, 0x0007, 0x0013); 143 | } 144 | 145 | // Display Inversion ON 146 | void ili9225_lcdInversionOn(TFT_t * dev) { 147 | lcdWriteRegisterWord(dev, 0x0007, 0x0017); 148 | } 149 | -------------------------------------------------------------------------------- /driver/ili9225.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9225_H__ 2 | #define __ILI9225_H__ 3 | 4 | void ili9225_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9225_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9225_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9225_lcdDisplayOff(TFT_t * dev); 8 | void ili9225_lcdDisplayOn(TFT_t * dev); 9 | void ili9225_lcdInversionOff(TFT_t * dev); 10 | void ili9225_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9320.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9320.h" 6 | 7 | void ili9320_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9320, width, height, offsetx, offsety); 9 | 10 | static const uint16_t regValues[] = { 11 | 0x00e5, 0x8000, 12 | 0x0000, 0x0001, 13 | 0x0001, 0x100, 14 | 0x0002, 0x0700, 15 | 0x0003, 0x1030, 16 | 0x0004, 0x0000, 17 | 0x0008, 0x0202, 18 | 0x0009, 0x0000, 19 | 0x000A, 0x0000, 20 | 0x000C, 0x0000, 21 | 0x000D, 0x0000, 22 | 0x000F, 0x0000, 23 | //-----Power On sequence----------------------- 24 | 0x0010, 0x0000, 25 | 0x0011, 0x0007, 26 | 0x0012, 0x0000, 27 | 0x0013, 0x0000, 28 | TFTLCD_DELAY, 50, 29 | 0x0010, 0x17B0, //SAP=1, BT=7, APE=1, AP=3 30 | 0x0011, 0x0007, //DC1=0, DC0=0, VC=7 31 | TFTLCD_DELAY, 10, 32 | 0x0012, 0x013A, //VCMR=1, PON=3, VRH=10 33 | TFTLCD_DELAY, 10, 34 | 0x0013, 0x1A00, //VDV=26 35 | 0x0029, 0x000c, //VCM=12 36 | TFTLCD_DELAY, 10, 37 | //-----Gamma control----------------------- 38 | 0x0030, 0x0000, 39 | 0x0031, 0x0505, 40 | 0x0032, 0x0004, 41 | 0x0035, 0x0006, 42 | 0x0036, 0x0707, 43 | 0x0037, 0x0105, 44 | 0x0038, 0x0002, 45 | 0x0039, 0x0707, 46 | 0x003C, 0x0704, 47 | 0x003D, 0x0807, 48 | //-----Set RAM area----------------------- 49 | 0x0060, 0xA700, //GS=1 50 | //0x0060, 0x2700, //GS=1 51 | 0x0061, 0x0001, 52 | 0x006A, 0x0000, 53 | 0x0021, 0x0000, 54 | 0x0020, 0x0000, 55 | //-----Partial Display Control------------ 56 | 0x0080, 0x0000, 57 | 0x0081, 0x0000, 58 | 0x0082, 0x0000, 59 | 0x0083, 0x0000, 60 | 0x0084, 0x0000, 61 | 0x0085, 0x0000, 62 | //-----Panel Control---------------------- 63 | 0x0090, 0x0010, 64 | 0x0092, 0x0000, 65 | 0x0093, 0x0003, 66 | 0x0095, 0x0110, 67 | 0x0097, 0x0000, 68 | 0x0098, 0x0000, 69 | //-----Display on----------------------- 70 | 0x0007, 0x0173, 71 | TFTLCD_DELAY, 50, 72 | }; 73 | lcdInitTable16(dev, regValues, sizeof(regValues)); 74 | 75 | // ili9320 custom function 76 | DrawPixel = ili9325_lcdDrawPixel; 77 | DrawFillRect = ili9325_lcdDrawFillRect; 78 | DisplayOff = ili9325_lcdDisplayOff; 79 | DisplayOn = ili9325_lcdDisplayOn; 80 | InversionOff = ili9325_lcdInversionOff; 81 | InversionOn = ili9325_lcdInversionOn; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /driver/ili9320.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9320_H__ 2 | #define __ILI9320_H__ 3 | 4 | void ili9320_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9325_lcdDisplayOff(TFT_t * dev); 8 | void ili9325_lcdDisplayOn(TFT_t * dev); 9 | void ili9325_lcdInversionOff(TFT_t * dev); 10 | void ili9325_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9325.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9325.h" 6 | 7 | void ili9325_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9325, width, height, offsetx, offsety); 9 | //printf("ili9325_lcdInit _model=%x\n", dev->_model); 10 | 11 | static const uint16_t regValues[] = { 12 | 0x00E5, 0x78F0, // set SRAM internal timing 13 | 0x0001, 0x0100, // set Driver Output Control 14 | 0x0002, 0x0200, // set 1 line inversion 15 | 0x0003, 0x1030, // set GRAM write direction and BGR=1. 16 | 0x0004, 0x0000, // Resize register 17 | 0x0005, 0x0000, // .kbv 16bits Data Format Selection 18 | 0x0008, 0x0207, // set the back porch and front porch 19 | 0x0009, 0x0000, // set non-display area refresh cycle ISC[3:0] 20 | 0x000A, 0x0000, // FMARK function 21 | 0x000C, 0x0000, // RGB interface setting 22 | 0x000D, 0x0000, // Frame marker Position 23 | 0x000F, 0x0000, // RGB interface polarity 24 | // ----------- Power On sequence ----------- // 25 | 0x0010, 0x0000, // SAP, BT[3:0], AP, DSTB, SLP, STB 26 | 0x0011, 0x0007, // DC1[2:0], DC0[2:0], VC[2:0] 27 | 0x0012, 0x0000, // VREG1OUT voltage 28 | 0x0013, 0x0000, // VDV[4:0] for VCOM amplitude 29 | 0x0007, 0x0001, 30 | TFTLCD_DELAY, 200, // Dis-charge capacitor power voltage 31 | 0x0010, 0x1690, // SAP=1, BT=6, APE=1, AP=1, DSTB=0, SLP=0, STB=0 32 | 0x0011, 0x0227, // DC1=2, DC0=2, VC=7 33 | TFTLCD_DELAY, 50, // wait_ms 50ms 34 | 0x0012, 0x000D, // VCIRE=1, PON=0, VRH=5 35 | TFTLCD_DELAY, 50, // wait_ms 50ms 36 | 0x0013, 0x1200, // VDV=28 for VCOM amplitude 37 | 0x0029, 0x000A, // VCM=10 for VCOMH 38 | 0x002B, 0x000D, // Set Frame Rate 39 | TFTLCD_DELAY, 50, // wait_ms 50ms 40 | 0x0020, 0x0000, // GRAM horizontal Address 41 | 0x0021, 0x0000, // GRAM Vertical Address 42 | // ----------- Adjust the Gamma Curve ----------// 43 | 44 | 0x0030, 0x0000, 45 | 0x0031, 0x0404, 46 | 0x0032, 0x0003, 47 | 0x0035, 0x0405, 48 | 0x0036, 0x0808, 49 | 0x0037, 0x0407, 50 | 0x0038, 0x0303, 51 | 0x0039, 0x0707, 52 | 0x003C, 0x0504, 53 | 0x003D, 0x0808, 54 | 55 | //------------------ Set GRAM area ---------------// 56 | 0x0060, 0x2700, // Gate Scan Line GS=0 [0xA700] 57 | //0x0060, 0xA700, // Gate Scan Line GS=0 [0xA700] 58 | 0x0061, 0x0001, // NDL,VLE, REV .kbv 59 | 0x006A, 0x0000, // set scrolling line 60 | //-------------- Partial Display Control ---------// 61 | 0x0080, 0x0000, 62 | 0x0081, 0x0000, 63 | 0x0082, 0x0000, 64 | 0x0083, 0x0000, 65 | 0x0084, 0x0000, 66 | 0x0085, 0x0000, 67 | //-------------- Panel Control -------------------// 68 | 0x0090, 0x0010, 69 | 0x0092, 0x0000, 70 | 0x0007, 0x0133, // 262K color and display ON 71 | }; 72 | lcdInitTable16(dev, regValues, sizeof(regValues)); 73 | 74 | // ili9325 custom function 75 | DrawPixel = ili9325_lcdDrawPixel; 76 | DrawFillRect = ili9325_lcdDrawFillRect; 77 | DisplayOff = ili9325_lcdDisplayOff; 78 | DisplayOn = ili9325_lcdDisplayOn; 79 | InversionOff = ili9325_lcdInversionOff; 80 | InversionOn = ili9325_lcdInversionOn; 81 | } 82 | 83 | // Draw pixel 84 | // x:X coordinate 85 | // y:Y coordinate 86 | // color:color 87 | void ili9325_lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color) { 88 | if (x >= dev->_width) return; 89 | if (y >= dev->_height) return; 90 | 91 | uint16_t _x = x + dev->_offsetx; 92 | uint16_t _y = y + dev->_offsety; 93 | 94 | lcdWriteRegisterWord(dev, 0x0020, _x); // RAM Address Set 1 95 | lcdWriteRegisterWord(dev, 0x0021, _y); // RAM Address Set 2 96 | lcdWriteRegisterWord(dev, 0x0022, color); // Write Data to GRAM 97 | } 98 | 99 | // Draw rectangule of filling 100 | // x1:Start X coordinate 101 | // y1:Start Y coordinate 102 | // x2:End X coordinate 103 | // y2:End Y coordinate 104 | // color:color 105 | void ili9325_lcdDrawFillRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color){ 106 | if (x1 >= dev->_width) return; 107 | if (x2 >= dev->_width) x2 = dev->_width-1; 108 | if (y1 >= dev->_height) return; 109 | if (y2 >= dev->_height) y2 = dev->_height-1; 110 | 111 | uint16_t _x1 = x1 + dev->_offsetx; 112 | uint16_t _x2 = x2 + dev->_offsetx; 113 | uint16_t _y1 = y1 + dev->_offsety; 114 | uint16_t _y2 = y2 + dev->_offsety; 115 | 116 | for(int _y=_y1;_y<=_y2;_y++){ 117 | lcdWriteRegisterWord(dev, 0x0020, _x1); // RAM Address Set 1 118 | lcdWriteRegisterWord(dev, 0x0021, _y); // RAM Address Set 2 119 | lcdWriteCommandWord(dev, 0x0022); // Write Data to GRAM 120 | for(int _x=_x1;_x<=_x2;_x++){ 121 | lcdWriteDataWord(dev, color); // Write Data to GRAM 122 | } 123 | } 124 | } 125 | 126 | // Display OFF 127 | void ili9325_lcdDisplayOff(TFT_t *dev) { 128 | lcdWriteRegisterWord(dev, 0x0007, 0x0000); // Set GON=0 DTE=0 D1=0, D0=0 129 | } 130 | 131 | // Display ON 132 | void ili9325_lcdDisplayOn(TFT_t *dev) { 133 | lcdWriteRegisterWord(dev, 0x0007, 0x0173); // Set GON=1 DTE=1 D1=1, D0=1 134 | } 135 | 136 | // Display Inversion OFF 137 | void ili9325_lcdInversionOff(TFT_t * dev) { 138 | lcdWriteRegisterWord(dev, 0x0061, 0x0001); 139 | } 140 | 141 | // Display Inversion ON 142 | void ili9325_lcdInversionOn(TFT_t * dev) { 143 | lcdWriteRegisterWord(dev, 0x0061, 0x0000); 144 | } 145 | -------------------------------------------------------------------------------- /driver/ili9325.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9325_H__ 2 | #define __ILI9325_H__ 3 | 4 | void ili9325_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9325_lcdDisplayOff(TFT_t * dev); 8 | void ili9325_lcdDisplayOn(TFT_t * dev); 9 | void ili9325_lcdInversionOff(TFT_t * dev); 10 | void ili9325_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9327.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9327.h" 6 | 7 | void ili9327_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9327, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0x36, 1, 0x08, 25 | 0x3A, 1, 0x05, 26 | 0xC0, 6, 0x00, 0x35, 0x00, 0x00, 0x01, 0x02, 27 | 0xC1, 4, 0x10, 0x10, 0x02, 0x02, 28 | 0xC5, 1, 0x04, 29 | 0xC8,15, 0x04, 0x67, 0x35, 0x04, 0x08, 0x06, 0x24, 0x01, 0x37, 0x40, 0x03, 0x10, 0x08, 0x80, 0x00, 30 | 0xD0, 3, 0x07, 0x04, 0x00, 31 | 0xD1, 3, 0x00, 0x0C, 0x0F, 32 | 0xD2, 2, 0x01, 0x44, 33 | }; 34 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 35 | lcdInitTable(dev, regValues, sizeof(regValues)); 36 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 37 | 38 | // ili9327 custom function 39 | DrawPixel = ili9341_lcdDrawPixel; 40 | DrawFillRect = ili9341_lcdDrawFillRect; 41 | DisplayOff = ili9341_lcdDisplayOff; 42 | DisplayOn = ili9341_lcdDisplayOn; 43 | InversionOff = ili9341_lcdInversionOff; 44 | InversionOn = ili9341_lcdInversionOn; 45 | } 46 | -------------------------------------------------------------------------------- /driver/ili9327.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9327_H__ 2 | #define __ILI9327_H__ 3 | 4 | void ili9327_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9341.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9341.h" 6 | 7 | void ili9341_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9341, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0xC0, 1, 0x23, 25 | 0xC1, 1, 0x10, 26 | 0xC5, 2, 0x3E, 0x28, 27 | 0xC7, 1, 0x86, 28 | 0x36, 1, 0x98, 29 | 0xB1, 2, 0x00, 0x18, 30 | 0xB6, 4, 0x0A, 0xA2, 0x27, 0x04, 31 | 0x26, 1, 0x01, 32 | 0xE0,15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, 33 | 0xE1,15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, 34 | }; 35 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 36 | lcdInitTable(dev, regValues, sizeof(regValues)); 37 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 38 | 39 | // ili9341 custom function 40 | DrawPixel = ili9341_lcdDrawPixel; 41 | DrawFillRect = ili9341_lcdDrawFillRect; 42 | DisplayOff = ili9341_lcdDisplayOff; 43 | DisplayOn = ili9341_lcdDisplayOn; 44 | InversionOff = ili9341_lcdInversionOff; 45 | InversionOn = ili9341_lcdInversionOn; 46 | } 47 | 48 | // Draw pixel 49 | // x:X coordinate 50 | // y:Y coordinate 51 | // color:color 52 | void ili9341_lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color) { 53 | if (x >= dev->_width) return; 54 | if (y >= dev->_height) return; 55 | 56 | uint16_t _x = x + dev->_offsetx; 57 | uint16_t _y = y + dev->_offsety; 58 | 59 | lcdWriteCommandByte(dev, 0x2A); // set column(x) address 60 | lcdWriteDataWord(dev, _x); 61 | lcdWriteDataWord(dev, _x); 62 | lcdWriteCommandByte(dev, 0x2B); // set Page(y) address 63 | lcdWriteDataWord(dev, _y); 64 | lcdWriteDataWord(dev, _y); 65 | lcdWriteCommandByte(dev, 0x2C); // Memory Write 66 | #ifndef P16BIT 67 | lcdWriteDataWord(dev, color); 68 | #else 69 | lcdWriteDataWord_16bit(dev, color); 70 | #endif 71 | } 72 | 73 | // Draw rectangule of filling 74 | // x1:Start X coordinate 75 | // y1:Start Y coordinate 76 | // x2:End X coordinate 77 | // y2:End Y coordinate 78 | // color:color 79 | void ili9341_lcdDrawFillRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color){ 80 | if (x1 >= dev->_width) return; 81 | if (x2 >= dev->_width) x2 = dev->_width-1; 82 | if (y1 >= dev->_height) return; 83 | if (y2 >= dev->_height) y2 = dev->_height-1; 84 | 85 | uint16_t _x1 = x1 + dev->_offsetx; 86 | uint16_t _x2 = x2 + dev->_offsetx; 87 | uint16_t _y1 = y1 + dev->_offsety; 88 | uint16_t _y2 = y2 + dev->_offsety; 89 | 90 | lcdWriteCommandByte(dev, 0x2A); // set column(x) address 91 | lcdWriteDataWord(dev, _x1); 92 | lcdWriteDataWord(dev, _x2); 93 | lcdWriteCommandByte(dev, 0x2B); // set Page(y) address 94 | lcdWriteDataWord(dev, _y1); 95 | lcdWriteDataWord(dev, _y2); 96 | lcdWriteCommandByte(dev, 0x2C); // Memory Write 97 | 98 | for(int i=_x1;i<=_x2;i++){ 99 | for(int j=_y1;j<=_y2;j++){ 100 | #ifndef P16BIT 101 | lcdWriteDataWord(dev, color); 102 | #else 103 | lcdWriteDataWord_16bit(dev, color); 104 | #endif 105 | } 106 | } 107 | } 108 | 109 | // Display OFF 110 | void ili9341_lcdDisplayOff(TFT_t *dev) { 111 | lcdWriteCommandByte(dev, 0x28); 112 | } 113 | 114 | // Display ON 115 | void ili9341_lcdDisplayOn(TFT_t *dev) { 116 | lcdWriteCommandByte(dev, 0x29); 117 | } 118 | 119 | // Display Inversion OFF 120 | void ili9341_lcdInversionOff(TFT_t * dev) { 121 | lcdWriteCommandByte(dev, 0x20); 122 | } 123 | 124 | // Display Inversion ON 125 | void ili9341_lcdInversionOn(TFT_t * dev) { 126 | lcdWriteCommandByte(dev, 0x21); 127 | } 128 | -------------------------------------------------------------------------------- /driver/ili9341.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9341_H__ 2 | #define __ILI9341_H__ 3 | 4 | void ili9341_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9342.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9342.h" 6 | 7 | void ili9342_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9342, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0xC0, 2, 0x26, 0x09, 25 | 0xC1, 1, 0x10, 26 | 0xC5, 2, 0x3E, 0x28, 27 | 0xC7, 1, 0x86, 28 | 0x36, 1, 0xE8, 29 | 0xB1, 2, 0x00, 0x18, 30 | 0xB6, 4, 0x0A, 0xA2, 0x27, 0x04, 31 | 0x21, 0, // Display Inversion ON 32 | 0x26, 1, 0x01, 33 | 0xE0,15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, 34 | 0xE1,15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, 35 | }; 36 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 37 | lcdInitTable(dev, regValues, sizeof(regValues)); 38 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 39 | 40 | // ili9342 custom function 41 | DrawPixel = ili9341_lcdDrawPixel; 42 | DrawFillRect = ili9341_lcdDrawFillRect; 43 | DisplayOff = ili9341_lcdDisplayOff; 44 | DisplayOn = ili9341_lcdDisplayOn; 45 | InversionOff = ili9341_lcdInversionOff; 46 | InversionOn = ili9341_lcdInversionOn; 47 | } 48 | -------------------------------------------------------------------------------- /driver/ili9342.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9342_H__ 2 | #define __ILI9342_H__ 3 | 4 | void ili9342_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9481.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9481.h" 6 | 7 | void ili9481_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9481, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0xB0, 1, 0x00, // unlocks E0, F0 25 | 0xB3, 4, 0x02, 0x00, 0x00, 0x00, //Frame Memory, interface [02 00 00 00] 26 | 0xB4, 1, 0x00, // Frame mode [00] 27 | 0xD0, 3, 0x07, 0x42, 0x18, 28 | 0xD1, 3, 0x00, 0x07, 0x18, 29 | 0xD2, 2, 0x01, 0x02, 30 | 0xD3, 2, 0x01, 0x02, // Set Power for Partial Mode [01 22] 31 | 0xD4, 2, 0x01, 0x02, // Set Power for Idle Mode [01 22] 32 | 0xC0, 5, 0x10, 0x3B, 0x00, 0x02, 0x11, 33 | //0xC0, 5, 0x14, 0x3B, 0x00, 0x02, 0x11, 34 | 0xC1, 3, 0x10, 0x10, 0x88, // Display Timing Normal [10 10 88] 35 | 0xC5, 1, 0x03, //Frame Rate [03] 36 | 0xC6, 1, 0x02, //Interface Control [02] 37 | 0xC8, 12, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16, 0x37, 0x75, 0x77, 0x54, 0x0C, 0x00, 38 | 0xCC, 1, 0x00, //Panel Control [00] 39 | 0x36, 1, 0x18, //0x08, 40 | }; 41 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 42 | lcdInitTable(dev, regValues, sizeof(regValues)); 43 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 44 | 45 | // ili9481 custom function 46 | DrawPixel = ili9341_lcdDrawPixel; 47 | DrawFillRect = ili9341_lcdDrawFillRect; 48 | DisplayOff = ili9341_lcdDisplayOff; 49 | DisplayOn = ili9341_lcdDisplayOn; 50 | InversionOff = ili9341_lcdInversionOff; 51 | InversionOn = ili9341_lcdInversionOn; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /driver/ili9481.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9481_H__ 2 | #define __ILI9481_H__ 3 | 4 | void ili9481_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9486.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9486.h" 6 | 7 | void ili9486_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9486, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0xB0, 1, 0x00, // unlocks E0, F0 25 | 0xB3, 4, 0x02, 0x00, 0x00, 0x00, //Frame Memory, interface [02 00 00 00] 26 | 0xB4, 1, 0x00, // Frame mode [00] 27 | 0xB6, 3, 0x02, 0x02, 0x3B, // Display Function Control [02 02 3B] 28 | //0xB6, 3, 0x02, 0x42, 0x3B, // Display Function Control [02 02 3B] 29 | 0xD0, 3, 0x07, 0x42, 0x18, 30 | 0xD1, 3, 0x00, 0x07, 0x18, 31 | 0xD2, 2, 0x01, 0x02, 32 | 0xD3, 2, 0x01, 0x02, // Set Power for Partial Mode [01 22] 33 | //0xD4, 2, 0x01, 0x02, // Set Power for Idle Mode [01 22] 34 | //0xC0, 5, 0x10, 0x3B, 0x00, 0x02, 0x11, 35 | 0xC0, 5, 0x14, 0x3B, 0x00, 0x02, 0x11, 36 | 0xC1, 3, 0x10, 0x10, 0x88, // Display Timing Normal [10 10 88] 37 | 0xC5, 1, 0x03, //Frame Rate [03] 38 | 0xC6, 1, 0x02, //Interface Control [02] 39 | 0xC8, 12, 0x00, 0x32, 0x36, 0x45, 0x06, 0x16, 0x37, 0x75, 0x77, 0x54, 0x0C, 0x00, 40 | 0xCC, 1, 0x00, //Panel Control [00] 41 | 0x36, 1, 0x18, //0x08, 42 | }; 43 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 44 | lcdInitTable(dev, regValues, sizeof(regValues)); 45 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 46 | 47 | // ili9486 custom function 48 | DrawPixel = ili9341_lcdDrawPixel; 49 | DrawFillRect = ili9341_lcdDrawFillRect; 50 | DisplayOff = ili9341_lcdDisplayOff; 51 | DisplayOn = ili9341_lcdDisplayOn; 52 | InversionOff = ili9341_lcdInversionOff; 53 | InversionOn = ili9341_lcdInversionOn; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /driver/ili9486.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9486_H__ 2 | #define __ILI9486_H__ 3 | 4 | void ili9486_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/ili9488.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "ili9488.h" 6 | 7 | void ili9488_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x9488, width, height, offsetx, offsety); 9 | 10 | static const uint8_t reset_off[] = { 11 | 0x01, 0, //Soft Reset 12 | TFTLCD_DELAY8, 150, 13 | 0x28, 0, //Display Off 14 | 0x3A, 1, 0x55, //Pixel read=565, write=565. 15 | }; 16 | 17 | static const uint8_t wake_on[] = { 18 | 0x11, 0, //Sleep Out 19 | TFTLCD_DELAY8, 150, 20 | 0x29, 0, //Display On 21 | }; 22 | 23 | static const uint8_t regValues[] = { 24 | 0xC0, 2, 0x10, 0x10, //Power Control 1 [0E 0E] 25 | 0xC1, 1, 0x41, //Power Control 2 [43] 26 | 0xC5, 4, 0x00, 0x22, 0x80, 0x40, //VCOM Control 1 [00 40 00 40] 27 | //0x36, 1, 0x68, //Memory Access [00] 28 | //0x36, 1, 0x98, //Memory Access [00] 29 | 0x36, 1, 0x18, //Memory Access [00] 30 | 0xB0, 1, 0x00, //Interface [00] 31 | 0xB1, 2, 0xB0, 0x11, //Frame Rate Control [B0 11] 32 | 0xB4, 1, 0x02, //Inversion Control [02] 33 | 0xB6, 3, 0x02, 0x02, 0x3B, // Display Function Control [02 02 3B] .kbv NL=480 34 | 0xB7, 1, 0xC6, //Entry Mode [06] 35 | 0x3A, 1, 0x55, //Interlace Pixel Format [XX] 36 | 0xF7, 4, 0xA9, 0x51, 0x2C, 0x82, //Adjustment Control 3 [A9 51 2C 82] 37 | }; 38 | lcdInitTable(dev, reset_off, sizeof(reset_off)); 39 | lcdInitTable(dev, regValues, sizeof(regValues)); 40 | lcdInitTable(dev, wake_on, sizeof(wake_on)); 41 | 42 | // ili9488 custom function 43 | DrawPixel = ili9341_lcdDrawPixel; 44 | DrawFillRect = ili9341_lcdDrawFillRect; 45 | DisplayOff = ili9341_lcdDisplayOff; 46 | DisplayOn = ili9341_lcdDisplayOn; 47 | InversionOff = ili9341_lcdInversionOff; 48 | InversionOn = ili9341_lcdInversionOn; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /driver/ili9488.h: -------------------------------------------------------------------------------- 1 | #ifndef __ILI9488_H__ 2 | #define __ILI9488_H__ 3 | 4 | void ili9488_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9341_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9341_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9341_lcdDisplayOff(TFT_t * dev); 8 | void ili9341_lcdDisplayOn(TFT_t * dev); 9 | void ili9341_lcdInversionOff(TFT_t * dev); 10 | void ili9341_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/lgdp4532.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "lgdp4532.h" 6 | 7 | void lgdp4532_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x4532, width, height, offsetx, offsety); 9 | 10 | static const uint16_t LGDP4532_regValues[] = { 11 | 0x0000,0x0001, //Device code read 12 | 0x0010,0x0628, //Power control 1 SAP[2:0] BT[3:0] AP[2:0] DK DSTB SLP 13 | 0x0012,0x0006, //Power control 3 PON VRH[3:0] 14 | //0x0013,0x0A32, //Power control 4 VCOMG VDV[4:0] VCM[6:0] 15 | 0x0011,0x0040, //Power control 2; DC1[2:0] DC0[2:0] VC[2:0] 16 | //0x0015,0x0050, //Regulator control RSET RI[2:0] RV[2:0] RCONT[2:0] 17 | 0x0012,0x0016, //Power control 3 PON VRH[3:0] 18 | TFTLCD_DELAY,50, 19 | 0x0010,0x5660, //Power control 1 SAP[2:0] BT[3:0] AP[2:0] DK DSTB SLP 20 | TFTLCD_DELAY,50, 21 | //0x0013,0x2A4E, //Power control 4 VCOMG VDV[4:0] VCM[6:0] 22 | //0x0001,0x0100, //Driver output control SM SS 23 | //0x0002,0x0300, //LCD Driving Wave Control 24 | 0x0003,0x1030, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 25 | //0x0003,0x1020, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 26 | //0x0003,0x1010, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 27 | //0x0003,0x1000, //Entry mode TRI DFM BGR ORG I/D[1:0] AM 28 | //0x0007,0x0202, //Display Control 1 PTDE[1:0] BASEE GON DTE COL D[1:0] 29 | TFTLCD_DELAY,50, 30 | //0x0008,0x0202, //Display Control 2 FP[3:0] BP[3:0] front and back porch (blank period at begin and end..) 31 | //0x000A,0x0000, //Test Register 1 (RA0h) 32 | //Gamma adjustment 33 | 0x0030,0x0000, 34 | 0x0031,0x0402, 35 | 0x0032,0x0106, 36 | 0x0033,0x0700, 37 | 0x0034,0x0104, 38 | 0x0035,0x0301, 39 | 0x0036,0x0707, 40 | 0x0037,0x0305, 41 | 0x0038,0x0208, 42 | 0x0039,0x0F0B, 43 | TFTLCD_DELAY,50, 44 | //some of this stuff in range 41-93 really throws things off.... 45 | //0x0041,0x0002, 46 | //0x0060,0x2700, //Driver Output Control (R60h) 47 | 0x0060,0xA700, //Driver Output Control (R60h) 48 | 0x0061,0x0001, //Base Image Display Control (R61h) 49 | //0x0090,0x0119, //Panel Interface Control 1 (R90h) DIVI[1:0] RTNI[4:0] 50 | //0x0092,0x010A, //Panel Interface Control 2 (R92h) NOWI[2:0] EQI2[1:0] EQI1[1:0] 51 | //0x0093,0x0004, //Panel Interface Control 3 (R93h) MCPI[2:0] 52 | //0x00A0,0x0100, //Test Register 1 (RA0h) 53 | TFTLCD_DELAY,50, 54 | 0x0007,0x0133, //Display Control 1 PTDE[1:0] BASEE GON DTE COL D[1:0] 55 | TFTLCD_DELAY,50, 56 | //0x00A0,0x0000, //Test Register 1 (RA0h) 57 | }; 58 | lcdInitTable16(dev, LGDP4532_regValues, sizeof(LGDP4532_regValues)); 59 | 60 | // lgdp4532 custom function 61 | DrawPixel = ili9325_lcdDrawPixel; 62 | DrawFillRect = ili9325_lcdDrawFillRect; 63 | DisplayOff = ili9325_lcdDisplayOff; 64 | DisplayOn = ili9325_lcdDisplayOn; 65 | InversionOff = ili9325_lcdInversionOff; 66 | InversionOn = ili9325_lcdInversionOn; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /driver/lgdp4532.h: -------------------------------------------------------------------------------- 1 | #ifndef __LGDP4532_H__ 2 | #define __LGDP4532_H__ 3 | 4 | void lgdp4532_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9325_lcdDisplayOff(TFT_t * dev); 8 | void ili9325_lcdDisplayOn(TFT_t * dev); 9 | void ili9325_lcdInversionOff(TFT_t * dev); 10 | void ili9325_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/r61509.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "r61509.h" 6 | 7 | void r61509_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x1509, width, height, offsetx, offsety); 9 | 10 | static const uint16_t regValues[] = { 11 | //0x0400, 0x6200, 12 | 0x0008, 0x0808, 13 | 0x0010, 0x0016, //69.5Hz 0016 14 | 0x0011, 0x0101, 15 | 0x0012, 0x0000, 16 | 0x0013, 0x0001, 17 | 0x0100, 0x0330, //BT,AP 18 | 0x0101, 0x0237, //DC0,DC1,VC 19 | 0x0103, 0x0D00, //VDV 20 | 0x0280, 0x6100, //VCM 21 | 0x0102, 0xC1B0, //VRH,VCMR,PSON,PON 22 | TFTLCD_DELAY16,50, 23 | // 0x0001, 0x0100, 24 | 0x0001, 0x0000, 25 | 0x0002, 0x0100, 26 | 0x0003, 0x1030, //1030 27 | 0x0009, 0x0001, 28 | 0x000C, 0x0000, 29 | 0x0090, 0x8000, 30 | 0x000F, 0x0000, 31 | 0x0210, 0x0000, 32 | 0x0211, 0x00EF, 33 | 0x0212, 0x0000, 34 | 0x0213, 0x018F, //432=01AF,400=018F 35 | 0x0500, 0x0000, 36 | 0x0501, 0x0000, 37 | 0x0502, 0x005F, 38 | 0x0400, 0x6200, 39 | //0x0400, 0xE200, 40 | 0x0401, 0x0001, 41 | 0x0404, 0x0000, 42 | TFTLCD_DELAY16,50, 43 | 0x0007, 0x0100, //BASEE 44 | TFTLCD_DELAY16,50, 45 | 0x0200, 0x0000, 46 | 0x0201, 0x0000, 47 | }; 48 | lcdInitTable16(dev, regValues, sizeof(regValues)); 49 | 50 | // r61509 custom function 51 | DrawPixel = r61509_lcdDrawPixel; 52 | DrawFillRect = r61509_lcdDrawFillRect; 53 | DisplayOff = r61509_lcdDisplayOff; 54 | DisplayOn = r61509_lcdDisplayOn; 55 | InversionOff = r61509_lcdInversionOff; 56 | InversionOn = r61509_lcdInversionOn; 57 | } 58 | 59 | // Draw pixel 60 | // x:X coordinate 61 | // y:Y coordinate 62 | // color:color 63 | void r61509_lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color) { 64 | if (x >= dev->_width) return; 65 | if (y >= dev->_height) return; 66 | 67 | uint16_t _x = x + dev->_offsetx; 68 | uint16_t _y = y + dev->_offsety; 69 | 70 | lcdWriteRegisterWord(dev, 0x0200, _x); // RAM Address Set 1 71 | lcdWriteRegisterWord(dev, 0x0201, _y); // RAM Address Set 2 72 | lcdWriteRegisterWord(dev, 0x0202, color); // Write Data to GRAM 73 | } 74 | 75 | // Draw rectangule of filling 76 | // x1:Start X coordinate 77 | // y1:Start Y coordinate 78 | // x2:End X coordinate 79 | // y2:End Y coordinate 80 | // color:color 81 | void r61509_lcdDrawFillRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color){ 82 | if (x1 >= dev->_width) return; 83 | if (x2 >= dev->_width) x2 = dev->_width-1; 84 | if (y1 >= dev->_height) return; 85 | if (y2 >= dev->_height) y2 = dev->_height-1; 86 | 87 | uint16_t _x1 = x1 + dev->_offsetx; 88 | uint16_t _x2 = x2 + dev->_offsetx; 89 | uint16_t _y1 = y1 + dev->_offsety; 90 | uint16_t _y2 = y2 + dev->_offsety; 91 | 92 | for(int _y=_y1;_y<=_y2;_y++){ 93 | lcdWriteRegisterWord(dev, 0x0200, _x1); // RAM Address Set 1 94 | lcdWriteRegisterWord(dev, 0x0201, _y); // RAM Address Set 2 95 | lcdWriteCommandWord(dev, 0x0202); // Write Data to GRAM 96 | for(int _x=_x1;_x<=_x2;_x++){ 97 | lcdWriteDataWord(dev, color); // Write Data to GRAM 98 | } 99 | } 100 | } 101 | 102 | // Display OFF 103 | void r61509_lcdDisplayOff(TFT_t *dev) { 104 | lcdWriteRegisterWord(dev, 0x0007, 0x0000); // Display Control 1 105 | } 106 | 107 | // Display ON 108 | void r61509_lcdDisplayOn(TFT_t *dev) { 109 | lcdWriteRegisterWord(dev, 0x0007, 0x0100); // Display Control 1 110 | } 111 | 112 | // Display Inversion OFF 113 | void r61509_lcdInversionOff(TFT_t * dev) { 114 | // I can't find register 115 | //lcdWriteRegisterWord(dev, 0x0003, 0x1030); // Display Control 1 116 | } 117 | 118 | // Display Inversion ON 119 | void r61509_lcdInversionOn(TFT_t * dev) { 120 | // I can't find register 121 | //lcdWriteRegisterWord(dev, 0x0003, 0x0030); // Display Control 1 122 | } 123 | -------------------------------------------------------------------------------- /driver/r61509.h: -------------------------------------------------------------------------------- 1 | #ifndef __R61509_H__ 2 | #define __R61509_H__ 3 | 4 | void r61509_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void r61509_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void r61509_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void r61509_lcdDisplayOff(TFT_t * dev); 8 | void r61509_lcdDisplayOn(TFT_t * dev); 9 | void r61509_lcdInversionOff(TFT_t * dev); 10 | void r61509_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/s6d1121.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "s6d1121.h" 6 | 7 | void s6d1121_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | lcdInit(dev, 0x1121, width, height, offsetx, offsety); 9 | 10 | static const uint16_t regValues[] = { 11 | 0x0011,0x2004, 12 | 0x0013,0xCC00, 13 | 0x0015,0x2600, 14 | 0x0014,0x252A, 15 | 0x0012,0x0033, 16 | 0x0013,0xCC04, 17 | 0x0013,0xCC06, 18 | 0x0013,0xCC4F, 19 | 0x0013,0x674F, 20 | 0x0011,0x2003, 21 | 0x0030,0x2609, 22 | 0x0031,0x242C, 23 | 0x0032,0x1F23, 24 | 0x0033,0x2425, 25 | 0x0034,0x2226, 26 | 0x0035,0x2523, 27 | 0x0036,0x1C1A, 28 | 0x0037,0x131D, 29 | 0x0038,0x0B11, 30 | 0x0039,0x1210, 31 | 0x003A,0x1315, 32 | 0x003B,0x3619, 33 | 0x003C,0x0D00, 34 | 0x003D,0x000D, 35 | 0x0016,0x0007, 36 | //0x0001,0x0127, 37 | 0x0001,0x0027, 38 | 0x0002,0x0013, 39 | 0x0003,0x0003, 40 | 0x0008,0x0303, 41 | 0x000A,0x000B, 42 | 0x000B,0x0003, 43 | 0x000C,0x0000, 44 | 0x0041,0x0000, 45 | 0x0050,0x0000, 46 | 0x0060,0x0005, 47 | 0x0070,0x000B, 48 | 0x0071,0x0000, 49 | 0x0078,0x0000, 50 | 0x007A,0x0000, 51 | 0x0079,0x0007, 52 | //0x0007,0x0051, 53 | 0x0007,0x0053, 54 | 0x0079,0x0000, 55 | }; 56 | lcdInitTable16(dev, regValues, sizeof(regValues)); 57 | 58 | // s6d1121 custom function 59 | DrawPixel = ili9325_lcdDrawPixel; 60 | DrawFillRect = ili9325_lcdDrawFillRect; 61 | DisplayOff = ili9325_lcdDisplayOff; 62 | DisplayOn = ili9325_lcdDisplayOn; 63 | InversionOff = ili9325_lcdInversionOff; 64 | InversionOn = ili9325_lcdInversionOn; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /driver/s6d1121.h: -------------------------------------------------------------------------------- 1 | #ifndef __S6D1121_H__ 2 | #define __S6D1121_H__ 3 | 4 | void s6d1121_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9325_lcdDisplayOff(TFT_t * dev); 8 | void ili9325_lcdDisplayOn(TFT_t * dev); 9 | void ili9325_lcdInversionOff(TFT_t * dev); 10 | void ili9325_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /driver/st7781.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../tft_lib.h" 5 | #include "st7781.h" 6 | 7 | void st7781_lcdInit(TFT_t *dev, int width, int height, int offsetx, int offsety) { 8 | #ifdef ST7781 9 | lcdInit(dev, 0x7781, width, height, offsetx, offsety); 10 | #elif defined ST7783 11 | lcdInit(dev, 0x7783, width, height, offsetx, offsety); 12 | #endif 13 | printf("st7781_lcdInit _model=%x\n", dev->_model); 14 | 15 | static const uint16_t regValues[] = { 16 | 0x00FF, 0x0001, //can we do 0xFF 17 | 0x00F3, 0x0008, 18 | 0x0000, 0x0001, 19 | 0x0001, 0x0000, // Driver Output Control Register (R01h) 20 | 0x0002, 0x0700, // LCD Driving Waveform Control (R02h) 21 | 0x0003, 0x1030, // Entry Mode (R03h) 22 | 0x0008, 0x0302, 23 | 0x0009, 0x0000, 24 | 0x0010, 0x0000, // Power Control 1 (R10h) 25 | 0x0011, 0x0007, // Power Control 2 (R11h) 26 | 0x0012, 0x0000, // Power Control 3 (R12h) 27 | 0x0013, 0x0000, // Power Control 4 (R13h) 28 | TFTLCD_DELAY16,50, 29 | 0x0010, 0x14B0, // Power Control 1 SAP=1, BT=4, APE=1, AP=3 30 | TFTLCD_DELAY16,10, 31 | 0x0011, 0x0007, // Power Control 2 VC=7 32 | TFTLCD_DELAY16,10, 33 | 0x0012, 0x008E, // Power Control 3 VCIRE=1, VRH=14 34 | 0x0013, 0x0C00, // Power Control 4 VDV=12 35 | 0x0029, 0x0015, // NVM read data 2 VCM=21 36 | TFTLCD_DELAY16,10, 37 | 0x0030, 0x0000, // Gamma Control 1 38 | 0x0031, 0x0107, // Gamma Control 2 39 | 0x0032, 0x0000, // Gamma Control 3 40 | 0x0035, 0x0203, // Gamma Control 6 41 | 0x0036, 0x0402, // Gamma Control 7 42 | 0x0037, 0x0000, // Gamma Control 8 43 | 0x0038, 0x0207, // Gamma Control 9 44 | 0x0039, 0x0000, // Gamma Control 10 45 | 0x003C, 0x0203, // Gamma Control 13 46 | 0x003D, 0x0403, // Gamma Control 14 47 | 0x0060, 0xA700, // Driver Output Control (R60h) .kbv was 0xa700 48 | 0x0061, 0x0001, // Driver Output Control (R61h) 49 | 0x0090, 0X0029, // Panel Interface Control 1 (R90h) 50 | 0x0007, 0x0133, // Display Control (R07h) 51 | }; 52 | lcdInitTable16(dev, regValues, sizeof(regValues)); 53 | 54 | #if 0 55 | lcdWriteRegisterWord(dev, 0x00FF, 0x0001); //can we do 0xFF 56 | lcdWriteRegisterWord(dev, 0x00F3, 0x0008); 57 | lcdWriteRegisterWord(dev, 0x0000, 0x0001); 58 | lcdWriteRegisterWord(dev, 0x0001, 0x0000); // Driver Output Control Register (R01h) 59 | lcdWriteRegisterWord(dev, 0x0002, 0x0700); // LCD Driving Waveform Control (R02h) 60 | lcdWriteRegisterWord(dev, 0x0003, 0x1030); // Entry Mode (R03h) 61 | lcdWriteRegisterWord(dev, 0x0008, 0x0302); 62 | lcdWriteRegisterWord(dev, 0x0009, 0x0000); 63 | lcdWriteRegisterWord(dev, 0x0010, 0x0000); // Power Control 1 (R10h) 64 | lcdWriteRegisterWord(dev, 0x0011, 0x0007); // Power Control 2 (R11h) 65 | lcdWriteRegisterWord(dev, 0x0012, 0x0000); // Power Control 3 (R12h) 66 | lcdWriteRegisterWord(dev, 0x0013, 0x0000); // Power Control 4 (R13h) 67 | TFTLCD_DELAY16(50); 68 | lcdWriteRegisterWord(dev, 0x0010, 0x14B0); // Power Control 1 SAP=1, BT=4, APE=1, AP=3 69 | TFTLCD_DELAY16(10); 70 | lcdWriteRegisterWord(dev, 0x0011, 0x0007); // Power Control 2 VC=7 71 | TFTLCD_DELAY16(10); 72 | lcdWriteRegisterWord(dev, 0x0012, 0x008E); // Power Control 3 VCIRE=1, VRH=14 73 | lcdWriteRegisterWord(dev, 0x0013, 0x0C00); // Power Control 4 VDV=12 74 | lcdWriteRegisterWord(dev, 0x0029, 0x0015); // NVM read data 2 VCM=21 75 | TFTLCD_DELAY16(10); 76 | lcdWriteRegisterWord(dev, 0x0030, 0x0000); // Gamma Control 1 77 | lcdWriteRegisterWord(dev, 0x0031, 0x0107); // Gamma Control 2 78 | lcdWriteRegisterWord(dev, 0x0032, 0x0000); // Gamma Control 3 79 | lcdWriteRegisterWord(dev, 0x0035, 0x0203); // Gamma Control 6 80 | lcdWriteRegisterWord(dev, 0x0036, 0x0402); // Gamma Control 7 81 | lcdWriteRegisterWord(dev, 0x0037, 0x0000); // Gamma Control 8 82 | lcdWriteRegisterWord(dev, 0x0038, 0x0207); // Gamma Control 9 83 | lcdWriteRegisterWord(dev, 0x0039, 0x0000); // Gamma Control 10 84 | lcdWriteRegisterWord(dev, 0x003C, 0x0203); // Gamma Control 13 85 | lcdWriteRegisterWord(dev, 0x003D, 0x0403); // Gamma Control 14 86 | lcdWriteRegisterWord(dev, 0x0060, 0xA700); // Driver Output Control (R60h) .kbv was 0xa700 87 | lcdWriteRegisterWord(dev, 0x0061, 0x0001); // Driver Output Control (R61h) 88 | lcdWriteRegisterWord(dev, 0x0090, 0X0029); // Panel Interface Control 1 (R90h) 89 | lcdWriteRegisterWord(dev, 0x0007, 0x0133); // Display Control (R07h) 90 | #endif 91 | 92 | // st7781 custom function 93 | DrawPixel = ili9325_lcdDrawPixel; 94 | DrawFillRect = ili9325_lcdDrawFillRect; 95 | DisplayOff = ili9325_lcdDisplayOff; 96 | DisplayOn = ili9325_lcdDisplayOn; 97 | InversionOff = ili9325_lcdInversionOff; 98 | InversionOn = ili9325_lcdInversionOn; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /driver/st7781.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7781_H__ 2 | #define __ST7781_H__ 3 | 4 | void st7781_lcdInit(TFT_t * dev, int width, int height, int offsetx, int offsety); 5 | void ili9325_lcdDrawPixel(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 6 | void ili9325_lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 7 | void ili9325_lcdDisplayOff(TFT_t * dev); 8 | void ili9325_lcdDisplayOn(TFT_t * dev); 9 | void ili9325_lcdInversionOff(TFT_t * dev); 10 | void ili9325_lcdInversionOn(TFT_t * dev); 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /fontx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "fontx.h" 7 | 8 | #define FontxDebug 0 // for Debug 9 | 10 | // フォントファイルパスを構造体に保存 11 | void Fontx_addFont(FontxFile *fx, const char *path) 12 | { 13 | memset(fx,0,sizeof(FontxFile)); 14 | fx->path = path; 15 | fx->opened = false; 16 | } 17 | 18 | // フォント構造体を初期化 19 | void Fontx_init(FontxFile *fxs,const char *f0,const char *f1) 20 | { 21 | Fontx_addFont(&fxs[0],f0); 22 | Fontx_addFont(&fxs[1],f1); 23 | } 24 | 25 | // フォントファイルをOPEN 26 | bool Fontx_openFontxFile(FontxFile *fx) 27 | { 28 | FILE *f; 29 | 30 | if(!fx->opened){ 31 | fx->opened = true; 32 | f = fopen(fx->path,"r"); 33 | if(!f){ 34 | fx->valid = false; 35 | printf("FsFontx:%s not found.\n",fx->path); 36 | } else { 37 | fx->file = f; 38 | char buf[18]; 39 | 40 | fread(buf, sizeof buf, 1, fx->file); 41 | // for(i=0;ifxname,&buf[6],8); 45 | fx->w = buf[14]; 46 | fx->h = buf[15]; 47 | fx->is_ank = (buf[16] == 0); 48 | fx->bc = buf[17]; 49 | fx->fsz = (fx->w + 7)/8 * fx->h; 50 | if(fx->fsz > FontxGlyphBufSize){ 51 | printf("too big font size.\n"); 52 | fx->valid = false; 53 | } else { 54 | fx->valid = true; 55 | } 56 | } 57 | } 58 | return fx->valid; 59 | } 60 | 61 | // フォントファイルをCLOSE 62 | void Fontx_closeFontxFile(FontxFile *fx) 63 | { 64 | if(fx->opened){ 65 | fclose(fx->file); 66 | fx->opened = false; 67 | } 68 | } 69 | 70 | 71 | /* 72 | フォントファイルからフォントパターンを取り出す 73 | 74 | フォントの並び(16X16ドット) 75 | 00000000 01111111 76 | 12345678 90123456 77 | 01 pGlyph[000] pGlyph[001] 78 | 02 pGlyph[002] pGlyph[003] 79 | 03 pGlyph[004] pGlyph[005] 80 | 04 pGlyph[006] pGlyph[007] 81 | 05 pGlyph[008] pGlyph[009] 82 | 06 pGlyph[010] pGlyph[011] 83 | 07 pGlyph[012] pGlyph[013] 84 | 08 pGlyph[014] pGlyph[015] 85 | 09 pGlyph[016] pGlyph[017] 86 | 10 pGlyph[018] pGlyph[019] 87 | 11 pGlyph[020] pGlyph[021] 88 | 12 pGlyph[022] pGlyph[023] 89 | 13 pGlyph[024] pGlyph[025] 90 | 14 pGlyph[026] pGlyph[027] 91 | 15 pGlyph[028] pGlyph[029] 92 | 16 pGlyph[030] pGlyph[031] 93 | 94 | フォントの並び(24X24ドット) 95 | 00000000 01111111 11122222 96 | 12345678 90123456 78901234 97 | 01 pGlyph[000] pGlyph[001] pGlyph[002] 98 | 02 pGlyph[003] pGlyph[004] pGlyph[005] 99 | 03 pGlyph[006] pGlyph[007] pGlyph[008] 100 | 04 pGlyph[009] pGlyph[010] pGlyph[011] 101 | 05 pGlyph[012] pGlyph[013] pGlyph[014] 102 | 06 pGlyph[015] pGlyph[016] pGlyph[017] 103 | 07 pGlyph[018] pGlyph[019] pGlyph[020] 104 | 08 pGlyph[021] pGlyph[022] pGlyph[023] 105 | 09 pGlyph[024] pGlyph[025] pGlyph[026] 106 | 10 pGlyph[027] pGlyph[028] pGlyph[029] 107 | 11 pGlyph[030] pGlyph[031] pGlyph[032] 108 | 12 pGlyph[033] pGlyph[034] pGlyph[035] 109 | 13 pGlyph[036] pGlyph[037] pGlyph[038] 110 | 14 pGlyph[039] pGlyph[040] pGlyph[041] 111 | 15 pGlyph[042] pGlyph[043] pGlyph[044] 112 | 16 pGlyph[045] pGlyph[046] pGlyph[047] 113 | 17 pGlyph[048] pGlyph[049] pGlyph[050] 114 | 18 pGlyph[051] pGlyph[052] pGlyph[053] 115 | 19 pGlyph[054] pGlyph[055] pGlyph[056] 116 | 20 pGlyph[057] pGlyph[058] pGlyph[059] 117 | 21 pGlyph[060] pGlyph[061] pGlyph[062] 118 | 22 pGlyph[063] pGlyph[064] pGlyph[065] 119 | 23 pGlyph[066] pGlyph[067] pGlyph[068] 120 | 24 pGlyph[069] pGlyph[070] pGlyph[071] 121 | 122 | フォントの並び(32X32ドット) 123 | 00000000 01111111 11122222 22222333 124 | 12345678 90123456 78901234 56789012 125 | 01 pGlyph[000] pGlyph[001] pGlyph[002] pGlyph[003] 126 | 02 pGlyph[004] pGlyph[005] pGlyph[006] pGlyph[007] 127 | 03 pGlyph[008] pGlyph[009] pGlyph[010] pGlyph[011] 128 | 04 pGlyph[012] pGlyph[013] pGlyph[014] pGlyph[015] 129 | 05 pGlyph[016] pGlyph[017] pGlyph[018] pGlyph[019] 130 | 06 pGlyph[020] pGlyph[021] pGlyph[022] pGlyph[023] 131 | 07 pGlyph[024] pGlyph[025] pGlyph[026] pGlyph[027] 132 | 08 pGlyph[028] pGlyph[029] pGlyph[030] pGlyph[031] 133 | 09 pGlyph[032] pGlyph[033] pGlyph[034] pGlyph[035] 134 | 10 pGlyph[036] pGlyph[037] pGlyph[038] pGlyph[039] 135 | 11 pGlyph[040] pGlyph[041] pGlyph[042] pGlyph[043] 136 | 12 pGlyph[044] pGlyph[045] pGlyph[046] pGlyph[047] 137 | 13 pGlyph[048] pGlyph[049] pGlyph[050] pGlyph[051] 138 | 14 pGlyph[052] pGlyph[053] pGlyph[054] pGlyph[055] 139 | 15 pGlyph[056] pGlyph[057] pGlyph[058] pGlyph[059] 140 | 16 pGlyph[060] pGlyph[061] pGlyph[062] pGlyph[063] 141 | 17 pGlyph[064] pGlyph[065] pGlyph[066] pGlyph[067] 142 | 18 pGlyph[068] pGlyph[069] pGlyph[070] pGlyph[071] 143 | 19 pGlyph[072] pGlyph[073] pGlyph[074] pGlyph[075] 144 | 20 pGlyph[076] pGlyph[077] pGlyph[078] pGlyph[079] 145 | 21 pGlyph[080] pGlyph[081] pGlyph[082] pGlyph[083] 146 | 22 pGlyph[084] pGlyph[085] pGlyph[086] pGlyph[087] 147 | 23 pGlyph[088] pGlyph[089] pGlyph[090] pGlyph[091] 148 | 24 pGlyph[092] pGlyph[093] pGlyph[094] pGlyph[095] 149 | 25 pGlyph[096] pGlyph[097] pGlyph[098] pGlyph[099] 150 | 26 pGlyph[100] pGlyph[101] pGlyph[102] pGlyph[103] 151 | 27 pGlyph[104] pGlyph[105] pGlyph[106] pGlyph[107] 152 | 28 pGlyph[108] pGlyph[109] pGlyph[110] pGlyph[111] 153 | 29 pGlyph[112] pGlyph[113] pGlyph[114] pGlyph[115] 154 | 30 pGlyph[116] pGlyph[117] pGlyph[118] pGlyph[119] 155 | 31 pGlyph[120] pGlyph[121] pGlyph[122] pGlyph[123] 156 | 32 pGlyph[124] pGlyph[125] pGlyph[127] pGlyph[128] 157 | 158 | */ 159 | 160 | bool GetFontx(FontxFile *fxs, uint32_t sjis , uint8_t *pGlyph, 161 | uint8_t *pw, uint8_t *ph) 162 | { 163 | 164 | int i; 165 | // FontxFile fx; 166 | long offset; 167 | 168 | if(FontxDebug)printf("[GetFontx]sjis=%x %d\n",sjis,sjis); 169 | for(i=0; i<2; i++){ 170 | if(!Fontx_openFontxFile(&fxs[i])) continue; 171 | // printf("openFontxFile[%d]\n",i); 172 | 173 | if(sjis < 0x100){ 174 | if(fxs[i].is_ank){ 175 | if(FontxDebug)printf("[GetFontx]fxs.is_ank fxs.fsz=%d\n",fxs[i].fsz); 176 | offset = 17 + sjis * fxs[i].fsz; 177 | if(FontxDebug)printf("[GetFontx]offset=%ld\n",offset); 178 | if(fseek(fxs[i].file, offset, SEEK_SET)) { 179 | printf("Fontx::fseek(18) failed.\n"); 180 | return false; 181 | } 182 | if(fread(pGlyph, 1, fxs[i].fsz, fxs[i].file) != fxs[i].fsz){ 183 | printf("Fontx::fread failed.\n"); 184 | return false; 185 | } 186 | if(pw) *pw = fxs[i].w; 187 | if(ph) *ph = fxs[i].h; 188 | return true; 189 | } 190 | } 191 | else { 192 | if(!fxs[i].is_ank){ 193 | if(fseek(fxs[i].file, 18, SEEK_SET)) { 194 | printf("Fontx::fseek(18) failed.\n"); 195 | return false; 196 | } 197 | uint16_t buf[2], nc = 0, bc = fxs[i].bc; 198 | 199 | while(bc--){ 200 | if(fread((char *)buf, 1, 4, fxs[i].file) != 4){ 201 | printf("Fontx::fread failed.\n"); 202 | return false; 203 | } 204 | if(FontxDebug)printf("[GetFontx]buf=%x %x\n",buf[0],buf[1]); 205 | if(sjis >= buf[0] && sjis <= buf[1]) { 206 | nc += sjis - buf[0]; 207 | uint32_t pos = 18 + fxs[i].bc * 4 + nc * fxs[i].fsz; 208 | if(fseek(fxs[i].file, pos, SEEK_SET)) { 209 | printf("FsFontx::seek(%u) failed.\n",pos); 210 | return false; 211 | } 212 | if(fread(pGlyph, 1, fxs[i].fsz, fxs[i].file) != fxs[i].fsz){ 213 | printf("Fontx::fread failed.\n"); 214 | return false; 215 | } 216 | if(pw) *pw = fxs[i].w; 217 | if(ph) *ph = fxs[i].h; 218 | return true; 219 | } 220 | nc += buf[1] - buf[0] + 1; 221 | } 222 | } 223 | } 224 | } 225 | return false; 226 | } 227 | 228 | 229 | /* 230 | フォントパターンをビットマップイメージに変換する 231 | 232 | fonts(16X16ドット) 233 | 00000000 01111111 234 | 12345678 90123456 235 | 01 pGlyph[000] pGlyph[001] 236 | 02 pGlyph[002] pGlyph[003] 237 | 03 pGlyph[004] pGlyph[005] 238 | 04 pGlyph[006] pGlyph[007] 239 | 05 pGlyph[008] pGlyph[009] 240 | 06 pGlyph[010] pGlyph[011] 241 | 07 pGlyph[012] pGlyph[013] 242 | 08 pGlyph[014] pGlyph[015] 243 | 09 pGlyph[016] pGlyph[017] 244 | 10 pGlyph[018] pGlyph[019] 245 | 11 pGlyph[020] pGlyph[021] 246 | 12 pGlyph[022] pGlyph[023] 247 | 13 pGlyph[024] pGlyph[025] 248 | 14 pGlyph[026] pGlyph[027] 249 | 15 pGlyph[028] pGlyph[029] 250 | 16 pGlyph[030] pGlyph[031] 251 | 252 | line[32*4] 253 | 01 line[000] line[001] line[002] .... line[014] line[015] line[016-031] 254 | | Not Use 255 | 07 line[000] line[001] line[002] .... line[014] line[015] line[016-031] 256 | 257 | 08 line[032] line[033] line[034] .... line[046] line[047] line[048-063] 258 | | Not Use 259 | 16 line[032] line[033] line[034] .... line[046] line[047] line[048-063] 260 | 261 | 262 | 263 | fonts(24X24ドット) 264 | 00000000 01111111 11122222 265 | 12345678 90123456 78901234 266 | 01 pGlyph[000] pGlyph[001] pGlyph[002] 267 | 02 pGlyph[003] pGlyph[004] pGlyph[005] 268 | 03 pGlyph[006] pGlyph[007] pGlyph[008] 269 | 04 pGlyph[009] pGlyph[010] pGlyph[011] 270 | 05 pGlyph[012] pGlyph[013] pGlyph[014] 271 | 06 pGlyph[015] pGlyph[016] pGlyph[017] 272 | 07 pGlyph[018] pGlyph[019] pGlyph[020] 273 | 08 pGlyph[021] pGlyph[022] pGlyph[023] 274 | 09 pGlyph[024] pGlyph[025] pGlyph[026] 275 | 10 pGlyph[027] pGlyph[028] pGlyph[029] 276 | 11 pGlyph[030] pGlyph[031] pGlyph[032] 277 | 12 pGlyph[033] pGlyph[034] pGlyph[035] 278 | 13 pGlyph[036] pGlyph[037] pGlyph[038] 279 | 14 pGlyph[039] pGlyph[040] pGlyph[041] 280 | 15 pGlyph[042] pGlyph[043] pGlyph[044] 281 | 16 pGlyph[045] pGlyph[046] pGlyph[047] 282 | 17 pGlyph[048] pGlyph[049] pGlyph[050] 283 | 18 pGlyph[051] pGlyph[052] pGlyph[053] 284 | 19 pGlyph[054] pGlyph[055] pGlyph[056] 285 | 20 pGlyph[057] pGlyph[058] pGlyph[059] 286 | 21 pGlyph[060] pGlyph[061] pGlyph[062] 287 | 22 pGlyph[063] pGlyph[064] pGlyph[065] 288 | 23 pGlyph[066] pGlyph[067] pGlyph[068] 289 | 24 pGlyph[069] pGlyph[070] pGlyph[071] 290 | 291 | line[32*4] 292 | 01 line[000] line[001] line[002] .... line[022] line[023] line[024-031] 293 | | Not Use 294 | 08 line[000] line[001] line[002] .... line[022] line[023] line[024-031] 295 | 296 | 09 line[032] line[033] line[034] .... line[054] line[055] line[056-063] 297 | | Not Use 298 | 16 line[032] line[033] line[034] .... line[054] line[055] line[056-063] 299 | 300 | 17 line[064] line[065] line[066] .... line[086] line[087] line[088-095] 301 | | Not Use 302 | 24 line[064] line[065] line[066] .... line[086] line[087] line[088-095] 303 | 304 | 305 | fonts(32X32ドット) 306 | 00000000 01111111 11122222 22222333 307 | 12345678 90123456 78901234 56789012 308 | 01 pGlyph[000] pGlyph[001] pGlyph[002] pGlyph[003] 309 | 02 pGlyph[004] pGlyph[005] pGlyph[006] pGlyph[007] 310 | 03 pGlyph[008] pGlyph[009] pGlyph[010] pGlyph[011] 311 | 04 pGlyph[012] pGlyph[013] pGlyph[014] pGlyph[015] 312 | 05 pGlyph[016] pGlyph[017] pGlyph[018] pGlyph[019] 313 | 06 pGlyph[020] pGlyph[021] pGlyph[022] pGlyph[023] 314 | 07 pGlyph[024] pGlyph[025] pGlyph[026] pGlyph[027] 315 | 08 pGlyph[028] pGlyph[029] pGlyph[030] pGlyph[031] 316 | 09 pGlyph[032] pGlyph[033] pGlyph[034] pGlyph[035] 317 | 10 pGlyph[036] pGlyph[037] pGlyph[038] pGlyph[039] 318 | 11 pGlyph[040] pGlyph[041] pGlyph[042] pGlyph[043] 319 | 12 pGlyph[044] pGlyph[045] pGlyph[046] pGlyph[047] 320 | 13 pGlyph[048] pGlyph[049] pGlyph[050] pGlyph[051] 321 | 14 pGlyph[052] pGlyph[053] pGlyph[054] pGlyph[055] 322 | 15 pGlyph[056] pGlyph[057] pGlyph[058] pGlyph[059] 323 | 16 pGlyph[060] pGlyph[061] pGlyph[062] pGlyph[063] 324 | 17 pGlyph[064] pGlyph[065] pGlyph[066] pGlyph[067] 325 | 18 pGlyph[068] pGlyph[069] pGlyph[070] pGlyph[071] 326 | 19 pGlyph[072] pGlyph[073] pGlyph[074] pGlyph[075] 327 | 20 pGlyph[076] pGlyph[077] pGlyph[078] pGlyph[079] 328 | 21 pGlyph[080] pGlyph[081] pGlyph[082] pGlyph[083] 329 | 22 pGlyph[084] pGlyph[085] pGlyph[086] pGlyph[087] 330 | 23 pGlyph[088] pGlyph[089] pGlyph[090] pGlyph[091] 331 | 24 pGlyph[092] pGlyph[093] pGlyph[094] pGlyph[095] 332 | 25 pGlyph[096] pGlyph[097] pGlyph[098] pGlyph[099] 333 | 26 pGlyph[100] pGlyph[101] pGlyph[102] pGlyph[103] 334 | 27 pGlyph[104] pGlyph[105] pGlyph[106] pGlyph[107] 335 | 28 pGlyph[108] pGlyph[109] pGlyph[110] pGlyph[111] 336 | 29 pGlyph[112] pGlyph[113] pGlyph[114] pGlyph[115] 337 | 30 pGlyph[116] pGlyph[117] pGlyph[118] pGlyph[119] 338 | 31 pGlyph[120] pGlyph[121] pGlyph[122] pGlyph[123] 339 | 32 pGlyph[124] pGlyph[125] pGlyph[127] pGlyph[128] 340 | 341 | line[32*4] 342 | 01 line[000] line[001] line[002] .... line[030] line[031] 343 | | 344 | 08 line[000] line[001] line[002] .... line[030] line[031] 345 | 346 | 09 line[032] line[033] line[034] .... line[062] line[063] 347 | | 348 | 16 line[032] line[033] line[034] .... line[062] line[063] 349 | 350 | 17 line[064] line[065] line[066] .... line[094] line[095] 351 | | 352 | 24 line[064] line[065] line[066] .... line[094] line[095] 353 | 354 | 25 line[096] line[097] line[098] .... line[126] line[127] 355 | | 356 | 32 line[096] line[097] line[098] .... line[126] line[127] 357 | 358 | */ 359 | void Font2Bitmap(uint8_t *fonts, uint8_t *line, uint8_t w, uint8_t h, uint8_t inverse) { 360 | int x,y; 361 | for(y=0; y<(h/8); y++){ 362 | for(x=0; x> (x % 8))) line[linep] = line[linep] + (1 << mask); 375 | } 376 | mask--; 377 | if (mask < 0) mask = 7; 378 | fontp += (w + 7)/8; 379 | } 380 | 381 | if (inverse) { 382 | for(y=0; y<(h/8); y++){ 383 | for(x=0; x> (x % 8))) { 422 | printf("*"); 423 | } else { 424 | printf("."); 425 | } 426 | } 427 | printf("\n"); 428 | fpos=fpos+(pw+7)/8; 429 | } 430 | } 431 | 432 | // Bitmapの表示 433 | void ShowBitmap(uint8_t *bitmap, uint8_t pw, uint8_t ph) { 434 | int x,y,fpos; 435 | for (y=0;y<(ph+7)/8;y++) { 436 | for (x=0;x> fpos); 447 | if (bitmap[x+(y/8)*32] & (0x80 >> fpos)) { 448 | printf("*"); 449 | } else { 450 | printf("."); 451 | } 452 | } 453 | printf("\n"); 454 | fpos++; 455 | if (fpos > 7) fpos = 0; 456 | } 457 | } 458 | 459 | 460 | // フォント構造体の表示 461 | void DumpFX(FontxFile *fxs) 462 | { 463 | int i; 464 | for(i=0;i<2;i++) { 465 | printf("fxs[%d]->path=%s\n",i,fxs[i].path); 466 | printf("fxs[%d]->opened=%d\n",i,fxs[i].opened); 467 | printf("fxs[%d]->fxname=%s\n",i,fxs[i].fxname); 468 | printf("fxs[%d]->valid=%d\n",i,fxs[i].valid); 469 | printf("fxs[%d]->is_ank=%d\n",i,fxs[i].is_ank); 470 | printf("fxs[%d]->w=%d\n",i,fxs[i].w); 471 | printf("fxs[%d]->h=%d\n",i,fxs[i].h); 472 | printf("fxs[%d]->fsz=%d\n",i,fxs[i].fsz); 473 | printf("fxs[%d]->bc=%d\n",i,fxs[i].bc); 474 | } 475 | } 476 | 477 | // UTF code(3Byte) を SJIS Code(2 Byte) に変換 478 | uint16_t UTF2SJIS(uint8_t *utf8) { 479 | unsigned char strJIS[3] = {0}; 480 | unsigned char *pi1 = utf8; 481 | unsigned char **pi2 = &pi1; 482 | unsigned char *po1 = strJIS; 483 | unsigned char **po2 = &po1; 484 | size_t ilen = 3; 485 | size_t olen = 2; 486 | iconv_t cd; 487 | uint16_t sjis; 488 | 489 | if((cd = iconv_open("sjis","utf-8")) == (iconv_t)-1){ 490 | if(FontxDebug)printf("iconv open fail \n"); 491 | return 0; 492 | }else { 493 | if(FontxDebug)printf("iconv open ok \n"); 494 | } 495 | 496 | iconv(cd,(char**)pi2,&ilen,(char**)po2,&olen); 497 | iconv_close(cd); 498 | 499 | if(FontxDebug)printf("[UTF2SJIS]strJIS=%x-%x\n",strJIS[0],strJIS[1]); 500 | if (strJIS[0] & 0x80) { 501 | sjis = strJIS[0] << 8; 502 | sjis = sjis + strJIS[1]; 503 | } else { 504 | sjis = strJIS[0]; 505 | } 506 | if(FontxDebug)printf("[UTF2SJIS]sjis=%x\n",sjis); 507 | return sjis; 508 | } 509 | 510 | 511 | // UTFを含む文字列をSJISに変換 512 | int String2SJIS(unsigned char *str_in, uint8_t stlen, uint16_t *sjis, 513 | uint8_t ssize) { 514 | int i; 515 | uint8_t sp; 516 | uint8_t c1 = 0; 517 | uint8_t c2 = 0; 518 | uint8_t utf8[3]; 519 | uint16_t sjis2; 520 | int spos = 0; 521 | 522 | for(i=0;i> 1; 567 | } 568 | return ch2; 569 | } 570 | -------------------------------------------------------------------------------- /fontx.h: -------------------------------------------------------------------------------- 1 | #define FontxGlyphBufSize (32*32/8) 2 | 3 | typedef struct { 4 | const char *path; 5 | char fxname[9]; 6 | bool opened; 7 | bool valid; 8 | bool is_ank; 9 | uint8_t w; 10 | uint8_t h; 11 | uint16_t fsz; 12 | uint8_t bc; 13 | FILE *file; 14 | } FontxFile; 15 | 16 | void Fontx_addFont(FontxFile *fx, const char *path); 17 | void Fontx_init(FontxFile *fxs,const char *f0,const char *f1); 18 | bool Fontx_openFontxFile(FontxFile *fx); 19 | void Fontx_closeFontxFile(FontxFile *fx); 20 | bool GetFontx (FontxFile *fxs, uint32_t sjis , uint8_t *pGlyph, 21 | uint8_t *pw, uint8_t *ph); 22 | void Font2Bitmap(uint8_t *fonts, uint8_t *line, uint8_t w, uint8_t h, 23 | uint8_t inverse); 24 | void UnderlineBitmap(uint8_t *line, uint8_t w, uint8_t h); 25 | void ReversBitmap(uint8_t *line, uint8_t w, uint8_t h); 26 | void ShowFont(uint8_t *fonts, uint8_t pw, uint8_t ph); 27 | void ShowBitmap(uint8_t *bitmap, uint8_t pw, uint8_t ph); 28 | void DumpFX(FontxFile *fxs); 29 | uint16_t UTF2SJIS(uint8_t *utf8); 30 | int String2SJIS(unsigned char *str_in, uint8_t stlen, uint16_t *sjis, 31 | uint8_t ssize); 32 | uint8_t RotateByte(uint8_t ch); 33 | -------------------------------------------------------------------------------- /fontx/ILGH16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGH16XB.FNT -------------------------------------------------------------------------------- /fontx/ILGH24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGH24XB.FNT -------------------------------------------------------------------------------- /fontx/ILGH32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGH32XB.FNT -------------------------------------------------------------------------------- /fontx/ILGZ16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGZ16XB.FNT -------------------------------------------------------------------------------- /fontx/ILGZ16XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGZ16XF.FNT -------------------------------------------------------------------------------- /fontx/ILGZ24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGZ24XB.FNT -------------------------------------------------------------------------------- /fontx/ILGZ32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILGZ32XB.FNT -------------------------------------------------------------------------------- /fontx/ILMH16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMH16XB.FNT -------------------------------------------------------------------------------- /fontx/ILMH24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMH24XB.FNT -------------------------------------------------------------------------------- /fontx/ILMH24XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMH24XF.FNT -------------------------------------------------------------------------------- /fontx/ILMH32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMH32XB.FNT -------------------------------------------------------------------------------- /fontx/ILMH32XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMH32XF.FNT -------------------------------------------------------------------------------- /fontx/ILMZ16XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ16XB.FNT -------------------------------------------------------------------------------- /fontx/ILMZ16XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ16XF.FNT -------------------------------------------------------------------------------- /fontx/ILMZ24XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ24XB.FNT -------------------------------------------------------------------------------- /fontx/ILMZ24XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ24XF.FNT -------------------------------------------------------------------------------- /fontx/ILMZ32XB.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ32XB.FNT -------------------------------------------------------------------------------- /fontx/ILMZ32XF.FNT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/fontx/ILMZ32XF.FNT -------------------------------------------------------------------------------- /images/RaspberryPi_logo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/images/RaspberryPi_logo.jpeg -------------------------------------------------------------------------------- /images/RaspberryPi_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/images/RaspberryPi_logo.png -------------------------------------------------------------------------------- /images/Ubuntu_log.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/images/Ubuntu_log.jpeg -------------------------------------------------------------------------------- /images/Ubuntu_log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nopnop2002/Raspberry-ili9325/8bbd5eaa87d5ad61d39221aa14e51f729414a5cf/images/Ubuntu_log.png -------------------------------------------------------------------------------- /jpegtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "tft_lib.h" 13 | #include "tjpgd2/tjpgd.h" 14 | #include "tjpgd2/decode_jpeg.h" 15 | 16 | #include "driver/ili9341.h" 17 | #define DRIVER_NAME "ILI9341" 18 | #define SCREEN_WIDTH 240 19 | #define SCREEN_HEIGHT 320 20 | #define OFFSET_X 0 21 | #define OFFSET_Y 0 22 | #define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e) 23 | 24 | #define _DEBUG_ 0 25 | 26 | time_t elapsedTime(struct timeval startTime, struct timeval endTime) { 27 | time_t diffsec = difftime(endTime.tv_sec, startTime.tv_sec); 28 | suseconds_t diffsub = endTime.tv_usec - startTime.tv_usec; 29 | //printf("diffsec=%ld diffsub=%ld\n",diffsec, diffsub); 30 | if(diffsub < 0) { 31 | diffsec--; 32 | diffsub = (endTime.tv_usec+1000000) - startTime.tv_usec; 33 | } 34 | uint16_t diffmsec = diffsub / 1000; 35 | time_t diff = (diffsec * 1000) + diffmsec; 36 | return diff; 37 | } 38 | 39 | time_t JPEGTest(TFT_t * dev, char * file, int width, int height) { 40 | struct timeval startTime, endTime; 41 | gettimeofday(&startTime, NULL); 42 | 43 | lcdFillScreen(dev, BLACK); 44 | 45 | int _width = width; 46 | if (width > 240) _width = 240; 47 | int _height = height; 48 | if (height > 320) _height = 320; 49 | 50 | pixel_s **pixels; 51 | uint16_t imageWidth; 52 | uint16_t imageHeight; 53 | uint16_t err = decode_image(&pixels, file, width, height, &imageWidth, &imageHeight); 54 | if (err == ESP_OK) { 55 | printf("width=%d height=%d\n", width, height); 56 | printf("imageWidth=%d imageHeight=%d\n", imageWidth, imageHeight); 57 | 58 | uint16_t jpegWidth = width; 59 | uint16_t offsetX = 0; 60 | if (width > imageWidth) { 61 | jpegWidth = imageWidth; 62 | offsetX = (width - imageWidth) / 2; 63 | } 64 | printf("jpegWidth=%d offsetX=%d\n", jpegWidth, offsetX); 65 | 66 | uint16_t jpegHeight = height; 67 | uint16_t offsetY = 0; 68 | if (height > imageHeight) { 69 | jpegHeight = imageHeight; 70 | offsetY = (height - imageHeight) / 2; 71 | } 72 | printf("jpegHeight=%d offsetY=%d\n", jpegHeight, offsetY); 73 | uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * jpegWidth); 74 | 75 | int ypos = (height-1) - offsetY; 76 | for(int y = 0; y < jpegHeight; y++){ 77 | for(int x = 0;x < jpegWidth; x++){ 78 | pixel_s pixel = pixels[y][x]; 79 | uint16_t color = rgb565_conv(pixel.red, pixel.green, pixel.blue); 80 | //lcdDrawPixel(dev, x+offsetX, y+offsetY, color); 81 | lcdDrawPixel(dev, x+offsetX, ypos, color); 82 | } 83 | ypos--; 84 | } 85 | 86 | free(colors); 87 | release_image(&pixels, _width, _height); 88 | //printf("Finish\n"); 89 | } else { 90 | printf("decode_image err=%d imageWidth=%d imageHeight=%d\n", err, imageWidth, imageHeight); 91 | } 92 | 93 | gettimeofday(&endTime, NULL); 94 | time_t diff = elapsedTime(startTime, endTime); 95 | printf("%s elapsed time[ms]=%ld\n",__func__, diff); 96 | return diff; 97 | 98 | } 99 | 100 | 101 | int main(int argc, char **argv){ 102 | 103 | if(wiringPiSetup() == -1) { 104 | printf("wiringPiSetup Fail\n"); 105 | return 1; 106 | } 107 | 108 | int i; 109 | char base[128]; 110 | strcpy(base, argv[0]); 111 | for(i=strlen(base);i>0;i--) { 112 | if (base[i-1] == '/') { 113 | base[i] = 0; 114 | break; 115 | } 116 | } 117 | if(_DEBUG_)printf("base=%s\n",base); 118 | 119 | char ppath[128]; 120 | strcpy(ppath,base); 121 | strcat(ppath,"pin.conf"); 122 | if(_DEBUG_)printf("ppath=%s\n",ppath); 123 | struct stat buffer; 124 | if (stat(ppath, &buffer) != 0) { 125 | printf("pin.conf [%s] not found\n",ppath); 126 | return 1; 127 | } 128 | 129 | TFT_t dev; 130 | lcdInterface(&dev, ppath); 131 | lcdReset(&dev); 132 | INIT_FUNCTION(&dev, SCREEN_WIDTH, SCREEN_HEIGHT, OFFSET_X, OFFSET_Y); 133 | 134 | 135 | char file[64]; 136 | //strcpy(file, "./images/RaspberryPi_logo.jpeg"); 137 | //strcpy(file, "./images/Ubuntu_log.jpeg"); 138 | strcpy(file, "./images/dailyImage.jpeg"); 139 | JPEGTest(&dev, file, SCREEN_WIDTH, SCREEN_HEIGHT); 140 | sleep(5); 141 | 142 | //lcdFadeout(&dev, DIRECTION90, BLACK); 143 | } 144 | -------------------------------------------------------------------------------- /me.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | #for debug 5 | function __echo () { 6 | echo $1 7 | echo $1 >> $DrawFile 8 | } 9 | 10 | function _echo () { 11 | echo $1 >> $DrawFile 12 | } 13 | 14 | DrawFile="./draw.txt" 15 | if [ -f ${DrawFile} ]; then 16 | rm $DrawFile 17 | fi 18 | 19 | #Inquiry tft information 20 | screen_width=`./draw width` 21 | screen_height=`./draw height` 22 | driver_name=`./draw driver` 23 | echo -n "Your TFT is " 24 | echo -n ${driver_name} 25 | echo -n " " 26 | echo -n ${screen_width} 27 | echo -n "x" 28 | echo ${screen_height} 29 | 30 | #Calculate Y position 31 | xorg=10 32 | ycenter=$((screen_height/2)) 33 | yorg=$((ycenter-130)) 34 | #echo $ycenter 35 | #echo $yorg 36 | if [ $yorg -lt 0 ]; then 37 | yorg=0 38 | fi 39 | 40 | #Black(0x000000) 41 | _echo "FillScrren,0x0000" 42 | _echo "SetFontDirection,3" 43 | 44 | #White(0xffffff) 45 | color=`./rgb2color 0xffffff` 46 | y1=$yorg 47 | y2=$((y1+235)) 48 | x1=$xorg 49 | x2=$((x1+30)) 50 | _echo "DrawRoundRect,${x1},${y1},${x2},${y2},10,${color}" 51 | xs=$((xorg+30)) 52 | ys=$((yorg+10)) 53 | _echo "DrawUTF8String,G24,${xs},${ys},System Information,${color}" 54 | 55 | #Cyan(0x00ffff) 56 | color=`./rgb2color 0x00ffff` 57 | x1=$((xorg+44)) 58 | x2=$((x1+10)) 59 | y1=$((yorg+10)) 60 | y2=$((y1+10)) 61 | xs=$((xs+30)) 62 | ys=$((yorg+30)) 63 | _echo "DrawFillRect,${x1},${y1},${x2},${y2},${color}" 64 | #_echo "SetFontUnderLine,${color}" 65 | _echo "DrawUTF8String,G24,${xs},${ys},wlan0 IP Address,${color}" 66 | #_echo "UnsetFontUnderLine" 67 | IpAddr=`ifconfig wlan0 | grep "inet " | awk {'print $2'}` 68 | xs=$((xs+20)) 69 | _echo "SetFontUnderLine,${color}" 70 | if [ -n "$IpAddr" ]; then 71 | _echo "DrawUTF8String,G24,${xs},${ys},${IpAddr},${color}" 72 | else 73 | _echo "DrawUTF8String,G24,${xs},${ys},,${color}" 74 | fi 75 | _echo "UnsetFontUnderLine" 76 | 77 | #Magenta(0xff0090) 78 | color=`./rgb2color 0xff0090` 79 | x1=$((x1+50)) 80 | x2=$((x1+10)) 81 | xs=$((xs+30)) 82 | _echo "DrawFillRect,${x1},${y1},${x2},${y2},${color}" 83 | _echo "DrawUTF8String,G24,${xs},${ys},eth0 IP Address,${color}" 84 | IpAddr=`ifconfig eth0 | grep "inet " | awk {'print $2'}` 85 | xs=$((xs+20)) 86 | _echo "SetFontUnderLine,${color}" 87 | if [ -n "$IpAddr" ]; then 88 | _echo "DrawUTF8String,G24,${xs},${ys},${IpAddr},${color}" 89 | else 90 | _echo "DrawUTF8String,G24,${xs},${ys},,${color}" 91 | fi 92 | _echo "UnsetFontUnderLine" 93 | 94 | #Orange(0xff5c00) 95 | color=`./rgb2color 0xff5c00` 96 | x1=$((x1+50)) 97 | x2=$((x1+10)) 98 | xs=$((xs+30)) 99 | _echo "DrawFillRect,${x1},${y1},${x2},${y2},${color}" 100 | _echo "DrawUTF8String,G24,${xs},${ys},kernel release,${color}" 101 | Release=`uname -r` 102 | xs=$((xs+20)) 103 | _echo "SetFontUnderLine,${color}" 104 | _echo "DrawUTF8String,G24,${xs},${ys},${Release},${color}" 105 | _echo "UnsetFontUnderLine" 106 | 107 | #Lime Green(0x00ff00) 108 | color=`./rgb2color 0x00ff00` 109 | x1=$((x1+50)) 110 | x2=$((x1+10)) 111 | xs=$((xs+30)) 112 | _echo "DrawFillRect,${x1},${y1},${x2},${y2},${color}" 113 | _echo "DrawUTF8String,G24,${xs},${ys},CPU Temp.,${color}" 114 | temp=`vcgencmd measure_temp | cut -d= -f2` 115 | xs=$((xs+20)) 116 | _echo "SetFontUnderLine,${color}" 117 | _echo "DrawUTF8String,G24,${xs},${ys},${temp},${color}" 118 | _echo "UnsetFontUnderLine" 119 | 120 | if [ $screen_width -gt 240 ]; then 121 | #Blue(0x0000ff) 122 | color=`./rgb2color 0x0000ff` 123 | x1=$((x1+50)) 124 | x2=$((x1+10)) 125 | xs=$((xs+30)) 126 | _echo "DrawFillRect,${x1},${y1},${x2},${y2},${color}" 127 | _echo "DrawUTF8String,G24,${xs},${ys},DISK Usage,${color}" 128 | temp=`df | grep root | awk {'print $5'}` 129 | xs=$((xs+20)) 130 | _echo "SetFontUnderLine,${color}" 131 | _echo "DrawUTF8String,G24,${xs},${ys},${temp},${color}" 132 | _echo "UnsetFontUnderLine" 133 | fi 134 | 135 | ./draw $DrawFile > /dev/null 136 | -------------------------------------------------------------------------------- /pin.conf: -------------------------------------------------------------------------------- 1 | #Number is WiringPi Number(NOT GPIO Number) 2 | RST=7 3 | CS=8 4 | RS=9 5 | WR=11 6 | RD=31 7 | D0=21 8 | D1=22 9 | D2=23 10 | D3=24 11 | D4=25 12 | D5=26 13 | D6=27 14 | D7=28 15 | #If your TFT is 8 bit Parallel,A definition after this isn't used. 16 | D8=2 17 | D9=3 18 | D10=4 19 | D11=5 20 | D12=15 21 | D13=16 22 | D14=29 23 | D15=30 24 | 25 | -------------------------------------------------------------------------------- /pin.conf.26pin: -------------------------------------------------------------------------------- 1 | #for 26pin header 2 | #Number is WiringPi Number(NOT GPIO Number) 3 | RST=7 ; Pin#7 4 | CS=8 ; Pin#3 5 | RS=9 ; Pin#5 6 | WR=11 ; Pin#26 7 | RD=15 ; Pin#8 8 | D0=16 ; Pin#10 9 | D1=0 ; Pin#11 10 | D2=1 ; Pin#12 11 | D3=2 ; Pin#13 12 | D4=3 ; Pin#15 13 | D5=4 ; Pin#16 14 | D6=5 ; Pin#18 15 | D7=6 ; Pin#22 16 | #If your TFT is 8 bit Parallel,A definition after this isn't used. 17 | D8=2 18 | D9=3 19 | D10=4 20 | D11=5 21 | D12=15 22 | D13=16 23 | D14=29 24 | D15=30 25 | 26 | -------------------------------------------------------------------------------- /pin.conf.40pin: -------------------------------------------------------------------------------- 1 | #Number is WiringPi Number(NOT GPIO Number) 2 | RST=7 3 | CS=8 4 | RS=9 5 | WR=11 6 | RD=31 7 | D0=21 8 | D1=22 9 | D2=23 10 | D3=24 11 | D4=25 12 | D5=26 13 | D6=27 14 | D7=28 15 | #If your TFT is 8 bit Parallel,A definition after this isn't used. 16 | D8=2 17 | D9=3 18 | D10=4 19 | D11=5 20 | D12=15 21 | D13=16 22 | D14=29 23 | D15=30 24 | 25 | -------------------------------------------------------------------------------- /pngle/decode_png.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "pngle.h" 4 | 5 | void png_init(pngle_t *pngle, uint32_t w, uint32_t h) 6 | { 7 | //printf("png_init w=%d h=%d\n", w, h); 8 | //printf("screenWidth=%d screenHeight=%d\n", pngle->screenWidth, pngle->screenHeight); 9 | pngle->imageWidth = w; 10 | pngle->imageHeight = h; 11 | pngle->reduction = false; 12 | pngle->scale_factor = 1.0; 13 | 14 | // Calculate Reduction 15 | if (pngle->screenWidth < pngle->imageWidth || pngle->screenHeight < pngle->imageHeight) { 16 | pngle->reduction = true; 17 | double factorWidth = (double)pngle->screenWidth / (double)pngle->imageWidth; 18 | double factorHeight = (double)pngle->screenHeight / (double)pngle->imageHeight; 19 | pngle->scale_factor = factorWidth; 20 | if (factorHeight < factorWidth) pngle->scale_factor = factorHeight; 21 | pngle->imageWidth = pngle->imageWidth * pngle->scale_factor; 22 | pngle->imageHeight = pngle->imageHeight * pngle->scale_factor; 23 | } 24 | //printf("reduction=%d scale_factor=%f\n", pngle->reduction, pngle->scale_factor); 25 | //printf("imageWidth=%d imageHeight=%d\n", pngle->imageWidth, pngle->imageHeight); 26 | } 27 | 28 | void png_draw(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]) 29 | { 30 | //printf("png_draw x=%d y=%d w=%d h=%d\n", x,y,w,h); 31 | #if 0 32 | uint8_t r = rgba[0]; 33 | uint8_t g = rgba[1]; 34 | uint8_t b = rgba[2]; 35 | #endif 36 | 37 | // image reduction 38 | uint32_t _x = x; 39 | uint32_t _y = y; 40 | if (pngle->reduction) { 41 | _x = x * pngle->scale_factor; 42 | _y = y * pngle->scale_factor; 43 | } 44 | if (_y < pngle->screenHeight && _x < pngle->screenWidth) { 45 | pngle->pixels[_y][_x].red = rgba[0]; 46 | pngle->pixels[_y][_x].green = rgba[1]; 47 | pngle->pixels[_y][_x].blue = rgba[2]; 48 | } 49 | 50 | } 51 | 52 | void png_finish(pngle_t *pngle) { 53 | //printf("png_finish\n"); 54 | } 55 | -------------------------------------------------------------------------------- /pngle/decode_png.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | void png_init(pngle_t *pngle, uint32_t w, uint32_t h); 5 | void png_draw(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]); 6 | void png_finish(pngle_t *pngle); 7 | 8 | -------------------------------------------------------------------------------- /pngle/miniz.h: -------------------------------------------------------------------------------- 1 | #define MINIZ_HEADER_FILE_ONLY 2 | #include "miniz.c" 3 | -------------------------------------------------------------------------------- /pngle/pngle.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 kikuchan 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef __PNGLE_H__ 26 | #define __PNGLE_H__ 27 | 28 | #include 29 | #include 30 | #include "miniz.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifndef MIN 37 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 38 | #endif 39 | 40 | #ifdef PNGLE_DEBUG 41 | #define debug_printf(...) fprintf(stderr, __VA_ARGS__) 42 | #else 43 | #define debug_printf(...) ((void)0) 44 | #endif 45 | 46 | //#define PNGLE_NO_GAMMA_CORRECTION 47 | 48 | typedef struct __attribute__((__packed__)) { 49 | uint8_t red; 50 | uint8_t green; 51 | uint8_t blue; 52 | } pixel_png; 53 | 54 | typedef enum { 55 | PNGLE_STATE_ERROR = -2, 56 | PNGLE_STATE_EOF = -1, 57 | PNGLE_STATE_INITIAL = 0, 58 | 59 | PNGLE_STATE_FIND_CHUNK_HEADER, 60 | PNGLE_STATE_HANDLE_CHUNK, 61 | PNGLE_STATE_CRC, 62 | } pngle_state_t; 63 | 64 | 65 | typedef enum { 66 | // Supported chunks 67 | // Filter chunk names by following command to (re)generate hex constants; 68 | // % perl -ne 'chomp; s/.*\s*\/\/\s*//; print "\tPNGLE_CHUNK_$_ = 0x" . unpack("H*") . "UL, // $_\n";' 69 | PNGLE_CHUNK_IHDR = 0x49484452UL, // IHDR 70 | PNGLE_CHUNK_PLTE = 0x504c5445UL, // PLTE 71 | PNGLE_CHUNK_IDAT = 0x49444154UL, // IDAT 72 | PNGLE_CHUNK_IEND = 0x49454e44UL, // IEND 73 | PNGLE_CHUNK_tRNS = 0x74524e53UL, // tRNS 74 | PNGLE_CHUNK_gAMA = 0x67414d41UL, // gAMA 75 | } pngle_chunk_t; 76 | 77 | typedef struct _pngle_ihdr_t { 78 | uint32_t width; 79 | uint32_t height; 80 | uint8_t depth; 81 | uint8_t color_type; 82 | uint8_t compression; 83 | uint8_t filter; 84 | uint8_t interlace; 85 | } pngle_ihdr_t; 86 | 87 | typedef unsigned int UINT; 88 | 89 | typedef struct pngle pngle_t; 90 | 91 | typedef void (*pngle_init_callback_t)(pngle_t *pngle, uint32_t w, uint32_t h); 92 | typedef void (*pngle_draw_callback_t)(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t rgba[4]); 93 | typedef void (*pngle_done_callback_t)(pngle_t *pngle); 94 | 95 | struct pngle { 96 | pngle_ihdr_t hdr; 97 | 98 | uint_fast8_t channels; // 0 indicates IHDR hasn't been processed yet 99 | 100 | // PLTE chunk 101 | size_t n_palettes; 102 | uint8_t *palette; 103 | 104 | // tRNS chunk 105 | size_t n_trans_palettes; 106 | uint8_t *trans_palette; 107 | 108 | // parser state (reset on every chunk header) 109 | pngle_state_t state; 110 | uint32_t chunk_type; 111 | uint32_t chunk_remain; 112 | mz_ulong crc32; 113 | 114 | // decompression state (reset on IHDR) 115 | tinfl_decompressor inflator; // 11000 bytes 116 | uint8_t lz_buf[TINFL_LZ_DICT_SIZE]; // 32768 bytes 117 | uint8_t *next_out; // NULL indicates IDAT hasn't been processed yet 118 | size_t avail_out; 119 | 120 | // scanline decoder (reset on every set_interlace_pass() call) 121 | uint8_t *scanline_ringbuf; 122 | size_t scanline_ringbuf_size; 123 | size_t scanline_ringbuf_cidx; 124 | int_fast8_t scanline_remain_bytes_to_render; 125 | int_fast8_t filter_type; 126 | uint32_t drawing_x; 127 | uint32_t drawing_y; 128 | 129 | // interlace 130 | uint_fast8_t interlace_pass; 131 | 132 | const char *error; 133 | 134 | #ifndef PNGLE_NO_GAMMA_CORRECTION 135 | uint8_t *gamma_table; 136 | double display_gamma; 137 | #endif 138 | 139 | pngle_init_callback_t init_callback; 140 | pngle_draw_callback_t draw_callback; 141 | pngle_done_callback_t done_callback; 142 | 143 | void *user_data; 144 | uint16_t screenWidth; 145 | uint16_t screenHeight; 146 | uint16_t imageWidth; 147 | uint16_t imageHeight; 148 | pixel_png **pixels; 149 | bool reduction; 150 | double scale_factor; 151 | }; 152 | 153 | 154 | // ---------------- 155 | // Basic interfaces 156 | // ---------------- 157 | pngle_t *pngle_new(uint16_t width, uint16_t height); 158 | void pngle_destroy(pngle_t *pngle, uint16_t width, uint16_t height); 159 | void pngle_reset(pngle_t *pngle); // clear its internal state (not applied to pngle_set_* functions) 160 | const char *pngle_error(pngle_t *pngle); 161 | int pngle_feed(pngle_t *pngle, const void *buf, size_t len); // returns -1: On error, 0: Need more data, n: n bytes eaten 162 | 163 | uint32_t pngle_get_width(pngle_t *pngle); 164 | uint32_t pngle_get_height(pngle_t *pngle); 165 | 166 | void pngle_set_init_callback(pngle_t *png, pngle_init_callback_t callback); 167 | void pngle_set_draw_callback(pngle_t *png, pngle_draw_callback_t callback); 168 | void pngle_set_done_callback(pngle_t *png, pngle_done_callback_t callback); 169 | 170 | void pngle_set_display_gamma(pngle_t *pngle, double display_gamma); // enables gamma correction by specifying display gamma, typically 2.2. No effect when gAMA chunk is missing 171 | 172 | void pngle_set_user_data(pngle_t *pngle, void *user_data); 173 | void *pngle_get_user_data(pngle_t *pngle); 174 | 175 | 176 | // Get IHDR information 177 | pngle_ihdr_t *pngle_get_ihdr(pngle_t *pngle); 178 | 179 | 180 | #ifdef __cplusplus 181 | } 182 | #endif 183 | 184 | #endif /* __PNGLE_H__ */ 185 | -------------------------------------------------------------------------------- /pngtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "tft_lib.h" 13 | #include "pngle/pngle.h" 14 | #include "pngle/decode_png.h" 15 | 16 | #include "driver/ili9341.h" 17 | #define DRIVER_NAME "ILI9341" 18 | #define SCREEN_WIDTH 240 19 | #define SCREEN_HEIGHT 320 20 | #define OFFSET_X 0 21 | #define OFFSET_Y 0 22 | #define INIT_FUNCTION(a, b, c, d, e) ili9341_lcdInit(a, b, c, d, e) 23 | 24 | #define _DEBUG_ 0 25 | 26 | time_t elapsedTime(struct timeval startTime, struct timeval endTime) { 27 | time_t diffsec = difftime(endTime.tv_sec, startTime.tv_sec); 28 | suseconds_t diffsub = endTime.tv_usec - startTime.tv_usec; 29 | //printf("diffsec=%ld diffsub=%ld\n",diffsec, diffsub); 30 | if(diffsub < 0) { 31 | diffsec--; 32 | diffsub = (endTime.tv_usec+1000000) - startTime.tv_usec; 33 | } 34 | uint16_t diffmsec = diffsub / 1000; 35 | time_t diff = (diffsec * 1000) + diffmsec; 36 | return diff; 37 | } 38 | 39 | time_t PNGTest(TFT_t * dev, char * file, int width, int height) { 40 | struct timeval startTime, endTime; 41 | gettimeofday(&startTime, NULL); 42 | 43 | lcdFillScreen(dev, BLACK); 44 | 45 | int _width = width; 46 | if (width > 240) _width = 240; 47 | int _height = height; 48 | if (height > 320) _height = 320; 49 | 50 | // open PNG file 51 | FILE* fp = fopen(file, "rb"); 52 | if (fp == NULL) { 53 | printf("File not found [%s]\n", file); 54 | return 0; 55 | } 56 | 57 | char buf[1024]; 58 | size_t remain = 0; 59 | int len; 60 | 61 | pngle_t *pngle = pngle_new(_width, _height); 62 | 63 | pngle_set_init_callback(pngle, png_init); 64 | pngle_set_draw_callback(pngle, png_draw); 65 | pngle_set_done_callback(pngle, png_finish); 66 | 67 | double display_gamma = 2.2; 68 | pngle_set_display_gamma(pngle, display_gamma); 69 | 70 | 71 | while (!feof(fp)) { 72 | if (remain >= sizeof(buf)) { 73 | printf("Buffer exceeded\n"); 74 | return 0; 75 | } 76 | 77 | len = fread(buf + remain, 1, sizeof(buf) - remain, fp); 78 | if (len <= 0) { 79 | //printf("EOF\n"); 80 | break; 81 | } 82 | 83 | int fed = pngle_feed(pngle, buf, remain + len); 84 | if (fed < 0) { 85 | printf("ERROR; %s\n", pngle_error(pngle)); 86 | return 0; 87 | } 88 | 89 | remain = remain + len - fed; 90 | if (remain > 0) memmove(buf, buf + fed, remain); 91 | } 92 | 93 | fclose(fp); 94 | 95 | uint16_t pngWidth = width; 96 | uint16_t offsetX = 0; 97 | if (width > pngle->imageWidth) { 98 | pngWidth = pngle->imageWidth; 99 | offsetX = (width - pngle->imageWidth) / 2; 100 | } 101 | printf("pngWidth=%d offsetX=%d", pngWidth, offsetX); 102 | 103 | uint16_t pngHeight = height; 104 | uint16_t offsetY = 0; 105 | if (height > pngle->imageHeight) { 106 | pngHeight = pngle->imageHeight; 107 | offsetY = (height - pngle->imageHeight) / 2; 108 | } 109 | printf("pngHeight=%d offsetY=%d\n", pngHeight, offsetY); 110 | uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * pngWidth); 111 | 112 | int ypos = (height-1) - offsetY; 113 | for(int y = 0; y < pngHeight; y++){ 114 | for(int x = 0;x < pngWidth; x++){ 115 | pixel_png pixel = pngle->pixels[y][x]; 116 | uint16_t color = rgb565_conv(pixel.red, pixel.green, pixel.blue); 117 | //lcdDrawPixel(dev, x+offsetX, y+offsetY, color); 118 | lcdDrawPixel(dev, x+offsetX, ypos, color); 119 | } 120 | ypos--; 121 | } 122 | 123 | 124 | free(colors); 125 | pngle_destroy(pngle, _width, _height); 126 | 127 | gettimeofday(&endTime, NULL); 128 | time_t diff = elapsedTime(startTime, endTime); 129 | printf("%s elapsed time[ms]=%ld\n",__func__, diff); 130 | return diff; 131 | } 132 | 133 | 134 | int main(int argc, char **argv){ 135 | 136 | if(wiringPiSetup() == -1) { 137 | printf("wiringPiSetup Fail\n"); 138 | return 1; 139 | } 140 | 141 | int i; 142 | char base[128]; 143 | strcpy(base, argv[0]); 144 | for(i=strlen(base);i>0;i--) { 145 | if (base[i-1] == '/') { 146 | base[i] = 0; 147 | break; 148 | } 149 | } 150 | if(_DEBUG_)printf("base=%s\n",base); 151 | 152 | char ppath[128]; 153 | strcpy(ppath,base); 154 | strcat(ppath,"pin.conf"); 155 | if(_DEBUG_)printf("ppath=%s\n",ppath); 156 | struct stat buffer; 157 | if (stat(ppath, &buffer) != 0) { 158 | printf("pin.conf [%s] not found\n",ppath); 159 | return 1; 160 | } 161 | 162 | TFT_t dev; 163 | lcdInterface(&dev, ppath); 164 | lcdReset(&dev); 165 | INIT_FUNCTION(&dev, SCREEN_WIDTH, SCREEN_HEIGHT, OFFSET_X, OFFSET_Y); 166 | 167 | 168 | char file[64]; 169 | strcpy(file, "./images/Ubuntu_log.png"); 170 | PNGTest(&dev, file, SCREEN_WIDTH, SCREEN_HEIGHT); 171 | sleep(5); 172 | 173 | //lcdFadeout(&dev, DIRECTION90, BLACK); 174 | } 175 | -------------------------------------------------------------------------------- /rgb2color.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // Convert RBG to RGB565. 7 | // RGB565 is R(5)+G(6)+B(5)=16bit color format. 8 | // Bit image "RRRRRGGGGGGBBBBB" 9 | uint16_t rgb565_conv(uint16_t r,uint16_t g,uint16_t b) 10 | { 11 | unsigned int RR,GG,BB; 12 | RR = (r * 31 / 255) << 11; 13 | GG = (g * 63 / 255) << 5; 14 | BB = (b * 31 / 255); 15 | return(RR | GG | BB); 16 | } 17 | 18 | 19 | void usage (char * prog) { 20 | printf("%s HTML_Color_Code\n",prog); 21 | printf("%s 0xff0000\n",prog); 22 | } 23 | 24 | 25 | int main(int argc, char **argv) 26 | { 27 | if(argc != 2) { 28 | usage(argv[0]); 29 | return 1; 30 | } 31 | 32 | char html[10]; 33 | strcpy(html,argv[1]); 34 | if (strncmp(html,"0x",2) == 0) { 35 | strcpy(html,&html[2]); 36 | } 37 | //printf("html=%s\n",html); 38 | if (strlen(html) != 6) { 39 | usage(argv[0]); 40 | return 1; 41 | } 42 | uint16_t r,g,b; 43 | char rc[3],gc[3],bc[3]; 44 | memset(rc,0,sizeof(rc)); 45 | memset(gc,0,sizeof(gc)); 46 | memset(bc,0,sizeof(bc)); 47 | rc[0]=html[0]; 48 | rc[1]=html[1]; 49 | gc[0]=html[2]; 50 | gc[1]=html[3]; 51 | bc[0]=html[4]; 52 | bc[1]=html[5]; 53 | 54 | r = strtol(rc,NULL,16); 55 | g = strtol(gc,NULL,16); 56 | b = strtol(bc,NULL,16); 57 | //printf("r=%x g=%x b=%x\n",r,g,b); 58 | uint16_t color; 59 | color = rgb565_conv(r, g, b); 60 | printf("0x%04x\n",color); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /tft_lib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define __TFT_LIB_C__ 9 | #include "tft_lib.h" 10 | 11 | #define _DEBUG_ 0 12 | 13 | // delay defined in WiringPi.h 14 | void lcdDelay(int ms) { 15 | delay(ms); 16 | } 17 | 18 | void lcdWriteByte(TFT_t *dev, uint8_t data) { 19 | digitalWrite(dev->pins.d0, data & 1); 20 | digitalWrite(dev->pins.d1, (data & 2) >> 1); 21 | digitalWrite(dev->pins.d2, (data & 4) >> 2); 22 | digitalWrite(dev->pins.d3, (data & 8) >> 3); 23 | digitalWrite(dev->pins.d4, (data & 16) >> 4); 24 | digitalWrite(dev->pins.d5, (data & 32) >> 5); 25 | digitalWrite(dev->pins.d6, (data & 64) >> 6); 26 | digitalWrite(dev->pins.d7, (data & 128) >> 7); 27 | 28 | digitalWrite(dev->pins.wr, LOW); 29 | //delayMicroseconds(10); 30 | digitalWrite(dev->pins.wr, HIGH); 31 | } 32 | 33 | void lcdWriteWord(TFT_t *dev, uint16_t data) { 34 | digitalWrite(dev->pins.d0, data & 1); 35 | digitalWrite(dev->pins.d1, (data & 2) >> 1); 36 | digitalWrite(dev->pins.d2, (data & 4) >> 2); 37 | digitalWrite(dev->pins.d3, (data & 8) >> 3); 38 | digitalWrite(dev->pins.d4, (data & 16) >> 4); 39 | digitalWrite(dev->pins.d5, (data & 32) >> 5); 40 | digitalWrite(dev->pins.d6, (data & 64) >> 6); 41 | digitalWrite(dev->pins.d7, (data & 128) >> 7); 42 | digitalWrite(dev->pins.d8, (data & 256) >> 8); 43 | digitalWrite(dev->pins.d9, (data & 512) >> 9); 44 | digitalWrite(dev->pins.d10, (data & 1024) >> 10); 45 | digitalWrite(dev->pins.d11, (data & 2048) >> 11); 46 | digitalWrite(dev->pins.d12, (data & 4096) >> 12); 47 | digitalWrite(dev->pins.d13, (data & 8192) >> 13); 48 | digitalWrite(dev->pins.d14, (data & 16384) >> 14); 49 | digitalWrite(dev->pins.d15, (data & 32768) >> 15); 50 | 51 | digitalWrite(dev->pins.wr, LOW); 52 | //delayMicroseconds(10); 53 | digitalWrite(dev->pins.wr, HIGH); 54 | } 55 | 56 | 57 | void lcdWriteDataWord(TFT_t *dev, uint16_t data) { 58 | digitalWrite(dev->pins.cs, LOW); 59 | digitalWrite(dev->pins.rs, HIGH); 60 | digitalWrite(dev->pins.rd, HIGH); 61 | digitalWrite(dev->pins.wr, HIGH); 62 | lcdWriteByte(dev, data >> 8); 63 | lcdWriteByte(dev, data); 64 | digitalWrite(dev->pins.cs, HIGH); 65 | } 66 | 67 | 68 | // For 16bit parallel interface 69 | // It's effective only at color data. 70 | // Many thanks for myg3nx 71 | void lcdWriteDataWord_16bit(TFT_t *dev, uint16_t data) { 72 | digitalWrite(dev->pins.cs, LOW); 73 | digitalWrite(dev->pins.rs, HIGH); 74 | digitalWrite(dev->pins.rd, HIGH); 75 | digitalWrite(dev->pins.wr, HIGH); 76 | lcdWriteWord(dev, data); 77 | digitalWrite(dev->pins.cs, HIGH); 78 | } 79 | 80 | void lcdWriteDataByte(TFT_t *dev, uint8_t data) { 81 | digitalWrite(dev->pins.cs, LOW); 82 | digitalWrite(dev->pins.rs, HIGH); 83 | digitalWrite(dev->pins.rd, HIGH); 84 | digitalWrite(dev->pins.wr, HIGH); 85 | lcdWriteByte(dev, data); 86 | digitalWrite(dev->pins.cs, HIGH); 87 | } 88 | 89 | void lcdWriteCommandWord(TFT_t *dev, uint16_t command) { 90 | digitalWrite(dev->pins.cs, LOW); 91 | digitalWrite(dev->pins.rs, LOW); 92 | digitalWrite(dev->pins.rd, HIGH); 93 | digitalWrite(dev->pins.wr, HIGH); 94 | lcdWriteByte(dev, command >> 8); 95 | lcdWriteByte(dev, command); 96 | digitalWrite(dev->pins.cs, HIGH); 97 | } 98 | 99 | void lcdWriteCommandByte(TFT_t *dev, uint8_t command) { 100 | digitalWrite(dev->pins.cs, LOW); 101 | digitalWrite(dev->pins.rs, LOW); 102 | digitalWrite(dev->pins.rd, HIGH); 103 | digitalWrite(dev->pins.wr, HIGH); 104 | lcdWriteByte(dev, command); 105 | digitalWrite(dev->pins.cs, HIGH); 106 | } 107 | 108 | 109 | void lcdWriteRegisterWord(TFT_t *dev, uint16_t addr, uint16_t data) { 110 | lcdWriteCommandWord(dev, addr); 111 | lcdWriteDataWord(dev, data); 112 | } 113 | 114 | void lcdWriteRegisterByte(TFT_t *dev, uint8_t addr, uint16_t data) { 115 | lcdWriteCommandByte(dev, addr); 116 | lcdWriteDataWord(dev, data); 117 | } 118 | 119 | void lcdInterface(TFT_t *dev, char* ppath) { 120 | #if 0 121 | dev->pins.rst = 7; 122 | dev->pins.cs = 8; 123 | dev->pins.rs = 9; 124 | dev->pins.wr = 11; 125 | dev->pins.rd = 31; 126 | dev->pins.d0 = 21; 127 | dev->pins.d1 = 22; 128 | dev->pins.d2 = 23; 129 | dev->pins.d3 = 24; 130 | dev->pins.d4 = 25; 131 | dev->pins.d5 = 26; 132 | dev->pins.d6 = 27; 133 | dev->pins.d7 = 28; 134 | #endif 135 | 136 | if(_DEBUG_) printf("ppath=%s\n",ppath); 137 | 138 | ReadPinConfig(&(dev->pins), ppath); 139 | if(_DEBUG_)printf("rst=%d cs=%d rs=%d wr=%d rd=%d\n", 140 | dev->pins.rst, dev->pins.cs, dev->pins.rs, dev->pins.wr, dev->pins.rd); 141 | if(_DEBUG_)printf("d0=%d d1=%d d2=%d d4=%d d4=%d d5=%d d6=%d d7=%d\n", 142 | dev->pins.d0, dev->pins.d1, dev->pins.d2, dev->pins.d3, dev->pins.d4, dev->pins.d5, dev->pins.d6, dev->pins.d7); 143 | #ifdef P16BIT 144 | if(_DEBUG_)printf("d8=%d d9=%d d10=%d d11=%d d12=%d d13=%d d14=%d d15=%d\n", 145 | dev->pins.d8, dev->pins.d9, dev->pins.d10, dev->pins.d11, dev->pins.d12, dev->pins.d13, dev->pins.d14, dev->pins.d15); 146 | #endif 147 | 148 | pinMode(dev->pins.cs, OUTPUT); 149 | digitalWrite(dev->pins.cs, HIGH); 150 | pinMode(dev->pins.rs, OUTPUT); 151 | digitalWrite(dev->pins.rs, HIGH); 152 | pinMode(dev->pins.wr, OUTPUT); 153 | digitalWrite(dev->pins.wr, HIGH); 154 | pinMode(dev->pins.rd, OUTPUT); 155 | digitalWrite(dev->pins.rd, HIGH); 156 | pinMode(dev->pins.rst, OUTPUT); 157 | digitalWrite(dev->pins.rst, HIGH); 158 | 159 | pinMode(dev->pins.d0, OUTPUT); 160 | pinMode(dev->pins.d1, OUTPUT); 161 | pinMode(dev->pins.d2, OUTPUT); 162 | pinMode(dev->pins.d3, OUTPUT); 163 | pinMode(dev->pins.d4, OUTPUT); 164 | pinMode(dev->pins.d5, OUTPUT); 165 | pinMode(dev->pins.d6, OUTPUT); 166 | pinMode(dev->pins.d7, OUTPUT); 167 | 168 | pinMode(dev->pins.d8, OUTPUT); 169 | pinMode(dev->pins.d9, OUTPUT); 170 | pinMode(dev->pins.d10, OUTPUT); 171 | pinMode(dev->pins.d11, OUTPUT); 172 | pinMode(dev->pins.d12, OUTPUT); 173 | pinMode(dev->pins.d13, OUTPUT); 174 | pinMode(dev->pins.d14, OUTPUT); 175 | pinMode(dev->pins.d15, OUTPUT); 176 | } 177 | 178 | void lcdReset(TFT_t *dev) { 179 | digitalWrite(dev->pins.rst, HIGH); 180 | delay(100); 181 | digitalWrite(dev->pins.rst, LOW); 182 | delay(100); 183 | digitalWrite(dev->pins.rst, HIGH); 184 | delay(100); 185 | } 186 | 187 | void lcdInitTable(TFT_t *dev, const void *table, int16_t size) 188 | { 189 | int i; 190 | uint8_t *p = (uint8_t *) table; 191 | while (size > 0) { 192 | uint8_t cmd = *p++; 193 | uint8_t len = *p++; 194 | if (cmd == TFTLCD_DELAY8) { 195 | delay(len); 196 | len = 0; 197 | } else { 198 | lcdWriteCommandByte(dev, cmd); 199 | for (i = 0; i < len; i++) { 200 | uint8_t data = *p++; 201 | lcdWriteDataByte(dev, data); 202 | } 203 | } 204 | size -= len + 2; 205 | } 206 | } 207 | 208 | void lcdInitTable16(TFT_t *dev, const void *table, int16_t size) 209 | { 210 | uint16_t *p = (uint16_t *) table; 211 | while (size > 0) { 212 | uint16_t cmd = *p++; 213 | uint16_t dat = *p++; 214 | if (cmd == TFTLCD_DELAY16) 215 | delay(dat); 216 | else { 217 | lcdWriteRegisterWord(dev, cmd, dat); 218 | } 219 | size -= 2 * sizeof(int16_t); 220 | } 221 | } 222 | 223 | void lcdInit(TFT_t *dev, uint16_t model, int width, int height, int offsetx, int offsety) { 224 | dev->_model = model; 225 | dev->_width = width; 226 | dev->_height = height; 227 | dev->_offsetx = offsetx; 228 | dev->_offsety = offsety; 229 | dev->_font_direction = DIRECTION0; 230 | dev->_font_fill = false; 231 | dev->_font_underline = false; 232 | } 233 | 234 | // Draw pixel 235 | // x:X coordinate 236 | // y:Y coordinate 237 | // color:color 238 | void lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color) { 239 | (*DrawPixel)(dev, x, y, color); 240 | } 241 | 242 | // Draw rectangule of filling 243 | // x1:Start X coordinate 244 | // y1:Start Y coordinate 245 | // x2:End X coordinate 246 | // y2:End Y coordinate 247 | // color:color 248 | void lcdDrawFillRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color){ 249 | (*DrawFillRect)(dev, x1, y1, x2, y2, color); 250 | } 251 | 252 | // Display Off 253 | void lcdDisplayOff(TFT_t *dev) { 254 | (*DisplayOff)(dev); 255 | } 256 | 257 | // Display On 258 | void lcdDisplayOn(TFT_t *dev) { 259 | (*DisplayOn)(dev); 260 | } 261 | 262 | // Inversion Off 263 | void lcdInversionOff(TFT_t *dev) { 264 | (*InversionOff)(dev); 265 | } 266 | 267 | // Inversion On 268 | void lcdInversionOn(TFT_t *dev) { 269 | (*InversionOn)(dev); 270 | } 271 | 272 | // Fill screen 273 | // color:color 274 | void lcdFillScreen(TFT_t *dev, uint16_t color) { 275 | lcdDrawFillRect(dev, 0, 0, dev->_width-1, dev->_height-1, color); 276 | } 277 | 278 | // Fadeout screen 279 | // color:color 280 | void lcdFadeout(TFT_t *dev, int direction, uint16_t color) { 281 | if (direction == DIRECTION0) { 282 | for (int x=0;x_width-1;x++) { 283 | lcdDrawFillRect(dev, x, 0, x+1, dev->_height-1, color); 284 | } 285 | } else if (direction == DIRECTION90) { 286 | for (int y=dev->_height-1;y>0;y--) { 287 | lcdDrawFillRect(dev, 0, y-1, dev->_width-1, y, color); 288 | } 289 | } else if (direction == DIRECTION180) { 290 | for (int x=dev->_width-1;x>0;x--) { 291 | lcdDrawFillRect(dev, x-1, 0, x, dev->_height-1, color); 292 | } 293 | } else if (direction == DIRECTION270) { 294 | for (int y=0;y_height-1;y++) { 295 | lcdDrawFillRect(dev, 0, y, dev->_width-1, y+1, color); 296 | } 297 | } 298 | } 299 | 300 | // Draw line 301 | // x1:Start X coordinate 302 | // y1:Start Y coordinate 303 | // x2:End X coordinate 304 | // y2:End Y coordinate 305 | // color:color 306 | void lcdDrawLine(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) 307 | { 308 | int i; 309 | int dx,dy; 310 | int sx,sy; 311 | int E; 312 | 313 | /* distance between two points */ 314 | dx = ( x2 > x1 ) ? x2 - x1 : x1 - x2; 315 | dy = ( y2 > y1 ) ? y2 - y1 : y1 - y2; 316 | 317 | /* direction of two point */ 318 | sx = ( x2 > x1 ) ? 1 : -1; 319 | sy = ( y2 > y1 ) ? 1 : -1; 320 | 321 | /* inclination < 1 */ 322 | if ( dx > dy ) { 323 | E = -dx; 324 | for ( i = 0 ; i <= dx ; i++ ) { 325 | lcdDrawPixel(dev, x1, y1, color); 326 | x1 += sx; 327 | E += 2 * dy; 328 | if ( E >= 0 ) { 329 | y1 += sy; 330 | E -= 2 * dx; 331 | } 332 | } 333 | /* inclination >= 1 */ 334 | } else { 335 | E = -dy; 336 | for ( i = 0 ; i <= dy ; i++ ) { 337 | lcdDrawPixel(dev, x1, y1, color); 338 | y1 += sy; 339 | E += 2 * dx; 340 | if ( E >= 0 ) { 341 | x1 += sx; 342 | E -= 2 * dy; 343 | } 344 | } 345 | } 346 | } 347 | 348 | // Draw rectangule 349 | // x1:Start X coordinate 350 | // y1:Start Y coordinate 351 | // x2:End X coordinate 352 | // y2:End Y coordinate 353 | // color:color 354 | void lcdDrawRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) 355 | { 356 | lcdDrawLine(dev,x1,y1,x2,y1,color); 357 | lcdDrawLine(dev,x2,y1,x2,y2,color); 358 | lcdDrawLine(dev,x2,y2,x1,y2,color); 359 | lcdDrawLine(dev,x1,y2,x1,y1,color); 360 | } 361 | 362 | // Draw round 363 | // x0:Central X coordinate 364 | // y0:Central Y coordinate 365 | // r:radius 366 | // color:color 367 | void lcdDrawCircle(TFT_t *dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) 368 | { 369 | int x; 370 | int y; 371 | int err; 372 | int old_err; 373 | 374 | x=0; 375 | y=-r; 376 | err=2-2*r; 377 | do{ 378 | lcdDrawPixel(dev, x0-x, y0+y, color); 379 | lcdDrawPixel(dev, x0-y, y0-x, color); 380 | lcdDrawPixel(dev, x0+x, y0-y, color); 381 | lcdDrawPixel(dev, x0+y, y0+x, color); 382 | if ((old_err=err)<=x) err+=++x*2+1; 383 | if (old_err>y || err>x) err+=++y*2+1; 384 | } while(y<0); 385 | 386 | } 387 | 388 | // Draw round of filling 389 | // x0:Central X coordinate 390 | // y0:Central Y coordinate 391 | // r:radius 392 | // color:color 393 | void lcdDrawFillCircle(TFT_t *dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) 394 | { 395 | int x; 396 | int y; 397 | int err; 398 | int old_err; 399 | int ChangeX; 400 | 401 | x=0; 402 | y=-r; 403 | err=2-2*r; 404 | ChangeX=1; 405 | do{ 406 | if(ChangeX) { 407 | lcdDrawLine(dev,x0-x,y0-y,x0-x,y0+y,color); 408 | lcdDrawLine(dev,x0+x,y0-y,x0+x,y0+y,color); 409 | } // if 410 | ChangeX=(old_err=err)<=x; 411 | if (ChangeX) err+=++x*2+1; 412 | if (old_err>y || err>x) err+=++y*2+1; 413 | } while(y<=0); 414 | 415 | } 416 | 417 | // Draw rectangule with round corner 418 | // x1:Start X coordinate 419 | // y1:Start Y coordinate 420 | // x2:End X coordinate 421 | // y2:End Y coordinate 422 | // r:radius 423 | // color:color 424 | void lcdDrawRoundRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color) 425 | { 426 | int x; 427 | int y; 428 | int err; 429 | int old_err; 430 | unsigned char temp; 431 | 432 | if(x1>x2) { 433 | temp=x1; x1=x2; x2=temp; 434 | } 435 | 436 | if(y1>y2) { 437 | temp=y1; y1=y2; y2=temp; 438 | } 439 | if(x2-x1 < r) return; // Add 20190517 440 | if(y2-y1 < r) return; // Add 20190517 441 | 442 | 443 | x=0; 444 | y=-r; 445 | err=2-2*r; 446 | 447 | do{ 448 | if(x) { 449 | lcdDrawPixel(dev, x1+r-x, y1+r+y, color); 450 | lcdDrawPixel(dev, x2-r+x, y1+r+y, color); 451 | lcdDrawPixel(dev, x1+r-x, y2-r-y, color); 452 | lcdDrawPixel(dev, x2-r+x, y2-r-y, color); 453 | } // if 454 | if ((old_err=err)<=x) err+=++x*2+1; 455 | if (old_err>y || err>x) err+=++y*2+1; 456 | } while(y<0); 457 | 458 | lcdDrawLine(dev, x1+r,y1 ,x2-r,y1 ,color); 459 | lcdDrawLine(dev, x1+r,y2 ,x2-r,y2 ,color); 460 | lcdDrawLine(dev, x1 ,y1+r,x1 ,y2-r, color); 461 | lcdDrawLine(dev, x2 ,y1+r,x2 ,y2-r, color); 462 | } 463 | 464 | // Draw arrow 465 | // x1:Start X coordinate 466 | // y1:Start Y coordinate 467 | // x2:End X coordinate 468 | // y2:End Y coordinate 469 | // w:Width of the botom 470 | // color:color 471 | // Thanks http://k-hiura.cocolog-nifty.com/blog/2010/11/post-2a62.html 472 | void lcdDrawArrow(TFT_t *dev, uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t w,uint16_t color){ 473 | 474 | double Vx= x1 - x0; 475 | double Vy= y1 - y0; 476 | double v = sqrt(Vx*Vx+Vy*Vy); 477 | // printf("v=%f\n",v); 478 | double Ux= Vx/v; 479 | double Uy= Vy/v; 480 | 481 | uint16_t L[2],R[2]; 482 | L[0]= x1 - Uy*w - Ux*v; 483 | L[1]= y1 + Ux*w - Uy*v; 484 | R[0]= x1 + Uy*w - Ux*v; 485 | R[1]= y1 - Ux*w - Uy*v; 486 | // printf("L=%d-%d R=%d-%d\n",L[0],L[1],R[0],R[1]); 487 | 488 | // lcdDrawLine(dev,x0,y0,x1,y1,color); 489 | lcdDrawLine(dev,x1,y1,L[0],L[1],color); 490 | lcdDrawLine(dev,x1,y1,R[0],R[1],color); 491 | lcdDrawLine(dev,L[0],L[1],R[0],R[1],color); 492 | } 493 | 494 | 495 | // Draw arrow of filling 496 | // x1:Start X coordinate 497 | // y1:Start Y coordinate 498 | // x2:End X coordinate 499 | // y2:End Y coordinate 500 | // w:Width of the botom 501 | // color:color 502 | void lcdDrawFillArrow(TFT_t *dev, uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t w,uint16_t color){ 503 | 504 | double Vx= x1 - x0; 505 | double Vy= y1 - y0; 506 | double v = sqrt(Vx*Vx+Vy*Vy); 507 | // printf("v=%f\n",v); 508 | double Ux= Vx/v; 509 | double Uy= Vy/v; 510 | 511 | uint16_t L[2],R[2]; 512 | L[0]= x1 - Uy*w - Ux*v; 513 | L[1]= y1 + Ux*w - Uy*v; 514 | R[0]= x1 + Uy*w - Ux*v; 515 | R[1]= y1 - Ux*w - Uy*v; 516 | // printf("L=%d-%d R=%d-%d\n",L[0],L[1],R[0],R[1]); 517 | 518 | lcdDrawLine(dev,x0,y0,x1,y1,color); 519 | lcdDrawLine(dev,x1,y1,L[0],L[1],color); 520 | lcdDrawLine(dev,x1,y1,R[0],R[1],color); 521 | lcdDrawLine(dev,L[0],L[1],R[0],R[1],color); 522 | 523 | int ww; 524 | for(ww=w-1;ww>0;ww--) { 525 | L[0]= x1 - Uy*ww - Ux*v; 526 | L[1]= y1 + Ux*ww - Uy*v; 527 | R[0]= x1 + Uy*ww - Ux*v; 528 | R[1]= y1 - Ux*ww - Uy*v; 529 | // printf("Fill>L=%d-%d R=%d-%d\n",L[0],L[1],R[0],R[1]); 530 | lcdDrawLine(dev,x1,y1,L[0],L[1],color); 531 | lcdDrawLine(dev,x1,y1,R[0],R[1],color); 532 | } 533 | } 534 | 535 | 536 | // RGB565 conversion 537 | // RGB565 is R(5)+G(6)+B(5)=16bit color format. 538 | // Bit image "RRRRRGGGGGGBBBBB" 539 | uint16_t rgb565_conv(uint16_t r,uint16_t g,uint16_t b) 540 | { 541 | unsigned int RR,GG,BB; 542 | RR = (r * 31 / 255) << 11; 543 | GG = (g * 63 / 255) << 5; 544 | BB = (b * 31 / 255); 545 | return(RR | GG | BB); 546 | } 547 | 548 | 549 | // Draw SJIS character 550 | // x:X coordinate 551 | // y:Y coordinate 552 | // sjis: SJIS code 553 | // color:color 554 | int lcdDrawSJISChar(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,uint16_t sjis,uint16_t color) { 555 | uint16_t xx,yy,bit,ofs; 556 | unsigned char fonts[128]; // font pattern 557 | unsigned char pw, ph; 558 | int h,w; 559 | uint16_t mask; 560 | bool rc; 561 | 562 | if(_DEBUG_)printf("_font_direction=%d\n",dev->_font_direction); 563 | // sjis = UTF2SJIS(utf8); 564 | //if(_DEBUG_)printf("sjis=%04x\n",sjis); 565 | 566 | rc = GetFontx(fx, sjis, fonts, &pw, &ph); // SJIS -> Font pattern 567 | if(_DEBUG_)printf("GetFontx rc=%d pw=%d ph=%d\n",rc,pw,ph); 568 | if (!rc) return -1; 569 | 570 | int xd1, yd1; 571 | int xd2, yd2; 572 | int xss, yss; 573 | int xsd, ysd; 574 | int next; 575 | if (dev->_font_direction == 0) { 576 | xd1 = +1; 577 | yd1 = -1; 578 | xd2 = 0; 579 | yd2 = 0; 580 | xss = x; 581 | yss = y + ph - 1; 582 | xsd = 1; 583 | ysd = 0; 584 | next = x + pw; 585 | } else if (dev->_font_direction == 2) { 586 | xd1 = -1; 587 | yd1 = +1; 588 | xd2 = 0; 589 | yd2 = 0; 590 | xss = x; 591 | yss = y - ph + 1; 592 | xsd = 1; 593 | ysd = 0; 594 | next = x - pw; 595 | } else if (dev->_font_direction == 1) { 596 | xd1 = 0; 597 | yd1 = 0; 598 | xd2 = -1; 599 | yd2 = -1; 600 | xss = x + ph; 601 | yss = y; 602 | xsd = 0; 603 | ysd = 1; 604 | next = y - pw; 605 | } else if (dev->_font_direction == 3) { 606 | xd1 = 0; 607 | yd1 = 0; 608 | xd2 = +1; 609 | yd2 = +1; 610 | xss = x - ph - 1; 611 | yss = y; 612 | xsd = 0; 613 | ysd = 1; 614 | next = y + pw; 615 | } 616 | 617 | int bits; 618 | if(_DEBUG_)printf("xss=%d yss=%d\n",xss,yss); 619 | ofs = 0; 620 | yy = yss; 621 | xx = xss; 622 | for(h=0;h_font_fill) lcdDrawPixel(dev, xx, yy, dev->_font_fill_color); 637 | } 638 | if (h == (ph-2) && dev->_font_underline) 639 | lcdDrawPixel(dev, xx, yy, dev->_font_underline_color); 640 | if (h == (ph-1) && dev->_font_underline) 641 | lcdDrawPixel(dev, xx, yy, dev->_font_underline_color); 642 | 643 | xx = xx + xd1; 644 | yy = yy + yd2; 645 | mask = mask >> 1; 646 | } 647 | ofs++; 648 | } 649 | yy = yy + yd1; 650 | xx = xx + xd2; 651 | 652 | } 653 | 654 | if (next < 0) next = 0; 655 | return next; 656 | } 657 | 658 | // Draw UTF8 character 659 | // x:X coordinate 660 | // y:Y coordinate 661 | // utf8: UTF8 code 662 | // color:color 663 | int lcdDrawUTF8Char(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,uint8_t *utf8,uint16_t color) { 664 | uint16_t sjis[1]; 665 | 666 | sjis[0] = UTF2SJIS(utf8); 667 | if(_DEBUG_)printf("sjis=%04x\n",sjis[0]); 668 | return lcdDrawSJISChar(dev,fx,x,y,sjis[0],color); 669 | } 670 | 671 | // Draw UTF8 string 672 | // x:X coordinate 673 | // y:Y coordinate 674 | // utfs: UTF8 string 675 | // color:color 676 | int lcdDrawUTF8String(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,unsigned char *utfs,uint16_t color) { 677 | 678 | int i; 679 | int spos; 680 | uint16_t sjis[64]; 681 | spos = String2SJIS(utfs, strlen((char *)utfs), sjis, 64); 682 | if(_DEBUG_)printf("spos=%d\n",spos); 683 | for(i=0;i_font_direction == 0) 686 | x=lcdDrawSJISChar(dev,fx,x,y,sjis[i],color); 687 | if (dev->_font_direction == 1) 688 | y=lcdDrawSJISChar(dev,fx,x,y,sjis[i],color); 689 | if (dev->_font_direction == 2) 690 | x=lcdDrawSJISChar(dev,fx,x,y,sjis[i],color); 691 | if (dev->_font_direction == 3) 692 | y=lcdDrawSJISChar(dev,fx,x,y,sjis[i],color); 693 | } 694 | if (dev->_font_direction == 0) return x; 695 | if (dev->_font_direction == 2) return x; 696 | if (dev->_font_direction == 1) return y; 697 | if (dev->_font_direction == 3) return y; 698 | return 0; 699 | } 700 | 701 | // Set font direction 702 | // dir:Direction 703 | void lcdSetFontDirection(TFT_t *dev, uint16_t dir) { 704 | dev->_font_direction = dir; 705 | } 706 | 707 | // Set font filling 708 | // color:fill color 709 | void lcdSetFontFill(TFT_t *dev, uint16_t color) { 710 | dev->_font_fill = true; 711 | dev->_font_fill_color = color; 712 | } 713 | 714 | // UnSet font filling 715 | void lcdUnsetFontFill(TFT_t *dev) { 716 | dev->_font_fill = false; 717 | } 718 | 719 | // Set font underline 720 | // color:frame color 721 | void lcdSetFontUnderLine(TFT_t *dev, uint16_t color) { 722 | dev->_font_underline = true; 723 | dev->_font_underline_color = color; 724 | } 725 | 726 | // UnSet font underline 727 | void lcdUnsetFontUnderLine(TFT_t *dev) { 728 | dev->_font_underline = false; 729 | } 730 | 731 | 732 | int ReadPinConfig(GPIO_t *pin, char *path) { 733 | FILE *fp; 734 | char buff[128]; 735 | 736 | //printf("path=%s\n",path); 737 | fp = fopen(path,"r"); 738 | if(fp == NULL) return 0; 739 | while (fgets(buff,128,fp) != NULL) { 740 | //printf("buf=[%s]\n",buff); 741 | //printf("buff[0]=%x\n",buff[0]); 742 | 743 | int buffLen = strlen(buff); 744 | for (int index=0;indexrst)); 758 | } else if (strncmp(buff,"RS=",3) == 0) { 759 | sscanf(buff, "RS=%d", &(pin->rs)); 760 | } else if (strncmp(buff,"CS=",3) == 0) { 761 | sscanf(buff, "CS=%d", &(pin->cs)); 762 | } else if (strncmp(buff,"WR=",3) == 0) { 763 | sscanf(buff, "WR=%d", &(pin->wr)); 764 | } else if (strncmp(buff,"RD=",3) == 0) { 765 | sscanf(buff, "RD=%d", &(pin->rd)); 766 | } else if (strncmp(buff,"D0=",3) == 0) { 767 | sscanf(buff, "D0=%d", &(pin->d0)); 768 | } else if (strncmp(buff,"D1=",3) == 0) { 769 | sscanf(buff, "D1=%d", &(pin->d1)); 770 | } else if (strncmp(buff,"D2=",3) == 0) { 771 | sscanf(buff, "D2=%d", &(pin->d2)); 772 | } else if (strncmp(buff,"D3=",3) == 0) { 773 | sscanf(buff, "D3=%d", &(pin->d3)); 774 | } else if (strncmp(buff,"D4=",3) == 0) { 775 | sscanf(buff, "D4=%d", &(pin->d4)); 776 | } else if (strncmp(buff,"D5=",3) == 0) { 777 | sscanf(buff, "D5=%d", &(pin->d5)); 778 | } else if (strncmp(buff,"D6=",3) == 0) { 779 | sscanf(buff, "D6=%d", &(pin->d6)); 780 | } else if (strncmp(buff,"D7=",3) == 0) { 781 | sscanf(buff, "D7=%d", &(pin->d7)); 782 | } else if (strncmp(buff,"D8=",3) == 0) { 783 | sscanf(buff, "D8=%d", &(pin->d8)); 784 | } else if (strncmp(buff,"D9=",3) == 0) { 785 | sscanf(buff, "D9=%d", &(pin->d9)); 786 | } else if (strncmp(buff,"D10=",4) == 0) { 787 | sscanf(buff, "D10=%d", &(pin->d10)); 788 | } else if (strncmp(buff,"D11=",4) == 0) { 789 | sscanf(buff, "D11=%d", &(pin->d11)); 790 | } else if (strncmp(buff,"D12=",4) == 0) { 791 | sscanf(buff, "D12=%d", &(pin->d12)); 792 | } else if (strncmp(buff,"D13=",4) == 0) { 793 | sscanf(buff, "D13=%d", &(pin->d13)); 794 | } else if (strncmp(buff,"D14=",4) == 0) { 795 | sscanf(buff, "D14=%d", &(pin->d14)); 796 | } else if (strncmp(buff,"D15=",4) == 0) { 797 | sscanf(buff, "D15=%d", &(pin->d15)); 798 | } 799 | 800 | } 801 | fclose(fp); 802 | return 1; 803 | 804 | } 805 | -------------------------------------------------------------------------------- /tft_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __TFT_LIB_H__ 2 | #define __TFT_LIB_H__ 3 | 4 | 5 | /* 6 | The version of GCC has changed. 7 | raspberrypi 5.10.103-v7+:gcc (Raspbian 8.3.0-6+rpi1) 8.3.0 8 | raspberrypi 5.15.32-v7+:gcc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110 9 | 10 | "Multiple definition of" on GCC 10.2.1 but not GCC 8.3.0 11 | 12 | There was a change in behaviour about global variables between GCC 8.3.0 and GCC 10.2.1. 13 | In C you are supposed to only define a global variable in one translation unit, 14 | other translation unit that want to access the variable should declare it as "extern". 15 | 16 | GCC 8.3.0 has a collaborative definition, so no error occurs. 17 | But GCC 10.2.1 don't have cooperative definition, so error occurs. 18 | */ 19 | 20 | #ifndef __TFT_LIB_C__ 21 | #define DECLARE extern 22 | #else 23 | #define DECLARE 24 | #endif 25 | 26 | #include "fontx.h" 27 | 28 | #define RED 0xf800 29 | #define GREEN 0x07e0 30 | #define BLUE 0x001f 31 | #define BLACK 0x0000 32 | #define WHITE 0xffff 33 | #define GRAY 0x8c51 34 | #define YELLOW 0xFFE0 35 | #define CYAN 0x07FF 36 | #define PURPLE 0xF81F 37 | 38 | #define DIRECTION0 0 39 | #define DIRECTION90 1 40 | #define DIRECTION180 2 41 | #define DIRECTION270 3 42 | 43 | #define TFTLCD_DELAY 0xFFFF 44 | #define TFTLCD_DELAY16 0xFFFF 45 | #define TFTLCD_DELAY8 0x7F 46 | 47 | typedef struct { 48 | int rst; 49 | int cs; 50 | int rs; 51 | int wr; 52 | int rd; 53 | int d0; 54 | int d1; 55 | int d2; 56 | int d3; 57 | int d4; 58 | int d5; 59 | int d6; 60 | int d7; 61 | int d8; 62 | int d9; 63 | int d10; 64 | int d11; 65 | int d12; 66 | int d13; 67 | int d14; 68 | int d15; 69 | } GPIO_t; 70 | 71 | typedef struct { 72 | uint16_t _model; 73 | uint16_t _width; 74 | uint16_t _height; 75 | uint16_t _offsetx; 76 | uint16_t _offsety; 77 | int16_t _font_direction; 78 | int16_t _font_fill; 79 | uint16_t _font_fill_color; 80 | int16_t _font_underline; 81 | uint16_t _font_underline_color; 82 | GPIO_t pins; 83 | int16_t _delay; 84 | bool _debug; 85 | } TFT_t; 86 | 87 | // Driver dependent function 88 | DECLARE void (*DrawPixel)(TFT_t * dev, uint16_t x, uint16_t y, uint16_t color); 89 | DECLARE void (*DrawMultiPixels)(TFT_t * dev, uint16_t x, uint16_t y, uint16_t size, uint16_t * colors); 90 | DECLARE void (*DrawFillRect)(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 91 | DECLARE void (*DisplayOff)(TFT_t * dev); 92 | DECLARE void (*DisplayOn)(TFT_t * dev); 93 | DECLARE void (*InversionOff)(TFT_t * dev); 94 | DECLARE void (*InversionOn)(TFT_t * dev); 95 | 96 | // Global function 97 | void lcdDelay(int ms); 98 | void lcdWriteByte(TFT_t *dev, uint8_t data); 99 | void lcdWriteWord(TFT_t *dev, uint16_t data); 100 | void lcdWriteDataWord(TFT_t *dev, uint16_t data); 101 | void lcdWriteDataWord_16bit(TFT_t *dev, uint16_t data); 102 | void lcdWriteDataByte(TFT_t *dev, uint8_t data); 103 | void lcdWriteCommandWord(TFT_t *dev, uint16_t command); 104 | void lcdWriteCommandByte(TFT_t *dev, uint8_t command); 105 | void lcdWriteRegisterWord(TFT_t *dev, uint16_t addr, uint16_t data); 106 | void lcdWriteRegisterByte(TFT_t *dev, uint8_t addr, uint16_t data); 107 | void lcdInterface(TFT_t *dev, char* ppath); 108 | void lcdInit(TFT_t *dev, uint16_t model, int width, int height, int offsetx, int offsety); 109 | void lcdReset(TFT_t *dev); 110 | void lcdInitTable(TFT_t *dev, const void *table, int16_t size); 111 | void lcdInitTable16(TFT_t *dev, const void *table, int16_t size); 112 | void lcdDrawPixel(TFT_t *dev, uint16_t x, uint16_t y, uint16_t color); 113 | void lcdDrawFillRect(TFT_t * dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 114 | void lcdDisplayOff(TFT_t *dev); 115 | void lcdDisplayOn(TFT_t *dev); 116 | void lcdInversionOn(TFT_t *dev); 117 | void lcdInversionOff(TFT_t *dev); 118 | void lcdFillScreen(TFT_t *dev, uint16_t color); 119 | void lcdFadeout(TFT_t *dev, int direction, uint16_t color); 120 | void lcdDrawLine(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 121 | void lcdDrawRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 122 | void lcdDrawCircle(TFT_t *dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 123 | void lcdDrawFillCircle(TFT_t *dev, uint16_t x0, uint16_t y0, uint16_t r, uint16_t color); 124 | void lcdDrawRoundRect(TFT_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color); 125 | void lcdDrawArrow(TFT_t *dev, uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t w,uint16_t color); 126 | void lcdDrawFillArrow(TFT_t *dev, uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t w,uint16_t color); 127 | uint16_t rgb565_conv(uint16_t r,uint16_t g,uint16_t b); 128 | int lcdDrawSJISChar(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,uint16_t sjis,uint16_t color); 129 | int lcdDrawUTF8Char(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,uint8_t *utf8,uint16_t color); 130 | int lcdDrawUTF8String(TFT_t *dev, FontxFile *fx, uint16_t x,uint16_t y,unsigned char *utfs,uint16_t color); 131 | void lcdSetFontDirection(TFT_t *dev, uint16_t dir); 132 | void lcdSetFontFill(TFT_t *dev, uint16_t color); 133 | void lcdUnsetFontFill(TFT_t *dev); 134 | void lcdSetFontUnderLine(TFT_t *dev, uint16_t color); 135 | void lcdUnsetFontUnderLine(TFT_t *dev); 136 | int ReadPinConfig(GPIO_t *pin, char *path); 137 | 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /tjpgd2/decode_jpeg.c: -------------------------------------------------------------------------------- 1 | /* 2 | jpeg decoder. 3 | 4 | This example code is in the Public Domain (or CC0 licensed, at your option.) 5 | 6 | Unless required by applicable law or agreed to in writing, this 7 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | CONDITIONS OF ANY KIND, either express or implied. 9 | */ 10 | 11 | 12 | /* 13 | The image used for the effect on the LCD in the SPI master example is stored in flash 14 | as a jpeg file. This file contains the decode_image routine, which uses the tiny JPEG 15 | decoder library in ROM to decode this JPEG into a format that can be sent to the display. 16 | 17 | Keep in mind that the decoder library cannot handle progressive files (will give 18 | ``Image decoder: jd_prepare failed (8)`` as an error) so make sure to save in the correct 19 | format if you want to use a different image file. 20 | */ 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include "decode_jpeg.h" 27 | #include "tjpgd.h" 28 | 29 | #define _DEBUG_ 0 30 | 31 | //Data that is passed from the decoder function to the infunc/outfunc functions. 32 | typedef struct { 33 | pixel_s **outData; // Array of IMAGE_H pointers to arrays of 16-bit pixel values 34 | int screenWidth; // Width of the screen 35 | int screenHeight; // Height of the screen 36 | FILE* fp; // File pointer of jpeg file 37 | } JpegDev; 38 | 39 | 40 | //Input function for jpeg decoder. Just returns bytes from the inData field of the JpegDev structure. 41 | static size_t infunc(JDEC *decoder, uint8_t *buf, size_t len) { 42 | JpegDev *jd = (JpegDev *) decoder->device; 43 | if (_DEBUG_) printf("infunc len=%d fp=%p\n", len, jd->fp); 44 | int rlen; 45 | if (buf != NULL) { /* Read nd bytes from the input strem */ 46 | rlen = fread(buf, 1, len, jd->fp); 47 | if (_DEBUG_) printf("rlen=%d\n",rlen); 48 | } else { /* Skip nd bytes on the input stream */ 49 | if (_DEBUG_) printf("buff is NULL\n"); 50 | fseek(jd->fp, len, SEEK_CUR); 51 | rlen = len; 52 | } 53 | return rlen; 54 | } 55 | 56 | //Output function. Re-encodes the RGB888 data from the decoder as big-endian RGB565 and 57 | //stores it in the outData array of the JpegDev structure. 58 | static int outfunc(JDEC *decoder, void *bitmap, JRECT *rect) { 59 | JpegDev *jd = (JpegDev *) decoder->device; 60 | uint8_t *in = (uint8_t *) bitmap; 61 | if (_DEBUG_) printf("rect->top=%d rect->bottom=%d\n", rect->top, rect->bottom); 62 | if (_DEBUG_) printf("rect->left=%d rect->right=%d\n", rect->left, rect->right); 63 | if (_DEBUG_) printf("jd->screenWidth=%d jd->screenHeight=%d\n", jd->screenWidth, jd->screenHeight); 64 | 65 | for (int y = rect->top; y <= rect->bottom; y++) { 66 | for (int x = rect->left; x <= rect->right; x++) { 67 | 68 | if (y < jd->screenHeight && x < jd->screenWidth) { 69 | jd->outData[y][x].red = in[0]; 70 | jd->outData[y][x].green = in[1]; 71 | jd->outData[y][x].blue = in[2]; 72 | } 73 | 74 | in += 3; 75 | } 76 | } 77 | return 1; 78 | } 79 | 80 | // Specifies scaling factor N for output. The output image is descaled to 1 / 2 ^ N (N = 0 to 3). 81 | // When scaling feature is disabled (JD_USE_SCALE == 0), it must be 0. 82 | uint8_t getScale(uint16_t screenWidth, uint16_t screenHeight, uint16_t imageWidth, uint16_t imageHeight) { 83 | if (screenWidth >= imageWidth && screenHeight >= imageHeight) return 0; 84 | 85 | if (_DEBUG_) printf("screenWidth=%d imageWidth=%d\n", screenWidth, imageWidth); 86 | if (_DEBUG_) printf("screenHeight=%d imageHeight=%d\n", screenHeight, imageHeight); 87 | double scaleWidth = (double)imageWidth / (double)screenWidth; 88 | double scaleHeight = (double)imageHeight / (double)screenHeight; 89 | if (_DEBUG_) printf("scaleWidth=%f scaleHeight=%f\n", scaleWidth, scaleHeight); 90 | double scale = scaleWidth; 91 | if (scaleWidth < scaleHeight) scale = scaleHeight; 92 | if (_DEBUG_) printf("scale=%f\n", scale); 93 | //if (scale < 2.0) return 1; 94 | //if (scale < 4.0) return 2; 95 | if (scale <= 2.0) return 1; 96 | if (scale <= 4.0) return 2; 97 | return 3; 98 | 99 | } 100 | 101 | //Size of the work space for the jpeg decoder. 102 | #define WORKSZ 3100 103 | 104 | //Decode the embedded image into pixel lines that can be used with the rest of the logic. 105 | uint16_t decode_image(pixel_s ***pixels, char * file, uint16_t width, uint16_t height, uint16_t * imageWidth, uint16_t * imageHeight) { 106 | char *work = NULL; 107 | int r; 108 | JDEC decoder; 109 | JpegDev jd; 110 | *pixels = NULL; 111 | uint16_t ret = ESP_OK; 112 | 113 | 114 | //Alocate pixel memory. Each line is an array of IMAGE_W 16-bit pixels; the `*pixels` array itself contains pointers to these lines. 115 | *pixels = calloc(height, sizeof(pixel_s *)); 116 | if (*pixels == NULL) { 117 | printf("Error allocating memory for lines\n"); 118 | ret = ESP_ERR_NO_MEM; 119 | goto err; 120 | } 121 | for (int i = 0; i < height; i++) { 122 | (*pixels)[i] = malloc(width * sizeof(pixel_s)); 123 | if ((*pixels)[i] == NULL) { 124 | printf("Error allocating memory for line %d\n", i); 125 | ret = ESP_ERR_NO_MEM; 126 | goto err; 127 | } 128 | } 129 | 130 | //Allocate the work space for the jpeg decoder. 131 | work = calloc(WORKSZ, 1); 132 | if (work == NULL) { 133 | printf("Cannot allocate workspace\n"); 134 | ret = ESP_ERR_NO_MEM; 135 | goto err; 136 | } 137 | 138 | 139 | //Populate fields of the JpegDev struct. 140 | jd.outData = *pixels; 141 | jd.screenWidth = width; 142 | jd.screenHeight = height; 143 | jd.fp = fopen(file, "rb"); 144 | if (jd.fp == NULL) { 145 | printf("Image file not found [%s]\n", file); 146 | ret = ESP_ERR_NOT_FOUND; 147 | goto err; 148 | } 149 | if (_DEBUG_) printf("jd.fp=%p\n", jd.fp); 150 | 151 | //Prepare and decode the jpeg. 152 | r = jd_prepare(&decoder, infunc, work, WORKSZ, (void *) &jd); 153 | if (r != JDR_OK) { 154 | printf("Image decoder: jd_prepare failed (%d)\n", r); 155 | ret = ESP_ERR_NOT_SUPPORTED; 156 | goto err; 157 | } 158 | if (_DEBUG_) printf("decoder.width=%d decoder.height=%d\n", decoder.width, decoder.height); 159 | 160 | //Calculate Scaling factor 161 | uint8_t scale = getScale(width, height, decoder.width, decoder.height); 162 | if (_DEBUG_) printf("scale=%d\n", scale); 163 | 164 | //Calculate image size 165 | double factor = 1.0; 166 | if (scale == 1) factor = 0.5; 167 | if (scale == 2) factor = 0.25; 168 | if (scale == 3) factor = 0.125; 169 | if (_DEBUG_) printf("factor=%f\n",factor); 170 | *imageWidth = (double)decoder.width * factor; 171 | *imageHeight = (double)decoder.height * factor; 172 | if (_DEBUG_) printf("imageWidth=%d imageHeight=%d\n", *imageWidth, *imageHeight); 173 | 174 | 175 | r = jd_decomp(&decoder, outfunc, scale); 176 | if (r != JDR_OK) { 177 | printf("Image decoder: jd_decode failed (%d)\n", r); 178 | ret = ESP_ERR_NOT_SUPPORTED; 179 | goto err; 180 | } 181 | 182 | //All done! Free the work area (as we don't need it anymore) and return victoriously. 183 | free(work); 184 | fclose(jd.fp); 185 | return ret; 186 | err: 187 | //Something went wrong! Exit cleanly, de-allocating everything we allocated. 188 | if (*pixels != NULL) { 189 | for (int i = 0; i < height; i++) { 190 | free((*pixels)[i]); 191 | } 192 | free(*pixels); 193 | } 194 | free(work); 195 | return ret; 196 | } 197 | 198 | 199 | uint16_t release_image(pixel_s ***pixels, uint16_t width, uint16_t height) { 200 | if (*pixels != NULL) { 201 | for (int i = 0; i < height; i++) { 202 | free((*pixels)[i]); 203 | } 204 | free(*pixels); 205 | } 206 | return ESP_OK; 207 | } 208 | 209 | -------------------------------------------------------------------------------- /tjpgd2/decode_jpeg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define ESP_OK 0 5 | #define ESP_FAIL -1 6 | #define ESP_ERR_NO_MEM 0x101 7 | #define ESP_ERR_INVALID_ARG 0x102 8 | #define ESP_ERR_INVALID_STATE 0x103 9 | #define ESP_ERR_INVALID_SIZE 0x104 10 | #define ESP_ERR_NOT_FOUND 0x105 11 | #define ESP_ERR_NOT_SUPPORTED 0x106 12 | #define ESP_ERR_TIMEOUT 0x107 13 | #define ESP_ERR_INVALID_RESPONSE 0x108 14 | #define ESP_ERR_INVALID_CRC 0x109 15 | #define ESP_ERR_INVALID_VERSION 0x10A 16 | #define ESP_ERR_INVALID_MAC 0x10B 17 | #define ESP_ERR_WIFI_BASE 0x3000 18 | #define ESP_ERR_MESH_BASE 0x4000 19 | 20 | typedef struct __attribute__((__packed__)) { 21 | uint8_t red; 22 | uint8_t green; 23 | uint8_t blue; 24 | }pixel_s; 25 | 26 | 27 | /** 28 | * @brief Decode the jpeg ``image.jpg`` embedded into the program file into pixel data. 29 | * 30 | * @param pixels A pointer to a pointer for an array of rows, which themselves are an array of pixels. 31 | * Effectively, you can get the pixel data by doing ``decode_image(&myPixels); pixelval=myPixels[ypos][xpos];`` 32 | * @return - ESP_ERR_NOT_SUPPORTED if image is malformed or a progressive jpeg file 33 | * - ESP_ERR_NO_MEM if out of memory 34 | * - ESP_OK on succesful decode 35 | */ 36 | 37 | uint16_t decode_image(pixel_s ***pixels, char * file, uint16_t width, uint16_t height, uint16_t * imageWidth, uint16_t * imageHeight); 38 | 39 | /** 40 | * @brief Release image memory. 41 | * 42 | */ 43 | 44 | uint16_t release_image(pixel_s ***pixels, uint16_t width, uint16_t height); 45 | 46 | -------------------------------------------------------------------------------- /tjpgd2/tjpgd.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------/ 2 | / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2021 3 | /----------------------------------------------------------------------------*/ 4 | #ifndef DEF_TJPGDEC 5 | #define DEF_TJPGDEC 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include "tjpgdcnf.h" 12 | #include 13 | 14 | #if defined(_WIN32) /* Main development platform */ 15 | typedef unsigned char uint8_t; 16 | typedef unsigned short uint16_t; 17 | typedef short int16_t; 18 | typedef unsigned long uint32_t; 19 | typedef long int32_t; 20 | #else /* Embedded platform */ 21 | #include 22 | #endif 23 | 24 | /* Error code */ 25 | typedef enum { 26 | JDR_OK = 0, /* 0: Succeeded */ 27 | JDR_INTR, /* 1: Interrupted by output function */ 28 | JDR_INP, /* 2: Device error or wrong termination of input stream */ 29 | JDR_MEM1, /* 3: Insufficient memory pool for the image */ 30 | JDR_MEM2, /* 4: Insufficient stream input buffer */ 31 | JDR_PAR, /* 5: Parameter error */ 32 | JDR_FMT1, /* 6: Data format error (may be damaged data) */ 33 | JDR_FMT2, /* 7: Right format but not supported */ 34 | JDR_FMT3 /* 8: Not supported JPEG standard */ 35 | } JRESULT; 36 | 37 | 38 | 39 | /* Rectangular region in the output image */ 40 | typedef struct { 41 | uint16_t left; /* Left end */ 42 | uint16_t right; /* Right end */ 43 | uint16_t top; /* Top end */ 44 | uint16_t bottom; /* Bottom end */ 45 | } JRECT; 46 | 47 | 48 | 49 | /* Decompressor object structure */ 50 | typedef struct JDEC JDEC; 51 | struct JDEC { 52 | size_t dctr; /* Number of bytes available in the input buffer */ 53 | uint8_t* dptr; /* Current data read ptr */ 54 | uint8_t* inbuf; /* Bit stream input buffer */ 55 | uint8_t dmsk; /* Current bit in the current read byte */ 56 | uint8_t scale; /* Output scaling ratio */ 57 | uint8_t msx, msy; /* MCU size in unit of block (width, height) */ 58 | uint8_t qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */ 59 | uint8_t ncomp; /* Number of color components 1:grayscale, 3:color */ 60 | int16_t dcv[3]; /* Previous DC element of each component */ 61 | uint16_t nrst; /* Restart inverval */ 62 | uint16_t width, height; /* Size of the input image (pixel) */ 63 | uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ 64 | uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */ 65 | uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ 66 | int32_t* qttbl[4]; /* Dequantizer tables [id] */ 67 | void* workbuf; /* Working buffer for IDCT and RGB output */ 68 | uint8_t* mcubuf; /* Working buffer for the MCU */ 69 | void* pool; /* Pointer to available memory pool */ 70 | size_t sz_pool; /* Size of momory pool (bytes available) */ 71 | size_t (*infunc)(JDEC*, uint8_t*, size_t); /* Pointer to jpeg stream input function */ 72 | void* device; /* Pointer to I/O device identifiler for the session */ 73 | }; 74 | 75 | 76 | 77 | /* TJpgDec API functions */ 78 | JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev); 79 | JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale); 80 | 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /* _TJPGDEC */ 87 | -------------------------------------------------------------------------------- /tjpgd2/tjpgdcnf.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------*/ 2 | /* TJpgDec System Configurations */ 3 | /*----------------------------------------------*/ 4 | 5 | /* Size of stream input buffer */ 6 | #define JD_SZBUF 512 7 | 8 | /* Output pixel format 0:RGB888 (3-uint8_t/pix), 1:RGB565 (1-uint16_t/pix), 2:Grayscale (1-uint8_t/pix) */ 9 | #define JD_FORMAT 0 10 | 11 | /* Enable output descaling feature */ 12 | #define JD_USE_SCALE 1 13 | 14 | /* Use table conversion for saturation (might be a bit faster on 8-bit MCUs but increases 1 KB of code size) */ 15 | #define JD_TBLCLIP 0 16 | 17 | -------------------------------------------------------------------------------- /touch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "tft_lib.h" 10 | #include "xpt2046.h" 11 | #include "driver/ili9341.h" 12 | 13 | #define SPI_CHANNEL 0 // /dev/spidev0.0 14 | //#define SPI_CHANNEL 1 // /dev/spidev0.1 15 | #define GPIO_PEN 6 16 | #define _DEBUG_ 0 17 | 18 | FontxFile fxG32[2]; 19 | FontxFile fxM32[2]; 20 | FontxFile fxG24[2]; 21 | FontxFile fxM24[2]; 22 | FontxFile fxG16[2]; 23 | FontxFile fxM16[2]; 24 | 25 | TouchInfo tinfo; 26 | 27 | int main(int argc, char **argv){ 28 | int i,j; 29 | uint16_t xpos,ypos; 30 | uint16_t color; 31 | uint8_t utf[64]; 32 | 33 | int XMAX,YMAX; 34 | int XMAX2,YMAX2; 35 | 36 | if (wiringPiSPISetup(SPI_CHANNEL, 500000) < 0) { 37 | printf("wiringPiSPISetup failed:\n"); 38 | return -1; 39 | } 40 | 41 | if (wiringPiSetup() < 0) { 42 | printf("wiringPiSetup failed:\n"); 43 | return -1; 44 | } 45 | pinMode(GPIO_PEN,INPUT); 46 | 47 | 48 | char base[128]; 49 | strcpy(base, argv[0]); 50 | for(i=strlen(base);i>0;i--) { 51 | if (base[i-1] == '/') { 52 | base[i] = 0; 53 | break; 54 | } 55 | } 56 | //printf("base=%s\n",base); 57 | 58 | // You can change font file 59 | // 32Dot Gothic 60 | char G32[2][128]; 61 | strcpy(G32[0],base); 62 | strcpy(G32[1],base); 63 | strcat(G32[0],"fontx/ILGH32XB.FNT"); 64 | strcat(G32[1],"fontx/ILGZ32XB.FNT"); 65 | //printf("%s\n",G32[0]); 66 | //printf("%s\n",G32[1]); 67 | Fontx_init(fxG32,G32[0],G32[1]); 68 | 69 | // 32Dot Mincho 70 | char M32[2][128]; 71 | strcpy(M32[0],base); 72 | strcpy(M32[1],base); 73 | strcat(M32[0],"fontx/ILMH32XF.FNT"); 74 | strcat(M32[1],"fontx/ILMZ32XF.FNT"); 75 | //printf("%s\n",M32[0]); 76 | //printf("%s\n",M32[1]); 77 | Fontx_init(fxM32,M32[0],M32[1]); 78 | 79 | // 24Dot Gothic 80 | char G24[2][128]; 81 | strcpy(G24[0],base); 82 | strcpy(G24[1],base); 83 | strcat(G24[0],"fontx/ILGH24XB.FNT"); 84 | strcat(G24[1],"fontx/ILGZ24XB.FNT"); 85 | //printf("%s\n",G24[0]); 86 | //printf("%s\n",G24[1]); 87 | Fontx_init(fxG24,G24[0],G24[1]); 88 | 89 | // 24Dot Mincho 90 | char M24[2][128]; 91 | strcpy(M24[0],base); 92 | strcpy(M24[1],base); 93 | strcat(M24[0],"fontx/ILMH24XF.FNT"); 94 | strcat(M24[1],"fontx/ILMZ24XF.FNT"); 95 | //printf("%s\n",M24[0]); 96 | //printf("%s\n",M24[1]); 97 | Fontx_init(fxM24,M24[0],M24[1]); 98 | 99 | #if 0 100 | // 32Dot Gothic 101 | Fontx_init(fxG32,"./fontx/ILGH32XB.FNT","./fontx/ILGZ32XB.FNT"); 102 | // 32Dot Mincho 103 | Fontx_init(fxM32,"./fontx/ILMH32XF.FNT","./fontx/ILMZ32XF.FNT"); 104 | // 24Dot Gothic 105 | Fontx_init(fxG24,"./fontx/ILGH24XB.FNT","./fontx/ILGZ24XB.FNT"); 106 | // 24Dot Mincho 107 | Fontx_init(fxM24,"./fontx/ILMH24XF.FNT","./fontx/ILMZ24XF.FNT"); 108 | // 16Dot Gothic 109 | Fontx_init(fxG16,"./fontx/ILGH16XB.FNT","./fontx/ILGZ16XB.FNT"); 110 | // 16Dot Mincho 111 | Fontx_init(fxM16,"./fontx/ILMH16XB.FNT","./fontx/ILMZ16XF.FNT"); 112 | #endif 113 | 114 | char ppath[128]; 115 | strcpy(ppath,base); 116 | strcat(ppath,"pin.conf"); 117 | //printf("ppath=%s\n",ppath); 118 | struct stat buffer; 119 | if (stat(ppath, &buffer) != 0) { 120 | printf("pin.conf [%s] not found\n",ppath); 121 | return 1; 122 | } 123 | 124 | xptInit(&tinfo); 125 | 126 | TFT_t dev; 127 | lcdInterface(&dev, ppath); 128 | lcdReset(&dev); 129 | XMAX = 240; 130 | YMAX = 320; 131 | ili9341_lcdInit(&dev, XMAX, YMAX, 0, 0); 132 | 133 | XMAX2 = XMAX - 1; 134 | YMAX2 = YMAX - 1; 135 | 136 | //drawString 137 | lcdFillScreen(&dev, WHITE); 138 | lcdSetFontDirection(&dev, DIRECTION90); 139 | xpos = 180; 140 | ypos = YMAX2-(32*1); 141 | for (i=0;i<5;i++) { 142 | lcdDrawRect(&dev, xpos-8, ypos+16, xpos+40, ypos-32, BLACK); 143 | xptSetPoint(&tinfo, xpos-8 ,ypos+16 ,xpos+40, ypos-32, i); 144 | xptDump(&tinfo); 145 | color = BLACK; 146 | //strcpy(utf,"1"); 147 | utf[0] = i + 48; 148 | utf[1] = 0; 149 | ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color); 150 | ypos = ypos - 32; 151 | } 152 | 153 | xpos = 120; 154 | ypos = YMAX2-(32*1); 155 | for (i=0;i<5;i++) { 156 | lcdDrawRect(&dev, xpos-8, ypos+16, xpos+40, ypos-32, BLACK); 157 | xptSetPoint(&tinfo, xpos-8 ,ypos+16 ,xpos+40, ypos-32, i+5); 158 | xptDump(&tinfo); 159 | color = BLACK; 160 | //strcpy(utf,"1"); 161 | utf[0] = i + 53; 162 | utf[1] = 0; 163 | ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color); 164 | ypos = ypos - 32; 165 | } 166 | 167 | 168 | // read xpt2046 169 | int x, y; 170 | int pen_irq; 171 | int id; 172 | 173 | xpos = 40; 174 | ypos = YMAX2-(32*1); 175 | color = RED; 176 | for (;;) { 177 | usleep(10000); /* do it anyway ; settle time when pen goes up */ 178 | pen_irq = digitalRead(GPIO_PEN); 179 | if (pen_irq == LOW) { /* PenIRQ is LOW : touch! pen is down */ 180 | id = xptGetPoint(SPI_CHANNEL, &tinfo); 181 | if (id != -1) { 182 | if(_DEBUG_)printf("id=%d\n",id); 183 | ili9341_lcdInit(&dev, XMAX, YMAX, 0, 0); 184 | lcdSetFontDirection(&dev, DIRECTION90); 185 | utf[0] = id + 48; 186 | ypos = lcdDrawUTF8String(&dev, fxG32, xpos, ypos, utf, color); 187 | } 188 | } 189 | } // end for 190 | 191 | } 192 | -------------------------------------------------------------------------------- /xpt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "xpt2046.h" 9 | 10 | #define SPI_CHANNEL 0 // /dev/spidev0.0 11 | //#define SPI_CHANNEL 1 // /dev/spidev0.1 12 | #define GPIO_PEN 6 13 | #define CALIBRATIO 0 14 | 15 | int main (int argc, char **argv){ 16 | int x, y; 17 | int xpos, ypos; 18 | int pen_irq; 19 | 20 | if (wiringPiSPISetup(SPI_CHANNEL, 500000) < 0) { 21 | printf("wiringPiSPISetup failed:\n"); 22 | return -1; 23 | } 24 | 25 | if (wiringPiSetup() < 0) { 26 | printf("wiringPiSetup failed:\n"); 27 | return -1; 28 | } 29 | pinMode(GPIO_PEN,INPUT); 30 | 31 | #if(CALIBRATIO) 32 | int xmin=99999; 33 | int xmax=0; 34 | int ymin=99999; 35 | int ymax=0; 36 | #endif 37 | 38 | for (;;) { 39 | usleep(10000); /* do it anyway ; settle time when pen goes up */ 40 | pen_irq = digitalRead(GPIO_PEN); 41 | if (pen_irq == LOW) { /* PenIRQ is LOW : touch! pen is down */ 42 | // Get physically position 43 | xptGetxy(SPI_CHANNEL, &x, &y); 44 | // Get scrren position 45 | xpos = xptScrren(x); 46 | ypos = yptScrren(y); 47 | printf("touch !! x=%5d(%3d) y=%5d(%3d)\n", x, xpos, y, ypos); 48 | 49 | #if(CALIBRATIO) 50 | if (xmin > x) xmin=x; 51 | if (xmax < x) xmax=x; 52 | if (ymin > y) ymin=y; 53 | if (ymax < y) ymax=y; 54 | printf("touch !! xmin=%5d xmax=%5d\n", xmin, xmax); 55 | printf("touch !! ymin=%5d ymax=%5d\n", ymin, ymax); 56 | #endif 57 | 58 | } else { /* pen is up */ 59 | 60 | } 61 | } // end for 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /xpt2046.c: -------------------------------------------------------------------------------- 1 | /* 2 | XPT2046 Touch Screen Controller Library for Raspberry 3 | 4 | Original is 5 | https://github.com/xofc/xpt2uinput 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "xpt2046.h" 16 | 17 | #define MAX_LEN 4 18 | 19 | #define START 0x80 20 | #define XPOS 0x50 21 | #define YPOS 0x10 22 | 23 | #define XMIN 2000.0 24 | #define XMAX 30000.0 25 | #define YMIN 3000.0 26 | #define YMAX 30000.0 27 | 28 | #define _DEBUG_ 0 29 | 30 | int xptGetit(int spiCh, int cmd){ 31 | char buf[MAX_LEN]; 32 | int ret; 33 | int i; 34 | 35 | memset(buf, 0, sizeof(buf)); 36 | buf[0] = cmd; 37 | // printf("wbuf=0x%02x\n",wbuf[0]); 38 | ret=wiringPiSPIDataRW (spiCh,buf,sizeof(buf)); 39 | // for(i=0;i 239) xpos = 239; 58 | return xpos; 59 | } 60 | 61 | int yptScrren(int yp) { 62 | float dx, dy; 63 | int xpos, ypos; 64 | 65 | dy = 320.0 / (YMAX - YMIN); 66 | ypos = (yp-YMIN) * dy; 67 | if (ypos < 0) ypos = 0; 68 | if (ypos > 319) ypos = 319; 69 | return ypos; 70 | } 71 | 72 | 73 | void xptInit(TouchInfo *hoge){ 74 | hoge->tpc = 0; 75 | hoge->tpx = MAXTP; 76 | hoge->lsec = 0; 77 | hoge->lusec = 0; 78 | } 79 | 80 | void xptDump(TouchInfo *hoge){ 81 | int i; 82 | if (_DEBUG_ == 0) return; 83 | printf("tpc=%d\n",hoge->tpc); 84 | printf("tpx=%d\n",hoge->tpx); 85 | for(i=0;itpc;i++) { 86 | printf("x1[%02d]=%d",i,hoge->tps[i].x1); 87 | printf(" x2[%02d]=%d",i,hoge->tps[i].x2); 88 | printf(" y1[%02d]=%d",i,hoge->tps[i].y1); 89 | printf(" y2[%02d]=%d",i,hoge->tps[i].y2); 90 | printf(" id[%02d]=%d\n",i,hoge->tps[i].id); 91 | } 92 | } 93 | 94 | void xptSetPoint(TouchInfo *hoge,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t id){ 95 | if (hoge->tpc == hoge->tpx) return; 96 | int index = hoge->tpc; 97 | hoge->tps[index].x1 = x1; 98 | hoge->tps[index].x2 = x2; 99 | hoge->tps[index].y1 = y2; 100 | hoge->tps[index].y2 = y1; 101 | hoge->tps[index].id = id; 102 | hoge->tpc++; 103 | } 104 | 105 | int xptGetPoint(int spiCh, TouchInfo *hoge) { 106 | int x, y; 107 | int xpos, ypos; 108 | int i; 109 | struct timeval myTime; 110 | struct tm *time_st; 111 | suseconds_t dt; 112 | 113 | // Get physically position 114 | xptGetxy(spiCh, &x, &y); 115 | if(_DEBUG_)printf("touch !! x=%5d y=%5d\n", x, y); 116 | gettimeofday(&myTime, NULL); 117 | time_st = localtime(&myTime.tv_sec); 118 | if (myTime.tv_sec == hoge->lsec) { 119 | dt = myTime.tv_usec - hoge->lusec; 120 | if(_DEBUG_)printf("dt=%06d\n",dt); 121 | if (dt < DTMAX) return -1; 122 | } 123 | 124 | // Get scrren position 125 | xpos = xptScrren(x); 126 | ypos = yptScrren(y); 127 | if(_DEBUG_)printf("touch !! xpos=%5d ypos=%5d\n", xpos, ypos); 128 | 129 | for(i=0;itpc;i++) { 130 | if(_DEBUG_) { 131 | printf("x1[%02d]=%d",i,hoge->tps[i].x1); 132 | printf(" x2[%02d]=%d",i,hoge->tps[i].x2); 133 | printf(" y1[%02d]=%d",i,hoge->tps[i].y1); 134 | printf(" y2[%02d]=%d",i,hoge->tps[i].y2); 135 | printf(" id[%02d]=%d\n",i,hoge->tps[i].id); 136 | } 137 | if (xpos > hoge->tps[i].x1 && xpos < hoge->tps[i].x2) { 138 | if (ypos > hoge->tps[i].y1 && ypos < hoge->tps[i].y2) { 139 | gettimeofday(&myTime, NULL); 140 | time_st = localtime(&myTime.tv_sec); 141 | if(_DEBUG_)printf("myTime.tv_sec=%06d tv_usec=%06d\n",myTime.tv_sec,myTime.tv_usec); 142 | hoge->lsec = myTime.tv_sec; 143 | hoge->lusec = myTime.tv_usec; 144 | if(_DEBUG_)printf("usec=%06d-%06d\n",hoge->lsec,hoge->lusec); 145 | return hoge->tps[i].id; 146 | } 147 | } 148 | } 149 | return -1; 150 | } 151 | -------------------------------------------------------------------------------- /xpt2046.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | uint32_t x1; 5 | uint32_t x2; 6 | uint32_t y1; 7 | uint32_t y2; 8 | uint32_t id; 9 | } TouchPoint; 10 | 11 | #define MAXTP 20 12 | 13 | typedef struct { 14 | uint16_t tpc; 15 | uint16_t tpx; 16 | time_t lsec; 17 | suseconds_t lusec; 18 | TouchPoint tps[MAXTP]; 19 | } TouchInfo; 20 | 21 | #define XRATE 133 22 | #define YRATE 94 23 | #define DTMAX 800000 // 800m sec 24 | 25 | int xptGetit(int spiCh, int cmd); 26 | void xptGetxy(int spiCh, int *xp, int *yp); 27 | int xptScrren(int xp); 28 | int yptScrren(int yp); 29 | void xptInit(TouchInfo *hoge); 30 | void xptDump(TouchInfo *hoge); 31 | void xptSetPoint(TouchInfo *hoge,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t id); 32 | int xptGetPoint(int spiCh, TouchInfo *hoge); 33 | --------------------------------------------------------------------------------