initial working (stm32f4-discovery)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
Copyright 2017 STMicroelectronics.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,236 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ts3510.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides a set of functions needed to manage the TS3510
|
||||
* IO Expander devices.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2014 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ts3510.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup TS3510
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Private_Types_Definitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Touch screen driver structure initialization */
|
||||
TS_DrvTypeDef ts3510_ts_drv =
|
||||
{
|
||||
ts3510_Init,
|
||||
ts3510_ReadID,
|
||||
ts3510_Reset,
|
||||
|
||||
ts3510_TS_Start,
|
||||
ts3510_TS_DetectTouch,
|
||||
ts3510_TS_GetXY,
|
||||
|
||||
ts3510_TS_EnableIT,
|
||||
ts3510_TS_ClearIT,
|
||||
ts3510_TS_ITStatus,
|
||||
ts3510_TS_DisableIT,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/** @defgroup ts3510_Private_Function_Prototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ts3510_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize the ts3510 and configure the needed hardware resources
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None
|
||||
*/
|
||||
void ts3510_Init(uint16_t DeviceAddr)
|
||||
{
|
||||
/* Initialize IO BUS layer */
|
||||
IOE_Init();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the ts3510 by Software.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None
|
||||
*/
|
||||
void ts3510_Reset(uint16_t DeviceAddr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the ts3510 IO Expander device ID.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval The Device ID (two bytes).
|
||||
*/
|
||||
uint16_t ts3510_ReadID(uint16_t DeviceAddr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the touch Screen Controller (Single point detection)
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None.
|
||||
*/
|
||||
void ts3510_TS_Start(uint16_t DeviceAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return if there is touch detected or not.
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval Touch detected state.
|
||||
*/
|
||||
uint8_t ts3510_TS_DetectTouch(uint16_t DeviceAddr)
|
||||
{
|
||||
uint8_t aBufferTS[11];
|
||||
uint8_t aTmpBuffer[2] = {TS3510_READ_CMD, TS3510_WRITE_CMD};
|
||||
|
||||
/* Prepare for LCD read data */
|
||||
IOE_WriteMultiple(DeviceAddr, TS3510_SEND_CMD_REG, aTmpBuffer, 2);
|
||||
|
||||
/* Read TS data from LCD */
|
||||
IOE_ReadMultiple(DeviceAddr, TS3510_READ_BLOCK_REG, aBufferTS, 11);
|
||||
|
||||
/* check for first byte */
|
||||
if((aBufferTS[1] == 0xFF) && (aBufferTS[2] == 0xFF) && (aBufferTS[3] == 0xFF) && (aBufferTS[4] == 0xFF))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the touch screen X and Y positions values
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @param X: Pointer to X position value
|
||||
* @param Y: Pointer to Y position value
|
||||
* @retval None.
|
||||
*/
|
||||
void ts3510_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
|
||||
{
|
||||
uint8_t aBufferTS[11];
|
||||
uint8_t aTmpBuffer[2] = {TS3510_READ_CMD, TS3510_WRITE_CMD};
|
||||
|
||||
/* Prepare for LCD read data */
|
||||
IOE_WriteMultiple(DeviceAddr, TS3510_SEND_CMD_REG, aTmpBuffer, 2);
|
||||
|
||||
/* Read TS data from LCD */
|
||||
IOE_ReadMultiple(DeviceAddr, TS3510_READ_BLOCK_REG, aBufferTS, 11);
|
||||
|
||||
/* Calculate positions */
|
||||
*X = (((aBufferTS[1] << 8) | aBufferTS[2]) << 12) / 640;
|
||||
*Y = (((aBufferTS[3] << 8) | aBufferTS[4]) << 12) / 480;
|
||||
|
||||
/* set position to be relative to 12bits resolution */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the selected source to generate a global interrupt or not
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None
|
||||
*/
|
||||
void ts3510_TS_EnableIT(uint16_t DeviceAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the selected source to generate a global interrupt or not
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None
|
||||
*/
|
||||
void ts3510_TS_DisableIT(uint16_t DeviceAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the selected source to generate a global interrupt or not
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval TS interrupts status
|
||||
*/
|
||||
uint8_t ts3510_TS_ITStatus(uint16_t DeviceAddr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the selected source to generate a global interrupt or not
|
||||
* @param DeviceAddr: Device address on communication Bus.
|
||||
* @retval None
|
||||
*/
|
||||
void ts3510_TS_ClearIT(uint16_t DeviceAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ts3510.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains all the functions prototypes for the
|
||||
* ts3510.c IO expander driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2014 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TS3510_H
|
||||
#define __TS3510_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../Common/ts.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Component
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup TS3510
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup TS3510_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* */
|
||||
#define TS3510_READ_BLOCK_REG 0x8A
|
||||
#define TS3510_SEND_CMD_REG 0x00
|
||||
#define TS3510_READ_CMD 0x81
|
||||
#define TS3510_WRITE_CMD 0x08
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ts3510_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup ts3510_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief ts3510 Control functions
|
||||
*/
|
||||
void ts3510_Init(uint16_t DeviceAddr);
|
||||
void ts3510_Reset(uint16_t DeviceAddr);
|
||||
uint16_t ts3510_ReadID(uint16_t DeviceAddr);
|
||||
void ts3510_TS_Start(uint16_t DeviceAddr);
|
||||
uint8_t ts3510_TS_DetectTouch(uint16_t DeviceAddr);
|
||||
void ts3510_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
|
||||
void ts3510_TS_EnableIT(uint16_t DeviceAddr);
|
||||
void ts3510_TS_DisableIT(uint16_t DeviceAddr);
|
||||
uint8_t ts3510_TS_ITStatus (uint16_t DeviceAddr);
|
||||
void ts3510_TS_ClearIT (uint16_t DeviceAddr);
|
||||
|
||||
void IOE_Init(void);
|
||||
void IOE_Delay(uint32_t delay);
|
||||
uint8_t IOE_Read(uint8_t addr, uint8_t reg);
|
||||
uint16_t IOE_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
|
||||
void IOE_WriteMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
|
||||
|
||||
/* Touch screen driver structure */
|
||||
extern TS_DrvTypeDef ts3510_ts_drv;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __TS3510_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
Reference in New Issue
Block a user