rodrigoguniasmaniotto / u8glib

Automatically exported from code.google.com/p/u8glib
0 stars 0 forks source link

Add support for the HT1632 LED matrix driver #165

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
HT1632 drivers for the Arduino platform lack alot of features. It would be nice 
to add support for them in u8glib. I do have four 24x16 LED matrixes and I have 
written a working library for the Arduino platform. The problem is I can't 
really understand how u8glib drivers for devices work.

Where can I get a starting point? I have read most of the drivers for the 
various display modules (and the the flip-disk device) but I'm still confused.

Original issue reported on code.google.com by giann...@gmail.com on 7 May 2013 at 2:50

GoogleCodeExporter commented 8 years ago
i always wanted to write a tutorial on custom device creation, but i have not 
yet started.
How do you turn LEDs on and off?

Original comment by olikr...@gmail.com on 7 May 2013 at 7:37

GoogleCodeExporter commented 8 years ago
The LEDs are mapped on the HT1632's memory. You can either point to the 
specific memory region you want and then write the value, or point to the start 
of the memory and write the whole memory at once. I suppose u8glib will use the 
second method(?).

The display uses a custom interface method and is not SPI compatible.

I've attached the datasheet for your reference.

Original comment by giann...@gmail.com on 7 May 2013 at 7:51

Attachments:

GoogleCodeExporter commented 8 years ago
i have started a tutorial meanwhile...:
http://code.google.com/p/u8glib/wiki/devicedesign

Original comment by olikr...@gmail.com on 7 May 2013 at 7:55

GoogleCodeExporter commented 8 years ago
According to what I've read and your tutorial, I'll need:
1) Implement the communication (SPI-like interface, 8 bits for data, 7 for 
cmds) (com_fn)
2) Initialize the display
3) Send data (dev_fn)

A quick question. The HT1632 does not have memory pages, how do I define that? 
Should I define just one page?

Original comment by giann...@gmail.com on 7 May 2013 at 8:40

GoogleCodeExporter commented 8 years ago
1) not really: this is only an option. It could be integrated into dev_fn
2) yes (inside dev_fn)
3) yes (inside dev_fn)

> The HT1632 does not have memory pages, how do I define that? Should I define 
just one page?
Inside dev_fn, but there are also predefined "page procedures", called page 
buffers (pb) in u8glib. There are several page buffers for different memory 
layouts. What i read from the attached datasheet, the u8g_pb8v1 might fit best 
for your display.

It is like this: Some of the messages are handled directly inside dev_fn (like 
display init), but others are transfered to the page buffer procedure (like 
pixel set)

Original comment by olikr...@gmail.com on 7 May 2013 at 9:32

GoogleCodeExporter commented 8 years ago
... I continued with the wiki page...

Original comment by olikr...@gmail.com on 7 May 2013 at 10:10

GoogleCodeExporter commented 8 years ago
This seems alot more complicated than I thought. Let's see if I got this 
correct. In order to implement the HT1632, I'm going to need two files. One 
named "u8g_com_arduino_ht1632_bitbang.c" where all the communication procedures 
will be placed and a file named "u8g_dev_ht1632_26x16.c" where all the device 
specific functions will be placed.

Let's start with the communication part... The HT1632 needs data in three 
different ways. First of all, 8 bits containing the device commands, 7 bits for 
memory addresses and 8 bits LSB for the device data.

Those are the functions I've developed (and confirmed working) for my HT1632 
library. More or less that's how every HT1632 library is implemented.

void MatrixDisplay::writeDataMSB(byte cnt, byte data, bool extra) {
    for(int8_t i = cnt - 1; i >= 0; i--) {
        if ((data >> i) & 1) {
            PORT |= 1 << DATA;
        }
        else {
            PORT &= ~(1 << DATA);
        }
        PORT &= ~(1 << WR);
        PORT |= 1 << WR;
    }

    // Send an extra bit
    if (extra) {
        PORT |= 1 << DATA;
        PORT &= ~(1 << WR);
        PORT |= 1 << WR;
    }
}

void MatrixDisplay::writeDataLSB(byte cnt, byte data) {
    for (byte i = 0; i < cnt; i++) {
        if ((data >> i) & 1) {
            PORT |= 1 << DATA;
        }
        else {
            PORT &= ~(1 << DATA);
        }

        PORT &= ~(1 << WR);
        PORT |= 1 << WR;
    }
}

In what messages should I implement those? I understand that in 
U8G_COM_MSG_INIT, for example, I should setup the AVR pins.

Original comment by giann...@gmail.com on 8 May 2013 at 12:27

GoogleCodeExporter commented 8 years ago
I still think that the communication part (com procedures) are not required in 
your case. I have added a new device into repo:
http://code.google.com/p/u8glib/source/browse/csrc/u8g_dev_ht1632_26x16.c

It is only required to fill the two procedures. I think all the bit banging can 
be added to the same file, so only one single file is required.

Until a working device, you probably can use the c interface for testing:

extern u8g_dev_t u8g_dev_ht1632_26x16;

void setup(void)
{
}

void loop(void)
{
  u8g_t u8g;

  u8g_Init(&u8g, &u8g_dev_ht1632_26x16);
  u8g_FirstPage(&u8g);
  u8g_SetColorIndex(&u8g, 1);
  do  {
    u8g_SetFont(&u8g, u8g_font_7x13);
    u8g_DrawStr(&u8g, 0, 14, "ABCgdef");
  }while( u8g_NextPage(&u8g) );
  delay(1000);
}

Original comment by olikr...@gmail.com on 8 May 2013 at 9:22

GoogleCodeExporter commented 8 years ago
todo: rename to 24x16

Original comment by olikr...@gmail.com on 28 May 2013 at 4:16

GoogleCodeExporter commented 8 years ago
ToDo:
void ht1632_init(void) must be called from the INIT msg

Original comment by olikr...@gmail.com on 28 May 2013 at 3:15

GoogleCodeExporter commented 8 years ago
renamed and init procedure added, waiting for feedback (arduino forum thread)

Original comment by olikr...@gmail.com on 28 May 2013 at 5:59

GoogleCodeExporter commented 8 years ago
Added the C++ Constructor
//U8GLIB_HT1632_24X16 u8g(3, 2, 4);     // WR = 3, DATA = 2, CS = 4
to HelloWorld and GraphicsTest

ToDo:
- Wait for feedback from forum user (testing)
- Update other examples
- Update device table

Original comment by olikr...@gmail.com on 1 Jun 2013 at 11:41

GoogleCodeExporter commented 8 years ago
Forum Feedback: All ok with the current release.

Original comment by olikr...@gmail.com on 1 Jun 2013 at 3:08

GoogleCodeExporter commented 8 years ago
added device table entry

Original comment by olikr...@gmail.com on 1 Jun 2013 at 8:40

GoogleCodeExporter commented 8 years ago
closing this entry, continue with issue 176

Original comment by olikr...@gmail.com on 2 Jun 2013 at 4:32

GoogleCodeExporter commented 8 years ago
Is it possible to use multiple chained HT1632 devices? How can I do that with 
u8glib?

Original comment by DiaoulAel on 1 Feb 2015 at 5:30

GoogleCodeExporter commented 8 years ago
you could use two or more u8g objects, but chainig itself might not be possible

Original comment by olikr...@gmail.com on 1 Feb 2015 at 7:30