merge upstream changes
This commit is contained in:
commit
bdcbdd4c38
79
demos/gui/main.c
Executable file
79
demos/gui/main.c
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
#include "gui.h"
|
||||||
|
#include "glcd.h"
|
||||||
|
#include "touchpad.h"
|
||||||
|
|
||||||
|
__inline void lld_lcdWriteGPIO(uint16_t data) {
|
||||||
|
palWritePort(LCD_DATA_PORT, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline uint16_t lld_lcdReadGPIO(void) {
|
||||||
|
uint16_t value;
|
||||||
|
|
||||||
|
// change pin mode to digital input
|
||||||
|
LCD_DATA_PORT->CRH = 0x44444444;
|
||||||
|
LCD_DATA_PORT->CRL = 0x44444444;
|
||||||
|
|
||||||
|
value = palReadPort(LCD_DATA_PORT); // dummy
|
||||||
|
value = palReadPort(LCD_DATA_PORT);
|
||||||
|
|
||||||
|
// change pin mode back to digital output
|
||||||
|
LCD_DATA_PORT->CRH = 0x33333333;
|
||||||
|
LCD_DATA_PORT->CRL = 0x33333333;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GLCD driver object
|
||||||
|
static GLCDDriver GLCDD1;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
uint8_t setActive, setState, clearActive, clearState;
|
||||||
|
|
||||||
|
halInit();
|
||||||
|
chSysInit();
|
||||||
|
|
||||||
|
// Initializes the LCD
|
||||||
|
lcdInit(&GLCDD1);
|
||||||
|
|
||||||
|
// Initializes the touchpad
|
||||||
|
tpInit(&SPID1);
|
||||||
|
|
||||||
|
// clear the entire LCD screen
|
||||||
|
lcdClear(Black);
|
||||||
|
|
||||||
|
// Initializes the GUI thread
|
||||||
|
// 10ms interval
|
||||||
|
// HIGHPRIO-2 thread priority level
|
||||||
|
guiInit(10, HIGHPRIO-2);
|
||||||
|
|
||||||
|
// set the following buttons to active
|
||||||
|
// buttons wouldn't have any effect if you set these variables to 'inactive'
|
||||||
|
setActive = active;
|
||||||
|
clearActive = active;
|
||||||
|
|
||||||
|
// draw a button to set, and one to clear the LED
|
||||||
|
guiDrawButton(10, 10, 60, 60, "Set", Black, Yellow, "SetButton", &setActive, &setState);
|
||||||
|
guiDrawButton(70, 10, 120, 60, "Clear", Black, Red, "ClearButton", &clearActive, &clearState);
|
||||||
|
|
||||||
|
// you can delete a GUI element at any time from the GUI. You have to pass the GUI element name here.
|
||||||
|
// please note that you have to redraw the screen to delete the element yourself.
|
||||||
|
// guiDeleteElement("SetButton");
|
||||||
|
// guiDeleteElement("ClearButton");
|
||||||
|
|
||||||
|
while (TRUE) {
|
||||||
|
|
||||||
|
// check if button 'set' is pressed
|
||||||
|
if(setState)
|
||||||
|
palSetPad(GPIOD, GPIOD_LED3);
|
||||||
|
|
||||||
|
// check if button 'clear' is pressed
|
||||||
|
if(clearState)
|
||||||
|
palClearPad(GPIOD, GPIOD_LED3);
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
34
demos/powermodes/main.c
Executable file
34
demos/powermodes/main.c
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
#include "glcd.h"
|
||||||
|
|
||||||
|
static GLCDDriver GLCDD1;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
halInit();
|
||||||
|
chSysInit();
|
||||||
|
|
||||||
|
lcdInit(&GLCDD1);
|
||||||
|
lcdClear(Black);
|
||||||
|
lcdDrawString(100, 100, "Hello World", White, Black);
|
||||||
|
|
||||||
|
// wait two seconds to see current LCD content
|
||||||
|
chThdSleepSeconds(2);
|
||||||
|
|
||||||
|
// brings LCD to sleep mode
|
||||||
|
lcdSetPowerMode(sleepOn);
|
||||||
|
|
||||||
|
// wait two seconds to see current LCD content
|
||||||
|
chThdSleepSeconds(2);
|
||||||
|
|
||||||
|
// brings LCD back from sleep mode
|
||||||
|
// content displayed before gets displayed again
|
||||||
|
lcdSetPowerMode(sleepOff);
|
||||||
|
|
||||||
|
while (TRUE) {
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -9,11 +9,12 @@ extern uint16_t lcd_width, lcd_height;
|
|||||||
static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)];
|
static uint16_t buf[((SCREEN_HEIGHT > SCREEN_WIDTH ) ? SCREEN_HEIGHT : SCREEN_WIDTH)];
|
||||||
|
|
||||||
#ifdef LCD_USE_GPIO
|
#ifdef LCD_USE_GPIO
|
||||||
|
|
||||||
static __inline void lld_lcdWriteIndex(uint16_t index) {
|
static __inline void lld_lcdWriteIndex(uint16_t index) {
|
||||||
Clr_RS;
|
Clr_RS;
|
||||||
Set_RD;
|
Set_RD;
|
||||||
|
|
||||||
palWritePort(LCD_DATA_PORT, index);
|
lld_lcdWriteGPIO(index);
|
||||||
|
|
||||||
Clr_WR;
|
Clr_WR;
|
||||||
Set_WR;
|
Set_WR;
|
||||||
@ -22,7 +23,7 @@ static __inline void lld_lcdWriteIndex(uint16_t index) {
|
|||||||
static __inline void lld_lcdWriteData(uint16_t data) {
|
static __inline void lld_lcdWriteData(uint16_t data) {
|
||||||
Set_RS;
|
Set_RS;
|
||||||
|
|
||||||
palWritePort(LCD_DATA_PORT, data);
|
lld_lcdWriteGPIO(data);
|
||||||
|
|
||||||
Clr_WR;
|
Clr_WR;
|
||||||
Set_WR;
|
Set_WR;
|
||||||
@ -30,8 +31,10 @@ static __inline void lld_lcdWriteData(uint16_t data) {
|
|||||||
|
|
||||||
static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
|
static __inline void lld_lcdWriteReg(uint16_t lcdReg,uint16_t lcdRegValue) {
|
||||||
Clr_CS;
|
Clr_CS;
|
||||||
|
|
||||||
lld_lcdWriteIndex(lcdReg);
|
lld_lcdWriteIndex(lcdReg);
|
||||||
lld_lcdWriteData(lcdRegValue);
|
lld_lcdWriteData(lcdRegValue);
|
||||||
|
|
||||||
Set_CS;
|
Set_CS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,16 +45,7 @@ static __inline uint16_t lld_lcdReadData(void) {
|
|||||||
Set_WR;
|
Set_WR;
|
||||||
Clr_RD;
|
Clr_RD;
|
||||||
|
|
||||||
// change pin mode to digital input
|
value = lld_lcdReadGPIO();
|
||||||
LCD_DATA_PORT->CRH = 0x44444444;
|
|
||||||
LCD_DATA_PORT->CRL = 0x44444444;
|
|
||||||
|
|
||||||
value = palReadPort(LCD_DATA_PORT); // dummy
|
|
||||||
value = palReadPort(LCD_DATA_PORT);
|
|
||||||
|
|
||||||
// change pin mode back to digital output
|
|
||||||
LCD_DATA_PORT->CRH = 0x33333333;
|
|
||||||
LCD_DATA_PORT->CRL = 0x33333333;
|
|
||||||
|
|
||||||
Set_RD;
|
Set_RD;
|
||||||
|
|
||||||
@ -72,6 +66,7 @@ static __inline uint16_t lld_lcdReadReg(uint16_t lcdReg) {
|
|||||||
|
|
||||||
__inline void lld_lcdWriteStreamStart(void) {
|
__inline void lld_lcdWriteStreamStart(void) {
|
||||||
Clr_CS;
|
Clr_CS;
|
||||||
|
|
||||||
lld_lcdWriteIndex(0x0022);
|
lld_lcdWriteIndex(0x0022);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +80,7 @@ __inline void lld_lcdWriteStream(uint16_t *buffer, uint16_t size) {
|
|||||||
Set_RS;
|
Set_RS;
|
||||||
|
|
||||||
for(i = 0; i < size; i++) {
|
for(i = 0; i < size; i++) {
|
||||||
palWritePort(LCD_DATA_PORT, buffer[i]);
|
lld_lcdWriteGPIO(buffer[i]);
|
||||||
Clr_WR;
|
Clr_WR;
|
||||||
Set_WR;
|
Set_WR;
|
||||||
}
|
}
|
||||||
@ -112,6 +107,10 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LCD_USE_SPI
|
||||||
|
/* TODO */
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LCD_USE_FSMC
|
#ifdef LCD_USE_FSMC
|
||||||
|
|
||||||
#define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
|
#define LCD_REG (*((volatile uint16_t *) 0x60000000)) /* RS = 0 */
|
||||||
@ -173,15 +172,30 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LCD_USE_SPI
|
static __inline void lld_lcdDelay(uint16_t us) {
|
||||||
/* TODO! */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static __inline void lcdDelay(uint16_t us) {
|
|
||||||
chThdSleepMicroseconds(us);
|
chThdSleepMicroseconds(us);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lld_lcdSetPowerMode(uint8_t powerMode) {
|
||||||
|
switch(powerMode) {
|
||||||
|
case powerOff:
|
||||||
|
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
|
||||||
|
lld_lcdWriteReg(0x0007, 0x0000); // halt operation
|
||||||
|
lld_lcdWriteReg(0x0000, 0x0000); // turn off oszillator
|
||||||
|
lld_lcdWriteReg(0x0010, 0x0001); // enter sleepmode
|
||||||
|
break;
|
||||||
|
case powerOn:
|
||||||
|
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
|
||||||
|
lld_lcdInit();
|
||||||
|
break;
|
||||||
|
case sleepOn:
|
||||||
|
lld_lcdWriteReg(0x0010, 0x0001); // enter sleep mode
|
||||||
|
break;
|
||||||
|
case sleepOff:
|
||||||
|
lld_lcdWriteReg(0x0010, 0x0000); // leave sleep mode
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
|
void lld_lcdSetCursor(uint16_t x, uint16_t y) {
|
||||||
/* Reg 0x004E is an 8 bit value
|
/* Reg 0x004E is an 8 bit value
|
||||||
@ -334,47 +348,47 @@ void lld_lcdInit(void) {
|
|||||||
#endif
|
#endif
|
||||||
DeviceCode = lld_lcdReadReg(0x0000);
|
DeviceCode = lld_lcdReadReg(0x0000);
|
||||||
|
|
||||||
lld_lcdWriteReg(0x0000,0x0001); lcdDelay(5);
|
lld_lcdWriteReg(0x0000,0x0001); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0003,0xA8A4); lcdDelay(5);
|
lld_lcdWriteReg(0x0003,0xA8A4); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x000C,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x000C,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x000D,0x080C); lcdDelay(5);
|
lld_lcdWriteReg(0x000D,0x080C); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x000E,0x2B00); lcdDelay(5);
|
lld_lcdWriteReg(0x000E,0x2B00); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x001E,0x00B0); lcdDelay(5);
|
lld_lcdWriteReg(0x001E,0x00B0); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0001,0x2B3F); lcdDelay(5);
|
lld_lcdWriteReg(0x0001,0x2B3F); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0002,0x0600); lcdDelay(5);
|
lld_lcdWriteReg(0x0002,0x0600); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0010,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0010,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0011,0x6070); lcdDelay(5);
|
lld_lcdWriteReg(0x0011,0x6070); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0005,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0005,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0006,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0006,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0016,0xEF1C); lcdDelay(5);
|
lld_lcdWriteReg(0x0016,0xEF1C); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0017,0x0003); lcdDelay(5);
|
lld_lcdWriteReg(0x0017,0x0003); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0007,0x0133); lcdDelay(5);
|
lld_lcdWriteReg(0x0007,0x0133); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x000B,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x000B,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x000F,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x000F,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0041,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0041,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0042,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0042,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0048,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0048,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0049,0x013F); lcdDelay(5);
|
lld_lcdWriteReg(0x0049,0x013F); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x004A,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x004A,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x004B,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x004B,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0044,0xEF00); lcdDelay(5);
|
lld_lcdWriteReg(0x0044,0xEF00); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0045,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0045,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0046,0x013F); lcdDelay(5);
|
lld_lcdWriteReg(0x0046,0x013F); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0030,0x0707); lcdDelay(5);
|
lld_lcdWriteReg(0x0030,0x0707); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0031,0x0204); lcdDelay(5);
|
lld_lcdWriteReg(0x0031,0x0204); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0032,0x0204); lcdDelay(5);
|
lld_lcdWriteReg(0x0032,0x0204); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0033,0x0502); lcdDelay(5);
|
lld_lcdWriteReg(0x0033,0x0502); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0034,0x0507); lcdDelay(5);
|
lld_lcdWriteReg(0x0034,0x0507); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0035,0x0204); lcdDelay(5);
|
lld_lcdWriteReg(0x0035,0x0204); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0036,0x0204); lcdDelay(5);
|
lld_lcdWriteReg(0x0036,0x0204); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0037,0x0502); lcdDelay(5);
|
lld_lcdWriteReg(0x0037,0x0502); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x003A,0x0302); lcdDelay(5);
|
lld_lcdWriteReg(0x003A,0x0302); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x003B,0x0302); lcdDelay(5);
|
lld_lcdWriteReg(0x003B,0x0302); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0023,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0023,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0024,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x0024,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x0025,0x8000); lcdDelay(5);
|
lld_lcdWriteReg(0x0025,0x8000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x004f,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x004f,0x0000); lld_lcdDelay(5);
|
||||||
lld_lcdWriteReg(0x004e,0x0000); lcdDelay(5);
|
lld_lcdWriteReg(0x004e,0x0000); lld_lcdDelay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t lld_lcdGetOrientation(void) {
|
uint16_t lld_lcdGetOrientation(void) {
|
||||||
|
@ -5,129 +5,6 @@
|
|||||||
|
|
||||||
#ifdef LCD_USE_SSD1289
|
#ifdef LCD_USE_SSD1289
|
||||||
|
|
||||||
#ifdef LCD_USE_GPIO
|
|
||||||
#define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS);
|
|
||||||
#define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS);
|
|
||||||
#define Set_RS palSetPad(LCD_CMD_PORT, LCD_RS);
|
|
||||||
#define Clr_RS palClearPad(LCD_CMD_PORT, LCD_RS);
|
|
||||||
#define Set_WR palSetPad(LCD_CMD_PORT, LCD_WR);
|
|
||||||
#define Clr_WR palClearPad(LCD_CMD_PORT, LCD_WR);
|
|
||||||
#define Set_RD palSetPad(LCD_CMD_PORT, LCD_RD);
|
|
||||||
#define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LCD_USE_FSMC
|
|
||||||
/* LCD Registers */
|
|
||||||
#define R0 0x00
|
|
||||||
#define R1 0x01
|
|
||||||
#define R2 0x02
|
|
||||||
#define R3 0x03
|
|
||||||
#define R4 0x04
|
|
||||||
#define R5 0x05
|
|
||||||
#define R6 0x06
|
|
||||||
#define R7 0x07
|
|
||||||
#define R8 0x08
|
|
||||||
#define R9 0x09
|
|
||||||
#define R10 0x0A
|
|
||||||
#define R12 0x0C
|
|
||||||
#define R13 0x0D
|
|
||||||
#define R14 0x0E
|
|
||||||
#define R15 0x0F
|
|
||||||
#define R16 0x10
|
|
||||||
#define R17 0x11
|
|
||||||
#define R18 0x12
|
|
||||||
#define R19 0x13
|
|
||||||
#define R20 0x14
|
|
||||||
#define R21 0x15
|
|
||||||
#define R22 0x16
|
|
||||||
#define R23 0x17
|
|
||||||
#define R24 0x18
|
|
||||||
#define R25 0x19
|
|
||||||
#define R26 0x1A
|
|
||||||
#define R27 0x1B
|
|
||||||
#define R28 0x1C
|
|
||||||
#define R29 0x1D
|
|
||||||
#define R30 0x1E
|
|
||||||
#define R31 0x1F
|
|
||||||
#define R32 0x20
|
|
||||||
#define R33 0x21
|
|
||||||
#define R34 0x22
|
|
||||||
#define R36 0x24
|
|
||||||
#define R37 0x25
|
|
||||||
#define R40 0x28
|
|
||||||
#define R41 0x29
|
|
||||||
#define R43 0x2B
|
|
||||||
#define R45 0x2D
|
|
||||||
#define R48 0x30
|
|
||||||
#define R49 0x31
|
|
||||||
#define R50 0x32
|
|
||||||
#define R51 0x33
|
|
||||||
#define R52 0x34
|
|
||||||
#define R53 0x35
|
|
||||||
#define R54 0x36
|
|
||||||
#define R55 0x37
|
|
||||||
#define R56 0x38
|
|
||||||
#define R57 0x39
|
|
||||||
#define R59 0x3B
|
|
||||||
#define R60 0x3C
|
|
||||||
#define R61 0x3D
|
|
||||||
#define R62 0x3E
|
|
||||||
#define R63 0x3F
|
|
||||||
#define R64 0x40
|
|
||||||
#define R65 0x41
|
|
||||||
#define R66 0x42
|
|
||||||
#define R67 0x43
|
|
||||||
#define R68 0x44
|
|
||||||
#define R69 0x45
|
|
||||||
#define R70 0x46
|
|
||||||
#define R71 0x47
|
|
||||||
#define R72 0x48
|
|
||||||
#define R73 0x49
|
|
||||||
#define R74 0x4A
|
|
||||||
#define R75 0x4B
|
|
||||||
#define R76 0x4C
|
|
||||||
#define R77 0x4D
|
|
||||||
#define R78 0x4E
|
|
||||||
#define R79 0x4F
|
|
||||||
#define R80 0x50
|
|
||||||
#define R81 0x51
|
|
||||||
#define R82 0x52
|
|
||||||
#define R83 0x53
|
|
||||||
#define R96 0x60
|
|
||||||
#define R97 0x61
|
|
||||||
#define R106 0x6A
|
|
||||||
#define R118 0x76
|
|
||||||
#define R128 0x80
|
|
||||||
#define R129 0x81
|
|
||||||
#define R130 0x82
|
|
||||||
#define R131 0x83
|
|
||||||
#define R132 0x84
|
|
||||||
#define R133 0x85
|
|
||||||
#define R134 0x86
|
|
||||||
#define R135 0x87
|
|
||||||
#define R136 0x88
|
|
||||||
#define R137 0x89
|
|
||||||
#define R139 0x8B
|
|
||||||
#define R140 0x8C
|
|
||||||
#define R141 0x8D
|
|
||||||
#define R143 0x8F
|
|
||||||
#define R144 0x90
|
|
||||||
#define R145 0x91
|
|
||||||
#define R146 0x92
|
|
||||||
#define R147 0x93
|
|
||||||
#define R148 0x94
|
|
||||||
#define R149 0x95
|
|
||||||
#define R150 0x96
|
|
||||||
#define R151 0x97
|
|
||||||
#define R152 0x98
|
|
||||||
#define R153 0x99
|
|
||||||
#define R154 0x9A
|
|
||||||
#define R157 0x9D
|
|
||||||
#define R192 0xC0
|
|
||||||
#define R193 0xC1
|
|
||||||
#define R229 0xE5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -142,6 +19,7 @@ void lld_lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
|||||||
void lld_lcdClear(uint16_t color);
|
void lld_lcdClear(uint16_t color);
|
||||||
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color);
|
void lld_lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color);
|
||||||
void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
|
void lld_lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
|
||||||
|
void lld_lcdSetPowerMode(uint8_t powerMode);
|
||||||
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
uint16_t lld_lcdGetPixelColor(uint16_t x, uint16_t y);
|
||||||
uint16_t lld_lcdGetOrientation(void);
|
uint16_t lld_lcdGetOrientation(void);
|
||||||
uint16_t lld_lcdGetHeight(void);
|
uint16_t lld_lcdGetHeight(void);
|
||||||
@ -152,6 +30,133 @@ void lld_lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, i
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LCD_USE_GPIO
|
||||||
|
#define Set_CS palSetPad(LCD_CMD_PORT, LCD_CS);
|
||||||
|
#define Clr_CS palClearPad(LCD_CMD_PORT, LCD_CS);
|
||||||
|
#define Set_RS palSetPad(LCD_CMD_PORT, LCD_RS);
|
||||||
|
#define Clr_RS palClearPad(LCD_CMD_PORT, LCD_RS);
|
||||||
|
#define Set_WR palSetPad(LCD_CMD_PORT, LCD_WR);
|
||||||
|
#define Clr_WR palClearPad(LCD_CMD_PORT, LCD_WR);
|
||||||
|
#define Set_RD palSetPad(LCD_CMD_PORT, LCD_RD);
|
||||||
|
#define Clr_RD palClearPad(LCD_CMD_PORT, LCD_RD);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LCD_USE_SPI
|
||||||
|
/* TODO */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LCD_USE_FSMC
|
||||||
|
/* LCD Registers */
|
||||||
|
#define R0 0x00
|
||||||
|
#define R1 0x01
|
||||||
|
#define R2 0x02
|
||||||
|
#define R3 0x03
|
||||||
|
#define R4 0x04
|
||||||
|
#define R5 0x05
|
||||||
|
#define R6 0x06
|
||||||
|
#define R7 0x07
|
||||||
|
#define R8 0x08
|
||||||
|
#define R9 0x09
|
||||||
|
#define R10 0x0A
|
||||||
|
#define R12 0x0C
|
||||||
|
#define R13 0x0D
|
||||||
|
#define R14 0x0E
|
||||||
|
#define R15 0x0F
|
||||||
|
#define R16 0x10
|
||||||
|
#define R17 0x11
|
||||||
|
#define R18 0x12
|
||||||
|
#define R19 0x13
|
||||||
|
#define R20 0x14
|
||||||
|
#define R21 0x15
|
||||||
|
#define R22 0x16
|
||||||
|
#define R23 0x17
|
||||||
|
#define R24 0x18
|
||||||
|
#define R25 0x19
|
||||||
|
#define R26 0x1A
|
||||||
|
#define R27 0x1B
|
||||||
|
#define R28 0x1C
|
||||||
|
#define R29 0x1D
|
||||||
|
#define R30 0x1E
|
||||||
|
#define R31 0x1F
|
||||||
|
#define R32 0x20
|
||||||
|
#define R33 0x21
|
||||||
|
#define R34 0x22
|
||||||
|
#define R36 0x24
|
||||||
|
#define R37 0x25
|
||||||
|
#define R40 0x28
|
||||||
|
#define R41 0x29
|
||||||
|
#define R43 0x2B
|
||||||
|
#define R45 0x2D
|
||||||
|
#define R48 0x30
|
||||||
|
#define R49 0x31
|
||||||
|
#define R50 0x32
|
||||||
|
#define R51 0x33
|
||||||
|
#define R52 0x34
|
||||||
|
#define R53 0x35
|
||||||
|
#define R54 0x36
|
||||||
|
#define R55 0x37
|
||||||
|
#define R56 0x38
|
||||||
|
#define R57 0x39
|
||||||
|
#define R59 0x3B
|
||||||
|
#define R60 0x3C
|
||||||
|
#define R61 0x3D
|
||||||
|
#define R62 0x3E
|
||||||
|
#define R63 0x3F
|
||||||
|
#define R64 0x40
|
||||||
|
#define R65 0x41
|
||||||
|
#define R66 0x42
|
||||||
|
#define R67 0x43
|
||||||
|
#define R68 0x44
|
||||||
|
#define R69 0x45
|
||||||
|
#define R70 0x46
|
||||||
|
#define R71 0x47
|
||||||
|
#define R72 0x48
|
||||||
|
#define R73 0x49
|
||||||
|
#define R74 0x4A
|
||||||
|
#define R75 0x4B
|
||||||
|
#define R76 0x4C
|
||||||
|
#define R77 0x4D
|
||||||
|
#define R78 0x4E
|
||||||
|
#define R79 0x4F
|
||||||
|
#define R80 0x50
|
||||||
|
#define R81 0x51
|
||||||
|
#define R82 0x52
|
||||||
|
#define R83 0x53
|
||||||
|
#define R96 0x60
|
||||||
|
#define R97 0x61
|
||||||
|
#define R106 0x6A
|
||||||
|
#define R118 0x76
|
||||||
|
#define R128 0x80
|
||||||
|
#define R129 0x81
|
||||||
|
#define R130 0x82
|
||||||
|
#define R131 0x83
|
||||||
|
#define R132 0x84
|
||||||
|
#define R133 0x85
|
||||||
|
#define R134 0x86
|
||||||
|
#define R135 0x87
|
||||||
|
#define R136 0x88
|
||||||
|
#define R137 0x89
|
||||||
|
#define R139 0x8B
|
||||||
|
#define R140 0x8C
|
||||||
|
#define R141 0x8D
|
||||||
|
#define R143 0x8F
|
||||||
|
#define R144 0x90
|
||||||
|
#define R145 0x91
|
||||||
|
#define R146 0x92
|
||||||
|
#define R147 0x93
|
||||||
|
#define R148 0x94
|
||||||
|
#define R149 0x95
|
||||||
|
#define R150 0x96
|
||||||
|
#define R151 0x97
|
||||||
|
#define R152 0x98
|
||||||
|
#define R153 0x99
|
||||||
|
#define R154 0x9A
|
||||||
|
#define R157 0x9D
|
||||||
|
#define R192 0xC0
|
||||||
|
#define R193 0xC1
|
||||||
|
#define R229 0xE5
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
8
glcd.c
8
glcd.c
@ -8,8 +8,8 @@ uint16_t lcd_width, lcd_height;
|
|||||||
void lcdInit(GLCDDriver *glcdp) {
|
void lcdInit(GLCDDriver *glcdp) {
|
||||||
|
|
||||||
lld_lcdInit();
|
lld_lcdInit();
|
||||||
lcd_width = SCREEN_WIDTH;
|
lcd_width = lcdGetWidth();
|
||||||
lcd_height = SCREEN_HEIGHT;
|
lcd_height = lcdGetHeight();
|
||||||
|
|
||||||
lcdSetOrientation(portrait);
|
lcdSetOrientation(portrait);
|
||||||
}
|
}
|
||||||
@ -30,6 +30,10 @@ static void lcdSetCursor(uint16_t x, uint16_t y) {
|
|||||||
lld_lcdSetCursor(x, y);
|
lld_lcdSetCursor(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcdSetPowerMode(uint8_t powerMode) {
|
||||||
|
lld_lcdSetPowerMode(powerMode);
|
||||||
|
}
|
||||||
|
|
||||||
void lcdSetOrientation(uint8_t newOrientation) {
|
void lcdSetOrientation(uint8_t newOrientation) {
|
||||||
lld_lcdSetOrientation(newOrientation);
|
lld_lcdSetOrientation(newOrientation);
|
||||||
}
|
}
|
||||||
|
5
glcd.h
5
glcd.h
@ -12,9 +12,6 @@
|
|||||||
#include "ssd1289_lld.h"
|
#include "ssd1289_lld.h"
|
||||||
#include "s6d1121_lld.h"
|
#include "s6d1121_lld.h"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 240
|
|
||||||
#define SCREEN_HEIGHT 320
|
|
||||||
|
|
||||||
#define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv)
|
#define PORTRAIT (lcdGetOrientation() == portrait || lcdGetOrientation() == portraitInv)
|
||||||
#define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv)
|
#define LANDSCAPE (lcdGetOrientation() == landscape || lcdGetOrientation() == landscapeInv)
|
||||||
|
|
||||||
@ -36,6 +33,7 @@
|
|||||||
enum orientation {portrait, landscape, portraitInv, landscapeInv};
|
enum orientation {portrait, landscape, portraitInv, landscapeInv};
|
||||||
enum filled {frame, filled};
|
enum filled {frame, filled};
|
||||||
enum transparency {solid, transparent};
|
enum transparency {solid, transparent};
|
||||||
|
enum powermode {powerOff, powerOn, sleepOn, sleepOff};
|
||||||
|
|
||||||
typedef const uint8_t* font_t;
|
typedef const uint8_t* font_t;
|
||||||
|
|
||||||
@ -62,6 +60,7 @@ void lcdSetOrientation(uint8_t newOrientation);
|
|||||||
void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
void lcdSetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||||
void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
|
void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
|
||||||
void lcdWriteArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *buffer, size_t n);
|
void lcdWriteArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t *buffer, size_t n);
|
||||||
|
void lcdSetPowerMode(uint8_t powerMode);
|
||||||
|
|
||||||
/* Drawing functions */
|
/* Drawing functions */
|
||||||
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point);
|
void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t point);
|
||||||
|
24
graph.c
24
graph.c
@ -1,26 +1,26 @@
|
|||||||
#include "glcd.h"
|
#include "glcd.h"
|
||||||
|
|
||||||
#define GRID_X 20
|
|
||||||
#define GRID_Y 20
|
|
||||||
|
|
||||||
#define MARKSIZE 5 // half
|
#define MARKSIZE 5 // half
|
||||||
|
|
||||||
static uint16_t x, y; // origins in graph
|
static uint16_t x, y; // origins in graph
|
||||||
|
static uint16_t grid_X, grid_Y; //grids
|
||||||
|
|
||||||
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
|
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color) {
|
||||||
uint16_t i, length;
|
uint16_t i, length;
|
||||||
volatile uint16_t off;
|
volatile uint16_t off;
|
||||||
|
|
||||||
x = x0;
|
x = x0;
|
||||||
y = y0;
|
y = y0;
|
||||||
|
grid_X = gridX;
|
||||||
|
grid_Y = gridY;
|
||||||
|
|
||||||
// X-Axis
|
// X-Axis
|
||||||
length = x1 - x0;
|
length = x1 - x0;
|
||||||
lcdDrawLine(x0, y0, x1, y0, color);
|
lcdDrawLine(x0, y0, x1, y0, color);
|
||||||
lcdDrawLine(x1, y0, x1-5, y0+5, color);
|
lcdDrawLine(x1, y0, x1-5, y0+5, color);
|
||||||
lcdDrawLine(x1, y0, x1-5, y0-5, color);
|
lcdDrawLine(x1, y0, x1-5, y0-5, color);
|
||||||
for(i=1; i<(length / GRID_X); i++) {
|
for(i=1; i<(length / grid_X); i++) {
|
||||||
off = x0 + i*GRID_X;
|
off = x0 + i * grid_X;
|
||||||
lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color);
|
lcdDrawLine(off, y0-MARKSIZE, off, y0+MARKSIZE, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,25 +29,25 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
|
|||||||
lcdDrawLine(x0, y0, x0, y1, color);
|
lcdDrawLine(x0, y0, x0, y1, color);
|
||||||
lcdDrawLine(x0, y1, x0-5, y1+5, color);
|
lcdDrawLine(x0, y1, x0-5, y1+5, color);
|
||||||
lcdDrawLine(x0, y1, x0+5, y1+5, color);
|
lcdDrawLine(x0, y1, x0+5, y1+5, color);
|
||||||
for(i=1; i<(length / GRID_Y); i++) {
|
for(i=1; i<(length / grid_Y); i++) {
|
||||||
off = x0 + i*GRID_Y;
|
off = y0 + i * grid_Y;
|
||||||
lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color);
|
lcdDrawLine(x0-MARKSIZE, off, x0+MARKSIZE, off, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t color) {
|
void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
for(i=0; i<entries; i++)
|
for(i = 0; i < entries; i++)
|
||||||
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, color);
|
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void graphDrawNet(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) {
|
void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) {
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
for(i = 0; i < entries; ++i)
|
for(i = 0; i < entries; ++i)
|
||||||
lcdDrawLine(coord[i-1][0]+x, y-coord[i-1][1], coord[i][0]+x, y-coord[i][1], lineColor);
|
lcdDrawLine(coord[i-1][0]+x, y-coord[i-1][1], coord[i][0]+x, y-coord[i][1], lineColor);
|
||||||
for(i=0; i<entries; ++i)
|
for(i = 0; i < entries; ++i)
|
||||||
if(radius != 0)
|
if(radius != 0)
|
||||||
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, dotColor);
|
lcdDrawCircle(coord[i][0]+x, y-coord[i][1], radius, 1, dotColor);
|
||||||
}
|
}
|
||||||
|
7
graph.h
7
graph.h
@ -11,11 +11,12 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* param:
|
* param:
|
||||||
* - x0, y0, x1, y1: location of arrows
|
* - x0, y0, x1, y1: location of arrows
|
||||||
|
* - gridX, gridY: grid size in X and Y direction
|
||||||
* - color: color of arrows
|
* - color: color of arrows
|
||||||
*
|
*
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
|
void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t gridX, uint16_t gridY, uint16_t color);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: does draw coordinates into graph as dots
|
* Description: does draw coordinates into graph as dots
|
||||||
@ -28,7 +29,7 @@ void graphDrawSystem(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_
|
|||||||
*
|
*
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t color);
|
void graphDrawDots(int coord[][2], uint16_t entries, uint16_t radius, uint16_t color);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: does draw coordinates into graph connected by lines
|
* Description: does draw coordinates into graph connected by lines
|
||||||
@ -42,7 +43,7 @@ void graphDrawDots(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16
|
|||||||
*
|
*
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void graphDrawNet(int16_t coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor);
|
void graphDrawNet(int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
284
gui.c
284
gui.c
@ -1,109 +1,225 @@
|
|||||||
#include "ch.h"
|
|
||||||
#include "hal.h"
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "glcd.h"
|
|
||||||
#include "touchpad.h"
|
|
||||||
|
|
||||||
uint16_t x, y;
|
static struct guiNode_t *firstGUI = NULL;
|
||||||
unsigned char buffer[32];
|
|
||||||
|
static uint8_t addElement(struct guiNode_t *newNode) {
|
||||||
|
struct guiNode_t *new;
|
||||||
|
|
||||||
|
if(firstGUI == NULL) {
|
||||||
|
firstGUI = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
|
if(firstGUI == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*firstGUI = *newNode;
|
||||||
|
firstGUI->next = NULL;
|
||||||
|
} else {
|
||||||
|
new = firstGUI;
|
||||||
|
while(new->next != NULL)
|
||||||
|
new = new->next;
|
||||||
|
|
||||||
|
new->next = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
|
if(new->next == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
new = new->next;
|
||||||
|
*new = *newNode;
|
||||||
|
new->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t deleteElement(char *label) {
|
||||||
|
struct guiNode_t *pointer, *pointer1;
|
||||||
|
|
||||||
|
if(firstGUI != NULL) {
|
||||||
|
if(strcmp(firstGUI->label, label) == 0) {
|
||||||
|
pointer = firstGUI->next;
|
||||||
|
chHeapFree(firstGUI);
|
||||||
|
firstGUI = pointer;
|
||||||
|
} else {
|
||||||
|
pointer = firstGUI;
|
||||||
|
|
||||||
|
while(pointer->next != NULL) {
|
||||||
|
pointer1 = pointer->next;
|
||||||
|
|
||||||
|
if(strcmp(firstGUI->label, label) == 0) {
|
||||||
|
pointer->next = pointer1->next;
|
||||||
|
chHeapFree(pointer1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer = pointer1;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1; // successful
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // not successful
|
||||||
|
}
|
||||||
|
|
||||||
|
void guiPrintElements(BaseSequentialStream *chp) {
|
||||||
|
struct guiNode_t *pointer = firstGUI;
|
||||||
|
|
||||||
|
chprintf(chp, "\r\n\nguiNodes:\r\n\n");
|
||||||
|
|
||||||
|
while(pointer != NULL) {
|
||||||
|
chprintf(chp, "x0: %d\r\n", pointer->x0);
|
||||||
|
chprintf(chp, "y0: %d\r\n", pointer->y0);
|
||||||
|
chprintf(chp, "x1: %d\r\n", pointer->x1);
|
||||||
|
chprintf(chp, "y1: %d\r\n", pointer->y1);
|
||||||
|
chprintf(chp, "label: %s\r\n", pointer->label);
|
||||||
|
chprintf(chp, "active: %d\r\n", *(pointer->active));
|
||||||
|
chprintf(chp, "state: %d\r\n", *(pointer->state));
|
||||||
|
chprintf(chp, "*next: 0x%x\r\n", pointer->next);
|
||||||
|
chprintf(chp, "\r\n\n");
|
||||||
|
pointer = pointer->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void guiThread(const uint16_t interval) {
|
||||||
|
uint16_t x, y;
|
||||||
|
struct guiNode_t *node;
|
||||||
|
|
||||||
static void TouchPadThread(uint16_t updateInterval) {
|
|
||||||
chRegSetThreadName("GUI");
|
chRegSetThreadName("GUI");
|
||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
|
for(node = firstGUI; node; node = node->next) {
|
||||||
|
// check if GUI element is active
|
||||||
|
if(*(node->active) == active) {
|
||||||
x = tpReadX();
|
x = tpReadX();
|
||||||
y = tpReadY();
|
y = tpReadY();
|
||||||
|
|
||||||
chThdSleepMilliseconds(updateInterval);
|
// we got a button
|
||||||
}
|
if(node->type == button) {
|
||||||
}
|
if(x >= node->x0 && x <= node->x1 && y >= node->y0 && y <= node->y1)
|
||||||
|
*(node->state) = 1;
|
||||||
static void buttonThread(struct button_t *a) {
|
|
||||||
uint16_t x0, y0, x1, y1;
|
|
||||||
|
|
||||||
x0 = a->x0;
|
|
||||||
y0 = a->y0;
|
|
||||||
x1 = a->x1;
|
|
||||||
y1 = a->y1;
|
|
||||||
|
|
||||||
while(TRUE) {
|
|
||||||
if(x >= x0 && x <= x1 && y >= y0 && y <= y1)
|
|
||||||
*(a->state) = 1;
|
|
||||||
else
|
else
|
||||||
*(a->state) = 0;
|
*(node->state) = 0;
|
||||||
|
} else {
|
||||||
|
*(node->state) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
chThdSleepMilliseconds(a->interval);
|
// we got a slider
|
||||||
|
if(node->type == slider) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a wheel
|
||||||
|
if(node->type == wheel) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a keymatrix
|
||||||
|
if(node->type == keymatrix) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void barThread(struct bar_t *a) {
|
Thread *guiInit(uint16_t interval, tprio_t priority) {
|
||||||
uint16_t percent = 0, value = 0, value_old = 0;
|
|
||||||
|
|
||||||
while(TRUE) {
|
|
||||||
percent = *(a->percent);
|
|
||||||
if(percent > 100)
|
|
||||||
percent = 100;
|
|
||||||
|
|
||||||
if(a->orientation == horizontal) {
|
|
||||||
value = ((((a->x1)-(a->x0)) * percent) / 100);
|
|
||||||
if(value_old > value || value == 0)
|
|
||||||
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
|
|
||||||
else
|
|
||||||
lcdDrawRect(a->x0+1, a->y0+1, a->x0+value, a->y1, filled, a->valueColor);
|
|
||||||
} else if(a->orientation == vertical) {
|
|
||||||
value = ((((a->y1)-(a->y0)) * percent) / 100);
|
|
||||||
if(value_old > value || value == 0)
|
|
||||||
lcdFillArea(a->x0+1, a->y0+1, a->x1, a->y1, a->bkColor);
|
|
||||||
else
|
|
||||||
lcdDrawRect(a->x0+1, a->y0+1, a->x1, a->y0+value, filled, a->valueColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
value_old = value;
|
|
||||||
chThdSleepMilliseconds(a->interval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void guiInit(uint16_t updateInterval) {
|
|
||||||
Thread *tp = NULL;
|
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), HIGHPRIO-1, TouchPadThread, updateInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t interval, uint8_t *state) {
|
|
||||||
struct button_t *button;
|
|
||||||
Thread *tp = NULL;
|
Thread *tp = NULL;
|
||||||
|
|
||||||
button = chHeapAlloc(NULL, sizeof(struct button_t));
|
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(512), priority, guiThread, interval);
|
||||||
button->x0 = x0;
|
|
||||||
button->y0 = y0;
|
return tp;
|
||||||
button->x1 = x1;
|
}
|
||||||
button->y1 = y1;
|
|
||||||
button->state = state;
|
uint8_t guiDeleteElement(char *label) {
|
||||||
button->interval = interval;
|
return deleteElement(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state) {
|
||||||
|
struct guiNode_t *newNode;
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
|
if(newNode == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
newNode->type = button;
|
||||||
|
newNode->label = label;
|
||||||
|
newNode->x0 = x0;
|
||||||
|
newNode->y0 = y0;
|
||||||
|
newNode->x1 = x1;
|
||||||
|
newNode->y1 = y1;
|
||||||
|
newNode->label = str;
|
||||||
|
newNode->active = active;
|
||||||
|
newNode->state = state;
|
||||||
|
|
||||||
|
if(addElement(newNode) != 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor);
|
lcdDrawRectString(x0, y0, x1, y1, str, font, fontColor, buttonColor);
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, buttonThread, button);
|
|
||||||
|
|
||||||
return tp;
|
if(shadow != 0) {
|
||||||
|
for(i = 0; i < shadow; i++) {
|
||||||
|
lcdDrawLine(x0+shadow, y1+i, x1+shadow-1, y1+i, Black);
|
||||||
|
lcdDrawLine(x1+i, y0+shadow, x1+i, y1+shadow-1, Black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chHeapFree(newNode);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent) {
|
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
||||||
struct bar_t *bar;
|
struct guiNode_t *newNode;
|
||||||
Thread *tp = NULL;
|
|
||||||
|
|
||||||
bar = chHeapAlloc(NULL, sizeof(struct bar_t));
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
bar->x0 = x0;
|
if(newNode == NULL)
|
||||||
bar->y0 = y0;
|
return 0;
|
||||||
bar->x1 = x1;
|
|
||||||
bar->y1 = y1;
|
|
||||||
bar->orientation = orientation;
|
|
||||||
bar->frameColor = frameColor;
|
|
||||||
bar->bkColor = bkColor;
|
|
||||||
bar->valueColor = valueColor;
|
|
||||||
bar->percent = percent;
|
|
||||||
bar->interval = interval;
|
|
||||||
|
|
||||||
lcdDrawRect(x0, y0, x1, y1, frame, frameColor);
|
newNode->type = slider;
|
||||||
tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(64), NORMALPRIO, barThread, bar);
|
newNode->type = label;
|
||||||
|
newNode->x0 = x0;
|
||||||
|
newNode->y0 = y0;
|
||||||
|
newNode->x1 = x1;
|
||||||
|
newNode->y1 = y1;
|
||||||
|
newNode->state = value;
|
||||||
|
newNode->active = active;
|
||||||
|
newNode->orientation = orientation;
|
||||||
|
|
||||||
return tp;
|
if(addElement(newNode) != 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// lcdDraw functions
|
||||||
|
|
||||||
|
chHeapFree(newNode);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value) {
|
||||||
|
struct guiNode_t *newNode;
|
||||||
|
|
||||||
|
newNode = chHeapAlloc(NULL, sizeof(struct guiNode_t));
|
||||||
|
if(newNode == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
newNode->type = wheel;
|
||||||
|
newNode->label = label;
|
||||||
|
newNode->x0 = x0;
|
||||||
|
newNode->y0 = y0;
|
||||||
|
newNode->r1 = radius1;
|
||||||
|
newNode->r2 = radius2;
|
||||||
|
newNode->active = active;
|
||||||
|
newNode->state = value;
|
||||||
|
|
||||||
|
if(addElement(newNode) != 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// lcdDraw functions
|
||||||
|
|
||||||
|
chHeapFree(newNode);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
91
gui.h
91
gui.h
@ -1,7 +1,10 @@
|
|||||||
#ifndef GUI_H
|
#ifndef GUI_H
|
||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
#include "glcd.h"
|
#include "glcd.h"
|
||||||
|
#include "touchpad.h"
|
||||||
|
|
||||||
struct button_t {
|
struct button_t {
|
||||||
uint16_t x0;
|
uint16_t x0;
|
||||||
@ -12,70 +15,78 @@ struct button_t {
|
|||||||
uint16_t interval;
|
uint16_t interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bar_t {
|
static struct guiNode_t {
|
||||||
|
uint8_t type;
|
||||||
uint16_t x0;
|
uint16_t x0;
|
||||||
uint16_t y0;
|
uint16_t y0;
|
||||||
uint16_t x1;
|
uint16_t x1;
|
||||||
uint16_t y1;
|
uint16_t y1;
|
||||||
uint16_t orientation;
|
uint16_t r1;
|
||||||
uint16_t frameColor;
|
uint16_t r2;
|
||||||
uint16_t bkColor;
|
uint8_t orientation;
|
||||||
uint16_t valueColor;
|
uint8_t *active;
|
||||||
uint16_t interval;
|
uint8_t *state;
|
||||||
uint8_t *percent;
|
char *label;
|
||||||
|
struct guiNode_t *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {horizontal, vertical};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum {button, slider, wheel, keymatrix};
|
||||||
|
enum {horizontal, vertical};
|
||||||
|
enum {inactive, active};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: starts main GUI thread which keeps X and Y coordinates of touchpad updated for guiDraw() threads
|
* Description: creates the GUI thread
|
||||||
*
|
*
|
||||||
* param:
|
* param: - interval: thread sleep in milliseconds after each GUI element update
|
||||||
* - updateInterval: update interval in milliseconds until next coordinates read-out
|
* - priority: priority of the thread
|
||||||
*
|
|
||||||
* return: none
|
|
||||||
*/
|
|
||||||
void guiInit(uint16_t updateIntervl);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Description: draws button and creates thread which keeps pressed/unpressed state up-to-date
|
|
||||||
*
|
|
||||||
* param:
|
|
||||||
* - x0, y0, x1, y1: coordinates where button gets drawn
|
|
||||||
* - str: string written centered into button
|
|
||||||
* - fontColor: color of string
|
|
||||||
* - buttonColor: color of button
|
|
||||||
* - interval: interval in ms which updates state
|
|
||||||
* - state: pointer to variable which keeps state (1 = pressed, 0 = unpressed)
|
|
||||||
*
|
*
|
||||||
* return: pointer to created thread
|
* return: pointer to created thread
|
||||||
*/
|
*/
|
||||||
Thread *guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, unsigned char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t inverval, uint8_t *state);
|
Thread *guiInit(uint16_t interval, tprio_t priority);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Description: draws a bar graph and updates it's value
|
* Description: prints all GUI elements structs (linked list)
|
||||||
*
|
*
|
||||||
* param:
|
* param: - chp: pointer to output stream
|
||||||
* - x0, y0, x1, y1: coordinates where bar graph gets drawn
|
|
||||||
* - orientation: horizontal or vertical
|
|
||||||
* - frameColor: color of the frame
|
|
||||||
* - bkColor: color of piece inside bar with is not set
|
|
||||||
* - valueColor: color of value that will be drawn into bar
|
|
||||||
* - interval: interval in ms which updates percentage
|
|
||||||
* - percent: pointer value from 0 to 100 percent
|
|
||||||
*
|
*
|
||||||
* return : pointer to created thread
|
* return: none
|
||||||
*/
|
*/
|
||||||
Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent);
|
|
||||||
|
void guiPrintElements(BaseSequentialStream *chp);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Description: deletes a GUI element from the linked list
|
||||||
|
*
|
||||||
|
* param: - label: label of the element (parameter of each guiDrawXXX function)
|
||||||
|
*
|
||||||
|
* return: 1 if successful, 0 otherwise
|
||||||
|
*/
|
||||||
|
uint8_t guiDeleteElement(char *label);
|
||||||
|
/*
|
||||||
|
* Description: draws a button on the screen and keeps it's state up to date
|
||||||
|
*
|
||||||
|
* param: - x0, y0, x1, y1: start and end coordinates of the button's rectangle
|
||||||
|
* - str: string that gets drawn into the rectangle - button's lable
|
||||||
|
* - fontColor: color of the lable
|
||||||
|
* - buttonColor: color of the rectangle
|
||||||
|
* - shadow: draws a black shadow with N pixels size if != 0
|
||||||
|
* - active: pass pointer to variable which holds the state 'active' or 'inactive'
|
||||||
|
* - state: pass pointer to variable whcih will keep the state of the button (pressed / unpressed)'
|
||||||
|
*
|
||||||
|
* return: 1 if button successfully created
|
||||||
|
*/
|
||||||
|
uint8_t guiDrawButton(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, char *str, font_t font, uint16_t fontColor, uint16_t buttonColor, uint16_t shadow, char *label, uint8_t *active, uint8_t *state);
|
||||||
|
|
||||||
|
uint8_t guiDrawSlider(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
||||||
|
|
||||||
|
uint8_t guiDrawWheel(uint16_t x0, uint16_t y0, uint16_t radius1, uint16_t radius2, uint16_t bkColor, uint16_t valueColor, char *label, uint8_t *active, uint8_t *value);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
46
readme
46
readme
@ -1,47 +1,13 @@
|
|||||||
Chibios LCD Driver
|
please read the wiki pages to this project carefully, before you ask any questions:
|
||||||
|
|
||||||
### checkout Driver code into ext/
|
http://chibios.org/dokuwiki/doku.php?id=chibios:community
|
||||||
cd chibios/ext
|
|
||||||
git clone https://github.com/tectu/Chibios-LCD-Driver lcd
|
|
||||||
|
|
||||||
### Edit boardfiles:
|
|
||||||
add the following to your board.h file, matching to your pinconfig:
|
|
||||||
#define TP_PORT GPIOC
|
|
||||||
#define TP_IRQ 4
|
|
||||||
#define TP_CS 6
|
|
||||||
|
|
||||||
#define LCD_DATA_PORT GPIOE
|
|
||||||
#define LCD_CMD_PORT GPIOD
|
|
||||||
#define LCD_CS 12
|
|
||||||
#define LCD_RS 13
|
|
||||||
#define LCD_WR 14
|
|
||||||
#define LCD_RD 15
|
|
||||||
|
|
||||||
### Edit Makefile:
|
### Maintainer & Contributors
|
||||||
include lcd.mk:
|
Contributors: - Badger
|
||||||
include $(CHIBIOS)/ext/lcd/lcd.mk
|
- Abhishek
|
||||||
|
|
||||||
Add $(LCDSRC) to CSRC:
|
Maintainer: - Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||||
CSRC = $(PORTSRC) \
|
|
||||||
$(KERNSRC) \
|
|
||||||
$(TESTSRC) \
|
|
||||||
$(HALSRC) \
|
|
||||||
$(PLATFORMSRC) \
|
|
||||||
$(BOARDSRC) \
|
|
||||||
$(FATFSSRC) \
|
|
||||||
$(LCDSRC) \
|
|
||||||
$(CHIBIOS)/os/various/evtimer.c \
|
|
||||||
$(CHIBIOS)/os/various/syscalls.c
|
|
||||||
|
|
||||||
Add $(LCDINC) to INCDIR:
|
|
||||||
INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
|
|
||||||
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
|
|
||||||
$(FATFSINC) \
|
|
||||||
$(LCDINC) \
|
|
||||||
$(CHIBIOS)/os/various ../common
|
|
||||||
|
|
||||||
### Use
|
|
||||||
1. include header files wherever you need it.
|
|
||||||
|
|
||||||
2. select the controller type you want to use in glcdconf.h
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user