get pixel return value implemented in struct
This commit is contained in:
commit
e4094ad468
15 changed files with 131 additions and 119 deletions
14
demos/README
14
demos/README
|
@ -2,17 +2,3 @@ This are a few demos, showing how to use the library.
|
|||
|
||||
Please note that this are not compilable projects.
|
||||
|
||||
|
||||
Your boarfile do need to contain the following informations:
|
||||
|
||||
#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
|
||||
|
||||
|
|
30
demos/console/main.c
Executable file
30
demos/console/main.c
Executable file
|
@ -0,0 +1,30 @@
|
|||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "glcd.h"
|
||||
#include "test.h"
|
||||
#include "console.h"
|
||||
|
||||
static GLCDDriver GLCDD1;
|
||||
static GLCDConsole CON1;
|
||||
|
||||
int main(void) {
|
||||
halInit();
|
||||
chSysInit();
|
||||
|
||||
// init LCD and clear it
|
||||
lcdInit(&GLCDD1);
|
||||
lcdClear(Black);
|
||||
|
||||
// init console
|
||||
lcdConsoleInit(&CON1, 0, 0, lcdGetWidth(), lcdGetHeight(), font_Small, Black, White);
|
||||
|
||||
// use test thread for console output
|
||||
TestThread((BaseSequentialStream*)&CON1);
|
||||
|
||||
while (TRUE) {
|
||||
|
||||
chThdSleepMilliseconds(200);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -100,16 +100,16 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|||
uint16_t i;
|
||||
volatile uint16_t dummy;
|
||||
|
||||
dummy = lld_lcdReadGPIO();
|
||||
dummy = lld_lcdReadData();
|
||||
for(i = 0; i < size; i++)
|
||||
buffer[i] = lld_lcdReadData();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // LCD_USE_GPIO
|
||||
|
||||
#ifdef LCD_USE_SPI
|
||||
/* TODO */
|
||||
#endif
|
||||
#endif // LCD_USE_SPI
|
||||
|
||||
#ifdef LCD_USE_FSMC
|
||||
|
||||
|
@ -170,7 +170,7 @@ __inline void lld_lcdReadStream(uint16_t *buffer, size_t size) {
|
|||
buffer[i] = LCD_RAM;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // LCD_USE_FSMC
|
||||
|
||||
static __inline void lld_lcdDelay(uint16_t us) {
|
||||
chThdSleepMicroseconds(us);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#ifdef TOUCHPAD_USE_ADS7843
|
||||
|
||||
__inline uint16_t lld_readX(void) {
|
||||
__inline uint16_t lld_tpReadX(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t x;
|
||||
|
@ -19,7 +19,7 @@ __inline uint16_t lld_readX(void) {
|
|||
return x;
|
||||
}
|
||||
|
||||
__inline uint16_t lld_readY(void) {
|
||||
__inline uint16_t lld_tpReadY(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
@ -36,7 +36,7 @@ __inline uint16_t lld_readY(void) {
|
|||
return y;
|
||||
}
|
||||
|
||||
__inline uint16_t lld_readZ(void) {
|
||||
__inline uint16_t lld_tpReadZ(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#ifdef TOUCHPAD_USE_ADS7843
|
||||
|
||||
uint16_t lld_readX(void);
|
||||
uint16_t lld_readY(void);
|
||||
uint16_t lld_readZ(void);
|
||||
uint16_t lld_tpReadX(void);
|
||||
uint16_t lld_tpReadY(void);
|
||||
uint16_t lld_tpReadZ(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#ifdef TOUCHPAD_USE_XPT2046
|
||||
|
||||
__inline uint16_t lld_readX(void) {
|
||||
__inline uint16_t lld_tpReadX(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t x;
|
||||
|
@ -19,7 +19,7 @@ __inline uint16_t lld_readX(void) {
|
|||
return x;
|
||||
}
|
||||
|
||||
__inline uint16_t lld_readY(void) {
|
||||
__inline uint16_t lld_tpReadY(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
@ -36,7 +36,7 @@ __inline uint16_t lld_readY(void) {
|
|||
return y;
|
||||
}
|
||||
|
||||
__inline uint16_t lld_readZ(void) {
|
||||
__inline uint16_t lld_tpReadZ(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#ifdef TOUCHPAD_USE_XPT2046
|
||||
|
||||
uint16_t lld_readX(void);
|
||||
uint16_t lld_readY(void);
|
||||
uint16_t lld_readZ(void);
|
||||
uint16_t lld_tpReadX(void);
|
||||
uint16_t lld_tpReadY(void);
|
||||
uint16_t lld_tpReadZ(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -116,30 +116,26 @@ float sintable[91] = {
|
|||
|
||||
};
|
||||
|
||||
float getSin(unsigned int degree)
|
||||
{
|
||||
float getSin(unsigned int degree) {
|
||||
degree = degree % 360;
|
||||
if(degree <= 90)
|
||||
{
|
||||
|
||||
if(degree <= 90) {
|
||||
return sintable[degree];
|
||||
}
|
||||
else if(degree <= 180)
|
||||
{
|
||||
else if(degree <= 180) {
|
||||
return sintable[180-degree];
|
||||
}
|
||||
else if(degree <= 270)
|
||||
{
|
||||
else if(degree <= 270) {
|
||||
return sintable[degree-180]*(-1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return sintable[360-degree]*(-1.0);
|
||||
}
|
||||
}
|
||||
|
||||
double getCos(unsigned int degree)
|
||||
{
|
||||
double getCos(unsigned int degree) {
|
||||
degree = degree % 360;
|
||||
|
||||
return getSin(degree+90);
|
||||
}
|
||||
|
||||
|
@ -148,12 +144,11 @@ char sgn(char x){
|
|||
return (x > 0) ? 1 : (x < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
unsigned char max(unsigned char a, unsigned char b)
|
||||
{
|
||||
unsigned char max(unsigned char a, unsigned char b) {
|
||||
return (a<b) ? b : a;
|
||||
}
|
||||
|
||||
unsigned char min (unsigned char a, unsigned char b)
|
||||
{
|
||||
unsigned char min (unsigned char a, unsigned char b) {
|
||||
return (a<b) ? a : b;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,13 @@
|
|||
* Copyright: 2011 Roland Domke
|
||||
*/
|
||||
|
||||
#ifndef FASTMATH_H_
|
||||
#define FASTMATH_H_
|
||||
#ifndef FASTMATH_H
|
||||
#define FASTMATH_H
|
||||
|
||||
char sgn(char x);
|
||||
double getCos(unsigned int degree);
|
||||
double getSin(unsigned int degree);
|
||||
unsigned char max(unsigned char a, unsigned char b);
|
||||
unsigned char min(unsigned char a, unsigned char b);
|
||||
|
||||
#endif /* FASTMATH_H_ */
|
||||
|
|
24
glcd/glcd.c
24
glcd/glcd.c
|
@ -1,6 +1,4 @@
|
|||
#include "glcd.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define EMSG(a) const struct a *emsg = (const struct a*)msg
|
||||
|
||||
|
@ -68,8 +66,9 @@ static msg_t ThreadGLCDWorker(void *arg) {
|
|||
}
|
||||
|
||||
case GLCD_GET_PIXEL_COLOR: {
|
||||
/* ToDo */
|
||||
|
||||
EMSG(glcd_msg_get_pixel_color);
|
||||
((struct glcd_msg_get_pixel_color *)emsg)->color =
|
||||
lld_lcdGetPixelColor(emsg->x, emsg->y);
|
||||
result = GLCD_DONE;
|
||||
break;
|
||||
}
|
||||
|
@ -110,6 +109,7 @@ static msg_t ThreadGLCDWorker(void *arg) {
|
|||
|
||||
/* Done, release msg again. */
|
||||
chMsgRelease(p, (msg_t)result);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -206,16 +206,14 @@ glcd_result_t lcdClear(uint16_t color) {
|
|||
|
||||
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y) {
|
||||
struct glcd_msg_get_pixel_color msg;
|
||||
uint16_t result;
|
||||
|
||||
msg.action = GLCD_GET_PIXEL_COLOR;
|
||||
msg.x = x;
|
||||
msg.y = y;
|
||||
msg.color = &result;
|
||||
|
||||
chMsgSend(workerThread, (msg_t)&msg);
|
||||
|
||||
return result;
|
||||
return msg.color;
|
||||
}
|
||||
|
||||
glcd_result_t lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
|
||||
|
@ -269,6 +267,13 @@ glcd_result_t lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
|
|||
}
|
||||
|
||||
void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
|
||||
// speed improvement if vertical or horizontal
|
||||
if(x0 == x1) {
|
||||
lcdFillArea(x0, y0, x0+1, y1, color);
|
||||
} else if (y0 == y1) {
|
||||
lcdFillArea(x0, y0, x1, y0+1, color);
|
||||
|
||||
} else {
|
||||
int16_t dy, dx;
|
||||
int16_t addx = 1, addy = 1;
|
||||
int16_t P, diff;
|
||||
|
@ -316,6 +321,7 @@ void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t co
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t lcdDrawChar(uint16_t cx, uint16_t cy, char c, font_t font, uint16_t color, uint16_t bkcolor, bool_t tpText) {
|
||||
/* Working pointer */
|
||||
|
@ -456,9 +462,7 @@ void lcdDrawRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t fil
|
|||
y0 = TempY;
|
||||
}
|
||||
if(filled) {
|
||||
for(i=x0; i<x1; i++)
|
||||
for(j=y0; j<y1; j++)
|
||||
lcdDrawPixel(i , j , color);
|
||||
lcdFillArea(x0, y0, x1, y1, color);
|
||||
} else {
|
||||
lcdDrawLine(x0, y0, x1, y0, color);
|
||||
lcdDrawLine(x0, y1, x1, y1, color);
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "fonts.h"
|
||||
#include "worker.h"
|
||||
#include "fastMath.h"
|
||||
#include "glcdWorker.h"
|
||||
|
||||
#if !defined(LCD_USE_FSMC) && !defined(LCD_USE_GPIO) && !defined(LCD_USE_SPI)
|
||||
#include "glcdconf.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef WORKER_H
|
||||
#define WORKER_H
|
||||
#ifndef GLCD_WORKER_H
|
||||
#define GLCD_WORKER_H
|
||||
|
||||
#define GLCD_WORKER_SIZE 512
|
||||
|
|
@ -89,7 +89,7 @@ static inline void buttonUpdate(struct guiNode_t *node) {
|
|||
}
|
||||
|
||||
static inline void sliderUpdate(struct guiNode_t *node) {
|
||||
uint16_t length;
|
||||
uint16_t length = 1;
|
||||
|
||||
if(node->orientation == horizontal)
|
||||
length = node->x1 - node->x0;
|
||||
|
@ -113,8 +113,6 @@ static inline void sliderUpdate(struct guiNode_t *node) {
|
|||
// a bit of safety here
|
||||
if(node->percentage > 100)
|
||||
node->percentage = 100;
|
||||
if(node->percentage < 0)
|
||||
node->percentage = 0;
|
||||
|
||||
if(node->orientation == horizontal) {
|
||||
node->value = ((((node->x1)-(node->x0)) * node->percentage) / 100);
|
||||
|
@ -303,6 +301,11 @@ uint8_t guiDrawKeymatrix(uint16_t x0, uint16_t y0, uint16_t size, uint16_t space
|
|||
return 0;
|
||||
|
||||
// lcdDraw functions
|
||||
(void)size;
|
||||
(void)space;
|
||||
(void)buttonColor;
|
||||
(void)fontColor;
|
||||
(void)font;
|
||||
|
||||
chHeapFree(newNode);
|
||||
|
||||
|
|
2
readme
2
readme
|
@ -5,7 +5,7 @@ http://chibios.org/dokuwiki/doku.php?id=chibios:community
|
|||
|
||||
|
||||
### Maintainer & Contributors
|
||||
Contributors: - Badger -> console implementation and FSMC for F1 and SSD1289
|
||||
Contributors: - Badger -> console implementation and FSMC
|
||||
- Abhishek -> font rendering
|
||||
- Ben William -> fastMath and lcdDrawEllipse()
|
||||
- dxli (Dongxu Li) -> lcdDrawEllipse() filled option
|
||||
|
|
|
@ -16,14 +16,6 @@ void tpInit(SPIDriver *spip) {
|
|||
spiStart(spip, &spicfg);
|
||||
}
|
||||
|
||||
static __inline uint16_t readX(void) {
|
||||
return lld_readX();
|
||||
}
|
||||
|
||||
static __inline uint16_t readY(void) {
|
||||
return lld_readY();
|
||||
}
|
||||
|
||||
uint8_t tpIRQ(void) {
|
||||
return (!palReadPad(TP_IRQ_PORT, TP_IRQ));
|
||||
}
|
||||
|
@ -33,8 +25,8 @@ static uint16_t tpReadRealX(void) {
|
|||
uint16_t i, x;
|
||||
|
||||
for(i=0; i<CONVERSIONS; i++) {
|
||||
readX();
|
||||
results += readX();
|
||||
lld_tpReadX();
|
||||
results += lld_tpReadX();
|
||||
}
|
||||
|
||||
x = (((SCREEN_WIDTH-1) * (results/CONVERSIONS)) / 2048);
|
||||
|
@ -47,8 +39,8 @@ static uint16_t tpReadRealY(void) {
|
|||
uint16_t i, y;
|
||||
|
||||
for(i=0; i<CONVERSIONS; i++) {
|
||||
readY();
|
||||
results += readY();
|
||||
lld_tpReadY();
|
||||
results += lld_tpReadY();
|
||||
}
|
||||
|
||||
y = (((SCREEN_HEIGHT-1) * (results/CONVERSIONS)) / 2048);
|
||||
|
@ -97,7 +89,7 @@ uint16_t tpReadY(void) {
|
|||
}
|
||||
|
||||
uint16_t tpReadZ(void) {
|
||||
return lld_readZ();
|
||||
return lld_tpReadZ();
|
||||
}
|
||||
|
||||
static void tpDrawCross(uint16_t x, uint16_t y) {
|
||||
|
|
Loading…
Add table
Reference in a new issue