-
Notifications
You must be signed in to change notification settings - Fork 0
/
digital_out.h
88 lines (73 loc) · 1.77 KB
/
digital_out.h
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
/*!
* @file digital_out.h v1.0
* @Copyright © 2021 Kazushi Kurasawa
*
* @date 2021.02.14
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#ifndef MSLH_DIGITAL_OUT_H
#define MSLH_DIGITAL_OUT_H
#include "arm_math.h"
#include "gpio.h"
namespace mslh {
/**
* @brief
* A digital output, used for setting the state of a GPIO.
*
* Example:
* @code
* // Toggle a LED
* #include "digitalout.h"
*
* using namespace mslh;
*
* DigitalOut led(GPIOC, GPIO_PIN_3);
*
* int main() {
* // Abbreviation Microcomputer startup settings
*
* MX_GPIO_Init(); // Need setup HAL_GPIO.
*
* while(1) {
* led = !led;
* HAL_Delay(100);
* }
* }
* @endcode
*/
class DigitalOut {
public:
/**
* @param GPIO pin in the case of "PC_5", they are ""GPIOC" and """GPIO_PIN_6".
* */
DigitalOut(GPIO_TypeDef *gpio_x, uint16_t gpio_pin);
DigitalOut(const DigitalOut &obj);
/**
* @fn
* Rewrites GPIO_Pinstate(pin output).
*
* @note
* This class's operator supports the same functionality
* by treating GPIO_Pinstate(pin output) like a variable.
*
* @param GPIO_Pinstate. 0 is false, else true.
*/
void write(int32_t value);
DigitalOut& operator= (int32_t value);
/**
* @fn
* GPIO_Pinstate (pin output) can be treated like a variable. <br>
* ピン出力を変数のように扱えるようになるが,バグの温床となる可能性もある.
*/
operator int32_t () const;
// operator int32_t (){ return _pinstate; }
private:
GPIO_TypeDef *_gpio_x;
const uint16_t _gpio_pin;
int32_t _pinstate;
friend class DigitalBusOut;
};
} // namespace mslh
#endif //MSLH_DIGITAL_OUT_H