1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library ddk.protocol.gpio;
6
7using zx;
8
9/// Flags for `ConfigIn`.
10const uint32 GPIO_PULL_DOWN = 0x0;
11const uint32 GPIO_PULL_UP = 0x1;
12const uint32 GPIO_NO_PULL = 0x2;
13const uint32 GPIO_PULL_MASK = 0x3;
14
15/// Values for `SetPolarity`.
16enum GpioPolarity : uint32 {
17    LOW = 0x0;
18    HIGH = 0x1;
19};
20
21[Layout = "ddk-protocol", HandleWrappers]
22interface Gpio {
23    /// Configures a GPIO for input.
24    ConfigIn(uint32 flags) -> (zx.status s);
25    /// Configures a GPIO for output.
26    ConfigOut(uint8 initial_value) -> (zx.status s);
27    /// Configures the GPIO pin for an alternate function (I2C, SPI, etc)
28    /// the interpretation of "function" is platform dependent.
29    SetAltFunction(uint64 function) -> (zx.status s);
30    /// Reads the current value of a GPIO (0 or 1).
31    Read()-> (zx.status s, uint8 value);
32    /// Sets the current value of the GPIO (any non-zero value maps to 1).
33    Write(uint8 value) -> (zx.status s);
34    /// Gets an interrupt object pertaining to a particular GPIO pin.
35    GetInterrupt(uint32 flags) -> (zx.status s, handle<interrupt> irq);
36    /// Release the interrupt.
37    ReleaseInterrupt()-> (zx.status s);
38    /// Set GPIO polarity.
39    SetPolarity(GpioPolarity polarity) -> (zx.status s);
40};
41