Pigweed
 
Loading...
Searching...
No Matches
i2c_service.h
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include <array>
17#include <cstddef>
18#include <memory>
19#include <utility>
20
21#include "pw_function/function.h"
22#include "pw_i2c/i2c.pwpb.h"
23#include "pw_i2c/i2c.rpc.pwpb.h"
24#include "pw_i2c/initiator.h"
25#include "pw_rpc/pwpb/server_reader_writer.h"
26
27namespace pw::i2c {
28
30class I2cService final : public pw_rpc::pwpb::I2c::Service<I2cService> {
31 public:
36
38 explicit I2cService(InitiatorSelector&& initiator_selector)
39 : initiator_selector_(std::move(initiator_selector)) {}
40
43 const pwpb::I2cWriteRequest::Message& request,
44 pw::rpc::PwpbUnaryResponder<pwpb::I2cWriteResponse::Message>& responder);
45
47 void I2cRead(
48 const pwpb::I2cReadRequest::Message& request,
49 pw::rpc::PwpbUnaryResponder<pwpb::I2cReadResponse::Message>& responder);
50
51 private:
52 InitiatorSelector initiator_selector_;
53};
54
55} // namespace pw::i2c
RPC service for performing I2C transactions.
Definition: i2c_service.h:30
void I2cWrite(const pwpb::I2cWriteRequest::Message &request, pw::rpc::PwpbUnaryResponder< pwpb::I2cWriteResponse::Message > &responder)
Writes a message to the specified I2C device register.
I2cService(InitiatorSelector &&initiator_selector)
Creates an I2cService instance.
Definition: i2c_service.h:38
pw::Function< Initiator *(size_t pos)> InitiatorSelector
Definition: i2c_service.h:35
void I2cRead(const pwpb::I2cReadRequest::Message &request, pw::rpc::PwpbUnaryResponder< pwpb::I2cReadResponse::Message > &responder)
Reads a message from the specified I2C device register.
The common, base driver interface for initiating thread-safe transactions with devices on an I2C bus....
Definition: initiator.h:49
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:74