Updates to mouse and makefile for Mikromedia STM32-M4 board.

This commit is contained in:
inmarket 2013-11-24 02:24:03 +10:00
parent 361136d7ca
commit 299311b480
3 changed files with 44 additions and 91 deletions

View File

@ -77,9 +77,9 @@ LDSCRIPT= $(PORTLD)/STM32F407xG.ld
# Imported source files and paths for uGFX
GFXLIB = ../uGFX
include $(GFXLIB)/gfx.mk
include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/board.mk
include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk # The replacement ChibiOS board files
include $(GFXLIB)/gfx.mk
# Where is our source code - alter these for your project.
MYFILES = $(GFXLIB)/demos/modules/gdisp/basics

View File

@ -13,9 +13,6 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H
/* read ADC if more than this many ticks since last read */
#define ADC_UPDATE_INTERVAL 3
#define ADC_NUM_CHANNELS 2
#define ADC_BUF_DEPTH 1
@ -34,55 +31,6 @@ static const ADCConversionGroup adcgrpcfg = {
ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9)
};
static systime_t last_update;
static volatile uint16_t tpx, tpy, detect;
static inline void delay(uint16_t dly) {
static uint16_t i;
for(i = 0; i < dly; i++)
asm("nop");
}
void read_mikro_tp(void) {
systime_t now = chTimeNow();
adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
uint16_t _detect, _tpx, _tpy;
if(now < last_update || ((now - last_update) > ADC_UPDATE_INTERVAL)) {
// detect button press
// sample[0] will go from ~200 to ~4000 when pressed
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
_detect = samples[0];
// read x channel
palSetPad(GPIOB, GPIOB_DRIVEA);
palClearPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(1);
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
_tpx = samples[1];
// read y channel (invert)
palClearPad(GPIOB, GPIOB_DRIVEA);
palSetPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(1);
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
_tpy = samples[0];
// ready for next read
palClearPad(GPIOB, GPIOB_DRIVEA);
palClearPad(GPIOB, GPIOB_DRIVEB);
chSysLock();
tpx = _tpx;
tpy = _tpy;
detect = _detect;
last_update = now;
chSysUnlock();
}
}
/**
* @brief Initialise the board for the touch.
*
@ -90,23 +38,6 @@ void read_mikro_tp(void) {
*/
static inline void init_board(void) {
adcStart(&ADCD1, NULL);
last_update = chTimeNow();
// leave DRIVEA & DRIVEB ready for next read
palClearPad(GPIOB, GPIOB_DRIVEA);
palClearPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(1);
}
/**
* @brief Check whether the surface is currently touched
* @return TRUE if the surface is currently touched
*
* @notapi
*/
static inline bool_t getpin_pressed(void) {
read_mikro_tp();
return (detect > 2000) ? true : false;
}
/**
@ -124,29 +55,51 @@ static inline void aquire_bus(void) {
* @notapi
*/
static inline void release_bus(void) {
}
/**
* @brief Read an x value from touch controller
* @return The value read from the controller
*
* @notapi
*/
static inline uint16_t read_x_value(void) {
read_mikro_tp();
return tpx;
static inline void setup_x(void) {
palSetPad(GPIOB, GPIOB_DRIVEA);
palClearPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(2);
}
/**
* @brief Read an y value from touch controller
* @return The value read from the controller
*
* @notapi
*/
static inline uint16_t read_y_value(void) {
read_mikro_tp();
return tpy;
static inline void setup_y(void) {
palClearPad(GPIOB, GPIOB_DRIVEA);
palSetPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(2);
}
static inline void setup_z(void) {
palClearPad(GPIOB, GPIOB_DRIVEA);
palClearPad(GPIOB, GPIOB_DRIVEB);
chThdSleepMilliseconds(2);
}
static inline uint16_t read_x(void) {
adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
return samples[1];
}
static inline uint16_t read_y(void) {
adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
return samples[0];
}
static inline uint16_t read_z(void) {
adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH);
// z will go from ~200 to ~4000 when pressed
// auto range this back to 0 to 100
if (samples[0] > 4000)
return 100;
if (samples[0] < 400)
return 0;
return (samples[0] - 400) / ((4000-400)/100);
}
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */

View File

@ -22,8 +22,8 @@
#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_READ_CYCLES 1
#define GINPUT_MOUSE_POLL_PERIOD 25
#define GINPUT_MOUSE_MAX_CLICK_JITTER 2
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
#define GINPUT_MOUSE_CLICK_TIME 500