[En-Nut-Discussion] Platform independent HD44780 driver (remove old ones)

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Tue Sep 16 15:06:46 CEST 2014


>>>>> "Thiago" == Thiago A Corrêa <thiago.correa at gmail.com> writes:

    Thiago> Ok, I've uploaded it. It isn't fancy at all, HD44780 is fairly
    Thiago> simple.  It might need some tweaking. Let me know if anyone has
    Thiago> problems with it.

Probably appended patch is better.
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
diff --git a/nut/dev/hd44780.c b/nut/dev/hd44780.c
index 90f6a27..82b9e19 100644
--- a/nut/dev/hd44780.c
+++ b/nut/dev/hd44780.c
@@ -80,26 +80,60 @@
 #define LCD_LONG_DELAY  400
 #endif
 
+#if defined(LCD_EN_PIO_ID)
+#undef GPIO_ID
 #define GPIO_ID LCD_EN_PIO_ID
 #include <cfg/arch/porttran.h>
 static INLINE void LCD_EN_SET(void) { GPIO_SET_HI(LCD_EN_BIT); }
 static INLINE void LCD_EN_CLR(void) { GPIO_SET_LO(LCD_EN_BIT); }
 static INLINE void LCD_EN_INIT(void) { GPIO_OUTPUT(LCD_EN_BIT); }
-#undef GPIO_ID
+#else
+#define LCD_EN_SET()
+#define LCD_EN_CLR()
+#define LCD_EN_INIT()
+#endif
 
+#if defined(LCD_RS_PIO_ID)
+#undef GPIO_ID
 #define GPIO_ID LCD_RS_PIO_ID
 #include <cfg/arch/porttran.h>
 static INLINE void LCD_RS_SET(void) { GPIO_SET_HI(LCD_RS_BIT); }
 static INLINE void LCD_RS_CLR(void) { GPIO_SET_LO(LCD_RS_BIT); }
 static INLINE void LCD_RS_INIT(void) { GPIO_OUTPUT(LCD_RS_BIT); }
-#undef GPIO_ID
+#else
+#define LCD_RS_SET()
+#define LCD_RS_CLR()
+#define LCD_RS_INIT()
+#endif
 
+#if defined( LCD_RW_PIO_ID)
+#undef GPIO_ID
 #define GPIO_ID LCD_RW_PIO_ID
 #include <cfg/arch/porttran.h>
 static INLINE void LCD_RW_SET(void) { GPIO_SET_HI(LCD_RW_BIT); }
 static INLINE void LCD_RW_CLR(void) { GPIO_SET_LO(LCD_RW_BIT); }
 static INLINE void LCD_RW_INIT(void) { GPIO_OUTPUT(LCD_RW_BIT); }
-#undef GPIO_ID
+#else
+#define LCD_RW_SET()
+#define LCD_RW_CLR()
+#define LCD_RW_INIT()
+#endif
+
+#if defined(LCD_DATA_PIO_ID)
+#define PORT_SET_CONF() GpioPortConfigSet( LCD_DATA_PIO_ID, LCD_DATA_MASK, GPIO_CFG_INPUT | GPIO_CFG_PULLUP )
+#define PORT_GET()       GpioPortGet( LCD_DATA_PIO_ID & LCD_DATA_MASK)
+#define PORT_SET_HIGH(x) GpioPortSetHigh( LCD_DATA_PIO_ID, x & LCD_DATA_MASK )
+#define PORT_SET_Low(x)  GpioPortSetLow ( LCD_DATA_PIO_ID, x & LCD_DATA_MASK )
+#else
+#define PORT_SET_CONF()
+#define PORT_GET()       0
+#define PORT_SET_HIGH(x)
+#define PORT_SET_LOW(x)
+#endif
+
+#if !defined(LCD_DATA_LSB)
+#define LCD_DATA_LSB 0
+#endif
 
 /*!
  * \addtogroup xgDisplay
@@ -112,13 +146,13 @@ static INLINE uint8_t LcdReadNibble(void)
 {
     uint8_t ret;
        LCD_RW_SET();
-       GpioPortConfigSet( LCD_DATA_PIO_ID, LCD_DATA_MASK, GPIO_CFG_INPUT | GPIO_CFG_PULLUP );
+       PORT_SET_CONF();
        LCD_EN_SET();
        NutMicroDelay(LCD_SHORT_DELAY);
-       ret = GpioPortGet( LCD_DATA_PIO_ID ) & LCD_DATA_MASK;
+       ret = PORT_GET();
        ret >>= LCD_DATA_LSB;
        LCD_EN_CLR();
-       GpioPortConfigSet( LCD_DATA_PIO_ID, LCD_DATA_MASK, GPIO_CFG_OUTPUT );
+       PORT_SET_CONF();
        NutMicroDelay(LCD_SHORT_DELAY);
        return ret;
 }
@@ -164,8 +198,8 @@ static void LcdDelay(int xt)
 static void LcdWriteNibble(unsigned int nib)
 {
     nib <<= LCD_DATA_LSB;
-       GpioPortSetHigh( LCD_DATA_PIO_ID, nib & LCD_DATA_MASK );
-       GpioPortSetLow( LCD_DATA_PIO_ID, ~nib & LCD_DATA_MASK );
+       PORT_SET_HIGH(nib);
+       PORT_SET_LOW(~nib);
 
     /* Create Enable Pulse:
      * For HD44780 Displays we need:
@@ -277,11 +311,11 @@ static int LcdInit(NUTDEVICE * dev)
 {
        LCD_RS_INIT();
        LCD_RW_INIT();
-       GpioPortConfigSet( LCD_DATA_PIO_ID, LCD_DATA_MASK, GPIO_CFG_OUTPUT );
+       PORT_SET_CONF();
 
     LCD_RS_CLR();
     LCD_RW_CLR();
-    GpioPortSetLow( LCD_DATA_PIO_ID, LCD_DATA_MASK );
+    PORT_SET_LOW(0xff);
     NutMicroDelay(30);
 
        LCD_EN_INIT();


More information about the En-Nut-Discussion mailing list