Pages

Saturday, April 06, 2013

Guzunty Pi LED driver core demo program reading notes


Now I am guessing how the gz_led_driver core display 4 digits.  The deom program should more or less doing something below.

1. Set RPi clock to the slowest 5 MHz.

2. Set SPI module to send 4 bytes each time.

3. Get wall clock time time_t from Linux, convert it to a 25 characters long buffer time_str.

4. Put the 4 characters in time_str corresponding to hh:mm to 4 character buffer time_buff.

5. Convert the 4 characters in time_buff to 4 seven segment LED patterns in 4 character buffer payload.

6. SPI write the payload buffer.

One thing I don't understand is the use of colon.  It appears that each second colon alternates between 0 and 1, and do the "payload[1] &= ~0x80;".  Perhaps it is for blinking a digit, but not sure why payload[1] only.

.END




*** gz_led_demo.c ***

...

const unsigned char font[128] = 
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // All
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // unprintable
0x00, 0x30, 0x22, 0x76, // SP, !, ", # (H)
0x6d, 0x7f, 0x7d, 0x20, // $ (5), % (8), & (6), '
0x39, 0x0f, 0x76, 0x76, // (, ), * (H), + (H)
0x10, 0x40, 0x00, 0x52, // ',', -, ., /
0x3f, 0x06, 0x5b, 0x4f, // 0, 1, 2, 3
0x66, 0x6d, 0x7d, 0x07, // 4, 5, 6, 7
0x7f, 0x6f, 0x30, 0x30, // 8, 9, :, ;
0x58, 0x48, 0x4c, 0x53, // <, =, >, ?
0x7b, 0x77, 0x7f, 0x39, // @, A, B, C
0x3f, 0x79, 0x71, 0x3d, // D (0), E, F, G
0x76, 0x06, 0x1e, 0x75, // H, I (1), J, K
0x38, 0x55, 0x37, 0x3f, // L, M, N, O (0)
0x73, 0x7d, 0x31, 0x6d, // P, Q, R, S (5)
0x07, 0x3e, 0x2a, 0x6a, // T, U, V, W
0x76, 0x6e, 0x5b, 0x39, // X (H), Y (y), Z, [
0x64, 0x0f, 0x23, 0x08, // backslash, ], ^, _
0x02, 0x77, 0x7c, 0x58, // ', a (A), b, c
0x5e, 0x7b, 0x71, 0x6f, // d, e, f (F), g
0x74, 0x04, 0x0c, 0x75, // h, i (1), j, k (K)
0x06, 0x55, 0x54, 0x5c, // l, m (M), n, o
0x73, 0x67, 0x50, 0x6d, // p (P), q, r, s (5)
0x78, 0x1c, 0x1c, 0x6a, // t, u, v (u), w (W)
0x76, 0x6e, 0x5b, 0x39, // x (H), y, Z (2), { ([)
0x30, 0x0f, 0x01, 0x00  // |, } (]), ~, DEL
};

gz_clock_ena(GZ_CLK_5MHz, 0xfff); // Turn on the slowest clock we can

unsigned char colon = 0;
unsigned char payload[4];
    
gz_spi_set_width(4);              // Pass blocks of 4 bytes on SPI

      while (1)
 {
        time_t t;
        time(&t);

        char time_buf[4];
        char time_str[25];

        sprintf(time_str, "%s",ctime(&t));

        time_buf[0] = time_str[11];
        time_buf[1] = time_str[12];
        time_buf[2] = time_str[14];
        time_buf[3] = time_str[15];
        
for (; i < 4; i++) 
{
 payload[i] = ~font[(unsigned char)time_buf[i]];
   }

if (colon != 0) {
 payload[1] &= ~0x80;
 colon = 0;
        }
        else {
 colon = 1;
   }

 gz_spi_write(payload);          // pass display bytes to SPI
         sleep(1);      
 }

    gz_spi_close();                   // close SPI channel
    gz_clock_dis();                   // turn off GPIO clock

.END

No comments:

Post a Comment