|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2017, Niklas Hauser |
| 3 | + * |
| 4 | + * This file is part of the modm project. |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + */ |
| 10 | +// ---------------------------------------------------------------------------- |
| 11 | + |
| 12 | +#include <modm/board.hpp> |
| 13 | +#include <modm/platform/clock/rcc.hpp> |
| 14 | + |
| 15 | +extern void |
| 16 | +nt35510_init(uint8_t); |
| 17 | + |
| 18 | +// ---------------------------------- DISPLAY ---------------------------------- |
| 19 | +void |
| 20 | +board_initialize_display_nt35510(uint8_t ColorCoding) |
| 21 | +{ |
| 22 | + using namespace modm::platform; |
| 23 | + if (Rcc::isEnabled<Peripheral::Ltdc>()) return; |
| 24 | + // Enable clock to LTDC, DSI interface |
| 25 | + Rcc::enable<Peripheral::Ltdc>(); |
| 26 | + Rcc::enable<Peripheral::Dsihost>(); |
| 27 | + |
| 28 | + { |
| 29 | + // Expanded `HAL_DSI_Init()`: |
| 30 | + // Enable regulator |
| 31 | + DSI->WRPCR = DSI_WRPCR_REGEN; |
| 32 | + // Wait until stable |
| 33 | + for (int t = 1'024; not (DSI->WISR & DSI_WISR_RRS) and t; t--) { |
| 34 | + modm::delay_ms(1); |
| 35 | + } |
| 36 | + // Set up PLL and enable it |
| 37 | + DSI->WRPCR |= (0 << 16) | (2 << 11) | (125 << 2) | DSI_WRPCR_PLLEN; |
| 38 | + // Wait until stable |
| 39 | + for (int t = 1'024; not (DSI->WISR & DSI_WISR_PLLLS) and t; t--) { |
| 40 | + modm::delay_ms(1); |
| 41 | + } |
| 42 | + // D-PHY clock and digital enable |
| 43 | + DSI->PCTLR = DSI_PCTLR_CKE | DSI_PCTLR_DEN; |
| 44 | + // Clock lane configuration |
| 45 | + DSI->CLCR = DSI_CLCR_DPCC; |
| 46 | + // Configure the number of active data lanes |
| 47 | + DSI->PCONFR = 1; |
| 48 | + // Set the TX escape clock division factor |
| 49 | + DSI->CCR = 4; |
| 50 | + // Calculate the bit period in high-speed mode in unit of 0.25 ns (UIX4) |
| 51 | + // The equation is : UIX4 = IntegerPart( (1000/F_PHY_Mhz) * 4 ) |
| 52 | + // Where : F_PHY_Mhz = (NDIV * HSE_Mhz) / (IDF * ODF) |
| 53 | + // Set the bit period in high-speed mode |
| 54 | + DSI->WPCR[0] = 8; |
| 55 | + // Disable all error interrupts and reset the Error Mask |
| 56 | + DSI->IER[0] = 0; |
| 57 | + DSI->IER[1] = 0; |
| 58 | + } |
| 59 | + |
| 60 | + constexpr uint32_t VSA = 2; |
| 61 | + constexpr uint32_t VBP = 34; |
| 62 | + constexpr uint32_t VFP = 34; |
| 63 | + |
| 64 | + constexpr uint32_t HSA = 120; |
| 65 | + constexpr uint32_t HBP = 150; |
| 66 | + constexpr uint32_t HFP = 150; |
| 67 | + |
| 68 | + constexpr uint32_t HACT = 800; |
| 69 | + constexpr uint32_t VACT = 480; |
| 70 | + const uint8_t pixel_size = (ColorCoding == 0) ? sizeof(uint32_t) : sizeof(uint16_t); |
| 71 | + constexpr float ClockRatio = 62500.f / 27429; |
| 72 | + |
| 73 | + { |
| 74 | + // Expanded `HAL_DSI_ConfigVideoMode()` |
| 75 | + // Select video mode by resetting CMDM and DSIM bits |
| 76 | + DSI->MCR = 0; |
| 77 | + DSI->WCFGR = 0; |
| 78 | + // Configure the video mode transmission type |
| 79 | + DSI->VMCR = 2; |
| 80 | + // Configure the video packet size |
| 81 | + DSI->VPCR = HACT; |
| 82 | + // Set the chunks number to be transmitted through the DSI link |
| 83 | + DSI->VCCR = 0; |
| 84 | + // Set the size of the null packet |
| 85 | + DSI->VNPCR = 0xFFF; |
| 86 | + // Select the virtual channel for the LTDC interface traffic |
| 87 | + DSI->LVCIDR = 0; |
| 88 | + // Configure the polarity of control signals |
| 89 | + DSI->LPCR = 0; |
| 90 | + // Select the color coding for the host |
| 91 | + DSI->LCOLCR = ColorCoding; |
| 92 | + // Select the color coding for the wrapper |
| 93 | + DSI->WCFGR = ColorCoding << 1; |
| 94 | + // Set the Horizontal Synchronization Active (HSA) in lane byte clock cycles |
| 95 | + DSI->VHSACR = HSA * ClockRatio; |
| 96 | + // Set the Horizontal Back Porch (HBP) in lane byte clock cycles |
| 97 | + DSI->VHBPCR = HBP * ClockRatio; |
| 98 | + // Set the total line time (HLINE=HSA+HBP+HACT+HFP) in lane byte clock cycles |
| 99 | + DSI->VLCR = (HACT + HSA + HBP + HFP) * ClockRatio; |
| 100 | + // Set the Vertical Synchronization Active (VSA) |
| 101 | + DSI->VVSACR = VSA; |
| 102 | + // Set the Vertical Back Porch (VBP) |
| 103 | + DSI->VVBPCR = VBP; |
| 104 | + // Set the Vertical Front Porch (VFP) |
| 105 | + DSI->VVFPCR = VFP; |
| 106 | + // Set the Vertical Active period |
| 107 | + DSI->VVACR = VACT; |
| 108 | + // Low power largest packet size |
| 109 | + // Low power VACT largest packet size |
| 110 | + DSI->LPMCR = (64 << 16) | 64; |
| 111 | + // Configure the command transmission mode |
| 112 | + // Enable LP transition in HFP period |
| 113 | + // Enable LP transition in HBP period |
| 114 | + DSI->VMCR |= DSI_VMCR_LPCE | DSI_VMCR_LPHFPE | DSI_VMCR_LPHBPE | DSI_VMCR_LPVAE | |
| 115 | + DSI_VMCR_LPVFPE | DSI_VMCR_LPVBPE | DSI_VMCR_LPVSAE; |
| 116 | + } |
| 117 | + { |
| 118 | + // Enable the DSI host |
| 119 | + DSI->CR = DSI_CR_EN; |
| 120 | + // Enable the DSI wrapper |
| 121 | + DSI->WCR = DSI_WCR_DSIEN; |
| 122 | + } |
| 123 | + |
| 124 | + /* done by SystemClock::enable() |
| 125 | + { |
| 126 | + // LCD clock configuration |
| 127 | + // PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz |
| 128 | + // PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz |
| 129 | + // PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz |
| 130 | + // LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz |
| 131 | + RCC->PLLSAICFGR = (7 << 28) | (15 << 24) | (3 << 16) | (384 << 6); |
| 132 | + // Select PLLSAI clock for 48MHz clocks |
| 133 | + RCC->DCKCFGR = RCC_DCKCFGR_CK48MSEL; |
| 134 | + // Enable PLLSAI |
| 135 | + RCC->CR |= RCC_CR_PLLSAION; |
| 136 | + for (int t = 1'024; not (RCC->CR & RCC_CR_PLLSAIRDY) and t; t--) { |
| 137 | + modm::delay_ms(1); |
| 138 | + } |
| 139 | + } |
| 140 | + */ |
| 141 | + |
| 142 | + { |
| 143 | + // HAL_LTDC_Init(&hltdc_eval); |
| 144 | + // Configures the HS, VS, DE and PC polarity |
| 145 | + LTDC->GCR = 0; |
| 146 | + // Sets Synchronization size |
| 147 | + LTDC->SSCR = ((HSA - 1) << 16) | (VSA - 1); |
| 148 | + // Sets Accumulated Back porch |
| 149 | + LTDC->BPCR = ((HSA + HBP - 1) << 16) | (VSA + VBP - 1); |
| 150 | + // Sets Accumulated Active Width |
| 151 | + LTDC->AWCR = ((HACT + HSA + HBP - 1) << 16) | (VACT + VSA + VBP - 1); |
| 152 | + // Sets Total Width and Height |
| 153 | + LTDC->TWCR = ((HACT + HSA + HBP + HFP - 1) << 16) | (VACT + VSA + VBP + VFP - 1); |
| 154 | + // Sets the background color value |
| 155 | + LTDC->BCCR = 0; |
| 156 | + // Enable LTDC by setting LTDCEN bit |
| 157 | + LTDC->GCR |= LTDC_GCR_LTDCEN; |
| 158 | + } |
| 159 | + |
| 160 | + nt35510_init(ColorCoding); |
| 161 | + |
| 162 | + { |
| 163 | + // HAL_LTDC_ConfigLayer() |
| 164 | + // Configures the horizontal start and stop position |
| 165 | + LTDC_Layer1->WHPCR = ((HACT + HSA + HBP - 1) << 16) | (HSA + HBP); |
| 166 | + // Configures the vertical start and stop position |
| 167 | + LTDC_Layer1->WVPCR = ((VACT + VSA + VBP - 1) << 16) | (VSA + VBP); |
| 168 | + // Specifies the pixel format |
| 169 | + LTDC_Layer1->PFCR = ColorCoding; |
| 170 | + // Configures the default color values |
| 171 | + LTDC_Layer1->DCCR = 0xff000000; |
| 172 | + // Specifies the constant alpha value |
| 173 | + LTDC_Layer1->CACR = 0xff; |
| 174 | + // Specifies the blending factors |
| 175 | + LTDC_Layer1->BFCR = 0x607; |
| 176 | + // Configures the color frame buffer pitch in byte |
| 177 | + LTDC_Layer1->CFBLR = ((HACT * pixel_size) << 16) | ((HACT * pixel_size) + 3); |
| 178 | + // Configures the frame buffer line number |
| 179 | + LTDC_Layer1->CFBLNR = VACT; |
| 180 | + |
| 181 | + /* Configured in display.cpp |
| 182 | + // Configures the color frame buffer start address |
| 183 | + LTDC_Layer1->CFBAR = buffer_address; |
| 184 | + // Enable LTDC_Layer by setting LEN bit |
| 185 | + LTDC_Layer1->CR = LTDC_LxCR_LEN; |
| 186 | + // Sets the Reload type |
| 187 | + LTDC->SRCR = LTDC_SRCR_IMR; |
| 188 | + */ |
| 189 | + } |
| 190 | +} |
0 commit comments