This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
1945 lines (1672 loc) · 62.6 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* USER CODE BEGIN Header */
/**
* Original work Copyright 2020, STMicroelectronics
* Modified work Copyright 2020, the Pez Globo team and the Pufferfish project
*contributors
*
******************************************************************************
* @file : main.cpp
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <functional>
#include "Pufferfish/AlarmsManager.h"
#include "Pufferfish/Application/AlarmMuteService.h"
#include "Pufferfish/Application/Alarms.h"
#include "Pufferfish/Application/LogEvents.h"
#include "Pufferfish/Application/States.h"
#include "Pufferfish/Application/mcu_pb.h" // Only used for debugging
#include "Pufferfish/Driver/BreathingCircuit/AlarmLimitsService.h"
#include "Pufferfish/Driver/BreathingCircuit/Alarms.h"
#include "Pufferfish/Driver/BreathingCircuit/AlarmsService.h"
#include "Pufferfish/Driver/BreathingCircuit/ControlLoop.h"
#include "Pufferfish/Driver/BreathingCircuit/ParametersService.h"
#include "Pufferfish/Driver/BreathingCircuit/SensorAlarmsService.h"
#include "Pufferfish/Driver/BreathingCircuit/SignalSmoothing.h"
#include "Pufferfish/Driver/BreathingCircuit/Simulator.h"
#include "Pufferfish/Driver/Button/Button.h"
#include "Pufferfish/Driver/I2C/ExtendedI2CDevice.h"
#include "Pufferfish/Driver/I2C/HoneywellABP/Device.h"
#include "Pufferfish/Driver/I2C/HoneywellABP/Sensor.h"
#include "Pufferfish/Driver/I2C/LTC4015/Sensor.h"
#include "Pufferfish/Driver/I2C/SDP.h"
#include "Pufferfish/Driver/I2C/SFM3000.h"
#include "Pufferfish/Driver/I2C/SFM3019/Sensor.h"
#include "Pufferfish/Driver/I2C/TCA9548A.h"
#include "Pufferfish/Driver/Indicators/AuditoryAlarm.h"
#include "Pufferfish/Driver/Indicators/LEDAlarm.h"
#include "Pufferfish/Driver/Indicators/PulseGenerator.h"
#include "Pufferfish/Driver/Power/AlarmsService.h"
#include "Pufferfish/Driver/Power/Simulator.h"
#include "Pufferfish/Driver/Serial/Backend/AlarmsService.h"
#include "Pufferfish/Driver/Serial/Backend/UART.h"
#include "Pufferfish/Driver/Serial/FDO2/Sensor.h"
#include "Pufferfish/Driver/Serial/Nonin/Sensor.h"
#include "Pufferfish/Driver/Serial/Nonin/SensorAlarmService.h"
#include "Pufferfish/Driver/ShiftedOutput.h"
#include "Pufferfish/HAL/Endian.h"
#include "Pufferfish/HAL/STM32/HAL.h"
#include "Pufferfish/Statuses.h"
#include "Pufferfish/Util/Timeouts.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc3;
CRC_HandleTypeDef hcrc;
I2C_HandleTypeDef hi2c1;
I2C_HandleTypeDef hi2c2;
I2C_HandleTypeDef hi2c4;
RNG_HandleTypeDef hrng;
SPI_HandleTypeDef hspi1;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim4;
TIM_HandleTypeDef htim5;
TIM_HandleTypeDef htim8;
TIM_HandleTypeDef htim12;
UART_HandleTypeDef huart4;
UART_HandleTypeDef huart7;
UART_HandleTypeDef huart8;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart3;
/* USER CODE BEGIN PV */
namespace PF = Pufferfish;
// Application State
PF::Application::Store store;
// Event Logging
PF::Application::LogEventsSender log_events_sender;
PF::Application::LogEventsManager log_events_manager(log_events_sender);
// Request/Response Services
PF::Driver::BreathingCircuit::ParametersServices parameters_service;
PF::Driver::BreathingCircuit::AlarmLimitsServices alarm_limits_service;
// Breathing Circuit Simulation
PF::Driver::BreathingCircuit::Simulators simulator;
// HAL Utilities
PF::HAL::STM32::CRC32 crc32c(hcrc);
PF::HAL::STM32::Random rng(hrng);
// HAL Time
// Normally we'd call this variable "time", but it conflicts with a declaration from <ctime>,
// which is required by the Boost PFR library
PF::HAL::STM32::Time hal_time;
// Buffered UARTs
volatile Pufferfish::HAL::STM32::LargeBufferedUART backend_uart(huart3, hal_time);
volatile Pufferfish::HAL::STM32::LargeBufferedUART fdo2_uart(huart7, hal_time);
volatile Pufferfish::HAL::STM32::ReadOnlyBufferedUART nonin_oem_uart(huart4, hal_time);
// UART Serial Communication
PF::Driver::Serial::Backend::UARTBackend backend(backend_uart, crc32c, store, log_events_sender);
PF::Driver::Serial::Backend::AlarmsService backend_alarms;
// Create an object for ADC3 of AnalogInput Class
static const uint32_t adc_poll_timeout = 10;
PF::HAL::STM32::AnalogInput adc3_input(hadc3, adc_poll_timeout);
// The following lines suppress Eclipse CDT's warning about C-style casts;
// those come from STM32CubeMX-generated #define constants, which we have no
// control over
// Interface Board
PF::HAL::STM32::DigitalOutput ser_clock(
*SER_CLK_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SER_CLK_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalOutput ser_clear(
*SER_CLR_N_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SER_CLR_N_Pin, // @suppress("C-Style cast instead of C++ cast")
false);
PF::HAL::STM32::DigitalOutput ser_r_clock(
*SER_RCLK_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SER_RCLK_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalOutput ser_input(
*SER_IN_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SER_IN_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalOutput board_led1(
*LD1_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
LD1_Pin); // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
static const uint32_t flash_period = 50;
static const uint32_t blink_period = 500;
static const uint32_t dim_period = 8;
PF::Driver::Indicators::PWMGenerator flasher(flash_period, 1);
PF::Driver::Indicators::PWMGenerator blinker(blink_period, 1);
PF::Driver::Indicators::PWMGenerator dimmer(dim_period, 1);
PF::Driver::ShiftRegister leds_reg(ser_input, ser_clock, ser_r_clock, ser_clear, hal_time);
PF::Driver::ShiftedOutput alarm_led_r(leds_reg, 0);
PF::Driver::ShiftedOutput alarm_led_g(leds_reg, 1);
PF::Driver::ShiftedOutput alarm_led_b(leds_reg, 2);
PF::Driver::ShiftedOutput led_alarm_en(leds_reg, 3);
PF::Driver::ShiftedOutput led_full_o2(leds_reg, 4);
// NOLINTNEXTLINE(readability-magic-numbers)
PF::Driver::ShiftedOutput led_manual_breath(leds_reg, 5);
// NOLINTNEXTLINE(readability-magic-numbers)
PF::Driver::ShiftedOutput led_lock(leds_reg, 6);
PF::HAL::STM32::DigitalOutput alarm_reg_high(
*ALARM1_HIGH_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
ALARM1_HIGH_Pin); // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
PF::HAL::STM32::DigitalOutput alarm_reg_med(
*ALARM1_MED_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
ALARM1_MED_Pin); // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
PF::HAL::STM32::DigitalOutput alarm_reg_low(
*ALARM1_LOW_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
ALARM1_LOW_Pin); // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
PF::HAL::STM32::DigitalOutput alarm_buzzer(
*BUZZ1_EN_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
BUZZ1_EN_Pin); // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
PF::Driver::Indicators::LEDAlarm alarm_dev_led(alarm_led_r, alarm_led_g, alarm_led_b);
PF::Driver::Indicators::AuditoryAlarm alarm_dev_sound(
alarm_reg_high, alarm_reg_med, alarm_reg_low, alarm_buzzer);
// PF::AlarmsManager h_alarms(alarm_dev_led, alarm_dev_sound);
PF::HAL::STM32::DigitalInput button_alarm_en(
*SET_ALARM_EN_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SET_ALARM_EN_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalInput button_full_o2(
*SET_100_O2_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SET_100_O2_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalInput button_manual_breath(
*SET_MANUAL_BREATH_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SET_MANUAL_BREATH_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalInput button_lock(
*SET_LOCK_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SET_LOCK_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::HAL::STM32::DigitalInput button_power(
*SET_PWR_ON_OFF_GPIO_Port, // @suppress("C-Style cast instead of C++ cast") // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
SET_PWR_ON_OFF_Pin, // @suppress("C-Style cast instead of C++ cast")
true);
PF::Protocols::Application::Debouncer switch_debounce;
PF::Driver::Button::Button button_membrane(button_alarm_en, switch_debounce, hal_time);
// Solenoid Valves
PF::HAL::STM32::PWM drive1_ch1(htim2, TIM_CHANNEL_4);
PF::HAL::STM32::PWM drive1_ch2(htim2, TIM_CHANNEL_2);
PF::HAL::STM32::PWM drive1_ch3(htim3, TIM_CHANNEL_4);
PF::HAL::STM32::PWM drive1_ch4(htim3, TIM_CHANNEL_1);
PF::HAL::STM32::PWM drive1_ch5(htim3, TIM_CHANNEL_2);
PF::HAL::STM32::PWM drive1_ch6(htim3, TIM_CHANNEL_3);
PF::HAL::STM32::PWM drive1_ch7(htim4, TIM_CHANNEL_2);
PF::HAL::STM32::PWM drive2_ch1(htim4, TIM_CHANNEL_3);
PF::HAL::STM32::PWM drive2_ch2(htim4, TIM_CHANNEL_4);
PF::HAL::STM32::PWM drive2_ch3(htim5, TIM_CHANNEL_1);
PF::HAL::STM32::PWM drive2_ch4(htim8, TIM_CHANNEL_1);
PF::HAL::STM32::PWM drive2_ch5(htim8, TIM_CHANNEL_2);
PF::HAL::STM32::PWM drive2_ch6(htim8, TIM_CHANNEL_4);
PF::HAL::STM32::PWM drive2_ch7(htim12, TIM_CHANNEL_2);
// Base I2C Devices
// Note: I2C1 is marked I2C2 in the control board v1.0 schematic, and vice versa
/*PF::HAL::STM32::I2CDevice i2c_hal_mux1(hi2c2, PF::Driver::I2C::TCA9548A::default_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_mux2(hi2c1, PF::Driver::I2C::TCA9548A::default_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press1(hi2c1, PF::Driver::I2C::abpxxxx001pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press2(hi2c1, PF::Driver::I2C::abpxxxx001pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press3(hi2c1, PF::Driver::I2C::abpxxxx001pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press7(hi2c1, PF::Driver::I2C::abpxxxx030pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press8(hi2c1, PF::Driver::I2C::abpxxxx030pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press9(hi2c1, PF::Driver::I2C::abpxxxx001pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press13(hi2c2, PF::Driver::I2C::SDPSensor::sdp8xx_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press14(hi2c2, PF::Driver::I2C::SDPSensor::sdp3x_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press15(hi2c2, PF::Driver::I2C::SDPSensor::sdp3x_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press16(hi2c2, PF::Driver::I2C::SFM3000::default_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press17(hi2c2, PF::Driver::I2C::SDPSensor::sdp3x_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_press18(hi2c2, PF::Driver::I2C::SDPSensor::sdp3x_i2c_addr);*/
PF::HAL::STM32::I2CDevice i2c1_hal_global(hi2c1, 0x00);
PF::HAL::STM32::I2CDevice i2c2_hal_global(hi2c2, 0x00);
PF::HAL::STM32::I2CDevice i2c4_hal_global(hi2c4, 0x00);
PF::HAL::STM32::I2CDevice i2c_hal_abp(
hi2c1, PF::Driver::I2C::HoneywellABP::abpxxxx001pg2a3.i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_ltc4015(hi2c1, PF::Driver::I2C::LTC4015::device_addr);
PF::HAL::STM32::I2CDevice i2c_hal_sfm3019_air(hi2c2, PF::Driver::I2C::SFM3019::default_i2c_addr);
PF::HAL::STM32::I2CDevice i2c_hal_sfm3019_o2(hi2c4, PF::Driver::I2C::SFM3019::default_i2c_addr);
/*
// I2C Mux
PF::Driver::I2C::TCA9548A i2c_mux1(i2c_hal_mux1);
PF::Driver::I2C::TCA9548A i2c_mux2(i2c_hal_mux2);
// Extended I2C Device
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press1(i2c_hal_press1, i2c_mux2, 0);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press2(i2c_hal_press2, i2c_mux2, 2);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press3(i2c_hal_press3, i2c_mux2, 4);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press7(i2c_hal_press7, i2c_mux2, 1);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press8(i2c_hal_press8, i2c_mux2, 3);
// NOLINTNEXTLINE(readability-magic-numbers)
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press9(i2c_hal_press9, i2c_mux2, 5);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press13(i2c_hal_press13, i2c_mux1, 0);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press14(i2c_hal_press14, i2c_mux1, 2);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press15(i2c_hal_press15, i2c_mux1, 4);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press16(i2c_hal_press16, i2c_mux1, 1);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press17(i2c_hal_press17, i2c_mux1, 3);
PF::Driver::I2C::ExtendedI2CDevice i2c_ext_press18(
i2c_hal_press18,
i2c_mux1,
// NOLINTNEXTLINE(readability-magic-numbers)
5);
// Actual usable sensor
PF::Driver::I2C::HoneywellABP i2c_press1(i2c_ext_press1, PF::Driver::I2C::abpxxxx001pg2a3);
PF::Driver::I2C::HoneywellABP i2c_press2(i2c_ext_press2, PF::Driver::I2C::abpxxxx001pg2a3);
PF::Driver::I2C::HoneywellABP i2c_press3(i2c_ext_press3, PF::Driver::I2C::abpxxxx001pg2a3);
PF::Driver::I2C::HoneywellABP i2c_press7(i2c_ext_press7, PF::Driver::I2C::abpxxxx030pg2a3);
PF::Driver::I2C::HoneywellABP i2c_press8(i2c_ext_press8, PF::Driver::I2C::abpxxxx030pg2a3);
PF::Driver::I2C::HoneywellABP i2c_press9(i2c_ext_press9, PF::Driver::I2C::abpxxxx001pg2a3);
PF::Driver::I2C::SDPSensor i2c_press13(i2c_ext_press13);
PF::Driver::I2C::SDPSensor i2c_press14(i2c_ext_press14);
PF::Driver::I2C::SDPSensor i2c_press15(i2c_ext_press15);
PF::Driver::I2C::SFM3000 i2c_press16(i2c_ext_press16);
PF::Driver::I2C::SDPSensor i2c_press17(i2c_ext_press17);
PF::Driver::I2C::SDPSensor i2c_press18(i2c_ext_press18);
*/
// HoneyWell ABP
PF::Driver::I2C::HoneywellABP::Device abp_dev(
i2c_hal_abp, PF::Driver::I2C::HoneywellABP::abpxxxx001pg2a3);
PF::Driver::I2C::HoneywellABP::Sensor abp(abp_dev, hal_time);
// SFM3019
PF::Driver::I2C::SFM3019::Device sfm3019_dev_air(
i2c_hal_sfm3019_air, i2c2_hal_global, PF::Driver::I2C::SFM3019::GasType::air);
PF::Driver::I2C::SFM3019::Sensor sfm3019_air(sfm3019_dev_air, true, hal_time);
PF::Driver::I2C::SFM3019::Device sfm3019_dev_o2(
i2c_hal_sfm3019_o2, i2c4_hal_global, PF::Driver::I2C::SFM3019::GasType::o2);
PF::Driver::I2C::SFM3019::Sensor sfm3019_o2(sfm3019_dev_o2, true, hal_time);
// FDO2
PF::Driver::Serial::FDO2::Device fdo2_dev(fdo2_uart);
PF::Driver::Serial::FDO2::Sensor fdo2(fdo2_dev, hal_time);
// Nonin OEM III
PF::Driver::Serial::Nonin::Device nonin_oem_dev(nonin_oem_uart);
PF::Driver::Serial::Nonin::Sensor nonin_oem(nonin_oem_dev, hal_time);
// LTC4015
PF::Driver::I2C::LTC4015::Device ltc4015_dev(i2c_hal_ltc4015);
PF::Driver::I2C::LTC4015::Sensor ltc4015(ltc4015_dev);
// Power
PF::Driver::Power::Simulator power_simulator;
// Initializables
auto initializables =
PF::Driver::make_initializables(sfm3019_air, sfm3019_o2, abp, fdo2, nonin_oem, ltc4015);
/*
// Test list
// NOLINTNEXTLINE(readability-magic-numbers)
auto i2c_test_list = PF::Util::make_array<PF::Driver::Testable *>(
&i2c_mux1,
&i2c_mux2,
&i2c_press1,
&i2c_press2,
&i2c_press3,
&i2c_press7,
&i2c_press8,
&i2c_press9,
&i2c_press13,
&i2c_press14,
&i2c_press15,
&i2c_press16,
&i2c_press17,
&i2c_press18);
*/
int interface_test_state = 0;
int interface_test_millis = 0;
// Alarms
PF::Application::AlarmsManager alarms_manager(
log_events_manager,
PF::Driver::BreathingCircuit::debouncers,
PF::Driver::BreathingCircuit::init_waiters);
PF::Application::AlarmMuteService alarm_mute;
PF::Driver::BreathingCircuit::AlarmsServices breathing_circuit_alarms;
PF::Driver::Power::AlarmsService power_alarms;
// Breathing Circuit Control
PF::Driver::BreathingCircuit::HFNCControlLoop hfnc(
store.parameters(),
store.sensor_measurements_raw(),
sfm3019_air,
sfm3019_o2,
drive1_ch1,
drive1_ch2);
// Signal processing
PF::Driver::BreathingCircuit::SensorMeasurementsSmoothers sensor_smoothers;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_I2C1_Init(void);
static void MX_UART4_Init(void);
static void MX_ADC3_Init(void);
static void MX_CRC_Init(void);
static void MX_I2C2_Init(void);
static void MX_TIM2_Init(void);
static void MX_UART7_Init(void);
static void MX_UART8_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_I2C4_Init(void);
static void MX_TIM3_Init(void);
static void MX_TIM4_Init(void);
static void MX_TIM5_Init(void);
static void MX_TIM8_Init(void);
static void MX_TIM12_Init(void);
static void MX_RNG_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void initialize_states() {
// Parameters
PF::Application::Parameters parameters{};
PF::Application::StateSegment parameters_request{};
PF::Driver::BreathingCircuit::make_state_initializers(parameters_request, parameters);
store.parameters() = parameters;
store.input(parameters_request, true);
// Alarm Limits
PF::Application::AlarmLimits alarm_limits{};
PF::Application::StateSegment alarm_limits_request{};
PF::Driver::BreathingCircuit::make_state_initializers(alarm_limits_request, alarm_limits);
store.alarm_limits() = alarm_limits;
store.input(alarm_limits_request, true);
// Alarm Mute
PF::Application::AlarmMute alarm_mute{};
PF::Application::StateSegment alarm_mute_request{};
PF::Application::make_state_initializers(alarm_mute_request, alarm_mute);
store.alarm_mute() = alarm_mute;
store.input(alarm_mute_request, true);
}
void interface_test_loop() {
// get state of buttons
bool l_alarm_en = button_alarm_en.read();
bool l_o2 = button_full_o2.read();
bool l_manual = button_manual_breath.read();
bool l_lock = button_lock.read();
// bool l_power = button_power.read();
// simply write back
led_alarm_en.write(l_alarm_en);
led_full_o2.write(l_o2);
led_manual_breath.write(l_manual);
led_lock.write(l_lock);
// cycle though alarms
// if (!l_power) {
// hAlarms.clearAll();
// } else if (hal_time.millis() - interface_test_millis > 100) {
// hAlarms.add(PF::AlarmStatus::highPriority);
// interface_test_millis = hal_time.millis();
// if (interface_test_state) {
// interface_test_state--;
// hAlarms.add(static_cast<PF::AlarmStatus>(interface_test_state));
// } else {
// interface_test_state = static_cast<int>(PF::AlarmStatus::noAlarm);
// hAlarms.clearAll();
// }
// }
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/*
// FIXME: Added for testing
// Local variable to read ADC3 input
uint32_t adc3_data = 0;
PF::Driver::Button::EdgeState state;
bool mem_buttonstate = false;
static const uint32_t blink_low_delay = 5;
static const uint32_t loop_delay = 50;
*/
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SPI1_Init();
MX_I2C1_Init();
MX_UART4_Init();
MX_ADC3_Init();
MX_CRC_Init();
MX_I2C2_Init();
MX_TIM2_Init();
MX_UART7_Init();
MX_UART8_Init();
MX_USART1_UART_Init();
MX_USART3_UART_Init();
MX_I2C4_Init();
MX_TIM3_Init();
MX_TIM4_Init();
MX_TIM5_Init();
MX_TIM8_Init();
MX_TIM12_Init();
MX_RNG_Init();
/* USER CODE BEGIN 2 */
// Time
PF::HAL::STM32::Time::micros_delay_init();
/*
interface_test_millis = hal_time.millis();
// ADCs
adc3_input.start();
*/
// HAL utilities
rng.setup();
// UARTs
backend_uart.setup_irq();
fdo2_uart.setup_irq();
nonin_oem_uart.setup_irq();
// Hardware PWMs
drive1_ch1.start();
drive1_ch1.set_duty_cycle(0);
drive1_ch2.start();
drive1_ch2.set_duty_cycle(0);
// Software PWMs
blinker.start(hal_time.millis());
flasher.start(hal_time.millis());
dimmer.start(hal_time.millis());
// Request/response states
initialize_states();
// Log events sender
uint32_t session_id = 0;
rng.generate(session_id);
log_events_sender.setup(session_id);
rng.generate(session_id);
alarm_mute.setup(session_id);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
// Setup
static const uint32_t setup_indicator_duration = 2000;
PF::Util::MsTimer setup_indicator_timer(setup_indicator_duration);
board_led1.write(true);
while (true) {
initializables.setup();
if (initializables.setup_failed()) {
setup_indicator_timer.reset(hal_time.millis());
// Flash the LED rapidly to indicate failure
while (setup_indicator_timer.within_timeout(hal_time.millis())) {
flasher.input(hal_time.millis());
board_led1.write(flasher.output());
}
} else if (initializables.setup_in_progress()) {
board_led1.write(true);
} else { // All are done with setup and ok
break;
}
}
// Blink the LED somewhat slowly to indicate success
setup_indicator_timer.reset(hal_time.millis());
while (setup_indicator_timer.within_timeout(hal_time.millis())) {
blinker.input(hal_time.millis());
board_led1.write(blinker.output());
}
board_led1.write(false);
// Configure the simulators
PF::Driver::Serial::Nonin::SensorConnections sensor_connections{};
PF::Driver::BreathingCircuit::SensorStates breathing_circuit_sensor_states{};
uint32_t discard_i = 0;
float discard_f = 0;
breathing_circuit_sensor_states.sfm3019_air =
sfm3019_air.output(discard_f) == PF::InitializableState::ok;
breathing_circuit_sensor_states.sfm3019_o2 =
sfm3019_o2.output(discard_f) == PF::InitializableState::ok;
breathing_circuit_sensor_states.fdo2 = fdo2.output(discard_i) == PF::InitializableState::ok;
breathing_circuit_sensor_states.nonin_oem =
nonin_oem.output(sensor_connections, discard_f, discard_f) == PF::InitializableState::ok;
bool ltc4015_status = ltc4015.output(store.mcu_power_status()) == PF::InitializableState::ok;
// Reset nonin timer
nonin_oem.post_setup_reset();
// Normal loop
while (true) {
uint32_t current_time = hal_time.millis();
// Software PWM signals
flasher.input(hal_time.millis());
blinker.input(hal_time.millis());
dimmer.input(hal_time.millis());
// Clock updates
log_events_manager.update_time(current_time);
alarms_manager.update_time(current_time);
// Request/response services update
parameters_service.transform(
store.parameters_request(),
store.has_parameters_request(),
store.parameters(),
log_events_manager,
alarms_manager);
alarm_limits_service.transform(
store.parameters(),
store.alarm_limits_request(),
store.has_parameters_request() && store.has_alarm_limits_request(),
store.alarm_limits(),
log_events_manager);
// Independent Sensors
fdo2.output(hfnc.sensor_vars().po2);
auto nonin_status = nonin_oem.output(
sensor_connections,
store.sensor_measurements_raw().spo2,
store.sensor_measurements_raw().hr);
PF::Driver::Serial::Nonin::SensorAlarmsService::transform(
nonin_status, sensor_connections, alarms_manager);
// *temporary* should be used in the breathing circuit
abp.output(hfnc.sensor_vars().p_out_above_atm);
// Breathing Circuit Sensor Simulator
simulator.transform(
current_time,
store.parameters(),
hfnc.sensor_vars(),
breathing_circuit_sensor_states,
store.sensor_measurements_raw(),
store.cycle_measurements());
// Breathing Circuit Control Loop
hfnc.update(current_time);
sensor_smoothers.transform(
current_time, store.sensor_measurements_raw(), store.sensor_measurements_filtered());
breathing_circuit_alarms.transform(
store.parameters(),
store.alarm_limits(),
store.sensor_measurements_filtered(),
alarms_manager);
// Breathing Circuit Sensor Alarms
PF::Driver::BreathingCircuit::SensorAlarmsService::transform(
hfnc.sensor_connections(), alarms_manager);
// Power management
if (!ltc4015_status) {
power_simulator.transform(current_time, store.mcu_power_status());
} else {
ltc4015.output(store.mcu_power_status());
}
power_alarms.transform(store.mcu_power_status(), alarms_manager);
// Indicators for debugging
/*static constexpr float valve_opening_indicator_threshold = 0.00001;
if (hfnc.actuator_vars().valve_air_opening > valve_opening_indicator_threshold) {
board_led1.write(dimmer.output());
} else {
board_led1.write(false);
}*/
/*if (hfnc.sensor_vars().flow_o2 > 1 || hfnc.sensor_vars().flow_air > 1) {
board_led1.write(true);
} else if (hfnc.sensor_vars().flow_o2 < -1 || hfnc.sensor_vars().flow_air < -1) {
board_led1.write(dimmer.output());
} else {
board_led1.write(false);
}*/
// Alarms
alarms_manager.transform(store.active_log_events());
// TODO(lietk12): allow toggling alarm mute state with the hardware button, but only when
// both the backend and frontend are connected. This should use the
// alarm_mute.transform(current_time, bool, ...) method.
alarm_mute.transform(
current_time, store.alarm_mute_request(), store.alarm_mute(), log_events_manager);
if (!store.backend_connected()) {
alarm_mute.transform(
current_time,
false,
PF::Application::AlarmMuteSource_mcu_backend_loss,
store.alarm_mute(),
log_events_manager);
} else if (!store.backend_connections().has_mcu) {
// The MCU isn't able to send any data to the backend but the backend is able to send
// data to the MCU, so the MCU should also cancel any active alarm mute
alarm_mute.transform(
current_time,
false,
PF::Application::AlarmMuteSource_backend_mcu_loss,
store.alarm_mute(),
log_events_manager);
} else if (!store.backend_connections().has_frontend) {
alarm_mute.transform(
current_time,
false,
PF::Application::AlarmMuteSource_backend_frontend_loss,
store.alarm_mute(),
log_events_manager);
}
if (store.active_log_events().id_count > 0 && !store.alarm_mute().active) {
board_led1.write(true);
} else {
blinker.input(current_time);
board_led1.write(blinker.output());
}
// Backend Communication Protocol
backend.receive();
backend.update_clock(current_time);
backend.send();
store.backend_connected() = backend.connected();
backend_alarms.transform(store.backend_connected(), alarms_manager, log_events_manager);
/*
PF::AlarmManagerStatus stat = h_alarms.update(hal_time.millis());
if (stat != PF::AlarmManagerStatus::ok) {
Error_Handler();
}
board_led1.write(false);
hal_time.delay(blink_low_delay);
board_led1.write(true);
//interface_test_loop();
//leds_reg.update();
*/
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Macro to configure the PLL clock source
*/
__HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSE);
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI
|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 24;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_UART4
|RCC_PERIPHCLK_UART7|RCC_PERIPHCLK_USART1
|RCC_PERIPHCLK_UART8|RCC_PERIPHCLK_RNG
|RCC_PERIPHCLK_SPI1|RCC_PERIPHCLK_I2C2
|RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_I2C1
|RCC_PERIPHCLK_I2C4;
PeriphClkInitStruct.PLL2.PLL2M = 1;
PeriphClkInitStruct.PLL2.PLL2N = 19;
PeriphClkInitStruct.PLL2.PLL2P = 3;
PeriphClkInitStruct.PLL2.PLL2Q = 2;
PeriphClkInitStruct.PLL2.PLL2R = 2;
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL;
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
PeriphClkInitStruct.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1;
PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_D3PCLK1;
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief ADC3 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC3_Init(void)
{
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC3_Init 1 */
/* USER CODE END ADC3_Init 1 */
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc3.Init.Resolution = ADC_RESOLUTION_16B;
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc3.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc3.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC3_Init 2 */
/* USER CODE END ADC3_Init 2 */
}
/**
* @brief CRC Initialization Function
* @param None
* @retval None
*/
static void MX_CRC_Init(void)
{
/* USER CODE BEGIN CRC_Init 0 */
/* USER CODE END CRC_Init 0 */
/* USER CODE BEGIN CRC_Init 1 */
/* USER CODE END CRC_Init 1 */
hcrc.Instance = CRC;
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
hcrc.Init.GeneratingPolynomial = 517762881;
hcrc.Init.CRCLength = CRC_POLYLENGTH_32B;
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE;
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE;
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
if (HAL_CRC_Init(&hcrc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CRC_Init 2 */
/* USER CODE END CRC_Init 2 */
}
/**
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C1_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
/* USER CODE BEGIN I2C1_Init 1 */
/* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x00602173;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief I2C2 Initialization Function