rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 • committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,141 @@
/**
******************************************************************************
* @file accelero.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the Accelerometer driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ACCELERO_H
#define __ACCELERO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ACCELERO
* @{
*/
/** @defgroup ACCELERO_Exported_Types
* @{
*/
/** @defgroup ACCELERO_Driver_structure Accelerometer Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
void (*DeInit)(void);
uint8_t (*ReadID)(void);
void (*Reset)(void);
void (*LowPower)(uint16_t);
void (*ConfigIT)(void);
void (*EnableIT)(uint8_t);
void (*DisableIT)(uint8_t);
uint8_t (*ITStatus)(uint16_t);
void (*ClearIT)(void);
void (*FilterConfig)(uint8_t);
void (*FilterCmd)(uint8_t);
void (*GetXYZ)(int16_t *);
}ACCELERO_DrvTypeDef;
/**
* @}
*/
/** @defgroup ACCELERO_Configuration_structure Accelerometer Configuration structure
* @{
*/
/* ACCELERO struct */
typedef struct
{
uint8_t Power_Mode; /* Power-down/Normal Mode */
uint8_t AccOutput_DataRate; /* OUT data rate */
uint8_t Axes_Enable; /* Axes enable */
uint8_t High_Resolution; /* High Resolution enabling/disabling */
uint8_t BlockData_Update; /* Block Data Update */
uint8_t Endianness; /* Endian Data selection */
uint8_t AccFull_Scale; /* Full Scale selection */
uint8_t Communication_Mode;
}ACCELERO_InitTypeDef;
/* ACCELERO High Pass Filter struct */
typedef struct
{
uint8_t HighPassFilter_Mode_Selection; /* Internal filter mode */
uint8_t HighPassFilter_CutOff_Frequency; /* High pass filter cut-off frequency */
uint8_t HighPassFilter_AOI1; /* HPF_enabling/disabling for AOI function on interrupt 1 */
uint8_t HighPassFilter_AOI2; /* HPF_enabling/disabling for AOI function on interrupt 2 */
uint8_t HighPassFilter_Data_Sel;
uint8_t HighPassFilter_Stat;
}ACCELERO_FilterConfigTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ACCELERO_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,120 @@
/**
******************************************************************************
* @file audio.h
* @author MCD Application Team
* @brief This header file contains the common defines and functions prototypes
* for the Audio driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __AUDIO_H
#define __AUDIO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup AUDIO
* @{
*/
/** @defgroup AUDIO_Exported_Constants
* @{
*/
/* Codec audio Standards */
#define CODEC_STANDARD 0x04
#define I2S_STANDARD I2S_STANDARD_PHILIPS
/**
* @}
*/
/** @defgroup AUDIO_Exported_Types
* @{
*/
/** @defgroup AUDIO_Driver_structure Audio Driver structure
* @{
*/
typedef struct
{
uint32_t (*Init)(uint16_t, uint16_t, uint8_t, uint32_t);
void (*DeInit)(void);
uint32_t (*ReadID)(uint16_t);
uint32_t (*Play)(uint16_t, uint16_t*, uint16_t);
uint32_t (*Pause)(uint16_t);
uint32_t (*Resume)(uint16_t);
uint32_t (*Stop)(uint16_t, uint32_t);
uint32_t (*SetFrequency)(uint16_t, uint32_t);
uint32_t (*SetVolume)(uint16_t, uint8_t);
uint32_t (*SetMute)(uint16_t, uint32_t);
uint32_t (*SetOutputMode)(uint16_t, uint8_t);
uint32_t (*Reset)(uint16_t);
}AUDIO_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __AUDIO_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,139 @@
/**
******************************************************************************
* @file camera.h
* @author MCD Application Team
* @brief This header file contains the common defines and functions prototypes
* for the camera driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CAMERA_H
#define __CAMERA_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup CAMERA
* @{
*/
/** @defgroup CAMERA_Exported_Types
* @{
*/
/** @defgroup CAMERA_Driver_structure Camera Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t, uint32_t);
uint16_t (*ReadID)(uint16_t);
void (*Config)(uint16_t, uint32_t, uint32_t, uint32_t);
}CAMERA_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/** @defgroup CAMERA_Exported_Constants
* @{
*/
#define CAMERA_R160x120 0x00 /* QQVGA Resolution */
#define CAMERA_R320x240 0x01 /* QVGA Resolution */
#define CAMERA_R480x272 0x02 /* 480x272 Resolution */
#define CAMERA_R640x480 0x03 /* VGA Resolution */
#define CAMERA_CONTRAST_BRIGHTNESS 0x00 /* Camera contrast brightness features */
#define CAMERA_BLACK_WHITE 0x01 /* Camera black white feature */
#define CAMERA_COLOR_EFFECT 0x03 /* Camera color effect feature */
#define CAMERA_BRIGHTNESS_LEVEL0 0x00 /* Brightness level -2 */
#define CAMERA_BRIGHTNESS_LEVEL1 0x01 /* Brightness level -1 */
#define CAMERA_BRIGHTNESS_LEVEL2 0x02 /* Brightness level 0 */
#define CAMERA_BRIGHTNESS_LEVEL3 0x03 /* Brightness level +1 */
#define CAMERA_BRIGHTNESS_LEVEL4 0x04 /* Brightness level +2 */
#define CAMERA_CONTRAST_LEVEL0 0x05 /* Contrast level -2 */
#define CAMERA_CONTRAST_LEVEL1 0x06 /* Contrast level -1 */
#define CAMERA_CONTRAST_LEVEL2 0x07 /* Contrast level 0 */
#define CAMERA_CONTRAST_LEVEL3 0x08 /* Contrast level +1 */
#define CAMERA_CONTRAST_LEVEL4 0x09 /* Contrast level +2 */
#define CAMERA_BLACK_WHITE_BW 0x00 /* Black and white effect */
#define CAMERA_BLACK_WHITE_NEGATIVE 0x01 /* Negative effect */
#define CAMERA_BLACK_WHITE_BW_NEGATIVE 0x02 /* BW and Negative effect */
#define CAMERA_BLACK_WHITE_NORMAL 0x03 /* Normal effect */
#define CAMERA_COLOR_EFFECT_NONE 0x00 /* No effects */
#define CAMERA_COLOR_EFFECT_BLUE 0x01 /* Blue effect */
#define CAMERA_COLOR_EFFECT_GREEN 0x02 /* Green effect */
#define CAMERA_COLOR_EFFECT_RED 0x03 /* Red effect */
#define CAMERA_COLOR_EFFECT_ANTIQUE 0x04 /* Antique effect */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __CAMERA_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,113 @@
/**
******************************************************************************
* @file epd.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the
* EPD (E Paper Display) driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __EPD_H
#define __EPD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup Common
* @{
*/
/** @addtogroup EPD
* @{
*/
/** @defgroup EPD_Exported_Types
* @{
*/
/** @defgroup EPD_Driver_structure E Paper Display Driver structure
* @{
*/
typedef struct
{
void (*Init)(void);
void (*WritePixel)(uint8_t);
/* Optimized operation */
void (*SetDisplayWindow)(uint16_t, uint16_t, uint16_t, uint16_t);
void (*RefreshDisplay)(void);
void (*CloseChargePump)(void);
uint16_t (*GetEpdPixelWidth)(void);
uint16_t (*GetEpdPixelHeight)(void);
void (*DrawImage)(uint16_t, uint16_t, uint16_t, uint16_t, uint8_t*);
}
EPD_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* EPD_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,143 @@
/**
******************************************************************************
* @file gyro.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the gyroscope driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GYRO_H
#define __GYRO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup GYRO
* @{
*/
/** @defgroup GYRO_Exported_Types
* @{
*/
/** @defgroup GYRO_Driver_structure Gyroscope Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
void (*DeInit)(void);
uint8_t (*ReadID)(void);
void (*Reset)(void);
void (*LowPower)(uint16_t);
void (*ConfigIT)(uint16_t);
void (*EnableIT)(uint8_t);
void (*DisableIT)(uint8_t);
uint8_t (*ITStatus)(uint16_t, uint16_t);
void (*ClearIT)(uint16_t, uint16_t);
void (*FilterConfig)(uint8_t);
void (*FilterCmd)(uint8_t);
void (*GetXYZ)(float *);
}GYRO_DrvTypeDef;
/**
* @}
*/
/** @defgroup GYRO_Config_structure Gyroscope Configuration structure
* @{
*/
typedef struct
{
uint8_t Power_Mode; /* Power-down/Sleep/Normal Mode */
uint8_t Output_DataRate; /* OUT data rate */
uint8_t Axes_Enable; /* Axes enable */
uint8_t Band_Width; /* Bandwidth selection */
uint8_t BlockData_Update; /* Block Data Update */
uint8_t Endianness; /* Endian Data selection */
uint8_t Full_Scale; /* Full Scale selection */
}GYRO_InitTypeDef;
/* GYRO High Pass Filter struct */
typedef struct
{
uint8_t HighPassFilter_Mode_Selection; /* Internal filter mode */
uint8_t HighPassFilter_CutOff_Frequency; /* High pass filter cut-off frequency */
}GYRO_FilterConfigTypeDef;
/*GYRO Interrupt struct */
typedef struct
{
uint8_t Latch_Request; /* Latch interrupt request into CLICK_SRC register */
uint8_t Interrupt_Axes; /* X, Y, Z Axes Interrupts */
uint8_t Interrupt_ActiveEdge; /* Interrupt Active edge */
}GYRO_InterruptConfigTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __GYRO_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,99 @@
/**
******************************************************************************
* @file tsensor.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the
* Temperature Sensor driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HSENSOR_H
#define __HSENSOR_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup HSENSOR
* @{
*/
/** @defgroup HSENSOR_Exported_Types
* @{
*/
/** @defgroup HSENSOR_Driver_structure Temperature Sensor Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
uint8_t (*ReadID)(uint16_t);
float (*ReadHumidity)(uint16_t);
}HSENSOR_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __HSENSOR_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,166 @@
/**
******************************************************************************
* @file idd.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the IDD driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __IDD_H
#define __IDD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup IDD
* @{
*/
/** @defgroup IDD_Exported_Types IDD Exported Types
* @{
*/
/** @defgroup IDD_Config_structure IDD Configuration structure
* @{
*/
typedef struct
{
uint16_t AmpliGain; /*!< Specifies ampli gain value
*/
uint16_t VddMin; /*!< Specifies minimum MCU VDD can reach to protect MCU from reset
*/
uint16_t Shunt0Value; /*!< Specifies value of Shunt 0 if existing
*/
uint16_t Shunt1Value; /*!< Specifies value of Shunt 1 if existing
*/
uint16_t Shunt2Value; /*!< Specifies value of Shunt 2 if existing
*/
uint16_t Shunt3Value; /*!< Specifies value of Shunt 3 if existing
*/
uint16_t Shunt4Value; /*!< Specifies value of Shunt 4 if existing
*/
uint16_t Shunt0StabDelay; /*!< Specifies delay of Shunt 0 stabilization if existing
*/
uint16_t Shunt1StabDelay; /*!< Specifies delay of Shunt 1 stabilization if existing
*/
uint16_t Shunt2StabDelay; /*!< Specifies delay of Shunt 2 stabilization if existing
*/
uint16_t Shunt3StabDelay; /*!< Specifies delay of Shunt 3 stabilization if existing
*/
uint16_t Shunt4StabDelay; /*!< Specifies delay of Shunt 4 stabilization if existing
*/
uint8_t ShuntNbOnBoard; /*!< Specifies number of shunts that are present on board
This parameter can be a value of @ref IDD_shunt_number */
uint8_t ShuntNbUsed; /*!< Specifies number of shunts used for measurement
This parameter can be a value of @ref IDD_shunt_number */
uint8_t VrefMeasurement; /*!< Specifies if Vref is automatically measured before each Idd measurement
This parameter can be a value of @ref IDD_Vref_Measurement */
uint8_t Calibration; /*!< Specifies if calibration is done before each Idd measurement
*/
uint8_t PreDelayUnit; /*!< Specifies Pre delay unit
This parameter can be a value of @ref IDD_PreDelay */
uint8_t PreDelayValue; /*!< Specifies Pre delay value in selected unit
*/
uint8_t MeasureNb; /*!< Specifies number of Measure to be performed
This parameter can be a value between 1 and 256 */
uint8_t DeltaDelayUnit; /*!< Specifies Delta delay unit
This parameter can be a value of @ref IDD_DeltaDelay */
uint8_t DeltaDelayValue; /*!< Specifies Delta delay between 2 measures
value can be between 1 and 128 */
}IDD_ConfigTypeDef;
/**
* @}
*/
/** @defgroup IDD_Driver_structure IDD Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
void (*DeInit)(uint16_t);
uint16_t (*ReadID)(uint16_t);
void (*Reset)(uint16_t);
void (*LowPower)(uint16_t);
void (*WakeUp)(uint16_t);
void (*Start)(uint16_t);
void (*Config)(uint16_t,IDD_ConfigTypeDef);
void (*GetValue)(uint16_t, uint32_t *);
void (*EnableIT)(uint16_t);
void (*ClearIT)(uint16_t);
uint8_t (*GetITStatus)(uint16_t);
void (*DisableIT)(uint16_t);
void (*ErrorEnableIT)(uint16_t);
void (*ErrorClearIT)(uint16_t);
uint8_t (*ErrorGetITStatus)(uint16_t);
void (*ErrorDisableIT)(uint16_t);
uint8_t (*ErrorGetSrc)(uint16_t);
uint8_t (*ErrorGetCode)(uint16_t);
}IDD_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __IDD_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,148 @@
/**
******************************************************************************
* @file io.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the IO driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __IO_H
#define __IO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup IO
* @{
*/
/** @defgroup IO_Exported_Types
* @{
*/
/**
* @brief IO Bit SET and Bit RESET enumeration
*/
typedef enum
{
IO_PIN_RESET = 0,
IO_PIN_SET
}IO_PinState;
typedef enum
{
IO_MODE_INPUT = 0, /* input floating */
IO_MODE_OUTPUT, /* output Push Pull */
IO_MODE_IT_RISING_EDGE, /* float input - irq detect on rising edge */
IO_MODE_IT_FALLING_EDGE, /* float input - irq detect on falling edge */
IO_MODE_IT_LOW_LEVEL, /* float input - irq detect on low level */
IO_MODE_IT_HIGH_LEVEL, /* float input - irq detect on high level */
/* following modes only available on MFX*/
IO_MODE_ANALOG, /* analog mode */
IO_MODE_OFF, /* when pin isn't used*/
IO_MODE_INPUT_PU, /* input with internal pull up resistor */
IO_MODE_INPUT_PD, /* input with internal pull down resistor */
IO_MODE_OUTPUT_OD, /* Open Drain output without internal resistor */
IO_MODE_OUTPUT_OD_PU, /* Open Drain output with internal pullup resistor */
IO_MODE_OUTPUT_OD_PD, /* Open Drain output with internal pulldown resistor */
IO_MODE_OUTPUT_PP, /* PushPull output without internal resistor */
IO_MODE_OUTPUT_PP_PU, /* PushPull output with internal pullup resistor */
IO_MODE_OUTPUT_PP_PD, /* PushPull output with internal pulldown resistor */
IO_MODE_IT_RISING_EDGE_PU, /* push up resistor input - irq on rising edge */
IO_MODE_IT_RISING_EDGE_PD, /* push dw resistor input - irq on rising edge */
IO_MODE_IT_FALLING_EDGE_PU, /* push up resistor input - irq on falling edge */
IO_MODE_IT_FALLING_EDGE_PD, /* push dw resistor input - irq on falling edge */
IO_MODE_IT_LOW_LEVEL_PU, /* push up resistor input - irq detect on low level */
IO_MODE_IT_LOW_LEVEL_PD, /* push dw resistor input - irq detect on low level */
IO_MODE_IT_HIGH_LEVEL_PU, /* push up resistor input - irq detect on high level */
IO_MODE_IT_HIGH_LEVEL_PD, /* push dw resistor input - irq detect on high level */
}IO_ModeTypedef;
/** @defgroup IO_Driver_structure IO Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
uint16_t (*ReadID)(uint16_t);
void (*Reset)(uint16_t);
void (*Start)(uint16_t, uint32_t);
uint8_t (*Config)(uint16_t, uint32_t, IO_ModeTypedef);
void (*WritePin)(uint16_t, uint32_t, uint8_t);
uint32_t (*ReadPin)(uint16_t, uint32_t);
void (*EnableIT)(uint16_t);
void (*DisableIT)(uint16_t);
uint32_t (*ITStatus)(uint16_t, uint32_t);
void (*ClearIT)(uint16_t, uint32_t);
}IO_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __IO_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,112 @@
/**
******************************************************************************
* @file lcd.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the LCD driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LCD_H
#define __LCD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup LCD
* @{
*/
/** @defgroup LCD_Exported_Types
* @{
*/
/** @defgroup LCD_Driver_structure LCD Driver structure
* @{
*/
typedef struct
{
void (*Init)(void);
uint16_t (*ReadID)(void);
void (*DisplayOn)(void);
void (*DisplayOff)(void);
void (*SetCursor)(uint16_t, uint16_t);
void (*WritePixel)(uint16_t, uint16_t, uint16_t);
uint16_t (*ReadPixel)(uint16_t, uint16_t);
/* Optimized operation */
void (*SetDisplayWindow)(uint16_t, uint16_t, uint16_t, uint16_t);
void (*DrawHLine)(uint16_t, uint16_t, uint16_t, uint16_t);
void (*DrawVLine)(uint16_t, uint16_t, uint16_t, uint16_t);
uint16_t (*GetLcdPixelWidth)(void);
uint16_t (*GetLcdPixelHeight)(void);
void (*DrawBitmap)(uint16_t, uint16_t, uint8_t*);
void (*DrawRGBImage)(uint16_t, uint16_t, uint16_t, uint16_t, uint8_t*);
}LCD_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LCD_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,123 @@
/**
******************************************************************************
* @file magneto.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the MAGNETO driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAGNETO_H
#define __MAGNETO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup MAGNETO
* @{
*/
/** @defgroup MAGNETO_Exported_Types
* @{
*/
/** @defgroup MAGNETO_Config_structure Magnetometer Configuration structure
* @{
*/
typedef struct
{
uint8_t Register1;
uint8_t Register2;
uint8_t Register3;
uint8_t Register4;
uint8_t Register5;
}MAGNETO_InitTypeDef;
/**
* @}
*/
/** @defgroup MAGNETO_Driver_structure Magnetometer Driver structure
* @{
*/
typedef struct
{
void (*Init)(MAGNETO_InitTypeDef);
void (*DeInit)(void);
uint8_t (*ReadID)(void);
void (*Reset)(void);
void (*LowPower)(uint16_t);
void (*ConfigIT)(void);
void (*EnableIT)(uint8_t);
void (*DisableIT)(uint8_t);
uint8_t (*ITStatus)(uint16_t);
void (*ClearIT)(void);
void (*FilterConfig)(uint8_t);
void (*FilterCmd)(uint8_t);
void (*GetXYZ)(int16_t *);
}MAGNETO_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __MAGNETO_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,99 @@
/**
******************************************************************************
* @file tsensor.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the
* Temperature Sensor driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PSENSOR_H
#define __PSENSOR_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup PSENSOR
* @{
*/
/** @defgroup PSENSOR_Exported_Types
* @{
*/
/** @defgroup PSENSOR_Driver_structure Temperature Sensor Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
uint8_t (*ReadID)(uint16_t);
float (*ReadPressure)(uint16_t);
}PSENSOR_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __PSENSOR_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,105 @@
/**
******************************************************************************
* @file ts.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the Touch Screen driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TS_H
#define __TS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup TS
* @{
*/
/** @defgroup TS_Exported_Types
* @{
*/
/** @defgroup TS_Driver_structure Touch Sensor Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t);
uint16_t (*ReadID)(uint16_t);
void (*Reset)(uint16_t);
void (*Start)(uint16_t);
uint8_t (*DetectTouch)(uint16_t);
void (*GetXY)(uint16_t, uint16_t*, uint16_t*);
void (*EnableIT)(uint16_t);
void (*ClearIT)(uint16_t);
uint8_t (*GetITStatus)(uint16_t);
void (*DisableIT)(uint16_t);
}TS_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __TS_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,116 @@
/**
******************************************************************************
* @file tsensor.h
* @author MCD Application Team
* @brief This header file contains the functions prototypes for the
* Temperature Sensor driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSENSOR_H
#define __TSENSOR_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup TSENSOR
* @{
*/
/** @defgroup TSENSOR_Exported_Types
* @{
*/
/** @defgroup TSENSOR_Config_structure Temperature Sensor Configuration structure
* @{
*/
typedef struct
{
uint8_t AlertMode; /* Alert Mode Temperature out of range*/
uint8_t ConversionMode; /* Continuous/One Shot Mode */
uint8_t ConversionResolution; /* Temperature Resolution */
uint8_t ConversionRate; /* Number of measure per second */
int8_t TemperatureLimitHigh; /* High Temperature Limit Range */
int8_t TemperatureLimitLow; /* Low Temperature Limit Range */
}TSENSOR_InitTypeDef;
/**
* @}
*/
/** @defgroup TSENSOR_Driver_structure Temperature Sensor Driver structure
* @{
*/
typedef struct
{
void (*Init)(uint16_t, TSENSOR_InitTypeDef *);
uint8_t (*IsReady)(uint16_t, uint32_t);
uint8_t (*ReadStatus)(uint16_t);
float (*ReadTemp)(uint16_t);
}TSENSOR_DrvTypeDef;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __TSENSOR_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,522 @@
/**
******************************************************************************
* @file cs42l51.c
* @author MCD Application Team
* @version V1.0.0
* @date 17-February-2017
* @brief This file provides the CS42L51 Audio Codec driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "cs42l51.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup CS42L51
* @brief This file provides a set of functions needed to drive the
* CS42L51 audio codec.
* @{
*/
/** @defgroup CS42L51_Exported_Variables
* @{
*/
/* Audio codec driver structure initialization */
AUDIO_DrvTypeDef cs42l51_drv =
{
cs42l51_Init,
cs42l51_DeInit,
cs42l51_ReadID,
cs42l51_Play,
cs42l51_Pause,
cs42l51_Resume,
cs42l51_Stop,
cs42l51_SetFrequency,
cs42l51_SetVolume,
cs42l51_SetMute,
cs42l51_SetOutputMode,
cs42l51_Reset,
};
/**
* @}
*/
/** @defgroup CS42L51_Private_Types
* @{
*/
/**
* @}
*/
/** @defgroup CS42L51_Private_Defines
* @{
*/
/* Uncomment this line to enable verifying data sent to codec after each write
operation (for debug purpose) */
#if !defined (VERIFY_WRITTENDATA)
#define VERIFY_WRITTENDATA
#endif /* VERIFY_WRITTENDATA */
/**
* @}
*/
/** @defgroup CS42L51_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup CS42L51_Private_Variables
* @{
*/
static uint8_t Is_CS42L51_Initialized = 0;
static uint8_t Is_CS42L51_Stop = 1;
static uint16_t CS42L51_Device = OUTPUT_DEVICE_HEADPHONE;
/**
* @}
*/
/** @defgroup CS42L51_Private_Functions
* @{
*/
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
/**
* @}
*/
/** @addtogroup CS42L51_Exported_Functions
* @{
*/
/**
* @brief Initialize the audio codec and the control interface.
* @param DeviceAddr: Device address on communication bus.
* @param Device: Can be combination values of OUTPUT_DEVICE_HEADPHONE and
* INPUT_DEVICE_MIC1.
* @param Volume: Initial output volume level (from 0 (-100dB) to 100 (0dB)).
* @param AudioFreq: Initial audio frequency (currently not used).
* @retval 0 if correct communication, else wrong communication.
*/
uint32_t cs42l51_Init(uint16_t DeviceAddr, uint16_t Device, uint8_t Volume, uint32_t AudioFreq)
{
uint32_t counter = 0;
uint8_t Value;
/* Check if codec is already initialized */
if(Is_CS42L51_Initialized == 0)
{
/* Initialize the Control interface of the Audio Codec */
AUDIO_IO_Init();
Is_CS42L51_Initialized = 1;
}
else
{
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x7E);
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value | 0x0E));
/* Disable zero cross and soft ramp */
Value = AUDIO_IO_Read(DeviceAddr, 0x09);
counter += CODEC_IO_Write(DeviceAddr, 0x09, (Value & 0xFC));
/* Power control : Enter standby (PDN = 1) */
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value | 0x01));
}
/* Mic Power and Speed Control : Auto detect on, Speed mode SSM, tri state off, MCLK divide by 2 off */
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
counter += CODEC_IO_Write(DeviceAddr, 0x03, ((Value & 0x0E) | 0xA0));
/* Interface control : Loopback off, Slave, I2S (SDIN and SOUT), Digital mix off, Mic mix off */
counter += CODEC_IO_Write(DeviceAddr, 0x04, 0x0C);
/* Mic control : ADC single volume off, ADCB boost off, ADCA boost off, MicBias on AIN3B/MICIN2 pin, MicBias level 0.8xVA, MICB boost 16db, MICA boost 16dB */
counter += CODEC_IO_Write(DeviceAddr, 0x05, 0x00);
/* ADC control : ADCB HPF off, ADCB HPF freeze off, ADCA HPF off, ADCA HPF freeze off, Soft ramp B off, Zero cross B off, Soft ramp A off, Zero cross A off */
counter += CODEC_IO_Write(DeviceAddr, 0x06, 0x00);
/* ADC Input Select, Invert and Mute : AIN1B to PGAB, AIN3A to PreAmp to PGAA, ADCB invert off, ADCA invert off, ADCB mute on, ADCA mute off */
counter += CODEC_IO_Write(DeviceAddr, 0x07, 0x32);
/* DAC output control : HP Gain to 1, Single volume control off, PCM invert signals polarity off, DAC channels mute on */
counter += CODEC_IO_Write(DeviceAddr, 0x08, 0xC3);
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
counter += CODEC_IO_Write(DeviceAddr, 0x09, 0x42);
/* ALCA and PGAA Control : ALCA soft ramp disable on, ALCA zero cross disable on, PGA A Gain 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0A, 0xC0);
/* ALCB and PGAB Control : ALCB soft ramp disable on, ALCB zero cross disable on, PGA B Gain 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0B, 0xC0);
/* ADCA Attenuator : 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0C, 0x00);
/* ADCB Attenuator : 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0D, 0x00);
/* ADCA mixer volume control : ADCA mixer channel mute on, ADCA mixer volume 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0E, 0x80);
/* ADCB mixer volume control : ADCB mixer channel mute on, ADCB mixer volume 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x0F, 0x80);
/* PCMA mixer volume control : PCMA mixer channel mute off, PCMA mixer volume 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x10, 0x00);
/* PCMB mixer volume control : PCMB mixer channel mute off, PCMB mixer volume 0dB */
counter += CODEC_IO_Write(DeviceAddr, 0x11, 0x00);
/* PCM channel mixer : AOUTA Left, AOUTB Right */
counter += CODEC_IO_Write(DeviceAddr, 0x18, 0x00);
if(Device & OUTPUT_DEVICE_HEADPHONE)
{
Value = VOLUME_CONVERT(Volume);
/* AOUTA volume control : AOUTA volume */
counter += CODEC_IO_Write(DeviceAddr, 0x16, Value);
/* AOUTB volume control : AOUTB volume */
counter += CODEC_IO_Write(DeviceAddr, 0x17, Value);
}
/* Store device */
CS42L51_Device = Device;
/* Return communication control value */
return counter;
}
/**
* @brief Deinitialize the audio codec.
* @param None
* @retval None
*/
void cs42l51_DeInit(void)
{
/* Deinitialize Audio Codec interface */
AUDIO_IO_DeInit();
Is_CS42L51_Initialized = 0;
}
/**
* @brief Get the CS42L51 ID.
* @param DeviceAddr: Device address on communication Bus.
* @retval The CS42L51 ID
*/
uint32_t cs42l51_ReadID(uint16_t DeviceAddr)
{
uint8_t Value;
if(Is_CS42L51_Initialized == 0)
{
/* Initialize the Control interface of the Audio Codec */
AUDIO_IO_Init();
Value = AUDIO_IO_Read(DeviceAddr, CS42L51_CHIPID_ADDR);
Value = (Value & CS42L51_ID_MASK);
/* Deinitialize Audio Codec interface */
AUDIO_IO_DeInit();
}
else
{
Value = AUDIO_IO_Read(DeviceAddr, CS42L51_CHIPID_ADDR);
Value = (Value & CS42L51_ID_MASK);
}
return((uint32_t) Value);
}
/**
* @brief Start the audio Codec play feature.
* @note For this codec no Play options are required.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
{
uint32_t counter = 0;
uint8_t Value;
if(Is_CS42L51_Stop == 1)
{
/* Unmute output device */
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
if(CS42L51_Device & OUTPUT_DEVICE_HEADPHONE)
{
/* DAC control : Signal processing to DAC, Freeze off, De-emphasis off, Analog output auto mute off, DAC soft ramp */
counter += CODEC_IO_Write(DeviceAddr, 0x09, 0x42);
/* Power control 1 : PDN_DACA, PDN_DACB disable. */
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0x9F));
}
if(CS42L51_Device & INPUT_DEVICE_MIC1)
{
/* Power control 1 : PDN_PGAA, PDN_ADCA disable. */
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0xF5));
/* Mic Power and Speed Control : PDN_MICA, PDN_MIC_BIAS disable. */
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value & 0xF9));
}
/* Power control : Exit standby (PDN = 0) */
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value & 0xFE));
Is_CS42L51_Stop = 0;
}
/* Return communication control value */
return counter;
}
/**
* @brief Pause playing on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_Pause(uint16_t DeviceAddr)
{
uint32_t counter = 0;
/* Pause the audio file playing */
/* Mute the output first */
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_ON);
return counter;
}
/**
* @brief Resume playing on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_Resume(uint16_t DeviceAddr)
{
uint32_t counter = 0;
/* Unmute the output */
counter += cs42l51_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
return counter;
}
/**
* @brief Stop audio Codec playing. It powers down the codec.
* @param DeviceAddr: Device address on communication Bus.
* @param CodecPdwnMode: selects the power down mode (currently not used).
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
{
uint32_t counter = 0;
uint8_t Value;
/* Set all power down bits to 1 exept PDN to mute ADCs and DACs*/
counter += CODEC_IO_Write(DeviceAddr, 0x02, 0x7E);
Value = AUDIO_IO_Read(DeviceAddr, 0x03);
counter += CODEC_IO_Write(DeviceAddr, 0x03, (Value | 0x0E));
/* Disable zero cross and soft ramp */
Value = AUDIO_IO_Read(DeviceAddr, 0x09);
counter += CODEC_IO_Write(DeviceAddr, 0x09, (Value & 0xFC));
/* Power control : Enter standby (PDN = 1) */
Value = AUDIO_IO_Read(DeviceAddr, 0x02);
counter += CODEC_IO_Write(DeviceAddr, 0x02, (Value | 0x01));
Is_CS42L51_Stop = 1;
return counter;
}
/**
* @brief Set higher or lower the codec volume level.
* @param DeviceAddr: Device address on communication Bus.
* @param Volume: output volume level (from 0 (-100dB) to 100 (0dB)).
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
{
uint32_t counter = 0;
uint8_t convertedvol = VOLUME_CONVERT(Volume);
/* AOUTA volume control : AOUTA volume */
counter += CODEC_IO_Write(DeviceAddr, 0x16, convertedvol);
/* AOUTB volume control : AOUTB volume */
counter += CODEC_IO_Write(DeviceAddr, 0x17, convertedvol);
return counter;
}
/**
* @brief Set new frequency.
* @param DeviceAddr: Device address on communication Bus.
* @param AudioFreq: Audio frequency used to play the audio stream.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
{
return 0;
}
/**
* @brief Enable or disable the mute feature on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
* mute mode.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
{
uint32_t counter = 0;
uint8_t Value;
/* Read DAC output control register */
Value = AUDIO_IO_Read(DeviceAddr, 0x08);
/* Set the Mute mode */
if(Cmd == AUDIO_MUTE_ON)
{
/* Mute DAC channels */
counter += CODEC_IO_Write(DeviceAddr, 0x08, (Value | 0x03));
}
else /* AUDIO_MUTE_OFF Disable the Mute */
{
/* Unmute DAC channels */
counter += CODEC_IO_Write(DeviceAddr, 0x08, (Value & 0xFC));
}
return counter;
}
/**
* @brief Switch dynamically (while audio file is played) the output target
* (speaker, headphone, etc).
* @note This function is currently not used (only headphone output device).
* @param DeviceAddr: Device address on communication Bus.
* @param Output: specifies the audio output device target.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
{
return 0;
}
/**
* @brief Reset CS42L51 registers.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs42l51_Reset(uint16_t DeviceAddr)
{
if(Is_CS42L51_Initialized == 1)
{
/* Deinitialize Audio Codec interface */
AUDIO_IO_DeInit();
/* Initialize the Control interface of the Audio Codec */
AUDIO_IO_Init();
}
return 0;
}
/**
* @}
*/
/** @addtogroup CS42L51_Private_Functions
* @{
*/
/**
* @brief Write and optionally read back a single data.
* @param Addr: I2C address
* @param Reg: Reg address
* @param Value: Data to be written
* @retval None
*/
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
uint32_t result = 0;
AUDIO_IO_Write(Addr, Reg, Value);
#ifdef VERIFY_WRITTENDATA
/* Verify that the data has been correctly written */
result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;
#endif /* VERIFY_WRITTENDATA */
return result;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,189 @@
/**
******************************************************************************
* @file cs42l51.h
* @author MCD Application Team
* @version V1.0.0
* @date 17-February-2017
* @brief This file contains all the functions prototypes for the cs42l51.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CS42L51_H
#define __CS42L51_H
/* Includes ------------------------------------------------------------------*/
#include "../Common/audio.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup CS42L51
* @{
*/
/** @defgroup CS42L51_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup CS42L51_Exported_Constants
* @{
*/
/******************************************************************************/
/*************************** Codec User defines ******************************/
/******************************************************************************/
/* Codec output devices */
#define OUTPUT_DEVICE_HEADPHONE 0x01
/* Codec input devices */
#define INPUT_DEVICE_MIC1 0x10
/* Volume Levels values */
#define DEFAULT_VOLMIN 0x00
#define DEFAULT_VOLMAX 0xFF
#define DEFAULT_VOLSTEP 0x04
#define AUDIO_PAUSE 0
#define AUDIO_RESUME 1
/* Codec POWER DOWN modes */
#define CODEC_PDWN_HW 1
#define CODEC_PDWN_SW 2
/* MUTE commands */
#define AUDIO_MUTE_ON 1
#define AUDIO_MUTE_OFF 0
/* AUDIO FREQUENCY */
#define AUDIO_FREQUENCY_192K ((uint32_t)192000)
#define AUDIO_FREQUENCY_96K ((uint32_t)96000)
#define AUDIO_FREQUENCY_48K ((uint32_t)48000)
#define AUDIO_FREQUENCY_44K ((uint32_t)44100)
#define AUDIO_FREQUENCY_32K ((uint32_t)32000)
#define AUDIO_FREQUENCY_22K ((uint32_t)22050)
#define AUDIO_FREQUENCY_16K ((uint32_t)16000)
#define AUDIO_FREQUENCY_11K ((uint32_t)11025)
#define AUDIO_FREQUENCY_8K ((uint32_t)8000)
/******************************************************************************/
/****************************** REGISTER MAPPING ******************************/
/******************************************************************************/
/**
* @brief CS42L51 ID
*/
#define CS42L51_ID 0xD8
#define CS42L51_ID_MASK 0xF8
/**
* @brief Chip ID Register: Chip I.D. and Revision Register
* Read only register
* Default value: 0x01
* [7:3] CHIPID[4:0]: I.D. code for the CS42L51.
* Default value: 11100b
* [2:0] REVID[2:0]: CS42L51 revision level.
* Default value:
* 000 - Rev A0
* 001 - Rev A1
* 010 - Rev B0
* 011 - Rev B1
*/
#define CS42L51_CHIPID_ADDR 0x01
/**
* @}
*/
/** @defgroup CS42L51_Exported_Macros
* @{
*/
#define VOLUME_CONVERT(Volume) ((Volume >= 100) ? 0 : ((uint8_t)(((Volume * 2) + 56))))
/**
* @}
*/
/** @defgroup CS42L51_Exported_Functions
* @{
*/
/*------------------------------------------------------------------------------
Audio Codec functions
------------------------------------------------------------------------------*/
/* High Layer codec functions */
uint32_t cs42l51_Init(uint16_t DeviceAddr, uint16_t Device, uint8_t Volume, uint32_t AudioFreq);
void cs42l51_DeInit(void);
uint32_t cs42l51_ReadID(uint16_t DeviceAddr);
uint32_t cs42l51_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
uint32_t cs42l51_Pause(uint16_t DeviceAddr);
uint32_t cs42l51_Resume(uint16_t DeviceAddr);
uint32_t cs42l51_Stop(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t cs42l51_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
uint32_t cs42l51_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
uint32_t cs42l51_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t cs42l51_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
uint32_t cs42l51_Reset(uint16_t DeviceAddr);
/* AUDIO IO functions */
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);
void AUDIO_IO_Delay(uint32_t Delay);
/* Audio driver structure */
extern AUDIO_DrvTypeDef cs42l51_drv;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* __CS42L51_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,494 @@
/**
******************************************************************************
* @file cs43l22.c
* @author MCD Application Team
* @version V2.0.2
* @date 06-October-2015
* @brief This file provides the CS43L22 Audio Codec driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "cs43l22.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup CS43L22
* @brief This file provides a set of functions needed to drive the
* CS43L22 audio codec.
* @{
*/
/** @defgroup CS43L22_Private_Types
* @{
*/
/**
* @}
*/
/** @defgroup CS43L22_Private_Defines
* @{
*/
#define VOLUME_CONVERT(Volume) (((Volume) > 100)? 100:((uint8_t)(((Volume) * 255) / 100)))
/* Uncomment this line to enable verifying data sent to codec after each write
operation (for debug purpose) */
#if !defined (VERIFY_WRITTENDATA)
/* #define VERIFY_WRITTENDATA */
#endif /* VERIFY_WRITTENDATA */
/**
* @}
*/
/** @defgroup CS43L22_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup CS43L22_Private_Variables
* @{
*/
/* Audio codec driver structure initialization */
AUDIO_DrvTypeDef cs43l22_drv =
{
cs43l22_Init,
cs43l22_DeInit,
cs43l22_ReadID,
cs43l22_Play,
cs43l22_Pause,
cs43l22_Resume,
cs43l22_Stop,
cs43l22_SetFrequency,
cs43l22_SetVolume,
cs43l22_SetMute,
cs43l22_SetOutputMode,
cs43l22_Reset,
};
static uint8_t Is_cs43l22_Stop = 1;
volatile uint8_t OutputDev = 0;
/**
* @}
*/
/** @defgroup CS43L22_Function_Prototypes
* @{
*/
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
/**
* @}
*/
/** @defgroup CS43L22_Private_Functions
* @{
*/
/**
* @brief Initializes the audio codec and the control interface.
* @param DeviceAddr: Device address on communication Bus.
* @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
* OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Init(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
{
uint32_t counter = 0;
/* Initialize the Control interface of the Audio Codec */
AUDIO_IO_Init();
/* Keep Codec powered OFF */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x01);
/*Save Output device for mute ON/OFF procedure*/
switch (OutputDevice)
{
case OUTPUT_DEVICE_SPEAKER:
OutputDev = 0xFA;
break;
case OUTPUT_DEVICE_HEADPHONE:
OutputDev = 0xAF;
break;
case OUTPUT_DEVICE_BOTH:
OutputDev = 0xAA;
break;
case OUTPUT_DEVICE_AUTO:
OutputDev = 0x05;
break;
default:
OutputDev = 0x05;
break;
}
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
/* Clock configuration: Auto detection */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_CLOCKING_CTL, 0x81);
/* Set the Slave Mode and the audio Standard */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_INTERFACE_CTL1, CODEC_STANDARD);
/* Set the Master volume */
counter += cs43l22_SetVolume(DeviceAddr, Volume);
/* If the Speaker is enabled, set the Mono mode and volume attenuation level */
if(OutputDevice != OUTPUT_DEVICE_HEADPHONE)
{
/* Set the Speaker Mono mode */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PLAYBACK_CTL2, 0x06);
/* Set the Speaker attenuation level */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_SPEAKER_A_VOL, 0x00);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_SPEAKER_B_VOL, 0x00);
}
/* Additional configuration for the CODEC. These configurations are done to reduce
the time needed for the Codec to power off. If these configurations are removed,
then a long delay should be added between powering off the Codec and switching
off the I2S peripheral MCLK clock (which is the operating clock for Codec).
If this delay is not inserted, then the codec will not shut down properly and
it results in high noise after shut down. */
/* Disable the analog soft ramp */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_ANALOG_ZC_SR_SETT, 0x00);
/* Disable the digital soft ramp */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x04);
/* Disable the limiter attack level */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_LIMIT_CTL1, 0x00);
/* Adjust Bass and Treble levels */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_TONE_CTL, 0x0F);
/* Adjust PCM volume level */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PCMA_VOL, 0x0A);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_PCMB_VOL, 0x0A);
/* Return communication control value */
return counter;
}
/**
* @brief Deinitializes the audio codec.
* @param None
* @retval None
*/
void cs43l22_DeInit(void)
{
/* Deinitialize Audio Codec interface */
AUDIO_IO_DeInit();
}
/**
* @brief Get the CS43L22 ID.
* @param DeviceAddr: Device address on communication Bus.
* @retval The CS43L22 ID
*/
uint32_t cs43l22_ReadID(uint16_t DeviceAddr)
{
uint8_t Value;
/* Initialize the Control interface of the Audio Codec */
AUDIO_IO_Init();
Value = AUDIO_IO_Read(DeviceAddr, CS43L22_CHIPID_ADDR);
Value = (Value & CS43L22_ID_MASK);
return((uint32_t) Value);
}
/**
* @brief Start the audio Codec play feature.
* @note For this codec no Play options are required.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size)
{
uint32_t counter = 0;
if(Is_cs43l22_Stop == 1)
{
/* Enable the digital soft ramp */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x06);
/* Enable Output device */
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
/* Power on the Codec */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9E);
Is_cs43l22_Stop = 0;
}
/* Return communication control value */
return counter;
}
/**
* @brief Pauses playing on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Pause(uint16_t DeviceAddr)
{
uint32_t counter = 0;
/* Pause the audio file playing */
/* Mute the output first */
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_ON);
/* Put the Codec in Power save mode */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x01);
return counter;
}
/**
* @brief Resumes playing on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Resume(uint16_t DeviceAddr)
{
uint32_t counter = 0;
volatile uint32_t index = 0x00;
/* Resumes the audio file playing */
/* Unmute the output first */
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_OFF);
for(index = 0x00; index < 0xFF; index++);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
/* Exit the Power save mode */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9E);
return counter;
}
/**
* @brief Stops audio Codec playing. It powers down the codec.
* @param DeviceAddr: Device address on communication Bus.
* @param CodecPdwnMode: selects the power down mode.
* - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
* mode, the codec is set to default configuration
* (user should re-Initialize the codec in order to
* play again the audio stream).
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Stop(uint16_t DeviceAddr, uint32_t CodecPdwnMode)
{
uint32_t counter = 0;
/* Mute the output first */
counter += cs43l22_SetMute(DeviceAddr, AUDIO_MUTE_ON);
/* Disable the digital soft ramp */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MISC_CTL, 0x04);
/* Power down the DAC and the speaker (PMDAC and PMSPK bits)*/
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL1, 0x9F);
Is_cs43l22_Stop = 1;
return counter;
}
/**
* @brief Sets higher or lower the codec volume level.
* @param DeviceAddr: Device address on communication Bus.
* @param Volume: a byte value from 0 to 255 (refer to codec registers
* description for more details).
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume)
{
uint32_t counter = 0;
uint8_t convertedvol = VOLUME_CONVERT(Volume);
if(Volume > 0xE6)
{
/* Set the Master volume */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol - 0xE7);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol - 0xE7);
}
else
{
/* Set the Master volume */
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_A_VOL, convertedvol + 0x19);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_MASTER_B_VOL, convertedvol + 0x19);
}
return counter;
}
/**
* @brief Sets new frequency.
* @param DeviceAddr: Device address on communication Bus.
* @param AudioFreq: Audio frequency used to play the audio stream.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq)
{
return 0;
}
/**
* @brief Enables or disables the mute feature on the audio codec.
* @param DeviceAddr: Device address on communication Bus.
* @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
* mute mode.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_SetMute(uint16_t DeviceAddr, uint32_t Cmd)
{
uint32_t counter = 0;
/* Set the Mute mode */
if(Cmd == AUDIO_MUTE_ON)
{
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xFF);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_A_VOL, 0x01);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_B_VOL, 0x01);
}
else /* AUDIO_MUTE_OFF Disable the Mute */
{
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_A_VOL, 0x00);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_HEADPHONE_B_VOL, 0x00);
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, OutputDev);
}
return counter;
}
/**
* @brief Switch dynamically (while audio file is played) the output target
* (speaker or headphone).
* @note This function modifies a global variable of the audio codec driver: OutputDev.
* @param DeviceAddr: Device address on communication Bus.
* @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
* OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_SetOutputMode(uint16_t DeviceAddr, uint8_t Output)
{
uint32_t counter = 0;
switch (Output)
{
case OUTPUT_DEVICE_SPEAKER:
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xFA); /* SPK always ON & HP always OFF */
OutputDev = 0xFA;
break;
case OUTPUT_DEVICE_HEADPHONE:
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xAF); /* SPK always OFF & HP always ON */
OutputDev = 0xAF;
break;
case OUTPUT_DEVICE_BOTH:
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0xAA); /* SPK always ON & HP always ON */
OutputDev = 0xAA;
break;
case OUTPUT_DEVICE_AUTO:
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0x05); /* Detect the HP or the SPK automatically */
OutputDev = 0x05;
break;
default:
counter += CODEC_IO_Write(DeviceAddr, CS43L22_REG_POWER_CTL2, 0x05); /* Detect the HP or the SPK automatically */
OutputDev = 0x05;
break;
}
return counter;
}
/**
* @brief Resets cs43l22 registers.
* @param DeviceAddr: Device address on communication Bus.
* @retval 0 if correct communication, else wrong communication
*/
uint32_t cs43l22_Reset(uint16_t DeviceAddr)
{
return 0;
}
/**
* @brief Writes/Read a single data.
* @param Addr: I2C address
* @param Reg: Reg address
* @param Value: Data to be written
* @retval None
*/
static uint8_t CODEC_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
uint32_t result = 0;
AUDIO_IO_Write(Addr, Reg, Value);
#ifdef VERIFY_WRITTENDATA
/* Verify that the data has been correctly written */
result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1;
#endif /* VERIFY_WRITTENDATA */
return result;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,228 @@
/**
******************************************************************************
* @file cs43l22.h
* @author MCD Application Team
* @version V2.0.2
* @date 06-October-2015
* @brief This file contains all the functions prototypes for the cs43l22.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CS43L22_H
#define __CS43L22_H
/* Includes ------------------------------------------------------------------*/
#include "../Common/audio.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup CS43L22
* @{
*/
/** @defgroup CS43L22_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup CS43L22_Exported_Constants
* @{
*/
/******************************************************************************/
/*************************** Codec User defines ******************************/
/******************************************************************************/
/* Codec output DEVICE */
#define OUTPUT_DEVICE_SPEAKER 1
#define OUTPUT_DEVICE_HEADPHONE 2
#define OUTPUT_DEVICE_BOTH 3
#define OUTPUT_DEVICE_AUTO 4
/* Volume Levels values */
#define DEFAULT_VOLMIN 0x00
#define DEFAULT_VOLMAX 0xFF
#define DEFAULT_VOLSTEP 0x04
#define AUDIO_PAUSE 0
#define AUDIO_RESUME 1
/* Codec POWER DOWN modes */
#define CODEC_PDWN_HW 1
#define CODEC_PDWN_SW 2
/* MUTE commands */
#define AUDIO_MUTE_ON 1
#define AUDIO_MUTE_OFF 0
/* AUDIO FREQUENCY */
#define AUDIO_FREQUENCY_192K ((uint32_t)192000)
#define AUDIO_FREQUENCY_96K ((uint32_t)96000)
#define AUDIO_FREQUENCY_48K ((uint32_t)48000)
#define AUDIO_FREQUENCY_44K ((uint32_t)44100)
#define AUDIO_FREQUENCY_32K ((uint32_t)32000)
#define AUDIO_FREQUENCY_22K ((uint32_t)22050)
#define AUDIO_FREQUENCY_16K ((uint32_t)16000)
#define AUDIO_FREQUENCY_11K ((uint32_t)11025)
#define AUDIO_FREQUENCY_8K ((uint32_t)8000)
/** CS43l22 Registers ***/
#define CS43L22_REG_ID 0x01
#define CS43L22_REG_POWER_CTL1 0x02
#define CS43L22_REG_POWER_CTL2 0x04
#define CS43L22_REG_CLOCKING_CTL 0x05
#define CS43L22_REG_INTERFACE_CTL1 0x06
#define CS43L22_REG_INTERFACE_CTL2 0x07
#define CS43L22_REG_PASSTHR_A_SELECT 0x08
#define CS43L22_REG_PASSTHR_B_SELECT 0x09
#define CS43L22_REG_ANALOG_ZC_SR_SETT 0x0A
#define CS43L22_REG_PASSTHR_GANG_CTL 0x0C
#define CS43L22_REG_PLAYBACK_CTL1 0x0D
#define CS43L22_REG_MISC_CTL 0x0E
#define CS43L22_REG_PLAYBACK_CTL2 0x0F
#define CS43L22_REG_PASSTHR_A_VOL 0x14
#define CS43L22_REG_PASSTHR_B_VOL 0x15
#define CS43L22_REG_PCMA_VOL 0x1A
#define CS43L22_REG_PCMB_VOL 0x1B
#define CS43L22_REG_BEEP_FREQ_ON_TIME 0x1C
#define CS43L22_REG_BEEP_VOL_OFF_TIME 0x1D
#define CS43L22_REG_BEEP_TONE_CFG 0x1E
#define CS43L22_REG_TONE_CTL 0x1F
#define CS43L22_REG_MASTER_A_VOL 0x20
#define CS43L22_REG_MASTER_B_VOL 0x21
#define CS43L22_REG_HEADPHONE_A_VOL 0x22
#define CS43L22_REG_HEADPHONE_B_VOL 0x23
#define CS43L22_REG_SPEAKER_A_VOL 0x24
#define CS43L22_REG_SPEAKER_B_VOL 0x25
#define CS43L22_REG_CH_MIXER_SWAP 0x26
#define CS43L22_REG_LIMIT_CTL1 0x27
#define CS43L22_REG_LIMIT_CTL2 0x28
#define CS43L22_REG_LIMIT_ATTACK_RATE 0x29
#define CS43L22_REG_OVF_CLK_STATUS 0x2E
#define CS43L22_REG_BATT_COMPENSATION 0x2F
#define CS43L22_REG_VP_BATTERY_LEVEL 0x30
#define CS43L22_REG_SPEAKER_STATUS 0x31
#define CS43L22_REG_TEMPMONITOR_CTL 0x32
#define CS43L22_REG_THERMAL_FOLDBACK 0x33
#define CS43L22_REG_CHARGE_PUMP_FREQ 0x34
/******************************************************************************/
/****************************** REGISTER MAPPING ******************************/
/******************************************************************************/
/**
* @brief CS43L22 ID
*/
#define CS43L22_ID 0xE0
#define CS43L22_ID_MASK 0xF8
/**
* @brief Chip ID Register: Chip I.D. and Revision Register
* Read only register
* Default value: 0x01
* [7:3] CHIPID[4:0]: I.D. code for the CS43L22.
* Default value: 11100b
* [2:0] REVID[2:0]: CS43L22 revision level.
* Default value:
* 000 - Rev A0
* 001 - Rev A1
* 010 - Rev B0
* 011 - Rev B1
*/
#define CS43L22_CHIPID_ADDR 0x01
/**
* @}
*/
/** @defgroup CS43L22_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup CS43L22_Exported_Functions
* @{
*/
/*------------------------------------------------------------------------------
Audio Codec functions
------------------------------------------------------------------------------*/
/* High Layer codec functions */
uint32_t cs43l22_Init(uint16_t DeviceAddr, uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
void cs43l22_DeInit(void);
uint32_t cs43l22_ReadID(uint16_t DeviceAddr);
uint32_t cs43l22_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
uint32_t cs43l22_Pause(uint16_t DeviceAddr);
uint32_t cs43l22_Resume(uint16_t DeviceAddr);
uint32_t cs43l22_Stop(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t cs43l22_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
uint32_t cs43l22_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
uint32_t cs43l22_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t cs43l22_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
uint32_t cs43l22_Reset(uint16_t DeviceAddr);
/* AUDIO IO functions */
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);
/* Audio driver structure */
extern AUDIO_DrvTypeDef cs43l22_drv;
#endif /* __CS43L22_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,459 @@
/**
******************************************************************************
* @file ft3x67.c
* @author MCD Application Team
* @brief This file provides a set of functions needed to manage the FT3X67
* touch screen devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "ft3x67.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup FT3X67
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup FT3X67_Private_Types_Definitions
* @{
*/
/* ft3x67 Handle definition. */
typedef struct
{
uint8_t i2cInitialized;
/* field holding the current number of simultaneous active touches */
uint8_t currActiveTouchNb;
/* field holding the touch index currently managed */
uint8_t currActiveTouchIdx;
} ft3x67_handle_TypeDef;
/**
* @}
*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup FT3X67_Private_Variables
* @{
*/
/* Touch screen driver structure initialization */
TS_DrvTypeDef ft3x67_ts_drv =
{
ft3x67_Init,
ft3x67_ReadID,
ft3x67_Reset,
ft3x67_TS_Start,
ft3x67_TS_DetectTouch,
ft3x67_TS_GetXY,
ft3x67_TS_EnableIT,
ft3x67_TS_ClearIT,
ft3x67_TS_ITStatus,
ft3x67_TS_DisableIT
};
/* Global ft3x67 handle */
static ft3x67_handle_TypeDef ft3x67_handle = { FT3X67_I2C_NOT_INITIALIZED, 0U, 0U};
/**
* @}
*/
/* Private functions prototypes-----------------------------------------------*/
/** @defgroup FT3X67_Private_Functions
* @{
*/
static uint8_t ft3x67_Get_I2C_InitializedStatus(void);
static void ft3x67_I2C_InitializeIfRequired(void);
static uint32_t ft3x67_TS_Configure(uint16_t DeviceAddr);
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup FT3X67_Exported_Functions
* @{
*/
/**
* @brief Initialize the ft3x67 communication bus
* from MCU to FT3X67 : ie I2C channel initialization (if required).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @retval None
*/
void ft3x67_Init(uint16_t DeviceAddr)
{
/* Initialize I2C link if needed */
ft3x67_I2C_InitializeIfRequired();
}
/**
* @brief Software Reset the ft3x67.
* @note : Not applicable to FT3X67.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @retval None
*/
void ft3x67_Reset(uint16_t DeviceAddr)
{
/* Do nothing */
/* No software reset sequence available in FT3X67 IC */
}
/**
* @brief Read the ft3x67 device ID, pre initialize I2C in case of need to be
* able to read the FT3X67 device ID, and verify this is a FT3X67.
* @param DeviceAddr: I2C FT3X67 Slave address.
* @retval The Device ID (two bytes).
*/
uint16_t ft3x67_ReadID(uint16_t DeviceAddr)
{
/* Initialize I2C link if needed */
ft3x67_I2C_InitializeIfRequired();
/* Return the device ID value */
return(TS_IO_Read(DeviceAddr, FT3X67_CHIP_ID_REG));
}
/**
* @brief Configures the touch Screen IC device to start detecting touches
* @param DeviceAddr: Device address on communication Bus (I2C slave address).
* @retval None.
*/
void ft3x67_TS_Start(uint16_t DeviceAddr)
{
/* Minimum static configuration of FT3X67 */
ft3x67_TS_Configure(DeviceAddr);
/* By default set FT3X67 IC in Polling mode : no INT generation on FT3X67 for new touch available */
/* Note TS_INT is active low */
ft3x67_TS_DisableIT(DeviceAddr);
}
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal global
* variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
uint8_t ft3x67_TS_DetectTouch(uint16_t DeviceAddr)
{
volatile uint8_t nbTouch = 0U;
/* Read register FT3X67_TD_STAT_REG to check number of touches detection */
nbTouch = TS_IO_Read(DeviceAddr, FT3X67_TD_STAT_REG);
nbTouch &= FT3X67_TD_STAT_MASK;
if(nbTouch > FT3X67_MAX_DETECTABLE_TOUCH)
{
/* If invalid number of touch detected, set it to zero */
nbTouch = 0U;
}
/* Update ft3x67 driver internal global : current number of active touches */
ft3x67_handle.currActiveTouchNb = nbTouch;
/* Reset current active touch index on which to work on */
ft3x67_handle.currActiveTouchIdx = 0U;
return(nbTouch);
}
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'ft3x67_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void ft3x67_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
uint8_t regAddress = 0U;
uint8_t dataxy[4U];
if(ft3x67_handle.currActiveTouchIdx < ft3x67_handle.currActiveTouchNb)
{
switch(ft3x67_handle.currActiveTouchIdx)
{
case 0U :
regAddress = FT3X67_P1_XH_REG;
break;
case 1U :
regAddress = FT3X67_P2_XH_REG;
break;
default :
break;
} /* end switch(ft3x67_handle.currActiveTouchIdx) */
/* Read X and Y positions */
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
/* Send back ready X position to caller */
*X = ((dataxy[0U] & FT3X67_TOUCH_POS_MSB_MASK) << 8U) | dataxy[1U];
/* Send back ready Y position to caller */
*Y = ((dataxy[2U] & FT3X67_TOUCH_POS_MSB_MASK) << 8U) | dataxy[3U];
/* Increment current touch index */
ft3x67_handle.currActiveTouchIdx++;
}
}
/**
* @brief Configure the FT3X67 device to generate IT on given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT3X67).
* @retval None
*/
void ft3x67_TS_EnableIT(uint16_t DeviceAddr)
{
/* Set interrupt trigger mode in FT3X67_GMODE_REG */
TS_IO_Write(DeviceAddr, FT3X67_GMODE_REG, FT3X67_G_MODE_INTERRUPT_TRIGGER);
}
/**
* @brief Configure the FT3X67 device to stop generating IT on the given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT3X67).
* @retval None
*/
void ft3x67_TS_DisableIT(uint16_t DeviceAddr)
{
/* Set interrupt polling mode in FT3X67_GMODE_REG */
TS_IO_Write(DeviceAddr, FT3X67_GMODE_REG, FT3X67_G_MODE_INTERRUPT_POLLING);
}
/**
* @brief Get IT status from FT3X67 interrupt status registers
* Should be called Following an EXTI coming to the MCU to know the detailed
* reason of the interrupt.
* @note : This feature is not applicable to FT3X67.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @retval TS interrupts status : always return 0 here
*/
uint8_t ft3x67_TS_ITStatus(uint16_t DeviceAddr)
{
/* Always return 0 as feature not applicable to FT3X67 */
return 0U;
}
/**
* @brief Clear IT status in FT3X67 interrupt status clear registers
* Should be called Following an EXTI coming to the MCU.
* @note : This feature is not applicable to FT3X67.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @retval None
*/
void ft3x67_TS_ClearIT(uint16_t DeviceAddr)
{
/* Nothing to be done here for FT3X67 */
}
/**
* @brief Configure gesture feature (enable/disable).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @param Activation : Enable or disable gesture feature. Possible values are
* FT3X67_GESTURE_DISABLE or FT3X67_GESTURE_ENABLE.
* @retval None.
*/
void ft3x67_TS_GestureConfig(uint16_t DeviceAddr, uint32_t Activation)
{
if(Activation == FT3X67_GESTURE_ENABLE)
{
/* Enable gesture feature. */
TS_IO_Write(DeviceAddr, FT3X67_GESTURE_FLAG_REG, FT3X67_GEST_ALL_FLAGS_ENABLE);
TS_IO_Write(DeviceAddr, FT3X67_GESTURE_ENABLE_REG, FT3X67_GESTURE_ENABLE);
}
else
{
/* Disable gesture feature. */
TS_IO_Write(DeviceAddr, FT3X67_GESTURE_FLAG_REG, FT3X67_GEST_ALL_FLAGS_DISABLE);
TS_IO_Write(DeviceAddr, FT3X67_GESTURE_ENABLE_REG, FT3X67_GESTURE_DISABLE);
}
}
/**
* @brief Get the last touch gesture identification (zoom, move up/down...).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @param pGestureId : Pointer to get last touch gesture Identification.
* @retval None.
*/
void ft3x67_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
{
volatile uint8_t ucReadData = 0U;
ucReadData = TS_IO_Read(DeviceAddr, FT3X67_GEST_ID_REG);
*pGestureId = ucReadData;
}
/**
* @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
* This touch detailed information contains :
* - weight that was applied to this touch
* - sub-area of the touch in the touch panel
* - event of linked to the touch (press down, lift up, ...)
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT3X67).
* @param touchIdx : Passed index of the touch (0..1) on which we want to get the
* detailed information.
* @param pWeight : Pointer to to get the weight information of 'touchIdx'.
* @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
* @param pEvent : Pointer to to get the event information of 'touchIdx'.
* @note Area and Weight features are not supported by FT3X67. Return always 0 value.
* @retval None.
*/
void ft3x67_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent)
{
volatile uint8_t ucReadData = 0U;
uint8_t regAddressXHigh = 0U;
if(touchIdx < ft3x67_handle.currActiveTouchNb)
{
switch(touchIdx)
{
case 0U :
regAddressXHigh = FT3X67_P1_XH_REG;
break;
case 1U :
regAddressXHigh = FT3X67_P2_XH_REG;
break;
default :
break;
} /* end switch(touchIdx) */
/* Read Event Id of touch index */
ucReadData = TS_IO_Read(DeviceAddr, regAddressXHigh);
*pEvent = (ucReadData & FT3X67_TOUCH_EVT_FLAG_MASK) >> FT3X67_TOUCH_EVT_FLAG_SHIFT;
/* Weight and area of touch index not supported by FT3X67 */
*pWeight = 0;
*pArea = 0;
} /* of if(touchIdx < ft3x67_handle.currActiveTouchNb) */
}
/**
* @}
*/
/* Private functions bodies---------------------------------------------------*/
/** @addtogroup FT3X67_Private_Functions
* @{
*/
/**
* @brief Return the status of I2C was initialized or not.
* @param None.
* @retval : I2C initialization status.
*/
static uint8_t ft3x67_Get_I2C_InitializedStatus(void)
{
return(ft3x67_handle.i2cInitialized);
}
/**
* @brief I2C initialize if needed.
* @param None.
* @retval : None.
*/
static void ft3x67_I2C_InitializeIfRequired(void)
{
if(ft3x67_Get_I2C_InitializedStatus() == FT3X67_I2C_NOT_INITIALIZED)
{
/* Initialize TS IO BUS layer (I2C) */
TS_IO_Init();
/* Set state to initialized */
ft3x67_handle.i2cInitialized = FT3X67_I2C_INITIALIZED;
}
}
/**
* @brief Basic static configuration of TouchScreen
* @param DeviceAddr: FT3X67 Device address for communication on I2C Bus.
* @retval Status FT3X67_STATUS_OK or FT3X67_STATUS_NOT_OK.
*/
static uint32_t ft3x67_TS_Configure(uint16_t DeviceAddr)
{
uint32_t status = FT3X67_STATUS_OK;
/* Disable gesture feature */
TS_IO_Write(DeviceAddr, FT3X67_GESTURE_ENABLE_REG, FT3X67_GESTURE_DISABLE);
return(status);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,289 @@
/**
******************************************************************************
* @file ft3x67.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the
* ft3x67.c touch screen driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FT3X67_H
#define __FT3X67_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/ts.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup FT3X67
* @{
*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup FT3X67_Exported_Constants
* @{
*/
/* Maximum border values of the touchscreen pad */
#define FT3X67_MAX_WIDTH 390U /* Touchscreen pad max width */
#define FT3X67_MAX_HEIGHT 390U /* Touchscreen pad max height */
/* Possible values of driver functions return status */
#define FT3X67_STATUS_OK 0x00U
#define FT3X67_STATUS_NOT_OK 0x01U
/* Possible values of global variable 'TS_I2C_Initialized' */
#define FT3X67_I2C_NOT_INITIALIZED 0x00U
#define FT3X67_I2C_INITIALIZED 0x01U
/* Max detectable simultaneous touches */
#define FT3X67_MAX_DETECTABLE_TOUCH 0x02U
/* Definitions for FT3X67 registers */
/* Current mode register of the FT3X67 (R/W) */
#define FT3X67_DEV_MODE_REG 0x00U
/* Possible values of FT3X67_DEV_MODE_REG */
#define FT3X67_DEV_MODE_WORKING 0x00U
#define FT3X67_DEV_MODE_FACTORY 0x40U
/* Touch Data Status register : gives number of active touch points (0..2) */
#define FT3X67_TD_STAT_REG 0x02U
/* Values related to FT3X67_TD_STAT_REG */
#define FT3X67_TD_STAT_MASK 0x0FU
/* Values Pn_XH and Pn_YH related */
#define FT3X67_TOUCH_EVT_FLAG_PRESS_DOWN 0x00U
#define FT3X67_TOUCH_EVT_FLAG_LIFT_UP 0x01U
#define FT3X67_TOUCH_EVT_FLAG_CONTACT 0x02U
#define FT3X67_TOUCH_EVT_FLAG_NO_EVENT 0x03U
#define FT3X67_TOUCH_EVT_FLAG_SHIFT 0x06U
#define FT3X67_TOUCH_EVT_FLAG_MASK (3U << FT3X67_TOUCH_EVT_FLAG_SHIFT)
#define FT3X67_TOUCH_POS_MSB_MASK 0x0FU
/* Point 1 registers */
#define FT3X67_P1_XH_REG 0x03U
#define FT3X67_P1_XL_REG 0x04U
#define FT3X67_P1_YH_REG 0x05U
#define FT3X67_P1_YL_REG 0x06U
#define FT3X67_P1_WEIGHT_REG 0x07U
#define FT3X67_P1_MISC_REG 0x08U
/* Point 2 registers */
#define FT3X67_P2_XH_REG 0x09U
#define FT3X67_P2_XL_REG 0x0AU
#define FT3X67_P2_YH_REG 0x0BU
#define FT3X67_P2_YL_REG 0x0CU
#define FT3X67_P2_WEIGHT_REG 0x0DU
#define FT3X67_P2_MISC_REG 0x0EU
/* Values related to Pn_MISC register */
#define FT3X67_TOUCH_AREA_MASK (0xFU << FT3X67_TOUCH_AREA_SHIFT)
#define FT3X67_TOUCH_AREA_SHIFT 0x04U
/* Threshold for touch detection register */
#define FT3X67_TH_GROUP_REG 0x80U
/* Filter function coefficients register */
#define FT3X67_TH_DIFF_REG 0x85U
/* Control register */
#define FT3X67_CTRL_REG 0x86U
/* Values related to FT3X67_CTRL_REG */
#define FT3X67_CTRL_KEEP_ACTIVE_MODE 0x00U
#define FT3X67_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE 0x01U
/* The time period of switching from Active mode to Monitor mode when there is no touching */
#define FT3X67_TIMEENTERMONITOR_REG 0x87U
/* Report rate in Active mode */
#define FT3X67_PERIODACTIVE_REG 0x88U
/* Report rate in Monitor mode */
#define FT3X67_PERIODMONITOR_REG 0x89U
/* High 8-bit of LIB Version info */
#define FT3X67_LIB_VER_H_REG 0xA1U
/* Low 8-bit of LIB Version info */
#define FT3X67_LIB_VER_L_REG 0xA2U
/* Chip Selecting */
#define FT3X67_CIPHER_REG 0xA3U
/* Interrupt mode register (used when in interrupt mode) */
#define FT3X67_GMODE_REG 0xA4U
/* Possible values of FT3X67_GMODE_REG */
#define FT3X67_G_MODE_INTERRUPT_POLLING 0x00U
#define FT3X67_G_MODE_INTERRUPT_TRIGGER 0x01U
/* Current power mode */
#define FT3X67_PWR_MODE_REG 0xA5U
/* Firmware version */
#define FT3X67_FIRMID_REG 0xA6U
/* Chip identification register */
#define FT3X67_CHIP_ID_REG 0xA8U
/* Possible values of FT3X67_CHIP_ID_REG */
#define FT3X67_ID_VALUE 0x11U
/* Release code version */
#define FT3X67_RELEASE_CODE_ID_REG 0xAFU
/* Current operating mode register */
#define FT3X67_STATE_REG 0xBCU
/* Possible values of FT3X67_STATE_REG */
#define FT3X67_STATE_INFO_MODE 0x00U
#define FT3X67_STATE_NORMAL_MODE 0x01U
#define FT3X67_STATE_FACTORY_MODE 0x03U
#define FT3X67_STATE_AUTO_CALIB_MODE 0x04U
/* Gesture enable register */
#define FT3X67_GESTURE_ENABLE_REG 0xD0U
/* Possible values of FT3X67_GESTURE_ENABLE_REG */
#define FT3X67_GESTURE_DISABLE 0x00U
#define FT3X67_GESTURE_ENABLE 0x01U
/* Gesture flag register */
#define FT3X67_GESTURE_FLAG_REG 0xD1U
/* Possible values of FT3X67_GESTURE_FLAG_REG can be any combination of following values */
#define FT3X67_GEST_LINE_RIGHT_TO_LEFT_ENABLE 0x01U
#define FT3X67_GEST_LINE_LEFT_TO_RIGHT_ENABLE 0x02U
#define FT3X67_GEST_LINE_DOWN_TO_UP_ENABLE 0x04U
#define FT3X67_GEST_LINE_UP_TO_DOWN_ENABLE 0x08U
#define FT3X67_GEST_DOUBLE_TAP_ENABLE 0x10U
#define FT3X67_GEST_ALL_FLAGS_ENABLE 0x1FU
#define FT3X67_GEST_ALL_FLAGS_DISABLE 0x00U
/* Gesture ID register */
#define FT3X67_GEST_ID_REG 0xD3U
/* Possible values of FT3X67_GEST_ID_REG */
#define FT3X67_GEST_ID_NO_GESTURE 0x00U
#define FT3X67_GEST_ID_MOVE_UP 0x22U
#define FT3X67_GEST_ID_MOVE_RIGHT 0x21U
#define FT3X67_GEST_ID_MOVE_DOWN 0x23U
#define FT3X67_GEST_ID_MOVE_LEFT 0x20U
#define FT3X67_GEST_ID_DOUBLE_CLICK 0x24U
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup FT3X67_Exported_Functions
* @{
*/
void ft3x67_Init(uint16_t DeviceAddr);
void ft3x67_Reset(uint16_t DeviceAddr);
uint16_t ft3x67_ReadID(uint16_t DeviceAddr);
void ft3x67_TS_Start(uint16_t DeviceAddr);
uint8_t ft3x67_TS_DetectTouch(uint16_t DeviceAddr);
void ft3x67_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
void ft3x67_TS_EnableIT(uint16_t DeviceAddr);
void ft3x67_TS_DisableIT(uint16_t DeviceAddr);
uint8_t ft3x67_TS_ITStatus (uint16_t DeviceAddr);
void ft3x67_TS_ClearIT (uint16_t DeviceAddr);
void ft3x67_TS_GestureConfig(uint16_t DeviceAddr, uint32_t Activation);
void ft3x67_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId);
void ft3x67_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent);
/**
* @}
*/
/* Imported TS IO functions --------------------------------------------------------*/
/** @defgroup FT3X67_Imported_Functions
* @{
*/
/* TouchScreen (TS) external IO functions */
extern void TS_IO_Init(void);
extern void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void TS_IO_Delay(uint32_t Delay);
/**
* @}
*/
/* Imported global variables --------------------------------------------------------*/
/** @defgroup FT3X67_Imported_Globals
* @{
*/
/* Touch screen driver structure */
extern TS_DrvTypeDef ft3x67_ts_drv;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __FT3X67_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,625 @@
/**
******************************************************************************
* @file ft5336.c
* @author MCD Application Team
* @version V1.0.0
* @date 25-June-2015
* @brief This file provides a set of functions needed to manage the FT5336
* touch screen devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "ft5336.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup FT5336
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup FT5336_Private_Types_Definitions
* @{
*/
/* Private define ------------------------------------------------------------*/
/** @defgroup FT5336_Private_Defines
* @{
*/
/* Private macro -------------------------------------------------------------*/
/** @defgroup FT5336_Private_Macros
* @{
*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup FT5336_Private_Variables
* @{
*/
/* Touch screen driver structure initialization */
TS_DrvTypeDef ft5336_ts_drv =
{
ft5336_Init,
ft5336_ReadID,
ft5336_Reset,
ft5336_TS_Start,
ft5336_TS_DetectTouch,
ft5336_TS_GetXY,
ft5336_TS_EnableIT,
ft5336_TS_ClearIT,
ft5336_TS_ITStatus,
ft5336_TS_DisableIT
};
/* Global ft5336 handle */
static ft5336_handle_TypeDef ft5336_handle = { FT5336_I2C_NOT_INITIALIZED, 0, 0};
/**
* @}
*/
/** @defgroup ft5336_Private_Function_Prototypes
* @{
*/
/* Private functions prototypes-----------------------------------------------*/
/**
* @brief Return the status of I2C was initialized or not.
* @param None.
* @retval : I2C initialization status.
*/
static uint8_t ft5336_Get_I2C_InitializedStatus(void);
/**
* @brief I2C initialize if needed.
* @param None.
* @retval : None.
*/
static void ft5336_I2C_InitializeIfRequired(void);
/**
* @brief Basic static configuration of TouchScreen
* @param DeviceAddr: FT5336 Device address for communication on I2C Bus.
* @retval Status FT5336_STATUS_OK or FT5336_STATUS_NOT_OK.
*/
static uint32_t ft5336_TS_Configure(uint16_t DeviceAddr);
/** @defgroup ft5336_Private_Functions
* @{
*/
/** @defgroup ft5336_Public_Function_Body
* @{
*/
/* Public functions bodies-----------------------------------------------*/
/**
* @brief Initialize the ft5336 communication bus
* from MCU to FT5336 : ie I2C channel initialization (if required).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval None
*/
void ft5336_Init(uint16_t DeviceAddr)
{
/* Wait at least 200ms after power up before accessing registers
* Trsi timing (Time of starting to report point after resetting) from FT5336GQQ datasheet */
TS_IO_Delay(200);
/* Initialize I2C link if needed */
ft5336_I2C_InitializeIfRequired();
}
/**
* @brief Software Reset the ft5336.
* @note : Not applicable to FT5336.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval None
*/
void ft5336_Reset(uint16_t DeviceAddr)
{
/* Do nothing */
/* No software reset sequence available in FT5336 IC */
}
/**
* @brief Read the ft5336 device ID, pre initialize I2C in case of need to be
* able to read the FT5336 device ID, and verify this is a FT5336.
* @param DeviceAddr: I2C FT5336 Slave address.
* @retval The Device ID (two bytes).
*/
uint16_t ft5336_ReadID(uint16_t DeviceAddr)
{
volatile uint8_t ucReadId = 0;
uint8_t nbReadAttempts = 0;
uint8_t bFoundDevice = 0; /* Device not found by default */
/* Initialize I2C link if needed */
ft5336_I2C_InitializeIfRequired();
/* At maximum 4 attempts to read ID : exit at first finding of the searched device ID */
for(nbReadAttempts = 0; ((nbReadAttempts < 3) && !(bFoundDevice)); nbReadAttempts++)
{
/* Read register FT5336_CHIP_ID_REG as DeviceID detection */
ucReadId = TS_IO_Read(DeviceAddr, FT5336_CHIP_ID_REG);
/* Found the searched device ID ? */
if(ucReadId == FT5336_ID_VALUE)
{
/* Set device as found */
bFoundDevice = 1;
}
}
/* Return the device ID value */
return (ucReadId);
}
/**
* @brief Configures the touch Screen IC device to start detecting touches
* @param DeviceAddr: Device address on communication Bus (I2C slave address).
* @retval None.
*/
void ft5336_TS_Start(uint16_t DeviceAddr)
{
/* Minimum static configuration of FT5336 */
FT5336_ASSERT(ft5336_TS_Configure(DeviceAddr));
/* By default set FT5336 IC in Polling mode : no INT generation on FT5336 for new touch available */
/* Note TS_INT is active low */
ft5336_TS_DisableIT(DeviceAddr);
}
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal global
* variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
uint8_t ft5336_TS_DetectTouch(uint16_t DeviceAddr)
{
volatile uint8_t nbTouch = 0;
/* Read register FT5336_TD_STAT_REG to check number of touches detection */
nbTouch = TS_IO_Read(DeviceAddr, FT5336_TD_STAT_REG);
nbTouch &= FT5336_TD_STAT_MASK;
if(nbTouch > FT5336_MAX_DETECTABLE_TOUCH)
{
/* If invalid number of touch detected, set it to zero */
nbTouch = 0;
}
/* Update ft5336 driver internal global : current number of active touches */
ft5336_handle.currActiveTouchNb = nbTouch;
/* Reset current active touch index on which to work on */
ft5336_handle.currActiveTouchIdx = 0;
return(nbTouch);
}
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'ft5336_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void ft5336_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
volatile uint8_t ucReadData = 0;
static uint16_t coord;
uint8_t regAddressXLow = 0;
uint8_t regAddressXHigh = 0;
uint8_t regAddressYLow = 0;
uint8_t regAddressYHigh = 0;
if(ft5336_handle.currActiveTouchIdx < ft5336_handle.currActiveTouchNb)
{
switch(ft5336_handle.currActiveTouchIdx)
{
case 0 :
regAddressXLow = FT5336_P1_XL_REG;
regAddressXHigh = FT5336_P1_XH_REG;
regAddressYLow = FT5336_P1_YL_REG;
regAddressYHigh = FT5336_P1_YH_REG;
break;
case 1 :
regAddressXLow = FT5336_P2_XL_REG;
regAddressXHigh = FT5336_P2_XH_REG;
regAddressYLow = FT5336_P2_YL_REG;
regAddressYHigh = FT5336_P2_YH_REG;
break;
case 2 :
regAddressXLow = FT5336_P3_XL_REG;
regAddressXHigh = FT5336_P3_XH_REG;
regAddressYLow = FT5336_P3_YL_REG;
regAddressYHigh = FT5336_P3_YH_REG;
break;
case 3 :
regAddressXLow = FT5336_P4_XL_REG;
regAddressXHigh = FT5336_P4_XH_REG;
regAddressYLow = FT5336_P4_YL_REG;
regAddressYHigh = FT5336_P4_YH_REG;
break;
case 4 :
regAddressXLow = FT5336_P5_XL_REG;
regAddressXHigh = FT5336_P5_XH_REG;
regAddressYLow = FT5336_P5_YL_REG;
regAddressYHigh = FT5336_P5_YH_REG;
break;
case 5 :
regAddressXLow = FT5336_P6_XL_REG;
regAddressXHigh = FT5336_P6_XH_REG;
regAddressYLow = FT5336_P6_YL_REG;
regAddressYHigh = FT5336_P6_YH_REG;
break;
case 6 :
regAddressXLow = FT5336_P7_XL_REG;
regAddressXHigh = FT5336_P7_XH_REG;
regAddressYLow = FT5336_P7_YL_REG;
regAddressYHigh = FT5336_P7_YH_REG;
break;
case 7 :
regAddressXLow = FT5336_P8_XL_REG;
regAddressXHigh = FT5336_P8_XH_REG;
regAddressYLow = FT5336_P8_YL_REG;
regAddressYHigh = FT5336_P8_YH_REG;
break;
case 8 :
regAddressXLow = FT5336_P9_XL_REG;
regAddressXHigh = FT5336_P9_XH_REG;
regAddressYLow = FT5336_P9_YL_REG;
regAddressYHigh = FT5336_P9_YH_REG;
break;
case 9 :
regAddressXLow = FT5336_P10_XL_REG;
regAddressXHigh = FT5336_P10_XH_REG;
regAddressYLow = FT5336_P10_YL_REG;
regAddressYHigh = FT5336_P10_YH_REG;
break;
default :
break;
} /* end switch(ft5336_handle.currActiveTouchIdx) */
/* Read low part of X position */
ucReadData = TS_IO_Read(DeviceAddr, regAddressXLow);
coord = (ucReadData & FT5336_TOUCH_POS_LSB_MASK) >> FT5336_TOUCH_POS_LSB_SHIFT;
/* Read high part of X position */
ucReadData = TS_IO_Read(DeviceAddr, regAddressXHigh);
coord |= ((ucReadData & FT5336_TOUCH_POS_MSB_MASK) >> FT5336_TOUCH_POS_MSB_SHIFT) << 8;
/* Send back ready X position to caller */
*X = coord;
/* Read low part of Y position */
ucReadData = TS_IO_Read(DeviceAddr, regAddressYLow);
coord = (ucReadData & FT5336_TOUCH_POS_LSB_MASK) >> FT5336_TOUCH_POS_LSB_SHIFT;
/* Read high part of Y position */
ucReadData = TS_IO_Read(DeviceAddr, regAddressYHigh);
coord |= ((ucReadData & FT5336_TOUCH_POS_MSB_MASK) >> FT5336_TOUCH_POS_MSB_SHIFT) << 8;
/* Send back ready Y position to caller */
*Y = coord;
ft5336_handle.currActiveTouchIdx++; /* next call will work on next touch */
} /* of if(ft5336_handle.currActiveTouchIdx < ft5336_handle.currActiveTouchNb) */
}
/**
* @brief Configure the FT5336 device to generate IT on given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
* @retval None
*/
void ft5336_TS_EnableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT5336_G_MODE_INTERRUPT_TRIGGER & (FT5336_G_MODE_INTERRUPT_MASK >> FT5336_G_MODE_INTERRUPT_SHIFT)) << FT5336_G_MODE_INTERRUPT_SHIFT;
/* Set interrupt trigger mode in FT5336_GMODE_REG */
TS_IO_Write(DeviceAddr, FT5336_GMODE_REG, regValue);
}
/**
* @brief Configure the FT5336 device to stop generating IT on the given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
* @retval None
*/
void ft5336_TS_DisableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT5336_G_MODE_INTERRUPT_POLLING & (FT5336_G_MODE_INTERRUPT_MASK >> FT5336_G_MODE_INTERRUPT_SHIFT)) << FT5336_G_MODE_INTERRUPT_SHIFT;
/* Set interrupt polling mode in FT5336_GMODE_REG */
TS_IO_Write(DeviceAddr, FT5336_GMODE_REG, regValue);
}
/**
* @brief Get IT status from FT5336 interrupt status registers
* Should be called Following an EXTI coming to the MCU to know the detailed
* reason of the interrupt.
* @note : This feature is not applicable to FT5336.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval TS interrupts status : always return 0 here
*/
uint8_t ft5336_TS_ITStatus(uint16_t DeviceAddr)
{
/* Always return 0 as feature not applicable to FT5336 */
return 0;
}
/**
* @brief Clear IT status in FT5336 interrupt status clear registers
* Should be called Following an EXTI coming to the MCU.
* @note : This feature is not applicable to FT5336.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval None
*/
void ft5336_TS_ClearIT(uint16_t DeviceAddr)
{
/* Nothing to be done here for FT5336 */
}
/**** NEW FEATURES enabled when Multi-touch support is enabled ****/
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/**
* @brief Get the last touch gesture identification (zoom, move up/down...).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @param pGestureId : Pointer to get last touch gesture Identification.
* @retval None.
*/
void ft5336_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
{
volatile uint8_t ucReadData = 0;
ucReadData = TS_IO_Read(DeviceAddr, FT5336_GEST_ID_REG);
* pGestureId = ucReadData;
}
/**
* @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
* This touch detailed information contains :
* - weight that was applied to this touch
* - sub-area of the touch in the touch panel
* - event of linked to the touch (press down, lift up, ...)
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @param touchIdx : Passed index of the touch (0..1) on which we want to get the
* detailed information.
* @param pWeight : Pointer to to get the weight information of 'touchIdx'.
* @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
* @param pEvent : Pointer to to get the event information of 'touchIdx'.
* @retval None.
*/
void ft5336_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent)
{
volatile uint8_t ucReadData = 0;
uint8_t regAddressXHigh = 0;
uint8_t regAddressPWeight = 0;
uint8_t regAddressPMisc = 0;
if(touchIdx < ft5336_handle.currActiveTouchNb)
{
switch(touchIdx)
{
case 0 :
regAddressXHigh = FT5336_P1_XH_REG;
regAddressPWeight = FT5336_P1_WEIGHT_REG;
regAddressPMisc = FT5336_P1_MISC_REG;
break;
case 1 :
regAddressXHigh = FT5336_P2_XH_REG;
regAddressPWeight = FT5336_P2_WEIGHT_REG;
regAddressPMisc = FT5336_P2_MISC_REG;
break;
case 2 :
regAddressXHigh = FT5336_P3_XH_REG;
regAddressPWeight = FT5336_P3_WEIGHT_REG;
regAddressPMisc = FT5336_P3_MISC_REG;
break;
case 3 :
regAddressXHigh = FT5336_P4_XH_REG;
regAddressPWeight = FT5336_P4_WEIGHT_REG;
regAddressPMisc = FT5336_P4_MISC_REG;
break;
case 4 :
regAddressXHigh = FT5336_P5_XH_REG;
regAddressPWeight = FT5336_P5_WEIGHT_REG;
regAddressPMisc = FT5336_P5_MISC_REG;
break;
case 5 :
regAddressXHigh = FT5336_P6_XH_REG;
regAddressPWeight = FT5336_P6_WEIGHT_REG;
regAddressPMisc = FT5336_P6_MISC_REG;
break;
case 6 :
regAddressXHigh = FT5336_P7_XH_REG;
regAddressPWeight = FT5336_P7_WEIGHT_REG;
regAddressPMisc = FT5336_P7_MISC_REG;
break;
case 7 :
regAddressXHigh = FT5336_P8_XH_REG;
regAddressPWeight = FT5336_P8_WEIGHT_REG;
regAddressPMisc = FT5336_P8_MISC_REG;
break;
case 8 :
regAddressXHigh = FT5336_P9_XH_REG;
regAddressPWeight = FT5336_P9_WEIGHT_REG;
regAddressPMisc = FT5336_P9_MISC_REG;
break;
case 9 :
regAddressXHigh = FT5336_P10_XH_REG;
regAddressPWeight = FT5336_P10_WEIGHT_REG;
regAddressPMisc = FT5336_P10_MISC_REG;
break;
default :
break;
} /* end switch(touchIdx) */
/* Read Event Id of touch index */
ucReadData = TS_IO_Read(DeviceAddr, regAddressXHigh);
* pEvent = (ucReadData & FT5336_TOUCH_EVT_FLAG_MASK) >> FT5336_TOUCH_EVT_FLAG_SHIFT;
/* Read weight of touch index */
ucReadData = TS_IO_Read(DeviceAddr, regAddressPWeight);
* pWeight = (ucReadData & FT5336_TOUCH_WEIGHT_MASK) >> FT5336_TOUCH_WEIGHT_SHIFT;
/* Read area of touch index */
ucReadData = TS_IO_Read(DeviceAddr, regAddressPMisc);
* pArea = (ucReadData & FT5336_TOUCH_AREA_MASK) >> FT5336_TOUCH_AREA_SHIFT;
} /* of if(touchIdx < ft5336_handle.currActiveTouchNb) */
}
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
/** @defgroup ft5336_Static_Function_Body
* @{
*/
/* Static functions bodies-----------------------------------------------*/
/**
* @brief Return the status of I2C was initialized or not.
* @param None.
* @retval : I2C initialization status.
*/
static uint8_t ft5336_Get_I2C_InitializedStatus(void)
{
return(ft5336_handle.i2cInitialized);
}
/**
* @brief I2C initialize if needed.
* @param None.
* @retval : None.
*/
static void ft5336_I2C_InitializeIfRequired(void)
{
if(ft5336_Get_I2C_InitializedStatus() == FT5336_I2C_NOT_INITIALIZED)
{
/* Initialize TS IO BUS layer (I2C) */
TS_IO_Init();
/* Set state to initialized */
ft5336_handle.i2cInitialized = FT5336_I2C_INITIALIZED;
}
}
/**
* @brief Basic static configuration of TouchScreen
* @param DeviceAddr: FT5336 Device address for communication on I2C Bus.
* @retval Status FT5336_STATUS_OK or FT5336_STATUS_NOT_OK.
*/
static uint32_t ft5336_TS_Configure(uint16_t DeviceAddr)
{
uint32_t status = FT5336_STATUS_OK;
/* Nothing special to be done for FT5336 */
return(status);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,540 @@
/**
******************************************************************************
* @file ft5336.h
* @author MCD Application Team
* @version V1.0.0
* @date 25-June-2015
* @brief This file contains all the functions prototypes for the
* ft5336.c Touch screen driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FT5336_H
#define __FT5336_H
#ifdef __cplusplus
extern "C" {
#endif
/* Set Multi-touch as supported */
#if !defined(TS_MONO_TOUCH_SUPPORTED)
#define TS_MULTI_TOUCH_SUPPORTED 1
#endif /* TS_MONO_TOUCH_SUPPORTED */
/* Includes ------------------------------------------------------------------*/
#include "../Common/ts.h"
/* Macros --------------------------------------------------------------------*/
#if defined(FT5336_ENABLE_ASSERT)
/* Assert activated */
#define FT5336_ASSERT(__condition__) do { if(__condition__) \
{ \
while(1); \
} \
}while(0)
#else
/* Assert not activated : macro has no effect */
#define FT5336_ASSERT(__condition__) do { if(__condition__) \
{ \
; \
} \
}while(0)
#endif /* FT5336_ENABLE_ASSERT == 1 */
/** @typedef ft5336_handle_TypeDef
* ft5336 Handle definition.
*/
typedef struct
{
uint8_t i2cInitialized;
/* field holding the current number of simultaneous active touches */
uint8_t currActiveTouchNb;
/* field holding the touch index currently managed */
uint8_t currActiveTouchIdx;
} ft5336_handle_TypeDef;
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup FT5336
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup FT5336_Exported_Types
* @{
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup FT5336_Exported_Constants
* @{
*/
/* I2C Slave address of touchscreen FocalTech FT5336 */
#define FT5336_I2C_SLAVE_ADDRESS ((uint8_t)0x70)
/* Maximum border values of the touchscreen pad */
#define FT5336_MAX_WIDTH ((uint16_t)480) /* Touchscreen pad max width */
#define FT5336_MAX_HEIGHT ((uint16_t)272) /* Touchscreen pad max height */
/* Possible values of driver functions return status */
#define FT5336_STATUS_OK ((uint8_t)0x00)
#define FT5336_STATUS_NOT_OK ((uint8_t)0x01)
/* Possible values of global variable 'TS_I2C_Initialized' */
#define FT5336_I2C_NOT_INITIALIZED ((uint8_t)0x00)
#define FT5336_I2C_INITIALIZED ((uint8_t)0x01)
/* Max detectable simultaneous touches */
#define FT5336_MAX_DETECTABLE_TOUCH ((uint8_t)0x05)
/**
* @brief : Definitions for FT5336 I2C register addresses on 8 bit
**/
/* Current mode register of the FT5336 (R/W) */
#define FT5336_DEV_MODE_REG ((uint8_t)0x00)
/* Possible values of FT5336_DEV_MODE_REG */
#define FT5336_DEV_MODE_WORKING ((uint8_t)0x00)
#define FT5336_DEV_MODE_FACTORY ((uint8_t)0x04)
#define FT5336_DEV_MODE_MASK ((uint8_t)0x07)
#define FT5336_DEV_MODE_SHIFT ((uint8_t)0x04)
/* Gesture ID register */
#define FT5336_GEST_ID_REG ((uint8_t)0x01)
/* Possible values of FT5336_GEST_ID_REG */
#define FT5336_GEST_ID_NO_GESTURE ((uint8_t)0x00)
#define FT5336_GEST_ID_MOVE_UP ((uint8_t)0x10)
#define FT5336_GEST_ID_MOVE_RIGHT ((uint8_t)0x14)
#define FT5336_GEST_ID_MOVE_DOWN ((uint8_t)0x18)
#define FT5336_GEST_ID_MOVE_LEFT ((uint8_t)0x1C)
#define FT5336_GEST_ID_SINGLE_CLICK ((uint8_t)0x20)
#define FT5336_GEST_ID_DOUBLE_CLICK ((uint8_t)0x22)
#define FT5336_GEST_ID_ROTATE_CLOCKWISE ((uint8_t)0x28)
#define FT5336_GEST_ID_ROTATE_C_CLOCKWISE ((uint8_t)0x29)
#define FT5336_GEST_ID_ZOOM_IN ((uint8_t)0x40)
#define FT5336_GEST_ID_ZOOM_OUT ((uint8_t)0x49)
/* Touch Data Status register : gives number of active touch points (0..5) */
#define FT5336_TD_STAT_REG ((uint8_t)0x02)
/* Values related to FT5336_TD_STAT_REG */
#define FT5336_TD_STAT_MASK ((uint8_t)0x0F)
#define FT5336_TD_STAT_SHIFT ((uint8_t)0x00)
/* Values Pn_XH and Pn_YH related */
#define FT5336_TOUCH_EVT_FLAG_PRESS_DOWN ((uint8_t)0x00)
#define FT5336_TOUCH_EVT_FLAG_LIFT_UP ((uint8_t)0x01)
#define FT5336_TOUCH_EVT_FLAG_CONTACT ((uint8_t)0x02)
#define FT5336_TOUCH_EVT_FLAG_NO_EVENT ((uint8_t)0x03)
#define FT5336_TOUCH_EVT_FLAG_SHIFT ((uint8_t)0x06)
#define FT5336_TOUCH_EVT_FLAG_MASK ((uint8_t)(3 << FT5336_TOUCH_EVT_FLAG_SHIFT))
#define FT5336_TOUCH_POS_MSB_MASK ((uint8_t)0x0F)
#define FT5336_TOUCH_POS_MSB_SHIFT ((uint8_t)0x00)
/* Values Pn_XL and Pn_YL related */
#define FT5336_TOUCH_POS_LSB_MASK ((uint8_t)0xFF)
#define FT5336_TOUCH_POS_LSB_SHIFT ((uint8_t)0x00)
#define FT5336_P1_XH_REG ((uint8_t)0x03)
#define FT5336_P1_XL_REG ((uint8_t)0x04)
#define FT5336_P1_YH_REG ((uint8_t)0x05)
#define FT5336_P1_YL_REG ((uint8_t)0x06)
/* Touch Pressure register value (R) */
#define FT5336_P1_WEIGHT_REG ((uint8_t)0x07)
/* Values Pn_WEIGHT related */
#define FT5336_TOUCH_WEIGHT_MASK ((uint8_t)0xFF)
#define FT5336_TOUCH_WEIGHT_SHIFT ((uint8_t)0x00)
/* Touch area register */
#define FT5336_P1_MISC_REG ((uint8_t)0x08)
/* Values related to FT5336_Pn_MISC_REG */
#define FT5336_TOUCH_AREA_MASK ((uint8_t)(0x04 << 4))
#define FT5336_TOUCH_AREA_SHIFT ((uint8_t)0x04)
#define FT5336_P2_XH_REG ((uint8_t)0x09)
#define FT5336_P2_XL_REG ((uint8_t)0x0A)
#define FT5336_P2_YH_REG ((uint8_t)0x0B)
#define FT5336_P2_YL_REG ((uint8_t)0x0C)
#define FT5336_P2_WEIGHT_REG ((uint8_t)0x0D)
#define FT5336_P2_MISC_REG ((uint8_t)0x0E)
#define FT5336_P3_XH_REG ((uint8_t)0x0F)
#define FT5336_P3_XL_REG ((uint8_t)0x10)
#define FT5336_P3_YH_REG ((uint8_t)0x11)
#define FT5336_P3_YL_REG ((uint8_t)0x12)
#define FT5336_P3_WEIGHT_REG ((uint8_t)0x13)
#define FT5336_P3_MISC_REG ((uint8_t)0x14)
#define FT5336_P4_XH_REG ((uint8_t)0x15)
#define FT5336_P4_XL_REG ((uint8_t)0x16)
#define FT5336_P4_YH_REG ((uint8_t)0x17)
#define FT5336_P4_YL_REG ((uint8_t)0x18)
#define FT5336_P4_WEIGHT_REG ((uint8_t)0x19)
#define FT5336_P4_MISC_REG ((uint8_t)0x1A)
#define FT5336_P5_XH_REG ((uint8_t)0x1B)
#define FT5336_P5_XL_REG ((uint8_t)0x1C)
#define FT5336_P5_YH_REG ((uint8_t)0x1D)
#define FT5336_P5_YL_REG ((uint8_t)0x1E)
#define FT5336_P5_WEIGHT_REG ((uint8_t)0x1F)
#define FT5336_P5_MISC_REG ((uint8_t)0x20)
#define FT5336_P6_XH_REG ((uint8_t)0x21)
#define FT5336_P6_XL_REG ((uint8_t)0x22)
#define FT5336_P6_YH_REG ((uint8_t)0x23)
#define FT5336_P6_YL_REG ((uint8_t)0x24)
#define FT5336_P6_WEIGHT_REG ((uint8_t)0x25)
#define FT5336_P6_MISC_REG ((uint8_t)0x26)
#define FT5336_P7_XH_REG ((uint8_t)0x27)
#define FT5336_P7_XL_REG ((uint8_t)0x28)
#define FT5336_P7_YH_REG ((uint8_t)0x29)
#define FT5336_P7_YL_REG ((uint8_t)0x2A)
#define FT5336_P7_WEIGHT_REG ((uint8_t)0x2B)
#define FT5336_P7_MISC_REG ((uint8_t)0x2C)
#define FT5336_P8_XH_REG ((uint8_t)0x2D)
#define FT5336_P8_XL_REG ((uint8_t)0x2E)
#define FT5336_P8_YH_REG ((uint8_t)0x2F)
#define FT5336_P8_YL_REG ((uint8_t)0x30)
#define FT5336_P8_WEIGHT_REG ((uint8_t)0x31)
#define FT5336_P8_MISC_REG ((uint8_t)0x32)
#define FT5336_P9_XH_REG ((uint8_t)0x33)
#define FT5336_P9_XL_REG ((uint8_t)0x34)
#define FT5336_P9_YH_REG ((uint8_t)0x35)
#define FT5336_P9_YL_REG ((uint8_t)0x36)
#define FT5336_P9_WEIGHT_REG ((uint8_t)0x37)
#define FT5336_P9_MISC_REG ((uint8_t)0x38)
#define FT5336_P10_XH_REG ((uint8_t)0x39)
#define FT5336_P10_XL_REG ((uint8_t)0x3A)
#define FT5336_P10_YH_REG ((uint8_t)0x3B)
#define FT5336_P10_YL_REG ((uint8_t)0x3C)
#define FT5336_P10_WEIGHT_REG ((uint8_t)0x3D)
#define FT5336_P10_MISC_REG ((uint8_t)0x3E)
/* Threshold for touch detection */
#define FT5336_TH_GROUP_REG ((uint8_t)0x80)
/* Values FT5336_TH_GROUP_REG : threshold related */
#define FT5336_THRESHOLD_MASK ((uint8_t)0xFF)
#define FT5336_THRESHOLD_SHIFT ((uint8_t)0x00)
/* Filter function coefficients */
#define FT5336_TH_DIFF_REG ((uint8_t)0x85)
/* Control register */
#define FT5336_CTRL_REG ((uint8_t)0x86)
/* Values related to FT5336_CTRL_REG */
/* Will keep the Active mode when there is no touching */
#define FT5336_CTRL_KEEP_ACTIVE_MODE ((uint8_t)0x00)
/* Switching from Active mode to Monitor mode automatically when there is no touching */
#define FT5336_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE ((uint8_t)0x01
/* The time period of switching from Active mode to Monitor mode when there is no touching */
#define FT5336_TIMEENTERMONITOR_REG ((uint8_t)0x87)
/* Report rate in Active mode */
#define FT5336_PERIODACTIVE_REG ((uint8_t)0x88)
/* Report rate in Monitor mode */
#define FT5336_PERIODMONITOR_REG ((uint8_t)0x89)
/* The value of the minimum allowed angle while Rotating gesture mode */
#define FT5336_RADIAN_VALUE_REG ((uint8_t)0x91)
/* Maximum offset while Moving Left and Moving Right gesture */
#define FT5336_OFFSET_LEFT_RIGHT_REG ((uint8_t)0x92)
/* Maximum offset while Moving Up and Moving Down gesture */
#define FT5336_OFFSET_UP_DOWN_REG ((uint8_t)0x93)
/* Minimum distance while Moving Left and Moving Right gesture */
#define FT5336_DISTANCE_LEFT_RIGHT_REG ((uint8_t)0x94)
/* Minimum distance while Moving Up and Moving Down gesture */
#define FT5336_DISTANCE_UP_DOWN_REG ((uint8_t)0x95)
/* Maximum distance while Zoom In and Zoom Out gesture */
#define FT5336_DISTANCE_ZOOM_REG ((uint8_t)0x96)
/* High 8-bit of LIB Version info */
#define FT5336_LIB_VER_H_REG ((uint8_t)0xA1)
/* Low 8-bit of LIB Version info */
#define FT5336_LIB_VER_L_REG ((uint8_t)0xA2)
/* Chip Selecting */
#define FT5336_CIPHER_REG ((uint8_t)0xA3)
/* Interrupt mode register (used when in interrupt mode) */
#define FT5336_GMODE_REG ((uint8_t)0xA4)
#define FT5336_G_MODE_INTERRUPT_MASK ((uint8_t)0x03)
#define FT5336_G_MODE_INTERRUPT_SHIFT ((uint8_t)0x00)
/* Possible values of FT5336_GMODE_REG */
#define FT5336_G_MODE_INTERRUPT_POLLING ((uint8_t)0x00)
#define FT5336_G_MODE_INTERRUPT_TRIGGER ((uint8_t)0x01)
/* Current power mode the FT5336 system is in (R) */
#define FT5336_PWR_MODE_REG ((uint8_t)0xA5)
/* FT5336 firmware version */
#define FT5336_FIRMID_REG ((uint8_t)0xA6)
/* FT5336 Chip identification register */
#define FT5336_CHIP_ID_REG ((uint8_t)0xA8)
/* Possible values of FT5336_CHIP_ID_REG */
#define FT5336_ID_VALUE ((uint8_t)0x51)
/* Release code version */
#define FT5336_RELEASE_CODE_ID_REG ((uint8_t)0xAF)
/* Current operating mode the FT5336 system is in (R) */
#define FT5336_STATE_REG ((uint8_t)0xBC)
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup ft5336_Exported_Macros
* @{
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup ft5336_Exported_Functions
* @{
*/
/**
* @brief ft5336 Control functions
*/
/**
* @brief Initialize the ft5336 communication bus
* from MCU to FT5336 : ie I2C channel initialization (if required).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval None
*/
void ft5336_Init(uint16_t DeviceAddr);
/**
* @brief Software Reset the ft5336.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval None
*/
void ft5336_Reset(uint16_t DeviceAddr);
/**
* @brief Read the ft5336 device ID, pre initialize I2C in case of need to be
* able to read the FT5336 device ID, and verify this is a FT5336.
* @param DeviceAddr: I2C FT5336 Slave address.
* @retval The Device ID (two bytes).
*/
uint16_t ft5336_ReadID(uint16_t DeviceAddr);
/**
* @brief Configures the touch Screen IC device to start detecting touches
* @param DeviceAddr: Device address on communication Bus (I2C slave address).
* @retval None.
*/
void ft5336_TS_Start(uint16_t DeviceAddr);
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal global
* variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
uint8_t ft5336_TS_DetectTouch(uint16_t DeviceAddr);
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'ft5336_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void ft5336_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
/**
* @brief Configure the FT5336 device to generate IT on given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
* @retval None
*/
void ft5336_TS_EnableIT(uint16_t DeviceAddr);
/**
* @brief Configure the FT5336 device to stop generating IT on the given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
* @retval None
*/
void ft5336_TS_DisableIT(uint16_t DeviceAddr);
/**
* @brief Get IT status from FT5336 interrupt status registers
* Should be called Following an EXTI coming to the MCU to know the detailed
* reason of the interrupt.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval TS interrupts status
*/
uint8_t ft5336_TS_ITStatus (uint16_t DeviceAddr);
/**
* @brief Clear IT status in FT5336 interrupt status clear registers
* Should be called Following an EXTI coming to the MCU.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @retval TS interrupts status
*/
void ft5336_TS_ClearIT (uint16_t DeviceAddr);
/**** NEW FEATURES enabled when Multi-touch support is enabled ****/
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/**
* @brief Get the last touch gesture identification (zoom, move up/down...).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @param pGestureId : Pointer to get last touch gesture Identification.
* @retval None.
*/
void ft5336_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId);
/**
* @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
* This touch detailed information contains :
* - weight that was applied to this touch
* - sub-area of the touch in the touch panel
* - event of linked to the touch (press down, lift up, ...)
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
* @param touchIdx : Passed index of the touch (0..1) on which we want to get the
* detailed information.
* @param pWeight : Pointer to to get the weight information of 'touchIdx'.
* @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
* @param pEvent : Pointer to to get the event information of 'touchIdx'.
* @retval None.
*/
void ft5336_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent);
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
/* Imported TS IO functions --------------------------------------------------------*/
/** @defgroup ft5336_Imported_Functions
* @{
*/
/* TouchScreen (TS) external IO functions */
extern void TS_IO_Init(void);
extern void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
extern void TS_IO_Delay(uint32_t Delay);
/**
* @}
*/
/* Imported global variables --------------------------------------------------------*/
/** @defgroup ft5336_Imported_Globals
* @{
*/
/* Touch screen driver structure */
extern TS_DrvTypeDef ft5336_ts_drv;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __FT5336_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,514 @@
/**
******************************************************************************
* @file ft6x06.c
* @author MCD Application Team
* @version V1.0.1
* @date 03-May-2016
* @brief This file provides a set of functions needed to manage the FT6X06
* IO Expander devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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 "ft6x06.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup FT6X06
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup FT6X06_Private_Defines FT6X06 Private Defines
* @{
*/
#define FT6x06_MAX_INSTANCE 2
/**
* @}
*/
/* Private macro -------------------------------------------------------------*/
/** @defgroup FT6X06_Private_Variables FT6X06 Private Variables
* @{
*/
/* Touch screen driver structure initialization */
TS_DrvTypeDef ft6x06_ts_drv =
{
ft6x06_Init,
ft6x06_ReadID,
ft6x06_Reset,
ft6x06_TS_Start,
ft6x06_TS_DetectTouch,
ft6x06_TS_GetXY,
ft6x06_TS_EnableIT,
ft6x06_TS_ClearIT,
ft6x06_TS_ITStatus,
ft6x06_TS_DisableIT
};
/* ft6x06 instances by address */
uint8_t ft6x06[FT6x06_MAX_INSTANCE] = {0};
/* Global ft6x06 handle */
static ft6x06_handle_TypeDef ft6x06_handle = { FT6206_I2C_NOT_INITIALIZED, 0, 0};
/**
* @}
*/
/** @defgroup ft6x06_Private_Function_Prototypes ft6x06 Private Function Prototypes
* @{
*/
static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr);
/* Private functions prototypes-----------------------------------------------*/
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
/**
* @brief Start TouchScreen calibration phase
* @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
* @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
*/
static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr);
#endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */
/**
* @brief Basic static configuration of TouchScreen
* @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
* @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
*/
static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup ft6x06_Private_Functions ft6x06 Private Functions
* @{
*/
/**
* @brief Initialize the ft6x06 communication bus
* from MCU to FT6206 : ie I2C channel initialization (if required).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval None
*/
void ft6x06_Init(uint16_t DeviceAddr)
{
uint8_t instance;
uint8_t empty;
/* Check if device instance already exists */
instance = ft6x06_GetInstance(DeviceAddr);
/* To prevent double initialization */
if(instance == 0xFF)
{
/* Look for empty instance */
empty = ft6x06_GetInstance(0);
if(empty < FT6x06_MAX_INSTANCE)
{
/* Register the current device instance */
ft6x06[empty] = DeviceAddr;
/* Initialize IO BUS layer */
TS_IO_Init();
}
}
}
/**
* @brief Software Reset the ft6x06.
* @note : Not applicable to FT6206.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval None
*/
void ft6x06_Reset(uint16_t DeviceAddr)
{
/* Do nothing */
/* No software reset sequence available in FT6206 IC */
}
/**
* @brief Read the ft6x06 device ID, pre initialize I2C in case of need to be
* able to read the FT6206 device ID, and verify this is a FT6206.
* @param DeviceAddr: I2C FT6x06 Slave address.
* @retval The Device ID (two bytes).
*/
uint16_t ft6x06_ReadID(uint16_t DeviceAddr)
{
/* Initialize I2C link if needed */
TS_IO_Init();
/* Return the device ID value */
return (TS_IO_Read(DeviceAddr, FT6206_CHIP_ID_REG));
}
/**
* @brief Configures the touch Screen IC device to start detecting touches
* It goes through an internal calibration process (Hw calibration sequence of
* the touch screen).
* @param DeviceAddr: Device address on communication Bus (I2C slave address).
* @retval None.
*/
void ft6x06_TS_Start(uint16_t DeviceAddr)
{
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
/* Hw Calibration sequence start : should be done once after each power up */
/* This is called internal calibration of the touch screen */
ft6x06_TS_Calibration(DeviceAddr);
#endif
/* Minimum static configuration of FT6206 */
ft6x06_TS_Configure(DeviceAddr);
/* By default set FT6206 IC in Polling mode : no INT generation on FT6206 for new touch available */
/* Note TS_INT is active low */
ft6x06_TS_DisableIT(DeviceAddr);
}
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal global
* variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr)
{
volatile uint8_t nbTouch = 0;
/* Read register FT6206_TD_STAT_REG to check number of touches detection */
nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG);
nbTouch &= FT6206_TD_STAT_MASK;
if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH)
{
/* If invalid number of touch detected, set it to zero */
nbTouch = 0;
}
/* Update ft6x06 driver internal global : current number of active touches */
ft6x06_handle.currActiveTouchNb = nbTouch;
/* Reset current active touch index on which to work on */
ft6x06_handle.currActiveTouchIdx = 0;
return(nbTouch);
}
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'ft6x06_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
uint8_t regAddress = 0;
uint8_t dataxy[4];
if(ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb)
{
switch(ft6x06_handle.currActiveTouchIdx)
{
case 0 :
regAddress = FT6206_P1_XH_REG;
break;
case 1 :
regAddress = FT6206_P2_XH_REG;
break;
default :
break;
}
/* Read X and Y positions */
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
/* Send back ready X position to caller */
*X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
/* Send back ready Y position to caller */
*Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
ft6x06_handle.currActiveTouchIdx++;
}
}
/**
* @brief Configure the FT6206 device to generate IT on given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
* @retval None
*/
void ft6x06_TS_EnableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT6206_G_MODE_INTERRUPT_TRIGGER & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
/* Set interrupt trigger mode in FT6206_GMODE_REG */
TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
}
/**
* @brief Configure the FT6206 device to stop generating IT on the given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
* @retval None
*/
void ft6x06_TS_DisableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT6206_G_MODE_INTERRUPT_POLLING & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
/* Set interrupt polling mode in FT6206_GMODE_REG */
TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
}
/**
* @brief Get IT status from FT6206 interrupt status registers
* Should be called Following an EXTI coming to the MCU to know the detailed
* reason of the interrupt.
* @note : This feature is not applicable to FT6206.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval TS interrupts status : always return 0 here
*/
uint8_t ft6x06_TS_ITStatus(uint16_t DeviceAddr)
{
/* Always return 0 as feature not applicable to FT6206 */
return 0;
}
/**
* @brief Clear IT status in FT6206 interrupt status clear registers
* Should be called Following an EXTI coming to the MCU.
* @note : This feature is not applicable to FT6206.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval None
*/
void ft6x06_TS_ClearIT(uint16_t DeviceAddr)
{
/* Nothing to be done here for FT6206 */
}
/**** NEW FEATURES enabled when Multi-touch support is enabled ****/
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/**
* @brief Get the last touch gesture identification (zoom, move up/down...).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
* @param pGestureId : Pointer to get last touch gesture Identification.
* @retval None.
*/
void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
{
volatile uint8_t ucReadData = 0;
ucReadData = TS_IO_Read(DeviceAddr, FT6206_GEST_ID_REG);
* pGestureId = ucReadData;
}
/**
* @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
* This touch detailed information contains :
* - weight that was applied to this touch
* - sub-area of the touch in the touch panel
* - event of linked to the touch (press down, lift up, ...)
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
* @param touchIdx : Passed index of the touch (0..1) on which we want to get the
* detailed information.
* @param pWeight : Pointer to to get the weight information of 'touchIdx'.
* @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
* @param pEvent : Pointer to to get the event information of 'touchIdx'.
* @retval None.
*/
void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent)
{
uint8_t regAddress = 0;
uint8_t dataxy[3];
if(touchIdx < ft6x06_handle.currActiveTouchNb)
{
switch(touchIdx)
{
case 0 :
regAddress = FT6206_P1_WEIGHT_REG;
break;
case 1 :
regAddress = FT6206_P2_WEIGHT_REG;
break;
default :
break;
} /* end switch(touchIdx) */
/* Read weight, area and Event Id of touch index */
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
/* Return weight of touch index */
* pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
/* Return area of touch index */
* pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
/* Return Event Id of touch index */
* pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
} /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */
}
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
/**
* @brief Start TouchScreen calibration phase
* @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
* @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
*/
static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr)
{
uint32_t nbAttempt = 0;
volatile uint8_t ucReadData;
volatile uint8_t regValue;
uint32_t status = FT6206_STATUS_OK;
uint8_t bEndCalibration = 0;
/* >> Calibration sequence start */
/* Switch FT6206 back to factory mode to calibrate */
regValue = (FT6206_DEV_MODE_FACTORY & FT6206_DEV_MODE_MASK) << FT6206_DEV_MODE_SHIFT;
TS_IO_Write(DeviceAddr, FT6206_DEV_MODE_REG, regValue); /* 0x40 */
/* Read back the same register FT6206_DEV_MODE_REG */
ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
TS_IO_Delay(300); /* Wait 300 ms */
if(((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY )
{
/* Return error to caller */
return(FT6206_STATUS_NOT_OK);
}
/* Start calibration command */
TS_IO_Write(DeviceAddr, FT6206_TD_STAT_REG, 0x04);
TS_IO_Delay(300); /* Wait 300 ms */
/* 100 attempts to wait switch from factory mode (calibration) to working mode */
for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++)
{
ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
ucReadData = (ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT;
if(ucReadData == FT6206_DEV_MODE_WORKING)
{
/* Auto Switch to FT6206_DEV_MODE_WORKING : means calibration have ended */
bEndCalibration = 1; /* exit for loop */
}
TS_IO_Delay(200); /* Wait 200 ms */
}
/* Calibration sequence end << */
return(status);
}
#endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */
/**
* @brief Basic static configuration of TouchScreen
* @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
* @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
*/
static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr)
{
uint32_t status = FT6206_STATUS_OK;
/* Nothing special to be done for FT6206 */
return(status);
}
/**
* @brief Check if the device instance of the selected address is already registered
* and return its index
* @param DeviceAddr: Device address on communication Bus.
* @retval Index of the device instance if registered, 0xFF if not.
*/
static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr)
{
uint8_t idx = 0;
/* Check all the registered instances */
for(idx = 0; idx < FT6x06_MAX_INSTANCE ; idx ++)
{
if(ft6x06[idx] == DeviceAddr)
{
return idx;
}
}
return 0xFF;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,471 @@
/**
******************************************************************************
* @file ft6x06.h
* @author MCD Application Team
* @version V1.0.1
* @date 03-May-2016
* @brief This file contains all the functions prototypes for the
* ft6x06.c IO expander driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FT6X06_H
#define __FT6X06_H
#ifdef __cplusplus
extern "C" {
#endif
/* Set Multi-touch as non supported */
#ifndef TS_MULTI_TOUCH_SUPPORTED
#define TS_MULTI_TOUCH_SUPPORTED 0
#endif
/* Set Auto-calibration as non supported */
#ifndef TS_AUTO_CALIBRATION_SUPPORTED
#define TS_AUTO_CALIBRATION_SUPPORTED 0
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/ts.h"
/* Macros --------------------------------------------------------------------*/
/** @typedef ft6x06_handle_TypeDef
* ft6x06 Handle definition.
*/
typedef struct
{
uint8_t i2cInitialized;
/* field holding the current number of simultaneous active touches */
uint8_t currActiveTouchNb;
/* field holding the touch index currently managed */
uint8_t currActiveTouchIdx;
} ft6x06_handle_TypeDef;
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup FT6X06
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup FT6X06_Exported_Types
* @{
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup FT6X06_Exported_Constants
* @{
*/
/* Maximum border values of the touchscreen pad */
#define FT_6206_MAX_WIDTH ((uint16_t)800) /* Touchscreen pad max width */
#define FT_6206_MAX_HEIGHT ((uint16_t)480) /* Touchscreen pad max height */
/* Touchscreen pad max width and height values for FT6x36 Touch*/
#define FT_6206_MAX_WIDTH_HEIGHT ((uint16_t)240)
/* Possible values of driver functions return status */
#define FT6206_STATUS_OK 0
#define FT6206_STATUS_NOT_OK 1
/* Possible values of global variable 'TS_I2C_Initialized' */
#define FT6206_I2C_NOT_INITIALIZED 0
#define FT6206_I2C_INITIALIZED 1
/* Max detectable simultaneous touches */
#define FT6206_MAX_DETECTABLE_TOUCH 2
/**
* @brief : Definitions for FT6206 I2C register addresses on 8 bit
**/
/* Current mode register of the FT6206 (R/W) */
#define FT6206_DEV_MODE_REG 0x00
/* Possible values of FT6206_DEV_MODE_REG */
#define FT6206_DEV_MODE_WORKING 0x00
#define FT6206_DEV_MODE_FACTORY 0x04
#define FT6206_DEV_MODE_MASK 0x7
#define FT6206_DEV_MODE_SHIFT 4
/* Gesture ID register */
#define FT6206_GEST_ID_REG 0x01
/* Possible values of FT6206_GEST_ID_REG */
#define FT6206_GEST_ID_NO_GESTURE 0x00
#define FT6206_GEST_ID_MOVE_UP 0x10
#define FT6206_GEST_ID_MOVE_RIGHT 0x14
#define FT6206_GEST_ID_MOVE_DOWN 0x18
#define FT6206_GEST_ID_MOVE_LEFT 0x1C
#define FT6206_GEST_ID_ZOOM_IN 0x48
#define FT6206_GEST_ID_ZOOM_OUT 0x49
/* Touch Data Status register : gives number of active touch points (0..2) */
#define FT6206_TD_STAT_REG 0x02
/* Values related to FT6206_TD_STAT_REG */
#define FT6206_TD_STAT_MASK 0x0F
#define FT6206_TD_STAT_SHIFT 0x00
/* Values Pn_XH and Pn_YH related */
#define FT6206_TOUCH_EVT_FLAG_PRESS_DOWN 0x00
#define FT6206_TOUCH_EVT_FLAG_LIFT_UP 0x01
#define FT6206_TOUCH_EVT_FLAG_CONTACT 0x02
#define FT6206_TOUCH_EVT_FLAG_NO_EVENT 0x03
#define FT6206_TOUCH_EVT_FLAG_SHIFT 6
#define FT6206_TOUCH_EVT_FLAG_MASK (3 << FT6206_TOUCH_EVT_FLAG_SHIFT)
#define FT6206_MSB_MASK 0x0F
#define FT6206_MSB_SHIFT 0
/* Values Pn_XL and Pn_YL related */
#define FT6206_LSB_MASK 0xFF
#define FT6206_LSB_SHIFT 0
#define FT6206_P1_XH_REG 0x03
#define FT6206_P1_XL_REG 0x04
#define FT6206_P1_YH_REG 0x05
#define FT6206_P1_YL_REG 0x06
/* Touch Pressure register value (R) */
#define FT6206_P1_WEIGHT_REG 0x07
/* Values Pn_WEIGHT related */
#define FT6206_TOUCH_WEIGHT_MASK 0xFF
#define FT6206_TOUCH_WEIGHT_SHIFT 0
/* Touch area register */
#define FT6206_P1_MISC_REG 0x08
/* Values related to FT6206_Pn_MISC_REG */
#define FT6206_TOUCH_AREA_MASK (0x04 << 4)
#define FT6206_TOUCH_AREA_SHIFT 0x04
#define FT6206_P2_XH_REG 0x09
#define FT6206_P2_XL_REG 0x0A
#define FT6206_P2_YH_REG 0x0B
#define FT6206_P2_YL_REG 0x0C
#define FT6206_P2_WEIGHT_REG 0x0D
#define FT6206_P2_MISC_REG 0x0E
/* Threshold for touch detection */
#define FT6206_TH_GROUP_REG 0x80
/* Values FT6206_TH_GROUP_REG : threshold related */
#define FT6206_THRESHOLD_MASK 0xFF
#define FT6206_THRESHOLD_SHIFT 0
/* Filter function coefficients */
#define FT6206_TH_DIFF_REG 0x85
/* Control register */
#define FT6206_CTRL_REG 0x86
/* Values related to FT6206_CTRL_REG */
/* Will keep the Active mode when there is no touching */
#define FT6206_CTRL_KEEP_ACTIVE_MODE 0x00
/* Switching from Active mode to Monitor mode automatically when there is no touching */
#define FT6206_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE 0x01
/* The time period of switching from Active mode to Monitor mode when there is no touching */
#define FT6206_TIMEENTERMONITOR_REG 0x87
/* Report rate in Active mode */
#define FT6206_PERIODACTIVE_REG 0x88
/* Report rate in Monitor mode */
#define FT6206_PERIODMONITOR_REG 0x89
/* The value of the minimum allowed angle while Rotating gesture mode */
#define FT6206_RADIAN_VALUE_REG 0x91
/* Maximum offset while Moving Left and Moving Right gesture */
#define FT6206_OFFSET_LEFT_RIGHT_REG 0x92
/* Maximum offset while Moving Up and Moving Down gesture */
#define FT6206_OFFSET_UP_DOWN_REG 0x93
/* Minimum distance while Moving Left and Moving Right gesture */
#define FT6206_DISTANCE_LEFT_RIGHT_REG 0x94
/* Minimum distance while Moving Up and Moving Down gesture */
#define FT6206_DISTANCE_UP_DOWN_REG 0x95
/* Maximum distance while Zoom In and Zoom Out gesture */
#define FT6206_DISTANCE_ZOOM_REG 0x96
/* High 8-bit of LIB Version info */
#define FT6206_LIB_VER_H_REG 0xA1
/* Low 8-bit of LIB Version info */
#define FT6206_LIB_VER_L_REG 0xA2
/* Chip Selecting */
#define FT6206_CIPHER_REG 0xA3
/* Interrupt mode register (used when in interrupt mode) */
#define FT6206_GMODE_REG 0xA4
#define FT6206_G_MODE_INTERRUPT_MASK 0x03
#define FT6206_G_MODE_INTERRUPT_SHIFT 0x00
/* Possible values of FT6206_GMODE_REG */
#define FT6206_G_MODE_INTERRUPT_POLLING 0x00
#define FT6206_G_MODE_INTERRUPT_TRIGGER 0x01
/* Current power mode the FT6206 system is in (R) */
#define FT6206_PWR_MODE_REG 0xA5
/* FT6206 firmware version */
#define FT6206_FIRMID_REG 0xA6
/* FT6206 Chip identification register */
#define FT6206_CHIP_ID_REG 0xA8
/* Possible values of FT6206_CHIP_ID_REG */
#define FT6206_ID_VALUE 0x11
#define FT6x36_ID_VALUE 0xCD
/* Release code version */
#define FT6206_RELEASE_CODE_ID_REG 0xAF
/* Current operating mode the FT6206 system is in (R) */
#define FT6206_STATE_REG 0xBC
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup ft6x06_Exported_Macros
* @{
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup ft6x06_Exported_Functions
* @{
*/
/**
* @brief ft6x06 Control functions
*/
/**
* @brief Initialize the ft6x06 communication bus
* from MCU to FT6206 : ie I2C channel initialization (if required).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval None
*/
void ft6x06_Init(uint16_t DeviceAddr);
/**
* @brief Software Reset the ft6x06.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval None
*/
void ft6x06_Reset(uint16_t DeviceAddr);
/**
* @brief Read the ft6x06 device ID, pre intitalize I2C in case of need to be
* able to read the FT6206 device ID, and verify this is a FT6206.
* @param DeviceAddr: I2C FT6x06 Slave address.
* @retval The Device ID (two bytes).
*/
uint16_t ft6x06_ReadID(uint16_t DeviceAddr);
/**
* @brief Configures the touch Screen IC device to start detecting touches
* @param DeviceAddr: Device address on communication Bus (I2C slave address).
* @retval None.
*/
void ft6x06_TS_Start(uint16_t DeviceAddr);
/**
* @brief Return if there is touches detected or not.
* Try to detect new touches and forget the old ones (reset internal global
* variables).
* @param DeviceAddr: Device address on communication Bus.
* @retval : Number of active touches detected (can be 0, 1 or 2).
*/
uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr);
/**
* @brief Get the touch screen X and Y positions values
* Manage multi touch thanks to touch Index global
* variable 'ft6x06_handle.currActiveTouchIdx'.
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
/**
* @brief Configure the FT6206 device to generate IT on given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
* @retval None
*/
void ft6x06_TS_EnableIT(uint16_t DeviceAddr);
/**
* @brief Configure the FT6206 device to stop generating IT on the given INT pin
* connected to MCU as EXTI.
* @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
* @retval None
*/
void ft6x06_TS_DisableIT(uint16_t DeviceAddr);
/**
* @brief Get IT status from FT6206 interrupt status registers
* Should be called Following an EXTI coming to the MCU to know the detailed
* reason of the interrupt.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval TS interrupts status
*/
uint8_t ft6x06_TS_ITStatus (uint16_t DeviceAddr);
/**
* @brief Clear IT status in FT6206 interrupt status clear registers
* Should be called Following an EXTI coming to the MCU.
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
* @retval TS interrupts status
*/
void ft6x06_TS_ClearIT (uint16_t DeviceAddr);
/**** NEW FEATURES enabled when Multi-touch support is enabled ****/
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/**
* @brief Get the last touch gesture identification (zoom, move up/down...).
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
* @param pGestureId : Pointer to get last touch gesture Identification.
* @retval None.
*/
void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId);
/**
* @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
* This touch detailed information contains :
* - weight that was applied to this touch
* - sub-area of the touch in the touch panel
* - event of linked to the touch (press down, lift up, ...)
* @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
* @param touchIdx : Passed index of the touch (0..1) on which we want to get the
* detailed information.
* @param pWeight : Pointer to to get the weight information of 'touchIdx'.
* @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
* @param pEvent : Pointer to to get the event information of 'touchIdx'.
* @retval None.
*/
void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent);
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
/* Imported TS IO functions --------------------------------------------------------*/
/** @defgroup ft6x06_Imported_Functions
* @{
*/
/* TouchScreen (TS) external IO functions */
extern void TS_IO_Init(void);
extern void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void TS_IO_Delay(uint32_t Delay);
/**
* @}
*/
/* Imported global variables --------------------------------------------------------*/
/** @defgroup ft6x06_Imported_Globals
* @{
*/
/* Touch screen driver structure */
extern TS_DrvTypeDef ft6x06_ts_drv;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __FT6X06_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,247 @@
/**
******************************************************************************
* @file hts221.c
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief This file provides a set of functions needed to manage the HTS221
* humidity and temperature devices
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "hts221.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup HTS221 HTS221
* @{
*/
/** @defgroup HTS221_Private_Variables HTS221 Private Variables
* @{
*/
/* HTS221 Humidity Private Variables */
HSENSOR_DrvTypeDef HTS221_H_Drv =
{
HTS221_H_Init,
HTS221_H_ReadID,
HTS221_H_ReadHumidity
};
/* HTS221_Temperature_Private_Variables */
TSENSOR_DrvTypeDef HTS221_T_Drv =
{
HTS221_T_Init,
0,
0,
HTS221_T_ReadTemp
};
/**
* @}
*/
/** @defgroup HTS221_Humidity_Private_Functions HTS221 Humidity Private Functions
* @{
*/
/**
* @brief Set HTS221 humidity sensor Initialization.
*/
void HTS221_H_Init(uint16_t DeviceAddr)
{
uint8_t tmp;
/* Read CTRL_REG1 */
tmp = SENSOR_IO_Read(DeviceAddr, HTS221_CTRL_REG1);
/* Enable BDU */
tmp &= ~HTS221_BDU_MASK;
tmp |= (1 << HTS221_BDU_BIT);
/* Set default ODR */
tmp &= ~HTS221_ODR_MASK;
tmp |= (uint8_t)0x01; /* Set ODR to 1Hz */
/* Activate the device */
tmp |= HTS221_PD_MASK;
/* Apply settings to CTRL_REG1 */
SENSOR_IO_Write(DeviceAddr, HTS221_CTRL_REG1, tmp);
}
/**
* @brief Read HTS221 ID.
* @retval ID
*/
uint8_t HTS221_H_ReadID(uint16_t DeviceAddr)
{
uint8_t ctrl = 0x00;
/* IO interface initialization */
SENSOR_IO_Init();
/* Read value at Who am I register address */
ctrl = SENSOR_IO_Read(DeviceAddr, HTS221_WHO_AM_I_REG);
return ctrl;
}
/**
* @brief Read humidity value of HTS221
* @retval humidity value;
*/
float HTS221_H_ReadHumidity(uint16_t DeviceAddr)
{
int16_t H0_T0_out, H1_T0_out, H_T_out;
int16_t H0_rh, H1_rh;
uint8_t buffer[2];
float tmp_f;
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_H0_RH_X2 | 0x80), buffer, 2);
H0_rh = buffer[0] >> 1;
H1_rh = buffer[1] >> 1;
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_H0_T0_OUT_L | 0x80), buffer, 2);
H0_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_H1_T0_OUT_L | 0x80), buffer, 2);
H1_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_HR_OUT_L_REG | 0x80), buffer, 2);
H_T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
tmp_f = (float)(H_T_out - H0_T0_out) * (float)(H1_rh - H0_rh) / (float)(H1_T0_out - H0_T0_out) + H0_rh;
tmp_f *= 10.0f;
tmp_f = ( tmp_f > 1000.0f ) ? 1000.0f
: ( tmp_f < 0.0f ) ? 0.0f
: tmp_f;
return (tmp_f / 10.0f);
}
/**
* @}
*/
/** @defgroup HTS221_Temperature_Private_Functions HTS221 Temperature Private Functions
* @{
*/
/**
* @brief Set HTS221 temperature sensor Initialization.
* @param DeviceAddr: I2C device address
* @param InitStruct: pointer to a TSENSOR_InitTypeDef structure
* that contains the configuration setting for the HTS221.
*/
void HTS221_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct)
{
uint8_t tmp;
/* Read CTRL_REG1 */
tmp = SENSOR_IO_Read(DeviceAddr, HTS221_CTRL_REG1);
/* Enable BDU */
tmp &= ~HTS221_BDU_MASK;
tmp |= (1 << HTS221_BDU_BIT);
/* Set default ODR */
tmp &= ~HTS221_ODR_MASK;
tmp |= (uint8_t)0x01; /* Set ODR to 1Hz */
/* Activate the device */
tmp |= HTS221_PD_MASK;
/* Apply settings to CTRL_REG1 */
SENSOR_IO_Write(DeviceAddr, HTS221_CTRL_REG1, tmp);
}
/**
* @brief Read temperature value of HTS221
* @param DeviceAddr: I2C device address
* @retval temperature value
*/
float HTS221_T_ReadTemp(uint16_t DeviceAddr)
{
int16_t T0_out, T1_out, T_out, T0_degC_x8_u16, T1_degC_x8_u16;
int16_t T0_degC, T1_degC;
uint8_t buffer[4], tmp;
float tmp_f;
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_T0_DEGC_X8 | 0x80), buffer, 2);
tmp = SENSOR_IO_Read(DeviceAddr, HTS221_T0_T1_DEGC_H2);
T0_degC_x8_u16 = (((uint16_t)(tmp & 0x03)) << 8) | ((uint16_t)buffer[0]);
T1_degC_x8_u16 = (((uint16_t)(tmp & 0x0C)) << 6) | ((uint16_t)buffer[1]);
T0_degC = T0_degC_x8_u16 >> 3;
T1_degC = T1_degC_x8_u16 >> 3;
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_T0_OUT_L | 0x80), buffer, 4);
T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
T1_out = (((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2];
SENSOR_IO_ReadMultiple(DeviceAddr, (HTS221_TEMP_OUT_L_REG | 0x80), buffer, 2);
T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
tmp_f = (float)(T_out - T0_out) * (float)(T1_degC - T0_degC) / (float)(T1_out - T0_out) + T0_degC;
return tmp_f;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,338 @@
/**
******************************************************************************
* @file hts221.h
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief HTS221 header driver file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HTS221__H
#define __HTS221__H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/hsensor.h"
#include "../Common/tsensor.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup HTS221
* @{
*/
/** @defgroup HTS221_Exported_Constants HTS221 Exported Constants
* @{
*/
/**
* @brief Bitfield positioning.
*/
#define HTS221_BIT(x) ((uint8_t)x)
/**
* @brief Device Identification register.
* Read
* Default value: 0xBC
* 7:0 This read-only register contains the device identifier for HTS221.
*/
#define HTS221_WHO_AM_I_REG (uint8_t)0x0F
/**
* @brief Device Identification value.
*/
#define HTS221_WHO_AM_I_VAL (uint8_t)0xBC
/**
* @brief Humidity and temperature average mode register.
* Read/write
* Default value: 0x1B
* 7:6 Reserved.
* 5:3 AVGT2-AVGT1-AVGT0: Select the temperature internal average.
*
* AVGT2 | AVGT1 | AVGT0 | Nr. Internal Average
* ----------------------------------------------------
* 0 | 0 | 0 | 2
* 0 | 0 | 1 | 4
* 0 | 1 | 0 | 8
* 0 | 1 | 1 | 16
* 1 | 0 | 0 | 32
* 1 | 0 | 1 | 64
* 1 | 1 | 0 | 128
* 1 | 1 | 1 | 256
*
* 2:0 AVGH2-AVGH1-AVGH0: Select humidity internal average.
* AVGH2 | AVGH1 | AVGH0 | Nr. Internal Average
* ------------------------------------------------------
* 0 | 0 | 0 | 4
* 0 | 0 | 1 | 8
* 0 | 1 | 0 | 16
* 0 | 1 | 1 | 32
* 1 | 0 | 0 | 64
* 1 | 0 | 1 | 128
* 1 | 1 | 0 | 256
* 1 | 1 | 1 | 512
*
*/
#define HTS221_AV_CONF_REG (uint8_t)0x10
#define HTS221_AVGT_BIT HTS221_BIT(3)
#define HTS221_AVGH_BIT HTS221_BIT(0)
#define HTS221_AVGH_MASK (uint8_t)0x07
#define HTS221_AVGT_MASK (uint8_t)0x38
/**
* @brief Control register 1.
* Read/write
* Default value: 0x00
* 7 PD: power down control. 0 - power down mode; 1 - active mode.
* 6:3 Reserved.
* 2 BDU: block data update. 0 - continuous update
* 1 - output registers not updated until MSB and LSB reading.
* 1:0 ODR1, ODR0: output data rate selection.
*
* ODR1 | ODR0 | Humidity output data-rate(Hz) | Pressure output data-rate(Hz)
* ----------------------------------------------------------------------------------
* 0 | 0 | one shot | one shot
* 0 | 1 | 1 | 1
* 1 | 0 | 7 | 7
* 1 | 1 | 12.5 | 12.5
*
*/
#define HTS221_CTRL_REG1 (uint8_t)0x20
#define HTS221_PD_BIT HTS221_BIT(7)
#define HTS221_BDU_BIT HTS221_BIT(2)
#define HTS221_ODR_BIT HTS221_BIT(0)
#define HTS221_PD_MASK (uint8_t)0x80
#define HTS221_BDU_MASK (uint8_t)0x04
#define HTS221_ODR_MASK (uint8_t)0x03
/**
* @brief Control register 2.
* Read/write
* Default value: 0x00
* 7 BOOT: Reboot memory content. 0: normal mode
* 1: reboot memory content. Self-cleared upon completation.
* 6:2 Reserved.
* 1 HEATHER: 0: heater enable; 1: heater disable.
* 0 ONE_SHOT: 0: waiting for start of conversion
* 1: start for a new dataset. Self-cleared upon completation.
*/
#define HTS221_CTRL_REG2 (uint8_t)0x21
#define HTS221_BOOT_BIT HTS221_BIT(7)
#define HTS221_HEATHER_BIT HTS221_BIT(1)
#define HTS221_ONESHOT_BIT HTS221_BIT(0)
#define HTS221_BOOT_MASK (uint8_t)0x80
#define HTS221_HEATHER_MASK (uint8_t)0x02
#define HTS221_ONE_SHOT_MASK (uint8_t)0x01
/**
* @brief Control register 3.
* Read/write
* Default value: 0x00
* 7 DRDY_H_L: Interrupt edge. 0: active high, 1: active low.
* 6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: push-pull
* 1: open drain.
* 5:3 Reserved.
* 2 DRDY: interrupt config. 0: disable, 1: enable.
*/
#define HTS221_CTRL_REG3 (uint8_t)0x22
#define HTS221_DRDY_H_L_BIT HTS221_BIT(7)
#define HTS221_PP_OD_BIT HTS221_BIT(6)
#define HTS221_DRDY_BIT HTS221_BIT(2)
#define HTS221_DRDY_H_L_MASK (uint8_t)0x80
#define HTS221_PP_OD_MASK (uint8_t)0x40
#define HTS221_DRDY_MASK (uint8_t)0x04
/**
* @brief Status register.
* Read
* Default value: 0x00
* 7:2 Reserved.
* 1 H_DA: Humidity data available. 0: new data for humidity is not yet available
* 1: new data for humidity is available.
* 0 T_DA: Temperature data available. 0: new data for temperature is not yet available
* 1: new data for temperature is available.
*/
#define HTS221_STATUS_REG (uint8_t)0x27
#define HTS221_H_DA_BIT HTS221_BIT(1)
#define HTS221_T_DA_BIT HTS221_BIT(0)
#define HTS221_HDA_MASK (uint8_t)0x02
#define HTS221_TDA_MASK (uint8_t)0x01
/**
* @brief Humidity data (LSB).
* Read
* Default value: 0x00.
* HOUT7 - HOUT0: Humidity data LSB (2's complement).
*/
#define HTS221_HR_OUT_L_REG (uint8_t)0x28
/**
* @brief Humidity data (MSB).
* Read
* Default value: 0x00.
* HOUT15 - HOUT8: Humidity data MSB (2's complement).
*/
#define HTS221_HR_OUT_H_REG (uint8_t)0x29
/**
* @brief Temperature data (LSB).
* Read
* Default value: 0x00.
* TOUT7 - TOUT0: temperature data LSB.
*/
#define HTS221_TEMP_OUT_L_REG (uint8_t)0x2A
/**
* @brief Temperature data (MSB).
* Read
* Default value: 0x00.
* TOUT15 - TOUT8: temperature data MSB.
*/
#define HTS221_TEMP_OUT_H_REG (uint8_t)0x2B
/**
* @brief Calibration registers.
* Read
*/
#define HTS221_H0_RH_X2 (uint8_t)0x30
#define HTS221_H1_RH_X2 (uint8_t)0x31
#define HTS221_T0_DEGC_X8 (uint8_t)0x32
#define HTS221_T1_DEGC_X8 (uint8_t)0x33
#define HTS221_T0_T1_DEGC_H2 (uint8_t)0x35
#define HTS221_H0_T0_OUT_L (uint8_t)0x36
#define HTS221_H0_T0_OUT_H (uint8_t)0x37
#define HTS221_H1_T0_OUT_L (uint8_t)0x3A
#define HTS221_H1_T0_OUT_H (uint8_t)0x3B
#define HTS221_T0_OUT_L (uint8_t)0x3C
#define HTS221_T0_OUT_H (uint8_t)0x3D
#define HTS221_T1_OUT_L (uint8_t)0x3E
#define HTS221_T1_OUT_H (uint8_t)0x3F
/**
* @}
*/
/** @defgroup HTS221_Humidity_Exported_Functions HTS221 Humidity Exported Functions
* @{
*/
/* HUMIDITY functions */
void HTS221_H_Init(uint16_t DeviceAddr);
uint8_t HTS221_H_ReadID(uint16_t DeviceAddr);
float HTS221_H_ReadHumidity(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup HTS221_HumImported_Globals Humidity Imported Globals
* @{
*/
/* Humidity driver structure */
extern HSENSOR_DrvTypeDef HTS221_H_Drv;
/**
* @}
*/
/** @defgroup HTS221_Temperature_Exported_Functions HTS221 Temperature Exported Functions
* @{
*/
/* TEMPERATURE functions */
void HTS221_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct);
float HTS221_T_ReadTemp(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup HTS221_TempImported_Globals Temperature Imported Globals
* @{
*/
/* Temperature driver structure */
extern TSENSOR_DrvTypeDef HTS221_T_Drv;
/**
* @}
*/
/** @defgroup HTS221_Imported_Functions HTS221 Imported Functions
* @{
*/
/* IO functions */
extern void SENSOR_IO_Init(void);
extern void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __HTS221__H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,489 @@
/**
******************************************************************************
* @file hx8347g.c
* @author MCD Application Team
* @brief This file includes the LCD driver for HX8347G LCD.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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 "hx8347g.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup HX8347G
* @brief This file provides a set of functions needed to drive the
* HX8347G LCD.
* @{
*/
/** @defgroup HX8347G_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup HX8347G_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup HX8347G_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup HX8347G_Private_Variables
* @{
*/
LCD_DrvTypeDef hx8347g_drv =
{
hx8347g_Init,
hx8347g_ReadID,
hx8347g_DisplayOn,
hx8347g_DisplayOff,
hx8347g_SetCursor,
hx8347g_WritePixel,
hx8347g_ReadPixel,
hx8347g_SetDisplayWindow,
hx8347g_DrawHLine,
hx8347g_DrawVLine,
hx8347g_GetLcdPixelWidth,
hx8347g_GetLcdPixelHeight,
hx8347g_DrawBitmap,
};
static uint8_t Is_hx8347g_Initialized = 0;
static uint16_t ArrayRGB[320] = {0};
/**
* @}
*/
/** @defgroup HX8347G_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup HX8347G_Private_Functions
* @{
*/
/**
* @brief Initialise the HX8347G LCD Component.
* @param None
* @retval None
*/
void hx8347g_Init(void)
{
if(Is_hx8347g_Initialized == 0)
{
Is_hx8347g_Initialized = 1;
/* Initialise HX8347G low level bus layer --------------------------------*/
LCD_IO_Init();
/* HX8347G requests 120ms (worst case) after reset */
LCD_Delay(120);
/* Driving ability setting */
hx8347g_WriteReg(LCD_REG_234, 0x00);
hx8347g_WriteReg(LCD_REG_235, 0x20);
hx8347g_WriteReg(LCD_REG_236, 0x0C);
hx8347g_WriteReg(LCD_REG_237, 0xC4);
hx8347g_WriteReg(LCD_REG_232, 0x40);
hx8347g_WriteReg(LCD_REG_233, 0x38);
hx8347g_WriteReg(LCD_REG_241, 0x01);
hx8347g_WriteReg(LCD_REG_242, 0x10);
hx8347g_WriteReg(LCD_REG_39, 0xA3);
/* Adjust the Gamma Curve */
hx8347g_WriteReg(LCD_REG_64, 0x01);
hx8347g_WriteReg(LCD_REG_65, 0x00);
hx8347g_WriteReg(LCD_REG_66, 0x00);
hx8347g_WriteReg(LCD_REG_67, 0x10);
hx8347g_WriteReg(LCD_REG_68, 0x0E);
hx8347g_WriteReg(LCD_REG_69, 0x24);
hx8347g_WriteReg(LCD_REG_70, 0x04);
hx8347g_WriteReg(LCD_REG_71, 0x50);
hx8347g_WriteReg(LCD_REG_72, 0x02);
hx8347g_WriteReg(LCD_REG_73, 0x13);
hx8347g_WriteReg(LCD_REG_74, 0x19);
hx8347g_WriteReg(LCD_REG_75, 0x19);
hx8347g_WriteReg(LCD_REG_76, 0x16);
hx8347g_WriteReg(LCD_REG_80, 0x1B);
hx8347g_WriteReg(LCD_REG_81, 0x31);
hx8347g_WriteReg(LCD_REG_82, 0x2F);
hx8347g_WriteReg(LCD_REG_83, 0x3F);
hx8347g_WriteReg(LCD_REG_84, 0x3F);
hx8347g_WriteReg(LCD_REG_85, 0x3E);
hx8347g_WriteReg(LCD_REG_86, 0x2F);
hx8347g_WriteReg(LCD_REG_87, 0x7B);
hx8347g_WriteReg(LCD_REG_88, 0x09);
hx8347g_WriteReg(LCD_REG_89, 0x06);
hx8347g_WriteReg(LCD_REG_90, 0x06);
hx8347g_WriteReg(LCD_REG_91, 0x0C);
hx8347g_WriteReg(LCD_REG_92, 0x1D);
hx8347g_WriteReg(LCD_REG_93, 0xCC);
/* Power voltage setting */
hx8347g_WriteReg(LCD_REG_27, 0x1B);
hx8347g_WriteReg(LCD_REG_26, 0x01);
hx8347g_WriteReg(LCD_REG_36, 0x2F);
hx8347g_WriteReg(LCD_REG_37, 0x57);
/*****VCOM offset ****/
hx8347g_WriteReg(LCD_REG_35, 0x86);
hx8347g_DisplayOn();
/* Set GRAM Area - Partial Display Control */
hx8347g_WriteReg(LCD_REG_1, 0x00); /* DP_STB = 0, DP_STB_S = 0, SCROLL = 0, */
hx8347g_SetDisplayWindow(0, 0, hx8347g_GetLcdPixelWidth(), hx8347g_GetLcdPixelHeight());
hx8347g_WriteReg(LCD_REG_22, 0xA0); /* Memory access control: MY = 1, MX = 0, MV = 1, ML = 0 */
}
/* Set the Cursor */
hx8347g_SetCursor(0, 0);
/* Prepare to write GRAM */
LCD_IO_WriteReg(LCD_REG_34);
}
/**
* @brief Enables the Display.
* @param None
* @retval None
*/
void hx8347g_DisplayOn(void)
{
/* Power On sequence ---------------------------------------------------------*/
hx8347g_WriteReg(LCD_REG_24, 0x36); /* Display frame rate = 70Hz RADJ = '0110' */
hx8347g_WriteReg(LCD_REG_25, 0x01); /* OSC_EN = 1 */
hx8347g_WriteReg(LCD_REG_28, 0x06); /* AP[2:0] = 111 */
hx8347g_WriteReg(LCD_REG_31, 0x90); /* GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0*/
LCD_Delay(10);
/* 262k/65k color selection */
hx8347g_WriteReg(LCD_REG_23, 0x05); /* default 0x06 262k color, 0x05 65k color */
/* SET PANEL */
hx8347g_WriteReg(LCD_REG_54, 0x09); /* SS_PANEL = 1, GS_PANEL = 0,REV_PANEL = 0, BGR_PANEL = 1 */
/* Display On */
hx8347g_WriteReg(LCD_REG_40, 0x38);
LCD_Delay(60);
hx8347g_WriteReg(LCD_REG_40, 0x3C);
}
/**
* @brief Disables the Display.
* @param None
* @retval None
*/
void hx8347g_DisplayOff(void)
{
/* Display Off */
hx8347g_WriteReg(LCD_REG_40, 0x38);
LCD_Delay(60);
hx8347g_WriteReg(LCD_REG_40, 0x04);
/* Power Off sequence ---------------------------------------------------------*/
hx8347g_WriteReg(LCD_REG_23, 0x0000); /* default 0x06 262k color, 0x05 65k color */
hx8347g_WriteReg(LCD_REG_24, 0x0000); /* Display frame rate = 70Hz RADJ = '0110' */
hx8347g_WriteReg(LCD_REG_25, 0x0000); /* OSC_EN = 1 */
hx8347g_WriteReg(LCD_REG_28, 0x0000); /* AP[2:0] = 111 */
hx8347g_WriteReg(LCD_REG_31, 0x0000); /* GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0*/
hx8347g_WriteReg(LCD_REG_54, 0x0000); /* SS_PANEL = 1, GS_PANEL = 0,REV_PANEL = 0, BGR_PANEL = 1 */
}
/**
* @brief Get the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t hx8347g_GetLcdPixelWidth(void)
{
return (uint16_t)HX8347G_LCD_PIXEL_WIDTH;
}
/**
* @brief Get the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t hx8347g_GetLcdPixelHeight(void)
{
return (uint16_t)HX8347G_LCD_PIXEL_HEIGHT;
}
/**
* @brief Get the HX8347G ID.
* @param None
* @retval The HX8347G ID
*/
uint16_t hx8347g_ReadID(void)
{
if(Is_hx8347g_Initialized == 0)
{
LCD_IO_Init();
/* HX8347G requests 120ms (worst case) after reset */
LCD_Delay(120);
}
return (hx8347g_ReadReg(0x00));
}
/**
* @brief Set Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void hx8347g_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
hx8347g_WriteReg(LCD_REG_6, 0x00);
hx8347g_WriteReg(LCD_REG_7, Xpos);
hx8347g_WriteReg(LCD_REG_2, Ypos >> 8);
hx8347g_WriteReg(LCD_REG_3, Ypos & 0xFF);
}
/**
* @brief Write pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color
* @retval None
*/
void hx8347g_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
/* Set Cursor */
hx8347g_SetCursor(Xpos, Ypos);
/* Prepare to write GRAM */
LCD_IO_WriteReg(LCD_REG_34);
/* Write 16-bit GRAM Reg */
LCD_IO_WriteMultipleData((uint8_t*)&RGBCode, 2);
}
/**
* @brief Read pixel.
* @param None
* @retval the RGB pixel color
*/
uint16_t hx8347g_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
/* Set Cursor */
hx8347g_SetCursor(Xpos, Ypos);
/* Dummy read */
LCD_IO_ReadData(LCD_REG_34);
/* Read 16-bit Reg */
return (LCD_IO_ReadData(LCD_REG_34));
}
/**
* @brief Writes to the selected LCD register.
* @param LCDReg: address of the selected register.
* @param LCDRegValue: value to write to the selected register.
* @retval None
*/
void hx8347g_WriteReg(uint8_t LCDReg, uint16_t LCDRegValue)
{
LCD_IO_WriteReg(LCDReg);
/* Write 16-bit GRAM Reg */
LCD_IO_WriteMultipleData((uint8_t*)&LCDRegValue, 2);
}
/**
* @brief Reads the selected LCD Register.
* @param LCDReg: address of the selected register.
* @retval LCD Register Value.
*/
uint16_t hx8347g_ReadReg(uint8_t LCDReg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_IO_WriteReg(LCDReg);
/* Read 16-bit Reg */
return (LCD_IO_ReadData(LCDReg));
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void hx8347g_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
/* Horizontal GRAM Start Address */
hx8347g_WriteReg(LCD_REG_6, (Xpos) >> 8); /* SP */
hx8347g_WriteReg(LCD_REG_7, (Xpos) & 0xFF); /* SP */
/* Horizontal GRAM End Address */
hx8347g_WriteReg(LCD_REG_8, (Xpos + Height - 1) >> 8); /* EP */
hx8347g_WriteReg(LCD_REG_9, (Xpos + Height - 1) & 0xFF); /* EP */
/* Vertical GRAM Start Address */
hx8347g_WriteReg(LCD_REG_2, (Ypos) >> 8); /* SC */
hx8347g_WriteReg(LCD_REG_3, (Ypos) & 0xFF); /* SC */
/* Vertical GRAM End Address */
hx8347g_WriteReg(LCD_REG_4, (Ypos + Width - 1) >> 8); /* EC */
hx8347g_WriteReg(LCD_REG_5, (Ypos + Width - 1) & 0xFF); /* EC */
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void hx8347g_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint32_t i = 0;
/* Set Cursor */
hx8347g_SetCursor(Xpos, Ypos);
/* Prepare to write GRAM */
LCD_IO_WriteReg(LCD_REG_34);
/* Sent a complete line */
for(i = 0; i < Length; i++)
{
ArrayRGB[i] = RGBCode;
}
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void hx8347g_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
/* Set Cursor */
hx8347g_SetCursor(Xpos, Ypos);
/* Prepare to write GRAM */
LCD_IO_WriteReg(LCD_REG_34);
/* Fill a complete vertical line */
for(counter = 0; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}
/* Write 16-bit GRAM Reg */
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
}
/**
* @brief Displays a bitmap picture loaded in the internal Flash.
* @param BmpAddress: Bmp picture address in the internal Flash.
* @retval None
*/
void hx8347g_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
/* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
/* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 1, MX = 0, MV = 1, ML = 0 */
hx8347g_WriteReg(LCD_REG_22, 0xE0);
/* Set Cursor */
hx8347g_SetCursor(Xpos, Ypos);
/* Prepare to write GRAM */
LCD_IO_WriteReg(LCD_REG_34);
LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*2);
/* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 1, MX = 1, MV = 1, ML = 0 */
hx8347g_WriteReg(LCD_REG_22, 0xA0);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,272 @@
/**
******************************************************************************
* @file hx8347g.h
* @author MCD Application Team
* @brief This file contains all the functions prototypes for the hx8347g.c
* driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HX8347G_H
#define __HX8347G_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/lcd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup hx8347g
* @{
*/
/** @defgroup HX8347G_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup HX8347G_Exported_Constants
* @{
*/
/**
* @brief HX8347G ID
*/
#define HX8347G_ID 0x0075
/**
* @brief HX8347G Size
*/
#define HX8347G_LCD_PIXEL_WIDTH ((uint16_t)320)
#define HX8347G_LCD_PIXEL_HEIGHT ((uint16_t)240)
/**
* @brief HX8347G Registers
*/
#define LCD_REG_0 0x00
#define LCD_REG_1 0x01
#define LCD_REG_2 0x02
#define LCD_REG_3 0x03
#define LCD_REG_4 0x04
#define LCD_REG_5 0x05
#define LCD_REG_6 0x06
#define LCD_REG_7 0x07
#define LCD_REG_8 0x08
#define LCD_REG_9 0x09
#define LCD_REG_10 0x0A
#define LCD_REG_11 0x0B
#define LCD_REG_12 0x0C
#define LCD_REG_13 0x0D
#define LCD_REG_14 0x0E
#define LCD_REG_15 0x0F
#define LCD_REG_16 0x10
#define LCD_REG_17 0x11
#define LCD_REG_18 0x12
#define LCD_REG_19 0x13
#define LCD_REG_20 0x14
#define LCD_REG_21 0x15
#define LCD_REG_22 0x16
#define LCD_REG_23 0x17
#define LCD_REG_24 0x18
#define LCD_REG_25 0x19
#define LCD_REG_26 0x1A
#define LCD_REG_27 0x1B
#define LCD_REG_28 0x1C
#define LCD_REG_29 0x1D
#define LCD_REG_30 0x1E
#define LCD_REG_31 0x1F
#define LCD_REG_32 0x20
#define LCD_REG_33 0x21
#define LCD_REG_34 0x22
#define LCD_REG_35 0x23
#define LCD_REG_36 0x24
#define LCD_REG_37 0x25
#define LCD_REG_38 0x26
#define LCD_REG_39 0x27
#define LCD_REG_40 0x28
#define LCD_REG_41 0x29
#define LCD_REG_42 0x2A
#define LCD_REG_43 0x2B
#define LCD_REG_44 0x2C
#define LCD_REG_45 0x2D
#define LCD_REG_46 0x2E
#define LCD_REG_47 0x2F
#define LCD_REG_48 0x30
#define LCD_REG_49 0x31
#define LCD_REG_50 0x32
#define LCD_REG_51 0x33
#define LCD_REG_52 0x34
#define LCD_REG_53 0x35
#define LCD_REG_54 0x36
#define LCD_REG_55 0x37
#define LCD_REG_56 0x38
#define LCD_REG_57 0x39
#define LCD_REG_58 0x3A
#define LCD_REG_59 0x3B
#define LCD_REG_60 0x3C
#define LCD_REG_61 0x3D
#define LCD_REG_62 0x3E
#define LCD_REG_63 0x3F
#define LCD_REG_64 0x40
#define LCD_REG_65 0x41
#define LCD_REG_66 0x42
#define LCD_REG_67 0x43
#define LCD_REG_68 0x44
#define LCD_REG_69 0x45
#define LCD_REG_70 0x46
#define LCD_REG_71 0x47
#define LCD_REG_72 0x48
#define LCD_REG_73 0x49
#define LCD_REG_74 0x4A
#define LCD_REG_75 0x4B
#define LCD_REG_76 0x4C
#define LCD_REG_77 0x4D
#define LCD_REG_78 0x4E
#define LCD_REG_79 0x4F
#define LCD_REG_80 0x50
#define LCD_REG_81 0x51
#define LCD_REG_82 0x52
#define LCD_REG_83 0x53
#define LCD_REG_84 0x54
#define LCD_REG_85 0x55
#define LCD_REG_86 0x56
#define LCD_REG_87 0x57
#define LCD_REG_88 0x58
#define LCD_REG_89 0x59
#define LCD_REG_90 0x5A
#define LCD_REG_91 0x5B
#define LCD_REG_92 0x5C
#define LCD_REG_93 0x5D
#define LCD_REG_94 0x5E
#define LCD_REG_95 0x5F
#define LCD_REG_96 0x60
#define LCD_REG_97 0x61
#define LCD_REG_98 0x62
#define LCD_REG_99 0x63
#define LCD_REG_104 0x68
#define LCD_REG_105 0x69
#define LCD_REG_112 0x70
#define LCD_REG_113 0x71
#define LCD_REG_132 0x84
#define LCD_REG_133 0x85
#define LCD_REG_195 0xC3
#define LCD_REG_197 0xC5
#define LCD_REG_199 0xC7
#define LCD_REG_203 0xCB
#define LCD_REG_204 0xCC
#define LCD_REG_205 0xCD
#define LCD_REG_206 0xCE
#define LCD_REG_207 0xCF
#define LCD_REG_208 0xD0
#define LCD_REG_209 0xD1
#define LCD_REG_210 0xD2
#define LCD_REG_211 0xD3
#define LCD_REG_232 0xE8
#define LCD_REG_233 0xE9
#define LCD_REG_234 0xEA
#define LCD_REG_235 0xEB
#define LCD_REG_236 0xEC
#define LCD_REG_237 0xED
#define LCD_REG_241 0xF1
#define LCD_REG_242 0xF2
#define LCD_REG_255 0xFF
/**
* @}
*/
/** @defgroup HX8347G_Exported_Functions
* @{
*/
void hx8347g_Init(void);
uint16_t hx8347g_ReadID(void);
void hx8347g_WriteReg(uint8_t LCDReg, uint16_t LCDRegValue);
uint16_t hx8347g_ReadReg(uint8_t LCDReg);
void hx8347g_DisplayOn(void);
void hx8347g_DisplayOff(void);
void hx8347g_SetCursor(uint16_t Xpos, uint16_t Ypos);
void hx8347g_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
uint16_t hx8347g_ReadPixel(uint16_t Xpos, uint16_t Ypos);
void hx8347g_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void hx8347g_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void hx8347g_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
void hx8347g_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
uint16_t hx8347g_GetLcdPixelWidth(void);
uint16_t hx8347g_GetLcdPixelHeight(void);
/* LCD driver structure */
extern LCD_DrvTypeDef hx8347g_drv;
/* LCD IO functions */
void LCD_IO_Init(void);
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
uint16_t LCD_IO_ReadData(uint16_t Reg);
void LCD_Delay (uint32_t delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __HX8347G_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,149 @@
/**
******************************************************************************
* @file iss66wvh8m8.h
* @author MCD Application Team
* @brief This file contains all the description of the ISS66WVH8M8 Octal memory.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ISS66WVH8M8_H
#define __ISS66WVH8M8_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ISS66WVH8M8
* @{
*/
/** @defgroup ISS66WVH8M8_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup ISS66WVH8M8_Exported_Constants
* @{
*/
/**
* @brief ISS66WVH8M8 Configuration
*/
#define ISS66WVH8M8_RAM_SIZE 0x800000 /* 64 MBits => 8 MBytes */
#define ISS66WVH8M8_LATENCY_83M 3
#define ISS66WVH8M8_LATENCY_100M 4
#define ISS66WVH8M8_LATENCY_133M 5
#define ISS66WVH8M8_LATENCY_166M 6
#define ISS66WVH8M8_CR0_LATENCY_83M ISS66WVH8M8_CR0_IL_3_CLOCK
#define ISS66WVH8M8_CR0_LATENCY_100M ISS66WVH8M8_CR0_IL_4_CLOCK
#define ISS66WVH8M8_CR0_LATENCY_133M ISS66WVH8M8_CR0_IL_5_CLOCK
#define ISS66WVH8M8_CR0_LATENCY_166M ISS66WVH8M8_CR0_IL_6_CLOCK
/**
* @brief ISS66WVH8M8 Registers
*/
/* Device Identification Register 0 */
#define ISS66WVH8M8_DIR0_ADDRESS ((uint32_t)0x00000000)
#define ISS66WVH8M8_DIR0_MANUFACTURER ((uint16_t)0x000F) /*!< Manufacturer */
#define ISS66WVH8M8_DIR0_CADC ((uint16_t)0x00F0) /*!< Column Address Bit Count */
#define ISS66WVH8M8_DIR0_RABC ((uint16_t)0x1F00) /*!< Row Address Bit Count */
#define ISS66WVH8M8_DIR0_DADDR ((uint16_t)0xC000) /*!< Die Address */
/* Device Identification Register 1 */
#define ISS66WVH8M8_DIR1_ADDRESS ((uint32_t)0x00000001)
#define ISS66WVH8M8_DIR1_DTYPE ((uint16_t)0x000F) /*!< Device Type */
/* Configuration Register 0 */
#define ISS66WVH8M8_CR0_ADDRESS ((uint32_t)0x00000800)
#define ISS66WVH8M8_CR0_BLENGTH ((uint16_t)0x0003) /*!< Burst length */
#define ISS66WVH8M8_CR0_HBE ((uint16_t)0x0004) /*!< Hybrid burst enable */
#define ISS66WVH8M8_CR0_FLE ((uint16_t)0x0008) /*!< Fixed latency enable */
#define ISS66WVH8M8_CR0_IL ((uint16_t)0x00F0) /*!< Initial latency */
#define ISS66WVH8M8_CR0_IL_5_CLOCK ((uint16_t)0x0000) /*!< 5 clock latency */
#define ISS66WVH8M8_CR0_IL_6_CLOCK ((uint16_t)0x0010) /*!< 6 clock latency */
#define ISS66WVH8M8_CR0_IL_3_CLOCK ((uint16_t)0x00E0) /*!< 3 clock latency */
#define ISS66WVH8M8_CR0_IL_4_CLOCK ((uint16_t)0x00F0) /*!< 4 clock latency */
#define ISS66WVH8M8_CR0_DS ((uint16_t)0x7000) /*!< Drive strength */
#define ISS66WVH8M8_CR0_DPDE ((uint16_t)0x8000) /*!< Deep Power down enable */
/* Configuration Register 1 */
#define ISS66WVH8M8_CR1_ADDRESS ((uint32_t)0x00000801)
#define ISS66WVH8M8_CR1_DRI ((uint16_t)0x0003) /*!< Distributed refresh interval */
/**
* @}
*/
/** @defgroup ISS66WVH8M8_Exported_Functions
* @{
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ISS66WVH8M8_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,416 @@
/**
******************************************************************************
* @file l3gd20.c
* @author MCD Application Team
* @version V2.0.0
* @date 26-June-2015
* @brief This file provides a set of functions needed to manage the L3GD20,
* ST MEMS motion sensor, 3-axis digital output gyroscope.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "l3gd20.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup L3GD20
* @{
*/
/** @defgroup L3GD20_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup L3GD20_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup L3GD20_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup L3GD20_Private_Variables
* @{
*/
GYRO_DrvTypeDef L3gd20Drv =
{
L3GD20_Init,
L3GD20_DeInit,
L3GD20_ReadID,
L3GD20_RebootCmd,
L3GD20_LowPower,
L3GD20_INT1InterruptConfig,
L3GD20_EnableIT,
L3GD20_DisableIT,
0,
0,
L3GD20_FilterConfig,
L3GD20_FilterCmd,
L3GD20_ReadXYZAngRate
};
/**
* @}
*/
/** @defgroup L3GD20_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup L3GD20_Private_Functions
* @{
*/
/**
* @brief Set L3GD20 Initialization.
* @param L3GD20_InitStruct: pointer to a L3GD20_InitTypeDef structure
* that contains the configuration setting for the L3GD20.
* @retval None
*/
void L3GD20_Init(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
/* Configure the low level interface */
GYRO_IO_Init();
/* Write value to MEMS CTRL_REG1 register */
ctrl = (uint8_t) InitStruct;
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
/* Write value to MEMS CTRL_REG4 register */
ctrl = (uint8_t) (InitStruct >> 8);
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG4_ADDR, 1);
}
/**
* @brief L3GD20 De-initialization
* @param None
* @retval None
*/
void L3GD20_DeInit(void)
{
}
/**
* @brief Read ID address of L3GD20
* @param None
* @retval ID name
*/
uint8_t L3GD20_ReadID(void)
{
uint8_t tmp;
/* Configure the low level interface */
GYRO_IO_Init();
/* Read WHO I AM register */
GYRO_IO_Read(&tmp, L3GD20_WHO_AM_I_ADDR, 1);
/* Return the ID */
return (uint8_t)tmp;
}
/**
* @brief Reboot memory content of L3GD20
* @param None
* @retval None
*/
void L3GD20_RebootCmd(void)
{
uint8_t tmpreg;
/* Read CTRL_REG5 register */
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
/* Enable or Disable the reboot memory */
tmpreg |= L3GD20_BOOT_REBOOTMEMORY;
/* Write value to MEMS CTRL_REG5 register */
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
}
/**
* @brief Set L3GD20 in low-power mode
* @param
* @retval None
*/
void L3GD20_LowPower(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
/* Write value to MEMS CTRL_REG1 register */
ctrl = (uint8_t) InitStruct;
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
}
/**
* @brief Set L3GD20 Interrupt INT1 configuration
* @param Int1Config: the configuration setting for the L3GD20 Interrupt.
* @retval None
*/
void L3GD20_INT1InterruptConfig(uint16_t Int1Config)
{
uint8_t ctrl_cfr = 0x00, ctrl3 = 0x00;
/* Read INT1_CFG register */
GYRO_IO_Read(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
/* Read CTRL_REG3 register */
GYRO_IO_Read(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
ctrl_cfr &= 0x80;
ctrl_cfr |= ((uint8_t) Int1Config >> 8);
ctrl3 &= 0xDF;
ctrl3 |= ((uint8_t) Int1Config);
/* Write value to MEMS INT1_CFG register */
GYRO_IO_Write(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
/* Write value to MEMS CTRL_REG3 register */
GYRO_IO_Write(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
}
/**
* @brief Enable INT1 or INT2 interrupt
* @param IntSel: choice of INT1 or INT2
* This parameter can be:
* @arg L3GD20_INT1
* @arg L3GD20_INT2
* @retval None
*/
void L3GD20_EnableIT(uint8_t IntSel)
{
uint8_t tmpreg;
/* Read CTRL_REG3 register */
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
if(IntSel == L3GD20_INT1)
{
tmpreg &= 0x7F;
tmpreg |= L3GD20_INT1INTERRUPT_ENABLE;
}
else if(IntSel == L3GD20_INT2)
{
tmpreg &= 0xF7;
tmpreg |= L3GD20_INT2INTERRUPT_ENABLE;
}
/* Write value to MEMS CTRL_REG3 register */
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
}
/**
* @brief Disable INT1 or INT2 interrupt
* @param IntSel: choice of INT1 or INT2
* This parameter can be:
* @arg L3GD20_INT1
* @arg L3GD20_INT2
* @retval None
*/
void L3GD20_DisableIT(uint8_t IntSel)
{
uint8_t tmpreg;
/* Read CTRL_REG3 register */
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
if(IntSel == L3GD20_INT1)
{
tmpreg &= 0x7F;
tmpreg |= L3GD20_INT1INTERRUPT_DISABLE;
}
else if(IntSel == L3GD20_INT2)
{
tmpreg &= 0xF7;
tmpreg |= L3GD20_INT2INTERRUPT_DISABLE;
}
/* Write value to MEMS CTRL_REG3 register */
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
}
/**
* @brief Set High Pass Filter Modality
* @param FilterStruct: contains the configuration setting for the L3GD20.
* @retval None
*/
void L3GD20_FilterConfig(uint8_t FilterStruct)
{
uint8_t tmpreg;
/* Read CTRL_REG2 register */
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
tmpreg &= 0xC0;
/* Configure MEMS: mode and cutoff frequency */
tmpreg |= FilterStruct;
/* Write value to MEMS CTRL_REG2 register */
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
}
/**
* @brief Enable or Disable High Pass Filter
* @param HighPassFilterState: new state of the High Pass Filter feature.
* This parameter can be:
* @arg: L3GD20_HIGHPASSFILTER_DISABLE
* @arg: L3GD20_HIGHPASSFILTER_ENABLE
* @retval None
*/
void L3GD20_FilterCmd(uint8_t HighPassFilterState)
{
uint8_t tmpreg;
/* Read CTRL_REG5 register */
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
tmpreg &= 0xEF;
tmpreg |= HighPassFilterState;
/* Write value to MEMS CTRL_REG5 register */
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
}
/**
* @brief Get status for L3GD20 data
* @param None
* @retval Data status in a L3GD20 Data
*/
uint8_t L3GD20_GetDataStatus(void)
{
uint8_t tmpreg;
/* Read STATUS_REG register */
GYRO_IO_Read(&tmpreg, L3GD20_STATUS_REG_ADDR, 1);
return tmpreg;
}
/**
* @brief Calculate the L3GD20 angular data.
* @param pfData: Data out pointer
* @retval None
*/
void L3GD20_ReadXYZAngRate(float *pfData)
{
uint8_t tmpbuffer[6] ={0};
int16_t RawData[3] = {0};
uint8_t tmpreg = 0;
float sensitivity = 0;
int i =0;
GYRO_IO_Read(&tmpreg,L3GD20_CTRL_REG4_ADDR,1);
GYRO_IO_Read(tmpbuffer,L3GD20_OUT_X_L_ADDR,6);
/* check in the control register 4 the data alignment (Big Endian or Little Endian)*/
if(!(tmpreg & L3GD20_BLE_MSB))
{
for(i=0; i<3; i++)
{
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
}
}
else
{
for(i=0; i<3; i++)
{
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i] << 8) + tmpbuffer[2*i+1]);
}
}
/* Switch the sensitivity value set in the CRTL4 */
switch(tmpreg & L3GD20_FULLSCALE_SELECTION)
{
case L3GD20_FULLSCALE_250:
sensitivity=L3GD20_SENSITIVITY_250DPS;
break;
case L3GD20_FULLSCALE_500:
sensitivity=L3GD20_SENSITIVITY_500DPS;
break;
case L3GD20_FULLSCALE_2000:
sensitivity=L3GD20_SENSITIVITY_2000DPS;
break;
}
/* Divide by sensitivity */
for(i=0; i<3; i++)
{
pfData[i]=(float)(RawData[i] * sensitivity);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,324 @@
/**
******************************************************************************
* @file l3gd20.h
* @author MCD Application Team
* @version V2.0.0
* @date 26-June-2015
* @brief This file contains all the functions prototypes for the l3gd20.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __L3GD20_H
#define __L3GD20_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/gyro.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup L3GD20
* @{
*/
/** @defgroup L3GD20_Exported_Constants
* @{
*/
/******************************************************************************/
/*************************** START REGISTER MAPPING **************************/
/******************************************************************************/
#define L3GD20_WHO_AM_I_ADDR 0x0F /* device identification register */
#define L3GD20_CTRL_REG1_ADDR 0x20 /* Control register 1 */
#define L3GD20_CTRL_REG2_ADDR 0x21 /* Control register 2 */
#define L3GD20_CTRL_REG3_ADDR 0x22 /* Control register 3 */
#define L3GD20_CTRL_REG4_ADDR 0x23 /* Control register 4 */
#define L3GD20_CTRL_REG5_ADDR 0x24 /* Control register 5 */
#define L3GD20_REFERENCE_REG_ADDR 0x25 /* Reference register */
#define L3GD20_OUT_TEMP_ADDR 0x26 /* Out temp register */
#define L3GD20_STATUS_REG_ADDR 0x27 /* Status register */
#define L3GD20_OUT_X_L_ADDR 0x28 /* Output Register X */
#define L3GD20_OUT_X_H_ADDR 0x29 /* Output Register X */
#define L3GD20_OUT_Y_L_ADDR 0x2A /* Output Register Y */
#define L3GD20_OUT_Y_H_ADDR 0x2B /* Output Register Y */
#define L3GD20_OUT_Z_L_ADDR 0x2C /* Output Register Z */
#define L3GD20_OUT_Z_H_ADDR 0x2D /* Output Register Z */
#define L3GD20_FIFO_CTRL_REG_ADDR 0x2E /* Fifo control Register */
#define L3GD20_FIFO_SRC_REG_ADDR 0x2F /* Fifo src Register */
#define L3GD20_INT1_CFG_ADDR 0x30 /* Interrupt 1 configuration Register */
#define L3GD20_INT1_SRC_ADDR 0x31 /* Interrupt 1 source Register */
#define L3GD20_INT1_TSH_XH_ADDR 0x32 /* Interrupt 1 Threshold X register */
#define L3GD20_INT1_TSH_XL_ADDR 0x33 /* Interrupt 1 Threshold X register */
#define L3GD20_INT1_TSH_YH_ADDR 0x34 /* Interrupt 1 Threshold Y register */
#define L3GD20_INT1_TSH_YL_ADDR 0x35 /* Interrupt 1 Threshold Y register */
#define L3GD20_INT1_TSH_ZH_ADDR 0x36 /* Interrupt 1 Threshold Z register */
#define L3GD20_INT1_TSH_ZL_ADDR 0x37 /* Interrupt 1 Threshold Z register */
#define L3GD20_INT1_DURATION_ADDR 0x38 /* Interrupt 1 DURATION register */
/******************************************************************************/
/**************************** END REGISTER MAPPING ***************************/
/******************************************************************************/
#define I_AM_L3GD20 ((uint8_t)0xD4)
#define I_AM_L3GD20_TR ((uint8_t)0xD5)
/** @defgroup Power_Mode_selection
* @{
*/
#define L3GD20_MODE_POWERDOWN ((uint8_t)0x00)
#define L3GD20_MODE_ACTIVE ((uint8_t)0x08)
/**
* @}
*/
/** @defgroup OutPut_DataRate_Selection
* @{
*/
#define L3GD20_OUTPUT_DATARATE_1 ((uint8_t)0x00)
#define L3GD20_OUTPUT_DATARATE_2 ((uint8_t)0x40)
#define L3GD20_OUTPUT_DATARATE_3 ((uint8_t)0x80)
#define L3GD20_OUTPUT_DATARATE_4 ((uint8_t)0xC0)
/**
* @}
*/
/** @defgroup Axes_Selection
* @{
*/
#define L3GD20_X_ENABLE ((uint8_t)0x02)
#define L3GD20_Y_ENABLE ((uint8_t)0x01)
#define L3GD20_Z_ENABLE ((uint8_t)0x04)
#define L3GD20_AXES_ENABLE ((uint8_t)0x07)
#define L3GD20_AXES_DISABLE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Bandwidth_Selection
* @{
*/
#define L3GD20_BANDWIDTH_1 ((uint8_t)0x00)
#define L3GD20_BANDWIDTH_2 ((uint8_t)0x10)
#define L3GD20_BANDWIDTH_3 ((uint8_t)0x20)
#define L3GD20_BANDWIDTH_4 ((uint8_t)0x30)
/**
* @}
*/
/** @defgroup Full_Scale_Selection
* @{
*/
#define L3GD20_FULLSCALE_250 ((uint8_t)0x00)
#define L3GD20_FULLSCALE_500 ((uint8_t)0x10)
#define L3GD20_FULLSCALE_2000 ((uint8_t)0x20)
#define L3GD20_FULLSCALE_SELECTION ((uint8_t)0x30)
/**
* @}
*/
/** @defgroup Full_Scale_Sensitivity
* @{
*/
#define L3GD20_SENSITIVITY_250DPS ((float)8.75f) /*!< gyroscope sensitivity with 250 dps full scale [DPS/LSB] */
#define L3GD20_SENSITIVITY_500DPS ((float)17.50f) /*!< gyroscope sensitivity with 500 dps full scale [DPS/LSB] */
#define L3GD20_SENSITIVITY_2000DPS ((float)70.00f) /*!< gyroscope sensitivity with 2000 dps full scale [DPS/LSB] */
/**
* @}
*/
/** @defgroup Block_Data_Update
* @{
*/
#define L3GD20_BlockDataUpdate_Continous ((uint8_t)0x00)
#define L3GD20_BlockDataUpdate_Single ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup Endian_Data_selection
* @{
*/
#define L3GD20_BLE_LSB ((uint8_t)0x00)
#define L3GD20_BLE_MSB ((uint8_t)0x40)
/**
* @}
*/
/** @defgroup High_Pass_Filter_status
* @{
*/
#define L3GD20_HIGHPASSFILTER_DISABLE ((uint8_t)0x00)
#define L3GD20_HIGHPASSFILTER_ENABLE ((uint8_t)0x10)
/**
* @}
*/
/** @defgroup INT1_INT2_selection
* @{
*/
#define L3GD20_INT1 ((uint8_t)0x00)
#define L3GD20_INT2 ((uint8_t)0x01)
/**
* @}
*/
/** @defgroup INT1_Interrupt_status
* @{
*/
#define L3GD20_INT1INTERRUPT_DISABLE ((uint8_t)0x00)
#define L3GD20_INT1INTERRUPT_ENABLE ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup INT2_Interrupt_status
* @{
*/
#define L3GD20_INT2INTERRUPT_DISABLE ((uint8_t)0x00)
#define L3GD20_INT2INTERRUPT_ENABLE ((uint8_t)0x08)
/**
* @}
*/
/** @defgroup INT1_Interrupt_ActiveEdge
* @{
*/
#define L3GD20_INT1INTERRUPT_LOW_EDGE ((uint8_t)0x20)
#define L3GD20_INT1INTERRUPT_HIGH_EDGE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Boot_Mode_selection
* @{
*/
#define L3GD20_BOOT_NORMALMODE ((uint8_t)0x00)
#define L3GD20_BOOT_REBOOTMEMORY ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup High_Pass_Filter_Mode
* @{
*/
#define L3GD20_HPM_NORMAL_MODE_RES ((uint8_t)0x00)
#define L3GD20_HPM_REF_SIGNAL ((uint8_t)0x10)
#define L3GD20_HPM_NORMAL_MODE ((uint8_t)0x20)
#define L3GD20_HPM_AUTORESET_INT ((uint8_t)0x30)
/**
* @}
*/
/** @defgroup High_Pass_CUT OFF_Frequency
* @{
*/
#define L3GD20_HPFCF_0 0x00
#define L3GD20_HPFCF_1 0x01
#define L3GD20_HPFCF_2 0x02
#define L3GD20_HPFCF_3 0x03
#define L3GD20_HPFCF_4 0x04
#define L3GD20_HPFCF_5 0x05
#define L3GD20_HPFCF_6 0x06
#define L3GD20_HPFCF_7 0x07
#define L3GD20_HPFCF_8 0x08
#define L3GD20_HPFCF_9 0x09
/**
* @}
*/
/**
* @}
*/
/** @defgroup L3GD20_Exported_Functions
* @{
*/
/* Sensor Configuration Functions */
void L3GD20_Init(uint16_t InitStruct);
void L3GD20_DeInit(void);
void L3GD20_LowPower(uint16_t InitStruct);
uint8_t L3GD20_ReadID(void);
void L3GD20_RebootCmd(void);
/* Interrupt Configuration Functions */
void L3GD20_INT1InterruptConfig(uint16_t Int1Config);
void L3GD20_EnableIT(uint8_t IntSel);
void L3GD20_DisableIT(uint8_t IntSel);
/* High Pass Filter Configuration Functions */
void L3GD20_FilterConfig(uint8_t FilterStruct);
void L3GD20_FilterCmd(uint8_t HighPassFilterState);
void L3GD20_ReadXYZAngRate(float *pfData);
uint8_t L3GD20_GetDataStatus(void);
/* Gyroscope IO functions */
void GYRO_IO_Init(void);
void GYRO_IO_DeInit(void);
void GYRO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
void GYRO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
/* Gyroscope driver structure */
extern GYRO_DrvTypeDef L3gd20Drv;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __L3GD20_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,220 @@
/**
******************************************************************************
* @file lis3mdl.c
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief This file provides a set of functions needed to manage the LIS3MDL
* magnetometer devices
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "lis3mdl.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup LIS3MDL LIS3MDL
* @{
*/
/** @defgroup LIS3MDL_Mag_Private_Variables LIS3MDL Mag Private Variables
* @{
*/
MAGNETO_DrvTypeDef Lis3mdlMagDrv =
{
LIS3MDL_MagInit,
LIS3MDL_MagDeInit,
LIS3MDL_MagReadID,
0,
LIS3MDL_MagLowPower,
0,
0,
0,
0,
0,
0,
0,
LIS3MDL_MagReadXYZ
};
/**
* @}
*/
/** @defgroup LIS3MDL_Mag_Private_Functions LIS3MDL Mag Private Functions
* @{
*/
/**
* @brief Set LIS3MDL Magnetometer Initialization.
* @param LIS3MDL_InitStruct: pointer to a LIS3MDL_MagInitTypeDef structure
* that contains the configuration setting for the LIS3MDL.
*/
void LIS3MDL_MagInit(MAGNETO_InitTypeDef LIS3MDL_InitStruct)
{
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG1, LIS3MDL_InitStruct.Register1);
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG2, LIS3MDL_InitStruct.Register2);
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG3, LIS3MDL_InitStruct.Register3);
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG4, LIS3MDL_InitStruct.Register4);
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG5, LIS3MDL_InitStruct.Register5);
}
/**
* @brief LIS3MDL Magnetometer De-initialization.
*/
void LIS3MDL_MagDeInit(void)
{
uint8_t ctrl = 0x00;
/* Read control register 1 value */
ctrl = SENSOR_IO_Read(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG3);
/* Clear Selection Mode bits */
ctrl &= ~(LIS3MDL_MAG_SELECTION_MODE);
/* Set Power down */
ctrl |= LIS3MDL_MAG_POWERDOWN2_MODE;
/* write back control register */
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG3, ctrl);
}
/**
* @brief Read LIS3MDL ID.
* @retval ID
*/
uint8_t LIS3MDL_MagReadID(void)
{
/* IO interface initialization */
SENSOR_IO_Init();
/* Read value at Who am I register address */
return (SENSOR_IO_Read(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_WHO_AM_I_REG));
}
/**
* @brief Set/Unset Magnetometer in low power mode.
* @param status 0 means disable Low Power Mode, otherwise Low Power Mode is enabled
*/
void LIS3MDL_MagLowPower(uint16_t status)
{
uint8_t ctrl = 0;
/* Read control register 1 value */
ctrl = SENSOR_IO_Read(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG3);
/* Clear Low Power Mode bit */
ctrl &= ~(0x20);
/* Set Low Power Mode */
if(status)
{
ctrl |= LIS3MDL_MAG_CONFIG_LOWPOWER_MODE;
}else
{
ctrl |= LIS3MDL_MAG_CONFIG_NORMAL_MODE;
}
/* write back control register */
SENSOR_IO_Write(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG3, ctrl);
}
/**
* @brief Read X, Y & Z Magnetometer values
* @param pData: Data out pointer
*/
void LIS3MDL_MagReadXYZ(int16_t* pData)
{
int16_t pnRawData[3];
uint8_t ctrlm= 0;
uint8_t buffer[6];
uint8_t i = 0;
float sensitivity = 0;
/* Read the magnetometer control register content */
ctrlm = SENSOR_IO_Read(LIS3MDL_MAG_I2C_ADDRESS_HIGH, LIS3MDL_MAG_CTRL_REG2);
/* Read output register X, Y & Z acceleration */
SENSOR_IO_ReadMultiple(LIS3MDL_MAG_I2C_ADDRESS_HIGH, (LIS3MDL_MAG_OUTX_L | 0x80), buffer, 6);
for(i=0; i<3; i++)
{
pnRawData[i]=((((uint16_t)buffer[2*i+1]) << 8) + (uint16_t)buffer[2*i]);
}
/* Normal mode */
/* Switch the sensitivity value set in the CRTL_REG2 */
switch(ctrlm & 0x60)
{
case LIS3MDL_MAG_FS_4_GA:
sensitivity = LIS3MDL_MAG_SENSITIVITY_FOR_FS_4GA;
break;
case LIS3MDL_MAG_FS_8_GA:
sensitivity = LIS3MDL_MAG_SENSITIVITY_FOR_FS_8GA;
break;
case LIS3MDL_MAG_FS_12_GA:
sensitivity = LIS3MDL_MAG_SENSITIVITY_FOR_FS_12GA;
break;
case LIS3MDL_MAG_FS_16_GA:
sensitivity = LIS3MDL_MAG_SENSITIVITY_FOR_FS_16GA;
break;
}
/* Obtain the mGauss value for the three axis */
for(i=0; i<3; i++)
{
pData[i]=( int16_t )(pnRawData[i] * sensitivity);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,232 @@
/**
******************************************************************************
* @file lis3mdl.h
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief LIS3MDL header driver file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LIS3MDL__H
#define __LIS3MDL__H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/magneto.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup LIS3MDL
* @{
*/
/** @defgroup LIS3MDL_Exported_Constants LIS3MDL Exported Constants
* @{
*/
/************** I2C Address *****************/
#define LIS3MDL_MAG_I2C_ADDRESS_LOW ((uint8_t)0x38) // SAD[0] = 0
#define LIS3MDL_MAG_I2C_ADDRESS_HIGH ((uint8_t)0x3C) // SAD[0] = 1
/************** Who am I *******************/
#define I_AM_LIS3MDL ((uint8_t)0x3D)
/************** Device Register *******************/
#define LIS3MDL_MAG_WHO_AM_I_REG 0x0F
#define LIS3MDL_MAG_CTRL_REG1 0x20
#define LIS3MDL_MAG_CTRL_REG2 0x21
#define LIS3MDL_MAG_CTRL_REG3 0x22
#define LIS3MDL_MAG_CTRL_REG4 0x23
#define LIS3MDL_MAG_CTRL_REG5 0x24
#define LIS3MDL_MAG_STATUS_REG 0x27
#define LIS3MDL_MAG_OUTX_L 0x28
#define LIS3MDL_MAG_OUTX_H 0x29
#define LIS3MDL_MAG_OUTY_L 0x2A
#define LIS3MDL_MAG_OUTY_H 0x2B
#define LIS3MDL_MAG_OUTZ_L 0x2C
#define LIS3MDL_MAG_OUTZ_H 0x2D
#define LIS3MDL_MAG_TEMP_OUT_L 0x2E
#define LIS3MDL_MAG_TEMP_OUT_H 0x2F
#define LIS3MDL_MAG_INT_CFG 0x30
#define LIS3MDL_MAG_INT_SRC 0x31
#define LIS3MDL_MAG_INT_THS_L 0x32
#define LIS3MDL_MAG_INT_THS_H 0x33
/* Mag Temperature Sensor Control*/
#define LIS3MDL_MAG_TEMPSENSOR_ENABLE ((uint8_t) 0x80) /*!< Temp sensor Enable */
#define LIS3MDL_MAG_TEMPSENSOR_DISABLE ((uint8_t) 0x00) /*!< Temp sensor Disable */
/* Mag_XY-axis Operating Mode */
#define LIS3MDL_MAG_OM_XY_LOWPOWER ((uint8_t) 0x00)
#define LIS3MDL_MAG_OM_XY_MEDIUM ((uint8_t) 0x20)
#define LIS3MDL_MAG_OM_XY_HIGH ((uint8_t) 0x40)
#define LIS3MDL_MAG_OM_XY_ULTRAHIGH ((uint8_t) 0x60)
/* Mag Data Rate */
#define LIS3MDL_MAG_ODR_0_625_HZ ((uint8_t) 0x00) /*!< Output Data Rate = 0.625 Hz */
#define LIS3MDL_MAG_ODR_1_25_HZ ((uint8_t) 0x04) /*!< Output Data Rate = 1.25 Hz */
#define LIS3MDL_MAG_ODR_2_5_HZ ((uint8_t) 0x08) /*!< Output Data Rate = 2.5 Hz */
#define LIS3MDL_MAG_ODR_5_0_HZ ((uint8_t) 0x0C) /*!< Output Data Rate = 5.0 Hz */
#define LIS3MDL_MAG_ODR_10_HZ ((uint8_t) 0x10) /*!< Output Data Rate = 10 Hz */
#define LIS3MDL_MAG_ODR_20_HZ ((uint8_t) 0x14) /*!< Output Data Rate = 20 Hz */
#define LIS3MDL_MAG_ODR_40_HZ ((uint8_t) 0x18) /*!< Output Data Rate = 40 Hz */
#define LIS3MDL_MAG_ODR_80_HZ ((uint8_t) 0x1C) /*!< Output Data Rate = 80 Hz */
/* Mag Data Rate */
#define LMS303C_MAG_SELFTEST_DISABLE ((uint8_t 0x00)
#define LMS303C_MAG_SELFTEST_ENABLE ((uint8_t 0x01)
/* Mag Full Scale */
#define LIS3MDL_MAG_FS_DEFAULT ((uint8_t) 0x00)
#define LIS3MDL_MAG_FS_4_GA ((uint8_t) 0x00)
#define LIS3MDL_MAG_FS_8_GA ((uint8_t) 0x20)
#define LIS3MDL_MAG_FS_12_GA ((uint8_t) 0x40)
#define LIS3MDL_MAG_FS_16_GA ((uint8_t) 0x60) /*!< Full scale = ±16 Gauss */
/* Mag_Reboot */
#define LIS3MDL_MAG_REBOOT_DEFAULT ((uint8_t) 0x00)
#define LIS3MDL_MAG_REBOOT_ENABLE ((uint8_t) 0x08)
/* Mag Soft reset */
#define LIS3MDL_MAG_SOFT_RESET_DEFAULT ((uint8_t) 0x00)
#define LIS3MDL_MAG_SOFT_RESET_ENABLE ((uint8_t) 0x04)
/* Mag_Communication_Mode */
#define LIS3MDL_MAG_SIM_4_WIRE ((uint8_t) 0x00)
#define LIS3MDL_MAG_SIM_3_WIRE ((uint8_t) 0x04)
/* Mag Lowpower mode config */
#define LIS3MDL_MAG_CONFIG_NORMAL_MODE ((uint8_t) 0x00)
#define LIS3MDL_MAG_CONFIG_LOWPOWER_MODE ((uint8_t) 0x20)
/* Mag Operation Mode */
#define LIS3MDL_MAG_SELECTION_MODE ((uint8_t) 0x03) /* CTRL_REG3 */
#define LIS3MDL_MAG_CONTINUOUS_MODE ((uint8_t) 0x00)
#define LIS3MDL_MAG_SINGLE_MODE ((uint8_t) 0x01)
#define LIS3MDL_MAG_POWERDOWN1_MODE ((uint8_t) 0x02)
#define LIS3MDL_MAG_POWERDOWN2_MODE ((uint8_t) 0x03)
/* Mag_Z-axis Operation Mode */
#define LIS3MDL_MAG_OM_Z_LOWPOWER ((uint8_t) 0x00)
#define LIS3MDL_MAG_OM_Z_MEDIUM ((uint8_t) 0x04)
#define LIS3MDL_MAG_OM_Z_HIGH ((uint8_t) 0x08)
#define LIS3MDL_MAG_OM_Z_ULTRAHIGH ((uint8_t) 0x0C)
/* Mag Big little-endian selection */
#define LIS3MDL_MAG_BLE_LSB ((uint8_t) 0x00)
#define LIS3MDL_MAG_BLE_MSB ((uint8_t) 0x02)
/* Mag_Bloc_update_magnetic_data */
#define LIS3MDL_MAG_BDU_CONTINUOUS ((uint8_t) 0x00)
#define LIS3MDL_MAG_BDU_MSBLSB ((uint8_t) 0x40)
/* Magnetometer_Sensitivity */
#define LIS3MDL_MAG_SENSITIVITY_FOR_FS_4GA ((float)0.14f) /**< Sensitivity value for 4 gauss full scale [mgauss/LSB] */
#define LIS3MDL_MAG_SENSITIVITY_FOR_FS_8GA ((float)0.29f) /**< Sensitivity value for 8 gauss full scale [mgauss/LSB] */
#define LIS3MDL_MAG_SENSITIVITY_FOR_FS_12GA ((float)0.43f) /**< Sensitivity value for 12 gauss full scale [mgauss/LSB] */
#define LIS3MDL_MAG_SENSITIVITY_FOR_FS_16GA ((float)0.58f) /**< Sensitivity value for 16 gauss full scale [mgauss/LSB] */
/**
* @}
*/
/** @defgroup LIS3MDL_Exported_Functions LIS3MDL Exported Functions
* @{
*/
void LIS3MDL_MagInit(MAGNETO_InitTypeDef LIS3MDL_InitStruct);
void LIS3MDL_MagDeInit(void);
uint8_t LIS3MDL_MagReadID(void);
void LIS3MDL_MagLowPower(uint16_t status);
void LIS3MDL_MagReadXYZ(int16_t* pData);
/**
* @}
*/
/** @defgroup LIS3MDL_Imported_Functions LIS3MDL Imported Functions
* @{
*/
/* IO functions */
extern void SENSOR_IO_Init(void);
extern void SENSOR_IO_DeInit(void);
extern void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
/**
* @}
*/
/** @defgroup LIS3MDL_Imported_Globals Imported Globals
* @{
*/
/* MAG driver structure */
extern MAGNETO_DrvTypeDef Lis3mdlMagDrv;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LIS3MDL__H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,246 @@
/**
******************************************************************************
* @file lps22hb.c
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief This file provides a set of functions needed to manage the LPS22HB
* pressure and temperature devices
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "lps22hb.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup LPS22HB LPS22HB
* @{
*/
/** @defgroup LPS22HB_Private_FunctionsPrototypes LPS22HB Private Functions Prototypes
* @{
*/
static void LPS22HB_Init(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup LPS22HB_Private_Variables LPS22HB Private Variables
* @{
*/
/* Pressure Private Variables */
PSENSOR_DrvTypeDef LPS22HB_P_Drv =
{
LPS22HB_P_Init,
LPS22HB_P_ReadID,
LPS22HB_P_ReadPressure
};
/* Temperature Private Variables */
TSENSOR_DrvTypeDef LPS22HB_T_Drv =
{
LPS22HB_T_Init,
0,
0,
LPS22HB_T_ReadTemp
};
/**
* @}
*/
/** @defgroup LPS22HB_Pressure_Private_Functions LPS22HB Pressure Private Functions
* @{
*/
/**
* @brief Set LPS22HB pressure sensor Initialization.
*/
void LPS22HB_P_Init(uint16_t DeviceAddr)
{
LPS22HB_Init(DeviceAddr);
}
/**
* @brief Read LPS22HB ID.
* @retval ID
*/
uint8_t LPS22HB_P_ReadID(uint16_t DeviceAddr)
{
uint8_t ctrl = 0x00;
/* IO interface initialization */
SENSOR_IO_Init();
/* Read value at Who am I register address */
ctrl = SENSOR_IO_Read(DeviceAddr, LPS22HB_WHO_AM_I_REG);
return ctrl;
}
/**
* @brief Read pressure value of LPS22HB
* @retval pressure value
*/
float LPS22HB_P_ReadPressure(uint16_t DeviceAddr)
{
int32_t raw_press;
uint8_t buffer[3];
uint32_t tmp = 0;
uint8_t i;
for(i = 0; i < 3; i++)
{
buffer[i] = SENSOR_IO_Read(DeviceAddr, (LPS22HB_PRESS_OUT_XL_REG + i));
}
/* Build the raw data */
for(i = 0; i < 3; i++)
tmp |= (((uint32_t)buffer[i]) << (8 * i));
/* convert the 2's complement 24 bit to 2's complement 32 bit */
if(tmp & 0x00800000)
tmp |= 0xFF000000;
raw_press = ((int32_t)tmp);
raw_press = (raw_press * 100) / 4096;
return (float)((float)raw_press / 100.0f);
}
/**
* @}
*/
/** @defgroup LPS22HB_Temperature_Private_Functions LPS22HB Temperature Private Functions
* @{
*/
/**
* @brief Set LPS22HB temperature sensor Initialization.
* @param DeviceAddr: I2C device address
* @param InitStruct: pointer to a TSENSOR_InitTypeDef structure
* that contains the configuration setting for the HTS221.
* @retval None
*/
void LPS22HB_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct)
{
LPS22HB_Init(DeviceAddr);
}
/**
* @brief Read temperature value of LPS22HB
* @param DeviceAddr: I2C device address
* @retval temperature value
*/
float LPS22HB_T_ReadTemp(uint16_t DeviceAddr)
{
int16_t raw_data;
uint8_t buffer[2];
uint16_t tmp;
uint8_t i;
for(i = 0; i < 2; i++)
{
buffer[i] = SENSOR_IO_Read(DeviceAddr, (LPS22HB_TEMP_OUT_L_REG + i));
}
/* Build the raw tmp */
tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0];
raw_data = (tmp * 10) / 100;
return ((float)(raw_data / 10.0f));
}
/**
* @}
*/
/** @addtogroup LPS22HB_Private_Functions LPS22HB Private functions
* @{
*/
/**
* @brief Set LPS22HB Initialization.
* @param DeviceAddr: I2C device address
* @retval None
*/
static void LPS22HB_Init(uint16_t DeviceAddr)
{
uint8_t tmp;
/* Set Power mode */
tmp = SENSOR_IO_Read(DeviceAddr, LPS22HB_RES_CONF_REG);
tmp &= ~LPS22HB_LCEN_MASK;
tmp |= (uint8_t)0x01; /* Set low current mode */
SENSOR_IO_Write(DeviceAddr, LPS22HB_RES_CONF_REG, tmp);
/* Read CTRL_REG1 */
tmp = SENSOR_IO_Read(DeviceAddr, LPS22HB_CTRL_REG1);
/* Set default ODR */
tmp &= ~LPS22HB_ODR_MASK;
tmp |= (uint8_t)0x30; /* Set ODR to 25Hz */
/* Enable BDU */
tmp &= ~LPS22HB_BDU_MASK;
tmp |= ((uint8_t)0x02);
/* Apply settings to CTRL_REG1 */
SENSOR_IO_Write(DeviceAddr, LPS22HB_CTRL_REG1, tmp);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,534 @@
/**
******************************************************************************
* @file lps22hb.h
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief LPS22HB header driver file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LPS22HB__H
#define __LPS22HB__H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/psensor.h"
#include "../Common/tsensor.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup LPS22HB
* @{
*/
/** @defgroup LPS22HB_Exported_Macros LPS22HB Exported Macros
* @{
*/
/**
* @brief Bitfield positioning.
*/
#define LPS22HB_BIT(x) ((uint8_t)x)
/**
* @}
*/
/** @defgroup LPS22HB_Exported_Constants LPS22HB Exported Constants
* @{
*/
/**
* @brief Device Identification register.
* Read
* Default value: 0xB1
* 7:0 This read-only register contains the device identifier that, for LPS22HB, is set to B1h.
*/
#define LPS22HB_WHO_AM_I_REG (uint8_t)0x0F
/**
* @brief Device Identification value.
*/
#define LPS22HB_WHO_AM_I_VAL (uint8_t)0xB1
/**
* @brief Reference Pressure Register(LSB data)
* Read/write
* Default value: 0x00
* 7:0 REFL7-0: Lower part of the reference pressure value that
* is sum to the sensor output pressure.
*/
#define LPS22HB_REF_P_XL_REG (uint8_t)0x15
/**
* @brief Reference Pressure Register (Middle data)
* Read/write
* Default value: 0x00
* 7:0 REFL15-8: Middle part of the reference pressure value that
* is sum to the sensor output pressure.
*/
#define LPS22HB_REF_P_L_REG (uint8_t)0x16
/**
* @brief Reference Pressure Register (MSB data)
* Read/write
* Default value: 0x00
* 7:0 REFL23-16 Higest part of the reference pressure value that
* is sum to the sensor output pressure.
*/
#define LPS22HB_REF_P_H_REG (uint8_t)0x17
/**
* @brief Pressure and temperature resolution mode Register
* Read/write
* Default value: 0x05
* 7:2 These bits must be set to 0 for proper operation of the device
* 1: Reserved
* 0 LC_EN: Low Current Mode Enable. Default 0
*/
#define LPS22HB_RES_CONF_REG (uint8_t)0x1A
#define LPS22HB_LCEN_MASK (uint8_t)0x01
/**
* @brief Control Register 1
* Read/write
* Default value: 0x00
* 7: This bit must be set to 0 for proper operation of the device
* 6:4 ODR2, ODR1, ODR0: output data rate selection.Default 000
* ODR2 | ODR1 | ODR0 | Pressure output data-rate(Hz) | Pressure output data-rate(Hz)
* ----------------------------------------------------------------------------------
* 0 | 0 | 0 | one shot | one shot
* 0 | 0 | 1 | 1 | 1
* 0 | 1 | 0 | 10 | 10
* 0 | 1 | 1 | 25 | 25
* 1 | 0 | 0 | 50 | 50
* 1 | 0 | 1 | 75 | 75
* 1 | 1 | 0 | Reserved | Reserved
* 1 | 1 | 1 | Reserved | Reserved
*
* 3 EN_LPFP: Enable Low Pass filter on Pressure data. Default value:0
* 2:LPF_CFG Low-pass configuration register. (0: Filter cutoff is ODR/9; 1: filter cutoff is ODR/20)
* 1 BDU: block data update. 0 - continuous update; 1 - output registers not updated until MSB and LSB reading.
* 0 SIM: SPI Serial Interface Mode selection. 0 - SPI 4-wire; 1 - SPI 3-wire
*/
#define LPS22HB_CTRL_REG1 (uint8_t)0x10
#define LPS22HB_ODR_MASK (uint8_t)0x70
#define LPS22HB_LPFP_MASK (uint8_t)0x08
#define LPS22HB_LPFP_CUTOFF_MASK (uint8_t)0x04
#define LPS22HB_BDU_MASK (uint8_t)0x02
#define LPS22HB_SIM_MASK (uint8_t)0x01
#define LPS22HB_LPFP_BIT LPS22HB_BIT(3)
/**
* @brief Control Register 2
* Read/write
* Default value: 0x10
* 7 BOOT: Reboot memory content. 0: normal mode; 1: reboot memory content. Self-clearing upon completation
* 6 FIFO_EN: FIFO Enable. 0: disable; 1: enable
* 5 STOP_ON_FTH: Stop on FIFO Threshold FIFO Watermark level use. 0: disable; 1: enable
* 4 IF_ADD_INC: Register address automatically incrementeed during a multiple byte access with a serial interface (I2C or SPI).
* Default value 1.( 0: disable; 1: enable)
* 3 I2C DIS: Disable I2C interface 0: I2C Enabled; 1: I2C disabled
* 2 SWRESET: Software reset. 0: normal mode; 1: SW reset. Self-clearing upon completation
* 1 AUTO_ZERO: Autozero enable. 0: normal mode; 1: autozero enable.
* 0 ONE_SHOT: One shot enable. 0: waiting for start of conversion; 1: start for a new dataset
*/
#define LPS22HB_CTRL_REG2 (uint8_t)0x11
#define LPS22HB_BOOT_BIT LPS22HB_BIT(7)
#define LPS22HB_FIFO_EN_BIT LPS22HB_BIT(6)
#define LPS22HB_WTM_EN_BIT LPS22HB_BIT(5)
#define LPS22HB_ADD_INC_BIT LPS22HB_BIT(4)
#define LPS22HB_I2C_BIT LPS22HB_BIT(3)
#define LPS22HB_SW_RESET_BIT LPS22HB_BIT(2)
#define LPS22HB_FIFO_EN_MASK (uint8_t)0x40
#define LPS22HB_WTM_EN_MASK (uint8_t)0x20
#define LPS22HB_ADD_INC_MASK (uint8_t)0x10
#define LPS22HB_I2C_MASK (uint8_t)0x08
#define LPS22HB_ONE_SHOT_MASK (uint8_t)0x01
/**
* @brief CTRL Reg3 Interrupt Control Register
* Read/write
* Default value: 0x00
* 7 INT_H_L: Interrupt active high, low. 0:active high; 1: active low.
* 6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: Push-pull; 1: open drain.
* 5 F_FSS5: FIFO full flag on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable).
* 4 F_FTH: FIFO threshold (watermark) status on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable).
* 3 F_OVR: FIFO overrun interrupt on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable).
* 2 DRDY: Data-ready signal on INT_DRDY pin. Defaul value: 0. (0: Diasable; 1 : Enable).
* 1:0 INT_S2, INT_S1: data signal on INT pad control bits.
* INT_S2 | INT_S1 | INT pin
* ------------------------------------------------------
* 0 | 0 | Data signal( in order of priority:PTH_DRDY or F_FTH or F_OVR_or F_FSS5
* 0 | 1 | Pressure high (P_high)
* 1 | 0 | Pressure low (P_low)
* 1 | 1 | P_low OR P_high
*/
#define LPS22HB_CTRL_REG3 (uint8_t)0x12
#define LPS22HB_PP_OD_BIT LPS22HB_BIT(6)
#define LPS22HB_FIFO_FULL_BIT LPS22HB_BIT(5)
#define LPS22HB_FIFO_FTH_BIT LPS22HB_BIT(4)
#define LPS22HB_FIFO_OVR_BIT LPS22HB_BIT(3)
#define LPS22HB_DRDY_BIT LPS22HB_BIT(2)
#define LPS22HB_INT_H_L_MASK (uint8_t)0x80
#define LPS22HB_PP_OD_MASK (uint8_t)0x40
#define LPS22HB_FIFO_FULL_MASK (uint8_t)0x20
#define LPS22HB_FIFO_FTH_MASK (uint8_t)0x10
#define LPS22HB_FIFO_OVR_MASK (uint8_t)0x08
#define LPS22HB_DRDY_MASK (uint8_t)0x04
#define LPS22HB_INT_S12_MASK (uint8_t)0x03
/**
* @brief Interrupt Differential configuration Register
* Read/write
* Default value: 0x00.
* 7 AUTORIFP: AutoRifP Enable
* 6 RESET_ARP: Reset AutoRifP function
* 4 AUTOZERO: Autozero enabled
* 5 RESET_AZ: Reset Autozero Function
* 3 DIFF_EN: Interrupt generation enable
* 2 LIR: Latch Interrupt request into INT_SOURCE register. 0 - interrupt request not latched
* 1 - interrupt request latched
* 1 PL_E: Enable interrupt generation on differential pressure low event. 0 - disable; 1 - enable
* 0 PH_E: Enable interrupt generation on differential pressure high event. 0 - disable; 1 - enable
*/
#define LPS22HB_INTERRUPT_CFG_REG (uint8_t)0x0B
#define LPS22HB_DIFF_EN_BIT LPS22HB_BIT(3)
#define LPS22HB_LIR_BIT LPS22HB_BIT(2)
#define LPS22HB_PLE_BIT LPS22HB_BIT(1)
#define LPS22HB_PHE_BIT LPS22HB_BIT(0)
#define LPS22HB_AUTORIFP_MASK (uint8_t)0x80
#define LPS22HB_RESET_ARP_MASK (uint8_t)0x40
#define LPS22HB_AUTOZERO_MASK (uint8_t)0x20
#define LPS22HB_RESET_AZ_MASK (uint8_t)0x10
#define LPS22HB_DIFF_EN_MASK (uint8_t)0x08
#define LPS22HB_LIR_MASK (uint8_t)0x04
#define LPS22HB_PLE_MASK (uint8_t)0x02
#define LPS22HB_PHE_MASK (uint8_t)0x01
/**
* @brief Interrupt source Register (It is cleared by reading it)
* Read
* 7 BOOT_STATUS: If 1 indicates that the Boot (Reboot) phase is running.
* 6:3 Reserved: Keep these bits at 0
* 2 IA: Interrupt Active.0: no interrupt has been generated
* 1: one or more interrupt events have been generated.
* 1 PL: Differential pressure Low. 0: no interrupt has been generated
* 1: Low differential pressure event has occurred.
* 0 PH: Differential pressure High. 0: no interrupt has been generated
* 1: High differential pressure event has occurred.
*/
#define LPS22HB_INTERRUPT_SOURCE_REG (uint8_t)0x25
#define LPS22HB_BOOT_STATUS_BIT LPS22HB_BIT(7)
#define LPS22HB_IA_BIT LPS22HB_BIT(2)
#define LPS22HB_PL_BIT LPS22HB_BIT(1)
#define LPS22HB_PH_BIT LPS22HB_BIT(0)
#define LPS22HB_BOOT_STATUS_MASK (uint8_t)0x80
#define LPS22HB_IA_MASK (uint8_t)0x04
#define LPS22HB_PL_MASK (uint8_t)0x02
#define LPS22HB_PH_MASK (uint8_t)0x01
/**
* @brief Status Register
* Read
* 7:6 Reserved: 0
* 5 T_OR: Temperature data overrun. 0: no overrun has occurred
* 1: a new data for temperature has overwritten the previous one.
* 4 P_OR: Pressure data overrun. 0: no overrun has occurred
* 1: new data for pressure has overwritten the previous one.
* 3:2 Reserved: 0
* 1 T_DA: Temperature data available. 0: new data for temperature is not yet available
* 1: new data for temperature is available.
* 0 P_DA: Pressure data available. 0: new data for pressure is not yet available
* 1: new data for pressure is available.
*/
#define LPS22HB_STATUS_REG (uint8_t)0x27
#define LPS22HB_TOR_BIT LPS22HB_BIT(5)
#define LPS22HB_POR_BIT LPS22HB_BIT(4)
#define LPS22HB_TDA_BIT LPS22HB_BIT(1)
#define LPS22HB_PDA_BIT LPS22HB_BIT(0)
#define LPS22HB_TOR_MASK (uint8_t)0x20
#define LPS22HB_POR_MASK (uint8_t)0x10
#define LPS22HB_TDA_MASK (uint8_t)0x02
#define LPS22HB_PDA_MASK (uint8_t)0x01
/**
* @brief Pressure data (LSB) register.
* Read
* Default value: 0x00.(To be verified)
* POUT7 - POUT0: Pressure data LSB (2's complement).
* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L &
* PRESS_OUT_XL)[dec]/4096.
*/
#define LPS22HB_PRESS_OUT_XL_REG (uint8_t)0x28
/**
* @brief Pressure data (Middle part) register.
* Read
* Default value: 0x80.
* POUT15 - POUT8: Pressure data middle part (2's complement).
* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L &
* PRESS_OUT_XL)[dec]/4096.
*/
#define LPS22HB_PRESS_OUT_L_REG (uint8_t)0x29
/**
* @brief Pressure data (MSB) register.
* Read
* Default value: 0x2F.
* POUT23 - POUT16: Pressure data MSB (2's complement).
* Pressure output data: Pout(hPA)=(PRESS_OUT_H & PRESS_OUT_L &
* PRESS_OUT_XL)[dec]/4096.
*/
#define LPS22HB_PRESS_OUT_H_REG (uint8_t)0x2A
/**
* @brief Temperature data (LSB) register.
* Read
* Default value: 0x00.
* TOUT7 - TOUT0: temperature data LSB.
* Tout(degC)=TEMP_OUT/100
*/
#define LPS22HB_TEMP_OUT_L_REG (uint8_t)0x2B
/**
* @brief Temperature data (MSB) register.
* Read
* Default value: 0x00.
* TOUT15 - TOUT8: temperature data MSB.
* Tout(degC)=TEMP_OUT/100
*/
#define LPS22HBH_TEMP_OUT_H_REG (uint8_t)0x2C
/**
* @brief Threshold pressure (LSB) register.
* Read/write
* Default value: 0x00.
* 7:0 THS7-THS0: LSB Threshold pressure Low part of threshold value for pressure interrupt
* generation. The complete threshold value is given by THS_P_H & THS_P_L and is
* expressed as unsigned number. P_ths(hPA)=(THS_P_H & THS_P_L)[dec]/16.
*/
#define LPS22HB_THS_P_LOW_REG (uint8_t)0x0C
/**
* @brief Threshold pressure (MSB)
* Read/write
* Default value: 0x00.
* 7:0 THS15-THS8: MSB Threshold pressure. High part of threshold value for pressure interrupt
* generation. The complete threshold value is given by THS_P_H & THS_P_L and is
* expressed as unsigned number. P_ths(mbar)=(THS_P_H & THS_P_L)[dec]/16.
*/
#define LPS22HB_THS_P_HIGH_REG (uint8_t)0x0D
/**
* @brief FIFO control register
* Read/write
* Default value: 0x00
* 7:5 F_MODE2, F_MODE1, F_MODE0: FIFO mode selection.
* FM2 | FM1 | FM0 | FIFO MODE
* ---------------------------------------------------
* 0 | 0 | 0 | BYPASS MODE
* 0 | 0 | 1 | FIFO MODE. Stops collecting data when full
* 0 | 1 | 0 | STREAM MODE: Keep the newest measurements in the FIFO
* 0 | 1 | 1 | STREAM MODE until trigger deasserted, then change to FIFO MODE
* 1 | 0 | 0 | BYPASS MODE until trigger deasserted, then STREAM MODE
* 1 | 0 | 1 | Reserved for future use
* 1 | 1 | 0 | Reserved
* 1 | 1 | 1 | BYPASS mode until trigger deasserted, then FIFO MODE
*
* 4:0 WTM_POINT4-0 : FIFO Watermark level selection (0-31)
*/
#define LPS22HB_CTRL_FIFO_REG (uint8_t)0x14
#define LPS22HB_FIFO_MODE_MASK (uint8_t)0xE0
#define LPS22HB_WTM_POINT_MASK (uint8_t)0x1F
/**
* @brief FIFO Status register
* Read
* 7 FTH_FIFO: FIFO threshold status. 0:FIFO filling is lower than FTH level
* 1: FIFO is equal or higher than FTH level.
* 6 OVR: Overrun bit status. 0 - FIFO not full
* 1 - FIFO is full and at least one sample in the FIFO has been overwritten.
* 5:0 FSS: FIFO Stored data level. 000000: FIFO empty, 100000: FIFO is full and has 32 unread samples.
*/
#define LPS22HB_STATUS_FIFO_REG (uint8_t)0x26
#define LPS22HB_FTH_FIFO_BIT LPS22HB_BIT(7)
#define LPS22HB_OVR_FIFO_BIT LPS22HB_BIT(6)
#define LPS22HB_FTH_FIFO_MASK (uint8_t)0x80
#define LPS22HB_OVR_FIFO_MASK (uint8_t)0x40
#define LPS22HB_LEVEL_FIFO_MASK (uint8_t)0x3F
#define LPS22HB_FIFO_EMPTY (uint8_t)0x00
#define LPS22HB_FIFO_FULL (uint8_t)0x20
/**
* @brief Pressure offset register (LSB)
* Read/write
* Default value: 0x00
* 7:0 RPDS7-0:Pressure Offset for 1 point calibration (OPC) after soldering.
* This register contains the low part of the pressure offset value after soldering,for
* differential pressure computing. The complete value is given by RPDS_L & RPDS_H
* and is expressed as signed 2 complement value.
*/
#define LPS22HB_RPDS_L_REG (uint8_t)0x18
/**
* @brief Pressure offset register (MSB)
* Read/write
* Default value: 0x00
* 7:0 RPDS15-8:Pressure Offset for 1 point calibration (OPC) after soldering.
* This register contains the high part of the pressure offset value after soldering (see description RPDS_L)
*/
#define LPS22HB_RPDS_H_REG (uint8_t)0x19
/**
* @brief Clock Tree Configuration register
* Read/write
* Default value: 0x00
* 7:6 Reserved.
* 5: CTE: Clock Tree Enhancement
*/
#define LPS22HB_CLOCK_TREE_CONFIGURATION (uint8_t)0x43
#define LPS22HB_CTE_MASK (uint8_t)0x20
/**
* @}
*/
/** @defgroup LPS22HB_Pressure_Exported_Functions LPS22HB Pressure Exported Functions
* @{
*/
/* PRESSURE functions */
void LPS22HB_P_Init(uint16_t DeviceAddr);
uint8_t LPS22HB_P_ReadID(uint16_t DeviceAddr);
float LPS22HB_P_ReadPressure(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup HTS221_PressImported_Globals PRESSURE Imported Globals
* @{
*/
/* PRESSURE driver structure */
extern PSENSOR_DrvTypeDef LPS22HB_P_Drv;
/**
* @}
*/
/** @defgroup LPS22HB_Temperature_Exported_Functions LPS22HB Temperature Exported Functions
* @{
*/
/* TEMPERATURE functions */
void LPS22HB_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct);
float LPS22HB_T_ReadTemp(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup HTS221_TempImported_Globals Temperature Imported Globals
* @{
*/
/* Temperature driver structure */
extern TSENSOR_DrvTypeDef LPS22HB_T_Drv;
/**
* @}
*/
/** @defgroup LPS22HB_Imported_Functions LPS22HB Imported Functions
* @{
*/
/* IO functions */
extern void SENSOR_IO_Init(void);
extern void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LPS22HB__H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,661 @@
/**
******************************************************************************
* @file ls016b8uy.c
* @author MCD Application Team
* @version V1.0.0
* @date 10-May-2016
* @brief This file includes the LCD driver for LS016B8UY LCD.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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 "ls016b8uy.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ls016b8uy
* @brief This file provides a set of functions needed to drive the
* LS016B8UY LCD.
* @{
*/
/** @defgroup LS016B8UY_Private_TypesDefinitions
* @{
*/
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
} LS016B8UY_Rgb888;
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Variables
* @{
*/
LCD_DrvTypeDef ls016b8uy_drv =
{
ls016b8uy_Init,
ls016b8uy_ReadID,
ls016b8uy_DisplayOn,
ls016b8uy_DisplayOff,
ls016b8uy_SetCursor,
ls016b8uy_WritePixel,
ls016b8uy_ReadPixel,
ls016b8uy_SetDisplayWindow,
ls016b8uy_DrawHLine,
ls016b8uy_DrawVLine,
ls016b8uy_GetLcdPixelWidth,
ls016b8uy_GetLcdPixelHeight,
ls016b8uy_DrawBitmap,
ls016b8uy_DrawRGBImage,
};
static uint16_t WindowsXstart = 0;
static uint16_t WindowsYstart = 0;
static uint16_t WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH-1;
static uint16_t WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
/**
* @}
*/
/** @defgroup LS016B8UY_Private_FunctionPrototypes
* @{
*/
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos);
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata);
/**
* @}
*/
/** @defgroup LS016B8UY_Private_Functions
* @{
*/
/**
* @brief Initialize the LS016B8UY LCD Component.
* @param None
* @retval None
*/
void ls016b8uy_Init(void)
{
uint8_t parameter[4];
/* Initialize LS016B8UY low level bus layer ----------------------------------*/
LCD_IO_Init();
parameter[0] = 0x00; /* VSYNC output */
ls016b8uy_WriteReg(LCD_CMD_VSYNC_OUTPUT, parameter, 1);
parameter[0] = 0x06; /* 18 bits color mode */
ls016b8uy_WriteReg(LCD_CMD_COLOR_MODE, parameter, 1);
parameter[0] = 0x01; /* Panel setting command <No.1 UN-Lock> */
parameter[1] = 0xFE;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_1, parameter, 2);
parameter[0] = 0xDE; /* Panel setting command <No.2 UN-Lock> */
parameter[1] = 0x21;
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_2, parameter, 2);
parameter[0] = 0x05; /* V-Porch setting */
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_V_PORCH, parameter, 2);
parameter[0] = 0x05; /* Idle mode V-Porch setting */
parameter[1] = 0x33;
ls016b8uy_WriteReg(LCD_CMD_PANEL_IDLE_V_PORCH, parameter, 2);
parameter[0] = 0x04; /* panel timing setting */
parameter[1] = 0x03;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_1, parameter, 2);
parameter[0] = 0x5E; /* panel timing setting */
parameter[1] = 0x08;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_2, parameter, 2);
parameter[0] = 0x0A; /* panel timing setting */
parameter[1] = 0x0C;
parameter[2] = 0x02;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_3, parameter, 3);
parameter[0] = 0x03; /* panel timing setting */
parameter[1] = 0x04;
ls016b8uy_WriteReg(LCD_CMD_PANEL_TIMING_4, parameter, 2);
parameter[0] = 0x0C; /* panel power setting */
ls016b8uy_WriteReg(LCD_CMD_PANEL_POWER, parameter, 1);
parameter[0] = 0x02; /* Oscillator Setting = 2MHz */
ls016b8uy_WriteReg(LCD_CMD_OSCILLATOR, parameter, 1);
parameter[0] = 0x53; /* GVDD = 4.76V setting */
ls016b8uy_WriteReg(LCD_CMD_GVDD, parameter, 1);
parameter[0] = 0x00; /* Reload MTP After SLPOUT */
parameter[1] = 0x45; /* VCOMH=3.76V */
ls016b8uy_WriteReg(LCD_CMD_RELOAD_MTP_VCOMH, parameter, 2);
parameter[0] = 0x03; /* OP-Amp Ability. (Normal) */
parameter[1] = 0x12; /* Step-up Cycle for AVDD Booster Freq./4 */
ls016b8uy_WriteReg(LCD_CMD_OPAMP, parameter, 2);
parameter[0] = 0x00; /* Tearing Effect Option (00h:VSYNC Interface OFF, 01h:VSYNC Interface ON) */
ls016b8uy_WriteReg(LCD_CMD_TEARING_EFFECT, parameter, 1);
ls016b8uy_WriteReg(LCD_CMD_PANEL_SETTING_LOCK, parameter, 0); /* Panel setting command <Lock> */
ls016b8uy_WriteReg(LCD_CMD_SLEEP_OUT, parameter, 0); /* Sleep Out Command */
LCD_IO_Delay(150); /* Wait for 150ms */
parameter[0] = 0x00; /* CASET */
parameter[1] = 0x1E;
parameter[2] = 0x00;
parameter[3] = 0xD1;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00; /* RASET */
parameter[1] = 0x00;
parameter[2] = 0x00;
parameter[3] = 0xB3;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
parameter[0] = 0x83; /* Normal display for Driver Down side */
ls016b8uy_WriteReg(LCD_CMD_NORMAL_DISPLAY, parameter, 1);
ls016b8uy_DisplayOn(); /* Display ON command */
}
/**
* @brief Enables the Display.
* @param None
* @retval None
*/
void ls016b8uy_DisplayOn(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_ON, (uint8_t*)NULL, 0); /* Display ON command */
ls016b8uy_WriteReg(LCD_CMD_IDLE_MODE_OFF, (uint8_t*)NULL, 0); /* Idle mode OFF command */
}
/**
* @brief Disables the Display.
* @param None
* @retval None
*/
void ls016b8uy_DisplayOff(void)
{
ls016b8uy_WriteReg(LCD_CMD_DISPLAY_OFF, (uint8_t*)NULL, 0); /* Display OFF command */
LCD_IO_Delay(20); /* Wait for 20ms */
ls016b8uy_WriteReg(LCD_CMD_SLEEP_IN, (uint8_t*)NULL, 0); /* Sleep In Command */
LCD_IO_Delay(150); /* Wait for 150ms */
}
/**
* @brief Get the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t ls016b8uy_GetLcdPixelWidth(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_WIDTH;
}
/**
* @brief Get the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t ls016b8uy_GetLcdPixelHeight(void)
{
return (uint16_t)LS016B8UY_LCD_PIXEL_HEIGHT;
}
/**
* @brief Get the LS016B8UY ID.
* @param None
* @retval The LS016B8UY ID
*/
uint16_t ls016b8uy_ReadID(void)
{
LCD_IO_Init();
/* TODO : LCD read ID command not known for now, so assumption that the connected LCD is LS016B8UY */
return (LS016B8UY_ID);
}
/**
* @brief Set Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void ls016b8uy_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t parameter[4];
parameter[0] = 0x00; /* CASET */
parameter[1] = 0x1E + Xpos;
parameter[2] = 0x00;
parameter[3] = 0xD1 + Xpos;
ls016b8uy_WriteReg(LCD_CMD_CASET, parameter, 4);
parameter[0] = 0x00; /* RASET */
parameter[1] = 0x00 + Ypos;
parameter[2] = 0x00;
parameter[3] = 0xB3 + Ypos;
ls016b8uy_WriteReg(LCD_CMD_RASET, parameter, 4);
}
/**
* @brief Write pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color in RGB565 format
* @retval None
*/
void ls016b8uy_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2;
r = (RGBCode & 0xF800) >> 11; /* Extract red component from RGB565 pixel data */
g = (RGBCode & 0x07E0) >> 5; /* Extract green component from RGB565 pixel data */
b = (RGBCode & 0x001F) >> 0; /* Extract blue component from RGB565 pixel data */
/* Prepare data to write with new pixel components and read old pixel component */
rgb888_part1 = (r << 11) + (g << 2);
rgb888_part2 = (b << 11);
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Write RAM data */
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
}
/**
* @brief Read pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval The RGB pixel color in RGB565 format
*/
uint16_t ls016b8uy_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint8_t r, g, b;
uint16_t rgb565;
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Read RGB888 data from LCD RAM */
rgb888 = ls016b8uy_ReadPixel_rgb888(Xpos, Ypos);
/* Convert RGB888 to RGB565 */
r = ((rgb888.red & 0xF8) >> 3); /* Extract the red component 5 most significant bits */
g = ((rgb888.green & 0xFC) >> 2); /* Extract the green component 6 most significant bits */
b = ((rgb888.blue & 0xF8) >> 3); /* Extract the blue component 5 most significant bits */
rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0);
return (rgb565);
}
/**
* @brief Writes to the selected LCD register.
* @param Command: command value (or register address as named in LS016B8UY doc).
* @param Parameters: pointer on parameters value (if command uses one or several parameters).
* @param NbParameters: number of command parameters (0 if no parameter)
* @retval None
*/
void ls016b8uy_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters)
{
uint8_t i;
/* Send command */
LCD_IO_WriteReg(Command);
/* Send command's parameters if any */
for (i=0; i<NbParameters; i++)
{
LCD_IO_WriteData(Parameters[i]);
}
}
/**
* @brief Reads the selected LCD Register.
* @param Command: command value (or register address as named in LS016B8UY doc).
* @retval Register Value.
*/
uint8_t ls016b8uy_ReadReg(uint8_t Command)
{
/* Send command */
LCD_IO_WriteReg(Command);
/* Read dummy data */
LCD_IO_ReadData();
/* Read register value */
return (LCD_IO_ReadData());
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void ls016b8uy_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
if (Xpos < LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXstart = Xpos;
}
else
{
WindowsXstart = 0;
}
if (Ypos < LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYstart = Ypos;
}
else
{
WindowsYstart = 0;
}
if (Width + Xpos <= LS016B8UY_LCD_PIXEL_WIDTH)
{
WindowsXend = Width + Xpos - 1;
}
else
{
WindowsXend = LS016B8UY_LCD_PIXEL_WIDTH - 1;
}
if (Height + Ypos <= LS016B8UY_LCD_PIXEL_HEIGHT)
{
WindowsYend = Height + Ypos - 1;
}
else
{
WindowsYend = LS016B8UY_LCD_PIXEL_HEIGHT-1;
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color in RGB565 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ls016b8uy_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
uint16_t r, g, b;
uint16_t rgb888_part1, rgb888_part2, rgb888_part3;
r = (RGBCode & 0xF800) >> 11; /* Extract red component from RGB565 pixel data */
g = (RGBCode & 0x07E0) >> 5; /* Extract green component from RGB565 pixel data */
b = (RGBCode & 0x001F) >> 0; /* Extract blue component from RGB565 pixel data */
rgb888_part1 = (r << 11) + (g << 2); /* Build pattern first part to write in LCD RAM */
rgb888_part2 = (b << 11) + (r << 3); /* Build pattern second part to write in LCD RAM */
rgb888_part3 = (g << 10) + (b << 3); /* Build pattern third part to write in LCD RAM */
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Sent a complete line */
for(counter = 0; counter < Length; counter+=2)
{
/* Write 2 pixels at a time by performing 3 access (pixels coded on 24 bits in LCD RAM whereas access are coded on 16 bits) */
LCD_IO_WriteData(rgb888_part1);
LCD_IO_WriteData(rgb888_part2);
if (counter != (Length-1)) /* When writing last pixel when Length is odd, the third part is not written */
{
LCD_IO_WriteData(rgb888_part3);
}
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ls016b8uy_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Fill a complete vertical line */
for(counter = 0; counter < Length; counter++)
{
ls016b8uy_WritePixel(Xpos, Ypos + counter, RGBCode);
}
}
/**
* @brief Displays a bitmap picture.
* @param BmpAddress: Bmp picture address.
* @param Xpos: Bmp X position in the LCD
* @param Ypos: Bmp Y position in the LCD
* @retval None
*/
void ls016b8uy_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
uint32_t posY;
uint32_t nb_line = 0;
uint16_t Xsize = WindowsXend - WindowsXstart + 1;
uint16_t Ysize = WindowsYend - WindowsYstart + 1;
/* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
for (posY = (Ypos + Ysize); posY > Ypos; posY--) /* In BMP files the line order is inverted */
{
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, posY - 1);
/* Draw one line of the picture */
ls016b8uy_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2)));
nb_line++;
}
}
/**
* @brief Displays picture.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @param Ysize: Image Y size in the LCD
* @retval None
*/
void ls016b8uy_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
{
uint32_t posY;
uint32_t nb_line = 0;
for (posY = Ypos; posY < (Ypos + Ysize); posY ++)
{
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, posY);
/* Draw one line of the picture */
ls016b8uy_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2)));
nb_line++;
}
}
/******************************************************************************
Static Functions
*******************************************************************************/
/**
* @brief Read pixel from LCD RAM in RGB888 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval Each RGB pixel color components in a structure
*/
static LS016B8UY_Rgb888 ls016b8uy_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos)
{
LS016B8UY_Rgb888 rgb888;
uint16_t rgb888_part1, rgb888_part2;
/* In LCD RAM, pixels are 24 bits packed and read with 16 bits access
* Here is the pixels components arrangement in memory :
* bits: 15 14 13 12 11 10 09 08 | 07 06 05 04 03 02 01 00
* address 0 : red pixel 0 X X | green pixel 0 X X
* address 1 : blue pixel 0 X X | red pixel 1 X X
* address 2 : green pixel 1 X X | blue pixel 1 X X
*/
/* Set Cursor */
ls016b8uy_SetCursor(Xpos, Ypos);
/* Prepare to read LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_READ_RAM, (uint8_t*)NULL, 0); /* RAM read data command */
/* Dummy read */
LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part1 = LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part2 = LCD_IO_ReadData();
/* red component */
rgb888.red = (rgb888_part1 & 0xFC00) >> 8;
/* green component */
rgb888.green = (rgb888_part1 & 0x00FC) >> 0;
/* blue component */
rgb888.blue = (rgb888_part2 & 0xFC00) >> 8;
return rgb888;
}
/**
* @brief Displays a single picture line.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @retval None
*/
static void ls016b8uy_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata)
{
uint32_t i = 0;
uint32_t posX;
uint16_t r, g, b;
uint16_t rgb888_part;
uint16_t *rgb565 = (uint16_t*)pdata;
/* Prepare to write to LCD RAM */
ls016b8uy_WriteReg(LCD_CMD_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
for (posX = Xpos; posX < (Xsize + Xpos); posX += 2)
{
if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */
(posX <= WindowsXend) && (Ypos <= WindowsYend))
{
/* Write pixels in LCD RAM after RGB565 -> RGB888 conversion */
/* As data in LCD RAM are 24bits packed, three 16 bits writes access are needed to transmit 2 pixels data */
r = (rgb565[i] & 0xF800) >> 11; /* Extract red component from first RGB565 pixel data */
g = (rgb565[i] & 0x07E0) >> 5; /* Extract green component from first RGB565 pixel data */
rgb888_part = (r << 11) + (g << 2); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
b = (rgb565[i] & 0x001F) >> 0; /* Extract blue component from first RGB565 pixel data */
r = (rgb565[i+1] & 0xF800) >> 11; /* Extract red component from second RGB565 pixel data */
rgb888_part = (b << 11) + (r << 3); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
if (posX != (Xsize + Xpos - 1)) /* When writing last pixel when size is odd, the third part is not written */
{
g = (rgb565[i+1] & 0x07E0) >> 5; /* Extract green component from second RGB565 pixel data */
b = (rgb565[i+1] & 0x001F) >> 0; /* Extract blue component from second RGB565 pixel data */
rgb888_part = (g << 10) + (b << 3); /* Build data to be written in LCD RAM */
LCD_IO_WriteData(rgb888_part);
}
i += 2;
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,179 @@
/**
******************************************************************************
* @file ls016b8uy.h
* @author MCD Application Team
* @version V1.0.0
* @date 10-May-2016
* @brief This file contains all the functions prototypes for the ls016b8uy.c
* driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LS016B8UY_H
#define __LS016B8UY_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "../Common/lcd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ls016b8uy
* @{
*/
/** @defgroup LS016B8UY_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup LS016B8UY_Exported_Constants
* @{
*/
/**
* @brief LS016B8UY ID
*/
#define LS016B8UY_ID 0xFFFF
/**
* @brief LS016B8UY Size
*/
#define LS016B8UY_LCD_PIXEL_WIDTH ((uint16_t)180)
#define LS016B8UY_LCD_PIXEL_HEIGHT ((uint16_t)180)
/**
* @brief LS016B8UY Registers
*/
#define LCD_CMD_SLEEP_IN 0x10
#define LCD_CMD_SLEEP_OUT 0x11
#define LCD_CMD_DISPLAY_OFF 0x28
#define LCD_CMD_DISPLAY_ON 0x29
#define LCD_CMD_WRITE_RAM 0x2C
#define LCD_CMD_READ_RAM 0x2E
#define LCD_CMD_CASET 0x2A
#define LCD_CMD_RASET 0x2B
#define LCD_CMD_VSYNC_OUTPUT 0x35
#define LCD_CMD_NORMAL_DISPLAY 0x36
#define LCD_CMD_IDLE_MODE_OFF 0x38
#define LCD_CMD_IDLE_MODE_ON 0x39
#define LCD_CMD_COLOR_MODE 0x3A
#define LCD_CMD_PANEL_SETTING_1 0xB0
#define LCD_CMD_PANEL_SETTING_2 0xB1
#define LCD_CMD_OSCILLATOR 0xB3
#define LCD_CMD_PANEL_SETTING_LOCK 0xB4
#define LCD_CMD_PANEL_V_PORCH 0xB7
#define LCD_CMD_PANEL_IDLE_V_PORCH 0xB8
#define LCD_CMD_GVDD 0xC0
#define LCD_CMD_OPAMP 0xC2
#define LCD_CMD_RELOAD_MTP_VCOMH 0xC5
#define LCD_CMD_PANEL_TIMING_1 0xC8
#define LCD_CMD_PANEL_TIMING_2 0xC9
#define LCD_CMD_PANEL_TIMING_3 0xCA
#define LCD_CMD_PANEL_TIMING_4 0xCC
#define LCD_CMD_PANEL_POWER 0xD0
#define LCD_CMD_TEARING_EFFECT 0xDD
/**
* @}
*/
/** @defgroup LS016B8UY_Exported_Functions
* @{
*/
void ls016b8uy_Init(void);
uint16_t ls016b8uy_ReadID(void);
void ls016b8uy_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters);
uint8_t ls016b8uy_ReadReg(uint8_t Command);
void ls016b8uy_DisplayOn(void);
void ls016b8uy_DisplayOff(void);
void ls016b8uy_SetCursor(uint16_t Xpos, uint16_t Ypos);
void ls016b8uy_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
uint16_t ls016b8uy_ReadPixel(uint16_t Xpos, uint16_t Ypos);
void ls016b8uy_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ls016b8uy_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ls016b8uy_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
void ls016b8uy_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata);
void ls016b8uy_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
uint16_t ls016b8uy_GetLcdPixelWidth(void);
uint16_t ls016b8uy_GetLcdPixelHeight(void);
/* LCD driver structure */
extern LCD_DrvTypeDef ls016b8uy_drv;
/* LCD IO functions */
void LCD_IO_Init(void);
void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
void LCD_IO_WriteData(uint16_t RegValue);
uint16_t LCD_IO_ReadData(void);
void LCD_IO_Delay(uint32_t delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LS016B8UY_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,408 @@
/**
******************************************************************************
* @file lsm303c.c
* @author MCD Application Team
* @version V2.0.0
* @date 07-April-2017
* @brief This file provides a set of functions needed to manage the LSM303C
* MEMS accelerometer.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "lsm303c.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup LSM303C
* @{
*/
/** @defgroup LSM303C_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup LSM303C_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup LSM303C_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup LSM303C_Private_Functions
* @{
*/
/**
* @}
*/
/** @defgroup LSM303C_Private_Variables
* @{
*/
ACCELERO_DrvTypeDef Lsm303cDrv_accelero =
{
LSM303C_AccInit,
LSM303C_AccDeInit,
LSM303C_AccReadID,
0,
LSM303C_AccLowPower,
0,
0,
0,
0,
0,
LSM303C_AccFilterConfig,
0,
LSM303C_AccReadXYZ
};
MAGNETO_DrvTypeDef Lsm303cDrv_magneto =
{
LSM303C_MagInit,
LSM303C_MagDeInit,
LSM303C_MagReadID,
0,
LSM303C_MagLowPower,
0,
0,
0,
0,
0,
0,
0,
LSM303C_MagReadXYZ
};
/**
* @}
*/
/**
* @brief Set LSM303C Accelerometer Initialization.
* @param InitStruct: Init parameters
* @retval None
*/
void LSM303C_AccInit(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
/* Low level init */
ACCELERO_IO_Init();
/* Write value to ACC MEMS CTRL_REG1 register */
ctrl = (uint8_t) InitStruct;
ACCELERO_IO_Write(LSM303C_CTRL_REG1_A, ctrl);
/* Write value to ACC MEMS CTRL_REG4 register */
ctrl = ((uint8_t) (InitStruct >> 8));
ACCELERO_IO_Write(LSM303C_CTRL_REG4_A, ctrl);
}
/**
* @brief LSM303C Accelerometer De-initialization.
* @param None
* @retval None
*/
void LSM303C_AccDeInit(void)
{
}
/**
* @brief Read LSM303C ID.
* @param None
* @retval ID
*/
uint8_t LSM303C_AccReadID(void)
{
uint8_t ctrl = 0x00;
/* Low level init */
ACCELERO_IO_Init();
/* Enabled SPI/I2C read communication */
ACCELERO_IO_Write(LSM303C_CTRL_REG4_A, 0x5);
/* Read value at Who am I register address */
ctrl = ACCELERO_IO_Read(LSM303C_WHO_AM_I_ADDR);
return ctrl;
}
/**
* @brief Put Accelerometer in power down mode or not.
* @param Mode equal to LSM303C_ACC_ODR_OFF means enable Low Power Mode, otherwise Output data rate is set.
* This parameter can be a value of @ref Acc_OutPut_DataRate_Selection
* @retval None
*/
void LSM303C_AccLowPower(uint16_t Mode)
{
uint8_t ctrl = 0x00;
/* Read control register 1 value */
ctrl = ACCELERO_IO_Read(LSM303C_CTRL_REG1_A);
/* Clear ODR bits */
ctrl &= ~(LSM303C_ACC_ODR_BITPOSITION);
/* Set Power down */
ctrl |= (uint8_t)Mode;
/* write back control register */
ACCELERO_IO_Write(LSM303C_CTRL_REG1_A, ctrl);
}
/**
* @brief Set High Pass Filter Modality
* @param FilterStruct: contains data for filter config
* @retval None
*/
void LSM303C_AccFilterConfig(uint8_t FilterStruct)
{
uint8_t tmpreg;
// /* Read CTRL_REG2 register */
// tmpreg = ACCELERO_IO_Read(LSM303C_CTRL_REG2_A);
//
// tmpreg &= 0x0C;
tmpreg = FilterStruct;
/* Write value to ACC MEMS CTRL_REG2 register */
ACCELERO_IO_Write(LSM303C_CTRL_REG2_A, tmpreg);
}
/**
* @brief Read X, Y & Z Acceleration values
* @param pData: Data out pointer
* @retval None
*/
void LSM303C_AccReadXYZ(int16_t* pData)
{
int16_t pnRawData[3];
uint8_t ctrlx[2]={0,0};
uint8_t buffer[6];
uint8_t i = 0;
uint8_t sensitivity = LSM303C_ACC_SENSITIVITY_2G;
/* Read the acceleration control register content */
ctrlx[0] = ACCELERO_IO_Read(LSM303C_CTRL_REG4_A);
ctrlx[1] = ACCELERO_IO_Read(LSM303C_CTRL_REG5_A);
/* Read output register X, Y & Z acceleration */
buffer[0] = ACCELERO_IO_Read(LSM303C_OUT_X_L_A);
buffer[1] = ACCELERO_IO_Read(LSM303C_OUT_X_H_A);
buffer[2] = ACCELERO_IO_Read(LSM303C_OUT_Y_L_A);
buffer[3] = ACCELERO_IO_Read(LSM303C_OUT_Y_H_A);
buffer[4] = ACCELERO_IO_Read(LSM303C_OUT_Z_L_A);
buffer[5] = ACCELERO_IO_Read(LSM303C_OUT_Z_H_A);
for(i=0; i<3; i++)
{
pnRawData[i]=((int16_t)((uint16_t)buffer[2*i+1] << 8) + buffer[2*i]);
}
/* Normal mode */
/* Switch the sensitivity value set in the CRTL4 */
switch(ctrlx[0] & LSM303C_ACC_FULLSCALE_8G)
{
case LSM303C_ACC_FULLSCALE_2G:
sensitivity = LSM303C_ACC_SENSITIVITY_2G;
break;
case LSM303C_ACC_FULLSCALE_4G:
sensitivity = LSM303C_ACC_SENSITIVITY_4G;
break;
case LSM303C_ACC_FULLSCALE_8G:
sensitivity = LSM303C_ACC_SENSITIVITY_8G;
break;
}
/* Obtain the mg value for the three axis */
for(i=0; i<3; i++)
{
pData[i]=(pnRawData[i] * sensitivity);
}
}
/***********************************************************************************************
Magnetometer driver
***********************************************************************************************/
/**
* @brief Set LSM303C Magnetometer Initialization.
* @param LSM303C_InitStruct: pointer to a LSM303C_MagInitTypeDef structure
* that contains the configuration setting for the LSM303C.
* @retval None
*/
void LSM303C_MagInit(MAGNETO_InitTypeDef LSM303C_InitStruct)
{
MAGNETO_IO_Write(LSM303C_CTRL_REG1_M, LSM303C_InitStruct.Register1);
MAGNETO_IO_Write(LSM303C_CTRL_REG2_M, LSM303C_InitStruct.Register2);
MAGNETO_IO_Write(LSM303C_CTRL_REG3_M, LSM303C_InitStruct.Register3);
MAGNETO_IO_Write(LSM303C_CTRL_REG4_M, LSM303C_InitStruct.Register4);
MAGNETO_IO_Write(LSM303C_CTRL_REG5_M, LSM303C_InitStruct.Register5);
}
/**
* @brief LSM303C Magnetometer De-initialization.
* @param None
* @retval None
*/
void LSM303C_MagDeInit(void)
{
}
/**
* @brief Read LSM303C ID.
* @param None
* @retval ID
*/
uint8_t LSM303C_MagReadID(void)
{
/* Low level init */
MAGNETO_IO_Init();
/* Enabled the SPI/I2C read operation */
MAGNETO_IO_Write(LSM303C_CTRL_REG3_M, 0x84);
/* Read value at Who am I register address */
return MAGNETO_IO_Read(LSM303C_WHO_AM_I_ADDR);
}
/**
* @brief Put Magnetometer in power down mode or not.
* @param Mode equal to LSM303C_MAG_POWERDOWN2_MODE means enable deepest Low Power Mode, otherwise other mode is set.
* This parameter can be a value of @ref Mag_Operation_Mode
* @retval None
*/
void LSM303C_MagLowPower(uint16_t Mode)
{
uint8_t ctrl = 0x00;
/* Read control register 1 value */
ctrl = MAGNETO_IO_Read(LSM303C_CTRL_REG3_M);
/* Clear ODR bits */
ctrl &= ~(LSM303C_MAG_SELECTION_MODE);
/* Set mode */
ctrl |= (uint8_t)Mode;
/* write back control register */
MAGNETO_IO_Write(LSM303C_CTRL_REG3_M, ctrl);
}
/**
* @brief Get status for Mag LSM303C data
* @param None
* @retval Data status in a LSM303C Data register
*/
uint8_t LSM303C_MagGetDataStatus(void)
{
/* Read Mag STATUS register */
return MAGNETO_IO_Read(LSM303C_STATUS_REG_M);
}
/**
* @brief Read X, Y & Z Magnetometer values
* @param pData: Data out pointer
* @retval None
*/
void LSM303C_MagReadXYZ(int16_t* pData)
{
uint8_t ctrlx;
uint8_t buffer[6];
uint8_t i=0;
/* Read the magnetometer control register content */
ctrlx = MAGNETO_IO_Read(LSM303C_CTRL_REG4_M);
/* Read output register X, Y & Z magnetometer */
buffer[0] = MAGNETO_IO_Read(LSM303C_OUT_X_L_M);
buffer[1] = MAGNETO_IO_Read(LSM303C_OUT_X_H_M);
buffer[2] = MAGNETO_IO_Read(LSM303C_OUT_Y_L_M);
buffer[3] = MAGNETO_IO_Read(LSM303C_OUT_Y_H_M);
buffer[4] = MAGNETO_IO_Read(LSM303C_OUT_Z_L_M);
buffer[5] = MAGNETO_IO_Read(LSM303C_OUT_Z_H_M);
/* Check in the control register4 the data alignment*/
if((ctrlx & LSM303C_MAG_BLE_MSB))
{
for(i=0; i<3; i++)
{
pData[i]=((int16_t)((uint16_t)buffer[2*i] << 8) + buffer[2*i+1]);
}
}
else
{
for(i=0; i<3; i++)
{
pData[i]=((int16_t)((uint16_t)buffer[2*i+1] << 8) + buffer[2*i]);
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,619 @@
/**
******************************************************************************
* @file lsm303c.h
* @author MCD Application Team
* @version V2.0.0
* @date 07-April-2017
* @brief This file contains all the functions prototypes for the LSM303C.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LSM303C_H
#define __LSM303C_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/accelero.h"
#include "../Common/magneto.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup LSM303C
* @{
*/
/** @defgroup LSM303C_Exported_Types
* @{
*/
/**
* @}
*/
/******************************************************************************/
/*************************** START REGISTER MAPPING **************************/
/******************************************************************************/
/* Acceleration Registers */
#define LSM303C_WHO_AM_I_ADDR 0x0F /* device identification register */
#define LSM303C_ACT_THS_A 0x1E
#define LSM303C_ACT_DUR_A 0x1F
#define LSM303C_CTRL_REG1_A 0x20 /* Control register 1 acceleration */
#define LSM303C_CTRL_REG2_A 0x21 /* Control register 2 acceleration */
#define LSM303C_CTRL_REG3_A 0x22 /* Control register 3 acceleration */
#define LSM303C_CTRL_REG4_A 0x23 /* Control register 4 acceleration */
#define LSM303C_CTRL_REG5_A 0x24 /* Control register 5 acceleration */
#define LSM303C_CTRL_REG6_A 0x25 /* Control register 6 acceleration */
#define LSM303C_CTRL_REG7_A 0x26 /* Control register 6 acceleration */
#define LSM303C_STATUS_REG_A 0x27 /* Status register acceleration */
#define LSM303C_OUT_X_L_A 0x28 /* Output Register X acceleration */
#define LSM303C_OUT_X_H_A 0x29 /* Output Register X acceleration */
#define LSM303C_OUT_Y_L_A 0x2A /* Output Register Y acceleration */
#define LSM303C_OUT_Y_H_A 0x2B /* Output Register Y acceleration */
#define LSM303C_OUT_Z_L_A 0x2C /* Output Register Z acceleration */
#define LSM303C_OUT_Z_H_A 0x2D /* Output Register Z acceleration */
#define LSM303C_FIFO_CTRL 0x2E /* Fifo control Register acceleration */
#define LSM303C_FIFO_SRC 0x2F /* Fifo src Register acceleration */
#define LSM303C_IG_CFG1_A 0x30 /* Interrupt 1 configuration Register acceleration */
#define LSM303C_IG_SRC1_A 0x31 /* Interrupt 1 source Register acceleration */
#define LSM303C_IG_THS_X1_A 0x32
#define LSM303C_IG_THS_Y1_A 0x33
#define LSM303C_IG_THS_Z1_A 0x34
#define LSM303C_IG_DUR1_A 0x32
#define LSM303C_INT1_DURATION_A 0x33 /* Interrupt 1 DURATION register acceleration */
#define LSM303C_INT2_CFG_A 0x34 /* Interrupt 2 configuration Register acceleration */
#define LSM303C_INT2_SOURCE_A 0x35 /* Interrupt 2 source Register acceleration */
#define LSM303C_INT2_THS_A 0x36 /* Interrupt 2 Threshold register acceleration */
#define LSM303C_INT2_DURATION_A 0x37 /* Interrupt 2 DURATION register acceleration */
#define LSM303C_CLICK_CFG_A 0x38 /* Click configuration Register acceleration */
#define LSM303C_CLICK_SOURCE_A 0x39 /* Click 2 source Register acceleration */
#define LSM303C_CLICK_THS_A 0x3A /* Click 2 Threshold register acceleration */
#define LSM303C_TIME_LIMIT_A 0x3B /* Time Limit Register acceleration */
#define LSM303C_TIME_LATENCY_A 0x3C /* Time Latency Register acceleration */
#define LSM303C_TIME_WINDOW_A 0x3D /* Time window register acceleration */
/* Magnetic field Registers */
#define LSM303C_CTRL_REG1_M 0x20 /* Magnetic control register 1 */
#define LSM303C_CTRL_REG2_M 0x21 /* Magnetic control register 2 */
#define LSM303C_CTRL_REG3_M 0x22 /* Magnetic control register 3 */
#define LSM303C_CTRL_REG4_M 0x23 /* Magnetic control register 4 */
#define LSM303C_CTRL_REG5_M 0x24 /* Magnetic control register 5 */
#define LSM303C_STATUS_REG_M 0x27 /* Magnetic status register M */
#define LSM303C_OUT_X_L_M 0x28 /* Output Register X magnetic field */
#define LSM303C_OUT_X_H_M 0x29 /* Output Register X magnetic field */
#define LSM303C_OUT_Y_L_M 0x2A /* Output Register Y magnetic field */
#define LSM303C_OUT_Y_H_M 0x2B /* Output Register Y magnetic field */
#define LSM303C_OUT_Z_L_M 0x2C /* Output Register Z magnetic field */
#define LSM303C_OUT_Z_H_M 0x2D /* Output Register Z magnetic field */
#define LSM303C_TEMP_OUT_L_M 0x2E /* Temperature Register magnetic field */
#define LSM303C_TEMP_OUT_H_M 0x2F /* Temperature Register magnetic field */
#define LSM303C_INT_CFG_M 0x30 /* Axis interrupt configuration */
#define LSM303C_INT_SRC_M 0x31 /* Axis interrupt source */
#define LSM303C_INT_THS_L_M 0x32 /* Interrupt threshold L */
#define LSM303C_INT_THS_H_M 0x33 /* Interrupt threshold M */
/******************************************************************************/
/**************************** END REGISTER MAPPING ***************************/
/******************************************************************************/
/** @defgroup Power_Mode_selection
* @{
*/
#define LMS303C_ACC_ID ((uint8_t)0x41)
#define LMS303C_MAG_ID ((uint8_t)0x3D)
/**
* @}
*/
/** @defgroup Acc_OutPut_DataRate_Selection
* @{
*/
#define LSM303C_ACC_ODR_BITPOSITION ((uint8_t)0x70) /*!< Output Data Rate bit position */
#define LSM303C_ACC_ODR_OFF ((uint8_t)0x00) /*!< Output Data Rate powerdown */
#define LSM303C_ACC_ODR_10_HZ ((uint8_t)0x10) /*!< Output Data Rate = 10 Hz */
#define LSM303C_ACC_ODR_50_HZ ((uint8_t)0x20) /*!< Output Data Rate = 50 Hz */
#define LSM303C_ACC_ODR_100_HZ ((uint8_t)0x30) /*!< Output Data Rate = 100 Hz */
#define LSM303C_ACC_ODR_200_HZ ((uint8_t)0x40) /*!< Output Data Rate = 200 Hz */
#define LSM303C_ACC_ODR_400_HZ ((uint8_t)0x50) /*!< Output Data Rate = 400 Hz */
#define LSM303C_ACC_ODR_800_HZ ((uint8_t)0x60) /*!< Output Data Rate = 800 Hz */
/**
* @}
*/
/** @defgroup Acc_Axes_Selection
* @{
*/
#define LSM303C_ACC_X_ENABLE ((uint8_t)0x01)
#define LSM303C_ACC_Y_ENABLE ((uint8_t)0x02)
#define LSM303C_ACC_Z_ENABLE ((uint8_t)0x04)
#define LSM303C_ACC_AXES_ENABLE ((uint8_t)0x07)
#define LSM303C_ACC_AXES_DISABLE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Acc_High_Resolution
* @{
*/
#define LSM303C_ACC_HR_ENABLE ((uint8_t)0x80)
#define LSM303C_ACC_HR_DISABLE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Communication_Mode
* @{
*/
#define LSM303C_ACC_I2C_MODE ((uint8_t) 0x02)
#define LSM303C_ACC_SPI_MODE ((uint8_t) 0x01)
/**
* @}
*/
/** @defgroup Acc_Full_Scale_Selection
* @{
*/
#define LSM303C_ACC_FULLSCALE_2G ((uint8_t)0x00) /*!< ±2 g */
#define LSM303C_ACC_FULLSCALE_4G ((uint8_t)0x20) /*!< ±4 g */
#define LSM303C_ACC_FULLSCALE_8G ((uint8_t)0x30) /*!< ±8 g */
/**
* @}
*/
/** @defgroup Acc_Full_Scale_Selection
* @{
*/
#define LSM303C_ACC_SENSITIVITY_2G ((uint8_t)1) /*!< accelerometer sensitivity with 2 g full scale [mg/LSB] */
#define LSM303C_ACC_SENSITIVITY_4G ((uint8_t)2) /*!< accelerometer sensitivity with 4 g full scale [mg/LSB] */
#define LSM303C_ACC_SENSITIVITY_8G ((uint8_t)4) /*!< accelerometer sensitivity with 8 g full scale [mg/LSB] */
#define LSM303C_ACC_SENSITIVITY_16G ((uint8_t)12) /*!< accelerometer sensitivity with 12 g full scale [mg/LSB] */
/**
* @}
*/
/** @defgroup Acc_Block_Data_Update
* @{
*/
#define LSM303C_ACC_BDU_CONTINUOUS ((uint8_t)0x00) /*!< Continuos Update */
#define LSM303C_ACC_BDU_MSBLSB ((uint8_t)0x08) /*!< Single Update: output registers not updated until MSB and LSB reading */
/**
* @}
*/
/** @defgroup Acc_Endian_Data_selection
* @{
*/
#define LSM303C_ACC_BLE_LSB ((uint8_t)0x00) /*!< Little Endian: data LSB @ lower address */
#define LSM303C_ACC_BLE_MSB ((uint8_t)0x40) /*!< Big Endian: data MSB @ lower address */
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_Mode
* @{
*/
#define LSM303C_ACC_HPM_REF_SIGNAL ((uint8_t)0x08)
#define LSM303C_ACC_HPM_NORMAL_MODE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Acc_High_Pass_CUT OFF_Frequency
* @{
*/
#define LSM303C_ACC_DFC1_ODRDIV50 ((uint8_t)0x00)
#define LSM303C_ACC_DFC1_ODRDIV100 ((uint8_t)0x20)
#define LSM303C_ACC_DFC1_ODRDIV9 ((uint8_t)0x40)
#define LSM303C_ACC_DFC1_ODRDIV400 ((uint8_t)0x60)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_status
* @{
*/
#define LSM303C_ACC_HPF_DISABLE ((uint8_t)0x00)
#define LSM303C_ACC_HPF_ENABLE ((uint8_t)0x08)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_Click_status
* @{
*/
#define LSM303C_ACC_HPF_CLICK_DISABLE ((uint8_t)0x00)
#define LSM303C_ACC_HPF_CLICK_ENABLE ((uint8_t)0x04)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_HPI2S_status
* @{
*/
#define LSM303C_ACC_HPI2S_INT1_DISABLE ((uint8_t)0x00)
#define LSM303C_ACC_HPI2S_INT1_ENABLE ((uint8_t)0x01)
#define LSM303C_ACC_HPI2S_INT2_DISABLE ((uint8_t)0x00)
#define LSM303C_ACC_HPI2S_INT2_ENABLE ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_Interrupt1_Configuration_definition
* @{
*/
#define LSM303C_IT1_CLICK ((uint8_t)0x80)
#define LSM303C_IT1_AOI1 ((uint8_t)0x40)
#define LSM303C_IT1_AOI2 ((uint8_t)0x20)
#define LSM303C_IT1_DRY1 ((uint8_t)0x10)
#define LSM303C_IT1_DRY2 ((uint8_t)0x08)
#define LSM303C_IT1_WTM ((uint8_t)0x04)
#define LSM303C_IT1_OVERRUN ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_Interrupt2_Configuration_definition
* @{
*/
#define LSM303C_IT2_CLICK ((uint8_t)0x80)
#define LSM303C_IT2_INT1 ((uint8_t)0x40)
#define LSM303C_IT2_INT2 ((uint8_t)0x20)
#define LSM303C_IT2_BOOT ((uint8_t)0x10)
#define LSM303C_IT2_ACT ((uint8_t)0x08)
#define LSM303C_IT2_HLACTIVE ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_INT_Combination_Status
* @{
*/
#define LSM303C_OR_COMBINATION ((uint8_t)0x00) /*!< OR combination of enabled IRQs */
#define LSM303C_AND_COMBINATION ((uint8_t)0x80) /*!< AND combination of enabled IRQs */
#define LSM303C_MOV_RECOGNITION ((uint8_t)0x40) /*!< 6D movement recognition */
#define LSM303C_POS_RECOGNITION ((uint8_t)0xC0) /*!< 6D position recognition */
/**
* @}
*/
/** @defgroup Acc_INT_Axes
* @{
*/
#define LSM303C_Z_HIGH ((uint8_t)0x20) /*!< Z High enabled IRQs */
#define LSM303C_Z_LOW ((uint8_t)0x10) /*!< Z low enabled IRQs */
#define LSM303C_Y_HIGH ((uint8_t)0x08) /*!< Y High enabled IRQs */
#define LSM303C_Y_LOW ((uint8_t)0x04) /*!< Y low enabled IRQs */
#define LSM303C_X_HIGH ((uint8_t)0x02) /*!< X High enabled IRQs */
#define LSM303C_X_LOW ((uint8_t)0x01) /*!< X low enabled IRQs */
/**
* @}
*/
/** @defgroup Acc_INT_Click
* @{
*/
#define LSM303C_Z_DOUBLE_CLICK ((uint8_t)0x20) /*!< Z double click IRQs */
#define LSM303C_Z_SINGLE_CLICK ((uint8_t)0x10) /*!< Z single click IRQs */
#define LSM303C_Y_DOUBLE_CLICK ((uint8_t)0x08) /*!< Y double click IRQs */
#define LSM303C_Y_SINGLE_CLICK ((uint8_t)0x04) /*!< Y single click IRQs */
#define LSM303C_X_DOUBLE_CLICK ((uint8_t)0x02) /*!< X double click IRQs */
#define LSM303C_X_SINGLE_CLICK ((uint8_t)0x01) /*!< X single click IRQs */
/**
* @}
*/
/** @defgroup Acc_INT1_Interrupt_status
* @{
*/
#define LSM303C_INT1INTERRUPT_DISABLE ((uint8_t)0x00)
#define LSM303C_INT1INTERRUPT_ENABLE ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup Acc_INT1_Interrupt_ActiveEdge
* @{
*/
#define LSM303C_INT1INTERRUPT_LOW_EDGE ((uint8_t)0x20)
#define LSM303C_INT1INTERRUPT_HIGH_EDGE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Mag_Temperature_Sensor
* @{
*/
#define LSM303C_MAG_TEMPSENSOR_ENABLE ((uint8_t) 0x80) /*!< Temp sensor Enable */
#define LSM303C_MAG_TEMPSENSOR_DISABLE ((uint8_t) 0x00) /*!< Temp sensor Disable */
/**
* @}
*/
/** @defgroup Mag_XY-axis_Operating_Mode
* @{
*/
#define LSM303C_MAG_OM_XY_LOWPOWER ((uint8_t) 0x00 << 5)
#define LSM303C_MAG_OM_XY_MEDIUM ((uint8_t) 0x01 << 5)
#define LSM303C_MAG_OM_XY_HIGH ((uint8_t) 0x02 << 5)
#define LSM303C_MAG_OM_XY_ULTRAHIGH ((uint8_t) 0x03 << 5)
/**
* @}
*/
/** @defgroup Mag_Data_Rate
* @{
*/
#define LSM303C_MAG_ODR_0_625_HZ ((uint8_t) 0x00 << 2) /*!< Output Data Rate = 0.625 Hz */
#define LSM303C_MAG_ODR_1_25_HZ ((uint8_t) 0x01 << 2) /*!< Output Data Rate = 1.25 Hz */
#define LSM303C_MAG_ODR_2_5_HZ ((uint8_t) 0x02 << 2) /*!< Output Data Rate = 2.5 Hz */
#define LSM303C_MAG_ODR_5_0_HZ ((uint8_t) 0x03 << 2) /*!< Output Data Rate = 5.0 Hz */
#define LSM303C_MAG_ODR_10_HZ ((uint8_t) 0x04 << 2) /*!< Output Data Rate = 10 Hz */
#define LSM303C_MAG_ODR_20_HZ ((uint8_t) 0x05 << 2) /*!< Output Data Rate = 20 Hz */
#define LSM303C_MAG_ODR_40_HZ ((uint8_t) 0x06 << 2) /*!< Output Data Rate = 40 Hz */
#define LSM303C_MAG_ODR_80_HZ ((uint8_t) 0x07 << 2) /*!< Output Data Rate = 80 Hz */
/**
* @}
*/
/** @defgroup Mag_Data_Rate
* @{
*/
#define LMS303C_MAG_SELFTEST_DISABLE ((uint8_t 0x00)
#define LMS303C_MAG_SELFTEST_ENABLE ((uint8_t 0x01)
/**
* @}
*/
/** @defgroup Mag_Full_Scale
* @{
*/
#define LSM303C_MAG_FS_DEFAULT ((uint8_t) 0x00 << 5)
#define LSM303C_MAG_FS_16_GA ((uint8_t) 0x03 << 5) /*!< Full scale = ±16 Gauss */
/**
* @}
*/
/** @defgroup Mag_Reboot
* @{
*/
#define LSM303C_MAG_REBOOT_DEFAULT ((uint8_t) 0x00 << 3)
#define LSM303C_MAG_REBOOT_ENABLE ((uint8_t) 0x01 << 3)
/**
* @}
*/
/** @defgroup Mag_Soft_reset
* @{
*/
#define LSM303C_MAG_SOFT_RESET_DEFAULT ((uint8_t) 0x00 << 2)
#define LSM303C_MAG_SOFT_RESET_ENABLE ((uint8_t) 0x01 << 2)
/**
* @}
*/
/** @defgroup Mag_Communication_Mode
* @{
*/
#define LSM303C_MAG_I2C_MODE ((uint8_t) 0x80)
#define LSM303C_MAG_SPI_MODE ((uint8_t) 0x04)
/**
* @}
*/
/** @defgroup Mag_Lowpower_mode_config
* @{
*/
#define LSM303C_MAG_CONFIG_NORMAL_MODE ((uint8_t) 0x00)
#define LSM303C_MAG_CONFIG_LOWPOWER_MODE ((uint8_t) 0x20)
/**
* @}
*/
/** @defgroup Mag_Operation_Mode
* @{
*/
#define LSM303C_MAG_SELECTION_MODE ((uint8_t) 0x03)
#define LSM303C_MAG_CONTINUOUS_MODE ((uint8_t) 0x00)
#define LSM303C_MAG_SINGLE_MODE ((uint8_t) 0x01)
#define LSM303C_MAG_POWERDOWN1_MODE ((uint8_t) 0x02)
#define LSM303C_MAG_POWERDOWN2_MODE ((uint8_t) 0x03)
/**
* @}
*/
/** @defgroup Mag_Z-axis_Operation_Mode
* @{
*/
#define LSM303C_MAG_OM_Z_LOWPOWER ((uint8_t) 0x00 << 2)
#define LSM303C_MAG_OM_Z_MEDIUM ((uint8_t) 0x01 << 2)
#define LSM303C_MAG_OM_Z_HIGH ((uint8_t) 0x02 << 2)
#define LSM303C_MAG_OM_Z_ULTRAHIGH ((uint8_t) 0x03 << 2)
/**
* @}
*/
/** @defgroup Mag_Big_little-endian_selection
* @{
*/
#define LSM303C_MAG_BLE_LSB ((uint8_t) 0x00)
#define LSM303C_MAG_BLE_MSB ((uint8_t) 0x02)
/**
* @}
*/
/** @defgroup Mag_Bloc_update_magnetic_data
* @{
*/
#define LSM303C_MAG_BDU_CONTINUOUS ((uint8_t) 0x00)
#define LSM303C_MAG_BDU_MSBLSB ((uint8_t) 0x40)
/**
* @}
*/
/**
* @defgroup Magnetometer_Sensitivity
* @{
*/
#define LSM303C_M_SENSITIVITY_XY_1_3Ga 1100 /*!< magnetometer X Y axes sensitivity for 1.3 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_1_9Ga 855 /*!< magnetometer X Y axes sensitivity for 1.9 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_2_5Ga 670 /*!< magnetometer X Y axes sensitivity for 2.5 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_4Ga 450 /*!< magnetometer X Y axes sensitivity for 4 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_4_7Ga 400 /*!< magnetometer X Y axes sensitivity for 4.7 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_5_6Ga 330 /*!< magnetometer X Y axes sensitivity for 5.6 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_XY_8_1Ga 230 /*!< magnetometer X Y axes sensitivity for 8.1 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_1_3Ga 980 /*!< magnetometer Z axis sensitivity for 1.3 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_1_9Ga 760 /*!< magnetometer Z axis sensitivity for 1.9 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_2_5Ga 600 /*!< magnetometer Z axis sensitivity for 2.5 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_4Ga 400 /*!< magnetometer Z axis sensitivity for 4 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_4_7Ga 355 /*!< magnetometer Z axis sensitivity for 4.7 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_5_6Ga 295 /*!< magnetometer Z axis sensitivity for 5.6 Ga full scale [LSB/Ga] */
#define LSM303C_M_SENSITIVITY_Z_8_1Ga 205 /*!< magnetometer Z axis sensitivity for 8.1 Ga full scale [LSB/Ga] */
/**
* @}
*/
/** @defgroup Mag_Working_Mode
* @{
*/
#define LSM303C_CONTINUOUS_CONVERSION ((uint8_t) 0x00) /*!< Continuous-Conversion Mode */
#define LSM303C_SINGLE_CONVERSION ((uint8_t) 0x01) /*!< Single-Conversion Mode */
#define LSM303C_SLEEP ((uint8_t) 0x02) /*!< Sleep Mode */
/**
* @}
*/
/** @defgroup LSM303C_AccExported_Functions ACCELEROMETER Exported functions
* @{
*/
void LSM303C_AccInit(uint16_t InitStruct);
void LSM303C_AccDeInit(void);
uint8_t LSM303C_AccReadID(void);
void LSM303C_AccLowPower(uint16_t Mode);
void LSM303C_AccFilterConfig(uint8_t FilterStruct);
void LSM303C_AccFilterCmd(uint8_t HighPassFilterState);
void LSM303C_AccReadXYZ(int16_t* pData);
void LSM303C_AccFilterClickCmd(uint8_t HighPassFilterClickState);
void LSM303C_AccIT1Enable(uint8_t LSM303C_IT);
void LSM303C_AccIT1Disable(uint8_t LSM303C_IT);
void LSM303C_AccIT2Enable(uint8_t LSM303C_IT);
void LSM303C_AccIT2Disable(uint8_t LSM303C_IT);
void LSM303C_AccClickITEnable(uint8_t ITClick);
void LSM303C_AccClickITDisable(uint8_t ITClick);
void LSM303C_AccZClickITConfig(void);
/**
* @}
*/
/** @defgroup LSM303C_AccImported_Globals ACCELEROMETER Imported Globals
* @{
*/
extern ACCELERO_DrvTypeDef Lsm303cDrv_accelero;
/**
* @}
*/
/** @defgroup LSM303C_MagExported_Functions MAGNETOMETER Exported functions
* @{
*/
void LSM303C_MagInit(MAGNETO_InitTypeDef LSM303C_InitStruct);
void LSM303C_MagDeInit(void);
uint8_t LSM303C_MagReadID(void);
void LSM303C_MagLowPower(uint16_t Mode);
void LSM303C_MagReadXYZ(int16_t* pData);
uint8_t LSM303C_MagGetDataStatus(void);
/**
* @}
*/
/** @defgroup LSM303C_MagImported_Globals MAGNETOMETER Imported Globals
* @{
*/
extern MAGNETO_DrvTypeDef Lsm303cDrv_magneto;
/**
* @}
*/
/** @defgroup LSM303C_Imported_Functions LSM303C IO Imported Functions
* @{
*/
/* ACCELERO IO functions */
extern void ACCELERO_IO_Init(void);
extern void ACCELERO_IO_ITConfig(void);
extern void ACCELERO_IO_Write(uint8_t RegisterAddr, uint8_t Value);
extern uint8_t ACCELERO_IO_Read(uint8_t RegisterAddr);
/* MAGNETO IO function */
extern void MAGNETO_IO_Init(void);
extern void MAGNETO_IO_ITConfig(void);
extern void MAGNETO_IO_Write(uint8_t RegisterAddr, uint8_t Value);
extern uint8_t MAGNETO_IO_Read(uint8_t RegisterAddr);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LSM303C_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,578 @@
/**
******************************************************************************
* @file lsm303dlhc.c
* @author MCD Application Team
* @version V2.0.0
* @date 24-June-2015
* @brief This file provides a set of functions needed to manage the lsm303dlhc
* MEMS accelerometer.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "lsm303dlhc.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup LSM303DLHC
* @{
*/
/** @defgroup LSM303DLHC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup LSM303DLHC_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup LSM303DLHC_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup LSM303DLHC_Private_Variables
* @{
*/
ACCELERO_DrvTypeDef Lsm303dlhcDrv =
{
LSM303DLHC_AccInit,
LSM303DLHC_AccDeInit,
LSM303DLHC_AccReadID,
LSM303DLHC_AccRebootCmd,
0,
LSM303DLHC_AccZClickITConfig,
0,
0,
0,
0,
LSM303DLHC_AccFilterConfig,
LSM303DLHC_AccFilterCmd,
LSM303DLHC_AccReadXYZ
};
/**
* @}
*/
/** @defgroup LSM303DLHC_Private_Functions
* @{
*/
/**
* @brief Set LSM303DLHC Initialization.
* @param InitStruct: Init parameters
* @retval None
*/
void LSM303DLHC_AccInit(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
/* Low level init */
COMPASSACCELERO_IO_Init();
/* Write value to ACC MEMS CTRL_REG1 register */
ctrl = (uint8_t) InitStruct;
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG1_A, ctrl);
/* Write value to ACC MEMS CTRL_REG4 register */
ctrl = (uint8_t) (InitStruct << 8);
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG4_A, ctrl);
}
/**
* @brief LSM303DLHC De-initialization.
* @param None
* @retval None
*/
void LSM303DLHC_AccDeInit(void)
{
}
/**
* @brief Read LSM303DLHC ID.
* @param None
* @retval ID
*/
uint8_t LSM303DLHC_AccReadID(void)
{
uint8_t ctrl = 0x00;
/* Low level init */
COMPASSACCELERO_IO_Init();
/* Read value at Who am I register address */
ctrl = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_WHO_AM_I_ADDR);
return ctrl;
}
/**
* @brief Reboot memory content of LSM303DLHC
* @param None
* @retval None
*/
void LSM303DLHC_AccRebootCmd(void)
{
uint8_t tmpreg;
/* Read CTRL_REG5 register */
tmpreg = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG5_A);
/* Enable or Disable the reboot memory */
tmpreg |= LSM303DLHC_BOOT_REBOOTMEMORY;
/* Write value to ACC MEMS CTRL_REG5 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG5_A, tmpreg);
}
/**
* @brief Set High Pass Filter Modality
* @param FilterStruct: contains data for filter config
* @retval None
*/
void LSM303DLHC_AccFilterConfig(uint8_t FilterStruct)
{
uint8_t tmpreg;
/* Read CTRL_REG2 register */
tmpreg = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A);
tmpreg &= 0x0C;
tmpreg |= FilterStruct;
/* Write value to ACC MEMS CTRL_REG2 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A, tmpreg);
}
/**
* @brief Enable or Disable High Pass Filter
* @param HighPassFilterState: new state of the High Pass Filter feature.
* This parameter can be:
* @arg: LSM303DLHC_HIGHPASSFILTER_DISABLE
* @arg: LSM303DLHC_HIGHPASSFILTER_ENABLE
* @retval None
*/
void LSM303DLHC_AccFilterCmd(uint8_t HighPassFilterState)
{
uint8_t tmpreg;
/* Read CTRL_REG2 register */
tmpreg = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A);
tmpreg &= 0xF7;
tmpreg |= HighPassFilterState;
/* Write value to ACC MEMS CTRL_REG2 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A, tmpreg);
}
/**
* @brief Read X, Y & Z Acceleration values
* @param pData: Data out pointer
* @retval None
*/
void LSM303DLHC_AccReadXYZ(int16_t* pData)
{
int16_t pnRawData[3];
uint8_t ctrlx[2]={0,0};
int8_t buffer[6];
uint8_t i = 0;
uint8_t sensitivity = LSM303DLHC_ACC_SENSITIVITY_2G;
/* Read the acceleration control register content */
ctrlx[0] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG4_A);
ctrlx[1] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG5_A);
/* Read output register X, Y & Z acceleration */
buffer[0] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_X_L_A);
buffer[1] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_X_H_A);
buffer[2] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_Y_L_A);
buffer[3] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_Y_H_A);
buffer[4] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_Z_L_A);
buffer[5] = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_OUT_Z_H_A);
/* Check in the control register4 the data alignment*/
if(!(ctrlx[0] & LSM303DLHC_BLE_MSB))
{
for(i=0; i<3; i++)
{
pnRawData[i]=((int16_t)((uint16_t)buffer[2*i+1] << 8) + buffer[2*i]);
}
}
else /* Big Endian Mode */
{
for(i=0; i<3; i++)
{
pnRawData[i]=((int16_t)((uint16_t)buffer[2*i] << 8) + buffer[2*i+1]);
}
}
/* Normal mode */
/* Switch the sensitivity value set in the CRTL4 */
switch(ctrlx[0] & LSM303DLHC_FULLSCALE_16G)
{
case LSM303DLHC_FULLSCALE_2G:
sensitivity = LSM303DLHC_ACC_SENSITIVITY_2G;
break;
case LSM303DLHC_FULLSCALE_4G:
sensitivity = LSM303DLHC_ACC_SENSITIVITY_4G;
break;
case LSM303DLHC_FULLSCALE_8G:
sensitivity = LSM303DLHC_ACC_SENSITIVITY_8G;
break;
case LSM303DLHC_FULLSCALE_16G:
sensitivity = LSM303DLHC_ACC_SENSITIVITY_16G;
break;
}
/* Obtain the mg value for the three axis */
for(i=0; i<3; i++)
{
pData[i]=(pnRawData[i] * sensitivity);
}
}
/**
* @brief Enable or Disable High Pass Filter on CLick
* @param HighPassFilterState: new state of the High Pass Filter feature.
* This parameter can be:
* @arg: LSM303DLHC_HPF_CLICK_DISABLE
* @arg: LSM303DLHC_HPF_CLICK_ENABLE
* @retval None
*/
void LSM303DLHC_AccFilterClickCmd(uint8_t HighPassFilterClickState)
{
uint8_t tmpreg = 0x00;
/* Read CTRL_REG2 register */
tmpreg = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A);
tmpreg &= ~(LSM303DLHC_HPF_CLICK_ENABLE);
tmpreg |= HighPassFilterClickState;
/* Write value to ACC MEMS CTRL_REG2 regsister */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A, tmpreg);
}
/**
* @brief Enable LSM303DLHC Interrupt1
* @param LSM303DLHC_IT: specifies the LSM303DLHC interrupt source to be enabled.
* This parameter can be any combination of the following values:
* @arg LSM303DLHC_IT1_CLICK
* @arg LSM303DLHC_IT1_AOI1
* @arg LSM303DLHC_IT1_AOI2
* @arg LSM303DLHC_IT1_DRY1
* @arg LSM303DLHC_IT1_DRY2
* @arg LSM303DLHC_IT1_WTM
* @arg LSM303DLHC_IT1_OVERRUN
* @retval None
*/
void LSM303DLHC_AccIT1Enable(uint8_t LSM303DLHC_IT)
{
uint8_t tmpval = 0x00;
/* Read CTRL_REG3 register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG3_A);
/* Enable IT1 */
tmpval |= LSM303DLHC_IT;
/* Write value to MEMS CTRL_REG3 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG3_A, tmpval);
}
/**
* @brief Disable LSM303DLHC Interrupt1
* @param LSM303DLHC_IT: specifies the LSM303DLHC interrupt source to be disabled.
* This parameter can be any combination of the following values:
* @arg LSM303DLHC_IT1_CLICK
* @arg LSM303DLHC_IT1_AOI1
* @arg LSM303DLHC_IT1_AOI2
* @arg LSM303DLHC_IT1_DRY1
* @arg LSM303DLHC_IT1_DRY2
* @arg LSM303DLHC_IT1_WTM
* @arg LSM303DLHC_IT1_OVERRUN
* @retval None
*/
void LSM303DLHC_AccIT1Disable(uint8_t LSM303DLHC_IT)
{
uint8_t tmpval = 0x00;
/* Read CTRL_REG3 register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG3_A);
/* Disable IT1 */
tmpval &= ~LSM303DLHC_IT;
/* Write value to MEMS CTRL_REG3 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG3_A, tmpval);
}
/**
* @brief Enable LSM303DLHC Interrupt2
* @param LSM303DLHC_IT: specifies the LSM303DLHC interrupt source to be enabled.
* This parameter can be any combination of the following values:
* @arg LSM303DLHC_IT2_CLICK
* @arg LSM303DLHC_IT2_INT1
* @arg LSM303DLHC_IT2_INT2
* @arg LSM303DLHC_IT2_BOOT
* @arg LSM303DLHC_IT2_ACT
* @arg LSM303DLHC_IT2_HLACTIVE
* @retval None
*/
void LSM303DLHC_AccIT2Enable(uint8_t LSM303DLHC_IT)
{
uint8_t tmpval = 0x00;
/* Read CTRL_REG3 register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG6_A);
/* Enable IT2 */
tmpval |= LSM303DLHC_IT;
/* Write value to MEMS CTRL_REG3 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG6_A, tmpval);
}
/**
* @brief Disable LSM303DLHC Interrupt2
* @param LSM303DLHC_IT: specifies the LSM303DLHC interrupt source to be disabled.
* This parameter can be any combination of the following values:
* @arg LSM303DLHC_IT2_CLICK
* @arg LSM303DLHC_IT2_INT1
* @arg LSM303DLHC_IT2_INT2
* @arg LSM303DLHC_IT2_BOOT
* @arg LSM303DLHC_IT2_ACT
* @arg LSM303DLHC_IT2_HLACTIVE
* @retval None
*/
void LSM303DLHC_AccIT2Disable(uint8_t LSM303DLHC_IT)
{
uint8_t tmpval = 0x00;
/* Read CTRL_REG3 register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG6_A);
/* Disable IT2 */
tmpval &= ~LSM303DLHC_IT;
/* Write value to MEMS CTRL_REG3 register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG6_A, tmpval);
}
/**
* @brief INT1 interrupt enable
* @param ITCombination: Or or And combination
* ITAxes: Axes to be enabled
* @retval None
*/
void LSM303DLHC_AccINT1InterruptEnable(uint8_t ITCombination, uint8_t ITAxes)
{
uint8_t tmpval = 0x00;
/* Read INT1_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_INT1_CFG_A);
/* Enable the selected interrupt */
tmpval |= (ITAxes | ITCombination);
/* Write value to MEMS INT1_CFR register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_INT1_CFG_A, tmpval);
}
/**
* @brief INT1 interrupt disable
* @param ITCombination: Or or And combination
* ITAxes: Axes to be enabled
* @retval None
*/
void LSM303DLHC_AccINT1InterruptDisable(uint8_t ITCombination, uint8_t ITAxes)
{
uint8_t tmpval = 0x00;
/* Read INT1_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_INT1_CFG_A);
/* Disable the selected interrupt */
tmpval &= ~(ITAxes | ITCombination);
/* Write value to MEMS INT1_CFR register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_INT1_CFG_A, tmpval);
}
/**
* @brief INT2 interrupt enable
* @param ITCombination: Or or And combination
* ITAxes: axes to be enabled
* @retval None
*/
void LSM303DLHC_AccINT2InterruptEnable(uint8_t ITCombination, uint8_t ITAxes)
{
uint8_t tmpval = 0x00;
/* Read INT2_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_INT2_CFG_A);
/* Enable the selected interrupt */
tmpval |= (ITAxes | ITCombination);
/* Write value to MEMS INT2_CFR register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_INT2_CFG_A, tmpval);
}
/**
* @brief INT2 interrupt config
* @param ITCombination: Or or And combination
* ITAxes: axes to be enabled
* @retval None
*/
void LSM303DLHC_AccINT2InterruptDisable(uint8_t ITCombination, uint8_t ITAxes)
{
uint8_t tmpval = 0x00;
/* Read INT2_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_INT2_CFG_A);
/* Disable the selected interrupt */
tmpval &= ~(ITAxes | ITCombination);
/* Write value to MEMS INT2_CFR register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_INT2_CFG_A, tmpval);
}
/**
* @brief Click interrupt enable
* @param ITClick: the selected interrupt to enable
* @retval None
*/
void LSM303DLHC_AccClickITEnable(uint8_t ITClick)
{
uint8_t tmpval = 0x00;
/* Read CLICK_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CLICK_CFG_A);
/* Enable the selected interrupt */
tmpval |= ITClick;
/* Write value to MEMS CLICK CFG register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CLICK_CFG_A, tmpval);
/* Configure Click Threshold on Z axis */
tmpval = 0x0A;
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CLICK_THS_A, tmpval);
/* Configure Time Limit */
tmpval = 0x05;
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_TIME_LIMIT_A, tmpval);
/* Configure Latency */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_TIME_LATENCY_A, tmpval);
/* Configure Click Window */
tmpval = 0x32;
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_TIME_WINDOW_A, tmpval);
}
/**
* @brief Click interrupt disable
* @param ITClick: the selected click interrupt to disable
* @retval None
*/
void LSM303DLHC_AccClickITDisable(uint8_t ITClick)
{
uint8_t tmpval = 0x00;
/* Read CLICK_CFR register */
tmpval = COMPASSACCELERO_IO_Read(ACC_I2C_ADDRESS, LSM303DLHC_CLICK_CFG_A);
/* Disable the selected interrupt */
tmpval &= ~ITClick;
/* Write value to MEMS CLICK_CFR register */
COMPASSACCELERO_IO_Write(ACC_I2C_ADDRESS, LSM303DLHC_CLICK_CFG_A, tmpval);
}
/**
* @brief Click on Z axis interrupt config
* @param None
* @retval None
*/
void LSM303DLHC_AccZClickITConfig(void)
{
/* Configure low level IT config */
COMPASSACCELERO_IO_ITConfig();
/* Select click IT as INT1 interrupt */
LSM303DLHC_AccIT1Enable(LSM303DLHC_IT1_CLICK);
/* Enable High pass filter for click IT */
LSM303DLHC_AccFilterClickCmd(LSM303DLHC_HPF_CLICK_ENABLE);
/* Enable simple click IT on Z axis, */
LSM303DLHC_AccClickITEnable(LSM303DLHC_Z_SINGLE_CLICK);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,498 @@
/**
******************************************************************************
* @file lsm303dlhc.h
* @author MCD Application Team
* @version V2.0.0
* @date 24-June-2015
* @brief This file contains all the functions prototypes for the lsm303dlhc.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LSM303DLHC_H
#define __LSM303DLHC_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/accelero.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup LSM303DLHC
* @{
*/
/** @defgroup LSM303DLHC_Exported_Types
* @{
*/
/**
* @}
*/
/******************************************************************************/
/*************************** START REGISTER MAPPING **************************/
/******************************************************************************/
/* Exported constant IO ------------------------------------------------------*/
#define ACC_I2C_ADDRESS 0x32
#define MAG_I2C_ADDRESS 0x3C
/* Acceleration Registers */
#define LSM303DLHC_WHO_AM_I_ADDR 0x0F /* device identification register */
#define LSM303DLHC_CTRL_REG1_A 0x20 /* Control register 1 acceleration */
#define LSM303DLHC_CTRL_REG2_A 0x21 /* Control register 2 acceleration */
#define LSM303DLHC_CTRL_REG3_A 0x22 /* Control register 3 acceleration */
#define LSM303DLHC_CTRL_REG4_A 0x23 /* Control register 4 acceleration */
#define LSM303DLHC_CTRL_REG5_A 0x24 /* Control register 5 acceleration */
#define LSM303DLHC_CTRL_REG6_A 0x25 /* Control register 6 acceleration */
#define LSM303DLHC_REFERENCE_A 0x26 /* Reference register acceleration */
#define LSM303DLHC_STATUS_REG_A 0x27 /* Status register acceleration */
#define LSM303DLHC_OUT_X_L_A 0x28 /* Output Register X acceleration */
#define LSM303DLHC_OUT_X_H_A 0x29 /* Output Register X acceleration */
#define LSM303DLHC_OUT_Y_L_A 0x2A /* Output Register Y acceleration */
#define LSM303DLHC_OUT_Y_H_A 0x2B /* Output Register Y acceleration */
#define LSM303DLHC_OUT_Z_L_A 0x2C /* Output Register Z acceleration */
#define LSM303DLHC_OUT_Z_H_A 0x2D /* Output Register Z acceleration */
#define LSM303DLHC_FIFO_CTRL_REG_A 0x2E /* Fifo control Register acceleration */
#define LSM303DLHC_FIFO_SRC_REG_A 0x2F /* Fifo src Register acceleration */
#define LSM303DLHC_INT1_CFG_A 0x30 /* Interrupt 1 configuration Register acceleration */
#define LSM303DLHC_INT1_SOURCE_A 0x31 /* Interrupt 1 source Register acceleration */
#define LSM303DLHC_INT1_THS_A 0x32 /* Interrupt 1 Threshold register acceleration */
#define LSM303DLHC_INT1_DURATION_A 0x33 /* Interrupt 1 DURATION register acceleration */
#define LSM303DLHC_INT2_CFG_A 0x34 /* Interrupt 2 configuration Register acceleration */
#define LSM303DLHC_INT2_SOURCE_A 0x35 /* Interrupt 2 source Register acceleration */
#define LSM303DLHC_INT2_THS_A 0x36 /* Interrupt 2 Threshold register acceleration */
#define LSM303DLHC_INT2_DURATION_A 0x37 /* Interrupt 2 DURATION register acceleration */
#define LSM303DLHC_CLICK_CFG_A 0x38 /* Click configuration Register acceleration */
#define LSM303DLHC_CLICK_SOURCE_A 0x39 /* Click 2 source Register acceleration */
#define LSM303DLHC_CLICK_THS_A 0x3A /* Click 2 Threshold register acceleration */
#define LSM303DLHC_TIME_LIMIT_A 0x3B /* Time Limit Register acceleration */
#define LSM303DLHC_TIME_LATENCY_A 0x3C /* Time Latency Register acceleration */
#define LSM303DLHC_TIME_WINDOW_A 0x3D /* Time window register acceleration */
/* Magnetic field Registers */
#define LSM303DLHC_CRA_REG_M 0x00 /* Control register A magnetic field */
#define LSM303DLHC_CRB_REG_M 0x01 /* Control register B magnetic field */
#define LSM303DLHC_MR_REG_M 0x02 /* Control register MR magnetic field */
#define LSM303DLHC_OUT_X_H_M 0x03 /* Output Register X magnetic field */
#define LSM303DLHC_OUT_X_L_M 0x04 /* Output Register X magnetic field */
#define LSM303DLHC_OUT_Z_H_M 0x05 /* Output Register Z magnetic field */
#define LSM303DLHC_OUT_Z_L_M 0x06 /* Output Register Z magnetic field */
#define LSM303DLHC_OUT_Y_H_M 0x07 /* Output Register Y magnetic field */
#define LSM303DLHC_OUT_Y_L_M 0x08 /* Output Register Y magnetic field */
#define LSM303DLHC_SR_REG_M 0x09 /* Status Register magnetic field */
#define LSM303DLHC_IRA_REG_M 0x0A /* IRA Register magnetic field */
#define LSM303DLHC_IRB_REG_M 0x0B /* IRB Register magnetic field */
#define LSM303DLHC_IRC_REG_M 0x0C /* IRC Register magnetic field */
#define LSM303DLHC_TEMP_OUT_H_M 0x31 /* Temperature Register magnetic field */
#define LSM303DLHC_TEMP_OUT_L_M 0x32 /* Temperature Register magnetic field */
/******************************************************************************/
/**************************** END REGISTER MAPPING ***************************/
/******************************************************************************/
#define I_AM_LMS303DLHC ((uint8_t)0x33)
/** @defgroup Acc_Power_Mode_selection
* @{
*/
#define LSM303DLHC_NORMAL_MODE ((uint8_t)0x00)
#define LSM303DLHC_LOWPOWER_MODE ((uint8_t)0x08)
/**
* @}
*/
/** @defgroup Acc_OutPut_DataRate_Selection
* @{
*/
#define LSM303DLHC_ODR_1_HZ ((uint8_t)0x10) /*!< Output Data Rate = 1 Hz */
#define LSM303DLHC_ODR_10_HZ ((uint8_t)0x20) /*!< Output Data Rate = 10 Hz */
#define LSM303DLHC_ODR_25_HZ ((uint8_t)0x30) /*!< Output Data Rate = 25 Hz */
#define LSM303DLHC_ODR_50_HZ ((uint8_t)0x40) /*!< Output Data Rate = 50 Hz */
#define LSM303DLHC_ODR_100_HZ ((uint8_t)0x50) /*!< Output Data Rate = 100 Hz */
#define LSM303DLHC_ODR_200_HZ ((uint8_t)0x60) /*!< Output Data Rate = 200 Hz */
#define LSM303DLHC_ODR_400_HZ ((uint8_t)0x70) /*!< Output Data Rate = 400 Hz */
#define LSM303DLHC_ODR_1620_HZ_LP ((uint8_t)0x80) /*!< Output Data Rate = 1620 Hz only in Low Power Mode */
#define LSM303DLHC_ODR_1344_HZ ((uint8_t)0x90) /*!< Output Data Rate = 1344 Hz in Normal mode and 5376 Hz in Low Power Mode */
/**
* @}
*/
/** @defgroup Acc_Axes_Selection
* @{
*/
#define LSM303DLHC_X_ENABLE ((uint8_t)0x01)
#define LSM303DLHC_Y_ENABLE ((uint8_t)0x02)
#define LSM303DLHC_Z_ENABLE ((uint8_t)0x04)
#define LSM303DLHC_AXES_ENABLE ((uint8_t)0x07)
#define LSM303DLHC_AXES_DISABLE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Acc_High_Resolution
* @{
*/
#define LSM303DLHC_HR_ENABLE ((uint8_t)0x08)
#define LSM303DLHC_HR_DISABLE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Acc_Full_Scale_Selection
* @{
*/
#define LSM303DLHC_FULLSCALE_2G ((uint8_t)0x00) /*!< ±2 g */
#define LSM303DLHC_FULLSCALE_4G ((uint8_t)0x10) /*!< ±4 g */
#define LSM303DLHC_FULLSCALE_8G ((uint8_t)0x20) /*!< ±8 g */
#define LSM303DLHC_FULLSCALE_16G ((uint8_t)0x30) /*!< ±16 g */
/**
* @}
*/
/** @defgroup Acc_Full_Scale_Selection
* @{
*/
#define LSM303DLHC_ACC_SENSITIVITY_2G ((uint8_t)1) /*!< accelerometer sensitivity with 2 g full scale [mg/LSB] */
#define LSM303DLHC_ACC_SENSITIVITY_4G ((uint8_t)2) /*!< accelerometer sensitivity with 4 g full scale [mg/LSB] */
#define LSM303DLHC_ACC_SENSITIVITY_8G ((uint8_t)4) /*!< accelerometer sensitivity with 8 g full scale [mg/LSB] */
#define LSM303DLHC_ACC_SENSITIVITY_16G ((uint8_t)12) /*!< accelerometer sensitivity with 12 g full scale [mg/LSB] */
/**
* @}
*/
/** @defgroup Acc_Block_Data_Update
* @{
*/
#define LSM303DLHC_BlockUpdate_Continous ((uint8_t)0x00) /*!< Continuos Update */
#define LSM303DLHC_BlockUpdate_Single ((uint8_t)0x80) /*!< Single Update: output registers not updated until MSB and LSB reading */
/**
* @}
*/
/** @defgroup Acc_Endian_Data_selection
* @{
*/
#define LSM303DLHC_BLE_LSB ((uint8_t)0x00) /*!< Little Endian: data LSB @ lower address */
#define LSM303DLHC_BLE_MSB ((uint8_t)0x40) /*!< Big Endian: data MSB @ lower address */
/**
* @}
*/
/** @defgroup Acc_Boot_Mode_selection
* @{
*/
#define LSM303DLHC_BOOT_NORMALMODE ((uint8_t)0x00)
#define LSM303DLHC_BOOT_REBOOTMEMORY ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_Mode
* @{
*/
#define LSM303DLHC_HPM_NORMAL_MODE_RES ((uint8_t)0x00)
#define LSM303DLHC_HPM_REF_SIGNAL ((uint8_t)0x40)
#define LSM303DLHC_HPM_NORMAL_MODE ((uint8_t)0x80)
#define LSM303DLHC_HPM_AUTORESET_INT ((uint8_t)0xC0)
/**
* @}
*/
/** @defgroup Acc_High_Pass_CUT OFF_Frequency
* @{
*/
#define LSM303DLHC_HPFCF_8 ((uint8_t)0x00)
#define LSM303DLHC_HPFCF_16 ((uint8_t)0x10)
#define LSM303DLHC_HPFCF_32 ((uint8_t)0x20)
#define LSM303DLHC_HPFCF_64 ((uint8_t)0x30)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_status
* @{
*/
#define LSM303DLHC_HIGHPASSFILTER_DISABLE ((uint8_t)0x00)
#define LSM303DLHC_HIGHPASSFILTER_ENABLE ((uint8_t)0x08)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_Click_status
* @{
*/
#define LSM303DLHC_HPF_CLICK_DISABLE ((uint8_t)0x00)
#define LSM303DLHC_HPF_CLICK_ENABLE ((uint8_t)0x04)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_AOI1_status
* @{
*/
#define LSM303DLHC_HPF_AOI1_DISABLE ((uint8_t)0x00)
#define LSM303DLHC_HPF_AOI1_ENABLE ((uint8_t)0x01)
/**
* @}
*/
/** @defgroup Acc_High_Pass_Filter_AOI2_status
* @{
*/
#define LSM303DLHC_HPF_AOI2_DISABLE ((uint8_t)0x00)
#define LSM303DLHC_HPF_AOI2_ENABLE ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_Interrupt1_Configuration_definition
* @{
*/
#define LSM303DLHC_IT1_CLICK ((uint8_t)0x80)
#define LSM303DLHC_IT1_AOI1 ((uint8_t)0x40)
#define LSM303DLHC_IT1_AOI2 ((uint8_t)0x20)
#define LSM303DLHC_IT1_DRY1 ((uint8_t)0x10)
#define LSM303DLHC_IT1_DRY2 ((uint8_t)0x08)
#define LSM303DLHC_IT1_WTM ((uint8_t)0x04)
#define LSM303DLHC_IT1_OVERRUN ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_Interrupt2_Configuration_definition
* @{
*/
#define LSM303DLHC_IT2_CLICK ((uint8_t)0x80)
#define LSM303DLHC_IT2_INT1 ((uint8_t)0x40)
#define LSM303DLHC_IT2_INT2 ((uint8_t)0x20)
#define LSM303DLHC_IT2_BOOT ((uint8_t)0x10)
#define LSM303DLHC_IT2_ACT ((uint8_t)0x08)
#define LSM303DLHC_IT2_HLACTIVE ((uint8_t)0x02)
/**
* @}
*/
/** @defgroup Acc_INT_Combination_Status
* @{
*/
#define LSM303DLHC_OR_COMBINATION ((uint8_t)0x00) /*!< OR combination of enabled IRQs */
#define LSM303DLHC_AND_COMBINATION ((uint8_t)0x80) /*!< AND combination of enabled IRQs */
#define LSM303DLHC_MOV_RECOGNITION ((uint8_t)0x40) /*!< 6D movement recognition */
#define LSM303DLHC_POS_RECOGNITION ((uint8_t)0xC0) /*!< 6D position recognition */
/**
* @}
*/
/** @defgroup Acc_INT_Axes
* @{
*/
#define LSM303DLHC_Z_HIGH ((uint8_t)0x20) /*!< Z High enabled IRQs */
#define LSM303DLHC_Z_LOW ((uint8_t)0x10) /*!< Z low enabled IRQs */
#define LSM303DLHC_Y_HIGH ((uint8_t)0x08) /*!< Y High enabled IRQs */
#define LSM303DLHC_Y_LOW ((uint8_t)0x04) /*!< Y low enabled IRQs */
#define LSM303DLHC_X_HIGH ((uint8_t)0x02) /*!< X High enabled IRQs */
#define LSM303DLHC_X_LOW ((uint8_t)0x01) /*!< X low enabled IRQs */
/**
* @}
*/
/** @defgroup Acc_INT_Click
* @{
*/
#define LSM303DLHC_Z_DOUBLE_CLICK ((uint8_t)0x20) /*!< Z double click IRQs */
#define LSM303DLHC_Z_SINGLE_CLICK ((uint8_t)0x10) /*!< Z single click IRQs */
#define LSM303DLHC_Y_DOUBLE_CLICK ((uint8_t)0x08) /*!< Y double click IRQs */
#define LSM303DLHC_Y_SINGLE_CLICK ((uint8_t)0x04) /*!< Y single click IRQs */
#define LSM303DLHC_X_DOUBLE_CLICK ((uint8_t)0x02) /*!< X double click IRQs */
#define LSM303DLHC_X_SINGLE_CLICK ((uint8_t)0x01) /*!< X single click IRQs */
/**
* @}
*/
/** @defgroup Acc_INT1_Interrupt_status
* @{
*/
#define LSM303DLHC_INT1INTERRUPT_DISABLE ((uint8_t)0x00)
#define LSM303DLHC_INT1INTERRUPT_ENABLE ((uint8_t)0x80)
/**
* @}
*/
/** @defgroup Acc_INT1_Interrupt_ActiveEdge
* @{
*/
#define LSM303DLHC_INT1INTERRUPT_LOW_EDGE ((uint8_t)0x20)
#define LSM303DLHC_INT1INTERRUPT_HIGH_EDGE ((uint8_t)0x00)
/**
* @}
*/
/** @defgroup Mag_Data_Rate
* @{
*/
#define LSM303DLHC_ODR_0_75_HZ ((uint8_t) 0x00) /*!< Output Data Rate = 0.75 Hz */
#define LSM303DLHC_ODR_1_5_HZ ((uint8_t) 0x04) /*!< Output Data Rate = 1.5 Hz */
#define LSM303DLHC_ODR_3_0_HZ ((uint8_t) 0x08) /*!< Output Data Rate = 3 Hz */
#define LSM303DLHC_ODR_7_5_HZ ((uint8_t) 0x0C) /*!< Output Data Rate = 7.5 Hz */
#define LSM303DLHC_ODR_15_HZ ((uint8_t) 0x10) /*!< Output Data Rate = 15 Hz */
#define LSM303DLHC_ODR_30_HZ ((uint8_t) 0x14) /*!< Output Data Rate = 30 Hz */
#define LSM303DLHC_ODR_75_HZ ((uint8_t) 0x18) /*!< Output Data Rate = 75 Hz */
#define LSM303DLHC_ODR_220_HZ ((uint8_t) 0x1C) /*!< Output Data Rate = 220 Hz */
/**
* @}
*/
/** @defgroup Mag_Full_Scale
* @{
*/
#define LSM303DLHC_FS_1_3_GA ((uint8_t) 0x20) /*!< Full scale = ±1.3 Gauss */
#define LSM303DLHC_FS_1_9_GA ((uint8_t) 0x40) /*!< Full scale = ±1.9 Gauss */
#define LSM303DLHC_FS_2_5_GA ((uint8_t) 0x60) /*!< Full scale = ±2.5 Gauss */
#define LSM303DLHC_FS_4_0_GA ((uint8_t) 0x80) /*!< Full scale = ±4.0 Gauss */
#define LSM303DLHC_FS_4_7_GA ((uint8_t) 0xA0) /*!< Full scale = ±4.7 Gauss */
#define LSM303DLHC_FS_5_6_GA ((uint8_t) 0xC0) /*!< Full scale = ±5.6 Gauss */
#define LSM303DLHC_FS_8_1_GA ((uint8_t) 0xE0) /*!< Full scale = ±8.1 Gauss */
/**
* @}
*/
/**
* @defgroup Magnetometer_Sensitivity
* @{
*/
#define LSM303DLHC_M_SENSITIVITY_XY_1_3Ga 1100 /*!< magnetometer X Y axes sensitivity for 1.3 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_1_9Ga 855 /*!< magnetometer X Y axes sensitivity for 1.9 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_2_5Ga 670 /*!< magnetometer X Y axes sensitivity for 2.5 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_4Ga 450 /*!< magnetometer X Y axes sensitivity for 4 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_4_7Ga 400 /*!< magnetometer X Y axes sensitivity for 4.7 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_5_6Ga 330 /*!< magnetometer X Y axes sensitivity for 5.6 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_XY_8_1Ga 230 /*!< magnetometer X Y axes sensitivity for 8.1 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_1_3Ga 980 /*!< magnetometer Z axis sensitivity for 1.3 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_1_9Ga 760 /*!< magnetometer Z axis sensitivity for 1.9 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_2_5Ga 600 /*!< magnetometer Z axis sensitivity for 2.5 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_4Ga 400 /*!< magnetometer Z axis sensitivity for 4 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_4_7Ga 355 /*!< magnetometer Z axis sensitivity for 4.7 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_5_6Ga 295 /*!< magnetometer Z axis sensitivity for 5.6 Ga full scale [LSB/Ga] */
#define LSM303DLHC_M_SENSITIVITY_Z_8_1Ga 205 /*!< magnetometer Z axis sensitivity for 8.1 Ga full scale [LSB/Ga] */
/**
* @}
*/
/** @defgroup Mag_Working_Mode
* @{
*/
#define LSM303DLHC_CONTINUOS_CONVERSION ((uint8_t) 0x00) /*!< Continuous-Conversion Mode */
#define LSM303DLHC_SINGLE_CONVERSION ((uint8_t) 0x01) /*!< Single-Conversion Mode */
#define LSM303DLHC_SLEEP ((uint8_t) 0x02) /*!< Sleep Mode */
/**
* @}
*/
/** @defgroup Mag_Temperature_Sensor
* @{
*/
#define LSM303DLHC_TEMPSENSOR_ENABLE ((uint8_t) 0x80) /*!< Temp sensor Enable */
#define LSM303DLHC_TEMPSENSOR_DISABLE ((uint8_t) 0x00) /*!< Temp sensor Disable */
/**
* @}
*/
/** @defgroup LSM303DLHC_Exported_Functions
* @{
*/
/* ACC functions */
void LSM303DLHC_AccInit(uint16_t InitStruct);
void LSM303DLHC_AccDeInit(void);
uint8_t LSM303DLHC_AccReadID(void);
void LSM303DLHC_AccRebootCmd(void);
void LSM303DLHC_AccFilterConfig(uint8_t FilterStruct);
void LSM303DLHC_AccFilterCmd(uint8_t HighPassFilterState);
void LSM303DLHC_AccReadXYZ(int16_t* pData);
void LSM303DLHC_AccFilterClickCmd(uint8_t HighPassFilterClickState);
void LSM303DLHC_AccIT1Enable(uint8_t LSM303DLHC_IT);
void LSM303DLHC_AccIT1Disable(uint8_t LSM303DLHC_IT);
void LSM303DLHC_AccIT2Enable(uint8_t LSM303DLHC_IT);
void LSM303DLHC_AccIT2Disable(uint8_t LSM303DLHC_IT);
void LSM303DLHC_AccINT1InterruptEnable(uint8_t ITCombination, uint8_t ITAxes);
void LSM303DLHC_AccINT1InterruptDisable(uint8_t ITCombination, uint8_t ITAxes);
void LSM303DLHC_AccINT2InterruptEnable(uint8_t ITCombination, uint8_t ITAxes);
void LSM303DLHC_AccINT2InterruptDisable(uint8_t ITCombination, uint8_t ITAxes);
void LSM303DLHC_AccClickITEnable(uint8_t ITClick);
void LSM303DLHC_AccClickITDisable(uint8_t ITClick);
void LSM303DLHC_AccZClickITConfig(void);
/* COMPASS / ACCELERO IO functions */
void COMPASSACCELERO_IO_Init(void);
void COMPASSACCELERO_IO_ITConfig(void);
void COMPASSACCELERO_IO_Write(uint16_t DeviceAddr, uint8_t RegisterAddr, uint8_t Value);
uint8_t COMPASSACCELERO_IO_Read(uint16_t DeviceAddr, uint8_t RegisterAddr);
/* ACC driver structure */
extern ACCELERO_DrvTypeDef Lsm303dlhcDrv;
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LSM303DLHC_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,394 @@
/**
******************************************************************************
* @file lsm6dsl.c
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief This file provides a set of functions needed to manage the LSM6DSL
* accelero and gyro devices
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "lsm6dsl.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup LSM6DSL LSM6DSL
* @{
*/
/** @defgroup LSM6DSL_Private_Variables LSM6DSL Private Variables
* @{
*/
ACCELERO_DrvTypeDef Lsm6dslAccDrv =
{
LSM6DSL_AccInit,
LSM6DSL_AccDeInit,
LSM6DSL_AccReadID,
0,
LSM6DSL_AccLowPower,
0,
0,
0,
0,
0,
0,
0,
LSM6DSL_AccReadXYZ
};
GYRO_DrvTypeDef Lsm6dslGyroDrv =
{
LSM6DSL_GyroInit,
LSM6DSL_GyroDeInit,
LSM6DSL_GyroReadID,
0,
LSM6DSL_GyroLowPower,
0,
0,
0,
0,
0,
0,
0,
LSM6DSL_GyroReadXYZAngRate
};
/**
* @}
*/
/** @defgroup LSM6DSL_ACC_Private_Functions LSM6DSL ACC Private Functions
* @{
*/
/**
* @brief Set LSM6DSL Accelerometer Initialization.
* @param InitStruct: Init parameters
*/
void LSM6DSL_AccInit(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
uint8_t tmp;
/* Read CTRL1_XL */
tmp = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL1_XL);
/* Write value to ACC MEMS CTRL1_XL register: FS and Data Rate */
ctrl = (uint8_t) InitStruct;
tmp &= ~(0xFC);
tmp |= ctrl;
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL1_XL, tmp);
/* Read CTRL3_C */
tmp = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL3_C);
/* Write value to ACC MEMS CTRL3_C register: BDU and Auto-increment */
ctrl = ((uint8_t) (InitStruct >> 8));
tmp &= ~(0x44);
tmp |= ctrl;
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL3_C, tmp);
}
/**
* @brief LSM6DSL Accelerometer De-initialization.
*/
void LSM6DSL_AccDeInit(void)
{
uint8_t ctrl = 0x00;
/* Read control register 1 value */
ctrl = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL1_XL);
/* Clear ODR bits */
ctrl &= ~(LSM6DSL_ODR_BITPOSITION);
/* Set Power down */
ctrl |= LSM6DSL_ODR_POWER_DOWN;
/* write back control register */
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL1_XL, ctrl);
}
/**
* @brief Read LSM6DSL ID.
* @retval ID
*/
uint8_t LSM6DSL_AccReadID(void)
{
/* IO interface initialization */
SENSOR_IO_Init();
/* Read value at Who am I register address */
return (SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_WHO_AM_I_REG));
}
/**
* @brief Set/Unset Accelerometer in low power mode.
* @param status 0 means disable Low Power Mode, otherwise Low Power Mode is enabled
*/
void LSM6DSL_AccLowPower(uint16_t status)
{
uint8_t ctrl = 0x00;
/* Read CTRL6_C value */
ctrl = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL6_C);
/* Clear Low Power Mode bit */
ctrl &= ~(0x10);
/* Set Low Power Mode */
if(status)
{
ctrl |= LSM6DSL_ACC_GYRO_LP_XL_ENABLED;
}else
{
ctrl |= LSM6DSL_ACC_GYRO_LP_XL_DISABLED;
}
/* write back control register */
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL6_C, ctrl);
}
/**
* @brief Read X, Y & Z Acceleration values
* @param pData: Data out pointer
*/
void LSM6DSL_AccReadXYZ(int16_t* pData)
{
int16_t pnRawData[3];
uint8_t ctrlx= 0;
uint8_t buffer[6];
uint8_t i = 0;
float sensitivity = 0;
/* Read the acceleration control register content */
ctrlx = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL1_XL);
/* Read output register X, Y & Z acceleration */
SENSOR_IO_ReadMultiple(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_OUTX_L_XL, buffer, 6);
for(i=0; i<3; i++)
{
pnRawData[i]=((((uint16_t)buffer[2*i+1]) << 8) + (uint16_t)buffer[2*i]);
}
/* Normal mode */
/* Switch the sensitivity value set in the CRTL1_XL */
switch(ctrlx & 0x0C)
{
case LSM6DSL_ACC_FULLSCALE_2G:
sensitivity = LSM6DSL_ACC_SENSITIVITY_2G;
break;
case LSM6DSL_ACC_FULLSCALE_4G:
sensitivity = LSM6DSL_ACC_SENSITIVITY_4G;
break;
case LSM6DSL_ACC_FULLSCALE_8G:
sensitivity = LSM6DSL_ACC_SENSITIVITY_8G;
break;
case LSM6DSL_ACC_FULLSCALE_16G:
sensitivity = LSM6DSL_ACC_SENSITIVITY_16G;
break;
}
/* Obtain the mg value for the three axis */
for(i=0; i<3; i++)
{
pData[i]=( int16_t )(pnRawData[i] * sensitivity);
}
}
/**
* @}
*/
/** @defgroup LSM6DSL_GYRO_Private_Functions LSM6DSL GYRO Private Functions
* @{
*/
/**
* @brief Set LSM6DSL Gyroscope Initialization.
* @param InitStruct: pointer to a LSM6DSL_InitTypeDef structure
* that contains the configuration setting for the LSM6DSL.
*/
void LSM6DSL_GyroInit(uint16_t InitStruct)
{
uint8_t ctrl = 0x00;
uint8_t tmp;
/* Read CTRL2_G */
tmp = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL2_G);
/* Write value to GYRO MEMS CTRL2_G register: FS and Data Rate */
ctrl = (uint8_t) InitStruct;
tmp &= ~(0xFC);
tmp |= ctrl;
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL2_G, tmp);
/* Read CTRL3_C */
tmp = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL3_C);
/* Write value to GYRO MEMS CTRL3_C register: BDU and Auto-increment */
ctrl = ((uint8_t) (InitStruct >> 8));
tmp &= ~(0x44);
tmp |= ctrl;
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL3_C, tmp);
}
/**
* @brief LSM6DSL Gyroscope De-initialization
*/
void LSM6DSL_GyroDeInit(void)
{
uint8_t ctrl = 0x00;
/* Read control register 1 value */
ctrl = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL2_G);
/* Clear ODR bits */
ctrl &= ~(LSM6DSL_ODR_BITPOSITION);
/* Set Power down */
ctrl |= LSM6DSL_ODR_POWER_DOWN;
/* write back control register */
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL2_G, ctrl);
}
/**
* @brief Read ID address of LSM6DSL
* @retval ID
*/
uint8_t LSM6DSL_GyroReadID(void)
{
/* IO interface initialization */
SENSOR_IO_Init();
/* Read value at Who am I register address */
return SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_WHO_AM_I_REG);
}
/**
* @brief Set/Unset LSM6DSL Gyroscope in low power mode
* @param status 0 means disable Low Power Mode, otherwise Low Power Mode is enabled
*/
void LSM6DSL_GyroLowPower(uint16_t status)
{
uint8_t ctrl = 0x00;
/* Read CTRL7_G value */
ctrl = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL7_G);
/* Clear Low Power Mode bit */
ctrl &= ~(0x80);
/* Set Low Power Mode */
if(status)
{
ctrl |= LSM6DSL_ACC_GYRO_LP_G_ENABLED;
}else
{
ctrl |= LSM6DSL_ACC_GYRO_LP_G_DISABLED;
}
/* write back control register */
SENSOR_IO_Write(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL7_G, ctrl);
}
/**
* @brief Calculate the LSM6DSL angular data.
* @param pfData: Data out pointer
*/
void LSM6DSL_GyroReadXYZAngRate(float *pfData)
{
int16_t pnRawData[3];
uint8_t ctrlg= 0;
uint8_t buffer[6];
uint8_t i = 0;
float sensitivity = 0;
/* Read the gyro control register content */
ctrlg = SENSOR_IO_Read(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_CTRL2_G);
/* Read output register X, Y & Z acceleration */
SENSOR_IO_ReadMultiple(LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, LSM6DSL_ACC_GYRO_OUTX_L_G, buffer, 6);
for(i=0; i<3; i++)
{
pnRawData[i]=((((uint16_t)buffer[2*i+1]) << 8) + (uint16_t)buffer[2*i]);
}
/* Normal mode */
/* Switch the sensitivity value set in the CRTL2_G */
switch(ctrlg & 0x0C)
{
case LSM6DSL_GYRO_FS_245:
sensitivity = LSM6DSL_GYRO_SENSITIVITY_245DPS;
break;
case LSM6DSL_GYRO_FS_500:
sensitivity = LSM6DSL_GYRO_SENSITIVITY_500DPS;
break;
case LSM6DSL_GYRO_FS_1000:
sensitivity = LSM6DSL_GYRO_SENSITIVITY_1000DPS;
break;
case LSM6DSL_GYRO_FS_2000:
sensitivity = LSM6DSL_GYRO_SENSITIVITY_2000DPS;
break;
}
/* Obtain the mg value for the three axis */
for(i=0; i<3; i++)
{
pfData[i]=( float )(pnRawData[i] * sensitivity);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,346 @@
/**
******************************************************************************
* @file lsm6dsl.h
* @author MCD Application Team
* @version V1.0.0
* @date 14-February-2017
* @brief LSM6DSL header driver file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LSM6DSL__H
#define __LSM6DSL__H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/accelero.h"
#include "../Common/gyro.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup LSM6DSL
* @{
*/
/** @defgroup LSM6DSL_Exported_Constants LSM6DSL Exported Constants
* @{
*/
/************** I2C Address *****************/
#define LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW 0xD4 // SAD[0] = 0
#define LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH 0xD6 // SAD[0] = 1
/************** Who am I *******************/
#define LSM6DSL_ACC_GYRO_WHO_AM_I 0x6A
/************** Device Register *******************/
#define LSM6DSL_ACC_GYRO_FUNC_CFG_ACCESS 0x01
#define LSM6DSL_ACC_GYRO_SENSOR_SYNC_TIME 0x04
#define LSM6DSL_ACC_GYRO_SENSOR_RES_RATIO 0x05
#define LSM6DSL_ACC_GYRO_FIFO_CTRL1 0x06
#define LSM6DSL_ACC_GYRO_FIFO_CTRL2 0x07
#define LSM6DSL_ACC_GYRO_FIFO_CTRL3 0x08
#define LSM6DSL_ACC_GYRO_FIFO_CTRL4 0x09
#define LSM6DSL_ACC_GYRO_FIFO_CTRL5 0x0A
#define LSM6DSL_ACC_GYRO_DRDY_PULSE_CFG_G 0x0B
#define LSM6DSL_ACC_GYRO_INT1_CTRL 0x0D
#define LSM6DSL_ACC_GYRO_INT2_CTRL 0x0E
#define LSM6DSL_ACC_GYRO_WHO_AM_I_REG 0x0F
#define LSM6DSL_ACC_GYRO_CTRL1_XL 0x10
#define LSM6DSL_ACC_GYRO_CTRL2_G 0x11
#define LSM6DSL_ACC_GYRO_CTRL3_C 0x12
#define LSM6DSL_ACC_GYRO_CTRL4_C 0x13
#define LSM6DSL_ACC_GYRO_CTRL5_C 0x14
#define LSM6DSL_ACC_GYRO_CTRL6_C 0x15
#define LSM6DSL_ACC_GYRO_CTRL7_G 0x16
#define LSM6DSL_ACC_GYRO_CTRL8_XL 0x17
#define LSM6DSL_ACC_GYRO_CTRL9_XL 0x18
#define LSM6DSL_ACC_GYRO_CTRL10_C 0x19
#define LSM6DSL_ACC_GYRO_MASTER_CONFIG 0x1A
#define LSM6DSL_ACC_GYRO_WAKE_UP_SRC 0x1B
#define LSM6DSL_ACC_GYRO_TAP_SRC 0x1C
#define LSM6DSL_ACC_GYRO_D6D_SRC 0x1D
#define LSM6DSL_ACC_GYRO_STATUS_REG 0x1E
#define LSM6DSL_ACC_GYRO_OUT_TEMP_L 0x20
#define LSM6DSL_ACC_GYRO_OUT_TEMP_H 0x21
#define LSM6DSL_ACC_GYRO_OUTX_L_G 0x22
#define LSM6DSL_ACC_GYRO_OUTX_H_G 0x23
#define LSM6DSL_ACC_GYRO_OUTY_L_G 0x24
#define LSM6DSL_ACC_GYRO_OUTY_H_G 0x25
#define LSM6DSL_ACC_GYRO_OUTZ_L_G 0x26
#define LSM6DSL_ACC_GYRO_OUTZ_H_G 0x27
#define LSM6DSL_ACC_GYRO_OUTX_L_XL 0x28
#define LSM6DSL_ACC_GYRO_OUTX_H_XL 0x29
#define LSM6DSL_ACC_GYRO_OUTY_L_XL 0x2A
#define LSM6DSL_ACC_GYRO_OUTY_H_XL 0x2B
#define LSM6DSL_ACC_GYRO_OUTZ_L_XL 0x2C
#define LSM6DSL_ACC_GYRO_OUTZ_H_XL 0x2D
#define LSM6DSL_ACC_GYRO_SENSORHUB1_REG 0x2E
#define LSM6DSL_ACC_GYRO_SENSORHUB2_REG 0x2F
#define LSM6DSL_ACC_GYRO_SENSORHUB3_REG 0x30
#define LSM6DSL_ACC_GYRO_SENSORHUB4_REG 0x31
#define LSM6DSL_ACC_GYRO_SENSORHUB5_REG 0x32
#define LSM6DSL_ACC_GYRO_SENSORHUB6_REG 0x33
#define LSM6DSL_ACC_GYRO_SENSORHUB7_REG 0x34
#define LSM6DSL_ACC_GYRO_SENSORHUB8_REG 0x35
#define LSM6DSL_ACC_GYRO_SENSORHUB9_REG 0x36
#define LSM6DSL_ACC_GYRO_SENSORHUB10_REG 0x37
#define LSM6DSL_ACC_GYRO_SENSORHUB11_REG 0x38
#define LSM6DSL_ACC_GYRO_SENSORHUB12_REG 0x39
#define LSM6DSL_ACC_GYRO_FIFO_STATUS1 0x3A
#define LSM6DSL_ACC_GYRO_FIFO_STATUS2 0x3B
#define LSM6DSL_ACC_GYRO_FIFO_STATUS3 0x3C
#define LSM6DSL_ACC_GYRO_FIFO_STATUS4 0x3D
#define LSM6DSL_ACC_GYRO_FIFO_DATA_OUT_L 0x3E
#define LSM6DSL_ACC_GYRO_FIFO_DATA_OUT_H 0x3F
#define LSM6DSL_ACC_GYRO_TIMESTAMP0_REG 0x40
#define LSM6DSL_ACC_GYRO_TIMESTAMP1_REG 0x41
#define LSM6DSL_ACC_GYRO_TIMESTAMP2_REG 0x42
#define LSM6DSL_ACC_GYRO_TIMESTAMP_L 0x49
#define LSM6DSL_ACC_GYRO_TIMESTAMP_H 0x4A
#define LSM6DSL_ACC_GYRO_STEP_COUNTER_L 0x4B
#define LSM6DSL_ACC_GYRO_STEP_COUNTER_H 0x4C
#define LSM6DSL_ACC_GYRO_SENSORHUB13_REG 0x4D
#define LSM6DSL_ACC_GYRO_SENSORHUB14_REG 0x4E
#define LSM6DSL_ACC_GYRO_SENSORHUB15_REG 0x4F
#define LSM6DSL_ACC_GYRO_SENSORHUB16_REG 0x50
#define LSM6DSL_ACC_GYRO_SENSORHUB17_REG 0x51
#define LSM6DSL_ACC_GYRO_SENSORHUB18_REG 0x52
#define LSM6DSL_ACC_GYRO_FUNC_SRC 0x53
#define LSM6DSL_ACC_GYRO_TAP_CFG1 0x58
#define LSM6DSL_ACC_GYRO_TAP_THS_6D 0x59
#define LSM6DSL_ACC_GYRO_INT_DUR2 0x5A
#define LSM6DSL_ACC_GYRO_WAKE_UP_THS 0x5B
#define LSM6DSL_ACC_GYRO_WAKE_UP_DUR 0x5C
#define LSM6DSL_ACC_GYRO_FREE_FALL 0x5D
#define LSM6DSL_ACC_GYRO_MD1_CFG 0x5E
#define LSM6DSL_ACC_GYRO_MD2_CFG 0x5F
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_X_L 0x66
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_X_H 0x67
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Y_L 0x68
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Y_H 0x69
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Z_L 0x6A
#define LSM6DSL_ACC_GYRO_OUT_MAG_RAW_Z_H 0x6B
#define LSM6DSL_ACC_GYRO_X_OFS_USR 0x73
#define LSM6DSL_ACC_GYRO_Y_OFS_USR 0x74
#define LSM6DSL_ACC_GYRO_Z_OFS_USR 0x75
/************** Embedded functions register mapping *******************/
#define LSM6DSL_ACC_GYRO_SLV0_ADD 0x02
#define LSM6DSL_ACC_GYRO_SLV0_SUBADD 0x03
#define LSM6DSL_ACC_GYRO_SLAVE0_CONFIG 0x04
#define LSM6DSL_ACC_GYRO_SLV1_ADD 0x05
#define LSM6DSL_ACC_GYRO_SLV1_SUBADD 0x06
#define LSM6DSL_ACC_GYRO_SLAVE1_CONFIG 0x07
#define LSM6DSL_ACC_GYRO_SLV2_ADD 0x08
#define LSM6DSL_ACC_GYRO_SLV2_SUBADD 0x09
#define LSM6DSL_ACC_GYRO_SLAVE2_CONFIG 0x0A
#define LSM6DSL_ACC_GYRO_SLV3_ADD 0x0B
#define LSM6DSL_ACC_GYRO_SLV3_SUBADD 0x0C
#define LSM6DSL_ACC_GYRO_SLAVE3_CONFIG 0x0D
#define LSM6DSL_ACC_GYRO_DATAWRITE_SRC_MODE_SUB_SLV0 0x0E
#define LSM6DSL_ACC_GYRO_CONFIG_PEDO_THS_MIN 0x0F
#define LSM6DSL_ACC_GYRO_SM_STEP_THS 0x13
#define LSM6DSL_ACC_GYRO_PEDO_DEB_REG 0x14
#define LSM6DSL_ACC_GYRO_STEP_COUNT_DELTA 0x15
#define LSM6DSL_ACC_GYRO_MAG_SI_XX 0x24
#define LSM6DSL_ACC_GYRO_MAG_SI_XY 0x25
#define LSM6DSL_ACC_GYRO_MAG_SI_XZ 0x26
#define LSM6DSL_ACC_GYRO_MAG_SI_YX 0x27
#define LSM6DSL_ACC_GYRO_MAG_SI_YY 0x28
#define LSM6DSL_ACC_GYRO_MAG_SI_YZ 0x29
#define LSM6DSL_ACC_GYRO_MAG_SI_ZX 0x2A
#define LSM6DSL_ACC_GYRO_MAG_SI_ZY 0x2B
#define LSM6DSL_ACC_GYRO_MAG_SI_ZZ 0x2C
#define LSM6DSL_ACC_GYRO_MAG_OFFX_L 0x2D
#define LSM6DSL_ACC_GYRO_MAG_OFFX_H 0x2E
#define LSM6DSL_ACC_GYRO_MAG_OFFY_L 0x2F
#define LSM6DSL_ACC_GYRO_MAG_OFFY_H 0x30
#define LSM6DSL_ACC_GYRO_MAG_OFFZ_L 0x31
#define LSM6DSL_ACC_GYRO_MAG_OFFZ_H 0x32
/* Accelero Full_ScaleSelection */
#define LSM6DSL_ACC_FULLSCALE_2G ((uint8_t)0x00) /*!< ±2 g */
#define LSM6DSL_ACC_FULLSCALE_4G ((uint8_t)0x08) /*!< ±4 g */
#define LSM6DSL_ACC_FULLSCALE_8G ((uint8_t)0x0C) /*!< ±8 g */
#define LSM6DSL_ACC_FULLSCALE_16G ((uint8_t)0x04) /*!< ±16 g */
/* Accelero Full Scale Sensitivity */
#define LSM6DSL_ACC_SENSITIVITY_2G ((float)0.061f) /*!< accelerometer sensitivity with 2 g full scale [mgauss/LSB] */
#define LSM6DSL_ACC_SENSITIVITY_4G ((float)0.122f) /*!< accelerometer sensitivity with 4 g full scale [mgauss/LSB] */
#define LSM6DSL_ACC_SENSITIVITY_8G ((float)0.244f) /*!< accelerometer sensitivity with 8 g full scale [mgauss/LSB] */
#define LSM6DSL_ACC_SENSITIVITY_16G ((float)0.488f) /*!< accelerometer sensitivity with 12 g full scale [mgauss/LSB] */
/* Accelero Power Mode selection */
#define LSM6DSL_ACC_GYRO_LP_XL_DISABLED ((uint8_t)0x00) /* LP disabled*/
#define LSM6DSL_ACC_GYRO_LP_XL_ENABLED ((uint8_t)0x10) /* LP enabled*/
/* Output Data Rate */
#define LSM6DSL_ODR_BITPOSITION ((uint8_t)0xF0) /*!< Output Data Rate bit position */
#define LSM6DSL_ODR_POWER_DOWN ((uint8_t)0x00) /* Power Down mode */
#define LSM6DSL_ODR_13Hz ((uint8_t)0x10) /* Low Power mode */
#define LSM6DSL_ODR_26Hz ((uint8_t)0x20) /* Low Power mode */
#define LSM6DSL_ODR_52Hz ((uint8_t)0x30) /* Low Power mode */
#define LSM6DSL_ODR_104Hz ((uint8_t)0x40) /* Normal mode */
#define LSM6DSL_ODR_208Hz ((uint8_t)0x50) /* Normal mode */
#define LSM6DSL_ODR_416Hz ((uint8_t)0x60) /* High Performance mode */
#define LSM6DSL_ODR_833Hz ((uint8_t)0x70) /* High Performance mode */
#define LSM6DSL_ODR_1660Hz ((uint8_t)0x80) /* High Performance mode */
#define LSM6DSL_ODR_3330Hz ((uint8_t)0x90) /* High Performance mode */
#define LSM6DSL_ODR_6660Hz ((uint8_t)0xA0) /* High Performance mode */
/* Gyro Full Scale Selection */
#define LSM6DSL_GYRO_FS_245 ((uint8_t)0x00)
#define LSM6DSL_GYRO_FS_500 ((uint8_t)0x04)
#define LSM6DSL_GYRO_FS_1000 ((uint8_t)0x08)
#define LSM6DSL_GYRO_FS_2000 ((uint8_t)0x0C)
/* Gyro Full Scale Sensitivity */
#define LSM6DSL_GYRO_SENSITIVITY_245DPS ((float)8.750f) /**< Sensitivity value for 245 dps full scale [mdps/LSB] */
#define LSM6DSL_GYRO_SENSITIVITY_500DPS ((float)17.50f) /**< Sensitivity value for 500 dps full scale [mdps/LSB] */
#define LSM6DSL_GYRO_SENSITIVITY_1000DPS ((float)35.00f) /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */
#define LSM6DSL_GYRO_SENSITIVITY_2000DPS ((float)70.00f) /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */
/* Gyro Power Mode selection */
#define LSM6DSL_ACC_GYRO_LP_G_DISABLED ((uint8_t)0x00) /* LP disabled*/
#define LSM6DSL_ACC_GYRO_LP_G_ENABLED ((uint8_t)0x80) /* LP enabled*/
/* Block Data Update */
#define LSM6DSL_BDU_CONTINUOS ((uint8_t)0x00)
#define LSM6DSL_BDU_BLOCK_UPDATE ((uint8_t)0x40)
/* Auto-increment */
#define LSM6DSL_ACC_GYRO_IF_INC_DISABLED ((uint8_t)0x00)
#define LSM6DSL_ACC_GYRO_IF_INC_ENABLED ((uint8_t)0x04)
/**
* @}
*/
/** @defgroup LSM6DSL_AccExported_Functions ACCELEROMETER Exported functions
* @{
*/
void LSM6DSL_AccInit(uint16_t InitStruct);
void LSM6DSL_AccDeInit(void);
uint8_t LSM6DSL_AccReadID(void);
void LSM6DSL_AccLowPower(uint16_t status);
void LSM6DSL_AccReadXYZ(int16_t* pData);
/**
* @}
*/
/** @defgroup LSM6DSL_AccImported_Globals ACCELEROMETER Imported Globals
* @{
*/
extern ACCELERO_DrvTypeDef Lsm6dslAccDrv;
/**
* @}
*/
/** @defgroup LSM6DSL_GyroExported_Functions GYROSCOPE Exported functions
* @{
*/
/* Sensor Configuration Functions */
void LSM6DSL_GyroInit(uint16_t InitStruct);
void LSM6DSL_GyroDeInit(void);
uint8_t LSM6DSL_GyroReadID(void);
void LSM6DSL_GyroLowPower(uint16_t status);
void LSM6DSL_GyroReadXYZAngRate(float *pfData);
/**
* @}
*/
/** @defgroup LSM6DSL_GyroImported_Globals GYROSCOPE Imported Globals
* @{
*/
/* Gyroscope driver structure */
extern GYRO_DrvTypeDef Lsm6dslGyroDrv;
/**
* @}
*/
/** @defgroup LSM6DSL_Imported_Functions LSM6DSL Imported Functions
* @{
*/
/* IO functions */
extern void SENSOR_IO_Init(void);
extern void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
extern uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
extern uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
extern void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __LSM6DSL__H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,185 @@
/**
******************************************************************************
* @file m24sr.h
* @author MCD Application Team
* @version V1.1.0
* @date 21-April-2017
* @brief This file provides a set of functions needed to manage M24SR
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution 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 other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __M24SR_H
#define __M24SR_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup M24SR
* @{
*/
/** @defgroup M24SR_Exported_Constants M24SR Exported Constants
* @{
*/
/* NFC IO specific config parameters */
#define NFC_IO_STATUS_SUCCESS (uint16_t) 0x0000
#define NFC_IO_ERROR_TIMEOUT (uint16_t) 0x0011
#define NFC_IO_TRIALS (uint32_t) 1 /* In case M24SR will reply ACK failed allow to perform retry */
/* Status and error code -----------------------------------------------------*/
#define M24SR_ACTION_COMPLETED (uint16_t) 0x9000
#define M24SR_STATUS_SUCCESS (uint16_t) 0x0000
#define M24SR_ERROR_DEFAULT (uint16_t) 0x0010
#define M24SR_ERROR_TIMEOUT (uint16_t) 0x0011
#define M24SR_ERROR_CRC (uint16_t) 0x0012
#define M24SR_ERROR_NACK (uint16_t) 0x0013
#define M24SR_ERROR_PARAMETER (uint16_t) 0x0014
#define M24SR_ERROR_NBATEMPT (uint16_t) 0x0015
#define M24SR_ERROR_NOACKNOWLEDGE (uint16_t) 0x0016
#define M24SR_ANSWER_TIMEOUT (uint32_t) 80 /* Timeout used by the component function NFC_IO_IsDeviceReady() */
#define M24SR_ANSWER_STABLE (uint8_t) 5 /* Loop repetition used by the component function NFC_IO_IsDeviceReady() */
/*-------------------------- GPO_Mode ----------------------------*/
#define M24SR_GPO_POLLING (uint8_t) 0x00 /* Normal I²C polling */
#define M24SR_GPO_SYNCHRO (uint8_t) 0x01 /* allow to use GPO polling as I2C synchronization */
#define M24SR_GPO_INTERRUPT (uint8_t) 0x02 /* allow to use GPO interrupt as I2C synchronization */
/*-------------------------- Password_Management ----------------------------*/
#define M24SR_READ_PWD (uint16_t) 0x0001
#define M24SR_WRITE_PWD (uint16_t) 0x0002
#define M24SR_I2C_PWD (uint16_t) 0x0003
/*-------------------------- Verify command answer ----------------------------*/
#define M24SR_PWD_NOT_NEEDED (uint16_t) 0x9000
#define M24SR_PWD_NEEDED (uint16_t) 0x6300
#define M24SR_PWD_CORRECT (uint16_t) 0x9000
/**
* @}
*/
/** @defgroup M24SR_Exported_FunctionsPrototypes M24SR Exported FunctionsPrototypes
* @{
*/
/* public function --------------------------------------------------------------------------*/
void M24SR_Init (uint16_t DeviceAddr, uint8_t GpoMode);
uint16_t M24SR_GetSession (uint16_t DeviceAddr);
uint16_t M24SR_KillSession (uint16_t DeviceAddr);
uint16_t M24SR_Deselect (uint16_t DeviceAddr);
uint16_t M24SR_SelectApplication (uint16_t DeviceAddr);
uint16_t M24SR_SelectCCfile (uint16_t DeviceAddr);
uint16_t M24SR_SelectNDEFfile (uint16_t DeviceAddr, uint16_t NDEFfileId);
uint16_t M24SR_SelectSystemfile (uint16_t DeviceAddr);
uint16_t M24SR_ReadBinary (uint16_t DeviceAddr, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
uint16_t M24SR_STReadBinary (uint16_t DeviceAddr, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
uint16_t M24SR_UpdateBinary (uint16_t DeviceAddr, uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite);
uint16_t M24SR_Verify (uint16_t DeviceAddr, uint16_t uPwdId, uint8_t NbPwdByte, uint8_t *pPwd);
uint16_t M24SR_ChangeReferenceData (uint16_t DeviceAddr, uint16_t uPwdId, uint8_t *pPwd);
uint16_t M24SR_EnableVerificationRequirement (uint16_t DeviceAddr, uint16_t uReadOrWrite);
uint16_t M24SR_DisableVerificationRequirement (uint16_t DeviceAddr, uint16_t uReadOrWrite);
uint16_t M24SR_EnablePermanentState (uint16_t DeviceAddr, uint16_t uReadOrWrite);
uint16_t M24SR_DisablePermanentState (uint16_t DeviceAddr, uint16_t uReadOrWrite);
uint16_t M24SR_SendInterrupt (uint16_t DeviceAddr);
uint16_t M24SR_StateControl (uint16_t DeviceAddr, uint8_t uSetOrReset);
uint16_t M24SR_ManageI2CGPO (uint16_t DeviceAddr, uint8_t GPO_I2Cconfig);
uint16_t M24SR_ManageRFGPO (uint16_t DeviceAddr, uint8_t GPO_RFconfig);
void M24SR_RFConfig (uint8_t OnOffChoice);
void M24SR_GPO_Callback (void );
/**
* @}
*/
/** @defgroup M24SR_Imported_Functions M24SR Imported Functions
* @{
*/
/* IO functions */
extern void NFC_IO_Init(uint8_t GpoIrqEnable);
extern void NFC_IO_DeInit(void);
extern uint16_t NFC_IO_ReadMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length );
extern uint16_t NFC_IO_WriteMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length);
extern uint16_t NFC_IO_IsDeviceReady (uint8_t Addr, uint32_t Trials);
extern void NFC_IO_ReadState(uint8_t * pPinState);
extern void NFC_IO_RfDisable(uint8_t PinState);
extern void NFC_IO_Delay(uint32_t Delay);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __M24SR_H */
/******************* (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,668 @@
/**
******************************************************************************
* @file mfxstm32l152.h
* @author MCD Application Team
* @version V2.0.0
* @date 24-June-2015
* @brief This file contains all the functions prototypes for the
* mfxstm32l152.c IO expander driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MFXSTM32L152_H
#define __MFXSTM32L152_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/ts.h"
#include "../Common/io.h"
#include "../Common/idd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup MFXSTM32L152
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup MFXSTM32L152_Exported_Types
* @{
*/
typedef struct
{
uint8_t SYS_CTRL;
uint8_t ERROR_SRC;
uint8_t ERROR_MSG;
uint8_t IRQ_OUT;
uint8_t IRQ_SRC_EN;
uint8_t IRQ_PENDING;
uint8_t IDD_CTRL;
uint8_t IDD_PRE_DELAY;
uint8_t IDD_SHUNT0_MSB;
uint8_t IDD_SHUNT0_LSB;
uint8_t IDD_SHUNT1_MSB;
uint8_t IDD_SHUNT1_LSB;
uint8_t IDD_SHUNT2_MSB;
uint8_t IDD_SHUNT2_LSB;
uint8_t IDD_SHUNT3_MSB;
uint8_t IDD_SHUNT3_LSB;
uint8_t IDD_SHUNT4_MSB;
uint8_t IDD_SHUNT4_LSB;
uint8_t IDD_GAIN_MSB;
uint8_t IDD_GAIN_LSB;
uint8_t IDD_VDD_MIN_MSB;
uint8_t IDD_VDD_MIN_LSB;
uint8_t IDD_VALUE_MSB;
uint8_t IDD_VALUE_MID;
uint8_t IDD_VALUE_LSB;
uint8_t IDD_CAL_OFFSET_MSB;
uint8_t IDD_CAL_OFFSET_LSB;
uint8_t IDD_SHUNT_USED;
}IDD_dbgTypeDef;
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup MFXSTM32L152_Exported_Constants
* @{
*/
/**
* @brief MFX COMMON defines
*/
/**
* @brief Register address: chip IDs (R)
*/
#define MFXSTM32L152_REG_ADR_ID ((uint8_t)0x00)
/**
* @brief Register address: chip FW_VERSION (R)
*/
#define MFXSTM32L152_REG_ADR_FW_VERSION_MSB ((uint8_t)0x01)
#define MFXSTM32L152_REG_ADR_FW_VERSION_LSB ((uint8_t)0x00)
/**
* @brief Register address: System Control Register (R/W)
*/
#define MFXSTM32L152_REG_ADR_SYS_CTRL ((uint8_t)0x40)
/**
* @brief Register address: Vdd monitoring (R)
*/
#define MFXSTM32L152_REG_ADR_VDD_REF_MSB ((uint8_t)0x06)
#define MFXSTM32L152_REG_ADR_VDD_REF_LSB ((uint8_t)0x07)
/**
* @brief Register address: Error source
*/
#define MFXSTM32L152_REG_ADR_ERROR_SRC ((uint8_t)0x03)
/**
* @brief Register address: Error Message
*/
#define MFXSTM32L152_REG_ADR_ERROR_MSG ((uint8_t)0x04)
/**
* @brief Reg Addr IRQs: to config the pin that informs Main MCU that MFX events appear
*/
#define MFXSTM32L152_REG_ADR_MFX_IRQ_OUT ((uint8_t)0x41)
/**
* @brief Reg Addr IRQs: to select the events which activate the MFXSTM32L152_IRQ_OUT signal
*/
#define MFXSTM32L152_REG_ADR_IRQ_SRC_EN ((uint8_t)0x42)
/**
* @brief Reg Addr IRQs: the Main MCU must read the IRQ_PENDING register to know the interrupt reason
*/
#define MFXSTM32L152_REG_ADR_IRQ_PENDING ((uint8_t)0x08)
/**
* @brief Reg Addr IRQs: the Main MCU must acknowledge it thanks to a writing access to the IRQ_ACK register
*/
#define MFXSTM32L152_REG_ADR_IRQ_ACK ((uint8_t)0x44)
/**
* @brief MFXSTM32L152_REG_ADR_ID choices
*/
#define MFXSTM32L152_ID_1 ((uint8_t)0x7B)
#define MFXSTM32L152_ID_2 ((uint8_t)0x79)
/**
* @brief MFXSTM32L152_REG_ADR_SYS_CTRL choices
*/
#define MFXSTM32L152_SWRST ((uint8_t)0x80)
#define MFXSTM32L152_STANDBY ((uint8_t)0x40)
#define MFXSTM32L152_ALTERNATE_GPIO_EN ((uint8_t)0x08) /* by the way if IDD and TS are enabled they take automatically the AF pins*/
#define MFXSTM32L152_IDD_EN ((uint8_t)0x04)
#define MFXSTM32L152_TS_EN ((uint8_t)0x02)
#define MFXSTM32L152_GPIO_EN ((uint8_t)0x01)
/**
* @brief MFXSTM32L152_REG_ADR_ERROR_SRC choices
*/
#define MFXSTM32L152_IDD_ERROR_SRC ((uint8_t)0x04) /* Error raised by Idd */
#define MFXSTM32L152_TS_ERROR_SRC ((uint8_t)0x02) /* Error raised by Touch Screen */
#define MFXSTM32L152_GPIO_ERROR_SRC ((uint8_t)0x01) /* Error raised by Gpio */
/**
* @brief MFXSTM32L152_REG_ADR_MFX_IRQ_OUT choices
*/
#define MFXSTM32L152_OUT_PIN_TYPE_OPENDRAIN ((uint8_t)0x00)
#define MFXSTM32L152_OUT_PIN_TYPE_PUSHPULL ((uint8_t)0x01)
#define MFXSTM32L152_OUT_PIN_POLARITY_LOW ((uint8_t)0x00)
#define MFXSTM32L152_OUT_PIN_POLARITY_HIGH ((uint8_t)0x02)
/**
* @brief REG_ADR_IRQ_SRC_EN, REG_ADR_IRQ_PENDING & REG_ADR_IRQ_ACK choices
*/
#define MFXSTM32L152_IRQ_TS_OVF ((uint8_t)0x80) /* TouchScreen FIFO Overflow irq*/
#define MFXSTM32L152_IRQ_TS_FULL ((uint8_t)0x40) /* TouchScreen FIFO Full irq*/
#define MFXSTM32L152_IRQ_TS_TH ((uint8_t)0x20) /* TouchScreen FIFO threshold triggered irq*/
#define MFXSTM32L152_IRQ_TS_NE ((uint8_t)0x10) /* TouchScreen FIFO Not Empty irq*/
#define MFXSTM32L152_IRQ_TS_DET ((uint8_t)0x08) /* TouchScreen Detect irq*/
#define MFXSTM32L152_IRQ_ERROR ((uint8_t)0x04) /* Error message from MFXSTM32L152 firmware irq */
#define MFXSTM32L152_IRQ_IDD ((uint8_t)0x02) /* IDD function irq */
#define MFXSTM32L152_IRQ_GPIO ((uint8_t)0x01) /* General GPIO irq (only for SRC_EN and PENDING) */
#define MFXSTM32L152_IRQ_ALL ((uint8_t)0xFF) /* All global interrupts */
#define MFXSTM32L152_IRQ_TS (MFXSTM32L152_IRQ_TS_DET | MFXSTM32L152_IRQ_TS_NE | MFXSTM32L152_IRQ_TS_TH | MFXSTM32L152_IRQ_TS_FULL | MFXSTM32L152_IRQ_TS_OVF )
/**
* @brief GPIO: 24 programmable input/output called MFXSTM32L152_GPIO[23:0] are provided
*/
/**
* @brief Reg addr: GPIO DIRECTION (R/W): GPIO pins direction: (0) input, (1) output.
*/
#define MFXSTM32L152_REG_ADR_GPIO_DIR1 ((uint8_t)0x60) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPIO_DIR2 ((uint8_t)0x61) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPIO_DIR3 ((uint8_t)0x62) /* agpio [0:7] */
/**
* @brief Reg addr: GPIO TYPE (R/W): If GPIO in output: (0) output push pull, (1) output open drain.
* If GPIO in input: (0) input without pull resistor, (1) input with pull resistor.
*/
#define MFXSTM32L152_REG_ADR_GPIO_TYPE1 ((uint8_t)0x64) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPIO_TYPE2 ((uint8_t)0x65) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPIO_TYPE3 ((uint8_t)0x66) /* agpio [0:7] */
/**
* @brief Reg addr: GPIO PULL_UP_PULL_DOWN (R/W): discussion open with Jean Claude
*/
#define MFXSTM32L152_REG_ADR_GPIO_PUPD1 ((uint8_t)0x68) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPIO_PUPD2 ((uint8_t)0x69) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPIO_PUPD3 ((uint8_t)0x6A) /* agpio [0:7] */
/**
* @brief Reg addr: GPIO SET (W): When GPIO is in output mode, write (1) puts the corresponding GPO in High level.
*/
#define MFXSTM32L152_REG_ADR_GPO_SET1 ((uint8_t)0x6C) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPO_SET2 ((uint8_t)0x6D) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPO_SET3 ((uint8_t)0x6E) /* agpio [0:7] */
/**
* @brief Reg addr: GPIO CLEAR (W): When GPIO is in output mode, write (1) puts the corresponding GPO in Low level.
*/
#define MFXSTM32L152_REG_ADR_GPO_CLR1 ((uint8_t)0x70) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPO_CLR2 ((uint8_t)0x71) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPO_CLR3 ((uint8_t)0x72) /* agpio [0:7] */
/**
* @brief Reg addr: GPIO STATE (R): Give state of the GPIO pin.
*/
#define MFXSTM32L152_REG_ADR_GPIO_STATE1 ((uint8_t)0x10) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_GPIO_STATE2 ((uint8_t)0x11) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_GPIO_STATE3 ((uint8_t)0x12) /* agpio [0:7] */
/**
* @brief GPIO IRQ_GPIs
*/
/* GPIOs can INDIVIDUALLY generate interruption to the Main MCU thanks to the MFXSTM32L152_IRQ_OUT signal */
/* the general MFXSTM32L152_IRQ_GPIO_SRC_EN shall be enabled too */
/**
* @brief GPIO IRQ_GPI_SRC1/2/3 (R/W): registers enable or not the feature to generate irq
*/
#define MFXSTM32L152_REG_ADR_IRQ_GPI_SRC1 ((uint8_t)0x48) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_SRC2 ((uint8_t)0x49) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_SRC3 ((uint8_t)0x4A) /* agpio [0:7] */
/**
* @brief GPIO IRQ_GPI_EVT1/2/3 (R/W): Irq generated on level (0) or edge (1).
*/
#define MFXSTM32L152_REG_ADR_IRQ_GPI_EVT1 ((uint8_t)0x4C) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_EVT2 ((uint8_t)0x4D) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_EVT3 ((uint8_t)0x4E) /* agpio [0:7] */
/**
* @brief GPIO IRQ_GPI_TYPE1/2/3 (R/W): Irq generated on (0) : Low level or Falling edge. (1) : High level or Rising edge.
*/
#define MFXSTM32L152_REG_ADR_IRQ_GPI_TYPE1 ((uint8_t)0x50) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_TYPE2 ((uint8_t)0x51) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_TYPE3 ((uint8_t)0x52) /* agpio [0:7] */
/**
* @brief GPIO IRQ_GPI_PENDING1/2/3 (R): irq occurs
*/
#define MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING1 ((uint8_t)0x0C) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING2 ((uint8_t)0x0D) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING3 ((uint8_t)0x0E) /* agpio [0:7] */
/**
* @brief GPIO IRQ_GPI_ACK1/2/3 (W): Write (1) to acknowledge IRQ event
*/
#define MFXSTM32L152_REG_ADR_IRQ_GPI_ACK1 ((uint8_t)0x54) /* gpio [0:7] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_ACK2 ((uint8_t)0x55) /* gpio [8:15] */
#define MFXSTM32L152_REG_ADR_IRQ_GPI_ACK3 ((uint8_t)0x56) /* agpio [0:7] */
/**
* @brief GPIO: IO Pins definition
*/
#define MFXSTM32L152_GPIO_PIN_0 ((uint32_t)0x0001)
#define MFXSTM32L152_GPIO_PIN_1 ((uint32_t)0x0002)
#define MFXSTM32L152_GPIO_PIN_2 ((uint32_t)0x0004)
#define MFXSTM32L152_GPIO_PIN_3 ((uint32_t)0x0008)
#define MFXSTM32L152_GPIO_PIN_4 ((uint32_t)0x0010)
#define MFXSTM32L152_GPIO_PIN_5 ((uint32_t)0x0020)
#define MFXSTM32L152_GPIO_PIN_6 ((uint32_t)0x0040)
#define MFXSTM32L152_GPIO_PIN_7 ((uint32_t)0x0080)
#define MFXSTM32L152_GPIO_PIN_8 ((uint32_t)0x0100)
#define MFXSTM32L152_GPIO_PIN_9 ((uint32_t)0x0200)
#define MFXSTM32L152_GPIO_PIN_10 ((uint32_t)0x0400)
#define MFXSTM32L152_GPIO_PIN_11 ((uint32_t)0x0800)
#define MFXSTM32L152_GPIO_PIN_12 ((uint32_t)0x1000)
#define MFXSTM32L152_GPIO_PIN_13 ((uint32_t)0x2000)
#define MFXSTM32L152_GPIO_PIN_14 ((uint32_t)0x4000)
#define MFXSTM32L152_GPIO_PIN_15 ((uint32_t)0x8000)
#define MFXSTM32L152_GPIO_PIN_16 ((uint32_t)0x010000)
#define MFXSTM32L152_GPIO_PIN_17 ((uint32_t)0x020000)
#define MFXSTM32L152_GPIO_PIN_18 ((uint32_t)0x040000)
#define MFXSTM32L152_GPIO_PIN_19 ((uint32_t)0x080000)
#define MFXSTM32L152_GPIO_PIN_20 ((uint32_t)0x100000)
#define MFXSTM32L152_GPIO_PIN_21 ((uint32_t)0x200000)
#define MFXSTM32L152_GPIO_PIN_22 ((uint32_t)0x400000)
#define MFXSTM32L152_GPIO_PIN_23 ((uint32_t)0x800000)
#define MFXSTM32L152_AGPIO_PIN_0 MFXSTM32L152_GPIO_PIN_16
#define MFXSTM32L152_AGPIO_PIN_1 MFXSTM32L152_GPIO_PIN_17
#define MFXSTM32L152_AGPIO_PIN_2 MFXSTM32L152_GPIO_PIN_18
#define MFXSTM32L152_AGPIO_PIN_3 MFXSTM32L152_GPIO_PIN_19
#define MFXSTM32L152_AGPIO_PIN_4 MFXSTM32L152_GPIO_PIN_20
#define MFXSTM32L152_AGPIO_PIN_5 MFXSTM32L152_GPIO_PIN_21
#define MFXSTM32L152_AGPIO_PIN_6 MFXSTM32L152_GPIO_PIN_22
#define MFXSTM32L152_AGPIO_PIN_7 MFXSTM32L152_GPIO_PIN_23
#define MFXSTM32L152_GPIO_PINS_ALL ((uint32_t)0xFFFFFF)
/**
* @brief GPIO: constant
*/
#define MFXSTM32L152_GPIO_DIR_IN ((uint8_t)0x0)
#define MFXSTM32L152_GPIO_DIR_OUT ((uint8_t)0x1)
#define MFXSTM32L152_IRQ_GPI_EVT_LEVEL ((uint8_t)0x0)
#define MFXSTM32L152_IRQ_GPI_EVT_EDGE ((uint8_t)0x1)
#define MFXSTM32L152_IRQ_GPI_TYPE_LLFE ((uint8_t)0x0) /* Low Level Falling Edge */
#define MFXSTM32L152_IRQ_GPI_TYPE_HLRE ((uint8_t)0x1) /*High Level Raising Edge */
#define MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR ((uint8_t)0x0)
#define MFXSTM32L152_GPI_WITH_PULL_RESISTOR ((uint8_t)0x1)
#define MFXSTM32L152_GPO_PUSH_PULL ((uint8_t)0x0)
#define MFXSTM32L152_GPO_OPEN_DRAIN ((uint8_t)0x1)
#define MFXSTM32L152_GPIO_PULL_DOWN ((uint8_t)0x0)
#define MFXSTM32L152_GPIO_PULL_UP ((uint8_t)0x1)
/**
* @brief TOUCH SCREEN Registers
*/
/**
* @brief Touch Screen Registers
*/
#define MFXSTM32L152_TS_SETTLING ((uint8_t)0xA0)
#define MFXSTM32L152_TS_TOUCH_DET_DELAY ((uint8_t)0xA1)
#define MFXSTM32L152_TS_AVE ((uint8_t)0xA2)
#define MFXSTM32L152_TS_TRACK ((uint8_t)0xA3)
#define MFXSTM32L152_TS_FIFO_TH ((uint8_t)0xA4)
#define MFXSTM32L152_TS_FIFO_STA ((uint8_t)0x20)
#define MFXSTM32L152_TS_FIFO_LEVEL ((uint8_t)0x21)
#define MFXSTM32L152_TS_XY_DATA ((uint8_t)0x24)
/**
* @brief TS registers masks
*/
#define MFXSTM32L152_TS_CTRL_STATUS ((uint8_t)0x08)
#define MFXSTM32L152_TS_CLEAR_FIFO ((uint8_t)0x80)
/**
* @brief Register address: Idd control register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_CTRL ((uint8_t)0x80)
/**
* @brief Register address: Idd pre delay register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_PRE_DELAY ((uint8_t)0x81)
/**
* @brief Register address: Idd Shunt registers (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_SHUNT0_MSB ((uint8_t)0x82)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT0_LSB ((uint8_t)0x83)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT1_MSB ((uint8_t)0x84)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT1_LSB ((uint8_t)0x85)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT2_MSB ((uint8_t)0x86)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT2_LSB ((uint8_t)0x87)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT3_MSB ((uint8_t)0x88)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT3_LSB ((uint8_t)0x89)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT4_MSB ((uint8_t)0x8A)
#define MFXSTM32L152_REG_ADR_IDD_SHUNT4_LSB ((uint8_t)0x8B)
/**
* @brief Register address: Idd ampli gain register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_GAIN_MSB ((uint8_t)0x8C)
#define MFXSTM32L152_REG_ADR_IDD_GAIN_LSB ((uint8_t)0x8D)
/**
* @brief Register address: Idd VDD min register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_VDD_MIN_MSB ((uint8_t)0x8E)
#define MFXSTM32L152_REG_ADR_IDD_VDD_MIN_LSB ((uint8_t)0x8F)
/**
* @brief Register address: Idd value register (R)
*/
#define MFXSTM32L152_REG_ADR_IDD_VALUE_MSB ((uint8_t)0x14)
#define MFXSTM32L152_REG_ADR_IDD_VALUE_MID ((uint8_t)0x15)
#define MFXSTM32L152_REG_ADR_IDD_VALUE_LSB ((uint8_t)0x16)
/**
* @brief Register address: Idd calibration offset register (R)
*/
#define MFXSTM32L152_REG_ADR_IDD_CAL_OFFSET_MSB ((uint8_t)0x18)
#define MFXSTM32L152_REG_ADR_IDD_CAL_OFFSET_LSB ((uint8_t)0x19)
/**
* @brief Register address: Idd shunt used offset register (R)
*/
#define MFXSTM32L152_REG_ADR_IDD_SHUNT_USED ((uint8_t)0x1A)
/**
* @brief Register address: shunt stabilisation delay registers (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_SH0_STABILIZATION ((uint8_t)0x90)
#define MFXSTM32L152_REG_ADR_IDD_SH1_STABILIZATION ((uint8_t)0x91)
#define MFXSTM32L152_REG_ADR_IDD_SH2_STABILIZATION ((uint8_t)0x92)
#define MFXSTM32L152_REG_ADR_IDD_SH3_STABILIZATION ((uint8_t)0x93)
#define MFXSTM32L152_REG_ADR_IDD_SH4_STABILIZATION ((uint8_t)0x94)
/**
* @brief Register address: Idd number of measurements register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_NBR_OF_MEAS ((uint8_t)0x96)
/**
* @brief Register address: Idd delta delay between 2 measurements register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_MEAS_DELTA_DELAY ((uint8_t)0x97)
/**
* @brief Register address: Idd number of shunt on board register (R/W)
*/
#define MFXSTM32L152_REG_ADR_IDD_SHUNTS_ON_BOARD ((uint8_t)0x98)
/** @defgroup IDD_Control_Register_Defines IDD Control Register Defines
* @{
*/
/**
* @brief IDD control register masks
*/
#define MFXSTM32L152_IDD_CTRL_REQ ((uint8_t)0x01)
#define MFXSTM32L152_IDD_CTRL_SHUNT_NB ((uint8_t)0x0E)
#define MFXSTM32L152_IDD_CTRL_VREF_DIS ((uint8_t)0x40)
#define MFXSTM32L152_IDD_CTRL_CAL_DIS ((uint8_t)0x80)
/**
* @brief IDD Shunt Number
*/
#define MFXSTM32L152_IDD_SHUNT_NB_1 ((uint8_t) 0x01)
#define MFXSTM32L152_IDD_SHUNT_NB_2 ((uint8_t) 0x02)
#define MFXSTM32L152_IDD_SHUNT_NB_3 ((uint8_t) 0x03)
#define MFXSTM32L152_IDD_SHUNT_NB_4 ((uint8_t) 0x04)
#define MFXSTM32L152_IDD_SHUNT_NB_5 ((uint8_t) 0x05)
/**
* @brief Vref Measurement
*/
#define MFXSTM32L152_IDD_VREF_AUTO_MEASUREMENT_ENABLE ((uint8_t) 0x00)
#define MFXSTM32L152_IDD_VREF_AUTO_MEASUREMENT_DISABLE ((uint8_t) 0x70)
/**
* @brief IDD Calibration
*/
#define MFXSTM32L152_IDD_AUTO_CALIBRATION_ENABLE ((uint8_t) 0x00)
#define MFXSTM32L152_IDD_AUTO_CALIBRATION_DISABLE ((uint8_t) 0x80)
/**
* @}
*/
/** @defgroup IDD_PreDelay_Defines IDD PreDelay Defines
* @{
*/
/**
* @brief IDD PreDelay masks
*/
#define MFXSTM32L152_IDD_PREDELAY_UNIT ((uint8_t) 0x80)
#define MFXSTM32L152_IDD_PREDELAY_VALUE ((uint8_t) 0x7F)
/**
* @brief IDD PreDelay unit
*/
#define MFXSTM32L152_IDD_PREDELAY_0_5_MS ((uint8_t) 0x00)
#define MFXSTM32L152_IDD_PREDELAY_20_MS ((uint8_t) 0x80)
/**
* @}
*/
/** @defgroup IDD_DeltaDelay_Defines IDD Delta DElay Defines
* @{
*/
/**
* @brief IDD Delta Delay masks
*/
#define MFXSTM32L152_IDD_DELTADELAY_UNIT ((uint8_t) 0x80)
#define MFXSTM32L152_IDD_DELTADELAY_VALUE ((uint8_t) 0x7F)
/**
* @brief IDD Delta Delay unit
*/
#define MFXSTM32L152_IDD_DELTADELAY_0_5_MS ((uint8_t) 0x00)
#define MFXSTM32L152_IDD_DELTADELAY_20_MS ((uint8_t) 0x80)
/**
* @}
*/
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup MFXSTM32L152_Exported_Macros
* @{
*/
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup MFXSTM32L152_Exported_Functions
* @{
*/
/**
* @brief MFXSTM32L152 Control functions
*/
void mfxstm32l152_Init(uint16_t DeviceAddr);
void mfxstm32l152_DeInit(uint16_t DeviceAddr);
void mfxstm32l152_Reset(uint16_t DeviceAddr);
uint16_t mfxstm32l152_ReadID(uint16_t DeviceAddr);
uint16_t mfxstm32l152_ReadFwVersion(uint16_t DeviceAddr);
void mfxstm32l152_LowPower(uint16_t DeviceAddr);
void mfxstm32l152_WakeUp(uint16_t DeviceAddr);
void mfxstm32l152_EnableITSource(uint16_t DeviceAddr, uint8_t Source);
void mfxstm32l152_DisableITSource(uint16_t DeviceAddr, uint8_t Source);
uint8_t mfxstm32l152_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source);
void mfxstm32l152_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source);
void mfxstm32l152_SetIrqOutPinPolarity(uint16_t DeviceAddr, uint8_t Polarity);
void mfxstm32l152_SetIrqOutPinType(uint16_t DeviceAddr, uint8_t Type);
/**
* @brief MFXSTM32L152 IO functionalities functions
*/
void mfxstm32l152_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
uint8_t mfxstm32l152_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
void mfxstm32l152_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
uint32_t mfxstm32l152_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
void mfxstm32l152_IO_EnableIT(uint16_t DeviceAddr);
void mfxstm32l152_IO_DisableIT(uint16_t DeviceAddr);
uint32_t mfxstm32l152_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
void mfxstm32l152_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void mfxstm32l152_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
void mfxstm32l152_IO_EnableAF(uint16_t DeviceAddr);
void mfxstm32l152_IO_DisableAF(uint16_t DeviceAddr);
void mfxstm32l152_IO_SetIrqTypeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Type);
void mfxstm32l152_IO_SetIrqEvtMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Evt);
void mfxstm32l152_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void mfxstm32l152_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
/**
* @brief MFXSTM32L152 Touch screen functionalities functions
*/
void mfxstm32l152_TS_Start(uint16_t DeviceAddr);
uint8_t mfxstm32l152_TS_DetectTouch(uint16_t DeviceAddr);
void mfxstm32l152_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
void mfxstm32l152_TS_EnableIT(uint16_t DeviceAddr);
void mfxstm32l152_TS_DisableIT(uint16_t DeviceAddr);
uint8_t mfxstm32l152_TS_ITStatus (uint16_t DeviceAddr);
void mfxstm32l152_TS_ClearIT (uint16_t DeviceAddr);
/**
* @brief MFXSTM32L152 IDD current measurement functionalities functions
*/
void mfxstm32l152_IDD_Start(uint16_t DeviceAddr);
void mfxstm32l152_IDD_Config(uint16_t DeviceAddr, IDD_ConfigTypeDef MfxIddConfig);
void mfxstm32l152_IDD_ConfigShuntNbLimit(uint16_t DeviceAddr, uint8_t ShuntNbLimit);
void mfxstm32l152_IDD_GetValue(uint16_t DeviceAddr, uint32_t *ReadValue);
uint8_t mfxstm32l152_IDD_GetShuntUsed(uint16_t DeviceAddr);
void mfxstm32l152_IDD_EnableIT(uint16_t DeviceAddr);
void mfxstm32l152_IDD_ClearIT(uint16_t DeviceAddr);
uint8_t mfxstm32l152_IDD_GetITStatus(uint16_t DeviceAddr);
void mfxstm32l152_IDD_DisableIT(uint16_t DeviceAddr);
/**
* @brief MFXSTM32L152 Error management functions
*/
uint8_t mfxstm32l152_Error_ReadSrc(uint16_t DeviceAddr);
uint8_t mfxstm32l152_Error_ReadMsg(uint16_t DeviceAddr);
void mfxstm32l152_Error_EnableIT(uint16_t DeviceAddr);
void mfxstm32l152_Error_ClearIT(uint16_t DeviceAddr);
uint8_t mfxstm32l152_Error_GetITStatus(uint16_t DeviceAddr);
void mfxstm32l152_Error_DisableIT(uint16_t DeviceAddr);
uint8_t mfxstm32l152_ReadReg(uint16_t DeviceAddr, uint8_t RegAddr);
void mfxstm32l152_WriteReg(uint16_t DeviceAddr, uint8_t RegAddr, uint8_t Value);
/**
* @brief iobus prototypes (they should be defined in common/stm32_iobus.h)
*/
void MFX_IO_Init(void);
void MFX_IO_DeInit(void);
void MFX_IO_ITConfig (void);
void MFX_IO_EnableWakeupPin(void);
void MFX_IO_Wakeup(void);
void MFX_IO_Delay(uint32_t delay);
void MFX_IO_Write(uint16_t addr, uint8_t reg, uint8_t value);
uint8_t MFX_IO_Read(uint16_t addr, uint8_t reg);
uint16_t MFX_IO_ReadMultiple(uint16_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
/**
* @}
*/
/* Touch screen driver structure */
extern TS_DrvTypeDef mfxstm32l152_ts_drv;
/* IO driver structure */
extern IO_DrvTypeDef mfxstm32l152_io_drv;
/* IDD driver structure */
extern IDD_DrvTypeDef mfxstm32l152_idd_drv;
#ifdef __cplusplus
}
#endif
#endif /* __MFXSTM32L152_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,317 @@
/**
******************************************************************************
* @file mx25lm51245g.h
* @author MCD Application Team
* @brief This file contains all the description of the MX25LM51245G Octal memory.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MX25LM51245G_H
#define __MX25LM51245G_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup MX25LM51245G
* @{
*/
/** @defgroup MX25LM51245G_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup MX25LM51245G_Exported_Constants
* @{
*/
/**
* @brief MX25LM51245G Configuration
*/
#define MX25LM51245G_FLASH_SIZE 0x4000000 /* 512 MBits => 64 MBytes */
#define MX25LM51245G_BLOCK_SIZE 0x10000 /* 1024 blocks of 64 KBytes */
#define MX25LM51245G_SECTOR_SIZE 0x1000 /* 16384 sectors of 4 kBytes */
#define MX25LM51245G_PAGE_SIZE 0x100 /* 262144 pages of 256 bytes */
#define MX25LM51245G_DUMMY_CYCLES_READ 8
#define MX25LM51245G_DUMMY_CYCLES_READ_OCTAL_66M 6
#define MX25LM51245G_DUMMY_CYCLES_READ_OCTAL_84M 8
#define MX25LM51245G_DUMMY_CYCLES_READ_OCTAL_104M 10
#define MX25LM51245G_DUMMY_CYCLES_READ_OCTAL_133M 14
#define MX25LM51245G_CR2_DC_66M MX25LM51245G_CR2_DC_6_CYCLES
#define MX25LM51245G_CR2_DC_84M MX25LM51245G_CR2_DC_8_CYCLES
#define MX25LM51245G_CR2_DC_104M MX25LM51245G_CR2_DC_10_CYCLES
#define MX25LM51245G_CR2_DC_133M MX25LM51245G_CR2_DC_14_CYCLES
#define MX25LM51245G_CHIP_ERASE_MAX_TIME 300000
#define MX25LM51245G_BLOCK_ERASE_MAX_TIME 2000
#define MX25LM51245G_SECTOR_ERASE_MAX_TIME 400
#define MX25LM51245G_WRITE_REG_MAX_TIME 40
/**
* @brief MX25LM51245G Commands
*/
/* Read Operations */
#define READ_CMD 0x03
#define READ_4_BYTE_ADDR_CMD 0x13
#define FAST_READ_CMD 0x0B
#define FAST_READ_4_BYTE_ADDR_CMD 0x0C
#define OCTAL_IO_READ_CMD 0xEC13
#define OCTAL_IO_DTR_READ_CMD 0xEE11
/* Program Operations */
#define PAGE_PROG_CMD 0x02
#define PAGE_PROG_4_BYTE_ADDR_CMD 0x12
#define OCTAL_PAGE_PROG_CMD 0x12ED
/* Erase Operations */
#define SECTOR_ERASE_CMD 0x20
#define SECTOR_ERASE_4_BYTE_ADDR_CMD 0x21
#define OCTAL_SECTOR_ERASE_CMD 0x21DE
#define BLOCK_ERASE_CMD 0xD8
#define BLOCK_ERASE_4_BYTE_ADDR_CMD 0xDC
#define OCTAL_BLOCK_ERASE_CMD 0xDC23
#define CHIP_ERASE_CMD 0x60
#define CHIP_ERASE_CMD_2 0xC7
#define OCTAL_CHIP_ERASE_CMD 0x609F
#define OCTAL_CHIP_ERASE_CMD_2 0xC738
#define PROG_ERASE_RESUME_CMD 0x30
#define PROG_ERASE_SUSPEND_CMD 0xB0
#define OCTAL_PROG_ERASE_RESUME_CMD 0x30CF
#define OCTAL_PROG_ERASE_SUSPEND_CMD 0xB04F
/* Identification Operations */
#define READ_ID_CMD 0x9F
#define READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5A
#define OCTAL_READ_ID_CMD 0x9F60
#define OCTAL_READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5AA5
/* Write Operations */
#define WRITE_ENABLE_CMD 0x06
#define WRITE_DISABLE_CMD 0x04
#define OCTAL_WRITE_ENABLE_CMD 0x06F9
#define OCTAL_WRITE_DISABLE_CMD 0x04FB
/* Register Operations */
#define READ_STATUS_REG_CMD 0x05
#define READ_CFG_REG_CMD 0x15
#define WRITE_STATUS_CFG_REG_CMD 0x01
#define OCTAL_READ_STATUS_REG_CMD 0x05FA
#define OCTAL_READ_CFG_REG_CMD 0x15EA
#define OCTAL_WRITE_STATUS_CFG_REG_CMD 0x01FE
#define READ_CFG_REG_2_CMD 0x71
#define WRITE_CFG_REG_2_CMD 0x72
#define OCTAL_READ_CFG_REG_2_CMD 0x718E
#define OCTAL_WRITE_CFG_REG_2_CMD 0x728D
#define READ_FAST_BOOT_REG_CMD 0x16
#define WRITE_FAST_BOOT_REG 0x17
#define ERASE_FAST_BOOT_REG 0x18
#define OCTAL_READ_FAST_BOOT_REG_CMD 0x16E9
#define OCTAL_WRITE_FAST_BOOT_REG 0x17E8
#define OCTAL_ERASE_FAST_BOOT_REG 0x18E7
#define READ_SEC_REG_CMD 0x2B
#define WRITE_SEC_REG_CMD 0x2F
#define OCTAL_READ_SECURITY_REG_CMD 0x2BD4
#define OCTAL_WRITE_SECURITY_REG_CMD 0x2FD0
#define READ_LOCK_REG_CMD 0x2D
#define WRITE_LOCK_REG_CMD 0x2C
#define OCTAL_READ_LOCK_REG_CMD 0x2DD2
#define OCTAL_WRITE_LOCK_REG_CMD 0x2CD3
#define READ_SPB_STATUS_CMD 0xE2
#define PROG_SPB_BIT_CMD 0xE3
#define ERASE_ALL_SPB_BIT_CMD 0xE4
#define OCTAL_READ_SPB_STATUS_CMD 0xE21D
#define OCTAL_PROG_SPB_BIT_CMD 0xE31C
#define OCTAL_ERASE_ALL_SPB_BIT_CMD 0xE41B
#define READ_DPB_REG_CMD 0xE0
#define WRITE_DPB_REG_CMD 0xE1
#define OCTAL_READ_DPB_REG_CMD 0xE01F
#define OCTAL_WRITE_DPB_REG_CMD 0xE11E
/* Power Down Operations */
#define DEEP_POWER_DOWN_CMD 0xB9
#define RELEASE_DEEP_POWER_DOWN_CMD 0xAB
#define OCTAL_ENTER_DEEP_POWER_DOWN_CMD 0xB946
/* Burst Operations */
#define SET_BURST_LENGTH_CMD 0xC0
#define OCTAL_SET_BURST_LENGTH_CMD 0xC03F
/* One-Time Programmable Operations */
#define ENTER_SECURED_OTP_CMD 0xB1
#define EXIT_SECURED_OTP_CMD 0xC1
#define OCTAL_ENTER_SECURED_OTP_CMD 0xB14E
#define OCTAL_EXIT_SECURED_OTP_CMD 0xC13E
/* No Operation */
#define NO_OPERATION_CMD 0x00
#define OCTAL_NO_OPERATION_CMD 0x00FF
/* Reset Operations */
#define RESET_ENABLE_CMD 0x66
#define RESET_MEMORY_CMD 0x99
#define OCTAL_RESET_ENABLE_CMD 0x6699
#define OCTAL_RESET_MEMORY_CMD 0x9966
/* Protection Operations */
#define WRITE_PROTECT_SEL_CMD 0x68
#define OCTAL_WRITE_PROTECT_SEL_CMD 0x6897
#define GANG_BLOCK_LOCK_CMD 0x7E
#define GANG_BLOCK_UNLOCK_CMD 0x98
#define OCTAL_GANG_BLOCK_LOCK_CMD 0x7E81
#define OCTAL_GANG_BLOCK_UNLOCK_CMD 0x9867
/**
* @brief MX25LM51245G Registers
*/
/* Status Register */
#define MX25LM51245G_SR_WIP ((uint8_t)0x01) /*!< Write in progress */
#define MX25LM51245G_SR_WEL ((uint8_t)0x02) /*!< Write enable latch */
#define MX25LM51245G_SR_BP ((uint8_t)0x3C) /*!< Block protect */
/* Configuration Register 1 */
#define MX25LM51245G_CR1_ODS ((uint8_t)0x07) /*!< Output driver strength */
#define MX25LM51245G_CR1_TB ((uint8_t)0x08) /*!< Top / bottom */
/* Configuration Register 2 */
/* Address : 0x00000000 */
#define MX25LM51245G_CR2_REG1_ADDR ((uint32_t)0x00000000) /*!< CR2 register address 0x00000000 */
#define MX25LM51245G_CR2_SOPI ((uint8_t)0x01) /*!< STR OPI Enable */
#define MX25LM51245G_CR2_DOPI ((uint8_t)0x02) /*!< DTR OPI Enable */
/* Address : 0x00000200 */
#define MX25LM51245G_CR2_REG2_ADDR ((uint32_t)0x00000200) /*!< CR2 register address 0x00000200 */
#define MX25LM51245G_CR2_DQSPRC ((uint8_t)0x01) /*!< DTR DQS pre-cycle */
#define MX25LM51245G_CR2_DOS ((uint8_t)0x02) /*!< DQS on STR mode */
/* Address : 0x00000300 */
#define MX25LM51245G_CR2_REG3_ADDR ((uint32_t)0x00000300) /*!< CR2 register address 0x00000300 */
#define MX25LM51245G_CR2_DC ((uint8_t)0x07) /*!< Dummy cycle */
#define MX25LM51245G_CR2_DC_20_CYCLES ((uint8_t)0x00) /*!< 20 Dummy cycles */
#define MX25LM51245G_CR2_DC_18_CYCLES ((uint8_t)0x01) /*!< 18 Dummy cycles */
#define MX25LM51245G_CR2_DC_16_CYCLES ((uint8_t)0x02) /*!< 16 Dummy cycles */
#define MX25LM51245G_CR2_DC_14_CYCLES ((uint8_t)0x03) /*!< 14 Dummy cycles */
#define MX25LM51245G_CR2_DC_12_CYCLES ((uint8_t)0x04) /*!< 12 Dummy cycles */
#define MX25LM51245G_CR2_DC_10_CYCLES ((uint8_t)0x05) /*!< 10 Dummy cycles */
#define MX25LM51245G_CR2_DC_8_CYCLES ((uint8_t)0x06) /*!< 8 Dummy cycles */
#define MX25LM51245G_CR2_DC_6_CYCLES ((uint8_t)0x07) /*!< 6 Dummy cycles */
/* Address : 0x00000500 */
#define MX25LM51245G_CR2_REG4_ADDR ((uint32_t)0x00000500) /*!< CR2 register address 0x00000500 */
#define MX25LM51245G_CR2_PPTSEL ((uint8_t)0x01) /*!< Preamble pattern selection */
/* Address : 0x40000000 */
#define MX25LM51245G_CR2_REG5_ADDR ((uint32_t)0x40000000) /*!< CR2 register address 0x40000000 */
#define MX25LM51245G_CR2_DEFSOPI ((uint8_t)0x01) /*!< Enable SOPI after power on reset */
#define MX25LM51245G_CR2_DEFDOPI ((uint8_t)0x02) /*!< Enable DOPI after power on reset */
/* Security Register */
#define MX25LM51245G_SECR_SOI ((uint8_t)0x01) /*!< Secured OTP indicator */
#define MX25LM51245G_SECR_LDSO ((uint8_t)0x02) /*!< Lock-down secured OTP */
#define MX25LM51245G_SECR_PSB ((uint8_t)0x04) /*!< Program suspend bit */
#define MX25LM51245G_SECR_ESB ((uint8_t)0x08) /*!< Erase suspend bit */
#define MX25LM51245G_SECR_P_FAIL ((uint8_t)0x20) /*!< Program fail flag */
#define MX25LM51245G_SECR_E_FAIL ((uint8_t)0x40) /*!< Erase fail flag */
#define MX25LM51245G_SECR_WPSEL ((uint8_t)0x40) /*!< Write protection selection */
/**
* @}
*/
/** @defgroup MX25LM51245G_Exported_Functions
* @{
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __MX25LM51245G_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,211 @@
/**
******************************************************************************
* @file mx25r6435f.h
* @author MCD Application Team
* @version V1.0.0
* @date 17-February-2017
* @brief This file contains all the description of the MX25R6435F QSPI memory.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MX25R6435F_H
#define __MX25R6435F_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup mx25r6435f
* @{
*/
/** @defgroup MX25R6435F_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup MX25R6435F_Exported_Constants
* @{
*/
/**
* @brief MX25R6435F Configuration
*/
#define MX25R6435F_FLASH_SIZE 0x800000 /* 64 MBits => 8MBytes */
#define MX25R6435F_BLOCK_SIZE 0x10000 /* 128 blocks of 64KBytes */
#define MX25R6435F_SUBBLOCK_SIZE 0x8000 /* 256 blocks of 32KBytes */
#define MX25R6435F_SECTOR_SIZE 0x1000 /* 2048 sectors of 4kBytes */
#define MX25R6435F_PAGE_SIZE 0x100 /* 32768 pages of 256 bytes */
#define MX25R6435F_DUMMY_CYCLES_READ 8
#define MX25R6435F_DUMMY_CYCLES_READ_DUAL 4
#define MX25R6435F_DUMMY_CYCLES_READ_QUAD 4
#define MX25R6435F_DUMMY_CYCLES_2READ 2
#define MX25R6435F_DUMMY_CYCLES_4READ 4
#define MX25R6435F_ALT_BYTES_PE_MODE 0xA5
#define MX25R6435F_ALT_BYTES_NO_PE_MODE 0xAA
#define MX25R6435F_CHIP_ERASE_MAX_TIME 240000
#define MX25R6435F_BLOCK_ERASE_MAX_TIME 3500
#define MX25R6435F_SUBBLOCK_ERASE_MAX_TIME 3000
#define MX25R6435F_SECTOR_ERASE_MAX_TIME 240
/**
* @brief MX25R6435F Commands
*/
/* Read Operations */
#define READ_CMD 0x03
#define FAST_READ_CMD 0x0B
#define DUAL_OUT_READ_CMD 0x3B
#define DUAL_INOUT_READ_CMD 0xBB
#define QUAD_OUT_READ_CMD 0x6B
#define QUAD_INOUT_READ_CMD 0xEB
/* Program Operations */
#define PAGE_PROG_CMD 0x02
#define QUAD_PAGE_PROG_CMD 0x38
/* Erase Operations */
#define SECTOR_ERASE_CMD 0x20
#define SUBBLOCK_ERASE_CMD 0x52
#define BLOCK_ERASE_CMD 0xD8
#define CHIP_ERASE_CMD 0x60
#define CHIP_ERASE_CMD_2 0xC7
#define PROG_ERASE_RESUME_CMD 0x7A
#define PROG_ERASE_RESUME_CMD_2 0x30
#define PROG_ERASE_SUSPEND_CMD 0x75
#define PROG_ERASE_SUSPEND_CMD_2 0xB0
/* Identification Operations */
#define READ_ID_CMD 0x9F
#define READ_ELECTRONIC_ID_CMD 0xAB
#define READ_ELEC_MANUFACTURER_DEVICE_ID_CMD 0x90
#define READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5A
/* Write Operations */
#define WRITE_ENABLE_CMD 0x06
#define WRITE_DISABLE_CMD 0x04
/* Register Operations */
#define READ_STATUS_REG_CMD 0x05
#define READ_CFG_REG_CMD 0x15
#define WRITE_STATUS_CFG_REG_CMD 0x01
#define READ_SEC_REG_CMD 0x2B
#define WRITE_SEC_REG_CMD 0x2F
/* Power Down Operations */
#define DEEP_POWER_DOWN_CMD 0xB9
/* Burst Operations */
#define SET_BURST_LENGTH_CMD 0xC0
/* One-Time Programmable Operations */
#define ENTER_SECURED_OTP_CMD 0xB1
#define EXIT_SECURED_OTP_CMD 0xC1
/* No Operation */
#define NO_OPERATION_CMD 0x00
/* Reset Operations */
#define RESET_ENABLE_CMD 0x66
#define RESET_MEMORY_CMD 0x99
#define RELEASE_READ_ENHANCED_CMD 0xFF
/**
* @brief MX25R6435F Registers
*/
/* Status Register */
#define MX25R6435F_SR_WIP ((uint8_t)0x01) /*!< Write in progress */
#define MX25R6435F_SR_WEL ((uint8_t)0x02) /*!< Write enable latch */
#define MX25R6435F_SR_BP ((uint8_t)0x3C) /*!< Block protect */
#define MX25R6435F_SR_QE ((uint8_t)0x40) /*!< Quad enable */
#define MX25R6435F_SR_SRWD ((uint8_t)0x80) /*!< Status register write disable */
/* Configuration Register 1 */
#define MX25R6435F_CR1_TB ((uint8_t)0x08) /*!< Top / bottom */
/* Configuration Register 2 */
#define MX25R6435F_CR2_LH_SWITCH ((uint8_t)0x02) /*!< Low power / high performance switch */
/* Security Register */
#define MX25R6435F_SECR_SOI ((uint8_t)0x01) /*!< Secured OTP indicator */
#define MX25R6435F_SECR_LDSO ((uint8_t)0x02) /*!< Lock-down secured OTP */
#define MX25R6435F_SECR_PSB ((uint8_t)0x04) /*!< Program suspend bit */
#define MX25R6435F_SECR_ESB ((uint8_t)0x08) /*!< Erase suspend bit */
#define MX25R6435F_SECR_P_FAIL ((uint8_t)0x20) /*!< Program fail flag */
#define MX25R6435F_SECR_E_FAIL ((uint8_t)0x40) /*!< Erase fail flag */
/**
* @}
*/
/** @defgroup MX25R6435F_Exported_Functions
* @{
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __MX25R6435F_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,219 @@
/**
******************************************************************************
* @file n25q128a.h
* @author MCD Application Team
* @version V1.0.0
* @date 29-May-2015
* @brief This file contains all the description of the N25Q128A QSPI memory.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __N25Q128A_H
#define __N25Q128A_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup n25q128a
* @{
*/
/** @defgroup N25Q128A_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup N25Q128A_Exported_Constants
* @{
*/
/**
* @brief N25Q128A Configuration
*/
#define N25Q128A_FLASH_SIZE 0x1000000 /* 128 MBits => 16MBytes */
#define N25Q128A_SECTOR_SIZE 0x10000 /* 256 sectors of 64KBytes */
#define N25Q128A_SUBSECTOR_SIZE 0x1000 /* 4096 subsectors of 4kBytes */
#define N25Q128A_PAGE_SIZE 0x100 /* 65536 pages of 256 bytes */
#define N25Q128A_DUMMY_CYCLES_READ 8
#define N25Q128A_DUMMY_CYCLES_READ_QUAD 10
#define N25Q128A_BULK_ERASE_MAX_TIME 250000
#define N25Q128A_SECTOR_ERASE_MAX_TIME 3000
#define N25Q128A_SUBSECTOR_ERASE_MAX_TIME 800
/**
* @brief N25Q128A Commands
*/
/* Reset Operations */
#define RESET_ENABLE_CMD 0x66
#define RESET_MEMORY_CMD 0x99
/* Identification Operations */
#define READ_ID_CMD 0x9E
#define READ_ID_CMD2 0x9F
#define MULTIPLE_IO_READ_ID_CMD 0xAF
#define READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5A
/* Read Operations */
#define READ_CMD 0x03
#define FAST_READ_CMD 0x0B
#define DUAL_OUT_FAST_READ_CMD 0x3B
#define DUAL_INOUT_FAST_READ_CMD 0xBB
#define QUAD_OUT_FAST_READ_CMD 0x6B
#define QUAD_INOUT_FAST_READ_CMD 0xEB
/* Write Operations */
#define WRITE_ENABLE_CMD 0x06
#define WRITE_DISABLE_CMD 0x04
/* Register Operations */
#define READ_STATUS_REG_CMD 0x05
#define WRITE_STATUS_REG_CMD 0x01
#define READ_LOCK_REG_CMD 0xE8
#define WRITE_LOCK_REG_CMD 0xE5
#define READ_FLAG_STATUS_REG_CMD 0x70
#define CLEAR_FLAG_STATUS_REG_CMD 0x50
#define READ_NONVOL_CFG_REG_CMD 0xB5
#define WRITE_NONVOL_CFG_REG_CMD 0xB1
#define READ_VOL_CFG_REG_CMD 0x85
#define WRITE_VOL_CFG_REG_CMD 0x81
#define READ_ENHANCED_VOL_CFG_REG_CMD 0x65
#define WRITE_ENHANCED_VOL_CFG_REG_CMD 0x61
/* Program Operations */
#define PAGE_PROG_CMD 0x02
#define DUAL_IN_FAST_PROG_CMD 0xA2
#define EXT_DUAL_IN_FAST_PROG_CMD 0xD2
#define QUAD_IN_FAST_PROG_CMD 0x32
#define EXT_QUAD_IN_FAST_PROG_CMD 0x12
/* Erase Operations */
#define SUBSECTOR_ERASE_CMD 0x20
#define SECTOR_ERASE_CMD 0xD8
#define BULK_ERASE_CMD 0xC7
#define PROG_ERASE_RESUME_CMD 0x7A
#define PROG_ERASE_SUSPEND_CMD 0x75
/* One-Time Programmable Operations */
#define READ_OTP_ARRAY_CMD 0x4B
#define PROG_OTP_ARRAY_CMD 0x42
/**
* @brief N25Q128A Registers
*/
/* Status Register */
#define N25Q128A_SR_WIP ((uint8_t)0x01) /*!< Write in progress */
#define N25Q128A_SR_WREN ((uint8_t)0x02) /*!< Write enable latch */
#define N25Q128A_SR_BLOCKPR ((uint8_t)0x5C) /*!< Block protected against program and erase operations */
#define N25Q128A_SR_PRBOTTOM ((uint8_t)0x20) /*!< Protected memory area defined by BLOCKPR starts from top or bottom */
#define N25Q128A_SR_SRWREN ((uint8_t)0x80) /*!< Status register write enable/disable */
/* Nonvolatile Configuration Register */
#define N25Q128A_NVCR_LOCK ((uint16_t)0x0001) /*!< Lock nonvolatile configuration register */
#define N25Q128A_NVCR_DUAL ((uint16_t)0x0004) /*!< Dual I/O protocol */
#define N25Q128A_NVCR_QUAB ((uint16_t)0x0008) /*!< Quad I/O protocol */
#define N25Q128A_NVCR_RH ((uint16_t)0x0010) /*!< Reset/hold */
#define N25Q128A_NVCR_ODS ((uint16_t)0x01C0) /*!< Output driver strength */
#define N25Q128A_NVCR_XIP ((uint16_t)0x0E00) /*!< XIP mode at power-on reset */
#define N25Q128A_NVCR_NB_DUMMY ((uint16_t)0xF000) /*!< Number of dummy clock cycles */
/* Volatile Configuration Register */
#define N25Q128A_VCR_WRAP ((uint8_t)0x03) /*!< Wrap */
#define N25Q128A_VCR_XIP ((uint8_t)0x08) /*!< XIP */
#define N25Q128A_VCR_NB_DUMMY ((uint8_t)0xF0) /*!< Number of dummy clock cycles */
/* Enhanced Volatile Configuration Register */
#define N25Q128A_EVCR_ODS ((uint8_t)0x07) /*!< Output driver strength */
#define N25Q128A_EVCR_VPPA ((uint8_t)0x08) /*!< Vpp accelerator */
#define N25Q128A_EVCR_RH ((uint8_t)0x10) /*!< Reset/hold */
#define N25Q128A_EVCR_DUAL ((uint8_t)0x40) /*!< Dual I/O protocol */
#define N25Q128A_EVCR_QUAD ((uint8_t)0x80) /*!< Quad I/O protocol */
/* Flag Status Register */
#define N25Q128A_FSR_PRERR ((uint8_t)0x02) /*!< Protection error */
#define N25Q128A_FSR_PGSUS ((uint8_t)0x04) /*!< Program operation suspended */
#define N25Q128A_FSR_VPPERR ((uint8_t)0x08) /*!< Invalid voltage during program or erase */
#define N25Q128A_FSR_PGERR ((uint8_t)0x10) /*!< Program error */
#define N25Q128A_FSR_ERERR ((uint8_t)0x20) /*!< Erase error */
#define N25Q128A_FSR_ERSUS ((uint8_t)0x40) /*!< Erase operation suspended */
#define N25Q128A_FSR_READY ((uint8_t)0x80) /*!< Ready or command in progress */
/**
* @}
*/
/** @defgroup N25Q128A_Exported_Functions
* @{
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __N25Q128A_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,261 @@
/**
******************************************************************************
* @file n25q256a.h
* @author MCD Application Team
* @version V1.0.0
* @date 02-March-2015
* @brief This file contains all the description of the N25Q256A QSPI memory.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __N25Q256A_H
#define __N25Q256A_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup n25q256a
* @{
*/
/** @defgroup N25Q256A_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup N25Q256A_Exported_Constants
* @{
*/
/**
* @brief N25Q256A Configuration
*/
#define N25Q256A_FLASH_SIZE 0x2000000 /* 256 MBits => 32MBytes */
#define N25Q256A_SECTOR_SIZE 0x10000 /* 512 sectors of 64KBytes */
#define N25Q256A_SUBSECTOR_SIZE 0x1000 /* 8192 subsectors of 4kBytes */
#define N25Q256A_PAGE_SIZE 0x100 /* 131072 pages of 256 bytes */
#define N25Q256A_DUMMY_CYCLES_READ 8
#define N25Q256A_DUMMY_CYCLES_READ_QUAD 10
#define N25Q256A_DUMMY_CYCLES_READ_DTR 6
#define N25Q256A_DUMMY_CYCLES_READ_QUAD_DTR 8
#define N25Q256A_BULK_ERASE_MAX_TIME 480000
#define N25Q256A_SECTOR_ERASE_MAX_TIME 3000
#define N25Q256A_SUBSECTOR_ERASE_MAX_TIME 800
/**
* @brief N25Q256A Commands
*/
/* Reset Operations */
#define RESET_ENABLE_CMD 0x66
#define RESET_MEMORY_CMD 0x99
/* Identification Operations */
#define READ_ID_CMD 0x9E
#define READ_ID_CMD2 0x9F
#define MULTIPLE_IO_READ_ID_CMD 0xAF
#define READ_SERIAL_FLASH_DISCO_PARAM_CMD 0x5A
/* Read Operations */
#define READ_CMD 0x03
#define READ_4_BYTE_ADDR_CMD 0x13
#define FAST_READ_CMD 0x0B
#define FAST_READ_DTR_CMD 0x0D
#define FAST_READ_4_BYTE_ADDR_CMD 0x0C
#define DUAL_OUT_FAST_READ_CMD 0x3B
#define DUAL_OUT_FAST_READ_DTR_CMD 0x3D
#define DUAL_OUT_FAST_READ_4_BYTE_ADDR_CMD 0x3C
#define DUAL_INOUT_FAST_READ_CMD 0xBB
#define DUAL_INOUT_FAST_READ_DTR_CMD 0xBD
#define DUAL_INOUT_FAST_READ_4_BYTE_ADDR_CMD 0xBC
#define QUAD_OUT_FAST_READ_CMD 0x6B
#define QUAD_OUT_FAST_READ_DTR_CMD 0x6D
#define QUAD_OUT_FAST_READ_4_BYTE_ADDR_CMD 0x6C
#define QUAD_INOUT_FAST_READ_CMD 0xEB
#define QUAD_INOUT_FAST_READ_DTR_CMD 0xED
#define QUAD_INOUT_FAST_READ_4_BYTE_ADDR_CMD 0xEC
/* Write Operations */
#define WRITE_ENABLE_CMD 0x06
#define WRITE_DISABLE_CMD 0x04
/* Register Operations */
#define READ_STATUS_REG_CMD 0x05
#define WRITE_STATUS_REG_CMD 0x01
#define READ_LOCK_REG_CMD 0xE8
#define WRITE_LOCK_REG_CMD 0xE5
#define READ_FLAG_STATUS_REG_CMD 0x70
#define CLEAR_FLAG_STATUS_REG_CMD 0x50
#define READ_NONVOL_CFG_REG_CMD 0xB5
#define WRITE_NONVOL_CFG_REG_CMD 0xB1
#define READ_VOL_CFG_REG_CMD 0x85
#define WRITE_VOL_CFG_REG_CMD 0x81
#define READ_ENHANCED_VOL_CFG_REG_CMD 0x65
#define WRITE_ENHANCED_VOL_CFG_REG_CMD 0x61
#define READ_EXT_ADDR_REG_CMD 0xC8
#define WRITE_EXT_ADDR_REG_CMD 0xC5
/* Program Operations */
#define PAGE_PROG_CMD 0x02
#define PAGE_PROG_4_BYTE_ADDR_CMD 0x12
#define DUAL_IN_FAST_PROG_CMD 0xA2
#define EXT_DUAL_IN_FAST_PROG_CMD 0xD2
#define QUAD_IN_FAST_PROG_CMD 0x32
#define EXT_QUAD_IN_FAST_PROG_CMD 0x12 /*0x38*/
#define QUAD_IN_FAST_PROG_4_BYTE_ADDR_CMD 0x34
/* Erase Operations */
#define SUBSECTOR_ERASE_CMD 0x20
#define SUBSECTOR_ERASE_4_BYTE_ADDR_CMD 0x21
#define SECTOR_ERASE_CMD 0xD8
#define SECTOR_ERASE_4_BYTE_ADDR_CMD 0xDC
#define BULK_ERASE_CMD 0xC7
#define PROG_ERASE_RESUME_CMD 0x7A
#define PROG_ERASE_SUSPEND_CMD 0x75
/* One-Time Programmable Operations */
#define READ_OTP_ARRAY_CMD 0x4B
#define PROG_OTP_ARRAY_CMD 0x42
/* 4-byte Address Mode Operations */
#define ENTER_4_BYTE_ADDR_MODE_CMD 0xB7
#define EXIT_4_BYTE_ADDR_MODE_CMD 0xE9
/* Quad Operations */
#define ENTER_QUAD_CMD 0x35
#define EXIT_QUAD_CMD 0xF5
/**
* @brief N25Q256A Registers
*/
/* Status Register */
#define N25Q256A_SR_WIP ((uint8_t)0x01) /*!< Write in progress */
#define N25Q256A_SR_WREN ((uint8_t)0x02) /*!< Write enable latch */
#define N25Q256A_SR_BLOCKPR ((uint8_t)0x5C) /*!< Block protected against program and erase operations */
#define N25Q256A_SR_PRBOTTOM ((uint8_t)0x20) /*!< Protected memory area defined by BLOCKPR starts from top or bottom */
#define N25Q256A_SR_SRWREN ((uint8_t)0x80) /*!< Status register write enable/disable */
/* Nonvolatile Configuration Register */
#define N25Q256A_NVCR_NBADDR ((uint16_t)0x0001) /*!< 3-bytes or 4-bytes addressing */
#define N25Q256A_NVCR_SEGMENT ((uint16_t)0x0002) /*!< Upper or lower 128Mb segment selected by default */
#define N25Q256A_NVCR_DUAL ((uint16_t)0x0004) /*!< Dual I/O protocol */
#define N25Q256A_NVCR_QUAB ((uint16_t)0x0008) /*!< Quad I/O protocol */
#define N25Q256A_NVCR_RH ((uint16_t)0x0010) /*!< Reset/hold */
#define N25Q256A_NVCR_ODS ((uint16_t)0x01C0) /*!< Output driver strength */
#define N25Q256A_NVCR_XIP ((uint16_t)0x0E00) /*!< XIP mode at power-on reset */
#define N25Q256A_NVCR_NB_DUMMY ((uint16_t)0xF000) /*!< Number of dummy clock cycles */
/* Volatile Configuration Register */
#define N25Q256A_VCR_WRAP ((uint8_t)0x03) /*!< Wrap */
#define N25Q256A_VCR_XIP ((uint8_t)0x08) /*!< XIP */
#define N25Q256A_VCR_NB_DUMMY ((uint8_t)0xF0) /*!< Number of dummy clock cycles */
/* Extended Address Register */
#define N25Q256A_EAR_A24 ((uint8_t)0x01) /*!< Select the lower or upper 128Mb segment */
/* Enhanced Volatile Configuration Register */
#define N25Q256A_EVCR_ODS ((uint8_t)0x07) /*!< Output driver strength */
#define N25Q256A_EVCR_VPPA ((uint8_t)0x08) /*!< Vpp accelerator */
#define N25Q256A_EVCR_RH ((uint8_t)0x10) /*!< Reset/hold */
#define N25Q256A_EVCR_DUAL ((uint8_t)0x40) /*!< Dual I/O protocol */
#define N25Q256A_EVCR_QUAD ((uint8_t)0x80) /*!< Quad I/O protocol */
/* Flag Status Register */
#define N25Q256A_FSR_NBADDR ((uint8_t)0x01) /*!< 3-bytes or 4-bytes addressing */
#define N25Q256A_FSR_PRERR ((uint8_t)0x02) /*!< Protection error */
#define N25Q256A_FSR_PGSUS ((uint8_t)0x04) /*!< Program operation suspended */
#define N25Q256A_FSR_VPPERR ((uint8_t)0x08) /*!< Invalid voltage during program or erase */
#define N25Q256A_FSR_PGERR ((uint8_t)0x10) /*!< Program error */
#define N25Q256A_FSR_ERERR ((uint8_t)0x20) /*!< Erase error */
#define N25Q256A_FSR_ERSUS ((uint8_t)0x40) /*!< Erase operation suspended */
#define N25Q256A_FSR_READY ((uint8_t)0x80) /*!< Ready or command in progress */
/**
* @}
*/
/** @defgroup N25Q256A_Exported_Functions
* @{
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __N25Q256A_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,861 @@
/**
******************************************************************************
* @file ov9655.c
* @author MCD Application Team
* @version V1.0.0
* @date 25-June-2015
* @brief This file provides the OV9655 camera driver
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "ov9655.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup OV9655
* @brief This file provides a set of functions needed to drive the
* OV9655 Camera module.
* @{
*/
/** @defgroup OV9655_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup OV9655_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup OV9655_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup OV9655_Private_FunctionPrototypes
* @{
*/
static uint64_t ov9655_ConvertValue(uint32_t feature, uint32_t value);
/**
* @}
*/
/** @defgroup OV9655_Private_Variables
* @{
*/
CAMERA_DrvTypeDef ov9655_drv =
{
ov9655_Init,
ov9655_ReadID,
ov9655_Config,
};
/* Initialization sequence for VGA resolution (640x480)*/
const unsigned char OV9655_VGA[][2]=
{
{0x00, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0xb5, 0x00},
{0x35, 0x00},
{0xa8, 0xc1},
{0x3a, 0xcc},
{0x3d, 0x99},
{0x77, 0x02},
{0x13, 0xe7},
{0x26, 0x72},
{0x27, 0x08},
{0x28, 0x08},
{0x2c, 0x08},
{0xab, 0x04},
{0x6e, 0x00},
{0x6d, 0x55},
{0x00, 0x11},
{0x10, 0x7b},
{0xbb, 0xae},
{0x11, 0x03},
{0x72, 0x00},
{0x3e, 0x0c},
{0x74, 0x3a},
{0x76, 0x01},
{0x75, 0x35},
{0x73, 0x00},
{0xc7, 0x80},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x02},
{0x65, 0x20},
{0x66, 0x01},
{0xc3, 0x4e},
{0x33, 0x00},
{0xa4, 0x50},
{0xaa, 0x92},
{0xc2, 0x01},
{0xc1, 0xc8},
{0x1e, 0x04},
{0xa9, 0xef},
{0x0e, 0x61},
{0x39, 0x57},
{0x0f, 0x48},
{0x24, 0x3c},
{0x25, 0x36},
{0x12, 0x63},
{0x03, 0x12},
{0x32, 0xff},
{0x17, 0x16},
{0x18, 0x02},
{0x19, 0x01},
{0x1a, 0x3d},
{0x36, 0xfa},
{0x69, 0x0a},
{0x8c, 0x8d},
{0xc0, 0xaa},
{0x40, 0xd0},
{0x43, 0x14},
{0x44, 0xf0},
{0x45, 0x46},
{0x46, 0x62},
{0x47, 0x2a},
{0x48, 0x3c},
{0x59, 0x85},
{0x5a, 0xa9},
{0x5b, 0x64},
{0x5c, 0x84},
{0x5d, 0x53},
{0x5e, 0x0e},
{0x6c, 0x0c},
{0xc6, 0x85},
{0xcb, 0xf0},
{0xcc, 0xd8},
{0x71, 0x78},
{0xa5, 0x68},
{0x6f, 0x9e},
{0x42, 0xc0},
{0x3f, 0x82},
{0x8a, 0x23},
{0x14, 0x3a},
{0x3b, 0xcc},
{0x34, 0x3d},
{0x41, 0x40},
{0xc9, 0xe0},
{0xca, 0xe8},
{0xcd, 0x93},
{0x7a, 0x20},
{0x7b, 0x1c},
{0x7c, 0x28},
{0x7d, 0x3c},
{0x7e, 0x5a},
{0x7f, 0x68},
{0x80, 0x76},
{0x81, 0x80},
{0x82, 0x88},
{0x83, 0x8f},
{0x84, 0x96},
{0x85, 0xa3},
{0x86, 0xaf},
{0x87, 0xc4},
{0x88, 0xd7},
{0x89, 0xe8},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0x6b, 0x5a},
{0x90, 0x92},
{0x91, 0x92},
{0x9f, 0x90},
{0xa0, 0x90},
{0x16, 0x24},
{0x2a, 0x00},
{0x2b, 0x00},
{0xac, 0x80},
{0xad, 0x80},
{0xae, 0x80},
{0xaf, 0x80},
{0xb2, 0xf2},
{0xb3, 0x20},
{0xb4, 0x20},
{0xb6, 0xaf},
{0x29, 0x15},
{0x9d, 0x02},
{0x9e, 0x02},
{0x9e, 0x02},
{0x04, 0x03},
{0x05, 0x2e},
{0x06, 0x2e},
{0x07, 0x2e},
{0x08, 0x2e},
{0x2f, 0x2e},
{0x4a, 0xe9},
{0x4b, 0xdd},
{0x4c, 0xdd},
{0x4d, 0xdd},
{0x4e, 0xdd},
{0x70, 0x06},
{0xa6, 0x40},
{0xbc, 0x02},
{0xbd, 0x01},
{0xbe, 0x02},
{0xbf, 0x01},
};
/* Initialization sequence for QVGA resolution (320x240) */
const unsigned char OV9655_QVGA[][2]=
{
{0x00, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x03, 0x02},
{0x04, 0x03},
{0x09, 0x01},
{0x0b, 0x57},
{0x0e, 0x61},
{0x0f, 0x40},
{0x11, 0x01},
{0x12, 0x62},
{0x13, 0xc7},
{0x14, 0x3a},
{0x16, 0x24},
{0x17, 0x18},
{0x18, 0x04},
{0x19, 0x01},
{0x1a, 0x81},
{0x1e, 0x00},
{0x24, 0x3c},
{0x25, 0x36},
{0x26, 0x72},
{0x27, 0x08},
{0x28, 0x08},
{0x29, 0x15},
{0x2a, 0x00},
{0x2b, 0x00},
{0x2c, 0x08},
{0x32, 0x12},
{0x33, 0x00},
{0x34, 0x3f},
{0x35, 0x00},
{0x36, 0x3a},
{0x38, 0x72},
{0x39, 0x57},
{0x3a, 0xcc},
{0x3b, 0x04},
{0x3d, 0x99},
{0x3e, 0x02},
{0x3f, 0xc1},
{0x40, 0xc0},
{0x41, 0x41},
{0x42, 0xc0},
{0x43, 0x0a},
{0x44, 0xf0},
{0x45, 0x46},
{0x46, 0x62},
{0x47, 0x2a},
{0x48, 0x3c},
{0x4a, 0xfc},
{0x4b, 0xfc},
{0x4c, 0x7f},
{0x4d, 0x7f},
{0x4e, 0x7f},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0x59, 0x85},
{0x5a, 0xa9},
{0x5b, 0x64},
{0x5c, 0x84},
{0x5d, 0x53},
{0x5e, 0x0e},
{0x5f, 0xf0},
{0x60, 0xf0},
{0x61, 0xf0},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x02},
{0x65, 0x20},
{0x66, 0x00},
{0x69, 0x0a},
{0x6b, 0x5a},
{0x6c, 0x04},
{0x6d, 0x55},
{0x6e, 0x00},
{0x6f, 0x9d},
{0x70, 0x21},
{0x71, 0x78},
{0x72, 0x11},
{0x73, 0x01},
{0x74, 0x10},
{0x75, 0x10},
{0x76, 0x01},
{0x77, 0x02},
{0x7A, 0x12},
{0x7B, 0x08},
{0x7C, 0x16},
{0x7D, 0x30},
{0x7E, 0x5e},
{0x7F, 0x72},
{0x80, 0x82},
{0x81, 0x8e},
{0x82, 0x9a},
{0x83, 0xa4},
{0x84, 0xac},
{0x85, 0xb8},
{0x86, 0xc3},
{0x87, 0xd6},
{0x88, 0xe6},
{0x89, 0xf2},
{0x8a, 0x24},
{0x8c, 0x80},
{0x90, 0x7d},
{0x91, 0x7b},
{0x9d, 0x02},
{0x9e, 0x02},
{0x9f, 0x7a},
{0xa0, 0x79},
{0xa1, 0x40},
{0xa4, 0x50},
{0xa5, 0x68},
{0xa6, 0x4a},
{0xa8, 0xc1},
{0xa9, 0xef},
{0xaa, 0x92},
{0xab, 0x04},
{0xac, 0x80},
{0xad, 0x80},
{0xae, 0x80},
{0xaf, 0x80},
{0xb2, 0xf2},
{0xb3, 0x20},
{0xb4, 0x20},
{0xb5, 0x00},
{0xb6, 0xaf},
{0xb6, 0xaf},
{0xbb, 0xae},
{0xbc, 0x7f},
{0xbd, 0x7f},
{0xbe, 0x7f},
{0xbf, 0x7f},
{0xbf, 0x7f},
{0xc0, 0xaa},
{0xc1, 0xc0},
{0xc2, 0x01},
{0xc3, 0x4e},
{0xc6, 0x05},
{0xc7, 0x81},
{0xc9, 0xe0},
{0xca, 0xe8},
{0xcb, 0xf0},
{0xcc, 0xd8},
{0xcd, 0x93},
{0x12, 0x63},
{0x40, 0x10},
};
/* Initialization sequence for QQVGA resolution (160x120) */
const char OV9655_QQVGA[][2]=
{
{0x00, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x03, 0x02},
{0x04, 0x03},
{0x09, 0x01},
{0x0b, 0x57},
{0x0e, 0x61},
{0x0f, 0x40},
{0x11, 0x01},
{0x12, 0x62},
{0x13, 0xc7},
{0x14, 0x3a},
{0x16, 0x24},
{0x17, 0x18},
{0x18, 0x04},
{0x19, 0x01},
{0x1a, 0x81},
{0x1e, 0x00},
{0x24, 0x3c},
{0x25, 0x36},
{0x26, 0x72},
{0x27, 0x08},
{0x28, 0x08},
{0x29, 0x15},
{0x2a, 0x00},
{0x2b, 0x00},
{0x2c, 0x08},
{0x32, 0xa4},
{0x33, 0x00},
{0x34, 0x3f},
{0x35, 0x00},
{0x36, 0x3a},
{0x38, 0x72},
{0x39, 0x57},
{0x3a, 0xcc},
{0x3b, 0x04},
{0x3d, 0x99},
{0x3e, 0x0e},
{0x3f, 0xc1},
{0x40, 0xc0},
{0x41, 0x41},
{0x42, 0xc0},
{0x43, 0x0a},
{0x44, 0xf0},
{0x45, 0x46},
{0x46, 0x62},
{0x47, 0x2a},
{0x48, 0x3c},
{0x4a, 0xfc},
{0x4b, 0xfc},
{0x4c, 0x7f},
{0x4d, 0x7f},
{0x4e, 0x7f},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0x59, 0x85},
{0x5a, 0xa9},
{0x5b, 0x64},
{0x5c, 0x84},
{0x5d, 0x53},
{0x5e, 0x0e},
{0x5f, 0xf0},
{0x60, 0xf0},
{0x61, 0xf0},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x02},
{0x65, 0x20},
{0x66, 0x00},
{0x69, 0x0a},
{0x6b, 0x5a},
{0x6c, 0x04},
{0x6d, 0x55},
{0x6e, 0x00},
{0x6f, 0x9d},
{0x70, 0x21},
{0x71, 0x78},
{0x72, 0x22},
{0x73, 0x02},
{0x74, 0x10},
{0x75, 0x10},
{0x76, 0x01},
{0x77, 0x02},
{0x7A, 0x12},
{0x7B, 0x08},
{0x7C, 0x16},
{0x7D, 0x30},
{0x7E, 0x5e},
{0x7F, 0x72},
{0x80, 0x82},
{0x81, 0x8e},
{0x82, 0x9a},
{0x83, 0xa4},
{0x84, 0xac},
{0x85, 0xb8},
{0x86, 0xc3},
{0x87, 0xd6},
{0x88, 0xe6},
{0x89, 0xf2},
{0x8a, 0x24},
{0x8c, 0x80},
{0x90, 0x7d},
{0x91, 0x7b},
{0x9d, 0x02},
{0x9e, 0x02},
{0x9f, 0x7a},
{0xa0, 0x79},
{0xa1, 0x40},
{0xa4, 0x50},
{0xa5, 0x68},
{0xa6, 0x4a},
{0xa8, 0xc1},
{0xa9, 0xef},
{0xaa, 0x92},
{0xab, 0x04},
{0xac, 0x80},
{0xad, 0x80},
{0xae, 0x80},
{0xaf, 0x80},
{0xb2, 0xf2},
{0xb3, 0x20},
{0xb4, 0x20},
{0xb5, 0x00},
{0xb6, 0xaf},
{0xb6, 0xaf},
{0xbb, 0xae},
{0xbc, 0x7f},
{0xbd, 0x7f},
{0xbe, 0x7f},
{0xbf, 0x7f},
{0xbf, 0x7f},
{0xc0, 0xaa},
{0xc1, 0xc0},
{0xc2, 0x01},
{0xc3, 0x4e},
{0xc6, 0x05},
{0xc7, 0x82},
{0xc9, 0xe0},
{0xca, 0xe8},
{0xcb, 0xf0},
{0xcc, 0xd8},
{0xcd, 0x93},
{0x12, 0x63},
{0x40, 0x10},
};
/**
* @}
*/
/** @defgroup OV9655_Private_Functions
* @{
*/
/**
* @brief Initializes the OV9655 CAMERA component.
* @param DeviceAddr: Device address on communication Bus.
* @param resolution: Camera resolution
* @retval None
*/
void ov9655_Init(uint16_t DeviceAddr, uint32_t resolution)
{
uint32_t index;
/* Initialize I2C */
CAMERA_IO_Init();
/* Prepare the camera to be configured by resetting all its registers */
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_COM7, 0x80);
CAMERA_Delay(200);
/* Initialize OV9655 */
switch (resolution)
{
case CAMERA_R160x120:
{
for(index=0; index<(sizeof(OV9655_QQVGA)/2); index++)
{
CAMERA_IO_Write(DeviceAddr, OV9655_QQVGA[index][0], OV9655_QQVGA[index][1]);
CAMERA_Delay(2);
}
break;
}
case CAMERA_R320x240:
{
for(index=0; index<(sizeof(OV9655_QVGA)/2); index++)
{
CAMERA_IO_Write(DeviceAddr, OV9655_QVGA[index][0], OV9655_QVGA[index][1]);
CAMERA_Delay(2);
}
break;
}
case CAMERA_R480x272:
{
/* Not supported resolution */
break;
}
case CAMERA_R640x480:
{
for(index=0; index<(sizeof(OV9655_VGA)/2); index++)
{
CAMERA_IO_Write(DeviceAddr, OV9655_VGA[index][0], OV9655_VGA[index][1]);
CAMERA_Delay(2);
}
break;
}
default:
{
break;
}
}
}
/**
* @brief Configures the OV9655 camera feature.
* @param DeviceAddr: Device address on communication Bus.
* @param feature: Camera feature to be configured
* @param value: Value to be configured
* @param brightness_value: Brightness value to be configured
* @retval None
*/
void ov9655_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t brightness_value)
{
uint8_t tslb, mtx1, mtx2, mtx3, mtx4, mtx5, mtx6;
uint64_t value_tmp;
uint32_t br_value;
/* Convert the input value into ov9655 parameters */
value_tmp = ov9655_ConvertValue(feature, value);
br_value = (uint32_t)ov9655_ConvertValue(CAMERA_CONTRAST_BRIGHTNESS, brightness_value);
switch(feature)
{
case CAMERA_CONTRAST_BRIGHTNESS:
{
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_BRTN, br_value);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_CNST1, value_tmp);
break;
}
case CAMERA_BLACK_WHITE:
case CAMERA_COLOR_EFFECT:
{
tslb = (uint8_t)(value_tmp >> 48);
mtx1 = (uint8_t)(value_tmp >> 40);
mtx2 = (uint8_t)(value_tmp >> 32);
mtx3 = (uint8_t)(value_tmp >> 24);
mtx4 = (uint8_t)(value_tmp >> 16);
mtx5 = (uint8_t)(value_tmp >> 8);
mtx6 = (uint8_t)(value_tmp);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_TSLB, tslb);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX1, mtx1);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX2, mtx2);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX3, mtx3);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX4, mtx4);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX5, mtx5);
CAMERA_IO_Write(DeviceAddr, OV9655_SENSOR_MTX6, mtx6);
break;
}
default:
{
break;
}
}
}
/**
* @brief Read the OV9655 Camera identity.
* @param DeviceAddr: Device address on communication Bus.
* @retval the OV9655 ID
*/
uint16_t ov9655_ReadID(uint16_t DeviceAddr)
{
/* Initialize I2C */
CAMERA_IO_Init();
/* Get the camera ID */
return (CAMERA_IO_Read(DeviceAddr, OV9655_SENSOR_PIDH));
}
/******************************************************************************
Static Functions
*******************************************************************************/
/**
* @brief Convert input values into ov9655 parameters.
* @param feature: Camera feature to be configured
* @param value: Value to be configured
* @retval The converted value
*/
static uint64_t ov9655_ConvertValue(uint32_t feature, uint32_t value)
{
uint64_t ret = 0;
switch(feature)
{
case CAMERA_BLACK_WHITE:
{
switch(value)
{
case CAMERA_BLACK_WHITE_BW:
{
ret = OV9655_BLACK_WHITE_BW;
break;
}
case CAMERA_BLACK_WHITE_NEGATIVE:
{
ret = OV9655_BLACK_WHITE_NEGATIVE;
break;
}
case CAMERA_BLACK_WHITE_BW_NEGATIVE:
{
ret = OV9655_BLACK_WHITE_BW_NEGATIVE;
break;
}
case CAMERA_BLACK_WHITE_NORMAL:
{
ret = OV9655_BLACK_WHITE_NORMAL;
break;
}
default:
{
ret = OV9655_BLACK_WHITE_NORMAL;
break;
}
}
break;
}
case CAMERA_CONTRAST_BRIGHTNESS:
{
switch(value)
{
case CAMERA_BRIGHTNESS_LEVEL0:
{
ret = OV9655_BRIGHTNESS_LEVEL0;
break;
}
case CAMERA_BRIGHTNESS_LEVEL1:
{
ret = OV9655_BRIGHTNESS_LEVEL1;
break;
}
case CAMERA_BRIGHTNESS_LEVEL2:
{
ret = OV9655_BRIGHTNESS_LEVEL2;
break;
}
case CAMERA_BRIGHTNESS_LEVEL3:
{
ret = OV9655_BRIGHTNESS_LEVEL3;
break;
}
case CAMERA_BRIGHTNESS_LEVEL4:
{
ret = OV9655_BRIGHTNESS_LEVEL4;
break;
}
case CAMERA_CONTRAST_LEVEL0:
{
ret = OV9655_CONTRAST_LEVEL0;
break;
}
case CAMERA_CONTRAST_LEVEL1:
{
ret = OV9655_CONTRAST_LEVEL1;
break;
}
case CAMERA_CONTRAST_LEVEL2:
{
ret = OV9655_CONTRAST_LEVEL2;
break;
}
case CAMERA_CONTRAST_LEVEL3:
{
ret = OV9655_CONTRAST_LEVEL3;
break;
}
case CAMERA_CONTRAST_LEVEL4:
{
ret = OV9655_CONTRAST_LEVEL4;
break;
}
default:
{
ret = OV9655_CONTRAST_LEVEL0;
break;
}
}
break;
}
case CAMERA_COLOR_EFFECT:
{
switch(value)
{
case CAMERA_COLOR_EFFECT_ANTIQUE:
{
ret = OV9655_COLOR_EFFECT_ANTIQUE;
break;
}
case CAMERA_COLOR_EFFECT_BLUE:
{
ret = OV9655_COLOR_EFFECT_BLUE;
break;
}
case CAMERA_COLOR_EFFECT_GREEN:
{
ret = OV9655_COLOR_EFFECT_GREEN;
break;
}
case CAMERA_COLOR_EFFECT_RED:
{
ret = OV9655_COLOR_EFFECT_RED;
break;
}
case CAMERA_COLOR_EFFECT_NONE:
default:
{
ret = OV9655_COLOR_EFFECT_NONE;
break;
}
}
break;
default:
{
ret = 0;
break;
}
}
}
return ret;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,159 @@
/**
******************************************************************************
* @file ov9655.h
* @author MCD Application Team
* @version V1.0.0
* @date 25-June-2015
* @brief This file contains all the functions prototypes for the ov9655.c
* driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OV9655_H
#define __OV9655_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/camera.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ov9655
* @{
*/
/** @defgroup OV9655_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup OV9655_Exported_Constants
* @{
*/
/**
* @brief OV9655 ID
*/
#define OV9655_ID 0x96
/**
* @brief OV9655 Registers
*/
/* OV9655 Registers definition */
#define OV9655_SENSOR_PIDH 0x0A
#define OV9655_SENSOR_PIDL 0x0B
#define OV9655_SENSOR_COM7 0x12
#define OV9655_SENSOR_TSLB 0x3A
#define OV9655_SENSOR_MTX1 0x4F
#define OV9655_SENSOR_MTX2 0x50
#define OV9655_SENSOR_MTX3 0x51
#define OV9655_SENSOR_MTX4 0x52
#define OV9655_SENSOR_MTX5 0x53
#define OV9655_SENSOR_MTX6 0x54
#define OV9655_SENSOR_BRTN 0x55
#define OV9655_SENSOR_CNST1 0x56
#define OV9655_SENSOR_CNST2 0x57
/**
* @brief OV9655 Features Parameters
*/
#define OV9655_BRIGHTNESS_LEVEL0 0xB0 /* Brightness level -2 */
#define OV9655_BRIGHTNESS_LEVEL1 0x98 /* Brightness level -1 */
#define OV9655_BRIGHTNESS_LEVEL2 0x00 /* Brightness level 0 */
#define OV9655_BRIGHTNESS_LEVEL3 0x18 /* Brightness level +1 */
#define OV9655_BRIGHTNESS_LEVEL4 0x30 /* Brightness level +2 */
#define OV9655_BLACK_WHITE_BW 0xCC000000000000 /* Black and white effect */
#define OV9655_BLACK_WHITE_NEGATIVE 0xEC808000008080 /* Negative effect */
#define OV9655_BLACK_WHITE_BW_NEGATIVE 0xEC000000000000 /* BW and Negative effect */
#define OV9655_BLACK_WHITE_NORMAL 0xCC808000008080 /* Normal effect */
#define OV9655_CONTRAST_LEVEL0 0x30 /* Contrast level -2 */
#define OV9655_CONTRAST_LEVEL1 0x38 /* Contrast level -1 */
#define OV9655_CONTRAST_LEVEL2 0x40 /* Contrast level 0 */
#define OV9655_CONTRAST_LEVEL3 0x50 /* Contrast level +1 */
#define OV9655_CONTRAST_LEVEL4 0x60 /* Contrast level +2 */
#define OV9655_COLOR_EFFECT_NONE 0xCC808000008080 /* No color effect */
#define OV9655_COLOR_EFFECT_ANTIQUE 0xCC000020F00000 /* Antique effect */
#define OV9655_COLOR_EFFECT_BLUE 0xCC000000000060 /* Blue effect */
#define OV9655_COLOR_EFFECT_GREEN 0xCC000000008000 /* Green effect */
#define OV9655_COLOR_EFFECT_RED 0xCC600000000000 /* Red effect */
/**
* @}
*/
/** @defgroup OV9655_Exported_Functions
* @{
*/
void ov9655_Init(uint16_t DeviceAddr, uint32_t resolution);
void ov9655_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t BR_value);
uint16_t ov9655_ReadID(uint16_t DeviceAddr);
void CAMERA_IO_Init(void);
void CAMERA_IO_Write(uint8_t addr, uint8_t reg, uint8_t value);
uint8_t CAMERA_IO_Read(uint8_t addr, uint8_t reg);
void CAMERA_Delay(uint32_t delay);
/* CAMERA driver structure */
extern CAMERA_DrvTypeDef ov9655_drv;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __OV9655_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,121 @@
/**
******************************************************************************
* @file rk043fn48h.h
* @author MCD Application Team
* @version V1.0.0
* @date 25-June-2015
* @brief This file contains all the constants parameters for the RK043FN48H-CT672B
* LCD component.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RK043FN48H_H
#define __RK043FN48H_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup rk043fn48h
* @{
*/
/** @defgroup RK043FN48H_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup RK043FN48H_Exported_Constants
* @{
*/
/**
* @brief RK043FN48H Size
*/
#define RK043FN48H_WIDTH ((uint16_t)480) /* LCD PIXEL WIDTH */
#define RK043FN48H_HEIGHT ((uint16_t)272) /* LCD PIXEL HEIGHT */
/**
* @brief RK043FN48H Timing
*/
#define RK043FN48H_HSYNC ((uint16_t)41) /* Horizontal synchronization */
#define RK043FN48H_HBP ((uint16_t)13) /* Horizontal back porch */
#define RK043FN48H_HFP ((uint16_t)32) /* Horizontal front porch */
#define RK043FN48H_VSYNC ((uint16_t)10) /* Vertical synchronization */
#define RK043FN48H_VBP ((uint16_t)2) /* Vertical back porch */
#define RK043FN48H_VFP ((uint16_t)2) /* Vertical front porch */
/**
* @brief RK043FN48H frequency divider
*/
#define RK043FN48H_FREQUENCY_DIVIDER 5 /* LCD Frequency divider */
/**
* @}
*/
/** @defgroup RK043FN48H_Exported_Functions
* @{
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __RK043FN48H_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,471 @@
/**
******************************************************************************
* @file st7735.c
* @author MCD Application Team
* @version V1.1.1
* @date 24-November-2014
* @brief This file includes the driver for ST7735 LCD mounted on the Adafruit
* 1.8" TFT LCD shield (reference ID 802).
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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 "st7735.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ST7735
* @brief This file provides a set of functions needed to drive the
* ST7735 LCD.
* @{
*/
/** @defgroup ST7735_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup ST7735_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup ST7735_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup ST7735_Private_Variables
* @{
*/
LCD_DrvTypeDef st7735_drv =
{
st7735_Init,
0,
st7735_DisplayOn,
st7735_DisplayOff,
st7735_SetCursor,
st7735_WritePixel,
0,
st7735_SetDisplayWindow,
st7735_DrawHLine,
st7735_DrawVLine,
st7735_GetLcdPixelWidth,
st7735_GetLcdPixelHeight,
st7735_DrawBitmap,
};
static uint16_t ArrayRGB[320] = {0};
/**
* @}
*/
/** @defgroup ST7735_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup ST7735_Private_Functions
* @{
*/
/**
* @brief Initialize the ST7735 LCD Component.
* @param None
* @retval None
*/
void st7735_Init(void)
{
uint8_t data = 0;
/* Initialize ST7735 low level bus layer -----------------------------------*/
LCD_IO_Init();
/* Out of sleep mode, 0 args, no delay */
st7735_WriteReg(LCD_REG_17, 0x00);
/* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/
LCD_IO_WriteReg(LCD_REG_177);
data = 0x01;
LCD_IO_WriteMultipleData(&data, 1);
data = 0x2C;
LCD_IO_WriteMultipleData(&data, 1);
data = 0x2D;
LCD_IO_WriteMultipleData(&data, 1);
/* Frame rate control - idle mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D) */
st7735_WriteReg(LCD_REG_178, 0x01);
st7735_WriteReg(LCD_REG_178, 0x2C);
st7735_WriteReg(LCD_REG_178, 0x2D);
/* Frame rate ctrl - partial mode, 6 args: Dot inversion mode, Line inversion mode */
st7735_WriteReg(LCD_REG_179, 0x01);
st7735_WriteReg(LCD_REG_179, 0x2C);
st7735_WriteReg(LCD_REG_179, 0x2D);
st7735_WriteReg(LCD_REG_179, 0x01);
st7735_WriteReg(LCD_REG_179, 0x2C);
st7735_WriteReg(LCD_REG_179, 0x2D);
/* Display inversion ctrl, 1 arg, no delay: No inversion */
st7735_WriteReg(LCD_REG_180, 0x07);
/* Power control, 3 args, no delay: -4.6V , AUTO mode */
st7735_WriteReg(LCD_REG_192, 0xA2);
st7735_WriteReg(LCD_REG_192, 0x02);
st7735_WriteReg(LCD_REG_192, 0x84);
/* Power control, 1 arg, no delay: VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */
st7735_WriteReg(LCD_REG_193, 0xC5);
/* Power control, 2 args, no delay: Opamp current small, Boost frequency */
st7735_WriteReg(LCD_REG_194, 0x0A);
st7735_WriteReg(LCD_REG_194, 0x00);
/* Power control, 2 args, no delay: BCLK/2, Opamp current small & Medium low */
st7735_WriteReg(LCD_REG_195, 0x8A);
st7735_WriteReg(LCD_REG_195, 0x2A);
/* Power control, 2 args, no delay */
st7735_WriteReg(LCD_REG_196, 0x8A);
st7735_WriteReg(LCD_REG_196, 0xEE);
/* Power control, 1 arg, no delay */
st7735_WriteReg(LCD_REG_197, 0x0E);
/* Don't invert display, no args, no delay */
LCD_IO_WriteReg(LCD_REG_32);
/* Set color mode, 1 arg, no delay: 16-bit color */
st7735_WriteReg(LCD_REG_58, 0x05);
/* Column addr set, 4 args, no delay: XSTART = 0, XEND = 127 */
LCD_IO_WriteReg(LCD_REG_42);
data = 0x00;
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteMultipleData(&data, 1);
data = 0x7F;
LCD_IO_WriteMultipleData(&data, 1);
/* Row addr set, 4 args, no delay: YSTART = 0, YEND = 159 */
LCD_IO_WriteReg(LCD_REG_43);
data = 0x00;
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteMultipleData(&data, 1);
data = 0x9F;
LCD_IO_WriteMultipleData(&data, 1);
/* Magical unicorn dust, 16 args, no delay */
st7735_WriteReg(LCD_REG_224, 0x02);
st7735_WriteReg(LCD_REG_224, 0x1c);
st7735_WriteReg(LCD_REG_224, 0x07);
st7735_WriteReg(LCD_REG_224, 0x12);
st7735_WriteReg(LCD_REG_224, 0x37);
st7735_WriteReg(LCD_REG_224, 0x32);
st7735_WriteReg(LCD_REG_224, 0x29);
st7735_WriteReg(LCD_REG_224, 0x2d);
st7735_WriteReg(LCD_REG_224, 0x29);
st7735_WriteReg(LCD_REG_224, 0x25);
st7735_WriteReg(LCD_REG_224, 0x2B);
st7735_WriteReg(LCD_REG_224, 0x39);
st7735_WriteReg(LCD_REG_224, 0x00);
st7735_WriteReg(LCD_REG_224, 0x01);
st7735_WriteReg(LCD_REG_224, 0x03);
st7735_WriteReg(LCD_REG_224, 0x10);
/* Sparkles and rainbows, 16 args, no delay */
st7735_WriteReg(LCD_REG_225, 0x03);
st7735_WriteReg(LCD_REG_225, 0x1d);
st7735_WriteReg(LCD_REG_225, 0x07);
st7735_WriteReg(LCD_REG_225, 0x06);
st7735_WriteReg(LCD_REG_225, 0x2E);
st7735_WriteReg(LCD_REG_225, 0x2C);
st7735_WriteReg(LCD_REG_225, 0x29);
st7735_WriteReg(LCD_REG_225, 0x2D);
st7735_WriteReg(LCD_REG_225, 0x2E);
st7735_WriteReg(LCD_REG_225, 0x2E);
st7735_WriteReg(LCD_REG_225, 0x37);
st7735_WriteReg(LCD_REG_225, 0x3F);
st7735_WriteReg(LCD_REG_225, 0x00);
st7735_WriteReg(LCD_REG_225, 0x00);
st7735_WriteReg(LCD_REG_225, 0x02);
st7735_WriteReg(LCD_REG_225, 0x10);
/* Normal display on, no args, no delay */
st7735_WriteReg(LCD_REG_19, 0x00);
/* Main screen turn on, no delay */
st7735_WriteReg(LCD_REG_41, 0x00);
/* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(LCD_REG_54, 0xC0);
}
/**
* @brief Enables the Display.
* @param None
* @retval None
*/
void st7735_DisplayOn(void)
{
uint8_t data = 0;
LCD_IO_WriteReg(LCD_REG_19);
LCD_Delay(10);
LCD_IO_WriteReg(LCD_REG_41);
LCD_Delay(10);
LCD_IO_WriteReg(LCD_REG_54);
data = 0xC0;
LCD_IO_WriteMultipleData(&data, 1);
}
/**
* @brief Disables the Display.
* @param None
* @retval None
*/
void st7735_DisplayOff(void)
{
uint8_t data = 0;
LCD_IO_WriteReg(LCD_REG_19);
LCD_Delay(10);
LCD_IO_WriteReg(LCD_REG_40);
LCD_Delay(10);
LCD_IO_WriteReg(LCD_REG_54);
data = 0xC0;
LCD_IO_WriteMultipleData(&data, 1);
}
/**
* @brief Sets Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t data = 0;
LCD_IO_WriteReg(LCD_REG_42);
data = (Xpos) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Xpos) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteReg(LCD_REG_43);
data = (Ypos) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Ypos) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
LCD_IO_WriteReg(LCD_REG_44);
}
/**
* @brief Writes pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color
* @retval None
*/
void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
uint8_t data = 0;
if((Xpos >= ST7735_LCD_PIXEL_WIDTH) || (Ypos >= ST7735_LCD_PIXEL_HEIGHT))
{
return;
}
/* Set Cursor */
st7735_SetCursor(Xpos, Ypos);
data = RGBCode >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = RGBCode;
LCD_IO_WriteMultipleData(&data, 1);
}
/**
* @brief Writes to the selected LCD register.
* @param LCDReg: Address of the selected register.
* @param LCDRegValue: value to write to the selected register.
* @retval None
*/
void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue)
{
LCD_IO_WriteReg(LCDReg);
LCD_IO_WriteMultipleData(&LCDRegValue, 1);
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
uint8_t data = 0;
/* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */
LCD_IO_WriteReg(LCD_REG_42);
data = (Xpos) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Xpos) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
data = (Xpos + Width - 1) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Xpos + Width - 1) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
/* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */
LCD_IO_WriteReg(LCD_REG_43);
data = (Ypos) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Ypos) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
data = (Ypos + Height - 1) >> 8;
LCD_IO_WriteMultipleData(&data, 1);
data = (Ypos + Height - 1) & 0xFF;
LCD_IO_WriteMultipleData(&data, 1);
}
/**
* @brief Draws horizontal line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = 0;
if(Xpos + Length > ST7735_LCD_PIXEL_WIDTH) return;
/* Set Cursor */
st7735_SetCursor(Xpos, Ypos);
for(counter = 0; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
}
/**
* @brief Draws vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the line length.
* @retval None
*/
void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint8_t counter = 0;
if(Ypos + Length > ST7735_LCD_PIXEL_HEIGHT) return;
for(counter = 0; counter < Length; counter++)
{
st7735_WritePixel(Xpos, Ypos + counter, RGBCode);
}
}
/**
* @brief Gets the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t st7735_GetLcdPixelWidth(void)
{
return ST7735_LCD_PIXEL_WIDTH;
}
/**
* @brief Gets the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t st7735_GetLcdPixelHeight(void)
{
return ST7735_LCD_PIXEL_HEIGHT;
}
/**
* @brief Displays a bitmap picture loaded in the internal Flash.
* @param BmpAddress: Bmp picture address in the internal Flash.
* @retval None
*/
void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
/* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
/* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 0, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(LCD_REG_54, 0x40);
/* Set Cursor */
st7735_SetCursor(Xpos, Ypos);
LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*2);
/* Set GRAM write direction and BGR = 0 */
/* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
st7735_WriteReg(LCD_REG_54, 0xC0);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,214 @@
/**
******************************************************************************
* @file st7735.h
* @author MCD Application Team
* @version V1.1.1
* @date 24-November-2014
* @brief This file contains all the functions prototypes for the st7735.c
* driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ST7735_H
#define __ST7735_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/lcd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ST7735
* @{
*/
/** @defgroup ST7735_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup ST7735_Exported_Constants
* @{
*/
/**
* @brief ST7735 Size
*/
#define ST7735_LCD_PIXEL_WIDTH ((uint16_t)128)
#define ST7735_LCD_PIXEL_HEIGHT ((uint16_t)160)
/**
* @brief ST7735 Registers
*/
#define LCD_REG_0 0x00 /* No Operation: NOP */
#define LCD_REG_1 0x01 /* Software reset: SWRESET */
#define LCD_REG_4 0x04 /* Read Display ID: RDDID */
#define LCD_REG_9 0x09 /* Read Display Statu: RDDST */
#define LCD_REG_10 0x0A /* Read Display Power: RDDPM */
#define LCD_REG_11 0x0B /* Read Display: RDDMADCTL */
#define LCD_REG_12 0x0C /* Read Display Pixel: RDDCOLMOD */
#define LCD_REG_13 0x0D /* Read Display Image: RDDIM */
#define LCD_REG_14 0x0E /* Read Display Signal: RDDSM */
#define LCD_REG_16 0x10 /* Sleep in & booster off: SLPIN */
#define LCD_REG_17 0x11 /* Sleep out & booster on: SLPOUT */
#define LCD_REG_18 0x12 /* Partial mode on: PTLON */
#define LCD_REG_19 0x13 /* Partial off (Normal): NORON */
#define LCD_REG_32 0x20 /* Display inversion off: INVOFF */
#define LCD_REG_33 0x21 /* Display inversion on: INVON */
#define LCD_REG_38 0x26 /* Gamma curve select: GAMSET */
#define LCD_REG_40 0x28 /* Display off: DISPOFF */
#define LCD_REG_41 0x29 /* Display on: DISPON */
#define LCD_REG_42 0x2A /* Column address set: CASET */
#define LCD_REG_43 0x2B /* Row address set: RASET */
#define LCD_REG_44 0x2C /* Memory write: RAMWR */
#define LCD_REG_45 0x2D /* LUT for 4k,65k,262k color: RGBSET */
#define LCD_REG_46 0x2E /* Memory read: RAMRD*/
#define LCD_REG_48 0x30 /* Partial start/end address set: PTLAR */
#define LCD_REG_52 0x34 /* Tearing effect line off: TEOFF */
#define LCD_REG_53 0x35 /* Tearing effect mode set & on: TEON */
#define LCD_REG_54 0x36 /* Memory data access control: MADCTL */
#define LCD_REG_56 0x38 /* Idle mode off: IDMOFF */
#define LCD_REG_57 0x39 /* Idle mode on: IDMON */
#define LCD_REG_58 0x3A /* Interface pixel format: COLMOD */
#define LCD_REG_177 0xB1 /* In normal mode (Full colors): FRMCTR1 */
#define LCD_REG_178 0xB2 /* In Idle mode (8-colors): FRMCTR2 */
#define LCD_REG_179 0xB3 /* In partial mode + Full colors: FRMCTR3 */
#define LCD_REG_180 0xB4 /* Display inversion control: INVCTR */
#define LCD_REG_192 0xC0 /* Power control setting: PWCTR1 */
#define LCD_REG_193 0xC1 /* Power control setting: PWCTR2 */
#define LCD_REG_194 0xC2 /* In normal mode (Full colors): PWCTR3 */
#define LCD_REG_195 0xC3 /* In Idle mode (8-colors): PWCTR4 */
#define LCD_REG_196 0xC4 /* In partial mode + Full colors: PWCTR5 */
#define LCD_REG_197 0xC5 /* VCOM control 1: VMCTR1 */
#define LCD_REG_199 0xC7 /* Set VCOM offset control: VMOFCTR */
#define LCD_REG_209 0xD1 /* Set LCM version code: WRID2 */
#define LCD_REG_210 0xD2 /* Customer Project code: WRID3 */
#define LCD_REG_217 0xD9 /* NVM control status: NVCTR1 */
#define LCD_REG_218 0xDA /* Read ID1: RDID1 */
#define LCD_REG_219 0xDB /* Read ID2: RDID2 */
#define LCD_REG_220 0xDC /* Read ID3: RDID3 */
#define LCD_REG_222 0xDE /* NVM Read Command: NVCTR2 */
#define LCD_REG_223 0xDF /* NVM Write Command: NVCTR3 */
#define LCD_REG_224 0xE0 /* Set Gamma adjustment (+ polarity): GAMCTRP1 */
#define LCD_REG_225 0xE1 /* Set Gamma adjustment (- polarity): GAMCTRN1 */
/**
* @brief LCD Lines depending on the chosen fonts.
*/
#define LCD_LINE_0 LINE(0)
#define LCD_LINE_1 LINE(1)
#define LCD_LINE_2 LINE(2)
#define LCD_LINE_3 LINE(3)
#define LCD_LINE_4 LINE(4)
#define LCD_LINE_5 LINE(5)
#define LCD_LINE_6 LINE(6)
#define LCD_LINE_7 LINE(7)
#define LCD_LINE_8 LINE(8)
#define LCD_LINE_9 LINE(9)
#define LCD_LINE_10 LINE(10)
#define LCD_LINE_11 LINE(11)
#define LCD_LINE_12 LINE(12)
#define LCD_LINE_13 LINE(13)
#define LCD_LINE_14 LINE(14)
#define LCD_LINE_15 LINE(15)
#define LCD_LINE_16 LINE(16)
#define LCD_LINE_17 LINE(17)
#define LCD_LINE_18 LINE(18)
#define LCD_LINE_19 LINE(19)
/**
* @}
*/
/** @defgroup ADAFRUIT_SPI_LCD_Exported_Functions
* @{
*/
void st7735_Init(void);
uint16_t st7735_ReadID(void);
void st7735_DisplayOn(void);
void st7735_DisplayOff(void);
void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos);
void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue);
uint8_t st7735_ReadReg(uint8_t LCDReg);
void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
uint16_t st7735_GetLcdPixelWidth(void);
uint16_t st7735_GetLcdPixelHeight(void);
void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
/* LCD driver structure */
extern LCD_DrvTypeDef st7735_drv;
/* LCD IO functions */
void LCD_IO_Init(void);
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
void LCD_Delay(uint32_t delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ST7735_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,725 @@
/**
******************************************************************************
* @file st7789h2.c
* @author MCD Application Team
* @version V1.1.1
* @date 29-December-2016
* @brief This file includes the LCD driver for st7789h2 LCD.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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 "st7789h2.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @defgroup ST7789H2
* @brief This file provides a set of functions needed to drive the
* FRIDA FRD154BP2901 LCD.
* @{
*/
/** @defgroup ST7789H2_Private_TypesDefinitions ST7789H2 Private TypesDefinitions
* @{
*/
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
} ST7789H2_Rgb888;
/**
* @}
*/
/** @defgroup ST7789H2_Private_Defines ST7789H2 Private Defines
* @{
*/
/**
* @}
*/
/** @defgroup ST7789H2_Private_Macros ST7789H2 Private Macros
* @{
*/
/**
* @}
*/
/** @defgroup ST7789H2_Private_Variables ST7789H2 Private Variables
* @{
*/
LCD_DrvTypeDef ST7789H2_drv =
{
ST7789H2_Init,
ST7789H2_ReadID,
ST7789H2_DisplayOn,
ST7789H2_DisplayOff,
ST7789H2_SetCursor,
ST7789H2_WritePixel,
ST7789H2_ReadPixel,
ST7789H2_SetDisplayWindow,
ST7789H2_DrawHLine,
ST7789H2_DrawVLine,
ST7789H2_GetLcdPixelWidth,
ST7789H2_GetLcdPixelHeight,
ST7789H2_DrawBitmap,
ST7789H2_DrawRGBImage,
};
static uint16_t WindowsXstart = 0;
static uint16_t WindowsYstart = 0;
static uint16_t WindowsXend = ST7789H2_LCD_PIXEL_WIDTH-1;
static uint16_t WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1;
/**
* @}
*/
/** @defgroup ST7789H2_Private_FunctionPrototypes ST7789H2 Private FunctionPrototypes
* @{
*/
static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos);
static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata);
/**
* @}
*/
/** @defgroup ST7789H2_Private_Functions ST7789H2 Private Functions
* @{
*/
/**
* @brief Initialize the st7789h2 LCD Component.
* @param None
* @retval None
*/
void ST7789H2_Init(void)
{
uint8_t parameter[14];
/* Initialize st7789h2 low level bus layer ----------------------------------*/
LCD_IO_Init();
/* Sleep In Command */
ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0);
/* Wait for 10ms */
LCD_IO_Delay(10);
/* SW Reset Command */
ST7789H2_WriteReg(0x01, (uint8_t*)NULL, 0);
/* Wait for 200ms */
LCD_IO_Delay(200);
/* Sleep Out Command */
ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0);
/* Wait for 120ms */
LCD_IO_Delay(120);
/* Normal display for Driver Down side */
parameter[0] = 0x00;
ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1);
/* Color mode 16bits/pixel */
parameter[0] = 0x05;
ST7789H2_WriteReg(ST7789H2_COLOR_MODE, parameter, 1);
/* Display inversion On */
ST7789H2_WriteReg(ST7789H2_DISPLAY_INVERSION, (uint8_t*)NULL, 0);
/* Set Column address CASET */
parameter[0] = 0x00;
parameter[1] = 0x00;
parameter[2] = 0x00;
parameter[3] = 0xEF;
ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4);
/* Set Row address RASET */
parameter[0] = 0x00;
parameter[1] = 0x00;
parameter[2] = 0x00;
parameter[3] = 0xEF;
ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4);
/*--------------- ST7789H2 Frame rate setting -------------------------------*/
/* PORCH control setting */
parameter[0] = 0x0C;
parameter[1] = 0x0C;
parameter[2] = 0x00;
parameter[3] = 0x33;
parameter[4] = 0x33;
ST7789H2_WriteReg(ST7789H2_PORCH_CTRL, parameter, 5);
/* GATE control setting */
parameter[0] = 0x35;
ST7789H2_WriteReg(ST7789H2_GATE_CTRL, parameter, 1);
/*--------------- ST7789H2 Power setting ------------------------------------*/
/* VCOM setting */
parameter[0] = 0x1F;
ST7789H2_WriteReg(ST7789H2_VCOM_SET, parameter, 1);
/* LCM Control setting */
parameter[0] = 0x2C;
ST7789H2_WriteReg(ST7789H2_LCM_CTRL, parameter, 1);
/* VDV and VRH Command Enable */
parameter[0] = 0x01;
parameter[1] = 0xC3;
ST7789H2_WriteReg(ST7789H2_VDV_VRH_EN, parameter, 2);
/* VDV Set */
parameter[0] = 0x20;
ST7789H2_WriteReg(ST7789H2_VDV_SET, parameter, 1);
/* Frame Rate Control in normal mode */
parameter[0] = 0x0F;
ST7789H2_WriteReg(ST7789H2_FR_CTRL, parameter, 1);
/* Power Control */
parameter[0] = 0xA4;
parameter[1] = 0xA1;
ST7789H2_WriteReg(ST7789H2_POWER_CTRL, parameter, 1);
/*--------------- ST7789H2 Gamma setting ------------------------------------*/
/* Positive Voltage Gamma Control */
parameter[0] = 0xD0;
parameter[1] = 0x08;
parameter[2] = 0x11;
parameter[3] = 0x08;
parameter[4] = 0x0C;
parameter[5] = 0x15;
parameter[6] = 0x39;
parameter[7] = 0x33;
parameter[8] = 0x50;
parameter[9] = 0x36;
parameter[10] = 0x13;
parameter[11] = 0x14;
parameter[12] = 0x29;
parameter[13] = 0x2D;
ST7789H2_WriteReg(ST7789H2_PV_GAMMA_CTRL, parameter, 14);
/* Negative Voltage Gamma Control */
parameter[0] = 0xD0;
parameter[1] = 0x08;
parameter[2] = 0x10;
parameter[3] = 0x08;
parameter[4] = 0x06;
parameter[5] = 0x06;
parameter[6] = 0x39;
parameter[7] = 0x44;
parameter[8] = 0x51;
parameter[9] = 0x0B;
parameter[10] = 0x16;
parameter[11] = 0x14;
parameter[12] = 0x2F;
parameter[13] = 0x31;
ST7789H2_WriteReg(ST7789H2_NV_GAMMA_CTRL, parameter, 14);
/* Display ON command */
ST7789H2_DisplayOn();
/* Tearing Effect Line On: Option (00h:VSYNC Interface OFF, 01h:VSYNC Interface ON) */
parameter[0] = 0x00;
ST7789H2_WriteReg(ST7789H2_TEARING_EFFECT, parameter, 1);
}
/**
* @brief Set the Display Orientation.
* @param orientation: ST7789H2_ORIENTATION_PORTRAIT, ST7789H2_ORIENTATION_LANDSCAPE
* or ST7789H2_ORIENTATION_LANDSCAPE_ROT180
* @retval None
*/
void ST7789H2_SetOrientation(uint32_t orientation)
{
uint8_t parameter[6];
if(orientation == ST7789H2_ORIENTATION_LANDSCAPE)
{
parameter[0] = 0x00;
}
else if(orientation == ST7789H2_ORIENTATION_LANDSCAPE_ROT180)
{
/* Vertical Scrolling Definition */
/* TFA describes the Top Fixed Area */
parameter[0] = 0x00;
parameter[1] = 0x00;
/* VSA describes the height of the Vertical Scrolling Area */
parameter[2] = 0x01;
parameter[3] = 0xF0;
/* BFA describes the Bottom Fixed Area */
parameter[4] = 0x00;
parameter[5] = 0x00;
ST7789H2_WriteReg(ST7789H2_VSCRDEF, parameter, 6);
/* Vertical Scroll Start Address of RAM */
/* GRAM row nbr (320) - Display row nbr (240) = 80 = 0x50 */
parameter[0] = 0x00;
parameter[1] = 0x50;
ST7789H2_WriteReg(ST7789H2_VSCSAD, parameter, 2);
parameter[0] = 0xC0;
}
else
{
parameter[0] = 0x60;
}
ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1);
}
/**
* @brief Enables the Display.
* @param None
* @retval None
*/
void ST7789H2_DisplayOn(void)
{
/* Display ON command */
ST7789H2_WriteReg(ST7789H2_DISPLAY_ON, (uint8_t*)NULL, 0);
/* Sleep Out command */
ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0);
}
/**
* @brief Disables the Display.
* @param None
* @retval None
*/
void ST7789H2_DisplayOff(void)
{
uint8_t parameter[1];
parameter[0] = 0xFE;
/* Display OFF command */
ST7789H2_WriteReg(ST7789H2_DISPLAY_OFF, parameter, 1);
/* Sleep In Command */
ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0);
/* Wait for 10ms */
LCD_IO_Delay(10);
}
/**
* @brief Get the LCD pixel Width.
* @param None
* @retval The Lcd Pixel Width
*/
uint16_t ST7789H2_GetLcdPixelWidth(void)
{
return (uint16_t)ST7789H2_LCD_PIXEL_WIDTH;
}
/**
* @brief Get the LCD pixel Height.
* @param None
* @retval The Lcd Pixel Height
*/
uint16_t ST7789H2_GetLcdPixelHeight(void)
{
return (uint16_t)ST7789H2_LCD_PIXEL_HEIGHT;
}
/**
* @brief Get the st7789h2 ID.
* @param None
* @retval The st7789h2 ID
*/
uint16_t ST7789H2_ReadID(void)
{
LCD_IO_Init();
return ST7789H2_ReadReg(ST7789H2_LCD_ID);
}
/**
* @brief Set Cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void ST7789H2_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
uint8_t parameter[4];
/* CASET: Comumn Addrses Set */
parameter[0] = 0x00;
parameter[1] = 0x00 + Xpos;
parameter[2] = 0x00;
parameter[3] = 0xEF + Xpos;
ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4);
/* RASET: Row Addrses Set */
parameter[0] = 0x00;
parameter[1] = 0x00 + Ypos;
parameter[2] = 0x00;
parameter[3] = 0xEF + Ypos;
ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4);
}
/**
* @brief Write pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param RGBCode: the RGB pixel color in RGB565 format
* @retval None
*/
void ST7789H2_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
/* Set Cursor */
ST7789H2_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Write RAM data */
LCD_IO_WriteData(RGBCode);
}
/**
* @brief Read pixel.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval The RGB pixel color in RGB565 format
*/
uint16_t ST7789H2_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
ST7789H2_Rgb888 rgb888;
uint8_t r, g, b;
uint16_t rgb565;
/* Set Cursor */
ST7789H2_SetCursor(Xpos, Ypos);
/* Read RGB888 data from LCD RAM */
rgb888 = ST7789H2_ReadPixel_rgb888(Xpos, Ypos);
/* Convert RGB888 to RGB565 */
r = ((rgb888.red & 0xF8) >> 3); /* Extract the red component 5 most significant bits */
g = ((rgb888.green & 0xFC) >> 2); /* Extract the green component 6 most significant bits */
b = ((rgb888.blue & 0xF8) >> 3); /* Extract the blue component 5 most significant bits */
rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0);
return (rgb565);
}
/**
* @brief Writes to the selected LCD register.
* @param Command: command value (or register address as named in st7789h2 doc).
* @param Parameters: pointer on parameters value (if command uses one or several parameters).
* @param NbParameters: number of command parameters (0 if no parameter)
* @retval None
*/
void ST7789H2_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters)
{
uint8_t i;
/* Send command */
LCD_IO_WriteReg(Command);
/* Send command's parameters if any */
for (i=0; i<NbParameters; i++)
{
LCD_IO_WriteData(Parameters[i]);
}
}
/**
* @brief Reads the selected LCD Register.
* @param Command: command value (or register address as named in st7789h2 doc).
* @retval Register Value.
*/
uint8_t ST7789H2_ReadReg(uint8_t Command)
{
/* Send command */
LCD_IO_WriteReg(Command);
/* Read dummy data */
LCD_IO_ReadData();
/* Read register value */
return (LCD_IO_ReadData());
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X bottom left position.
* @param Ypos: specifies the Y bottom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void ST7789H2_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
if (Xpos < ST7789H2_LCD_PIXEL_WIDTH)
{
WindowsXstart = Xpos;
}
else
{
WindowsXstart = 0;
}
if (Ypos < ST7789H2_LCD_PIXEL_HEIGHT)
{
WindowsYstart = Ypos;
}
else
{
WindowsYstart = 0;
}
if (Width + Xpos <= ST7789H2_LCD_PIXEL_WIDTH)
{
WindowsXend = Width + Xpos - 1;
}
else
{
WindowsXend = ST7789H2_LCD_PIXEL_WIDTH - 1;
}
if (Height + Ypos <= ST7789H2_LCD_PIXEL_HEIGHT)
{
WindowsYend = Height + Ypos - 1;
}
else
{
WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1;
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color in RGB565 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ST7789H2_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
/* Set Cursor */
ST7789H2_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Sent a complete line */
for(counter = 0; counter < Length; counter++)
{
LCD_IO_WriteData(RGBCode);
}
}
/**
* @brief Draw vertical line.
* @param RGBCode: Specifies the RGB color
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: specifies the Line length.
* @retval None
*/
void ST7789H2_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
/* Set Cursor */
ST7789H2_SetCursor(Xpos, Ypos);
/* Prepare to write to LCD RAM */
ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
/* Fill a complete vertical line */
for(counter = 0; counter < Length; counter++)
{
ST7789H2_WritePixel(Xpos, Ypos + counter, RGBCode);
}
}
/**
* @brief Displays a bitmap picture.
* @param BmpAddress: Bmp picture address.
* @param Xpos: Bmp X position in the LCD
* @param Ypos: Bmp Y position in the LCD
* @retval None
*/
void ST7789H2_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
uint32_t posY;
uint32_t nb_line = 0;
uint16_t Xsize = WindowsXend - WindowsXstart + 1;
uint16_t Ysize = WindowsYend - WindowsYstart + 1;
/* Read bitmap size */
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
/* Get bitmap data address offset */
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
for (posY = (Ypos + Ysize); posY > Ypos; posY--) /* In BMP files the line order is inverted */
{
/* Set Cursor */
ST7789H2_SetCursor(Xpos, posY - 1);
/* Draw one line of the picture */
ST7789H2_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2)));
nb_line++;
}
}
/**
* @brief Displays picture.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @param Ysize: Image Y size in the LCD
* @retval None
*/
void ST7789H2_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
{
uint32_t posY;
uint32_t nb_line = 0;
for (posY = Ypos; posY < (Ypos + Ysize); posY ++)
{
/* Set Cursor */
ST7789H2_SetCursor(Xpos, posY);
/* Draw one line of the picture */
ST7789H2_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2)));
nb_line++;
}
}
/******************************************************************************
Static Functions
*******************************************************************************/
/**
* @brief Read pixel from LCD RAM in RGB888 format
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval Each RGB pixel color components in a structure
*/
static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos)
{
ST7789H2_Rgb888 rgb888;
uint16_t rgb888_part1, rgb888_part2;
/* In LCD RAM, pixels are 24 bits packed and read with 16 bits access
* Here is the pixels components arrangement in memory :
* bits: 15 14 13 12 11 10 09 08 | 07 06 05 04 03 02 01 00
* address 0 : red pixel 0 X X | green pixel 0 X X
* address 1 : blue pixel 0 X X | red pixel 1 X X
* address 2 : green pixel 1 X X | blue pixel 1 X X
*/
/* Set Cursor */
ST7789H2_SetCursor(Xpos, Ypos);
/* Prepare to read LCD RAM */
ST7789H2_WriteReg(ST7789H2_READ_RAM, (uint8_t*)NULL, 0); /* RAM read data command */
/* Dummy read */
LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part1 = LCD_IO_ReadData();
/* Read first part of the RGB888 data */
rgb888_part2 = LCD_IO_ReadData();
/* red component */
rgb888.red = (rgb888_part1 & 0xFC00) >> 8;
/* green component */
rgb888.green = (rgb888_part1 & 0x00FC) >> 0;
/* blue component */
rgb888.blue = (rgb888_part2 & 0xFC00) >> 8;
return rgb888;
}
/**
* @brief Displays a single picture line.
* @param pdata: picture address.
* @param Xpos: Image X position in the LCD
* @param Ypos: Image Y position in the LCD
* @param Xsize: Image X size in the LCD
* @retval None
*/
static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata)
{
uint32_t i = 0;
uint32_t posX;
uint16_t *rgb565 = (uint16_t*)pdata;
/* Prepare to write to LCD RAM */
ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
for (posX = Xpos; posX < (Xsize + Xpos); posX++)
{
if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */
(posX <= WindowsXend) && (Ypos <= WindowsYend))
{
if (posX != (Xsize + Xpos)) /* When writing last pixel when size is odd, the third part is not written */
{
LCD_IO_WriteData(rgb565[i]);
}
i++;
}
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,188 @@
/**
******************************************************************************
* @file st7789h2.h
* @author MCD Application Team
* @version V1.1.1
* @date 29-December-2016
* @brief This file contains all the functions prototypes for the st7789h2.c
* driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ST7789H2_H
#define __ST7789H2_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "../Common/lcd.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @addtogroup ST7789H2
* @{
*/
/** @defgroup ST7789H2_Exported_Types ST7789H2 Exported Types
* @{
*/
/**
* @}
*/
/** @defgroup ST7789H2_Exported_Constants ST7789H2 Exported Constants
* @{
*/
/**
* @brief ST7789H2 ID
*/
#define ST7789H2_ID 0x85
/**
* @brief ST7789H2 Size
*/
#define ST7789H2_LCD_PIXEL_WIDTH ((uint16_t)240)
#define ST7789H2_LCD_PIXEL_HEIGHT ((uint16_t)240)
/**
* @brief LCD_OrientationTypeDef
* Possible values of Display Orientation
*/
#define ST7789H2_ORIENTATION_PORTRAIT ((uint32_t)0x00) /* Portrait orientation choice of LCD screen */
#define ST7789H2_ORIENTATION_LANDSCAPE ((uint32_t)0x01) /* Landscape orientation choice of LCD screen */
#define ST7789H2_ORIENTATION_LANDSCAPE_ROT180 ((uint32_t)0x02) /* Landscape rotated 180° orientation choice of LCD screen */
/**
* @brief ST7789H2 Registers
*/
#define ST7789H2_LCD_ID 0x04
#define ST7789H2_SLEEP_IN 0x10
#define ST7789H2_SLEEP_OUT 0x11
#define ST7789H2_PARTIAL_DISPLAY 0x12
#define ST7789H2_DISPLAY_INVERSION 0x21
#define ST7789H2_DISPLAY_ON 0x29
#define ST7789H2_WRITE_RAM 0x2C
#define ST7789H2_READ_RAM 0x2E
#define ST7789H2_CASET 0x2A
#define ST7789H2_RASET 0x2B
#define ST7789H2_VSCRDEF 0x33 /* Vertical Scroll Definition */
#define ST7789H2_VSCSAD 0x37 /* Vertical Scroll Start Address of RAM */
#define ST7789H2_TEARING_EFFECT 0x35
#define ST7789H2_NORMAL_DISPLAY 0x36
#define ST7789H2_IDLE_MODE_OFF 0x38
#define ST7789H2_IDLE_MODE_ON 0x39
#define ST7789H2_COLOR_MODE 0x3A
#define ST7789H2_PORCH_CTRL 0xB2
#define ST7789H2_GATE_CTRL 0xB7
#define ST7789H2_VCOM_SET 0xBB
#define ST7789H2_DISPLAY_OFF 0xBD
#define ST7789H2_LCM_CTRL 0xC0
#define ST7789H2_VDV_VRH_EN 0xC2
#define ST7789H2_VDV_SET 0xC4
#define ST7789H2_VCOMH_OFFSET_SET 0xC5
#define ST7789H2_FR_CTRL 0xC6
#define ST7789H2_POWER_CTRL 0xD0
#define ST7789H2_PV_GAMMA_CTRL 0xE0
#define ST7789H2_NV_GAMMA_CTRL 0xE1
/**
* @}
*/
/** @defgroup ST7789H2_Exported_Functions ST7789H2 Exported Functions
* @{
*/
void ST7789H2_Init(void);
void ST7789H2_SetOrientation(uint32_t orientation);
uint16_t ST7789H2_ReadID(void);
void ST7789H2_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters);
uint8_t ST7789H2_ReadReg(uint8_t Command);
void ST7789H2_DisplayOn(void);
void ST7789H2_DisplayOff(void);
void ST7789H2_SetCursor(uint16_t Xpos, uint16_t Ypos);
void ST7789H2_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode);
uint16_t ST7789H2_ReadPixel(uint16_t Xpos, uint16_t Ypos);
void ST7789H2_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ST7789H2_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
void ST7789H2_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
void ST7789H2_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata);
void ST7789H2_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
uint16_t ST7789H2_GetLcdPixelWidth(void);
uint16_t ST7789H2_GetLcdPixelHeight(void);
/* LCD driver structure */
extern LCD_DrvTypeDef ST7789H2_drv;
/* LCD IO functions */
extern void LCD_IO_Init(void);
extern void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size);
extern void LCD_IO_WriteReg(uint8_t Reg);
extern void LCD_IO_WriteData(uint16_t RegValue);
extern uint16_t LCD_IO_ReadData(void);
extern void LCD_IO_Delay(uint32_t delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ST7789H2_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,604 @@
/**
******************************************************************************
* @file stmpe1600.c
* @author MCD Application Team
* @version V1.1.0
* @date 10-February-2015
* @brief This file provides a set of functions needed to manage the STMPE1600
* IO Expander devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 "stmpe1600.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @defgroup STMPE1600
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Types_Definitions
* @{
*/
/* Private define ------------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Defines
* @{
*/
#define STMPE1600_MAX_INSTANCE 2
/* Private macro -------------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Macros
* @{
*/
/* Private variables ---------------------------------------------------------*/
static uint16_t tmp = 0;
/** @defgroup STMPE1600_Private_Variables
* @{
*/
/* IO driver structure initialization */
IO_DrvTypeDef stmpe1600_io_drv =
{
stmpe1600_Init,
stmpe1600_ReadID,
stmpe1600_Reset,
stmpe1600_Start,
stmpe1600_IO_Config,
stmpe1600_IO_WritePin,
stmpe1600_IO_ReadPin,
0,
0,
stmpe1600_IO_ITStatus,
stmpe1600_IO_ClearIT,
};
uint8_t stmpe1600[STMPE1600_MAX_INSTANCE] = {0};
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup STMPE1600_Private_Function_Prototypes
* @{
*/
static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr);
/* Private functions ---------------------------------------------------------*/
/** @defgroup STMPE1600_Private_Functions
* @{
*/
/**
* @brief Initialize the stmpe1600 and configure the needed hardware resources
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_Init(uint16_t DeviceAddr)
{
uint8_t instance;
uint8_t empty;
/* Check if device instance already exists */
instance = stmpe1600_GetInstance(DeviceAddr);
if(instance == 0xFF)
{
/* Look for empty instance */
empty = stmpe1600_GetInstance(0);
if(empty < STMPE1600_MAX_INSTANCE)
{
/* Register the current device instance */
stmpe1600[empty] = DeviceAddr;
/* Initialize IO BUS layer */
IOE_Init();
/* Generate stmpe1600 Software reset */
stmpe1600_Reset(DeviceAddr);
}
}
}
/**
* @brief Configures the touch Screen Controller (Single point detection)
* @param DeviceAddr: Device address on communication Bus.
* @retval None.
*/
void stmpe1600_Start(uint16_t DeviceAddr, uint32_t IO_Pin)
{
/*Configuration already done during the initialization */
}
/**
* @brief Reset the stmpe1600 by Software.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_Reset(uint16_t DeviceAddr)
{
/* Power Down the stmpe1600 */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x80);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(2);
/* Power On the Codec after the power off: all registers are reinitialized */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint16_t)0x00);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(2);
}
/**
* @brief Read the stmpe1600 device ID.
* @param DeviceAddr: Device address on communication Bus.
* @retval The Device ID (two bytes).
*/
uint16_t stmpe1600_ReadID(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Initialize IO BUS layer */
IOE_Init();
/* Read the stmpe1600 device ID */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_CHP_ID, tmpData, 2);
/* Return the device ID value */
return((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
}
/**
* @brief Set the global interrupt Polarity.
* @param DeviceAddr: Device address on communication Bus.
* @param Polarity: could be one of these values;
* @arg STMPE1600_POLARITY_LOW: Interrupt line is active Low/Falling edge
* @arg STMPE1600_POLARITY_HIGH: Interrupt line is active High/Rising edge
* @retval None
*/
void stmpe1600_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity)
{
uint8_t tmp = 0;
/* Get the current register value */
tmp = IOE_Read(DeviceAddr, STMPE1600_REG_SYS_CTRL);
/* Mask the polarity bit */
tmp &= ~(uint16_t)0x01;
/* Set the Interrupt Output line polarity */
tmp |= (uint8_t)Polarity;
/* Set the new register value */
IOE_Write(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmp);
}
/**
* @brief Enable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Configure NVIC IT for IOE */
IOE_ITConfig();
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the global interrupts to be Enabled */
tmp |= (uint16_t)STMPE1600_IT_ENABLE;
/* Write Back the Interrupt Control register */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the global interrupts to be Enabled */
tmp &= ~(uint16_t)STMPE1600_IT_ENABLE;
/* Write Back the Interrupt Control register */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_SYS_CTRL, (uint8_t *)&tmp, 2);
}
/**
* @brief Initialize the selected pin(s) direction.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @param Direction: could be STMPE1600_DIRECTION_IN or STMPE1600_DIRECTION_OUT.
* @retval None
*/
void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPDR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the Pin direction */
if (Direction != STMPE1600_DIRECTION_IN)
{
tmp |= (uint16_t)IO_Pin;
}
else
{
tmp &= ~(uint16_t)IO_Pin;
}
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPDR, (uint8_t *)&tmp, 2);
}
/**
* @brief Configure the IO pin(s) according to IO mode structure value.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The output pin to be set or reset. This parameter can be one
* of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 7.
* @param IO_Mode: The IO pin mode to configure, could be one of the following values:
* @arg IO_MODE_INPUT
* @arg IO_MODE_OUTPUT
* @arg IO_MODE_IT_RISING_EDGE
* @arg IO_MODE_IT_FALLING_EDGE
* @retval 0 if no error, IO_Mode if error
*/
uint8_t stmpe1600_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode)
{
uint8_t error_code = 0;
uint8_t buffer[2] = {0,0};
/* Configure IO pin according to selected IO mode */
switch(IO_Mode)
{
case IO_MODE_INPUT: /* Input mode */
stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
break;
case IO_MODE_OUTPUT: /* Output mode */
stmpe1600_IO_DisablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_OUT);
break;
case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */
stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_HIGH);
stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
/* Clear all IO IT pending bits if any */
stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
/* Read GMPR to enable interrupt */
IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);
break;
case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */
stmpe1600_SetITPolarity(DeviceAddr, STMPE1600_POLARITY_LOW);
stmpe1600_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe1600_IO_InitPin(DeviceAddr, IO_Pin, STMPE1600_DIRECTION_IN);
/* Clear all IO IT pending bits if any */
stmpe1600_IO_ClearIT(DeviceAddr, IO_Pin);
/* Read GMPR to enable interrupt */
IOE_ReadMultiple(DeviceAddr , STMPE1600_REG_GPMR, buffer, 2);
break;
default:
error_code = (uint8_t) IO_Mode;
break;
}
return error_code;
}
/**
* @brief Enable polarity inversion of the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_PolarityInv_Enable(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Enable pin polarity inversion */
tmp |= (uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable polarity inversion of the selected IO pins.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPPIR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Disable pin polarity inversion */
tmp &= ~ (uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPPIR, (uint8_t *)&tmp, 2);
}
/**
* @brief Set the value of the selected IO pins.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be set.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @param PinState: The value to be set.
* @retval None
*/
void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Set the pin state */
if(PinState != 0)
{
tmp |= (uint16_t)IO_Pin;
}
else
{
tmp &= ~(uint16_t)IO_Pin;
}
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_GPSR, (uint8_t *)&tmp, 2);
}
/**
* @brief Read the state of the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be read.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval State of the selected IO pin(s).
*/
uint32_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_GPMR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return the pin(s) state */
return(tmp & IO_Pin);
}
/**
* @brief Enable the interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Enable global interrupt */
stmpe1600_EnableGlobalIT(DeviceAddr);
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Put pin in IT mode */
tmp |= (uint16_t)IO_Pin;
/* Write the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2);
}
/**
* @brief Disable the interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be configured.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval None
*/
void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the current register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Disable the IT pin mode */
tmp &= ~(uint16_t)IO_Pin;
/* Set the new register value */
IOE_WriteMultiple(DeviceAddr, STMPE1600_REG_IEGPIOR, (uint8_t *)&tmp, 2);
}
/**
* @brief Read the IT status of the selected IO pin(s)
* (clears all the pending bits if any).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be checked.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval IT Status of the selected IO pin(s).
*/
uint32_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return the pin IT status */
return((tmp & IO_Pin) == IO_Pin);
}
/**
* @brief Detect an IT pending bit from the selected IO pin(s).
* (clears all the pending bits if any).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: IO pin(s) to be checked.
* This parameter could be any combination of the following values:
* @arg STMPE1600_PIN_x: where x can be from 0 to 15.
* @retval IT pending bit detection status.
*/
uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
tmp = ((uint16_t)tmpData[0] | (((uint16_t)tmpData[1]) << 8));
/* Return if there is an IT pending bit or not */
return(tmp & IO_Pin);
}
/**
* @brief Clear all the IT pending bits if any.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmpData[2] = {0 , 0};
/* Get the register value to clear all pending bits */
IOE_ReadMultiple(DeviceAddr, STMPE1600_REG_ISGPIOR, tmpData, 2);
}
/**
* @brief Check if the device instance of the selected address is already registered
* and return its index
* @param DeviceAddr: Device address on communication Bus.
* @retval Index of the device instance if registered, 0xFF if not.
*/
static uint8_t stmpe1600_GetInstance(uint16_t DeviceAddr)
{
uint8_t idx = 0;
/* Check all the registered instances */
for(idx = 0; idx < STMPE1600_MAX_INSTANCE ; idx ++)
{
/* Return index if there is address match */
if(stmpe1600[idx] == DeviceAddr)
{
return idx;
}
}
return 0xFF;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,213 @@
/**
******************************************************************************
* @file stmpe1600.h
* @author MCD Application Team
* @version V1.1.0
* @date 10-February-2015
* @brief This file contains all the functions prototypes for the
* stmpe1600.c IO expander driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STMPE1600_H
#define __STMPE1600_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/io.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @defgroup STMPE1600
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Types
* @{
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Constants
* @{
*/
/**
* @brief STMPE1600 chip IDs
*/
#define STMPE1600_ID 0x1600
/**
* @brief Interrupt enable
*/
#define STMPE1600_IT_ENABLE 0x04
/**
* @brief Identification registers & System Control
*/
#define STMPE1600_REG_CHP_ID 0x00
#define STMPE1600_REG_ID_VERSION 0x02
#define STMPE1600_REG_SYS_CTRL 0x03
/**
* @brief IO Registers
*/
#define STMPE1600_REG_GPMR 0x10
#define STMPE1600_REG_GPSR 0x12
#define STMPE1600_REG_GPDR 0x14
#define STMPE1600_REG_GPPIR 0x16
/**
* @brief Interrupt Control registers
*/
#define STMPE1600_REG_IEGPIOR 0x08
#define STMPE1600_REG_ISGPIOR 0x0A
/**
* @brief IO Pins direction
*/
#define STMPE1600_DIRECTION_IN 0x00
#define STMPE1600_DIRECTION_OUT 0x01
/**
* @brief IO IT polarity
*/
#define STMPE1600_POLARITY_LOW 0x00
#define STMPE1600_POLARITY_HIGH 0x01
/**
* @brief IO Pins
*/
#define STMPE1600_PIN_0 0x0001
#define STMPE1600_PIN_1 0x0002
#define STMPE1600_PIN_2 0x0004
#define STMPE1600_PIN_3 0x0008
#define STMPE1600_PIN_4 0x0010
#define STMPE1600_PIN_5 0x0020
#define STMPE1600_PIN_6 0x0040
#define STMPE1600_PIN_7 0x0080
#define STMPE1600_PIN_8 0x0100
#define STMPE1600_PIN_9 0x0200
#define STMPE1600_PIN_10 0x0400
#define STMPE1600_PIN_11 0x0800
#define STMPE1600_PIN_12 0x1000
#define STMPE1600_PIN_13 0x2000
#define STMPE1600_PIN_14 0x4000
#define STMPE1600_PIN_15 0x8000
#define STMPE1600_PIN_ALL 0xFFFF
/**
* @}
*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Macros
* @{
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup STMPE1600_Exported_Functions
* @{
*/
/**
* @brief STMPE1600 Control functions
*/
void stmpe1600_Init(uint16_t DeviceAddr);
void stmpe1600_Reset(uint16_t DeviceAddr);
uint16_t stmpe1600_ReadID(uint16_t DeviceAddr);
void stmpe1600_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity);
void stmpe1600_EnableGlobalIT(uint16_t DeviceAddr);
void stmpe1600_DisableGlobalIT(uint16_t DeviceAddr);
/**
* @brief STMPE1600 IO functionalities functions
*/
void stmpe1600_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
uint8_t stmpe1600_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
void stmpe1600_IO_PolarityInv_Enable(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_PolarityInv_Disable(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
uint32_t stmpe1600_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
uint32_t stmpe1600_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
uint8_t stmpe1600_IO_ReadIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe1600_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
void IOE_Init(void);
void IOE_ITConfig (void);
void IOE_Delay(uint32_t delay);
void IOE_Write(uint8_t addr, uint8_t reg, uint8_t value);
uint8_t IOE_Read(uint8_t addr, uint8_t reg);
uint16_t IOE_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
void IOE_WriteMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
/* STMPE1600 driver structure */
extern IO_DrvTypeDef stmpe1600_io_drv;
#ifdef __cplusplus
}
#endif
#endif /* __STMPE1600_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,977 @@
/**
******************************************************************************
* @file stmpe811.c
* @author MCD Application Team
* @version V2.0.0
* @date 15-December-2014
* @brief This file provides a set of functions needed to manage the STMPE811
* IO Expander devices.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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 "stmpe811.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @defgroup STMPE811
* @{
*/
/** @defgroup STMPE811_Private_Types_Definitions
* @{
*/
/** @defgroup STMPE811_Private_Defines
* @{
*/
#define STMPE811_MAX_INSTANCE 2
/**
* @}
*/
/** @defgroup STMPE811_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup STMPE811_Private_Variables
* @{
*/
/* Touch screen driver structure initialization */
TS_DrvTypeDef stmpe811_ts_drv =
{
stmpe811_Init,
stmpe811_ReadID,
stmpe811_Reset,
stmpe811_TS_Start,
stmpe811_TS_DetectTouch,
stmpe811_TS_GetXY,
stmpe811_TS_EnableIT,
stmpe811_TS_ClearIT,
stmpe811_TS_ITStatus,
stmpe811_TS_DisableIT,
};
/* IO driver structure initialization */
IO_DrvTypeDef stmpe811_io_drv =
{
stmpe811_Init,
stmpe811_ReadID,
stmpe811_Reset,
stmpe811_IO_Start,
stmpe811_IO_Config,
stmpe811_IO_WritePin,
stmpe811_IO_ReadPin,
stmpe811_IO_EnableIT,
stmpe811_IO_DisableIT,
stmpe811_IO_ITStatus,
stmpe811_IO_ClearIT,
};
/* stmpe811 instances by address */
uint8_t stmpe811[STMPE811_MAX_INSTANCE] = {0};
/**
* @}
*/
/** @defgroup STMPE811_Private_Function_Prototypes
* @{
*/
static uint8_t stmpe811_GetInstance(uint16_t DeviceAddr);
/**
* @}
*/
/** @defgroup STMPE811_Private_Functions
* @{
*/
/**
* @brief Initialize the stmpe811 and configure the needed hardware resources
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_Init(uint16_t DeviceAddr)
{
uint8_t instance;
uint8_t empty;
/* Check if device instance already exists */
instance = stmpe811_GetInstance(DeviceAddr);
/* To prevent double initialization */
if(instance == 0xFF)
{
/* Look for empty instance */
empty = stmpe811_GetInstance(0);
if(empty < STMPE811_MAX_INSTANCE)
{
/* Register the current device instance */
stmpe811[empty] = DeviceAddr;
/* Initialize IO BUS layer */
IOE_Init();
/* Generate stmpe811 Software reset */
stmpe811_Reset(DeviceAddr);
}
}
}
/**
* @brief Reset the stmpe811 by Software.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_Reset(uint16_t DeviceAddr)
{
/* Power Down the stmpe811 */
IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 2);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(10);
/* Power On the Codec after the power off => all registers are reinitialized */
IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 0);
/* Wait for a delay to ensure registers erasing */
IOE_Delay(2);
}
/**
* @brief Read the stmpe811 IO Expander device ID.
* @param DeviceAddr: Device address on communication Bus.
* @retval The Device ID (two bytes).
*/
uint16_t stmpe811_ReadID(uint16_t DeviceAddr)
{
/* Initialize IO BUS layer */
IOE_Init();
/* Return the device ID value */
return ((IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_LSB) << 8) |\
(IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_MSB)));
}
/**
* @brief Enable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_EnableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmp = 0;
/* Read the Interrupt Control register */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
/* Set the global interrupts to be Enabled */
tmp |= (uint8_t)STMPE811_GIT_EN;
/* Write Back the Interrupt Control register */
IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
}
/**
* @brief Disable the Global interrupt.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_DisableGlobalIT(uint16_t DeviceAddr)
{
uint8_t tmp = 0;
/* Read the Interrupt Control register */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
/* Set the global interrupts to be Disabled */
tmp &= ~(uint8_t)STMPE811_GIT_EN;
/* Write Back the Interrupt Control register */
IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
}
/**
* @brief Enable the interrupt mode for the selected IT source
* @param DeviceAddr: Device address on communication Bus.
* @param Source: The interrupt source to be configured, could be:
* @arg STMPE811_GIT_IO: IO interrupt
* @arg STMPE811_GIT_ADC : ADC interrupt
* @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
* @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
* @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
* @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
* @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
* @retval None
*/
void stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source)
{
uint8_t tmp = 0;
/* Get the current value of the INT_EN register */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN);
/* Set the interrupts to be Enabled */
tmp |= Source;
/* Set the register */
IOE_Write(DeviceAddr, STMPE811_REG_INT_EN, tmp);
}
/**
* @brief Disable the interrupt mode for the selected IT source
* @param DeviceAddr: Device address on communication Bus.
* @param Source: The interrupt source to be configured, could be:
* @arg STMPE811_GIT_IO: IO interrupt
* @arg STMPE811_GIT_ADC : ADC interrupt
* @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
* @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
* @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
* @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
* @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
* @retval None
*/
void stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source)
{
uint8_t tmp = 0;
/* Get the current value of the INT_EN register */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN);
/* Set the interrupts to be Enabled */
tmp &= ~Source;
/* Set the register */
IOE_Write(DeviceAddr, STMPE811_REG_INT_EN, tmp);
}
/**
* @brief Set the global interrupt Polarity.
* @param DeviceAddr: Device address on communication Bus.
* @param Polarity: the IT mode polarity, could be one of the following values:
* @arg STMPE811_POLARITY_LOW: Interrupt line is active Low/Falling edge
* @arg STMPE811_POLARITY_HIGH: Interrupt line is active High/Rising edge
* @retval None
*/
void stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity)
{
uint8_t tmp = 0;
/* Get the current register value */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
/* Mask the polarity bits */
tmp &= ~(uint8_t)0x04;
/* Modify the Interrupt Output line configuration */
tmp |= Polarity;
/* Set the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
}
/**
* @brief Set the global interrupt Type.
* @param DeviceAddr: Device address on communication Bus.
* @param Type: Interrupt line activity type, could be one of the following values:
* @arg STMPE811_TYPE_LEVEL: Interrupt line is active in level model
* @arg STMPE811_TYPE_EDGE: Interrupt line is active in edge model
* @retval None
*/
void stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type)
{
uint8_t tmp = 0;
/* Get the current register value */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL);
/* Mask the type bits */
tmp &= ~(uint8_t)0x02;
/* Modify the Interrupt Output line configuration */
tmp |= Type;
/* Set the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp);
}
/**
* @brief Check the selected Global interrupt source pending bit
* @param DeviceAddr: Device address on communication Bus.
* @param Source: the Global interrupt source to be checked, could be:
* @arg STMPE811_GIT_IO: IO interrupt
* @arg STMPE811_GIT_ADC : ADC interrupt
* @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
* @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
* @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
* @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
* @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
* @retval The checked Global interrupt source status.
*/
uint8_t stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source)
{
/* Return the global IT source status */
return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & Source) == Source);
}
/**
* @brief Return the Global interrupts status
* @param DeviceAddr: Device address on communication Bus.
* @param Source: the Global interrupt source to be checked, could be:
* @arg STMPE811_GIT_IO: IO interrupt
* @arg STMPE811_GIT_ADC : ADC interrupt
* @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
* @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
* @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
* @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
* @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
* @retval The checked Global interrupt source status.
*/
uint8_t stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source)
{
/* Return the global IT source status */
return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & Source));
}
/**
* @brief Clear the selected Global interrupt pending bit(s)
* @param DeviceAddr: Device address on communication Bus.
* @param Source: the Global interrupt source to be cleared, could be any combination
* of the following values:
* @arg STMPE811_GIT_IO: IO interrupt
* @arg STMPE811_GIT_ADC : ADC interrupt
* @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt
* @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt
* @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt
* @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt
* @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt
* @retval None
*/
void stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source)
{
/* Write 1 to the bits that have to be cleared */
IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, Source);
}
/**
* @brief Start the IO functionality use and disable the AF for selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO pin(s) to put in AF. This parameter can be one
* of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t mode;
/* Get the current register value */
mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2);
/* Set the Functionalities to be Disabled */
mode &= ~(STMPE811_IO_FCT | STMPE811_ADC_FCT);
/* Write the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
/* Disable AF for the selected IO pin(s) */
stmpe811_IO_DisableAF(DeviceAddr, (uint8_t)IO_Pin);
}
/**
* @brief Configures the IO pin(s) according to IO mode structure value.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The output pin to be set or reset. This parameter can be one
* of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @param IO_Mode: The IO pin mode to configure, could be one of the following values:
* @arg IO_MODE_INPUT
* @arg IO_MODE_OUTPUT
* @arg IO_MODE_IT_RISING_EDGE
* @arg IO_MODE_IT_FALLING_EDGE
* @arg IO_MODE_IT_LOW_LEVEL
* @arg IO_MODE_IT_HIGH_LEVEL
* @retval 0 if no error, IO_Mode if error
*/
uint8_t stmpe811_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode)
{
uint8_t error_code = 0;
/* Configure IO pin according to selected IO mode */
switch(IO_Mode)
{
case IO_MODE_INPUT: /* Input mode */
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
break;
case IO_MODE_OUTPUT: /* Output mode */
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_OUT);
break;
case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */
stmpe811_IO_EnableIT(DeviceAddr);
stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE);
stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_RISING);
break;
case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */
stmpe811_IO_EnableIT(DeviceAddr);
stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE);
stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_FALLING);
break;
case IO_MODE_IT_LOW_LEVEL: /* Low level interrupt mode */
stmpe811_IO_EnableIT(DeviceAddr);
stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL);
stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_LOW);
break;
case IO_MODE_IT_HIGH_LEVEL: /* High level interrupt mode */
stmpe811_IO_EnableIT(DeviceAddr);
stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin);
stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN);
stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL);
stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_HIGH);
break;
default:
error_code = (uint8_t) IO_Mode;
break;
}
return error_code;
}
/**
* @brief Initialize the selected IO pin direction.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO pin to be configured. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: Where x can be from 0 to 7.
* @param Direction: could be STMPE811_DIRECTION_IN or STMPE811_DIRECTION_OUT.
* @retval None
*/
void stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction)
{
uint8_t tmp = 0;
/* Get all the Pins direction */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_DIR);
/* Set the selected pin direction */
if (Direction != STMPE811_DIRECTION_IN)
{
tmp |= (uint8_t)IO_Pin;
}
else
{
tmp &= ~(uint8_t)IO_Pin;
}
/* Write the register new value */
IOE_Write(DeviceAddr, STMPE811_REG_IO_DIR, tmp);
}
/**
* @brief Disable the AF for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO pin to be configured. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: Where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmp = 0;
/* Get the current state of the IO_AF register */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF);
/* Enable the selected pins alternate function */
tmp |= (uint8_t)IO_Pin;
/* Write back the new value in IO AF register */
IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp);
}
/**
* @brief Enable the AF for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO pin to be configured. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: Where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmp = 0;
/* Get the current register value */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF);
/* Enable the selected pins alternate function */
tmp &= ~(uint8_t)IO_Pin;
/* Write back the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp);
}
/**
* @brief Configure the Edge for which a transition is detectable for the
* selected pin.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO pin to be configured. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: Where x can be from 0 to 7.
* @param Edge: The edge which will be detected. This parameter can be one or
* a combination of following values: STMPE811_EDGE_FALLING and STMPE811_EDGE_RISING .
* @retval None
*/
void stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge)
{
uint8_t tmp1 = 0, tmp2 = 0;
/* Get the current registers values */
tmp1 = IOE_Read(DeviceAddr, STMPE811_REG_IO_FE);
tmp2 = IOE_Read(DeviceAddr, STMPE811_REG_IO_RE);
/* Disable the Falling Edge */
tmp1 &= ~(uint8_t)IO_Pin;
/* Disable the Falling Edge */
tmp2 &= ~(uint8_t)IO_Pin;
/* Enable the Falling edge if selected */
if (Edge & STMPE811_EDGE_FALLING)
{
tmp1 |= (uint8_t)IO_Pin;
}
/* Enable the Rising edge if selected */
if (Edge & STMPE811_EDGE_RISING)
{
tmp2 |= (uint8_t)IO_Pin;
}
/* Write back the new registers values */
IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, tmp1);
IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, tmp2);
}
/**
* @brief Write a new IO pin state.
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The output pin to be set or reset. This parameter can be one
* of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @param PinState: The new IO pin state.
* @retval None
*/
void stmpe811_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState)
{
/* Apply the bit value to the selected pin */
if (PinState != 0)
{
/* Set the register */
IOE_Write(DeviceAddr, STMPE811_REG_IO_SET_PIN, (uint8_t)IO_Pin);
}
else
{
/* Set the register */
IOE_Write(DeviceAddr, STMPE811_REG_IO_CLR_PIN, (uint8_t)IO_Pin);
}
}
/**
* @brief Return the state of the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The output pin to be set or reset. This parameter can be one
* of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @retval IO pin(s) state.
*/
uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin)
{
return((uint32_t)(IOE_Read(DeviceAddr, STMPE811_REG_IO_MP_STA) & (uint8_t)IO_Pin));
}
/**
* @brief Enable the global IO interrupt source.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_IO_EnableIT(uint16_t DeviceAddr)
{
IOE_ITConfig();
/* Enable global IO IT source */
stmpe811_EnableITSource(DeviceAddr, STMPE811_GIT_IO);
/* Enable global interrupt */
stmpe811_EnableGlobalIT(DeviceAddr);
}
/**
* @brief Disable the global IO interrupt source.
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_IO_DisableIT(uint16_t DeviceAddr)
{
/* Disable the global interrupt */
stmpe811_DisableGlobalIT(DeviceAddr);
/* Disable global IO IT source */
stmpe811_DisableITSource(DeviceAddr, STMPE811_GIT_IO);
}
/**
* @brief Enable interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO interrupt to be enabled. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmp = 0;
/* Get the IO interrupt state */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN);
/* Set the interrupts to be enabled */
tmp |= (uint8_t)IO_Pin;
/* Write the register new value */
IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp);
}
/**
* @brief Disable interrupt mode for the selected IO pin(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO interrupt to be disabled. This parameter could be any
* combination of the following values:
* @arg STMPE811_PIN_x: where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
uint8_t tmp = 0;
/* Get the IO interrupt state */
tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN);
/* Set the interrupts to be Disabled */
tmp &= ~(uint8_t)IO_Pin;
/* Write the register new value */
IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp);
}
/**
* @brief Check the status of the selected IO interrupt pending bit
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: The IO interrupt to be checked could be:
* @arg STMPE811_PIN_x Where x can be from 0 to 7.
* @retval Status of the checked IO pin(s).
*/
uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin)
{
/* Get the Interrupt status */
return(IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_STA) & (uint8_t)IO_Pin);
}
/**
* @brief Clear the selected IO interrupt pending bit(s).
* @param DeviceAddr: Device address on communication Bus.
* @param IO_Pin: the IO interrupt to be cleared, could be:
* @arg STMPE811_PIN_x: Where x can be from 0 to 7.
* @retval None
*/
void stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin)
{
/* Clear the global IO IT pending bit */
stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_GIT_IO);
/* Clear the IO IT pending bit(s) */
IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_STA, (uint8_t)IO_Pin);
/* Clear the Edge detection pending bit*/
IOE_Write(DeviceAddr, STMPE811_REG_IO_ED, (uint8_t)IO_Pin);
/* Clear the Rising edge pending bit */
IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, (uint8_t)IO_Pin);
/* Clear the Falling edge pending bit */
IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, (uint8_t)IO_Pin);
}
/**
* @brief Configures the touch Screen Controller (Single point detection)
* @param DeviceAddr: Device address on communication Bus.
* @retval None.
*/
void stmpe811_TS_Start(uint16_t DeviceAddr)
{
uint8_t mode;
/* Get the current register value */
mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2);
/* Set the Functionalities to be Enabled */
mode &= ~(STMPE811_IO_FCT);
/* Write the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
/* Select TSC pins in TSC alternate mode */
stmpe811_IO_EnableAF(DeviceAddr, STMPE811_TOUCH_IO_ALL);
/* Set the Functionalities to be Enabled */
mode &= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT);
/* Set the new register value */
IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode);
/* Select Sample Time, bit number and ADC Reference */
IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL1, 0x49);
/* Wait for 2 ms */
IOE_Delay(2);
/* Select the ADC clock speed: 3.25 MHz */
IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL2, 0x01);
/* Select 2 nF filter capacitor */
/* Configuration:
- Touch average control : 4 samples
- Touch delay time : 500 uS
- Panel driver setting time: 500 uS
*/
IOE_Write(DeviceAddr, STMPE811_REG_TSC_CFG, 0x9A);
/* Configure the Touch FIFO threshold: single point reading */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_TH, 0x01);
/* Clear the FIFO memory content. */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
/* Put the FIFO back into operation mode */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
/* Set the range and accuracy pf the pressure measurement (Z) :
- Fractional part :7
- Whole part :1
*/
IOE_Write(DeviceAddr, STMPE811_REG_TSC_FRACT_XYZ, 0x01);
/* Set the driving capability (limit) of the device for TSC pins: 50mA */
IOE_Write(DeviceAddr, STMPE811_REG_TSC_I_DRIVE, 0x01);
/* Touch screen control configuration (enable TSC):
- No window tracking index
- XYZ acquisition mode
*/
IOE_Write(DeviceAddr, STMPE811_REG_TSC_CTRL, 0x01);
/* Clear all the status pending bits if any */
IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, 0xFF);
/* Wait for 2 ms delay */
IOE_Delay(2);
}
/**
* @brief Return if there is touch detected or not.
* @param DeviceAddr: Device address on communication Bus.
* @retval Touch detected state.
*/
uint8_t stmpe811_TS_DetectTouch(uint16_t DeviceAddr)
{
uint8_t state;
uint8_t ret = 0;
state = ((IOE_Read(DeviceAddr, STMPE811_REG_TSC_CTRL) & (uint8_t)STMPE811_TS_CTRL_STATUS) == (uint8_t)0x80);
if(state > 0)
{
if(IOE_Read(DeviceAddr, STMPE811_REG_FIFO_SIZE) > 0)
{
ret = 1;
}
}
else
{
/* Reset FIFO */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
/* Enable the FIFO again */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
}
return ret;
}
/**
* @brief Get the touch screen X and Y positions values
* @param DeviceAddr: Device address on communication Bus.
* @param X: Pointer to X position value
* @param Y: Pointer to Y position value
* @retval None.
*/
void stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
uint8_t dataXYZ[4];
uint32_t uldataXYZ;
IOE_ReadMultiple(DeviceAddr, STMPE811_REG_TSC_DATA_NON_INC, dataXYZ, sizeof(dataXYZ)) ;
/* Calculate positions values */
uldataXYZ = (dataXYZ[0] << 24)|(dataXYZ[1] << 16)|(dataXYZ[2] << 8)|(dataXYZ[3] << 0);
*X = (uldataXYZ >> 20) & 0x00000FFF;
*Y = (uldataXYZ >> 8) & 0x00000FFF;
/* Reset FIFO */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01);
/* Enable the FIFO again */
IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00);
}
/**
* @brief Configure the selected source to generate a global interrupt or not
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_TS_EnableIT(uint16_t DeviceAddr)
{
IOE_ITConfig();
/* Enable global TS IT source */
stmpe811_EnableITSource(DeviceAddr, STMPE811_TS_IT);
/* Enable global interrupt */
stmpe811_EnableGlobalIT(DeviceAddr);
}
/**
* @brief Configure the selected source to generate a global interrupt or not
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_TS_DisableIT(uint16_t DeviceAddr)
{
/* Disable global interrupt */
stmpe811_DisableGlobalIT(DeviceAddr);
/* Disable global TS IT source */
stmpe811_DisableITSource(DeviceAddr, STMPE811_TS_IT);
}
/**
* @brief Configure the selected source to generate a global interrupt or not
* @param DeviceAddr: Device address on communication Bus.
* @retval TS interrupts status
*/
uint8_t stmpe811_TS_ITStatus(uint16_t DeviceAddr)
{
/* Return TS interrupts status */
return(stmpe811_ReadGITStatus(DeviceAddr, STMPE811_TS_IT));
}
/**
* @brief Configure the selected source to generate a global interrupt or not
* @param DeviceAddr: Device address on communication Bus.
* @retval None
*/
void stmpe811_TS_ClearIT(uint16_t DeviceAddr)
{
/* Clear the global TS IT source */
stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_TS_IT);
}
/**
* @brief Check if the device instance of the selected address is already registered
* and return its index
* @param DeviceAddr: Device address on communication Bus.
* @retval Index of the device instance if registered, 0xFF if not.
*/
static uint8_t stmpe811_GetInstance(uint16_t DeviceAddr)
{
uint8_t idx = 0;
/* Check all the registered instances */
for(idx = 0; idx < STMPE811_MAX_INSTANCE ; idx ++)
{
if(stmpe811[idx] == DeviceAddr)
{
return idx;
}
}
return 0xFF;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,291 @@
/**
******************************************************************************
* @file stmpe811.h
* @author MCD Application Team
* @version V2.0.0
* @date 15-December-2014
* @brief This file contains all the functions prototypes for the
* stmpe811.c IO expander driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STMPE811_H
#define __STMPE811_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "../Common/ts.h"
#include "../Common/io.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Components
* @{
*/
/** @defgroup STMPE811
* @{
*/
/** @defgroup STMPE811_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup STMPE811_Exported_Constants
* @{
*/
/* Chip IDs */
#define STMPE811_ID 0x0811
/* Identification registers & System Control */
#define STMPE811_REG_CHP_ID_LSB 0x00
#define STMPE811_REG_CHP_ID_MSB 0x01
#define STMPE811_REG_ID_VER 0x02
/* Global interrupt Enable bit */
#define STMPE811_GIT_EN 0x01
/* IO expander functionalities */
#define STMPE811_ADC_FCT 0x01
#define STMPE811_TS_FCT 0x02
#define STMPE811_IO_FCT 0x04
#define STMPE811_TEMPSENS_FCT 0x08
/* Global Interrupts definitions */
#define STMPE811_GIT_IO 0x80 /* IO interrupt */
#define STMPE811_GIT_ADC 0x40 /* ADC interrupt */
#define STMPE811_GIT_TEMP 0x20 /* Not implemented */
#define STMPE811_GIT_FE 0x10 /* FIFO empty interrupt */
#define STMPE811_GIT_FF 0x08 /* FIFO full interrupt */
#define STMPE811_GIT_FOV 0x04 /* FIFO overflowed interrupt */
#define STMPE811_GIT_FTH 0x02 /* FIFO above threshold interrupt */
#define STMPE811_GIT_TOUCH 0x01 /* Touch is detected interrupt */
#define STMPE811_ALL_GIT 0x1F /* All global interrupts */
#define STMPE811_TS_IT (STMPE811_GIT_TOUCH | STMPE811_GIT_FTH | STMPE811_GIT_FOV | STMPE811_GIT_FF | STMPE811_GIT_FE) /* Touch screen interrupts */
/* General Control Registers */
#define STMPE811_REG_SYS_CTRL1 0x03
#define STMPE811_REG_SYS_CTRL2 0x04
#define STMPE811_REG_SPI_CFG 0x08
/* Interrupt system Registers */
#define STMPE811_REG_INT_CTRL 0x09
#define STMPE811_REG_INT_EN 0x0A
#define STMPE811_REG_INT_STA 0x0B
#define STMPE811_REG_IO_INT_EN 0x0C
#define STMPE811_REG_IO_INT_STA 0x0D
/* IO Registers */
#define STMPE811_REG_IO_SET_PIN 0x10
#define STMPE811_REG_IO_CLR_PIN 0x11
#define STMPE811_REG_IO_MP_STA 0x12
#define STMPE811_REG_IO_DIR 0x13
#define STMPE811_REG_IO_ED 0x14
#define STMPE811_REG_IO_RE 0x15
#define STMPE811_REG_IO_FE 0x16
#define STMPE811_REG_IO_AF 0x17
/* ADC Registers */
#define STMPE811_REG_ADC_INT_EN 0x0E
#define STMPE811_REG_ADC_INT_STA 0x0F
#define STMPE811_REG_ADC_CTRL1 0x20
#define STMPE811_REG_ADC_CTRL2 0x21
#define STMPE811_REG_ADC_CAPT 0x22
#define STMPE811_REG_ADC_DATA_CH0 0x30
#define STMPE811_REG_ADC_DATA_CH1 0x32
#define STMPE811_REG_ADC_DATA_CH2 0x34
#define STMPE811_REG_ADC_DATA_CH3 0x36
#define STMPE811_REG_ADC_DATA_CH4 0x38
#define STMPE811_REG_ADC_DATA_CH5 0x3A
#define STMPE811_REG_ADC_DATA_CH6 0x3B
#define STMPE811_REG_ADC_DATA_CH7 0x3C
/* Touch Screen Registers */
#define STMPE811_REG_TSC_CTRL 0x40
#define STMPE811_REG_TSC_CFG 0x41
#define STMPE811_REG_WDM_TR_X 0x42
#define STMPE811_REG_WDM_TR_Y 0x44
#define STMPE811_REG_WDM_BL_X 0x46
#define STMPE811_REG_WDM_BL_Y 0x48
#define STMPE811_REG_FIFO_TH 0x4A
#define STMPE811_REG_FIFO_STA 0x4B
#define STMPE811_REG_FIFO_SIZE 0x4C
#define STMPE811_REG_TSC_DATA_X 0x4D
#define STMPE811_REG_TSC_DATA_Y 0x4F
#define STMPE811_REG_TSC_DATA_Z 0x51
#define STMPE811_REG_TSC_DATA_XYZ 0x52
#define STMPE811_REG_TSC_FRACT_XYZ 0x56
#define STMPE811_REG_TSC_DATA_INC 0x57
#define STMPE811_REG_TSC_DATA_NON_INC 0xD7
#define STMPE811_REG_TSC_I_DRIVE 0x58
#define STMPE811_REG_TSC_SHIELD 0x59
/* Touch Screen Pins definition */
#define STMPE811_TOUCH_YD STMPE811_PIN_7
#define STMPE811_TOUCH_XD STMPE811_PIN_6
#define STMPE811_TOUCH_YU STMPE811_PIN_5
#define STMPE811_TOUCH_XU STMPE811_PIN_4
#define STMPE811_TOUCH_IO_ALL (uint32_t)(STMPE811_TOUCH_YD | STMPE811_TOUCH_XD | STMPE811_TOUCH_YU | STMPE811_TOUCH_XU)
/* IO Pins definition */
#define STMPE811_PIN_0 0x01
#define STMPE811_PIN_1 0x02
#define STMPE811_PIN_2 0x04
#define STMPE811_PIN_3 0x08
#define STMPE811_PIN_4 0x10
#define STMPE811_PIN_5 0x20
#define STMPE811_PIN_6 0x40
#define STMPE811_PIN_7 0x80
#define STMPE811_PIN_ALL 0xFF
/* IO Pins directions */
#define STMPE811_DIRECTION_IN 0x00
#define STMPE811_DIRECTION_OUT 0x01
/* IO IT types */
#define STMPE811_TYPE_LEVEL 0x00
#define STMPE811_TYPE_EDGE 0x02
/* IO IT polarity */
#define STMPE811_POLARITY_LOW 0x00
#define STMPE811_POLARITY_HIGH 0x04
/* IO Pin IT edge modes */
#define STMPE811_EDGE_FALLING 0x01
#define STMPE811_EDGE_RISING 0x02
/* TS registers masks */
#define STMPE811_TS_CTRL_ENABLE 0x01
#define STMPE811_TS_CTRL_STATUS 0x80
/**
* @}
*/
/** @defgroup STMPE811_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup STMPE811_Exported_Functions
* @{
*/
/**
* @brief STMPE811 Control functions
*/
void stmpe811_Init(uint16_t DeviceAddr);
void stmpe811_Reset(uint16_t DeviceAddr);
uint16_t stmpe811_ReadID(uint16_t DeviceAddr);
void stmpe811_EnableGlobalIT(uint16_t DeviceAddr);
void stmpe811_DisableGlobalIT(uint16_t DeviceAddr);
void stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source);
void stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source);
void stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity);
void stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type);
uint8_t stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source);
uint8_t stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source);
void stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source);
/**
* @brief STMPE811 IO functionalities functions
*/
void stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin);
uint8_t stmpe811_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode);
void stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction);
void stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge);
void stmpe811_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState);
uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe811_IO_EnableIT(uint16_t DeviceAddr);
void stmpe811_IO_DisableIT(uint16_t DeviceAddr);
void stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin);
uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin);
void stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin);
/**
* @brief STMPE811 Touch screen functionalities functions
*/
void stmpe811_TS_Start(uint16_t DeviceAddr);
uint8_t stmpe811_TS_DetectTouch(uint16_t DeviceAddr);
void stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
void stmpe811_TS_EnableIT(uint16_t DeviceAddr);
void stmpe811_TS_DisableIT(uint16_t DeviceAddr);
uint8_t stmpe811_TS_ITStatus (uint16_t DeviceAddr);
void stmpe811_TS_ClearIT (uint16_t DeviceAddr);
void IOE_Init(void);
void IOE_ITConfig (void);
void IOE_Delay(uint32_t delay);
void IOE_Write(uint8_t addr, uint8_t reg, uint8_t value);
uint8_t IOE_Read(uint8_t addr, uint8_t reg);
uint16_t IOE_ReadMultiple(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
/* Touch screen driver structure */
extern TS_DrvTypeDef stmpe811_ts_drv;
/* IO driver structure */
extern IO_DrvTypeDef stmpe811_io_drv;
#ifdef __cplusplus
}
#endif
#endif /* __STMPE811_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,188 @@
/**
******************************************************************************
* @file wm8994.h
* @author MCD Application Team
* @version V2.1.0
* @date 22-February-2016
* @brief This file contains all the functions prototypes for the
* wm8994.c driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __WM8994_H
#define __WM8994_H
/* Includes ------------------------------------------------------------------*/
#include "../Common/audio.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup Component
* @{
*/
/** @addtogroup WM8994
* @{
*/
/** @defgroup WM8994_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup WM8994_Exported_Constants
* @{
*/
/******************************************************************************/
/*************************** Codec User defines ******************************/
/******************************************************************************/
/* Codec output DEVICE */
#define OUTPUT_DEVICE_SPEAKER ((uint16_t)0x0001)
#define OUTPUT_DEVICE_HEADPHONE ((uint16_t)0x0002)
#define OUTPUT_DEVICE_BOTH ((uint16_t)0x0003)
#define OUTPUT_DEVICE_AUTO ((uint16_t)0x0004)
#define INPUT_DEVICE_DIGITAL_MICROPHONE_1 ((uint16_t)0x0100)
#define INPUT_DEVICE_DIGITAL_MICROPHONE_2 ((uint16_t)0x0200)
#define INPUT_DEVICE_INPUT_LINE_1 ((uint16_t)0x0300)
#define INPUT_DEVICE_INPUT_LINE_2 ((uint16_t)0x0400)
#define INPUT_DEVICE_DIGITAL_MIC1_MIC2 ((uint16_t)0x0800)
/* Volume Levels values */
#define DEFAULT_VOLMIN 0x00
#define DEFAULT_VOLMAX 0xFF
#define DEFAULT_VOLSTEP 0x04
#define AUDIO_PAUSE 0
#define AUDIO_RESUME 1
/* Codec POWER DOWN modes */
#define CODEC_PDWN_HW 1
#define CODEC_PDWN_SW 2
/* MUTE commands */
#define AUDIO_MUTE_ON 1
#define AUDIO_MUTE_OFF 0
/* AUDIO FREQUENCY */
#define AUDIO_FREQUENCY_192K ((uint32_t)192000)
#define AUDIO_FREQUENCY_96K ((uint32_t)96000)
#define AUDIO_FREQUENCY_48K ((uint32_t)48000)
#define AUDIO_FREQUENCY_44K ((uint32_t)44100)
#define AUDIO_FREQUENCY_32K ((uint32_t)32000)
#define AUDIO_FREQUENCY_22K ((uint32_t)22050)
#define AUDIO_FREQUENCY_16K ((uint32_t)16000)
#define AUDIO_FREQUENCY_11K ((uint32_t)11025)
#define AUDIO_FREQUENCY_8K ((uint32_t)8000)
#define VOLUME_CONVERT(Volume) (((Volume) > 100)? 100:((uint8_t)(((Volume) * 63) / 100)))
#define VOLUME_IN_CONVERT(Volume) (((Volume) >= 100)? 239:((uint8_t)(((Volume) * 240) / 100)))
/******************************************************************************/
/****************************** REGISTER MAPPING ******************************/
/******************************************************************************/
/**
* @brief WM8994 ID
*/
#define WM8994_ID 0x8994
/**
* @brief Device ID Register: Reading from this register will indicate device
* family ID 8994h
*/
#define WM8994_CHIPID_ADDR 0x00
/**
* @}
*/
/** @defgroup WM8994_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup WM8994_Exported_Functions
* @{
*/
/*------------------------------------------------------------------------------
Audio Codec functions
------------------------------------------------------------------------------*/
/* High Layer codec functions */
uint32_t wm8994_Init(uint16_t DeviceAddr, uint16_t OutputInputDevice, uint8_t Volume, uint32_t AudioFreq);
void wm8994_DeInit(void);
uint32_t wm8994_ReadID(uint16_t DeviceAddr);
uint32_t wm8994_Play(uint16_t DeviceAddr, uint16_t* pBuffer, uint16_t Size);
uint32_t wm8994_Pause(uint16_t DeviceAddr);
uint32_t wm8994_Resume(uint16_t DeviceAddr);
uint32_t wm8994_Stop(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t wm8994_SetVolume(uint16_t DeviceAddr, uint8_t Volume);
uint32_t wm8994_SetMute(uint16_t DeviceAddr, uint32_t Cmd);
uint32_t wm8994_SetOutputMode(uint16_t DeviceAddr, uint8_t Output);
uint32_t wm8994_SetFrequency(uint16_t DeviceAddr, uint32_t AudioFreq);
uint32_t wm8994_Reset(uint16_t DeviceAddr);
/* AUDIO IO functions */
void AUDIO_IO_Init(void);
void AUDIO_IO_DeInit(void);
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
uint8_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
void AUDIO_IO_Delay(uint32_t Delay);
/* Audio driver structure */
extern AUDIO_DrvTypeDef wm8994_drv;
#endif /* __WM8994_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,606 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,286 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,630 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "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****/

View file

@ -0,0 +1,161 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,395 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "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****/

View file

@ -0,0 +1,161 @@
/**
******************************************************************************
* @file stm32l496g_discovery_idd.h
* @author MCD Application Team
* @brief Header file for stm32l496g_discovery_idd.c module.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,321 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,144 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,278 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,135 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,732 @@
/**
******************************************************************************
* @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 handeled using the function BSP_SD_IRQHandler(),
the DMA Tx/Rx transfer complete are handeled 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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "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_PULLUP;
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****/

View file

@ -0,0 +1,165 @@
/**
******************************************************************************
* @file stm32l496g_discovery_sd.h
* @author MCD Application Team
* @brief This file includes the uSD card driver.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,374 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 "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****/

View file

@ -0,0 +1,130 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/** @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****/

View file

@ -0,0 +1,533 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

View file

@ -0,0 +1,219 @@
/**
******************************************************************************
* @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>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* 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****/

Some files were not shown because too many files have changed in this diff Show more