1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
26
27
30
31
36
37
40
43
44
47
48
51
62
63
66
69
70
73
76
77
80
81
82
83
84
85
86
87
88
89
90
91
92
95
96
99
100
101
102
103
104
105
106
107
108
109
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
151
152
153
156
157
160
161
165
169
170
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
202
206
207
214
218
219
226
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
278
282
283
286
287
288
289
293
294
295
296
297
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
454
455
456
457
458
459
460
461
466
467
468
475
476
477
478
479
480
481
482
487
488
489
495
496
497
498
499
500
501
502
503
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
531
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
585
586
587
588
589
596
600
601
602
605
606
607
608
609
610
611
612
613
614
615
616
619
620
621
622
623
624
625
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
657
658
659
660
661
662
663
664
665
670
671
672
673
674
678
679
680
681
682
683
684
685
690
691
692
698
699
700
701
702
703
704
708
709
710
711
712
715
716
717
718
719
720
721
722
723
724
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
812
813
814
815
816
817
818
819
820
821
822
823
824
825
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
858
862
863
866
867
868
869
872
876
877
880
884
885
891
895
896
902
906
907
914
918
919
920
921
922
923
924
925
926
927
931
932
936
940
941
942
943
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
979
980
981
985
989
990
991
992
993
994
995
996
1002
1003
1004
1005
1006
1007
1013
1014
1015
1019
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1050
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1080
1081
1082
1083
1084
1085
1086
1087
1088
1092
1093
1094
1097
1098
1101
1102
1105
1106
/* ... */
#include "stm32f429i_discovery.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
#define __STM32F429I_DISCO_BSP_VERSION_MAIN (0x02)
#define __STM32F429I_DISCO_BSP_VERSION_SUB1 (0x01)
#define __STM32F429I_DISCO_BSP_VERSION_SUB2 (0x08)
#define __STM32F429I_DISCO_BSP_VERSION_RC (0x00)
#define __STM32F429I_DISCO_BSP_VERSION ((__STM32F429I_DISCO_BSP_VERSION_MAIN << 24)\
|(__STM32F429I_DISCO_BSP_VERSION_SUB1 << 16)\
|(__STM32F429I_DISCO_BSP_VERSION_SUB2 << 8 )\
|(__STM32F429I_DISCO_BSP_VERSION_RC))...
5 defines
/* ... */
/* ... */
/* ... */
/* ... */
GPIO_TypeDef *GPIO_PORT[LEDn] = {LED3_GPIO_PORT,
LED4_GPIO_PORT
...};
const uint16_t GPIO_PIN[LEDn] = {LED3_PIN,
LED4_PIN
...};
GPIO_TypeDef *BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT};
const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN};
const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn};
uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX;
uint32_t SpixTimeout = SPIx_TIMEOUT_MAX;
I2C_HandleTypeDef I2cHandle;
static SPI_HandleTypeDef SpiHandle;
static uint8_t Is_LCD_IO_Initialized = 0;
/* ... */
/* ... */
static void I2Cx_Init(void);
static void I2Cx_ITConfig(void);
static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value);
static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg);
static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
static void I2Cx_Error(void);
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c);
#ifdef EE_M24LR64
static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length);
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);/* ... */
#endif
static void SPIx_Init(void);
static void SPIx_Write(uint16_t Value);
static uint32_t SPIx_Read(uint8_t ReadSize);
static uint8_t SPIx_WriteRead(uint8_t Byte);
static void SPIx_Error(void);
static void SPIx_MspInit(SPI_HandleTypeDef *hspi);
void LCD_IO_Init(void);
void LCD_IO_WriteData(uint16_t RegValue);
void LCD_IO_WriteReg(uint8_t Reg);
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
void LCD_Delay(uint32_t delay);
void IOE_Init(void);
void IOE_ITConfig(void);
void IOE_Delay(uint32_t Delay);
void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
uint8_t IOE_Read(uint8_t Addr, uint8_t Reg);
uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
void GYRO_IO_Init(void);
void GYRO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
void GYRO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
#ifdef EE_M24LR64
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);/* ... */
#endif
/* ... */
/* ... */
/* ... */
uint32_t BSP_GetVersion(void)
{
return __STM32F429I_DISCO_BSP_VERSION;
}{ ... }
/* ... */
void BSP_LED_Init(Led_TypeDef Led)
{
GPIO_InitTypeDef GPIO_InitStruct;
LEDx_GPIO_CLK_ENABLE(Led);
GPIO_InitStruct.Pin = GPIO_PIN[Led];
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
}{ ... }
/* ... */
void BSP_LED_On(Led_TypeDef Led)
{
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
}{ ... }
/* ... */
void BSP_LED_Off(Led_TypeDef Led)
{
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
}{ ... }
/* ... */
void BSP_LED_Toggle(Led_TypeDef Led)
{
HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
}{ ... }
/* ... */
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
{
GPIO_InitTypeDef GPIO_InitStruct;
BUTTONx_GPIO_CLK_ENABLE(Button);
if (ButtonMode == BUTTON_MODE_GPIO)
{
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
}if (ButtonMode == BUTTON_MODE_GPIO) { ... }
if (ButtonMode == BUTTON_MODE_EXTI)
{
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
}if (ButtonMode == BUTTON_MODE_EXTI) { ... }
}{ ... }
/* ... */
uint32_t BSP_PB_GetState(Button_TypeDef Button)
{
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}{ ... }
/* ... */
/* ... */
static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct;
#ifdef EE_M24LR64
static DMA_HandleTypeDef hdma_tx;
static DMA_HandleTypeDef hdma_rx;
I2C_HandleTypeDef *pI2cHandle;
pI2cHandle = &I2cHandle;/* ... */
#endif
if (hi2c->Instance == DISCOVERY_I2Cx)
{
DISCOVERY_I2Cx_SDA_GPIO_CLK_ENABLE();
DISCOVERY_I2Cx_SCL_GPIO_CLK_ENABLE();
GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SCL_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SDA_PIN;
HAL_GPIO_Init(DISCOVERY_I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct);
Configure the GPIOs
DISCOVERY_I2Cx_CLOCK_ENABLE();
DISCOVERY_I2Cx_FORCE_RESET();
DISCOVERY_I2Cx_RELEASE_RESET();
HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0);
HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
#ifdef EE_M24LR64
EEPROM_I2C_DMA_CLK_ENABLE();
hdma_tx.Instance = EEPROM_I2C_DMA_STREAM_TX;
hdma_tx.Init.Channel = EEPROM_I2C_DMA_CHANNEL;
hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_tx.Init.Mode = DMA_NORMAL;
hdma_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
hdma_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_tx.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
__HAL_LINKDMA(pI2cHandle, hdmatx, hdma_tx);
HAL_DMA_Init(&hdma_tx);
HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0);
HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn));
hdma_rx.Instance = EEPROM_I2C_DMA_STREAM_RX;
hdma_rx.Init.Channel = EEPROM_I2C_DMA_CHANNEL;
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_rx.Init.Mode = DMA_NORMAL;
hdma_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
hdma_rx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_rx.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_rx.Init.PeriphBurst = DMA_PBURST_SINGLE;
__HAL_LINKDMA(pI2cHandle, hdmarx, hdma_rx);
HAL_DMA_Init(&hdma_rx);
HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0);
HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn));/* ... */
#endif
}if (hi2c->Instance == DISCOVERY_I2Cx) { ... }
}{ ... }
/* ... */
static void I2Cx_Init(void)
{
if (HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET)
{
I2cHandle.Instance = DISCOVERY_I2Cx;
I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED;
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
I2cHandle.Init.OwnAddress1 = 0;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2cHandle.Init.OwnAddress2 = 0;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
I2Cx_MspInit(&I2cHandle);
HAL_I2C_Init(&I2cHandle);
}if (HAL_I2C_GetState(&I2cHandle) == HAL_I2C_STATE_RESET) { ... }
}{ ... }
/* ... */
static void I2Cx_ITConfig(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
STMPE811_INT_CLK_ENABLE();
GPIO_InitStruct.Pin = STMPE811_INT_PIN;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
HAL_GPIO_Init(STMPE811_INT_GPIO_PORT, &GPIO_InitStruct);
HAL_NVIC_SetPriority((IRQn_Type)(STMPE811_INT_EXTI), 0x0F, 0x00);
HAL_NVIC_EnableIRQ((IRQn_Type)(STMPE811_INT_EXTI));
}{ ... }
/* ... */
static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Write(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
if (status != HAL_OK)
{
I2Cx_Error();
}if (status != HAL_OK) { ... }
}{ ... }
/* ... */
static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Write(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
if (status != HAL_OK)
{
I2Cx_Error();
}if (status != HAL_OK) { ... }
}{ ... }
/* ... */
static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg)
{
HAL_StatusTypeDef status = HAL_OK;
uint8_t value = 0;
status = HAL_I2C_Mem_Read(&I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout);
if (status != HAL_OK)
{
I2Cx_Error();
}if (status != HAL_OK) { ... }
return value;
}{ ... }
/* ... */
static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Read(&I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
if (status == HAL_OK)
{
return 0;
}if (status == HAL_OK) { ... }
else
{
I2Cx_Error();
return 1;
}else { ... }
}{ ... }
#ifdef EE_M24LR64
/* ... */
static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Write_DMA(&I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length);
if (status != HAL_OK)
{
I2Cx_Error();
}if (status != HAL_OK) { ... }
return status;
}I2Cx_WriteBufferDMA (uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length) { ... }
/* ... */
static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Read_DMA(&I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length);
if (status != HAL_OK)
{
I2Cx_Error();
}if (status != HAL_OK) { ... }
return status;
}I2Cx_ReadBufferDMA (uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length) { ... }
/* ... */
static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
{
return (HAL_I2C_IsDeviceReady(&I2cHandle, DevAddress, Trials, I2cxTimeout));
}I2Cx_IsDeviceReady (uint16_t DevAddress, uint32_t Trials) { ... }
/* ... */#endif
/* ... */
static void I2Cx_Error(void)
{
HAL_I2C_DeInit(&I2cHandle);
I2Cx_Init();
}{ ... }
/* ... */
static void SPIx_Init(void)
{
if (HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
{
SpiHandle.Instance = DISCOVERY_SPIx;
/* ... */
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
SpiHandle.Init.CRCPolynomial = 7;
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
SpiHandle.Init.NSS = SPI_NSS_SOFT;
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
SpiHandle.Init.Mode = SPI_MODE_MASTER;
SPIx_MspInit(&SpiHandle);
HAL_SPI_Init(&SpiHandle);
}if (HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET) { ... }
}{ ... }
/* ... */
static uint32_t SPIx_Read(uint8_t ReadSize)
{
HAL_StatusTypeDef status = HAL_OK;
uint32_t readvalue;
status = HAL_SPI_Receive(&SpiHandle, (uint8_t *) &readvalue, ReadSize, SpixTimeout);
if (status != HAL_OK)
{
SPIx_Error();
}if (status != HAL_OK) { ... }
return readvalue;
}{ ... }
/* ... */
static void SPIx_Write(uint16_t Value)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_SPI_Transmit(&SpiHandle, (uint8_t *) &Value, 1, SpixTimeout);
if (status != HAL_OK)
{
SPIx_Error();
}if (status != HAL_OK) { ... }
}{ ... }
/* ... */
static uint8_t SPIx_WriteRead(uint8_t Byte)
{
uint8_t receivedbyte = 0;
if (HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t *) &Byte, (uint8_t *) &receivedbyte, 1, SpixTimeout) != HAL_OK)
{
SPIx_Error();
}if (HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t *) &Byte, (uint8_t *) &receivedbyte, 1, SpixTimeout) != HAL_OK) { ... }
return receivedbyte;
}{ ... }
/* ... */
static void SPIx_Error(void)
{
HAL_SPI_DeInit(&SpiHandle);
SPIx_Init();
}{ ... }
/* ... */
static void SPIx_MspInit(SPI_HandleTypeDef *hspi)
{
GPIO_InitTypeDef GPIO_InitStructure;
DISCOVERY_SPIx_CLK_ENABLE();
DISCOVERY_SPIx_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_PIN);
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF;
HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure);
}{ ... }
SPI Routines
/* ... */
void LCD_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
if (Is_LCD_IO_Initialized == 0)
{
Is_LCD_IO_Initialized = 1;
LCD_WRX_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = LCD_WRX_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(LCD_WRX_GPIO_PORT, &GPIO_InitStructure);
LCD_RDX_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = LCD_RDX_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(LCD_RDX_GPIO_PORT, &GPIO_InitStructure);
LCD_NCS_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = LCD_NCS_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
LCD_CS_LOW();
LCD_CS_HIGH();
SPIx_Init();
}if (Is_LCD_IO_Initialized == 0) { ... }
}{ ... }
/* ... */
void LCD_IO_WriteData(uint16_t RegValue)
{
LCD_WRX_HIGH();
LCD_CS_LOW();
SPIx_Write(RegValue);
LCD_CS_HIGH();
}{ ... }
/* ... */
void LCD_IO_WriteReg(uint8_t Reg)
{
LCD_WRX_LOW();
LCD_CS_LOW();
SPIx_Write(Reg);
LCD_CS_HIGH();
}{ ... }
/* ... */
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize)
{
uint32_t readvalue = 0;
LCD_CS_LOW();
LCD_WRX_LOW();
SPIx_Write(RegValue);
readvalue = SPIx_Read(ReadSize);
LCD_WRX_HIGH();
LCD_CS_HIGH();
return readvalue;
}{ ... }
/* ... */
void LCD_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
/* ... */
LINK LCD
/* ... */
void IOE_Init(void)
{
I2Cx_Init();
}{ ... }
/* ... */
void IOE_ITConfig(void)
{
I2Cx_ITConfig();
}{ ... }
/* ... */
void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
I2Cx_WriteData(Addr, Reg, Value);
}{ ... }
/* ... */
uint8_t IOE_Read(uint8_t Addr, uint8_t Reg)
{
return I2Cx_ReadData(Addr, Reg);
}{ ... }
/* ... */
void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
{
I2Cx_WriteBuffer(Addr, Reg, pBuffer, Length);
}{ ... }
/* ... */
uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
{
return I2Cx_ReadBuffer(Addr, Reg, pBuffer, Length);
}{ ... }
/* ... */
void IOE_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK IOE
/* ... */
void GYRO_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GYRO_CS_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = GYRO_CS_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);
GYRO_CS_HIGH();
GYRO_INT_GPIO_CLK_ENABLE();
GPIO_InitStructure.Pin = GYRO_INT1_PIN | GYRO_INT2_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GYRO_INT_GPIO_PORT, &GPIO_InitStructure);
SPIx_Init();
}{ ... }
/* ... */
void GYRO_IO_Write(uint8_t *pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
{
/* ... */
if (NumByteToWrite > 0x01)
{
WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD;
}if (NumByteToWrite > 0x01) { ... }
GYRO_CS_LOW();
SPIx_WriteRead(WriteAddr);
while (NumByteToWrite >= 0x01)
{
SPIx_WriteRead(*pBuffer);
NumByteToWrite--;
pBuffer++;
}while (NumByteToWrite >= 0x01) { ... }
GYRO_CS_HIGH();
}{ ... }
/* ... */
void GYRO_IO_Read(uint8_t *pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
{
if (NumByteToRead > 0x01)
{
ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
}if (NumByteToRead > 0x01) { ... }
else
{
ReadAddr |= (uint8_t)READWRITE_CMD;
}else { ... }
GYRO_CS_LOW();
SPIx_WriteRead(ReadAddr);
while (NumByteToRead > 0x00)
{
*pBuffer = SPIx_WriteRead(DUMMY_BYTE);
NumByteToRead--;
pBuffer++;
}while (NumByteToRead > 0x00) { ... }
GYRO_CS_HIGH();
}{ ... }
#ifdef EE_M24LR64
/* ... */
void EEPROM_IO_Init(void)
{
I2Cx_Init();
}EEPROM_IO_Init (void) { ... }
/* ... */
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pBuffer, uint32_t BufferSize)
{
return (I2Cx_WriteBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize));
}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)
{
return (I2Cx_ReadBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize));
}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)
{
return (I2Cx_IsDeviceReady(DevAddress, Trials));
}EEPROM_IO_IsDeviceReady (uint16_t DevAddress, uint32_t Trials) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
/* ... */