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