Page 1 of 3

Restructorizing

Posted: Thu Jul 12, 2012 12:28 pm
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

Re: Restructorizing

Posted: Thu Jul 12, 2012 12:53 pm
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

Re: Restructorizing

Posted: Thu Jul 12, 2012 2:17 pm
by Tectu
That's correct, Giovanni. But it dosen't make my situation easier or more confortable at the moment ;-)


~ Tectu

Re: Restructorizing

Posted: Mon Jul 16, 2012 1:02 am
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

Re: Restructorizing

Posted: Mon Jul 16, 2012 9:58 am
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.

Re: Restructorizing

Posted: Mon Jul 16, 2012 10:22 am
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?

Re: Restructorizing

Posted: Mon Jul 16, 2012 10:34 am
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.

Re: Restructorizing

Posted: Mon Jul 16, 2012 10:39 am
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.

Re: Restructorizing

Posted: Mon Jul 16, 2012 10:45 am
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.

Re: Restructorizing

Posted: Mon Jul 16, 2012 10:53 am
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.