Welcome to mirror list, hosted at ThFree Co, Russian Federation.

app_stts22h.c « Src « Core « Zigbee_TempMeas_Server_Coord « Zigbee « Applications « STM32WB5MM-DK « Projects - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 270f9128213698b621ef02910d76bf919733002a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
 * @file    app_stts22h.c
 * @author  MCD Application Team
 * @brief   Temperature Application
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2019-2021 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "app_stts22h.h"
#include "stm32_lcd.h"
#include "stm32wb5mm_dk_lcd.h"
#include "app_zigbee.h"

/* Private defines -----------------------------------------------------------*/
#define STTS22H_UPDATE_PERIOD       (uint32_t)(0.5*1000*1000/CFG_TS_TICK_VAL) /*500ms*/

/* Private variables ---------------------------------------------------------*/
extern I2C_HandleTypeDef hbus_i2c3;
static STTS22H_Object_t stts22h_obj_0;
uint8_t STTS22H_Update_Timer_Id;

/* Private function prototypes -----------------------------------------------*/
static void STTS22H_Update_Timer_Callback(void);

/* Private functions ---------------------------------------------------------*/
static int32_t STTS22H_write(void *handle, uint8_t reg, uint8_t *bufp,uint16_t len)
{
  BSP_I2C3_WriteReg(STTS22H_I2C_ADD_H, (uint16_t) reg, bufp, len);
  return 0;
}
static int32_t STTS22H_read(void *handle, uint8_t reg, uint8_t *bufp,uint16_t len)
{
  BSP_I2C3_ReadReg(STTS22H_I2C_ADD_H, (uint16_t) reg, bufp, len);
  return 0;
}

/**
 * @brief  STTS22H sensor Initialization.
 * @param  None
 * @retval BSP status
 */
int32_t STTS22H_Init_Sensor(void){
  STTS22H_IO_t            io_ctx;
  uint8_t              id;
  int32_t              ret = BSP_ERROR_NONE;

  /* Configure the environmental sensor driver */
  io_ctx.BusType     = STTS22H_I2C_BUS; /* I2C */
  io_ctx.Address     = STTS22H_I2C_ADD_H;
  io_ctx.Init        = BSP_I2C3_Init;
  io_ctx.DeInit      = BSP_I2C3_DeInit;
  io_ctx.ReadReg     = BSP_I2C3_ReadReg;
  io_ctx.WriteReg    = BSP_I2C3_WriteReg;
  io_ctx.GetTick     = BSP_GetTick;

  stts22h_obj_0.Ctx.write_reg = STTS22H_write;
  stts22h_obj_0.Ctx.read_reg = STTS22H_read;
  stts22h_obj_0.Ctx.handle = &hbus_i2c3;
  
  if (STTS22H_RegisterBusIO(&stts22h_obj_0, &io_ctx) != STTS22H_OK)
  {
    ret = BSP_ERROR_UNKNOWN_COMPONENT;
  }
  else if (STTS22H_ReadID(&stts22h_obj_0, &id) != STTS22H_OK)
  {
    ret = BSP_ERROR_UNKNOWN_COMPONENT;
  }
  else if (id != STTS22H_ID)
  {
    ret = BSP_ERROR_UNKNOWN_COMPONENT;
  }
  else if (STTS22H_Init(&stts22h_obj_0) != STTS22H_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  else if (STTS22H_TEMP_Enable(&stts22h_obj_0) != STTS22H_OK)
  {
    ret = BSP_ERROR_COMPONENT_FAILURE;
  }
  else
  {
    ret = BSP_ERROR_NONE;
  
    UTIL_SEQ_RegTask( 1 << CFG_TASK_GET_MEASURE_ENV_ID, UTIL_SEQ_RFU, STTS22H_PrintValues);
    
    /* Create timer to get the measure of environement data */
    HW_TS_Create(CFG_TIM_PROC_ID_ISR,
        &STTS22H_Update_Timer_Id,
        hw_ts_Repeated,
        STTS22H_Update_Timer_Callback);

  }
  return ret;
}

void STTS22H_Start_Measure(void)
{
  HW_TS_Start(STTS22H_Update_Timer_Id, STTS22H_UPDATE_PERIOD);
}

void STTS22H_Stop_Measure(void)
{
  HW_TS_Stop(STTS22H_Update_Timer_Id);
}

static void STTS22H_Update_Timer_Callback(void)
{
  UTIL_SEQ_SetTask(1 << CFG_TASK_GET_MEASURE_ENV_ID, CFG_SCH_PRIO_0);
}

/**
 * @brief  Get the STTS22H temperature value
 * @param  Value pointer where the temperature value is written
 * @retval None
 */
void STTS22H_getTemperatureValue(float *value){
  float val;
  STTS22H_TEMP_GetTemperature(&stts22h_obj_0,&val);
  *value = val;
}

void STTS22H_PrintValues(void){
  float temp_val;
  char text[32];

  STTS22H_TEMP_GetTemperature(&stts22h_obj_0,&temp_val);

  sprintf(text,"T:%.1f C",temp_val);
  UTIL_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)text, CENTER_MODE);
  BSP_LCD_Refresh(0);

  APP_ZIGBEE_WriteTempAttribute(temp_val); 

  return;
}