// Copyright 2020 Embedded Artistry LLC
// SPDX-License-Identifier: MIT

#ifndef STM32_RCC_HELPER_HPP_
#define STM32_RCC_HELPER_HPP_

#include <cstdint>

/** Translation class which handles STM32 RCC Interactions.
 *
 * The GPIO function implementations are isolated from this header because we do not want to make
 * the STM32 headers accessible from the rest of the system.
 *
 * This class cannot be directly instantiated.
 */
class STM32ClockControl
{
  public:
	/** Enable the peripheral clock to one of the UART/USART devices
	 *
	 * @precondition UART/USART Device is valid for the STM32 processor.
	 * @postcondition UART/USART device's peripheral clock is enabled.
	 *
	 * @param [in] timer The timer device to enable.
	 */
	static void uartEnable(uint8_t device) noexcept;

	/** Disable the peripheral clock to one of the UART/USART devices.
	 *
	 * @precondition UART/USART Device is valid for the STM32 processor.
	 * @postcondition UART/USART device's peripheral clock is disabled.
	 *
	 * @param [in] timer The timer device to disable.
	 */
	static void uartDisable(uint8_t device) noexcept;

	/** Enable the peripheral clock to one of the DMA devices
	 *
	 * @precondition DMA device is valid for the STM32 processor.
	 * @postcondition DMA device's peripheral clock is enabled
	 *
	 * @param [in] The DMA device ID to enable.
	 */
	static void dmaEnable(uint8_t device) noexcept;

	/** Disable the peripheral clock to one of the DMA devices
	 *
	 * @precondition DMA device is valid for the STM32 processor.
	 * @postcondition DMA device's peripheral clock is disabled
	 *
	 * @param [in] The DMA device ID to enable.
	 */
	static void dmaDisable(uint8_t device) noexcept;

	/** Enable the peripheral clock to one of the timer devices.
	 *
	 * @precondition timer is a valid channel for the STM32 processor.
	 * @postcondition Timer peripheral clock is enabled.
	 *
	 * @param [in] timer The timer device to enable.
	 */
	static void timerEnable(uint8_t timer) noexcept;

	/** Disable the peripheral clock to one of the timer devices.
	 *
	 * @precondition timer is a valid channel for the STM32 processor.
	 * @postcondition Timer peripheral clock is disabled.
	 *
	 * @param [in] timer The timer device to disable.
	 */
	static void timerDisable(uint8_t timer) noexcept;

	/** Enable the peripheral clock to one of the I2C devices.
	 *
	 * @precondition I2C is a valid channel for the STM32 processor.
	 * @postcondition I2C peripheral clock is enabled.
	 *
	 * @param [in] device The I2C device to enable.
	 */
	static void i2cEnable(uint8_t device);

	/** Disable the peripheral clock to one of the I2C devices.
	 *
	 * @precondition I2C is a valid channel for the STM32 processor.
	 * @postcondition I2C peripheral clock is disabled.
	 *
	 * @param [in] device The I2C device to disable.
	 */
	static void i2cDisable(uint8_t device);

  private:
	/// This class can't be instantiated
	STM32ClockControl() = default;
	~STM32ClockControl() = default;
};

#endif // STM32_RCC_HELPER_HPP_
