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 "fsl_gpio.h" 17 #include "pw_digital_io/digital_io.h" 18 19 namespace pw::digital_io { 20 21 class McuxpressoDigitalOut : public pw::digital_io::DigitalOut { 22 public: 23 McuxpressoDigitalOut(GPIO_Type* base, 24 uint32_t port, 25 uint32_t pin, 26 pw::digital_io::State initial_state); 27 is_enabled()28 bool is_enabled() const { return enabled_; } 29 30 private: 31 pw::Status DoEnable(bool enable) override; 32 pw::Status DoSetState(pw::digital_io::State state) override; 33 34 GPIO_Type* base_; 35 const uint32_t port_; 36 const uint32_t pin_; 37 const pw::digital_io::State initial_state_; 38 bool enabled_ = false; 39 }; 40 41 class McuxpressoDigitalIn : public pw::digital_io::DigitalIn { 42 public: 43 McuxpressoDigitalIn(GPIO_Type* base, uint32_t port, uint32_t pin); 44 is_enabled()45 bool is_enabled() const { return enabled_; } 46 47 private: 48 pw::Status DoEnable(bool enable) override; 49 pw::Result<pw::digital_io::State> DoGetState() override; 50 51 GPIO_Type* base_; 52 const uint32_t port_; 53 const uint32_t pin_; 54 bool enabled_ = false; 55 }; 56 57 } // namespace pw::digital_io 58