USB Host Shield 2.0
Loading...
Searching...
No Matches
UHS2_gpio.cpp
Go to the documentation of this file.
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation; either version 2 of the License, or
6(at your option) any later version.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17Contact information
18-------------------
19
20Circuits At Home, LTD
21Web : http://www.circuitsathome.com
22e-mail : support@circuitsathome.com
23
24UHS2_GPIO implements "wiring" style GPIO access. Implemented by Brian Walton brian@riban.co.uk
25 */
26
27#include "UHS2_gpio.h"
28
32UHS2_GPIO::UHS2_GPIO(USB *pUsb) : m_pUsb(pUsb)
33{
34}
35
41 if(pin > 7)
42 return;
43 uint8_t nValue = m_pUsb->gpioRdOutput();
44 uint8_t nMask = 1 << pin;
45 nValue &= (~nMask);
46 if(val)
47 nValue |= (nMask);
48 m_pUsb->gpioWr(nValue);
49}
50
56 if(pin > 7)
57 return -1;
58 uint8_t nMask = 1 << pin;
59 uint8_t nValue = m_pUsb->gpioRd();
60 return ((nValue & nMask)?1:0);
61}
62
69 if(pin > 7)
70 return -1;
71 uint8_t nMask = 1 << pin;
72 uint8_t nValue = m_pUsb->gpioRdOutput();
73 return ((nValue & nMask)?1:0);
74}
uint8_t gpioRd()
Reads the current GPI input values.
Definition usbhost.h:392
uint8_t gpioRdOutput()
Reads the current GPI output values.
Definition usbhost.h:405
void gpioWr(uint8_t data)
Definition usbhost.h:277
UHS2_GPIO(USB *pUsb)
Implement an instance of a UHS2_GPIO object.
Definition UHS2_gpio.cpp:32
void digitalWrite(uint8_t pin, uint8_t val)
Set a GPIO output value.
Definition UHS2_gpio.cpp:40
int digitalRead(uint8_t pin)
Read the value from a GPIO input pin.
Definition UHS2_gpio.cpp:55
int digitalReadOutput(uint8_t pin)
Read the value from a GPIO output pin.
Definition UHS2_gpio.cpp:68
Definition UsbCore.h:220