
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
main.cpp@6:e689075b04ed, 2019-12-28 (annotated)
- Committer:
- bmazzeo
- Date:
- Sat Dec 28 18:50:08 2019 +0000
- Revision:
- 6:e689075b04ed
- Parent:
- 5:66c230f74325
- Child:
- 7:e1dfd64eba81
First working version with graphics and some display of audio numbers.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adustm | 0:da04816fb411 | 1 | #include "mbed.h" |
Jerome Coutant
5:66c230f74325
|
2
|
#include "stm32746g_discovery_audio.h"
|
|
Jerome Coutant
5:66c230f74325
|
3
|
#include "stm32746g_discovery_sdram.h"
|
|
bmazzeo | 6:e689075b04ed | 4 | #include "stm32746g_discovery_lcd.h" |
adustm | 0:da04816fb411 | 5 | |
Jerome Coutant
5:66c230f74325
|
6
|
typedef enum {
|
|
adustm | 0:da04816fb411 | 7 | BUFFER_OFFSET_NONE = 0, |
adustm | 0:da04816fb411 | 8 | BUFFER_OFFSET_HALF = 1, |
adustm | 0:da04816fb411 | 9 | BUFFER_OFFSET_FULL = 2, |
Jerome Coutant
5:66c230f74325
|
10
|
} BUFFER_StateTypeDef;
|
|
Jerome Coutant
5:66c230f74325
|
11
|
|
|
adustm | 0:da04816fb411 | 12 | |
bmazzeo | 6:e689075b04ed | 13 | // #define AUDIO_BLOCK_SIZE ((uint32_t)512) |
bmazzeo | 6:e689075b04ed | 14 | #define AUDIO_BLOCK_SIZE ((uint32_t)256) |
bmazzeo | 6:e689075b04ed | 15 | |
bmazzeo | 6:e689075b04ed | 16 | #define SDRAM_DEVICE_ADDR_AUDIO_MEM ((uint32_t)0xC00A0000) |
bmazzeo | 6:e689075b04ed | 17 | #define AUDIO_BUFFER_IN SDRAM_DEVICE_ADDR_AUDIO_MEM |
Jerome Coutant
5:66c230f74325
|
18
|
#define AUDIO_BUFFER_OUT (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE * 2))
|
|
Jerome Coutant
5:66c230f74325
|
19
|
|
|
bmazzeo | 6:e689075b04ed | 20 | #define OSC_START_X_POS 10 |
bmazzeo | 6:e689075b04ed | 21 | #define OSC_LINE_SIZE 256 |
bmazzeo | 6:e689075b04ed | 22 | #define L_CHANNEL_Y_POS 120 |
bmazzeo | 6:e689075b04ed | 23 | #define R_CHANNEL_Y_POS 220 |
bmazzeo | 6:e689075b04ed | 24 | |
Jerome Coutant
5:66c230f74325
|
25
|
volatile uint32_t audio_rec_buffer_state = BUFFER_OFFSET_NONE;
|
|
bmazzeo | 6:e689075b04ed | 26 | static void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint32_t Mem_start, uint16_t Length); |
Jerome Coutant
5:66c230f74325
|
27
|
|
|
adustm | 0:da04816fb411 | 28 | int main() |
adustm | 0:da04816fb411 | 29 | { |
bmazzeo | 6:e689075b04ed | 30 | |
bmazzeo | 6:e689075b04ed | 31 | BSP_LCD_Init(); |
bmazzeo | 6:e689075b04ed | 32 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
bmazzeo | 6:e689075b04ed | 33 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
bmazzeo | 6:e689075b04ed | 34 | |
bmazzeo | 6:e689075b04ed | 35 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
bmazzeo | 6:e689075b04ed | 36 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
bmazzeo | 6:e689075b04ed | 37 | |
bmazzeo | 6:e689075b04ed | 38 | |
bmazzeo | 6:e689075b04ed | 39 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
bmazzeo | 6:e689075b04ed | 40 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
bmazzeo | 6:e689075b04ed | 41 | BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"487 Audio Loopback Test Code", LEFT_MODE); |
bmazzeo | 6:e689075b04ed | 42 | |
Jerome Coutant
5:66c230f74325
|
43
|
printf("\n\nAUDIO LOOPBACK EXAMPLE START:\n");
|
|
Jerome Coutant
5:66c230f74325
|
44
|
|
|
Jerome Coutant
5:66c230f74325
|
45
|
BSP_AUDIO_IN_OUT_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, OUTPUT_DEVICE_HEADPHONE, DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR);
|
|
Jerome Coutant
5:66c230f74325
|
46
|
printf("AUDIO loop from digital micro (U20 & U21 components on board) to headphone (CN10 jack connector)\n");
|
|
Jerome Coutant
5:66c230f74325
|
47
|
|
|
bmazzeo | 6:e689075b04ed | 48 | BSP_LCD_DisplayStringAt(10, 20, (uint8_t *)"SDRAM Initialization", LEFT_MODE); |
bmazzeo | 6:e689075b04ed | 49 | |
adustm | 0:da04816fb411 | 50 | |
adustm | 0:da04816fb411 | 51 | /* Initialize SDRAM buffers */ |
Jerome Coutant
5:66c230f74325
|
52
|
BSP_SDRAM_Init();
|
|
Jerome Coutant
5:66c230f74325
|
53
|
memset((uint16_t *)AUDIO_BUFFER_IN, 0, AUDIO_BLOCK_SIZE * 2);
|
|
Jerome Coutant
5:66c230f74325
|
54
|
memset((uint16_t *)AUDIO_BUFFER_OUT, 0, AUDIO_BLOCK_SIZE * 2);
|
|
Jerome Coutant
5:66c230f74325
|
55
|
printf("SDRAM init done\n");
|
|
Jerome Coutant
5:66c230f74325
|
56
|
|
|
adustm | 0:da04816fb411 | 57 | audio_rec_buffer_state = BUFFER_OFFSET_NONE; |
adustm | 0:da04816fb411 | 58 | |
adustm | 0:da04816fb411 | 59 | /* Start Recording */ |
Jerome Coutant
5:66c230f74325
|
60
|
if (BSP_AUDIO_IN_Record((uint16_t *)AUDIO_BUFFER_IN, AUDIO_BLOCK_SIZE) != AUDIO_OK) {
|
|
Jerome Coutant
5:66c230f74325
|
61
|
printf("BSP_AUDIO_IN_Record error\n");
|
|
Jerome Coutant
5:66c230f74325
|
62
|
}
|
|
adustm | 0:da04816fb411 | 63 | |
adustm | 0:da04816fb411 | 64 | /* Start Playback */ |
Jerome Coutant
5:66c230f74325
|
65
|
BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
|
|
Jerome Coutant
5:66c230f74325
|
66
|
if (BSP_AUDIO_OUT_Play((uint16_t *)AUDIO_BUFFER_OUT, AUDIO_BLOCK_SIZE * 2) != AUDIO_OK) {
|
|
Jerome Coutant
5:66c230f74325
|
67
|
printf("BSP_AUDIO_OUT_Play error\n");
|
|
Jerome Coutant
5:66c230f74325
|
68
|
}
|
|
adustm | 0:da04816fb411 | 69 | |
bmazzeo | 6:e689075b04ed | 70 | |
bmazzeo | 6:e689075b04ed | 71 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
bmazzeo | 6:e689075b04ed | 72 | uint32_t counter; |
bmazzeo | 6:e689075b04ed | 73 | counter = 0; |
bmazzeo | 6:e689075b04ed | 74 | |
bmazzeo | 6:e689075b04ed | 75 | char buf[10]; |
bmazzeo | 6:e689075b04ed | 76 | |
adustm | 0:da04816fb411 | 77 | while (1) { |
bmazzeo | 6:e689075b04ed | 78 | /* First Half */ |
bmazzeo | 6:e689075b04ed | 79 | |
adustm | 0:da04816fb411 | 80 | /* Wait end of half block recording */ |
Jerome Coutant
5:66c230f74325
|
81
|
while (audio_rec_buffer_state == BUFFER_OFFSET_HALF) {
|
|
adustm | 0:da04816fb411 | 82 | } |
adustm | 0:da04816fb411 | 83 | audio_rec_buffer_state = BUFFER_OFFSET_NONE; |
Jerome Coutant
5:66c230f74325
|
84
|
|
|
adustm | 0:da04816fb411 | 85 | /* Copy recorded 1st half block */ |
adustm | 0:da04816fb411 | 86 | memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE); |
Jerome Coutant
5:66c230f74325
|
87
|
|
|
bmazzeo | 6:e689075b04ed | 88 | /* Second Half */ |
bmazzeo | 6:e689075b04ed | 89 | |
adustm | 0:da04816fb411 | 90 | /* Wait end of one block recording */ |
Jerome Coutant
5:66c230f74325
|
91
|
while (audio_rec_buffer_state == BUFFER_OFFSET_FULL) {
|
|
adustm | 0:da04816fb411 | 92 | } |
adustm | 0:da04816fb411 | 93 | audio_rec_buffer_state = BUFFER_OFFSET_NONE; |
Jerome Coutant
5:66c230f74325
|
94
|
|
|
adustm | 0:da04816fb411 | 95 | /* Copy recorded 2nd half block */ |
adustm | 0:da04816fb411 | 96 | memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE); |
bmazzeo | 6:e689075b04ed | 97 | |
bmazzeo | 6:e689075b04ed | 98 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
bmazzeo | 6:e689075b04ed | 99 | BSP_LCD_DrawHLine(OSC_START_X_POS, L_CHANNEL_Y_POS, OSC_LINE_SIZE); |
bmazzeo | 6:e689075b04ed | 100 | BSP_LCD_DrawHLine(OSC_START_X_POS, R_CHANNEL_Y_POS, OSC_LINE_SIZE); |
bmazzeo | 6:e689075b04ed | 101 | |
bmazzeo | 6:e689075b04ed | 102 | Draw_Trace(OSC_START_X_POS, L_CHANNEL_Y_POS, AUDIO_BUFFER_OUT, 256); |
bmazzeo | 6:e689075b04ed | 103 | |
bmazzeo | 6:e689075b04ed | 104 | counter++; |
bmazzeo | 6:e689075b04ed | 105 | sprintf(buf, "%d", counter); |
bmazzeo | 6:e689075b04ed | 106 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
bmazzeo | 6:e689075b04ed | 107 | BSP_LCD_DisplayStringAt(0, 40, (uint8_t *) buf, LEFT_MODE); |
adustm | 0:da04816fb411 | 108 | } |
adustm | 0:da04816fb411 | 109 | } |
Jerome Coutant
5:66c230f74325
|
110
|
|
|
Jerome Coutant
5:66c230f74325
|
111
|
|
|
bmazzeo | 6:e689075b04ed | 112 | /** |
bmazzeo | 6:e689075b04ed | 113 | * @brief Draws a trace of the data line. |
bmazzeo | 6:e689075b04ed | 114 | * @param Xpos: X position |
bmazzeo | 6:e689075b04ed | 115 | * @param Ypos: Y position |
bmazzeo | 6:e689075b04ed | 116 | * @param Mem_start: Start of memory location |
bmazzeo | 6:e689075b04ed | 117 | * @param Length: length of trace |
bmazzeo | 6:e689075b04ed | 118 | * @retval None |
bmazzeo | 6:e689075b04ed | 119 | */ |
bmazzeo | 6:e689075b04ed | 120 | void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint32_t Mem_start, uint16_t Length) |
bmazzeo | 6:e689075b04ed | 121 | { |
bmazzeo | 6:e689075b04ed | 122 | uint32_t i; |
bmazzeo | 6:e689075b04ed | 123 | int data_value; |
bmazzeo | 6:e689075b04ed | 124 | char buf[12]; |
bmazzeo | 6:e689075b04ed | 125 | |
bmazzeo | 6:e689075b04ed | 126 | sprintf(buf, "%12d", *((uint32_t*) Mem_start)); |
bmazzeo | 6:e689075b04ed | 127 | BSP_LCD_DisplayStringAt(0, 60, (uint8_t *) buf, LEFT_MODE); |
bmazzeo | 6:e689075b04ed | 128 | |
bmazzeo | 6:e689075b04ed | 129 | sprintf(buf, "%12d", *((uint32_t*) Mem_start+1)); |
bmazzeo | 6:e689075b04ed | 130 | BSP_LCD_DisplayStringAt(0, 80, (uint8_t *) buf, LEFT_MODE); |
bmazzeo | 6:e689075b04ed | 131 | |
bmazzeo | 6:e689075b04ed | 132 | sprintf(buf, "%12d", *((uint32_t*) Mem_start+2)); |
bmazzeo | 6:e689075b04ed | 133 | BSP_LCD_DisplayStringAt(0, 100, (uint8_t *) buf, LEFT_MODE); |
bmazzeo | 6:e689075b04ed | 134 | /* |
bmazzeo | 6:e689075b04ed | 135 | |
bmazzeo | 6:e689075b04ed | 136 | for (i=1; i<=Length; i++) |
bmazzeo | 6:e689075b04ed | 137 | { |
bmazzeo | 6:e689075b04ed | 138 | data_value = *((uint32_t*) (Mem_start + i)); |
bmazzeo | 6:e689075b04ed | 139 | BSP_LCD_DrawPixel(Xpos + i, int16_t((int) Ypos + data_value), LCD_COLOR_WHITE); |
bmazzeo | 6:e689075b04ed | 140 | } |
bmazzeo | 6:e689075b04ed | 141 | */ |
bmazzeo | 6:e689075b04ed | 142 | |
bmazzeo | 6:e689075b04ed | 143 | } |
bmazzeo | 6:e689075b04ed | 144 | |
bmazzeo | 6:e689075b04ed | 145 | /* Read data value from SDRAM memory */ |
bmazzeo | 6:e689075b04ed | 146 | // ret = *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))); |
bmazzeo | 6:e689075b04ed | 147 | |
bmazzeo | 6:e689075b04ed | 148 | |
adustm | 0:da04816fb411 | 149 | /*------------------------------------------------------------------------------------- |
adustm | 0:da04816fb411 | 150 | Callbacks implementation: |
adustm | 0:da04816fb411 | 151 | the callbacks API are defined __weak in the stm32746g_discovery_audio.c file |
adustm | 0:da04816fb411 | 152 | and their implementation should be done in the user code if they are needed. |
adustm | 0:da04816fb411 | 153 | Below some examples of callback implementations. |
adustm | 0:da04816fb411 | 154 | -------------------------------------------------------------------------------------*/ |
adustm | 0:da04816fb411 | 155 | /** |
adustm | 0:da04816fb411 | 156 | * @brief Manages the DMA Transfer complete interrupt. |
adustm | 0:da04816fb411 | 157 | * @param None |
adustm | 0:da04816fb411 | 158 | * @retval None |
adustm | 0:da04816fb411 | 159 | */ |
adustm | 0:da04816fb411 | 160 | void BSP_AUDIO_IN_TransferComplete_CallBack(void) |
adustm | 0:da04816fb411 | 161 | { |
Jerome Coutant
5:66c230f74325
|
162
|
audio_rec_buffer_state = BUFFER_OFFSET_FULL;
|
|
adustm | 0:da04816fb411 | 163 | } |
adustm | 0:da04816fb411 | 164 | |
adustm | 0:da04816fb411 | 165 | /** |
adustm | 0:da04816fb411 | 166 | * @brief Manages the DMA Half Transfer complete interrupt. |
adustm | 0:da04816fb411 | 167 | * @param None |
adustm | 0:da04816fb411 | 168 | * @retval None |
adustm | 0:da04816fb411 | 169 | */ |
adustm | 0:da04816fb411 | 170 | void BSP_AUDIO_IN_HalfTransfer_CallBack(void) |
adustm | 0:da04816fb411 | 171 | { |
Jerome Coutant
5:66c230f74325
|
172
|
audio_rec_buffer_state = BUFFER_OFFSET_HALF;
|
|
adustm | 0:da04816fb411 | 173 | } |
adustm | 0:da04816fb411 | 174 | |
Jerome Coutant
5:66c230f74325
|
175
|
/**
|
|
Jerome Coutant
5:66c230f74325
|
176
|
* @brief Audio IN Error callback function.
|
|
Jerome Coutant
5:66c230f74325
|
177
|
* @param None
|
|
Jerome Coutant
5:66c230f74325
|
178
|
* @retval None
|
|
Jerome Coutant
5:66c230f74325
|
179
|
*/
|
|
Jerome Coutant
5:66c230f74325
|
180
|
void BSP_AUDIO_IN_Error_CallBack(void)
|
|
adustm | 0:da04816fb411 | 181 | { |
Jerome Coutant
5:66c230f74325
|
182
|
printf("BSP_AUDIO_IN_Error_CallBack\n");
|
|
adustm | 0:da04816fb411 | 183 | } |