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
3
3
4
4
Licensed under the MIT license: https://opensource.org/licenses/MIT
5
5
*/
@@ -991,33 +991,38 @@ inline object *cdrx (object *arg) {
991
991
992
992
// I2C interface
993
993
994
- void I2Cinit (bool enablePullup) {
994
+ void I2Cinit (bool enablePullup) {
995
995
(void ) enablePullup;
996
996
Wire.begin ();
997
997
}
998
998
999
- inline uint8_t I2Cread () {
999
+ inline uint8_t I2Cread () {
1000
1000
return Wire.read ();
1001
1001
}
1002
1002
1003
- inline bool I2Cwrite (uint8_t data) {
1003
+ inline bool I2Cwrite (uint8_t data) {
1004
1004
return Wire.write (data);
1005
1005
}
1006
1006
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;
1011
1016
}
1012
1017
1013
- bool I2Crestart (uint8_t address, uint8_t read) {
1018
+ bool I2Crestart (uint8_t address, uint8_t read) {
1014
1019
int error = (Wire.endTransmission (false ) != 0 );
1015
1020
if (read == 0 ) Wire.beginTransmission (address);
1016
1021
else Wire.requestFrom (address, I2CCount);
1017
1022
return error ? false : true ;
1018
1023
}
1019
1024
1020
- void I2Cstop (uint8_t read) {
1025
+ void I2Cstop (uint8_t read) {
1021
1026
if (read == 0 ) Wire.endTransmission (); // Check for error?
1022
1027
}
1023
1028
@@ -2832,7 +2837,7 @@ object *fn_writeline (object *args, object *env) {
2832
2837
2833
2838
object *fn_restarti2c (object *args, object *env) {
2834
2839
(void ) env;
2835
- int stream = first (args)-> integer ;
2840
+ int stream = istream ( first (args)) ;
2836
2841
args = cdr (args);
2837
2842
int read = 0 ; // Write
2838
2843
I2CCount = 0 ;
@@ -2842,7 +2847,7 @@ object *fn_restarti2c (object *args, object *env) {
2842
2847
read = (rw != NULL );
2843
2848
}
2844
2849
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 " ));
2846
2851
return I2Crestart (address, read ) ? tee : nil;
2847
2852
}
2848
2853
0 commit comments