Subversion Repositories testOled

Rev

Rev 2 | Rev 8 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* USER CODE BEGIN Header */
2
/**
3
 ******************************************************************************
4
 * @file           : main.c
5
 * @brief          : Main program body
6
 ******************************************************************************
7
 * @attention
8
 *
9
 * Copyright (c) 2022 STMicroelectronics.
10
 * All rights reserved.
11
 *
12
 * This software is licensed under terms that can be found in the LICENSE file
13
 * in the root directory of this software component.
14
 * If no LICENSE file comes with this software, it is provided AS-IS.
15
 *
16
 ******************************************************************************
17
 */
18
/* USER CODE END Header */
19
/* Includes ------------------------------------------------------------------*/
20
#include "main.h"
21
 
22
/* Private includes ----------------------------------------------------------*/
23
/* USER CODE BEGIN Includes */
24
#include "display.h"
4 mjames 25
#include "bmp280driver.h"
2 mjames 26
/* USER CODE END Includes */
27
 
28
/* Private typedef -----------------------------------------------------------*/
29
/* USER CODE BEGIN PTD */
30
 
31
/* USER CODE END PTD */
32
 
33
/* Private define ------------------------------------------------------------*/
34
/* USER CODE BEGIN PD */
35
/* USER CODE END PD */
36
 
37
/* Private macro -------------------------------------------------------------*/
38
/* USER CODE BEGIN PM */
39
 
40
/* USER CODE END PM */
41
 
42
/* Private variables ---------------------------------------------------------*/
4 mjames 43
I2C_HandleTypeDef hi2c1;
2 mjames 44
 
4 mjames 45
SPI_HandleTypeDef hspi1;
46
 
2 mjames 47
/* USER CODE BEGIN PV */
48
 
49
/* USER CODE END PV */
50
 
51
/* Private function prototypes -----------------------------------------------*/
52
void SystemClock_Config(void);
53
static void MX_GPIO_Init(void);
54
static void MX_SPI1_Init(void);
4 mjames 55
static void MX_I2C1_Init(void);
2 mjames 56
/* USER CODE BEGIN PFP */
57
 
58
/* USER CODE END PFP */
59
 
60
/* Private user code ---------------------------------------------------------*/
61
/* USER CODE BEGIN 0 */
62
 
63
/* USER CODE END 0 */
64
 
65
/**
4 mjames 66
 * @brief  The application entry point.
67
 * @retval int
68
 */
2 mjames 69
int main(void)
4 mjames 70
 {
2 mjames 71
  /* USER CODE BEGIN 1 */
72
 
73
  /* USER CODE END 1 */
74
 
75
  /* MCU Configuration--------------------------------------------------------*/
76
 
77
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
78
  HAL_Init();
79
 
80
  /* USER CODE BEGIN Init */
81
 
82
  /* USER CODE END Init */
83
 
84
  /* Configure the system clock */
85
  SystemClock_Config();
86
 
87
  /* USER CODE BEGIN SysInit */
88
 
89
  /* USER CODE END SysInit */
90
 
91
  /* Initialize all configured peripherals */
92
  MX_GPIO_Init();
93
  MX_SPI1_Init();
4 mjames 94
  MX_I2C1_Init();
2 mjames 95
  /* USER CODE BEGIN 2 */
96
  cc_init();
4 mjames 97
 
98
  init_bmp(&hi2c1);
99
  uint32_t lastTick = HAL_GetTick();
2 mjames 100
  /* USER CODE END 2 */
101
 
102
  /* Infinite loop */
103
  /* USER CODE BEGIN WHILE */
104
  while (1)
105
  {
106
    cc_display(0);
4 mjames 107
 
108
    if (HAL_GetTick() - lastTick > 200)
109
    {
110
      lastTick = HAL_GetTick();
111
      /* Reading the raw data from sensor */
112
      struct bmp280_uncomp_data ucomp_data;
113
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
114
 
115
      uint32_t comp_pres = 0;
116
      int32_t comp_temp = -10000;
117
      if (rslt == 0)
118
      {
119
        uint8_t rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
120
 
121
        uint8_t rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
122
      }
123
    }
2 mjames 124
    /* USER CODE END WHILE */
125
 
126
    /* USER CODE BEGIN 3 */
127
  }
128
  /* USER CODE END 3 */
129
}
130
 
131
/**
4 mjames 132
 * @brief System Clock Configuration
133
 * @retval None
134
 */
2 mjames 135
void SystemClock_Config(void)
136
{
137
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
138
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
139
 
140
  /** Initializes the RCC Oscillators according to the specified parameters
4 mjames 141
   * in the RCC_OscInitTypeDef structure.
142
   */
2 mjames 143
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
144
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
145
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
146
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
147
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
148
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
149
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
150
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
151
  {
152
    Error_Handler();
153
  }
154
 
155
  /** Initializes the CPU, AHB and APB buses clocks
4 mjames 156
   */
157
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
2 mjames 158
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
159
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
160
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
161
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
162
 
163
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
164
  {
165
    Error_Handler();
166
  }
167
}
168
 
169
/**
4 mjames 170
 * @brief I2C1 Initialization Function
171
 * @param None
172
 * @retval None
173
 */
174
static void MX_I2C1_Init(void)
175
{
176
 
177
  /* USER CODE BEGIN I2C1_Init 0 */
178
 
179
  /* USER CODE END I2C1_Init 0 */
180
 
181
  /* USER CODE BEGIN I2C1_Init 1 */
182
 
183
  /* USER CODE END I2C1_Init 1 */
184
  hi2c1.Instance = I2C1;
185
  hi2c1.Init.ClockSpeed = 100000;
186
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
187
  hi2c1.Init.OwnAddress1 = 0;
188
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
189
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
190
  hi2c1.Init.OwnAddress2 = 0;
191
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
192
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
193
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
194
  {
195
    Error_Handler();
196
  }
197
  /* USER CODE BEGIN I2C1_Init 2 */
198
 
199
  /* USER CODE END I2C1_Init 2 */
200
}
201
 
202
/**
203
 * @brief SPI1 Initialization Function
204
 * @param None
205
 * @retval None
206
 */
2 mjames 207
static void MX_SPI1_Init(void)
208
{
209
 
210
  /* USER CODE BEGIN SPI1_Init 0 */
211
 
212
  /* USER CODE END SPI1_Init 0 */
213
 
214
  /* USER CODE BEGIN SPI1_Init 1 */
215
 
216
  /* USER CODE END SPI1_Init 1 */
217
  /* SPI1 parameter configuration*/
218
  hspi1.Instance = SPI1;
219
  hspi1.Init.Mode = SPI_MODE_MASTER;
220
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
221
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
222
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
223
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
224
  hspi1.Init.NSS = SPI_NSS_SOFT;
225
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
226
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
227
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
228
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
229
  hspi1.Init.CRCPolynomial = 10;
230
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
231
  {
232
    Error_Handler();
233
  }
234
  /* USER CODE BEGIN SPI1_Init 2 */
235
 
236
  /* USER CODE END SPI1_Init 2 */
237
}
238
 
239
/**
4 mjames 240
 * @brief GPIO Initialization Function
241
 * @param None
242
 * @retval None
243
 */
2 mjames 244
static void MX_GPIO_Init(void)
245
{
246
  GPIO_InitTypeDef GPIO_InitStruct = {0};
247
 
248
  /* GPIO Ports Clock Enable */
249
  __HAL_RCC_GPIOD_CLK_ENABLE();
250
  __HAL_RCC_GPIOA_CLK_ENABLE();
251
  __HAL_RCC_GPIOB_CLK_ENABLE();
252
 
253
  /*Configure GPIO pin Output Level */
4 mjames 254
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | SPI_RESET_Pin, GPIO_PIN_RESET);
2 mjames 255
 
256
  /*Configure GPIO pin Output Level */
257
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
258
 
259
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */
4 mjames 260
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_RESET_Pin;
2 mjames 261
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
262
  GPIO_InitStruct.Pull = GPIO_NOPULL;
263
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
264
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
265
 
266
  /*Configure GPIO pin : SPI_CD_Pin */
267
  GPIO_InitStruct.Pin = SPI_CD_Pin;
268
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
269
  GPIO_InitStruct.Pull = GPIO_NOPULL;
270
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
271
  HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct);
272
}
273
 
274
/* USER CODE BEGIN 4 */
275
 
276
/* USER CODE END 4 */
277
 
278
/**
4 mjames 279
 * @brief  This function is executed in case of error occurrence.
280
 * @retval None
281
 */
2 mjames 282
void Error_Handler(void)
283
{
284
  /* USER CODE BEGIN Error_Handler_Debug */
285
  /* User can add his own implementation to report the HAL error return state */
286
  __disable_irq();
287
  while (1)
288
  {
289
  }
290
  /* USER CODE END Error_Handler_Debug */
291
}
292
 
4 mjames 293
#ifdef USE_FULL_ASSERT
2 mjames 294
/**
4 mjames 295
 * @brief  Reports the name of the source file and the source line number
296
 *         where the assert_param error has occurred.
297
 * @param  file: pointer to the source file name
298
 * @param  line: assert_param error line source number
299
 * @retval None
300
 */
2 mjames 301
void assert_failed(uint8_t *file, uint32_t line)
302
{
303
  /* USER CODE BEGIN 6 */
304
  /* User can add his own implementation to report the file name and line number,
305
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
306
  /* USER CODE END 6 */
307
}
308
#endif /* USE_FULL_ASSERT */