comparison Small_CPU/Src/i2c.c @ 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 e4207f0aaa4b
children 4fe5400567e7
comparison
equal deleted inserted replaced
240:625d20070261 241:2b9775f71e30
20 while(1) 20 while(1)
21 { 21 {
22 } 22 }
23 } 23 }
24 */ 24 */
25
26 //TODO: remove this function. Why return a global variable?
27 HAL_StatusTypeDef I2C1_Status(void)
28 {
29 return (HAL_StatusTypeDef)global.I2C_SystemStatus;
30 }
31
32 25
33 GPIO_PinState HAL_I2C_Read_Data_PIN(void) 26 GPIO_PinState HAL_I2C_Read_Data_PIN(void)
34 { 27 {
35 return HAL_GPIO_ReadPin(I2Cx_SDA_GPIO_PORT,I2Cx_SDA_PIN); 28 return HAL_GPIO_ReadPin(I2Cx_SDA_GPIO_PORT,I2Cx_SDA_PIN);
36 } 29 }
55 break; 48 break;
56 } 49 }
57 return HAL_I2C_Read_Data_PIN(); 50 return HAL_I2C_Read_Data_PIN();
58 } 51 }
59 52
60 //TODO: make this void. return is never used
61 HAL_StatusTypeDef MX_I2C1_Init(void) 53 HAL_StatusTypeDef MX_I2C1_Init(void)
62 { 54 {
63 I2cHandle.Instance = I2Cx; 55 I2cHandle.Instance = I2Cx;
64 I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; 56 I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
65 I2cHandle.Init.ClockSpeed = 100000;//400000; REDUCED for compatibility with HMC5583L + MMA8452Q 57 I2cHandle.Init.ClockSpeed = 100000;//400000; REDUCED for compatibility with HMC5583L + MMA8452Q
75 67
76 if(global.dataSendToSlavePending) 68 if(global.dataSendToSlavePending)
77 { 69 {
78 scheduleSpecial_Evaluate_DataSendToSlave(); 70 scheduleSpecial_Evaluate_DataSendToSlave();
79 } 71 }
80 return (HAL_StatusTypeDef)global.I2C_SystemStatus; 72 return global.I2C_SystemStatus;
81 } 73 }
82 74
83 75
84 void I2C_DeInit(void) 76 void I2C_DeInit(void)
85 { 77 {
102 if(global.I2C_SystemStatus != HAL_OK) 94 if(global.I2C_SystemStatus != HAL_OK)
103 { 95 {
104 I2C_Error_count(); 96 I2C_Error_count();
105 } 97 }
106 98
107 return (HAL_StatusTypeDef)global.I2C_SystemStatus; 99 return global.I2C_SystemStatus;
108 } 100 }
109 101
110 // TODO: return value never used
111 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size) 102 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size)
112 { 103 {
113 if(global.I2C_SystemStatus != HAL_OK) 104 if(global.I2C_SystemStatus != HAL_OK)
114 return global.I2C_SystemStatus; 105 return global.I2C_SystemStatus;
115 106