From 78e2f7bb1cbc48d9fcfb340a3cd9641ac6020760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 25 Jan 2016 00:39:29 +0100 Subject: [PATCH] combine the driver data for digits and matrix --- global.h | 3 ++ lib/vfd.c | 88 ++++++++++++++++++++++++++++--------------------------- main.c | 3 -- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/global.h b/global.h index 297b35a..559ae06 100644 --- a/global.h +++ b/global.h @@ -14,6 +14,9 @@ */ /* Copyright (c) 2016 King Kévin */ +/* get the length of an array */ +#define LENGTH(x) (sizeof(x) / sizeof((x)[0])) + /* system clock frequency in Hz */ #define SYSTEM_CLOCK_FREQ 72000000 diff --git a/lib/vfd.c b/lib/vfd.c index 32d73ab..d44275d 100644 --- a/lib/vfd.c +++ b/lib/vfd.c @@ -30,9 +30,6 @@ #include "global.h" // global definitions #include "vfd.h" // VFD library API -/* get the length of an array */ -#define LENGTH(x) (sizeof(x) / sizeof((x)[0])) - /* supertex HV518 VFD driver pins */ /* port on which the pins to control the supertex HV518 VFD driver are * we use port A because of the SPI interface */ @@ -304,10 +301,14 @@ static const uint8_t pict5x7[][5] = { }; /* the 32 bits values to be shifted out to the VFD driver - * split into 16 bit for SPI transfer */ -static uint16_t vfd_spi[VFD_DIGITS+VFD_MATRIX][VFD_DRIVERS*2] = {0}; -static volatile uint8_t vfd_spi_i = 0; // which driver data is being transmitted + * split into 16 bit for SPI transfer + * since the bits for digits and matrix are independant, they can be conbined + * we have more matrix (12) than digits (10) + */ +static uint16_t driver_data[VFD_MATRIX][VFD_DRIVERS*2] = {0}; +static volatile uint8_t spi_i = 0; // which driver data is being transmitted static volatile uint8_t vfd_mux = 0; // which part to output +static const uint32_t digit_mask = 0x00fff0; // the bits used for selecting then digit and 7 segment anodes (for the second driver) /* set digit to ASCII character * use the MSB of to enable the dot */ @@ -317,9 +318,9 @@ void vfd_digit(uint8_t nb, char c) return; } - uint32_t vfd_data[VFD_DRIVERS] = {0}; // the data to be shifted out for the driver + uint32_t digit_data = 0; // the data to be shifted out for the driver (for the second driver) - vfd_data[1] = 1<<(4+(9-nb)); // select digit + digit_data = 1<<(4+(9-nb)); // select digit /* encode segment * here the bit order (classic 7 segment + underline and dot) * 3_ @@ -328,28 +329,27 @@ void vfd_digit(uint8_t nb, char c) * 0_2, * */ if (false) { // add the underline (not encoded) - vfd_data[1] |= (1<<(14)); + digit_data |= (1<<(14)); } if (c&0x80) { // add the dot (encoded in the 8th bit) - vfd_data[1] |= (1<<(15)); + digit_data |= (1<<(15)); } if (false) { // add the comma (not encoded) - vfd_data[1] |= (1<<(16)); + digit_data |= (1<<(16)); } c &= 0x7f; // only take the ASCII part if (c>=' ') { // only take printable characters uint8_t i = c-' '; // get index for character if (i>16; - } + digit_data &= digit_mask; // be sure only the bits for the digit are used + digit_data |= (driver_data[nb][2]+(driver_data[nb][3]<<16))&~digit_mask; // get the existing data and add the bits for the digit + driver_data[nb][2] = digit_data; // write back data (least significant half) + driver_data[nb][3] = (digit_data>>16); // write back data (most significant half) } /* set dot matrix to ASCII character @@ -361,39 +361,41 @@ void vfd_matrix(uint8_t nb, char c) return; } - uint32_t vfd_data[VFD_DRIVERS] = {0}; // the data to be shifted out for the driver + uint32_t matrix_data[VFD_DRIVERS] = {0}; // the data to be shifted out for the driver // select matrix if (nb<4) { - vfd_data[1] = 1<<(3-nb); + matrix_data[1] = 1<<(3-nb); } else { - vfd_data[0] = 1<<(35-nb); + matrix_data[0] = 1<<(35-nb); } if ((c<0x80) && (c>=' ')) { // only take printable characters uint8_t i = c-' '; // get index for character if (i0x7f) { // the non ASCII character are used for pictures uint8_t i = c-0x80; // get index for character if (i>16; + for (uint8_t i=0; i>16; } } @@ -401,9 +403,9 @@ void vfd_matrix(uint8_t nb, char c) * the data has to be transmitted separately */ void vfd_clear(void) { - for (uint8_t i=0; i