Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

libs/Pin.h

Committer:
Bigcheese
Date:
2014-03-01
Revision:
1:ab59fc9af055
Parent:
0:31e91bb0ef3c
Child:
2:1df0b61d3b5a

File content as of revision 1:ab59fc9af055:

#ifndef PIN_H
#define PIN_H

#include <stdlib.h>
#include "mbed.h" // smoothed mbed.h lib
#include "libs/Kernel.h"
#include "libs/utils.h"
#include <string>

class Pin{
    public:
        Pin() { }

        Pin* from_string(std::string value){
            gpio_init(&pin, A0, PIN_INPUT);
            return this;
        }

        inline Pin*  as_output(){
            gpio_dir(&pin, PIN_OUTPUT);
            return this;
        }  

        inline Pin*  as_input(){
            gpio_dir(&pin, PIN_INPUT);
            return this;
        }  

        inline Pin* as_open_drain(){
            gpio_mode(&pin, OpenDrain);
            return this;
        }

        inline bool get(){
            return this->inverting ^ gpio_read(&pin);
        }

        inline void set(bool value){
            value = this->inverting ^ value;
            gpio_write(&pin, value);
        }

        bool inverting; 
        gpio_t pin;
};

#endif