1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
27
28
29
30
31
32
33
34
35
38
39
42
43
46
47
50
51
55
58
59
62
63
66
67
68
69
70
74
75
76
77
78
79
80
83
84
87
90
91
94
95
96
100
101
103
104
105
106
109
110
113
114
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
137
138
141
142
143
144
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
202
203
204
205
208
209
213
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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
326
327
328
329
330
331
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
360
361
362
363
364
365
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
395
396
397
398
399
400
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
455
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
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
565
566
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
593
597
598
599
600
601
602
606
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
634
638
642
646
650
654
658
659
660
661
662
665
666
667
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
740
741
742
743
744
745
746
747
752
753
754
760
761
762
763
764
765
766
767
768
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
823
824
825
826
833
837
838
842
843
844
845
846
847
848
849
850
851
852
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
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
939
944
945
949
954
955
959
963
964
967
968
969
970
971
972
975
979
980
983
986
987
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1016
1020
1021
1027
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1044
1045
1049
1053
1054
1057
1060
1061
1064
1067
1068
1069
1070
1071
1072
1075
1079
1080
1084
1089
1090
1096
1097
1098
1099
1100
1101
1102
1103
1104
1110
1111
1112
1116
1121
1122
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1140
1144
1145
1148
1151
1152
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1194
1198
1199
1200
1201
1204
1208
1209
1215
1216
1217
1218
1219
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1238
1239
1240
1241
1242
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1262
1266
1267
1268
1269
1272
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1302
1303
1304
1305
1306
1307
1308
1309
1310
1314
1315
1318
1319
1322
1323
1326
1327
/* ... */
/* ... */
#include "stm32446e_eval.h"
#if defined(USE_IOEXPANDER)
#include "stm32446e_eval_io.h"
#endif
/* ... */
/* ... */
/* ... */
/* ... */
typedef struct
{
__IO uint16_t REG;
__IO uint16_t RAM;
...}LCD_CONTROLLER_TypeDef;
/* ... */
/* ... */
/* ... */
#define __STM32446E_EVAL_BSP_VERSION_MAIN (0x02)
#define __STM32446E_EVAL_BSP_VERSION_SUB1 (0x01)
#define __STM32446E_EVAL_BSP_VERSION_SUB2 (0x02)
#define __STM32446E_EVAL_BSP_VERSION_RC (0x00)
#define __STM32446E_EVAL_BSP_VERSION ((__STM32446E_EVAL_BSP_VERSION_MAIN << 24)\
|(__STM32446E_EVAL_BSP_VERSION_SUB1 << 16)\
|(__STM32446E_EVAL_BSP_VERSION_SUB2 << 8 )\
|(__STM32446E_EVAL_BSP_VERSION_RC))...
#define FMC_BANK1_BASE ((uint32_t)(0x60000000 | 0x00000000))
#define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
#define FMC_BANK1 ((LCD_CONTROLLER_TypeDef *) FMC_BANK1_BASE)
8 defines
/* ... */
/* ... */
/* ... */
/* ... */
#if defined(USE_IOEXPANDER)
const uint32_t GPIO_PIN[LEDn] = {LED1_PIN,
LED2_PIN,
LED3_PIN,
LED4_PIN...};/* ... */
#else
const uint32_t GPIO_PIN[LEDn] = {LED1_PIN,
LED3_PIN...};/* ... */
#endif
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT,
TAMPER_BUTTON_GPIO_PORT,
KEY_BUTTON_GPIO_PORT...};
const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN,
TAMPER_BUTTON_PIN,
KEY_BUTTON_PIN...};
const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn,
TAMPER_BUTTON_EXTI_IRQn,
KEY_BUTTON_EXTI_IRQn...};
USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
const uint16_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
const uint16_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
static FMPI2C_HandleTypeDef hEvalI2c;
/* ... */
/* ... */
static void I2Cx_MspInit(void);
static void I2Cx_Init(void);
#if defined(USE_IOEXPANDER)
static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg);/* ... */
#endif
static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
static void I2Cx_Error(uint8_t Addr);
static void FMC_BANK1_WriteData(uint16_t Data);
static void FMC_BANK1_WriteReg(uint8_t Reg);
static uint16_t FMC_BANK1_ReadData(void);
static void FMC_BANK1_Init(void);
static void FMC_BANK1_MspInit(void);
#if defined(USE_IOEXPANDER)
void MFX_IO_Init(void);
void MFX_IO_DeInit(void);
void MFX_IO_ITConfig(void);
void MFX_IO_Delay(uint32_t Delay);
void MFX_IO_Write(uint16_t Addr, uint8_t Reg, uint8_t Value);
uint8_t MFX_IO_Read(uint16_t Addr, uint8_t Reg);
uint16_t MFX_IO_ReadMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
void MFX_IO_Wakeup(void);
void MFX_IO_EnableWakeupPin(void);/* ... */
#endif
void LCD_IO_Init(void);
void LCD_IO_WriteData(uint16_t Data);
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
void LCD_IO_WriteReg(uint8_t Reg);
uint16_t LCD_IO_ReadData(uint16_t Reg);
void AUDIO_IO_Init(void);
void AUDIO_IO_DeInit(void);
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
void AUDIO_IO_Delay(uint32_t Delay);
void CAMERA_IO_Init(void);
void CAMERA_Delay(uint32_t Delay);
void CAMERA_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
uint16_t CAMERA_IO_Read(uint8_t Addr, uint16_t Reg);
void EEPROM_IO_Init(void);
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
/* ... */
/* ... */
/* ... */
uint32_t BSP_GetVersion(void)
{
return __STM32446E_EVAL_BSP_VERSION;
}{ ... }
/* ... */
void BSP_LED_Init(Led_TypeDef Led)
{
#if !defined(USE_STM32446E_EVAL_REVA)
GPIO_InitTypeDef gpio_init_structure;
if ((Led == LED1) || (Led == LED3))
{
LEDx_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = GPIO_PIN[Led];
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(LEDx_GPIO_PORT, &gpio_init_structure);
HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_SET);
}if ((Led == LED1) || (Led == LED3)) { ... }
else
{
#endif
#if defined(USE_IOEXPANDER)
BSP_IO_Init();
BSP_IO_ConfigPin(GPIO_PIN[Led], IO_MODE_OUTPUT_PP_PU);
BSP_IO_WritePin(GPIO_PIN[Led], BSP_IO_PIN_SET);/* ... */
#endif
#if !defined(USE_STM32446E_EVAL_REVA)
}else { ... }
#endif
}{ ... }
/* ... */
void BSP_LED_DeInit(Led_TypeDef Led)
{
#if !defined(USE_STM32446E_EVAL_REVA)
GPIO_InitTypeDef gpio_init_structure;
if ((Led == LED1) || (Led == LED3))
{
HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_RESET);
gpio_init_structure.Pin = GPIO_PIN[Led];
HAL_GPIO_DeInit(LEDx_GPIO_PORT, gpio_init_structure.Pin);
}if ((Led == LED1) || (Led == LED3)) { ... }
else
{
#endif
#if defined(USE_IOEXPANDER)
BSP_IO_ConfigPin(GPIO_PIN[Led], IO_MODE_OFF);/* ... */
#endif
#if !defined(USE_STM32446E_EVAL_REVA)
}else { ... }
#endif
}{ ... }
/* ... */
void BSP_LED_On(Led_TypeDef Led)
{
#if !defined(USE_STM32446E_EVAL_REVA)
if ((Led == LED1) || (Led == LED3))
{
HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_RESET);
}if ((Led == LED1) || (Led == LED3)) { ... }
else
{
#endif
#if defined(USE_IOEXPANDER)
BSP_IO_WritePin(GPIO_PIN[Led], BSP_IO_PIN_RESET);/* ... */
#endif
#if !defined(USE_STM32446E_EVAL_REVA)
}else { ... }
#endif
}{ ... }
/* ... */
void BSP_LED_Off(Led_TypeDef Led)
{
#if !defined(USE_STM32446E_EVAL_REVA)
if ((Led == LED1) || (Led == LED3))
{
HAL_GPIO_WritePin(LEDx_GPIO_PORT, GPIO_PIN[Led], GPIO_PIN_SET);
}if ((Led == LED1) || (Led == LED3)) { ... }
else
{
#endif
#if defined(USE_IOEXPANDER)
BSP_IO_WritePin(GPIO_PIN[Led], BSP_IO_PIN_SET);/* ... */
#endif
#if !defined(USE_STM32446E_EVAL_REVA)
}else { ... }
#endif
}{ ... }
/* ... */
void BSP_LED_Toggle(Led_TypeDef Led)
{
#if !defined(USE_STM32446E_EVAL_REVA)
if ((Led == LED1) || (Led == LED3))
{
HAL_GPIO_TogglePin(LEDx_GPIO_PORT, GPIO_PIN[Led]);
}if ((Led == LED1) || (Led == LED3)) { ... }
else
{
#endif
#if defined(USE_IOEXPANDER)
BSP_IO_TogglePin(GPIO_PIN[Led]);/* ... */
#endif
#if !defined(USE_STM32446E_EVAL_REVA)
}else { ... }
#endif
}{ ... }
/* ... */
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
{
GPIO_InitTypeDef gpio_init_structure;
BUTTONx_GPIO_CLK_ENABLE(Button);
if(ButtonMode == BUTTON_MODE_GPIO)
{
gpio_init_structure.Pin = BUTTON_PIN[Button];
gpio_init_structure.Mode = GPIO_MODE_INPUT;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
}if (ButtonMode == BUTTON_MODE_GPIO) { ... }
if(ButtonMode == BUTTON_MODE_EXTI)
{
gpio_init_structure.Pin = BUTTON_PIN[Button];
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FAST;
if(Button != BUTTON_WAKEUP)
{
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
}if (Button != BUTTON_WAKEUP) { ... }
else
{
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
}else { ... }
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
}if (ButtonMode == BUTTON_MODE_EXTI) { ... }
}{ ... }
/* ... */
void BSP_PB_DeInit(Button_TypeDef Button)
{
GPIO_InitTypeDef gpio_init_structure;
gpio_init_structure.Pin = BUTTON_PIN[Button];
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
}{ ... }
/* ... */
uint32_t BSP_PB_GetState(Button_TypeDef Button)
{
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}{ ... }
/* ... */
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef gpio_init_structure;
EVAL_COMx_TX_GPIO_CLK_ENABLE(COM);
EVAL_COMx_RX_GPIO_CLK_ENABLE(COM);
EVAL_COMx_CLK_ENABLE(COM);
gpio_init_structure.Pin = COM_TX_PIN[COM];
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Speed = GPIO_SPEED_FAST;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Alternate = COM_TX_AF[COM];
HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure);
gpio_init_structure.Pin = COM_RX_PIN[COM];
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = COM_RX_AF[COM];
HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure);
huart->Instance = COM_USART[COM];
HAL_UART_Init(huart);
}{ ... }
/* ... */
void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart)
{
huart->Instance = COM_USART[COM];
HAL_UART_DeInit(huart);
EVAL_COMx_CLK_DISABLE(COM);
/* ... */
/* ... */
}{ ... }
#if defined(USE_IOEXPANDER)
/* ... */
uint8_t BSP_JOY_Init(JOYMode_TypeDef JoyMode)
{
uint8_t ret = 0;
ret = BSP_IO_Init();
if(JoyMode == JOY_MODE_EXTI)
{
BSP_IO_ConfigPin(JOY_ALL_PINS, IO_MODE_IT_FALLING_EDGE_PU);
}if (JoyMode == JOY_MODE_EXTI) { ... }
else
{
BSP_IO_ConfigPin(JOY_ALL_PINS, IO_MODE_INPUT_PU);
}else { ... }
return ret;
}{ ... }
/* ... */
void BSP_JOY_DeInit(void)
{
BSP_IO_ConfigPin(JOY_ALL_PINS, IO_MODE_OFF);
}{ ... }
/* ... */
JOYState_TypeDef BSP_JOY_GetState(void)
{
uint16_t pin_status = 0;
pin_status = BSP_IO_ReadPin(JOY_ALL_PINS);
if((pin_status & JOY_NONE_PIN) == JOY_NONE)
{
return(JOYState_TypeDef) JOY_NONE;
}if ((pin_status & JOY_NONE_PIN) == JOY_NONE) { ... }
else if(!(pin_status & JOY_SEL_PIN))
{
return(JOYState_TypeDef) JOY_SEL;
}else if (!(pin_status & JOY_SEL_PIN)) { ... }
else if(!(pin_status & JOY_DOWN_PIN))
{
return(JOYState_TypeDef) JOY_DOWN;
}else if (!(pin_status & JOY_DOWN_PIN)) { ... }
else if(!(pin_status & JOY_LEFT_PIN))
{
return(JOYState_TypeDef) JOY_LEFT;
}else if (!(pin_status & JOY_LEFT_PIN)) { ... }
else if(!(pin_status & JOY_RIGHT_PIN))
{
return(JOYState_TypeDef) JOY_RIGHT;
}else if (!(pin_status & JOY_RIGHT_PIN)) { ... }
else if(!(pin_status & JOY_UP_PIN))
{
return(JOYState_TypeDef) JOY_UP;
}else if (!(pin_status & JOY_UP_PIN)) { ... }
else
{
return(JOYState_TypeDef) JOY_NONE;
}else { ... }
}{ ... }
/* ... */#endif
/* ... */
/* ... */
static void I2Cx_MspInit(void)
{
GPIO_InitTypeDef gpio_init_structure;
EVAL_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = EVAL_I2Cx_SCL_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FAST;
gpio_init_structure.Alternate = EVAL_I2Cx_SCL_SDA_AF;
HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
gpio_init_structure.Pin = EVAL_I2Cx_SDA_PIN;
HAL_GPIO_Init(EVAL_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
EVAL_I2Cx_CLK_ENABLE();
EVAL_I2Cx_FORCE_RESET();
EVAL_I2Cx_RELEASE_RESET();
HAL_NVIC_SetPriority(EVAL_I2Cx_EV_IRQn, 0x05, 0);
HAL_NVIC_EnableIRQ(EVAL_I2Cx_EV_IRQn);
HAL_NVIC_SetPriority(EVAL_I2Cx_ER_IRQn, 0x05, 0);
HAL_NVIC_EnableIRQ(EVAL_I2Cx_ER_IRQn);
}{ ... }
/* ... */
static void I2Cx_Init(void)
{
if(HAL_FMPI2C_GetState(&hEvalI2c) == HAL_FMPI2C_STATE_RESET)
{
hEvalI2c.Instance = EVAL_I2Cx;
hEvalI2c.Init.Timing = EVAL_I2Cx_TIMING;
hEvalI2c.Init.OwnAddress1 = 0;
hEvalI2c.Init.AddressingMode = FMPI2C_ADDRESSINGMODE_7BIT;
hEvalI2c.Init.DualAddressMode = FMPI2C_DUALADDRESS_DISABLE;
hEvalI2c.Init.OwnAddress2 = 0;
hEvalI2c.Init.GeneralCallMode = FMPI2C_GENERALCALL_DISABLE;
hEvalI2c.Init.NoStretchMode = FMPI2C_NOSTRETCH_DISABLE;
I2Cx_MspInit();
HAL_FMPI2C_Init(&hEvalI2c);
}if (HAL_FMPI2C_GetState(&hEvalI2c) == HAL_FMPI2C_STATE_RESET) { ... }
}{ ... }
#if defined(USE_IOEXPANDER)
/* ... */
static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_FMPI2C_Mem_Write(&hEvalI2c, Addr, (uint16_t)Reg, FMPI2C_MEMADD_SIZE_8BIT, &Value, 1, 100);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
}{ ... }
/* ... */
static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg)
{
HAL_StatusTypeDef status = HAL_OK;
uint8_t Value = 0;
status = HAL_FMPI2C_Mem_Read(&hEvalI2c, Addr, Reg, FMPI2C_MEMADD_SIZE_8BIT, &Value, 1, 1000);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return Value;
}{ ... }
/* ... */#endif
/* ... */
static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_FMPI2C_Mem_Read(&hEvalI2c, Addr, (uint16_t)Reg, MemAddSize, Buffer, Length, 1000);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_FMPI2C_Mem_Write(&hEvalI2c, Addr, (uint16_t)Reg, MemAddSize, Buffer, Length, 1000);
if(status != HAL_OK)
{
I2Cx_Error(Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
{
return (HAL_FMPI2C_IsDeviceReady(&hEvalI2c, DevAddress, Trials, 1000));
}{ ... }
/* ... */
static void I2Cx_Error(uint8_t Addr)
{
HAL_FMPI2C_DeInit(&hEvalI2c);
I2Cx_Init();
}{ ... }
I2C Routines
/* ... */
static void FMC_BANK1_MspInit(void)
{
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_FMC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
gpio_init_structure.Alternate = GPIO_AF12_FMC;
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 |\
GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | GPIO_PIN_7 |\
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOE, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_0 ;
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
}{ ... }
/* ... */
static void FMC_BANK1_Init(void)
{
SRAM_HandleTypeDef hsram;
FMC_NORSRAM_TimingTypeDef sram_timing;
hsram.Instance = FMC_NORSRAM_DEVICE;
hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
sram_timing.AddressSetupTime = 5;
sram_timing.AddressHoldTime = 1;
sram_timing.DataSetupTime = 9;
sram_timing.BusTurnAroundDuration = 0;
sram_timing.CLKDivision = 2;
sram_timing.DataLatency = 2;
sram_timing.AccessMode = FMC_ACCESS_MODE_A;
hsram.Init.NSBank = FMC_NORSRAM_BANK1;
hsram.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
hsram.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
hsram.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
hsram.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
hsram.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
hsram.Init.WrapMode = FMC_WRAP_MODE_DISABLE;
hsram.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
hsram.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
hsram.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
hsram.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
hsram.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
hsram.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
hsram.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
hsram.Init.PageSize = FMC_PAGE_SIZE_NONE;
FMC_BANK1_MspInit();
HAL_SRAM_Init(&hsram, &sram_timing, &sram_timing);
}{ ... }
/* ... */
static void FMC_BANK1_WriteData(uint16_t Data)
{
FMC_BANK1->RAM = Data;
}{ ... }
/* ... */
static void FMC_BANK1_WriteReg(uint8_t Reg)
{
FMC_BANK1->REG = Reg;
}{ ... }
/* ... */
static uint16_t FMC_BANK1_ReadData(void)
{
return FMC_BANK1->RAM;
}{ ... }
/* ... */
#if defined(USE_IOEXPANDER)
/* ... */
void MFX_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void MFX_IO_DeInit(void)
{
}{ ... }
/* ... */
void MFX_IO_ITConfig(void)
{
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
gpio_init_structure.Pin = GPIO_PIN_0;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_LOW;
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
HAL_GPIO_Init(GPIOA, &gpio_init_structure);
HAL_NVIC_SetPriority((IRQn_Type)(EXTI0_IRQn), 0x0F, 0x0F);
HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI0_IRQn));
}{ ... }
/* ... */
void MFX_IO_Write(uint16_t Addr, uint8_t Reg, uint8_t Value)
{
I2Cx_Write((uint8_t) Addr, Reg, Value);
}{ ... }
/* ... */
uint8_t MFX_IO_Read(uint16_t Addr, uint8_t Reg)
{
return I2Cx_Read((uint8_t) Addr, Reg);
}{ ... }
/* ... */
uint16_t MFX_IO_ReadMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
{
return I2Cx_ReadMultiple((uint8_t) Addr, (uint16_t)Reg, FMPI2C_MEMADD_SIZE_8BIT, Buffer, Length);
}{ ... }
/* ... */
void MFX_IO_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
/* ... */
void MFX_IO_Wakeup(void)
{
}{ ... }
/* ... */
void MFX_IO_EnableWakeupPin(void)
{
}{ ... }
/* ... */#endif
/* ... */
void LCD_IO_Init(void)
{
FMC_BANK1_Init();
}{ ... }
/* ... */
void LCD_IO_WriteData(uint16_t Data)
{
FMC_BANK1_WriteData(Data);
}{ ... }
/* ... */
#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION) && !defined (__CC_ARM)
__attribute__((optimize("O1")))
#endif
__NOINLINE void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
{
uint32_t counter;
uint16_t *ptr = (uint16_t *) pData;
for (counter = 0; counter < Size; counter+=2)
{
FMC_BANK1_WriteData(*ptr);
ptr++;
}for (counter = 0; counter < Size; counter+=2) { ... }
}{ ... }
/* ... */
void LCD_IO_WriteReg(uint8_t Reg)
{
FMC_BANK1_WriteReg(Reg);
}{ ... }
/* ... */
uint16_t LCD_IO_ReadData(uint16_t Reg)
{
FMC_BANK1_WriteReg(Reg);
return FMC_BANK1_ReadData();
}{ ... }
LINK LCD
/* ... */
void AUDIO_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void AUDIO_IO_DeInit(void)
{
}{ ... }
/* ... */
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
{
uint16_t tmp = Value;
Value = ((uint16_t)(tmp >> 8) & 0x00FF);
Value |= ((uint16_t)(tmp << 8)& 0xFF00);
I2Cx_WriteMultiple(Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
}{ ... }
/* ... */
uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
{
uint16_t read_value = 0, tmp = 0;
I2Cx_ReadMultiple(Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
read_value = tmp;
return read_value;
}{ ... }
/* ... */
void AUDIO_IO_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK AUDIO
/* ... */
void CAMERA_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void CAMERA_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
{
uint16_t tmp = Value;
if(Addr == CAMERA_I2C_ADDRESS_2)
{
I2Cx_WriteMultiple(Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 1);
}if (Addr == CAMERA_I2C_ADDRESS_2) { ... }
else
{
Value = ((uint16_t)(tmp >> 8) & 0x00FF);
Value |= ((uint16_t)(tmp << 8)& 0xFF00);
I2Cx_WriteMultiple(Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
}else { ... }
}{ ... }
/* ... */
uint16_t CAMERA_IO_Read(uint8_t Addr, uint16_t Reg)
{
uint16_t read_value = 0, tmp = 0;
if(Addr == CAMERA_I2C_ADDRESS_2)
{
I2Cx_ReadMultiple(Addr , Reg, FMPI2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 1);
}if (Addr == CAMERA_I2C_ADDRESS_2) { ... }
else
{
I2Cx_ReadMultiple(Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
read_value = tmp;
}else { ... }
return read_value;
}{ ... }
/* ... */
void CAMERA_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK CAMERA
/* ... */
void EEPROM_IO_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
{
return (I2Cx_WriteMultiple(DevAddress, MemAddress, FMPI2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
{
return (I2Cx_ReadMultiple(DevAddress, MemAddress, FMPI2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
}{ ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
{
return (I2Cx_IsDeviceReady(DevAddress, Trials));
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */