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. */
|
||||
/*===========================================================================*/
|
||||
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. */
|
||||
|
@ -78,11 +84,8 @@
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
void tp_lld_init(void) {
|
||||
/* Initialise the TOUCHPAD structure */
|
||||
|
||||
/* ToDo */
|
||||
(void)tp;
|
||||
void tp_lld_init(TOUCHPADDriver *tp) {
|
||||
spiStart(tp->spid, &spicfg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +115,7 @@ uint16_t tp_lld_read_y(void) {
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
uint16_t tp_lld_read_y(void) {
|
||||
uint16_t tp_lld_read_z(void) {
|
||||
/* ToDo */
|
||||
return 42;
|
||||
}
|
||||
|
@ -120,3 +123,4 @@ uint16_t tp_lld_read_y(void) {
|
|||
|
||||
#endif /* HAL_USE_TOUCHPAD */
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -21,20 +21,50 @@
|
|||
#ifndef _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) {
|
||||
return 42;
|
||||
__inline uint16_t lld_tpReadY(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;
|
||||
}
|
||||
|
||||
uint16_t tp_lld_read_y(void) {
|
||||
return 42;
|
||||
__inline uint16_t lld_tpReadZ(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t tp_lld_read_z(void) {
|
||||
return 42;
|
||||
}
|
||||
|
||||
#endif /* _XPT2046_H */
|
||||
|
||||
|
|
|
@ -60,21 +60,17 @@ extern "C" {
|
|||
uint16_t tpReadY(void);
|
||||
|
||||
#if TOUCHPAD_PRESSURE
|
||||
|
||||
uint16_t tpReadZ(void);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define tpInit(tp) tp_lld_init()
|
||||
#define tpInit(tp) tp_lld_init(tp)
|
||||
#define tpReadX() tp_lld_read_x()
|
||||
#define tpReadY() tp_lld_read_y()
|
||||
|
||||
#if TOUCHPAD_PRESSURE
|
||||
|
||||
#define tpReadZ() tp_lld_read_z()
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -55,7 +55,11 @@ typedef struct TOUCHPADDriver TOUCHPADDriver;
|
|||
* @brief Structure representing a Touchpad driver.
|
||||
*/
|
||||
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
|
||||
|
||||
/* 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_y(void);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue