123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- /**
- ******************************************************************************
- * @file stm32f4_discovery.c
- * @author MCD Application Team
- * @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.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "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.4
- */
- #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 (0x04) /*!< [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};
- #if 0
- uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */
- uint32_t SpixTimeout = SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
- static SPI_HandleTypeDef SpiHandle;
- static I2C_HandleTypeDef I2cHandle;
- /**
- * @}
- */
- /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F4 DISCOVERY LOW LEVEL Private FunctionPrototypes
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_Private_Functions STM32F4 DISCOVERY LOW LEVEL Private Functions
- * @{
- */
- static void I2Cx_Init(void);
- static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value);
- static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg);
- static void I2Cx_MspInit(void);
- static void I2Cx_Error(uint8_t Addr);
- static void SPIx_Init(void);
- static void SPIx_MspInit(void);
- static uint8_t SPIx_WriteRead(uint8_t Byte);
- static void SPIx_Error(void);
- /* Link functions for Accelerometer peripheral */
- void ACCELERO_IO_Init(void);
- void ACCELERO_IO_ITConfig(void);
- void ACCELERO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
- void ACCELERO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
- /* Link functions for Audio peripheral */
- void AUDIO_IO_Init(void);
- void AUDIO_IO_DeInit(void);
- void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
- uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
- /**
- * @}
- */
- /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_LED_Functions STM32F4 DISCOVERY LOW LEVEL LED Functions
- * @{
- */
- #endif
- /**
- * @brief This method returns the STM32F4 DISCO BSP Driver revision
- * @retval version : 0xXYZR (8bits for each decimal, R for RC)
- */
- uint32_t BSP_GetVersion(void)
- {
- return __STM32F4_DISCO_BSP_VERSION;
- }
- /**
- * @brief Configures LED GPIO.
- * @param Led: Specifies the Led to be configured.
- * This parameter can be one of following parameters:
- * @arg LED4
- * @arg LED3
- * @arg LED5
- * @arg LED6
- */
- void BSP_LED_Init(Led_TypeDef Led)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
-
- /* Enable the GPIO_LED Clock */
- LEDx_GPIO_CLK_ENABLE(Led);
- /* Configure the GPIO_LED pin */
- GPIO_InitStruct.Pin = GPIO_PIN[Led];
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
-
- HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
-
- HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
- }
- /**
- * @brief Turns selected LED On.
- * @param Led: Specifies the Led to be set on.
- * This parameter can be one of following parameters:
- * @arg LED4
- * @arg LED3
- * @arg LED5
- * @arg LED6
- */
- void BSP_LED_On(Led_TypeDef Led)
- {
- HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
- }
- /**
- * @brief Turns selected LED Off.
- * @param Led: Specifies the Led to be set off.
- * This parameter can be one of following parameters:
- * @arg LED4
- * @arg LED3
- * @arg LED5
- * @arg LED6
- */
- void BSP_LED_Off(Led_TypeDef Led)
- {
- HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
- }
- /**
- * @brief Toggles the selected LED.
- * @param Led: Specifies the Led to be toggled.
- * This parameter can be one of following parameters:
- * @arg LED4
- * @arg LED3
- * @arg LED5
- * @arg LED6
- */
- void BSP_LED_Toggle(Led_TypeDef Led)
- {
- HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
- }
- /**
- * @}
- */
- /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUTTON_Functions STM32F4 DISCOVERY LOW LEVEL BUTTON Functions
- * @{
- */
- /**
- * @brief Configures Button GPIO and EXTI Line.
- * @param Button: Specifies the Button to be configured.
- * This parameter should be: BUTTON_KEY
- * @param Mode: Specifies Button mode.
- * This parameter can be one of following parameters:
- * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
- * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
- * generation capability
- */
- void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Mode)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
-
- /* Enable the BUTTON Clock */
- BUTTONx_GPIO_CLK_ENABLE(Button);
-
- if (Mode == BUTTON_MODE_GPIO)
- {
- /* Configure Button pin as input */
- GPIO_InitStruct.Pin = BUTTON_PIN[Button];
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
-
- HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
- }
-
- if (Mode == BUTTON_MODE_EXTI)
- {
- /* Configure Button pin as input with External interrupt */
- GPIO_InitStruct.Pin = BUTTON_PIN[Button];
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
-
- /* Enable and set Button EXTI Interrupt to the lowest priority */
- HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
- HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
- }
- }
- /**
- * @brief Returns the selected Button state.
- * @param Button: Specifies the Button to be checked.
- * This parameter should be: BUTTON_KEY
- * @retval The Button GPIO pin value.
- */
- uint32_t BSP_PB_GetState(Button_TypeDef Button)
- {
- return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
- }
- #if 0
- /**
- * @}
- */
- /** @defgroup STM32F4_DISCOVERY_LOW_LEVEL_BUS_Functions STM32F4 DISCOVERY LOW LEVEL BUS Functions
- * @{
- */
- /*******************************************************************************
- BUS OPERATIONS
- *******************************************************************************/
- /******************************* SPI Routines *********************************/
- /**
- * @brief SPIx Bus initialization
- */
- static void SPIx_Init(void)
- {
- if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
- {
- /* SPI configuration -----------------------------------------------------*/
- SpiHandle.Instance = DISCOVERY_SPIx;
- SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
- SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
- SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
- SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
- SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
- SpiHandle.Init.CRCPolynomial = 7;
- SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
- SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
- SpiHandle.Init.NSS = SPI_NSS_SOFT;
- SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
- SpiHandle.Init.Mode = SPI_MODE_MASTER;
- SPIx_MspInit();
- HAL_SPI_Init(&SpiHandle);
- }
- }
- /**
- * @brief Sends a Byte through the SPI interface and return the Byte received
- * from the SPI bus.
- * @param Byte: Byte send.
- * @retval The received byte value
- */
- static uint8_t SPIx_WriteRead(uint8_t Byte)
- {
- uint8_t receivedbyte = 0;
-
- /* Send a Byte through the SPI peripheral */
- /* Read byte from the SPI bus */
- if(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*) &Byte, (uint8_t*) &receivedbyte, 1, SpixTimeout) != HAL_OK)
- {
- SPIx_Error();
- }
-
- return receivedbyte;
- }
- /**
- * @brief SPIx error treatment function.
- */
- static void SPIx_Error(void)
- {
- /* De-initialize the SPI communication bus */
- HAL_SPI_DeInit(&SpiHandle);
-
- /* Re-Initialize the SPI communication bus */
- SPIx_Init();
- }
- /**
- * @brief SPI MSP Init.
- */
- static void SPIx_MspInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Enable the SPI peripheral */
- DISCOVERY_SPIx_CLK_ENABLE();
-
- /* Enable SCK, MOSI and MISO GPIO clocks */
- DISCOVERY_SPIx_GPIO_CLK_ENABLE();
-
- /* SPI SCK, MOSI, MISO pin configuration */
- GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MISO_PIN | DISCOVERY_SPIx_MOSI_PIN);
- GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStructure.Pull = GPIO_PULLDOWN;
- GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
- GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF;
- HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure);
- }
- /******************************* I2C Routines**********************************/
- /**
- * @brief Configures I2C interface.
- */
- static void I2Cx_Init(void)
- {
- if(HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
- {
- /* DISCOVERY_I2Cx peripheral configuration */
- I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED;
- I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
- I2cHandle.Init.OwnAddress1 = 0x33;
- I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- I2cHandle.Instance = DISCOVERY_I2Cx;
-
- /* Init the I2C */
- I2Cx_MspInit();
- HAL_I2C_Init(&I2cHandle);
- }
- }
- /**
- * @brief Write a value in a register of the device through BUS.
- * @param Addr: Device address on BUS Bus.
- * @param Reg: The target register address to write
- * @param Value: The target register value to be written
- * @retval HAL status
- */
- static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value)
- {
- HAL_StatusTypeDef status = HAL_OK;
-
- status = HAL_I2C_Mem_Write(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
- /* Check the communication status */
- if(status != HAL_OK)
- {
- /* Execute user timeout callback */
- I2Cx_Error(Addr);
- }
- }
- /**
- * @brief Read a register of the device through BUS
- * @param Addr: Device address on BUS
- * @param Reg: The target register address to read
- * @retval HAL status
- */
- static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint8_t value = 0;
-
- status = HAL_I2C_Mem_Read(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &value, 1,I2cxTimeout);
-
- /* Check the communication status */
- if(status != HAL_OK)
- {
- /* Execute user timeout callback */
- I2Cx_Error(Addr);
- }
- return value;
- }
- /**
- * @brief Manages error callback by re-initializing I2C.
- * @param Addr: I2C Address
- */
- static void I2Cx_Error(uint8_t Addr)
- {
- /* De-initialize the I2C communication bus */
- HAL_I2C_DeInit(&I2cHandle);
-
- /* Re-Initialize the I2C communication bus */
- I2Cx_Init();
- }
- /**
- * @brief I2C MSP Initialization
- */
- static void I2Cx_MspInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* Enable I2C GPIO clocks */
- DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
- /* DISCOVERY_I2Cx SCL and SDA pins configuration ---------------------------*/
- GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
- HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &GPIO_InitStruct);
- /* Enable the DISCOVERY_I2Cx peripheral clock */
- DISCOVERY_I2Cx_CLK_ENABLE();
- /* Force the I2C peripheral clock reset */
- DISCOVERY_I2Cx_FORCE_RESET();
- /* Release the I2C peripheral clock reset */
- DISCOVERY_I2Cx_RELEASE_RESET();
- /* Enable and set I2Cx Interrupt to the highest priority */
- HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
- /* Enable and set I2Cx Interrupt to the highest priority */
- HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
- }
- /*******************************************************************************
- LINK OPERATIONS
- *******************************************************************************/
- /***************************** LINK ACCELEROMETER *****************************/
- /**
- * @brief Configures the Accelerometer SPI interface.
- */
- void ACCELERO_IO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Configure the Accelerometer Control pins --------------------------------*/
- /* Enable CS GPIO clock and configure GPIO pin for Accelerometer Chip select */
- ACCELERO_CS_GPIO_CLK_ENABLE();
-
- /* Configure GPIO PIN for LIS Chip select */
- GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
- GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
- HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
-
- /* Deselect: Chip Select high */
- ACCELERO_CS_HIGH();
-
- SPIx_Init();
- }
- /**
- * @brief Configures the Accelerometer INT2.
- * EXTI0 is already used by user button so INT1 is not configured here.
- */
- void ACCELERO_IO_ITConfig(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable INT2 GPIO clock and configure GPIO PINs to detect Interrupts */
- ACCELERO_INT_GPIO_CLK_ENABLE();
-
- /* Configure GPIO PINs to detect Interrupts */
- GPIO_InitStructure.Pin = ACCELERO_INT2_PIN;
- GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(ACCELERO_INT_GPIO_PORT, &GPIO_InitStructure);
-
- /* Enable and set Accelerometer INT2 to the lowest priority */
- HAL_NVIC_SetPriority((IRQn_Type)ACCELERO_INT2_EXTI_IRQn, 0x0F, 0);
- HAL_NVIC_EnableIRQ((IRQn_Type)ACCELERO_INT2_EXTI_IRQn);
- }
- /**
- * @brief Writes one byte to the Accelerometer.
- * @param pBuffer: pointer to the buffer containing the data to be written to the Accelerometer.
- * @param WriteAddr: Accelerometer's internal address to write to.
- * @param NumByteToWrite: Number of bytes to write.
- */
- void ACCELERO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
- {
- /* Configure the MS bit:
- - When 0, the address will remain unchanged in multiple read/write commands.
- - When 1, the address will be auto incremented in multiple read/write commands.
- */
- if(NumByteToWrite > 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);
- }
- #endif
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
|