Lines Matching +full:lower +full:- +full:cal
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
30 * GPIOTHS - Temp/Humidity sensor over GPIO.
33 * output over single-wire protocol from embedded 8-bit microcontroller.
34 * Note that it uses a custom single-wire protocol, it is not 1-wire(tm).
37 * DHT11: Temp 0c to 50c +-2.0c, Humidity 20% to 90% +-5%
38 * DHT12: Temp -20c to 60c +-0.5c, Humidity 20% to 95% +-5%
39 * DHT21: Temp -40c to 80c +-0.3c, Humidity 0% to 100% +-3%
40 * DHT22: Temp -40c to 80c +-0.3c, Humidity 0% to 100% +-2%
109 ofw_bus_search_compatible(dev, compat_data)->ocd_data) in gpioths_probe()
125 gpio_pin_is_active(sc->pin, &cur_level); in gpioths_dht_timeuntil()
148 gpio_pin_setflags(sc->pin, GPIO_PIN_OUTPUT); in gpioths_dht_initread()
149 gpio_pin_set_active(sc->pin, false); in gpioths_dht_initread()
151 gpio_pin_set_active(sc->pin, true); in gpioths_dht_initread()
152 gpio_pin_setflags(sc->pin, GPIO_PIN_INPUT); in gpioths_dht_initread()
168 device_printf(sc->dev, "err(START) = %d\n", err); in gpioths_dht_readbytes()
172 /* reading - 41 cycles */ in gpioths_dht_readbytes()
176 device_printf(sc->dev, "err(CAL, %d) = %d\n", i, err); in gpioths_dht_readbytes()
181 device_printf(sc->dev, "err(INTERVAL, %d) = %d\n", i, err); in gpioths_dht_readbytes()
191 avglen = avglen / (GPIOTHS_DHT_CYCLES - 1); in gpioths_dht_readbytes()
220 device_printf(sc->dev, "%d: %d %d\n", i, calibrations[i], in gpioths_dht_readbytes()
223 device_printf(sc->dev, "len=%d, data=%x, crc=%x/%x\n", avglen, value, crc, in gpioths_dht_readbytes()
229 err = -1; in gpioths_dht_readbytes()
237 * - DHT11: 0HHHHHHH 00000000 00TTTTTT 00000000 in gpioths_dht_readbytes()
238 * - DHT12: 0HHHHHHH 0000hhhh 00TTTTTT s000tttt in gpioths_dht_readbytes()
243 * - DHT21: 000000HH HHHHHHHH s00000TT TTTTTTTT in gpioths_dht_readbytes()
244 * - DHT22: 000000HH HHHHHHHH s00000TT TTTTTTTT in gpioths_dht_readbytes()
251 * the upper bits of its 16-bit humidity. A DHT11/12 should not report in gpioths_dht_readbytes()
252 * a value lower than 20. To allow for the possibility that a device in gpioths_dht_readbytes()
262 negmul = (value & 0x80) ? -1 : 1; in gpioths_dht_readbytes()
263 sc->temp = DK_OFFSET + (negmul * (tmphi * 10 + tmplo)); in gpioths_dht_readbytes()
264 sc->hum = (value >> 24) & 0x7f; in gpioths_dht_readbytes()
267 negmul = (value & 0x8000) ? -1 : 1; in gpioths_dht_readbytes()
268 sc->temp = DK_OFFSET + (negmul * (value & 0x03ff)); in gpioths_dht_readbytes()
269 sc->hum = ((value >> 16) & 0x03ff) / 10; in gpioths_dht_readbytes()
272 sc->fails = 0; in gpioths_dht_readbytes()
276 device_printf(dev, "fails=%d, temp=%d, hum=%d\n", sc->fails, in gpioths_dht_readbytes()
277 sc->temp, sc->hum); in gpioths_dht_readbytes()
282 sc->fails++; in gpioths_dht_readbytes()
294 if (!sc->detaching) in gpioths_poll()
295 taskqueue_enqueue_timeout_sbt(taskqueue_thread, &sc->task, in gpioths_poll()
311 sc->dev = dev; in gpioths_attach()
313 TIMEOUT_TASK_INIT(taskqueue_thread, &sc->task, 0, gpioths_poll, sc); in gpioths_attach()
316 /* Try to configure our pin from fdt data on fdt-based systems. */ in gpioths_attach()
318 &sc->pin); in gpioths_attach()
325 * on fdt-based systems). in gpioths_attach()
329 err = gpio_pin_get_by_child_index(dev, PIN_IDX, &sc->pin); in gpioths_attach()
333 device_printf(sc->dev, in gpioths_attach()
343 err = gpio_pin_setflags(sc->pin, GPIO_PIN_OUTPUT); in gpioths_attach()
348 err = gpio_pin_set_active(sc->pin, true); in gpioths_attach()
353 err = gpio_pin_setflags(sc->pin, GPIO_PIN_INPUT); in gpioths_attach()
369 &sc->temp, 0, sysctl_handle_int, "IK", "temperature", NULL); in gpioths_attach()
372 CTLFLAG_RD, &sc->hum, 0, "relative humidity(%)"); in gpioths_attach()
375 CTLFLAG_RD, &sc->fails, 0, in gpioths_attach()
387 gpio_pin_release(sc->pin); in gpioths_detach()
388 sc->detaching = true; in gpioths_detach()
389 while (taskqueue_cancel_timeout(taskqueue_thread, &sc->task, NULL) != 0) in gpioths_detach()
390 taskqueue_drain_timeout(taskqueue_thread, &sc->task); in gpioths_detach()