Goran Mahovlic
2 years ago
26 changed files with 13312 additions and 0 deletions
@ -0,0 +1,3 @@
|
||||
# Copyright (c) 2017 STMicroelectronics |
||||
|
||||
This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this software except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). |
@ -0,0 +1,140 @@
|
||||
<!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 32L496GDISCOVERY Board Drivers</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="l496gdiscovery-board-drivers"><mark>32L496GDISCOVERY Board Drivers</mark></h1> |
||||
<p>Copyright © 2017 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="license">License</h1> |
||||
<p>Licensed by ST under BSD 3-Clause license (the "License"). You may not use this package except in compliance with the License. You may obtain a copy of the License at:</p> |
||||
<p><a href="https://opensource.org/licenses/BSD-3-Clause">https://opensource.org/licenses/BSD-3-Clause</a></p> |
||||
<h1 id="purpose">Purpose</h1> |
||||
<p>This directory contains the board drivers to demonstrate the capabilities of the 32L496GDISCOVERY Kit.</p> |
||||
</div> |
||||
<div class="col-sm-12 col-lg-8"> |
||||
<h1 id="update-history">Update History</h1> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section23" checked aria-hidden="true"> <label for="collapse-section23" aria-hidden="true">V1.1.6 / 11-February-2021</label> |
||||
<div> |
||||
<h2 id="main-changes">Main Changes</h2> |
||||
<ul> |
||||
<li>Minor update of Release Notes template</li> |
||||
<li>Add License.md file for GitHub publication</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section22" aria-hidden="true"> <label for="collapse-section22" aria-hidden="true">V1.1.5 / 26-June-2020</label> |
||||
<div> |
||||
<h2 id="main-changes-1">Main Changes</h2> |
||||
<ul> |
||||
<li>Remove useless assignment in BSP_COM_Init() function</li> |
||||
<li>Update common GPIO configuration in BSP_SD_MspInit() to remove internal pull-up</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section21" aria-hidden="true"> <label for="collapse-section21" aria-hidden="true">V1.1.4 / 22-November-2019</label> |
||||
<div> |
||||
<h2 id="main-changes-2">Main Changes</h2> |
||||
<ul> |
||||
<li>Enable the Sample Shift (SSHIFT) feature in <em>BSP_QSPI_Init()</em> to ensure the read data isn’t corrupted when prescaler is div/1</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section20" aria-hidden="true"> <label for="collapse-section20" aria-hidden="true">V1.1.3 / 18-October-2019</label> |
||||
<div> |
||||
<h2 id="main-changes-3">Main Changes</h2> |
||||
<ul> |
||||
<li>stm32l496g_discovery.c |
||||
<ul> |
||||
<li>Remove superfluous settings of PD.11 and PF.00 from FMC_BANK1_MspInit() and FMC_BANK1_MspDeInit() that were preventing a correct usage of PSRAM</li> |
||||
</ul></li> |
||||
<li>Minor update in release notes format</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section19" aria-hidden="true"> <label for="collapse-section19" aria-hidden="true">V1.1.2 / 03-April-2019</label> |
||||
<div> |
||||
<h2 id="main-changes-4">Main Changes</h2> |
||||
<ul> |
||||
<li>stm32l496g_discovery.c |
||||
<ul> |
||||
<li>Correct logical test in DrawChar()</li> |
||||
<li>Comment minor correction</li> |
||||
</ul></li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section18" aria-hidden="true"> <label for="collapse-section18" aria-hidden="true">V1.1.1 / 27-July-2018</label> |
||||
<div> |
||||
<h2 id="main-changes-5">Main Changes</h2> |
||||
<ul> |
||||
<li>Release notes update to new format</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
<div class="collapse"> |
||||
<input type="checkbox" id="collapse-section17" aria-hidden="true"> <label for="collapse-section17" aria-hidden="true">V1.1.0 / 25-August-2017</label> |
||||
<div> |
||||
<h2 id="main-changes-6">Main Changes</h2> |
||||
<ul> |
||||
<li>stm32l496g_discovery.h/.c |
||||
<ul> |
||||
<li>Add BSP_COM_Init()/BSP_COM_DeInit() APIs for ST-Link USB Virtual Com Port</li> |
||||
</ul></li> |
||||
<li>stm32l496g_discovery_audio.h/.c |
||||
<ul> |
||||
<li>Add INPUT_DEVICE_DIGITAL_MIC1 and INPUT_DEVICE_DIGITAL_MIC2 to provide the capability to record over a single digital microphone (respectively left and right microphones)</li> |
||||
</ul></li> |
||||
<li>stm32l496g_discovery_sd.c/.h |
||||
<ul> |
||||
<li>Add weak BSP SD functions |
||||
<ul> |
||||
<li>BSP_SD_MspInit(), BSP_SD_MspDeInit(), BSP_SD_WriteCpltCallback(), BSP_SD_ReadCpltCallback() and BSP_SD_AbortCallback()</li> |
||||
</ul></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">V1.0.0 / 17-February-2017</label> |
||||
<div> |
||||
<h2 id="main-changes-7">Main Changes</h2> |
||||
<ul> |
||||
<li>First official release of <strong>STM32L496G-Discovery</strong> board drivers for STM32Cube L4 FW package</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<footer class="sticky"> |
||||
For complete documentation on <mark>STM32 Microcontrollers</mark> , visit: <a href="http://www.st.com/STM32">http://www.st.com/STM32</a> |
||||
</footer> |
||||
</body> |
||||
</html> |
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 7.3 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,590 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains definitions for STM32L496G_DISCOVERY's LEDs, |
||||
* push-buttons hardware resources (MB1261). |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_H |
||||
#define __STM32L496G_DISCOVERY_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Define for STM32L496G_DISCOVERY board |
||||
*/ |
||||
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l4xx_hal.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_Common
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief LED Types Definition |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
LED1 = 0, |
||||
LED2 = 1, |
||||
LED_ORANGE = LED1, |
||||
LED_GREEN = LED2 |
||||
} |
||||
Led_TypeDef; |
||||
|
||||
|
||||
/**
|
||||
* @brief JOYSTICK Types Definition |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
JOY_SEL = 0, |
||||
JOY_LEFT = 1, |
||||
JOY_RIGHT = 2, |
||||
JOY_DOWN = 3, |
||||
JOY_UP = 4, |
||||
JOY_NONE = 5 |
||||
} JOYState_TypeDef; |
||||
|
||||
typedef enum |
||||
{ |
||||
JOY_MODE_GPIO = 0, |
||||
JOY_MODE_EXTI = 1 |
||||
} JOYMode_TypeDef; |
||||
|
||||
typedef enum
|
||||
{ |
||||
COM1 = 0 |
||||
} COM_TypeDef; |
||||
|
||||
/**
|
||||
* @brief LCD constroller Types Definition |
||||
*/ |
||||
typedef struct |
||||
{ |
||||
__IO uint16_t REG; |
||||
__IO uint16_t RAM; |
||||
} LCD_CONTROLLER_TypeDef; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_FMC FMC LCD Constants
|
||||
* @{ |
||||
*/ |
||||
/* We use BANK1 as we use FMC_NE1 signal */ |
||||
#define FMC_BANK1_BASE ((uint32_t)(0x60000000 | 0x00000000)) |
||||
#define FMC_LCD_BASE ((uint32_t)(0x60000000 | 0x00080000)) /*using A18*/ |
||||
#define FMC_BANK1_ADDR ((LCD_CONTROLLER_TypeDef *) FMC_BANK1_BASE) |
||||
#define LCD_ADDR ((LCD_CONTROLLER_TypeDef *) FMC_LCD_BASE) |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_LED LED Constants
|
||||
* @{ |
||||
*/ |
||||
/* To do: invert LED1 and LED2 */ |
||||
#define LEDn 2 |
||||
|
||||
/* LED1 is accessed thru the MFX */ |
||||
#define LED1_PIN IO1_PIN_4 |
||||
|
||||
#define LED2_PIN GPIO_PIN_13 |
||||
#define LED2_GPIO_PORT GPIOB |
||||
#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_BUTTON BUTTON Constants
|
||||
* @{ |
||||
*/ |
||||
#define JOYn 5 |
||||
|
||||
/**
|
||||
* @brief Joystick Right push-button |
||||
*/ |
||||
#define RIGHT_JOY_PIN GPIO_PIN_11 /* PF.11 */ |
||||
#define RIGHT_JOY_GPIO_PORT GPIOF |
||||
#define RIGHT_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() |
||||
#define RIGHT_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE() |
||||
#define RIGHT_JOY_EXTI_IRQn EXTI15_10_IRQn |
||||
|
||||
/**
|
||||
* @brief Joystick Left push-button |
||||
*/ |
||||
#define LEFT_JOY_PIN GPIO_PIN_9 /* PI.09 */ |
||||
#define LEFT_JOY_GPIO_PORT GPIOI |
||||
#define LEFT_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() |
||||
#define LEFT_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE() |
||||
#define LEFT_JOY_EXTI_IRQn EXTI9_5_IRQn |
||||
|
||||
/**
|
||||
* @brief Joystick Up push-button |
||||
*/ |
||||
#define UP_JOY_PIN GPIO_PIN_8 /* PI.08 */ |
||||
#define UP_JOY_GPIO_PORT GPIOI |
||||
#define UP_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() |
||||
#define UP_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE() |
||||
#define UP_JOY_EXTI_IRQn EXTI9_5_IRQn |
||||
|
||||
/**
|
||||
* @brief Joystick Down push-button |
||||
*/ |
||||
#define DOWN_JOY_PIN GPIO_PIN_10 /* PI.10 */ |
||||
#define DOWN_JOY_GPIO_PORT GPIOI |
||||
#define DOWN_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() |
||||
#define DOWN_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE() |
||||
#define DOWN_JOY_EXTI_IRQn EXTI15_10_IRQn |
||||
|
||||
/**
|
||||
* @brief Joystick Sel push-button |
||||
*/ |
||||
#define SEL_JOY_PIN GPIO_PIN_13 /* PC.13 */ |
||||
#define SEL_JOY_GPIO_PORT GPIOC |
||||
#define SEL_JOY_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() |
||||
#define SEL_JOY_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() |
||||
#define SEL_JOY_EXTI_IRQn EXTI15_10_IRQn |
||||
|
||||
#define JOYx_GPIO_CLK_ENABLE(__JOY__) do { if((__JOY__) == JOY_SEL) { SEL_JOY_GPIO_CLK_ENABLE(); } else \ |
||||
if((__JOY__) == JOY_DOWN) { DOWN_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_LEFT) { LEFT_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_RIGHT) { RIGHT_JOY_GPIO_CLK_ENABLE(); } else \
|
||||
if((__JOY__) == JOY_UP) { UP_JOY_GPIO_CLK_ENABLE(); } } while(0) |
||||
|
||||
#define JOYx_GPIO_CLK_DISABLE(__JOY__) do { if((__JOY__) == JOY_SEL) { SEL_JOY_GPIO_CLK_DISABLE(); } else \ |
||||
if((__JOY__) == JOY_DOWN) { DOWN_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_LEFT) { LEFT_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_RIGHT) { RIGHT_JOY_GPIO_CLK_DISABLE(); } else \
|
||||
if((__JOY__) == JOY_UP) { UP_JOY_GPIO_CLK_DISABLE(); } } while(0) |
||||
|
||||
#define JOY_ALL_PINS (RIGHT_JOY_PIN | LEFT_JOY_PIN | UP_JOY_PIN | DOWN_JOY_PIN | SEL_JOY_PIN) |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L4R9I_DISCOVERY_COM COM Constants
|
||||
* @{ |
||||
*/ |
||||
#define COMn 1 |
||||
|
||||
/**
|
||||
* @brief Definition for COM port1, connected to USART2 (ST-Link USB Virtual Com Port) |
||||
*/
|
||||
#define DISCOVERY_COM1 USART2 |
||||
#define DISCOVERY_COM1_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE() |
||||
#define DISCOVERY_COM1_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE() |
||||
|
||||
#define DISCOVERY_COM1_TX_PIN GPIO_PIN_2 |
||||
#define DISCOVERY_COM1_TX_GPIO_PORT GPIOA |
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() |
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() |
||||
#define DISCOVERY_COM1_TX_AF GPIO_AF7_USART2 |
||||
|
||||
#define DISCOVERY_COM1_RX_PIN GPIO_PIN_6 |
||||
#define DISCOVERY_COM1_RX_GPIO_PORT GPIOD |
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() |
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() |
||||
#define DISCOVERY_COM1_RX_AF GPIO_AF7_USART2 |
||||
|
||||
#define DISCOVERY_COM1_IRQn USART2_IRQn |
||||
|
||||
|
||||
#define DISCOVERY_COMx_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_CLK_ENABLE();}} while(0) |
||||
#define DISCOVERY_COMx_CLK_DISABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_CLK_DISABLE();}} while(0) |
||||
|
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_TX_GPIO_CLK_ENABLE();}} while(0) |
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_DISABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_TX_GPIO_CLK_DISABLE();}} while(0) |
||||
|
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_RX_GPIO_CLK_ENABLE();}} while(0) |
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_DISABLE(__INDEX__) do { if((__INDEX__) == COM1) {DISCOVERY_COM1_RX_GPIO_CLK_DISABLE();}} while(0) |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_BUS BUS Constants
|
||||
* @{ |
||||
*/ |
||||
|
||||
#if defined(HAL_I2C_MODULE_ENABLED) |
||||
/*##################### I2C1 ###################################*/ |
||||
/* User can use this section to tailor I2C1 instance used and associated
|
||||
resources */ |
||||
/* Definition for I2C1 Pins */ |
||||
#define DISCOVERY_I2C1_SCL_GPIO_PORT GPIOG |
||||
#define DISCOVERY_I2C1_SDA_GPIO_PORT GPIOG |
||||
#define DISCOVERY_I2C1_SCL_PIN GPIO_PIN_14 |
||||
#define DISCOVERY_I2C1_SDA_PIN GPIO_PIN_13 |
||||
|
||||
#define DISCOVERY_I2C1_SCL_SDA_AF GPIO_AF4_I2C1 |
||||
|
||||
/* Definition for I2C1 clock resources */ |
||||
#define DISCOVERY_I2C1 I2C1 |
||||
#define DISCOVERY_I2C1_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE() |
||||
#define DISCOVERY_I2C1_CLK_DISABLE() __HAL_RCC_I2C1_CLK_DISABLE() |
||||
#define DISCOVERY_I2C1_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() |
||||
#define DISCOVERY_I2C1_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() |
||||
#define DISCOVERY_I2C1_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() |
||||
#define DISCOVERY_I2C1_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() |
||||
#define DISCOVERY_I2C1_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET() |
||||
#define DISCOVERY_I2C1_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET() |
||||
|
||||
/* Definition for I2C1's NVIC */ |
||||
#define DISCOVERY_I2C1_EV_IRQn I2C1_EV_IRQn |
||||
#define DISCOVERY_I2C1_EV_IRQHandler I2C1_EV_IRQHandler |
||||
#define DISCOVERY_I2C1_ER_IRQn I2C1_ER_IRQn |
||||
#define DISCOVERY_I2C1_ER_IRQHandler I2C1_ER_IRQHandler |
||||
|
||||
/* I2C TIMING Register define when I2C clock source is SYSCLK */ |
||||
/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 80 MHz */ |
||||
/* Set 0x90112626 value to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */ |
||||
#ifndef DISCOVERY_I2C1_TIMING |
||||
#define DISCOVERY_I2C1_TIMING 0x90D00e28/* 0x90112626*/ |
||||
#endif /* DISCOVERY_I2C1_TIMING */ |
||||
|
||||
/* I2C clock speed configuration (in Hz)
|
||||
WARNING: |
||||
Make sure that this define is not already declared in other files (ie. |
||||
stm324xg_discovery.h file). It can be used in parallel by other modules. */ |
||||
#ifndef BSP_I2C_SPEED |
||||
#define BSP_I2C_SPEED 100000 |
||||
#endif /* BSP_I2C_SPEED */ |
||||
|
||||
/* Maximum Timeout values for flags waiting loops. These timeouts are not based
|
||||
on accurate values, they just guarantee that the application will not remain |
||||
stuck if the I2C communication is corrupted. |
||||
You may modify these timeout values depending on CPU frequency and application |
||||
conditions (interrupts routines ...). */ |
||||
#define DISCOVERY_I2C1_TIMEOUT_MAX 3000 |
||||
|
||||
|
||||
/*##################### I2C2 ###################################*/ |
||||
/* User can use this section to tailor I2C2 instance used and associated
|
||||
resources */ |
||||
/* Definition for I2C2 Pins */ |
||||
#define DISCOVERY_I2C2_SCL_PIN GPIO_PIN_4 |
||||
#define DISCOVERY_I2C2_SCL_GPIO_PORT GPIOH |
||||
#define DISCOVERY_I2C2_SDA_PIN GPIO_PIN_14 |
||||
#define DISCOVERY_I2C2_SDA_GPIO_PORT GPIOB |
||||
#define DISCOVERY_I2C2_SCL_SDA_AF GPIO_AF4_I2C2 |
||||
/* Definition for I2C2 clock resources */ |
||||
#define DISCOVERY_I2C2 I2C2 |
||||
#define DISCOVERY_I2C2_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() |
||||
#define DISCOVERY_I2C2_CLK_DISABLE() __HAL_RCC_I2C2_CLK_DISABLE() |
||||
#define DISCOVERY_I2C2_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
#define DISCOVERY_I2C2_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define DISCOVERY_I2C2_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() |
||||
#define DISCOVERY_I2C2_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
#define DISCOVERY_I2C2_FORCE_RESET() __HAL_RCC_I2C2_FORCE_RESET() |
||||
#define DISCOVERY_I2C2_RELEASE_RESET() __HAL_RCC_I2C2_RELEASE_RESET() |
||||
|
||||
/* Definition for I2C2's NVIC */ |
||||
#define DISCOVERY_I2C2_EV_IRQn I2C2_EV_IRQn |
||||
#define DISCOVERY_I2C2_ER_IRQn I2C2_ER_IRQn |
||||
|
||||
/* I2C TIMING Register define when I2C clock source is SYSCLK */ |
||||
/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 80 MHz */ |
||||
/* Set 0x90112626 value to reach 100 KHz speed (Rise time = 25ns, Fall time = 10ns) */ |
||||
#ifndef DISCOVERY_I2C2_TIMING |
||||
#define DISCOVERY_I2C2_TIMING 0x40403E5D |
||||
#endif /* DISCOVERY_I2C2_TIMING */ |
||||
|
||||
#define IDD_I2C_ADDRESS ((uint16_t) 0x84) |
||||
#define IO1_I2C_ADDRESS ((uint16_t) 0x84) |
||||
#define AUDIO_I2C_ADDRESS ((uint16_t) 0x94) |
||||
#define TS_I2C_ADDRESS ((uint16_t) 0x70) |
||||
#define CAMERA_I2C_ADDRESS ((uint16_t) 0x60) |
||||
|
||||
/* Maximum Timeout values for flags waiting loops. These timeouts are not based
|
||||
on accurate values, they just guarantee that the application will not remain |
||||
stuck if the I2C communication is corrupted. |
||||
You may modify these timeout values depending on CPU frequency and application |
||||
conditions (interrupts routines ...). */ |
||||
#define DISCOVERY_I2C2_TIMEOUT_MAX 3000 |
||||
|
||||
|
||||
#ifndef DISCOVERY_I2C_TIMING |
||||
#define DISCOVERY_I2C_TIMING /*0x90D00e28*/ 0x90112626 |
||||
#endif /* DISCOVERY_I2C2_TIMING */ |
||||
|
||||
/* Written here after to enable compilation only, to be thoroughly reviewed */ |
||||
|
||||
/* Definition for AUDIO I2Cx resources */ |
||||
#define DISCOVERY_AUDIO_I2Cx I2C1 |
||||
#define DISCOVERY_AUDIO_I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE() |
||||
#define DISCOVERY_AUDIO_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() |
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
|
||||
#define DISCOVERY_AUDIO_I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET() |
||||
#define DISCOVERY_AUDIO_I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET() |
||||
|
||||
/* Definition for I2Cx Pins */ |
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_PIN GPIO_PIN_6 |
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT GPIOB |
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF GPIO_AF4_I2C1 |
||||
#define DISCOVERY_AUDIO_I2Cx_SDA_PIN GPIO_PIN_7 |
||||
|
||||
/* I2C interrupt requests */ |
||||
#define DISCOVERY_AUDIO_I2Cx_EV_IRQn I2C1_EV_IRQn |
||||
#define DISCOVERY_AUDIO_I2Cx_ER_IRQn I2C1_ER_IRQn |
||||
|
||||
|
||||
/* Definition for TS (Capacitive Touch Panel) I2Cx resources */ |
||||
#define DISCOVERY_TS_I2Cx I2C2 |
||||
#define DISCOVERY_TS_I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() |
||||
#define DISCOVERY_TS_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() |
||||
#define DISCOVERY_TS_I2Cx_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
#define DISCOVERY_TS_I2Cx_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() |
||||
#define DISCOVERY_TS_I2Cx_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define DISCOVERY_TS_I2Cx_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
|
||||
#define DISCOVERY_TS_I2Cx_FORCE_RESET() __HAL_RCC_I2C2_FORCE_RESET() |
||||
#define DISCOVERY_TS_I2Cx_RELEASE_RESET() __HAL_RCC_I2C2_RELEASE_RESET() |
||||
|
||||
/* Definition for I2Cx Pins */ |
||||
#define DISCOVERY_TS_I2Cx_SCL_PIN GPIO_PIN_4 |
||||
#define DISCOVERY_TS_I2Cx_SCL_GPIO_PORT GPIOH |
||||
#define DISCOVERY_TS_I2Cx_SDA_PIN GPIO_PIN_14 |
||||
#define DISCOVERY_TS_I2Cx_SDA_GPIO_PORT GPIOB |
||||
#define DISCOVERY_TS_I2Cx_SCL_SDA_AF GPIO_AF4_I2C2 |
||||
|
||||
/* I2C interrupt requests */ |
||||
#define DISCOVERY_TS_I2Cx_EV_IRQn I2C2_EV_IRQn |
||||
#define DISCOVERY_TS_I2Cx_ER_IRQn I2C2_ER_IRQn |
||||
|
||||
/* I2C clock setting */ |
||||
#define DISCOVERY_TS_RCC_PERIPHCLK_I2C RCC_PERIPHCLK_I2C2 |
||||
#define DISCOVERY_TS_RCC_CLKSOURCE_I2C RCC_I2C2CLKSOURCE_SYSCLK |
||||
|
||||
|
||||
|
||||
/* Definition for Camera I2Cx resources */ |
||||
#define DISCOVERY_CAMERA_I2Cx I2C2 |
||||
#define DISCOVERY_CAMERA_I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() |
||||
#define DISCOVERY_CAMERA_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() |
||||
#define DISCOVERY_CAMERA_I2Cx_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
#define DISCOVERY_CAMERA_I2Cx_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() |
||||
#define DISCOVERY_CAMERA_I2Cx_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define DISCOVERY_CAMERA_I2Cx_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
|
||||
#define DISCOVERY_CAMERA_I2Cx_FORCE_RESET() __HAL_RCC_I2C2_FORCE_RESET() |
||||
#define DISCOVERY_CAMERA_I2Cx_RELEASE_RESET() __HAL_RCC_I2C2_RELEASE_RESET() |
||||
|
||||
/* Definition for I2Cx Pins */ |
||||
#define DISCOVERY_CAMERA_I2Cx_SCL_PIN GPIO_PIN_4 |
||||
#define DISCOVERY_CAMERA_I2Cx_SCL_GPIO_PORT GPIOH |
||||
#define DISCOVERY_CAMERA_I2Cx_SDA_PIN GPIO_PIN_14 |
||||
#define DISCOVERY_CAMERA_I2Cx_SDA_GPIO_PORT GPIOB |
||||
#define DISCOVERY_CAMERA_I2Cx_SCL_SDA_AF GPIO_AF4_I2C2 |
||||
|
||||
/* I2C interrupt requests */ |
||||
#define DISCOVERY_CAMERA_I2Cx_EV_IRQn I2C2_EV_IRQn |
||||
#define DISCOVERY_CAMERA_I2Cx_ER_IRQn I2C2_ER_IRQn |
||||
|
||||
/* I2C clock setting */ |
||||
#define DISCOVERY_CAMERA_RCC_PERIPHCLK_I2C RCC_PERIPHCLK_I2C2 |
||||
#define DISCOVERY_CAMERA_RCC_CLKSOURCE_I2C RCC_I2C2CLKSOURCE_SYSCLK |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Definition for external, camera and Arduino connector I2Cx resources */ /* to be reviewed */ |
||||
#define DISCOVERY_EXT_I2Cx I2C2 |
||||
#define DISCOVERY_EXT_I2Cx_CLK_ENABLE() __HAL_RCC_I2C2_CLK_ENABLE() |
||||
#define DISCOVERY_EXT_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() |
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
||||
|
||||
#define DISCOVERY_EXT_I2Cx_FORCE_RESET() __HAL_RCC_I2C2_FORCE_RESET() |
||||
#define DISCOVERY_EXT_I2Cx_RELEASE_RESET() __HAL_RCC_I2C2_RELEASE_RESET() |
||||
|
||||
/* Definition for I2Cx Pins */ |
||||
#define DISCOVERY_EXT_I2Cx_SCL_PIN GPIO_PIN_10 |
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT GPIOB |
||||
#define DISCOVERY_EXT_I2Cx_SCL_AF GPIO_AF4_I2C2 |
||||
#define DISCOVERY_EXT_I2Cx_SDA_AF GPIO_AF4_I2C2 |
||||
#define DISCOVERY_EXT_I2Cx_SDA_PIN GPIO_PIN_9 |
||||
|
||||
/* I2C interrupt requests */ |
||||
#define DISCOVERY_EXT_I2Cx_EV_IRQn I2C2_EV_IRQn |
||||
#define DISCOVERY_EXT_I2Cx_ER_IRQn I2C2_ER_IRQn |
||||
|
||||
#ifndef DISCOVERY_I2C_SPEED |
||||
#define DISCOVERY_I2C_SPEED 100000 |
||||
#endif /* DISCOVERY_I2C_SPEED */ |
||||
|
||||
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */ |
||||
|
||||
|
||||
|
||||
/*##################### Audio Codec ##########################*/ |
||||
/**
|
||||
* @brief Audio codec chip reset definition |
||||
*/ |
||||
/* Audio codec power on/off macro definition */ |
||||
#define CODEC_AUDIO_POWER_OFF() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET) |
||||
#define CODEC_AUDIO_POWER_ON() HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_SET) |
||||
|
||||
/* Audio Reset Pin definition */ |
||||
#define AUDIO_RESET_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() |
||||
#define AUDIO_RESET_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() |
||||
#define AUDIO_RESET_PIN GPIO_PIN_6 |
||||
#define AUDIO_RESET_GPIO GPIOC |
||||
|
||||
|
||||
|
||||
|
||||
/*##################### MFX ##########################*/ |
||||
/**
|
||||
* @brief MFX interface pins |
||||
*/ |
||||
|
||||
#define MFX_INT_GPIO_PORT GPIOC /* GPIOC */ |
||||
#define MFX_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() |
||||
#define MFX_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() |
||||
#define MFX_INT_PIN GPIO_PIN_5 /* PC.05 */ |
||||
#define MFX_INT_EXTI_IRQn EXTI9_5_IRQn |
||||
|
||||
#define MFX_WAKEUP_GPIO_PORT GPIOH /* GPIOH */ |
||||
#define MFX_WAKEUP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define MFX_WAKEUP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
#define MFX_WAKEUP_PIN GPIO_PIN_6 /* PH.06 */ |
||||
|
||||
|
||||
|
||||
/* Legacy */ |
||||
#define IDD_INT_GPIO_PORT MFX_INT_GPIO_PORT |
||||
#define IDD_INT_GPIO_CLK_ENABLE() MFX_INT_GPIO_CLK_ENABLE() |
||||
#define IDD_INT_GPIO_CLK_DISABLE() MFX_INT_GPIO_CLK_DISABLE() |
||||
#define IDD_INT_PIN MFX_INT_PIN |
||||
#define IDD_INT_EXTI_IRQn MFX_INT_EXTI_IRQn |
||||
#define IDD_WAKEUP_GPIO_PORT MFX_WAKEUP_GPIO_PORT |
||||
#define IDD_WAKEUP_GPIO_CLK_ENABLE() MFX_WAKEUP_GPIO_CLK_ENABLE() |
||||
#define IDD_WAKEUP_GPIO_CLK_DISABLE() MFX_WAKEUP_GPIO_CLK_DISABLE() |
||||
#define IDD_WAKEUP_PIN MFX_WAKEUP_PIN |
||||
|
||||
|
||||
/**
|
||||
* @brief Idd current measurement interface pins on MFX |
||||
*/ |
||||
#define IDD_AMP_CONTROL_PIN AGPIO_PIN_1 |
||||
|
||||
/**
|
||||
* @brief TS INT pin |
||||
*/ |
||||
#define TS_INT_PIN GPIO_PIN_14 |
||||
#define TS_INT_GPIO_PORT GPIOG |
||||
#define TS_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() |
||||
#define TS_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() |
||||
#define TS_INT_EXTI_IRQn EXTI15_10_IRQn |
||||
|
||||
/**
|
||||
* @brief TS RST pin |
||||
*/ |
||||
/* TS RST is accessed thru the MFX */ |
||||
#define TS_RST_PIN IO1_PIN_1 |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint32_t BSP_GetVersion(void); |
||||
void BSP_LED_Init(Led_TypeDef Led); |
||||
void BSP_LED_DeInit(Led_TypeDef Led); |
||||
void BSP_LED_On(Led_TypeDef Led); |
||||
void BSP_LED_Off(Led_TypeDef Led); |
||||
void BSP_LED_Toggle(Led_TypeDef Led); |
||||
uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode); |
||||
void BSP_JOY_DeInit(void); |
||||
JOYState_TypeDef BSP_JOY_GetState(void); |
||||
#if defined(HAL_UART_MODULE_ENABLED) |
||||
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *husart); |
||||
void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart); |
||||
#endif /* HAL_UART_MODULE_ENABLED */ |
||||
|
||||
/* These __weak functions can be surcharged by application code for specific application needs */ |
||||
void BSP_ErrorHandler(void); |
||||
|
||||
|
||||
void FMC_BANK1_MspInit(void); |
||||
void FMC_BANK1_MspDeInit(void); |
||||
#if defined(HAL_I2C_MODULE_ENABLED) |
||||
void I2C2_Init(void); |
||||
void I2C2_DeInit(void); |
||||
#endif /* HAL_I2C_MODULE_ENABLED */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,270 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_audio.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_audio.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_AUDIO_H |
||||
#define __STM32L496G_DISCOVERY_AUDIO_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#if defined(BSP_AUDIO_USE_RTOS) |
||||
#include "k_mem.h" |
||||
#else |
||||
#include <stdlib.h> |
||||
#endif |
||||
/* Include audio component Driver */ |
||||
#include "../Components/cs42l51/cs42l51.h" |
||||
#include "stm32l496g_discovery.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_AUDIO
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_AUDIO_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
typedef void (*Audio_CallbackTypeDef)(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_AUDIO_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
/** @defgroup BSP_Audio_Out_Option BSP Audio Out Option
|
||||
* @{ |
||||
*/ |
||||
#define BSP_AUDIO_OUT_CIRCULARMODE ((uint32_t)0x00000001) /* BUFFER CIRCULAR MODE */ |
||||
#define BSP_AUDIO_OUT_NORMALMODE ((uint32_t)0x00000002) /* BUFFER NORMAL MODE */ |
||||
#define BSP_AUDIO_OUT_STEREOMODE ((uint32_t)0x00000004) /* STEREO MODE */ |
||||
#define BSP_AUDIO_OUT_MONOMODE ((uint32_t)0x00000008) /* MONO MODE */ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup BSP_Audio_Sample_Rate BSP Audio Sample Rate
|
||||
* @{ |
||||
*/ |
||||
#define BSP_AUDIO_FREQUENCY_96K SAI_AUDIO_FREQUENCY_96K |
||||
#define BSP_AUDIO_FREQUENCY_48K SAI_AUDIO_FREQUENCY_48K |
||||
#define BSP_AUDIO_FREQUENCY_44K SAI_AUDIO_FREQUENCY_44K |
||||
#define BSP_AUDIO_FREQUENCY_32K SAI_AUDIO_FREQUENCY_32K |
||||
#define BSP_AUDIO_FREQUENCY_22K SAI_AUDIO_FREQUENCY_22K |
||||
#define BSP_AUDIO_FREQUENCY_16K SAI_AUDIO_FREQUENCY_16K |
||||
#define BSP_AUDIO_FREQUENCY_11K SAI_AUDIO_FREQUENCY_11K |
||||
#define BSP_AUDIO_FREQUENCY_8K SAI_AUDIO_FREQUENCY_8K |
||||
/**
|
||||
* @} |
||||
*/ |
||||
/*------------------------------------------------------------------------------
|
||||
USER SAI defines parameters |
||||
-----------------------------------------------------------------------------*/ |
||||
/* SAI peripheral configuration defines */ |
||||
#define AUDIO_SAIx_TX_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE() |
||||
#define AUDIO_SAIx_TX_CLK_DISABLE() __HAL_RCC_SAI1_CLK_DISABLE() |
||||
#define AUDIO_SAIx_TX_MCK_SCK_SD_FS_AF GPIO_AF13_SAI1 |
||||
|
||||
#define AUDIO_SAIx_TX_MCK_SCK_SD_FS_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() |
||||
#define AUDIO_SAIx_TX_MCK_SCK_SD_FS_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() |
||||
#define AUDIO_SAIx_TX_FS_PIN GPIO_PIN_4 |
||||
#define AUDIO_SAIx_TX_SCK_PIN GPIO_PIN_5 |
||||
#define AUDIO_SAIx_TX_SD_PIN GPIO_PIN_6 |
||||
#define AUDIO_SAIx_TX_MCK_PIN GPIO_PIN_2 |
||||
#define AUDIO_SAIx_TX_MCK_SCK_SD_FS_GPIO_PORT GPIOE |
||||
|
||||
/* SAI DMA Channel definitions */ |
||||
#define AUDIO_SAIx_DMAx_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE() |
||||
#define AUDIO_SAIx_DMAx_CLK_DISABLE() __HAL_RCC_DMA2_CLK_DISABLE() |
||||
#define AUDIO_SAIx_DMAx_CHANNEL DMA2_Channel1 |
||||
#define AUDIO_SAIx_DMAx_IRQ DMA2_Channel1_IRQn |
||||
#define AUDIO_SAIx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD |
||||
#define AUDIO_SAIx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD |
||||
#define DMA_MAX_SZE (uint32_t)0xFFFF |
||||
|
||||
#define AUDIO_SAIx_DMAx_IRQHandler DMA2_Channel1_IRQHandler |
||||
|
||||
/* Select the interrupt preemption priority for the DMA interrupt */ |
||||
#define AUDIO_OUT_IRQ_PREPRIO 5 /* Select the preemption priority level(0 is the highest) */ |
||||
|
||||
/* Disable SAIx PLL */ |
||||
#define AUDIO_SAIx_PLL_DISABLE() HAL_RCCEx_DisablePLLSAI2() |
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
AUDIO IN CONFIGURATION |
||||
------------------------------------------------------------------------------*/ |
||||
/* DFSDM Configuration defines */ |
||||
#define AUDIO_DFSDMx_LEFT_CHANNEL DFSDM1_Channel2 |
||||
#define AUDIO_DFSDMx_LEFT_FILTER DFSDM1_Filter0 |
||||
#define AUDIO_DFSDMx_CLK_ENABLE() __HAL_RCC_DFSDM1_CLK_ENABLE() |
||||
#define AUDIO_DFSDMx_CLK_DISABLE() __HAL_RCC_DFSDM1_CLK_DISABLE() |
||||
#define AUDIO_DFSDMx_CKOUT_PIN GPIO_PIN_9 |
||||
#define AUDIO_DFSDMx_DMIC_DATIN_PIN GPIO_PIN_7 |
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_PORT GPIOE |
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() |
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() |
||||
#define AUDIO_DFSDMx_CKOUT_DMIC_DATIN_AF GPIO_AF6_DFSDM1 |
||||
|
||||
/* DFSDM DMA Right and Left channels definitions */ |
||||
#define AUDIO_DFSDMx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() |
||||
#define AUDIO_DFSDMx_DMAx_CLK_DISABLE() __HAL_RCC_DMA1_CLK_DISABLE() |
||||
#define AUDIO_DFSDMx_DMAx_LEFT_CHANNEL DMA1_Channel4 |
||||
#define AUDIO_DFSDMx_DMAx_LEFT_IRQ DMA1_Channel4_IRQn |
||||
#define AUDIO_DFSDM_DMAx_LEFT_IRQHandler DMA1_Channel4_IRQHandler |
||||
#define AUDIO_DFSDMx_DMAx_RIGHT_CHANNEL DMA1_Channel5 |
||||
#define AUDIO_DFSDMx_DMAx_RIGHT_IRQ DMA1_Channel5_IRQn |
||||
#define AUDIO_DFSDM_DMAx_RIGHT_IRQHandler DMA1_Channel5_IRQHandler |
||||
#define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_WORD |
||||
#define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_WORD |
||||
|
||||
|
||||
/* Select the interrupt preemption priority and subpriority for the IT/DMA interrupt */ |
||||
#define AUDIO_IN_IRQ_PREPRIO 6 /* Select the preemption priority level(0 is the highest) */ |
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
CONFIGURATION: Audio Driver Configuration parameters |
||||
------------------------------------------------------------------------------*/ |
||||
|
||||
#define AUDIODATA_SIZE 2 /* 16-bits audio data size */ |
||||
|
||||
/* Audio status definition */ |
||||
#define AUDIO_OK 0 |
||||
#define AUDIO_ERROR 1 |
||||
#define AUDIO_TIMEOUT 2 |
||||
|
||||
/* Audio out parameters */ |
||||
#define DEFAULT_AUDIO_OUT_FREQ BSP_AUDIO_FREQUENCY_48K |
||||
#define DEFAULT_AUDIO_OUT_BIT_RESOLUTION ((uint8_t)16) |
||||
#define DEFAULT_AUDIO_OUT_CHANNEL_NBR ((uint8_t)2) /* Mono = 1, Stereo = 2 */ |
||||
#define DEFAULT_AUDIO_OUT_VOLUME ((uint16_t)80) |
||||
|
||||
/* AudioFreq * DataSize (2 bytes) * NumChannels (Stereo: 2) */ |
||||
#define DEFAULT_AUDIO_IN_FREQ BSP_AUDIO_FREQUENCY_16K |
||||
#define DEFAULT_AUDIO_IN_BIT_RESOLUTION 16 |
||||
#define DEFAULT_AUDIO_IN_CHANNEL_NBR 1 /* Mono = 1, Stereo = 2 */ |
||||
#define DEFAULT_AUDIO_IN_VOLUME 80 |
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
OPTIONAL Configuration defines parameters |
||||
------------------------------------------------------------------------------*/ |
||||
|
||||
/* Delay for the Codec to be correctly reset */ |
||||
#define CODEC_RESET_DELAY 5 |
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
INPUT DEVICES definition |
||||
------------------------------------------------------------------------------*/ |
||||
/* MP34DT01TR digital microphone on PCB top side */ |
||||
#define INPUT_DEVICE_DIGITAL_MIC1 0x20 /* Left microphone */ |
||||
#define INPUT_DEVICE_DIGITAL_MIC2 0x40 /* Right microphone */ |
||||
#define INPUT_DEVICE_DIGITAL_MIC (INPUT_DEVICE_DIGITAL_MIC1 | INPUT_DEVICE_DIGITAL_MIC2) |
||||
/* Analog microphone input from 3.5 audio jack connector */ |
||||
#define INPUT_DEVICE_ANALOG_MIC INPUT_DEVICE_MIC1 |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_AUDIO_Exported_Variables Exported Variables
|
||||
* @{ |
||||
*/ |
||||
extern SAI_HandleTypeDef BSP_AUDIO_hSai_Tx; |
||||
extern SAI_HandleTypeDef BSP_AUDIO_hSai_Rx; |
||||
extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmLeftFilter; |
||||
extern DFSDM_Filter_HandleTypeDef BSP_AUDIO_hDfsdmRightFilter; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_AUDIO_Exported_Macros Exported Macros
|
||||
* @{ |
||||
*/ |
||||
#define DMA_MAX(_X_) (((_X_) <= DMA_MAX_SZE)? (_X_):DMA_MAX_SZE) |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
/** @defgroup STM32L496G_DISCOVERY_AUDIO_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq); |
||||
uint8_t BSP_AUDIO_OUT_DeInit(void); |
||||
uint8_t BSP_AUDIO_OUT_Play(uint16_t *pData, uint32_t Size); |
||||
uint8_t BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size); |
||||
uint8_t BSP_AUDIO_OUT_Pause(void); |
||||
uint8_t BSP_AUDIO_OUT_Resume(void); |
||||
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option); |
||||
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume); |
||||
uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq); |
||||
void BSP_AUDIO_OUT_ChangeAudioConfig(uint32_t AudioOutOption); |
||||
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd); |
||||
uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output); |
||||
void BSP_AUDIO_OUT_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, |
||||
Audio_CallbackTypeDef HalfTransferCallback, |
||||
Audio_CallbackTypeDef TransferCompleteCallback); |
||||
|
||||
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); |
||||
uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr); |
||||
uint8_t BSP_AUDIO_IN_DeInit(void); |
||||
uint8_t BSP_AUDIO_IN_Record(uint16_t *pData, uint32_t Size); |
||||
uint8_t BSP_AUDIO_IN_SetFrequency(uint32_t AudioFreq); |
||||
uint8_t BSP_AUDIO_IN_Stop(void); |
||||
uint8_t BSP_AUDIO_IN_Pause(void); |
||||
uint8_t BSP_AUDIO_IN_Resume(void); |
||||
void BSP_AUDIO_IN_RegisterCallbacks(Audio_CallbackTypeDef ErrorCallback, |
||||
Audio_CallbackTypeDef HalfTransferCallback, |
||||
Audio_CallbackTypeDef TransferCompleteCallback); |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_AUDIO_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,614 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_camera.c |
||||
* @author MCD Application Team |
||||
* @brief This file includes the driver for Camera modules mounted on |
||||
* STM32L496G-Discovery board. |
||||
@verbatim |
||||
How to use this driver: |
||||
------------------------ |
||||
- This driver is used to drive the camera. |
||||
- The OV9655 component driver MUST be included with this driver. |
||||
|
||||
Driver description: |
||||
------------------- |
||||
+ Initialization steps: |
||||
o Initialize the camera using the BSP_CAMERA_Init() function. |
||||
o Start the camera capture/snapshot using the CAMERA_Start() function. |
||||
o Suspend, resume or stop the camera capture using the following functions: |
||||
- BSP_CAMERA_Suspend() |
||||
- BSP_CAMERA_Resume() |
||||
- BSP_CAMERA_Stop() |
||||
|
||||
+ Options |
||||
o Increase or decrease on the fly the brightness and/or contrast |
||||
using the following function: |
||||
- BSP_CAMERA_ContrastBrightnessConfig |
||||
o Add a special effect on the fly using the following functions: |
||||
- BSP_CAMERA_BlackWhiteConfig() |
||||
- BSP_CAMERA_ColorEffectConfig() |
||||
@endverbatim |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery_camera.h" |
||||
#include "stm32l496g_discovery.h" |
||||
#include "stm32l496g_discovery_io.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_CAMERA
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Private_TypesDefinitions STM32L496G_DISCOVERY_CAMERA Private Types Definitions
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Private_Defines STM32L496G_DISCOVERY_CAMERA Private Defines
|
||||
* @{ |
||||
*/ |
||||
#define CAMERA_VGA_RES_X 640 |
||||
#define CAMERA_VGA_RES_Y 480 |
||||
#define CAMERA_480x272_RES_X 480 |
||||
#define CAMERA_480x272_RES_Y 272 |
||||
#define CAMERA_QVGA_RES_X 320 |
||||
#define CAMERA_QVGA_RES_Y 240 |
||||
#define CAMERA_QQVGA_RES_X 160 |
||||
#define CAMERA_QQVGA_RES_Y 120 |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Private_Macros STM32L496G_DISCOVERY_CAMERA Private Macros
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Private_Variables STM32L496G_DISCOVERY_CAMERA Private Variables
|
||||
* @{ |
||||
*/ |
||||
DCMI_HandleTypeDef hDcmiHandler; |
||||
CAMERA_DrvTypeDef *camera_drv; |
||||
/* Camera current resolution naming (QQVGA, VGA, ...) */ |
||||
static uint32_t CameraCurrentResolution; |
||||
|
||||
/* Camera module I2C HW address */ |
||||
static uint32_t CameraHwAddress; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Private_FunctionPrototypes STM32L496G_DISCOVERY_CAMERA Private Function Prototypes
|
||||
* @{ |
||||
*/ |
||||
static uint32_t GetSize(uint32_t resolution); |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Exported_Functions STM32L496G_DISCOVERY_CAMERA Exported Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes the camera. |
||||
* @param Resolution : camera sensor requested resolution (x, y) : standard resolution |
||||
* naming QQVGA, QVGA, VGA ... |
||||
* @retval Camera status |
||||
*/ |
||||
uint8_t BSP_CAMERA_Init(uint32_t Resolution) |
||||
{ |
||||
DCMI_HandleTypeDef *phdcmi; |
||||
uint8_t status = CAMERA_ERROR; |
||||
|
||||
/* Get the DCMI handle structure */ |
||||
phdcmi = &hDcmiHandler; |
||||
|
||||
|
||||
/* Initialize the IO functionalities */ |
||||
BSP_IO_Init(); |
||||
|
||||
|
||||
/*** Configures the DCMI to interface with the camera module ***/ |
||||
/* DCMI configuration */ |
||||
phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; |
||||
phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_HIGH; |
||||
phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; |
||||
phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_HIGH; |
||||
phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; |
||||
phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; |
||||
phdcmi->Init.ByteSelectMode = DCMI_BSM_ALL; |
||||
phdcmi->Init.LineSelectMode = DCMI_LSM_ALL; |
||||
phdcmi->Instance = DCMI; |
||||
|
||||
/* Camera initialization */ |
||||
BSP_CAMERA_MspInit(&hDcmiHandler, NULL); |
||||
|
||||
/* Read ID of Camera module via I2C */ |
||||
if (ov9655_ReadID(CAMERA_I2C_ADDRESS) == OV9655_ID) |
||||
{ |
||||
/* Initialize the camera driver structure */ |
||||
camera_drv = &ov9655_drv; |
||||
CameraHwAddress = CAMERA_I2C_ADDRESS; |
||||
|
||||
/* DCMI Initialization */ |
||||
HAL_DCMI_Init(phdcmi); |
||||
|
||||
/* Camera Module Initialization via I2C to the wanted 'Resolution' */ |
||||
if (Resolution == CAMERA_R320x240) |
||||
{ |
||||
/* For 240x240 resolution, the OV9655 sensor is set to QVGA resolution
|
||||
* as OV9655 doesn't supports 240x240 resolution, |
||||
* then DCMI is configured to output a 240x240 cropped window */ |
||||
camera_drv->Init(CameraHwAddress, CAMERA_R320x240); |
||||
|
||||
|
||||
HAL_DCMI_ConfigCROP(phdcmi, |
||||
40, /* Crop in the middle of the VGA picture */ |
||||
0, /* Same height (same number of lines: no need to crop vertically) */ |
||||
(240 * 2) - 1, /* 2 pixels clock needed to capture one pixel */ |
||||
(240 * 1) - 1); /* All 240 lines are captured */ |
||||
HAL_DCMI_EnableCROP(phdcmi); |
||||
|
||||
|
||||
/* Set the RGB565 mode */ |
||||
MFX_IO_Write(CameraHwAddress, 0x12 /*OV9655_COM7*/, 0x63); |
||||
MFX_IO_Write(CameraHwAddress, 0x40 /*OV9655_COM15*/, 0x10); |
||||
/* Invert the HRef signal */ |
||||
MFX_IO_Write(CameraHwAddress, 0x15 /*OV9655_COM10*/, 0x08); |
||||
HAL_Delay(500); |
||||
} |
||||
else |
||||
{ |
||||
camera_drv->Init(CameraHwAddress, Resolution); |
||||
HAL_DCMI_DisableCROP(phdcmi); |
||||
} |
||||
|
||||
CameraCurrentResolution = Resolution; |
||||
|
||||
/* Return CAMERA_OK status */ |
||||
status = CAMERA_OK; |
||||
} |
||||
else |
||||
{ |
||||
/* Return CAMERA_NOT_SUPPORTED status */ |
||||
status = CAMERA_NOT_SUPPORTED; |
||||
} |
||||
|
||||
return status; |
||||
} |
||||
|
||||
/**
|
||||
* @brief DeInitializes the camera. |
||||
* @retval Camera status |
||||
*/ |
||||
uint8_t BSP_CAMERA_DeInit(void) |
||||
{ |
||||
hDcmiHandler.Instance = DCMI; |
||||
|
||||
HAL_DCMI_DeInit(&hDcmiHandler); |
||||
BSP_CAMERA_MspDeInit(&hDcmiHandler, NULL); |
||||
return CAMERA_OK; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Starts the camera capture in continuous mode. |
||||
* @param buff: pointer to the camera output buffer |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_ContinuousStart(uint8_t *buff) |
||||
{ |
||||
/* Start the camera capture */ |
||||
HAL_DCMI_Start_DMA(&hDcmiHandler, DCMI_MODE_CONTINUOUS, (uint32_t)buff, GetSize(CameraCurrentResolution)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Starts the camera capture in snapshot mode. |
||||
* @param buff: pointer to the camera output buffer |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_SnapshotStart(uint8_t *buff) |
||||
{ |
||||
/* Start the camera capture */ |
||||
HAL_DCMI_Start_DMA(&hDcmiHandler, DCMI_MODE_SNAPSHOT, (uint32_t)buff, GetSize(CameraCurrentResolution)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Suspend the CAMERA capture |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_Suspend(void) |
||||
{ |
||||
/* Suspend the Camera Capture */ |
||||
HAL_DCMI_Suspend(&hDcmiHandler); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Resume the CAMERA capture |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_Resume(void) |
||||
{ |
||||
/* Start the Camera Capture */ |
||||
HAL_DCMI_Resume(&hDcmiHandler); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Stop the CAMERA capture |
||||
* @retval Camera status |
||||
*/ |
||||
uint8_t BSP_CAMERA_Stop(void) |
||||
{ |
||||
uint8_t status = CAMERA_ERROR; |
||||
|
||||
if (HAL_DCMI_Stop(&hDcmiHandler) == HAL_OK) |
||||
{ |
||||
status = CAMERA_OK; |
||||
} |
||||
|
||||
/* Set Camera in Power Down */ |
||||
BSP_CAMERA_PwrDown(); |
||||
|
||||
return status; |
||||
} |
||||
|
||||
/**
|
||||
* @brief CANERA power up |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_PwrUp(void) |
||||
{ |
||||
/* De-assert the camera POWER_DOWN pin (active high) */ |
||||
BSP_IO_WritePin(CAMERA_PWR_EN_PIN, GPIO_PIN_RESET); |
||||
|
||||
HAL_Delay(3); /* POWER_DOWN de-asserted during 3ms */ |
||||
} |
||||
|
||||
/**
|
||||
* @brief CAMERA power down |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_PwrDown(void) |
||||
{ |
||||
/* Assert the camera POWER_DOWN pin (active high) */ |
||||
BSP_IO_WritePin(CAMERA_PWR_EN_PIN, GPIO_PIN_SET); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures the camera contrast and brightness. |
||||
* @param contrast_level: Contrast level |
||||
* This parameter can be one of the following values: |
||||
* @arg CAMERA_CONTRAST_LEVEL4: for contrast +2 |
||||
* @arg CAMERA_CONTRAST_LEVEL3: for contrast +1 |
||||
* @arg CAMERA_CONTRAST_LEVEL2: for contrast 0 |
||||
* @arg CAMERA_CONTRAST_LEVEL1: for contrast -1 |
||||
* @arg CAMERA_CONTRAST_LEVEL0: for contrast -2 |
||||
* @param brightness_level: Contrast level |
||||
* This parameter can be one of the following values: |
||||
* @arg CAMERA_BRIGHTNESS_LEVEL4: for brightness +2 |
||||
* @arg CAMERA_BRIGHTNESS_LEVEL3: for brightness +1 |
||||
* @arg CAMERA_BRIGHTNESS_LEVEL2: for brightness 0 |
||||
* @arg CAMERA_BRIGHTNESS_LEVEL1: for brightness -1 |
||||
* @arg CAMERA_BRIGHTNESS_LEVEL0: for brightness -2 |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_ContrastBrightnessConfig(uint32_t contrast_level, uint32_t brightness_level) |
||||
{ |
||||
if (camera_drv->Config != NULL) |
||||
{ |
||||
camera_drv->Config(CameraHwAddress, CAMERA_CONTRAST_BRIGHTNESS, contrast_level, brightness_level); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures the camera white balance. |
||||
* @param Mode: black_white mode |
||||
* This parameter can be one of the following values: |
||||
* @arg CAMERA_BLACK_WHITE_BW |
||||
* @arg CAMERA_BLACK_WHITE_NEGATIVE |
||||
* @arg CAMERA_BLACK_WHITE_BW_NEGATIVE |
||||
* @arg CAMERA_BLACK_WHITE_NORMAL |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_BlackWhiteConfig(uint32_t Mode) |
||||
{ |
||||
if (camera_drv->Config != NULL) |
||||
{ |
||||
camera_drv->Config(CameraHwAddress, CAMERA_BLACK_WHITE, Mode, 0); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures the camera color effect. |
||||
* @param Effect: Color effect |
||||
* This parameter can be one of the following values: |
||||
* @arg CAMERA_COLOR_EFFECT_ANTIQUE |
||||
* @arg CAMERA_COLOR_EFFECT_BLUE |
||||
* @arg CAMERA_COLOR_EFFECT_GREEN |
||||
* @arg CAMERA_COLOR_EFFECT_RED |
||||
* @retval None |
||||
*/ |
||||
void BSP_CAMERA_ColorEffectConfig(uint32_t Effect) |
||||
{ |
||||
if (camera_drv->Config != NULL) |
||||
{ |
||||
camera_drv->Config(CameraHwAddress, CAMERA_COLOR_EFFECT, Effect, 0); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get the capture size in pixels unit. |
||||
* @param resolution: the current resolution. |
||||
* @retval capture size in pixels unit. |
||||
*/ |
||||
static uint32_t GetSize(uint32_t resolution) |
||||
{ |
||||
uint32_t size = 0; |
||||
|
||||
/* Get capture size */ |
||||
switch (resolution) |
||||
{ |
||||
case CAMERA_R160x120: |
||||
{ |
||||
size = 0x2580; |
||||
} |
||||
break; |
||||
case CAMERA_R320x240: |
||||
{ |
||||
size = 0x9600; |
||||
} |
||||
break; |
||||
case CAMERA_R480x272: |
||||
{ |
||||
size = 0xFF00; |
||||
} |
||||
break; |
||||
case CAMERA_R640x480: |
||||
{ |
||||
size = 0x25800; |
||||
} |
||||
break; |
||||
default: |
||||
{ |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return size; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes the DCMI MSP. |
||||
* @param hdcmi: HDMI handle |
||||
* @param Params |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_MspInit(DCMI_HandleTypeDef *hdcmi, void *Params) |
||||
{ |
||||
static DMA_HandleTypeDef hdma_handler; |
||||
GPIO_InitTypeDef gpio_init_structure; |
||||
|
||||
/*** Enable peripherals and GPIO clocks ***/ |
||||
/* Enable DCMI clock */ |
||||
__HAL_RCC_DCMI_CLK_ENABLE(); |
||||
|
||||
/* Enable DMA2 clock */ |
||||
__HAL_RCC_DMA2_CLK_ENABLE(); |
||||
|
||||
/* Enable GPIO clocks */ |
||||
__HAL_RCC_GPIOA_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOE_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOH_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOI_CLK_ENABLE(); |
||||
|
||||
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_4); |
||||
__HAL_RCC_HSI48_ENABLE(); |
||||
HAL_Delay(10); // HSI48 should start in 10ms
|
||||
|
||||
|
||||
/*** Configure the GPIO ***/ |
||||
/* Configure DCMI GPIO as alternate function */ |
||||
gpio_init_structure.Pin = GPIO_PIN_5; |
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
||||
gpio_init_structure.Pull = GPIO_NOPULL; |
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
||||
gpio_init_structure.Alternate = GPIO_AF10_DCMI; |
||||
HAL_GPIO_Init(GPIOE, &gpio_init_structure); |
||||
|
||||
|
||||
gpio_init_structure.Pin = GPIO_PIN_5 | GPIO_PIN_8 | GPIO_PIN_9 | \
|
||||
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14; |
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
||||
gpio_init_structure.Pull = GPIO_NOPULL; |
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
||||
gpio_init_structure.Alternate = GPIO_AF10_DCMI; |
||||
HAL_GPIO_Init(GPIOH, &gpio_init_structure); |
||||
|
||||
gpio_init_structure.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7; |
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
||||
gpio_init_structure.Pull = GPIO_NOPULL; |
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
||||
gpio_init_structure.Alternate = GPIO_AF10_DCMI; |
||||
HAL_GPIO_Init(GPIOI, &gpio_init_structure); |
||||
|
||||
/*** Configure the DMA ***/ |
||||
/* Set the parameters to be configured */ |
||||
hdma_handler.Instance = BSP_CAMERA_DMA_INSTANCE; |
||||
|
||||
hdma_handler.Init.Request = DMA_REQUEST_0; |
||||
hdma_handler.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||||
hdma_handler.Init.PeriphInc = DMA_PINC_DISABLE; |
||||
hdma_handler.Init.MemInc = DMA_MINC_ENABLE; /* Image captured by the DCMI is stored in memory */ |
||||
hdma_handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; |
||||
hdma_handler.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
||||
hdma_handler.Init.Mode = DMA_CIRCULAR; |
||||
hdma_handler.Init.Priority = DMA_PRIORITY_HIGH; |
||||
|
||||
/* Associate the initialized DMA handle to the DCMI handle */ |
||||
__HAL_LINKDMA(hdcmi, DMA_Handle, hdma_handler); |
||||
|
||||
/*** Configure the NVIC for DCMI and DMA ***/ |
||||
/* NVIC configuration for DCMI transfer complete interrupt */ |
||||
HAL_NVIC_SetPriority(DCMI_IRQn, 0x0F, 0); |
||||
HAL_NVIC_EnableIRQ(DCMI_IRQn); |
||||
|
||||
/* NVIC configuration for DMA2D transfer complete interrupt */ |
||||
HAL_NVIC_SetPriority(DMA2_Channel6_IRQn, 0x0F, 0); |
||||
HAL_NVIC_EnableIRQ(DMA2_Channel6_IRQn); |
||||
|
||||
/* Configure the DMA stream */ |
||||
HAL_DMA_Init(hdcmi->DMA_Handle); |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the DCMI MSP. |
||||
* @param hdcmi: HDMI handle |
||||
* @param Params |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_MspDeInit(DCMI_HandleTypeDef *hdcmi, void *Params) |
||||
{ |
||||
/* Disable NVIC for DCMI transfer complete interrupt */ |
||||
HAL_NVIC_DisableIRQ(DCMI_IRQn); |
||||
|
||||
/* Disable NVIC for DMA2 transfer complete interrupt */ |
||||
HAL_NVIC_DisableIRQ(DMA2_Channel6_IRQn); |
||||
|
||||
/* Configure the DMA stream */ |
||||
HAL_DMA_DeInit(hdcmi->DMA_Handle); |
||||
|
||||
/* Disable DCMI clock */ |
||||
__HAL_RCC_DCMI_CLK_DISABLE(); |
||||
|
||||
/* GPIO pins clock and DMA clock can be shut down in the application
|
||||
by surcharging this __weak function */ |
||||
} |
||||
|
||||
/**
|
||||
* @brief Line event callback |
||||
* @param hdcmi: pointer to the DCMI handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi) |
||||
{ |
||||
BSP_CAMERA_LineEventCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Line Event callback. |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_LineEventCallback(void) |
||||
{ |
||||
/* NOTE : This function should not be modified; when the callback is needed,
|
||||
the BSP_CAMERA_LineEventCallback can be implemented in the user file |
||||
*/ |
||||
} |
||||
|
||||
/**
|
||||
* @brief VSYNC event callback |
||||
* @param hdcmi: pointer to the DCMI handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi) |
||||
{ |
||||
BSP_CAMERA_VsyncEventCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief VSYNC Event callback. |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_VsyncEventCallback(void) |
||||
{ |
||||
/* NOTE : This function should not be modified; when the callback is needed,
|
||||
the BSP_CAMERA_VsyncEventCallback can be implemented in the user file |
||||
*/ |
||||
} |
||||
|
||||
/**
|
||||
* @brief Frame event callback |
||||
* @param hdcmi: pointer to the DCMI handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) |
||||
{ |
||||
BSP_CAMERA_FrameEventCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Frame Event callback. |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_FrameEventCallback(void) |
||||
{ |
||||
/* NOTE : This function should not be modified; when the callback is needed,
|
||||
the BSP_CAMERA_FrameEventCallback can be implemented in the user file |
||||
*/ |
||||
} |
||||
|
||||
/**
|
||||
* @brief Error callback |
||||
* @param hdcmi: pointer to the DCMI handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi) |
||||
{ |
||||
BSP_CAMERA_ErrorCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Error callback. |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_CAMERA_ErrorCallback(void) |
||||
{ |
||||
/* NOTE : This function should not be modified; when the callback is needed,
|
||||
the BSP_CAMERA_ErrorCallback can be implemented in the user file |
||||
*/ |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,145 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_camera.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_camera.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_CAMERA_H |
||||
#define __STM32L496G_DISCOVERY_CAMERA_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
/* Include Camera component Driver */ |
||||
#include "../Components/ov9655/ov9655.h" |
||||
#include "stm32l496g_discovery.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_CAMERA
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Exported_Types STM32L496G_DISCOVERY_CAMERA Exported Types
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Camera State structures definition |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
CAMERA_OK = 0x00, |
||||
CAMERA_ERROR = 0x01, |
||||
CAMERA_TIMEOUT = 0x02, |
||||
CAMERA_NOT_DETECTED = 0x03, |
||||
CAMERA_NOT_SUPPORTED = 0x04 |
||||
|
||||
} |
||||
Camera_StatusTypeDef; |
||||
|
||||
#define RESOLUTION_R160x120 CAMERA_R160x120 /* QQVGA Resolution */ |
||||
#define RESOLUTION_R320x240 CAMERA_R320x240 /* QVGA Resolution */ |
||||
#define RESOLUTION_R480x272 CAMERA_R480x272 /* 480x272 Resolution */ |
||||
#define RESOLUTION_R640x480 CAMERA_R640x480 /* VGA Resolution */ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_CAMERA_Exported_Constants STM32L496G_DISCOVERY_CAMERA Exported Constants
|
||||
* @{ |
||||
*/ |
||||
#define BSP_CAMERA_IRQHandler DCMI_IRQHandler |
||||
#define BSP_CAMERA_DMA_IRQHandler DMA2_Channel6_IRQHandler |
||||
#define BSP_CAMERA_DMA_IRQn DMA2_Channel6_IRQn |
||||
#define BSP_CAMERA_DMA_INSTANCE DMA2_Channel6 |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Camera special pins |
||||
*/ |
||||
/* Camera power up pin */ |
||||
#define CAMERA_PWR_EN_PIN IO1_PIN_6 |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_CAMERA_Exported_Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_CAMERA_Init(uint32_t Resolution); |
||||
uint8_t BSP_CAMERA_DeInit(void); |
||||
void BSP_CAMERA_ContinuousStart(uint8_t *buff); |
||||
void BSP_CAMERA_SnapshotStart(uint8_t *buff); |
||||
void BSP_CAMERA_Suspend(void); |
||||
void BSP_CAMERA_Resume(void); |
||||
uint8_t BSP_CAMERA_Stop(void); |
||||
void BSP_CAMERA_PwrUp(void); |
||||
void BSP_CAMERA_PwrDown(void); |
||||
void BSP_CAMERA_LineEventCallback(void); |
||||
void BSP_CAMERA_VsyncEventCallback(void); |
||||
void BSP_CAMERA_FrameEventCallback(void); |
||||
void BSP_CAMERA_ErrorCallback(void); |
||||
|
||||
/* Camera features functions prototype */ |
||||
void BSP_CAMERA_ContrastBrightnessConfig(uint32_t contrast_level, uint32_t brightness_level); |
||||
void BSP_CAMERA_BlackWhiteConfig(uint32_t Mode); |
||||
void BSP_CAMERA_ColorEffectConfig(uint32_t Effect); |
||||
|
||||
/* These functions can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */ |
||||
void BSP_CAMERA_MspInit(DCMI_HandleTypeDef *hdcmi, void *Params); |
||||
void BSP_CAMERA_MspDeInit(DCMI_HandleTypeDef *hdcmi, void *Params); |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_CAMERA_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,379 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_idd.c |
||||
* @author MCD Application Team |
||||
* @brief This file provides a set of firmware functions to manage the |
||||
* Idd measurement driver for STM32L496G-Discovery board. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery_idd.h" |
||||
#include "stm32l496g_discovery_io.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD STM32L496G-DISCOVERY IDD
|
||||
* @brief This file includes the Idd driver for STM32L496G-DISCOVERY board. |
||||
* It allows user to measure MCU Idd current on board, especially in |
||||
* different low power modes. |
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Private_Defines Private Defines
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Private_Variables Private Variables
|
||||
* @{ |
||||
*/ |
||||
static IDD_DrvTypeDef *IddDrv; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Private_Functions Private Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Configures IDD measurement component. |
||||
* @retval IDD_OK if no problem during initialization |
||||
*/ |
||||
uint8_t BSP_IDD_Init(void) |
||||
{ |
||||
IDD_ConfigTypeDef iddconfig = {0}; |
||||
uint8_t mfxstm32l152_id = 0; |
||||
uint8_t ret = 0; |
||||
|
||||
/* wake up mfx component in case it went to standby mode */ |
||||
mfxstm32l152_idd_drv.WakeUp(IDD_I2C_ADDRESS); |
||||
HAL_Delay(5); |
||||
|
||||
/* Read ID and verify if the MFX is ready */ |
||||
mfxstm32l152_id = mfxstm32l152_idd_drv.ReadID(IDD_I2C_ADDRESS); |
||||
|
||||
if ((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2)) |
||||
{ |
||||
/* Initialize the Idd driver structure */ |
||||
IddDrv = &mfxstm32l152_idd_drv; |
||||
|
||||
/* Initialize the Idd driver */ |
||||
if (IddDrv->Init != NULL) |
||||
{ |
||||
IddDrv->Init(IDD_I2C_ADDRESS); |
||||
} |
||||
|
||||
/* Configure Idd component with default values */ |
||||
iddconfig.AmpliGain = DISCOVERY_IDD_AMPLI_GAIN; |
||||
iddconfig.VddMin = DISCOVERY_IDD_VDD_MIN; |
||||
iddconfig.Shunt0Value = DISCOVERY_IDD_SHUNT0_VALUE; |
||||
iddconfig.Shunt1Value = DISCOVERY_IDD_SHUNT1_VALUE; |
||||
iddconfig.Shunt2Value = DISCOVERY_IDD_SHUNT2_VALUE; |
||||
iddconfig.Shunt3Value = 0; |
||||
iddconfig.Shunt4Value = DISCOVERY_IDD_SHUNT4_VALUE; |
||||
iddconfig.Shunt0StabDelay = DISCOVERY_IDD_SHUNT0_STABDELAY; |
||||
iddconfig.Shunt1StabDelay = DISCOVERY_IDD_SHUNT1_STABDELAY; |
||||
iddconfig.Shunt2StabDelay = DISCOVERY_IDD_SHUNT2_STABDELAY; |
||||
iddconfig.Shunt3StabDelay = 0; |
||||
iddconfig.Shunt4StabDelay = DISCOVERY_IDD_SHUNT4_STABDELAY; |
||||
iddconfig.ShuntNbOnBoard = MFXSTM32L152_IDD_SHUNT_NB_4; |
||||
iddconfig.ShuntNbUsed = MFXSTM32L152_IDD_SHUNT_NB_4; |
||||
iddconfig.VrefMeasurement = MFXSTM32L152_IDD_VREF_AUTO_MEASUREMENT_ENABLE; |
||||
iddconfig.Calibration = MFXSTM32L152_IDD_AUTO_CALIBRATION_ENABLE; |
||||
iddconfig.PreDelayUnit = MFXSTM32L152_IDD_PREDELAY_20_MS; |
||||
iddconfig.PreDelayValue = 0x7F; |
||||
iddconfig.MeasureNb = 100; |
||||
iddconfig.DeltaDelayUnit = MFXSTM32L152_IDD_DELTADELAY_0_5_MS; |
||||
iddconfig.DeltaDelayValue = 10; |
||||
BSP_IDD_Config(iddconfig); |
||||
|
||||
ret = IDD_OK; |
||||
} |
||||
else |
||||
{ |
||||
ret = IDD_ERROR; |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Unconfigures IDD measurement component. |
||||
* @retval IDD_OK if no problem during deinitialization |
||||
*/ |
||||
void BSP_IDD_DeInit(void) |
||||
{ |
||||
if (IddDrv->DeInit != NULL) |
||||
{ |
||||
IddDrv->DeInit(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Reset Idd measurement component. |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_Reset(void) |
||||
{ |
||||
if (IddDrv->Reset != NULL) |
||||
{ |
||||
IddDrv->Reset(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Turn Idd measurement component in low power (standby/sleep) mode |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_LowPower(void) |
||||
{ |
||||
if (IddDrv->LowPower != NULL) |
||||
{ |
||||
IddDrv->LowPower(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Start Measurement campaign |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_StartMeasure(void) |
||||
{ |
||||
|
||||
/* Activate the OPAMP used ny the MFX to measure the current consumption */ |
||||
BSP_IO_ConfigPin(IDD_AMP_CONTROL_PIN, IO_MODE_OUTPUT); |
||||
BSP_IO_WritePin(IDD_AMP_CONTROL_PIN, GPIO_PIN_RESET); |
||||
|
||||
if (IddDrv->Start != NULL) |
||||
{ |
||||
IddDrv->Start(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configure Idd component |
||||
* @param IddConfig: structure of idd parameters |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_Config(IDD_ConfigTypeDef IddConfig) |
||||
{ |
||||
if (IddDrv->Config != NULL) |
||||
{ |
||||
IddDrv->Config(IDD_I2C_ADDRESS, IddConfig); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get Idd current value. |
||||
* @param IddValue: Pointer on u32 to store Idd. Value unit is 10 nA. |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_GetValue(uint32_t *IddValue) |
||||
{ |
||||
/* De-activate the OPAMP used ny the MFX to measure the current consumption */ |
||||
BSP_IO_ConfigPin(IDD_AMP_CONTROL_PIN, IO_MODE_OUTPUT); |
||||
BSP_IO_WritePin(IDD_AMP_CONTROL_PIN, GPIO_PIN_RESET); |
||||
|
||||
if (IddDrv->GetValue != NULL) |
||||
{ |
||||
IddDrv->GetValue(IDD_I2C_ADDRESS, IddValue); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Enable Idd interrupt that warn end of measurement |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_EnableIT(void) |
||||
{ |
||||
if (IddDrv->EnableIT != NULL) |
||||
{ |
||||
IddDrv->EnableIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Clear Idd interrupt that warn end of measurement |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_ClearIT(void) |
||||
{ |
||||
if (IddDrv->ClearIT != NULL) |
||||
{ |
||||
IddDrv->ClearIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get Idd interrupt status |
||||
* @retval status |
||||
*/ |
||||
uint8_t BSP_IDD_GetITStatus(void) |
||||
{ |
||||
if (IddDrv->GetITStatus != NULL) |
||||
{ |
||||
return (IddDrv->GetITStatus(IDD_I2C_ADDRESS)); |
||||
} |
||||
else |
||||
{ |
||||
return IDD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Disable Idd interrupt that warn end of measurement |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_DisableIT(void) |
||||
{ |
||||
if (IddDrv->DisableIT != NULL) |
||||
{ |
||||
IddDrv->DisableIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get Error Code . |
||||
* @retval Error code or error status |
||||
*/ |
||||
uint8_t BSP_IDD_ErrorGetCode(void) |
||||
{ |
||||
if (IddDrv->ErrorGetSrc != NULL) |
||||
{ |
||||
if ((IddDrv->ErrorGetSrc(IDD_I2C_ADDRESS) & MFXSTM32L152_IDD_ERROR_SRC) != RESET) |
||||
{ |
||||
if (IddDrv->ErrorGetCode != NULL) |
||||
{ |
||||
return IddDrv->ErrorGetCode(IDD_I2C_ADDRESS); |
||||
} |
||||
else |
||||
{ |
||||
return IDD_ERROR; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
return IDD_ERROR; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
return IDD_ERROR; |
||||
} |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* @brief Enable error interrupt that warn end of measurement |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_ErrorEnableIT(void) |
||||
{ |
||||
if (IddDrv->ErrorEnableIT != NULL) |
||||
{ |
||||
IddDrv->ErrorEnableIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Clear Error interrupt that warn end of measurement |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_ErrorClearIT(void) |
||||
{ |
||||
if (IddDrv->ErrorClearIT != NULL) |
||||
{ |
||||
IddDrv->ErrorClearIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get Error interrupt status |
||||
* @retval Status |
||||
*/ |
||||
uint8_t BSP_IDD_ErrorGetITStatus(void) |
||||
{ |
||||
if (IddDrv->ErrorGetITStatus != NULL) |
||||
{ |
||||
return (IddDrv->ErrorGetITStatus(IDD_I2C_ADDRESS)); |
||||
} |
||||
else |
||||
{ |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Disable Error interrupt |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_ErrorDisableIT(void) |
||||
{ |
||||
if (IddDrv->ErrorDisableIT != NULL) |
||||
{ |
||||
IddDrv->ErrorDisableIT(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Wake up Idd measurement component. |
||||
* @retval None |
||||
*/ |
||||
void BSP_IDD_WakeUp(void) |
||||
{ |
||||
if (IddDrv->WakeUp != NULL) |
||||
{ |
||||
IddDrv->WakeUp(IDD_I2C_ADDRESS); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
||||
|
@ -0,0 +1,145 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_idd.h |
||||
* @author MCD Application Team |
||||
* @brief Header file for stm32l496g_discovery_idd.c module. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_IDD_H |
||||
#define __STM32L496G_DISCOVERY_IDD_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery.h" |
||||
/* Include Idd measurement component driver */ |
||||
#include "../Components/mfxstm32l152/mfxstm32l152.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_IDD
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup IDD_Config IDD Config
|
||||
* @{ |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
IDD_OK = 0, |
||||
IDD_TIMEOUT = 1, |
||||
IDD_ZERO_VALUE = 2, |
||||
IDD_ERROR = 0xFF |
||||
} |
||||
IDD_StatusTypeDef; |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Exported_Defines Exported Defines
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @brief Shunt values on discovery in milli ohms |
||||
*/ |
||||
#define DISCOVERY_IDD_SHUNT0_VALUE ((uint16_t) 1000) /*!< value in milliohm */ |
||||
#define DISCOVERY_IDD_SHUNT1_VALUE ((uint16_t) 24) /*!< value in ohm */ |
||||
#define DISCOVERY_IDD_SHUNT2_VALUE ((uint16_t) 620) /*!< value in ohm */ |
||||
#define DISCOVERY_IDD_SHUNT4_VALUE ((uint16_t) 10000) /*!< value in ohm */ |
||||
|
||||
/**
|
||||
* @brief Shunt stabilization delay on discovery in milli ohms |
||||
*/ |
||||
#define DISCOVERY_IDD_SHUNT0_STABDELAY ((uint8_t) 149) /*!< value in millisec */ |
||||
#define DISCOVERY_IDD_SHUNT1_STABDELAY ((uint8_t) 149) /*!< value in millisec */ |
||||
#define DISCOVERY_IDD_SHUNT2_STABDELAY ((uint8_t) 149) /*!< value in millisec */ |
||||
#define DISCOVERY_IDD_SHUNT4_STABDELAY ((uint8_t) 255) /*!< value in millisec */ |
||||
|
||||
/**
|
||||
* @brief IDD Ampli Gain on discovery |
||||
*/ |
||||
#define DISCOVERY_IDD_AMPLI_GAIN ((uint16_t) 4967) /*!< value is gain * 100 */ |
||||
|
||||
/**
|
||||
* @brief IDD Vdd Min on discovery |
||||
*/ |
||||
#define DISCOVERY_IDD_VDD_MIN ((uint16_t) 2000) /*!< value in millivolt */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
/** @defgroup STM32L496G_DISCOVERY_IDD_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_IDD_Init(void); |
||||
void BSP_IDD_DeInit(void); |
||||
void BSP_IDD_Reset(void); |
||||
void BSP_IDD_LowPower(void); |
||||
void BSP_IDD_WakeUp(void); |
||||
void BSP_IDD_StartMeasure(void); |
||||
void BSP_IDD_Config(IDD_ConfigTypeDef IddConfig); |
||||
void BSP_IDD_GetValue(uint32_t *IddValue); |
||||
void BSP_IDD_EnableIT(void); |
||||
void BSP_IDD_ClearIT(void); |
||||
uint8_t BSP_IDD_GetITStatus(void); |
||||
void BSP_IDD_DisableIT(void); |
||||
uint8_t BSP_IDD_ErrorGetCode(void); |
||||
void BSP_IDD_ErrorEnableIT(void); |
||||
void BSP_IDD_ErrorClearIT(void); |
||||
uint8_t BSP_IDD_ErrorGetITStatus(void); |
||||
void BSP_IDD_ErrorDisableIT(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_IDD_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,305 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_io.c |
||||
* @author MCD Application Team |
||||
* @brief This file provides a set of functions needed to manage the IO pins |
||||
* on STM32L496G-DISCO evaluation board. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* File Info : -----------------------------------------------------------------
|
||||
User NOTES |
||||
1. How To use this driver: |
||||
-------------------------- |
||||
- This driver is used to drive the IO module of the STM32L496G-DISCO evaluation |
||||
board. |
||||
- The STMPE811 and STMPE1600 IO expander device component driver must be included with this |
||||
driver in order to run the IO functionalities commanded by the IO expander |
||||
device mounted on the evaluation board. |
||||
|
||||
2. Driver description: |
||||
--------------------- |
||||
+ Initialization steps: |
||||
o Initialize the IO module using the BSP_IO_Init() function. This |
||||
function includes the MSP layer hardware resources initialization and the |
||||
communication layer configuration to start the IO functionalities use. |
||||
|
||||
+ IO functionalities use |
||||
o The IO pin mode is configured when calling the function BSP_IO_ConfigPin(), you |
||||
must specify the desired IO mode by choosing the "IO_ModeTypedef" parameter |
||||
predefined value. |
||||
o If an IO pin is used in interrupt mode, the function BSP_IO_ITGetStatus() is |
||||
needed to get the interrupt status. To clear the IT pending bits, you should |
||||
call the function BSP_IO_ITClear() with specifying the IO pending bit to clear. |
||||
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. |
||||
o To get/set an IO pin combination state you can use the functions |
||||
BSP_IO_ReadPin()/BSP_IO_WritePin() or the function BSP_IO_TogglePin() to toggle the pin |
||||
state. |
||||
|
||||
------------------------------------------------------------------------------*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery_io.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G-DISCO
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCO_IO STM32L496G-DISCO IO
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Private constants ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCO_IO_Private_Constants Private Constants
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private macros -------------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCO_IO_Private_Macros Private Macros
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private variables ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCO_IO_Private_Variables Private Variables
|
||||
* @{ |
||||
*/ |
||||
static IO_DrvTypeDef *io1_driver; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private function prototypes -----------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCO_IO_Private_Functions Private Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private functions ---------------------------------------------------------*/ |
||||
|
||||
/** @addtogroup STM32L496G-DISCO_IO_Exported_Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes and configures the IO functionalities and configures all |
||||
* necessary hardware resources (GPIOs, clocks..). |
||||
* @note BSP_IO_Init() is using HAL_Delay() function to ensure that stmpe811 |
||||
* IO Expander is correctly reset. HAL_Delay() function provides accurate |
||||
* delay (in milliseconds) based on variable incremented in SysTick ISR. |
||||
* This implies that if BSP_IO_Init() is called from a peripheral ISR process, |
||||
* then the SysTick interrupt must have higher priority (numerically lower) |
||||
* than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
||||
* @retval IO_OK: if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_IO_Init(void) |
||||
{ |
||||
uint8_t ret = IO_ERROR; |
||||
uint8_t mfxstm32l152_id = 0; |
||||
|
||||
if (io1_driver == NULL) /* Checks if MFX initialization has been already done */ |
||||
{ |
||||
mfxstm32l152_idd_drv.WakeUp(IO1_I2C_ADDRESS); |
||||
|
||||
HAL_Delay(10); |
||||
|
||||
/* Read ID and verify the IO expander is ready */ |
||||
mfxstm32l152_id = mfxstm32l152_io_drv.ReadID(IO1_I2C_ADDRESS); |
||||
|
||||
if ((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2)) |
||||
{ |
||||
/* Initialize the MFX */ |
||||
io1_driver = &mfxstm32l152_io_drv; |
||||
|
||||
/* Initialize the MFX IO driver structure */ |
||||
if (io1_driver->Init != NULL) |
||||
{ |
||||
io1_driver->Init(IO1_I2C_ADDRESS); |
||||
io1_driver->Start(IO1_I2C_ADDRESS, IO1_PIN_ALL >> IO1_PIN_OFFSET); |
||||
|
||||
ret = IO_OK; |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
ret = IO_ALREADY_INITIALIZED; |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Gets the selected pins IT status. |
||||
* @param IO_Pin: Selected pins to check the status. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @retval Status of the checked IO pin(s). |
||||
*/ |
||||
uint32_t BSP_IO_ITGetStatus(uint32_t IO_Pin) |
||||
{ |
||||
uint32_t status = 0; |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
/* Return the MFX Pin IT status */ |
||||
status |= (io1_driver->ITStatus(IO1_I2C_ADDRESS, io1_pin)) << IO1_PIN_OFFSET; |
||||
|
||||
return status; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Clears the selected IO IT pending bit. |
||||
* @param IO_Pin: Selected pins to check the status. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @retval None |
||||
*/ |
||||
void BSP_IO_ITClear(uint32_t IO_Pin) |
||||
{ |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
/* Clears the selected IO Expander 1 pin(s) mode */ |
||||
io1_driver->ClearIT(IO1_I2C_ADDRESS, io1_pin); |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures the IO pin(s) according to IO mode structure value. |
||||
* @param IO_Pin: Output pin to be set or reset. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @param IO_Mode: IO pin mode to configure |
||||
* This parameter can be one of the following values: |
||||
* @arg IO_MODE_INPUT |
||||
* @arg IO_MODE_OUTPUT |
||||
* @arg IO_MODE_IT_RISING_EDGE |
||||
* @arg IO_MODE_IT_FALLING_EDGE |
||||
* @arg IO_MODE_IT_LOW_LEVEL |
||||
* @arg IO_MODE_IT_HIGH_LEVEL |
||||
* @retval IO_OK: if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_IO_ConfigPin(uint32_t IO_Pin, IO_ModeTypedef IO_Mode) |
||||
{ |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
|
||||
/* Configure the selected IO Expander 1 pin(s) mode */ |
||||
io1_driver->Config(IO1_I2C_ADDRESS, io1_pin, IO_Mode); |
||||
|
||||
return IO_OK; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Sets the selected pins state. |
||||
* @param IO_Pin: Selected pins to write. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @param PinState: New pins state to write |
||||
* @retval None |
||||
*/ |
||||
void BSP_IO_WritePin(uint32_t IO_Pin, uint8_t PinState) |
||||
{ |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
/* Sets the IO Expander 1 selected pins state */ |
||||
io1_driver->WritePin(IO1_I2C_ADDRESS, io1_pin, PinState); |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief Gets the selected pins current state. |
||||
* @param IO_Pin: Selected pins to read. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @retval The current pins state |
||||
*/ |
||||
uint32_t BSP_IO_ReadPin(uint32_t IO_Pin) |
||||
{ |
||||
uint32_t pin_state = 0; |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
/* Gets the IO Expander 1 selected pins current state */ |
||||
pin_state |= (io1_driver->ReadPin(IO1_I2C_ADDRESS, io1_pin)) << IO1_PIN_OFFSET; |
||||
|
||||
|
||||
return pin_state; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Toggles the selected pins state |
||||
* @param IO_Pin: Selected pins to toggle. |
||||
* This parameter can be any combination of the IO pins. |
||||
* @retval None |
||||
*/ |
||||
void BSP_IO_TogglePin(uint32_t IO_Pin) |
||||
{ |
||||
uint32_t io1_pin = 0; |
||||
|
||||
io1_pin = (IO_Pin & IO1_PIN_ALL) >> IO1_PIN_OFFSET; |
||||
|
||||
/* Toggles the IO Expander 1 selected pins state */ |
||||
if (io1_driver->ReadPin(IO1_I2C_ADDRESS, io1_pin) == RESET) /* Set */ |
||||
{ |
||||
BSP_IO_WritePin(io1_pin, GPIO_PIN_SET); /* Reset */ |
||||
} |
||||
else |
||||
{ |
||||
BSP_IO_WritePin(io1_pin, GPIO_PIN_RESET); /* Set */ |
||||
} |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,128 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_io.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_eval_io.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCO_IO_H |
||||
#define __STM32L496G_DISCO_IO_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery.h" |
||||
#include "../Components/mfxstm32l152/mfxstm32l152.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCO
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCO_IO
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Exported types ------------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCO_IO_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
IO_OK = 0x00, |
||||
IO_ERROR = 0x01, |
||||
IO_TIMEOUT = 0x02, |
||||
IO_ALREADY_INITIALIZED = 0x03 |
||||
} |
||||
IO_StatusTypeDef; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCO_IO_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
/* Virtual pin offset IOExpander1 */ |
||||
#define IO1_PIN_OFFSET 0 |
||||
|
||||
|
||||
/* Pins definition IOExpander */ |
||||
#define IO1_PIN_0 (uint32_t)(0x00000001 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_1 (uint32_t)(0x00000002 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_2 (uint32_t)(0x00000004 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_3 (uint32_t)(0x00000008 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_4 (uint32_t)(0x00000010 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_5 (uint32_t)(0x00000020 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_6 (uint32_t)(0x00000040 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_7 (uint32_t)(0x00000080 << IO1_PIN_OFFSET) |
||||
#define IO1_PIN_8 (uint32_t)(0x00000100 << IO1_PIN_OFFSET) |
||||
#define AGPIO_PIN_0 (uint32_t)(0x00010000 << IO1_PIN_OFFSET) |
||||
#define AGPIO_PIN_1 (uint32_t)(0x00020000 << IO1_PIN_OFFSET) |
||||
|
||||
#define IO1_PIN_ALL (uint32_t)(0x000301FF << IO1_PIN_OFFSET) |
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCO_IO_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
uint8_t BSP_IO_Init(void); |
||||
void BSP_IO_ITClear(uint32_t IO_Pin); |
||||
uint32_t BSP_IO_ITGetStatus(uint32_t IO_Pin); |
||||
uint8_t BSP_IO_ConfigPin(uint32_t IO_Pin, IO_ModeTypedef IO_Mode); |
||||
void BSP_IO_WritePin(uint32_t IO_Pin, uint8_t PinState); |
||||
uint32_t BSP_IO_ReadPin(uint32_t IO_Pin); |
||||
void BSP_IO_TogglePin(uint32_t IO_Pin); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCO_IO_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,262 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_lcd.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_lcd.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_LCD_H |
||||
#define __STM32L496G_DISCOVERY_LCD_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery.h" |
||||
#include "stm32l496g_discovery_io.h" |
||||
/*#include "../Components/ls016b8uy/ls016b8uy.h"*/ |
||||
#include "../Components/st7789h2/st7789h2.h" |
||||
#include "../../../Utilities/Fonts/fonts.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_LCD STM32L496G-DISCOVERY LCD
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_LCD_Exported_Types STM32L496G DISCOVERY LCD Exported Types
|
||||
* @{ |
||||
*/ |
||||
typedef struct |
||||
{ |
||||
uint32_t TextColor; |
||||
uint32_t BackColor; |
||||
sFONT *pFont; |
||||
} LCD_DrawPropTypeDef; |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_LCD_Exported_Constants STM32L496G DISCOVERY LCD Exported Constants
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @brief LCD status structure definition |
||||
*/ |
||||
#define LCD_OK ((uint8_t)0x00) |
||||
#define LCD_ERROR ((uint8_t)0x01) |
||||
#define LCD_TIMEOUT ((uint8_t)0x02) |
||||
|
||||
typedef struct |
||||
{ |
||||
int16_t X; |
||||
int16_t Y; |
||||
} Point, * pPoint; |
||||
|
||||
/**
|
||||
* @brief Line mode structures definition |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
CENTER_MODE = 0x01, /* Center mode */ |
||||
RIGHT_MODE = 0x02, /* Right mode */ |
||||
LEFT_MODE = 0x03 /* Left mode */ |
||||
} Line_ModeTypdef; |
||||
|
||||
|
||||
#define LCD_ORIENTATION_PORTRAIT ((uint8_t)0x00) /*!< Portrait orientation choice of LCD screen */ |
||||
#define LCD_ORIENTATION_LANDSCAPE ((uint8_t)0x01) /*!< Landscape orientation choice of LCD screen */ |
||||
#define LCD_ORIENTATION_UNDEFINED ((uint8_t)0x02) /*!< Undefined LCD screen orientation */ |
||||
|
||||
|
||||
/**
|
||||
* @brief LCD color |
||||
*/ |
||||
#define LCD_COLOR_BLUE ((uint16_t)0x001F) |
||||
#define LCD_COLOR_GREEN ((uint16_t)0x07E0) |
||||
#define LCD_COLOR_RED ((uint16_t)0xF800) |
||||
#define LCD_COLOR_CYAN ((uint16_t)0x07FF) |
||||
#define LCD_COLOR_MAGENTA ((uint16_t)0xF81F) |
||||
#define LCD_COLOR_YELLOW ((uint16_t)0xFFE0) |
||||
#define LCD_COLOR_LIGHTBLUE ((uint16_t)0x841F) |
||||
#define LCD_COLOR_LIGHTGREEN ((uint16_t)0x87F0) |
||||
#define LCD_COLOR_LIGHTRED ((uint16_t)0xFC10) |
||||
#define LCD_COLOR_LIGHTMAGENTA ((uint16_t)0xFC1F) |
||||
#define LCD_COLOR_LIGHTYELLOW ((uint16_t)0xFFF0) |
||||
#define LCD_COLOR_DARKBLUE ((uint16_t)0x0010) |
||||
#define LCD_COLOR_DARKGREEN ((uint16_t)0x0400) |
||||
#define LCD_COLOR_DARKRED ((uint16_t)0x8000) |
||||
#define LCD_COLOR_DARKCYAN ((uint16_t)0x0410) |
||||
#define LCD_COLOR_DARKMAGENTA ((uint16_t)0x8010) |
||||
#define LCD_COLOR_DARKYELLOW ((uint16_t)0x8400) |
||||
#define LCD_COLOR_WHITE ((uint16_t)0xFFFF) |
||||
#define LCD_COLOR_LIGHTGRAY ((uint16_t)0xD69A) |
||||
#define LCD_COLOR_GRAY ((uint16_t)0x8410) |
||||
#define LCD_COLOR_DARKGRAY ((uint16_t)0x4208) |
||||
#define LCD_COLOR_BLACK ((uint16_t)0x0000) |
||||
#define LCD_COLOR_BROWN ((uint16_t)0xA145) |
||||
#define LCD_COLOR_ORANGE ((uint16_t)0xFD20) |
||||
|
||||
/**
|
||||
* @brief LCD default font |
||||
*/ |
||||
#define LCD_DEFAULT_FONT Font12 |
||||
|
||||
/**
|
||||
* @brief LCD special pins |
||||
*/ |
||||
/* LCD reset pin */ |
||||
/* LCD reset is accessed thru the MFX */ |
||||
#define LCD_RST_PIN IO1_PIN_2 |
||||
|
||||
/* LCD tearing effect pin */ |
||||
#define LCD_TE_PIN GPIO_PIN_7 |
||||
#define LCD_TE_GPIO_PORT GPIOH |
||||
#define LCD_TE_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define LCD_TE_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
|
||||
/* Backlight control pin */ |
||||
#if defined(LPTIMER_DIMMING) |
||||
#define LCD_BL_CTRL_PIN GPIO_PIN_15 |
||||
#define LCD_BL_CTRL_GPIO_PORT GPIOG |
||||
#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE() |
||||
#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE() |
||||
#else |
||||
#define LCD_BL_CTRL_PIN GPIO_PIN_0 |
||||
#define LCD_BL_CTRL_GPIO_PORT GPIOI |
||||
#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE() |
||||
#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE() |
||||
#endif |
||||
|
||||
|
||||
/* Power on control pin */ |
||||
#define LCD_PWR_CTRL_PIN GPIO_PIN_0 |
||||
#define LCD_PWR_CTRL_GPIO_PORT GPIOH |
||||
#define LCD_PWR_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE() |
||||
#define LCD_PWR_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOH_CLK_DISABLE() |
||||
|
||||
/* Use by application to not use backlight */ |
||||
extern FlagStatus WakeUpFromStandby; |
||||
extern FlagStatus WakeUpFromShutdown; |
||||
|
||||
|
||||
/* Screen dimming parameters */ |
||||
/* Definition for TIMx clock resources */ |
||||
#define TIMx TIM5 |
||||
#define TIMx_CLK_ENABLE() __HAL_RCC_TIM5_CLK_ENABLE() |
||||
#define TIMx_CLK_DISABLE() __HAL_RCC_TIM5_CLK_DISABLE() |
||||
#define TIMx_CHANNEL TIM_CHANNEL_4 |
||||
#define TIMx_CHANNEl_AF GPIO_AF2_TIM5 |
||||
#if defined(LPTIMER_DIMMING) |
||||
#define PERIOD_VALUE (uint32_t)(99) /* Period Value */ |
||||
#define PULSE_VALUE (uint32_t)(95) /* 5% cycle */ |
||||
#define PULSE_DECREASE_START (uint32_t)(45) /* cycle start level when starting to dim the screen */ |
||||
#define PULSE_DECREASE_DELAY (uint32_t)(40) /* gradually decrease cycle level every 40 milliseconds */ |
||||
#else |
||||
#define PERIOD_VALUE (uint32_t)(666 - 1) /* Period Value */ |
||||
#define PULSE_VALUE (uint32_t)((PERIOD_VALUE*5)/100) /* 5% cycle */ |
||||
#define PULSE_DECREASE_START (uint32_t)(PULSE_VALUE + 120) /* cycle start level when starting to dim the screen */ |
||||
#define PULSE_DECREASE_DELAY (uint32_t)(20) /* gradually decrease cycle level every 20 milliseconds */ |
||||
#endif |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_LCD_Exported_Functions STM32L496G DISCOVERY LCD Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_LCD_Init(void); |
||||
uint8_t BSP_LCD_InitEx(uint32_t orientation); |
||||
void BSP_LCD_Reset(void); |
||||
uint8_t BSP_LCD_DeInit(void); |
||||
uint32_t BSP_LCD_GetXSize(void); |
||||
uint32_t BSP_LCD_GetYSize(void); |
||||
|
||||
uint16_t BSP_LCD_GetTextColor(void); |
||||
uint16_t BSP_LCD_GetBackColor(void); |
||||
void BSP_LCD_SetTextColor(__IO uint16_t Color); |
||||
void BSP_LCD_SetBackColor(__IO uint16_t Color); |
||||
void BSP_LCD_SetFont(sFONT *fonts); |
||||
sFONT *BSP_LCD_GetFont(void); |
||||
|
||||
void BSP_LCD_Clear(uint16_t Color); |
||||
void BSP_LCD_ClearStringLine(uint16_t Line); |
||||
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr); |
||||
void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode); |
||||
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii); |
||||
|
||||
uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos); |
||||
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code); |
||||
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length); |
||||
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length); |
||||
void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); |
||||
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); |
||||
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius); |
||||
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount); |
||||
void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius); |
||||
void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp); |
||||
void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pbmp); |
||||
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); |
||||
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius); |
||||
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount); |
||||
void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius); |
||||
|
||||
void BSP_LCD_DisplayOff(void); |
||||
void BSP_LCD_DisplayOn(void); |
||||
|
||||
void BSP_LCD_ScreenDimmingOn(void); |
||||
void BSP_LCD_ScreenDimmingOff(void); |
||||
void BSP_LCD_ScreenDimmingConfig(const uint8_t start, const uint8_t stop, const uint8_t step, const uint8_t delay); |
||||
|
||||
uint8_t BSP_LCD_GetOrientation(void); |
||||
|
||||
/* These functions can be modified in case the current settings
|
||||
need to be changed for specific application needs */ |
||||
__weak void BSP_LCD_MspInit(void); |
||||
__weak void BSP_LCD_MspDeInit(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_LCD_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,119 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_qspi.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_qspi.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_QSPI_H |
||||
#define __STM32L496G_DISCOVERY_QSPI_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l4xx_hal.h" |
||||
#include "../Components/mx25r6435f/mx25r6435f.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_QSPI
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Exported constants --------------------------------------------------------*/ |
||||
/** @defgroup STM32L496G_DISCOVERY_QSPI_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
/* QSPI Error codes */ |
||||
#define QSPI_OK ((uint8_t)0x00) |
||||
#define QSPI_ERROR ((uint8_t)0x01) |
||||
#define QSPI_BUSY ((uint8_t)0x02) |
||||
#define QSPI_NOT_SUPPORTED ((uint8_t)0x04) |
||||
#define QSPI_SUSPENDED ((uint8_t)0x08) |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported types ------------------------------------------------------------*/ |
||||
/** @defgroup STM32L496G_DISCOVERY_QSPI_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
/* QSPI Info */ |
||||
typedef struct |
||||
{ |
||||
uint32_t FlashSize; /*!< Size of the flash */ |
||||
uint32_t EraseSectorSize; /*!< Size of sectors for the erase operation */ |
||||
uint32_t EraseSectorsNumber; /*!< Number of sectors for the erase operation */ |
||||
uint32_t ProgPageSize; /*!< Size of pages for the program operation */ |
||||
uint32_t ProgPagesNumber; /*!< Number of pages for the program operation */ |
||||
} QSPI_Info; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
/** @defgroup STM32L496G_DISCOVERY_QSPI_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_QSPI_Init(void); |
||||
uint8_t BSP_QSPI_DeInit(void); |
||||
uint8_t BSP_QSPI_Read(uint8_t *pData, uint32_t ReadAddr, uint32_t Size); |
||||
uint8_t BSP_QSPI_Write(uint8_t *pData, uint32_t WriteAddr, uint32_t Size); |
||||
uint8_t BSP_QSPI_Erase_Block(uint32_t BlockAddress); |
||||
uint8_t BSP_QSPI_Erase_Sector(uint32_t Sector); |
||||
uint8_t BSP_QSPI_Erase_Chip(void); |
||||
uint8_t BSP_QSPI_GetStatus(void); |
||||
uint8_t BSP_QSPI_GetInfo(QSPI_Info *pInfo); |
||||
uint8_t BSP_QSPI_EnableMemoryMappedMode(void); |
||||
uint8_t BSP_QSPI_SuspendErase(void); |
||||
uint8_t BSP_QSPI_ResumeErase(void); |
||||
uint8_t BSP_QSPI_EnterDeepPowerDown(void); |
||||
uint8_t BSP_QSPI_LeaveDeepPowerDown(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_QSPI_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,716 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_sd.c |
||||
* @author MCD Application Team |
||||
* @brief This file includes the uSD card driver. |
||||
@verbatim |
||||
============================================================================== |
||||
##### How to use this driver ##### |
||||
============================================================================== |
||||
(#) This driver is used to drive the micro SD external card mounted on STM32L496G-DISCOVERY |
||||
evaluation board. |
||||
|
||||
(#) This driver does not need a specific component driver for the micro SD device |
||||
to be included with. |
||||
|
||||
(#) Initialization steps: |
||||
(++) Initialize the micro SD card using the BSP_SD_Init() function. This |
||||
function includes the MSP layer hardware resources initialization and the |
||||
SDMMC1 interface configuration to interface with the external micro SD. It |
||||
also includes the micro SD initialization sequence. |
||||
(++) To check the SD card presence you can use the function BSP_SD_IsDetected() which |
||||
returns the detection status. |
||||
(++) The function BSP_SD_GetCardInfo() is used to get the micro SD card information |
||||
which is stored in the structure "HAL_SD_CardInfoTypedef". |
||||
|
||||
(#) Micro SD card operations |
||||
(++) The micro SD card can be accessed with read/write block(s) operations once |
||||
it is reay for access. The access cand be performed whether using the polling |
||||
mode by calling the functions BSP_SD_ReadBlocks()/BSP_SD_WriteBlocks(), or by DMA |
||||
transfer using the functions BSP_SD_ReadBlocks_DMA()/BSP_SD_WriteBlocks_DMA() |
||||
(++) The DMA transfer complete is used with interrupt mode. Once the SD transfer |
||||
is complete, the SD interrupt is handled using the function BSP_SD_IRQHandler(), |
||||
the DMA Tx/Rx transfer complete are handled using the functions |
||||
BSP_SD_DMA_Tx_IRQHandler()/BSP_SD_DMA_Rx_IRQHandler(). The corresponding user callbacks |
||||
are implemented by the user at application level. |
||||
(++) The SD erase block(s) is performed using the function BSP_SD_Erase() with specifying |
||||
the number of blocks to erase. |
||||
(++) The SD runtime status is returned when calling the function BSP_SD_GetStatus(). |
||||
[..] |
||||
@endverbatim |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery_io.h" |
||||
#include "stm32l496g_discovery_sd.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SD STM32L496G_DISCOVERY SD
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Private variables ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_SD_Private_Variables Private Variables
|
||||
* @{ |
||||
*/ |
||||
SD_HandleTypeDef uSdHandle; |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private function prototypes -----------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SD_Private_Functions Private Functions
|
||||
* @{ |
||||
*/ |
||||
static void SD_Detect_MspInit(void); |
||||
static void SD_Detect_MspDeInit(void); |
||||
static HAL_StatusTypeDef SD_DMAConfigRx(SD_HandleTypeDef *hsd); |
||||
static HAL_StatusTypeDef SD_DMAConfigTx(SD_HandleTypeDef *hsd); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions ---------------------------------------------------------*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_SD_Exported_Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes the SD card device. |
||||
* @param None |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_Init(void) |
||||
{ |
||||
uint8_t sd_state = MSD_OK; |
||||
|
||||
/* uSD device interface configuration */ |
||||
uSdHandle.Instance = SDMMC1; |
||||
uSdHandle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; |
||||
uSdHandle.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE; |
||||
uSdHandle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; |
||||
uSdHandle.Init.BusWide = SDMMC_BUS_WIDE_1B; |
||||
uSdHandle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE; |
||||
uSdHandle.Init.ClockDiv = SDMMC_TRANSFER_CLK_DIV; |
||||
|
||||
/* Msp SD Detect pin initialization */ |
||||
SD_Detect_MspInit(); |
||||
|
||||
/* Check if the SD card is plugged in the slot */ |
||||
if (BSP_SD_IsDetected() != SD_PRESENT) |
||||
{ |
||||
return MSD_ERROR_SD_NOT_PRESENT; |
||||
} |
||||
|
||||
/* Msp SD initialization */ |
||||
BSP_SD_MspInit(&uSdHandle, NULL); |
||||
|
||||
/* HAL SD initialization */ |
||||
if (HAL_SD_Init(&uSdHandle) != HAL_OK) |
||||
{ |
||||
sd_state = MSD_ERROR; |
||||
} |
||||
|
||||
/* Configure SD Bus width */ |
||||
if (sd_state == MSD_OK) |
||||
{ |
||||
/* Enable wide operation */ |
||||
if (HAL_SD_ConfigWideBusOperation(&uSdHandle, SDMMC_BUS_WIDE_4B) != HAL_OK) |
||||
{ |
||||
sd_state = MSD_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
sd_state = MSD_OK; |
||||
} |
||||
} |
||||
|
||||
return sd_state; |
||||
} |
||||
|
||||
/**
|
||||
* @brief DeInitializes the SD card device. |
||||
* @param None |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_DeInit(void) |
||||
{ |
||||
uint8_t sd_state = MSD_OK; |
||||
|
||||
uSdHandle.Instance = SDMMC1; |
||||
/* HAL SD deinitialization */ |
||||
if (HAL_SD_DeInit(&uSdHandle) != HAL_OK) |
||||
{ |
||||
sd_state = MSD_ERROR; |
||||
} |
||||
|
||||
/* Msp SD deinitialization */ |
||||
BSP_SD_MspDeInit(&uSdHandle, NULL); |
||||
|
||||
SD_Detect_MspDeInit(); |
||||
|
||||
return sd_state; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures Interrupt mode for SD detection pin. |
||||
* @param None |
||||
* @retval IO_OK: if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_SD_ITConfig(void) |
||||
{ |
||||
/* Check SD card detect pin */ |
||||
if (BSP_IO_ReadPin(SD_DETECT_PIN) != SD_DETECT_PIN) |
||||
{ |
||||
return BSP_IO_ConfigPin(SD_DETECT_PIN, IO_MODE_IT_RISING_EDGE_PU); |
||||
} |
||||
else |
||||
{ |
||||
return BSP_IO_ConfigPin(SD_DETECT_PIN, IO_MODE_IT_FALLING_EDGE_PU); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Detects if SD card is correctly plugged in the memory slot or not. |
||||
* @param None |
||||
* @retval Returns if SD is detected or not |
||||
*/ |
||||
uint8_t BSP_SD_IsDetected(void) |
||||
{ |
||||
__IO uint8_t status = SD_PRESENT; |
||||
|
||||
/* Check SD card detect pin */ |
||||
if (BSP_IO_ReadPin(SD_DETECT_PIN) != GPIO_PIN_RESET) |
||||
{ |
||||
status = SD_NOT_PRESENT; |
||||
} |
||||
|
||||
return status; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in polling mode. |
||||
* @param pData: Pointer to the buffer that will contain the data to transmit |
||||
* @param ReadAddr: Address from where data is to be read |
||||
* @param NumOfBlocks: Number of SD blocks to read |
||||
* @param Timeout: Timeout for read operation |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout) |
||||
{ |
||||
HAL_StatusTypeDef sd_state = HAL_OK; |
||||
|
||||
sd_state = HAL_SD_ReadBlocks(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks, Timeout); |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
return MSD_OK; |
||||
} |
||||
else |
||||
{ |
||||
return MSD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in polling mode. |
||||
* @param pData: Pointer to the buffer that will contain the data to transmit |
||||
* @param WriteAddr: Address from where data is to be written |
||||
* @param NumOfBlocks: Number of SD blocks to write |
||||
* @param Timeout: Timeout for write operation |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout) |
||||
{ |
||||
HAL_StatusTypeDef sd_state = HAL_OK; |
||||
|
||||
sd_state = HAL_SD_WriteBlocks(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks, Timeout); |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
return MSD_OK; |
||||
} |
||||
else |
||||
{ |
||||
return MSD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in an SD card, in DMA mode. |
||||
* @param pData: Pointer to the buffer that will contain the data to transmit |
||||
* @param ReadAddr: Address from where data is to be read |
||||
* @param NumOfBlocks: Number of SD blocks to read |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks) |
||||
{ |
||||
HAL_StatusTypeDef sd_state = HAL_OK; |
||||
|
||||
/* Invalidate the dma tx handle*/ |
||||
uSdHandle.hdmatx = NULL; |
||||
|
||||
/* Prepare the dma channel for a read operation */ |
||||
sd_state = SD_DMAConfigRx(&uSdHandle); |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
/* Read block(s) in DMA transfer mode */ |
||||
sd_state = HAL_SD_ReadBlocks_DMA(&uSdHandle, (uint8_t *)pData, ReadAddr, NumOfBlocks); |
||||
} |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
return MSD_OK; |
||||
} |
||||
else |
||||
{ |
||||
return MSD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Writes block(s) to a specified address in an SD card, in DMA mode. |
||||
* @param pData: Pointer to the buffer that will contain the data to transmit |
||||
* @param WriteAddr: Address from where data is to be written |
||||
* @param NumOfBlocks: Number of SD blocks to write |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks) |
||||
{ |
||||
HAL_StatusTypeDef sd_state = HAL_OK; |
||||
|
||||
/* Invalidate the dma rx handle*/ |
||||
uSdHandle.hdmarx = NULL; |
||||
|
||||
/* Prepare the dma channel for a read operation */ |
||||
sd_state = SD_DMAConfigTx(&uSdHandle); |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
/* Write block(s) in DMA transfer mode */ |
||||
sd_state = HAL_SD_WriteBlocks_DMA(&uSdHandle, (uint8_t *)pData, WriteAddr, NumOfBlocks); |
||||
} |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
return MSD_OK; |
||||
} |
||||
else |
||||
{ |
||||
return MSD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Erases the specified memory area of the given SD card. |
||||
* @param StartAddr: Start byte address |
||||
* @param EndAddr: End byte address |
||||
* @retval SD status |
||||
*/ |
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr) |
||||
{ |
||||
HAL_StatusTypeDef sd_state = HAL_OK; |
||||
|
||||
sd_state = HAL_SD_Erase(&uSdHandle, StartAddr, EndAddr); |
||||
|
||||
if (sd_state == HAL_OK) |
||||
{ |
||||
return MSD_OK; |
||||
} |
||||
else |
||||
{ |
||||
return MSD_ERROR; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Handles SD card interrupt request. |
||||
* @retval None |
||||
*/ |
||||
void BSP_SD_IRQHandler(void) |
||||
{ |
||||
HAL_SD_IRQHandler(&uSdHandle); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Handles SD DMA Tx transfer interrupt request. |
||||
* @retval None |
||||
*/ |
||||
void BSP_SD_DMA_Tx_IRQHandler(void) |
||||
{ |
||||
HAL_DMA_IRQHandler(uSdHandle.hdmatx); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Handles SD DMA Rx transfer interrupt request. |
||||
* @retval None |
||||
*/ |
||||
void BSP_SD_DMA_Rx_IRQHandler(void) |
||||
{ |
||||
HAL_DMA_IRQHandler(uSdHandle.hdmarx); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Gets the current SD card data status. |
||||
* @param None |
||||
* @retval Data transfer state. |
||||
*/ |
||||
uint8_t BSP_SD_GetCardState(void) |
||||
{ |
||||
HAL_SD_CardStateTypedef card_state; |
||||
card_state = HAL_SD_GetCardState(&uSdHandle); |
||||
|
||||
if (card_state == HAL_SD_CARD_TRANSFER) |
||||
{ |
||||
return (SD_TRANSFER_OK); |
||||
} |
||||
else if ((card_state == HAL_SD_CARD_SENDING) || |
||||
(card_state == HAL_SD_CARD_RECEIVING) || |
||||
(card_state == HAL_SD_CARD_PROGRAMMING)) |
||||
{ |
||||
return (SD_TRANSFER_BUSY); |
||||
} |
||||
else |
||||
{ |
||||
return (SD_TRANSFER_ERROR); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get SD information about specific SD card. |
||||
* @param CardInfo: Pointer to HAL_SD_CardInfoTypedef structure |
||||
* @retval None |
||||
*/ |
||||
void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo) |
||||
{ |
||||
/* Get SD card Information */ |
||||
HAL_SD_GetCardInfo(&uSdHandle, CardInfo); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes the SD MSP. |
||||
* @note The SDMMC clock configuration done within this function assumes that |
||||
* the PLLSAI1 input clock runs at 8 MHz. |
||||
* @param hsd: SD handle |
||||
* @param Params: Additional parameters |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params) |
||||
{ |
||||
GPIO_InitTypeDef gpioinitstruct = {0}; |
||||
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit; |
||||
|
||||
/* Prevent unused argument(s) compilation warning */ |
||||
UNUSED(Params); |
||||
|
||||
HAL_RCCEx_GetPeriphCLKConfig(&RCC_PeriphClkInit); |
||||
|
||||
/* Configure the SDMMC1 clock source. The clock is derived from the PLLSAI1 */ |
||||
/* Hypothesis is that PLLSAI1 VCO input is 8Mhz */ |
||||
RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC1; |
||||
RCC_PeriphClkInit.PLLSAI1.PLLSAI1N = 24; |
||||
RCC_PeriphClkInit.PLLSAI1.PLLSAI1Q = 4; |
||||
RCC_PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK; |
||||
RCC_PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLSAI1; |
||||
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) |
||||
{ |
||||
while (1) {} |
||||
} |
||||
|
||||
/* Enable SDMMC1 clock */ |
||||
__HAL_RCC_SDMMC1_CLK_ENABLE(); |
||||
|
||||
/* Enable DMA2 clocks */ |
||||
SD_DMAx_CLK_ENABLE(); |
||||
|
||||
/* Enable GPIOs clock */ |
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOD_CLK_ENABLE(); |
||||
|
||||
/* Common GPIO configuration */ |
||||
gpioinitstruct.Mode = GPIO_MODE_AF_PP; |
||||
gpioinitstruct.Pull = GPIO_NOPULL; |
||||
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||
gpioinitstruct.Alternate = GPIO_AF12_SDMMC1; |
||||
|
||||
/* GPIOC configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; |
||||
|
||||
HAL_GPIO_Init(GPIOC, &gpioinitstruct); |
||||
|
||||
/* GPIOD configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_2; |
||||
HAL_GPIO_Init(GPIOD, &gpioinitstruct); |
||||
|
||||
/* NVIC configuration for SDMMC1 interrupts */ |
||||
HAL_NVIC_SetPriority(SDMMCx_IRQn, 5, 0); |
||||
HAL_NVIC_EnableIRQ(SDMMCx_IRQn); |
||||
|
||||
/* DMA initialization should be done here but , as there is only one channel for RX and TX it is configured and done directly when required*/ |
||||
} |
||||
|
||||
/**
|
||||
* @brief De-Initializes the SD MSP. |
||||
* @param hsd: SD handle |
||||
* @param Params: Additional parameters |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params) |
||||
{ |
||||
GPIO_InitTypeDef gpioinitstruct = {0}; |
||||
|
||||
/* Prevent unused argument(s) compilation warning */ |
||||
UNUSED(Params); |
||||
|
||||
/* Enable SDMMC1 clock */ |
||||
__HAL_RCC_SDMMC1_CLK_DISABLE(); |
||||
|
||||
/* Enable DMA2 clocks */ |
||||
SD_DMAx_CLK_DISABLE(); |
||||
|
||||
/* Enable GPIOs clock */ |
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOD_CLK_ENABLE(); |
||||
|
||||
/* Common GPIO configuration */ |
||||
gpioinitstruct.Mode = GPIO_MODE_ANALOG; |
||||
gpioinitstruct.Pull = GPIO_NOPULL; |
||||
gpioinitstruct.Speed = GPIO_SPEED_FREQ_LOW; |
||||
gpioinitstruct.Alternate = 0; |
||||
|
||||
/* GPIOC configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; |
||||
|
||||
HAL_GPIO_Init(GPIOC, &gpioinitstruct); |
||||
|
||||
/* GPIOD configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_2; |
||||
HAL_GPIO_Init(GPIOD, &gpioinitstruct); |
||||
|
||||
/* NVIC configuration for SDMMC1 interrupts */ |
||||
HAL_NVIC_DisableIRQ(SDMMCx_IRQn); |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief BSP SD Abort callback |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_SD_AbortCallback(void) |
||||
{ |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief BSP Tx Transfer completed callback |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_SD_WriteCpltCallback(void) |
||||
{ |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief BSP Rx Transfer completed callback |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_SD_ReadCpltCallback(void) |
||||
{ |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief SD Abort callback |
||||
* @param hsd: SD handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd) |
||||
{ |
||||
BSP_SD_AbortCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callback |
||||
* @param hsd: SD handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd) |
||||
{ |
||||
BSP_SD_WriteCpltCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Rx Transfer completed callback |
||||
* @param hsd: SD handle |
||||
* @retval None |
||||
*/ |
||||
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd) |
||||
{ |
||||
BSP_SD_ReadCpltCallback(); |
||||
} |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_SD_Private_Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes the SD Detect pin MSP. |
||||
* @param hsd: SD handle |
||||
* @param Params |
||||
* @retval None |
||||
*/ |
||||
static void SD_Detect_MspInit(void) |
||||
{ |
||||
if (BSP_IO_Init() == IO_ERROR) |
||||
{ |
||||
BSP_ErrorHandler(); |
||||
} |
||||
BSP_IO_ConfigPin(SD_DETECT_PIN, IO_MODE_INPUT_PU); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes the SD Detect pin MSP. |
||||
* @param hsd: SD handle |
||||
* @param Params |
||||
* @retval None |
||||
*/ |
||||
static void SD_Detect_MspDeInit(void) |
||||
{ |
||||
/* Disable all interrupts */ |
||||
/*HAL_NVIC_DisableIRQ(MFX_INT_EXTI_IRQn);*/ |
||||
|
||||
if (BSP_IO_Init() == IO_ERROR) |
||||
{ |
||||
BSP_ErrorHandler(); |
||||
} |
||||
BSP_IO_ConfigPin(SD_DETECT_PIN, IO_MODE_ANALOG); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configure the DMA to receive data from the SD card |
||||
* @retval |
||||
* HAL_ERROR or HAL_OK |
||||
*/ |
||||
static HAL_StatusTypeDef SD_DMAConfigRx(SD_HandleTypeDef *hsd) |
||||
{ |
||||
static DMA_HandleTypeDef hdma_rx; |
||||
HAL_StatusTypeDef status = HAL_ERROR; |
||||
|
||||
/* Configure DMA Rx parameters */ |
||||
hdma_rx.Init.Request = DMA_REQUEST_7; |
||||
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||||
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE; |
||||
hdma_rx.Init.MemInc = DMA_MINC_ENABLE; |
||||
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; |
||||
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
||||
hdma_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH; |
||||
|
||||
hdma_rx.Instance = SD_DMAx_STREAM; |
||||
|
||||
/* Associate the DMA handle */ |
||||
__HAL_LINKDMA(hsd, hdmarx, hdma_rx); |
||||
|
||||
/* Stop any ongoing transfer and reset the state*/ |
||||
HAL_DMA_Abort(&hdma_rx); |
||||
|
||||
/* Deinitialize the Channel for new transfer */ |
||||
HAL_DMA_DeInit(&hdma_rx); |
||||
|
||||
/* Configure the DMA Channel */ |
||||
status = HAL_DMA_Init(&hdma_rx); |
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */ |
||||
HAL_NVIC_SetPriority(SD_DMAx_IRQn, 6, 0); |
||||
HAL_NVIC_EnableIRQ(SD_DMAx_IRQn); |
||||
|
||||
return (status); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Configure the DMA to transmit data to the SD card |
||||
* @retval |
||||
* HAL_ERROR or HAL_OK |
||||
*/ |
||||
static HAL_StatusTypeDef SD_DMAConfigTx(SD_HandleTypeDef *hsd) |
||||
{ |
||||
static DMA_HandleTypeDef hdma_tx; |
||||
HAL_StatusTypeDef status; |
||||
|
||||
/* Configure DMA Tx parameters */ |
||||
hdma_tx.Init.Request = DMA_REQUEST_7; |
||||
hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
||||
hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
||||
hdma_tx.Init.MemInc = DMA_MINC_ENABLE; |
||||
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; |
||||
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
||||
hdma_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH; |
||||
|
||||
hdma_tx.Instance = SD_DMAx_STREAM; |
||||
|
||||
/* Associate the DMA handle */ |
||||
__HAL_LINKDMA(hsd, hdmatx, hdma_tx); |
||||
|
||||
/* Stop any ongoing transfer and reset the state*/ |
||||
HAL_DMA_Abort(&hdma_tx); |
||||
|
||||
/* Deinitialize the Channel for new transfer */ |
||||
HAL_DMA_DeInit(&hdma_tx); |
||||
|
||||
/* Configure the DMA Channel */ |
||||
status = HAL_DMA_Init(&hdma_tx); |
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */ |
||||
HAL_NVIC_SetPriority(SD_DMAx_IRQn, 6, 0); |
||||
HAL_NVIC_EnableIRQ(SD_DMAx_IRQn); |
||||
|
||||
return (status); |
||||
} |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,149 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_sd.h |
||||
* @author MCD Application Team |
||||
* @brief This file includes the uSD card driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_SD_H |
||||
#define __STM32L496G_DISCOVERY_SD_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l4xx_hal.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_SD
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Exported types ------------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SD_Exported_Types Exported Types
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief SD Card information structure |
||||
*/ |
||||
#define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief SD status structure definition |
||||
*/ |
||||
#define MSD_OK ((uint8_t)0x00) |
||||
#define MSD_ERROR ((uint8_t)0x01) |
||||
#define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02) |
||||
|
||||
/**
|
||||
* @brief SD transfer state definition |
||||
*/ |
||||
#define SD_TRANSFER_OK ((uint8_t)0x00) |
||||
#define SD_TRANSFER_BUSY ((uint8_t)0x01) |
||||
#define SD_TRANSFER_ERROR ((uint8_t)0x02) |
||||
|
||||
/* Exported constants --------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SD_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
#define SD_DETECT_PIN IO1_PIN_8 |
||||
|
||||
#define SD_DATATIMEOUT ((uint32_t)100000000) |
||||
|
||||
#define SD_PRESENT ((uint8_t)0x01) |
||||
#define SD_NOT_PRESENT ((uint8_t)0x00) |
||||
|
||||
/* SD IRQ handler */ |
||||
#define SDMMCx_IRQHandler SDMMC1_IRQHandler |
||||
#define SDMMCx_IRQn SDMMC1_IRQn |
||||
|
||||
|
||||
/* DMA definitions for SD DMA transfer */ |
||||
#define SD_DMAx_CLK_ENABLE __HAL_RCC_DMA2_CLK_ENABLE |
||||
#define SD_DMAx_CLK_DISABLE __HAL_RCC_DMA2_CLK_DISABLE |
||||
#define SD_DMAx_STREAM DMA2_Channel5 |
||||
#define SD_DMAx_IRQn DMA2_Channel5_IRQn |
||||
#define SD_DMAx_IRQHandler DMA2_Channel5_IRQHandler |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SD_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_SD_Init(void); |
||||
uint8_t BSP_SD_DeInit(void); |
||||
uint8_t BSP_SD_ITConfig(void); |
||||
uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout); |
||||
uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout); |
||||
uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks); |
||||
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks); |
||||
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); |
||||
void BSP_SD_IRQHandler(void); |
||||
void BSP_SD_DMA_Tx_IRQHandler(void); |
||||
void BSP_SD_DMA_Rx_IRQHandler(void); |
||||
uint8_t BSP_SD_GetCardState(void); |
||||
void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo); |
||||
uint8_t BSP_SD_IsDetected(void); |
||||
|
||||
/* These __weak functions can be surcharged by application code in case the current settings
|
||||
(eg. interrupt priority, callbacks implementation) need to be changed for specific application needs */ |
||||
void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params); |
||||
void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params); |
||||
void BSP_SD_AbortCallback(void); |
||||
void BSP_SD_WriteCpltCallback(void); |
||||
void BSP_SD_ReadCpltCallback(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_SD_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,358 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_sram.c |
||||
* @author MCD Application Team |
||||
* @brief This file provides a set of functions needed to drive the |
||||
* IS66WV51216EBLL SRAM memory mounted on STM32L496G-Discovery board. |
||||
@verbatim |
||||
============================================================================== |
||||
##### How to use this driver ##### |
||||
============================================================================== |
||||
[..] |
||||
(#) This driver is used to drive the IS66WV51216EBLL-70BLI SRAM external memory mounted |
||||
on STM32L496G-Discovery evaluation board. |
||||
|
||||
(#) This driver does not need a specific component driver for the SRAM device |
||||
to be included with. |
||||
|
||||
(#) Initialization steps: |
||||
(++) Initialize the SRAM external memory using the BSP_SRAM_Init() function. This |
||||
function includes the MSP layer hardware resources initialization and the |
||||
FMC controller configuration to interface with the external SRAM memory. |
||||
|
||||
(#) SRAM read/write operations |
||||
(++) SRAM 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_SRAM_ReadData()/BSP_SRAM_WriteData(), or by DMA transfer using the functions |
||||
BSP_SRAM_ReadData_DMA()/BSP_SRAM_WriteData_DMA(). |
||||
(++) The AHB access is performed with 16-bit width transaction, the DMA transfer |
||||
configuration is fixed at single (no burst) halfword transfer |
||||
(see the SRAM_MspInit() static function). |
||||
(++) User can implement his own functions for read/write access with his desired |
||||
configurations. |
||||
(++) If interrupt mode is used for DMA transfer, the function BSP_SRAM_DMA_IRQHandler() |
||||
is called in IRQ handler file, to serve the generated interrupt once the DMA |
||||
transfer is complete. |
||||
@endverbatim |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery_sram.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM STM32L496G-DISCOVERY SRAM
|
||||
* @{ |
||||
*/ |
||||
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM_Private_Variables Private Variables
|
||||
* @{ |
||||
*/ |
||||
static SRAM_HandleTypeDef sramHandle; |
||||
static FMC_NORSRAM_TimingTypeDef Timing; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private macros ------------------------------------------------------------*/ |
||||
/* Private constants ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM_Private_Constants Private Constants
|
||||
* @{ |
||||
*/ |
||||
/* Timings for SRAM IS66WV51216EBLL-70BLI */ |
||||
#define SRAM_ADDR_SETUP_TIME 5 /* 60ns with a clock at 80 MHz (period of 12.5 ns) */ |
||||
#define SRAM_DATA_SETUP_TIME 3 /* 30ns with a clock at 80 MHz (period of 12.5 ns) */ |
||||
#define SRAM_TURN_AROUND_TIME 1 /* 5ns with a clock at 80 MHz (perido of 12.5 ns) */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private function prototypes -----------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM_Private_Functions Private Functions
|
||||
* @{ |
||||
*/ |
||||
static void SRAM_MspInit(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/* Private functions ---------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM_Exported_Functions Exported Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes the SRAM device. |
||||
* @retval SRAM status |
||||
*/ |
||||
uint8_t BSP_SRAM_Init(void) |
||||
{ |
||||
sramHandle.Instance = FMC_NORSRAM_DEVICE; |
||||
sramHandle.Extended = FMC_NORSRAM_EXTENDED_DEVICE; |
||||
|
||||
/* SRAM device configuration */ |
||||
Timing.AddressSetupTime = SRAM_ADDR_SETUP_TIME; |
||||
Timing.DataSetupTime = SRAM_DATA_SETUP_TIME; |
||||
Timing.BusTurnAroundDuration = SRAM_TURN_AROUND_TIME; |
||||
Timing.AccessMode = FMC_ACCESS_MODE_A; |
||||
|
||||
sramHandle.Init.NSBank = FMC_NORSRAM_BANK2; |
||||
sramHandle.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; |
||||
sramHandle.Init.MemoryType = FMC_MEMORY_TYPE_SRAM; |
||||
sramHandle.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16; |
||||
sramHandle.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE; |
||||
sramHandle.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE; |
||||
sramHandle.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE; |
||||
sramHandle.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; |
||||
sramHandle.Init.WriteBurst = FMC_WRITE_BURST_DISABLE; |
||||
sramHandle.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY; |
||||
sramHandle.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE; |
||||
sramHandle.Init.PageSize = FMC_PAGE_SIZE_NONE; |
||||
|
||||
/* SRAM controller initialization */ |
||||
SRAM_MspInit(); |
||||
if (HAL_SRAM_Init(&sramHandle, &Timing, &Timing) != HAL_OK) |
||||
{ |
||||
return SRAM_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
return SRAM_OK; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Reads an amount of data from the SRAM device in polling mode. |
||||
* @param uwStartAddress: Read start address |
||||
* @param pData: Pointer to data to be read |
||||
* @param uwDataSize: Size of read data from the memory |
||||
* @retval SRAM status |
||||
*/ |
||||
uint8_t BSP_SRAM_ReadData(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize) |
||||
{ |
||||
if (HAL_SRAM_Read_16b(&sramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK) |
||||
{ |
||||
return SRAM_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
return SRAM_OK; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Reads an amount of data from the SRAM device in DMA mode. |
||||
* @param uwStartAddress: Read start address |
||||
* @param pData: Pointer to data to be read |
||||
* @param uwDataSize: Size of read data from the memory |
||||
* @retval SRAM status |
||||
*/ |
||||
uint8_t BSP_SRAM_ReadData_DMA(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize) |
||||
{ |
||||
if (HAL_SRAM_Read_DMA(&sramHandle, (uint32_t *)uwStartAddress, (uint32_t *)pData, uwDataSize) != HAL_OK) |
||||
{ |
||||
return SRAM_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
return SRAM_OK; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Writes an amount of data from the SRAM device in polling mode. |
||||
* @param uwStartAddress: Write start address |
||||
* @param pData: Pointer to data to be written |
||||
* @param uwDataSize: Size of written data from the memory |
||||
* @retval SRAM status |
||||
*/ |
||||
uint8_t BSP_SRAM_WriteData(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize) |
||||
{ |
||||
if (HAL_SRAM_Write_16b(&sramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK) |
||||
{ |
||||
return SRAM_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
return SRAM_OK; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Writes an amount of data from the SRAM device in DMA mode. |
||||
* @param uwStartAddress: Write start address |
||||
* @param pData: Pointer to data to be written |
||||
* @param uwDataSize: Size of written data from the memory |
||||
* @retval SRAM status |
||||
*/ |
||||
uint8_t BSP_SRAM_WriteData_DMA(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize) |
||||
{ |
||||
if (HAL_SRAM_Write_DMA(&sramHandle, (uint32_t *)uwStartAddress, (uint32_t *)pData, uwDataSize) != HAL_OK) |
||||
{ |
||||
return SRAM_ERROR; |
||||
} |
||||
else |
||||
{ |
||||
return SRAM_OK; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief Handles SRAM DMA transfer interrupt request. |
||||
* @retval None |
||||
*/ |
||||
void BSP_SRAM_DMA_IRQHandler(void) |
||||
{ |
||||
HAL_DMA_IRQHandler(sramHandle.hdma); |
||||
} |
||||
|
||||
/** @addtogroup STM32L476G_EVAL_SRAM_Private_Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Initializes SRAM MSP. |
||||
* @retval None |
||||
*/ |
||||
static void SRAM_MspInit(void) |
||||
{ |
||||
static DMA_HandleTypeDef dmaHandle; |
||||
GPIO_InitTypeDef gpioinitstruct; |
||||
SRAM_HandleTypeDef *hsram = &sramHandle; |
||||
|
||||
/* Enable FMC clock */ |
||||
__HAL_RCC_FMC_CLK_ENABLE(); |
||||
|
||||
/* Enable chosen DMAx clock */ |
||||
SRAM_DMAx_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_PWR_CLK_ENABLE(); |
||||
HAL_PWREx_EnableVddIO2(); |
||||
|
||||
/* Common GPIO configuration */ |
||||
gpioinitstruct.Mode = GPIO_MODE_AF_PP; |
||||
gpioinitstruct.Pull = GPIO_NOPULL; |
||||
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||
gpioinitstruct.Alternate = GPIO_AF12_FMC; |
||||
|
||||
/*## Data Bus #######*/ |
||||
/* GPIOD configuration */ |
||||
gpioinitstruct.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, &gpioinitstruct); |
||||
|
||||
/* GPIOE configuration */ |
||||
gpioinitstruct.Pin = 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, &gpioinitstruct); |
||||
|
||||
/*## Address Bus #######*/ |
||||
/* GPIOD configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; |
||||
HAL_GPIO_Init(GPIOD, &gpioinitstruct); |
||||
|
||||
/* GPIOF configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | |
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | |
||||
GPIO_PIN_14 | GPIO_PIN_15; |
||||
HAL_GPIO_Init(GPIOF, &gpioinitstruct); |
||||
|
||||
/* GPIOG configuration */ |
||||
gpioinitstruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | |
||||
GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5; |
||||
HAL_GPIO_Init(GPIOG, &gpioinitstruct); |
||||
|
||||
/*## NOE and NWE configuration #######*/ |
||||
gpioinitstruct.Pull = GPIO_PULLUP; |
||||
gpioinitstruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; |
||||
HAL_GPIO_Init(GPIOD, &gpioinitstruct); |
||||
HAL_Delay(1); |
||||
|
||||
/*## NBL0, NBL1 configuration #######*/ |
||||
gpioinitstruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; |
||||
HAL_GPIO_Init(GPIOE, &gpioinitstruct); |
||||
|
||||
/*## NE configuration #######*/ |
||||
gpioinitstruct.Pin = GPIO_PIN_9; |
||||
HAL_GPIO_Init(GPIOG, &gpioinitstruct); |
||||
|
||||
/* Configure common DMA parameters */ |
||||
dmaHandle.Init.Direction = DMA_MEMORY_TO_MEMORY; |
||||
dmaHandle.Init.PeriphInc = DMA_PINC_ENABLE; |
||||
dmaHandle.Init.MemInc = DMA_MINC_ENABLE; |
||||
dmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; |
||||
dmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; |
||||
dmaHandle.Init.Mode = DMA_NORMAL; |
||||
dmaHandle.Init.Priority = DMA_PRIORITY_HIGH; |
||||
|
||||
dmaHandle.Instance = SRAM_DMAx_CHANNEL; |
||||
|
||||
/* Associate the DMA handle */ |
||||
__HAL_LINKDMA(hsram, hdma, dmaHandle); |
||||
|
||||
/* Deinitialize the Stream for new transfer */ |
||||
HAL_DMA_DeInit(&dmaHandle); |
||||
|
||||
/* Configure the DMA Stream */ |
||||
HAL_DMA_Init(&dmaHandle); |
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */ |
||||
HAL_NVIC_SetPriority(SRAM_DMAx_IRQn, 5, 0); |
||||
HAL_NVIC_EnableIRQ(SRAM_DMAx_IRQn); |
||||
} |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,114 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_sram.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_sram.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_SRAM_H |
||||
#define __STM32L496G_DISCOVERY_SRAM_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l4xx_hal.h" |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_SRAM
|
||||
* @{ |
||||
*/ |
||||
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/ |
||||
|
||||
/** @defgroup STM32L496G_DISCOVERY_SRAM_Exported_Constants Exported Constants
|
||||
* @{ |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief SRAM status structure definition |
||||
*/ |
||||
#define SRAM_OK 0x00 |
||||
#define SRAM_ERROR 0x01 |
||||
|
||||
#define SRAM_DEVICE_ADDR ((uint32_t)0x64000000) |
||||
#define SRAM_DEVICE_SIZE ((uint32_t)0x80000) /* SRAM device size in MBytes */ |
||||
|
||||
/* #define SRAM_MEMORY_WIDTH FMC_NORSRAM_MEM_BUS_WIDTH_8 */ |
||||
#define SRAM_MEMORY_WIDTH FMC_NORSRAM_MEM_BUS_WIDTH_16 |
||||
|
||||
#define SRAM_BURSTACCESS FMC_BURST_ACCESS_MODE_DISABLE |
||||
/* #define SRAM_BURSTACCESS FMC_BURST_ACCESS_MODE_ENABLE*/ |
||||
|
||||
#define SRAM_WRITEBURST FMC_WRITE_BURST_DISABLE |
||||
/* #define SRAM_WRITEBURST FMC_WRITE_BURST_ENABLE */ |
||||
|
||||
/* DMA definitions for SRAM DMA transfer */ |
||||
#define SRAM_DMAx_CLK_ENABLE __HAL_RCC_DMA1_CLK_ENABLE |
||||
#define SRAM_DMAx_CHANNEL DMA1_Channel1 |
||||
#define SRAM_DMAx_IRQn DMA1_Channel1_IRQn |
||||
#define SRAM_DMAx_IRQHandler DMA1_Channel1_IRQHandler |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/ |
||||
|
||||
/** @addtogroup STM32L496G_DISCOVERY_SRAM_Exported_Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_SRAM_Init(void); |
||||
uint8_t BSP_SRAM_ReadData(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize); |
||||
uint8_t BSP_SRAM_ReadData_DMA(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize); |
||||
uint8_t BSP_SRAM_WriteData(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize); |
||||
uint8_t BSP_SRAM_WriteData_DMA(uint32_t uwStartAddress, uint16_t *pData, uint32_t uwDataSize); |
||||
void BSP_SRAM_DMA_IRQHandler(void); |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_SRAM_H */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,517 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_ts.c |
||||
* @author MCD Application Team |
||||
* @brief This file provides a set of functions needed to manage the Touch |
||||
* Screen on STM32L496G-DISCOVERY evaluation board. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* File Info : -----------------------------------------------------------------
|
||||
User NOTES |
||||
1. How To use this driver: |
||||
-------------------------- |
||||
- This driver is used to drive the touch screen module of the STM32L496G-DISCOVERY |
||||
evaluation board on the FRIDA LCD mounted on MB1261 daughter board. |
||||
The touch screen driver IC is a FT6x36 type which share the same register naming |
||||
with FT6206 type. |
||||
|
||||
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. |
||||
|
||||
+ 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_StateTypeDef structure. |
||||
------------------------------------------------------------------------------*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery.h" |
||||
#include "stm32l496g_discovery_ts.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G-DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS STM32L496G-DISCOVERY TS
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Types_Definitions TS Private Types Definitions
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Defines TS Private Types Defines
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Macros TS Private Macros
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Imported_Variables TS Imported Variables
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Variables TS Private Variables
|
||||
* @{ |
||||
*/ |
||||
static TS_DrvTypeDef *tsDriver; |
||||
static uint8_t I2C_Address = 0; |
||||
static uint8_t tsOrientation = TS_SWAP_NONE; |
||||
static uint8_t TS_orientation = TS_ORIENTATION_UNDEFINED; |
||||
|
||||
/* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */ |
||||
char *ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None", |
||||
"Press down", |
||||
"Lift up", |
||||
"Contact" |
||||
}; |
||||
|
||||
/* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */ |
||||
char *ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None", |
||||
"Move Up", |
||||
"Move Right", |
||||
"Move Down", |
||||
"Move Left", |
||||
"Zoom In", |
||||
"Zoom Out" |
||||
}; |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Function_Prototypes TS Private Function Prototypes
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Public_Functions TS Public Functions
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @brief Initializes and configures the touch screen functionalities and |
||||
* configures all necessary hardware resources (GPIOs, I2C, clocks..). |
||||
* @param ts_SizeX : Maximum X size of the TS area on LCD |
||||
* @param ts_SizeY : Maximum Y size of the TS area on LCD |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY) |
||||
{ |
||||
return (BSP_TS_InitEx(ts_SizeX, ts_SizeY, TS_ORIENTATION_LANDSCAPE)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes and configures the touch screen functionalities and |
||||
* configures all necessary hardware resources (GPIOs, I2C, clocks..) |
||||
* with a given orientation |
||||
* @param ts_SizeX : Maximum X size of the TS area on LCD |
||||
* @param ts_SizeY : Maximum Y size of the TS area on LCD |
||||
* @param orientation : TS_ORIENTATION_LANDSCAPE or TS_ORIENTATION_PORTRAIT |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_InitEx(uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation) |
||||
{ |
||||
uint8_t ts_status = TS_OK; |
||||
uint16_t read_id = 0; |
||||
|
||||
/* Note : I2C_Address is un-initialized here, but is not used at all in init function */ |
||||
/* but the prototype of Init() is like that in template and should be respected */ |
||||
|
||||
/* Initialize the communication channel to sensor (I2C) if necessary */ |
||||
/* that is initialization is done only once after a power up */ |
||||
ft6x06_ts_drv.Init(I2C_Address); |
||||
|
||||
/* Scan FT6x36 TouchScreen IC controller ID register by I2C Read */ |
||||
/* Verify this is a FT6x36, otherwise this is an error case */ |
||||
|
||||
read_id = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS); |
||||
|
||||
if (read_id == FT6x36_ID_VALUE) |
||||
{ |
||||
/* Found FT6x36 : Initialize the TS driver structure */ |
||||
tsDriver = &ft6x06_ts_drv; |
||||
|
||||
I2C_Address = TS_I2C_ADDRESS; |
||||
|
||||
/* Get LCD chosen orientation */ |
||||
if (orientation == TS_ORIENTATION_PORTRAIT) |
||||
{ |
||||
tsOrientation = TS_SWAP_X | TS_SWAP_Y; |
||||
TS_orientation = TS_ORIENTATION_PORTRAIT; |
||||
} |
||||
else |
||||
{ |
||||
tsOrientation = TS_SWAP_XY | TS_SWAP_Y; |
||||
TS_orientation = TS_ORIENTATION_LANDSCAPE; |
||||
} |
||||
|
||||
if (ts_status == TS_OK) |
||||
{ |
||||
/* Software reset the TouchScreen */ |
||||
tsDriver->Reset(I2C_Address); |
||||
|
||||
/* Calibrate, Configure and Start the TouchScreen driver */ |
||||
tsDriver->Start(I2C_Address); |
||||
|
||||
return TS_OK; |
||||
|
||||
} /* of if(ts_status == TS_OK) */ |
||||
} |
||||
|
||||
return TS_DEVICE_NOT_FOUND; |
||||
|
||||
|
||||
} |
||||
|
||||
/**
|
||||
* @brief Configures and enables the touch screen interrupts. |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_ITConfig(void) |
||||
{ |
||||
uint8_t ts_status = TS_OK; |
||||
|
||||
/* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x36 */ |
||||
/* When touchscreen is operated in interrupt mode */ |
||||
BSP_TS_INT_MspInit(); |
||||
|
||||
/* Enable the TS in interrupt mode */ |
||||
/* In that case the INT output of FT6206 when new touch is available */ |
||||
/* is active on low level and directed on EXTI */ |
||||
tsDriver->EnableIT(I2C_Address); |
||||
|
||||
return (ts_status); |
||||
} |
||||
|
||||
/**
|
||||
* @brief deConfigures and enables the touch screen interrupts. |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_ITDeConfig(void) |
||||
{ |
||||
uint8_t ts_status = TS_OK; |
||||
|
||||
/* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x36 */ |
||||
/* When touchscreen is operated in interrupt mode */ |
||||
BSP_TS_INT_MspDeInit(); |
||||
|
||||
/* Enable the TS in interrupt mode */ |
||||
/* In that case the INT output of FT6206 when new touch is available */ |
||||
/* is active on low level and directed on EXTI */ |
||||
tsDriver->DisableIT(I2C_Address); |
||||
|
||||
return (ts_status); |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* @brief Returns status and positions of the touch screen. |
||||
* @param TS_State: Pointer to touch screen current state structure |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) |
||||
{ |
||||
static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0}; |
||||
static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0}; |
||||
uint8_t ts_status = TS_OK; |
||||
uint16_t tmp; |
||||
uint16_t Raw_x[TS_MAX_NB_TOUCH]; |
||||
uint16_t Raw_y[TS_MAX_NB_TOUCH]; |
||||
uint16_t xDiff; |
||||
uint16_t yDiff; |
||||
uint32_t index; |
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
uint32_t weight = 0; |
||||
uint32_t area = 0; |
||||
uint32_t event = 0; |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
/* Check and update the number of touches active detected */ |
||||
TS_State->touchDetected = tsDriver->DetectTouch(I2C_Address); |
||||
if (TS_State->touchDetected) |
||||
{ |
||||
for (index = 0; index < TS_State->touchDetected; index++) |
||||
{ |
||||
/* Get each touch coordinates */ |
||||
tsDriver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index])); |
||||
|
||||
if (tsOrientation & TS_SWAP_XY) |
||||
{ |
||||
tmp = Raw_x[index]; |
||||
Raw_x[index] = Raw_y[index]; |
||||
Raw_y[index] = tmp; |
||||
} |
||||
|
||||
if (tsOrientation & TS_SWAP_X) |
||||
{ |
||||
Raw_x[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_x[index]; |
||||
} |
||||
|
||||
if (tsOrientation & TS_SWAP_Y) |
||||
{ |
||||
Raw_y[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_y[index]; |
||||
} |
||||
|
||||
xDiff = Raw_x[index] > _x[index] ? (Raw_x[index] - _x[index]) : (_x[index] - Raw_x[index]); |
||||
yDiff = Raw_y[index] > _y[index] ? (Raw_y[index] - _y[index]) : (_y[index] - Raw_y[index]); |
||||
|
||||
if ((xDiff + yDiff) > 5) |
||||
{ |
||||
_x[index] = Raw_x[index]; |
||||
_y[index] = Raw_y[index]; |
||||
} |
||||
|
||||
|
||||
TS_State->touchX[index] = _x[index]; |
||||
TS_State->touchY[index] = _y[index]; |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
|
||||
/* Get touch info related to the current touch */ |
||||
ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event); |
||||
|
||||
/* Update TS_State structure */ |
||||
TS_State->touchWeight[index] = weight; |
||||
TS_State->touchArea[index] = area; |
||||
|
||||
/* Remap touch event */ |
||||
switch (event) |
||||
{ |
||||
case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN : |
||||
TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN; |
||||
break; |
||||
case FT6206_TOUCH_EVT_FLAG_LIFT_UP : |
||||
TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP; |
||||
break; |
||||
case FT6206_TOUCH_EVT_FLAG_CONTACT : |
||||
TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT; |
||||
break; |
||||
case FT6206_TOUCH_EVT_FLAG_NO_EVENT : |
||||
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
||||
break; |
||||
default : |
||||
ts_status = TS_ERROR; |
||||
break; |
||||
} /* of switch(event) */ |
||||
|
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
} /* of for(index=0; index < TS_State->touchDetected; index++) */ |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
/* Get gesture Id */ |
||||
ts_status = BSP_TS_Get_GestureId(TS_State); |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
} /* end of if(TS_State->touchDetected != 0) */ |
||||
|
||||
return (ts_status); |
||||
} |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
/**
|
||||
* @brief Update gesture Id following a touch detected. |
||||
* @param TS_State: Pointer to touch screen current state structure |
||||
* @retval TS_OK if all initializations are OK. Other value if error. |
||||
*/ |
||||
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State) |
||||
{ |
||||
uint32_t gestureId = 0; |
||||
uint8_t ts_status = TS_OK; |
||||
|
||||
/* Get gesture Id */ |
||||
ft6x06_TS_GetGestureID(I2C_Address, &gestureId); |
||||
|
||||
/* Remap gesture Id to a TS_GestureIdTypeDef value */ |
||||
switch (gestureId) |
||||
{ |
||||
case FT6206_GEST_ID_NO_GESTURE : |
||||
TS_State->gestureId = GEST_ID_NO_GESTURE; |
||||
break; |
||||
case FT6206_GEST_ID_MOVE_UP : |
||||
TS_State->gestureId = GEST_ID_MOVE_UP; |
||||
break; |
||||
case FT6206_GEST_ID_MOVE_RIGHT : |
||||
TS_State->gestureId = GEST_ID_MOVE_RIGHT; |
||||
break; |
||||
case FT6206_GEST_ID_MOVE_DOWN : |
||||
TS_State->gestureId = GEST_ID_MOVE_DOWN; |
||||
break; |
||||
case FT6206_GEST_ID_MOVE_LEFT : |
||||
TS_State->gestureId = GEST_ID_MOVE_LEFT; |
||||
break; |
||||
case FT6206_GEST_ID_ZOOM_IN : |
||||
TS_State->gestureId = GEST_ID_ZOOM_IN; |
||||
break; |
||||
case FT6206_GEST_ID_ZOOM_OUT : |
||||
TS_State->gestureId = GEST_ID_ZOOM_OUT; |
||||
break; |
||||
default : |
||||
ts_status = TS_ERROR; |
||||
break; |
||||
} /* of switch(gestureId) */ |
||||
|
||||
return (ts_status); |
||||
} |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Private_Functions TS Private Functions
|
||||
* @{ |
||||
*/ |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
/**
|
||||
* @brief Function used to reset all touch data before a new acquisition |
||||
* of touch information. |
||||
* @param TS_State: Pointer to touch screen current state structure |
||||
* @retval TS_OK if OK, TE_ERROR if problem found. |
||||
*/ |
||||
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State) |
||||
{ |
||||
uint8_t ts_status = TS_ERROR; |
||||
uint32_t index; |
||||
|
||||
if (TS_State != (TS_StateTypeDef *)NULL) |
||||
{ |
||||
TS_State->gestureId = GEST_ID_NO_GESTURE; |
||||
TS_State->touchDetected = 0; |
||||
|
||||
for (index = 0; index < TS_MAX_NB_TOUCH; index++) |
||||
{ |
||||
TS_State->touchX[index] = 0; |
||||
TS_State->touchY[index] = 0; |
||||
TS_State->touchArea[index] = 0; |
||||
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
||||
TS_State->touchWeight[index] = 0; |
||||
} |
||||
|
||||
ts_status = TS_OK; |
||||
|
||||
} /* of if (TS_State != (TS_StateTypeDef *)NULL) */ |
||||
|
||||
return (ts_status); |
||||
} |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
|
||||
uint8_t BSP_TS_GetOrientation(void) |
||||
{ |
||||
return TS_orientation; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes the TS_INT pin MSP. |
||||
* @param None |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_TS_INT_MspInit(void) |
||||
{ |
||||
GPIO_InitTypeDef gpio_init_structure; |
||||
|
||||
__HAL_RCC_PWR_CLK_ENABLE(); |
||||
SET_BIT(PWR->CR2, PWR_CR2_IOSV); |
||||
|
||||
TS_INT_GPIO_CLK_ENABLE(); |
||||
|
||||
/* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */ |
||||
gpio_init_structure.Pin = TS_INT_PIN; |
||||
|
||||
/* 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_FAST; |
||||
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING; |
||||
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); |
||||
|
||||
/* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */ |
||||
HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x08, 0x00); |
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Initializes the TS_INT pin MSP. |
||||
* @param None |
||||
* @retval None |
||||
*/ |
||||
__weak void BSP_TS_INT_MspDeInit(void) |
||||
{ |
||||
GPIO_InitTypeDef gpio_init_structure; |
||||
|
||||
__HAL_RCC_PWR_CLK_ENABLE(); |
||||
SET_BIT(PWR->CR2, PWR_CR2_IOSV); |
||||
|
||||
TS_INT_GPIO_CLK_ENABLE(); |
||||
|
||||
/* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */ |
||||
gpio_init_structure.Pin = TS_INT_PIN; |
||||
|
||||
gpio_init_structure.Pin = GPIO_PIN_All; |
||||
gpio_init_structure.Mode = GPIO_MODE_ANALOG; |
||||
gpio_init_structure.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); |
||||
|
||||
HAL_NVIC_DisableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); |
||||
} |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -0,0 +1,203 @@
|
||||
/**
|
||||
****************************************************************************** |
||||
* @file stm32l496g_discovery_ts.h |
||||
* @author MCD Application Team |
||||
* @brief This file contains the common defines and functions prototypes for |
||||
* the stm32l496g_discovery_ts.c driver. |
||||
****************************************************************************** |
||||
* @attention |
||||
* |
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. |
||||
* All rights reserved.</center></h2> |
||||
* |
||||
* This software component is licensed by ST under BSD 3-Clause license, |
||||
* the "License"; You may not use this file except in compliance with the |
||||
* License. You may obtain a copy of the License at: |
||||
* opensource.org/licenses/BSD-3-Clause |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __STM32L496G_DISCOVERY_TS_H |
||||
#define __STM32L496G_DISCOVERY_TS_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l496g_discovery.h" |
||||
#include "stm32l496g_discovery_lcd.h" |
||||
|
||||
/* Include TouchScreen component driver */ |
||||
#include "../Components/ft6x06/ft6x06.h" |
||||
|
||||
/** @addtogroup BSP
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @addtogroup STM32L496G-DISCOVERY
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS STM32L496G-DISCOVERY TS
|
||||
* @{ |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Exported_Constants TS Exported Constants
|
||||
* @{ |
||||
*/ |
||||
/** @brief With FT6206 : maximum 2 touches detected simultaneously
|
||||
*/ |
||||
#define TS_MAX_NB_TOUCH ((uint32_t) FT6206_MAX_DETECTABLE_TOUCH) |
||||
|
||||
#define TS_NO_IRQ_PENDING ((uint8_t) 0) |
||||
#define TS_IRQ_PENDING ((uint8_t) 1) |
||||
|
||||
#define TS_SWAP_NONE ((uint8_t) 0x01) |
||||
#define TS_SWAP_X ((uint8_t) 0x02) |
||||
#define TS_SWAP_Y ((uint8_t) 0x04) |
||||
#define TS_SWAP_XY ((uint8_t) 0x08) |
||||
|
||||
#define TS_ORIENTATION_PORTRAIT ((uint8_t) 0) |
||||
#define TS_ORIENTATION_LANDSCAPE ((uint8_t) 1) |
||||
#define TS_ORIENTATION_UNDEFINED ((uint8_t) 2) |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Exported_Types TS Exported Types
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @brief TS_StateTypeDef |
||||
* Define TS State structure |
||||
*/ |
||||
typedef struct |
||||
{ |
||||
uint8_t touchDetected; /*!< Total number of active touches detected at last scan */ |
||||
uint16_t touchX[TS_MAX_NB_TOUCH]; /*!< Touch X[0], X[1] coordinates on 12 bits */ |
||||
uint16_t touchY[TS_MAX_NB_TOUCH]; /*!< Touch Y[0], Y[1] coordinates on 12 bits */ |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
uint8_t touchWeight[TS_MAX_NB_TOUCH]; /*!< Touch_Weight[0], Touch_Weight[1] : weight property of touches */ |
||||
uint8_t touchEventId[TS_MAX_NB_TOUCH]; /*!< Touch_EventId[0], Touch_EventId[1] : take value of type @ref TS_TouchEventTypeDef */ |
||||
uint8_t touchArea[TS_MAX_NB_TOUCH]; /*!< Touch_Area[0], Touch_Area[1] : touch area of each touch */ |
||||
uint32_t gestureId; /*!< type of gesture detected : take value of type @ref TS_GestureIdTypeDef */ |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
} TS_StateTypeDef; |
||||
|
||||
/**
|
||||
* @brief TS_StatusTypeDef |
||||
* Define BSP_TS_xxx() functions possible return value, |
||||
* when status is returned by those functions. |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
TS_OK = 0x00, /*!< Touch Ok */ |
||||
TS_ERROR = 0x01, /*!< Touch Error */ |
||||
TS_TIMEOUT = 0x02, /*!< Touch Timeout */ |
||||
TS_DEVICE_NOT_FOUND = 0x03 /*!< Touchscreen device not found */ |
||||
} TS_StatusTypeDef; |
||||
|
||||
/**
|
||||
* @brief TS_GestureIdTypeDef |
||||
* Define Possible managed gesture identification values returned by touch screen |
||||
* driver. |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
GEST_ID_NO_GESTURE = 0x00, /*!< Gesture not defined / recognized */ |
||||
GEST_ID_MOVE_UP = 0x01, /*!< Gesture Move Up */ |
||||
GEST_ID_MOVE_RIGHT = 0x02, /*!< Gesture Move Right */ |
||||
GEST_ID_MOVE_DOWN = 0x03, /*!< Gesture Move Down */ |
||||
GEST_ID_MOVE_LEFT = 0x04, /*!< Gesture Move Left */ |
||||
GEST_ID_ZOOM_IN = 0x05, /*!< Gesture Zoom In */ |
||||
GEST_ID_ZOOM_OUT = 0x06, /*!< Gesture Zoom Out */ |
||||
GEST_ID_NB_MAX = 0x07 /*!< max number of gesture id */ |
||||
} TS_GestureIdTypeDef; |
||||
|
||||
/**
|
||||
* @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; |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Imported_Variables STM32L496G DISCOVERY TS Imported Variables
|
||||
* @{ |
||||
*/ |
||||
/**
|
||||
* @brief Table for touchscreen event information display on LCD : |
||||
* table indexed on enum @ref TS_TouchEventTypeDef information |
||||
*/ |
||||
extern char *ts_event_string_tab[TOUCH_EVENT_NB_MAX]; |
||||
|
||||
/**
|
||||
* @brief Table for touchscreen gesture Id information display on LCD : table indexed |
||||
* on enum @ref TS_GestureIdTypeDef information |
||||
*/ |
||||
extern char *ts_gesture_id_string_tab[GEST_ID_NB_MAX]; |
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/** @defgroup STM32L496G-DISCOVERY_TS_Exported_Functions TS Exported Functions
|
||||
* @{ |
||||
*/ |
||||
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY); |
||||
uint8_t BSP_TS_InitEx(uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation); |
||||
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State); |
||||
uint8_t BSP_TS_GetOrientation(void); |
||||
|
||||
#if (TS_MULTI_TOUCH_SUPPORTED == 1) |
||||
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State); |
||||
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State); |
||||
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
||||
|
||||
uint8_t BSP_TS_ITConfig(void); |
||||
uint8_t BSP_TS_ITDeConfig(void); |
||||
|
||||
/* These __weak function can be surcharged by application code in case the current settings
|
||||
need to be changed for specific (example GPIO allocation) */ |
||||
void BSP_TS_INT_MspInit(void); |
||||
void BSP_TS_INT_MspDeInit(void); |
||||
|
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __STM32L496G_DISCOVERY_TS_H */ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
Loading…
Reference in new issue