for Arduino TFT LCD Screen 160x128

Dependents:   TFTLCDSCREEN Pong_ILI9163C

Fork of TFT_ILI9163C by _ peu605

Revision:
7:3dcb98ecf29f
Parent:
6:83f3605478ab
Child:
8:8dea70cf3ae8
--- a/TFT_ILI9163C.h	Wed Jan 28 13:35:18 2015 +0000
+++ b/TFT_ILI9163C.h	Sun Feb 01 15:36:04 2015 +0000
@@ -86,228 +86,30 @@
 #ifndef _TFT_ILI9163CLIB_H_
 #define _TFT_ILI9163CLIB_H_
 
-#include "mbed.h"
-
-#include <Adafruit_GFX.h>
-
-// from http://www.keil.com/forum/21105/bitband-macro-to-get-bit-number-from-bit-mask/
-#define MASK_TO_BITNUM(x)	(x&0x1?0:x&0x2?1:x&0x4?2:x&0x8?3:\
-	x&0x10?4:x&0x20?5:x&0x40?6:x&0x80?7:\
-	x&0x100?8:x&0x200?9:x&0x400?10:x&0x800?11:\
-	x&0x1000?12:x&0x2000?13:x&0x4000?14:x&0x8000?15:\
-	x&0x10000?16:x&0x20000?17:x&0x40000?18:x&0x80000?19:\
-	x&0x100000?20:x&0x200000?21:x&0x400000?22:x&0x800000?23:\
-	x&0x1000000?24:x&0x2000000?25:x&0x4000000?26:x&0x8000000?27:\
-	x&0x10000000?28:x&0x20000000?29:x&0x40000000?30:x&0x80000000?31:32)
-
-#if defined(TARGET_NUCLEO_F411RE) | defined(TARGET_NUCLEO_F302R8)
-	#define BITBAND_PERIPH(addr, bit) \
-	    (volatile uint32_t*)(PERIPH_BB_BASE+((uint32_t)addr-PERIPH_BASE)*32+(bit*4))
-	#define __NUCLEO_DMA__
+#if defined(TARGET_NUCLEO_F411RE)
+//    #define __F411RE_SOFT__
+//    #define __F411RE_DMA__
+    #define __F411RE_DMA_IT__
+#elif defined(TARGET_NUCLEO_F302R8)
+//    #define __F302R8_SOFT__
+    #define __F302R8_DMA__
+#else
+    #define __MBED_GENERIC__
 #endif
 
-//----- Define here witch display you own
-#define __144_RED_PCB__	//128x128
-//#define __22_RED_PCB__	//240x320
-//#define __144_AITENDO_PCB__	//128x128
-//---------------------------------------
 
