Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 13:02 20 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM2(+): ILI9341 rotated text

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8608
Posted: 01:46am 26 Nov 2015
Copy link to clipboard 
Print this post

One thing we lost with the way Geoff has implemented TFT suppport is the ability to change the screen orientation in a program and therefore the ability to display text rotated away from its normal orientation.

The code to demo scrolling included the ability to send setup commands to the ILI9341 controller so it was easy to modify this to change the screen orientation and using the hooks Geoff has put in the Micromite firmware to also let the firmware know the orientation has changed.




The attached code simply demonstrates how to use the "orientation" Cfunction that solves this. Note how the first call stores the original orientation. This is important if you are using touch as the touch input positioning will be incorrect when the original orientation is not set.

The code only works on the ILI9341 but has been tested on both MM2 and MM+.

The Cfunction code is also attached for reference


dim i%,original_orientation%
cls
original_orientation%=orientation(1) 'change to landscape but store original orientation
text MM.HRES\2,0,"landscape",C,,2,rgb(green)
i%=orientation(2)
text MM.HRES\2,0,"Portrait",C,,2,rgb(yellow)
i%=orientation(3)
text MM.HRES\2,0,"Rev. Landscape",C,,2,rgb(red)
i%=orientation(4)
text MM.HRES\2,0,"Rev. Portrait",C,,2,rgb(cyan)
i%=orientation(original_orientation%) 'restore the screen to how it was set up to match the touch calibration
end


CFunction orientation
00000000
8C820000 3C039D00 27BDFFD8 8C660090 2445FFFF AFBF0024 AFB30020 AFB2001C
AFB10018 AFB00014 2CA50004 10A000B0 80D10015 30450001 14A00065 8C650098
24060140 ACA60000 8C630094 240500F0 AC650000 3C039D00 8C630090 A0620015
8C820000 24030002 10430066 3C03BF81 24030003 104300A9 38420004 24120028
24030088 0062900A 3C03BF81 8C65F220 3C020661 7CA5D800 3444A053 50A40060
3C02BF81 8C63F220 2442A053 7C63D800 00621026 2413001C 2403002C 0062980A
3C02BF81 8C45F220 8C43F220 3C020580 3442A053 7CA5D800 00A22826 24040040
7C63D800 24421000 10620059 0085980A 3C109D00 8E030090 8E02001C 8064002C
0040F809 24050005 8E030090 2A730033 8E02001C 8064002D 3A730001 0040F809
24050005 12600058 3C02BF80 24030001 24040036 AC435A30 3C03BF80 AC445A20
8C625A10 30420080 1040FFFD 3C10BF80 3C029D00 8C430090 8C42001C 8064002C
24050006 8E035A20 0040F809 00000000 AE125A20 3C03BF80 8C625A10 30420080
1040FFFD 3C02BF80 8C425A20 3C029D00 8C430090 8C42001C 8064002D 0040F809
24050006 8FBF0024 02202021 00112FC3 00801021 00A01821 8FB30020 8FB2001C
8FB10018 8FB00014 03E00008 27BD0028 240600F0 ACA60000 8C630094 24050140
AC650000 3C039D00 8C630090 A0620015 8C820000 24030002 1443FF9E 24030003
3C03BF81 8C65F220 3C020661 7CA5D800 3444A053 14A4FFA3 24120048 3C02BF81
8C45F220 8C43F220 3C020580 3442A053 7CA5D800 00A22826 2413002C 24040040
7C63D800 24421000 1462FFA9 0085980A 3C109D00 8E030090 8E02001C 8064002C
0040F809 24050005 8E030090 8E02001C 8064002D 24130001 0040F809 24050005
1660FFAA 3C02BF80 24030001 24040036 AC435830 3C03BF80 AC445820 8C625810
30420080 1040FFFD 3C10BF80 3C029D00 8C430090 8C42001C 8064002C 24050006
8E035820 0040F809 00000000 AE125820 3C03BF80 8C625810 30420080 1040FFFD
3C02BF80 8C425820 1000FFA9 3C029D00 8FBF0024 00002021 00002821 00801021
00A01821 8FB30020 8FB2001C 8FB10018 8FB00014 03E00008 27BD0028 1000FF5A
241200E8
End CFunction





#define SPICON *(volatile unsigned int *)(0xbf805800)
#define SPISTAT *(volatile unsigned int *)(0xbf805810)
#define SPIBUF *(volatile unsigned int *)(0xbf805820)
#define SPIBRG *(volatile unsigned int *)(0xbf805830)
#define SPI2CON *(volatile unsigned int *)(0xbf805A00)
#define SPI2STAT *(volatile unsigned int *)(0xbf805A10)
#define SPI2BUF *(volatile unsigned int *)(0xbf805A20)
#define SPI2BRG *(volatile unsigned int *)(0xbf805A30)
#define SPIsend(a) {int j;SPIBUF=a; while((SPISTAT & 0x80)==0); j=SPIBUF;}
#define SPI2send(a) {int j;SPI2BUF=a; while((SPI2STAT & 0x80)==0); j=SPI2BUF;}
#define ILI9341_MEMCONTROL 0x36
#define ILI9341_MADCTL_MY 0x80
#define ILI9341_MADCTL_MX 0x40
#define ILI9341_MADCTL_MV 0x20
#define ILI9341_MADCTL_ML 0x10
#define ILI9341_MADCTL_RGB 0x00
#define ILI9341_MADCTL_BGR 0x08
#define ILI9341_MADCTL_MH 0x04

#define ILI9341_Portrait ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR
#define ILI9341_Portrait180 ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR
#define ILI9341_Landscape ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR
#define ILI9341_Landscape180 ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR
#define LANDSCAPE 1
#define PORTRAIT 2
#define RLANDSCAPE 3
#define RPORTRAIT 4

long long orientation(long *orient){
int was=Option->DISPLAY_ORIENTATION;
if(*orient>4 || *orient<1) return 0;
int spi=0,i;
int DisplayHRes = 320;
int DisplayVRes = 240;
if(*orient & 1) {
VRes=DisplayVRes;
HRes=DisplayHRes;
} else {
VRes=DisplayHRes;
HRes=DisplayVRes;
}
Option->DISPLAY_ORIENTATION=*orient;
if(*orient==LANDSCAPE)i=ILI9341_Landscape;
if(*orient==PORTRAIT)i=ILI9341_Portrait;
if(*orient==RLANDSCAPE)i=ILI9341_Landscape180;
if(*orient==RPORTRAIT)i=ILI9341_Portrait180;

if(NBRPINS>50)spi=1; //decide which SPI port to use
PinSetBit(Option->LCD_CD, LATCLR);
PinSetBit(Option->LCD_CS, LATCLR);
if(spi){
SPI2BRG=1;
SPI2send(ILI9341_MEMCONTROL);
} else {
SPIBRG=1;
SPIsend(ILI9341_MEMCONTROL);
}
PinSetBit(Option->LCD_CD, LATSET);
if(spi){
SPI2send(i);
} else {
SPIsend(i);
}
PinSetBit(Option->LCD_CS, LATSET);
return was;
}

Edited by matherp 2015-11-27
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1141
Posted: 03:09am 26 Nov 2015
Copy link to clipboard 
Print this post

As always: thanks a lot!

Michael
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024