Differential pressure meter
Dependencies: TFT_Touch_WaveShare
interfaces.h
00001 #ifndef INTERFACES_H 00002 #define INTERFACES_H 00003 #include "mbed.h" 00004 #include "system.h" 00005 00006 /* Interfaces classes declarations */ 00007 00008 00009 template<typename I> 00010 class HwInterface 00011 { 00012 public: 00013 virtual I& handle() = 0; 00014 }; 00015 00016 // SPI_1 00017 class SPI__1 : public HwInterface<SPI> 00018 { 00019 public: 00020 SPI__1(); 00021 virtual SPI& handle(); 00022 private: 00023 static const PinName sclk = PA_5; 00024 static const PinName miso = PA_6; 00025 static const PinName mosi = PA_7; 00026 SPI spi; 00027 }; 00028 00029 SPI__1::SPI__1() 00030 : spi(SPI__1::mosi, SPI__1::miso, SPI__1::sclk) 00031 { 00032 spi.format(8,3); 00033 spi.frequency(1000000); // 1MHz clock 00034 } 00035 00036 SPI& SPI__1::handle() 00037 { 00038 return spi; 00039 } 00040 00041 00042 ///// Hardware Interface class ////// 00043 template <class I> 00044 struct HwInterfaceType { typedef I type; }; 00045 00046 class HwInterfaces 00047 { 00048 00049 public: 00050 static HwInterfaces& instance(); 00051 template<typename I> typename HwInterfaceType<I>::type& getHwInterface(); 00052 // specializations for HW interfaces 00053 private: 00054 HwInterfaces(); 00055 // defined hw interfaces 00056 SPI__1 spi; 00057 }; 00058 00059 00060 HwInterfaces::HwInterfaces() 00061 : spi() 00062 { 00063 } 00064 00065 HwInterfaces& HwInterfaces::instance() 00066 { 00067 static HwInterfaces interfaces; 00068 return interfaces; 00069 } 00070 00071 template<typename I> typename HwInterfaceType<I>::type& HwInterfaces::getHwInterface() 00072 { 00073 if (is_same<I,SPI__1>::value) 00074 { 00075 return spi; 00076 } 00077 } 00078 00079 #endif
Generated on Tue Jul 19 2022 13:55:32 by 1.7.2