-//ILI9163C versions------------------------
-#if defined(__144_RED_PCB__)
-/*
-This display:
-http://www.ebay.com/itm/Replace-Nokia-5110-LCD-1-44-Red-Serial-128X128-SPI-Color-TFT-LCD-Display-Module-/271422122271
-This particular display has a design error! The controller has 3 pins to configure to constrain
-the memory and resolution to a fixed dimension (in that case 128x128) but they leaved those pins
-configured for 128x160 so there was several pixel memory addressing problems.
-I solved by setup several parameters that dinamically fix the resolution as needit so below
-the parameters for this diplay. If you have a strain or a correct display (can happen with chinese)
-you can copy those parameters and create setup for different displays.
-*/
-	#define _TFTWIDTH		128		//the REAL W resolution of the TFT
-	#define _TFTHEIGHT		128		//the REAL H resolution of the TFT
-	#define _GRAMWIDTH		128
-	#define _GRAMHEIGH		160
-//	#define _GRAMSIZE		_GRAMWIDTH * _GRAMHEIGH	//*see note 1
-	#define _GRAMSIZE		_TFTWIDTH * _TFTHEIGHT	//this is enough to fill visible area
-	#define __COLORSPC		1	// 1:GBR - 0:RGB
-	#define __GAMMASET1		//uncomment for another gamma
-	#define __OFFSET		(_GRAMHEIGH - _TFTHEIGHT)	// 32 *see note 2
-	//Tested!
-
-#elif defined (__22_RED_PCB__)
-/*
-Like this one:
-http://www.ebay.it/itm/2-2-Serial-SPI-TFT-LCD-Display-Module-240x320-Chip-ILI9340C-PCB-Adapter-SD-Card-/281304733556
-Not tested!
-*/
-	#define _TFTWIDTH		240		//the REAL W resolution of the TFT
-	#define _TFTHEIGHT		320		//the REAL H resolution of the TFT
-	#define _GRAMWIDTH		240
-	#define _GRAMHEIGH		320
-	#define _GRAMSIZE		_GRAMWIDTH * _GRAMHEIGH
-	#define __COLORSPC		1	// 1:GBR - 0:RGB
-	#define __GAMMASET1		//uncomment for another gamma
-	#define __OFFSET		0
-	
-#elif defined(__144_AITENDO_PCB__)
-/*
-This display:
-http://www.aitendo.com/product/3857
-M014C9163SPI
-*/
-	#define _TFTWIDTH		128		//the REAL W resolution of the TFT
-	#define _TFTHEIGHT		128		//the REAL H resolution of the TFT
-	#define _GRAMWIDTH		128
-	#define _GRAMHEIGH		128
-	#define _GRAMSIZE		_GRAMWIDTH * _GRAMHEIGH
-	#define __COLORSPC		1	// 1:GBR - 0:RGB
-	#define __GAMMASET1		//uncomment for another gamma
-	#define __OFFSET		0
-	
+#if defined(__F411RE_SOFT__)
+    #include "TFT_ILI9163C_F411RE_SOFT.h"
+#elif defined(__F411RE_DMA__)
+    #include "TFT_ILI9163C_F411RE_DMA.h"
+#elif defined(__F411RE_DMA_IT__)
+    #include "TFT_ILI9163C_F411RE_DMA_IT.h"
+#elif defined(__F302R8_SOFT__)
+    #include "TFT_ILI9163C_F302R8_SOFT.h"
+#elif defined(__F302R8_DMA__)
+    #include "TFT_ILI9163C_F302R8_DMA.h"
 #else
-	#define _TFTWIDTH		128		//128
-	#define _TFTHEIGHT		160		//160
-	#define _GRAMWIDTH		128
-	#define _GRAMHEIGH		160
-	#define _GRAMSIZE		_GRAMWIDTH * _GRAMHEIGH
-	#define __COLORSPC		1	// 1:GBR - 0:RGB
-	#define __GAMMASET1
-	#define __OFFSET		0
+    #include "TFT_ILI9163C_GENERIC.h"
 #endif
