initial working (stm32f4-discovery)

This commit is contained in:
2026-07-31 19:07:15 +03:00
commit ce6632f48c
2214 changed files with 1264937 additions and 0 deletions
@@ -0,0 +1,37 @@
---
name: 'Bug report'
about: 'Create a report to help us improve the quality of our software'
title: ''
labels: ''
assignees: ''
---
**Caution**
The Issues are strictly limited for the reporting of problem encountered with the software provided in this project.
For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post your report to the **ST Community** in the STM32 MCUs dedicated [page](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus).
**Describe the set-up**
* The board (either ST RPN reference or your custom board)
* IDE or at least the compiler and its version
**Describe the bug (skip if none)**
A clear and concise description of what the bug is.
**How to reproduce the bug (skip if none)**
1. Indicate the global behavior of your application project
2. List the modules that you suspect to be the cause of the problem (Drivers, BSP, MW...)
3. Describe the use case that generates the problem
4. How we can reproduce the problem
**Additional context**
If you have a first analysis, an enhancement, a fix or a patch, thank you to share your proposal.
**Screenshots**
If applicable, add screenshots to help explain your problem.
@@ -0,0 +1,3 @@
## IMPORTANT INFORMATION
Pull-requests are **not** accepted on this repository. Please use issues to report any bug or request.
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team via this [link](https://www.st.com/content/st_com/en/contact-us.html).
All complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4,
available [here](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html).
For answers to common questions about this code of conduct, see the [FAQ section](https://www.contributor-covenant.org/faq).
@@ -0,0 +1,28 @@
## Contributing guide
This document serves as a checklist before contributing to this repository.
It includes links to read up on if topics are unclear to you.
This guide mainly focuses on steps to be followed to submit an issue or a pull-request.
### 1. Before opening an issue
To report a bug or a request please file an issue in the right repository
(example for [stmpe1600](https://github.com/STMicroelectronics/stmpe1600/issues/new/choose)).
Please check the following boxes before posting an issue:
- [ ] `Make sure you are using the latest commit (major releases are tagged, but corrections are available as new commits).`
- [ ] `Make sure your issue is a question/feedback/suggestions RELATED TO the software provided in this repository.` Otherwise, it should be submitted to the ST Community under the MCU topic [page](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus).
- [ ] `Make sure your issue is not already reported/fixed on GitHub or discussed on a previous issue.` Please refer to this [dashboard](https://github.com/orgs/STMicroelectronics/projects/2) for the list of issues and pull-requests. Do not forget to browse into the **closed** issues.
### 2. Posting the issue
When you have checked the previous boxes. You will find two templates (Bug Report or Other Issue) available in the **Issues** tab of the repository.
### 3. Pull Requests
Pull-requests are **not** accepted on this repository. Please use **issues** to report any bug or request.
### 4. How to proceed
* We recommend to engage first a communication thru an issue, in order to present your proposal. Just to confirm that it corresponds to STMicroelectronics domain or scope.
* Then fork the project to your GitHub account to further develop your contribution. Please use the latest commit version.
* Please, submit one Pull Request for one new feature or proposal. This will ease the analysis and the final merge if accepted.
@@ -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,40 @@
# BSP STMPE1600 Component
## Overview
**STM32Cube** is an STMicroelectronics original initiative to ease the developers life by reducing efforts, time and cost.
**STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series.
* The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
* The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio.
* The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series.
* A consistent set of middleware components such as RTOS, USB, FatFS, graphics, touch sensing library...
* A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series.
Two models of publication are proposed for the STM32Cube embedded software:
* The monolithic **MCU Package**: all STM32Cube software modules of one STM32 series are present (Drivers, Middleware, Projects, Utilities) in the repository (usual name **STM32Cubexx**, xx corresponding to the STM32 series).
* The **MCU component**: each STM32Cube software module being part of the STM32Cube MCU Package, is delivered as an individual repository, allowing the user to select and get only the required software functions.
## Description
This **stmpe1600** MCU component repository is one element **common to all** STM32Cube MCU embedded software packages, providing the **STMPE1600** BSP IOE component part.
## License
Copyright (c) 2014 STMicroelectronics
This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this software except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause).
## Release note
Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stmpe1600/blob/main/Release_Notes.html).
## Compatibility information
Please refer to the repository of the BSP **board** driver you are using to know which version of this BSP component driver to use. It is **crucial** that you use a consistent set of versions.
## Troubleshooting
If you have any issue with the **software content** of this repository, you can file an issue [here](https://github.com/STMicroelectronics/stmpe1600/issues/new/choose).
For any other question related to the product, the tools, the environment, you can submit a topic to the [ST Community](https://community.st.com/s/).
@@ -0,0 +1,31 @@
# Report potential product security vulnerabilities
ST places a high priority on security, and our Product Security Incident
Response Team (PSIRT) is committed to rapidly addressing potential security
vulnerabilities affecting our products. PSIRT's long history and vast experience
in security allows ST to perform clear analyses and provide appropriate guidance
on mitigations and solutions when applicable.
If you wish to report potential security vulnerabilities regarding our products,
**please do not report them through public GitHub issues.** Instead, we
encourage you to report them to our ST PSIRT following the process described at:
**https://www.st.com/content/st_com/en/security/report-vulnerabilities.html**
### IMPORTANT - READ CAREFULLY:
STMicroelectronics International N.V., on behalf of itself, its affiliates and
subsidiaries, (collectively “ST”) takes all potential security vulnerability
reports or other related communications (“Report(s)”) seriously. In order to
review Your Report (the terms “You” and “Yours” include your employer, and all
affiliates, subsidiaries and related persons or entities) and take actions as
deemed appropriate, ST requires that we have the rights and Your permission to
do so.
As such, by submitting Your Report to ST, You agree that You have the right to
do so, and You grant to ST the rights to use the Report for purposes related to
security vulnerability analysis, testing, correction, patching, reporting and
any other related purpose or function.
By submitting Your Report, You agree that ST’s
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
applies to all related communications.
@@ -0,0 +1,584 @@
/**
******************************************************************************
* @file stmpe1600.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the STMPE1600
* IO Expander devices.
******************************************************************************
* @attention
*
* Copyright (c) 2015 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 "stmpe1600.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @defgroup STMPE1600
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Types_Definitions
* @{
*/
/* Private define ------------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Defines
* @{
*/
#define STMPE1600_MAX_INSTANCE 2
/* Private macro -------------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Macros
* @{
*/
/* Private variables ---------------------------------------------------------*/
static uint16_t tmp = 0;
/** @defgroup STMPE1600_Private_Variables
* @{
*/
/* IO driver structure initialization */
IO_DrvTypeDef stmpe1600_io_drv =
{
stmpe1600_Init,
stmpe1600_ReadID,
stmpe1600_Reset,
stmpe1600_Start,
stmpe1600_IO_Config,
stmpe1600_IO_WritePin,
stmpe1600_IO_ReadPin,
0,
0,
stmpe1600_IO_ITStatus,
stmpe1600_IO_ClearIT,
};
uint8_t stmpe1600[STMPE1600_MAX_INSTANCE] = {0};
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup STMPE1600_Private_Function_Prototypes
* @{
*/
static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr);
/* Private functions ---------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Functions
* @{
*/
/**
* @brief Initialize the stmpe1600 and configure the needed hardware resources
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_Init(uint16_t DeviceAddr)
{
uint8_t instance;
uint8_t empty;
/* Check if device instance already exists */
instance = stmpe1600_GetInstance(DeviceAddr);
if(instance == 0xFF)
{
/* Look for empty instance */
empty = stmpe1600_GetInstance(0);
if(empty < STMPE1600_MAX_INSTANCE)
{
/* Register the current device instance */
stmpe1600[empty] = DeviceAddr;
/* Initialize IO BUS layer */
IOE_Init();
/* Generate stmpe1600 Software reset */
stmpe1600_Reset(DeviceAddr);
}
}
}
/**
* @brief Configures the touch Screen Controller (Single point detection)
* @param DeviceAddr: Device address on communication Bus.
* @retval None.
*/
void stmpe1600_Start(uint16_t DeviceAddr, uint32_t IO_Pin)
{
/*Configuration already done during the initialization */
}
/**
* @brief Reset the stmpe1600 by Software.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_Reset(uint16_t DeviceAddr)
{
/* Power Down the stmpe1600 */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x80);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(2);
/* Power On the Codec after the power off: all registers are reinitialized */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x00);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(2);
}
/**
* @brief Read the stmpe1600 device ID.
* @param DeviceAddr: Device address on communication Bus.
* @retval The Device ID (two bytes).
*/
uint16_t stmpe1600_ReadID(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Initialize IO BUS layer */
IOE_Init();
/* Read the stmpe1600 device ID */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_CHP_ID, tmpData, 2);
/* Return the device ID value */
return((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
}
/**
* @brief Set the global interrupt Polarity.
* @param DeviceAddr: Device address on communication Bus.
* @param Polarity: could be one of these values;
* @arg STMPE1600_POLARITY_LOW: Interrupt line is active Low/Falling edge
* @arg STMPE1600_POLARITY_HIGH: Interrupt line is active High/Rising edge
* @retval None
*/
void stmpe1600_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity)
{
uint8_t tmp = 0;
/* Get the current register value */
tmp = IOE_Read(DeviceAddr, STMPE1600_REG_SYS_CTRL);
/* Mask the polarity bit */
tmp &= ~(uint16_t)0x01;
/* Set the Interrupt Output line polarity */
tmp |= (uint8_t)Polarity;
/* Set the new register value */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmp);
}
/**
* @brief Enable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Configure NVIC IT for IOE */
IOE_ITConfig();
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the global interrupts to be Enabled */
tmp |= (uint16_t)STMPE1600_IT_ENABLE;
/* Write Back the Interrupt Control register */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the global interrupts to be Enabled */
tmp &= ~(uint16_t)STMPE1600_IT_ENABLE;
/* Write Back the Interrupt Control register */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2);
}
/**
* @brief Initialize the selected pin(s) direction.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @param Direction: could be STMPE1600_DIRECTION_IN or STMPE1600_DIRECTION_OUT.
* @retval None
*/
void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPDR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the Pin direction */
if (Direction != STMPE1600_DIRECTION_IN)
{
tmp |= (uint16_t)IO_Pin;
}
else
{
tmp &= ~(uint16_t)IO_Pin;
}
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPDR, (uint8_t *)&tmp, 2);
}
/**
* @brief Configure the IO pin(s) according to IO mode structure value.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The output pin to be set or reset. This parameter can be one
* of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 7.
* @param IO_Mode: The IO pin mode to configure, could be one of the following values:
* @arg IO_MODE_INPUT
* @arg IO_MODE_OUTPUT
* @arg IO_MODE_IT_RISING_EDGE
* @arg IO_MODE_IT_FALLING_EDGE
* @retval 0 if no error, IO_Mode if error
*/
uint8_t stmpe1600_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode)
{
uint8_t error_code = 0;
uint8_t buffer[2] = {0,0};
/* Configure IO pin according to selected IO mode */
switch(IO_Mode)
{
case IO_MODE_INPUT: /* Input mode */
stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
break;
case IO_MODE_OUTPUT: /* Output mode */
stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_OUT);
break;
case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */
stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_HIGH);
stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
/* Clear all IO IT pending bits if any */
stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
/* Read GMPR to enable interrupt */
IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);
break;
case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */
stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_LOW);
stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
/* Clear all IO IT pending bits if any */
stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
/* Read GMPR to enable interrupt */
IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);
break;
default:
error_code = (uint8_t) IO_Mode;
break;
}
return error_code;
}
/**
* @brief Enable polarity inversion of the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_PolarityInv_Enable(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Enable pin polarity inversion */
tmp |= (uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable polarity inversion of the selected IO pins.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Disable pin polarity inversion */
tmp &= ~ (uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2);
}
/**
* @brief Set the value of the selected IO pins.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be set.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @param PinState: The value to be set.
* @retval None
*/
void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the pin state */
if(PinState != 0)
{
tmp |= (uint16_t)IO_Pin;
}
else
{
tmp &= ~(uint16_t)IO_Pin;
}
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPSR, (uint8_t *)&tmp, 2);
}
/**
* @brief Read the state of the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be read.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval State of the selected IO pin(s).
*/
uint32_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return the pin(s) state */
return(tmp & IO_Pin);
}
/**
* @brief Enable the interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Enable global interrupt */
stmpe1600_EnableGlobalIT(DeviceAddr);
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Put pin in IT mode */
tmp |= (uint16_t)IO_Pin;
/* Write the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable the interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Disable the IT pin mode */
tmp &= ~(uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2);
}
/**
* @brief Read the IT status of the selected IO pin(s)
* (clears all the pending bits if any).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be checked.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval IT Status of the selected IO pin(s).
*/
uint32_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return the pin IT status */
return((tmp & IO_Pin) == IO_Pin);
}
/**
* @brief Detect an IT pending bit from the selected IO pin(s).
* (clears all the pending bits if any).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be checked.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval IT pending bit detection status.
*/
uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return if there is an IT pending bit or not */
return(tmp & IO_Pin);
}
/**
* @brief Clear all the IT pending bits if any.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value to clear all pending bits */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
}
/**
* @brief Check if the device instance of the selected address is already registered
* and return its index
* @param DeviceAddr: Device address on communication Bus.
* @retval Index of the device instance if registered, 0xFF if not.
*/
static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr)
{
uint8_t idx = 0;
/* Check all the registered instances */
for(idx = 0; idx < STMPE1600_MAX_INSTANCE ; idx ++)
{
/* Return index if there is address match */
if(stmpe1600[idx] == DeviceAddr)
{
return idx;
}
}
return 0xFF;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,193 @@
/**
******************************************************************************
* @file stmpe1600.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the
* stmpe1600.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 __STMPE1600_H
#define __STMPE1600_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/io.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup STMPE1600
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Types
* @{
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Constants
* @{
*/
/**
* @brief STMPE1600 chip IDs
*/
#define STMPE1600_ID 0x1600
/**
* @brief Interrupt enable
*/
#define STMPE1600_IT_ENABLE 0x04
/**
* @brief Identification registers & System Control
*/
#define STMPE1600_REG_CHP_ID 0x00
#define STMPE1600_REG_ID_VERSION 0x02
#define STMPE1600_REG_SYS_CTRL 0x03
/**
* @brief IO Registers
*/
#define STMPE1600_REG_GPMR 0x10
#define STMPE1600_REG_GPSR 0x12
#define STMPE1600_REG_GPDR 0x14
#define STMPE1600_REG_GPPIR 0x16
/**
* @brief Interrupt Control registers
*/
#define STMPE1600_REG_IEGPIOR 0x08
#define STMPE1600_REG_ISGPIOR 0x0A
/**
* @brief IO Pins direction
*/
#define STMPE1600_DIRECTION_IN 0x00
#define STMPE1600_DIRECTION_OUT 0x01
/**
* @brief IO IT polarity
*/
#define STMPE1600_POLARITY_LOW 0x00
#define STMPE1600_POLARITY_HIGH 0x01
/**
* @brief IO Pins
*/
#define STMPE1600_PIN_0 0x0001
#define STMPE1600_PIN_1 0x0002
#define STMPE1600_PIN_2 0x0004
#define STMPE1600_PIN_3 0x0008
#define STMPE1600_PIN_4 0x0010
#define STMPE1600_PIN_5 0x0020
#define STMPE1600_PIN_6 0x0040
#define STMPE1600_PIN_7 0x0080
#define STMPE1600_PIN_8 0x0100
#define STMPE1600_PIN_9 0x0200
#define STMPE1600_PIN_10 0x0400
#define STMPE1600_PIN_11 0x0800
#define STMPE1600_PIN_12 0x1000
#define STMPE1600_PIN_13 0x2000
#define STMPE1600_PIN_14 0x4000
#define STMPE1600_PIN_15 0x8000
#define STMPE1600_PIN_ALL 0xFFFF
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Macros
* @{
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Functions
* @{
*/
/**
* @brief STMPE1600 Control functions
*/
void stmpe1600_Init(uint16_t DeviceAddr);
void stmpe1600_Reset(uint16_t DeviceAddr);
uint16_t stmpe1600_ReadID(uint16_t DeviceAddr);
void stmpe1600_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity);
void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr);
void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr);
/**
* @brief STMPE1600 IO functionalities functions
*/
void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
uint8_t stmpe1600_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
void stmpe1600_IO_PolarityInv_Enable(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
uint32_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
uint32_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
void IOE_Init(void);
void IOE_ITConfig (void);
void IOE_Delay(uint32_t delay);
void IOE_Write(uint8_t addr, uint8_t reg, uint8_t value);
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);
/* STMPE1600 driver structure */
extern IO_DrvTypeDef stmpe1600_io_drv;
#ifdef __cplusplus
}
#endif
#endif /* __STMPE1600_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/