ADS7843 porting - not tested yet!

This commit is contained in:
Joel Bodenmann 2014-10-11 18:24:12 +02:00
parent 097bce6aa4
commit d9f93a31bb
7 changed files with 100 additions and 141 deletions

View File

@ -1,22 +0,0 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#ifndef _LLD_GINPUT_MOUSE_CONFIG_H
#define _LLD_GINPUT_MOUSE_CONFIG_H
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
#define GINPUT_MOUSE_NEED_CALIBRATION TRUE
#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12
#define GINPUT_MOUSE_READ_CYCLES 4
#define GINPUT_MOUSE_POLL_PERIOD 3
#define GINPUT_MOUSE_MAX_CLICK_JITTER 2
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
#define GINPUT_MOUSE_CLICK_TIME 500
#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */

View File

@ -8,6 +8,13 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H
#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2
#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2
#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2
#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4
#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4
#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4
static const SPIConfig spicfg = {
0,
GPIOC,
@ -15,13 +22,25 @@ static const SPIConfig spicfg = {
/* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
};
static inline void init_board(void)
static bool_t init_board(GMouse* m, unsigned driverinstance)
{
(void)m;
// Only one touch interface on this board
if (driverinstance)
return FALSE;
// Set the GPIO modes
palSetPadMode(GPIOC, 4, PAL_MODE_INPUT);
// Start the SPI peripheral
spiStart(&SPID1, &spicfg);
return TRUE;
}
static inline bool_t getpin_pressed(void)
{
{
return (!palReadPad(GPIOC, 4));
}

View File

@ -1,5 +1,5 @@
# List the required driver.
GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c
# Required include directories
GFXINC += $(GFXLIB)/drivers/ginput/touch/ADS7843

View File

@ -1,94 +0,0 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/
#include "src/ginput/driver_mouse.h"
#include "ginput_lld_mouse_board.h"
#if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED
#define CMD_X 0x91
#define CMD_Y 0xD1
#else
#define CMD_X 0xD1
#define CMD_Y 0x91
#endif
static uint16_t sampleBuf[7];
static coord_t lastx, lasty;
static void filter(void) {
uint16_t temp;
int i,j;
for(i = 0; i < 4; i++) {
for(j = i; j < 7; j++) {
if(sampleBuf[i] > sampleBuf[j]) {
/* Swap the values */
temp = sampleBuf[i];
sampleBuf[i] = sampleBuf[j];
sampleBuf[j] = temp;
}
}
}
}
void ginput_lld_mouse_init(void) {
init_board();
}
void ginput_lld_mouse_get_reading(MouseReading *pt) {
uint16_t i;
// If touch-off return the previous results
if (!getpin_pressed()) {
pt->x = lastx;
pt->y = lasty;
pt->z = 0;
pt->buttons = 0;
return;
}
// Read the port to get the touch settings
aquire_bus();
/* Get the X value
* Discard the first conversion - very noisy and keep the ADC on hereafter
* till we are done with the sampling. Note that PENIRQ is disabled while reading.
* Finally switch on PENIRQ once again - perform a dummy read.
* Once we have the readings, find the medium using our filter function
*/
read_value(CMD_X);
for(i = 0; i < 7; i++)
sampleBuf[i] = read_value(CMD_X);
read_value(CMD_X-1);
filter();
lastx = (coord_t)sampleBuf[3];
/* Get the Y value using the same process as above */
read_value(CMD_Y);
for(i = 0; i < 7; i++)
sampleBuf[i] = read_value(CMD_Y);
read_value(CMD_Y-1);
filter();
lasty = (coord_t)sampleBuf[3];
// Release the bus
release_bus();
// Return the results
pt->x = lastx;
pt->y = lasty;
pt->z = 100;
pt->buttons = GINPUT_TOUCH_PRESSED;
}
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */

View File

@ -1,21 +0,0 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#ifndef _LLD_GINPUT_MOUSE_CONFIG_H
#define _LLD_GINPUT_MOUSE_CONFIG_H
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
#define GINPUT_MOUSE_NEED_CALIBRATION TRUE
#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE
#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 5
#define GINPUT_MOUSE_READ_CYCLES 4
#define GINPUT_MOUSE_POLL_PERIOD 25
#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
#define GINPUT_MOUSE_CLICK_TIME 500
#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */

View File

@ -0,0 +1,77 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE)
#define GMOUSE_DRIVER_VMT GMOUSEVMT_ADS7843
#include "src/ginput/driver_mouse.h"
// Get the hardware interface
#include "gmouse_lld_ADS7843_board.h"
// If the board file doesn't specify how many extra bytes it wants - assume 0
#ifndef BOARD_DATA_SIZE
#define BOARD_DATA_SIZE 0
#endif
#define CMD_X 0xD1
#define CMD_Y 0x91
void read_xyz(GMouse* m, GMouseReading* pdr)
{
(void)m;
// No buttons
pdr->buttons = 0;
if (getpin_pressed()) {
aquire_bus();
pdr->x = read_value(CMD_X);
pdr->y = read_value(CMD_Y);
pdr->z = 1;
release_bus();
} else {
// Don't touch x and y values here
pdr->z = 0;
}
}
const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
{
GDRIVER_TYPE_TOUCH,
GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST |
GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN,
sizeof(GMouse)+BOARD_DATA_SIZE,
_gmouseInitDriver,
_gmousePostInitDriver,
_gmouseDeInitDriver
},
1, // z_max - (currently?) not supported
0, // z_min - (currently?) not supported
1, // z_touchon
0, // z_touchoff
{ // pen_jitter
GMOUSE_ADS7843_PEN_CALIBRATE_ERROR, // calibrate
GMOUSE_ADS7843_PEN_CLICK_ERROR, // click
GMOUSE_ADS7843_PEN_MOVE_ERROR // move
},
{ // finger_jitter
GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR, // calibrate
GMOUSE_ADS7843_FINGER_CLICK_ERROR, // click
GMOUSE_ADS7843_FINGER_MOVE_ERROR // move
},
init_board, // init
0, // deinit
read_xyz, // get
0, // calsave
0 // calload
}};
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */

View File

@ -8,7 +8,7 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H
static inline void init_board(void) {
static bool_t init_board(GMouse* m, unsigned driverinstance) {
}