Mercurial > public > ostc4
comparison Small_CPU/Src/externalInterface.c @ 696:cc542448fb28
Merge
author | heinrichsweikamp |
---|---|
date | Fri, 19 Aug 2022 11:30:24 +0200 |
parents | 52d68cf9994c |
children | f1b40364b0af |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 696:cc542448fb28 |
---|---|
25 | 25 |
26 #include <math.h> | 26 #include <math.h> |
27 #include "i2c.h" | 27 #include "i2c.h" |
28 #include "externalInterface.h" | 28 #include "externalInterface.h" |
29 #include "scheduler.h" | 29 #include "scheduler.h" |
30 #include "uart.h" | |
31 #include "data_exchange.h" | |
30 | 32 |
31 extern SGlobal global; | 33 extern SGlobal global; |
34 extern UART_HandleTypeDef huart1; | |
32 | 35 |
33 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ | 36 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ |
34 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ | 37 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ |
35 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ | 38 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ |
36 | 39 |
50 static uint8_t recBuf[ADC_ANSWER_LENGTH]; | 53 static uint8_t recBuf[ADC_ANSWER_LENGTH]; |
51 static uint8_t timeoutCnt = 0; | 54 static uint8_t timeoutCnt = 0; |
52 static uint8_t externalInterfacePresent = 0; | 55 static uint8_t externalInterfacePresent = 0; |
53 | 56 |
54 float externalChannel_mV[MAX_ADC_CHANNEL]; | 57 float externalChannel_mV[MAX_ADC_CHANNEL]; |
58 static uint8_t externalV33_On = 0; | |
59 static uint8_t externalADC_On = 0; | |
60 static uint16_t externalCO2Value; | |
61 static uint16_t externalCO2SignalStrength; | |
62 static uint16_t externalCO2Status = 0; | |
55 | 63 |
56 | 64 |
57 void externalInterface_Init(void) | 65 void externalInterface_Init(void) |
58 { | 66 { |
59 activeChannel = 0; | 67 activeChannel = 0; |
63 { | 71 { |
64 externalInterfacePresent = 1; | 72 externalInterfacePresent = 1; |
65 global.deviceDataSendToMaster.hw_Info.extADC = 1; | 73 global.deviceDataSendToMaster.hw_Info.extADC = 1; |
66 } | 74 } |
67 global.deviceDataSendToMaster.hw_Info.checkADC = 1; | 75 global.deviceDataSendToMaster.hw_Info.checkADC = 1; |
76 | |
77 /* init data values */ | |
78 externalV33_On = 0; | |
79 externalCO2Value = 0; | |
80 externalCO2SignalStrength = 0; | |
81 externalCO2Status = 0; | |
68 } | 82 } |
69 | 83 |
70 | 84 |
71 uint8_t externalInterface_StartConversion(uint8_t channel) | 85 uint8_t externalInterface_StartConversion(uint8_t channel) |
72 { | 86 { |
166 { | 180 { |
167 retval = externalChannel_mV[channel]; | 181 retval = externalChannel_mV[channel]; |
168 } | 182 } |
169 return retval; | 183 return retval; |
170 } | 184 } |
185 | |
186 uint8_t setExternalInterfaceChannel(uint8_t channel, float value) | |
187 { | |
188 uint8_t retval = 0; | |
189 | |
190 if(channel < MAX_ADC_CHANNEL) | |
191 { | |
192 externalChannel_mV[channel] = value; | |
193 retval = 1; | |
194 } | |
195 return retval; | |
196 } | |
197 | |
198 void externalInterface_InitPower33(void) | |
199 { | |
200 GPIO_InitTypeDef GPIO_InitStructure; | |
201 | |
202 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
203 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
204 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
205 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
206 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); | |
207 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
208 } | |
209 | |
210 | |
211 uint8_t externalInterface_isEnabledPower33() | |
212 { | |
213 return externalV33_On; | |
214 } | |
215 | |
216 uint8_t externalInterface_isEnabledADC() | |
217 { | |
218 return externalADC_On; | |
219 } | |
220 | |
221 void externalInterface_SwitchPower33(uint8_t state) | |
222 { | |
223 if(state != externalV33_On) | |
224 { | |
225 if(state) | |
226 { | |
227 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | |
228 externalV33_On = 1; | |
229 MX_USART1_UART_Init(); | |
230 } | |
231 else | |
232 { | |
233 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
234 externalV33_On = 0; | |
235 externalInterface_SetCO2Value(0); | |
236 externalInterface_SetCO2SignalStrength(0); | |
237 MX_USART1_UART_DeInit(); | |
238 } | |
239 } | |
240 } | |
241 void externalInterface_SwitchADC(uint8_t state) | |
242 { | |
243 if((state) && (externalInterfacePresent)) | |
244 { | |
245 externalInterface_StartConversion(activeChannel); | |
246 externalADC_On = 1; | |
247 } | |
248 else | |
249 { | |
250 externalADC_On = 0; | |
251 } | |
252 } | |
253 | |
254 void externalInterface_SetCO2Value(uint16_t CO2_ppm) | |
255 { | |
256 externalCO2Value = CO2_ppm; | |
257 } | |
258 | |
259 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa) | |
260 { | |
261 externalCO2SignalStrength = LED_qa; | |
262 } | |
263 | |
264 uint16_t externalInterface_GetCO2Value(void) | |
265 { | |
266 return externalCO2Value; | |
267 } | |
268 | |
269 uint16_t externalInterface_GetCO2SignalStrength(void) | |
270 { | |
271 return externalCO2SignalStrength; | |
272 } | |
273 | |
274 | |
275 void externalInterface_SetCO2State(uint16_t state) | |
276 { | |
277 externalCO2Status = state; | |
278 } | |
279 | |
280 uint16_t externalInterface_GetCO2State(void) | |
281 { | |
282 return externalCO2Status; | |
283 } | |
284 | |
285 void externalInterface_ExecuteCmd(uint16_t Cmd) | |
286 { | |
287 char cmdString[10]; | |
288 uint8_t cmdLength = 0; | |
289 | |
290 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ | |
291 { | |
292 case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n"); | |
293 break; | |
294 default: | |
295 break; | |
296 } | |
297 if(cmdLength != 0) | |
298 { | |
299 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10); | |
300 } | |
301 return; | |
302 } | |
303 |