Add configurable options for HD44780 LCD display columns and rows.
[bertos.git] / bertos / drv / lcd_text.c
index b1f3d6f19a2f9fdef8196ca0a8550cc084542e7d..ff480776a3429ea17528534d436116be868e4eb0 100644 (file)
@@ -32,8 +32,7 @@
  *
  * \brief Generic text LCD driver (impl.).
  *
- * \version $Id$
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
  * \author Stefano Fedrigo <aleph@develer.com>
  */
 
@@ -46,7 +45,7 @@
 #include <drv/timer.h> // timer_delay()
 
 #include <mware/formatwr.h> // _formatted_write()
-#include <mware/list.h> // LIST_EMPTY()
+#include <struct/list.h> // LIST_EMPTY()
 
 #include <string.h> // strlen()
 
 /** Maximum number of layers. */
 #define LCD_LAYERS 6
 
-#if CONFIG_KERNEL
+#if CONFIG_KERN
+       #include <kern/sem.h>
        /** Semaphore to arbitrate access to the display. */
        static struct Semaphore lcd_semaphore;
        #define LOCK_LCD        sem_obtain(&lcd_semaphore)
        #define UNLOCK_LCD      sem_release(&lcd_semaphore)
-#else /* !CONFIG_KERNEL */
+#else /* !CONFIG_KERN */
        #define LOCK_LCD        do {} while (0)
        #define UNLOCK_LCD      do {} while (0)
-#endif /* !CONFIG_KERNEL */
+#endif /* !CONFIG_KERN */
 
 DECLARE_LIST_TYPE(Layer);
 
@@ -85,13 +85,13 @@ static lcdpos_t lcd_CursorAddr;
 void lcd_setAddr(Layer *layer, lcdpos_t addr)
 {
        /* Sanity check: wrap around to display limits */
-       while (addr >= LCD_ROWS * LCD_COLS)
-               addr -= LCD_ROWS * LCD_COLS;
+       while (addr >= CONFIG_LCD_ROWS * CONFIG_LCD_COLS)
+               addr -= CONFIG_LCD_ROWS * CONFIG_LCD_COLS;
 
        layer->addr = addr;
 }
 
-#if CONFIG_KERNEL
+#if CONFIG_KERN
 
 void lcd_lock(void)
 {
@@ -104,7 +104,7 @@ void lcd_unlock(void)
        UNLOCK_LCD;
 }
 
-#endif /* CONFIG_KERNEL */
+#endif /* CONFIG_KERN */
 
 
 /**
@@ -124,7 +124,7 @@ static void lcd_putCharUnlocked(char c, Layer *layer)
        layer->buf[addr] = c;
 
        /* Move to next character */
-       if (++layer->addr >= LCD_COLS * LCD_ROWS)
+       if (++layer->addr >= CONFIG_LCD_COLS * CONFIG_LCD_ROWS)
                layer->addr = 0;
 
        /* Do not write on LCD if layer is hidden. */
@@ -166,7 +166,7 @@ void lcd_layerSet(Layer *layer, char c)
 
        LOCK_LCD;
        lcd_setAddr(layer, 0);
-       for (i = 0; i < LCD_COLS * LCD_ROWS; i++)
+       for (i = 0; i < CONFIG_LCD_COLS * CONFIG_LCD_ROWS; i++)
                lcd_putCharUnlocked(c, layer);
        UNLOCK_LCD;
 }
@@ -184,7 +184,7 @@ void lcd_clearLine(Layer *layer, int y)
 
        LOCK_LCD;
        lcd_setAddr(layer, LCD_POS(0, y));
-       for (i = 0; i < LCD_COLS; i++)
+       for (i = 0; i < CONFIG_LCD_COLS; i++)
                lcd_putCharUnlocked(0, layer);
        UNLOCK_LCD;
 }
@@ -242,7 +242,7 @@ int lcd_vprintf(Layer *layer, lcdpos_t addr, uint8_t mode, const char *format, v
                 * NOTE: calculating the string lenght BEFORE it gets
                 * printf()-formatted. Real lenght may differ.
                 */
-               pad = (LCD_COLS - strlen(format)) / 2;
+               pad = (CONFIG_LCD_COLS - strlen(format)) / 2;
                while (pad--)
                        lcd_putCharUnlocked(' ', layer);
        }
@@ -250,7 +250,7 @@ int lcd_vprintf(Layer *layer, lcdpos_t addr, uint8_t mode, const char *format, v
        len = _formatted_write(format, (void (*)(char, void *))lcd_putCharUnlocked, layer, ap);
 
        if (mode & (LCD_FILL | LCD_CENTER))
-               while (layer->addr % LCD_COLS)
+               while (layer->addr % CONFIG_LCD_COLS)
                        lcd_putCharUnlocked(' ', layer);
 
        /*
@@ -321,7 +321,7 @@ Layer *lcd_newLayer(char pri)
 
        layer = (Layer *)LIST_HEAD(&lcd_FreeLayers);
        layer->addr = 0;
-       memset(layer->buf, 0, LCD_ROWS * LCD_COLS);
+       memset(layer->buf, 0, CONFIG_LCD_ROWS * CONFIG_LCD_COLS);
 
        lcd_enqueueLayer(layer, pri);
 
@@ -339,7 +339,7 @@ static void lcd_refresh(void)
        lcdpos_t addr;
        Layer *l;
 
-       for (addr = 0; addr < LCD_ROWS * LCD_COLS; ++addr)
+       for (addr = 0; addr < CONFIG_LCD_ROWS * CONFIG_LCD_COLS; ++addr)
        {
                FOREACH_NODE(l, &lcd_Layers)
                {
@@ -389,7 +389,7 @@ void lcd_deleteLayer(Layer *layer)
        lcdpos_t addr;
 
        /* Repair damage on underlaying layers */
-       for (addr = 0; addr < LCD_ROWS * LCD_COLS; ++addr)
+       for (addr = 0; addr < CONFIG_LCD_ROWS * CONFIG_LCD_COLS; ++addr)
        {
                /* If location was covered by us */
                if (layer->buf[addr])
@@ -437,6 +437,10 @@ static void lcd_setDefLayer(Layer *layer)
 #include <cfg/debug.h>
 void lcd_init(void)
 {
+       #if CONFIG_KERN
+       sem_init(&lcd_semaphore);
+       #endif
+
        int i;
 
        LIST_INIT(&lcd_Layers);