diff l476rg-hal-test/src/main.cpp @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0d3eea2dd7ea
children
line wrap: on
line diff
--- a/l476rg-hal-test/src/main.cpp	Fri Jan 20 03:40:30 2017 +0300
+++ b/l476rg-hal-test/src/main.cpp	Mon Jan 23 02:40:17 2017 +0300
@@ -49,7 +49,7 @@
 public:
 	typedef TCounter counter_t;
 
-	static void Init() {
+	static void init() {
 		TDev::instance()->EGR = TIM_EGR_UG;
 	}
 
@@ -111,32 +111,38 @@
 
 class AHB2Bus {
 public:
-	static void Enable(unsigned int flag) {
+	static void enable(unsigned int flag) {
 		RCC->AHB2ENR |= flag;
 	}
+
+	static uint32_t clock() {
+
+	}
 };
 
 class APB1Bus {
 public:
-	static void Enable(unsigned int flag) {
+	static void enable(unsigned int flag) {
 		RCC->APB1ENR1 |= flag;
 	}
 };
 
 class APB1Bus2 {
-	static void Enable(uint32_t flag) {
+	static void enable(uint32_t flag) {
 		RCC->APB1ENR2 |= flag;
 	}
 };
 
-template<typename TRegs, typename TBus, uint32_t BASE, uint32_t ENF> class TDevice {
+template <typename TRegs, typename TBus, uint32_t BASE, uint32_t ENF> class TDevice {
 public:
+	typedef TBus bus_t;
+
 	static TRegs* instance() {
 		return (TRegs*) BASE;
 	}
 
-	static void Enable() {
-		TBus::Enable(ENF);
+	static void enable() {
+		TBus::enable(ENF);
 	}
 
 	static uint32_t frequency() {
@@ -144,6 +150,75 @@
 	}
 };
 
+class OscMsi {
+};
+
+class OscHsi {
+};
+
+class OscHse {
+};
+
+class OscLsi {
+};
+
+class OscLse {
+};
+
+class Pll {
+};
+
+class Pclk1 {
+public:
+	uint32_t clock() {
+		return APB1Bus::clock();
+	}
+};
+
+class Rcc {
+public:
+	typedef enum {
+		PClk1,
+		Apb1TimerClk,
+		PClk2,
+		Apb2TimerClk,
+		HClk,
+		SysClk,
+		HsiClk,
+		HseClk,
+		LsiClk,
+		LseClk,
+		MsiClk,
+		PllClk,
+		PllQClk,
+		PllPClk,
+		PllSai1P,
+		PllSai1Q,
+		PllSai1R,
+		PllSai2P,
+		PllSai2R
+	} ClockSource;
+
+	template <ClockSource clk> unit32_t clock();
+};
+
+class SysClk {
+public:
+	uint32_t clock() {
+	}
+};
+
+class UartClockMux {
+public:
+	template <typename TClk> void select_clock_source();
+};
+
+template<> void UartClockMux::select_clock_source<Pclk1>() {
+}
+
+template<> void UartClockMux::select_clock_source<SysClk>() {
+}
+
 class Hardware {
 public:
 	typedef TDevice<GPIO_TypeDef, GPIOA_BASE, AHB2Bus, RCC_AHB2ENR_GPIOAEN> GpioA;