Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- * SEGGER Microcontroller GmbH & Co. KG *
- * Solutions for real time microcontroller applications *
- **********************************************************************
- * *
- * (c) 1996 - 2012 SEGGER Microcontroller GmbH & Co. KG *
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- ** emWin V5.12 - Graphical user interface for embedded applications **
- emWin is protected by international copyright laws. Knowledge of the
- source code may not be used to write a similar product. This file may
- only be used in accordance with a license and should not be re-
- distributed in any way. We appreciate your understanding and fairness.
- ----------------------------------------------------------------------
- File : TouchConf.c
- Purpose : Touch screen hardware access routines and driver
- configuration for Texas Instruments ADS7846 touch
- screen controller.
- ---------------------------END-OF-HEADER------------------------------
- */
- //#include "RTOS.h"
- #include "GUI.h"
- #include "main.h"
- #include "GUI_Type.h"
- #include "GUITDRV_ADS7846.h"
- #include "usart.h";
- #include <string.h>
- /*********************************************************************
- *
- * Macros
- *
- **********************************************************************
- */
- // #define DEBUG_TOUCH
- s[30];
- #define S_DELAY() {for (int i=0; i < 3000; i++){ \
- asm( \
- "mov r0, r0\n\t"\
- "mov r0, r0\n\t"\
- "mov r0, r0"\
- );}};
- #define CLK_SET() {S_DELAY(); HAL_GPIO_WritePin(T_SCK_GPIO_Port, T_SCK_Pin, GPIO_PIN_SET);}
- #define CLK_CLR() {S_DELAY(); HAL_GPIO_WritePin(T_SCK_GPIO_Port, T_SCK_Pin, GPIO_PIN_RESET);}
- //#define CLK_SET() {HAL_Delay(1); HAL_GPIO_WritePin(T_SCK_GPIO_Port, T_SCK_Pin, GPIO_PIN_SET);}
- //#define CLK_CLR() {HAL_Delay(1); HAL_GPIO_WritePin(T_SCK_GPIO_Port, T_SCK_Pin, GPIO_PIN_RESET);}
- #define CS_SET() HAL_GPIO_WritePin(T_CS_GPIO_Port, T_CS_Pin, GPIO_PIN_RESET)
- #define CS_CLR() HAL_GPIO_WritePin(T_CS_GPIO_Port, T_CS_Pin, GPIO_PIN_SET)
- #define DO_SET() HAL_GPIO_WritePin(T_MOSI_GPIO_Port, T_MOSI_Pin, GPIO_PIN_SET)
- #define DO_CLR() HAL_GPIO_WritePin(T_MOSI_GPIO_Port, T_MOSI_Pin, GPIO_PIN_RESET)
- #define DI_VAL() HAL_GPIO_ReadPin(T_MISO_GPIO_Port, T_MISO_Pin)
- #define BUSY_VAL() (0)
- #define PENIRQ_VAL() HAL_GPIO_ReadPin(T_PEN_GPIO_Port, T_PEN_Pin)
- /*********************************************************************
- *
- * Local functions
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _SendCmd
- *
- * Purpose:
- * Write 8 bit command to peripheral.
- */
- void _SendCmd(U8 Data) {
- int i;
- /* sprintf(s, "CMD: %2x\r\n", Data);
- HAL_UART_Transmit(&huart1, (uint8_t*)s, strlen(s), 20);
- */
- for (i = 0; i < 8; i++) {
- //
- // Output next bit
- //
- if (Data & (1 << 7)) {
- DO_SET();
- } else {
- DO_CLR();
- }
- //
- // Output one clock and prepare next bit
- //
- CLK_SET();
- CLK_CLR();
- Data <<= 1;
- }
- }
- /*********************************************************************
- *
- * _GetResult
- *
- * Purpose:
- * Read 16 bit result from peripheral.
- *
- * Return value:
- * 16 bit AD value.
- */
- U16 _GetResult(void) {
- U16 r;
- int i;
- U8 v;
- for (i = 0; i < 16; i++) {
- r <<= 1;
- if (DI_VAL()) {
- r |= 1;
- }
- CLK_SET();
- CLK_CLR();
- }
- r >>= 4; // Remove padding bytes
- #ifdef DEBUG_TOUCH
- if (r)
- {
- sprintf(s, "Res: %4x\r\n", r);
- HAL_UART_Transmit(&huart1, (uint8_t*)s, strlen(s), 20);
- }
- #endif
- return r;
- }
- /*********************************************************************
- *
- * _GetBusy
- *
- * Purpose:
- * Checks the busy line of the peripheral.
- *
- * Return value:
- * 0 = Peripheral ready
- * 1 = Peripheral busy
- */
- char _GetBusy(void) {
- //
- // Output one clock as the busy line will only get low when
- // providing a clock. After one clock the output data is ready
- // thus needing one clock less in the _GetResult() routine. The
- // _GetResult() routine can output more clocks than necessary as
- // they are ignored.
- //
- CLK_SET();
- CLK_CLR();
- //
- // Check busy line just to be sure that the peripheral is ready and data
- // has been already shifted out with the last clock.
- //
- //if (BUSY_VAL()) {
- // return 1;
- //}
- return 0;
- }
- /*********************************************************************
- *
- * _GetPENIRQ
- *
- * Purpose:
- * Checks the PENIRQ line of the peripheral for a touch event.
- *
- * Return value:
- * 0 = No touch event
- * 1 = Touch can be sampled
- */
- char _GetPENIRQ(void) {
- if (PENIRQ_VAL()) {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- /*********************************************************************
- *
- * _SetCS
- *
- * Purpose:
- * Sets the chip select line of the peripheral.
- */
- void _SetCS(char OnOff) {
- if (OnOff) {
- CS_SET();
- } else {
- CS_CLR();
- }
- }
- /*********************************************************************
- *
- * Public functions
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * TOUCH_X_Init
- *
- * Purpose:
- * Fill in the touch API routines and initalize the touch screen driver.
- */
- void TOUCH_X_Init(void);
- void TOUCH_X_Init(void) {
- GUITDRV_ADS7846_CONFIG Config = {0};
- Config.pfSendCmd = _SendCmd;
- Config.pfGetResult = _GetResult;
- Config.pfGetBusy = _GetBusy;
- Config.pfGetPENIRQ = _GetPENIRQ;
- Config.pfSetCS = _SetCS;
- Config.xLog0 = 0;
- Config.xLog1 = 240;
- Config.xPhys0 = 200;
- Config.xPhys1 = 3800;
- Config.yLog0 = 0;
- Config.yLog1 = 320;
- Config.yPhys0 = 320;
- Config.yPhys1 = 3700;
- Config.Orientation = GUI_SWAP_XY;
- GUITDRV_ADS7846_Config(&Config);
- }
- /*************************** End of file ****************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement