Mouse Cursor on LCD

@ hagster

Yeah, Section 6.5 starts with the Hardware Cursor :slight_smile: (thanks for that) Currently setting up my new development machine, only for NETMF.

Thanks again for your help :slight_smile:

Hey guys! I think I just got it for the FEZ Spider and the LPC24XX ! I found some C code on the internet and here is my first try (not very elegant, but works). I left the original comments in the code:




using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Processor;



namespace TestSpider2
{
    public partial class Program
    {
        //Mirroring on or off
        uint MIRROR_XY = 0;
        const uint LCD_BASE_ADDR = 0xFFE10000;

        uint CRSR_IMG = (LCD_BASE_ADDR + 0x800);
        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);
        uint CRSR_XY = (LCD_BASE_ADDR + 0xC10);
        uint CRSR_CLIP = (LCD_BASE_ADDR + 0xC14);
        uint CRSR_INTMSK = (LCD_BASE_ADDR + 0xC20);
        uint CRSR_INTCLR = (LCD_BASE_ADDR + 0xC24);
        uint CRSR_INTRAW = (LCD_BASE_ADDR + 0xC28);
        uint CRSR_INTSTAT = (LCD_BASE_ADDR + 0xC2C);

        //TE35
        uint U_LCD_XSIZE = 320;                                             /*  LCD x size                  */
        uint U_LCD_YSIZE = 240;                                             /*  LCD y size                  */


        uint CRSR_IMGBASE0 = 0xFFE10800;
        uint CRSR_IMGBASE1 = 0xFFE10900;
        uint CRSR_IMGBASE2 = 0xFFE10A00;
        uint CRSR_IMGBASE3 = 0xFFE10B00;

        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  
         };


        void cursor_Init()
        {
            int i;
            //unsigned int *puicursor = (unsigned int *)CRSR_IMGBASE0;   

            Register cursor0Reg = new Register(CRSR_IMGBASE0);

            cursor_SetPosition(0, 0);                                           /*  setcursor position at [0,0] */

            //CRSR_CTRL = 0x00;   

            Register crsControl = new Register(CRSR_CTRL, 0x00);  /*  the cursor is not display   */

            for (i = 0; i < 64; i++)
            {

                var next = cursor0Reg++;
                next.Value = uicursor[i];
                /*  read the cursor image       */
            }

            Register crsCfg = new Register(CRSR_CFG, (0x01 << 1) | (0x00 << 0));                                       /*  Cursor are synchronized to   
                                                                            the frame synchronization   
                                                                            pulse                       */


            //CRSR_CFG = (0x01 << 1) |                                           /*  Cursor are synchronized to   
            //                                                                the frame synchronization   
            //                                                                pulse                       */
            //             (0x00 << 0);                                            /*  select 32x32 pixel cursor   */

            Register pal1Reg = new Register(CRSR_PAL0, 0x00000000);
            Register pal2Reg = new Register(CRSR_PAL1, 0x00ffffff);

            //CRSR_PAL0 = 0x00000000;                                             /*  Palette 0 is black color    */
            //CRSR_PAL1 = 0x00ffffff;                                             /*  Palette 1 is white color    */

        }

        void cursor_SetPosition(uint ix, uint iy)
        {

            var crsClipRegister = new Register(CRSR_CLIP);
            var crsXYRegister = new Register(CRSR_XY);
            /*   
             *  if x coordinate is mirror, use underside way to set cursor's position  
             */
            if (MIRROR_XY == 1)
            {
                uint idx = 0;

                if (ix > 287)
                {

                    idx = ix - 287;
                    crsClipRegister.Value = (uint)((0 << 8) | (idx << 0));
                    //CRSR_CLIP = (uint)((0 << 8) | (idx << 0));
                    ix = 0;

                }
                else
                {

                    ix = U_LCD_XSIZE - ix - 1 - 32;

                }
            }


            /*   
     *  if x coordinate is normal, use underside way to set cursor's position  
     */
            crsXYRegister.Value = (uint)((iy << 16) | (ix << 0));
            //CRSR_XY = (uint)((iy << 16) | (ix << 0));
        }


        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            button.ButtonPressed += button_ButtonPressed;

            displayTE35.SimpleGraphics.Clear();

            cursor_Init();

            cursor_SetPosition(40,40);

            cursor_On();

            cursor_SetPosition(50,50);

        }

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

        void cursor_Off()
        {
            Register crsControl = new Register(CRSR_CTRL, 0x00);                                             /* enable the cursor's display  */
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            displayTE35.BacklightEnabled = !displayTE35.BacklightEnabled;
        }
    }
}


