tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
mcp23017.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_HARDWARE_MCP23017_MCP23017_HPP
4#define TETL_HARDWARE_MCP23017_MCP23017_HPP
5
6#include <etl/version.hpp>
7
8#include <etl/cstdint.hpp>
9#include <etl/utility.hpp>
10
12// ports
13enum struct port : etl::uint16_t {
14 a = 0x00,
15 b = 0x01,
16};
17
18// Address (A0-A2)
19enum struct address : etl::uint16_t {
20 a20 = 0x20,
21 a21 = 0x21,
22 a22 = 0x22,
23 a23 = 0x23,
24 a24 = 0x24,
25 a25 = 0x25,
26 a26 = 0x26,
27 a27 = 0x27,
28};
29
30// registers
31enum struct registers : etl::uint16_t {
32 io_direction_a = 0x00, // datasheet: IODIRA
33 io_direction_b = 0x01, // datasheet: IODIRB
34 IPOLA = 0x02,
35 IPOLB = 0x03,
36 GPINTENA = 0x04,
37 GPINTENB = 0x05,
38 DEFVALA = 0x06,
39 DEFVALB = 0x07,
40 INTCONA = 0x08,
41 INTCONB = 0x09,
42 // IOCON 0x0A
43 // IOCON 0x0B
44 GPPUA = 0x0C,
45 GPPUB = 0x0D,
46 INTFA = 0x0E,
47 INTFB = 0x0F,
48 INTCAPA = 0x10,
49 INTCAPB = 0x11,
50 GPIOA = 0x12,
51 GPIOB = 0x13,
52 OLATA = 0x14,
53 OLATB = 0x15,
54};
55
56// I/O Direction
57// Default state: io_direction::all_output
59 all_output = 0x00,
60 all_input = 0xFF,
61 input_O0 = 0x01,
62 input_O1 = 0x02,
63 input_O2 = 0x04,
64 input_O3 = 0x08,
65 input_O4 = 0x10,
66 input_O5 = 0x20,
67 input_O6 = 0x40,
68 input_O7 = 0x80,
69};
70
71// Input Polarity
72// Default state: MCP23017_IPOL_ALL_NORMAL
74 all_normal = 0x00,
84};
85
86// Pull-Up Resistor
87// Default state: MCP23017_GPPU_ALL_DISABLED
91 enabled_O0 = 0x01,
92 enabled_O1 = 0x02,
93 enabled_O2 = 0x04,
94 enabled_O3 = 0x08,
95 enabled_O4 = 0x10,
96 enabled_O5 = 0x20,
97 enabled_O6 = 0x40,
98 enabled_O7 = 0x80,
99};
100
101template <typename Driver>
102struct device {
103public:
104 explicit device() = default;
105 ~device() = default;
106 device(device&&) = delete;
107 device(device const&) = delete;
108 auto operator=(device&&) -> device& = delete;
109 auto operator=(device const&) -> device& = delete;
110
111 auto init() -> bool { return true; }
112
113 auto set_io_direction(port p, io_direction direction) -> void { etl::ignore_unused(p, direction); }
114};
115} // namespace etl::experimental::hardware::mcp23017
116
117#endif // TETL_HARDWARE_MCP23017_MCP23017_HPP
Definition mcp23017.hpp:11
address
Definition mcp23017.hpp:19
pull_up_resistor
Definition mcp23017.hpp:88
io_polarity
Definition mcp23017.hpp:73
io_direction
Definition mcp23017.hpp:58
registers
Definition mcp23017.hpp:31
port
Definition mcp23017.hpp:13
TETL_BUILTIN_UINT16 uint16_t
Unsigned integer type with width of exactly 16 bits.
Definition uint_t.hpp:14
TETL_BUILTIN_UINT8 uint8_t
Unsigned integer type with width of exactly 8 bits.
Definition uint_t.hpp:11
constexpr auto ignore_unused(Types &&...) -> void
Explicitly ignore arguments or variables.
Definition ignore_unused.hpp:17
auto init() -> bool
Definition mcp23017.hpp:111
auto operator=(device &&) -> device &=delete
auto operator=(device const &) -> device &=delete
auto set_io_direction(port p, io_direction direction) -> void
Definition mcp23017.hpp:113