tpInit()
This commit is contained in:
parent
79c0535678
commit
19bb3b15dd
4 changed files with 55 additions and 21 deletions
|
@ -56,6 +56,12 @@
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver local variables. */
|
/* 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 local functions. */
|
||||||
|
@ -78,11 +84,8 @@
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void tp_lld_init(void) {
|
void tp_lld_init(TOUCHPADDriver *tp) {
|
||||||
/* Initialise the TOUCHPAD structure */
|
spiStart(tp->spid, &spicfg);
|
||||||
|
|
||||||
/* ToDo */
|
|
||||||
(void)tp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +115,7 @@ uint16_t tp_lld_read_y(void) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
uint16_t tp_lld_read_y(void) {
|
uint16_t tp_lld_read_z(void) {
|
||||||
/* ToDo */
|
/* ToDo */
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
|
@ -120,3 +123,4 @@ uint16_t tp_lld_read_y(void) {
|
||||||
|
|
||||||
#endif /* HAL_USE_TOUCHPAD */
|
#endif /* HAL_USE_TOUCHPAD */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -21,20 +21,50 @@
|
||||||
#ifndef _XPT2046_H
|
#ifndef _XPT2046_H
|
||||||
#define _XPT2046_H
|
#define _XPT2046_H
|
||||||
|
|
||||||
void tp_lld_init(TOUCHPADDriver *tp) {
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
|
||||||
|
#define TP_CS_HIGH palSetPad(TP_CS_PORT, TP_CS)
|
||||||
|
#define TP_CS_LOW palClearPad(TP_CS_PORT, TP_CS)
|
||||||
|
|
||||||
|
__inline uint16_t lld_tpReadX(void) {
|
||||||
|
uint8_t txbuf[1];
|
||||||
|
uint8_t rxbuf[2];
|
||||||
|
uint16_t x;
|
||||||
|
|
||||||
|
txbuf[0] = 0xd0;
|
||||||
|
TP_CS_LOW;
|
||||||
|
spiSend(&SPID1, 1, txbuf);
|
||||||
|
spiReceive(&SPID1, 2, rxbuf);
|
||||||
|
TP_CS_HIGH;
|
||||||
|
|
||||||
|
x = rxbuf[0] << 4;
|
||||||
|
x |= rxbuf[1] >> 4;
|
||||||
|
|
||||||
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t tp_lld_read_x(void) {
|
__inline uint16_t lld_tpReadY(void) {
|
||||||
return 42;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t tp_lld_read_y(void) {
|
__inline uint16_t lld_tpReadZ(void) {
|
||||||
return 42;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t tp_lld_read_z(void) {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _XPT2046_H */
|
#endif /* _XPT2046_H */
|
||||||
|
|
||||||
|
|
|
@ -60,21 +60,17 @@ extern "C" {
|
||||||
uint16_t tpReadY(void);
|
uint16_t tpReadY(void);
|
||||||
|
|
||||||
#if TOUCHPAD_PRESSURE
|
#if TOUCHPAD_PRESSURE
|
||||||
|
|
||||||
uint16_t tpReadZ(void);
|
uint16_t tpReadZ(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define tpInit(tp) tp_lld_init()
|
#define tpInit(tp) tp_lld_init(tp)
|
||||||
#define tpReadX() tp_lld_read_x()
|
#define tpReadX() tp_lld_read_x()
|
||||||
#define tpReadY() tp_lld_read_y()
|
#define tpReadY() tp_lld_read_y()
|
||||||
|
|
||||||
#if TOUCHPAD_PRESSURE
|
#if TOUCHPAD_PRESSURE
|
||||||
|
|
||||||
#define tpReadZ() tp_lld_read_z()
|
#define tpReadZ() tp_lld_read_z()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -55,7 +55,11 @@ typedef struct TOUCHPADDriver TOUCHPADDriver;
|
||||||
* @brief Structure representing a Touchpad driver.
|
* @brief Structure representing a Touchpad driver.
|
||||||
*/
|
*/
|
||||||
struct TOUCHPADDriver {
|
struct TOUCHPADDriver {
|
||||||
/* ToDo */
|
/*
|
||||||
|
* @brief Pointer to SPI driver.
|
||||||
|
* @note SPI driver must be enabled in mcu- and halconf.h
|
||||||
|
*/
|
||||||
|
SPIDriver *spid;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -71,7 +75,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Core functions */
|
/* Core functions */
|
||||||
void tp_lld_init(void);
|
void tp_lld_init(TOUCHPADDriver *tp);
|
||||||
uint16_t tp_lld_read_x(void);
|
uint16_t tp_lld_read_x(void);
|
||||||
uint16_t tp_lld_read_y(void);
|
uint16_t tp_lld_read_y(void);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue