aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeterbailey <peterbailey@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-11-05 08:02:32 +0000
committerpeterbailey <peterbailey@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-11-05 08:02:32 +0000
commit580749292664f377180d0f8b929e01df27aea584 (patch)
tree2c14d60e2efe7da9f4ae9af4fd3b2ab3960cba9b
parentb2f63e0f19709ec976d3b7a8a54e76fd15e13b4b (diff)
downloadlcd4linux-580749292664f377180d0f8b929e01df27aea584.tar.gz
added protocol details to PICGraphic driver, fixed typos is generic headers
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1051 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--drv_PICGraphic.c106
-rw-r--r--drv_generic_gpio.h2
-rw-r--r--drv_generic_serial.h2
3 files changed, 80 insertions, 30 deletions
diff --git a/drv_PICGraphic.c b/drv_PICGraphic.c
index 1dda772..3b689d0 100644
--- a/drv_PICGraphic.c
+++ b/drv_PICGraphic.c
@@ -92,10 +92,10 @@ typedef struct {
static char *fbPG = 0, delayDone = 0;
-void drv_PICGraphic_1s(void *arg)
+void drv_PICGraphic_delay(void *arg)
{
delayDone = 1;
- info("delay done");
+ debug("delay done");
}
@@ -118,21 +118,20 @@ static int drv_PICGraphic_close(void)
return drv_generic_serial_close();
}
-static void convert2ASCII(char input, char * output)
+static void convert2ASCII(char input, char *output)
{
- unsigned char temp = input >> 4;
- if(temp < 10)
- output[0] = temp + '0';
- else
- output[0] = temp - 10 + 'a';
- input &= 0xf;
- if(input < 10)
- output[1] = input + '0';
- else
- output[1] = input - 10 + 'a';
+ unsigned char temp = input >> 4;
+ if (temp < 10)
+ output[0] = temp + '0';
+ else
+ output[0] = temp - 10 + 'a';
+ input &= 0xf;
+ if (input < 10)
+ output[1] = input + '0';
+ else
+ output[1] = input - 10 + 'a';
}
-
static void drv_PICGraphic_send(const char *data, const unsigned int len)
{
unsigned int i;
@@ -140,19 +139,46 @@ static void drv_PICGraphic_send(const char *data, const unsigned int len)
hexDigits[2] = 0;
drv_generic_serial_write(data, len);
info("sending %d bytes: ", len);
- for(i = 0; i < len; i++){ // min(10, len)
- convert2ASCII(data[i], hexDigits);
- info("0x%s (%c)", hexDigits, data[i]);
+ for (i = 0; i < min(10, len); i++) { // min(10, len)
+ convert2ASCII(data[i], hexDigits);
+ debug("0x%s (%c)", hexDigits, data[i]);
}
}
+static int drv_PICGraphic_recv(char *dest, const unsigned int len, const char *expect)
+{
+ unsigned int bytes = 0;
+ int status;
+ while (bytes < len) {
+ status = drv_generic_serial_read((char *) dest + bytes, 1);
+ if (status == 1) {
+ if (dest[bytes] != 0xa && dest[bytes] != 0xd) {
+ if (dest[bytes] != '@') {
+ bytes += status;
+ }
+ }
+ } else {
+ info("error receiving response: %d", status);
+ return status;
+ }
+ usleep(10000);
+ }
+ status = strncmp((const char *) dest, expect, len);
+ if (!status) {
+ return 0;
+ } else {
+ return 1;
+ }
+
+}
+
static void drv_PICGraphic_blit(const int row, const int col, const int height, const int width)
{
/* update a rectangular portion of the display */
- int r, c, index;
+ int r, c, index, status;
unsigned char cmd[5];
- info("blit from (%d,%d) to (%d,%d) out of (%d,%d)", row, col, row + height, col + width, DROWS, DCOLS);
+ debug("blit from (%d,%d) to (%d,%d) out of (%d,%d)", row, col, row + height, col + width, DROWS, DCOLS);
if (!fbPG)
return;
for (c = min(col, DCOLS - 1); c < min(col + width, DCOLS); c++) {
@@ -175,8 +201,8 @@ static void drv_PICGraphic_blit(const int row, const int col, const int height,
if (delayDone) {
delayDone = 0;
int row8, height8;
- row8 = 8*(row/8);
- height8 = 8*(height/8) + !!(height % 8);
+ row8 = 8 * (row / 8);
+ height8 = 8 * (height / 8) + !!(height % 8);
info("sending blit");
cmd[0] = 'b';
cmd[1] = row8;
@@ -184,8 +210,8 @@ static void drv_PICGraphic_blit(const int row, const int col, const int height,
cmd[3] = height8;
cmd[4] = width;
drv_PICGraphic_send(cmd, 5);
- for (r = min(row8, DROWS - 1); r < min(row8 + height8, DROWS); r+=8) {
- drv_PICGraphic_send(fbPG+DCOLS * (r / 8) + col, width);
+ for (r = min(row8, DROWS - 1); r < min(row8 + height8, DROWS); r += 8) {
+ drv_PICGraphic_send(fbPG + DCOLS * (r / 8) + col, width);
}
}
#else
@@ -194,8 +220,17 @@ static void drv_PICGraphic_blit(const int row, const int col, const int height,
delayDone = 0;
info("sending frame");
cmd[0] = 'f';
- drv_PICGraphic_send(cmd, 1);
+ drv_PICGraphic_send((char *) cmd, 1);
drv_PICGraphic_send(fbPG, DROWS * DCOLS / 8);
+ usleep(20000);
+ // wait for reception of confirmation code
+ status = drv_PICGraphic_recv(cmd, 2, "ff");
+ if (!status) {
+ info("received ff from device");
+ } else {
+ info("did not receive ff from device");
+ }
+
}
#endif
}
@@ -257,8 +292,8 @@ static int drv_PICGraphic_contrast(int contrast)
static int drv_PICGraphic_start2(const char *section)
{
char *s;
- char cmd[1];
- int contrast;
+ char cmd[2];
+ int contrast, status, bytes = 0, tick, tack;
/* read display size from config */
s = cfg_get(section, "Size", NULL);
@@ -300,8 +335,14 @@ static int drv_PICGraphic_start2(const char *section)
}
info("allocated framebuffer with size %d", DCOLS * DROWS / 8);
-
- timer_add(drv_PICGraphic_1s, 0, 500, 0); // 1s
+ if (cfg_number("Variables", "tick", 500, 100, 0, &tick) > 0 &&
+ cfg_number("Variables", "tack", 500, 100, 0, &tack) > 0) {
+ info("tick & tack read from config");
+ timer_add(drv_PICGraphic_delay, 0, min(tick, tack), 0); //
+ } else {
+ info("tick & tack not read from config");
+ timer_add(drv_PICGraphic_delay, 0, 80, 0); //
+ }
/* open communication with the display */
if (drv_PICGraphic_open(section) < 0) {
@@ -311,6 +352,15 @@ static int drv_PICGraphic_start2(const char *section)
/* reset & initialize display */
cmd[0] = 'i';
drv_PICGraphic_send(cmd, 1);
+ usleep(10000);
+ // wait for reception of confirmation code
+ status = drv_PICGraphic_recv(cmd, 2, "fi");
+
+ if (!status) {
+ info("received fi from device");
+ } else {
+ info("did not receive fi from device");
+ }
if (cfg_number(section, "Contrast", 8, 0, 15, &contrast) > 0) {
drv_PICGraphic_contrast(contrast);
diff --git a/drv_generic_gpio.h b/drv_generic_gpio.h
index 8b0d359..e4b3d40 100644
--- a/drv_generic_gpio.h
+++ b/drv_generic_gpio.h
@@ -30,7 +30,7 @@
#include "widget.h"
-extern int GPIS; /* number of GPO's */
+extern int GPIS; /* number of GPI's */
extern int GPOS; /* number of GPO's */
/* these function must be implemented by the real driver */
diff --git a/drv_generic_serial.h b/drv_generic_serial.h
index 8e6c98f..9bd03f9 100644
--- a/drv_generic_serial.h
+++ b/drv_generic_serial.h
@@ -25,7 +25,7 @@
*/
-#ifndef _DRV_GENERIC_SERIALH_
+#ifndef _DRV_GENERIC_SERIAL_H_
#define _DRV_GENERIC_SERIAL_H_
int drv_generic_serial_open(const char *section, const char *driver, const unsigned int flags);