Sync inav to Gitea
Make sure docs are updated / settings_md (push) Canceled after 0s
Build firmware / test (push) Canceled after 0s
Build firmware / build-SITL-Windows (push) Canceled after 0s
Build firmware / build-SITL-Mac (push) Canceled after 0s
Build firmware / build-SITL-Linux (push) Canceled after 0s
Build firmware / build-SITL-Linux-arm64 (push) Canceled after 0s
Build firmware / upload-artifacts (push) Canceled after 0s
Build firmware / build-single-target (push) Canceled after 0s
Build firmware / build (9) (push) Canceled after 0s
Build firmware / build (8) (push) Canceled after 0s
Build firmware / build (7) (push) Canceled after 0s
Build firmware / build (6) (push) Canceled after 0s
Build firmware / build (5) (push) Canceled after 0s
Build firmware / build (4) (push) Canceled after 0s
Build firmware / build (3) (push) Canceled after 0s
Build firmware / build (2) (push) Canceled after 0s
Build firmware / build (14) (push) Canceled after 0s
Build firmware / build (13) (push) Canceled after 0s
Build firmware / build (12) (push) Canceled after 0s
Build firmware / build (11) (push) Canceled after 0s
Build firmware / build (10) (push) Canceled after 0s
Build firmware / build (1) (push) Canceled after 0s
Build firmware / build (0) (push) Canceled after 0s
Build firmware / detect (push) Canceled after 0s
Build pre-release / build (push) Canceled after 0s
Build pre-release / Release (push) Canceled after 0s