Proud. Feels good #FTW :slight_smile:

5 Likes

@ AWSOMEDEVSIGNER - that is awesome, thanks for sharing.

1 Like

@ taylorza,@ andre.m

Happy to share :slight_smile: Will create some cleaner code and share. I saw that the registers in other code from @ hagster for example are pre-defined and static. I think Iโ€™ll do that as well. Going to clean that up and try to find a tool to generate this image bytes.

@ AWSOMEDEVSIGNER - pat yourself on the back, pour yourself a drink, put your feet up and sit there with a smug look on your face. Well done. We need to set you a harder challenge next time.

How does it work btw? Fast?

1 Like

@ hagster Thanks :slight_smile: And I think I stick with this thing for a while and try to build something useful that can be used with Glade. Itโ€™s fast without glitches so farโ€ฆ I just did a small test with a loop (20 iterations, moving that thing around). I think the image is a bit unfortunate. Need to find a tool to generate this image bytes somehow.

Update: And thanks again for the tip :slight_smile:

Update: Just add this code after the cursor_on() call (not elegant, but shows how fast it is:


while(true)
            { 
            for(uint i=0;i<=150;i++)
            {
                
                cursor_SetPosition(i,i);
               
            }

            for (uint i = 150; i == 0; i--)
            {

                cursor_SetPosition(i, i);

            }
            }

1 Like

@ AWSOMEDEVSIGNER - Good job!

Take a picture. Curious what it looks like.

1 Like

@ Architect

Thanks :slight_smile:

Here is a short video, just to demonstrate how fast it is:

And the picture, what it looks like (camera is not so good, so you will not see the black dots, between all the white stuff):

1 Like

@ AWSOMEDEVSIGNER - no usb mouse? :wink:

1 Like

@ Gus

Working on it :whistle: Wanted to see how it works and what needs to be done. Will create a code-share to demonstrate it with a USB-Mouse. Have to check, how to interact with Glade as well. Have no clue at the moment how to do that.

@ Gus

Here you are, moving that thing with the mouse 8) :

Here is the updated code:



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Processor;



namespace TestSpider2
{
    public partial class Program
    {
        //Mirroring on or off
        uint MIRROR_XY = 0;
        const uint LCD_BASE_ADDR = 0xFFE10000;

        uint CRSR_IMG = (LCD_BASE_ADDR + 0x800);
        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);
        uint CRSR_XY = (LCD_BASE_ADDR + 0xC10);
        uint CRSR_CLIP = (LCD_BASE_ADDR + 0xC14);
        uint CRSR_INTMSK = (LCD_BASE_ADDR + 0xC20);
        uint CRSR_INTCLR = (LCD_BASE_ADDR + 0xC24);
        uint CRSR_INTRAW = (LCD_BASE_ADDR + 0xC28);
        uint CRSR_INTSTAT = (LCD_BASE_ADDR + 0xC2C);

        //TE35
        uint U_LCD_XSIZE = 320;                                             /*  LCD x size                  */
        uint U_LCD_YSIZE = 240;                                             /*  LCD y size                  */


