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// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_HARDWARE_MCP23017_MCP23017_HPP
5#define TETL_HARDWARE_MCP23017_MCP23017_HPP
6
7#include <etl/version.hpp>
8
9#include <etl/cstdint.hpp>
10#include <etl/utility.hpp>
11
12namespace etl::experimental::hardware::mcp23017 {
13// ports
14enum struct port : etl::uint16_t {
15 a = 0x00,
16 b = 0x01,
17};
18
19// Address (A0-A2)
20enum struct address : etl::uint16_t {
21 a20 = 0x20,
22 a21 = 0x21,
23 a22 = 0x22,
24 a23 = 0x23,
25 a24 = 0x24,
26 a25 = 0x25,
27 a26 = 0x26,
28 a27 = 0x27,
29};
30
31// registers
32enum struct registers : etl::uint16_t {
33 io_direction_a = 0x00, // datasheet: IODIRA
34 io_direction_b = 0x01, // datasheet: IODIRB
35 IPOLA = 0x02,
36 IPOLB = 0x03,
37 GPINTENA = 0x04,
38 GPINTENB = 0x05,
39 DEFVALA = 0x06,
40 DEFVALB = 0x07,
41 INTCONA = 0x08,
42 INTCONB = 0x09,
43 // IOCON 0x0A
44 // IOCON 0x0B
45 GPPUA = 0x0C,
46 GPPUB = 0x0D,
47 INTFA = 0x0E,
48 INTFB = 0x0F,
49 INTCAPA = 0x10,
50 INTCAPB = 0x11,
51 GPIOA = 0x12,
52 GPIOB = 0x13,
53 OLATA = 0x14,
54 OLATB = 0x15,
55};
56
57// I/O Direction
58// Default state: io_direction::all_output
59enum struct io_direction : etl::uint8_t {
60 all_output = 0x00,
61 all_input = 0xFF,
62 input_O0 = 0x01,
63 input_O1 = 0x02,
64 input_O2 = 0x04,
65 input_O3 = 0x08,
66 input_O4 = 0x10,
67 input_O5 = 0x20,
68 input_O6 = 0x40,
69 input_O7 = 0x80,
70};
71
72// Input Polarity
73// Default state: MCP23017_IPOL_ALL_NORMAL
74enum struct io_polarity : etl::uint8_t {
75 all_normal = 0x00,
76 all_inverted = 0xFF,
77 inverted_O0 = 0x01,
78 inverted_O1 = 0x02,
79 inverted_O2 = 0x04,
80 inverted_O3 = 0x08,
81 inverted_O4 = 0x10,
82 inverted_O5 = 0x20,
83 inverted_O6 = 0x40,
84 inverted_O7 = 0x80,
85};
86
87// Pull-Up Resistor
88// Default state: MCP23017_GPPU_ALL_DISABLED
90 all_disabled = 0x00,
91 all_enabled = 0xFF,
92 enabled_O0 = 0x01,
93 enabled_O1 = 0x02,
94 enabled_O2 = 0x04,
95 enabled_O3 = 0x08,
96 enabled_O4 = 0x10,
97 enabled_O5 = 0x20,
98 enabled_O6 = 0x40,
99 enabled_O7 = 0x80,
100};
101
102template <typename Driver>
103struct device {
104public:
105 explicit device() = default;
106 ~device() = default;
107 device(device&&) = delete;
108 device(device const&) = delete;
109 auto operator=(device&&) -> device& = delete;
110 auto operator=(device const&) -> device& = delete;
111
112 auto init() -> bool
113 {
114 return true;
115 }
116
117 auto set_io_direction(port p, io_direction direction) -> void
118 {
119 etl::ignore_unused(p, direction);
120 }
121};
122} // namespace etl::experimental::hardware::mcp23017
123
124#endif // TETL_HARDWARE_MCP23017_MCP23017_HPP
address
Definition mcp23017.hpp:20
pull_up_resistor
Definition mcp23017.hpp:89
io_polarity
Definition mcp23017.hpp:74
io_direction
Definition mcp23017.hpp:59
registers
Definition mcp23017.hpp:32
port
Definition mcp23017.hpp:14
Definition mcp23017.hpp:12
Definition adjacent_find.hpp:9
constexpr auto ignore_unused(Types &&...) -> void
Explicitly ignore arguments or variables.
Definition ignore_unused.hpp:18
auto init() -> bool
Definition mcp23017.hpp:112
auto operator=(device &&) -> device &=delete
auto operator=(device const &) -> device &=delete
auto set_io_direction(port p, io_direction direction) -> void
Definition mcp23017.hpp:117