Hi peini,
you've opened very good and useful topic. Your first idea:
For a black anti-aliased text on the display i would then do the following:
1) Select a light gray font color and the first font and draw my text.
2) Select a darker gray font color and the second font and draw the same text at the same location.
3) Select the black color and third font and draw the text at the same location.
would be nice but I found it very complicated, time consuming (of mine and of processor) and you can't set the size of font spaces (in a String), nad so on.
I also thought about the anti-aliasing - for mixing it with background color we need to read the colour data from display controller.
Then I found your posts. I've tried to implement the reading pixel too. Nevetheless I spent many many hours with rearranging your useful code and the reading is still bad.
I tested that at least 2 dummy reads are needed (first it reads the last command: 0x2E) and second is 0x0000 (in 16 bit mode). There is lack of information in the datasheet ILI9341. I don't know how it reads data especially in 16bit MCU mode compared to 8bit. I hope it sends valid 16 bits in one Read_Data() but I'm not sure if it reads all colours (5:6:5) because it read bad data as I wrote above.
I should mention I use PIC32MX460F512L and 3.2" display (with RTP) with ILI9341 controller. I use PMP 16bit interface in PIC32 (PMMODEbits.MODE16 = 1) and IM[3:0]=1000= 8080 MCU 16-bit bus interface II in ILI9341. I use my own PCB based on Mikromedia for PIC32 originally.
My code:
Code: Select all
unsigned int Read_Data ( void )
{
volatile unsigned int _data = 0;
TFT_RS = 1;
//TFT_RD = 0; // start of Read_Strobe
// asm nop;
_data = PMDIN;
PMPWaitBusy();
//TFT_RD = 1; // end of Read_Strobe
return _data;
}
void Write_Command( unsigned short cmd ) {
TFT_RS = 1;
PMDIN = cmd;
PMPWaitBusy();
//TFT_WR = 0; asm nop; TFT_WR = 1; // I didn't find any influence of this TFT_Write_Strobe()
}
unsigned int GetPx_ILI9341_16b( unsigned int x, unsigned int y )
{
volatile unsigned int color = 0;
TFT_CS = 0;
// Writing part - only for testing
/*TFT_Set_Address_ILI9340( x-1, y+2 );
TFT_RS = 1;
PMDIN = 0x00FF;
PMPWaitBusy();
PMDIN = 0x0;
PMPWaitBusy();
PMDIN = 0xF800;
PMPWaitBusy();
*/
//TFT_Set_Address_ILI9340( x, y ); //same commands as for ILI9341
//it uses TFT_Write_Strobe(), I don't know it is needed
//but TFT_Set_Index_Ptr(0x2C); =writing command is at the end
Set_Index(0x2A);
Write_Command(x>>8);
Write_Command(x);
Set_Index(0x2B);
Write_Command(y>>8);
Write_Command(y);
Set_Index( 0x2E ); // ILI9341_CMD_MEMORY_READ
Read_Data(); // Dummy read
Read_Data();
Read_Data(); // maybe
color = Read_Data(); // should contain one pixel 16bit (5:6:5) colour I think
/* peini's 8bit reading
color = ( Read_Data() & 0xF8 ) << 8;
color |= ( Read_Data() & 0xFC ) << 3;
color |= Read_Data() >> 3;
*/
TFT_CS = 1;
return color;
}
Important note: It reads different data (but also not right) if I set PMMODEbits.WAITM = 2 instead of 1. WAITB and WAITE don't have any influence probably (default is 0 in both).
"Writing part - only for testing" - It can write 3 pixels on the display (on x-1, y+2 position) perfectly
In ...events_code.c file I have this
Code: Select all
void SetColorBtnStr(unsigned int x, unsigned int y)
{
char *colorStr[7];
unsigned int color16b;
color16b = GetPx_ILI9341_16b(x, y);
color16b = GetPx_ILI9341_16b(x, y);
WordToHex(color16b, colorStr);
strcpy(BtnCol1Scr4_Caption, colorStr);
strcpy(colorStr, " ");
DrawButton(&BtnCol1Scr4);
//...
}
//Event handler
void BtnColScr4OnCl() {
SetColorBtnStr(3,3); // here (3,3) is background colour only
}
I have set background color (of 4th screen) to SettCalib_4.Color = 0x3172;
Unfortunately it reads hexadecimal number:
1. 0000 with 1 preceding dummy Read_Data() after Set_Index( 0x2E )
2. 302C with 2 preceding dummy Read_Data()
3. 9430 with 3 preceding dummy Read_Data()
4. 2C94 with 4 preceding dummy Read_Data()
5. 302C with 5 preceding dummy Read_Data()
...
and put it to the button BtnCol1Scr4.Caption (can be seen from code above). You can see the read values are bad.
Digits 3 in background colour code and read data relate to each other somehow maybe. It is strange for me.
Regards
Vitek