Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cm3cpp_gpio.h - github.com/thirdpin/libopencm3_cpp_extensions.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 340c6f2c3df734e03bce4bb564e0c32022a57a77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * This file is part of the libopencm3_cpp_extensions project.
 * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions
 *
 * Copyright (C) 2016  Third Pin LLC
 * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
GPIO C++ Wrapper of libopencm3 library for STM32F2, STM32F4
*/

#ifndef CM3CPP_GPIO_H_
#define CM3CPP_GPIO_H_

// GENERAL INCLUDES
#include "stdint.h"

// LIBOPENCM3 INCLUDES
#include <libopencm3/stm32/exti.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#ifdef STM32F2
#include <libopencm3/stm32/f2/nvic.h>
#endif
#ifdef STM32F4
#include <libopencm3/stm32/f4/nvic.h>
#endif

// CM3CPP INCLUDES
#include "private/pinout.h"

namespace cm3cpp {

namespace gpio {

class Gpio
{
 public:
    struct Pinout
    {
        uint32_t port;
        uint16_t pin;
        uint8_t pin_number;
    };

    enum Mode
    {
        INPUT,
        OUTPUT,
        ALTERNATE_FUNCTION,
        ANALOG
    };

    enum PullMode
    {
        NO_PULL,
        PULL_UP,
        PULL_DOWN
    };

    enum OutputType
    {
        PUSH_PULL,
        OPEN_DRAIN
    };

    enum Speed
    {
        LOW_2MHz,
        MEDIUM_25MHz,
        FAST_50MHz,
        HIGH_SPEED_100MHz
    };

    enum AltFuncNumber
    {
        AF0,
        AF1,
        AF2,
        AF3,
        AF4,
        AF5,
        AF6,
        AF7,
        AF8,
        AF9,
        AF10,
        AF11,
        AF12,
        AF13,
        AF14,
        AF15
    };

    Gpio() {}
    Gpio(Pinout pinout);

    void init(Pinout pinout);
    void set();
    void clear();
    bool get() const;
    void toggle();
    uint16_t port_read() const;
    void port_write(uint16_t data);
    void port_config_lock();
    void mode_setup(Mode mode, PullMode pull_mode);
    void set_output_options(OutputType type, Speed speed);
    void set_af(AltFuncNumber af_num);
    void setup_exti(enum exti_trigger_type trigger);
    void clear_exti_pending_bit();
    bool get_exti_flag_status() const;

 private:
    Pinout _pinout;
};

}  // namespace gpio

}  // namespace cm3cpp

#endif /* CM3CPP_GPIO_H_ */