        uint CRSR_IMGBASE0 = 0xFFE10800;
        uint CRSR_IMGBASE1 = 0xFFE10900;
        uint CRSR_IMGBASE2 = 0xFFE10A00;
        uint CRSR_IMGBASE3 = 0xFFE10B00;

        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  
         };


        void cursor_Init()
        {
            int i;
            //unsigned int *puicursor = (unsigned int *)CRSR_IMGBASE0;   

            Register cursor0Reg = new Register(CRSR_IMGBASE0);

            cursor_SetPosition(0, 0);                                           /*  setcursor position at [0,0] */

            //CRSR_CTRL = 0x00;   

            Register crsControl = new Register(CRSR_CTRL, 0x00);  /*  the cursor is not display   */

            for (i = 0; i < 64; i++)
            {

                var next = cursor0Reg++;
                next.Value = uicursor[i];
                /*  read the cursor image       */
            }

            Register crsCfg = new Register(CRSR_CFG, (0x01 << 1) | (0x00 << 0));                                       /*  Cursor are synchronized to   
                                                                            the frame synchronization   
                                                                            pulse                       */


            //CRSR_CFG = (0x01 << 1) |                                           /*  Cursor are synchronized to   
            //                                                                the frame synchronization   
            //                                                                pulse                       */
            //             (0x00 << 0);                                            /*  select 32x32 pixel cursor   */

            Register pal1Reg = new Register(CRSR_PAL0, 0x00000000);
            Register pal2Reg = new Register(CRSR_PAL1, 0x00ffffff);

            //CRSR_PAL0 = 0x00000000;                                             /*  Palette 0 is black color    */
            //CRSR_PAL1 = 0x00ffffff;                                             /*  Palette 1 is white color    */

        }

        void cursor_SetPosition(uint ix, uint iy)
        {

            var crsClipRegister = new Register(CRSR_CLIP);
            var crsXYRegister = new Register(CRSR_XY);
            /*   
             *  if x coordinate is mirror, use underside way to set cursor's position  
             */
            if (MIRROR_XY == 1)
            {
                uint idx = 0;

                if (ix > 287)
                {

                    idx = ix - 287;
                    crsClipRegister.Value = (uint)((0 << 8) | (idx << 0));
                    //CRSR_CLIP = (uint)((0 << 8) | (idx << 0));
                    ix = 0;

                }
                else
                {

                    ix = U_LCD_XSIZE - ix - 1 - 32;

                }
            }


            /*   
     *  if x coordinate is normal, use underside way to set cursor's position  
     */
            crsXYRegister.Value = (uint)((iy << 16) | (ix << 0));
            //CRSR_XY = (uint)((iy << 16) | (ix << 0));
        }

        bool mouseConnected = false;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            button.ButtonPressed += button_ButtonPressed;

            displayTE35.SimpleGraphics.Clear();

            cursor_Init();

            cursor_SetPosition(40, 40);

            cursor_On();

            usbHost.MouseConnected += usbHost_MouseConnected;

           

           

            //int y = 0;
            //while (y < 300)
            //{
            //    for (uint i = 0; i <= 150; i++)
            //    {

            //        cursor_SetPosition(i, i);

            //    }

            //    for (uint i = 150; i == 0; i--)
            //    {

            //        cursor_SetPosition(i, i);

            //    }

            //    y++;
            //}

            //cursor_Off();
            //displayTE35.SimpleGraphics.Clear();

        }

        void ConnectedMouse_CursorMoved(GHI.Usb.Host.Mouse sender, GHI.Usb.Host.Mouse.CursorMovedEventArgs e)
        {
            cursor_SetPosition((uint)e.NewPosition.X, (uint)e.NewPosition.Y);
        }

       
        void usbHost_MouseConnected(USBHost sender, GHI.Usb.Host.Mouse mouse)
        {
            Debug.Print("Mouse Connected!");
            usbHost.ConnectedMouse.CursorMoved += ConnectedMouse_CursorMoved;
        }

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

        void cursor_Off()
        {
            Register crsControl = new Register(CRSR_CTRL, 0x00);                                             /* enable the cursor's display  */
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            displayTE35.BacklightEnabled = !displayTE35.BacklightEnabled;
        }
    }
}

Will create a code-share soon. But want to make it work with Glide.

7 Likes

