Skip to content

Commit 2a84600

Browse files
authored
Version 2.7b - 9th June 2019
Fixes technoblogy#16
1 parent 57d7dcb commit 2a84600

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ulisp-esp.ino

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* uLisp ESP Version 2.7 - www.ulisp.com
2-
David Johnson-Davies - www.technoblogy.com - 20th May 2019
1+
/* uLisp ESP Version 2.7b - www.ulisp.com
2+
David Johnson-Davies - www.technoblogy.com - 9th June 2019
33
44
Licensed under the MIT license: https://opensource.org/licenses/MIT
55
*/
@@ -991,33 +991,38 @@ inline object *cdrx (object *arg) {
991991

992992
// I2C interface
993993

994-
void I2Cinit(bool enablePullup) {
994+
void I2Cinit (bool enablePullup) {
995995
(void) enablePullup;
996996
Wire.begin();
997997
}
998998

999-
inline uint8_t I2Cread() {
999+
inline uint8_t I2Cread () {
10001000
return Wire.read();
10011001
}
10021002

1003-
inline bool I2Cwrite(uint8_t data) {
1003+
inline bool I2Cwrite (uint8_t data) {
10041004
return Wire.write(data);
10051005
}
10061006

1007-
bool I2Cstart(uint8_t address, uint8_t read) {
1008-
if (read == 0) Wire.beginTransmission(address);
1009-
else Wire.requestFrom(address, I2CCount);
1010-
return true;
1007+
bool I2Cstart (uint8_t address, uint8_t read) {
1008+
int ok = true;
1009+
if (read == 0) {
1010+
Wire.beginTransmission(address);
1011+
ok = (Wire.endTransmission(true) == 0);
1012+
Wire.beginTransmission(address);
1013+
}
1014+
else Wire.requestFrom(address, I2CCount);
1015+
return ok;
10111016
}
10121017

1013-
bool I2Crestart(uint8_t address, uint8_t read) {
1018+
bool I2Crestart (uint8_t address, uint8_t read) {
10141019
int error = (Wire.endTransmission(false) != 0);
10151020
if (read == 0) Wire.beginTransmission(address);
10161021
else Wire.requestFrom(address, I2CCount);
10171022
return error ? false : true;
10181023
}
10191024

1020-
void I2Cstop(uint8_t read) {
1025+
void I2Cstop (uint8_t read) {
10211026
if (read == 0) Wire.endTransmission(); // Check for error?
10221027
}
10231028

@@ -2832,7 +2837,7 @@ object *fn_writeline (object *args, object *env) {
28322837

28332838
object *fn_restarti2c (object *args, object *env) {
28342839
(void) env;
2835-
int stream = first(args)->integer;
2840+
int stream = istream(first(args));
28362841
args = cdr(args);
28372842
int read = 0; // Write
28382843
I2CCount = 0;
@@ -2842,7 +2847,7 @@ object *fn_restarti2c (object *args, object *env) {
28422847
read = (rw != NULL);
28432848
}
28442849
int address = stream & 0xFF;
2845-
if (stream>>8 != I2CSTREAM) error3(RESTARTI2C, PSTR("not i2c"));
2850+
if (stream>>8 != I2CSTREAM) error3(RESTARTI2C, PSTR("not an i2c stream"));
28462851
return I2Crestart(address, read) ? tee : nil;
28472852
}
28482853

0 commit comments

Comments
 (0)