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
28
29
32
33
36
37
40
41
45
48
49
52
55
56
57
58
59
63
64
65
66
67
68
71
72
75
76
78
79
80
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
109
110
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
153
154
157
158
162
166
167
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
195
196
197
198
199
200
201
202
203
204
205
206
207
214
218
219
226
230
231
238
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
295
296
297
298
299
300
301
302
303
304
305
312
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
374
375
377
378
379
380
383
384
385
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
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
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
512
513
514
515
521
522
523
524
525
526
527
528
529
530
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
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
639
645
646
650
656
657
661
665
666
669
670
671
674
678
679
683
688
689
694
703
704
708
713
714
718
722
723
727
731
732
733
734
737
741
742
745
749
750
756
757
758
759
760
761
762
763
764
765
766
767
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
801
802
803
804
805
806
807
808
809
810
814
815
819
823
824
825
826
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
848
852
853
859
860
861
862
863
864
865
866
867
868
874
878
879
883
887
888
891
892
895
896
899
900
/* ... */
#include "stm32f413h_discovery.h"
/* ... */
/* ... */
/* ... */
/* ... */
typedef struct
{
__IO uint16_t REG;
__IO uint16_t RAM;
...}LCD_CONTROLLER_TypeDef;
/* ... */
/* ... */
/* ... */
#define __STM32F413H_DISCOVERY_BSP_VERSION_MAIN (0x01)
#define __STM32F413H_DISCOVERY_BSP_VERSION_SUB1 (0x00)
#define __STM32F413H_DISCOVERY_BSP_VERSION_SUB2 (0x04)
#define __STM32F413H_DISCOVERY_BSP_VERSION_RC (0x00)
#define __STM32F413H_DISCOVERY_BSP_VERSION ((__STM32F413H_DISCOVERY_BSP_VERSION_MAIN << 24)\
|(__STM32F413H_DISCOVERY_BSP_VERSION_SUB1 << 16)\
|(__STM32F413H_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
|(__STM32F413H_DISCOVERY_BSP_VERSION_RC))...
#define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
#define FMC_BANK3 ((LCD_CONTROLLER_TypeDef *) FMC_BANK3_BASE)
7 defines
/* ... */
/* ... */
const uint32_t GPIO_PIN[LEDn] = {LED3_PIN,
LED4_PIN...};
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT,
LED4_GPIO_PORT...};
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT};
const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN};
const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn};
USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1};
GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT};
GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT};
const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN};
const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN};
const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF};
const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF};
static FMPI2C_HandleTypeDef hI2cAudioHandler;
/* ... */
/* ... */
static void FMPI2Cx_Init(FMPI2C_HandleTypeDef *i2c_handler);
static void FMPI2Cx_DeInit(FMPI2C_HandleTypeDef *i2c_handler);
static HAL_StatusTypeDef FMPI2Cx_ReadMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
static HAL_StatusTypeDef FMPI2Cx_WriteMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
static void FMPI2Cx_Error(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr);
static void FMC_BANK3_WriteData(uint16_t Data);
static void FMC_BANK3_WriteReg(uint8_t Reg);
static uint16_t FMC_BANK3_ReadData(void);
static void FMC_BANK3_Init(void);
static void FMC_BANK3_MspInit(void);
void LCD_IO_Init(void);
void LCD_IO_WriteData(uint16_t RegValue);
void LCD_IO_WriteReg(uint8_t Reg);
void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size);
uint16_t LCD_IO_ReadData(void);
void LCD_IO_Delay(uint32_t Delay);
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 TS_IO_Init(void);
void TS_IO_DeInit(void);
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
void TS_IO_Delay(uint32_t Delay);
/* ... */
/* ... */
/* ... */
uint32_t BSP_GetVersion(void)
{
return __STM32F413H_DISCOVERY_BSP_VERSION;
}{ ... }
/* ... */
void BSP_LED_Init(Led_TypeDef Led)
{
GPIO_InitTypeDef gpio_init_structure;
LEDx_GPIO_CLK_ENABLE(Led);
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(GPIO_PORT[Led], &gpio_init_structure);
}{ ... }
/* ... */
void BSP_LED_DeInit(Led_TypeDef Led)
{
GPIO_InitTypeDef gpio_init_structure;
gpio_init_structure.Pin = GPIO_PIN[Led];
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
}{ ... }
/* ... */
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_init_structure;
WAKEUP_BUTTON_GPIO_CLK_ENABLE();
if(ButtonMode == BUTTON_MODE_GPIO)
{
gpio_init_structure.Pin = BUTTON_PIN[Button];
gpio_init_structure.Mode = GPIO_MODE_INPUT;
gpio_init_structure.Pull = GPIO_PULLDOWN;
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_PULLDOWN;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
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;
DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM);
DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM);
DISCOVERY_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_FREQ_HIGH;
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);
DISCOVERY_COMx_CLK_DISABLE(COM);
/* ... */
/* ... */
}{ ... }
/* ... */
/* ... */
static void FMPI2Cx_MspInit(FMPI2C_HandleTypeDef *fmpi2c_handler)
{
GPIO_InitTypeDef gpio_init_structure;
DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = DISCOVERY_AUDIO_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 = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF;
HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN;
gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF;
HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
DISCOVERY_AUDIO_I2Cx_CLK_ENABLE();
DISCOVERY_AUDIO_I2Cx_FORCE_RESET();
DISCOVERY_AUDIO_I2Cx_RELEASE_RESET();
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0x00);
HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn);
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0x00);
HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn);
}{ ... }
/* ... */
static void FMPI2Cx_Init(FMPI2C_HandleTypeDef *fmpi2c_handler)
{
if(HAL_FMPI2C_GetState(fmpi2c_handler) == HAL_FMPI2C_STATE_RESET)
{
fmpi2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
fmpi2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
fmpi2c_handler->Init.OwnAddress1 = 0;
fmpi2c_handler->Init.AddressingMode = FMPI2C_ADDRESSINGMODE_7BIT;
fmpi2c_handler->Init.DualAddressMode = FMPI2C_DUALADDRESS_DISABLE;
fmpi2c_handler->Init.OwnAddress2 = 0;
fmpi2c_handler->Init.OwnAddress2Masks = FMPI2C_OA2_NOMASK;
fmpi2c_handler->Init.GeneralCallMode = FMPI2C_GENERALCALL_DISABLE;
fmpi2c_handler->Init.NoStretchMode = FMPI2C_NOSTRETCH_DISABLE;
FMPI2Cx_MspInit(fmpi2c_handler);
HAL_FMPI2C_Init(fmpi2c_handler);
}if (HAL_FMPI2C_GetState(fmpi2c_handler) == HAL_FMPI2C_STATE_RESET) { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef FMPI2Cx_ReadMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler,
uint8_t Addr,
uint16_t Reg,
uint16_t MemAddress,
uint8_t *Buffer,
uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_FMPI2C_Mem_Read(fmpi2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
if(status != HAL_OK)
{
FMPI2Cx_Error(fmpi2c_handler, Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static HAL_StatusTypeDef FMPI2Cx_WriteMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler,
uint8_t Addr,
uint16_t Reg,
uint16_t MemAddress,
uint8_t *Buffer,
uint16_t Length)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_FMPI2C_Mem_Write(fmpi2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
if(status != HAL_OK)
{
FMPI2Cx_Error(fmpi2c_handler, Addr);
}if (status != HAL_OK) { ... }
return status;
}{ ... }
/* ... */
static void FMPI2Cx_Error(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr)
{
HAL_FMPI2C_DeInit(fmpi2c_handler);
FMPI2Cx_Init(fmpi2c_handler);
}{ ... }
/* ... */
static void FMPI2Cx_DeInit(FMPI2C_HandleTypeDef *fmpi2c_handler)
{
fmpi2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
__HAL_FMPI2C_DISABLE(fmpi2c_handler);
HAL_FMPI2C_DeInit(fmpi2c_handler);
}{ ... }
I2C Routines
/* ... */
static void FMC_BANK3_MspInit(void)
{
GPIO_InitTypeDef gpio_init_structure;
__HAL_RCC_FSMC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_init_structure.Alternate = GPIO_AF12_FSMC;
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|\
GPIO_PIN_11 | GPIO_PIN_12;
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
gpio_init_structure.Pin = 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 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_10 ;
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
}{ ... }
/* ... */
static void FMC_BANK3_Init(void)
{
SRAM_HandleTypeDef hsram;
FSMC_NORSRAM_TimingTypeDef sram_timing;
FMC_BANK3_MspInit();
hsram.Instance = FSMC_NORSRAM_DEVICE;
hsram.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
sram_timing.AddressSetupTime = 3;
sram_timing.AddressHoldTime = 1;
sram_timing.DataSetupTime = 4;
sram_timing.BusTurnAroundDuration = 1;
sram_timing.CLKDivision = 2;
sram_timing.DataLatency = 2;
sram_timing.AccessMode = FSMC_ACCESS_MODE_A;
hsram.Init.NSBank = FSMC_NORSRAM_BANK3;
hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
hsram.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE;
hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
hsram.Init.WriteFifo = FSMC_WRITE_FIFO_DISABLE;
hsram.Init.PageSize = FSMC_PAGE_SIZE_NONE;
hsram.Init.ContinuousClock = FSMC_CONTINUOUS_CLOCK_SYNC_ONLY;
HAL_SRAM_Init(&hsram, &sram_timing, &sram_timing);
}{ ... }
/* ... */
static void FMC_BANK3_WriteData(uint16_t Data)
{
FMC_BANK3->RAM = Data;
__DSB();
}{ ... }
/* ... */
static void FMC_BANK3_WriteReg(uint8_t Reg)
{
FMC_BANK3->REG = Reg;
__DSB();
}{ ... }
/* ... */
static uint16_t FMC_BANK3_ReadData(void)
{
return FMC_BANK3->RAM;
}{ ... }
/* ... */
FMC Routines
/* ... */
void LCD_IO_Init(void)
{
FMC_BANK3_Init();
}{ ... }
/* ... */
void LCD_IO_WriteData(uint16_t RegValue)
{
FMC_BANK3_WriteData(RegValue);
}{ ... }
/* ... */
void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size)
{
uint32_t i;
for (i = 0; i < Size; i++)
{
FMC_BANK3_WriteData(pData[i]);
}for (i = 0; i < Size; i++) { ... }
}{ ... }
/* ... */
void LCD_IO_WriteReg(uint8_t Reg)
{
FMC_BANK3_WriteReg(Reg);
}{ ... }
/* ... */
uint16_t LCD_IO_ReadData(void)
{
return FMC_BANK3_ReadData();
}{ ... }
/* ... */
void LCD_IO_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK LCD
/* ... */
void AUDIO_IO_Init(void)
{
FMPI2Cx_Init(&hI2cAudioHandler);
}{ ... }
/* ... */
void AUDIO_IO_DeInit(void)
{
FMPI2Cx_DeInit(&hI2cAudioHandler);
}{ ... }
/* ... */
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);
FMPI2Cx_WriteMultiple(&hI2cAudioHandler, 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;
FMPI2Cx_ReadMultiple(&hI2cAudioHandler, 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;
}{ ... }
/* ... */
uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
{
return FMPI2Cx_ReadMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
}{ ... }
/* ... */
void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
{
FMPI2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
}{ ... }
/* ... */
void AUDIO_IO_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
LINK AUDIO
/* ... */
void TS_IO_Init(void)
{
GPIO_InitTypeDef gpio_init_structure;
TS_RESET_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = TS_RESET_PIN;
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(TS_RESET_GPIO_PORT, &gpio_init_structure);
FMPI2Cx_Init(&hI2cAudioHandler);
}{ ... }
/* ... */
void TS_IO_DeInit(void)
{
FMPI2Cx_DeInit(&hI2cAudioHandler);
}{ ... }
/* ... */
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
{
uint8_t read_value = 0;
FMPI2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
return read_value;
}{ ... }
/* ... */
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{
FMPI2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
}{ ... }
/* ... */
void TS_IO_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */