add an API function to directly write to an SI570 register

This commit is contained in:
Christian Daniel 2012-05-26 22:14:33 +02:00
parent 180193cecf
commit 6023743202
2 changed files with 16 additions and 0 deletions

View File

@ -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__

View File

@ -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);
}