![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
bla
Dependencies: BSP_DISCO_F769NI
main.cpp@2:6a613cb4b302, 2017-05-28 (annotated)
- Committer:
- joschaihl
- Date:
- Sun May 28 04:03:18 2017 +0000
- Revision:
- 2:6a613cb4b302
- Parent:
- 1:361238d5a1bc
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joschaihl | 0:2e946c38e476 | 1 | #include "mbed.h" |
joschaihl | 2:6a613cb4b302 | 2 | |
joschaihl | 1:361238d5a1bc | 3 | #include "stm32f769i_discovery.h" |
joschaihl | 1:361238d5a1bc | 4 | #include "stm32f769i_discovery_ts.h" |
joschaihl | 1:361238d5a1bc | 5 | #include "stm32f769i_discovery_lcd.h" |
joschaihl | 2:6a613cb4b302 | 6 | #include "stm32f769i_discovery_audio.h" |
joschaihl | 2:6a613cb4b302 | 7 | |
joschaihl | 2:6a613cb4b302 | 8 | #include <string> // std::string |
joschaihl | 2:6a613cb4b302 | 9 | #include <iostream> // std::cout, std::ostream, std::hex |
joschaihl | 2:6a613cb4b302 | 10 | #include <sstream> // std::stringbuf |
joschaihl | 2:6a613cb4b302 | 11 | using namespace std; |
joschaihl | 1:361238d5a1bc | 12 | TS_StateTypeDef TS_State = {0}; |
joschaihl | 1:361238d5a1bc | 13 | |
joschaihl | 0:2e946c38e476 | 14 | |
joschaihl | 0:2e946c38e476 | 15 | Serial pc(USBTX, USBRX); |
joschaihl | 2:6a613cb4b302 | 16 | Serial uc(D1, D0); |
joschaihl | 0:2e946c38e476 | 17 | |
joschaihl | 0:2e946c38e476 | 18 | DigitalOut led1(LED1); |
joschaihl | 0:2e946c38e476 | 19 | |
joschaihl | 0:2e946c38e476 | 20 | void print_thread() |
joschaihl | 0:2e946c38e476 | 21 | { |
joschaihl | 0:2e946c38e476 | 22 | while (true) { |
joschaihl | 2:6a613cb4b302 | 23 | if(pc.readable()) { |
joschaihl | 2:6a613cb4b302 | 24 | uc.putc(pc.getc()); |
joschaihl | 2:6a613cb4b302 | 25 | } |
joschaihl | 2:6a613cb4b302 | 26 | if(uc.readable()) { |
joschaihl | 2:6a613cb4b302 | 27 | pc.putc(uc.getc()); |
joschaihl | 2:6a613cb4b302 | 28 | } |
joschaihl | 0:2e946c38e476 | 29 | } |
joschaihl | 0:2e946c38e476 | 30 | } |
joschaihl | 0:2e946c38e476 | 31 | |
joschaihl | 0:2e946c38e476 | 32 | void led_thread() { |
joschaihl | 0:2e946c38e476 | 33 | while(true) { |
joschaihl | 0:2e946c38e476 | 34 | Thread::wait(200); |
joschaihl | 0:2e946c38e476 | 35 | led1 = !led1; |
joschaihl | 2:6a613cb4b302 | 36 | pc.printf("Hallo LEDS\r\n"); |
joschaihl | 0:2e946c38e476 | 37 | } |
joschaihl | 0:2e946c38e476 | 38 | } |
joschaihl | 0:2e946c38e476 | 39 | |
joschaihl | 1:361238d5a1bc | 40 | void gui_thread() { |
joschaihl | 2:6a613cb4b302 | 41 | uint16_t x1, y1; |
joschaihl | 2:6a613cb4b302 | 42 | BSP_LCD_Init(); |
joschaihl | 1:361238d5a1bc | 43 | BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); |
joschaihl | 1:361238d5a1bc | 44 | |
joschaihl | 1:361238d5a1bc | 45 | /* Touchscreen initialization */ |
joschaihl | 1:361238d5a1bc | 46 | if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) { |
joschaihl | 1:361238d5a1bc | 47 | printf("BSP_TS_Init error\n"); |
joschaihl | 1:361238d5a1bc | 48 | } |
joschaihl | 1:361238d5a1bc | 49 | |
joschaihl | 1:361238d5a1bc | 50 | /* Clear the LCD */ |
joschaihl | 1:361238d5a1bc | 51 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
joschaihl | 1:361238d5a1bc | 52 | |
joschaihl | 1:361238d5a1bc | 53 | /* Set Touchscreen Demo1 description */ |
joschaihl | 1:361238d5a1bc | 54 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
joschaihl | 1:361238d5a1bc | 55 | BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40); |
joschaihl | 1:361238d5a1bc | 56 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
joschaihl | 1:361238d5a1bc | 57 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
joschaihl | 1:361238d5a1bc | 58 | BSP_LCD_SetFont(&Font24); |
joschaihl | 1:361238d5a1bc | 59 | BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen basic example", CENTER_MODE); |
joschaihl | 1:361238d5a1bc | 60 | |
joschaihl | 1:361238d5a1bc | 61 | while (1) { |
joschaihl | 1:361238d5a1bc | 62 | BSP_TS_GetState(&TS_State); |
joschaihl | 1:361238d5a1bc | 63 | if(TS_State.touchDetected) { |
joschaihl | 1:361238d5a1bc | 64 | /* One or dual touch have been detected */ |
joschaihl | 1:361238d5a1bc | 65 | |
joschaihl | 1:361238d5a1bc | 66 | /* Get X and Y position of the first touch post calibrated */ |
joschaihl | 1:361238d5a1bc | 67 | x1 = TS_State.touchX[0]; |
joschaihl | 1:361238d5a1bc | 68 | y1 = TS_State.touchY[0]; |
joschaihl | 1:361238d5a1bc | 69 | printf("Touch Detected x=%d y=%d\r\n", x1, y1); |
joschaihl | 2:6a613cb4b302 | 70 | stringbuf touchstr; |
joschaihl | 2:6a613cb4b302 | 71 | std::ostream os (&touchstr); |
joschaihl | 2:6a613cb4b302 | 72 | os << "Touch detected x=" << x1 << ", y"; // + y1; |
joschaihl | 2:6a613cb4b302 | 73 | //string touchStr = |
joschaihl | 2:6a613cb4b302 | 74 | BSP_LCD_DisplayStringAt(0, 2, (uint8_t *) touchstr.str().c_str(), LEFT_MODE); |
joschaihl | 2:6a613cb4b302 | 75 | //BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
joschaihl | 2:6a613cb4b302 | 76 | //BSP_LCD_FillCircle(x1, y1, 20); |
joschaihl | 1:361238d5a1bc | 77 | |
joschaihl | 1:361238d5a1bc | 78 | Thread::wait(10); |
joschaihl | 1:361238d5a1bc | 79 | } |
joschaihl | 1:361238d5a1bc | 80 | } |
joschaihl | 1:361238d5a1bc | 81 | } |
joschaihl | 1:361238d5a1bc | 82 | |
joschaihl | 2:6a613cb4b302 | 83 | |
joschaihl | 2:6a613cb4b302 | 84 | |
joschaihl | 2:6a613cb4b302 | 85 | const uint16_t BSIZE = 10000; |
joschaihl | 2:6a613cb4b302 | 86 | uint16_t buf[BSIZE]; |
joschaihl | 2:6a613cb4b302 | 87 | |
joschaihl | 2:6a613cb4b302 | 88 | |
joschaihl | 2:6a613cb4b302 | 89 | |
joschaihl | 2:6a613cb4b302 | 90 | |
joschaihl | 2:6a613cb4b302 | 91 | void audio_thread(Thread *thisThread) |
joschaihl | 2:6a613cb4b302 | 92 | { |
joschaihl | 2:6a613cb4b302 | 93 | for(int i = 0; i < BSIZE; i++) { |
joschaihl | 2:6a613cb4b302 | 94 | // buf[i] = i*2; |
joschaihl | 2:6a613cb4b302 | 95 | } |
joschaihl | 2:6a613cb4b302 | 96 | /* const uint32_t SCRATCH_BUFF_SIZE = 128; |
joschaihl | 2:6a613cb4b302 | 97 | const uint32_t RECORD_BUFFER_SIZE = 512; |
joschaihl | 2:6a613cb4b302 | 98 | |
joschaihl | 2:6a613cb4b302 | 99 | typedef enum { |
joschaihl | 2:6a613cb4b302 | 100 | BUFFER_OFFSET_NONE = 0, |
joschaihl | 2:6a613cb4b302 | 101 | BUFFER_OFFSET_HALF = 1, |
joschaihl | 2:6a613cb4b302 | 102 | BUFFER_OFFSET_FULL = 2, |
joschaihl | 2:6a613cb4b302 | 103 | } BUFFER_StateTypeDef; |
joschaihl | 2:6a613cb4b302 | 104 | */ |
joschaihl | 2:6a613cb4b302 | 105 | //olatile uint32_t audio_rec_buffer_state = BUFFER_OFFSET_NONE; |
joschaihl | 2:6a613cb4b302 | 106 | //int32_t Scratch[SCRATCH_BUFF_SIZE]; |
joschaihl | 2:6a613cb4b302 | 107 | /* Buffer containing the PCM samples coming from the microphone */ |
joschaihl | 2:6a613cb4b302 | 108 | //int16_t RecordBuffer[RECORD_BUFFER_SIZE]; |
joschaihl | 2:6a613cb4b302 | 109 | /* Buffer used to stream the recorded PCM samples towards the audio codec. */ |
joschaihl | 2:6a613cb4b302 | 110 | |
joschaihl | 2:6a613cb4b302 | 111 | // uint32_t audio_loop_back_init = RESET ; |
joschaihl | 2:6a613cb4b302 | 112 | |
joschaihl | 2:6a613cb4b302 | 113 | pc.printf("Stacksize audiothread = %d\r\n", thisThread->stack_size()); |
joschaihl | 2:6a613cb4b302 | 114 | pc.printf("Stacksize audiothread max = %d\r\n", thisThread->max_stack()); |
joschaihl | 2:6a613cb4b302 | 115 | printf("\n\nAUDIO LOOPBACK EXAMPLE FOR DISCO-F769NI START:\n"); |
joschaihl | 2:6a613cb4b302 | 116 | |
joschaihl | 2:6a613cb4b302 | 117 | BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 100, AUDIO_FREQUENCY_48K); |
joschaihl | 2:6a613cb4b302 | 118 | |
joschaihl | 2:6a613cb4b302 | 119 | BSP_AUDIO_OUT_Play(buf, BSIZE); |
joschaihl | 2:6a613cb4b302 | 120 | while(1) { |
joschaihl | 2:6a613cb4b302 | 121 | |
joschaihl | 2:6a613cb4b302 | 122 | } |
joschaihl | 2:6a613cb4b302 | 123 | // const REAL_TIME_FREQUENCY = 220; |
joschaihl | 2:6a613cb4b302 | 124 | //const ANGULAR_FREQUENCY = REAL_TIME_FREQUENCY * 2 * Math.PI; |
joschaihl | 2:6a613cb4b302 | 125 | |
joschaihl | 2:6a613cb4b302 | 126 | /* Initialize Audio Recorder with 4 channels to be used */ |
joschaihl | 2:6a613cb4b302 | 127 | /* if (BSP_AUDIO_IN_AllocScratch(Scratch, SCRATCH_BUFF_SIZE) == AUDIO_OK) { |
joschaihl | 2:6a613cb4b302 | 128 | printf("Scratch allokiert mit %d\r\n", SCRATCH_BUFF_SIZE); |
joschaihl | 2:6a613cb4b302 | 129 | if(BSP_AUDIO_IN_Record(RecordBuffer, RECORD_BUFFER_SIZE)==AUDIO_OK) { |
joschaihl | 2:6a613cb4b302 | 130 | printf("RecordBuffer initialisiert\r\n"); |
joschaihl | 2:6a613cb4b302 | 131 | if(BSP_AUDIO_IN_Init(BSP_AUDIO_FREQUENCY_44K, 16, 1) == AUDIO_OK ) { |
joschaihl | 2:6a613cb4b302 | 132 | printf("BSP_AUDIO_IN_AllocScratch\n"); |
joschaihl | 2:6a613cb4b302 | 133 | |
joschaihl | 2:6a613cb4b302 | 134 | while (1) { |
joschaihl | 2:6a613cb4b302 | 135 | |
joschaihl | 2:6a613cb4b302 | 136 | } |
joschaihl | 2:6a613cb4b302 | 137 | } |
joschaihl | 2:6a613cb4b302 | 138 | } |
joschaihl | 2:6a613cb4b302 | 139 | }*/ |
joschaihl | 2:6a613cb4b302 | 140 | } |
joschaihl | 2:6a613cb4b302 | 141 | |
joschaihl | 0:2e946c38e476 | 142 | int main() |
joschaihl | 0:2e946c38e476 | 143 | { |
joschaihl | 2:6a613cb4b302 | 144 | pc.baud(115200); |
joschaihl | 2:6a613cb4b302 | 145 | pc.printf("\f*** Joscha ***\r\n"); |
joschaihl | 2:6a613cb4b302 | 146 | |
joschaihl | 2:6a613cb4b302 | 147 | |
joschaihl | 2:6a613cb4b302 | 148 | |
joschaihl | 2:6a613cb4b302 | 149 | |
joschaihl | 2:6a613cb4b302 | 150 | //pc.printf("\tCreating printthread...\n"); |
joschaihl | 2:6a613cb4b302 | 151 | //Thread printThread(print_thread, NULL, osPriorityRealtime ); |
joschaihl | 2:6a613cb4b302 | 152 | |
joschaihl | 2:6a613cb4b302 | 153 | //pc.printf("\tCreating ledthread...\r\n"); |
joschaihl | 2:6a613cb4b302 | 154 | //Thread ledThrea |
joschaihl | 2:6a613cb4b302 | 155 | |
joschaihl | 0:2e946c38e476 | 156 | |
joschaihl | 0:2e946c38e476 | 157 | |
joschaihl | 2:6a613cb4b302 | 158 | |
joschaihl | 2:6a613cb4b302 | 159 | |
joschaihl | 2:6a613cb4b302 | 160 | /* pc.printf("\tCreating ledthread...\n"); |
joschaihl | 2:6a613cb4b302 | 161 | Thread ledThread(osPriorityRealtime); |
joschaihl | 2:6a613cb4b302 | 162 | ledThread.start(&led_thread);*/ |
joschaihl | 2:6a613cb4b302 | 163 | |
joschaihl | 2:6a613cb4b302 | 164 | |
joschaihl | 1:361238d5a1bc | 165 | |
joschaihl | 2:6a613cb4b302 | 166 | /* pc.printf("\tCreating guithread...\n"); |
joschaihl | 2:6a613cb4b302 | 167 | Thread guiThread(osPriorityHigh); |
joschaihl | 2:6a613cb4b302 | 168 | guiThread.start(&gui_thread);*/ |
joschaihl | 2:6a613cb4b302 | 169 | |
joschaihl | 2:6a613cb4b302 | 170 | pc.printf("\tCreating audiothread...\r\n"); |
joschaihl | 2:6a613cb4b302 | 171 | Thread audioThread(osPriorityRealtime); |
joschaihl | 2:6a613cb4b302 | 172 | audioThread.start(&audio_thread, &audioThread); |
joschaihl | 2:6a613cb4b302 | 173 | |
joschaihl | 2:6a613cb4b302 | 174 | |
joschaihl | 2:6a613cb4b302 | 175 | |
joschaihl | 2:6a613cb4b302 | 176 | |
joschaihl | 2:6a613cb4b302 | 177 | while(true) { |
joschaihl | 1:361238d5a1bc | 178 | } |
joschaihl | 0:2e946c38e476 | 179 | |
joschaihl | 1:361238d5a1bc | 180 | |
joschaihl | 0:2e946c38e476 | 181 | } |