summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Daniel <cd@maintech.de>2012-05-26 22:14:33 +0200
committerChristian Daniel <cd@maintech.de>2012-05-26 22:14:33 +0200
commit60237432023bff8c9c13697a3deaa4e1d070413d (patch)
tree76cd2adfbfb5c1ee7becd07c47dd98029fb5262c
parent180193cecfbcafd24179a299aea40425407f7c88 (diff)
add an API function to directly write to an SI570 register
-rwxr-xr-xfirmware/include/si570.h3
-rw-r--r--firmware/src/si570.c13
2 files changed, 16 insertions, 0 deletions
diff --git a/firmware/include/si570.h b/firmware/include/si570.h
index 9bcc368..7cd816d 100755
--- a/firmware/include/si570.h
+++ b/firmware/include/si570.h
@@ -48,6 +48,7 @@ struct si570_ctx {
//API
int si570_init(struct si570_ctx *ctx, void *i2c_dev, uint8_t i2c_addr);
+int si570_reinit(struct si570_ctx *ctx);
int si570_read_calibration(struct si570_ctx *ctx);
int si570_reset(struct si570_ctx *ctx);
//mode of operation
@@ -56,5 +57,7 @@ int si570_get_lock(struct si570_ctx *ctx);
int si570_set_freq(struct si570_ctx *ctx, uint32_t freq, int trim);
//dump all registers
void si570_regdump(struct si570_ctx *ctx);
+//write register(s)
+int si570_reg_write(struct si570_ctx *ctx, uint8_t reg, int len, const uint8_t* data);
#endif //__SI570_H__
diff --git a/firmware/src/si570.c b/firmware/src/si570.c
index 1840afd..1ada99c 100644
--- a/firmware/src/si570.c
+++ b/firmware/src/si570.c
@@ -92,7 +92,13 @@ int si570_init(struct si570_ctx *ctx, void *i2c_dev, uint8_t i2c_addr)
{
ctx->i2c = i2c_dev;
ctx->slave_addr = i2c_addr;
+ ctx->init = 0;
+ return si570_reinit(ctx);
+}
+
+int si570_reinit(struct si570_ctx *ctx)
+{
TRACE_DEBUG("si570_init()\r\n");
if (0 != si570_reset(ctx)) {
@@ -112,6 +118,7 @@ int si570_init(struct si570_ctx *ctx, void *i2c_dev, uint8_t i2c_addr)
return 0;
}
+
void si570_print_info(struct si570_ctx *ctx)
{
TRACE_DEBUG("SI570 XTAL: %u Hz REF: %u Hz\n", ctx->xtal >> 3, ctx->info->init_freq * 1000);
@@ -295,3 +302,9 @@ void si570_regdump(struct si570_ctx *ctx)
data[0], data[1], data[2], data[3],
data[4], data[5], data[6], data[7]);
}
+
+//write register(s)
+int si570_reg_write(struct si570_ctx *ctx, uint8_t reg, int len, const uint8_t* data)
+{
+ return smbus8_write_bytes(ctx->i2c, ctx->slave_addr, reg, data, len);
+}