Mouse Cursor on LCD

@ microt

What kind of board do you have? If I remember right @ hagster mentioned something that register addresses may vary from the LPCXXXX used on each board. That could be a reason, maybe check the manual for your board and the SoM used. Maybe there are differences.

Maybe the CRSR_CTRL has another base-address on your board. The line you posted



prevents the cursor to be displayed on the screen. 

All the register settings can be found in the first lines of code, starting with the first line where [b]MIRROR_XY[/b] is defined.

@ microt

Ok. I think your G120 has an LPC1788, that has different cursor-addresses.

Check out the picture. You could try and change the values. That way you could change the implementation for your board.

You can find the manual for the LPC1788 here:

http://www.nxp.com/documents/user_manual/UM10470.pdf

Update: I found a C sample here for your board:

http://docs.lpcware.com/lpcopen/v1.03/group___e_x_a_m_p_l_e_s___p_e_r_i_p_h__17_x_x40_x_x___l_c_d.html

@ AWSOMEDEVSIGNER, Thanks.
I think you are right. My board is a G120

Will try it and let you know

1 Like

I would try it, if I had a G120 on my own. But, unfortunately not. Let me know if I can help :slight_smile:

@ AWSOMEDEVSIGNER

You are correct, I have changed the code the cursor address is different for G120
I have cleaned up the code, I will post it here one I can verify it.

I have some issues with the board, which I am debugging.

BTW: How do make the cursor image.
Can I use some editor and upload it as a resource file?
rather than a array.

1 Like

@ microt

Looking forward seeing your code in action :slight_smile:

A cursor editor can be found here:

http://www.lpcware.com/content/forum/lpc-cursor-editor

Could not make it work with a resource file for now. Checking other editors as well. But most of the editors are bloated and donā€™t generate the required data.

It should be relatively easy to make HTML5 Canvas based online editor.

1 Like

@ Architect

Sounds good to me :slight_smile: Maybe take that source form the editor and convert that to JS.

It is a very simple format. Here is something for you to start with :wink:

http://jsbin.com/hexani

2 Likes

@ Architect

Great! Thank you :slight_smile: I will check that out.

@ AWSOMEDEVSIGNER.
Below is the code I am running.
BTW: I found 1 error in your for loop.

@ Architect.
Not sure why the tool you suggested creates a reverse cursor.


using System;
using Microsoft.SPOT;
using GHI.Glide;
using GHI.Glide.Display;
using GHI.Glide.UI;
using GHI.Glide.Geom;
using System.Threading;
using Microsoft.SPOT.Touch;

using GHI.Processor;
using System.IO;

using GHI.Pins;

using Microsoft.SPOT.Presentation.Media;    //Colors

using System.Collections;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Hardware;

namespace MouseCur
{
    public class Cursor
    {
        //const uint LCD_BASE_ADDR = 0xFFE10000;  //LPC24xx
        const uint LCD_BASE_ADDR = 0x20088000;    //LPC178x : G120
        
        static uint CRSR_CTRL = (LCD_BASE_ADDR + 0xC00);
        uint CRSR_CFG = (LCD_BASE_ADDR + 0xC04);
        uint CRSR_PAL0 = (LCD_BASE_ADDR + 0xC08);
        uint CRSR_PAL1 = (LCD_BASE_ADDR + 0xC0C);
        static uint CRSR_XY = (LCD_BASE_ADDR + 0xC10);

        uint CRSR_IMGBASE0 = (LCD_BASE_ADDR + 0x800);

        uint[] uicursor = new uint[]  {   
            0xaaaaaaaa,0xaaaaaaaa,    
            0xaaaaaaaa,0xa9aaaaaa,    
            0xaaaaaaaa,0xa5aaaaaa,    
            0xaaaaaaaa,0x95aaaaaa,    
            0xaaaaaaaa,0x55aaaaaa,    
            0xaaaaaaaa,0x55a9aaaa,      
            0xaaaaaaaa,0x55a5aaaa,    
            0xaaaaaaaa,0x5595aaaa,    
            0xaaaaaaaa,0x55a9aaaa,    
            0xaaaaaaaa,0x55a9aaaa,    
            0xaaaaaaaa,0x69a5aaaa,   
            0xaaaaaaaa,0xaaa5aaaa,    
            0xaaaaaaaa,0xaa95aaaa,   
            0xaaaaaaaa,0xaa96aaaa,   
            0xaaaaaaaa,0xaa56aaaa,   
            0xaaaaaaaa,0xaa9aaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa,   
            0xaaaaaaaa,0xaaaaaaaa  
          };

        static Int32 X = 0;
        static Int32 Y = 0;

        public void Init()
        {
            Register cursor0Reg = new Register(CRSR_IMGBASE0);

            SetPosition(0, 0);
            Register crsControl = new Register(CRSR_CTRL, 0x00); //enable the cursor's display
            
            for (Int32 i = 0; i < uicursor.Length; i++)
            {
              cursor0Reg.Value = uicursor[i];
              cursor0Reg.Address += 4;
            }
             
            Register crsCfg = new Register(CRSR_CFG, 0x02);   //synchronized to frame synchronization   
            Register pal1Reg = new Register(CRSR_PAL0, 0x0000FF00);
            Register pal2Reg = new Register(CRSR_PAL1, 0x00FF00FF);
        }

        public static void SetPosition(Int32 iX, Int32 iY)
        {
            X += iX;
            Y += iY;

            if (X < 0) X = 0;
            if (Y < 0) Y = 0;

            if (X > SystemMetrics.ScreenWidth)  X = SystemMetrics.ScreenWidth;
            if (Y > SystemMetrics.ScreenHeight) Y = SystemMetrics.ScreenHeight;

            Register crsXYRegister = new Register(CRSR_XY, (Y << 16) | (X << 0));
        }

        public static void ClickPosition(Int32 Button, Boolean Click)
        {
            Point touch = new Point(0, 0);

            touch.X = X;
            touch.Y = Y;
            Program.DB_Print("*******Point X:" + X + " Y:" + Y);

            if (Click)
            {
                GlideTouch.RaiseTouchDownEvent(null, new TouchEventArgs(touch));
            }
            else
            {
                GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touch));
            }
        }

        public static void cursor_On()
        {
            Register crsControl = new Register(CRSR_CTRL, 0x01); //enable the cursor's display
        }
    }
}

@ microt - It is something I put together very quickly. I havenā€™t tested it. Easy to fix. ;D

1 Like

@ Architect. Thank you

@ AWSOMEDEVSIGNER.
I see one problem.
The cursor position is not correct.

i.e.
If I position it at 0,0.
It has a X offset around 20 to 30 pixel

So in glide it clicks the wrong buttons

1 Like

@ microt - fixed the reverse issue

You can now also paste the cursor data from the c code (64 comma separated numeric values) into the text area and it will draw the cursor.

http://jsbin.com/hexani

1 Like

@ Architect

Thatā€™s awesome! Thank you so much! Will dive deeper into the low-level stuff now :slight_smile:

Update: Will give it a worthy place on Azure, and create a cursor collection :slight_smile:

You are welcome! :slight_smile:

@ microt - You are right, the first iteration should check if it is the first iteration. and then increment. That way the first line would be ok as well. Thanks :slight_smile:

@ Architect - AWESOME! Here you go:

1 Like

Are you planning on adding the code snippet to code share?

@ Gus - There is a code share here: https://www.ghielectronics.com/community/codeshare/entry/969

Created a while ago :slight_smile: