changeset 241:2b9775f71e30 div-fixes-5

cleanup: factor out I2C1_Status() and cleanup type Having a function that returns global data is rather useless. Further, use HAL_StatusTypeDef directly, instead of typecasting between a HAL defined enum and our uint_8t. Cleanup only. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 08 Apr 2019 11:18:40 +0200
parents 625d20070261
children b23de15e2861
files Small_CPU/Inc/scheduler.h Small_CPU/Src/i2c.c Small_CPU/Src/pressure.c
diffstat 3 files changed, 6 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/scheduler.h	Mon Apr 08 11:49:13 2019 +0200
+++ b/Small_CPU/Inc/scheduler.h	Mon Apr 08 11:18:40 2019 +0200
@@ -69,7 +69,7 @@
 	uint8_t accidentFlag;
 	uint32_t accidentRemainingSeconds;
 	uint8_t sensorError[MAX_SENSORS];
-	uint8_t I2C_SystemStatus;
+	HAL_StatusTypeDef I2C_SystemStatus;
 } SGlobal;
 
 typedef struct
--- a/Small_CPU/Src/i2c.c	Mon Apr 08 11:49:13 2019 +0200
+++ b/Small_CPU/Src/i2c.c	Mon Apr 08 11:18:40 2019 +0200
@@ -23,13 +23,6 @@
 }
 */
 
-//TODO: remove this function. Why return a global variable?
-HAL_StatusTypeDef I2C1_Status(void)
-{
-return (HAL_StatusTypeDef)global.I2C_SystemStatus;
-}
-
-
 GPIO_PinState HAL_I2C_Read_Data_PIN(void)
 {
 	return HAL_GPIO_ReadPin(I2Cx_SDA_GPIO_PORT,I2Cx_SDA_PIN);
@@ -57,7 +50,6 @@
 	return HAL_I2C_Read_Data_PIN();
 }
 
-//TODO: make this void. return is never used
 HAL_StatusTypeDef MX_I2C1_Init(void)
 {
 	I2cHandle.Instance             = I2Cx;
@@ -77,7 +69,7 @@
 	{
 		scheduleSpecial_Evaluate_DataSendToSlave();
 	}
-	return (HAL_StatusTypeDef)global.I2C_SystemStatus;
+	return global.I2C_SystemStatus;
 }
 
 
@@ -104,10 +96,9 @@
 		I2C_Error_count();
 	}
 	
-	return (HAL_StatusTypeDef)global.I2C_SystemStatus;
+	return global.I2C_SystemStatus;
 }
 
-// TODO: return value never used
 HAL_StatusTypeDef I2C_Master_Receive(  uint16_t DevAddress, uint8_t *pData, uint16_t Size)
 {
 	if(global.I2C_SystemStatus != HAL_OK)
--- a/Small_CPU/Src/pressure.c	Mon Apr 08 11:49:13 2019 +0200
+++ b/Small_CPU/Src/pressure.c	Mon Apr 08 11:18:40 2019 +0200
@@ -29,7 +29,7 @@
  at the beginning of a dive the oldest value will be used
 */
 
-
+#include "scheduler.h"
 #include "pressure.h"
 #include "i2c.h"
 #include "rtc.h"
@@ -261,7 +261,7 @@
 	C2_x_2p16 = C[2] * 65536;
 	C1_x_2p15 = C[1] * 32768;
 	
-	if(I2C1_Status() == HAL_OK)
+	if(global.I2C_SystemStatus == HAL_OK)
 	{
 		pressureSensorInitSuccess = 1;
 	}
@@ -360,7 +360,7 @@
 
 void pressure_calculation(void)
 {
-	if(I2C1_Status() != HAL_OK)
+	if(global.I2C_SystemStatus != HAL_OK)
 		return;
 	
 	pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015();