main.c


1
/**
2
  ******************************************************************************
3
  * File Name          : main.c
4
  * Description        : Main program body
5
  ******************************************************************************
6
  *
7
  * COPYRIGHT(c) 2016 STMicroelectronics
8
  *
9
  * Redistribution and use in source and binary forms, with or without modification,
10
  * are permitted provided that the following conditions are met:
11
  *   1. Redistributions of source code must retain the above copyright notice,
12
  *      this list of conditions and the following disclaimer.
13
  *   2. Redistributions in binary form must reproduce the above copyright notice,
14
  *      this list of conditions and the following disclaimer in the documentation
15
  *      and/or other materials provided with the distribution.
16
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
17
  *      may be used to endorse or promote products derived from this software
18
  *      without specific prior written permission.
19
  *
20
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
  *
31
  ******************************************************************************
32
  */
33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32f1xx_hal.h"
35
36
/* USER CODE BEGIN Includes */
37
#include "pcm1774.h"
38
39
/* USER CODE END Includes */
40
41
/* Private variables ---------------------------------------------------------*/
42
I2C_HandleTypeDef hi2c1;
43
44
I2S_HandleTypeDef hi2s3;
45
46
/* USER CODE BEGIN PV */
47
/* Private variables ---------------------------------------------------------*/
48
49
/* USER CODE END PV */
50
51
/* Private function prototypes -----------------------------------------------*/
52
void SystemClock_Config(void);
53
static void MX_GPIO_Init(void);
54
static void MX_I2C1_Init(void);
55
static void MX_I2S3_Init(void);
56
57
/* USER CODE BEGIN PFP */
58
/* Private function prototypes -----------------------------------------------*/
59
60
/* USER CODE END PFP */
61
62
/* USER CODE BEGIN 0 */
63
64
uint16_t pcm_sound[32] = {
65
0x39,0xFB,0x35,0xFB,0xE2,0xF9,0xE5,0xF9,0xDF,0xFB,0xDE,0xFB,0xDA,0xFF,0xD9,0xFF,
66
0xEB,0x02,0xEE,0x02,0xF8,0x02,0xF3,0x02,0x33,0x00,0x38,0x00,0x07,0xFD,0x03,0xFD,
67
68
};
69
70
//! Low level function to send a byte to the PCM1774
71
//! @param address is the 8-bit address of register to write to
72
//! @param data is the data to write to register
73
void pcm1774_sendByte(unsigned char address, unsigned char data)
74
{
75
    
76
  uint8_t data2[2];
77
  data2[0] = address;
78
  data2[1] = data;
79
    
80
  HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)0x46<<1, (uint8_t *)data2, 2, 100);
81
  
82
  data2[0] = 0;
83
  data2[1] = 0;
84
    
