35 #include <oc_saipll.h> 37 #include <oc_gpio_mslld.h> 44 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 46 #define IsRam(Address) (oC_LSF_IsRamAddress(Address) || oC_LSF_IsExternalAddress(Address)) 47 #define IsRom(Address) oC_LSF_IsRomAddress(Address) 48 #define LTDC_Channel oC_Channel_LCD 50 #define IsLayerCorrect(Layer) ( (Layer) < 2 && (Layer) >= 0 ) 51 #define IsPolarityCorrect(Polarity) ( (Polarity) == oC_LCDTFT_LLD_Polarity_ActiveLow || (Polarity) == oC_LCDTFT_LLD_Polarity_ActiveHigh ) 52 #define IsChannelPoweredOn() (oC_Machine_GetPowerStateForChannel(LTDC_Channel) == oC_Power_On) 53 #define SetPolarity(Bit , Polarity) Bit = (Polarity == oC_LCDTFT_LLD_Polarity_ActiveHigh) ? 1 : 0 54 #define GetPolarity(Bit) ((Bit) == 1) ? oC_LCDTFT_LLD_Polarity_ActiveHigh : oC_LCDTFT_LLD_Polarity_ActiveHigh 55 #define AreOperationsEnabled() (LTDC_GCR->LTDCEN == 1) 56 #define AreOperationsDisabled() (LTDC_GCR->LTDCEN == 0) 57 #define LTDC_GCR oC_Register(LCD_TFT , LTDC_GCR ) 58 #define LTDC_SSCR oC_Register(LCD_TFT , LTDC_SSCR ) 59 #define LTDC_SRCR oC_Register(LCD_TFT , LTDC_SRCR ) 60 #define LTDC_BCCR oC_Register(LCD_TFT , LTDC_BCCR ) 61 #define LTDC_IER oC_Register(LCD_TFT , LTDC_IER ) 62 #define LTDC_TWCR oC_Register(LCD_TFT , LTDC_TWCR ) 63 #define LTDC_BPCR oC_Register(LCD_TFT , LTDC_BPCR ) 64 #define LTDC_AWCR oC_Register(LCD_TFT , LTDC_AWCR ) 65 #define LTDC_L1CFBAR oC_Register(LCD_TFT , LTDC_L1CFBAR ) 66 #define LTDC_L1CFBLR oC_Register(LCD_TFT , LTDC_L1CFBLR ) 67 #define LTDC_L1CFBLNR oC_Register(LCD_TFT , LTDC_L1CFBLNR ) 68 #define LTDC_L1CR oC_Register(LCD_TFT , LTDC_L1CR ) 69 #define LTDC_L1PFCR oC_Register(LCD_TFT , LTDC_L1PFCR ) 70 #define LTDC_L1WHPCR oC_Register(LCD_TFT , LTDC_L1WHPCR ) 71 #define LTDC_L1WVPCR oC_Register(LCD_TFT , LTDC_L1WVPCR ) 72 #define LTDC_L1DCCR oC_Register(LCD_TFT , LTDC_L1DCCR ) 73 #define LTDC_L1CACR oC_Register(LCD_TFT , LTDC_L1CACR ) 74 #define LTDC_L1BFCR oC_Register(LCD_TFT , LTDC_L1BFCR ) 75 #define RCC_CR oC_Register(RCC , RCC_CR) 76 #define RCC_PLLSAICFGR oC_Register(RCC , RCC_PLLSAICFGR) 77 #define RCC_DCKCFGR1 oC_Register(RCC , RCC_DCKCFGR1) 78 #define RCC_APB2RSTR oC_Register(RCC , RCC_APB2RSTR) 79 #define MAX_WIDTH 1024 80 #define MAX_HEIGHT 768 83 #define MAX_AHBP 0xFFF 84 #define MAX_AVBP 0x7FF 87 #define MAX_TOTALH 0xFFF 88 #define MAX_TOTALW 0x7FF 89 #define MAX_COLOR_VALUE(PixelSize) ( \ 90 ((PixelSize) == 1 ) ? 0x000000FF : \ 91 ((PixelSize) == 2 ) ? 0x0000FFFF : \ 92 ((PixelSize) == 3 ) ? 0x00FFFFFF : \ 93 ((PixelSize) == 4 ) ? 0xFFFFFFFF : 0 \ 96 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 103 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 106 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 113 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 115 static bool FindModulePin ( oC_Pin_t Pin , oC_LCDTFT_PinFunction_t Function , oC_LCDTFT_Pin_t * outModulePin );
116 static oC_ErrorCode_t ConnectModulePin ( oC_LCDTFT_Pin_t ModulePin );
117 static oC_ErrorCode_t ConnectPin ( oC_Pin_t Pin , oC_GPIO_LLD_Mode_t PinMode );
118 static oC_ColorFormat_t GetPixelFormat (
void );
119 static oC_UInt_t GetPixelSize (
void );
120 static oC_ErrorCode_t SetPixelFormat ( oC_ColorFormat_t PixelFormat );
124 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________ 132 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 135 static oC_Pixel_ResolutionUInt_t ConfiguredWidth = 0;
136 static oC_Pixel_ResolutionUInt_t ConfiguredHeight = 0;
137 static oC_Pin_t ConfiguredDispPin = 0;
138 static oC_Pin_t ConfiguredBlCtrlPin = 0;
139 static oC_ColorFormat_t ConfiguredColorFormat = oC_ColorFormat_Unknown;
140 static const oC_LCDTFT_PinFunction_t PinFunctions [oC_LCDTFT_LLD_PinIndex_NumberOfPins] = {
141 [ oC_LCDTFT_LLD_PinIndex_R0 ] = oC_LCDTFT_PinFunction_LCD_R0 ,
142 [ oC_LCDTFT_LLD_PinIndex_R1 ] = oC_LCDTFT_PinFunction_LCD_R1 ,
143 [ oC_LCDTFT_LLD_PinIndex_R2 ] = oC_LCDTFT_PinFunction_LCD_R2 ,
144 [ oC_LCDTFT_LLD_PinIndex_R3 ] = oC_LCDTFT_PinFunction_LCD_R3 ,
145 [ oC_LCDTFT_LLD_PinIndex_R4 ] = oC_LCDTFT_PinFunction_LCD_R4 ,
146 [ oC_LCDTFT_LLD_PinIndex_R5 ] = oC_LCDTFT_PinFunction_LCD_R5 ,
147 [ oC_LCDTFT_LLD_PinIndex_R6 ] = oC_LCDTFT_PinFunction_LCD_R6 ,
148 [ oC_LCDTFT_LLD_PinIndex_R7 ] = oC_LCDTFT_PinFunction_LCD_R7 ,
149 [ oC_LCDTFT_LLD_PinIndex_G0 ] = oC_LCDTFT_PinFunction_LCD_G0 ,
150 [ oC_LCDTFT_LLD_PinIndex_G1 ] = oC_LCDTFT_PinFunction_LCD_G1 ,
151 [ oC_LCDTFT_LLD_PinIndex_G2 ] = oC_LCDTFT_PinFunction_LCD_G2 ,
152 [ oC_LCDTFT_LLD_PinIndex_G3 ] = oC_LCDTFT_PinFunction_LCD_G3 ,
153 [ oC_LCDTFT_LLD_PinIndex_G4 ] = oC_LCDTFT_PinFunction_LCD_G4 ,
154 [ oC_LCDTFT_LLD_PinIndex_G5 ] = oC_LCDTFT_PinFunction_LCD_G5 ,
155 [ oC_LCDTFT_LLD_PinIndex_G6 ] = oC_LCDTFT_PinFunction_LCD_G6 ,
156 [ oC_LCDTFT_LLD_PinIndex_G7 ] = oC_LCDTFT_PinFunction_LCD_G7 ,
157 [ oC_LCDTFT_LLD_PinIndex_B0 ] = oC_LCDTFT_PinFunction_LCD_B0 ,
158 [ oC_LCDTFT_LLD_PinIndex_B1 ] = oC_LCDTFT_PinFunction_LCD_B1 ,
159 [ oC_LCDTFT_LLD_PinIndex_B2 ] = oC_LCDTFT_PinFunction_LCD_B2 ,
160 [ oC_LCDTFT_LLD_PinIndex_B3 ] = oC_LCDTFT_PinFunction_LCD_B3 ,
161 [ oC_LCDTFT_LLD_PinIndex_B4 ] = oC_LCDTFT_PinFunction_LCD_B4 ,
162 [ oC_LCDTFT_LLD_PinIndex_B5 ] = oC_LCDTFT_PinFunction_LCD_B5 ,
163 [ oC_LCDTFT_LLD_PinIndex_B6 ] = oC_LCDTFT_PinFunction_LCD_B6 ,
164 [ oC_LCDTFT_LLD_PinIndex_B7 ] = oC_LCDTFT_PinFunction_LCD_B7 ,
165 [ oC_LCDTFT_LLD_PinIndex_VSYNC ] = oC_LCDTFT_PinFunction_LCD_VSYNC ,
166 [ oC_LCDTFT_LLD_PinIndex_HSYNC ] = oC_LCDTFT_PinFunction_LCD_HSYNC ,
167 [ oC_LCDTFT_LLD_PinIndex_CLK ] = oC_LCDTFT_PinFunction_LCD_CLK ,
168 [ oC_LCDTFT_LLD_PinIndex_DE ] = oC_LCDTFT_PinFunction_LCD_DE ,
169 [ oC_LCDTFT_LLD_PinIndex_DISP ] = 0 ,
170 [ oC_LCDTFT_LLD_PinIndex_BL_CTRL ] = 0 ,
171 [ oC_LCDTFT_LLD_PinIndex_LED_K ] = 0 ,
172 [ oC_LCDTFT_LLD_PinIndex_LED_A ] = 0 ,
173 [ oC_LCDTFT_LLD_PinIndex_NC_XR ] = 0 ,
174 [ oC_LCDTFT_LLD_PinIndex_NC_YD ] = 0 ,
175 [ oC_LCDTFT_LLD_PinIndex_NC_XL ] = 0 ,
176 [ oC_LCDTFT_LLD_PinIndex_NC_YU ] = 0
179 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 186 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 196 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
203 ConfiguredFrequency = 0;
204 ConfiguredHeight = 0;
206 ConfiguredDispPin = 0;
207 ConfiguredBlCtrlPin = 0;
208 ConfiguredColorFormat = 0;
209 errorCode = oC_ErrorCode_None;
225 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
232 errorCode = oC_ErrorCode_None;
248 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
259 errorCode = oC_ErrorCode_None;
276 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
282 if(ErrorCondition( IsRam(outPower) , oC_ErrorCode_OutputAddressNotInRAM))
285 errorCode = oC_ErrorCode_None;
302 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
307 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
308 ErrorCondition( ConfiguredBlCtrlPin != 0 , oC_ErrorCode_ChannelNotConfigured) &&
309 ErrorCondition( ConfiguredDispPin != 0 , oC_ErrorCode_ChannelNotConfigured) &&
310 ErrorCondition( ConfiguredFrequency != 0 , oC_ErrorCode_ChannelNotConfigured) &&
311 ErrorCondition( ConfiguredHeight != 0 , oC_ErrorCode_ChannelNotConfigured) &&
312 ErrorCondition( ConfiguredWidth != 0 , oC_ErrorCode_ChannelNotConfigured)
315 LTDC_IER->TERRIE = 1;
319 LTDC_GCR->LTDCEN = 1;
321 oC_GPIO_LLD_SetPinsState(ConfiguredBlCtrlPin , oC_GPIO_LLD_PinsState_AllHigh);
322 oC_GPIO_LLD_SetPinsState(ConfiguredDispPin , oC_GPIO_LLD_PinsState_AllHigh);
324 errorCode = oC_ErrorCode_None;
340 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
344 if(ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn))
346 LTDC_GCR->LTDCEN = 0;
347 errorCode = oC_ErrorCode_None;
362 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
367 ErrorCondition( Frequency > 0 , oC_ErrorCode_WrongFrequency ) &&
368 ErrorCondition( PermissibleDifference >= 0 , oC_ErrorCode_WrongFrequency )
386 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
391 ErrorCondition( IsRam(outFrequency) , oC_ErrorCode_OutputAddressNotInRAM ) &&
392 ErrorCondition( ConfiguredFrequency != 0 , oC_ErrorCode_ChannelNotConfigured )
395 *outFrequency = ConfiguredFrequency;
396 errorCode = oC_ErrorCode_None;
411 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
416 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
417 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled )
420 switch(PixelPolarity)
422 case oC_LCDTFT_LLD_PixelClockPolarity_InputPixelClock:
424 errorCode = oC_ErrorCode_None;
426 case oC_LCDTFT_LLD_PixelClockPolarity_InvertedInputPixelClock:
428 errorCode = oC_ErrorCode_None;
431 errorCode = oC_ErrorCode_PolarityNotCorrect;
448 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
453 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
454 ErrorCondition( IsRam(outPixelPolarity) , oC_ErrorCode_OutputAddressNotInRAM )
457 if(LTDC_GCR->PCPOL == 0)
459 *outPixelPolarity = oC_LCDTFT_LLD_PixelClockPolarity_InputPixelClock;
463 *outPixelPolarity = oC_LCDTFT_LLD_PixelClockPolarity_InvertedInputPixelClock;
465 errorCode = oC_ErrorCode_None;
478 oC_ErrorCode_t
oC_LCDTFT_LLD_SetPolarities( oC_LCDTFT_LLD_Polarity_t HSyncPolarity , oC_LCDTFT_LLD_Polarity_t VSyncPolarity , oC_LCDTFT_LLD_Polarity_t DataEnablePolarity )
480 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
485 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
486 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled ) &&
487 ErrorCondition( IsPolarityCorrect(HSyncPolarity) , oC_ErrorCode_PolarityNotCorrect ) &&
488 ErrorCondition( IsPolarityCorrect(VSyncPolarity) , oC_ErrorCode_PolarityNotCorrect ) &&
489 ErrorCondition( IsPolarityCorrect(DataEnablePolarity) , oC_ErrorCode_PolarityNotCorrect )
492 SetPolarity( LTDC_GCR->HSPOL , HSyncPolarity );
493 SetPolarity( LTDC_GCR->VSPOL , VSyncPolarity );
494 SetPolarity( LTDC_GCR->DEPOL , DataEnablePolarity );
495 errorCode = oC_ErrorCode_None;
508 oC_ErrorCode_t
oC_LCDTFT_LLD_ReadPolarities( oC_LCDTFT_LLD_Polarity_t * outHSyncPolarity , oC_LCDTFT_LLD_Polarity_t * outVSyncPolarity , oC_LCDTFT_LLD_Polarity_t * outDataEnablePolarity )
510 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
515 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
516 ErrorCondition( IsRam(outHSyncPolarity) , oC_ErrorCode_OutputAddressNotInRAM ) &&
517 ErrorCondition( IsRam(outVSyncPolarity) , oC_ErrorCode_OutputAddressNotInRAM ) &&
518 ErrorCondition( IsRam(outDataEnablePolarity) , oC_ErrorCode_OutputAddressNotInRAM )
521 *outHSyncPolarity = GetPolarity(LTDC_GCR->HSPOL);
522 *outVSyncPolarity = GetPolarity(LTDC_GCR->VSPOL);
523 *outDataEnablePolarity = GetPolarity(LTDC_GCR->DEPOL);
524 errorCode = oC_ErrorCode_None;
539 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
544 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
545 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled ) &&
546 ErrorCondition( Width <= MAX_WIDTH , oC_ErrorCode_WidthTooBig ) &&
547 ErrorCondition( Height <= MAX_HEIGHT , oC_ErrorCode_HeightTooBig )
550 ConfiguredWidth = Width;
551 ConfiguredHeight = Height;
552 errorCode = oC_ErrorCode_None;
567 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
572 ErrorCondition( IsRam(outWidth) , oC_ErrorCode_OutputAddressNotInRAM ) &&
573 ErrorCondition( IsRam(outHeight) , oC_ErrorCode_OutputAddressNotInRAM ) &&
574 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
575 ErrorCondition( ConfiguredWidth > 0 , oC_ErrorCode_ChannelNotConfigured ) &&
576 ErrorCondition( ConfiguredHeight > 0 , oC_ErrorCode_ChannelNotConfigured )
579 *outWidth = ConfiguredWidth;
580 *outHeight = ConfiguredHeight;
581 errorCode = oC_ErrorCode_None;
596 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
600 RCC_APB2RSTR->LTDCRST = 1;
601 errorCode = oC_ErrorCode_None;
615 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
620 ErrorCondition( IsRam(Pins) || IsRom(Pins) , oC_ErrorCode_WrongAddress ) &&
621 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn )
624 #define IS_PIN_REQUIRED(PinIndex) \ 625 ( (PinIndex >= oC_LCDTFT_LLD_PinIndex_R0 && PinIndex <= oC_LCDTFT_LLD_PinIndex_R7) ? (PinIndex - oC_LCDTFT_LLD_PinIndex_R0) < requiredRed :\ 626 (PinIndex >= oC_LCDTFT_LLD_PinIndex_G0 && PinIndex <= oC_LCDTFT_LLD_PinIndex_G7) ? (PinIndex - oC_LCDTFT_LLD_PinIndex_G0) < requiredGreen :\ 627 (PinIndex >= oC_LCDTFT_LLD_PinIndex_B0 && PinIndex <= oC_LCDTFT_LLD_PinIndex_B7) ? (PinIndex - oC_LCDTFT_LLD_PinIndex_B0) < requiredBlue : true\ 629 oC_ColorFormat_t pixelFormat = GetPixelFormat();
630 uint8_t requiredRed = oC_ColorFormat_GetNoRedBits(pixelFormat);
631 uint8_t requiredGreen = oC_ColorFormat_GetNoGreenBits(pixelFormat);
632 uint8_t requiredBlue = oC_ColorFormat_GetNoBlueBits(pixelFormat);
634 errorCode = (pixelFormat != oC_ColorFormat_Unknown) ? oC_ErrorCode_None : oC_ErrorCode_PixelFormatNotConfigured;
636 for(oC_LCDTFT_LLD_PinIndex_t pinIndex = 0 ; !oC_ErrorOccur(errorCode ) && pinIndex < oC_LCDTFT_LLD_PinIndex_NumberOfPins ; pinIndex++ )
638 if(PinFunctions[pinIndex])
640 if(oC_GPIO_LLD_IsPinDefined(Pins->PinsArray[pinIndex]))
642 oC_LCDTFT_Pin_t modulePin = 0;
644 if(FindModulePin(Pins->PinsArray[pinIndex],PinFunctions[pinIndex],&modulePin))
646 errorCode = ConnectModulePin(modulePin);
650 errorCode = oC_ErrorCode_NoneOfModulePinAssigned;
653 else if(IS_PIN_REQUIRED(pinIndex))
655 errorCode = oC_ErrorCode_PinNotDefined;
661 !oC_ErrorOccur(errorCode) &&
662 oC_AssignErrorCode( &errorCode , ConnectPin(Pins->PinsArray[oC_LCDTFT_LLD_PinIndex_DISP] , oC_GPIO_LLD_Mode_Output ) ) &&
663 oC_AssignErrorCode( &errorCode , ConnectPin(Pins->PinsArray[oC_LCDTFT_LLD_PinIndex_BL_CTRL], oC_GPIO_LLD_Mode_Output ) )
666 ConfiguredDispPin = Pins->PinsArray[oC_LCDTFT_LLD_PinIndex_DISP];
667 ConfiguredBlCtrlPin = Pins->PinsArray[oC_LCDTFT_LLD_PinIndex_BL_CTRL];
668 errorCode = oC_ErrorCode_None;
688 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
693 ErrorCondition( IsRam(Pins) || IsRom(Pins) , oC_ErrorCode_WrongAddress )
696 errorCode = oC_ErrorCode_None;
698 for(oC_LCDTFT_LLD_PinIndex_t pinIndex = 0 ; pinIndex < oC_LCDTFT_LLD_PinIndex_NumberOfPins ; pinIndex++ )
700 if(Pins->PinsArray[pinIndex] != oC_Pin_NotUsed)
702 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPinsUnused(Pins->PinsArray[pinIndex]) );
703 oC_AssignErrorCode(&errorCode , oC_GPIO_MSLLD_DisconnectPin( Pins->PinsArray[pinIndex] , 0 ) );
720 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
724 oC_UInt_t pixelSize = GetPixelSize();
725 oC_UInt_t requiredBufferSize = pixelSize * ConfiguredWidth * ConfiguredHeight;
726 const void * bufferEnd = (
const void * )(((oC_UInt_t)Buffer) + requiredBufferSize - 1);
729 ErrorCondition( IsRam(Buffer) || IsRom(Buffer) , oC_ErrorCode_WrongAddress ) &&
730 ErrorCondition( GetPixelFormat() != oC_ColorFormat_Unknown , oC_ErrorCode_PixelFormatNotConfigured ) &&
731 ErrorCondition( pixelSize > 0 && pixelSize <= 4 , oC_ErrorCode_MachineCanBeDamaged ) &&
732 ErrorCondition( ConfiguredWidth > 0 , oC_ErrorCode_ResolutionNotSet ) &&
733 ErrorCondition( ConfiguredHeight> 0 , oC_ErrorCode_ResolutionNotSet ) &&
734 ErrorCondition( IsRam(bufferEnd) || IsRom(bufferEnd) , oC_ErrorCode_WrongBufferEndAddress ) &&
735 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
736 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled )
739 LTDC_L1CFBAR->Value = (uint32_t)Buffer;
740 errorCode = oC_ErrorCode_None;
755 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
760 ErrorCondition(IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
761 ErrorCondition(AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled )
764 errorCode = SetPixelFormat( PixelFormat );
779 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
784 ErrorCondition(IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
785 ErrorCondition(IsRam(outPixelFormat) , oC_ErrorCode_OutputAddressNotInRAM )
788 *outPixelFormat = GetPixelFormat();
789 errorCode = oC_ErrorCode_None;
804 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
809 ErrorCondition( IsRam(TimingParameters) || IsRom(TimingParameters) , oC_ErrorCode_WrongAddress ) &&
810 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
811 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled ) &&
812 ErrorCondition( ConfiguredWidth > 0 , oC_ErrorCode_ResolutionNotSet ) &&
813 ErrorCondition( ConfiguredHeight> 0 , oC_ErrorCode_ResolutionNotSet )
816 errorCode = SetTimingParameters( TimingParameters );
831 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
836 ErrorCondition( IsRam(outTimingParameters) , oC_ErrorCode_OutputAddressNotInRAM ) &&
837 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn )
840 errorCode = ReadTimingParameters( outTimingParameters );
855 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
860 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
861 ErrorCondition( AreOperationsDisabled() , oC_ErrorCode_ChannelOperationsNotDisabled ) &&
862 ErrorCondition( oC_Color_IsCorrect(Color) , oC_ErrorCode_ColorNotCorrect ) &&
863 ErrorCondition( ColorFormat != oC_ColorFormat_Unknown , oC_ErrorCode_ColorFormatNotSupported )
866 oC_Color_t converted = oC_Color_ConvertToFormat(Color,ColorFormat,oC_ColorFormat_RGB888);
867 LTDC_BCCR->Value = (uint32_t)converted;
868 LTDC_L1DCCR->Value = (uint32_t)converted;
869 LTDC_L1CACR->Value = 0xFF;
870 errorCode = oC_ErrorCode_None;
885 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
890 ErrorCondition( IsChannelPoweredOn() , oC_ErrorCode_ChannelNotPoweredOn ) &&
891 ErrorCondition( IsRam(outColor) , oC_ErrorCode_OutputAddressNotInRAM ) &&
892 ErrorCondition( ColorFormat != oC_ColorFormat_Unknown , oC_ErrorCode_ColorFormatNotSupported )
895 *outColor = oC_Color_ConvertToFormat((oC_Color_t)LTDC_BCCR->Value,oC_ColorFormat_RGB888,ColorFormat);
896 errorCode = oC_ErrorCode_None;
904 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 911 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 918 static bool FindModulePin( oC_Pin_t Pin , oC_LCDTFT_PinFunction_t Function , oC_LCDTFT_Pin_t * outModulePin )
920 bool success =
false;
922 oC_ModulePin_ForeachDefined(modulePin)
924 if((modulePin->Channel == LTDC_Channel) && modulePin->PinFunction == Function && modulePin->Pin == Pin)
926 *outModulePin = modulePin->ModulePinIndex;
940 static oC_ErrorCode_t ConnectModulePin( oC_LCDTFT_Pin_t ModulePin )
942 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
943 oC_Pin_t pin = oC_ModulePin_GetPin(ModulePin);
946 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ArePinsUnused(pin,&unused) ) &&
947 ErrorCondition( unused , oC_ErrorCode_PinIsUsed) &&
948 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPinsUsed(pin) ) &&
949 oC_AssignErrorCode(&errorCode , oC_GPIO_MSLLD_ConnectModulePin(ModulePin) )
952 errorCode = oC_ErrorCode_None;
961 static oC_ErrorCode_t ConnectPin( oC_Pin_t Pin , oC_GPIO_LLD_Mode_t PinMode )
963 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
967 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ArePinsUnused(Pin,&unused) ) &&
968 ErrorCondition( unused , oC_ErrorCode_PinIsUsed ) &&
969 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPinsUsed(Pin) ) &&
970 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pin) ) &&
971 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(Pin , PinMode) ) &&
972 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pin) )
975 errorCode = oC_ErrorCode_None;
986 static oC_ColorFormat_t GetPixelFormat(
void )
989 return ConfiguredColorFormat;
997 static oC_UInt_t GetPixelSize(
void )
999 oC_ColorFormat_t pixelFormat = GetPixelFormat();
1000 return oC_Color_GetFormatSize(pixelFormat);
1008 static oC_ErrorCode_t SetPixelFormat( oC_ColorFormat_t PixelFormat )
1010 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1014 case oC_ColorFormat_RGB888: LTDC_L1PFCR->PF = 1; errorCode = oC_ErrorCode_None; ConfiguredColorFormat = PixelFormat;
break;
1015 case oC_ColorFormat_RGB565: LTDC_L1PFCR->PF = 2; errorCode = oC_ErrorCode_None; ConfiguredColorFormat = PixelFormat;
break;
1016 default: errorCode = oC_ErrorCode_ColorFormatNotSupported;
break;
1029 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1030 uint32_t TOTAL_HEIGHT;
1031 uint32_t TOTAL_WIDTH;
1032 uint32_t ACTIVE_HEIGHT;
1033 uint32_t ACTIVE_WIDTH;
1034 oC_UInt_t pixelSize = GetPixelSize();
1036 ACTIVE_WIDTH = TimingParameters->HSYNC.PulseWidth + ConfiguredWidth + TimingParameters->HSYNC.BackPorch - 1;
1037 ACTIVE_HEIGHT= TimingParameters->VSYNC.PulseWidth + ConfiguredHeight + TimingParameters->VSYNC.BackPorch - 1;
1039 TOTAL_WIDTH = TimingParameters->HSYNC.PulseWidth + TimingParameters->HSYNC.BackPorch + ACTIVE_WIDTH + TimingParameters->HSYNC.FrontPorch;
1040 TOTAL_HEIGHT = TimingParameters->VSYNC.PulseWidth + TimingParameters->VSYNC.BackPorch + ACTIVE_HEIGHT+ TimingParameters->VSYNC.FrontPorch;
1043 ErrorCondition( TimingParameters->HSYNC.PulseWidth <= MAX_HSW , oC_ErrorCode_TimingParametersNotSupported ) &&
1044 ErrorCondition( TimingParameters->VSYNC.PulseWidth <= MAX_VSW , oC_ErrorCode_TimingParametersNotSupported ) &&
1045 ErrorCondition( TimingParameters->HSYNC.BackPorch <= MAX_AHBP , oC_ErrorCode_TimingParametersNotSupported ) &&
1046 ErrorCondition( TimingParameters->VSYNC.BackPorch <= MAX_AVBP , oC_ErrorCode_TimingParametersNotSupported ) &&
1047 ErrorCondition( TimingParameters->HSYNC.PulseWidth > 0 , oC_ErrorCode_TimingParametersNotFilled ) &&
1048 ErrorCondition( TimingParameters->VSYNC.PulseWidth > 0 , oC_ErrorCode_TimingParametersNotFilled ) &&
1049 ErrorCondition( TimingParameters->HSYNC.BackPorch > 0 , oC_ErrorCode_TimingParametersNotFilled ) &&
1050 ErrorCondition( TimingParameters->VSYNC.BackPorch > 0 , oC_ErrorCode_TimingParametersNotFilled ) &&
1051 ErrorCondition( ACTIVE_HEIGHT <= MAX_AAH , oC_ErrorCode_TimingParametersNotSupported ) &&
1052 ErrorCondition( ACTIVE_WIDTH <= MAX_AAW , oC_ErrorCode_TimingParametersNotSupported ) &&
1053 ErrorCondition( TOTAL_HEIGHT <= MAX_TOTALH , oC_ErrorCode_TimingParametersNotSupported ) &&
1054 ErrorCondition( TOTAL_WIDTH <= MAX_TOTALW , oC_ErrorCode_TimingParametersNotSupported )
1059 SetPixelFormat(ConfiguredColorFormat);
1061 LTDC_SSCR->HSW = TimingParameters->HSYNC.PulseWidth - 1;
1062 LTDC_SSCR->VSH = TimingParameters->VSYNC.PulseWidth - 1;
1064 LTDC_BPCR->AHBP = TimingParameters->HSYNC.BackPorch - 1;
1065 LTDC_BPCR->AVBP = TimingParameters->VSYNC.BackPorch - 1;
1067 LTDC_AWCR->AAH = ACTIVE_HEIGHT;
1068 LTDC_AWCR->AAW = ACTIVE_WIDTH;
1070 LTDC_TWCR->TOTALH = TOTAL_HEIGHT;
1071 LTDC_TWCR->TOTALW = TOTAL_WIDTH;
1073 LTDC_L1WHPCR->Value = TimingParameters->HSYNC.BackPorch | ((TimingParameters->HSYNC.BackPorch + ConfiguredWidth - 1) << 16);
1075 LTDC_L1WVPCR->WVSPPOS = TimingParameters->VSYNC.BackPorch + ConfiguredHeight - 1;
1076 LTDC_L1WVPCR->WVSTPOS = TimingParameters->VSYNC.BackPorch;
1078 LTDC_L1CFBLR->Value = ((ConfiguredWidth * pixelSize) << 16) | ((ConfiguredWidth * pixelSize) + 3);
1080 LTDC_L1CFBLNR->Value = ConfiguredHeight;
1082 LTDC_L1BFCR->BF1 = 4;
1083 LTDC_L1BFCR->BF2 = 5;
1085 errorCode = oC_ErrorCode_None;
1098 return oC_ErrorCode_NotImplemented;
1102 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ oC_ErrorCode_t oC_LCDTFT_LLD_SetTimingParameters(const oC_LCDTFT_LLD_TimingParameters_t *TimingParameters)
oC_ErrorCode_t oC_LCDTFT_LLD_SetBackgroundColor(oC_Color_t Color, oC_ColorFormat_t ColorFormat)
oC_ErrorCode_t oC_LCDTFT_LLD_RestoreDefaultState(void)
oC_ErrorCode_t oC_LCDTFT_LLD_EnableOperations(void)
oC_ErrorCode_t oC_LCDTFT_LLD_SetPixelFormat(oC_ColorFormat_t PixelFormat)
double oC_Frequency_t
type to store frequency
oC_ErrorCode_t oC_LCDTFT_LLD_SetResolution(oC_Pixel_ResolutionUInt_t Width, oC_Pixel_ResolutionUInt_t Height)
oC_ErrorCode_t oC_LCDTFT_LLD_SetPower(oC_Power_t Power)
oC_ErrorCode_t oC_LCDTFT_LLD_SetColormapBuffer(const void *Buffer)
oC_ErrorCode_t oC_LCDTFT_LLD_SetPolarities(oC_LCDTFT_LLD_Polarity_t HSyncPolarity, oC_LCDTFT_LLD_Polarity_t VSyncPolarity, oC_LCDTFT_LLD_Polarity_t DataEnablePolarity)
The file with interface for LSF module.
oC_ErrorCode_t oC_LCDTFT_LLD_ReadPixelClockPolarity(oC_LCDTFT_LLD_PixelClockPolarity_t *outPixelPolarity)
The file with LLD interface for the MEM driver.
The file with LLD interface for the GPIO driver.
oC_ErrorCode_t oC_LCDTFT_LLD_ReadPower(oC_Power_t *outPower)
oC_ErrorCode_t oC_LCDTFT_LLD_ReadTimingParameters(oC_LCDTFT_LLD_TimingParameters_t *outTimingParameters)
The file with interface for the module library.
Output of the PLL connected to the LTDC module (LTDC Clock)
Something is powered off.
oC_ErrorCode_t oC_LCDTFT_LLD_ReadResolution(oC_Pixel_ResolutionUInt_t *outWidth, oC_Pixel_ResolutionUInt_t *outHeight)
oC_ErrorCode_t oC_LCDTFT_LLD_TurnOffDriver(void)
oC_ErrorCode_t oC_LCDTFT_LLD_TurnOnDriver(void)
oC_ErrorCode_t oC_LCDTFT_LLD_DisconnectPins(const oC_LCDTFT_LLD_Pins_t *Pins)
oC_ErrorCode_t oC_LCDTFT_LLD_ConnectPins(const oC_LCDTFT_LLD_Pins_t *Pins)
oC_ErrorCode_t oC_LCDTFT_LLD_ReadPolarities(oC_LCDTFT_LLD_Polarity_t *outHSyncPolarity, oC_LCDTFT_LLD_Polarity_t *outVSyncPolarity, oC_LCDTFT_LLD_Polarity_t *outDataEnablePolarity)
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
The file with functions for the bits operation.
oC_ErrorCode_t oC_LCDTFT_LLD_ReadPixelFormat(oC_ColorFormat_t *outPixelFormat)
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
oC_ErrorCode_t oC_LCDTFT_LLD_ReadFrequency(oC_Frequency_t *outFrequency)
static oC_Power_t oC_Machine_GetPowerStateForChannel(oC_Channel_t Channel)
returns power state for channel
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
oC_ErrorCode_t oC_LCDTFT_LLD_SetPixelClockPolarity(oC_LCDTFT_LLD_PixelClockPolarity_t PixelPolarity)
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
oC_ErrorCode_t oC_SaiPll_Configure(oC_SaiPll_OutputLine_t OutputLine, oC_Frequency_t Frequency, oC_Frequency_t PermissibleDifference, oC_Frequency_t *outRealFrequency)
Configures SAI PLL.
oC_ErrorCode_t oC_LCDTFT_LLD_SetFrequency(oC_Frequency_t Frequency, oC_Frequency_t PermissibleDifference)
oC_ErrorCode_t oC_LCDTFT_LLD_ReadBackgroundColor(oC_Color_t *outColor, oC_ColorFormat_t ColorFormat)
The file with LLD interface for the LCDTFT driver.
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
oC_Power_t
stores registers power state
oC_ErrorCode_t oC_LCDTFT_LLD_DisableOperations(void)
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off