tlv5618.c
Go to the documentation of this file.00001
00038 #include "tlv5618.h"
00039 #include "hw/hw_tlv5618.h"
00040
00041 #include <io/kfile.h>
00042
00043 #include <string.h>
00044
00045
00046 static void tlv5618_write(Tlv5618 *ctx, uint16_t val)
00047 {
00048 TLV5618_CSLOW(ctx->cs_pin);
00049 kfile_putc(val >> 8, ctx->ch);
00050 kfile_putc(val & 0xFF, ctx->ch);
00051 kfile_flush(ctx->ch);
00052 TLV5618_CSHIGH(ctx->cs_pin);
00053 }
00054
00055 #define POWERDOWN 0x2000
00056 #define OUTA 0xC000
00057 #define OUTB 0x4000
00058
00064 void tlv5618_setOutA(Tlv5618 *ctx, uint16_t val)
00065 {
00066 val &= 0x0FFF;
00067 tlv5618_write(ctx, val | OUTA);
00068 }
00069
00075 void tlv5618_setOutB(Tlv5618 *ctx, uint16_t val)
00076 {
00077 val &= 0x0FFF;
00078 tlv5618_write(ctx, val | OUTB);
00079 }
00080
00084 void tlv5618_setPowerDown(Tlv5618 *ctx)
00085 {
00086 tlv5618_write(ctx, POWERDOWN);
00087 }
00088
00089
00097 void tlv5618_init(Tlv5618 *ctx, KFile *ch, int cs_pin)
00098 {
00099 memset(ctx, 0, sizeof(*ctx));
00100 ctx->cs_pin = cs_pin;
00101 ctx->ch = ch;
00102 TLV5618_CSINIT(cs_pin);
00103 tlv5618_setPowerDown(ctx);
00104 }