I noticed that the demo code that ships with the PIC32 mikroMMB does not include the GetPixel routine. I've spent some time trying to write one with no luck. I am starting to wonder if the display is "write-only". Has anyone else had any luck with a working GetPixel routine?
Thanks in advance;
Best Regards;
Peter Camilleri
mikroMMB GetPixel function
Re: mikroMMB GetPixel function
Hello,
Only problem here that it is not implemented in our TFT library.
I will add this request to libraries enhancement list, and it will be included in some of the coming
releases of compilers.
Best Regards
Two way communication is possible, you can read different (TFT) register values.I am starting to wonder if the display is "write-only".
Only problem here that it is not implemented in our TFT library.
I will add this request to libraries enhancement list, and it will be included in some of the coming
releases of compilers.
Best Regards
LibStock
http://www.libstock.com/
mikroSDK
https://www.mikroe.com/mikrosdk
mikroBUS
https://www.mikroe.com/mikrobus
http://www.libstock.com/
mikroSDK
https://www.mikroe.com/mikrosdk
mikroBUS
https://www.mikroe.com/mikrobus
Re: mikroMMB GetPixel function
What lcd board are you using? For hx8347-d getpixel code is simple.
-
- Posts: 5
- Joined: 02 Feb 2011 20:29
Re: mikroMMB GetPixel function
I am using the mikroMMB for PIC32 Board. I finally figured it out on my own.
There were two issues to overcome.
First the PMP and the LCD controllers both have pipelines that are transparent on write, but require dummy reads on read. So there are 2 dummy reads needed.
Secondly, the data format of read is not the same as that for writing. On write, data is packed in a 5:6:5 pixel in 16 bits. On read, pixel data is spread across 2 reads with a 6:2x:6:2x format. Really, two pixels are read in three reads.
To this end I have a working GetPixel routine and a GetSlice routine that grabs more data.
There were two issues to overcome.
First the PMP and the LCD controllers both have pipelines that are transparent on write, but require dummy reads on read. So there are 2 dummy reads needed.
Secondly, the data format of read is not the same as that for writing. On write, data is packed in a 5:6:5 pixel in 16 bits. On read, pixel data is spread across 2 reads with a 6:2x:6:2x format. Really, two pixels are read in three reads.
To this end I have a working GetPixel routine and a GetSlice routine that grabs more data.
Re: mikroMMB GetPixel function
Hi Peter,
could you post your getpixel and slice routines please ?
This way i don't have to reinvent everything frm scratch.
Thxs in advance !
Greetinges Francis
could you post your getpixel and slice routines please ?
This way i don't have to reinvent everything frm scratch.
Thxs in advance !
Greetinges Francis
Re: mikroMMB GetPixel function
no need of the routines anymore. I wrote them myself by now. Timing of PMP bus is critical ! Wait bits are needed.
Re: mikroMMB GetPixel function
see below for this function
Last edited by bisnouk on 06 Feb 2012 09:22, edited 1 time in total.
Regards,
Thierry - Avignon - France
Thierry - Avignon - France
Re: mikroMMB GetPixel function
Here is a valid function, I'm working (hard) and it's a success !
In first, I must declare PMP routine to have a good parallel port but why, i don't know.
Precondition :
GetPixel function :
In first, I must declare PMP routine to have a good parallel port but why, i don't know.
Code: Select all
void InitPMP(void)
{
PMMODE = 0;
PMAEN = 0;
PMCON = 0;
PMMODEbits.MODE = 2; // Master 2
PMMODEbits.WAITB = 0;
PMMODEbits.WAITM = 3;
PMMODEbits.WAITE = 0;
PMMODEbits.MODE16 = 1; // 16 bit mode
PMCONbits.CSF = 0;
PMCONbits.PTRDEN = 1;
PMCONbits.PTWREN = 1;
PMCONbits.PMPEN = 1;
}
Code: Select all
typedef unsigned short BYTE;
typedef unsigned int WORD;
/*********************************************************************
* IOS FOR THE DISPLAY CONTROLLER
*********************************************************************/
// Definitions for reset pin
#define RST_TRIS_BIT TRISC1_bit
#define RST_LAT_BIT LATC1_bit
// Definitions for RS pin
#define RS_TRIS_BIT TRISB15_bit
#define RS_LAT_BIT LATB15_bit
// Definitions for CS pin
#define CS_TRIS_BIT TRISF12_bit
#define CS_LAT_BIT LATF12_bit
// Definitions for Backlight power pin
#define BL_TRIS_BIT TRISD2_bit
#define BL_LAT_BIT LATD2_bit
#define BacklightOn() BL_LAT_BIT = 1
#define BacklightOff() BL_LAT_BIT = 0
/*********************************************************************
* Macros: RGB565CONVERT(red, green, blue)
* Overview: Converts HX8347 GRAM 12 bits (6:6:6) color into 5:6:5 RGB format.
* Input: Red, Green, Blue components in 6 bits color format.
* Output: 5 bits red, 6 bits green, 5 bits blue color.
* Side Effects: none
********************************************************************/
#define RGB565CONVERT(red, green, blue) (WORD) (((red >> 1) << 11) | (green << 5) | (blue >> 1));
/*********************************************************************
* Macros: PMPWaitBusy()
* Overview: Delays execution for PMP cycle time.
* Input: none
* Output: none
********************************************************************/
#define PMPWaitBusy() while(PMMODEbits.BUSY);
/*********************************************************************
* Macros: SetIndex(index)
* Overview: Writes index register.
* Input: index - Index register.
* Output: none
********************************************************************/
#define SetIndex(index) \
RS_LAT_BIT = 0; \
PMDIN = index; \
PMPWaitBusy();
/*********************************************************************
* Macros: WriteCommand(cmd)
* Overview: Writes command.
* Input: command.
* Output: none
********************************************************************/
#define WriteCommand(cmd) \
RS_LAT_BIT = 1; \
PMDIN = cmd; \
PMPWaitBusy();
/*********************************************************************
* Macros: WriteData(data)
* Overview: Writes data
* Input: data
* Output: none
********************************************************************/
#define WriteData(data) \
RS_LAT_BIT = 1; \
PMDIN = data; \
PMPWaitBusy();
/*********************************************************************
* Function : ReadData()
* Overview: Read data
* Input: none
* Output: WORD DATA
********************************************************************/
WORD ReadData(void){
WORD dat;
RS_LAT_BIT = 1;
dat = PMDIN; // start a read sequence
PMPWaitBusy(); // wait for read completion
dat = PMDIN;
return (dat);
}
/*********************************************************************
* Macros: SetAddress(x,y)
* Overview: Writes address pointer.
* Input: x - horizontal position
* y - vertical position
********************************************************************/
#define SetAddress(x, y) \
SetIndex(0x02); \
WriteCommand((WORD)(x>>8)); \
SetIndex(0x03); \
WriteCommand((WORD)(x&0x0FF)); \
SetIndex(0x06); \
WriteCommand((WORD)(y>>8)); \
SetIndex(0x07); \
WriteCommand((WORD)(y&0x0FF)); \
SetIndex(0x22);
/*********************************************************************
* Function: void SetReg(BYTE index, BYTE value)
* Input: index - register number
* value - value to be set
* Output: none
* Side Effects: none
* Overview: sets graphics controller register
********************************************************************/
void SetReg(BYTE index, BYTE value){
CS_LAT_BIT = 0;
SetIndex(index);
WriteCommand(value);
CS_LAT_BIT = 1;
}
Code: Select all
/*********************************************************************
* Function: WORD GetPixel(WORD x, WORD y)
* Input: x,y - pixel coordinates
* Output: WORD pixel Color in RGB565
********************************************************************/
WORD GetPixel(WORD x, WORD y){
WORD val;
BYTE r,g,b;
CS_LAT_BIT = 0;
SetAddress(x,y);
ReadData(); // Dummy Read for PMP read acces
ReadData(); // Dummy Read for TFT GRAM read acces
val = ReadData();
r = (BYTE)hi(val)>>2;
g = (BYTE)lo(val)>>2;
val = ReadData();
b = (BYTE)hi(val)>>2;
CS_LAT_BIT = 1;
return (WORD)RGB565CONVERT(r,g,b);
}
Regards,
Thierry - Avignon - France
Thierry - Avignon - France
Re: mikroMMB GetPixel function
holy ****... what a routine !
Mine is 20 lines long in all
Mine is 20 lines long in all
Re: mikroMMB GetPixel function
Yes, this code was the first and as Elektronika build-in functions are not public, I prefer write mine for debugging.
Now I use build-in functions for address TFT and the GetPixel function is shorter !
Now I use build-in functions for address TFT and the GetPixel function is shorter !
Regards,
Thierry - Avignon - France
Thierry - Avignon - France