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
00001 /* 00002 * ExioMcp23s17DigitalIn.h 00003 * 00004 * Created: 2016.10.30 00005 * 00006 */ 00007 00008 #ifndef _EXIOMCP2317SDIGITALIN_H_ 00009 #define _EXIOMCP2317SDIGITALIN_H_ 00010 00011 #include "mbed.h" 00012 #include "ExioMcp23s17.h" 00013 00014 class ExioMcp23s17DigitalIn { 00015 public: 00016 ExioMcp23s17DigitalIn(ExioMcp23s17* _pDevice, ExioPort _port, int _pin) : 00017 pDevice(_pDevice), 00018 port(_port), 00019 pin(_pin) 00020 { 00021 // set as input 00022 uint8_t tmp = pDevice->ioDirection(port); 00023 pDevice->ioDirection(port, tmp | (1 << pin)); 00024 } 00025 00026 void mode(PinMode pull) 00027 { 00028 uint8_t tmp = pDevice->ioPullup(port); 00029 switch (pull) { 00030 case PullUp: 00031 pDevice->ioPullup(port, tmp | (1 << pin)); 00032 break; 00033 case PullNone: 00034 pDevice->ioPullup(port, tmp & ~(1 << pin)); 00035 break; 00036 default: 00037 error("PinMode must be PullUp or PullNone"); 00038 } 00039 } 00040 00041 int read() 00042 { 00043 uint8_t data = pDevice->readPort(port); 00044 int bv = data & (1 << pin); 00045 return bv ? 1 : 0; 00046 } 00047 00048 protected: 00049 ExioMcp23s17* pDevice; 00050 ExioPort port; 00051 int pin; 00052 }; 00053 00054 #endif //_EXIOMCP2317SDIGITALIN_H_
Generated on Thu Jul 14 2022 16:20:00 by
1.7.2