
Semafor
Dependencies: BSP_DISCO_F746NG
main.cpp@0:96b25ebf5df8, 2020-12-16 (annotated)
- Committer:
- iliatumash
- Date:
- Wed Dec 16 21:18:17 2020 +0000
- Revision:
- 0:96b25ebf5df8
Semafor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iliatumash | 0:96b25ebf5df8 | 1 | #include "mbed.h" |
iliatumash | 0:96b25ebf5df8 | 2 | #include "stm32746g_discovery_lcd.h" |
iliatumash | 0:96b25ebf5df8 | 3 | #include "stm32746g_discovery_ts.h" |
iliatumash | 0:96b25ebf5df8 | 4 | #include <Semaphore.h> |
iliatumash | 0:96b25ebf5df8 | 5 | |
iliatumash | 0:96b25ebf5df8 | 6 | |
iliatumash | 0:96b25ebf5df8 | 7 | Semaphore semafor(1); |
iliatumash | 0:96b25ebf5df8 | 8 | Thread thread0, thread1, thread2; |
iliatumash | 0:96b25ebf5df8 | 9 | bool touch = false; |
iliatumash | 0:96b25ebf5df8 | 10 | |
iliatumash | 0:96b25ebf5df8 | 11 | void test_thread0() |
iliatumash | 0:96b25ebf5df8 | 12 | { |
iliatumash | 0:96b25ebf5df8 | 13 | while (true) { |
iliatumash | 0:96b25ebf5df8 | 14 | semafor.acquire(); |
iliatumash | 0:96b25ebf5df8 | 15 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); |
iliatumash | 0:96b25ebf5df8 | 16 | BSP_LCD_SetBackColor(LCD_COLOR_DARKBLUE); |
iliatumash | 0:96b25ebf5df8 | 17 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
iliatumash | 0:96b25ebf5df8 | 18 | BSP_LCD_DisplayStringAt(0, 50, (uint8_t *)"Jsem vlakno 1", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 19 | BSP_LCD_DisplayStringAt(0, 80, (uint8_t *)"Stiskni displej", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 20 | } |
iliatumash | 0:96b25ebf5df8 | 21 | } |
iliatumash | 0:96b25ebf5df8 | 22 | |
iliatumash | 0:96b25ebf5df8 | 23 | void test_thread1() |
iliatumash | 0:96b25ebf5df8 | 24 | { |
iliatumash | 0:96b25ebf5df8 | 25 | while (true) { |
iliatumash | 0:96b25ebf5df8 | 26 | semafor.acquire(); |
iliatumash | 0:96b25ebf5df8 | 27 | BSP_LCD_Clear(LCD_COLOR_BLUE); |
iliatumash | 0:96b25ebf5df8 | 28 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
iliatumash | 0:96b25ebf5df8 | 29 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
iliatumash | 0:96b25ebf5df8 | 30 | BSP_LCD_DisplayStringAt(0, 50, (uint8_t *)"Jsem vlakno 2", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 31 | BSP_LCD_DisplayStringAt(0, 80, (uint8_t *)"Stiskni displej", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 32 | } |
iliatumash | 0:96b25ebf5df8 | 33 | } |
iliatumash | 0:96b25ebf5df8 | 34 | |
iliatumash | 0:96b25ebf5df8 | 35 | void test_thread2() |
iliatumash | 0:96b25ebf5df8 | 36 | { |
iliatumash | 0:96b25ebf5df8 | 37 | while (true) { |
iliatumash | 0:96b25ebf5df8 | 38 | semafor.acquire(); |
iliatumash | 0:96b25ebf5df8 | 39 | BSP_LCD_Clear(LCD_COLOR_LIGHTBLUE); |
iliatumash | 0:96b25ebf5df8 | 40 | BSP_LCD_SetBackColor(LCD_COLOR_LIGHTBLUE); |
iliatumash | 0:96b25ebf5df8 | 41 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
iliatumash | 0:96b25ebf5df8 | 42 | BSP_LCD_DisplayStringAt(0, 50, (uint8_t *)"Jsem vlakno 3", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 43 | BSP_LCD_DisplayStringAt(0, 80, (uint8_t *)"Stiskni displej", CENTER_MODE); |
iliatumash | 0:96b25ebf5df8 | 44 | } |
iliatumash | 0:96b25ebf5df8 | 45 | } |
iliatumash | 0:96b25ebf5df8 | 46 | |
iliatumash | 0:96b25ebf5df8 | 47 | void display(){ |
iliatumash | 0:96b25ebf5df8 | 48 | BSP_LCD_Init(); |
iliatumash | 0:96b25ebf5df8 | 49 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
iliatumash | 0:96b25ebf5df8 | 50 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
iliatumash | 0:96b25ebf5df8 | 51 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); |
iliatumash | 0:96b25ebf5df8 | 52 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
iliatumash | 0:96b25ebf5df8 | 53 | BSP_LCD_SetBackColor(LCD_COLOR_BLUE); |
iliatumash | 0:96b25ebf5df8 | 54 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
iliatumash | 0:96b25ebf5df8 | 55 | } |
iliatumash | 0:96b25ebf5df8 | 56 | |
iliatumash | 0:96b25ebf5df8 | 57 | void touchScreen(){ |
iliatumash | 0:96b25ebf5df8 | 58 | TS_StateTypeDef TS_State; |
iliatumash | 0:96b25ebf5df8 | 59 | uint8_t status; |
iliatumash | 0:96b25ebf5df8 | 60 | status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
iliatumash | 0:96b25ebf5df8 | 61 | while(1) { |
iliatumash | 0:96b25ebf5df8 | 62 | BSP_TS_GetState(&TS_State); |
iliatumash | 0:96b25ebf5df8 | 63 | if (TS_State.touchDetected) { |
iliatumash | 0:96b25ebf5df8 | 64 | if(!touch) { |
iliatumash | 0:96b25ebf5df8 | 65 | touch = true; |
iliatumash | 0:96b25ebf5df8 | 66 | semafor.release(); |
iliatumash | 0:96b25ebf5df8 | 67 | } |
iliatumash | 0:96b25ebf5df8 | 68 | }else{ |
iliatumash | 0:96b25ebf5df8 | 69 | touch = false; |
iliatumash | 0:96b25ebf5df8 | 70 | } |
iliatumash | 0:96b25ebf5df8 | 71 | } |
iliatumash | 0:96b25ebf5df8 | 72 | } |
iliatumash | 0:96b25ebf5df8 | 73 | |
iliatumash | 0:96b25ebf5df8 | 74 | |
iliatumash | 0:96b25ebf5df8 | 75 | int main(){ |
iliatumash | 0:96b25ebf5df8 | 76 | display(); |
iliatumash | 0:96b25ebf5df8 | 77 | thread0.start(test_thread0); |
iliatumash | 0:96b25ebf5df8 | 78 | thread1.start(test_thread1); |
iliatumash | 0:96b25ebf5df8 | 79 | thread2.start(test_thread2); |
iliatumash | 0:96b25ebf5df8 | 80 | touchScreen(); |
iliatumash | 0:96b25ebf5df8 | 81 | while(1){ |
iliatumash | 0:96b25ebf5df8 | 82 | |
iliatumash | 0:96b25ebf5df8 | 83 | } |
iliatumash | 0:96b25ebf5df8 | 84 | } |