123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600 |
- #include "stm32f4xx_cec.h"
- #include "stm32f4xx_rcc.h"
- #if defined(STM32F446xx)
- #define BROADCAST_ADDRESS ((uint32_t)0x0000F)
- #define CFGR_CLEAR_MASK ((uint32_t)0x7000FE00)
- void CEC_DeInit(void)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, DISABLE);
- }
- void CEC_Init(CEC_InitTypeDef* CEC_InitStruct)
- {
- uint32_t tmpreg = 0;
-
- assert_param(IS_CEC_SIGNAL_FREE_TIME(CEC_InitStruct->CEC_SignalFreeTime));
- assert_param(IS_CEC_RX_TOLERANCE(CEC_InitStruct->CEC_RxTolerance));
- assert_param(IS_CEC_STOP_RECEPTION(CEC_InitStruct->CEC_StopReception));
- assert_param(IS_CEC_BIT_RISING_ERROR(CEC_InitStruct->CEC_BitRisingError));
- assert_param(IS_CEC_LONG_BIT_PERIOD_ERROR(CEC_InitStruct->CEC_LongBitPeriodError));
- assert_param(IS_CEC_BDR_NO_GEN_ERROR(CEC_InitStruct->CEC_BRDNoGen));
- assert_param(IS_CEC_SFT_OPTION(CEC_InitStruct->CEC_SFTOption));
-
- tmpreg = CEC->CFGR;
-
- tmpreg &= CFGR_CLEAR_MASK;
-
- tmpreg |= (CEC_InitStruct->CEC_SignalFreeTime | CEC_InitStruct->CEC_RxTolerance |
- CEC_InitStruct->CEC_StopReception | CEC_InitStruct->CEC_BitRisingError |
- CEC_InitStruct->CEC_LongBitPeriodError| CEC_InitStruct->CEC_BRDNoGen |
- CEC_InitStruct->CEC_SFTOption);
-
- CEC->CFGR = tmpreg;
- }
- void CEC_StructInit(CEC_InitTypeDef* CEC_InitStruct)
- {
- CEC_InitStruct->CEC_SignalFreeTime = CEC_SignalFreeTime_Standard;
- CEC_InitStruct->CEC_RxTolerance = CEC_RxTolerance_Standard;
- CEC_InitStruct->CEC_StopReception = CEC_StopReception_Off;
- CEC_InitStruct->CEC_BitRisingError = CEC_BitRisingError_Off;
- CEC_InitStruct->CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off;
- CEC_InitStruct->CEC_BRDNoGen = CEC_BRDNoGen_Off;
- CEC_InitStruct->CEC_SFTOption = CEC_SFTOption_Off;
- }
- void CEC_Cmd(FunctionalState NewState)
- {
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
-
- CEC->CR |= CEC_CR_CECEN;
- }
- else
- {
-
- CEC->CR &= ~CEC_CR_CECEN;
- }
- }
- void CEC_ListenModeCmd(FunctionalState NewState)
- {
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
-
- CEC->CFGR |= CEC_CFGR_LSTN;
- }
- else
- {
-
- CEC->CFGR &= ~CEC_CFGR_LSTN;
- }
- }
- void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress)
- {
- uint32_t tmp =0x00;
-
- assert_param(IS_CEC_ADDRESS(CEC_OwnAddress));
- tmp = 1 <<(CEC_OwnAddress + 16);
-
- CEC->CFGR |= tmp;
- }
- void CEC_OwnAddressClear(void)
- {
-
- CEC->CFGR = 0x0;
- }
- void CEC_SendData(uint8_t Data)
- {
-
- CEC->TXDR = Data;
- }
- uint8_t CEC_ReceiveData(void)
- {
-
- return (uint8_t)(CEC->RXDR);
- }
- void CEC_StartOfMessage(void)
- {
-
- CEC->CR |= CEC_CR_TXSOM;
- }
- void CEC_EndOfMessage(void)
- {
-
- CEC->CR |= CEC_CR_TXEOM;
- }
- void CEC_ITConfig(uint16_t CEC_IT, FunctionalState NewState)
- {
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- assert_param(IS_CEC_IT(CEC_IT));
- if (NewState != DISABLE)
- {
-
- CEC->IER |= CEC_IT;
- }
- else
- {
- CEC_IT =~CEC_IT;
-
- CEC->IER &= CEC_IT;
- }
- }
- FlagStatus CEC_GetFlagStatus(uint16_t CEC_FLAG)
- {
- FlagStatus bitstatus = RESET;
-
- assert_param(IS_CEC_GET_FLAG(CEC_FLAG));
-
-
- if ((CEC->ISR & CEC_FLAG) != (uint16_t)RESET)
- {
-
- bitstatus = SET;
- }
- else
- {
-
- bitstatus = RESET;
- }
-
- return bitstatus;
- }
- void CEC_ClearFlag(uint32_t CEC_FLAG)
- {
- assert_param(IS_CEC_CLEAR_FLAG(CEC_FLAG));
-
- CEC->ISR = CEC_FLAG;
- }
- ITStatus CEC_GetITStatus(uint16_t CEC_IT)
- {
- ITStatus bitstatus = RESET;
- uint32_t enablestatus = 0;
-
- assert_param(IS_CEC_GET_IT(CEC_IT));
-
- enablestatus = (CEC->IER & CEC_IT);
-
- if (((CEC->ISR & CEC_IT) != (uint32_t)RESET) && enablestatus)
- {
-
- bitstatus = SET;
- }
- else
- {
-
- bitstatus = RESET;
- }
-
- return bitstatus;
- }
- void CEC_ClearITPendingBit(uint16_t CEC_IT)
- {
- assert_param(IS_CEC_IT(CEC_IT));
-
- CEC->ISR = CEC_IT;
- }
- #endif
|