commit
fb070f8d2c
20 changed files with 937 additions and 16 deletions
Doxyfilehalext.mkreadme
halext
drivers
gdispNokia6610
gdispS6d1121
gdispSsd1289
gdispTestStub
touchpad
touchpadADS7843
touchpadXPT2046
include
readme.txtsrc
23
Doxyfile
Normal file
23
Doxyfile
Normal file
|
@ -0,0 +1,23 @@
|
|||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "ChibiOS-LCD-Driver"
|
||||
PROJECT_NUMBER = 0.0.1
|
||||
PROJECT_BRIEF = "Library for interfacing GLCDs with Touchpad to ChibiOS"
|
||||
OUTPUT_LANGUAGE = English
|
||||
TAB_SIZE = 2
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
INPUT =
|
||||
RECURSIVE = YES
|
||||
GENERATE_LATEX = NO
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_DYNAMIC_SECTIONS = YES
|
||||
GENERATE_TREEVIEW = YES
|
||||
DISABLE_INDEX = YES
|
||||
TREEVIEW_WIDTH = 300
|
||||
SEARCHENGINE = YES
|
||||
CLASS_DIAGRAMS = YES
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = YES
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# List the required driver.
|
||||
HALSRC += ${CHIBIOS}/os/halext/drivers/gdispNokia6610/gdisp_lld.c
|
||||
HALSRC += $(LCDLIB)/halext/drivers/gdispNokia6610/gdisp_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += ${CHIBIOS}/os/halext/drivers/gdispNokia6610
|
||||
HALINC += $(LCDLIB)/halext/drivers/gdispNokia6610
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# List the required driver.
|
||||
HALSRC += ${CHIBIOS}/os/halext/drivers/gdispS6d1121/gdisp_lld.c
|
||||
HALSRC += $(LCDLIB)/halext/drivers/gdispS6d1121/gdisp_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += ${CHIBIOS}/os/halext/drivers/gdispS6d1121
|
||||
HALINC += $(LCDLIB)/halext/drivers/gdispS6d1121
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# List the required driver.
|
||||
HALSRC += ${CHIBIOS}/os/halext/drivers/gdispSsd1289/gdisp_lld.c
|
||||
HALSRC += $(LCDLIB)/halext/drivers/gdispSsd1289/gdisp_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += ${CHIBIOS}/os/halext/drivers/gdispSsd1289
|
||||
HALINC += $(LCDLIB)/halext/drivers/gdispSsd1289
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# List the required driver.
|
||||
HALSRC += ${CHIBIOS}/os/halext/drivers/gdispTestStub/gdisp_lld.c
|
||||
HALSRC += $(LCDLIB)/halext/drivers/gdispTestStub/gdisp_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += ${CHIBIOS}/os/halext/drivers/gdispTestStub
|
||||
HALINC += $(LCDLIB)/halext/drivers/gdispTestStub
|
||||
|
|
9
halext/drivers/touchpad/touchpadADS7843/readme.txt
Normal file
9
halext/drivers/touchpad/touchpadADS7843/readme.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
To use this driver:
|
||||
|
||||
1. Add in your halconf.h:
|
||||
a) #define HAL_USE_TOUCHPAD TRUE
|
||||
|
||||
2. To your makefile add the following lines:
|
||||
include $(LCDLIB)/lcd.mk
|
||||
include $(LCDLIB)/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.mk
|
||||
|
152
halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c
Normal file
152
halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpadADS7843/touchpad_lld.c
|
||||
* @brief Touchpad Driver subsystem low level driver source.
|
||||
*
|
||||
* @addtogroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "touchpad.h"
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS)
|
||||
#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS)
|
||||
|
||||
#ifdef UNUSED
|
||||
#elif defined(__GNUC__)
|
||||
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
||||
#elif defined(__LCLINT__)
|
||||
# define UNUSED(x) /*@unused@*/ x
|
||||
#else
|
||||
# define UNUSED(x) x
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
TOUCHPADDriver Touchpad;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
static const SPIConfig spicfg = {
|
||||
NULL,
|
||||
TP_CS_PORT,
|
||||
TP_CS,
|
||||
SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/* ---- Required Routines ---- */
|
||||
|
||||
/**
|
||||
* @brief Low level Touchpad driver initialization.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void tp_lld_init(TOUCHPADDriver *tp) {
|
||||
spiStart(tp->spid, &spicfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads out the X direction.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_x(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
||||
txbuf[0] = 0xd0;
|
||||
TP_CS_LOW;
|
||||
spiSend(&SPID1, 1, txbuf);
|
||||
spiReceive(&SPID1, 2, rxbuf);
|
||||
TP_CS_HIGH;
|
||||
|
||||
y = rxbuf[0] << 4;
|
||||
y |= rxbuf[1] >> 4;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Reads out the X direction.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_y(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
||||
txbuf[0] = 0x90;
|
||||
TP_CS_LOW;
|
||||
spiSend(&SPID1, 1, txbuf);
|
||||
spiReceive(&SPID1, 2, rxbuf);
|
||||
TP_CS_HIGH;
|
||||
|
||||
y = rxbuf[0] << 4;
|
||||
y |= rxbuf[1] >> 4;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/* ---- Optional Routines ---- */
|
||||
#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__)
|
||||
/*
|
||||
* @brief for checking if touchpad is pressed or not.
|
||||
*
|
||||
* @return 1 if pressed / 0 if not pressed
|
||||
*
|
||||
* @noapi
|
||||
*/
|
||||
uint8_t tp_lld_irq(void) {
|
||||
return (!palReadPad(TP_IRQ_PORT, TP_IRQ));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
/** @} */
|
||||
|
6
halext/drivers/touchpad/touchpadADS7843/touchpad_lld.mk
Normal file
6
halext/drivers/touchpad/touchpadADS7843/touchpad_lld.mk
Normal file
|
@ -0,0 +1,6 @@
|
|||
# List the required driver.
|
||||
HALSRC += $(LCDLIB)/halext/drivers/touchpad/touchpadADS7843/touchpad_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += $(LCDLIB)/halext/drivers/touchpad/touchpadADS7843
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpadADS7843/touchpad_lld_config.h
|
||||
* @brief Touchpad Driver subsystem low level driver.
|
||||
*
|
||||
* @addtogroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TOUCHPAD_LLD_CONFIG_H
|
||||
#define _TOUCHPAD_LLD_CONFIG_H
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver hardware support. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define TOUCHPAD_HAS_IRQ TRUE
|
||||
#define TOUCHPAD_HAS_PRESSURE FALSE
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
|
||||
#endif /* _TOUCHPAD_LLD_CONFIG_H */
|
||||
/** @} */
|
9
halext/drivers/touchpad/touchpadXPT2046/readme.txt
Normal file
9
halext/drivers/touchpad/touchpadXPT2046/readme.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
To use this driver:
|
||||
|
||||
1. Add in your halconf.h:
|
||||
a) #define HAL_USE_TOUCHPAD TRUE
|
||||
|
||||
2. To your makefile add the following lines:
|
||||
include $(LCDLIB)/lcd.mk
|
||||
include $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk
|
||||
|
164
halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c
Normal file
164
halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpadXPT2046/touchpad_lld.c
|
||||
* @brief Touchpad Driver subsystem low level driver source.
|
||||
*
|
||||
* @addtogroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "touchpad.h"
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS)
|
||||
#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS)
|
||||
|
||||
#ifdef UNUSED
|
||||
#elif defined(__GNUC__)
|
||||
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
||||
#elif defined(__LCLINT__)
|
||||
# define UNUSED(x) /*@unused@*/ x
|
||||
#else
|
||||
# define UNUSED(x) x
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
TOUCHPADDriver Touchpad;
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
static const SPIConfig spicfg = {
|
||||
NULL,
|
||||
TP_CS_PORT,
|
||||
TP_CS,
|
||||
SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/* ---- Required Routines ---- */
|
||||
|
||||
/**
|
||||
* @brief Low level Touchpad driver initialization.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void tp_lld_init(TOUCHPADDriver *tp) {
|
||||
spiStart(tp->spid, &spicfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads out the X direction.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_x(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
||||
txbuf[0] = 0xd0;
|
||||
TP_CS_LOW;
|
||||
spiSend(&SPID1, 1, txbuf);
|
||||
spiReceive(&SPID1, 2, rxbuf);
|
||||
TP_CS_HIGH;
|
||||
|
||||
y = rxbuf[0] << 4;
|
||||
y |= rxbuf[1] >> 4;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Reads out the X direction.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_y(void) {
|
||||
uint8_t txbuf[1];
|
||||
uint8_t rxbuf[2];
|
||||
uint16_t y;
|
||||
|
||||
txbuf[0] = 0x90;
|
||||
TP_CS_LOW;
|
||||
spiSend(&SPID1, 1, txbuf);
|
||||
spiReceive(&SPID1, 2, rxbuf);
|
||||
TP_CS_HIGH;
|
||||
|
||||
y = rxbuf[0] << 4;
|
||||
y |= rxbuf[1] >> 4;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/* ---- Optional Routines ---- */
|
||||
#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__)
|
||||
/*
|
||||
* @brief for checking if touchpad is pressed or not.
|
||||
*
|
||||
* @return 1 if pressed / 0 if not pressed
|
||||
*
|
||||
* @noapi
|
||||
*/
|
||||
uint8_t tp_lld_irq(void) {
|
||||
return (!palReadPad(TP_IRQ_PORT, TP_IRQ));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TOUCHPAD_HAS_PRESSURE || defined(__DOXYGEN__)
|
||||
/*
|
||||
* @brief Reads out the Z direction / pressure.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_z(void) {
|
||||
/* ToDo */
|
||||
return 42;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
/** @} */
|
||||
|
6
halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk
Normal file
6
halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk
Normal file
|
@ -0,0 +1,6 @@
|
|||
# List the required driver.
|
||||
HALSRC += $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpadXPT2046/touchpad_lld_config.h
|
||||
* @brief Touchppad Driver subsystem low level driver.
|
||||
*
|
||||
* @addtogroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TOUCHPAD_LLD_CONFIG_H
|
||||
#define _TOUCHPAD_LLD_CONFIG_H
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver hardware support. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define TOUCHPAD_HAS_IRQ TRUE
|
||||
#define TOUCHPAD_HAS_PRESSURE TRUE
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
|
||||
#endif /* _TOUCHPAD_LLD_CONFIG_H */
|
||||
/** @} */
|
|
@ -1,9 +1,10 @@
|
|||
# List of all the ChibiOS/RT META files, there is no need to remove the files
|
||||
# from this list, you can disable parts of the kernel by editing halconf.h.
|
||||
|
||||
HALSRC += ${CHIBIOS}/os/halext/src/gdisp.c \
|
||||
${CHIBIOS}/os/halext/src/gdisp_fonts.c \
|
||||
${CHIBIOS}/os/halext/src/gdisp_emulation.c
|
||||
HALSRC += $(LCDLIB)/halext/src/gdisp.c \
|
||||
$(LCDLIB)/halext/src/gdisp_fonts.c \
|
||||
$(LCDLIB)/halext/src/gdisp_emulation.c \
|
||||
$(LCDLIB)/halext/src/touchpad.c
|
||||
|
||||
# Required include directories
|
||||
HALINC += ${CHIBIOS}/os/halext/include
|
||||
HALINC += $(LCDLIB)/halext/include
|
||||
|
|
|
@ -296,6 +296,8 @@
|
|||
#define RED_OF(c) (((c) & 0xF800)>>8)
|
||||
#define GREEN_OF(c) (((c)&0x007E)>>3)
|
||||
#define BLUE_OF(c) (((c)&0x001F)<<3)
|
||||
#define RGB565CONVERT(red, green, blue) (uint16_t)( (( red >> 3 ) << 11 ) | (( green >> 2 ) << 5 ) | ( blue >> 3 ))
|
||||
|
||||
|
||||
#elif defined(GDISP_PIXELFORMAT_RGB888)
|
||||
typedef uint32_t color_t;
|
||||
|
|
93
halext/include/touchpad.h
Normal file
93
halext/include/touchpad.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver/RT - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpad.h
|
||||
* @brief TOUCHPAD Touchpad Driver subsystem header file.
|
||||
*
|
||||
* @addgroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
#ifndef _TOUCHPAD_H
|
||||
#define _TOUCHPAD_H
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief specifies how many conversions are made for a readout.
|
||||
*
|
||||
* @note higher is more accurate, but takes more time
|
||||
*/
|
||||
#define CONVERSIONS 3
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Low Level Driver details and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/* Include the low level driver information */
|
||||
#include "touchpad_lld.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Type definitions */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Struct used for calibration
|
||||
*/
|
||||
struct cal {
|
||||
float xm;
|
||||
float ym;
|
||||
float xn;
|
||||
float yn;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void tpInit(TOUCHPADDriver *tp);
|
||||
uint16_t tpReadX(void);
|
||||
uint16_t tpReadY(void);
|
||||
|
||||
#if TOUCHPAD_HAS_IRQ
|
||||
uint8_t tpIRQ(void);
|
||||
#endif
|
||||
|
||||
#if TOUCHPAD_HAS_PRESSURE
|
||||
uint16_t tpReadZ(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
|
||||
#endif /* _TOUCHPAD_H */
|
||||
/** @} */
|
||||
|
102
halext/include/touchpad_lld.h
Normal file
102
halext/include/touchpad_lld.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver/RT - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpad_lld.h
|
||||
* @brief TOUCHPAD Driver subsystem low level driver header.
|
||||
*
|
||||
* @addgroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TOUCHPAD_LLD_H
|
||||
#define _TOUCHPAD_LLD_H
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Include the low level driver configuration information */
|
||||
/*===========================================================================*/
|
||||
|
||||
#include "touchpad_lld_config.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifndef TOUCHPAD_HAS_IRQ
|
||||
#define TOUCHPAD_HAS_IRQ FALSE
|
||||
#endif
|
||||
|
||||
#ifndef TOUCHPAD_HAS_PRESSURE
|
||||
#define TOUCHPAD_HAS_PRESSURE FALSE
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
typedef struct TOUCHPADDriver TOUCHPADDriver;
|
||||
|
||||
/**
|
||||
* @brief Structure representing a Touchpad driver.
|
||||
*/
|
||||
struct TOUCHPADDriver {
|
||||
/*
|
||||
* @brief Pointer to SPI driver.
|
||||
* @note SPI driver must be enabled in mcu- and halconf.h
|
||||
*/
|
||||
SPIDriver *spid;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !defined(__DOXYGEN__)
|
||||
extern TOUCHPADDriver Touchpad;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Core functions */
|
||||
void tp_lld_init(TOUCHPADDriver *tp);
|
||||
uint16_t tp_lld_read_x(void);
|
||||
uint16_t tp_lld_read_y(void);
|
||||
|
||||
#if TOUCHPAD_HAS_IRQ
|
||||
uint8_t tp_lld_irq(void);
|
||||
#endif
|
||||
|
||||
#if TOUCHPAD_HAS_PRESSURE
|
||||
uint16_t tp_lld_read_z(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
|
||||
#endif /* _TOUCHPAD_LLD_H */
|
||||
/** @} */
|
||||
|
|
@ -6,14 +6,14 @@ To include any of these functions/drivers in your project...
|
|||
include $(LCDLIB)/lcd.mk
|
||||
|
||||
3/ In your project Makefile add the makefiles for any specific drivers you want e.g
|
||||
include $(LCDLIB)/halext/drivers/gdispNokia6610/gdisp_lld.mk
|
||||
include $(LCDLIB)/halext/drivers/touchpad/touchpadXPT2046/touchpad_lld.mk
|
||||
|
||||
4/ In your project halconf.h turn on the support you want eg.
|
||||
/**
|
||||
* @brief Enables the GDISP subsystem.
|
||||
* @brief Enables the Touchpad subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_GDISP) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_GDISP TRUE
|
||||
#if !defined(HAL_USE_TOUCHPAD) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_TOUCHPAD TRUE
|
||||
#endif
|
||||
|
||||
5/ Do a make clean.
|
||||
|
|
261
halext/src/touchpad.c
Normal file
261
halext/src/touchpad.c
Normal file
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
ChibiOS-LCD-Driver - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS-LCD-Driver.
|
||||
|
||||
ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file touchpad.c
|
||||
* @brief Touchpad Driver code.
|
||||
*
|
||||
* @addgroup TOUCHPAD
|
||||
* @{
|
||||
*/
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "gdisp.h"
|
||||
#include "touchpad.h"
|
||||
|
||||
#if HAL_USE_TOUCHPAD || defined(__DOXYGEN__)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef UNUSED
|
||||
#elif defined(__GNUC__)
|
||||
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
||||
#elif defined(__LCLINT__)
|
||||
# define UNUSED(x) /*@unused@*/ x
|
||||
#else
|
||||
# define UNUSED(x) x
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
volatile static struct cal cal = {
|
||||
1, 1, 0, 0
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief returns the uncalibrated readout of the X direction from the controller
|
||||
*
|
||||
* @noapi
|
||||
*/
|
||||
static uint16_t _tpReadRealX(void) {
|
||||
uint32_t results = 0;
|
||||
uint16_t i, x;
|
||||
|
||||
for(i = 0; i < CONVERSIONS; i++) {
|
||||
tp_lld_read_x(); /* dummy, reduce noise on SPI */
|
||||
results += tp_lld_read_x();
|
||||
}
|
||||
|
||||
// 12-bit
|
||||
x = (((SCREEN_WIDTH-1) * (results/CONVERSIONS)) / 2048);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return the uncalibrated readout of the Y-direction from the controller
|
||||
*
|
||||
* @noapi
|
||||
*/
|
||||
static uint16_t _tpReadRealY(void) {
|
||||
uint32_t results = 0;
|
||||
uint16_t i, y;
|
||||
|
||||
for(i = 0; i < CONVERSIONS; i++) {
|
||||
tp_lld_read_y(); /* dummy, reduce noise on SPI */
|
||||
results += tp_lld_read_y();
|
||||
}
|
||||
|
||||
// 12-bit
|
||||
y = (((SCREEN_HEIGHT-1) * (results/CONVERSIONS)) / 2048);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief draws a cross. Used for calibration.
|
||||
*
|
||||
* @noapi
|
||||
*/
|
||||
static void _tpDrawCross(uint16_t x, uint16_t y) {
|
||||
gdispDrawLine(x-15, y, x-2, y, 0xffff);
|
||||
gdispDrawLine(x+2, y, x+15, y, 0xffff);
|
||||
gdispDrawLine(x, y-15, x, y-2, 0xffff);
|
||||
gdispDrawLine(x, y+2, x, y+15, 0xffff);
|
||||
|
||||
gdispDrawLine(x-15, y+15, x-7, y+15, RGB565CONVERT(184,158,131));
|
||||
gdispDrawLine(x-15, y+7, x-15, y+15, RGB565CONVERT(184,158,131));
|
||||
|
||||
gdispDrawLine(x-15, y-15, x-7, y-15, RGB565CONVERT(184,158,131));
|
||||
gdispDrawLine(x-15, y-7, x-15, y-15, RGB565CONVERT(184,158,131));
|
||||
|
||||
gdispDrawLine(x+7, y+15, x+15, y+15, RGB565CONVERT(184,158,131));
|
||||
gdispDrawLine(x+15, y+7, x+15, y+15, RGB565CONVERT(184,158,131));
|
||||
|
||||
gdispDrawLine(x+7, y-15, x+15, y-15, RGB565CONVERT(184,158,131));
|
||||
gdispDrawLine(x+15, y-15, x+15, y-7, RGB565CONVERT(184,158,131));
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Touchpad Driver initialization.
|
||||
* @note This function is NOT currently implicitly invoked by @p halInit().
|
||||
* It must be called manually.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void tpInit(TOUCHPADDriver *tp) {
|
||||
/* Initialise Mutex */
|
||||
//MUTEX_INIT
|
||||
|
||||
/* Initialise driver */
|
||||
//MUTEX_ENTER
|
||||
tp_lld_init(tp);
|
||||
//MUTEX_EXIT
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the X-Coordinate, relative to screen zero point.
|
||||
*
|
||||
* @return The X position in pixels.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
uint16_t tpReadX(void) {
|
||||
uint16_t x, y;
|
||||
|
||||
x = cal.xm * _tpReadRealX() + cal.xn;
|
||||
y = cal.ym * _tpReadRealY() + cal.yn;
|
||||
|
||||
/*
|
||||
switch(gdispGetOrientation()) { // implement gdispGetOrientation()
|
||||
case portrait:
|
||||
return x;
|
||||
case landscape:
|
||||
return SCREEN_HEIGHT - y;
|
||||
case portraitInv:
|
||||
return SCREEN_WIDTH - x;
|
||||
case landscapeInv:
|
||||
return y;
|
||||
}
|
||||
*/
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the X-Coordinate, relative to screen zero point.
|
||||
*
|
||||
* @return The Y position in pixels.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
uint16_t tpReadY(void) {
|
||||
uint16_t x, y;
|
||||
|
||||
x = cal.xm * _tpReadRealX() + cal.xn;
|
||||
y = cal.ym * _tpReadRealY() + cal.yn;
|
||||
|
||||
/*
|
||||
switch(gdispGetOrientation()) { // implement gdispGetOrientation()
|
||||
case portrait:
|
||||
return y;
|
||||
case landscape:
|
||||
return x;
|
||||
case portraitInv:
|
||||
return SCREEN_HEIGHT - y;
|
||||
case landscapeInv:
|
||||
return SCREEN_WIDTH - x;
|
||||
}
|
||||
*/
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
void tpCalibrate(void) {
|
||||
uint16_t cross[2][2] = {{40,50}, {200, 280}};
|
||||
uint16_t points[2][2];
|
||||
uint8_t i;
|
||||
|
||||
//gdispSetOrientation(portrait);
|
||||
gdispClear(Red);
|
||||
gdispDrawString(40, 10, "Calibration", &fontUI1Double, White);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
_tpDrawCross(cross[i][0], cross[i][1]);
|
||||
while(!tpIRQ());
|
||||
points[i][0] = _tpReadRealX();
|
||||
points[i][1] = _tpReadRealY();
|
||||
chThdSleepMilliseconds(100);
|
||||
while(tpIRQ());
|
||||
gdispFillArea(cross[i][0]-15, cross[i][1]-15, 42, 42, Red);
|
||||
}
|
||||
|
||||
cal.xm = ((float)cross[1][0] - (float)cross[0][0]) / ((float)points[1][0] - (float)points[0][0]);
|
||||
cal.ym = ((float)cross[1][1] - (float)cross[0][1]) / ((float)points[1][1] - (float)points[0][1]);
|
||||
|
||||
cal.xn = (float)cross[0][0] - cal.xm * (float)points[0][0];
|
||||
cal.yn = (float)cross[0][1] - cal.ym * (float)points[0][1];
|
||||
}
|
||||
|
||||
#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief returns if touchpad is pressed or not
|
||||
*
|
||||
* @return 1 if pressed, 0 otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
uint8_t tpIRQ(void) {
|
||||
return tp_lld_irq();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TOUCHPAD_HAS_PRESSURE || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief Get the pressure.
|
||||
*
|
||||
* @return The pressure.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
uint16_t tpReadZ(void) {
|
||||
/* ToDo */
|
||||
return (tp_lld_read_z());
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
/** @} */
|
||||
|
5
readme
5
readme
|
@ -1,3 +1,8 @@
|
|||
## Doxygen
|
||||
run doxygen in the toplevel directory to generate the doxygen documentation in html
|
||||
|
||||
|
||||
|
||||
## Wiki
|
||||
please read the wiki pages to this project carefully, before you ask any questions:
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue