Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berry add I2C read16/write16 supporting Little Endian #22448

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Support KNX for scripts (#22429)
- Support deep sleep (standby) for VL53L0X (#22441)
- Support for MS5837 pressure and temperature sensor (#22376)
- Berry add I2C read16/write16 supporting Little Endian

### Breaking Changed

Expand Down
14 changes: 14 additions & 0 deletions lib/libesp32/berry_tasmota/src/embedded/i2c_driver.be
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class I2C_Driver
def write8(reg, val)
return self.wire.write(self.addr, reg, val, 1)
end
#- write register with 16 bits value -#
def write16(reg, val)
return self.wire.write(self.addr, reg, val, 2)
end
#- write register with 16 bits value, Little Endian -#
def write16LE(reg, val)
val = ((val & 0xFF) << 8) | ((val & 0xFF00) >> 8)
return self.write16(reg, val)
end

# Set or clear a specific bit in a register
# write_bit(reg:int, bit:int, state:bool) -> nil
Expand Down Expand Up @@ -94,6 +103,11 @@ class I2C_Driver
var buf = self.wire.read_bytes(self.addr, reg, 2)
return (buf[0] << 8) + buf[1]
end
# read 16 bits Little Endian
def read16LE(reg)
var buf = self.wire.read_bytes(self.addr, reg, 2)
return (buf[1] << 8) + buf[0]
end
# read 24 bits
def read24(reg)
var buf = self.wire.read_bytes(self.addr, reg, 3)
Expand Down
Loading