Skip to content

Commit ec95c0b

Browse files
committed
SPI interface included
1 parent 75fd199 commit ec95c0b

File tree

5 files changed

+64
-7
lines changed

5 files changed

+64
-7
lines changed

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Compiled source #
3+
###################
4+
*.com
5+
*.class
6+
*.dll
7+
*.exe
8+
*.o
9+
*.so
10+
11+
# Packages #
12+
############
13+
# it's better to unpack these files and commit the raw source
14+
# git has its own built in compression methods
15+
*.7z
16+
*.dmg
17+
*.gz
18+
*.iso
19+
*.jar
20+
*.rar
21+
*.tar
22+
*.zip
23+
24+
# Logs and databases #
25+
######################
26+
*.log
27+
*.sql
28+
*.sqlite
29+
30+
# OS generated files #
31+
######################
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db
39+

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "I2C_device_Arduino"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 1.0.5
51+
PROJECT_NUMBER = 1.1.0
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=I2C_device_Arduino
2-
version=1.0.5
2+
version=1.1.0
33
author=Tedd OKANO
44
maintainer=Tedd OKANO
55
sentence=I2C_device class library

src/I2C_device.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "I2C_device.h"
22

3-
I2C_device::I2C_device( uint8_t i2c_address, bool repeated_start_enable ) : i2c( Wire ), i2c_addr( i2c_address ), rs_dis( !repeated_start_enable )
3+
I2C_device::I2C_device( uint8_t i2c_address, bool repeated_start_enable ) : i2c_addr( i2c_address ), i2c( Wire ), rs_dis( !repeated_start_enable )
44
{
55
}
66

7-
I2C_device::I2C_device( TwoWire& wire, uint8_t i2c_address, bool repeated_start_enable ) : i2c( wire ), i2c_addr( i2c_address ), rs_dis( !repeated_start_enable )
7+
I2C_device::I2C_device( TwoWire& wire, uint8_t i2c_address, bool repeated_start_enable ) : i2c_addr( i2c_address ), i2c( wire ), rs_dis( !repeated_start_enable )
88
{
99
}
1010

@@ -172,3 +172,18 @@ void I2C_device::bit_op16( uint8_t reg, uint16_t mask, uint16_t value )
172172
write_r16( reg, v );
173173
}
174174

175+
#include <SPI.h>
176+
177+
void I2C_device::txrx( const uint8_t *w_data, uint8_t *r_data, uint16_t size )
178+
{
179+
memcpy( r_data, w_data, size );
180+
181+
SPI.beginTransaction( spi_setting );
182+
183+
digitalWrite( SS, LOW );
184+
SPI.transfer( r_data, size );
185+
digitalWrite( SS, HIGH );
186+
187+
SPI.endTransaction();
188+
}
189+

src/I2C_device.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#ifndef ARDUINO_I2C_DEVICE_H
1212
#define ARDUINO_I2C_DEVICE_H
1313

14-
#include <Arduino.h>
15-
#include <stdint.h>
16-
#include <Wire.h>
14+
#include <Arduino.h>
15+
#include <stdint.h>
16+
#include <Wire.h>
17+
#include <SPI.h>
1718

1819
class I2C_device
1920
{
@@ -157,7 +158,9 @@ class I2C_device
157158
static void scan( TwoWire& target_i2c = Wire, uint8_t stop = 128 );
158159

159160
protected:
161+
void txrx( const uint8_t *w_data, uint8_t *r_data, uint16_t size );
160162
uint8_t i2c_addr;
163+
SPISettings spi_setting;
161164

162165
private:
163166
TwoWire& i2c;

0 commit comments

Comments
 (0)