85
}
86
87
//! Low level function to read a byte from the PCM1774
88
//! @param address is the 8-bit address of register to read from
89
//! @returns the byte read from the register
90
unsigned char pcm1774_readByte(unsigned char address)
91
{
92
  uint8_t data;
93
  //return i2c_receive_byte(PCM_1774_ADDRESS, address);
94
  HAL_I2C_Master_Receive(&hi2c1, (uint16_t)address, (uint8_t *)data, 1, 100);
95
  return data;
96
}
97
98
//! @param  address Address to write to
99
//!  @param   andOr If 1, then byte will be ORed by value of byte, otherwise byte will be ANDed with value of byte
100
//! @param  byte The value to AND or OR the register value
101
//! This is used to retain existing data contents and and/or just specific bits
102
void pcm1774_bitMask(unsigned char address, unsigned char byte, char andOr)
103
{
104
  unsigned char data;
105
106
  if(andOr)
107
    data = pcm1774_readByte(address) | byte;
108
  else
109
    data = pcm1774_readByte(address) & (char)(~byte);
110
111
  pcm1774_sendByte(address, data);
112
}
113
114
char initialize_pcm1774(void)
115
{
116
  // Default powerup registers recommended by PCM1774 at page 13/49
117
  /*
118
  pcm1774_sendByte(0x40, 0x27);  // L-Channel analog output volume
119
  pcm1774_sendByte(0x41, 0x27);  // R-Channel analog output volume
120
121
  pcm1774_sendByte(0x44, 0x27);  // L-Channel digital output volume
122
  pcm1774_sendByte(0x45, 0x27);  // R-Channel digital output volume
123
124
  pcm1774_sendByte(0x46, 0x20);  // DAC Audio Interface
125
  pcm1774_sendByte(0x49, 0xE0);  // DAC and analog BIAS power-up
126
127
  pcm1774_sendByte(0x56, 0x01);  // Zero-cross detection enable
128
  pcm1774_sendByte(0x48, 0x03);  // Analog Mixer Power-up
129
130
  pcm1774_sendByte(0x58, 0x11);  // Analog mixer input SW2, SW5 select to feed Digital DAC signals to Audio Jack output
131
  pcm1774_sendByte(0x49, 0xEC);  // Headphone Amplifier Power-up
132
133
  pcm1774_sendByte(0x4A, 0x01);  // Vcom power up
134
  pcm1774_sendByte(0x52, 0x30);  // Analog front-end D2S, MCB, PG1, 2, 5, 6 power-up
135
136
  pcm1774_sendByte(0x57, 0x11);  // Analog input select -- (For FM Radio)
137
  pcm1774_sendByte(0x57, 0x00);  // Analog input select -- We don't want FM Radio's Analog Input by default.
138
139
  pcm1774_DigitalVolume(90, 90);  // Digital Volume
140
  pcm1774_OutputVolume(50, 50);  // 20% overall Output Volume
141
  */
142
  
143
  pcm1774_sendByte(0x40, 0x27);
144
  pcm1774_sendByte(0x41, 0x27);
145
  pcm1774_sendByte(0x44, 0x27);
146
  pcm1774_sendByte(0x45, 0x27);
147
  pcm1774_sendByte(0x46, 0x01);
148
  pcm1774_sendByte(0x49, 0xEC);
149
  pcm1774_sendByte(0x56, 0x01);
150
  pcm1774_sendByte(0x48, 0x03);
151
  pcm1774_sendByte(0x58, 0x11);
152
  pcm1774_sendByte(0x49, 0xEC);
153
  pcm1774_sendByte(0x4A, 0x01);
154
  pcm1774_sendByte(0x52, 0x30);
155
  pcm1774_sendByte(0x57, 0x11);
156
  pcm1774_OutputVolume(50, 50);
157
  
158
  
159
  
160
  return 1;
161
}
162
163
void pcm1774_Reset(void)
164
{
165
  volatile int i = 0;
166
  pcm1774_sendByte(PCM1774_SYSTEM_RESET_SAMPLING_CONTROL, (1<<7));
167
  //for(i=0; i<5000; i++);
168
  //initialize_pcm1774();
169
  pcm1774_LoadDefaultDigitalConfiguration();
170
}
171
172
void pcm1774_LoadDefaultDigitalConfiguration(void)
173
{
174
  initialize_pcm1774();
175
176
  pcm1774_PowerUpMixer(TRUE, TRUE);
177
  pcm1774_PowerUpAnalog(TRUE, TRUE);
178
  pcm1774_PowerUpGainAmplifierAnalog(TRUE, TRUE);
179
  //pcm1774_selectAnalogInput(FALSE, FALSE);
180
181
/*  
182
  // Direct left input to left output
183
  pcm1774_redirectAnalogInputToLeftOutput(FALSE, FALSE);
184
  // Direct right input to right output
185
  pcm1774_redirectAnalogInputToRightOutput(FALSE, FALSE);
186
*/
187
  pcm1774_gainAmplifierAnalogInput(4, 4);
188
  pcm1774_ConnectDigitalOutputs(1, 1);
189
  pcm1774_DigitalVolume(40, 40);  // Digital Volume at 80%
190
  pcm1774_OutputVolume(50, 50);  // 20% Output Volume
191
}
192
193
void pcm1774_OutputVolume(int volumeLeft, int volumeRight)
194
{
195
  // Scale 0-100 to 0-63
196
  volumeLeft = (190*volumeLeft)/300;
197
  volumeRight= (190*volumeRight)/300;
198
199
  pcm1774_sendByte(PCM1774_HPA_L, (0x3f &  volumeLeft));
200
  pcm1774_sendByte(PCM1774_HPA_R, (0x3f & volumeRight));
201
}
202
203
void pcm1774_ConnectDigitalOutputs(char leftChannel, char rightChannel)
204
{
205
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, (1<<0), leftChannel);
206
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, (1<<4), rightChannel);
207
}
208
209
210
void pcm1774_DigitalVolume(int volumeLeft, int volumeRight)
211
{
212
  // Scale 0-100 to 0-63
213
  volumeLeft = (190*volumeLeft)/300;
214
  volumeRight= (190*volumeRight)/300;
215
216
  pcm1774_sendByte(PCM1774_DAC_AND_SOFT_MUTE_L, (0x3f &  volumeLeft));
217
  pcm1774_sendByte(PCM1774_DAC_AND_SOFT_MUTE_R, (0x3f & volumeRight));
218
}
219
220
void pcm1774_DigitalDeEmphasisFilter(char filter)
221
{
222
  // Filter should be:
223
  // 00:  OFF
224
  // 01:  32Khz
225
  // 10:  44.1Khz
226
  // 11:  48Khz
227
228
  // Clear old filter first
229
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, 0xC0, 0);
230
  // set the bits defined by filter to 1
