Restructorizing

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Restructorizing

Post by Tectu »

Hello Folks,

I was afraid that this day will come, but it must be done now.
As you all might know, the library needs to be completely over worked.

One of the main problems is the memory usage. As Giovanni supposed, I guess the best solution is to make a wrapper / server. Every function which needs to access the LCD (write or read it's RAM) will communicate to that server. The server will then queue all the requests and do the job. This does not only solve memory problems, but also helps to make everything threadsafe.
Another problem is that many of the functions calls do have to many arguments and would need even more in the future. I was thinking of using configurations struct, which would be passed to the functions. I never liked that kind of configuration, but I guess is a good solution here and it would meet the ChibiOS standard.
The next problem is the GUI abstraction layer. We all want a very nice GUI. The current implementation is just a part of the library because I needed a quick solution for some real project. The GUI abstratction layer should become more 'objective' like Qt and similar library do it:

Code: Select all

Button b = createButton(x,y,text,name);
    SetEventHandler(b, CLICK, buttonClickedFunc);

Or something like that.
But I guess before we can start thinking about the GUI, we need to fix the two points above.

So, heres the main problem: I never did such a big thing. I don't have any knowlege how to design all the server stuff etc. Please help me :cry:
I've no problem to give write access to the repository to some co-maintainer or whatever, if anybody got enough time and interests to work on the library.

I am open for any kind of other critism and ideas too.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Restructorizing

Post by Giovanni »

Note that the server would be also able to optimize request.

If one of the requests overlaps another one (area overlapping) then the overlapped request can be ignored or partially drawn.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Restructorizing

Post by Tectu »

That's correct, Giovanni. But it dosen't make my situation easier or more confortable at the moment ;-)


~ Tectu
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Restructorizing

Post by Tectu »

I had some serious talk with Badger on our IRC channel (#chibios on freenode).

We decided that a worker thread which handles all lowlevel access to the LCD modules makes sense on an RTOS.

Thanks to mabl's FatFS wrapper, I could implement the worker thread successfully.


~ Tectu
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Restructorizing

Post by Badger »

I've thought a bit more about the worker thread. We need to be careful of commands like "set cursor", this should not be handled by the worker thread as it adjusts an internal state. Instead, any drawing function that needs the 'cursor' in a particular position should include the cursor location as part of the request. Essentially, all of the commands handled by the worker should be stateless so we don't get any issues when multiple threads are issuing commands.
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: Restructorizing

Post by Abhishek »

Hello Badger,

IMHO a worker thread is needed in the high level function, especially the line drawing functions and text rendering stuff. But I don't see a lot of sense in the low level functions, the overhead involved may offset the benefits. Since I wasn't a part of the discussion yesterday, I might be sounding a little ignorant.

Also, what do you think about implementing it using mailboxes, rather than messages in the worker thread?
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Restructorizing

Post by Badger »

IMHO a worker thread is needed in the high level function, especially the line drawing functions and text rendering stuff. But I don't see a lot of sense in the low level functions, the overhead involved may offset the benefits.

there will no doubt be some overhead, but it is mainly just a context switch as the message passing is minimal. I'd regard line drawing and text rendering as low level, and should be covered by the server:
  • primitives: boxes, lines, etc
  • font rendering
  • read/write operations (e.g vertical scroll)

So then your high level functions, e.g guiDrawButton would issue a series of low level commands: draw a box at x,y of size h x w, put text "button" at x,y. So the high level functions will leave the server to do all the work, by means of issuing several low level functions.

The big benefit of all this is that it makes it very simple to use the display from several threads. If you're only ever going to use it from one then you wont see any benefit, but then you are missing the point of a RTOS :D

Also, what do you think about implementing it using mailboxes, rather than messages in the worker thread?

With message the client thread will have to wait for the message to be dealt with. Probably there is lower overhead with sending a message? I think in most cases we will want the drawing routines to block the client thread, so I see no big problem with just using messages.
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: Restructorizing

Post by Abhishek »

All right then. But I'd say low level functions call other low level functions directly, not via worker thread .

This means we might have to give a different name to the worker functions.
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: Restructorizing

Post by Badger »

of course, we would have two low level functions for some aspects. For example, to draw a pixel, there would be one external 'draw a pixel' routine that wraps the request and sends it to the server. Then there would be an internal 'draw a pixel' routine which is called only by the server, but not necessarily only as a result of a client calling 'draw a pixel', but also by other server functions, perhaps to render a character.

The internal function definitions would be in headers available only to the worker code.
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: Restructorizing

Post by Abhishek »

I had two questions in mind:
1. What about having a VMT architecture for the low-level GLCD driver?
2. Could we make the LCD driver implement a stream? This way we could send bulk image directly to the LCD. Of course we do have writestream and readstream methods now. Maybe we could have separate command streams and data streams, but not very enthusiastic about it.
Last edited by Abhishek on Mon Jul 16, 2012 11:00 am, edited 1 time in total.
Locked