Hallo,
ich sammle gerade meine erste ersten Erfahrungen mit Mikrocontrollern
und habe mir dafür das Board STM32 F4 Discovery Board 29zit ausgesucht.
Als Programmiersprache verwende ich C++.
Mein Ziel ist es Bilder und Animationen auf dem auf dem Board verbauten
Display anzuzeigen. Aktuell habe ich das Problem, dass meine Funktion
drawPixel(int const x, int const y, int const color) zwei statt einem
Pixel zeichnet.
Mein allgemeines Vorgehen:
- SDRAM initalisiert
- SPI initialisiert (Für die Ili9341 InitSequence)
- Ili9341 initialisiert
- LTDC initalisiert
- Layer 1 von 2 erstellt mit der Abmessung des Displays
- Funktion zum Setzten eines Pixels
Mein Code:
1 |
|
2 | static constexpr int const width = 240U;
|
3 | static constexpr int const height = 320U;
|
4 |
|
5 | static constexpr int const hSync = 10;
|
6 | static constexpr int const vSync = 2;
|
7 | static constexpr int const horBackPorch = 20;
|
8 | static constexpr int const verBackPorch = 2;
|
9 | static constexpr int const horFrntPorch = 10;
|
10 | static constexpr int const verFrntPorch = 4;
|
11 | static constexpr unsigned const horTotal = hSync + horBackPorch + width + horFrntPorch;
|
12 | static constexpr unsigned const verTotal = vSync + verBackPorch + height + verFrntPorch;
|
13 |
|
14 | //Setze Display-Maße
|
15 | ltdc.SSCR = ((hSync - 1) << INDX_LTDC_SSCR_HSW) | ((vSync - 1) << INDX_LTDC_SSCR_VSH);
|
16 | ltdc.BPCR = ((hSync + horBackPorch - 1) << INDX_LTDC_BPCR_AHBP) | ((vSync + verBackPorch - 1) << INDX_LTDC_BPCR_AVBP);
|
17 | ltdc.AWCR = ((hSync + horBackPorch + width - 1) << INDX_LTDC_AWCR_AAW) | ((vSync + verBackPorch + height - 1) << INDX_LTDC_AWCR_AAH);
|
18 | ltdc.TWCR = ((verTotal - 1) << INDX_LTDC_TWCR_TOTALH) | ((horTotal - 1) << INDX_LTDC_TWCR_TOTALW);
|
19 |
|
20 | //Hintergrundfarbe Schwarz
|
21 | ltdc.BCCR = (0x000000);
|
22 |
|
23 | //Aktiviere Imitiate Reload
|
24 | ltdc.SRCR |= MASK_LTDC_SRCR_IMR;
|
25 |
|
26 | //Setze FrameBuffer (externer SDRAM)
|
27 | layer.CFBAR = 0xD0000000;
|
28 | layer.CFBLR |= (width * 2) << 16 | (width * 2 + 3); //*2 = PixelSize von RGB565
|
29 | layer.CFBLNR |= height;
|
30 |
|
31 | //Setze Pixelformat
|
32 | layer.PFCR |= MASK_LTDC_Lx_PFCR_RGB565;
|
33 |
|
34 | //Setze Transparenz (Keine)
|
35 | layer.CACR = 255;
|
36 |
|
37 | //Setze Layergröße auf Displaygröße
|
38 | layer.WHPCR = hSync+horBackPorch+width-1 << INDX_LTDC_Lx_WHPCR_WHSPPOS | hSync+horBackPorch;
|
39 | layer.WVPCR = vSync+verBackPorch+height-1 << INDX_LTDC_Lx_WVPCR_WVSPPOS | vSync+verBackPorch;
|
40 |
|
41 | //Aktiviere die erste Layer
|
42 | layer.CR |= MASK_LTDC_Lx_CR_LEN;
|
43 |
|
44 | //Aktiviere den LTDC
|
45 | ltdc.GCR |= MASK_LTDC_GCR_LTDCEN;
|
46 |
|
47 | //Setze den ersten Pixel des Displays weiß.
|
48 | int x = 0;
|
49 | int y = 0;
|
50 | *((uint32_t *) 0xD0000000 + (x + y * width)) = 0xFFFF;
|
51 | //Resultat: Die ersten 2 Pixel sind weiß. Unabhängig vom x und y werden immer zwei Pixel gesetzt.
|
Ich kann an jede Stelle des Displays einen Pixel setzen, allerdings wird
der Pixel rechts daneben auch gesetzt. Habe ich evtl etwas falsch
konfiguriert?
Ich hoffe mir kann jemand helfen, ich bin am verzweifeln :-).