231
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, (filter<<6), 1);
232
}
233
234
void pcm1774_DigitalInterfaceSelection(char selection)
235
{
236
  // selection should be:
237
  // 00: I2S Format
238
  // 01: Right-justified format
239
  // 10: left-justified format
240
  // 11: DSP Format
241
242
  // Clear old filter first
243
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, 0x30, 0);
244
  // set the bits defined by filter to 1
245
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, ((selection&0x03)<<4), 1);
246
}
247
248
void pcm1774_DigitalGainControl(char control)
249
{
250
  // control should be:
251
  // 00: 0db
252
  // 01: 6db
253
  // 10: 12db
254
  // 11: 18db
255
256
  // Clear old filter first
257
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, 0x0C, 0);
258
  // set the bits defined by filter to 1
259
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, ((control&0x03)<<2), 1);
260
}
261
262
void pcm1774_DigitalOversamplingControl(char control)
263
{
264
  pcm1774_bitMask(PCM1774_DE_EMPHASIS_AUDIO_INTERFACE, 0x01, control);
265
}
266
267
void pcm1774_PowerUpMixer(char powerLeft, char powerRight)
268
{
269
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_POWER_UP_DOWN, (1<<0), powerLeft);
270
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_POWER_UP_DOWN, (1<<1), powerRight);
271
}
272
273
void pcm1774_PowerUpAnalogBiasControl(char power)
274
{
275
  pcm1774_bitMask(PCM1774_DAC_HPA_POWER_UP_DOWN, (1<<7), power);
276
}
277
278
void pcm1774_PowerUpDAC(char powerLeft, char powerRight)
279
{
280
  pcm1774_bitMask(PCM1774_DAC_HPA_POWER_UP_DOWN, (1<<5), powerLeft);
281
  pcm1774_bitMask(PCM1774_DAC_HPA_POWER_UP_DOWN, (1<<6), powerRight);
282
}
283
284
void pcm1774_PowerUpAnalog(char powerLeft, char powerRight)
285
{
286
  pcm1774_bitMask(PCM1774_DAC_HPA_POWER_UP_DOWN, (1<<2), powerLeft);
287
  pcm1774_bitMask(PCM1774_DAC_HPA_POWER_UP_DOWN, (1<<3), powerRight);
288
}
289
290
void pcm1774_LineOutputConfiguration(char config)
291
{
292
  char stereo = 0x00;
293
  char monaural = 0x04;
294
  char differential = 0x08;
295
296
  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x0C, 0);
297
  switch(config)
298
  {
299
    case 1:  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0xC0, monaural);  break;
300
    case 2:  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0xC0, differential); break;
301
302
    case 0:
303
    default:
304
      pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0xC0, stereo);
305
  }
306
}
307
308
void pcm1774_PowerUpVcom(char power)
309
{
310
  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x01, power);
311
}
312
313
void pcm1774_setShortCircuitProtectionLeft(char protection)
314
{
315
  // 0 is to enable protection
316
  if(protection)  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x04, 0);
317
  else      pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x04, 1);
318
}
319
320
void pcm1774_setShortCircuitProtectionRight(char protection)
321
{
322
  // 0 is to enable protection
323
  if(protection)  pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x08, 0);
324
  else      pcm1774_bitMask(PCM1774_ANALOG_OUTPUT_CONFIG_SELECT, 0x08, 1);
