Jump to content
Sign in to follow this  
Thermal Runaway

Lcd_Driver.h Template And Macro Explanation

Recommended Posts

Hello all,

 

I have been looking through the lcd_driver.h code (found in the Sourceboost Includes directory) and I am struggling to understand how it all works. For example:

 

1. What is the purpose of the following Macro?

 

#define _LCD_Write LCD_Write <InterfaceType, UseBusy, DataPort, Data_PortTris, CtrlPort, Ctrl_PortTris, RS, RW, E>

 

There are similar macros defined for other functions as well. They're all the same, but with a different name. What is this for?

 

2. What is the purpose of the following template?

 

 

#define _LCD_TEMPL template < unsigned char InterfaceType,\

unsigned char UseBusy,\

unsigned int DataPort, unsigned int Data_PortTris,\

unsigned int CtrlPort, unsigned int Ctrl_PortTris,\

unsigned char RS, unsigned char RW, unsigned char E>

 

I understand that the purpose of a template is that you create a generic function, and then within your code you can pass it arguments of different types. The pre-processor will collect all of these different types of function call, and create different types of function to suit the arguments that are being passed to it. Like function overloading, but with the advantage that you don't have to write each function out yourself - the pre-processor takes care of it all. I hope my understanding is correct there. But, even with that understanding, I still cannot make sense of the above template. Here's a function that uses it:

 

 

_LCD_TEMPL

void LCD_Clear()

{

_LCD_FunctionMode();

_LCD_Write( clear_lcd ); // clear display

_LCD_Write( return_home );

}

 

So I understand that LCD_Clear is now a function template. But I don't understand what each of the different parameters within the template are for. I completely lacking understanding of the purpose of this, to the point where I don't really know how to phrase my question about it! Can anyone provide a brief explanation?

 

======

 

Thanks in advance for any advice. I have been pouring over this source code for a while and I'm just finding myself more and more confused by it!

 

Brian

Share this post


Link to post
Share on other sites

These macros are used to make the code easier to use. To understand how they work you need to understand C++ templates (the BoostC compiler supports some of C++ language features including function templates). In short template arguments are values known at compile time and are passed down the call tree. What may look confusing is that a template argument may not be used inside a function called from application code but it will be used somewhere inside functions called from this function.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...