1717 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1818 */
1919
20- #include "AHT20.h"
20+ #include <aht20.h>
2121#include <stdio.h>
2222#include <string.h>
2323#include <assert.h>
@@ -73,6 +73,13 @@ static uint8_t ACK_CMD = 0x06;
7373 */
7474static uint8_t NACK_CMD = 0x15 ;
7575
76+ const aht20_sensor_api_t aht20_api = {
77+ .aht20_validate_calibration = aht20_validate_calibration ,
78+ .measure = aht20_measure ,
79+ .calculate_measurments = aht20_calculate_measurments ,
80+ .soft_reset = aht20_soft_reset ,
81+ };
82+
7683/*
7784 * calculates crc8 for given data
7885 */
@@ -84,48 +91,28 @@ static uint8_t calculate_crc(uint8_t *data);
8491 * Datasheet: AHT20 Product manuals
8592 * 5.3 Send command
8693 */
87- aht20_status_t aht20_get_calibration_status (I2C_HandleTypeDef * hi2c , uint8_t * status_word , uint16_t status_word_size ) {
94+ aht20_status_t aht20_validate_calibration (I2C_HandleTypeDef * hi2c ) {
8895 assert (hi2c != NULL );
89- assert (status_word != NULL );
96+ uint8_t status_word = 0 ;
97+
98+ HAL_Delay (40 );
9099
91100 if (HAL_OK != HAL_I2C_Master_Transmit (hi2c , DEVICE_ADDRESS , & GET_STATUS_CMD , (uint16_t )sizeof (GET_STATUS_CMD ), HAL_MAX_DELAY )) {
92101 return AHT20_STATUS_NOT_TRANSMITTED ;
93102 }
94103
95- if (HAL_OK != HAL_I2C_Master_Receive (hi2c , DEVICE_ADDRESS , status_word , status_word_size , HAL_MAX_DELAY )) {
104+ if (HAL_OK != HAL_I2C_Master_Receive (hi2c , DEVICE_ADDRESS , & status_word , ( uint16_t ) sizeof ( status_word ) , HAL_MAX_DELAY )) {
96105 return AHT20_STATUS_NOT_RECEIVED ;
97106 }
98107
99- return AHT20_STATUS_OK ;
100- }
101-
102- /*
103- * checks the 3rd bit of a received variable
104- *
105- * Datasheet: AHT20 Product manuals
106- * 5.4 Sensor reading process, paragraph 1
107- */
108- aht20_status_t aht20_check_calibration (uint8_t status_word ) {
109108 if (status_word & (1 << 3 )) {
110109 return AHT20_STATUS_OK ;
111110 } else {
112- return AHT20_STATUS_NOT_CALIBRATED ;
113- }
114- }
115-
116- /*
117- * sends an array of integers to trigger sensor calibration
118- *
119- * Datasheet: AHT20 Product manuals
120- * 5.4 Sensor reading process, paragraph 1
121- */
122- aht20_status_t aht20_calibrate (I2C_HandleTypeDef * hi2c , uint8_t status_word ) {
123- assert (hi2c != NULL );
124-
125- if (HAL_OK != HAL_I2C_Master_Transmit (hi2c , DEVICE_ADDRESS , INIT_CMD , (uint16_t )sizeof (INIT_CMD ), HAL_MAX_DELAY )) {
126- return AHT20_STATUS_NOT_TRANSMITTED ;
111+ if (HAL_OK != HAL_I2C_Master_Transmit (hi2c , DEVICE_ADDRESS , INIT_CMD , (uint16_t )sizeof (INIT_CMD ), HAL_MAX_DELAY )) {
112+ return AHT20_STATUS_NOT_TRANSMITTED ;
113+ }
114+ HAL_Delay (10 );
127115 }
128-
129116 return AHT20_STATUS_OK ;
130117}
131118
0 commit comments