#ifndef LL_RCC_H #define LL_RCC_H #include /// @brief enable clock for the given timer /// @param[in] tim: timer instance static inline void rcc_enable_timer_clock(TIM_TypeDef *tim) { if (tim == TIM1) SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN); else if (tim == TIM2) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_TIM2EN); else if (tim == TIM3) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_TIM3EN); } /// @brief enable clock for the given uart /// @param[in] uart: uart instance static inline void rcc_enable_uart_clock(USART_TypeDef *uart) { if (uart == USART1) SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN); else if (uart == USART2) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USART2EN); else if (uart == USART3) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USART3EN); else if (uart == UART4) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_UART4EN); else if (uart == UART5) SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_UART5EN); } static inline void rcc_enable_adc_clock(ADC_TypeDef *adc) { if (adc == ADC1) RCC->AHB2ENR1 |= RCC_AHB2ENR1_ADC12EN; } typedef enum { PCLK1, ///< Peripheral clock 1 (APB1) SYSCLK, ///< System clock HSI16, ///< Internal 16 MHz RC oscillator MSIK, ///< Internal MSI clock } I2C_CLOCKS; ///< I2C clock sources source /// @brief enable and select clock for I2C module /// @param[in] i2c: I2C module - I2C1, I2C2, I2C3 /// @param[in] clock: clock source: PCLK1, SYSCLK, HSI16, MSIK static inline void rcc_enable_i2c_clock(I2C_TypeDef *i2c, I2C_CLOCKS clock) { if (i2c == I2C1) { SET_BIT(RCC->CCIPR1, clock << RCC_CCIPR1_I2C1SEL_Pos); SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_I2C1EN); } else if (i2c == I2C2) { SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_I2C2EN); SET_BIT(RCC->CCIPR1, clock << RCC_CCIPR1_I2C2SEL_Pos); } else if (i2c == I2C3) { SET_BIT(RCC->CCIPR3, clock << RCC_CCIPR3_I2C3SEL_Pos); SET_BIT(RCC->APB3ENR, RCC_APB3ENR_I2C3EN); } } /// @brief enable dma clock /// @param[in] dma: dma instance static inline void rcc_enable_dma_clock(DMA_TypeDef *dma) { if (dma == GPDMA1) SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPDMA1EN); } /// @brief enable clock for the given dcmi /// @param[in] dcmi: dcmi instance static inline void rcc_enable_dcmi_clock(DCMI_TypeDef *dcmi) { if (dcmi == DCMI) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_DCMI_PSSIEN); } /// @brief enable clock for the given port /// @param[in] gpio: port instance static inline void rcc_enable_gpio_clock(GPIO_TypeDef *gpio) { if (gpio == GPIOA) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOAEN); else if (gpio == GPIOB) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOBEN); else if (gpio == GPIOC) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOCEN); else if (gpio == GPIOD) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIODEN); else if (gpio == GPIOE) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOEEN); else if (gpio == GPIOF) SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOFEN); else if (gpio == GPIOG) { SET_BIT(RCC->AHB2ENR1, RCC_AHB2ENR1_GPIOGEN); SET_BIT(PWR->SVMCR, PWR_SVMCR_IO2SV); } } #endif //LL_RCC_H