Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ExioMcp23s17DigitalIn.h
- Committer:
- ryood
- Date:
- 2016-10-30
- Revision:
- 3:aaea541bdbf9
- Child:
- 4:4a8ba9d9926b
File content as of revision 3:aaea541bdbf9:
/*
 * ExioDigitalIn.h
 *
 * Created: 2016.10.30
 *
 */
 
#ifndef _EXIOMCP2317SDIGITALIN_H_
#define _EXIOMCP2317SDIGITALIN_H_
#include "mbed.h"
#include "ExioMcp23s17.h"
class ExioMcp23s17DigitalIn {
public:
    ExioMcp23s17DigitalIn(ExioMcp23s17& _device, ExioPort _port, int _pin) : 
        device(_device),
        port(_port),
        pin(_pin)
    {
        // set as input
        uint8_t tmp = device.ioDirection(port);
        device.ioDirection(port, tmp | (1 << pin));
        //printf("pin:%d port:%d %d\r\n", pin, port, device.ioDirection(port));
    }
    
    void mode(PinMode pull)
    {
        uint8_t tmp = device.ioPullup(port);
        switch (pull) {
        case PullUp:
            device.ioPullup(port, tmp | (1 << pin));
            break;
        case PullNone:
            device.ioPullup(port, tmp & ~(1 << pin));
            break;
        default:
            error("PinMode must be PullUp or PullNone");
        }
    }
    
    int read()
    {
        uint8_t data = device.readPort(port);
        int bv = data & (1 << pin);
        return bv ? 1 : 0;
    }
    
protected:
    ExioMcp23s17 device;
    ExioPort port;
    int pin;
};
#endif //_EXIOMCP2317SDIGITALIN_H_