/** ****************************************************************************** * @file stm32f4_discovery.c * @author MCD Application Team * @version V2.1.2 * @date 27-January-2017 * @brief This file provides set of firmware functions to manage Leds and * push-button available on STM32F4-Discovery Kit from STMicroelectronics. ****************************************************************************** * @attention * *

© COPYRIGHT(c) 2017 STMicroelectronics

* * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f4_discovery.h" /** @defgroup BSP BSP * @{ */ /** @defgroup STM32F4_DISCOVERY STM32F4 DISCOVERY * @{ */ /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL STM32F4 DISCOVERY LOW LEVEL * @brief This file provides set of firmware functions to manage Leds and push-button * available on STM32F4-Discovery Kit from STMicroelectronics. * @{ */ /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F4 DISCOVERY LOW LEVEL Private TypesDefinitions * @{ */ /** * @} */ /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Defines STM32F4 DISCOVERY LOW LEVEL Private Defines * @{ */ /** * @brief STM32F4 DISCO BSP Driver version number V2.1.2 */ #define __STM32F4_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */ #define __STM32F4_DISCO_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ #define __STM32F4_DISCO_BSP_VERSION_SUB2 (0x02) /*!< [15:8] sub2 version */ #define __STM32F4_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ #define __STM32F4_DISCO_BSP_VERSION ((__STM32F4_DISCO_BSP_VERSION_MAIN << 24)\ |(__STM32F4_DISCO_BSP_VERSION_SUB1 << 16)\ |(__STM32F4_DISCO_BSP_VERSION_SUB2 << 8 )\ |(__STM32F4_DISCO_BSP_VERSION_RC)) /** * @} */ /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Macros STM32F4 DISCOVERY LOW LEVEL Private Macros * @{ */ /** * @} */ /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Variables STM32F4 DISCOVERY LOW LEVEL Private Variables * @{ */ GPIO_TypeDef* GPIO_PORT[LEDn] = {LED4_GPIO_PORT, LED3_GPIO_PORT, LED5_GPIO_PORT, LED6_GPIO_PORT}; const uint16_t GPIO_PIN[LEDn] = {LED4_PIN, LED3_PIN, LED5_PIN, LED6_PIN}; GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT}; const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN}; const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn}; uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /* 0x01) { WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD; } /* Set chip select Low at the start of the transmission */ ACCELERO_CS_LOW(); /* Send the Address of the indexed register */ SPIx_WriteRead(WriteAddr); /* Send the data that will be written into the device (MSB First) */ while(NumByteToWrite >= 0x01) { SPIx_WriteRead(*pBuffer); NumByteToWrite--; pBuffer++; } /* Set chip select High at the end of the transmission */ ACCELERO_CS_HIGH(); } /** * @brief Reads a block of data from the Accelerometer. * @param pBuffer: pointer to the buffer that receives the data read from the Accelerometer. * @param ReadAddr: Accelerometer's internal address to read from. * @param NumByteToRead: number of bytes to read from the Accelerometer. */ void ACCELERO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) { if(NumByteToRead > 0x01) { ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD); } else { ReadAddr |= (uint8_t)READWRITE_CMD; } /* Set chip select Low at the start of the transmission */ ACCELERO_CS_LOW(); /* Send the Address of the indexed register */ SPIx_WriteRead(ReadAddr); /* Receive the data that will be read from the device (MSB First) */ while(NumByteToRead > 0x00) { /* Send dummy byte (0x00) to generate the SPI clock to ACCELEROMETER (Slave device) */ *pBuffer = SPIx_WriteRead(DUMMY_BYTE); NumByteToRead--; pBuffer++; } /* Set chip select High at the end of the transmission */ ACCELERO_CS_HIGH(); } /********************************* LINK AUDIO *********************************/ /** * @brief Initializes Audio low level. */ void AUDIO_IO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Enable Reset GPIO Clock */ AUDIO_RESET_GPIO_CLK_ENABLE(); /* Audio reset pin configuration */ GPIO_InitStruct.Pin = AUDIO_RESET_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct); I2Cx_Init(); /* Power Down the codec */ HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_RESET); /* Wait for a delay to insure registers erasing */ HAL_Delay(5); /* Power on the codec */ HAL_GPIO_WritePin(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, GPIO_PIN_SET); /* Wait for a delay to insure registers erasing */ HAL_Delay(5); } /** * @brief DeInitializes Audio low level. */ void AUDIO_IO_DeInit(void) { } /** * @brief Writes a single data. * @param Addr: I2C address * @param Reg: Reg address * @param Value: Data to be written */ void AUDIO_IO_Write (uint8_t Addr, uint8_t Reg, uint8_t Value) { I2Cx_WriteData(Addr, Reg, Value); } /** * @brief Reads a single data. * @param Addr: I2C address * @param Reg: Reg address * @retval Data to be read */ uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg) { return I2Cx_ReadData(Addr, Reg); } /** * @} */ /** * @} */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/