Mercurial > public > ostc4
comparison Small_CPU/Src/externalInterface.c @ 662:1b995079c045 Betatest
PSCR Mode
author | heinrichs weikamp |
---|---|
date | Tue, 14 Dec 2021 15:36:10 +0100 |
parents | 011d8f9f5ddb |
children | 52d68cf9994c |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 662:1b995079c045 |
---|---|
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 uint16_t externalCO2Value; | |
60 static uint16_t externalCO2SignalStrength; | |
61 static uint16_t externalCO2Status = 0; | |
55 | 62 |
56 | 63 |
57 void externalInterface_Init(void) | 64 void externalInterface_Init(void) |
58 { | 65 { |
59 activeChannel = 0; | 66 activeChannel = 0; |
63 { | 70 { |
64 externalInterfacePresent = 1; | 71 externalInterfacePresent = 1; |
65 global.deviceDataSendToMaster.hw_Info.extADC = 1; | 72 global.deviceDataSendToMaster.hw_Info.extADC = 1; |
66 } | 73 } |
67 global.deviceDataSendToMaster.hw_Info.checkADC = 1; | 74 global.deviceDataSendToMaster.hw_Info.checkADC = 1; |
75 | |
76 /* init data values */ | |
77 externalV33_On = 0; | |
78 externalCO2Value = 0; | |
79 externalCO2SignalStrength = 0; | |
80 externalCO2Status = 0; | |
68 } | 81 } |
69 | 82 |
70 | 83 |
71 uint8_t externalInterface_StartConversion(uint8_t channel) | 84 uint8_t externalInterface_StartConversion(uint8_t channel) |
72 { | 85 { |
166 { | 179 { |
167 retval = externalChannel_mV[channel]; | 180 retval = externalChannel_mV[channel]; |
168 } | 181 } |
169 return retval; | 182 return retval; |
170 } | 183 } |
184 | |
185 void externalInterface_InitPower33(void) | |
186 { | |
187 GPIO_InitTypeDef GPIO_InitStructure; | |
188 | |
189 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
190 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
191 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
192 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
193 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); | |
194 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
195 } | |
196 | |
197 | |
198 uint8_t externalInterface_isEnabledPower33() | |
199 { | |
200 return externalV33_On; | |
201 } | |
202 void externalInterface_SwitchPower33(uint8_t state) | |
203 { | |
204 if(state != externalV33_On) | |
205 { | |
206 if(state) | |
207 { | |
208 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | |
209 externalV33_On = 1; | |
210 MX_USART1_UART_Init(); | |
211 } | |
212 else | |
213 { | |
214 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
215 externalV33_On = 0; | |
216 externalInterface_SetCO2Value(0); | |
217 externalInterface_SetCO2SignalStrength(0); | |
218 MX_USART1_UART_DeInit(); | |
219 } | |
220 } | |
221 } | |
222 | |
223 void externalInterface_SetCO2Value(uint16_t CO2_ppm) | |
224 { | |
225 externalCO2Value = CO2_ppm; | |
226 } | |
227 | |
228 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa) | |
229 { | |
230 externalCO2SignalStrength = LED_qa; | |
231 } | |
232 | |
233 uint16_t externalInterface_GetCO2Value(void) | |
234 { | |
235 return externalCO2Value; | |
236 } | |
237 | |
238 uint16_t externalInterface_GetCO2SignalStrength(void) | |
239 { | |
240 return externalCO2SignalStrength; | |
241 } | |
242 | |
243 | |
244 void externalInterface_SetCO2State(uint16_t state) | |
245 { | |
246 externalCO2Status = state; | |
247 } | |
248 | |
249 uint16_t externalInterface_GetCO2State(void) | |
250 { | |
251 return externalCO2Status; | |
252 } | |
253 | |
254 void externalInterface_ExecuteCmd(uint16_t Cmd) | |
255 { | |
256 char cmdString[10]; | |
257 uint8_t cmdLength = 0; | |
258 | |
259 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ | |
260 { | |
261 case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n"); | |
262 break; | |
263 default: | |
264 break; | |
265 } | |
266 if(cmdLength != 0) | |
267 { | |
268 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10); | |
269 } | |
270 return; | |
271 } | |
272 |