mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
tmp105: Create API for TMP105 temperature sensor.
* Define enum for TMP105 registers * Move tmp105_set() from I2C to TMP105 header * Document units and range of temperature as preconditions Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Alex Horn <alex.horn@cs.ox.ac.uk> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
eac236ea7b
commit
2915efbfa8
3 changed files with 76 additions and 11 deletions
17
hw/tmp105.c
17
hw/tmp105.c
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "hw.h"
|
||||
#include "i2c.h"
|
||||
#include "tmp105.h"
|
||||
|
||||
typedef struct {
|
||||
I2CSlave i2c;
|
||||
|
@ -92,22 +93,22 @@ static void tmp105_read(TMP105State *s)
|
|||
}
|
||||
|
||||
switch (s->pointer & 3) {
|
||||
case 0: /* Temperature */
|
||||
case TMP105_REG_TEMPERATURE:
|
||||
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
|
||||
s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
|
||||
(0xf0 << ((~s->config >> 5) & 3)); /* R */
|
||||
break;
|
||||
|
||||
case 1: /* Configuration */
|
||||
case TMP105_REG_CONFIG:
|
||||
s->buf[s->len ++] = s->config;
|
||||
break;
|
||||
|
||||
case 2: /* T_LOW */
|
||||
case TMP105_REG_T_LOW:
|
||||
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 8;
|
||||
s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 0;
|
||||
break;
|
||||
|
||||
case 3: /* T_HIGH */
|
||||
case TMP105_REG_T_HIGH:
|
||||
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 8;
|
||||
s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 0;
|
||||
break;
|
||||
|
@ -117,10 +118,10 @@ static void tmp105_read(TMP105State *s)
|
|||
static void tmp105_write(TMP105State *s)
|
||||
{
|
||||
switch (s->pointer & 3) {
|
||||
case 0: /* Temperature */
|
||||
case TMP105_REG_TEMPERATURE:
|
||||
break;
|
||||
|
||||
case 1: /* Configuration */
|
||||
case TMP105_REG_CONFIG:
|
||||
if (s->buf[0] & ~s->config & (1 << 0)) /* SD */
|
||||
printf("%s: TMP105 shutdown\n", __FUNCTION__);
|
||||
s->config = s->buf[0];
|
||||
|
@ -128,8 +129,8 @@ static void tmp105_write(TMP105State *s)
|
|||
tmp105_alarm_update(s);
|
||||
break;
|
||||
|
||||
case 2: /* T_LOW */
|
||||
case 3: /* T_HIGH */
|
||||
case TMP105_REG_T_LOW:
|
||||
case TMP105_REG_T_HIGH:
|
||||
if (s->len >= 3)
|
||||
s->limit[s->pointer & 1] = (int16_t)
|
||||
((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue