parent
d83f40652d
commit
774cf149c4
|
@ -1,5 +1,5 @@
|
||||||
/* uLisp ARM 2.7 - www.ulisp.com
|
/* uLisp ARM 2.7b - www.ulisp.com
|
||||||
David Johnson-Davies - www.technoblogy.com - 20th May 2019
|
David Johnson-Davies - www.technoblogy.com - 9th June 2019
|
||||||
|
|
||||||
Licensed under the MIT license: https://opensource.org/licenses/MIT
|
Licensed under the MIT license: https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
@ -1086,33 +1086,38 @@ inline object *cdrx (object *arg) {
|
||||||
|
|
||||||
// I2C interface
|
// I2C interface
|
||||||
|
|
||||||
void I2Cinit(bool enablePullup) {
|
void I2Cinit (bool enablePullup) {
|
||||||
(void) enablePullup;
|
(void) enablePullup;
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint8_t I2Cread() {
|
inline uint8_t I2Cread () {
|
||||||
return Wire.read();
|
return Wire.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool I2Cwrite(uint8_t data) {
|
inline bool I2Cwrite (uint8_t data) {
|
||||||
return Wire.write(data);
|
return Wire.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2Cstart(uint8_t address, uint8_t read) {
|
bool I2Cstart (uint8_t address, uint8_t read) {
|
||||||
if (read == 0) Wire.beginTransmission(address);
|
int ok = true;
|
||||||
else Wire.requestFrom(address, I2CCount);
|
if (read == 0) {
|
||||||
return true;
|
Wire.beginTransmission(address);
|
||||||
|
ok = (Wire.endTransmission(true) == 0);
|
||||||
|
Wire.beginTransmission(address);
|
||||||
|
}
|
||||||
|
else Wire.requestFrom(address, I2CCount);
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2Crestart(uint8_t address, uint8_t read) {
|
bool I2Crestart (uint8_t address, uint8_t read) {
|
||||||
int error = (Wire.endTransmission(false) != 0);
|
int error = (Wire.endTransmission(false) != 0);
|
||||||
if (read == 0) Wire.beginTransmission(address);
|
if (read == 0) Wire.beginTransmission(address);
|
||||||
else Wire.requestFrom(address, I2CCount);
|
else Wire.requestFrom(address, I2CCount);
|
||||||
return error ? false : true;
|
return error ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2Cstop(uint8_t read) {
|
void I2Cstop (uint8_t read) {
|
||||||
if (read == 0) Wire.endTransmission(); // Check for error?
|
if (read == 0) Wire.endTransmission(); // Check for error?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2981,7 +2986,7 @@ object *fn_writeline (object *args, object *env) {
|
||||||
|
|
||||||
object *fn_restarti2c (object *args, object *env) {
|
object *fn_restarti2c (object *args, object *env) {
|
||||||
(void) env;
|
(void) env;
|
||||||
int stream = first(args)->integer;
|
int stream = istream(first(args));
|
||||||
args = cdr(args);
|
args = cdr(args);
|
||||||
int read = 0; // Write
|
int read = 0; // Write
|
||||||
I2CCount = 0;
|
I2CCount = 0;
|
||||||
|
@ -2991,7 +2996,7 @@ object *fn_restarti2c (object *args, object *env) {
|
||||||
read = (rw != NULL);
|
read = (rw != NULL);
|
||||||
}
|
}
|
||||||
int address = stream & 0xFF;
|
int address = stream & 0xFF;
|
||||||
if (stream>>8 != I2CSTREAM) error3(RESTARTI2C, PSTR("not i2c"));
|
if (stream>>8 != I2CSTREAM) error3(RESTARTI2C, PSTR("not an i2c stream"));
|
||||||
return I2Crestart(address, read) ? tee : nil;
|
return I2Crestart(address, read) ? tee : nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue