Skip to content
This repository was archived by the owner on Jun 26, 2021. It is now read-only.

Commit e764bfe

Browse files
authored
Merge pull request #13 from adafruit/actionci
Moved to actions, doxygen
2 parents 05fc9b8 + 1909f9c commit e764bfe

File tree

5 files changed

+140
-73
lines changed

5 files changed

+140
-73
lines changed

.github/workflows/githubci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Arduino Library CI
2+
3+
on: [pull_request, push, repository_dispatch]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/setup-python@v1
11+
with:
12+
python-version: '3.x'
13+
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v2
15+
with:
16+
repository: adafruit/ci-arduino
17+
path: ci
18+
19+
- name: pre-install
20+
run: bash ci/actions_install.sh
21+
22+
- name: test platforms
23+
run: python3 ci/build_platform.py main_platforms
24+
25+
- name: clang
26+
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
27+
28+
- name: doxygen
29+
env:
30+
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
31+
PRETTYNAME : "Adafruit MCP23008 Library"
32+
run: bash ci/doxy_gen_and_deploy.sh

Adafruit_MCP23008.cpp

+46-44
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
1-
/***************************************************
2-
This is a library for the MCP23008 i2c port expander
3-
4-
These displays use I2C to communicate, 2 pins are required to
5-
interface
6-
Adafruit invests time and resources providing this open source code,
7-
please support Adafruit and open-source hardware by purchasing
8-
products from Adafruit!
9-
10-
Written by Limor Fried/Ladyada for Adafruit Industries.
11-
BSD license, all text above must be included in any redistribution
12-
****************************************************/
1+
/*!
2+
* @file Adafruit_MCP23008.cpp
3+
*
4+
* @mainpage Adafruit MCP23008 Library
5+
*
6+
* @section intro_sec Introduction
7+
*
8+
* This is a library for the MCP23008 i2c port expander
9+
*
10+
* These displays use I2C to communicate, 2 pins are required to
11+
* interface
12+
* Adafruit invests time and resources providing this open source code,
13+
* please support Adafruit and open-source hardware by purchasing
14+
* products from Adafruit!
15+
*
16+
* @section author Author
17+
*
18+
* Written by Limor Fried/Ladyada for Adafruit Industries.
19+
*
20+
* @section license License
21+
*
22+
* BSD license, all text above must be included in any redistribution
23+
*/
1324

1425
#if ARDUINO >= 100
15-
#include "Arduino.h"
26+
#include "Arduino.h"
1627
#else
17-
#include "WProgram.h"
28+
#include "WProgram.h"
1829
#endif
1930
#ifdef __AVR_ATtiny85__
20-
#include <TinyWireM.h>
21-
#define Wire TinyWireM
31+
#include <TinyWireM.h>
32+
#define Wire TinyWireM
2233
#else
23-
#include <Wire.h>
34+
#include <Wire.h>
2435
#endif
2536

2637
#ifdef __AVR
27-
#include <avr/pgmspace.h>
38+
#include <avr/pgmspace.h>
2839
#elif defined(ESP8266)
29-
#include <pgmspace.h>
40+
#include <pgmspace.h>
3041
#endif
3142
#include "Adafruit_MCP23008.h"
3243

33-
3444
////////////////////////////////////////////////////////////////////////////////
3545
// RTC_DS1307 implementation
3646

@@ -46,7 +56,8 @@ void Adafruit_MCP23008::begin(uint8_t addr) {
4656
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
4757
#if ARDUINO >= 100
4858
Wire.write((byte)MCP23008_IODIR);
49-
Wire.write((byte)0xFF); // all inputs
59+
Wire.write((byte)0xFF); // all inputs
60+
Wire.write((byte)0x00);
5061
Wire.write((byte)0x00);
5162
Wire.write((byte)0x00);
5263
Wire.write((byte)0x00);
@@ -55,10 +66,10 @@ void Adafruit_MCP23008::begin(uint8_t addr) {
5566
Wire.write((byte)0x00);
5667
Wire.write((byte)0x00);
5768
Wire.write((byte)0x00);
58-
Wire.write((byte)0x00);
5969
#else
6070
Wire.send(MCP23008_IODIR);
61-
Wire.send(0xFF); // all inputs
71+
Wire.send(0xFF); // all inputs
72+
Wire.send(0x00);
6273
Wire.send(0x00);
6374
Wire.send(0x00);
6475
Wire.send(0x00);
@@ -67,29 +78,24 @@ void Adafruit_MCP23008::begin(uint8_t addr) {
6778
Wire.send(0x00);
6879
Wire.send(0x00);
6980
Wire.send(0x00);
70-
Wire.send(0x00);
7181
#endif
7282
Wire.endTransmission();
73-
7483
}
7584

76-
void Adafruit_MCP23008::begin(void) {
77-
begin(0);
78-
}
85+
void Adafruit_MCP23008::begin(void) { begin(0); }
7986

8087
void Adafruit_MCP23008::pinMode(uint8_t p, uint8_t d) {
8188
uint8_t iodir;
82-
8389

8490
// only 8 bits!
8591
if (p > 7)
8692
return;
87-
93+
8894
iodir = read8(MCP23008_IODIR);
8995

9096
// set the pin and direction
9197
if (d == INPUT) {
92-
iodir |= 1 << p;
98+
iodir |= 1 << p;
9399
} else {
94100
iodir &= ~(1 << p);
95101
}
@@ -99,18 +105,15 @@ void Adafruit_MCP23008::pinMode(uint8_t p, uint8_t d) {
99105
}
100106

101107
uint8_t Adafruit_MCP23008::readGPIO(void) {
102-
// read the current GPIO input
108+
// read the current GPIO input
103109
return read8(MCP23008_GPIO);
104110
}
105111

106-
void Adafruit_MCP23008::writeGPIO(uint8_t gpio) {
107-
write8(MCP23008_GPIO, gpio);
108-
}
109-
112+
void Adafruit_MCP23008::writeGPIO(uint8_t gpio) { write8(MCP23008_GPIO, gpio); }
110113

111114
void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) {
112115
uint8_t gpio;
113-
116+
114117
// only 8 bits!
115118
if (p > 7)
116119
return;
@@ -120,7 +123,7 @@ void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) {
120123

121124
// set the pin and direction
122125
if (d == HIGH) {
123-
gpio |= 1 << p;
126+
gpio |= 1 << p;
124127
} else {
125128
gpio &= ~(1 << p);
126129
}
@@ -131,15 +134,15 @@ void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) {
131134

132135
void Adafruit_MCP23008::pullUp(uint8_t p, uint8_t d) {
133136
uint8_t gppu;
134-
137+
135138
// only 8 bits!
136139
if (p > 7)
137140
return;
138141

139142
gppu = read8(MCP23008_GPPU);
140143
// set the pin and direction
141144
if (d == HIGH) {
142-
gppu |= 1 << p;
145+
gppu |= 1 << p;
143146
} else {
144147
gppu &= ~(1 << p);
145148
}
@@ -159,9 +162,9 @@ uint8_t Adafruit_MCP23008::digitalRead(uint8_t p) {
159162
uint8_t Adafruit_MCP23008::read8(uint8_t addr) {
160163
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
161164
#if ARDUINO >= 100
162-
Wire.write((byte)addr);
165+
Wire.write((byte)addr);
163166
#else
164-
Wire.send(addr);
167+
Wire.send(addr);
165168
#endif
166169
Wire.endTransmission();
167170
Wire.requestFrom(MCP23008_ADDRESS | i2caddr, 1);
@@ -173,14 +176,13 @@ uint8_t Adafruit_MCP23008::read8(uint8_t addr) {
173176
#endif
174177
}
175178

176-
177179
void Adafruit_MCP23008::write8(uint8_t addr, uint8_t data) {
178180
Wire.beginTransmission(MCP23008_ADDRESS | i2caddr);
179181
#if ARDUINO >= 100
180182
Wire.write((byte)addr);
181183
Wire.write((byte)data);
182184
#else
183-
Wire.send(addr);
185+
Wire.send(addr);
184186
Wire.send(data);
185187
#endif
186188
Wire.endTransmission();

Adafruit_MCP23008.h

+58-27
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,87 @@
1-
/***************************************************
2-
This is a library for the MCP23008 i2c port expander
3-
4-
These displays use I2C to communicate, 2 pins are required to
5-
interface
6-
Adafruit invests time and resources providing this open source code,
7-
please support Adafruit and open-source hardware by purchasing
8-
products from Adafruit!
9-
10-
Written by Limor Fried/Ladyada for Adafruit Industries.
11-
BSD license, all text above must be included in any redistribution
12-
****************************************************/
1+
/*!
2+
* @file Adafruit_MCP23008.h
3+
*/
134

145
#ifndef _ADAFRUIT_MCP23008_H
156
#define _ADAFRUIT_MCP23008_H
167
// Don't forget the Wire library
178
#ifdef __AVR_ATtiny85__
18-
#include <TinyWireM.h>
9+
#include <TinyWireM.h>
1910
#else
20-
#include <Wire.h>
11+
#include <Wire.h>
2112
#endif
2213

14+
/*!
15+
* @brief Class that stores state and functions for interacting with MCP23008
16+
* chip
17+
*/
2318
class Adafruit_MCP23008 {
2419
public:
20+
/*!
21+
* @brief Begins the i2c connection using specified address
22+
* @param addr i2c address of the MCP23008
23+
*/
2524
void begin(uint8_t addr);
25+
/*!
26+
* @brief Begins the i2c connection using default address
27+
*/
2628
void begin(void);
2729

30+
/*!
31+
* @brief Sets the pin mode
32+
* @param p Mode to set
33+
* @param d Pin to set the mode to
34+
*/
2835
void pinMode(uint8_t p, uint8_t d);
36+
/*!
37+
* @brief Sets the pin and direction
38+
* @param p Pin to set
39+
* @param d Direction to set the pin
40+
*/
2941
void digitalWrite(uint8_t p, uint8_t d);
42+
/*!
43+
* @brief Sets pull-up resistor on specified pin
44+
* @param p Pin to set
45+
* @param d Direction to set the pin
46+
*/
3047
void pullUp(uint8_t p, uint8_t d);
48+
/*!
49+
* @brief Reads the status of a gpio pin
50+
* @param p Pin to read
51+
* @return Returns the current gpio
52+
*/
3153
uint8_t digitalRead(uint8_t p);
54+
/*!
55+
* @brief Reads the current GPIO input
56+
* @return Returns the current GPIO input
57+
*/
3258
uint8_t readGPIO(void);
59+
/*!
60+
* @brief Writes to the GPIO
61+
* @param gpio what to write
62+
*/
3363
void writeGPIO(uint8_t);
3464

35-
private:
65+
private:
3666
uint8_t i2caddr;
3767
uint8_t read8(uint8_t addr);
3868
void write8(uint8_t addr, uint8_t data);
3969
};
4070

41-
#define MCP23008_ADDRESS 0x20
71+
#define MCP23008_ADDRESS 0x20 //!< MCP23008 serial address
4272

4373
// registers
44-
#define MCP23008_IODIR 0x00
45-
#define MCP23008_IPOL 0x01
46-
#define MCP23008_GPINTEN 0x02
47-
#define MCP23008_DEFVAL 0x03
48-
#define MCP23008_INTCON 0x04
49-
#define MCP23008_IOCON 0x05
50-
#define MCP23008_GPPU 0x06
51-
#define MCP23008_INTF 0x07
52-
#define MCP23008_INTCAP 0x08
53-
#define MCP23008_GPIO 0x09
54-
#define MCP23008_OLAT 0x0A
74+
#define MCP23008_IODIR 0x00 //!< I/O direction register
75+
#define MCP23008_IPOL 0x01 //!< Input polarity register
76+
#define MCP23008_GPINTEN 0x02 //!< Interrupt-on-change control register
77+
#define MCP23008_DEFVAL \
78+
0x03 //!< Default compare register for interrupt-on-change
79+
#define MCP23008_INTCON 0x04 //!< Interrupt control register
80+
#define MCP23008_IOCON 0x05 //!< Configuration register
81+
#define MCP23008_GPPU 0x06 //!< Pull-up resistor configuration register
82+
#define MCP23008_INTF 0x07 //!< Interrupt flag register
83+
#define MCP23008_INTCAP 0x08 //!< Interrupt capture register
84+
#define MCP23008_GPIO 0x09 //!< Port register
85+
#define MCP23008_OLAT 0x0A //!< Output latch register
5586

5687
#endif

README README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Adafruit MCP23008 Library [![Build Status](https://github.com/adafruit/Adafruit-MCP23008-library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-MCP23008-library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-MCP23008-library/html/index.html)
2+
13
To download, click "Download Source" in the top right corner. Then install as indicated in our tutorial:
24
--> http://www.ladyada.net/library/arduino/libraries.html
35
in a folder called Adafruit_MCP23008.
@@ -16,4 +18,4 @@ Pins 10 thru 17 are your input/output pins
1618

1719
Check the datasheet for more info: http://ww1.microchip.com/downloads/en/DeviceDoc/21919b.pdf
1820

19-
Enjoy and send pull requests!
21+
Enjoy and send pull requests!

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit MCP23008 library
2-
version=1.0.2
2+
version=1.1.0
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino Library for the MCP23008 (and '9) I2C I/O expander

0 commit comments

Comments
 (0)