/* * 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.io/license.html */ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H // Resolution and Accuracy Settings #define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8 #define GMOUSE_ADS7843_PEN_CLICK_ERROR 6 #define GMOUSE_ADS7843_PEN_MOVE_ERROR 4 #define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14 #define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18 #define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14 // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 #define T_CS_HIGH palSetPad(GPIOC, 13) #define T_CS_LOW palClearPad(GPIOC, 13) #define T_SCK_HIGH palSetPad(GPIOB, 0) #define T_SCK_LOW palClearPad(GPIOB, 0) #define T_MOSI_HIGH palSetPad(GPIOF, 11) #define T_MOSI_LOW palClearPad(GPIOF, 11) #define T_MISO_LVL palReadPad(GPIOB, 1) /** * @brief Initialise the board for the touch. * * @notapi * * ADS7843 (clone chip) is connected to this pins: * T_CS GPIOC_PIN13 * T_SCK GPIOB_PIN0 * T_MISO GPIOB_PIN2 * T_MOSI GPIOF_PIN11 * T_PEN GPIOB_PIN1 */ static gBool init_board(GMouse* m, unsigned driverinstance) { (void)m; (void)driverinstance; /* palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 2, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOF, 11, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 1, PAL_MODE_INPUT); * GPIO config must be done by board.h */ T_CS_HIGH; T_SCK_LOW; return true; } /** * @brief Check whether the surface is currently touched * @return TRUE if the surface is currently touched * * @notapi * PB1 is connected to TP_IRQ (low active). */ static GFXINLINE gBool getpin_pressed(GMouse* m) { (void)m; return (!palReadPad(GPIOB, T_PEN)); } /** * @brief Aquire the bus ready for readings * * @notapi * PC13 is connected to TP_CS (low active): */ static GFXINLINE void aquire_bus(GMouse* m) { (void)m; T_CS_LOW; T_SCK_LOW; } /** * @brief Release the bus after readings * * @notapi */ static GFXINLINE void release_bus(GMouse* m) { (void)m; T_CS_HIGH; } /** * @brief Write a value to touch controller * @return none * * params[in] value The value to be write. * * @notapi */ static GFXINLINE void write_value(GMouse* m, gU16 value) { (void)m; int i; for (i=8; i>0; i--) { T_SCK_LOW; if (value & 0x0080) { T_MOSI_HIGH; } else { T_MOSI_LOW; } asm("nop"); value <<= 1; T_SCK_HIGH; } } /** * @brief Read a value from touch controller * @return The value read from the controller * * params[in] port The controller port to read. * * @notapi */ static GFXINLINE gU16 read_value(GMouse* m, gU16 port) { (void)m; int i; gU16 data = 0; write_value(m, port); gfxSleepMicroseconds(6); //The conversion time of ADS7846 is up to 6us T_SCK_LOW; asm("nop"); // or gfxSleepMicroseconds(1) ? T_SCK_HIGH; //Give 1 clock, clear BUSY asm("nop"); //Read 16-bit data, only the upper 12 bits are valid for (i=16; i>0; i--) { T_SCK_LOW; data <<= 1; asm("nop"); T_SCK_HIGH; if (T_MISO_LVL) { data ++; } } data >>= 4; return data; } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */