YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
gpio_msp432.h
1/*
2 * gpio_msp432.h
3 *
4 * Created on: 29.02.2016
5 * Author: Andreas Terstegge
6 */
7
8#ifndef _GPIO_MSP432_H_
9#define _GPIO_MSP432_H_
10
11#include "gpio_interface.h"
12#include <cassert>
13
14extern "C" {
15void PORT1_IRQHandler(void);
16void PORT2_IRQHandler(void);
17void PORT3_IRQHandler(void);
18void PORT4_IRQHandler(void);
19void PORT5_IRQHandler(void);
20void PORT6_IRQHandler(void);
21}
22
24public:
25 explicit gpio_msp432(gpio_pin_t gpio = 0xffff) {
26 _port = PORT(gpio);
27 _pin = PIN (gpio);
28 }
29 ~gpio_msp432() override = default;
30
31 // No copy, assignment is value passing
32 gpio_msp432 (const gpio_msp432&) = delete;
33 gpio_msp432& operator= (const gpio_msp432 & lhs) {
34 this->gpioWrite(lhs.operator bool());
35 return *this;
36 };
37
38 inline void setGpio(gpio_pin_t gpio) override {
39 _port = PORT(gpio);
40 _pin = PIN (gpio);
41 assert((_port > 0) && (_port < 11) && (_pin < 8));
42 }
43 inline gpio_pin_t getGpio() const override {
44 return (_port << 8) | _pin;
45 }
46
47 // Generic GPIO methods
49 void gpioMode (gpio_mode_t mode) override;
50 bool gpioRead () const override;
51 void gpioWrite (bool value) override;
52 void gpioToggle() override;
53
54 // Interrupt handling
55 void gpioAttachIrq (gpio_mode_t mode,
56 function<void()> handler) override;
57 void gpioDetachIrq () override;
58 void gpioEnableIrq () override;
59 void gpioDisableIrq() override;
60
61 // MSP432 specific methods
63 void setSEL (uint8_t sel) const;
64 void setMode(gpio_mode_t mode);
65
66 // IRQ handlers are our best friends
68 friend void PORT1_IRQHandler(void);
69 friend void PORT2_IRQHandler(void);
70 friend void PORT3_IRQHandler(void);
71 friend void PORT4_IRQHandler(void);
72 friend void PORT5_IRQHandler(void);
73 friend void PORT6_IRQHandler(void);
74
75 using gpio_interface::operator =;
76 using gpio_interface::operator bool;
77
78private:
79 uint8_t _port;
80 uint8_t _pin;
81 bool _open_source {false};
82 bool _open_drain {false};
83 bool _pull_up {false};
84 bool _pull_down {false};
85
86 static void handleIrq(uint8_t port, uint8_t pin);
87 static function<void()> _intHandler[6][8];
88 static bool _both[6][8];
89};
90
91#endif // _GPIO_MSP432_H_