32 return (int32_t)(-45000 + (int64_t)175000 * raw / 65535);
37 int32_t v = (int32_t)((int64_t)100000 * raw / 65535);
38 return v > 100000 ? 100000 : v;
41bool pc_sht3x_parse(
const uint8_t resp[6], int32_t *temp_mc, int32_t *rh_mpct)
47 uint16_t traw = (uint16_t)(((uint16_t)resp[0] << 8) | resp[1]);
48 uint16_t hraw = (uint16_t)(((uint16_t)resp[3] << 8) | resp[4]);
76bool send_cmd(uint16_t cmd)
78 Wire.beginTransmission(s_sht.addr);
79 Wire.write((uint8_t)(cmd >> 8));
80 Wire.write((uint8_t)(cmd & 0xFF));
81 return Wire.endTransmission() == 0;
101 if (Wire.requestFrom((
int)s_sht.addr, 6) != 6)
106 for (
int i = 0; i < 6; i++)
108 r[i] = (uint8_t)Wire.read();
Pluggable monotonic clock for all library timing.
void pcdelay(uint32_t ms)
Block for at least ms milliseconds - the library's single delay primitive.
Parameterized CRC engine - one source of truth for every cyclic redundancy check.
constexpr pc_crc_params PC_CRC8_NRSC5
CRC-8/NRSC-5 - the Sensirion sensor CRC. check = 0xF7. Used by services/sht3x.
uint32_t pc_crc(const pc_crc_params *p, const uint8_t *data, size_t len)
One-shot CRC of len octets at data.
The one owner of the shared I2C bus bring-up for the peripheral drivers.
void pc_i2c_begin()
Bring up the shared I2C bus on PC_I2C_SDA_PIN / PC_I2C_SCL_PIN (-1 = default).
User-facing configuration for ProtoCore.
#define PC_SHT3X_I2C_ADDR
I2C address of the SHT3x (0x44 with ADDR low; 0x45 with ADDR high).
Sensirion SHT3x temperature / humidity sensor codec (PC_ENABLE_SHT3X).
uint8_t pc_sht3x_crc8(const uint8_t *data, size_t len)
Sensirion CRC-8 (poly 0x31, init 0xFF) over len bytes.
bool pc_sht3x_parse(const uint8_t resp[6], int32_t *temp_mc, int32_t *rh_mpct)
Decode a six-byte single-shot response (T msb/lsb/crc, RH msb/lsb/crc). Verifies both CRC-8 words,...
int32_t pc_sht3x_temp_mc(uint16_t raw)
Convert a raw 16-bit temperature tick to milli-degrees Celsius.
bool pc_sht3x_begin(uint8_t addr)
Soft-reset the SHT3x at addr over I2C.
#define SHT3X_CMD_SOFT_RESET
soft reset
int32_t pc_sht3x_rh_mpct(uint16_t raw)
Convert a raw 16-bit humidity tick to milli-percent relative humidity (0..100000).
bool pc_sht3x_read(int32_t *temp_mc, int32_t *rh_mpct)
Trigger a single-shot high-repeatability measurement, read + verify the six bytes,...
#define SHT3X_CMD_SINGLE_HIGH
high repeatability, no clock stretching