-/*
-	Note 1: The __144_RED_PCB__ display has hardware addressing of 128 x 160
-	but the tft resolution it's 128 x 128 so the dram should be set correctly
-	
-	Note 2: This is the offset between image in RAM and TFT. In that case 160 - 128 = 32;
-*/
-//--------- Keep out hands from here!-------------
-
-#define	BLACK   		0x0000
-#define WHITE   		0xFFFF
-
-//ILI9163C registers-----------------------
-#define CMD_NOP     	0x00//Non operation
-#define CMD_SWRESET 	0x01//Soft Reset
-#define CMD_SLPIN   	0x10//Sleep ON
-#define CMD_SLPOUT  	0x11//Sleep OFF
-#define CMD_PTLON   	0x12//Partial Mode ON
-#define CMD_NORML   	0x13//Normal Display ON
-#define CMD_DINVOF  	0x20//Display Inversion OFF
-#define CMD_DINVON   	0x21//Display Inversion ON
-#define CMD_GAMMASET 	0x26//Gamma Set (0x01[1],0x02[2],0x04[3],0x08[4])
-#define CMD_DISPOFF 	0x28//Display OFF
-#define CMD_DISPON  	0x29//Display ON
-#define CMD_IDLEON  	0x39//Idle Mode ON
-#define CMD_IDLEOF  	0x38//Idle Mode OFF
-#define CMD_CLMADRS   	0x2A//Column Address Set
-#define CMD_PGEADRS   	0x2B//Page Address Set
-
-#define CMD_RAMWR   	0x2C//Memory Write
-#define CMD_RAMRD   	0x2E//Memory Read
-#define CMD_CLRSPACE   	0x2D//Color Space : 4K/65K/262K
-#define CMD_PARTAREA	0x30//Partial Area
-#define CMD_VSCLLDEF	0x33//Vertical Scroll Definition
-#define CMD_TEFXLON		0x34//Tearing Effect Line ON
-#define CMD_TEFXLOF		0x35//Tearing Effect Line OFF
-#define CMD_MADCTL  	0x36//Memory Access Control
-
-#define CMD_PIXFMT  	0x3A//Interface Pixel Format
-#define CMD_FRMCTR1 	0xB1//Frame Rate Control (In normal mode/Full colors)
-#define CMD_FRMCTR2 	0xB2//Frame Rate Control(In Idle mode/8-colors)
-#define CMD_FRMCTR3 	0xB3//Frame Rate Control(In Partial mode/full colors)
-#define CMD_DINVCTR		0xB4//Display Inversion Control
-#define CMD_RGBBLK		0xB5//RGB Interface Blanking Porch setting
-#define CMD_DFUNCTR 	0xB6//Display Fuction set 5
-#define CMD_SDRVDIR 	0xB7//Source Driver Direction Control
-#define CMD_GDRVDIR 	0xB8//Gate Driver Direction Control 
-
-#define CMD_PWCTR1  	0xC0//Power_Control1
-#define CMD_PWCTR2  	0xC1//Power_Control2
-#define CMD_PWCTR3  	0xC2//Power_Control3
-#define CMD_PWCTR4  	0xC3//Power_Control4
-#define CMD_PWCTR5  	0xC4//Power_Control5
-#define CMD_VCOMCTR1  	0xC5//VCOM_Control 1
-#define CMD_VCOMCTR2  	0xC6//VCOM_Control 2
-#define CMD_VCOMOFFS  	0xC7//VCOM Offset Control
-#define CMD_PGAMMAC		0xE0//Positive Gamma Correction Setting
-#define CMD_NGAMMAC		0xE1//Negative Gamma Correction Setting
-#define CMD_GAMRSEL		0xF2//GAM_R_SEL
-
-
-class TFT_ILI9163C : public Adafruit_GFX, public SPI {
-
- public:
-
-	TFT_ILI9163C(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc, PinName reset);
-	TFT_ILI9163C(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc);
-
-	void     	begin(void),
-				setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),//graphic Addressing
-				setCursor(int16_t x,int16_t y),//char addressing
-				pushColor(uint16_t color),
-				clearScreen(uint16_t color=0x0000),//same as fillScreen
-				setRotation(uint8_t r);
-
-	virtual void	fillScreen(uint16_t color=0x0000),
-					drawPixel(int16_t x, int16_t y, uint16_t color),
-					drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
-					drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
-					fillRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color),
-					invertDisplay(bool i);
-				
-  uint16_t 		Color565(uint8_t r, uint8_t g, uint8_t b);
-  void 			setBitrate(uint32_t n);	
-
- private:
-	uint8_t		_Mactrl_Data;//container for the memory access control data
-	uint8_t		_colorspaceData;
-	void 		colorSpace(uint8_t cspace);
-	void		writecommand(uint8_t c);
-	void		writedata(uint8_t d);
-	void		writedata16(uint16_t d);
-	void		writedata32(uint16_t d1, uint16_t d2);
-	void		writedata16burst(uint16_t d, int32_t len);
-	void 		chipInit();
-	bool 		boundaryCheck(int16_t x,int16_t y);
-	void 		homeAddress();
-	void		init(PinName cs, PinName dc);
-
-	DigitalOut _cs;
-	DigitalOut _dc;
-	PinName _resetPinName;
-	
-#if defined(TARGET_NUCLEO_F411RE) | defined(TARGET_NUCLEO_F302R8)
-	void		selectSlave();
-	void		deselectSlave();
-	void		setCommandMode();
-	void		setDataMode();
-	void		set8bitMode();
-	void		set16bitMode();
-	void		waitSpiFree();
-	void		waitBufferFree();
-	
-	GPIO_TypeDef *cs_port_reg;
-	volatile uint32_t cs_reg_mask;
-	GPIO_TypeDef *dc_port_reg;
-	volatile uint32_t dc_reg_mask;
-	
-	// peripheral bit-band addresses
-//	volatile uint32_t *bb_cs_port;
-//	volatile uint32_t *bb_dc_port;
-	volatile uint32_t *bb_spi_txe;
-	volatile uint32_t *bb_spi_bsy;
-	volatile uint32_t *bb_spi_spe;
-	#if defined(TARGET_NUCLEO_F411RE)
-		volatile uint32_t *bb_spi_dff;
-	#endif
-
-	#if defined(__NUCLEO_DMA__)
-		DMA_HandleTypeDef hdma;
-		volatile uint32_t *bb_spi_txdmaen;
-		volatile uint32_t *bb_dma_sxcr_en;
-	#endif
 
 #endif
-};
-#endif