@ AWSOMEDEVSIGNER - fantastic :slight_smile:

1 Like

@ Gus

Thanks :slight_smile: I just need a hint how to plug that into Glade. Will create some mouse-cursors like hour-glass and normal (nice looking) cursors as well. But need to go again through the docs to check the image-format again.

Probably a simple bit mask.

1 Like

@ Architect

I will try that today as well. See a lot of fun ahead :slight_smile:

Very nice

I I tried putting this code into a glide project
But it hangs

1 Like

@ microt

Thanks :slight_smile: Hope you get it working with Glide somehow. Trying to create some cursors.

The code to write the cursor value to the CRSR_IMGBASE0 register was not correct. Here is the correct code:

  for (i = 0; i < uicursor.Length; i++)
            {
                cursor0Reg.Address+=4;
                cursor0Reg.Value = uicursor[i];
                   
            }

Just replace the for-loop (within the cursor_Init Method) with the above code. And you get a nice looking cursor.

Got it working with the Super-Simple-Glide example!

Here is the code:



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Processor;
using GHI.Glide;



namespace TestSpider2
{
    public partial class Program
    {
        static GHI.Glide.Display.Window window;
        //Mirroring on or off
        uint MIRROR_XY = 0;
        const uint LCD_BASE_ADDR = 0xFFE10000;

        uint CRSR_IMG = (LCD_BASE_ADDR + 0x800);
        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);
        uint CRSR_XY = (LCD_BASE_ADDR + 0xC10);
        uint CRSR_CLIP = (LCD_BASE_ADDR + 0xC14);
        uint CRSR_INTMSK = (LCD_BASE_ADDR + 0xC20);
        uint CRSR_INTCLR = (LCD_BASE_ADDR + 0xC24);
        uint CRSR_INTRAW = (LCD_BASE_ADDR + 0xC28);
        uint CRSR_INTSTAT = (LCD_BASE_ADDR + 0xC2C);

        //TE35
        uint U_LCD_XSIZE = 320;                                             /*  LCD x size                  */
        uint U_LCD_YSIZE = 240;                                             /*  LCD y size                  */


        uint CRSR_IMGBASE0 = 0xFFE10800;
        uint CRSR_IMGBASE1 = 0xFFE10900;
        uint CRSR_IMGBASE2 = 0xFFE10A00;
        uint CRSR_IMGBASE3 = 0xFFE10B00;

