Mercurial > public > ostc4
comparison Small_CPU/Src/i2c.c @ 239:e4207f0aaa4b div-fixes-5
cleanup: factor out dataSendToSlaveStopEval
The global dataSendToSlaveStopEval was set all over the place, but never
tested, so useless to set it. And remove an unused piece of code. Trivial
cleanup.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Mon, 08 Apr 2019 10:35:29 +0200 |
parents | a9d798e8c11f |
children | 2b9775f71e30 |
comparison
equal
deleted
inserted
replaced
238:a9d798e8c11f | 239:e4207f0aaa4b |
---|---|
66 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; | 66 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; |
67 I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; | 67 I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; |
68 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; | 68 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; |
69 I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; | 69 I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; |
70 I2cHandle.Init.OwnAddress1 = 0x01; | 70 I2cHandle.Init.OwnAddress1 = 0x01; |
71 | |
72 global.dataSendToSlaveStopEval = 1; | |
73 | 71 |
74 global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); | 72 global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); |
75 HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED); | 73 HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED); |
76 HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F); | 74 HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F); |
77 | 75 |
78 | |
79 | |
80 global.dataSendToSlaveStopEval = 0; | |
81 if(global.dataSendToSlavePending) | 76 if(global.dataSendToSlavePending) |
82 { | 77 { |
83 scheduleSpecial_Evaluate_DataSendToSlave(); | 78 scheduleSpecial_Evaluate_DataSendToSlave(); |
84 } | 79 } |
85 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | 80 return (HAL_StatusTypeDef)global.I2C_SystemStatus; |
89 void I2C_DeInit(void) | 84 void I2C_DeInit(void) |
90 { | 85 { |
91 HAL_I2C_DeInit(&I2cHandle); | 86 HAL_I2C_DeInit(&I2cHandle); |
92 } | 87 } |
93 | 88 |
94 | 89 static uint8_t i2c_errors = 0; |
95 uint8_t i2c_errors = 0; | |
96 | 90 |
97 void I2C_Error_count(void) | 91 void I2C_Error_count(void) |
98 { | 92 { |
99 i2c_errors++; | 93 i2c_errors++; |
100 } | 94 } |
101 | 95 |
102 //TODO: not used, remove | |
103 HAL_StatusTypeDef I2C_Master_TransmitNoStop( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | |
104 { | |
105 if(global.I2C_SystemStatus != HAL_OK) | |
106 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | |
107 | |
108 global.dataSendToSlaveStopEval = 1; | |
109 | |
110 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 0); | |
111 if(global.I2C_SystemStatus != HAL_OK) | |
112 { | |
113 I2C_Error_count(); | |
114 } | |
115 global.dataSendToSlaveStopEval = 0; | |
116 //TODO: REMOVE. | |
117 // if(global.dataSendToSlavePending) | |
118 // { | |
119 // scheduleSpecial_Evaluate_DataSendToSlave(); | |
120 // } | |
121 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | |
122 } | |
123 | |
124 | |
125 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | 96 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) |
126 { | 97 { |
127 if(global.I2C_SystemStatus != HAL_OK) | 98 if(global.I2C_SystemStatus != HAL_OK) |
128 return global.I2C_SystemStatus; | 99 return global.I2C_SystemStatus; |
129 | |
130 global.dataSendToSlaveStopEval = 1; | |
131 | 100 |
132 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 2); | 101 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 2); |
133 if(global.I2C_SystemStatus != HAL_OK) | 102 if(global.I2C_SystemStatus != HAL_OK) |
134 { | 103 { |
135 I2C_Error_count(); | 104 I2C_Error_count(); |
136 } | 105 } |
137 | |
138 global.dataSendToSlaveStopEval = 0; | |
139 | 106 |
140 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | 107 return (HAL_StatusTypeDef)global.I2C_SystemStatus; |
141 } | 108 } |
142 | 109 |
143 // TODO: return value never used | 110 // TODO: return value never used |
144 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | 111 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size) |
145 { | 112 { |
146 if(global.I2C_SystemStatus != HAL_OK) | 113 if(global.I2C_SystemStatus != HAL_OK) |
147 return global.I2C_SystemStatus; | 114 return global.I2C_SystemStatus; |
148 | 115 |
149 global.dataSendToSlaveStopEval = 1; | |
150 | |
151 global.I2C_SystemStatus = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); | 116 global.I2C_SystemStatus = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); |
152 if(global.I2C_SystemStatus != HAL_OK) | 117 if(global.I2C_SystemStatus != HAL_OK) |
153 { | 118 { |
154 I2C_Error_count(); | 119 I2C_Error_count(); |
155 } | 120 } |
156 | 121 |
157 global.dataSendToSlaveStopEval = 0; | |
158 | |
159 return global.I2C_SystemStatus; | 122 return global.I2C_SystemStatus; |
160 } | 123 } |
161 |