325
}
326
327
char pcm1774_readShortCircuitStatusLeft(void)
328
{
329
  // 0 means short circuit detected
330
  return (!(pcm1774_readByte(PCM1774_SHUTDOWN_STATUS_READBACK) & 0x04));
331
}
332
333
char pcm1774_readShortCircuitStatusRight(void)
334
{
335
  // 0 means short circuit detected
336
  return (!(pcm1774_readByte(PCM1774_SHUTDOWN_STATUS_READBACK) & 0x08));
337
}
338
339
void pcm1774_PowerUpGainAmplifierAnalog(char powerLeft, char powerRight)
340
{
341
  pcm1774_bitMask(PCM1774_PG_1_2_5_6_POWER_UP_DOWN, (1<<4), powerLeft);
342
  pcm1774_bitMask(PCM1774_PG_1_2_5_6_POWER_UP_DOWN, (1<<5), powerRight);
343
}
344
345
void pcm1774_selectAnalogInput(char selectLeft, char selectRight)
346
{
347
  pcm1774_bitMask(PCM1774_ANALOG_INPUT_SELECT, (1<<0), selectLeft);  
348
  pcm1774_bitMask(PCM1774_ANALOG_INPUT_SELECT, (1<<4), selectRight);
349
}
350
351
void pcm1774_gainAmplifierAnalogInput(char leftGain, char rightGain)
352
{
353
  /* leftGain and rightGain are 3-bit values as follows:
354
  0 –21 dB (default)
355
  1 –18 dB
356
  2 –15 dB
357
  3 –12 dB
358
  4 –9 dB
359
  5 –6 dB
360
  6 –3 dB
361
  7 –0 dB
362
  */
363
364
  leftGain &= 0x07;
365
  rightGain &= 0x07;
366
  pcm1774_bitMask(PCM1774_ANALOG_TO_ANALOG_PATH_GAIN, 0x77, 0);
367
  pcm1774_bitMask(PCM1774_ANALOG_TO_ANALOG_PATH_GAIN, ((rightGain<<4)|leftGain), 1);
368
}
369
370
void pcm1774_redirectAnalogInputToLeftOutput(char left, char right)
371
{
372
  char bitmask;
373
374
  bitmask = (1 << 1) | (1 << 2);
375
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, bitmask, 0);
376
377
  bitmask = (left << 1) | (right << 2);
378
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, bitmask, 1);
379
}
380
381
void pcm1774_redirectAnalogInputToRightOutput(char left, char right)
382
{
383
  char bitmask;
384
385
  bitmask = (1 << 6) | (1 << 5);
386
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, bitmask, 0);
387
388
  bitmask = (left << 6) | (right << 5);
389
  pcm1774_bitMask(PCM1774_ANALOG_MIXER_SWITCH, bitmask, 1);