        byte[] imageBytes = Resources.GetBytes(Resources.BinaryResources.selection);

        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  
         };

      
        void cursor_Init()
        {
            int i;
            //unsigned int *puicursor = (unsigned int *)CRSR_IMGBASE0;   

            Register cursor0Reg = new Register(CRSR_IMGBASE0);

            cursor_SetPosition(0, 0);                                           /*  setcursor position at [0,0] */

            //CRSR_CTRL = 0x00;   

            Register crsControl = new Register(CRSR_CTRL, 0x00);  /*  the cursor is not display   */

                      
            

            for (i = 0; i < uicursor.Length; i++)
            {
                cursor0Reg.Address+=4;
                cursor0Reg.Value = uicursor[i];
                   
            }

            Register crsCfg = new Register(CRSR_CFG, (0x01 << 1) | (0x00 << 0));                                       /*  Cursor are synchronized to   
                                                                            the frame synchronization   
                                                                            pulse                       */


            //CRSR_CFG = (0x01 << 1) |                                           /*  Cursor are synchronized to   
            //                                                                the frame synchronization   
            //                                                                pulse                       */
            //             (0x00 << 0);                                            /*  select 32x32 pixel cursor   */

            Register pal1Reg = new Register(CRSR_PAL0, 0x00000000);
            Register pal2Reg = new Register(CRSR_PAL1, 0x000000ff);

            //CRSR_PAL0 = 0x00000000;                                             /*  Palette 0 is black color    */
            //CRSR_PAL1 = 0x00ffffff;                                             /*  Palette 1 is white color    */

        }

        void cursor_SetPosition(uint ix, uint iy)
        {

            var crsClipRegister = new Register(CRSR_CLIP);
            var crsXYRegister = new Register(CRSR_XY);
            /*   
             *  if x coordinate is mirror, use underside way to set cursor's position  
             */
            if (MIRROR_XY == 1)
            {
                uint idx = 0;

                if (ix > 287)
                {

                    idx = ix - 287;
                    crsClipRegister.Value = (uint)((0 << 8) | (idx << 0));
                    //CRSR_CLIP = (uint)((0 << 8) | (idx << 0));
                    ix = 0;

                }
                else
                {

                    ix = U_LCD_XSIZE - ix - 1 - 32;

                }
            }


            /*   
     *  if x coordinate is normal, use underside way to set cursor's position  
     */
            crsXYRegister.Value = (uint)((iy << 16) | (ix << 0));
            //CRSR_XY = (uint)((iy << 16) | (ix << 0));
        }

        bool mouseConnected = false;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            button.ButtonPressed += button_ButtonPressed;

            displayTE35.SimpleGraphics.Clear();

            cursor_Init();

            cursor_SetPosition(40, 40);

            cursor_On();

            usbHost.MouseConnected += usbHost_MouseConnected;


            string xml;
            xml = "<Glide Version=\"" + "1.0.7" + "\">";
            xml += "<Window Name=\"window\" Width=\"320\" Height=\"240\" BackColor=\"FFFFFF\">";
            xml += "<TextBlock Name=\"title\" X=\"0\" Y=\"104\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Simple Example\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"6\" FontColor=\"000000\" BackColor=\"000000\" ShowBackColor=\"False\"/>";
            xml += "</Window>";
            xml += "</Glide>";

            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Load the Window XML string.
            window =  GlideLoader.LoadWindow(xml);

            // Assign the Window to MainWindow; rendering it to the LCD.
            Glide.MainWindow = window;

            // Sleep forever.
            GT.Timer tm = new GT.Timer(1000);
            tm.Tick += tm_Tick;
            tm.Start();


            //int y = 0;
            //while (y < 300)
            //{
            //    for (uint i = 0; i <= 150; i++)
            //    {

            //        cursor_SetPosition(i, i);

            //    }

            //    for (uint i = 150; i == 0; i--)
            //    {

            //        cursor_SetPosition(i, i);

            //    }

            //    y++;
            //}

            //cursor_Off();
            //displayTE35.SimpleGraphics.Clear();

        }

        void tm_Tick(GT.Timer timer)
        {
           
        }

        void ConnectedMouse_CursorMoved(GHI.Usb.Host.Mouse sender, GHI.Usb.Host.Mouse.CursorMovedEventArgs e)
        {

            cursor_SetPosition((uint)e.NewPosition.X, (uint)e.NewPosition.Y);

        }


        void usbHost_MouseConnected(USBHost sender, GHI.Usb.Host.Mouse mouse)
        {
            Debug.Print("Mouse Connected!");
            usbHost.ConnectedMouse.CursorMoved += ConnectedMouse_CursorMoved;
        }

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

        void cursor_Off()
        {
            Register crsControl = new Register(CRSR_CTRL, 0x00);                                             /* enable the cursor's display  */
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            displayTE35.BacklightEnabled = !displayTE35.BacklightEnabled;
        }
    }
}

Start the sample and after itโ€™s started, connect the mouse. I donโ€™t know how to check a connected device. The shadow from the mouse cursor is only because of the camera and because I am already a bit shaky (coffee & 3AM). Itโ€™s there, but very low compared to the video. Maybe display sync. Not sure.

Here the proof:

1 Like

@ AWSOMEDEVSIGNER
Lot of progress. You are a super man.

โ€“
I am still stuck
It hangs after this line

       //CRSR_CTRL = 0x00;   
         Register crsControl = new Register(CRSR_CTRL, 0x00);  /*  the cursor is not display   */

โ€“

Mine is not a Gadgeteer project it is a Microframework project. Not sure if that makes a difference

1 Like