Skip to content

Commit 8d07481

Browse files
author
Amadeusz Jasak
committed
Moved to arduino-0015. Added EEEPROM library (external I2C EEPROM), RTC library (DS1307 clock) and Expander library (PCF8574 port expander).
1 parent 855e476 commit 8d07481

File tree

21 files changed

+478
-20
lines changed

21 files changed

+478
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.o
2-
.DS_Store
2+
.DS_Store
3+
*~

EEEPROM/EEEPROM.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
EEEPROM.h - External (I2C) EEPROM libray.
3+
Copyright (c) 2009 Amadeusz Jasak. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/******************************************************************************
21+
* Includes
22+
******************************************************************************/
23+
24+
#include "WConstants.h"
25+
#include "EEEPROM.h"
26+
#include "Wire.h"
27+
28+
/******************************************************************************
29+
* Definitions
30+
******************************************************************************/
31+
32+
/******************************************************************************
33+
* Constructors
34+
******************************************************************************/
35+
EEEPROM::EEEPROM(int address)
36+
{
37+
this->address = address;
38+
}
39+
40+
/******************************************************************************
41+
* User API
42+
******************************************************************************/
43+
44+
uint8_t EEEPROM::read(unsigned int addr)
45+
{
46+
uint8_t rdata = 0x00;
47+
Wire.beginTransmission(this->address);
48+
Wire.send((int)(addr >> 8)); // MSB
49+
Wire.send((int)(addr & 0xFF)); // LSB
50+
Wire.endTransmission();
51+
Wire.requestFrom(this->address, 1);
52+
if (Wire.available()) rdata = Wire.receive();
53+
return rdata;
54+
}
55+
56+
void EEEPROM::readPage(unsigned int addr, uint8_t *buffer, int length = 16)
57+
{
58+
Wire.beginTransmission(this->address);
59+
Wire.send((int)(addr >> 8)); // MSB
60+
Wire.send((int)(addr & 0xFF)); // LSB
61+
Wire.endTransmission();
62+
Wire.requestFrom(this->address,length);
63+
int c = 0;
64+
for ( c = 0; c < length; c++ )
65+
if (Wire.available()) buffer[c] = Wire.receive();
66+
}
67+
68+
void EEEPROM::write(unsigned int addr, uint8_t value)
69+
{
70+
Wire.beginTransmission(this->address);
71+
Wire.send((int)(addr >> 8)); // MSB
72+
Wire.send((int)(addr & 0xFF)); // LSB
73+
Wire.send((int)value);
74+
Wire.endTransmission();
75+
delay(5);
76+
}
77+
78+
void EEEPROM::writePage(unsigned int addr, uint8_t *data, int length = 16)
79+
{
80+
Wire.beginTransmission(this->address);
81+
Wire.send((int)(addr >> 8)); // MSB
82+
Wire.send((int)(addr & 0xFF)); // LSB
83+
byte c;
84+
for ( c = 0; c < length; c++)
85+
Wire.send(data[c]);
86+
Wire.endTransmission();
87+
}

EEEPROM/EEEPROM.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
EEEPROM.h - External (I2C) EEPROM libray.
3+
Copyright (c) 2009 Amadeusz Jasak. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef EEEPROM_h
21+
#define EEEPROM_h
22+
23+
#include <inttypes.h>
24+
25+
class EEEPROM
26+
{
27+
private:
28+
int address;
29+
30+
public:
31+
EEEPROM(int address);
32+
33+
uint8_t read(unsigned int);
34+
void write(unsigned int, uint8_t);
35+
36+
void readPage(unsigned int addr, uint8_t *buffer, int length);
37+
void writePage(unsigned int addr, uint8_t *data, int length);
38+
};
39+
40+
#endif
41+

EEEPROM/keywords.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#######################################
2+
# Syntax Coloring Map For EEEPROM
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
EEEPROM KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
read KEYWORD2
16+
write KEYWORD2
17+
readPage KEYWORD2
18+
writePage KEYWORD2
19+
20+
#######################################
21+
# Constants (LITERAL1)
22+
#######################################
23+

Ethernet/Client.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
#include "Client.h"
99
#include "Server.h"
1010

11+
uint16_t Client::_srcport = 0;
12+
1113
Client::Client(uint8_t sock) {
1214
_sock = sock;
1315
}
@@ -29,8 +31,9 @@ uint8_t Client::connect() {
2931
if (_sock == 255)
3032
return 0;
3133

32-
// XXX: what port should we connect from?
33-
socket(_sock, Sn_MR_TCP, _port, 0);
34+
_srcport++;
35+
36+
socket(_sock, Sn_MR_TCP, 1024 + _srcport, 0);
3437

3538
if (!::connect(_sock, _ip, _port))
3639
return 0;

Ethernet/Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class Client : public Print {
77
private:
8+
static uint16_t _srcport;
89
uint8_t _sock;
910
uint8_t *_ip;
1011
uint16_t _port;

Ethernet/examples/WebServer/WebServer.pde

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void loop()
5454
}
5555
}
5656
}
57+
// give the web browser time to receive the data
58+
delay(1);
5759
client.stop();
5860
}
5961
}

Ethernet/utility/spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS) // CS=1, waiting for SPI start // SPI mode 0, 4MHz
3939
#define SPI0_Init() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
40-
PORTB = SPI0_SS_BIT;\
40+
PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
4141
SPCR = 0x50
4242
//-----------------------------------------------------------------------------
4343

Expander/Expander.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Expander.h - PCF8574 expander library
3+
Copyright (c) 2009 Amadeusz Jasak. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/******************************************************************************
21+
* Includes
22+
******************************************************************************/
23+
24+
#include "WConstants.h"
25+
#include "Expander.h"
26+
#include "Wire.h"
27+
28+
/******************************************************************************
29+
* Definitions
30+
******************************************************************************/
31+
32+
/******************************************************************************
33+
* Constructors
34+
******************************************************************************/
35+
Expander::Expander(uint8_t address)
36+
{
37+
this->address = address;
38+
39+
this->write(0x00);
40+
}
41+
42+
/******************************************************************************
43+
* User API
44+
******************************************************************************/
45+
46+
void Expander::write(uint8_t value)
47+
{
48+
Wire.beginTransmission(this->address);
49+
Wire.send(value);
50+
Wire.endTransmission();
51+
}
52+
53+
uint8_t Expander::read()
54+
{
55+
uint8_t value = 0x00;
56+
Wire.requestFrom(this->address, (uint8_t)1);
57+
if(Wire.available()) {
58+
value = Wire.receive();
59+
}
60+
return value;
61+
}

Expander/Expander.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Expander.h - PCF8574 expander library
3+
Copyright (c) 2009 Amadeusz Jasak. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef EXPANDER_h
21+
#define EXPANDER_h
22+
23+
#include <inttypes.h>
24+
25+
class Expander
26+
{
27+
private:
28+
uint8_t address;
29+
30+
public:
31+
Expander(uint8_t address);
32+
33+
void write(uint8_t value);
34+
uint8_t read();
35+
};
36+
37+
#endif
38+

0 commit comments

Comments
 (0)