From 9ccab0c20744cb832197e8da5e0005ee4d4ae15d Mon Sep 17 00:00:00 2001 From: Tectu Date: Thu, 7 Jun 2012 14:37:29 +0200 Subject: cleanups --- glcd.c | 11 ++++++----- gui.c | 40 ++++++++++++++++++++++++++++++++++++++++ gui.h | 7 +++++++ lcd.mk | 3 ++- 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 gui.c create mode 100644 gui.h diff --git a/glcd.c b/glcd.c index bfb1f17d..42be9fb3 100644 --- a/glcd.c +++ b/glcd.c @@ -11,7 +11,7 @@ static __inline void lcdWriteIndex(uint16_t index) { Clr_RS; Set_RD; - LCD_DATA_PORT->ODR = index; + palWritePort(LCD_DATA_PORT, index); Clr_WR; Set_WR; @@ -20,7 +20,7 @@ static __inline void lcdWriteIndex(uint16_t index) { static __inline void lcdWriteData(uint16_t data) { Set_RS; - LCD_DATA_PORT->ODR = data; + palWritePort(LCD_DATA_PORT, data); Clr_WR; Set_WR; @@ -36,9 +36,10 @@ static __inline uint16_t lcdReadData(void) { // change pin mode to digital input LCD_DATA_PORT->CRH = 0x44444444; LCD_DATA_PORT->CRL = 0x44444444; - - value = LCD_DATA_PORT->IDR; // dummy - value = LCD_DATA_PORT->IDR; + + + value = palReadPort(LCD_DATA_PORT); // dummy + value = palReadPort(LCD_DATA_PORT); // change pin mode back to digital output LCD_DATA_PORT->CRH = 0x33333333; diff --git a/gui.c b/gui.c new file mode 100644 index 00000000..ef90d63e --- /dev/null +++ b/gui.c @@ -0,0 +1,40 @@ +#include "ch.h" +#include "hal.h" +#include "gui.h" +#include "glcd.h" +#include "touchpad.h" + +volatile uint16_t x, y; + +static WORKING_AREA(waTouchPadThread, 512); +static msg_t TouchPadThread(void *arg) { + (void)arg; + unsigned char buffer[10]; + chRegSetThreadName("GUI"); + + while(TRUE) { + if(tpIRQ()) { + x = tpReadX(); + y = tpReadY(); + + lcdFillArea(10, 10, 80, 80, Black); + sprintf(buffer, "X: %d", x); + lcdDrawString(10, 10, buffer, White, Black); + sprintf(buffer, "Y: %d", y); + lcdDrawString(10, 25, buffer, White, Black); + } + + chThdSleepMilliseconds(10); + } +} + + +void guiInit(void) { + chThdCreateStatic(TouchPadThread, sizeof(TouchPadThread), HIGHPRIO, TouchPadThread, NULL); +} + +void guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state) { + lcdDrawRectString(x0, y0, x1, y1, str, fontColor, buttonColor); + +} + diff --git a/gui.h b/gui.h new file mode 100644 index 00000000..3a6835ca --- /dev/null +++ b/gui.h @@ -0,0 +1,7 @@ +#ifndef GUI_H +#define GUI_H + +void guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, uint16_t fontColor, uint16_t buttonColor, uint8_t *state); + +#endif + diff --git a/lcd.mk b/lcd.mk index 4acb09cf..e842f05c 100644 --- a/lcd.mk +++ b/lcd.mk @@ -2,6 +2,7 @@ LCDSRC = ${CHIBIOS}/ext/lcd/glcd.c \ ${CHIBIOS}/ext/fonts.c \ ${CHIBIOS}/ext/touchpad.c \ - ${CHIBIOS}/ext/graph.c + ${CHIBIOS}/ext/graph.c \ + ${CHIBIOS}/ext/gui.c LCDINC = ${CHIBIOS}/ext/lcd -- cgit v1.2.3