1
0

add P4 & P5

This commit is contained in:
2025-11-24 15:44:12 +01:00
parent bd24f1fb79
commit f6fa6d94ce
1120 changed files with 576492 additions and 83 deletions

View File

@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Release Notes for HTS221 Component Drivers</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<link rel="stylesheet" href="../../../../_htmresc/mini-st.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row">
<div class="col-sm-12 col-lg-4">
<div class="card fluid">
<div class="sectione dark">
<center>
<h1 id="release-notes-for-hts221-component-drivers"><small>Release Notes for</small> <mark>HTS221 Component Drivers</mark></h1>
<p>Copyright © 2017 STMicroelectronics<br />
</p>
<a href="https://www.st.com" class="logo"><img src="../../../../_htmresc/st_logo.png" alt="ST logo" /></a>
</center>
</div>
</div>
<h1 id="license">License</h1>
<p>Licensed by ST under BSD 3-Clause license (the "License"). You may not use this package except in compliance with the License. You may obtain a copy of the License at:</p>
<p><a href="https://opensource.org/licenses/BSD-3-Clause">https://opensource.org/licenses/BSD-3-Clause</a></p>
<h1 id="purpose">Purpose</h1>
<p>This directory contains the HTS221 component drivers.</p>
</div>
<div class="col-sm-12 col-lg-8">
<h1 id="update-history">Update History</h1>
<div class="collapse">
<input type="checkbox" id="collapse-section22" checked aria-hidden="true"> <label for="collapse-section22" aria-hidden="true">V1.0.1 / 03-April-2019</label>
<div>
<h2 id="main-changes">Main Changes</h2>
<ul>
<li>Update release notes format</li>
<li>Reformat the BSD 3-Clause license declaration in the files header (replace license terms by a web reference to OSI website where those terms lie)</li>
</ul>
</div>
</div>
<div class="collapse">
<input type="checkbox" id="collapse-section19" aria-hidden="true"> <label for="collapse-section19" aria-hidden="true">V1.0.0 / 14-February-2017</label>
<div>
<h2 id="main-changes-1">Main Changes</h2>
<ul>
<li>First official release of HTS221 Temperature/Humidity sensor</li>
</ul>
</div>
</div>
</div>
</div>
<footer class="sticky">
For complete documentation on <mark>STM32 Microcontrollers</mark> , visit: <a href="http://www.st.com/STM32">http://www.st.com/STM32</a>
</footer>
</body>
</html>

View File

@@ -0,0 +1,229 @@
/**
******************************************************************************
* @file hts221.c
* @author MCD Application Team
* @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.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "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,320 @@
/**
******************************************************************************
* @file hts221.h
* @author MCD Application Team
* @brief HTS221 header driver file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __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****/