123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #ifndef MBED_PORTINOUT_H
- #define MBED_PORTINOUT_H
- #include "platform/platform.h"
- #if defined (DEVICE_PORTINOUT) || defined(DOXYGEN_ONLY)
- #include "hal/port_api.h"
- #include "platform/mbed_critical.h"
- namespace mbed {
- class PortInOut {
- public:
-
- PortInOut(PortName port, int mask = 0xFFFFFFFF)
- {
- core_util_critical_section_enter();
- port_init(&_port, port, mask, PIN_INPUT);
- core_util_critical_section_exit();
- }
-
- void write(int value)
- {
- port_write(&_port, value);
- }
-
- int read()
- {
- return port_read(&_port);
- }
-
- void output()
- {
- core_util_critical_section_enter();
- port_dir(&_port, PIN_OUTPUT);
- core_util_critical_section_exit();
- }
-
- void input()
- {
- core_util_critical_section_enter();
- port_dir(&_port, PIN_INPUT);
- core_util_critical_section_exit();
- }
-
- void mode(PinMode mode)
- {
- core_util_critical_section_enter();
- port_mode(&_port, mode);
- core_util_critical_section_exit();
- }
-
- PortInOut &operator= (int value)
- {
- write(value);
- return *this;
- }
-
- PortInOut &operator= (PortInOut &rhs)
- {
- write(rhs.read());
- return *this;
- }
-
- operator int()
- {
- return read();
- }
- private:
- port_t _port;
- };
- }
- #endif
- #endif
|