390
}
391
392
static char pcm1774_getMappedLevel(int level)
393
{
394
          // -12,  -11,  -10,   -9,   -8,   -7,   -6,   -5,   -4,   -3,   -2,   -1
395
  char table[] = { 0x9B, 0x9A, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
396
            0x80, // 0
397
           //   1,    2,    3,    4,    5,    6,    7,    8,    9,   10,   11,   12
398
           0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83
399
          };
400
401
  if(level < -12 || level > 12)
402
    level = 0;
403
  level += 12;  // map level to the table
404
  return table[level];
405
}
406
407
void pcm1774_bassBoost(signed char level)
408
{
409
  pcm1774_sendByte(PCM1774_BASS_BOOST, pcm1774_getMappedLevel(level));
410
}
411
412
void pcm1774_middleBoost(signed char level)
413
{
414
  pcm1774_sendByte(PCM1774_MIDDLE_BOOST, pcm1774_getMappedLevel(level));
415
}
416
417
void pcm1774_trebleBoost(signed char level)
418
{
419
  pcm1774_sendByte(PCM1774_TREBLE_BOOST, pcm1774_getMappedLevel(level));
420
}
421
422
void pcm1774_3dSoundEffect(char narrow_or_wide, char level)
423
{
424
  // If not narrow, then set the bit for wide
425
  char wide = 0;
426
  if(!narrow_or_wide) wide = 0x10;
427
  if(level > 10) level = 10;
428
429
  if(level==0)  pcm1774_sendByte(PCM1774_SOUND_EFFECT_SOURCE_3D_SOUND, 0);
430
  else      pcm1774_bitMask(PCM1774_SOUND_EFFECT_SOURCE_3D_SOUND, (level|0x40|wide), 1);
431
}
432
433
434
435
436
437
438
439
/* USER CODE END 0 */
440
441
int main(void)
442
{
443
444
  /* USER CODE BEGIN 1 */
445
446
  /* USER CODE END 1 */
447
448
  /* MCU Configuration----------------------------------------------------------*/
449
450
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
451
  HAL_Init();
452
453
  /* Configure the system clock */
454
  SystemClock_Config();
455
456
  /* Initialize all configured peripherals */
457
  MX_GPIO_Init();
458
  MX_I2C1_Init();
459
  MX_I2S3_Init();
460
461
  /* USER CODE BEGIN 2 */
462
  //SysTick_Init();
463
  
464
  
465
  //pcm1774_Reset();
466
  char dac_init = initialize_pcm1774();
467
468
  /* USER CODE END 2 */
469
470
  /* Infinite loop */
471
  /* USER CODE BEGIN WHILE */
472
  while (1)
473
  {
474
    HAL_I2S_Transmit(&hi2s3,pcm_sound,32,1000);
475
    
476
  /* USER CODE END WHILE */
477
478
  /* USER CODE BEGIN 3 */
479
480
  }
481
  /* USER CODE END 3 */
482
483
}
484
485
/** System Clock Configuration
486
*/
487
void SystemClock_Config(void)
488
{
489
490
  RCC_OscInitTypeDef RCC_OscInitStruct;
491
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
492
  RCC_PeriphCLKInitTypeDef PeriphClkInit;
493
494
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
495
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
496
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
497
  RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_HSE;
498
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
499
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
500
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
501
  RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL_NONE;
502
  RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV2;
503
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
504
505
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
506
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
507
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
508
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
509
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
510
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
511
512
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2S3;
513
  PeriphClkInit.I2s3ClockSelection = RCC_I2S3CLKSOURCE_PLLI2S_VCO;
514
  PeriphClkInit.PLLI2S.PLLI2SMUL = RCC_PLLI2S_MUL16;
515
  PeriphClkInit.PLLI2S.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV2;
516
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
517
518
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
519
520
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
521
522
  __HAL_RCC_PLLI2S_ENABLE();
523
524
  /* SysTick_IRQn interrupt configuration */
525
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
526
}
527
528
/* I2C1 init function */
529
void MX_I2C1_Init(void)
530
{
531
532
  hi2c1.Instance = I2C1;
533
  hi2c1.Init.ClockSpeed = 100000;
534
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
535
  hi2c1.Init.OwnAddress1 = 0;
536
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
537
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
538
  hi2c1.Init.OwnAddress2 = 0;
539
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
540
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
541
  HAL_I2C_Init(&hi2c1);
542
543
}
544
545
/* I2S3 init function */
546
void MX_I2S3_Init(void)
547
{
548
549
  hi2s3.Instance = SPI3;
550
  hi2s3.Init.Mode = I2S_MODE_MASTER_TX;
551
  hi2s3.Init.Standard = I2S_STANDARD_LSB;
552
  hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
553
  hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
554
  hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_32K;
555
  hi2s3.Init.CPOL = I2S_CPOL_LOW;
556
  HAL_I2S_Init(&hi2s3);
557
558
}
559
560
/** Configure pins as 
561
        * Analog 
562
        * Input 
563
        * Output
564
        * EVENT_OUT
565
        * EXTI
566
*/
567
void MX_GPIO_Init(void)
568
{
569
570
  /* GPIO Ports Clock Enable */
571
  __HAL_RCC_GPIOD_CLK_ENABLE();
572
  __HAL_RCC_GPIOA_CLK_ENABLE();
573
  __HAL_RCC_GPIOC_CLK_ENABLE();
574
  __HAL_RCC_GPIOB_CLK_ENABLE();
575
576
}
577
578
/* USER CODE BEGIN 4 */
579
580
/* USER CODE END 4 */
581
582
#ifdef USE_FULL_ASSERT
583
584
/**
585
   * @brief Reports the name of the source file and the source line number
586
   * where the assert_param error has occurred.
587
   * @param file: pointer to the source file name
588
   * @param line: assert_param error line source number
589
   * @retval None
590
   */
591
void assert_failed(uint8_t* file, uint32_t line)
592
{
593
  /* USER CODE BEGIN 6 */
594
  /* User can add his own implementation to report the file name and line number,
595
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
596
  /* USER CODE END 6 */
597
598
}
599
600
#endif
601
602
/**
603
  * @}
604
  */ 
605
606
/**
607
  * @}
608
*/ 
609
610
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/