This commit is contained in:
2026-08-03 16:37:40 +08:00
commit dac37fd077
14095 changed files with 5603119 additions and 0 deletions
@@ -0,0 +1,37 @@
---
name: 'Issue 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,5 @@
## IMPORTANT INFORMATION
### Contributor License Agreement (CLA)
* The Pull Request feature will be considered by STMicroelectronics after the signature of a **Contributor License Agreement (CLA)** by the submitter.
* If you did not sign such agreement, please follow the steps mentioned in the [CONTRIBUTING.md](CONTRIBUTING.md) file.
@@ -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, refer to the FAQ section [here](https://www.contributor-covenant.org/faq).
@@ -0,0 +1,40 @@
## Contributing guide
This guide serves as a checklist before contributing to this repository. It mainly focuses on the steps to follow to submit an issue or a pull-request.
### 1. Issues
#### 1.1 Before opening an issue
Please check the following points 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, please refer to section [3](CONTRIBUTING.md#3.-support-requests-and-questions) below.
* 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.
#### 1.2 Posting the issue
When you have checked the previous points, create a new report from the **Issues** tab of this repository. A template is available [here](issues/new/choose) to help you report the issue you are facing or the enhancement you would like to propose.
### 2. Pull Requests
#### 2.1 Before opening a pull-request
STMicrolectronics is happy to receive contributions from the community, based on an initial Contributor License Agreement (CLA) procedure.
* If you are an individual writing original source code and you are sure **you own the intellectual property**, then you need to sign an Individual [CLA](https://cla.st.com).
* If you work for a company that wants also to allow you to contribute with your work, your company needs to provide a Corporate [CLA](https://cla.st.com) mentioning your GitHub account name.
* If you are not sure that a CLA (Individual or Corporate) has been signed for your GitHub account you can check the [CLA](https://cla.st.com) dedicated page.
Please note that:
* The Corporate CLA will always take precedence over the Individual CLA.
* One CLA submission is sufficient, for any project proposed by STMicroelectronics.
#### 2.2 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 per new feature or proposal. This will ease the analysis and the final merge if accepted.
### 3. Support requests and questions
For support requests or any other question related to the product, the tools, the environment, you can submit a post to the **ST Community** on the appropriate topic [page](https://community.st.com/s/topiccatalog).
@@ -0,0 +1,11 @@
Copyright 2019 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,45 @@
# BSP STM32H747I-DICO Component
![latest tag](https://img.shields.io/github/v/tag/STMicroelectronics/stm32h747i-disco.svg?color=brightgreen)
## Overview
**STM32Cube** is an STMicroelectronics original initiative to ease 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 libraries 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 **stm32h747i-disco** MCU component repository is one element of the **STM32CubeH7** MCU embedded software package, providing the **STM32H747I-DICO** BSP BOARD component part.
## Release note
Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stm32h747i-disco/blob/main/Release_Notes.html).
## Compatibility information
Below is the list of the BSP *component* drivers to be used with this BSP *board* driver. It is **crucial** that you use a consistent set of CMSIS - HAL - BSP versions, as mentioned in [this](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Release_Notes.html) release note.
* [stm32-bsp-common](https://github.com/STMicroelectronics/stm32-bsp-common)
* [stm32-adv7533](https://github.com/STMicroelectronics/stm32-adv7533)
* [stm32-ft6x06](https://github.com/STMicroelectronics/stm32-ft6x06)
* [stm32-mt25tl01g](https://github.com/STMicroelectronics/stm32-mt25tl01g)
* [stm32-is42s32800j](https://github.com/STMicroelectronics/stm32-is42s32800j)
* [stm32-otm8009a](https://github.com/STMicroelectronics/stm32-otm8009a)
* [stm32-ov9655](https://github.com/STMicroelectronics/stm32-ov9655)
* [stm32-ov5640](https://github.com/STMicroelectronics/stm32-ov5640)
* [stm32-wm8994](https://github.com/STMicroelectronics/stm32-wm8994)
* [stm32-nt35510](https://github.com/STMicroelectronics/stm32-nt35510)
## Troubleshooting
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) guide.
@@ -0,0 +1,284 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Release Notes for STM32H747I-DISCO BSP Driver</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<link rel="stylesheet" href="_htmresc/mini-st_2020.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
<link rel="icon" type="image/x-icon" href="_htmresc/favicon.png" />
</head>
<body>
<div class="row">
<div class="col-sm-12 col-lg-4">
<center>
<h1 id="release-notes-for">Release Notes for</h1>
<h1 id="stm32h747i-disco-bsp-drivers"><mark>STM32H747I-DISCO BSP Drivers</mark></h1>
<p>Copyright © 2019 STMicroelectronics<br />
</p>
<a href="https://www.st.com" class="logo"><img src="_htmresc/st_logo_2020.png" alt="ST logo" /></a>
</center>
<h1 id="purpose">Purpose</h1>
<p>The BSP (Board Specific Package) drivers are parts of the STM32Cube package based on the HAL drivers and provide a set of high level APIs relative to the hardware components and features in the evaluation boards, discovery kits and nucleo boards coming with the STM32Cube package for a given STM32 series.</p>
<p>The BSP drivers allow a quick access to the boards services using high level APIs and without any specific configuration as the link with the HAL and the external components is done in intrinsic within the drivers.</p>
<p>From project settings points of view, user has only to add the necessary drivers files in the workspace and call the needed functions from examples. However some low level configuration functions are weak and can be overridden by the applications if user wants to change some BSP drivers default behavior.</p>
</div>
<div class="col-sm-12 col-lg-8">
<h1 id="update-history"><strong>Update History</strong></h1>
<div class="collapse">
<input type="checkbox" id="collapse-section13" checked aria-hidden="true"> <label for="collapse-section13" aria-hidden="true"><strong>V3.6.3 / 07-October-2024</strong></label>
<div>
<h2 id="main-changes">Main Changes</h2>
<ul>
<li>Fix wrong LCD layer address definitions in stm32h747i_discovery_conf_template.h.</li>
<li>Fix audio mode of SAI play handle in BSP_AUDIO_IN_Init() API.</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section12" aria-hidden="true"> <label for="collapse-section12" aria-hidden="true"><strong>V3.6.2 / 12-March-2024</strong></label>
<div>
<h2 id="main-changes-1">Main Changes</h2>
<ul>
<li>Remove misleading comments.</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section11" aria-hidden="true"> <label for="collapse-section11" aria-hidden="true"><strong>V3.6.1 / 09-November-2023</strong></label>
<div>
<h2 id="main-changes-2">Main Changes</h2>
<ul>
<li>Increase timeout compliantly to the SD Cards specification.</li>
<li>Update LCD BSP Driver to support Dynamic ID.</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section10" aria-hidden="true"> <label for="collapse-section10" aria-hidden="true"><strong>V3.6.0 / 26-May-2023</strong></label>
<div>
<h2 id="main-changes-3">Main Changes</h2>
<ul>
<li>Update STM32H747I-DISC BSP drivers to support LCD based on nt35510 component.</li>
</ul>
<h2 id="notes">Notes</h2>
<ul>
<li>One of the following flags must be enabled in stm32h747i_discovery_conf.h file options in order to select the target daughter board revision connected on STM32H747I DISCOVERY :
<ul>
<li>USE_LCD_CTRL_OTM8009A : Applicable for all LCD daughter boards (MB1166) except for Rev -A09.</li>
<li>USE_LCD_CTRL_NT35510  : Applicable only for LCD daughter boards (MB1166) Rev -A09.</li>
</ul></li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section9" aria-hidden="true"> <label for="collapse-section9" aria-hidden="true"><strong>V3.5.1 / 11-February-2022</strong></label>
<div>
<h2 id="main-changes-4">Main Changes</h2>
<ul>
<li>All source files: update disclaimer to add reference to the new license agreement.</li>
<li>Modified the address calculation in the BSP_LCD_FillRGBRect() function when USE_DMA2D_TO_FILL_RGB_RECT is enabled to suppress the display of a distorted shape instead of a rectangle when trying to draw a rectangle with a bigger height.</li>
<li>Cache maintained operation is included in the BSP_LCD_FillRGBRect() function to solve the display issue when USE_DMA2D_TO_FILL_RGB_RECT is enabled.</li>
<li>Updated the BSP_SD_Init() API to fix the detection pin check.</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section8" aria-hidden="true"> <label for="collapse-section8" aria-hidden="true"><strong>V3.5.0 / 04-February-2021</strong></label>
<div>
<h2 id="main-changes-5">Main Changes</h2>
<ul>
<li>BSP camera:
<ul>
<li>Update “BSP_CAMERA_DeInit” implementation to power down the camera instead of a full reset (allowing to save 120ms needed by the reset operation)</li>
</ul></li>
<li>BSP SD:
<ul>
<li>Update to add “USE_SD_BUS_WIDE_4B” configuration define allowing to specify if the SD card is intended to be interfaced with 4 data lanes
<ul>
<li>Notes:
<ul>
<li>when the “USE_SD_BUS_WIDE_4B” define is set to zero the SD is configured with 1 data lane allowing to overcome an issue with HW shared pins between the SD interface and the camera interface (if both camera and SD are needed)</li>
</ul></li>
</ul></li>
</ul></li>
<li>By default the “USE_SD_BUS_WIDE_4B” define is set to “1” to have the best SD performance</li>
</ul>
<h2 id="dependencies">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section7" aria-hidden="true"> <label for="collapse-section7" aria-hidden="true"><strong>V3.4.0 / 29-January-2021</strong></label>
<div>
<h2 id="main-changes-6">Main Changes</h2>
<ul>
<li>BSP QSPI: Add explicit definition of “BSP_QSPI_Erase_t” type with 8KB, 64KB and 128KB erase size
<ul>
<li>Notes:
<ul>
<li>The STM32H747I-DISCO comes with a dual flash QSPI, the erase size for each flash is 4KB, 32KB and 64KB</li>
<li>From BSP top view these two flash are seen as a single one with twice the size</li>
</ul></li>
</ul></li>
<li>BSP camera:
<ul>
<li>Apply HW reset after the initialization sequence for both OV9655 and OV5640 camera to fix potential noise issue</li>
</ul></li>
<li>BSP Joystick:
<ul>
<li>Fix “BSP_JOY_GetState” behavior by comparing the right joystick pin state (joystick pins are active high)</li>
<li>Add missing joystick interrupt priority defines to the “stm32h747i_discovery_conf_template.h” file
<ul>
<li>BSP_JOY1_SEL_IT_PRIORITY to BSP_JOY1_UP_IT_PRIORITY defines</li>
</ul></li>
</ul></li>
<li>BSP button:
<ul>
<li>Update the “stm32h747i_discovery_conf_template.h” file to rename the BSP_BUTTON_USER_IT_PRIORITY define to “BSP_BUTTON_WAKEUP_IT_PRIORITY” that is the right naming used withinb the driver</li>
</ul></li>
<li>Minor typo fixes in comments</li>
</ul>
<h2 id="dependencies-1">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section6" aria-hidden="true"> <label for="collapse-section6" aria-hidden="true"><strong>V3.3.0 / 12-December-2020</strong></label>
<div>
<h2 id="main-changes-7">Main Changes</h2>
<ul>
<li>Update stm32h747i_discovery_camera.c:
<ul>
<li>Update “BSP_CAMERA_DeInit” implementation to check “Camera_CompObj” and “Camera_Drv” pointers against NULL</li>
</ul></li>
<li>Add support of “OV5640” camera
<ul>
<li>stm32h747i_discovery_conf_template.h:
<ul>
<li>Add “USE_CAMERA_SENSOR_OV5640” define set to “1” by default</li>
</ul></li>
<li>stm32h747i_discovery_camera.h:
<ul>
<li>Add check on “USE_CAMERA_SENSOR_OV5640” define and enable it by default if not defined</li>
<li>Add inclusion of “Components/ov5640/ov5640.h”</li>
<li>Update “CAMERA_Ctx_t” structure with “CameraId” field</li>
<li>Add “CAMERA_OV5640_ADDRESS” define</li>
</ul></li>
<li>stm32h747i_discovery_camera.c:
<ul>
<li>Add “OV5640_Probe” static function implementation</li>
<li>Update “BSP_CAMERA_Init” function implementation to support “OV5640” camera
<ul>
<li>Probing both camera “OV5640” and “OV9655” to check which camera is connected to the STM32H747I-DISCO</li>
<li>Update the “CameraId” field of CAMERA_Ctx_t" structure</li>
<li>Proceed with the DCMI and the camera initialization according to the idenfied “CameraId”</li>
</ul></li>
</ul></li>
</ul></li>
</ul>
<h2 id="dependencies-2">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section5" aria-hidden="true"> <label for="collapse-section5" aria-hidden="true"><strong>V3.2.0 / 02-October-2020</strong></label>
<div>
<h2 id="main-changes-8">Main Changes</h2>
<ul>
<li>Update stm32h747i_discovery_lcd.c:
<ul>
<li>Fix MX_DSIHOST_DSI_Init API implementation : add missed “FrameBTAAcknowledgeEnable” parameter setting</li>
<li>Fix LCD_InitSequence API implementation: add missed “gpio_init_structure.Pull” parameter setting</li>
<li>Fix MX_LTDC_ClockConfig API implementation: Add “PLL3.PLL3RGE”, “PLL3.PLL3VCOSEL” and “PLL3.PLL3FRACN” parameters settings</li>
<li>Add support of DSI to HDMI bridge (daughter board MB1232.A):
<ul>
<li>Update and rework BSP_LCD_InitHDMI API implementation</li>
<li>Update MX_LTDC_ClockConfig2 API implementation to set the correct PLL3 settings in case of DSI-HDMI bridge</li>
<li>Upodate BSP_LCD_GetXSize and BSP_LCD_GetYSize APIs implementation to get the XSize and YSize information from the LCD context variable instead of the LCD panel object</li>
</ul></li>
</ul></li>
<li>Update stm32h747i_discovery_camera.c:
<ul>
<li>“Camera_Cap” declared as variable instead of pointer to avoid memory allocation issue</li>
<li>Add BSP_CAMERA_PwrUp API</li>
<li>Fix BSP_CAMERA_HwReset and BSP_CAMERA_PwrDown APIs implementation with the right pin PJ14</li>
</ul></li>
<li>Add License.md file</li>
</ul>
<h2 id="dependencies-3">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section4" aria-hidden="true"> <label for="collapse-section4" aria-hidden="true"><strong>V3.1.0 / 30-April-2020</strong></label>
<div>
<h2 id="main-changes-9">Main Changes</h2>
<ul>
<li>Update BSP_BUS APIs with protection against RTOS multithread usage (under BSP_USE_CMSIS_OS pre-processor conditional define)</li>
</ul>
<h2 id="dependencies-4">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section3" aria-hidden="true"> <label for="collapse-section3" aria-hidden="true"><strong>V3.0.0 / 25-February-2020</strong></label>
<div>
<h2 id="main-changes-10">Main Changes</h2>
<ul>
<li>Rename GUI_Drv_t into UTILS_LCD_Drv_t</li>
</ul>
<h2 id="backward-compatibility">Backward Compatibility</h2>
<ul>
<li>This version breaks the compatibility with previous versions</li>
</ul>
<h2 id="dependencies-5">Dependencies</h2>
<ul>
<li>Components/common v7.0.0</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section2" aria-hidden="true"> <label for="collapse-section2" aria-hidden="true"><strong>V2.0.0 / 25-November-2019</strong></label>
<div>
<h2 id="main-changes-11">Main Changes</h2>
<ul>
<li>First official release of STM32H747I-DISCO BSP drivers in line with STM32Cube BSP drivers development guidelines (UM2298)</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section1" aria-hidden="true"> <label for="collapse-section1" aria-hidden="true"><strong>V1.0.0 / 05-April-2019</strong></label>
<div>
<h2 id="main-changes-12">Main Changes</h2>
<ul>
<li>First official release</li>
</ul>
</div>
</div>
</div>
</div>
<footer class="sticky">
For complete documentation on <mark>STM32 Microcontrollers</mark> , visit: <span style="font-color: blue;"><a href="http://www.st.com/stm32">www.st.com/stm32</a></span>
</footer>
</body>
</html>
@@ -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 STs
[Privacy Policy](https://www.st.com/content/st_com/en/common/privacy-portal.html)
applies to all related communications.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

@@ -0,0 +1,933 @@
/**
******************************************************************************
* @file stm32h747i_discovery.c
* @author MCD Application Team
* @brief This file provides a set of firmware functions to manage
* LEDs
* push-buttons
* COM ports
* available on STM32H747I-DISCO board(MB1248) from STMicroelectronics.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 "stm32h747i_discovery.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL LOW LEVEL
* @{
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Private_TypesDefinitions Private Types Definitions
* @{
*/
typedef void (* BSP_EXTI_LineCallback) (void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Private_FunctionPrototypes Private Function Prototypes
* @{
*/
static void BUTTON_WAKEUP_EXTI_Callback(void);
#if (USE_BSP_COM_FEATURE > 0)
static void USART1_MspInit(UART_HandleTypeDef *huart);
static void USART1_MspDeInit(UART_HandleTypeDef *huart);
#endif
static void JOY1_UP_EXTI_Callback(void);
static void JOY1_DOWN_EXTI_Callback(void);
static void JOY1_LEFT_EXTI_Callback(void);
static void JOY1_RIGHT_EXTI_Callback(void);
static void JOY1_SEL_EXTI_Callback(void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Exported_Variables Exported Variables
* @{
*/
EXTI_HandleTypeDef hpb_exti[BUTTONn];
#if (USE_BSP_COM_FEATURE > 0)
UART_HandleTypeDef hcom_uart[COMn];
USART_TypeDef* COM_USART[COMn] = {COM1_UART};
#endif
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Private_Variables Private Variables
* @{
*/
static GPIO_TypeDef* LED_PORT[LEDn] = { LED1_GPIO_PORT,
LED2_GPIO_PORT,
LED3_GPIO_PORT,
LED4_GPIO_PORT};
static const uint32_t LED_PIN[LEDn] = { LED1_PIN,
LED2_PIN,
LED3_PIN,
LED4_PIN};
static GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {BUTTON_WAKEUP_GPIO_PORT};
static const uint16_t BUTTON_PIN[BUTTONn] = {BUTTON_WAKEUP_PIN};
static const IRQn_Type BUTTON_IRQn[BUTTONn] = {BUTTON_WAKEUP_EXTI_IRQn};
#if (USE_COM_LOG > 0)
static COM_TypeDef COM_ActiveLogPort = COM1;
#endif
#if (USE_BSP_COM_FEATURE > 0)
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
static uint32_t IsComMspCbValid[COMn] = {0};
#endif
#endif
static uint32_t JoyPinsMask;
static GPIO_TypeDef* JOY1_PORT[JOY_KEY_NUMBER] = {JOY1_SEL_GPIO_PORT,
JOY1_DOWN_GPIO_PORT,
JOY1_LEFT_GPIO_PORT,
JOY1_RIGHT_GPIO_PORT,
JOY1_UP_GPIO_PORT
};
static const uint16_t JOY1_PIN[JOY_KEY_NUMBER] = {JOY1_SEL_PIN,
JOY1_DOWN_PIN,
JOY1_LEFT_PIN,
JOY1_RIGHT_PIN,
JOY1_UP_PIN
};
static const IRQn_Type JOY1_IRQn[JOY_KEY_NUMBER] = {JOY1_SEL_EXTI_IRQn,
JOY1_DOWN_EXTI_IRQn,
JOY1_LEFT_EXTI_IRQn,
JOY1_RIGHT_EXTI_IRQn,
JOY1_UP_EXTI_IRQn
};
static EXTI_HandleTypeDef hjoy_exti[JOY_KEY_NUMBER];
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Exported_Functions Exported Functions
* @{
*/
/**
* @brief This method returns the STM32H747I DISCO BSP Driver revision
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
*/
int32_t BSP_GetVersion(void)
{
return (int32_t)STM32H747I_DISCO_BSP_VERSION;
}
/**
* @brief This method returns the board name
* @retval pointer to the board name string
*/
const uint8_t* BSP_GetBoardName(void)
{
return (uint8_t*)STM32H747I_DISCO_BSP_BOARD_NAME;
}
/**
* @brief This method returns the board ID
* @retval pointer to the board name string
*/
const uint8_t* BSP_GetBoardID(void)
{
return (uint8_t*)STM32H747I_DISCO_BSP_BOARD_ID;
}
/**
* @brief Configures LED on GPIO.
* @param Led LED to be configured.
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval BSP status
*/
int32_t BSP_LED_Init(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the GPIO_LED clock */
LEDx_GPIO_CLK_ENABLE();
/* Configure the GPIO_LED pin */
GPIO_InitStruct.Pin = LED_PIN[Led];
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(LED_PORT[Led], &GPIO_InitStruct);
/* By default, turn off LED */
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
return ret;
}
/**
* @brief DeInit LEDs.
* @param Led LED to be configured.
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval BSP status
*/
int32_t BSP_LED_DeInit(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
/* DeInit the GPIO_LED pin */
gpio_init_structure.Pin = LED_PIN [Led];
/* Turn off LED */
HAL_GPIO_WritePin (LED_PORT [Led], (uint16_t)LED_PIN[Led], GPIO_PIN_SET);
HAL_GPIO_DeInit (LED_PORT [Led], gpio_init_structure.Pin);
return ret;
}
/**
* @brief Turns selected LED On.
* @param Led LED to be set on
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval BSP status
*/
int32_t BSP_LED_On(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
HAL_GPIO_WritePin (LED_PORT [Led], (uint16_t)LED_PIN [Led], GPIO_PIN_RESET);
return ret;
}
/**
* @brief Turns selected LED Off.
* @param Led LED to be set off
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval BSP status
*/
int32_t BSP_LED_Off(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
HAL_GPIO_WritePin (LED_PORT [Led], (uint16_t)LED_PIN [Led], GPIO_PIN_SET);
return ret;
}
/**
* @brief Toggles the selected LED.
* @param Led LED to be toggled
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval BSP status
*/
int32_t BSP_LED_Toggle(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
HAL_GPIO_TogglePin(LED_PORT[Led], (uint16_t)LED_PIN[Led]);
return ret;
}
/**
* @brief Get the selected LED state.
* @param Led LED to be get its state
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @arg LED4
* @retval LED status
*/
int32_t BSP_LED_GetState (Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
ret = (int32_t)HAL_GPIO_ReadPin (LED_PORT [Led], (uint16_t)LED_PIN [Led]);
return ret;
}
/**
* @brief Configures button GPIO and EXTI Line.
* @param Button Button to be configured
* This parameter can be one of the following values:
* @arg BUTTON_WAKEUP: Wakeup Push Button
* @param ButtonMode Button mode
* This parameter can be one of the following values:
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
* with interrupt generation capability
* @retval BSP status
*/
int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
{
GPIO_InitTypeDef gpio_init_structure;
static BSP_EXTI_LineCallback ButtonCallback[BUTTONn] ={BUTTON_WAKEUP_EXTI_Callback};
static uint32_t BSP_BUTTON_PRIO [BUTTONn] ={BSP_BUTTON_WAKEUP_IT_PRIORITY};
static const uint32_t BUTTON_EXTI_LINE[BUTTONn] ={BUTTON_WAKEUP_EXTI_LINE};
/* Enable the BUTTON clock*/
BUTTON_WAKEUP_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = BUTTON_PIN [Button];
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
if(ButtonMode == BUTTON_MODE_GPIO)
{
/* Configure Button pin as input */
gpio_init_structure.Mode = GPIO_MODE_INPUT;
HAL_GPIO_Init(BUTTON_PORT [Button], &gpio_init_structure);
}
else /* (ButtonMode == BUTTON_MODE_EXTI) */
{
/* Configure Button pin as input with External interrupt */
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
(void)HAL_EXTI_GetHandle(&hpb_exti[Button], BUTTON_EXTI_LINE[Button]);
(void)HAL_EXTI_RegisterCallback(&hpb_exti[Button], HAL_EXTI_COMMON_CB_ID, ButtonCallback[Button]);
/* Enable and set Button EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((BUTTON_IRQn[Button]), BSP_BUTTON_PRIO[Button], 0x00);
HAL_NVIC_EnableIRQ((BUTTON_IRQn[Button]));
}
return BSP_ERROR_NONE;
}
/**
* @brief Push Button DeInit.
* @param Button Button to be configured
* This parameter can be one of the following values:
* @arg BUTTON_WAKEUP: Wakeup Push Button
* @note PB DeInit does not disable the GPIO clock
* @retval BSP status
*/
int32_t BSP_PB_DeInit(Button_TypeDef Button)
{
GPIO_InitTypeDef gpio_init_structure;
gpio_init_structure.Pin = BUTTON_PIN[Button];
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
return BSP_ERROR_NONE;
}
/**
* @brief Returns the selected button state.
* @param Button Button to be checked
* This parameter can be one of the following values:
* @arg BUTTON_WAKEUP: Wakeup Push Button
* @retval The Button GPIO pin value
*/
int32_t BSP_PB_GetState(Button_TypeDef Button)
{
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
/**
* @brief This function handles Push-Button interrupt requests.
* @param Button Specifies the pin connected EXTI line
* @retval None
*/
void BSP_PB_IRQHandler(Button_TypeDef Button)
{
HAL_EXTI_IRQHandler(&hpb_exti[Button]);
}
/**
* @brief KEY EXTI line detection callbacks.
* @retval None
*/
static void BUTTON_WAKEUP_EXTI_Callback(void)
{
BSP_PB_Callback(BUTTON_WAKEUP);
}
/**
* @brief BSP Push Button callback
* @param Button Specifies the pin connected EXTI line
* @retval None.
*/
__weak void BSP_PB_Callback(Button_TypeDef Button)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Button);
/* This function should be implemented by the user application.
It is called into this driver when an event on Button is triggered. */
}
#if (USE_BSP_COM_FEATURE > 0)
/**
* @brief Configures COM port.
* @param COM COM port to be configured.
* This parameter can be COM1
* @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the
* configuration information for the specified USART peripheral.
* @retval BSP status
*/
int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init)
{
int32_t ret = BSP_ERROR_NONE;
if(COM >= COMn)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Init the UART Msp */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
USART1_MspInit(&hcom_uart[COM]);
#else
if(IsComMspCbValid[COM] == 0U)
{
if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
{
return BSP_ERROR_MSP_FAILURE;
}
}
#endif
if(MX_USART1_Init(&hcom_uart[COM], COM_Init) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
return ret;
}
/**
* @brief DeInit COM port.
* @param COM COM port to be configured.
* This parameter can be (COM1)
* @retval BSP status
*/
int32_t BSP_COM_DeInit(COM_TypeDef COM)
{
int32_t ret = BSP_ERROR_NONE;
if(COM >= COMn)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* USART configuration */
hcom_uart[COM].Instance = COM_USART[COM];
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
USART1_MspDeInit(&hcom_uart[COM]);
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0) */
if(HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
return ret;
}
/**
* @brief Configures COM1 port.
* @param huart USART handle
* @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the
* configuration information for the specified USART peripheral.
* @retval HAL error code
*/
__weak HAL_StatusTypeDef MX_USART1_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init)
{
/* USART configuration */
huart->Instance = COM_USART[COM1];
huart->Init.BaudRate = (uint32_t)COM_Init->BaudRate;
huart->Init.Mode = UART_MODE_TX_RX;
huart->Init.Parity = (uint32_t)COM_Init->Parity;
huart->Init.WordLength = (uint32_t)COM_Init->WordLength;
huart->Init.StopBits = (uint32_t)COM_Init->StopBits;
huart->Init.HwFlowCtl = (uint32_t)COM_Init->HwFlowCtl;
huart->Init.OverSampling = UART_OVERSAMPLING_8;
return HAL_UART_Init(huart);
}
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/**
* @brief Register Default COM Msp Callbacks
* @param COM COM port to be configured.
* @retval BSP status
*/
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM)
{
int32_t ret = BSP_ERROR_NONE;
if(COM >= COMn)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
/* Register default MspInit/MspDeInit Callback */
if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, USART1_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, USART1_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsComMspCbValid[COM] = 1U;
}
}
/* BSP status */
return ret;
}
/**
* @brief Register COM1 Msp Callback registering
* @param COM COM port to be configured.
* @param Callbacks pointer to COM MspInit/MspDeInit callback functions
* @retval BSP status
*/
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM, BSP_COM_Cb_t *Callback)
{
int32_t ret = BSP_ERROR_NONE;
if(COM >= COMn)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
/* Register MspInit/MspDeInit Callbacks */
if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, Callback->pMspInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, Callback->pMspDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsComMspCbValid[COM] = 1U;
}
}
/* BSP status */
return ret;
}
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
#if (USE_COM_LOG > 0)
/**
* @brief Select the active COM port.
* @param COM COM port to be activated.
* This parameter can be COM1 or/and COM2
* @retval BSP status
*/
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM)
{
if(COM_ActiveLogPort != COM)
{
COM_ActiveLogPort = COM;
}
return BSP_ERROR_NONE;
}
#ifdef __GNUC__
int __io_putchar (int ch)
#else
int fputc (int ch, FILE *f)
#endif /* __GNUC__ */
{
(void)HAL_UART_Transmit (&hcom_uart [COM_ActiveLogPort], (uint8_t *) &ch, 1, COM_POLL_TIMEOUT);
return ch;
}
#endif /* USE_COM_LOG */
#endif /* USE_BSP_COM_FEATURE */
/**
* @brief Configures joystick GPIO and EXTI modes.
* @param JOY Joystick to be initialized
* @param JoyMode Button mode.
* This parameter can be one of the following values:
* @arg JOY_MODE_GPIO: Joystick pins will be used as simple IOs
* @arg JOY_MODE_EXTI: Joystick pins will be connected to EXTI line
* with interrupt generation capability
* @param JoyPins joystick pins to be initialized
* @retval BSP status
*/
int32_t BSP_JOY_Init(JOY_TypeDef JOY, JOYMode_TypeDef JoyMode, JOYPin_TypeDef JoyPins)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t joykey, key_pressed;
GPIO_InitTypeDef gpio_init_structure;
static BSP_EXTI_LineCallback JoyCallback[JOY_KEY_NUMBER] = {JOY1_SEL_EXTI_Callback,
JOY1_DOWN_EXTI_Callback,
JOY1_LEFT_EXTI_Callback,
JOY1_RIGHT_EXTI_Callback,
JOY1_UP_EXTI_Callback
};
static const uint32_t JOY_EXTI_LINE[JOY_KEY_NUMBER] = {JOY1_SEL_EXTI_LINE,
JOY1_DOWN_EXTI_LINE,
JOY1_LEFT_EXTI_LINE,
JOY1_RIGHT_EXTI_LINE,
JOY1_UP_EXTI_LINE
};
static uint32_t BSP_JOY_PRIO [JOY_KEY_NUMBER] ={BSP_JOY1_SEL_IT_PRIORITY,
BSP_JOY1_DOWN_IT_PRIORITY,
BSP_JOY1_LEFT_IT_PRIORITY,
BSP_JOY1_RIGHT_IT_PRIORITY,
BSP_JOY1_UP_IT_PRIORITY
};
/* Store Joystick pins initialized */
JoyPinsMask |= (uint32_t)JoyPins;
/* Initialized the Joystick. */
for(joykey = 0U; joykey < JOY_KEY_NUMBER ; joykey++)
{
key_pressed = 1UL << joykey;
if((key_pressed & (uint32_t)JoyPins) == key_pressed)
{
if(JOY == JOY1)
{
/* Enable the JOY clock */
if(key_pressed == (uint32_t)JOY_SEL)
{
JOY1_SEL_GPIO_CLK_ENABLE();
}
else if(key_pressed == (uint32_t)JOY_DOWN)
{
JOY1_DOWN_GPIO_CLK_ENABLE();
}
else if(key_pressed == (uint32_t) JOY_LEFT)
{
JOY1_LEFT_GPIO_CLK_ENABLE();
}
else if(key_pressed == (uint32_t) JOY_RIGHT)
{
JOY1_RIGHT_GPIO_CLK_ENABLE();
}
else
{
if(key_pressed == (uint32_t) JOY_UP)
{
JOY1_UP_GPIO_CLK_ENABLE();
}
}
gpio_init_structure.Pin = JOY1_PIN[joykey];
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
if (JoyMode == JOY_MODE_GPIO)
{
/* Configure Joy pin as input */
gpio_init_structure.Mode = GPIO_MODE_INPUT;
HAL_GPIO_Init(JOY1_PORT[joykey], &gpio_init_structure);
}
else /*(JoyMode == JOY_MODE_EXTI)*/
{
/* Configure Joy pin as input with External interrupt */
gpio_init_structure.Mode = GPIO_MODE_IT_RISING_FALLING;
HAL_GPIO_Init(JOY1_PORT[joykey], &gpio_init_structure);
(void)HAL_EXTI_GetHandle(&hjoy_exti[joykey], JOY_EXTI_LINE[joykey]);
(void)HAL_EXTI_RegisterCallback(&hjoy_exti[joykey], HAL_EXTI_COMMON_CB_ID, JoyCallback[joykey]);
/* Enable and set Joy EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((IRQn_Type)(JOY1_IRQn[joykey]), BSP_JOY_PRIO[joykey], 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(JOY1_IRQn[joykey]));
}
}
}
}
return ret;
}
/**
* @brief DeInit joystick GPIOs.
* @param JOY instance
* @note JOY DeInit does not disable the MFX, just set the MFX pins in Off mode
* @param JoyPins joystick pins to be de-initialized
* @retval BSP status
*/
int32_t BSP_JOY_DeInit(JOY_TypeDef JOY, JOYPin_TypeDef JoyPins)
{
uint32_t joykey, key_pressed;
/* Store Joystick pins initialized */
JoyPinsMask &= (uint32_t)JoyPins;
/* Initialized the Joystick. */
for(joykey = 0U; joykey < JOY_KEY_NUMBER ; joykey++)
{
key_pressed = 1UL << joykey;
if((key_pressed & (uint32_t)JoyPins) == key_pressed)
{
if(JOY == JOY1)
{
/* Disable the JOY clock */
switch(key_pressed)
{
case JOY_SEL:
JOY1_SEL_GPIO_CLK_DISABLE();
break;
case JOY_DOWN:
JOY1_DOWN_GPIO_CLK_DISABLE();
break;
case JOY_LEFT:
JOY1_LEFT_GPIO_CLK_DISABLE();
break;
case JOY_RIGHT:
JOY1_RIGHT_GPIO_CLK_DISABLE();
break;
case JOY_UP:
JOY1_UP_GPIO_CLK_DISABLE();
break;
default:
break;
}
HAL_GPIO_DeInit(JOY1_PORT[joykey], JOY1_PIN[joykey]);
}
}
}
return BSP_ERROR_NONE;
}
/**
* @brief Returns the current joystick status.
* @retval Code of the joystick key pressed
* This code can be one of the following values:
* @arg JOY_NONE
* @arg JOY_SEL
* @arg JOY_DOWN
* @arg JOY_LEFT
* @arg JOY_RIGHT
* @arg JOY_UP
*/
int32_t BSP_JOY_GetState(JOY_TypeDef JOY,uint32_t JoyPin)
{
uint32_t joykey, key_pressed;
for (joykey = 0U; joykey < JOY_KEY_NUMBER ; joykey++)
{
key_pressed = 1UL << joykey;
if((key_pressed & JoyPinsMask) == key_pressed)
{
if(JOY == JOY1)
{
if (HAL_GPIO_ReadPin(JOY1_PORT[joykey], JOY1_PIN[joykey]) != GPIO_PIN_SET)
{
/* Return Code Joystick key pressed */
return (int32_t)key_pressed;
}
}
}
}
/* No Joystick key pressed */
return (int32_t)JOY_NONE;
}
/**
* @brief This function handles JOY keys interrupt request.
* @param JOY Joystick instance
* @param JoyPin Specifies the pin connected EXTI handler
* @retval None
*/
void BSP_JOY_IRQHandler(JOY_TypeDef JOY, JOYPin_TypeDef JoyPin)
{
if(JOY == JOY1)
{
HAL_EXTI_IRQHandler(&hjoy_exti[POSITION_VAL(JoyPin)]);
}
}
/**
* @brief BSP Joystick Callback.
* @param JOY Joystick instance
* @param JoyPin Specifies the pin connected EXTI line
* @retval None.
*/
__weak void BSP_JOY_Callback(JOY_TypeDef JOY, uint32_t JoyPin)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(JOY);
UNUSED(JoyPin);
/* This function should be implemented by the user application.
It is called into this driver when an event on JoyPin is triggered. */
}
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Private_Functions Private Functions
* @{
*/
/**
* @brief JOY1 UP EXTI line detection callbacks.
* @retval None
*/
static void JOY1_UP_EXTI_Callback(void)
{
BSP_JOY_Callback(JOY1, JOY_UP);
}
/**
* @brief JOY1 DOWN EXTI line detection callbacks.
* @retval None
*/
static void JOY1_DOWN_EXTI_Callback(void)
{
BSP_JOY_Callback(JOY1, JOY_DOWN);
}
/**
* @brief JOY1 SEL EXTI line detection callbacks.
* @retval None
*/
static void JOY1_SEL_EXTI_Callback(void)
{
BSP_JOY_Callback(JOY1, JOY_SEL);
}
/**
* @brief JOY1 LEFT EXTI line detection callbacks.
* @retval None
*/
static void JOY1_LEFT_EXTI_Callback(void)
{
BSP_JOY_Callback(JOY1, JOY_LEFT);
}
/**
* @brief JOY1 RIGHT EXTI line detection callbacks.
* @retval None
*/
static void JOY1_RIGHT_EXTI_Callback(void)
{
BSP_JOY_Callback(JOY1, JOY_RIGHT);
}
#if (USE_BSP_COM_FEATURE > 0)
/**
* @brief Initializes UART MSP.
* @param huart UART handle
* @retval None
*/
static void USART1_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* Enable GPIO clock */
COM1_TX_GPIO_CLK_ENABLE();
COM1_RX_GPIO_CLK_ENABLE();
/* Enable USART clock */
COM1_CLK_ENABLE();
/* Configure USART Tx as alternate function */
gpio_init_structure.Pin = COM1_TX_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Alternate = COM1_TX_AF;
HAL_GPIO_Init(COM1_TX_GPIO_PORT, &gpio_init_structure);
/* Configure USART Rx as alternate function */
gpio_init_structure.Pin = COM1_RX_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = COM1_RX_AF;
HAL_GPIO_Init(COM1_RX_GPIO_PORT, &gpio_init_structure);
}
/**
* @brief Initialize USART6 Msp part
* @param huart UART handle
* @retval None
*/
static void USART1_MspDeInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* COM GPIO pin configuration */
gpio_init_structure.Pin = COM1_TX_PIN;
HAL_GPIO_DeInit(COM1_TX_GPIO_PORT, gpio_init_structure.Pin);
gpio_init_structure.Pin = COM1_RX_PIN;
HAL_GPIO_DeInit(COM1_RX_GPIO_PORT, gpio_init_structure.Pin);
/* Disable USART clock */
COM1_CLK_DISABLE();
}
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,377 @@
/**
******************************************************************************
* @file stm32h747i_discovery.h
* @author MCD Application Team
* @brief This file contains definitions for STM32H747I_DISCO:
* LEDs
* push-buttons
* COM ports
* hardware resources.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_H
#define STM32H747I_DISCO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#if (USE_BSP_COM_FEATURE > 0)
#if (USE_COM_LOG > 0)
#ifndef __GNUC__
#include "stdio.h"
#endif
#endif
#endif
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_LOW_LEVEL
* @{
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Exported_Types Exported Types
* @{
*/
typedef enum
{
LED1 = 0U,
LED_GREEN = LED1,
LED2 = 1U,
LED_ORANGE = LED2,
LED3 = 2U,
LED_RED = LED3,
LED4 = 3U,
LED_BLUE = LED4,
LEDn
} Led_TypeDef;
typedef enum
{
BUTTON_WAKEUP = 0U,
BUTTONn
} Button_TypeDef;
typedef enum
{
BUTTON_MODE_GPIO = 0U,
BUTTON_MODE_EXTI = 1U
}ButtonMode_TypeDef;
#if (USE_BSP_COM_FEATURE > 0)
typedef enum
{
COM1 = 0U,
COMn
}COM_TypeDef;
typedef enum
{
COM_STOPBITS_1 = UART_STOPBITS_1,
COM_STOPBITS_2 = UART_STOPBITS_2,
}COM_StopBitsTypeDef;
typedef enum
{
COM_PARITY_NONE = UART_PARITY_NONE,
COM_PARITY_EVEN = UART_PARITY_EVEN,
COM_PARITY_ODD = UART_PARITY_ODD,
}COM_ParityTypeDef;
typedef enum
{
COM_HWCONTROL_NONE = UART_HWCONTROL_NONE,
COM_HWCONTROL_RTS = UART_HWCONTROL_RTS,
COM_HWCONTROL_CTS = UART_HWCONTROL_CTS,
COM_HWCONTROL_RTS_CTS = UART_HWCONTROL_RTS_CTS,
}COM_HwFlowCtlTypeDef;
typedef enum
{
COM_WORDLENGTH_7B = UART_WORDLENGTH_7B,
COM_WORDLENGTH_8B = UART_WORDLENGTH_8B,
COM_WORDLENGTH_9B = UART_WORDLENGTH_9B,
}COM_WordLengthTypeDef;
typedef struct
{
uint32_t BaudRate;
COM_WordLengthTypeDef WordLength;
COM_StopBitsTypeDef StopBits;
COM_ParityTypeDef Parity;
COM_HwFlowCtlTypeDef HwFlowCtl;
}COM_InitTypeDef;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(UART_HandleTypeDef *);
void (* pMspDeInitCb)(UART_HandleTypeDef *);
}BSP_COM_Cb_t;
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1) */
#endif
typedef enum
{
JOY_MODE_GPIO = 0U,
JOY_MODE_EXTI = 1U
}JOYMode_TypeDef;
typedef enum
{
JOY1 = 0U,
JOYn
}JOY_TypeDef;
typedef enum
{
JOY_NONE = 0x00U,
JOY_SEL = 0x01U,
JOY_DOWN = 0x02U,
JOY_LEFT = 0x04U,
JOY_RIGHT = 0x08U,
JOY_UP = 0x10U,
JOY_ALL = 0x1FU
}JOYPin_TypeDef;
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_Exported_Constants Exported Constants
* @{
*/
/**
* @brief Define for STM32H747I_DISCO board
*/
#if !defined (USE_STM32H747I_DISCO)
#define USE_STM32H747I_DISCO
#endif
/**
* @brief STM32H747I Discovery BSP Driver version number
*/
#define STM32H747I_DISCO_BSP_VERSION_MAIN (0x03) /*!< [31:24] main version */
#define STM32H747I_DISCO_BSP_VERSION_SUB1 (0x06) /*!< [23:16] sub1 version */
#define STM32H747I_DISCO_BSP_VERSION_SUB2 (0x03) /*!< [15:8] sub2 version */
#define STM32H747I_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
#define STM32H747I_DISCO_BSP_VERSION ((STM32H747I_DISCO_BSP_VERSION_MAIN << 24)\
|(STM32H747I_DISCO_BSP_VERSION_SUB1 << 16)\
|(STM32H747I_DISCO_BSP_VERSION_SUB2 << 8 )\
|(STM32H747I_DISCO_BSP_VERSION_RC))
#define STM32H747I_DISCO_BSP_BOARD_NAME "STM32H747I-DISCO";
#define STM32H747I_DISCO_BSP_BOARD_ID "MB12481D";
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_LED EVAL LOW LEVEL LED
* @{
*/
#define LED1_GPIO_PORT GPIOI
#define LED1_PIN GPIO_PIN_12
#define LED2_GPIO_PORT GPIOI
#define LED2_PIN GPIO_PIN_13
#define LED3_GPIO_PORT GPIOI
#define LED3_PIN GPIO_PIN_14
#define LED4_GPIO_PORT GPIOI
#define LED4_PIN GPIO_PIN_15
#define LEDx_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
#define LEDx_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_BUTTON LOW LEVEL BUTTON
* @{
*/
/* Button state */
#define BUTTON_RELEASED 0U
#define BUTTON_PRESSED 1U
/**
* @brief Wakeup push-button
*/
#define BUTTON_WAKEUP_PIN GPIO_PIN_13
#define BUTTON_WAKEUP_GPIO_PORT GPIOC
#define BUTTON_WAKEUP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define BUTTON_WAKEUP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
#define BUTTON_WAKEUP_EXTI_IRQn EXTI15_10_IRQn
#define BUTTON_WAKEUP_EXTI_LINE EXTI_LINE_13
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_COM LOW LEVEL COM
* @{
*/
#if (USE_BSP_COM_FEATURE > 0)
/**
* @brief Definition for COM port1, connected to USART1
*/
#define COM1_UART USART1
#define COM1_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE()
#define COM1_CLK_DISABLE() __HAL_RCC_USART1_CLK_DISABLE()
#define COM1_TX_PIN GPIO_PIN_9
#define COM1_TX_GPIO_PORT GPIOA
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_TX_AF GPIO_AF7_USART1
#define COM1_RX_PIN GPIO_PIN_10
#define COM1_RX_GPIO_PORT GPIOA
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_RX_AF GPIO_AF7_USART1
#define COM_POLL_TIMEOUT 1000
#define MX_UART_InitTypeDef COM_InitTypeDef
#endif
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LOW_LEVEL_JOY LOW LEVEL JOY
* @{
*/
#define JOY_KEY_NUMBER 5U
#define JOY1_SEL_PIN GPIO_PIN_2
#define JOY1_SEL_GPIO_PORT GPIOK
#define JOY1_SEL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define JOY1_SEL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define JOY1_SEL_EXTI_IRQn EXTI2_IRQn
#define JOY1_SEL_EXTI_LINE EXTI_LINE_2
#define JOY1_DOWN_PIN GPIO_PIN_3
#define JOY1_DOWN_GPIO_PORT GPIOK
#define JOY1_DOWN_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define JOY1_DOWN_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define JOY1_DOWN_EXTI_IRQn EXTI3_IRQn
#define JOY1_DOWN_EXTI_LINE EXTI_LINE_3
#define JOY1_LEFT_PIN GPIO_PIN_4
#define JOY1_LEFT_GPIO_PORT GPIOK
#define JOY1_LEFT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define JOY1_LEFT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define JOY1_LEFT_EXTI_IRQn EXTI4_IRQn
#define JOY1_LEFT_EXTI_LINE EXTI_LINE_4
#define JOY1_RIGHT_PIN GPIO_PIN_5
#define JOY1_RIGHT_GPIO_PORT GPIOK
#define JOY1_RIGHT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define JOY1_RIGHT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define JOY1_RIGHT_EXTI_IRQn EXTI9_5_IRQn
#define JOY1_RIGHT_EXTI_LINE EXTI_LINE_5
#define JOY1_UP_PIN GPIO_PIN_6
#define JOY1_UP_GPIO_PORT GPIOK
#define JOY1_UP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define JOY1_UP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define JOY1_UP_EXTI_IRQn EXTI9_5_IRQn
#define JOY1_UP_EXTI_LINE EXTI_LINE_6
/**
* @}
*/
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_LOW_LEVEL_Exported_Variables
* @{
*/
extern EXTI_HandleTypeDef hpb_exti[];
#if (USE_BSP_COM_FEATURE > 0)
extern UART_HandleTypeDef hcom_uart[];
extern USART_TypeDef* COM_USART[];
#endif
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_LOW_LEVEL_Exported_Functions
* @{
*/
int32_t BSP_GetVersion(void);
const uint8_t* BSP_GetBoardName(void);
const uint8_t* BSP_GetBoardID(void);
int32_t BSP_LED_Init(Led_TypeDef Led);
int32_t BSP_LED_DeInit(Led_TypeDef Led);
int32_t BSP_LED_On(Led_TypeDef Led);
int32_t BSP_LED_Off(Led_TypeDef Led);
int32_t BSP_LED_Toggle(Led_TypeDef Led);
int32_t BSP_LED_GetState (Led_TypeDef Led);
int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
int32_t BSP_PB_DeInit(Button_TypeDef Button);
int32_t BSP_PB_GetState(Button_TypeDef Button);
void BSP_PB_Callback(Button_TypeDef Button);
#if (USE_BSP_COM_FEATURE > 0)
int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init);
int32_t BSP_COM_DeInit(COM_TypeDef COM);
#if( USE_COM_LOG > 0)
int32_t BSP_COM_SelectLogPort (COM_TypeDef COM);
#endif
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM);
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM, BSP_COM_Cb_t *Callback);
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
HAL_StatusTypeDef MX_USART1_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init);
#endif
int32_t BSP_JOY_Init(JOY_TypeDef JOY, JOYMode_TypeDef JoyMode, JOYPin_TypeDef JoyPins);
int32_t BSP_JOY_DeInit(JOY_TypeDef JOY, JOYPin_TypeDef JoyPins);
int32_t BSP_JOY_GetState(JOY_TypeDef JOY,uint32_t JoyPin);
void BSP_JOY_Callback(JOY_TypeDef JOY, uint32_t JoyPin);
void BSP_JOY_IRQHandler(JOY_TypeDef JOY, JOYPin_TypeDef JoyPin);
void BSP_JOY_IRQHandler(JOY_TypeDef JOY, JOYPin_TypeDef JoyPin);
void BSP_PB_IRQHandler(Button_TypeDef Button);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,458 @@
/**
******************************************************************************
* @file stm32h747i_discovery_audio.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_audio.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_AUDIO_H
#define STM32H747I_DISCO_AUDIO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#if (USE_AUDIO_CODEC_WM8994 > 0U)
/* Include audio component Driver */
#include "../Components/wm8994/wm8994.h"
#endif
#include "../Components/Common/audio.h"
/* Include PDM to PCM lib header file */
#include "pdm2pcm_glo.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_AUDIO
* @{
*/
/** @defgroup STM32H747I_DISCO_AUDIO_Exported_Types Exported Types
* @{
*/
typedef struct
{
uint32_t Device;
uint32_t SampleRate;
uint32_t BitsPerSample;
uint32_t ChannelsNbr;
uint32_t Volume;
}BSP_AUDIO_Init_t;
typedef struct
{
uint32_t Instance; /* Audio IN instance */
uint32_t Device; /* Audio IN device to be used */
uint32_t SampleRate; /* Audio IN Sample rate */
uint32_t BitsPerSample; /* Audio IN Sample resolution */
uint32_t ChannelsNbr; /* Audio IN number of channel */
uint16_t *pBuff; /* Audio IN record buffer */
uint8_t **pMultiBuff; /* Audio IN multi-buffer */
uint32_t Size; /* Audio IN record buffer size */
uint32_t Volume; /* Audio IN volume */
uint32_t State; /* Audio IN State */
uint32_t IsMultiBuff; /* Audio IN multi-buffer usage */
uint32_t IsMspCallbacksValid; /* Is Msp Callbacks registered */
}AUDIO_IN_Ctx_t;
typedef struct
{
uint32_t Instance; /* Audio OUT instance */
uint32_t Device; /* Audio OUT device to be used */
uint32_t SampleRate; /* Audio OUT Sample rate */
uint32_t BitsPerSample; /* Audio OUT Sample Bit Per Sample */
uint32_t Volume; /* Audio OUT volume */
uint32_t ChannelsNbr; /* Audio OUT number of channel */
uint32_t IsMute; /* Mute state */
uint32_t State; /* Audio OUT State */
uint32_t IsMspCallbacksValid; /* Is Msp Callbacks registered */
}AUDIO_OUT_Ctx_t;
typedef struct
{
uint32_t AudioFrequency;
uint32_t AudioMode;
uint32_t DataSize;
uint32_t MonoStereoMode;
uint32_t ClockStrobing;
uint32_t Synchro;
uint32_t OutputDrive;
uint32_t SynchroExt;
uint32_t FrameLength;
uint32_t ActiveFrameLength;
uint32_t SlotActive;
}MX_SAI_Config_t;
#if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
typedef struct
{
pSAI_CallbackTypeDef pMspSaiInitCb;
pSAI_CallbackTypeDef pMspSaiDeInitCb;
}BSP_AUDIO_OUT_Cb_t;
#endif /* (USE_HAL_SAI_REGISTER_CALLBACKS == 1) */
#if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
typedef struct
{
#if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
void (* pMspSaiInitCb )(SAI_HandleTypeDef *);
void (* pMspSaiDeInitCb)(SAI_HandleTypeDef *);
#endif
}BSP_AUDIO_IN_Cb_t;
#endif /*(USE_HAL_SAI_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_AUDIO_Exported_Constants Exported Constants
* @{
*/
/* Audio codec I2C address */
#define AUDIO_I2C_ADDRESS 0x34U
/* Audio Out instances number */
#define AUDIO_OUT_INSTANCES_NBR 2U
/* AUDIO FREQUENCY */
#define AUDIO_FREQUENCY_192K 192000U
#define AUDIO_FREQUENCY_176K 176400U
#define AUDIO_FREQUENCY_96K 96000U
#define AUDIO_FREQUENCY_88K 88200U
#define AUDIO_FREQUENCY_48K 48000U
#define AUDIO_FREQUENCY_44K 44100U
#define AUDIO_FREQUENCY_32K 32000U
#define AUDIO_FREQUENCY_22K 22050U
#define AUDIO_FREQUENCY_16K 16000U
#define AUDIO_FREQUENCY_11K 11025U
#define AUDIO_FREQUENCY_8K 8000U
/* AUDIO RESOLUTION */
#define AUDIO_RESOLUTION_16B 16U
#define AUDIO_RESOLUTION_32B 32U
/* Audio Out devices */
#define AUDIO_OUT_DEVICE_NONE 0U
#define AUDIO_OUT_DEVICE_SPEAKER 1U
#define AUDIO_OUT_DEVICE_HEADPHONE 2U
#define AUDIO_OUT_DEVICE_SPK_HP 3U
#define AUDIO_OUT_DEVICE_AUTO 4U
#define AUDIO_OUT_DEVICE_HDMI 5U
/* Audio Mute state */
#define BSP_AUDIO_MUTE_DISABLED 0U
#define BSP_AUDIO_MUTE_ENABLED 1U
/* Audio Out states */
#define AUDIO_OUT_STATE_RESET 0U
#define AUDIO_OUT_STATE_PLAYING 1U
#define AUDIO_OUT_STATE_STOP 2U
#define AUDIO_OUT_STATE_PAUSE 3U
/* Audio Out states */
/* Volume Input Output selection */
#define AUDIO_VOLUME_INPUT 0U
#define AUDIO_VOLUME_OUTPUT 1U
/* Codec commands */
#define CODEC_PDWN_SW 1U
#define CODEC_MUTE_ON 1U
#define CODEC_MUTE_OFF 0U
/*------------------------------------------------------------------------------
USER SAI defines parameters
-----------------------------------------------------------------------------*/
/** CODEC_AudioFrame_SLOT_TDMMode In W8994 codec the Audio frame contains 4 slots : TDM Mode
* TDM format :
* +------------------|------------------|--------------------|-------------------+
* | CODEC_SLOT0 Left | CODEC_SLOT1 Left | CODEC_SLOT0 Right | CODEC_SLOT1 Right |
* +------------------------------------------------------------------------------+
*/
/* To have 2 separate audio stream in Both headphone and speaker the 4 slot must be activated */
#define CODEC_AUDIOFRAME_SLOT_0123 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3
/* To have an audio stream in headphone only SAI Slot 0 and Slot 2 must be activated */
#define CODEC_AUDIOFRAME_SLOT_02 SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_2
/* To have an audio stream in speaker only SAI Slot 1 and Slot 3 must be activated */
#define CODEC_AUDIOFRAME_SLOT_13 SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_3
/* SAI peripheral configuration defines */
#define AUDIO_OUT_SAIx SAI1_Block_A
#define AUDIO_OUT_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()
#define AUDIO_OUT_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE()
#define AUDIO_OUT_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define AUDIO_OUT_SAIx_MCLK_GPIO_PORT GPIOG
#define AUDIO_OUT_SAIx_MCLK_PIN GPIO_PIN_7
#define AUDIO_OUT_SAIx_MCLK_AF GPIO_AF6_SAI1
#define AUDIO_OUT_SAIx_SCK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_OUT_SAIx_SCK_GPIO_PORT GPIOE
#define AUDIO_OUT_SAIx_SCK_PIN GPIO_PIN_5
#define AUDIO_OUT_SAIx_SCK_AF GPIO_AF6_SAI1
#define AUDIO_OUT_SAIx_SD_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_OUT_SAIx_SD_GPIO_PORT GPIOE
#define AUDIO_OUT_SAIx_SD_PIN GPIO_PIN_6
#define AUDIO_OUT_SAIx_SD_AF GPIO_AF6_SAI1
#define AUDIO_OUT_SAIx_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_OUT_SAIx_FS_GPIO_PORT GPIOE
#define AUDIO_OUT_SAIx_FS_PIN GPIO_PIN_4
#define AUDIO_OUT_SAIx_FS_AF GPIO_AF6_SAI1
/* SAI DMA Stream definitions */
#define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
#define AUDIO_OUT_SAIx_DMAx_STREAM DMA2_Stream1
#define AUDIO_OUT_SAIx_DMAx_REQUEST DMA_REQUEST_SAI1_A
#define AUDIO_OUT_SAIx_DMAx_IRQ DMA2_Stream1_IRQn
#define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
#define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
#define AUDIO_OUT_SAIx_DMAx_IRQHandler DMA2_Stream1_IRQHandler
/*------------------------------------------------------------------------------
AUDIO IN defines parameters
------------------------------------------------------------------------------*/
/* SAI peripheral configuration defines */
#define AUDIO_IN_SAIx SAI1_Block_B
#define AUDIO_IN_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()
#define AUDIO_IN_SAIx_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE()
#define AUDIO_IN_SAIx_AF GPIO_AF6_SAI1
#define AUDIO_IN_SAIx_SD_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_IN_SAIx_SD_GPIO_PORT GPIOE
#define AUDIO_IN_SAIx_SD_PIN GPIO_PIN_3
/* SAI DMA Stream definitions */
#define AUDIO_IN_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
#define AUDIO_IN_SAIx_DMAx_STREAM DMA2_Stream4
#define AUDIO_IN_SAIx_DMAx_REQUEST DMA_REQUEST_SAI1_B
#define AUDIO_IN_SAIx_DMAx_IRQ DMA2_Stream4_IRQn
#define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
#define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
#define AUDIO_IN_SAIx_DMAx_IRQHandler DMA2_Stream4_IRQHandler
#define AUDIO_IN_INT_GPIO_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define AUDIO_IN_INT_GPIO_PORT GPIOJ
#define AUDIO_IN_INT_GPIO_PIN GPIO_PIN_15
#define AUDIO_IN_INT_IRQ EXTI15_10_IRQn
/* SAI PDM input definitions */
#define AUDIO_IN_SAI_PDMx SAI4_Block_A
#define AUDIO_IN_SAI_PDMx_CLK_ENABLE() __HAL_RCC_SAI4_CLK_ENABLE()
#define AUDIO_IN_SAI_PDMx_CLK_DISABLE() __HAL_RCC_SAI4_CLK_DISABLE()
#define AUDIO_IN_SAI_PDMx_FS_SCK_AF GPIO_AF8_SAI4
#define AUDIO_IN_SAI_PDMx_FS_SCK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_IN_SAI_PDMx_FS_SCK_GPIO_PORT GPIOE
#define AUDIO_IN_SAI_PDMx_FS_PIN GPIO_PIN_4
#define AUDIO_IN_SAI_PDMx_SCK_PIN GPIO_PIN_5
#define AUDIO_IN_SAI_PDMx_CLK_IN_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define AUDIO_IN_SAI_PDMx_CLK_IN_PIN GPIO_PIN_2
#define AUDIO_IN_SAI_PDMx_CLK_IN_PORT GPIOE
#define AUDIO_IN_SAI_PDMx_DATA_IN_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define AUDIO_IN_SAI_PDMx_DATA_IN_PIN GPIO_PIN_1
#define AUDIO_IN_SAI_PDMx_DATA_IN_PORT GPIOC
#define AUDIO_IN_SAI_PDMx_DATA_CLK_AF GPIO_AF10_SAI4
#define AUDIO_IN_SAI_PDMx_IRQHandler SAI4_IRQHandler
#define AUDIO_IN_SAI_PDMx_IRQ SAI4_IRQn
/* SAI PDM DMA Stream definitions */
#define AUDIO_IN_SAI_PDMx_DMAx_CLK_ENABLE() __HAL_RCC_BDMA_CLK_ENABLE()
#define AUDIO_IN_SAI_PDMx_DMAx_STREAM BDMA_Channel1
#define AUDIO_IN_SAI_PDMx_DMAx_REQUEST BDMA_REQUEST_SAI4_A
#define AUDIO_IN_SAI_PDMx_DMAx_IRQ BDMA_Channel1_IRQn
#define AUDIO_IN_SAI_PDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
#define AUDIO_IN_SAI_PDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
#define AUDIO_IN_SAI_PDMx_DMAx_IRQHandler BDMA_Channel1_IRQHandler
/* Audio In devices */
/* Analog microphone input from 3.5 audio jack connector */
#define AUDIO_IN_DEVICE_ANALOG_MIC 0x00U
/* MP34DT01TR digital microphone on PCB top side */
#define AUDIO_IN_DEVICE_DIGITAL_MIC 0x10U
/* Audio In states */
#define AUDIO_IN_STATE_RESET 0U
#define AUDIO_IN_STATE_RECORDING 1U
#define AUDIO_IN_STATE_STOP 2U
#define AUDIO_IN_STATE_PAUSE 3U
/* Audio In instances number:
Instance 0 is SAI path
Instance 2 is SAI PDM path
*/
#define AUDIO_IN_INSTANCES_NBR 2U
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_AUDIO_Exported_Macros Exported Macros
* @{
*/
#define POS_VAL(VAL) (POSITION_VAL(VAL) - 4)
#define VOLUME_OUT_CONVERT(Volume) (((Volume) > 100)? 63:((uint8_t)(((Volume) * 63) / 100)))
#define VOLUME_IN_CONVERT(Volume) (((Volume) >= 100)? 239:((uint8_t)(((Volume) * 239) / 100)))
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_AUDIO_Exported_Variables
* @{
*/
/* Audio in and out component object */
extern void *Audio_CompObj;
/* Play */
extern SAI_HandleTypeDef haudio_out_sai;
extern AUDIO_OUT_Ctx_t Audio_Out_Ctx[];
/* Audio in and out component object */
extern void *Audio_CompObj;
extern SAI_HandleTypeDef haudio_in_sai;
extern AUDIO_IN_Ctx_t Audio_In_Ctx[];
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_AUDIO_OUT_Exported_Functions
* @{
*/
int32_t BSP_AUDIO_OUT_Init(uint32_t Instance, BSP_AUDIO_Init_t* AudioInit);
int32_t BSP_AUDIO_OUT_DeInit(uint32_t Instance);
#if (USE_HAL_SAI_REGISTER_CALLBACKS == 1U)
int32_t BSP_AUDIO_OUT_RegisterMspCallbacks (uint32_t Instance, BSP_AUDIO_OUT_Cb_t *CallBacks);
int32_t BSP_AUDIO_OUT_RegisterDefaultMspCallbacks (uint32_t Instance);
#endif /* (USE_HAL_SAI_REGISTER_CALLBACKS == 1U) */
int32_t BSP_AUDIO_OUT_Play(uint32_t Instance, uint8_t* pData, uint32_t NbrOfBytes);
int32_t BSP_AUDIO_OUT_Pause(uint32_t Instance);
int32_t BSP_AUDIO_OUT_Resume(uint32_t Instance);
int32_t BSP_AUDIO_OUT_Stop(uint32_t Instance);
int32_t BSP_AUDIO_OUT_Mute(uint32_t Instance);
int32_t BSP_AUDIO_OUT_UnMute(uint32_t Instance);
int32_t BSP_AUDIO_OUT_IsMute(uint32_t Instance, uint32_t *IsMute);
int32_t BSP_AUDIO_OUT_SetDevice(uint32_t Instance, uint32_t Device);
int32_t BSP_AUDIO_OUT_GetDevice(uint32_t Instance, uint32_t *Device);
int32_t BSP_AUDIO_OUT_SetSampleRate(uint32_t Instance, uint32_t SampleRate);
int32_t BSP_AUDIO_OUT_GetSampleRate(uint32_t Instance, uint32_t *SampleRate);
int32_t BSP_AUDIO_OUT_SetBitsPerSample(uint32_t Instance, uint32_t BitsPerSample);
int32_t BSP_AUDIO_OUT_GetBitsPerSample(uint32_t Instance, uint32_t *BitsPerSample);
int32_t BSP_AUDIO_OUT_SetChannelsNbr(uint32_t Instance, uint32_t ChannelNbr);
int32_t BSP_AUDIO_OUT_GetChannelsNbr(uint32_t Instance, uint32_t *ChannelNbr);
int32_t BSP_AUDIO_OUT_SetVolume(uint32_t Instance, uint32_t Volume);
int32_t BSP_AUDIO_OUT_GetVolume(uint32_t Instance, uint32_t *Volume);
int32_t BSP_AUDIO_OUT_GetState(uint32_t Instance, uint32_t *State);
void BSP_AUDIO_OUT_IRQHandler(uint32_t Instance);
/* User Callbacks: user has to implement these functions in his code if they are needed. */
/* This function is called when the requested data has been completely transferred.*/
void BSP_AUDIO_OUT_TransferComplete_CallBack(uint32_t Instance);
/* This function is called when half of the requested buffer has been transferred. */
void BSP_AUDIO_OUT_HalfTransfer_CallBack(uint32_t Instance);
/* This function is called when an Interrupt due to transfer error on or peripheral
error occurs. */
void BSP_AUDIO_OUT_Error_CallBack(uint32_t Instance);
/* These function can be modified in case the current settings need to be changed
for specific application needs */
HAL_StatusTypeDef MX_SAI1_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t SampleRate);
HAL_StatusTypeDef MX_SAI4_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t SampleRate);
HAL_StatusTypeDef MX_SAI1_Block_A_Init(SAI_HandleTypeDef* hsai, MX_SAI_Config_t *MXConfig);
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_AUDIO_IN_Exported_Functions
* @{
*/
int32_t BSP_AUDIO_IN_Init(uint32_t Instance, BSP_AUDIO_Init_t* AudioInit);
int32_t BSP_AUDIO_IN_DeInit(uint32_t Instance);
#if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
int32_t BSP_AUDIO_IN_RegisterDefaultMspCallbacks (uint32_t Instance);
int32_t BSP_AUDIO_IN_RegisterMspCallbacks (uint32_t Instance, BSP_AUDIO_IN_Cb_t *CallBacks);
#endif /*(USE_HAL_SAI_REGISTER_CALLBACKS == 1) */
int32_t BSP_AUDIO_IN_Record(uint32_t Instance, uint8_t* pBuf, uint32_t NbrOfBytes);
int32_t BSP_AUDIO_IN_Stop(uint32_t Instance);
int32_t BSP_AUDIO_IN_Pause(uint32_t Instance);
int32_t BSP_AUDIO_IN_Resume(uint32_t Instance);
int32_t BSP_AUDIO_IN_SetDevice(uint32_t Instance, uint32_t Device);
int32_t BSP_AUDIO_IN_GetDevice(uint32_t Instance, uint32_t *Device);
int32_t BSP_AUDIO_IN_SetSampleRate(uint32_t Instance, uint32_t SampleRate);
int32_t BSP_AUDIO_IN_GetSampleRate(uint32_t Instance, uint32_t *SampleRate);
int32_t BSP_AUDIO_IN_SetBitsPerSample(uint32_t Instance, uint32_t BitsPerSample);
int32_t BSP_AUDIO_IN_GetBitsPerSample(uint32_t Instance, uint32_t *BitsPerSample);
int32_t BSP_AUDIO_IN_SetChannelsNbr(uint32_t Instance, uint32_t ChannelNbr);
int32_t BSP_AUDIO_IN_GetChannelsNbr(uint32_t Instance, uint32_t *ChannelNbr);
int32_t BSP_AUDIO_IN_SetVolume(uint32_t Instance, uint32_t Volume);
int32_t BSP_AUDIO_IN_GetVolume(uint32_t Instance, uint32_t *Volume);
int32_t BSP_AUDIO_IN_GetState(uint32_t Instance, uint32_t *State);
/* Specific PDM recodr APIs */
int32_t BSP_AUDIO_IN_PDMToPCM_Init(uint32_t Instance, uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut);
int32_t BSP_AUDIO_IN_PDMToPCM(uint32_t Instance, uint16_t *PDMBuf, uint16_t *PCMBuf);
int32_t BSP_AUDIO_IN_RecordPDM(uint32_t Instance, uint8_t* pBuf, uint32_t NbrOfBytes);
void BSP_AUDIO_IN_IRQHandler(uint32_t Instance, uint32_t InputDevice);
/* User Callbacks: user has to implement these functions in his code if they are needed. */
/* This function should be implemented by the user application.
It is called into this driver when the current buffer is filled to prepare the next
buffer pointer and its size. */
void BSP_AUDIO_IN_TransferComplete_CallBack(uint32_t Instance);
void BSP_AUDIO_IN_HalfTransfer_CallBack(uint32_t Instance);
/* This function is called when an Interrupt due to transfer error on or peripheral
error occurs. */
void BSP_AUDIO_IN_Error_CallBack(uint32_t Instance);
/* These function can be modified in case the current settings (e.g. DMA stream)
need to be changed for specific application needs */
HAL_StatusTypeDef MX_SAI1_Block_B_Init(SAI_HandleTypeDef* hsai, MX_SAI_Config_t *MXConfig);
HAL_StatusTypeDef MX_SAI4_Block_A_Init(SAI_HandleTypeDef* hsai, MX_SAI_Config_t *MXConfig);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_AUDIO_H */
@@ -0,0 +1,882 @@
/**
******************************************************************************
* @file stm32h747i_discovery_bus.c
* @author MCD Application Team
* @brief This file provides a set of firmware functions to communicate
* with external devices available on STM32H747I-DISCO board (MB1248) from
* STMicroelectronics
******************************************************************************
* @attention
*
* Copyright (c) 2019 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 "stm32h747i_discovery_bus.h"
#include "stm32h747i_discovery_errno.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_BUS BUS
* @{
*/
/** @defgroup STM32H747I_DISCO_BUS_Private_Constants Private Constants
* @{
*/
#ifndef I2C_VALID_TIMING_NBR
#define I2C_VALID_TIMING_NBR 128U
#endif
#define I2C_SPEED_FREQ_STANDARD 0U /* 100 kHz */
#define I2C_SPEED_FREQ_FAST 1U /* 400 kHz */
#define I2C_SPEED_FREQ_FAST_PLUS 2U /* 1 MHz */
#define I2C_ANALOG_FILTER_DELAY_MIN 50U /* ns */
#define I2C_ANALOG_FILTER_DELAY_MAX 260U /* ns */
#define I2C_USE_ANALOG_FILTER 1U
#define I2C_DIGITAL_FILTER_COEF 0U
#define I2C_PRESC_MAX 16U
#define I2C_SCLDEL_MAX 16U
#define I2C_SDADEL_MAX 16U
#define I2C_SCLH_MAX 256U
#define I2C_SCLL_MAX 256U
#define SEC2NSEC 1000000000UL
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Private_Types Private Types
* @{
*/
typedef struct
{
uint32_t freq; /* Frequency in Hz */
uint32_t freq_min; /* Minimum frequency in Hz */
uint32_t freq_max; /* Maximum frequency in Hz */
uint32_t hddat_min; /* Minimum data hold time in ns */
uint32_t vddat_max; /* Maximum data valid time in ns */
uint32_t sudat_min; /* Minimum data setup time in ns */
uint32_t lscl_min; /* Minimum low period of the SCL clock in ns */
uint32_t hscl_min; /* Minimum high period of SCL clock in ns */
uint32_t trise; /* Rise time in ns */
uint32_t tfall; /* Fall time in ns */
uint32_t dnf; /* Digital noise filter coefficient */
} I2C_Charac_t;
typedef struct
{
uint32_t presc; /* Timing prescaler */
uint32_t tscldel; /* SCL delay */
uint32_t tsdadel; /* SDA delay */
uint32_t sclh; /* SCL high period */
uint32_t scll; /* SCL low period */
} I2C_Timings_t;
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_BUS_Private_Constants
* @{
*/
static const I2C_Charac_t I2C_Charac[] =
{
[I2C_SPEED_FREQ_STANDARD] =
{
.freq = 100000,
.freq_min = 80000,
.freq_max = 120000,
.hddat_min = 0,
.vddat_max = 3450,
.sudat_min = 250,
.lscl_min = 4700,
.hscl_min = 4000,
.trise = 640,
.tfall = 20,
.dnf = I2C_DIGITAL_FILTER_COEF,
},
[I2C_SPEED_FREQ_FAST] =
{
.freq = 400000,
.freq_min = 320000,
.freq_max = 480000,
.hddat_min = 0,
.vddat_max = 900,
.sudat_min = 100,
.lscl_min = 1300,
.hscl_min = 600,
.trise = 250,
.tfall = 100,
.dnf = I2C_DIGITAL_FILTER_COEF,
},
[I2C_SPEED_FREQ_FAST_PLUS] =
{
.freq = 1000000,
.freq_min = 800000,
.freq_max = 1200000,
.hddat_min = 0,
.vddat_max = 450,
.sudat_min = 50,
.lscl_min = 500,
.hscl_min = 260,
.trise = 60,
.tfall = 100,
.dnf = I2C_DIGITAL_FILTER_COEF,
},
};
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Private_Variables Private Variables
* @{
*/
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
static uint32_t IsI2c4MspCbValid = 0;
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
static uint32_t I2c4InitCounter = 0;
static I2C_Timings_t I2c_valid_timing[I2C_VALID_TIMING_NBR];
static uint32_t I2c_valid_timing_nbr = 0;
#if defined(BSP_USE_CMSIS_OS)
static osSemaphoreId BspI2cSemaphore = 0;
#endif
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Exported_Variables Exported Variables
* @{
*/
I2C_HandleTypeDef hbus_i2c4;
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Private_FunctionPrototypes Private FunctionPrototypes
* @{
*/
static void I2C4_MspInit(I2C_HandleTypeDef *phi2c);
static void I2C4_MspDeInit(I2C_HandleTypeDef *phi2c);
static int32_t I2C4_WriteReg(uint16_t DevAddr, uint16_t Reg, uint16_t MemAddSize, uint8_t *pData, uint16_t Length);
static int32_t I2C4_ReadReg(uint16_t DevAddr, uint16_t Reg, uint16_t MemAddSize, uint8_t *pData, uint16_t Length);
static uint32_t I2C_GetTiming(uint32_t clock_src_freq, uint32_t i2c_freq);
static uint32_t I2C_Compute_SCLL_SCLH(uint32_t clock_src_freq, uint32_t I2C_speed);
static void I2C_Compute_PRESC_SCLDEL_SDADEL(uint32_t clock_src_freq, uint32_t I2C_speed);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Exported_Functions Exported Functions
* @{
*/
/**
* @brief Initializes I2C HAL.
* @retval BSP status
*/
int32_t BSP_I2C4_Init(void)
{
int32_t ret = BSP_ERROR_NONE;
hbus_i2c4.Instance = BUS_I2C4;
if (I2c4InitCounter == 0U)
{
I2c4InitCounter++;
if (HAL_I2C_GetState(&hbus_i2c4) == HAL_I2C_STATE_RESET)
{
#if defined(BSP_USE_CMSIS_OS)
if(BspI2cSemaphore == NULL)
{
/* Create semaphore to prevent multiple I2C access */
osSemaphoreDef(BSP_I2C_SEM);
BspI2cSemaphore = osSemaphoreCreate(osSemaphore(BSP_I2C_SEM), 1);
}
#endif
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 0)
/* Init the I2C4 Msp */
I2C4_MspInit(&hbus_i2c4);
#else
if (IsI2c4MspCbValid == 0U)
{
if (BSP_I2C4_RegisterDefaultMspCallbacks() != BSP_ERROR_NONE)
{
ret = BSP_ERROR_MSP_FAILURE;
}
}
if (ret == BSP_ERROR_NONE)
{
#endif
if (MX_I2C4_Init(&hbus_i2c4, I2C_GetTiming(HAL_RCC_GetPCLK2Freq(), BUS_I2C4_FREQUENCY)) != HAL_OK)
{
ret = BSP_ERROR_BUS_FAILURE;
}
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
}
#endif
}
}
return ret;
}
/**
* @brief DeInitializes I2C HAL.
* @retval BSP status
*/
int32_t BSP_I2C4_DeInit(void)
{
int32_t ret = BSP_ERROR_NONE;
I2c4InitCounter--;
if (I2c4InitCounter == 0U)
{
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 0)
I2C4_MspDeInit(&hbus_i2c4);
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 0) */
/* Init the I2C */
if (HAL_I2C_DeInit(&hbus_i2c4) != HAL_OK)
{
ret = BSP_ERROR_BUS_FAILURE;
}
}
return ret;
}
/**
* @brief MX I2C4 initialization.
* @param hI2c I2C handle
* @param timing I2C timing
* @retval HAL status
*/
__weak HAL_StatusTypeDef MX_I2C4_Init(I2C_HandleTypeDef *hI2c, uint32_t timing)
{
HAL_StatusTypeDef status = HAL_OK;
hI2c->Init.Timing = timing;
hI2c->Init.OwnAddress1 = 0;
hI2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hI2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hI2c->Init.OwnAddress2 = 0;
hI2c->Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hI2c->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hI2c->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(hI2c) != HAL_OK)
{
status = HAL_ERROR;
}
else
{
uint32_t analog_filter;
analog_filter = I2C_ANALOGFILTER_ENABLE;
if (HAL_I2CEx_ConfigAnalogFilter(hI2c, analog_filter) != HAL_OK)
{
status = HAL_ERROR;
}
else
{
if (HAL_I2CEx_ConfigDigitalFilter(hI2c, I2C_DIGITAL_FILTER_COEF) != HAL_OK)
{
status = HAL_ERROR;
}
}
}
return status;
}
/**
* @brief Write a 8bit value in a register of the device through BUS.
* @param DevAddr Device address on Bus.
* @param Reg The target register address to write
* @param pData The target register value to be written
* @param Length buffer size to be written
* @retval BSP status
*/
int32_t BSP_I2C4_WriteReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
int32_t ret;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
if(I2C4_WriteReg(DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length) == 0)
{
ret = BSP_ERROR_NONE;
}
else
{
if( HAL_I2C_GetError(&hbus_i2c4) == HAL_I2C_ERROR_AF)
{
ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE;
}
else
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
return ret;
}
/**
* @brief Read a 8bit register of the device through BUS
* @param DevAddr Device address on BUS
* @param Reg The target register address to read
* @param pData Pointer to data buffer
* @param Length Length of the data
* @retval BSP status
*/
int32_t BSP_I2C4_ReadReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
int32_t ret;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
if(I2C4_ReadReg(DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length) == 0)
{
ret = BSP_ERROR_NONE;
}
else
{
if( HAL_I2C_GetError(&hbus_i2c4) == HAL_I2C_ERROR_AF)
{
ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE;
}
else
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
return ret;
}
/**
* @brief Write a 16bit value in a register of the device through BUS.
* @param DevAddr Device address on Bus.
* @param Reg The target register address to write
* @param pData The target register value to be written
* @param Length buffer size to be written
* @retval BSP status
*/
int32_t BSP_I2C4_WriteReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
int32_t ret;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
if(I2C4_WriteReg(DevAddr, Reg, I2C_MEMADD_SIZE_16BIT, pData, Length) == 0)
{
ret = BSP_ERROR_NONE;
}
else
{
if( HAL_I2C_GetError(&hbus_i2c4) == HAL_I2C_ERROR_AF)
{
ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE;
}
else
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
return ret;
}
/**
* @brief Read a 16bit register of the device through BUS
* @param DevAddr Device address on BUS
* @param Reg The target register address to read
* @param pData Pointer to data buffer
* @param Length Length of the data
* @retval BSP status
*/
int32_t BSP_I2C4_ReadReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
int32_t ret;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
if(I2C4_ReadReg(DevAddr, Reg, I2C_MEMADD_SIZE_16BIT, pData, Length) == 0)
{
ret = BSP_ERROR_NONE;
}
else
{
if( HAL_I2C_GetError(&hbus_i2c4) == HAL_I2C_ERROR_AF)
{
ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE;
}
else
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
return ret;
}
/**
* @brief Checks if target device is ready for communication.
* @note This function is used with Memory devices
* @param DevAddr Target device address
* @param Trials Number of trials
* @retval BSP status
*/
int32_t BSP_I2C4_IsReady(uint16_t DevAddr, uint32_t Trials)
{
int32_t ret = BSP_ERROR_NONE;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
if(HAL_I2C_IsDeviceReady(&hbus_i2c4, DevAddr, Trials, 1000) != HAL_OK)
{
ret = BSP_ERROR_BUSY;
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
return ret;
}
/**
* @brief Delay function
* @retval Tick value
*/
int32_t BSP_GetTick(void)
{
return (int32_t)HAL_GetTick();
}
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
/**
* @brief Register Default I2C4 Bus Msp Callbacks
* @retval BSP status
*/
int32_t BSP_I2C4_RegisterDefaultMspCallbacks (void)
{
int32_t ret = BSP_ERROR_NONE;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
__HAL_I2C_RESET_HANDLE_STATE(&hbus_i2c4);
/* Register default MspInit/MspDeInit Callback */
if(HAL_I2C_RegisterCallback(&hbus_i2c4, HAL_I2C_MSPINIT_CB_ID, I2C4_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_I2C_RegisterCallback(&hbus_i2c4, HAL_I2C_MSPDEINIT_CB_ID, I2C4_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsI2c4MspCbValid = 1U;
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
/* BSP status */
return ret;
}
/**
* @brief Register I2C4 Bus Msp Callback registering
* @param Callbacks pointer to I2C4 MspInit/MspDeInit callback functions
* @retval BSP status
*/
int32_t BSP_I2C4_RegisterMspCallbacks (BSP_I2C_Cb_t *Callback)
{
int32_t ret = BSP_ERROR_NONE;
#if defined(BSP_USE_CMSIS_OS)
/* Get semaphore to prevent multiple I2C access */
osSemaphoreWait(BspI2cSemaphore, osWaitForever);
#endif
__HAL_I2C_RESET_HANDLE_STATE(&hbus_i2c4);
/* Register MspInit/MspDeInit Callbacks */
if(HAL_I2C_RegisterCallback(&hbus_i2c4, HAL_I2C_MSPINIT_CB_ID, Callback->pMspI2cInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_I2C_RegisterCallback(&hbus_i2c4, HAL_I2C_MSPDEINIT_CB_ID, Callback->pMspI2cDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsI2c4MspCbValid = 1U;
}
#if defined(BSP_USE_CMSIS_OS)
/* Release semaphore to prevent multiple I2C access */
osSemaphoreRelease(BspI2cSemaphore);
#endif
/* BSP status */
return ret;
}
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Private_Functions Private Functions
* @{
*/
/**
* @brief Compute I2C timing according current I2C clock source and required I2C clock.
* @param clock_src_freq I2C clock source in Hz.
* @param i2c_freq Required I2C clock in Hz.
* @retval I2C timing or 0 in case of error.
*/
static uint32_t I2C_GetTiming(uint32_t clock_src_freq, uint32_t i2c_freq)
{
uint32_t ret = 0;
uint32_t speed;
uint32_t idx;
if((clock_src_freq != 0U) && (i2c_freq != 0U))
{
for ( speed = 0 ; speed <= (uint32_t)I2C_SPEED_FREQ_FAST_PLUS ; speed++)
{
if ((i2c_freq >= I2C_Charac[speed].freq_min) &&
(i2c_freq <= I2C_Charac[speed].freq_max))
{
I2C_Compute_PRESC_SCLDEL_SDADEL(clock_src_freq, speed);
idx = I2C_Compute_SCLL_SCLH(clock_src_freq, speed);
if (idx < I2C_VALID_TIMING_NBR)
{
ret = ((I2c_valid_timing[idx].presc & 0x0FU) << 28) |\
((I2c_valid_timing[idx].tscldel & 0x0FU) << 20) |\
((I2c_valid_timing[idx].tsdadel & 0x0FU) << 16) |\
((I2c_valid_timing[idx].sclh & 0xFFU) << 8) |\
((I2c_valid_timing[idx].scll & 0xFFU) << 0);
}
break;
}
}
}
return ret;
}
/**
* @brief Compute PRESC, SCLDEL and SDADEL.
* @param clock_src_freq I2C source clock in HZ.
* @param I2C_speed I2C frequency (index).
* @retval None.
*/
static void I2C_Compute_PRESC_SCLDEL_SDADEL(uint32_t clock_src_freq, uint32_t I2C_speed)
{
uint32_t prev_presc = I2C_PRESC_MAX;
uint32_t ti2cclk;
int32_t tsdadel_min, tsdadel_max;
int32_t tscldel_min;
uint32_t presc, scldel, sdadel;
uint32_t tafdel_min, tafdel_max;
ti2cclk = (SEC2NSEC + (clock_src_freq / 2U))/ clock_src_freq;
tafdel_min = I2C_ANALOG_FILTER_DELAY_MIN;
tafdel_max = I2C_ANALOG_FILTER_DELAY_MAX;
/* tDNF = DNF x tI2CCLK
tPRESC = (PRESC+1) x tI2CCLK
SDADEL >= {tf +tHD;DAT(min) - tAF(min) - tDNF - [3 x tI2CCLK]} / {tPRESC}
SDADEL <= {tVD;DAT(max) - tr - tAF(max) - tDNF- [4 x tI2CCLK]} / {tPRESC} */
tsdadel_min = (int32_t)I2C_Charac[I2C_speed].tfall + (int32_t)I2C_Charac[I2C_speed].hddat_min -
(int32_t)tafdel_min - (int32_t)(((int32_t)I2C_Charac[I2C_speed].dnf + 3) * (int32_t)ti2cclk);
tsdadel_max = (int32_t)I2C_Charac[I2C_speed].vddat_max - (int32_t)I2C_Charac[I2C_speed].trise -
(int32_t)tafdel_max - (int32_t)(((int32_t)I2C_Charac[I2C_speed].dnf + 4) * (int32_t)ti2cclk);
/* {[tr+ tSU;DAT(min)] / [tPRESC]} - 1 <= SCLDEL */
tscldel_min = (int32_t)I2C_Charac[I2C_speed].trise + (int32_t)I2C_Charac[I2C_speed].sudat_min;
if (tsdadel_min <= 0)
{
tsdadel_min = 0;
}
if (tsdadel_max <= 0)
{
tsdadel_max = 0;
}
for (presc = 0; presc < I2C_PRESC_MAX; presc++)
{
for (scldel = 0; scldel < I2C_SCLDEL_MAX; scldel++)
{
/* TSCLDEL = (SCLDEL+1) * (PRESC+1) * TI2CCLK */
uint32_t tscldel = (scldel + 1U) * (presc + 1U) * ti2cclk;
if (tscldel >= (uint32_t)tscldel_min)
{
for (sdadel = 0; sdadel < I2C_SDADEL_MAX; sdadel++)
{
/* TSDADEL = SDADEL * (PRESC+1) * TI2CCLK */
uint32_t tsdadel = (sdadel * (presc + 1U)) * ti2cclk;
if ((tsdadel >= (uint32_t)tsdadel_min) && (tsdadel <= (uint32_t)tsdadel_max))
{
if(presc != prev_presc)
{
I2c_valid_timing[I2c_valid_timing_nbr].presc = presc;
I2c_valid_timing[I2c_valid_timing_nbr].tscldel = scldel;
I2c_valid_timing[I2c_valid_timing_nbr].tsdadel = sdadel;
prev_presc = presc;
I2c_valid_timing_nbr ++;
if(I2c_valid_timing_nbr >= I2C_VALID_TIMING_NBR)
{
return;
}
}
}
}
}
}
}
}
/**
* @brief Calculate SCLL and SCLH and find best configuration.
* @param clock_src_freq I2C source clock in HZ.
* @param I2C_speed I2C frequency (index).
* @retval config index (0 to I2C_VALID_TIMING_NBR], 0xFFFFFFFF for no valid config.
*/
static uint32_t I2C_Compute_SCLL_SCLH (uint32_t clock_src_freq, uint32_t I2C_speed)
{
uint32_t ret = 0xFFFFFFFFU;
uint32_t ti2cclk;
uint32_t ti2cspeed;
uint32_t prev_error;
uint32_t dnf_delay;
uint32_t clk_min, clk_max;
uint32_t scll, sclh;
uint32_t tafdel_min;
ti2cclk = (SEC2NSEC + (clock_src_freq / 2U))/ clock_src_freq;
ti2cspeed = (SEC2NSEC + (I2C_Charac[I2C_speed].freq / 2U))/ I2C_Charac[I2C_speed].freq;
tafdel_min = I2C_ANALOG_FILTER_DELAY_MIN;
/* tDNF = DNF x tI2CCLK */
dnf_delay = I2C_Charac[I2C_speed].dnf * ti2cclk;
clk_max = SEC2NSEC / I2C_Charac[I2C_speed].freq_min;
clk_min = SEC2NSEC / I2C_Charac[I2C_speed].freq_max;
prev_error = ti2cspeed;
for (uint32_t count = 0; count < I2c_valid_timing_nbr; count++)
{
/* tPRESC = (PRESC+1) x tI2CCLK*/
uint32_t tpresc = (I2c_valid_timing[count].presc + 1U) * ti2cclk;
for (scll = 0; scll < I2C_SCLL_MAX; scll++)
{
/* tLOW(min) <= tAF(min) + tDNF + 2 x tI2CCLK + [(SCLL+1) x tPRESC ] */
uint32_t tscl_l = tafdel_min + dnf_delay + (2U * ti2cclk) + ((scll + 1U) * tpresc);
/* The I2CCLK period tI2CCLK must respect the following conditions:
tI2CCLK < (tLOW - tfilters) / 4 and tI2CCLK < tHIGH */
if ((tscl_l > I2C_Charac[I2C_speed].lscl_min) && (ti2cclk < ((tscl_l - tafdel_min - dnf_delay) / 4U)))
{
for (sclh = 0; sclh < I2C_SCLH_MAX; sclh++)
{
/* tHIGH(min) <= tAF(min) + tDNF + 2 x tI2CCLK + [(SCLH+1) x tPRESC] */
uint32_t tscl_h = tafdel_min + dnf_delay + (2U * ti2cclk) + ((sclh + 1U) * tpresc);
/* tSCL = tf + tLOW + tr + tHIGH */
uint32_t tscl = tscl_l + tscl_h + I2C_Charac[I2C_speed].trise + I2C_Charac[I2C_speed].tfall;
if ((tscl >= clk_min) && (tscl <= clk_max) && (tscl_h >= I2C_Charac[I2C_speed].hscl_min) && (ti2cclk < tscl_h))
{
int32_t error = (int32_t)tscl - (int32_t)ti2cspeed;
if (error < 0)
{
error = -error;
}
/* look for the timings with the lowest clock error */
if ((uint32_t)error < prev_error)
{
prev_error = (uint32_t)error;
I2c_valid_timing[count].scll = scll;
I2c_valid_timing[count].sclh = sclh;
ret = count;
}
}
}
}
}
}
return ret;
}
/**
* @brief Initializes I2C MSP.
* @param phi2c I2C handler
* @retval None
*/
static void I2C4_MspInit(I2C_HandleTypeDef *phi2c)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(phi2c);
/*** Configure the GPIOs ***/
/* Enable SCL GPIO clock */
BUS_I2C4_SCL_GPIO_CLK_ENABLE();
/* Enable SDA GPIO clock */
BUS_I2C4_SDA_GPIO_CLK_ENABLE();
/* Configure I2C Tx as alternate function */
gpio_init_structure.Pin = BUS_I2C4_SCL_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Alternate = BUS_I2C4_SCL_AF;
HAL_GPIO_Init(BUS_I2C4_SCL_GPIO_PORT, &gpio_init_structure);
/* Configure I2C Rx as alternate function */
gpio_init_structure.Pin = BUS_I2C4_SDA_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Alternate = BUS_I2C4_SDA_AF;
HAL_GPIO_Init(BUS_I2C4_SDA_GPIO_PORT, &gpio_init_structure);
/*** Configure the I2C peripheral ***/
/* Enable I2C clock */
BUS_I2C4_CLK_ENABLE();
/* Force the I2C peripheral clock reset */
BUS_I2C4_FORCE_RESET();
/* Release the I2C peripheral clock reset */
BUS_I2C4_RELEASE_RESET();
}
/**
* @brief DeInitializes I2C MSP.
* @param phi2c I2C handler
* @retval None
*/
static void I2C4_MspDeInit(I2C_HandleTypeDef *phi2c)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(phi2c);
/* Configure I2C Tx, Rx as alternate function */
gpio_init_structure.Pin = BUS_I2C4_SCL_PIN;
HAL_GPIO_DeInit(BUS_I2C4_SCL_GPIO_PORT, gpio_init_structure.Pin );
gpio_init_structure.Pin = BUS_I2C4_SDA_PIN;
HAL_GPIO_DeInit(BUS_I2C4_SDA_GPIO_PORT, gpio_init_structure.Pin);
/* Disable I2C clock */
BUS_I2C4_CLK_DISABLE();
}
/**
* @brief Write a value in a register of the device through BUS.
* @param DevAddr Device address on Bus.
* @param MemAddSize Size of internal memory address
* @param Reg The target register address to write
* @param pData The target register value to be written
* @param Length data length in bytes
* @retval BSP status
*/
static int32_t I2C4_WriteReg(uint16_t DevAddr, uint16_t Reg, uint16_t MemAddSize, uint8_t *pData, uint16_t Length)
{
if(HAL_I2C_Mem_Write(&hbus_i2c4, DevAddr, Reg, MemAddSize, pData, Length, 1000) == HAL_OK)
{
return BSP_ERROR_NONE;
}
return BSP_ERROR_BUS_FAILURE;
}
/**
* @brief Read a register of the device through BUS
* @param DevAddr Device address on BUS
* @param MemAddSize Size of internal memory address
* @param Reg The target register address to read
* @param pData The target register value to be read
* @param Length data length in bytes
* @retval BSP status
*/
static int32_t I2C4_ReadReg(uint16_t DevAddr, uint16_t Reg, uint16_t MemAddSize, uint8_t *pData, uint16_t Length)
{
if (HAL_I2C_Mem_Read(&hbus_i2c4, DevAddr, Reg, MemAddSize, pData, Length, 1000) == HAL_OK)
{
return BSP_ERROR_NONE;
}
return BSP_ERROR_BUS_FAILURE;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,135 @@
/**
******************************************************************************
* @file stm32h747i_discovery_bus.h
* @author MCD Application Team
* @brief This file is the header of stm32h747i_discovery_bus.c file
******************************************************************************
* @attention
*
* Copyright (c) 2019 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 STM32H747I_DISCO_BUS_H
#define STM32H747I_DISCO_BUS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#if defined(BSP_USE_CMSIS_OS)
#include "cmsis_os.h"
#endif
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_BUS
* @{
*/
/** @defgroup STM32H747I_DISCO_BUS_Exported_Types Exported Types
* @{
*/
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(I2C_HandleTypeDef *);
void (* pMspDeInitCb)(I2C_HandleTypeDef *);
}BSP_I2C_Cb_t;
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_BUS_Exported_Constants Exported Constants
* @{
*/
/* Definition for I2C4 clock resources */
#define BUS_I2C4 I2C4
#define BUS_I2C4_CLK_ENABLE() __HAL_RCC_I2C4_CLK_ENABLE()
#define BUS_I2C4_CLK_DISABLE() __HAL_RCC_I2C4_CLK_DISABLE()
#define BUS_I2C4_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define BUS_I2C4_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define BUS_I2C4_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define BUS_I2C4_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define BUS_I2C4_FORCE_RESET() __HAL_RCC_I2C4_FORCE_RESET()
#define BUS_I2C4_RELEASE_RESET() __HAL_RCC_I2C4_RELEASE_RESET()
/* Definition for I2C4 Pins */
#define BUS_I2C4_SCL_PIN GPIO_PIN_12
#define BUS_I2C4_SDA_PIN GPIO_PIN_13
#define BUS_I2C4_SCL_GPIO_PORT GPIOD
#define BUS_I2C4_SDA_GPIO_PORT GPIOD
#define BUS_I2C4_SCL_AF GPIO_AF4_I2C4
#define BUS_I2C4_SDA_AF GPIO_AF4_I2C4
#ifndef BUS_I2C4_FREQUENCY
#define BUS_I2C4_FREQUENCY 100000U /* Frequency of I2Cn = 100 KHz*/
#endif
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_BUS_Exported_Variables
* @{
*/
extern I2C_HandleTypeDef hbus_i2c4;
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_BUS_Exported_Functions
* @{
*/
int32_t BSP_I2C4_Init(void);
int32_t BSP_I2C4_DeInit(void);
int32_t BSP_I2C4_WriteReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length);
int32_t BSP_I2C4_ReadReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length);
int32_t BSP_I2C4_WriteReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length);
int32_t BSP_I2C4_ReadReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length);
int32_t BSP_I2C4_IsReady(uint16_t DevAddr, uint32_t Trials);
int32_t BSP_GetTick(void);
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
int32_t BSP_I2C4_RegisterDefaultMspCallbacks (void);
int32_t BSP_I2C4_RegisterMspCallbacks (BSP_I2C_Cb_t *Callback);
#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
HAL_StatusTypeDef MX_I2C4_Init(I2C_HandleTypeDef *phi2c, uint32_t timing);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_BUS_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,280 @@
/**
******************************************************************************
* @file STM32H747I_discovery_camera.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the STM32H747I_discovery_camera.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2019 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 STM32H747I_DISCO_CAMERA_H
#define STM32H747I_DISCO_CAMERA_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_errno.h"
#include "stm32h747i_discovery_conf.h"
#include "camera.h"
#ifndef USE_CAMERA_SENSOR_OV9655
#define USE_CAMERA_SENSOR_OV9655 1
#endif
#ifndef USE_CAMERA_SENSOR_OV5640
#define USE_CAMERA_SENSOR_OV5640 1
#endif
#if (USE_CAMERA_SENSOR_OV9655 == 1)
#include "../Components/ov9655/ov9655.h"
#endif
#if (USE_CAMERA_SENSOR_OV5640 == 1)
#include "../Components/ov5640/ov5640.h"
#endif
#include "camera.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_CAMERA CAMERA
* @{
*/
/** @defgroup STM32H747I_DISCO_CAMERA_Exported_Types Exported Types
* @{
*/
typedef struct
{
uint32_t CameraId;
uint32_t Resolution;
uint32_t PixelFormat;
uint32_t LightMode;
uint32_t ColorEffect;
int32_t Brightness;
int32_t Saturation;
int32_t Contrast;
int32_t HueDegree;
uint32_t MirrorFlip;
uint32_t Zoom;
uint32_t NightMode;
uint32_t IsMspCallbacksValid;
}CAMERA_Ctx_t;
typedef struct
{
uint32_t Resolution;
uint32_t LightMode;
uint32_t ColorEffect;
uint32_t Brightness;
uint32_t Saturation;
uint32_t Contrast;
uint32_t HueDegree;
uint32_t MirrorFlip;
uint32_t Zoom;
uint32_t NightMode;
} CAMERA_Capabilities_t;
#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(DCMI_HandleTypeDef *);
void (* pMspDeInitCb)(DCMI_HandleTypeDef *);
}BSP_CAMERA_Cb_t;
#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_CAMERA_Exported_Constants Exported Constants
* @{
*/
/* Camera instance number */
#define CAMERA_INSTANCES_NBR 1U
#define CAMERA_MODE_CONTINUOUS DCMI_MODE_CONTINUOUS
#define CAMERA_MODE_SNAPSHOT DCMI_MODE_SNAPSHOT
/* Camera resolutions */
#define CAMERA_R160x120 0U /* QQVGA Resolution */
#define CAMERA_R320x240 1U /* QVGA Resolution */
#define CAMERA_R480x272 2U /* 480x272 Resolution */
#define CAMERA_R640x480 3U /* VGA Resolution */
#define CAMERA_R800x480 4U /* WVGA Resolution */
/* Camera Pixel Format */
#define CAMERA_PF_RGB565 0U /* Pixel Format RGB565 */
#define CAMERA_PF_RGB888 1U /* Pixel Format RGB888 */
#define CAMERA_PF_YUV422 2U /* Pixel Format YUV422 */
/* Brightness */
#define CAMERA_BRIGHTNESS_MIN -4
#define CAMERA_BRIGHTNESS_MAX 4
/* Saturation */
#define CAMERA_SATURATION_MIN -4
#define CAMERA_SATURATION_MAX 4
/* Contrast */
#define CAMERA_CONTRAST_MIN -4
#define CAMERA_CONTRAST_MAX 4
/* Hue Control */
#define CAMERA_HUEDEGREE_MIN -6
#define CAMERA_HUEDEGREE_MAX 5
/* Mirror/Flip */
#define CAMERA_MIRRORFLIP_NONE 0x00U /* Set camera normal mode */
#define CAMERA_MIRRORFLIP_FLIP 0x01U /* Set camera flip config */
#define CAMERA_MIRRORFLIP_MIRROR 0x02U /* Set camera mirror config */
/* Zoom */
#define CAMERA_ZOOM_x8 0x00U /* Set zoom to x8 */
#define CAMERA_ZOOM_x4 0x11U /* Set zoom to x4 */
#define CAMERA_ZOOM_x2 0x22U /* Set zoom to x2 */
#define CAMERA_ZOOM_x1 0x44U /* Set zoom to x1 */
/* Color Effect */
#define CAMERA_COLOR_EFFECT_NONE 0x00U /* No effect */
#define CAMERA_COLOR_EFFECT_BLUE 0x01U /* Blue effect */
#define CAMERA_COLOR_EFFECT_RED 0x02U /* Red effect */
#define CAMERA_COLOR_EFFECT_GREEN 0x04U /* Green effect */
#define CAMERA_COLOR_EFFECT_BW 0x08U /* Black and White effect */
#define CAMERA_COLOR_EFFECT_SEPIA 0x10U /* Sepia effect */
#define CAMERA_COLOR_EFFECT_NEGATIVE 0x20U /* Negative effect */
/* Light Mode */
#define CAMERA_LIGHT_AUTO 0x00U /* Light Mode Auto */
#define CAMERA_LIGHT_SUNNY 0x01U /* Light Mode Sunny */
#define CAMERA_LIGHT_OFFICE 0x02U /* Light Mode Office */
#define CAMERA_LIGHT_HOME 0x04U /* Light Mode Home */
#define CAMERA_LIGHT_CLOUDY 0x08U /* Light Mode Claudy */
/* Night Mode */
#define CAMERA_NIGHT_MODE_SET 0x00U /* Disable night mode */
#define CAMERA_NIGHT_MODE_RESET 0x01U /* Enable night mode */
#define CAMERA_IRQHandler DCMI_IRQHandler
#define CAMERA_DMA_IRQHandler DMA2_Stream3_IRQHandler
#define CAMERA_OV9655_ADDRESS 0x60U
#define CAMERA_OV5640_ADDRESS 0x78U
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_CAMERA_Exported_Variables
* @{
*/
extern void *Camera_CompObj;
extern DCMI_HandleTypeDef hcamera_dcmi;
extern CAMERA_Ctx_t Camera_Ctx[];
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_CAMERA_Exported_Functions
* @{
*/
int32_t BSP_CAMERA_Init(uint32_t Instance, uint32_t Resolution, uint32_t PixelFormat);
int32_t BSP_CAMERA_DeInit(uint32_t Instance);
#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
int32_t BSP_CAMERA_RegisterDefaultMspCallbacks (uint32_t Instance);
int32_t BSP_CAMERA_RegisterMspCallbacks(uint32_t Instance, BSP_CAMERA_Cb_t *CallBacks);
#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) */
int32_t BSP_CAMERA_Start(uint32_t Instance, uint8_t *buff, uint32_t Mode);
int32_t BSP_CAMERA_Stop(uint32_t Instance);
int32_t BSP_CAMERA_Suspend(uint32_t Instance);
int32_t BSP_CAMERA_Resume(uint32_t Instance);
int32_t BSP_CAMERA_GetCapabilities(uint32_t Instance, CAMERA_Capabilities_t *Capabilities);
int32_t BSP_CAMERA_SetResolution(uint32_t Instance, uint32_t Resolution);
int32_t BSP_CAMERA_GetResolution(uint32_t Instance, uint32_t *Resolution);
int32_t BSP_CAMERA_SetPixelFormat(uint32_t Instance, uint32_t PixelFormat);
int32_t BSP_CAMERA_GetPixelFormat(uint32_t Instance, uint32_t *PixelFormat);
int32_t BSP_CAMERA_SetLightMode(uint32_t Instance, uint32_t LightMode);
int32_t BSP_CAMERA_GetLightMode(uint32_t Instance, uint32_t *LightMode);
int32_t BSP_CAMERA_SetColorEffect(uint32_t Instance, uint32_t ColorEffect);
int32_t BSP_CAMERA_GetColorEffect(uint32_t Instance, uint32_t *ColorEffect);
int32_t BSP_CAMERA_SetBrightness(uint32_t Instance, int32_t Brightness);
int32_t BSP_CAMERA_GetBrightness(uint32_t Instance, int32_t *Brightness);
int32_t BSP_CAMERA_SetSaturation(uint32_t Instance, int32_t Saturation);
int32_t BSP_CAMERA_GetSaturation(uint32_t Instance, int32_t *Saturation);
int32_t BSP_CAMERA_SetContrast(uint32_t Instance, int32_t Contrast);
int32_t BSP_CAMERA_GetContrast(uint32_t Instance, int32_t *Contrast);
int32_t BSP_CAMERA_SetHueDegree(uint32_t Instance, int32_t HueDegree);
int32_t BSP_CAMERA_GetHueDegree(uint32_t Instance, int32_t *HueDegree);
int32_t BSP_CAMERA_SetMirrorFlip(uint32_t Instance, uint32_t MirrorFlip);
int32_t BSP_CAMERA_GetMirrorFlip(uint32_t Instance, uint32_t *MirrorFlip);
int32_t BSP_CAMERA_SetZoom(uint32_t Instance, uint32_t Zoom);
int32_t BSP_CAMERA_GetZoom(uint32_t Instance, uint32_t *Zoom);
int32_t BSP_CAMERA_EnableNightMode(uint32_t Instance);
int32_t BSP_CAMERA_DisableNightMode(uint32_t Instance);
int32_t BSP_CAMERA_HwReset(uint32_t Instance);
int32_t BSP_CAMERA_PwrDown(uint32_t Instance);
int32_t BSP_CAMERA_PwrUp(uint32_t Instance);
void BSP_CAMERA_LineEventCallback(uint32_t Instance);
void BSP_CAMERA_FrameEventCallback(uint32_t Instance);
void BSP_CAMERA_VsyncEventCallback(uint32_t Instance);
void BSP_CAMERA_ErrorCallback(uint32_t Instance);
void BSP_CAMERA_IRQHandler(uint32_t Instance);
void BSP_CAMERA_DMA_IRQHandler(uint32_t Instance);
/* These functions can be modified in case the current settings (e.g. DMA stream)
need to be changed for specific application needs */
HAL_StatusTypeDef MX_DCMI_Init(DCMI_HandleTypeDef* hdcmi);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_CAMERA_H */
@@ -0,0 +1,80 @@
/**
******************************************************************************
* @file stm32h747i_discovery_conf_template.h
* @author MCD Application Team
* @brief STM32H747I_DISCO board configuration file.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_CONF_H
#define STM32H747I_DISCO_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal.h"
/* COM define */
#define USE_COM_LOG 0U
#define USE_BSP_COM_FEATURE 0U
/* LCD controllers defines */
#define USE_LCD_CTRL_NT35510 0U
#define USE_LCD_CTRL_OTM8009A 1U
#define USE_LCD_CTRL_ADV7533 1U
#define LCD_LAYER_0_ADDRESS 0xD0000000U
#define LCD_LAYER_1_ADDRESS 0xD0200000U
#define USE_DMA2D_TO_FILL_RGB_RECT 0U
/* Camera sensors defines */
#define USE_CAMERA_SENSOR_OV5640 1U
#define USE_CAMERA_SENSOR_OV9655 1U
/* SD interface defines */
#define USE_SD_BUS_WIDE_4B 1U
/* Audio codecs defines */
#define USE_AUDIO_CODEC_WM8994 1U
/* TS supported features defines */
#define USE_TS_GESTURE 1U
#define USE_TS_MULTI_TOUCH 1U
/* Default TS touch number */
#define TS_TOUCH_NBR 2U
/* IRQ priorities */
#define BSP_SDRAM_IT_PRIORITY 15U
#define BSP_CAMERA_IT_PRIORITY 15U
#define BSP_BUTTON_WAKEUP_IT_PRIORITY 15U
#define BSP_AUDIO_OUT_IT_PRIORITY 14U
#define BSP_AUDIO_IN_IT_PRIORITY 15U
#define BSP_SD_IT_PRIORITY 14U
#define BSP_SD_RX_IT_PRIORITY 14U
#define BSP_SD_TX_IT_PRIORITY 15U
#define BSP_TS_IT_PRIORITY 15U
#define BSP_JOY1_SEL_IT_PRIORITY 15U
#define BSP_JOY1_DOWN_IT_PRIORITY 15U
#define BSP_JOY1_LEFT_IT_PRIORITY 15U
#define BSP_JOY1_RIGHT_IT_PRIORITY 15U
#define BSP_JOY1_UP_IT_PRIORITY 15U
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_CONF_H */
@@ -0,0 +1,66 @@
/**
******************************************************************************
* @file STM32H747I_discovery_errno.h
* @author MCD Application Team
* @brief Error Code.
*
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_ERRNO_H
#define STM32H747I_DISCO_ERRNO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Common Error codes */
#define BSP_ERROR_NONE 0
#define BSP_ERROR_NO_INIT -1
#define BSP_ERROR_WRONG_PARAM -2
#define BSP_ERROR_BUSY -3
#define BSP_ERROR_PERIPH_FAILURE -4
#define BSP_ERROR_COMPONENT_FAILURE -5
#define BSP_ERROR_UNKNOWN_FAILURE -6
#define BSP_ERROR_UNKNOWN_COMPONENT -7
#define BSP_ERROR_BUS_FAILURE -8
#define BSP_ERROR_CLOCK_FAILURE -9
#define BSP_ERROR_MSP_FAILURE -10
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
/* BSP OSPI error codes */
#define BSP_ERROR_QSPI_ASSIGN_FAILURE -24
#define BSP_ERROR_QSPI_SETUP_FAILURE -25
#define BSP_ERROR_QSPI_MMP_LOCK_FAILURE -26
#define BSP_ERROR_QSPI_MMP_UNLOCK_FAILURE -27
/* BSP TS error code */
#define BSP_ERROR_TS_TOUCH_NOT_DETECTED -30
/* BSP BUS error codes */
#define BSP_ERROR_BUS_TRANSACTION_FAILURE -100
#define BSP_ERROR_BUS_ARBITRATION_LOSS -101
#define BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE -102
#define BSP_ERROR_BUS_PROTOCOL_FAILURE -103
#define BSP_ERROR_BUS_MODE_FAULT -104
#define BSP_ERROR_BUS_FRAME_ERROR -105
#define BSP_ERROR_BUS_CRC_ERROR -106
#define BSP_ERROR_BUS_DMA_FAILURE -107
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_ERRNO_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,333 @@
/**
******************************************************************************
* @file stm32h747i_discovery_lcd.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_lcd.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_LCD_H
#define STM32H747I_DISCO_LCD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#include "lcd.h"
/* Include NT35510 LCD Driver IC driver code */
#include "../Components/nt35510/nt35510.h"
/* Include OTM8009A LCD Driver IC driver code */
#include "../Components/otm8009a/otm8009a.h"
#if (USE_LCD_CTRL_ADV7533 == 1)
/* Include ADV7533 HDMI Driver IC driver code */
#include "../Components/adv7533/adv7533.h"
#endif /* USE_LCD_CTRL_ADV7533 */
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_LCD
* @{
*/
/** @defgroup STM32H747I_DISCO_LCD_Exported_Constants Exported Constants
* @{
*/
#define LCD_INSTANCES_NBR 1
/**
* @brief HDMI Format
*/
#define HDMI_FORMAT_720_480 0x00U /* 720_480 format choice of HDMI display */
#define HDMI_FORMAT_720_576 0x01U /* 720_576 format choice of HDMI display */
#define LCD_ORIENTATION_LANDSCAPE 0x01U /* Landscape orientation choice of LCD screen */
#define LCD_DEFAULT_WIDTH 800
#define LCD_DEFAULT_HEIGHT 480
#define BSP_LCD_RELOAD_NONE 0U /* No reload executed */
#define BSP_LCD_RELOAD_IMMEDIATE LTDC_RELOAD_IMMEDIATE /* Immediate Reload */
#define BSP_LCD_RELOAD_VERTICAL_BLANKING LTDC_RELOAD_VERTICAL_BLANKING /* Vertical Blanking Reload */
/**
* @brief LCD special pins
*/
/* LCD reset pin */
#define LCD_RESET_PIN GPIO_PIN_3
#define LCD_RESET_PULL GPIO_NOPULL
#define LCD_RESET_GPIO_PORT GPIOG
#define LCD_RESET_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define LCD_RESET_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
/* LCD tearing effect pin */
#define LCD_TE_PIN GPIO_PIN_2
#define LCD_TE_GPIO_PORT GPIOJ
#define LCD_TE_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define LCD_TE_GPIO_CLK_DISABLE() __HAL_RCC_GPIOJ_CLK_DISABLE()
/* Back-light control pin */
#define LCD_BL_CTRL_PIN GPIO_PIN_12
#define LCD_BL_CTRL_GPIO_PORT GPIOJ
#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOJ_CLK_DISABLE()
/**
* @}
*/
/**
* @brief LCD color
*/
/* RGB565 colors definitions */
#define LCD_COLOR_RGB565_BLUE 0x001FU
#define LCD_COLOR_RGB565_GREEN 0x07E0U
#define LCD_COLOR_RGB565_RED 0xF800U
#define LCD_COLOR_RGB565_CYAN 0x07FFU
#define LCD_COLOR_RGB565_MAGENTA 0xF81FU
#define LCD_COLOR_RGB565_YELLOW 0xFFE0U
#define LCD_COLOR_RGB565_LIGHTBLUE 0x841FU
#define LCD_COLOR_RGB565_LIGHTGREEN 0x87F0U
#define LCD_COLOR_RGB565_LIGHTRED 0xFC10U
#define LCD_COLOR_RGB565_LIGHTCYAN 0x87FFU
#define LCD_COLOR_RGB565_LIGHTMAGENTA 0xFC1FU
#define LCD_COLOR_RGB565_LIGHTYELLOW 0xFFF0U
#define LCD_COLOR_RGB565_DARKBLUE 0x0010U
#define LCD_COLOR_RGB565_DARKGREEN 0x0400U
#define LCD_COLOR_RGB565_DARKRED 0x8000U
#define LCD_COLOR_RGB565_DARKCYAN 0x0410U
#define LCD_COLOR_RGB565_DARKMAGENTA 0x8010U
#define LCD_COLOR_RGB565_DARKYELLOW 0x8400U
#define LCD_COLOR_RGB565_WHITE 0xFFFFU
#define LCD_COLOR_RGB565_LIGHTGRAY 0xD69AU
#define LCD_COLOR_RGB565_GRAY 0x8410U
#define LCD_COLOR_RGB565_DARKGRAY 0x4208U
#define LCD_COLOR_RGB565_BLACK 0x0000U
#define LCD_COLOR_RGB565_BROWN 0xA145U
#define LCD_COLOR_RGB565_ORANGE 0xFD20U
/* Definition of Official ST COLOR */
#define LCD_COLOR_RGB565_ST_BLUE_DARK 0x0001U
#define LCD_COLOR_RGB565_ST_BLUE 0x01EBU
#define LCD_COLOR_RGB565_ST_BLUE_LIGHT 0x06A7U
#define LCD_COLOR_RGB565_ST_GREEN_LIGHT 0x05ECU
#define LCD_COLOR_RGB565_ST_GREEN_DARK 0x001CU
#define LCD_COLOR_RGB565_ST_YELLOW 0x07F0U
#define LCD_COLOR_RGB565_ST_BROWN 0x02C8U
#define LCD_COLOR_RGB565_ST_PINK 0x0681U
#define LCD_COLOR_RGB565_ST_PURPLE 0x02CDU
#define LCD_COLOR_RGB565_ST_GRAY_DARK 0x0251U
#define LCD_COLOR_RGB565_ST_GRAY 0x04BAU
#define LCD_COLOR_RGB565_ST_GRAY_LIGHT 0x05E7U
/* ARGB8888 colors definitions */
#define LCD_COLOR_ARGB8888_BLUE 0xFF0000FFUL
#define LCD_COLOR_ARGB8888_GREEN 0xFF00FF00UL
#define LCD_COLOR_ARGB8888_RED 0xFFFF0000UL
#define LCD_COLOR_ARGB8888_CYAN 0xFF00FFFFUL
#define LCD_COLOR_ARGB8888_MAGENTA 0xFFFF00FFUL
#define LCD_COLOR_ARGB8888_YELLOW 0xFFFFFF00UL
#define LCD_COLOR_ARGB8888_LIGHTBLUE 0xFF8080FFUL
#define LCD_COLOR_ARGB8888_LIGHTGREEN 0xFF80FF80UL
#define LCD_COLOR_ARGB8888_LIGHTRED 0xFFFF8080UL
#define LCD_COLOR_ARGB8888_LIGHTCYAN 0xFF80FFFFUL
#define LCD_COLOR_ARGB8888_LIGHTMAGENTA 0xFFFF80FFUL
#define LCD_COLOR_ARGB8888_LIGHTYELLOW 0xFFFFFF80UL
#define LCD_COLOR_ARGB8888_DARKBLUE 0xFF000080UL
#define LCD_COLOR_ARGB8888_DARKGREEN 0xFF008000UL
#define LCD_COLOR_ARGB8888_DARKRED 0xFF800000UL
#define LCD_COLOR_ARGB8888_DARKCYAN 0xFF008080UL
#define LCD_COLOR_ARGB8888_DARKMAGENTA 0xFF800080UL
#define LCD_COLOR_ARGB8888_DARKYELLOW 0xFF808000UL
#define LCD_COLOR_ARGB8888_WHITE 0xFFFFFFFFUL
#define LCD_COLOR_ARGB8888_LIGHTGRAY 0xFFD3D3D3UL
#define LCD_COLOR_ARGB8888_GRAY 0xFF808080UL
#define LCD_COLOR_ARGB8888_DARKGRAY 0xFF404040UL
#define LCD_COLOR_ARGB8888_BLACK 0xFF000000UL
#define LCD_COLOR_ARGB8888_BROWN 0xFFA52A2AUL
#define LCD_COLOR_ARGB8888_ORANGE 0xFFFFA500UL
/* Definition of Official ST Colors */
#define LCD_COLOR_ARGB8888_ST_BLUE_DARK 0xFF002052UL
#define LCD_COLOR_ARGB8888_ST_BLUE 0xFF39A9DCUL
#define LCD_COLOR_ARGB8888_ST_BLUE_LIGHT 0xFFD1E4F3UL
#define LCD_COLOR_ARGB8888_ST_GREEN_LIGHT 0xFFBBCC01UL
#define LCD_COLOR_ARGB8888_ST_GREEN_DARK 0xFF003D14UL
#define LCD_COLOR_ARGB8888_ST_YELLOW 0xFFFFD300UL
#define LCD_COLOR_ARGB8888_ST_BROWN 0xFF5C0915UL
#define LCD_COLOR_ARGB8888_ST_PINK 0xFFD4007AUL
#define LCD_COLOR_ARGB8888_ST_PURPLE 0xFF590D58UL
#define LCD_COLOR_ARGB8888_ST_GRAY_DARK 0xFF4F5251UL
#define LCD_COLOR_ARGB8888_ST_GRAY 0xFF90989EUL
#define LCD_COLOR_ARGB8888_ST_GRAY_LIGHT 0xFFB9C4CAUL
/** @defgroup STM32H747I_DISCO_LCD_Exported_Variables Exported Variables
* @{
*/
extern const LCD_UTILS_Drv_t LCD_Driver;
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_LCD_Exported_Types Exported Types
* @{
*/
typedef uint32_t(*ConvertColor_Func)(uint32_t);
typedef struct
{
uint32_t XSize;
uint32_t YSize;
uint32_t ActiveLayer;
uint32_t PixelFormat;
uint32_t BppFactor;
uint32_t IsMspCallbacksValid;
uint32_t ReloadEnable;
} BSP_LCD_Ctx_t;
typedef struct
{
uint32_t X0;
uint32_t X1;
uint32_t Y0;
uint32_t Y1;
uint32_t PixelFormat;
uint32_t Address;
}MX_LTDC_LayerConfig_t;
#define BSP_LCD_LayerConfig_t MX_LTDC_LayerConfig_t
#if ((USE_HAL_LTDC_REGISTER_CALLBACKS == 1) || (USE_HAL_DSI_REGISTER_CALLBACKS == 1))
typedef struct
{
#if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
pLTDC_CallbackTypeDef pMspLtdcInitCb;
pLTDC_CallbackTypeDef pMspLtdcDeInitCb;
#endif /* (USE_HAL_LTDC_REGISTER_CALLBACKS == 1) */
#if (USE_HAL_DSI_REGISTER_CALLBACKS == 1)
pDSI_CallbackTypeDef pMspDsiInitCb;
pDSI_CallbackTypeDef pMspDsiDeInitCb;
#endif /* (USE_HAL_DSI_REGISTER_CALLBACKS == 1) */
}BSP_LCD_Cb_t;
#endif /*((USE_HAL_LTDC_REGISTER_CALLBACKS == 1) || (USE_HAL_DSI_REGISTER_CALLBACKS == 1)) */
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_LCD_Exported_Variables
* @{
*/
extern DSI_HandleTypeDef hlcd_dsi;
extern DMA2D_HandleTypeDef hlcd_dma2d;
extern LTDC_HandleTypeDef hlcd_ltdc;
extern BSP_LCD_Ctx_t Lcd_Ctx[];
extern void *Lcd_CompObj;
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_LCD_Exported_Functions
* @{
*/
/* Initialization APIs */
int32_t BSP_LCD_Init(uint32_t Instance, uint32_t Orientation);
int32_t BSP_LCD_InitEx(uint32_t Instance, uint32_t Orientation, uint32_t PixelFormat, uint32_t Width, uint32_t Height);
#if (USE_LCD_CTRL_ADV7533 > 0)
int32_t BSP_LCD_InitHDMI(uint32_t Instance, uint32_t Format);
#endif /* (USE_LCD_CTRL_ADV7533 > 0) */
int32_t BSP_LCD_DeInit(uint32_t Instance);
/* Register Callbacks APIs */
#if (USE_HAL_DSI_REGISTER_CALLBACKS == 1)
int32_t BSP_LCD_RegisterDefaultMspCallbacks (uint32_t Instance);
int32_t BSP_LCD_RegisterMspCallbacks (uint32_t Instance, BSP_LCD_Cb_t *CallBacks);
#endif /*(USE_HAL_DSI_REGISTER_CALLBACKS == 1) */
/* LCD specific APIs: Layer control & LCD HW reset */
int32_t BSP_LCD_Reload(uint32_t Instance, uint32_t ReloadType);
int32_t BSP_LCD_ConfigLayer(uint32_t Instance, uint32_t LayerIndex, BSP_LCD_LayerConfig_t *Config);
int32_t BSP_LCD_SetLayerVisible(uint32_t Instance, uint32_t LayerIndex, FunctionalState State);
int32_t BSP_LCD_SetTransparency(uint32_t Instance, uint32_t LayerIndex, uint8_t Transparency);
int32_t BSP_LCD_SetLayerAddress(uint32_t Instance, uint32_t LayerIndex, uint32_t Address);
int32_t BSP_LCD_SetLayerWindow(uint32_t Instance, uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
int32_t BSP_LCD_SetColorKeying(uint32_t Instance, uint32_t LayerIndex, uint32_t Color);
int32_t BSP_LCD_ResetColorKeying(uint32_t Instance, uint32_t LayerIndex);
void BSP_LCD_Reset(uint32_t Instance);
/* LCD generic APIs: Display control */
int32_t BSP_LCD_DisplayOn(uint32_t Instance);
int32_t BSP_LCD_DisplayOff(uint32_t Instance);
int32_t BSP_LCD_SetBrightness(uint32_t Instance, uint32_t Brightness);
int32_t BSP_LCD_GetBrightness(uint32_t Instance, uint32_t *Brightness);
int32_t BSP_LCD_GetXSize(uint32_t Instance, uint32_t *XSize);
int32_t BSP_LCD_GetYSize(uint32_t Instance, uint32_t *YSize);
/* LCD generic APIs: Draw operations. This list of APIs is required for
lcd gfx utilities */
int32_t BSP_LCD_SetActiveLayer(uint32_t Instance, uint32_t LayerIndex);
int32_t BSP_LCD_DrawBitmap(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint8_t *pBmp);
int32_t BSP_LCD_DrawHLine(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Length, uint32_t Color);
int32_t BSP_LCD_DrawVLine(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Length, uint32_t Color);
int32_t BSP_LCD_FillRect(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Width, uint32_t Height, uint32_t Color);
int32_t BSP_LCD_ReadPixel(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t *Color);
int32_t BSP_LCD_WritePixel(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Color);
/* LCD MX APIs */
HAL_StatusTypeDef MX_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, uint32_t LayerIndex, MX_LTDC_LayerConfig_t *Config);
HAL_StatusTypeDef MX_LTDC_ClockConfig(LTDC_HandleTypeDef *hltdc);
HAL_StatusTypeDef MX_LTDC_Init(LTDC_HandleTypeDef *hltdc, uint32_t Width, uint32_t Height);
HAL_StatusTypeDef MX_LTDC_ClockConfig2(LTDC_HandleTypeDef *hltdc);
HAL_StatusTypeDef MX_DSIHOST_DSI_Init(DSI_HandleTypeDef *hdsi, uint32_t Width, uint32_t Height, uint32_t PixelFormat);
int32_t BSP_LCD_FillRGBRect(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint8_t *pData, uint32_t Width, uint32_t Height);
int32_t BSP_LCD_GetPixelFormat(uint32_t Instance, uint32_t *PixelFormat);
/**
* @}
*/
/* Private constants --------------------------------------------------------*/
/** @defgroup STM32H747I_DISCO_LCD_Private_Constants Private Constants
* @{
*/
/* Legacy defines */
#define LCD_ORIENTATION_PORTRAIT 0x00U /* Portrait orientation choice of LCD screen */
#define BSP_LCD_Relaod BSP_LCD_Reload
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_LCD_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,246 @@
/**
******************************************************************************
* @file stm32h747i_discovery_qspi.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_qspi.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_QSPI_H
#define STM32H747I_DISCO_QSPI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#include "../Components/mt25tl01g/mt25tl01g.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_QSPI
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup STM32H747I_DISCO_QSPI_Exported_Types Exported Types
* @{
*/
#define BSP_QSPI_Info_t MT25TL01G_Info_t
#define BSP_QSPI_Interface_t MT25TL01G_Interface_t
#define BSP_QSPI_Transfer_t MT25TL01G_Transfer_t
#define BSP_QSPI_DualFlash_t MT25TL01G_DualFlash_t
#define BSP_QSPI_ODS_t MT25TL01G_ODS_t
typedef enum
{
BSP_QSPI_ERASE_8K = MT25TL01G_ERASE_4K , /*!< 8K size Sector erase = 2 x 4K as Dual flash mode is used for this board */
BSP_QSPI_ERASE_64K = MT25TL01G_ERASE_32K , /*!< 64K size Sector erase = 2 x 32K as Dual flash mode is used for this board */
BSP_QSPI_ERASE_128K = MT25TL01G_ERASE_64K , /*!< 128K size Sector erase = 2 x 64K as Dual mode is used for this board */
BSP_QSPI_ERASE_CHIP = MT25TL01G_ERASE_CHIP /*!< Whole chip erase */
} BSP_QSPI_Erase_t;
typedef enum
{
QSPI_ACCESS_NONE = 0, /*!< Instance not initialized, */
QSPI_ACCESS_INDIRECT, /*!< Instance use indirect mode access */
QSPI_ACCESS_MMP /*!< Instance use Memory Mapped Mode read */
} BSP_QSPI_Access_t;
typedef struct
{
BSP_QSPI_Access_t IsInitialized; /*!< Instance access Flash method */
BSP_QSPI_Interface_t InterfaceMode; /*!< Flash Interface mode of Instance */
BSP_QSPI_Transfer_t TransferRate; /*!< Flash Transfer mode of Instance */
uint32_t DualFlashMode; /*!< Flash dual mode */
uint32_t IsMspCallbacksValid;
} BSP_QSPI_Ctx_t;
typedef struct
{
BSP_QSPI_Interface_t InterfaceMode; /*!< Current Flash Interface mode */
BSP_QSPI_Transfer_t TransferRate; /*!< Current Flash Transfer mode */
BSP_QSPI_DualFlash_t DualFlashMode; /*!< Dual Flash mode */
} BSP_QSPI_Init_t;
typedef struct
{
uint32_t FlashSize;
uint32_t ClockPrescaler;
uint32_t SampleShifting;
uint32_t DualFlashMode;
}MX_QSPI_Init_t;
#if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
typedef struct
{
void(*pMspInitCb)(pQSPI_CallbackTypeDef);
void(*pMspDeInitCb)(pQSPI_CallbackTypeDef);
}BSP_QSPI_Cb_t;
#endif /* (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup STM32H747I_DISCO_QSPI_Exported_Constants Exported Constants
* @{
*/
/* QSPI instances number */
#define QSPI_INSTANCES_NUMBER 1U
/* Definition for QSPI modes */
#define BSP_QSPI_SPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_MODE /* 1 Cmd Line, 1 Address Line and 1 Data Line */
#define BSP_QSPI_SPI_1I2O_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_1I2O_MODE /* 1 Cmd Line, 1 Address Line and 2 Data Lines */
#define BSP_QSPI_SPI_2IO_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_2IO_MODE /* 1 Cmd Line, 2 Address Lines and 2 Data Lines */
#define BSP_QSPI_SPI_1I4O_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_1I4O_MODE /* 1 Cmd Line, 1 Address Line and 4 Data Lines */
#define BSP_QSPI_SPI_4IO_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_4IO_MODE /* 1 Cmd Line, 4 Address Lines and 4 Data Lines */
#define BSP_QSPI_DPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_DPI_MODE /* 2 Cmd Lines, 2 Address Lines and 2 Data Lines */
#define BSP_QSPI_QPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_QPI_MODE /* 4 Cmd Lines, 4 Address Lines and 4 Data Lines */
/* Definition for QSPI transfer rates */
#define BSP_QSPI_STR_TRANSFER (BSP_QSPI_Transfer_t)MT25TL01G_STR_TRANSFER /* Single Transfer Rate */
#define BSP_QSPI_DTR_TRANSFER (BSP_QSPI_Transfer_t)MT25TL01G_DTR_TRANSFER /* Double Transfer Rate */
/* Definition for QSPI dual flash mode */
#define BSP_QSPI_DUALFLASH_DISABLE (BSP_QSPI_DualFlash_t)MT25TL01G_DUALFLASH_DISABLE /* Dual flash mode enabled */
/* Definition for QSPI Flash ID */
#define BSP_QSPI_FLASH_ID QSPI_FLASH_ID_1
/* QSPI block sizes for dual flash */
#define BSP_QSPI_BLOCK_8K MT25TL01G_SECTOR_4K
#define BSP_QSPI_BLOCK_64K MT25TL01G_BLOCK_32K
#define BSP_QSPI_BLOCK_128K MT25TL01G_BLOCK_64K
/* Definition for QSPI clock resources */
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define QSPI_BK1_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK2_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_BK2_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define QSPI_BK2_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define QSPI_BK2_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_BK2_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
/* Definition for QSPI Pins */
#define QSPI_CLK_PIN GPIO_PIN_2
#define QSPI_CLK_GPIO_PORT GPIOB
/* Bank 1 */
#define QSPI_BK1_CS_PIN GPIO_PIN_6
#define QSPI_BK1_CS_GPIO_PORT GPIOG
#define QSPI_BK1_D0_PIN GPIO_PIN_11
#define QSPI_BK1_D0_GPIO_PORT GPIOD
#define QSPI_BK1_D1_PIN GPIO_PIN_9
#define QSPI_BK1_D1_GPIO_PORT GPIOF
#define QSPI_BK1_D2_PIN GPIO_PIN_7
#define QSPI_BK1_D2_GPIO_PORT GPIOF
#define QSPI_BK1_D3_PIN GPIO_PIN_6
#define QSPI_BK1_D3_GPIO_PORT GPIOF
/* Bank 2 */
#define QSPI_BK2_CS_PIN GPIO_PIN_6
#define QSPI_BK2_CS_GPIO_PORT GPIOG
#define QSPI_BK2_D0_PIN GPIO_PIN_2
#define QSPI_BK2_D0_GPIO_PORT GPIOH
#define QSPI_BK2_D1_PIN GPIO_PIN_3
#define QSPI_BK2_D1_GPIO_PORT GPIOH
#define QSPI_BK2_D2_PIN GPIO_PIN_9
#define QSPI_BK2_D2_GPIO_PORT GPIOG
#define QSPI_BK2_D3_PIN GPIO_PIN_14
#define QSPI_BK2_D3_GPIO_PORT GPIOG
/* MT25TL01G Micron memory */
/* Size of the flash */
#define QSPI_FLASH_SIZE 26 /* Address bus width to access whole memory space */
#define QSPI_PAGE_SIZE 256
/* QSPI Base Address */
#define QSPI_BASE_ADDRESS 0x90000000
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_QSPI_Exported_Variables
* @{
*/
extern QSPI_HandleTypeDef hqspi;
extern BSP_QSPI_Ctx_t QSPI_Ctx[];
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup STM32H747I_DISCO_QSPI_Exported_Functions
* @{
*/
int32_t BSP_QSPI_Init(uint32_t Instance, BSP_QSPI_Init_t *Init);
int32_t BSP_QSPI_DeInit(uint32_t Instance);
#if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
int32_t BSP_QSPI_RegisterMspCallbacks (uint32_t Instance, BSP_QSPI_Cb_t *CallBacks);
int32_t BSP_QSPI_RegisterDefaultMspCallbacks (uint32_t Instance);
#endif /* (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) */
int32_t BSP_QSPI_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
int32_t BSP_QSPI_Write(uint32_t Instance, uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
int32_t BSP_QSPI_EraseBlock(uint32_t Instance, uint32_t BlockAddress, BSP_QSPI_Erase_t BlockSize);
int32_t BSP_QSPI_EraseChip(uint32_t Instance);
int32_t BSP_QSPI_GetStatus(uint32_t Instance);
int32_t BSP_QSPI_GetInfo(uint32_t Instance, BSP_QSPI_Info_t *pInfo);
int32_t BSP_QSPI_EnableMemoryMappedMode(uint32_t Instance);
int32_t BSP_QSPI_DisableMemoryMappedMode(uint32_t Instance);
int32_t BSP_QSPI_ReadID(uint32_t Instance, uint8_t *Id);
int32_t BSP_QSPI_ConfigFlash(uint32_t Instance, BSP_QSPI_Interface_t Mode, BSP_QSPI_Transfer_t Rate);
/* These functions can be modified in case the current settings
need to be changed for specific application needs */
HAL_StatusTypeDef MX_QSPI_Init(QSPI_HandleTypeDef *hQspi, MX_QSPI_Init_t *Config);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /*STM32H747I_DISCO_QSPI_H */
@@ -0,0 +1,972 @@
/**
******************************************************************************
* @file stm32h747i_discovery_sd.c
* @author MCD Application Team
* @brief This file includes the uSD card driver mounted on STM32H747I_DISCO
* boards.
@verbatim
How To use this driver:
-----------------------
- This driver is used to drive the micro SD external cards mounted on STM32H747I_DISCO
board.
- This driver does not need a specific component driver for the micro SD device
to be included with.
Driver description:
------------------
+ Initialization steps:
o Initialize the micro SD card using the BSP_SD_Init() function. This
function includes the MSP layer hardware resources initialization and the
SDIO interface configuration to interface with the external micro SD. It
also includes the micro SD initialization sequence.
o To check the SD card presence you can use the function BSP_SD_IsDetected() which
returns the detection status.
o If SD presence detection interrupt mode is desired, you must configure the
SD detection interrupt mode by calling the function BSP_SD_DetectITConfig().
The interrupt is generated as an external interrupt whenever the micro SD card is
plugged/unplugged in/from the evaluation board.
The SD detection is managed by MFX, so the SD detection interrupt has to be
treated by MFX_IRQOUT gpio pin IRQ handler. BSP_SD_DetectCallback() is called when
SD is detected.
o The function BSP_SD_GetCardInfo()are used to get the micro SD card information
which is stored in the structure "HAL_SD_CardInfoTypedef".
+ Micro SD card operations
o The micro SD card can be accessed with read/write block(s) operations once
it is ready for access. The access can be performed whether
using the polling mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(),
using the interrupt mode by calling the functions BSP_SD_ReadBlocks_IT()/BSP_SD_WriteBlocks_IT(),
or by DMA transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA().
o The DMA transfer complete is used with interrupt mode. Once the SD transfer
is complete, the SD interrupt is handled using the function BSP_SDMMC1_IRQHandler()
The DMA Tx/Rx transfer complete are handled using the functions
SD_SDMMC1_DMA_Tx_IRQHandler(), SD_SDMMC1_DMA_Rx_IRQHandler().The corresponding
user callbacks are implemented by the user at application level.
o The SD erase block(s) is performed using the functions BSP_SD_Erase() with specifying
the number of blocks to erase.
o The SD runtime status is returned when calling the function BSP_SD_GetCardState().
@endverbatim
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 "stm32h747i_discovery_sd.h"
#include "stm32h747i_discovery_bus.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_SD SD
* @{
*/
/** @defgroup STM32H747I_DISCO_SD_Private_TypesDefinitions Private TypesDefinitions
* @{
*/
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/* Is Msp Callbacks registered */
static uint32_t IsMspCallbacksValid[SD_INSTANCES_NBR] = {0};
#endif
typedef void (* BSP_EXTI_LineCallback) (void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Exported_Variables Exported Variables
* @{
*/
SD_HandleTypeDef hsd_sdmmc[SD_INSTANCES_NBR];
EXTI_HandleTypeDef hsd_exti[SD_INSTANCES_NBR];
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Private_Variables Private Variables
* @{
*/
static uint32_t PinDetect[SD_INSTANCES_NBR] = {SD_DETECT_PIN};
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/* Is Msp Callbacks registered */
static uint32_t IsMspCallbacksValid[SD_INSTANCES_NBR] = {0};
#endif
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Private_Functions_Prototypes Private Functions Prototypes
* @{
*/
static void SD_MspInit(SD_HandleTypeDef *hsd);
static void SD_MspDeInit(SD_HandleTypeDef *hsd);
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
static void SD_AbortCallback(SD_HandleTypeDef *hsd);
static void SD_TxCpltCallback(SD_HandleTypeDef *hsd);
static void SD_RxCpltCallback(SD_HandleTypeDef *hsd);
#if (USE_SD_TRANSCEIVER > 0U)
static void SD_DriveTransceiver_1_8V_Callback(FlagStatus status);
#endif
#endif /* (USE_HAL_SD_REGISTER_CALLBACKS == 1) */
static void SD_EXTI_Callback(void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Exported_Functions Exported Functions
* @{
*/
/**
* @brief Initializes the SD card device.
* @param Instance SD Instance
* @retval BSP status
*/
int32_t BSP_SD_Init(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Configure Input mode for SD detection pin */
SD_DETECT_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = SD_DETECT_PIN;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Mode = GPIO_MODE_INPUT;
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
if(BSP_SD_IsDetected(Instance) != SD_PRESENT)
{
ret = BSP_ERROR_UNKNOWN_COMPONENT;
}
else
{
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/* Register the SD MSP Callbacks */
if(IsMspCallbacksValid[Instance] == 0UL)
{
if(BSP_SD_RegisterDefaultMspCallbacks(Instance) != BSP_ERROR_NONE)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
#else
/* Msp SD initialization */
SD_MspInit(&hsd_sdmmc[Instance]);
#endif /* USE_HAL_SD_REGISTER_CALLBACKS */
if(ret == BSP_ERROR_NONE)
{
/* HAL SD initialization and Enable wide operation */
if(MX_SDMMC1_SD_Init(&hsd_sdmmc[Instance]) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
#if (USE_SD_BUS_WIDE_4B > 0)
else if(HAL_SD_ConfigWideBusOperation(&hsd_sdmmc[Instance], SDMMC_BUS_WIDE_4B) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
#endif
else
{
/* Switch to High Speed mode if the card support this mode */
(void)HAL_SD_ConfigSpeedBusOperation(&hsd_sdmmc[Instance], SDMMC_SPEED_MODE_HIGH);
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/* Register SD TC, HT and Abort callbacks */
if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_TX_CPLT_CB_ID, SD_TxCpltCallback) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_RX_CPLT_CB_ID, SD_RxCpltCallback) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_ABORT_CB_ID, SD_AbortCallback) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
#if (USE_SD_TRANSCEIVER != 0U)
if(HAL_SD_RegisterTransceiverCallback(&hsd_sdmmc[Instance], SD_DriveTransceiver_1_8V_Callback) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
#endif
}
#endif /* USE_HAL_SD_REGISTER_CALLBACKS */
}
}
}
}
return ret;
}
/**
* @brief DeInitializes the SD card device.
* @param Instance SD Instance
* @retval SD status
*/
int32_t BSP_SD_DeInit(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_DeInit(&hsd_sdmmc[Instance]) != HAL_OK)/* HAL SD de-initialization */
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
/* SD detection pin configuration */
gpio_init_structure.Pin = SD_DETECT_PIN;
HAL_GPIO_DeInit(SD_DETECT_GPIO_PORT, gpio_init_structure.Pin);
/* Msp SD de-initialization */
#if (USE_HAL_SD_REGISTER_CALLBACKS == 0)
SD_MspDeInit(&hsd_sdmmc[Instance]);
#endif /* (USE_HAL_SD_REGISTER_CALLBACKS == 0) */
}
}
return ret;
}
/**
* @brief Initializes the SDMMC1 peripheral.
* @param hsd SD handle
* @retval HAL status
*/
__weak HAL_StatusTypeDef MX_SDMMC1_SD_Init(SD_HandleTypeDef *hsd)
{
HAL_StatusTypeDef ret = HAL_OK;
/* uSD device interface configuration */
hsd->Instance = SDMMC1;
hsd->Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
hsd->Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
#if (USE_SD_BUS_WIDE_4B > 0)
hsd->Init.BusWide = SDMMC_BUS_WIDE_4B;
#else
hsd->Init.BusWide = SDMMC_BUS_WIDE_1B;
#endif
hsd->Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
#if (USE_SD_TRANSCEIVER >0)
hsd->Init.TranceiverPresent = SDMMC_TRANSCEIVER_PRESENT;
#endif /*USE_SD_TRANSCEIVER*/
#if ( USE_SD_HIGH_PERFORMANCE > 0 )
hsd->Init.ClockDiv = SDMMC_HSpeed_CLK_DIV;
#else
hsd->Init.ClockDiv = SDMMC_NSpeed_CLK_DIV;
#endif /*USE_SD_HIGH_PERFORMANCE*/
/* HAL SD initialization */
if(HAL_SD_Init(hsd) != HAL_OK)
{
ret = HAL_ERROR;
}
return ret;
}
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/**
* @brief Default BSP SD Msp Callbacks
* @param Instance SD Instance
* @retval BSP status
*/
int32_t BSP_SD_RegisterDefaultMspCallbacks(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Register MspInit/MspDeInit Callbacks */
if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_MSP_INIT_CB_ID, SD_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_MSP_DEINIT_CB_ID, SD_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsMspCallbacksValid[Instance] = 1U;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief BSP SD Msp Callback registering
* @param Instance SD Instance
* @param CallBacks pointer to MspInit/MspDeInit callbacks functions
* @retval BSP status
*/
int32_t BSP_SD_RegisterMspCallbacks(uint32_t Instance, BSP_SD_Cb_t *CallBacks)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Register MspInit/MspDeInit Callbacks */
if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_MSP_INIT_CB_ID, CallBacks->pMspInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if(HAL_SD_RegisterCallback(&hsd_sdmmc[Instance], HAL_SD_MSP_DEINIT_CB_ID, CallBacks->pMspDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsMspCallbacksValid[Instance] = 1U;
}
}
/* Return BSP status */
return ret;
}
#endif /* (USE_HAL_SD_REGISTER_CALLBACKS == 1) */
/**
* @brief Configures Interrupt mode for SD detection pin.
* @param Instance SD Instance
* @retval BSP status
*/
int32_t BSP_SD_DetectITConfig(uint32_t Instance)
{
int32_t ret;
GPIO_InitTypeDef gpio_init_structure;
const uint32_t SD_EXTI_LINE[SD_INSTANCES_NBR] = {SD_DETECT_EXTI_LINE};
static BSP_EXTI_LineCallback SdCallback[SD_INSTANCES_NBR] = {SD_EXTI_Callback};
if(Instance> SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
gpio_init_structure.Pin = PinDetect[Instance];
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Mode = GPIO_MODE_IT_RISING_FALLING;
HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_init_structure);
/* Enable and set SD detect EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((IRQn_Type)(SD_DETECT_EXTI_IRQn), 0x0F, 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(SD_DETECT_EXTI_IRQn));
HAL_EXTI_GetHandle(&hsd_exti[Instance], SD_EXTI_LINE[Instance]);
if(HAL_EXTI_RegisterCallback(&hsd_exti[Instance], HAL_EXTI_COMMON_CB_ID, SdCallback[Instance]) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief BSP SD Callback.
* @param Instance SD Instance
* @param Status Pin status
* @retval None.
*/
__weak void BSP_SD_DetectCallback(uint32_t Instance, uint32_t Status)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
UNUSED(Status);
/* This function should be implemented by the user application.
It is called into this driver when an event on JoyPin is triggered. */
}
/**
* @brief Detects if SD card is correctly plugged in the memory slot or not.
* @param Instance SD Instance
* @retval Returns if SD is detected or not
*/
int32_t BSP_SD_IsDetected(uint32_t Instance)
{
int32_t ret = BSP_ERROR_UNKNOWN_FAILURE;
if(Instance >= SD_INSTANCES_NBR)
{
return BSP_ERROR_WRONG_PARAM;
}
else
{
ret = (uint32_t)HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT,GPIO_PIN_8 );/*PinDetect[Instance]*/
/* Check SD card detect pin */
if(ret != GPIO_PIN_RESET)
{
ret = (int32_t)SD_NOT_PRESENT;
}
else
{
ret = (int32_t)SD_PRESENT;
}
}
return ret;
}
/**
* @brief Reads block(s) from a specified address in an SD card, in polling mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be read
* @param BlocksNbr Number of SD blocks to read
* @retval BSP status
*/
int32_t BSP_SD_ReadBlocks(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t timeout = SD_READ_TIMEOUT*BlocksNbr;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_ReadBlocks(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr, timeout) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Writes block(s) to a specified address in an SD card, in polling mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be written
* @param BlocksNbr Number of SD blocks to write
* @retval BSP status
*/
int32_t BSP_SD_WriteBlocks(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t timeout = SD_READ_TIMEOUT*BlocksNbr;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_WriteBlocks(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr, timeout) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Reads block(s) from a specified address in an SD card, in DMA mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be read
* @param BlocksNbr Number of SD blocks to read
* @retval BSP status
*/
int32_t BSP_SD_ReadBlocks_DMA(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_ReadBlocks_DMA(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be written
* @param BlocksNbr Number of SD blocks to write
* @retval BSP status
*/
int32_t BSP_SD_WriteBlocks_DMA(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_WriteBlocks_DMA(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Reads block(s) from a specified address in an SD card, in DMA mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be read
* @param BlocksNbr Number of SD blocks to read
* @retval SD status
*/
int32_t BSP_SD_ReadBlocks_IT(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_ReadBlocks_IT(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
* @param Instance SD Instance
* @param pData Pointer to the buffer that will contain the data to transmit
* @param BlockIdx Block index from where data is to be written
* @param BlocksNbr Number of SD blocks to write
* @retval SD status
*/
int32_t BSP_SD_WriteBlocks_IT(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_WriteBlocks_IT(&hsd_sdmmc[Instance], (uint8_t *)pData, BlockIdx, BlocksNbr) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Erases the specified memory area of the given SD card.
* @param Instance SD Instance
* @param BlockIdx Block index from where data is to be
* @param BlocksNbr Number of SD blocks to erase
* @retval SD status
*/
int32_t BSP_SD_Erase(uint32_t Instance, uint32_t BlockIdx, uint32_t BlocksNbr)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_Erase(&hsd_sdmmc[Instance], BlockIdx, BlockIdx + BlocksNbr) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief Gets the current SD card data status.
* @param Instance SD Instance
* @retval Data transfer state.
* This value can be one of the following values:
* @arg SD_TRANSFER_OK: No data transfer is acting
* @arg SD_TRANSFER_BUSY: Data transfer is acting
*/
int32_t BSP_SD_GetCardState(uint32_t Instance)
{
return (int32_t)((HAL_SD_GetCardState(&hsd_sdmmc[Instance]) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY);
}
/**
* @brief Get SD information about specific SD card.
* @param Instance SD Instance
* @param CardInfo Pointer to HAL_SD_CardInfoTypedef structure
* @retval BSP status
*/
int32_t BSP_SD_GetCardInfo(uint32_t Instance, BSP_SD_CardInfo *CardInfo)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >= SD_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(HAL_SD_GetCardInfo(&hsd_sdmmc[Instance], CardInfo) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
/* Return BSP status */
return ret;
}
#if !defined (USE_HAL_SD_REGISTER_CALLBACKS) || (USE_HAL_SD_REGISTER_CALLBACKS == 0)
/**
* @brief SD Abort callbacks
* @param hsd SD handle
* @retval None
*/
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_AbortCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
/**
* @brief Tx Transfer completed callbacks
* @param hsd SD handle
* @retval None
*/
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_WriteCpltCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
/**
* @brief Rx Transfer completed callbacks
* @param hsd SD handle
* @retval None
*/
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_ReadCpltCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
#if (USE_SD_TRANSCEIVER != 0U)
/**
* @brief Enable the SD Transceiver 1.8V Mode Callback.
*/
void HAL_SD_DriveTransciver_1_8V_Callback(FlagStatus status)
{
#if (USE_BSP_IO_CLASS > 0U)
if(status == SET)
{
BSP_IO_WritePin(0, SD_LDO_SEL_PIN, IO_PIN_SET);
}
else
{
BSP_IO_WritePin(0, SD_LDO_SEL_PIN, IO_PIN_RESET);
}
#endif
}
#endif
#endif /* !defined (USE_HAL_SD_REGISTER_CALLBACKS) || (USE_HAL_SD_REGISTER_CALLBACKS == 0) */
/**
* @brief This function handles pin detection interrupt request.
* @param Instance SD Instance
* @retval None
*/
void BSP_SD_DETECT_IRQHandler(uint32_t Instance)
{
HAL_EXTI_IRQHandler(&hsd_exti[Instance]);
}
/**
* @brief This function handles SDMMC interrupt requests.
* @param Instance SD Instance
* @retval None
*/
void BSP_SD_IRQHandler(uint32_t Instance)
{
HAL_SD_IRQHandler(&hsd_sdmmc[Instance]);
}
/**
* @brief BSP SD Abort callbacks
* @param Instance SD Instance
* @retval None
*/
__weak void BSP_SD_AbortCallback(uint32_t Instance)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
}
/**
* @brief BSP Tx Transfer completed callbacks
* @param Instance SD Instance
* @retval None
*/
__weak void BSP_SD_WriteCpltCallback(uint32_t Instance)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
}
/**
* @brief BSP Rx Transfer completed callbacks
* @param Instance SD Instance
* @retval None
*/
__weak void BSP_SD_ReadCpltCallback(uint32_t Instance)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
}
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Private_Functions Private Functions
* @{
*/
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
/**
* @brief SD Abort callbacks
* @param hsd SD handle
* @retval None
*/
static void SD_AbortCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_AbortCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
/**
* @brief Tx Transfer completed callbacks
* @param hsd SD handle
* @retval None
*/
static void SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_WriteCpltCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
/**
* @brief Rx Transfer completed callbacks
* @param hsd SD handle
* @retval None
*/
static void SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
BSP_SD_ReadCpltCallback((hsd == &hsd_sdmmc[0]) ? 0UL : 1UL);
}
#endif
/**
* @brief SD EXTI line detection callbacks.
* @retval None
*/
static void SD_EXTI_Callback(void)
{
uint32_t sd_status = SD_PRESENT;
BSP_SD_DetectCallback(0,sd_status);
}
/**
* @brief Initializes the SD MSP.
* @param hsd SD handle
* @retval None
*/
static void SD_MspInit(SD_HandleTypeDef *hsd)
{
GPIO_InitTypeDef gpio_init_structure;
if(hsd == &hsd_sdmmc[0])
{
#if (USE_SD_BUS_WIDE_4B > 0)
/* SD pins are in conflict with Camera pins on the Disco board
therefore Camera must be power down before using the BSP SD
To power down the camera , Set GPIOJ pin 14 to high
*/
/* Enable GPIO J clock */
__HAL_RCC_GPIOJ_CLK_ENABLE();
gpio_init_structure.Pin = GPIO_PIN_14;
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
/* Set the camera POWER_DOWN pin (active high) */
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_14, GPIO_PIN_SET);
#endif
/* Enable SDIO clock */
__HAL_RCC_SDMMC1_CLK_ENABLE();
/* Enable GPIOs clock */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/* Common GPIO configuration */
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_init_structure.Alternate = GPIO_AF12_SDIO1;
#if (USE_SD_BUS_WIDE_4B > 0)
/* SDMMC GPIO CLKIN PB8, D0 PC8, D1 PC9, D2 PC10, D3 PC11, CK PC12, CMD PD2 */
/* GPIOC configuration */
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
#else
/* SDMMC GPIO CLKIN PB8, D0 PC8, CK PC12, CMD PD2 */
/* GPIOC configuration */
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_12;
#endif
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
/* GPIOD configuration */
gpio_init_structure.Pin = GPIO_PIN_2;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
/* NVIC configuration for SDIO interrupts */
HAL_NVIC_SetPriority(SDMMC1_IRQn, BSP_SD_IT_PRIORITY, 0);
HAL_NVIC_EnableIRQ(SDMMC1_IRQn);
}
}
/**
* @brief DeInitializes the SD MSP.
* @param hsd SD handle
* @retval None
*/
static void SD_MspDeInit(SD_HandleTypeDef *hsd)
{
GPIO_InitTypeDef gpio_init_structure;
if(hsd == &hsd_sdmmc[0])
{
HAL_NVIC_DisableIRQ(SDMMC1_IRQn);
/* DeInit GPIO pins can be done in the application
(by surcharging this __weak function) */
/* Disable SDMMC1 clock */
__HAL_RCC_SDMMC1_CLK_DISABLE();
#if (USE_SD_BUS_WIDE_4B > 0)
/* GPIOJ configuration */
gpio_init_structure.Pin = GPIO_PIN_14;
HAL_GPIO_DeInit(GPIOJ, gpio_init_structure.Pin);
/* GPIOC configuration */
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
#else
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_12;
#endif
HAL_GPIO_DeInit(GPIOC, gpio_init_structure.Pin);
/* GPIOD configuration */
gpio_init_structure.Pin = GPIO_PIN_2;
HAL_GPIO_DeInit(GPIOD, gpio_init_structure.Pin);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,178 @@
/**
******************************************************************************
* @file stm32h747i_discovery_sd.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_sd.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_SD_H
#define STM32H747I_DISCO_SD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_SD
* @{
*/
/** @defgroup STM32H747I_DISCO_SD_Exported_Types Exported Types
* @{
*/
/**
* @brief SD Card information structure
*/
#define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(SD_HandleTypeDef *);
void (* pMspDeInitCb)(SD_HandleTypeDef *);
}BSP_SD_Cb_t;
#endif /* (USE_HAL_SD_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SD_Exported_Constants Exported Constants
* @{
*/
#define SD_INSTANCES_NBR 1UL
#ifndef SD_WRITE_TIMEOUT
#define SD_WRITE_TIMEOUT 500U
#endif
#ifndef SD_READ_TIMEOUT
#define SD_READ_TIMEOUT 100U
#endif
/**
* @brief SD interface bus width selection
* 4-bit wide data bus can be disabled to avoid conflict with
* camera pins (PC9 and PC11) on the Disco board.
* 1-bit (SDMMC_D0) databus width will be used instead.
*/
#ifndef USE_SD_BUS_WIDE_4B
#define USE_SD_BUS_WIDE_4B 1U
#endif
/**
* @brief SD transfer state definition
*/
#define SD_TRANSFER_OK 0U
#define SD_TRANSFER_BUSY 1U
/**
* @brief SD-detect signal
*/
#define SD_PRESENT 1UL
#define SD_NOT_PRESENT 0UL
/**
* @brief SD-detect signal
*/
#define SD_DETECT_PIN GPIO_PIN_8
#define SD_DETECT_GPIO_PORT GPIOI
#define SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
#define SD_DETECT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
#define SD_DETECT_EXTI_IRQn EXTI9_5_IRQn
#define SD_DETECT_EXTI_LINE EXTI_LINE_8
#define SD_DetectIRQHandler() HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8)
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_SD_Exported_Variables
* @{
*/
extern SD_HandleTypeDef hsd_sdmmc[];
extern EXTI_HandleTypeDef hsd_exti[];
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_SD_Exported_Functions
* @{
*/
int32_t BSP_SD_Init(uint32_t Instance);
int32_t BSP_SD_DeInit(uint32_t Instance);
#if (USE_HAL_SD_REGISTER_CALLBACKS == 1)
int32_t BSP_SD_RegisterMspCallbacks(uint32_t Instance, BSP_SD_Cb_t *CallBacks);
int32_t BSP_SD_RegisterDefaultMspCallbacks(uint32_t Instance);
#endif /* (USE_HAL_SD_REGISTER_CALLBACKS == 1) */
int32_t BSP_SD_DetectITConfig(uint32_t Instance);
int32_t BSP_SD_ReadBlocks(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t BlocksNbr);
int32_t BSP_SD_WriteBlocks(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t NbrOfBlocks);
int32_t BSP_SD_ReadBlocks_DMA(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t NbrOfBlocks);
int32_t BSP_SD_WriteBlocks_DMA(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t NbrOfBlocks);
int32_t BSP_SD_ReadBlocks_IT(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t NbrOfBlocks);
int32_t BSP_SD_WriteBlocks_IT(uint32_t Instance, uint32_t *pData, uint32_t BlockIdx, uint32_t NbrOfBlocks);
int32_t BSP_SD_Erase(uint32_t Instance, uint32_t BlockIdx, uint32_t BlocksNbr);
int32_t BSP_SD_GetCardState(uint32_t Instance);
int32_t BSP_SD_GetCardInfo(uint32_t Instance, BSP_SD_CardInfo *CardInfo);
int32_t BSP_SD_IsDetected(uint32_t Instance);
void BSP_SD_DETECT_IRQHandler(uint32_t Instance);
void BSP_SD_IRQHandler(uint32_t Instance);
/* These functions can be modified in case the current settings (e.g. DMA stream or IT)
need to be changed for specific application needs */
void BSP_SD_AbortCallback(uint32_t Instance);
void BSP_SD_WriteCpltCallback(uint32_t Instance);
void BSP_SD_ReadCpltCallback(uint32_t Instance);
void BSP_SD_DetectCallback(uint32_t Instance, uint32_t Status);
void HAL_SD_DriveTransciver_1_8V_Callback(FlagStatus status);
HAL_StatusTypeDef MX_SDMMC1_SD_Init(SD_HandleTypeDef *hsd);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_SD_H */
@@ -0,0 +1,485 @@
/**
******************************************************************************
* @file stm32h747i_discovery_sdram.c
* @author MCD Application Team
* @brief This file includes the SDRAM driver for the IS42S32800J-6BLI memory
* device mounted on STM32H747I-DISCO boards.
How To use this driver:
-----------------------
- This driver is used to drive the IS42S32800J-6BLI SDRAM external memory mounted
on STM32H747I_DISCO board.
- This driver does not need a specific component driver for the SDRAM device
to be included with.
Driver description:
------------------
+ Initialization steps:
o Initialize the SDRAM external memory using the BSP_SDRAM_Init() function. This
function includes the MSP layer hardware resources initialization and the
FMC controller configuration to interface with the external SDRAM memory.
o It contains the SDRAM initialization sequence to program the SDRAM external
device using the function BSP_SDRAM_Initialization_sequence(). Note that this
sequence is standard for all SDRAM devices, but can include some differences
from a device to another. If it is the case, the right sequence should be
implemented separately.
+ SDRAM read/write operations
o SDRAM external memory can be accessed with read/write operations once it is
initialized.
Read/write operation can be performed with AHB access using the functions
BSP_SDRAM_ReadData()/BSP_SDRAM_WriteData(), or by DMA transfer using the functions
BSP_SDRAM_ReadData_DMA()/BSP_SDRAM_WriteData_DMA().
o The AHB access is performed with 32-bit width transaction, the DMA transfer
configuration is fixed at single (no burst) word transfer (see the
SDRAM_MspInit() static function).
o User can implement his own functions for read/write access with his desired
configurations.
o If interrupt mode is used for DMA transfer, the function BSP_SDRAM_DMA_IRQHandler()
is called in IRQ handler file, to serve the generated interrupt once the DMA
transfer is complete.
o You can send a command to the SDRAM device in runtime using the function
BSP_SDRAM_Sendcmd(), and giving the desired command as parameter chosen between
the predefined commands of the "FMC_SDRAM_CommandTypeDef" structure.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 "stm32h747i_discovery_sdram.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_SDRAM
* @{
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Exported_Variables Exported Variables
* @{
*/
SDRAM_HandleTypeDef hsdram[SDRAM_INSTANCES_NBR];
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Private_Variables Private Variables
* @{
*/
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
static uint32_t IsMspCallbacksValid = 0;
#endif
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Private_Functions_Prototypes Private Functions Prototypes
* @{
*/
static void SDRAM_MspDeInit(SDRAM_HandleTypeDef *hSdram);
static void SDRAM_MspInit(SDRAM_HandleTypeDef *hSdram);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Exported_Functions Exported Functions
* @{
*/
/**
* @brief Initializes the SDRAM device.
* @param Instance SDRAM Instance
* @retval BSP status
*/
int32_t BSP_SDRAM_Init(uint32_t Instance)
{
int32_t ret;
static IS42S32800J_Context_t pRegMode;
if(Instance >=SDRAM_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
/* Register the SDRAM MSP Callbacks */
if(IsMspCallbacksValid == 0)
{
if(BSP_SDRAM_RegisterDefaultMspCallbacks(Instance) != BSP_ERROR_NONE)
{
return BSP_ERROR_PERIPH_FAILURE;
}
}
#else
/* Msp SDRAM initialization */
SDRAM_MspInit(&hsdram[0]);
#endif /* USE_HAL_SDRAM_REGISTER_CALLBACKS */
if(MX_SDRAM_Init(&hsdram[0]) != HAL_OK)
{
ret = BSP_ERROR_NO_INIT;
}
else
{
/* External memory mode register configuration */
pRegMode.TargetBank = FMC_SDRAM_CMD_TARGET_BANK2;
pRegMode.RefreshMode = IS42S32800J_AUTOREFRESH_MODE_CMD;
pRegMode.RefreshRate = REFRESH_COUNT;
pRegMode.BurstLength = IS42S32800J_BURST_LENGTH_1;
pRegMode.BurstType = IS42S32800J_BURST_TYPE_SEQUENTIAL;
pRegMode.CASLatency = IS42S32800J_CAS_LATENCY_3;
pRegMode.OperationMode = IS42S32800J_OPERATING_MODE_STANDARD;
pRegMode.WriteBurstMode = IS42S32800J_WRITEBURST_MODE_SINGLE;
/* SDRAM initialization sequence */
if(IS42S32800J_Init(&hsdram[0], &pRegMode) != IS42S32800J_OK)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
}
}
}
return ret;
}
/**
* @brief DeInitializes the SDRAM device.
* @param Instance SDRAM Instance
* @retval BSP status
*/
int32_t BSP_SDRAM_DeInit(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >=SDRAM_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* SDRAM device de-initialization */
hsdram[Instance].Instance = FMC_SDRAM_DEVICE;
(void)HAL_SDRAM_DeInit(&hsdram[Instance]);
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 0)
/* SDRAM controller de-initialization */
SDRAM_MspDeInit(&hsdram[Instance]);
#endif /* (USE_HAL_SDRAM_REGISTER_CALLBACKS == 0) */
ret = BSP_ERROR_NONE;
}
return ret;
}
/**
* @brief Initializes the SDRAM periperal.
* @param hSdram SDRAM handle
* @retval HAL status
*/
__weak HAL_StatusTypeDef MX_SDRAM_Init(SDRAM_HandleTypeDef *hSdram)
{
FMC_SDRAM_TimingTypeDef sdram_timing;
/* SDRAM device configuration */
hSdram->Instance = FMC_SDRAM_DEVICE;
/* SDRAM handle configuration */
hSdram->Init.SDBank = FMC_SDRAM_BANK2;
hSdram->Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9;
hSdram->Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
hSdram->Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_32;
hSdram->Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
hSdram->Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
hSdram->Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
hSdram->Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
hSdram->Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
hsdram->Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
/* Timing configuration for 100Mhz as SDRAM clock frequency (System clock is up to 200Mhz) */
sdram_timing.LoadToActiveDelay = 2;
sdram_timing.ExitSelfRefreshDelay = 7;
sdram_timing.SelfRefreshTime = 4;
sdram_timing.RowCycleDelay = 7;
sdram_timing.WriteRecoveryTime = 2;
sdram_timing.RPDelay = 2;
sdram_timing.RCDDelay = 2;
/* SDRAM controller initialization */
if(HAL_SDRAM_Init(hSdram, &sdram_timing) != HAL_OK)
{
return HAL_ERROR;
}
return HAL_OK;
}
/**
* @brief Initializes the SDRAM periperal.
* @retval HAL status
*/
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
/**
* @brief Default BSP SDRAM Msp Callbacks
* @param Instance SDRAM Instance
* @retval BSP status
*/
int32_t BSP_SDRAM_RegisterDefaultMspCallbacks (uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if the instance is supported */
if(Instance >=SDRAM_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Register MspInit/MspDeInit Callbacks */
if(HAL_SDRAM_RegisterCallback(&hsdram[Instance], HAL_SDRAM_MSP_INIT_CB_ID, SDRAM_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
if(HAL_SDRAM_RegisterCallback(&hsdram[Instance], HAL_SDRAM_MSP_DEINIT_CB_ID, SDRAM_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsMspCallbacksValid = 1;
}
}
/* Return BSP status */
return ret;
}
/**
* @brief BSP SDRAM Msp Callback registering
* @param Instance SDRAM Instance
* @param CallBacks pointer to MspInit/MspDeInit callbacks functions
* @retval BSP status
*/
int32_t BSP_SDRAM_RegisterMspCallbacks (uint32_t Instance, BSP_SDRAM_Cb_t *CallBacks)
{
int32_t ret = BSP_ERROR_NONE;
/* Check if the instance is supported */
if(Instance >=SDRAM_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Register MspInit/MspDeInit Callbacks */
if(HAL_SDRAM_RegisterCallback(&hsdram[Instance], HAL_SDRAM_MSP_INIT_CB_ID, CallBacks->pMspInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
if(HAL_SDRAM_RegisterCallback(&hsdram[Instance], HAL_SDRAM_MSP_DEINIT_CB_ID, CallBacks->pMspDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsMspCallbacksValid = 1;
}
}
/* Return BSP status */
return ret;
}
#endif /* (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1) */
/**
* @brief Sends command to the SDRAM bank.
* @param Instance SDRAM Instance
* @param SdramCmd Pointer to SDRAM command structure
* @retval BSP status
*/
int32_t BSP_SDRAM_SendCmd(uint32_t Instance, FMC_SDRAM_CommandTypeDef *SdramCmd)
{
int32_t ret;
if(Instance >=SDRAM_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else if(IS42S32800J_Sendcmd(&hsdram[Instance], SdramCmd) != IS42S32800J_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
}
return ret;
}
/**
* @brief This function handles MDMA_MDMA_Channel0 for SDRAM interrupt request.
* @retval None
*/
void BSP_SDRAM_IRQHandler(uint32_t Instance)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
HAL_MDMA_IRQHandler(hsdram[Instance].hmdma);
}
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Private_Functions Private Functions
* @{
*/
/**
* @brief Initializes SDRAM MSP.
* @param hsdram SDRAM handle
* @retval None
*/
static void SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram)
{
static MDMA_HandleTypeDef mdma_handle;
GPIO_InitTypeDef gpio_init_structure;
/* Enable FMC clock */
__HAL_RCC_FMC_CLK_ENABLE();
/* Enable chosen MDMAx clock */
SDRAM_MDMAx_CLK_ENABLE();
/* Enable GPIOs clock */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
/* Common GPIO configuration */
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_init_structure.Alternate = GPIO_AF12_FMC;
/* GPIOD configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_8| GPIO_PIN_9 | GPIO_PIN_10 |\
GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
/* GPIOE configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOE, &gpio_init_structure);
/* GPIOF configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
/* GPIOG configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 /*| GPIO_PIN_3 */|\
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
/* GPIOH configuration */
gpio_init_structure.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 |\
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
GPIO_PIN_15;
HAL_GPIO_Init(GPIOH, &gpio_init_structure);
/* GPIOI configuration */
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_9 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOI, &gpio_init_structure);
/* Configure common MDMA parameters */
mdma_handle.Init.Request = MDMA_REQUEST_SW;
mdma_handle.Init.TransferTriggerMode = MDMA_BLOCK_TRANSFER;
mdma_handle.Init.Priority = MDMA_PRIORITY_HIGH;
mdma_handle.Init.Endianness = MDMA_LITTLE_ENDIANNESS_PRESERVE;
mdma_handle.Init.SourceInc = MDMA_SRC_INC_WORD;
mdma_handle.Init.DestinationInc = MDMA_DEST_INC_WORD;
mdma_handle.Init.SourceDataSize = MDMA_SRC_DATASIZE_WORD;
mdma_handle.Init.DestDataSize = MDMA_DEST_DATASIZE_WORD;
mdma_handle.Init.DataAlignment = MDMA_DATAALIGN_PACKENABLE;
mdma_handle.Init.SourceBurst = MDMA_SOURCE_BURST_SINGLE;
mdma_handle.Init.DestBurst = MDMA_DEST_BURST_SINGLE;
mdma_handle.Init.BufferTransferLength = 128;
mdma_handle.Init.SourceBlockAddressOffset = 0;
mdma_handle.Init.DestBlockAddressOffset = 0;
mdma_handle.Instance = SDRAM_MDMAx_CHANNEL;
/* Associate the MDMA handle */
__HAL_LINKDMA(hsdram, hmdma, mdma_handle);
/* Deinitialize the stream for new transfer */
(void)HAL_MDMA_DeInit(&mdma_handle);
/* Configure the MDMA stream */
(void)HAL_MDMA_Init(&mdma_handle);
/* NVIC configuration for DMA transfer complete interrupt */
HAL_NVIC_SetPriority(SDRAM_MDMAx_IRQn, BSP_SDRAM_IT_PRIORITY, 0);
HAL_NVIC_EnableIRQ(SDRAM_MDMAx_IRQn);
}
/**
* @brief DeInitializes SDRAM MSP.
* @param hsdram SDRAM handle
* @retval None
*/
static void SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram)
{
static MDMA_HandleTypeDef mdma_handle;
/* Prevent unused argument(s) compilation warning */
UNUSED(hsdram);
/* Disable NVIC configuration for MDMA interrupt */
HAL_NVIC_DisableIRQ(SDRAM_MDMAx_IRQn);
/* Deinitialize the stream for new transfer */
mdma_handle.Instance = SDRAM_MDMAx_CHANNEL;
(void)HAL_MDMA_DeInit(&mdma_handle);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,122 @@
/**
******************************************************************************
* @file stm32h747i_discovery_sdram.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_sdram.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2018 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 STM32H747I_DISCO_SDRAM_H
#define STM32H747I_DISCO_SDRAM_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#include "../Components/is42s32800j/is42s32800j.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_SDRAM SDRAM
* @{
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Exported_Types Exported Types
* @{
*/
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(SDRAM_HandleTypeDef *);
void (* pMspDeInitCb)(SDRAM_HandleTypeDef *);
}BSP_SDRAM_Cb_t;
#endif /* (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_SDRAM_Exported_Constants Exported Constants
* @{
*/
#define SDRAM_INSTANCES_NBR 1U
#define SDRAM_DEVICE_ADDR 0xD0000000U
#define SDRAM_DEVICE_SIZE 0x2000000U
/* MDMA definitions for SDRAM DMA transfer */
#define SDRAM_MDMAx_CLK_ENABLE __HAL_RCC_MDMA_CLK_ENABLE
#define SDRAM_MDMAx_CLK_DISABLE __HAL_RCC_MDMA_CLK_DISABLE
#define SDRAM_MDMAx_CHANNEL MDMA_Channel0
#define SDRAM_MDMAx_IRQn MDMA_IRQn
#define SDRAM_MDMA_IRQHandler MDMA_IRQHandler
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_SDRAM_Exported_Variables
* @{
*/
extern SDRAM_HandleTypeDef hsdram[];
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_SDRAM_Exported_Functions
* @{
*/
int32_t BSP_SDRAM_Init(uint32_t Instance);
int32_t BSP_SDRAM_DeInit(uint32_t Instance);
#if (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1)
int32_t BSP_SDRAM_RegisterDefaultMspCallbacks (uint32_t Instance);
int32_t BSP_SDRAM_RegisterMspCallbacks (uint32_t Instance, BSP_SDRAM_Cb_t *CallBacks);
#endif /* (USE_HAL_SDRAM_REGISTER_CALLBACKS == 1) */
int32_t BSP_SDRAM_SendCmd(uint32_t Instance, FMC_SDRAM_CommandTypeDef *SdramCmd);
void BSP_SDRAM_IRQHandler(uint32_t Instance);
/* These functions can be modified in case the current settings need to be
changed for specific application needs */
HAL_StatusTypeDef MX_SDRAM_Init(SDRAM_HandleTypeDef *hSdram);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_SDRAM_H */
@@ -0,0 +1,695 @@
/**
******************************************************************************
* @file stm32h747i_discovery_ts.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the Touch
* Screen on STM32H747I_DISCO board.
******************************************************************************
* @attention
*
* Copyright (c) 2019 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.
*
******************************************************************************
*/
/* File Info : -----------------------------------------------------------------
User NOTES
1. How To use this driver:
--------------------------
- This driver is used to drive the FT6X06 touch screen module
mounted over TFT-LCD on the STM32H747I_DISCO board.
2. Driver description:
---------------------
+ Initialization steps:
o Initialize the TS module using the BSP_TS_Init() function. This
function includes the MSP layer hardware resources initialization and the
communication layer configuration to start the TS use. The LCD size properties
(x and y) are passed as parameters.
o If TS interrupt mode is desired, you must configure the TS interrupt mode
by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated
as an external interrupt whenever a touch is detected.
The interrupt mode internally uses the IO functionalities driver driven by
the IO expander, to configure the IT line.
+ Touch screen use
o The touch screen state is captured whenever the function BSP_TS_GetState() is
used. This function returns information about the last LCD touch occurred
in the TS_State_t structure.
o The IT is handled using the corresponding external interrupt IRQ handler,
the user IT callback treatment is implemented on the same external interrupt
callback.
------------------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_ts.h"
#include "stm32h747i_discovery_bus.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @defgroup STM32H747I_DISCO_TS TS
* @{
*/
/** @defgroup STM32H747I_DISCO_TS_Private_Types_Definitions Private Types Definitions
* @{
*/
typedef void (* BSP_EXTI_LineCallback) (void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Private_Macros Private Macros
* @{
*/
#define TS_MIN(a,b) ((a > b) ? b : a)
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Private_Function_Prototypes Private Function Prototypes
* @{
*/
static int32_t FT6X06_Probe(uint32_t Instance);
static void TS_EXTI_Callback(void);
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Privates_Variables Privates Variables
* @{
*/
static EXTI_HandleTypeDef hts_exti[TS_INSTANCES_NBR] = {0};
static TS_Drv_t *Ts_Drv = NULL;
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Exported_Variables Exported Variables
* @{
*/
TS_Ctx_t Ts_Ctx[TS_INSTANCES_NBR] = {0};
void *Ts_CompObj[TS_INSTANCES_NBR] = {0};
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Exported_Functions Exported Functions
* @{
*/
/**
* @brief Initializes and configures the touch screen functionalities and
* configures all necessary hardware resources (GPIOs, I2C, clocks..).
* @param Instance TS instance. Could be only 0.
* @param TS_Init TS Init structure
* @retval BSP status
*/
int32_t BSP_TS_Init(uint32_t Instance, TS_Init_t *TS_Init)
{
int32_t ret = BSP_ERROR_NONE;
if((Instance >=TS_INSTANCES_NBR) || (TS_Init->Width == 0U) ||( TS_Init->Width > TS_MAX_WIDTH) ||\
(TS_Init->Height == 0U) ||( TS_Init->Height > TS_MAX_HEIGHT) ||\
(TS_Init->Accuracy > TS_MIN((TS_Init->Width), (TS_Init->Height))))
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(FT6X06_Probe(Instance) != BSP_ERROR_NONE)
{
ret = BSP_ERROR_NO_INIT;
}
else
{
TS_Capabilities_t Capabilities;
Ts_Ctx[Instance].Width = TS_Init->Width;
Ts_Ctx[Instance].Height = TS_Init->Height;
Ts_Ctx[Instance].Orientation = TS_Init->Orientation;
Ts_Ctx[Instance].Accuracy = TS_Init->Accuracy;
if (Ts_Drv->GetCapabilities(Ts_CompObj[Instance], &Capabilities) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
/* Store maximum X and Y on context */
Ts_Ctx[Instance].MaxX = Capabilities.MaxXl;
Ts_Ctx[Instance].MaxY = Capabilities.MaxYl;
/* Initialize previous position in order to always detect first touch */
for(int i = 0; i < TS_TOUCH_NBR; i++)
{
Ts_Ctx[Instance].PreviousX[i] = TS_Init->Width + TS_Init->Accuracy + 1U;
Ts_Ctx[Instance].PreviousY[i] = TS_Init->Height + TS_Init->Accuracy + 1U;
}
}
}
}
return ret;
}
/**
* @brief De-Initializes the touch screen functionalities
* @param Instance TS instance. Could be only 0.
* @retval BSP status
*/
int32_t BSP_TS_DeInit(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(Ts_Drv->DeInit(Ts_CompObj[Instance]) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
}
}
return ret;
}
/**
* @brief Get Touch Screen instance capabilities
* @param Instance Touch Screen instance
* @param Capabilities pointer to Touch Screen capabilities
* @retval BSP status
*/
int32_t BSP_TS_GetCapabilities(uint32_t Instance, TS_Capabilities_t *Capabilities)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
(void)Ts_Drv->GetCapabilities(Ts_CompObj[Instance], Capabilities);
ret = BSP_ERROR_NONE;
}
return ret;
}
/**
* @brief Configures and enables the touch screen interrupts.
* @param Instance TS instance. Could be only 0.
* @retval BSP status
*/
int32_t BSP_TS_EnableIT(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
static const uint32_t TS_EXTI_LINE[TS_INSTANCES_NBR] = {TS_INT_LINE};
static BSP_EXTI_LineCallback TsCallback[TS_INSTANCES_NBR] = {TS_EXTI_Callback};
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
TS_INT_GPIO_CLK_ENABLE();
/* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */
/* TS_INT pin is active on low level on new touch available */
gpio_init_structure.Pin = TS_INT_PIN;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
if(Ts_Drv->EnableIT(Ts_CompObj[Instance]) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
(void)HAL_EXTI_GetHandle(&hts_exti[Instance], TS_EXTI_LINE[Instance]);
(void)HAL_EXTI_RegisterCallback(&hts_exti[Instance], HAL_EXTI_COMMON_CB_ID, TsCallback[Instance]);
HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), BSP_TS_IT_PRIORITY, 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn));
ret = BSP_ERROR_NONE;
}
}
return ret;
}
/**
* @brief Disables the touch screen interrupts.
* @param Instance TS instance. Could be only 0.
* @retval BSP status
*/
int32_t BSP_TS_DisableIT(uint32_t Instance)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
gpio_init_structure.Pin = TS_INT_PIN;
HAL_GPIO_DeInit(TS_INT_GPIO_PORT,gpio_init_structure.Pin);
HAL_NVIC_DisableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn));
if(Ts_Drv->DisableIT(Ts_CompObj[Instance]) != FT6X06_OK)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
}
}
return ret;
}
/**
* @brief BSP TS Callback.
* @param Instance TS instance. Could be only 0.
* @retval None.
*/
__weak void BSP_TS_Callback(uint32_t Instance)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
/* This function should be implemented by the user application.
It is called into this driver when an event on TS touch detection */
}
/**
* @brief Returns positions of a single touch screen.
* @param Instance TS instance. Could be only 0.
* @param TS_State Pointer to touch screen current state structure
* @retval BSP status
*/
int32_t BSP_TS_GetState(uint32_t Instance, TS_State_t *TS_State)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t x_oriented, y_oriented;
uint32_t x_diff, y_diff;
if(Instance >= TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
FT6X06_State_t state;
/* Get each touch coordinates */
if(Ts_Drv->GetState(Ts_CompObj[Instance], &state) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}/* Check and update the number of touches active detected */
else if(state.TouchDetected != 0U)
{
x_oriented = state.TouchX;
y_oriented = state.TouchY;
if((Ts_Ctx[Instance].Orientation & TS_SWAP_XY) == TS_SWAP_XY)
{
x_oriented = state.TouchY;
y_oriented = state.TouchX;
}
if((Ts_Ctx[Instance].Orientation & TS_SWAP_X) == TS_SWAP_X)
{
x_oriented = Ts_Ctx[Instance].MaxX - x_oriented - 1UL;
}
if((Ts_Ctx[Instance].Orientation & TS_SWAP_Y) == TS_SWAP_Y)
{
y_oriented = Ts_Ctx[Instance].MaxY - y_oriented - 1UL;
}
/* Apply boundary */
TS_State->TouchX = (x_oriented * Ts_Ctx[Instance].Width) / Ts_Ctx[Instance].MaxX;
TS_State->TouchY = (y_oriented * Ts_Ctx[Instance].Height) / Ts_Ctx[Instance].MaxY;
/* Store Current TS state */
TS_State->TouchDetected = state.TouchDetected;
/* Check accuracy */
x_diff = (TS_State->TouchX > Ts_Ctx[Instance].PreviousX[0])?
(TS_State->TouchX - Ts_Ctx[Instance].PreviousX[0]):
(Ts_Ctx[Instance].PreviousX[0] - TS_State->TouchX);
y_diff = (TS_State->TouchY > Ts_Ctx[Instance].PreviousY[0])?
(TS_State->TouchY - Ts_Ctx[Instance].PreviousY[0]):
(Ts_Ctx[Instance].PreviousY[0] - TS_State->TouchY);
if ((x_diff > Ts_Ctx[Instance].Accuracy) || (y_diff > Ts_Ctx[Instance].Accuracy))
{
/* New touch detected */
Ts_Ctx[Instance].PreviousX[0] = TS_State->TouchX;
Ts_Ctx[Instance].PreviousY[0] = TS_State->TouchY;
}
else
{
TS_State->TouchX = Ts_Ctx[Instance].PreviousX[0];
TS_State->TouchY = Ts_Ctx[Instance].PreviousY[0];
}
}
else
{
TS_State->TouchDetected = 0U;
TS_State->TouchX = Ts_Ctx[Instance].PreviousX[0];
TS_State->TouchY = Ts_Ctx[Instance].PreviousY[0];
}
}
return ret;
}
#if (USE_TS_MULTI_TOUCH > 0)
/**
* @brief Returns positions of multi touch screen.
* @param Instance TS instance. Could be only 0.
* @param TS_State Pointer to touch screen current state structure
* @retval BSP status
*/
int32_t BSP_TS_Get_MultiTouchState(uint32_t Instance, TS_MultiTouch_State_t *TS_State)
{
int32_t ret = BSP_ERROR_NONE;
uint32_t x_oriented[2], y_oriented[2];
uint32_t x_diff, y_diff;
uint32_t index;
if(Instance >= TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
TS_MultiTouch_State_t state;
/* Get each touch coordinates */
if(Ts_Drv->GetMultiTouchState(Ts_CompObj[Instance], &state) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}/* Check and update the number of touches active detected */
else if(state.TouchDetected != 0U)
{
for(index = 0; index < state.TouchDetected; index++)
{
x_oriented[index] = state.TouchX[index];
y_oriented[index] = state.TouchY[index];
if((Ts_Ctx[Instance].Orientation & TS_SWAP_XY) == TS_SWAP_XY)
{
x_oriented[index] = state.TouchY[index];
y_oriented[index] = state.TouchX[index];
}
if((Ts_Ctx[Instance].Orientation & TS_SWAP_X) == TS_SWAP_X)
{
x_oriented[index] = Ts_Ctx[Instance].MaxX - x_oriented[index] - 1UL;
}
if((Ts_Ctx[Instance].Orientation & TS_SWAP_Y) == TS_SWAP_Y)
{
y_oriented[index] = Ts_Ctx[Instance].MaxY - y_oriented[index] - 1UL;
}
/* Apply boundary */
TS_State->TouchX[index] = (x_oriented[index] * Ts_Ctx[Instance].Width) / Ts_Ctx[Instance].MaxX;
TS_State->TouchY[index] = (y_oriented[index] * Ts_Ctx[Instance].Height) / Ts_Ctx[Instance].MaxY;
/* Store Current TS state */
TS_State->TouchDetected = state.TouchDetected;
/* Check accuracy */
x_diff = (TS_State->TouchX[index] > Ts_Ctx[Instance].PreviousX[0])?
(TS_State->TouchX[index] - Ts_Ctx[Instance].PreviousX[0]):
(Ts_Ctx[Instance].PreviousX[0] - TS_State->TouchX[index]);
y_diff = (TS_State->TouchY[index] > Ts_Ctx[Instance].PreviousY[0])?
(TS_State->TouchY[index] - Ts_Ctx[Instance].PreviousY[0]):
(Ts_Ctx[Instance].PreviousY[0] - TS_State->TouchY[index]);
if ((x_diff > Ts_Ctx[Instance].Accuracy) || (y_diff > Ts_Ctx[Instance].Accuracy))
{
/* New touch detected */
Ts_Ctx[Instance].PreviousX[index] = TS_State->TouchX[index];
Ts_Ctx[Instance].PreviousY[index] = TS_State->TouchY[index];
}
else
{
TS_State->TouchX[index] = Ts_Ctx[Instance].PreviousX[index];
TS_State->TouchY[index] = Ts_Ctx[Instance].PreviousY[index];
}
}
}
else
{
TS_State->TouchDetected = 0U;
for(index = 0; index < TS_TOUCH_NBR; index++)
{
TS_State->TouchX[index] = Ts_Ctx[Instance].PreviousX[index];
TS_State->TouchY[index] = Ts_Ctx[Instance].PreviousY[index];
}
}
}
return ret;
}
#endif /* USE_TS_MULTI_TOUCH > 1 */
#if (USE_TS_GESTURE > 0)
/**
* @brief Update gesture Id following a touch detected.
* @param Instance TS instance. Could be only 0.
* @param GestureConfig Pointer to gesture configuration structure
* @retval BSP status
*/
int32_t BSP_TS_GestureConfig(uint32_t Instance, TS_Gesture_Config_t *GestureConfig)
{
int32_t ret = BSP_ERROR_NONE;
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
if(Ts_Drv->GestureConfig(Ts_CompObj[Instance], GestureConfig) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
}
return ret;
}
/**
* @brief Update gesture Id following a touch detected.
* @param Instance TS instance. Could be only 0.
* @param GestureId Pointer to gesture ID
* @retval BSP status
*/
int32_t BSP_TS_GetGestureId(uint32_t Instance, uint32_t *GestureId)
{
int32_t ret = BSP_ERROR_NONE;
uint8_t tmp = 0;
if(Instance >=TS_INSTANCES_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}/* Get gesture Id */
else if(Ts_Drv->GetGesture(Ts_CompObj[Instance], &tmp) < 0)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
/* Remap gesture Id to a TS_Gesture_Id_t value */
switch(tmp)
{
case FT6X06_GEST_ID_NO_GESTURE :
*GestureId = GESTURE_ID_NO_GESTURE;
break;
case FT6X06_GEST_ID_MOVE_UP :
*GestureId = GESTURE_ID_MOVE_UP;
break;
case FT6X06_GEST_ID_MOVE_RIGHT :
*GestureId = GESTURE_ID_MOVE_RIGHT;
break;
case FT6X06_GEST_ID_MOVE_DOWN :
*GestureId = GESTURE_ID_MOVE_DOWN;
break;
case FT6X06_GEST_ID_MOVE_LEFT :
*GestureId = GESTURE_ID_MOVE_LEFT;
break;
case FT6X06_GEST_ID_ZOOM_IN :
*GestureId = GESTURE_ID_ZOOM_IN;
break;
case FT6X06_GEST_ID_ZOOM_OUT :
*GestureId = GESTURE_ID_ZOOM_OUT;
break;
default :
*GestureId = GESTURE_ID_NO_GESTURE;
break;
}
ret = BSP_ERROR_NONE;
}
return ret;
}
#endif /* USE_TS_GESTURE > 0 */
/**
* @brief Set TS orientation
* @param Instance TS instance. Could be only 0.
* @param Orientation Orientation to be set
* @retval BSP status
*/
int32_t BSP_TS_Set_Orientation(uint32_t Instance, uint32_t Orientation)
{
Ts_Ctx[Instance].Orientation = Orientation;
return BSP_ERROR_NONE;
}
/**
* @brief Get TS orientation
* @param Instance TS instance. Could be only 0.
* @param Orientation Current Orientation to be returned
* @retval BSP status
*/
int32_t BSP_TS_Get_Orientation(uint32_t Instance, uint32_t *Orientation)
{
*Orientation = Ts_Ctx[Instance].Orientation;
return BSP_ERROR_NONE;
}
/**
* @brief This function handles TS interrupt request.
* @param Instance TS instance
* @retval None
*/
void BSP_TS_IRQHandler(uint32_t Instance)
{
HAL_EXTI_IRQHandler(&hts_exti[Instance]);
}
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Private_Functions Private Functions
* @{
*/
/**
* @brief Register Bus IOs if component ID is OK
* @param Instance TS instance. Could be only 0.
* @retval BSP status
*/
static int32_t FT6X06_Probe(uint32_t Instance)
{
int32_t ret;
FT6X06_IO_t IOCtx;
static FT6X06_Object_t FT6X06Obj;
FT6X06_Capabilities_t Cap;
uint32_t id, i;
uint32_t const i2c_address[] = {TS_I2C_ADDRESS, TS_I2C_ADDRESS_A02};
/* Configure the touch screen driver */
IOCtx.Init = BSP_I2C4_Init;
IOCtx.DeInit = BSP_I2C4_DeInit;
IOCtx.ReadReg = BSP_I2C4_ReadReg;
IOCtx.WriteReg = BSP_I2C4_WriteReg;
IOCtx.GetTick = BSP_GetTick;
for(i = 0; i < 2UL; i++)
{
IOCtx.Address = (uint16_t)i2c_address[i];
if(FT6X06_RegisterBusIO (&FT6X06Obj, &IOCtx) != FT6X06_OK)
{
ret = BSP_ERROR_BUS_FAILURE;
}
else if(FT6X06_ReadID(&FT6X06Obj, &id) != FT6X06_OK)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else if(id != FT6X06_ID)
{
ret = BSP_ERROR_UNKNOWN_COMPONENT;
}
else
{
(void)FT6X06_GetCapabilities(&FT6X06Obj, &Cap);
Ts_CompObj[Instance] = &FT6X06Obj;
Ts_Drv = (TS_Drv_t *) &FT6X06_TS_Driver;
if(Ts_Drv->Init(Ts_CompObj[Instance]) != FT6X06_OK)
{
ret = BSP_ERROR_COMPONENT_FAILURE;
}
else
{
ret = BSP_ERROR_NONE;
break;
}
}
}
return ret;
}
/**
* @brief TS EXTI touch detection callbacks.
* @retval None
*/
static void TS_EXTI_Callback(void)
{
BSP_TS_Callback(0);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
@@ -0,0 +1,242 @@
/**
******************************************************************************
* @file stm32h747i_discovery_ts.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the stm32h747i_discovery_ts.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2019 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 STM32H747I_DISCO_TS_H
#define STM32H747I_DISCO_TS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h747i_discovery_conf.h"
#include "stm32h747i_discovery_errno.h"
#include "../Components/Common/ts.h"
/* Include TouchScreen component driver */
#include "../Components/ft6x06/ft6x06.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H747I_DISCO
* @{
*/
/** @addtogroup STM32H747I_DISCO_TS
* @{
*/
/** @defgroup STM32H747I_DISCO_TS_Exported_Constants Exported Constants
* @{
*/
/** @brief With FT6206 : maximum 2 touches detected simultaneously
*/
#define TS_INSTANCES_NBR 1U
#ifndef USE_TS_MULTI_TOUCH
#define USE_TS_MULTI_TOUCH 1U
#endif
#ifndef USE_TS_GESTURE
#define USE_TS_GESTURE 1U
#endif
#ifndef TS_TOUCH_NBR
#define TS_TOUCH_NBR 2U
#endif
/* Maximum border values of the touchscreen pad */
#define TS_MAX_WIDTH 800U /* Touchscreen pad max width */
#define TS_MAX_HEIGHT 480U /* Touchscreen pad max height */
#define TS_SWAP_NONE 0x01U
#define TS_SWAP_X 0x02U
#define TS_SWAP_Y 0x04U
#define TS_SWAP_XY 0x08U
/**
* @brief TouchScreen Slave I2C address 1
*/
#define TS_I2C_ADDRESS 0x54U
/**
* @brief TouchScreen Slave I2C address 2
*/
#define TS_I2C_ADDRESS_A02 0x70U
/**
* @brief Touch screen interrupt signal
*/
#define TS_INT_PIN ((uint32_t)GPIO_PIN_7)
#define TS_INT_GPIO_PORT ((GPIO_TypeDef*)GPIOK)
#define TS_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
#define TS_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
#define TS_INT_EXTI_IRQn EXTI9_5_IRQn
#define TS_INT_LINE EXTI_LINE_7
#if (USE_TS_GESTURE == 1)
/**
* Define Possible managed gesture identification values returned by touch screen
* driver.
*/
#define GESTURE_ID_NO_GESTURE 0x00U /*!< Gesture not defined / recognized */
#define GESTURE_ID_MOVE_UP 0x01U /*!< Gesture Move Up */
#define GESTURE_ID_MOVE_RIGHT 0x02U /*!< Gesture Move Right */
#define GESTURE_ID_MOVE_DOWN 0x03U /*!< Gesture Move Down */
#define GESTURE_ID_MOVE_LEFT 0x04U /*!< Gesture Move Left */
#define GESTURE_ID_ZOOM_IN 0x05U /*!< Gesture Zoom In */
#define GESTURE_ID_ZOOM_OUT 0x06U /*!< Gesture Zoom Out */
#define GESTURE_ID_NB_MAX 0x07U /*!< max number of gesture id */
#endif /* (USE_TS_GESTURE == 1) */
/**
* @}
*/
/** @defgroup STM32H747I_DISCO_TS_Exported_Types Exported Types
* @{
*/
typedef struct
{
uint32_t Width; /* Screen Width */
uint32_t Height; /* Screen Height */
uint32_t Orientation; /* Touch Screen orientation from the upper left position */
uint32_t Accuracy; /* Expressed in pixel and means the x or y difference vs old
position to consider the new values valid */
}TS_Init_t;
typedef struct
{
uint32_t Width;
uint32_t Height;
uint32_t Orientation;
uint32_t Accuracy;
uint32_t MaxX;
uint32_t MaxY;
uint32_t PreviousX[TS_TOUCH_NBR];
uint32_t PreviousY[TS_TOUCH_NBR];
} TS_Ctx_t;
typedef struct
{
uint8_t MultiTouch;
uint8_t Gesture;
uint8_t MaxTouch;
uint32_t MaxXl;
uint32_t MaxYl;
} TS_Capabilities_t;
typedef struct
{
uint32_t TouchDetected;
uint32_t TouchX;
uint32_t TouchY;
} TS_State_t;
typedef struct
{
uint32_t TouchDetected;
uint32_t TouchX[TS_TOUCH_NBR];
uint32_t TouchY[TS_TOUCH_NBR];
uint32_t TouchWeight[TS_TOUCH_NBR];
uint32_t TouchEvent[TS_TOUCH_NBR];
uint32_t TouchArea[TS_TOUCH_NBR];
} TS_MultiTouch_State_t;
#if (USE_TS_GESTURE == 1)
typedef struct
{
uint32_t Radian;
uint32_t OffsetLeftRight;
uint32_t OffsetUpDown;
uint32_t DistanceLeftRight;
uint32_t DistanceUpDown;
uint32_t DistanceZoom;
}TS_Gesture_Config_t;
/**
* @brief TS_TouchEventTypeDef
* Define Possible touch events kind as returned values
* by touch screen IC Driver.
*/
typedef enum
{
TOUCH_EVENT_NO_EVT = 0x00, /*!< Touch Event : undetermined */
TOUCH_EVENT_PRESS_DOWN = 0x01, /*!< Touch Event Press Down */
TOUCH_EVENT_LIFT_UP = 0x02, /*!< Touch Event Lift Up */
TOUCH_EVENT_CONTACT = 0x03, /*!< Touch Event Contact */
TOUCH_EVENT_NB_MAX = 0x04 /*!< max number of touch events kind */
} TS_TouchEventTypeDef;
#endif /* (USE_TS_GESTURE == 1) */
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_TS_Exported_Variables
* @{
*/
extern TS_Ctx_t Ts_Ctx[];
extern void *Ts_CompObj[TS_INSTANCES_NBR];
/**
* @}
*/
/** @addtogroup STM32H747I_DISCO_TS_Exported_Functions
* @{
*/
int32_t BSP_TS_Init(uint32_t Instance, TS_Init_t *TS_Init);
int32_t BSP_TS_DeInit(uint32_t Instance);
int32_t BSP_TS_EnableIT(uint32_t Instance);
int32_t BSP_TS_DisableIT(uint32_t Instance);
int32_t BSP_TS_GetState(uint32_t Instance, TS_State_t *TS_State);
#if (USE_TS_MULTI_TOUCH > 0)
int32_t BSP_TS_Get_MultiTouchState(uint32_t Instance, TS_MultiTouch_State_t *TS_State);
#endif /* USE_TS_MULTI_TOUCH > 0 */
#if (USE_TS_GESTURE > 0)
int32_t BSP_TS_GestureConfig(uint32_t Instance, TS_Gesture_Config_t *GestureConfig);
int32_t BSP_TS_GetGestureId(uint32_t Instance, uint32_t *GestureId);
#endif /* (USE_TS_GESTURE > 0) */
int32_t BSP_TS_Set_Orientation(uint32_t Instance, uint32_t Orientation);
int32_t BSP_TS_Get_Orientation(uint32_t Instance, uint32_t *Orientation);
int32_t BSP_TS_GetCapabilities(uint32_t Instance, TS_Capabilities_t *Capabilities);
void BSP_TS_Callback(uint32_t Instance);
void BSP_TS_IRQHandler(uint32_t Instance);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H747I_DISCO_TS_H */