Skip to content

File gpio.h

File List > external-docs > libDaisy > src > per > gpio.h

Go to the documentation of this file

Source Code

#pragma once
#ifndef DSY_GPIO_H
#define DSY_GPIO_H
#include "daisy_core.h"

#ifdef __cplusplus

namespace daisy
{
class GPIO
{
  public:
    enum class Mode
    {
        INPUT,      
        OUTPUT,     
        OPEN_DRAIN, 
        ANALOG,     
    };

    enum class Pull
    {
        NOPULL,   
        PULLUP,   
        PULLDOWN, 
    };

    enum class Speed
    {
        LOW,
        MEDIUM,
        HIGH,
        VERY_HIGH,
    };

    struct Config
    {
        Pin   pin;
        Mode  mode;
        Pull  pull;
        Speed speed;

        Config()
        : pin(), mode(Mode::INPUT), pull(Pull::NOPULL), speed(Speed::LOW)
        {
        }
    };

    GPIO() {}

    void Init();

    void Init(const Config &cfg);

    void Init(Pin p, const Config &cfg);

    void Init(Pin   p,
              Mode  m  = Mode::INPUT,
              Pull  pu = Pull::NOPULL,
              Speed sp = Speed::LOW);

    void DeInit();

    bool Read();

    void Write(bool state);

    void Toggle();

    Config &GetConfig() { return cfg_; }

  private:
    uint32_t *GetGPIOBaseRegister();

    Config cfg_;

    uint32_t *port_base_addr_;
};

} // namespace daisy

#endif
#endif