Mercurial > public > ostc4
comparison Small_CPU/Src/externalInterface.c @ 704:f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
The code has been modified to support the handling of several protocols (including baud rate changes). The data is requested by polling and passed via DMA into a ringbuffer which is then parsed by a cyclic function call in the main loop. At the moment only the O2 values are forwarded but because the sensor send several types of data within a signle message already more is extracted but yet discarded.
| author | Ideenmodellierer |
|---|---|
| date | Fri, 28 Oct 2022 20:49:21 +0200 |
| parents | 52d68cf9994c |
| children | 045ff7800501 |
comparison
equal
deleted
inserted
replaced
| 703:2f457024049b | 704:f1b40364b0af |
|---|---|
| 55 static uint8_t externalInterfacePresent = 0; | 55 static uint8_t externalInterfacePresent = 0; |
| 56 | 56 |
| 57 float externalChannel_mV[MAX_ADC_CHANNEL]; | 57 float externalChannel_mV[MAX_ADC_CHANNEL]; |
| 58 static uint8_t externalV33_On = 0; | 58 static uint8_t externalV33_On = 0; |
| 59 static uint8_t externalADC_On = 0; | 59 static uint8_t externalADC_On = 0; |
| 60 static uint8_t externalUART_Protocol = 0; | |
| 60 static uint16_t externalCO2Value; | 61 static uint16_t externalCO2Value; |
| 61 static uint16_t externalCO2SignalStrength; | 62 static uint16_t externalCO2SignalStrength; |
| 62 static uint16_t externalCO2Status = 0; | 63 static uint16_t externalCO2Status = 0; |
| 63 | 64 |
| 64 | 65 |
| 109 { | 110 { |
| 110 retval = activeChannel; /* return channel number providing new data */ | 111 retval = activeChannel; /* return channel number providing new data */ |
| 111 activeChannel++; | 112 activeChannel++; |
| 112 if(activeChannel == MAX_ADC_CHANNEL) | 113 if(activeChannel == MAX_ADC_CHANNEL) |
| 113 { | 114 { |
| 114 activeChannel = 0; | 115 if(externalUART_Protocol == (EXT_INTERFACE_UART_O2 >> 8)) /* mixed mode digital and analog o2 sensors => channel 0 is reserved for digital sensor */ |
| 116 { | |
| 117 activeChannel = 1; | |
| 118 } | |
| 119 else | |
| 120 { | |
| 121 activeChannel = 0; | |
| 122 } | |
| 115 } | 123 } |
| 116 externalInterface_StartConversion(activeChannel); | 124 externalInterface_StartConversion(activeChannel); |
| 117 timeoutCnt = 0; | 125 timeoutCnt = 0; |
| 118 } | 126 } |
| 119 else | 127 else |
| 216 uint8_t externalInterface_isEnabledADC() | 224 uint8_t externalInterface_isEnabledADC() |
| 217 { | 225 { |
| 218 return externalADC_On; | 226 return externalADC_On; |
| 219 } | 227 } |
| 220 | 228 |
| 229 uint8_t externalInterface_GetUARTProtocol() | |
| 230 { | |
| 231 return externalUART_Protocol; | |
| 232 } | |
| 233 | |
| 221 void externalInterface_SwitchPower33(uint8_t state) | 234 void externalInterface_SwitchPower33(uint8_t state) |
| 222 { | 235 { |
| 223 if(state != externalV33_On) | 236 if(state != externalV33_On) |
| 224 { | 237 { |
| 225 if(state) | 238 if(state) |
| 226 { | 239 { |
| 227 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | 240 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); |
| 228 externalV33_On = 1; | 241 externalV33_On = 1; |
| 229 MX_USART1_UART_Init(); | |
| 230 } | 242 } |
| 231 else | 243 else |
| 232 { | 244 { |
| 233 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | 245 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); |
| 234 externalV33_On = 0; | 246 externalV33_On = 0; |
| 235 externalInterface_SetCO2Value(0); | 247 externalInterface_SetCO2Value(0); |
| 236 externalInterface_SetCO2SignalStrength(0); | 248 externalInterface_SetCO2SignalStrength(0); |
| 237 MX_USART1_UART_DeInit(); | |
| 238 } | 249 } |
| 239 } | 250 } |
| 240 } | 251 } |
| 241 void externalInterface_SwitchADC(uint8_t state) | 252 void externalInterface_SwitchADC(uint8_t state) |
| 242 { | 253 { |
| 246 externalADC_On = 1; | 257 externalADC_On = 1; |
| 247 } | 258 } |
| 248 else | 259 else |
| 249 { | 260 { |
| 250 externalADC_On = 0; | 261 externalADC_On = 0; |
| 262 } | |
| 263 } | |
| 264 | |
| 265 void externalInterface_SwitchUART(uint8_t protocol) | |
| 266 { | |
| 267 if(protocol < 0x08) | |
| 268 { | |
| 269 externalUART_Protocol = protocol; | |
| 270 MX_USART1_UART_DeInit(); | |
| 271 if( protocol != 0) | |
| 272 { | |
| 273 MX_USART1_UART_Init(); | |
| 274 } | |
| 251 } | 275 } |
| 252 } | 276 } |
| 253 | 277 |
| 254 void externalInterface_SetCO2Value(uint16_t CO2_ppm) | 278 void externalInterface_SetCO2Value(uint16_t CO2_ppm) |
| 255 { | 279 { |
