Differential pressure meter
Dependencies: TFT_Touch_WaveShare
Utils/interfaces.h@1:c311d5f59c8b, 2018-04-03 (annotated)
- Committer:
- igbt6
- Date:
- Tue Apr 03 20:13:35 2018 +0000
- Revision:
- 1:c311d5f59c8b
- Parent:
- 0:619824763516
Differential pressure meter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igbt6 | 0:619824763516 | 1 | #ifndef INTERFACES_H |
igbt6 | 0:619824763516 | 2 | #define INTERFACES_H |
igbt6 | 0:619824763516 | 3 | #include "mbed.h" |
igbt6 | 0:619824763516 | 4 | #include "system.h" |
igbt6 | 0:619824763516 | 5 | |
igbt6 | 0:619824763516 | 6 | /* Interfaces classes declarations */ |
igbt6 | 0:619824763516 | 7 | |
igbt6 | 0:619824763516 | 8 | |
igbt6 | 0:619824763516 | 9 | template<typename I> |
igbt6 | 0:619824763516 | 10 | class HwInterface |
igbt6 | 0:619824763516 | 11 | { |
igbt6 | 0:619824763516 | 12 | public: |
igbt6 | 0:619824763516 | 13 | virtual I& handle() = 0; |
igbt6 | 0:619824763516 | 14 | }; |
igbt6 | 0:619824763516 | 15 | |
igbt6 | 0:619824763516 | 16 | // SPI_1 |
igbt6 | 0:619824763516 | 17 | class SPI__1 : public HwInterface<SPI> |
igbt6 | 0:619824763516 | 18 | { |
igbt6 | 0:619824763516 | 19 | public: |
igbt6 | 0:619824763516 | 20 | SPI__1(); |
igbt6 | 0:619824763516 | 21 | virtual SPI& handle(); |
igbt6 | 0:619824763516 | 22 | private: |
igbt6 | 0:619824763516 | 23 | static const PinName sclk = PA_5; |
igbt6 | 0:619824763516 | 24 | static const PinName miso = PA_6; |
igbt6 | 0:619824763516 | 25 | static const PinName mosi = PA_7; |
igbt6 | 0:619824763516 | 26 | SPI spi; |
igbt6 | 0:619824763516 | 27 | }; |
igbt6 | 0:619824763516 | 28 | |
igbt6 | 0:619824763516 | 29 | SPI__1::SPI__1() |
igbt6 | 0:619824763516 | 30 | : spi(SPI__1::mosi, SPI__1::miso, SPI__1::sclk) |
igbt6 | 0:619824763516 | 31 | { |
igbt6 | 0:619824763516 | 32 | spi.format(8,3); |
igbt6 | 0:619824763516 | 33 | spi.frequency(1000000); // 1MHz clock |
igbt6 | 0:619824763516 | 34 | } |
igbt6 | 0:619824763516 | 35 | |
igbt6 | 0:619824763516 | 36 | SPI& SPI__1::handle() |
igbt6 | 0:619824763516 | 37 | { |
igbt6 | 0:619824763516 | 38 | return spi; |
igbt6 | 0:619824763516 | 39 | } |
igbt6 | 0:619824763516 | 40 | |
igbt6 | 0:619824763516 | 41 | |
igbt6 | 0:619824763516 | 42 | ///// Hardware Interface class ////// |
igbt6 | 0:619824763516 | 43 | template <class I> |
igbt6 | 0:619824763516 | 44 | struct HwInterfaceType { typedef I type; }; |
igbt6 | 0:619824763516 | 45 | |
igbt6 | 0:619824763516 | 46 | class HwInterfaces |
igbt6 | 0:619824763516 | 47 | { |
igbt6 | 0:619824763516 | 48 | |
igbt6 | 0:619824763516 | 49 | public: |
igbt6 | 0:619824763516 | 50 | static HwInterfaces& instance(); |
igbt6 | 0:619824763516 | 51 | template<typename I> typename HwInterfaceType<I>::type& getHwInterface(); |
igbt6 | 0:619824763516 | 52 | // specializations for HW interfaces |
igbt6 | 0:619824763516 | 53 | private: |
igbt6 | 0:619824763516 | 54 | HwInterfaces(); |
igbt6 | 0:619824763516 | 55 | // defined hw interfaces |
igbt6 | 0:619824763516 | 56 | SPI__1 spi; |
igbt6 | 0:619824763516 | 57 | }; |
igbt6 | 0:619824763516 | 58 | |
igbt6 | 0:619824763516 | 59 | |
igbt6 | 0:619824763516 | 60 | HwInterfaces::HwInterfaces() |
igbt6 | 0:619824763516 | 61 | : spi() |
igbt6 | 0:619824763516 | 62 | { |
igbt6 | 0:619824763516 | 63 | } |
igbt6 | 0:619824763516 | 64 | |
igbt6 | 0:619824763516 | 65 | HwInterfaces& HwInterfaces::instance() |
igbt6 | 0:619824763516 | 66 | { |
igbt6 | 0:619824763516 | 67 | static HwInterfaces interfaces; |
igbt6 | 0:619824763516 | 68 | return interfaces; |
igbt6 | 0:619824763516 | 69 | } |
igbt6 | 0:619824763516 | 70 | |
igbt6 | 0:619824763516 | 71 | template<typename I> typename HwInterfaceType<I>::type& HwInterfaces::getHwInterface() |
igbt6 | 0:619824763516 | 72 | { |
igbt6 | 0:619824763516 | 73 | if (is_same<I,SPI__1>::value) |
igbt6 | 0:619824763516 | 74 | { |
igbt6 | 0:619824763516 | 75 | return spi; |
igbt6 | 0:619824763516 | 76 | } |
igbt6 | 0:619824763516 | 77 | } |
igbt6 | 0:619824763516 | 78 | |
igbt6 | 0:619824763516 | 79 | #endif |