OpenMPTL - STM32F10X
C++ Microprocessor Template Library
spi.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ARCH_SPI_HPP_INCLUDED
22 #define ARCH_SPI_HPP_INCLUDED
23 
24 #include "../../../common/spi.hpp"
25 
26 namespace mptl {
27 
28 namespace mpl
29 {
30  template< typename gpio_type, freq_t gpio_speed >
31  struct spi_gpio_output_resources {
32  using type = typelist<
33  typename gpio_type::resources,
34  typename gpio_type::mode::template output< gpio_speed >,
35  typename gpio_type::output_type::af_push_pull
36  >;
37  };
38  template< freq_t gpio_speed >
39  struct spi_gpio_output_resources< void, gpio_speed > {
40  using type = void;
41  };
42 
43  template< typename gpio_type >
44  struct spi_gpio_input_resources {
45  using type = typelist<
46  typename gpio_type::resources,
47  typename gpio_type::mode::input,
48  typename gpio_type::input_type::pull_up_down
49  >;
50  };
51  template<>
52  struct spi_gpio_input_resources< void > {
53  using type = void;
54  };
55 } // namespace mpl
56 
57 
58 template<
59  unsigned spi_no,
60  typename system_clock_type,
61  typename gpio_sck_type = void,
62  typename gpio_miso_type = void,
63  typename gpio_mosi_type = void,
64  freq_t gpio_output_speed = mhz(50)
65  >
66 class spi : public spi_stm32_common< spi_no, system_clock_type >
67 {
69 
70 public:
71 
72  using resources = typelist<
73  typename base_type::resources,
74  typename mpl::spi_gpio_output_resources< gpio_sck_type, gpio_output_speed >::type,
75  typename mpl::spi_gpio_input_resources< gpio_miso_type >::type,
76  typename mpl::spi_gpio_output_resources< gpio_mosi_type, gpio_output_speed >::type
77  >;
78 };
79 
80 } // namespace mptl
81 
82 #endif // ARCH_SPI_HPP_INCLUDED
Definition: spi.hpp:66
unsigned int freq_t
typelist< typename base_type::resources, typename mpl::spi_gpio_output_resources< gpio_sck_type, gpio_output_speed >::type, typename mpl::spi_gpio_input_resources< gpio_miso_type >::type, typename mpl::spi_gpio_output_resources< gpio_mosi_type, gpio_output_speed >::type > resources
Definition: spi.hpp:77
Definition: rcc.hpp:221
typename mpl::make_typelist< sane_typelist<>, Tp... >::type typelist
static constexpr freq_t mhz(unsigned long long x)