/* * Linear Technology LTC1446 D/A Converter * Device driver * * Copyright (C) 2007 Michael Buesch * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include "ltc1446.h" #include "util.h" #include /* The hardware connection definitions */ #define LTC1446_PORT PORTD #define LTC1446_DDR DDRD #define LTC1446_CLK (1 << 4) /* Clock pin */ #define LTC1446_DIN (1 << 5) /* Data input pin */ #define LTC1446_CS (1 << 6) /* Chip select pin */ /* Put a data word into the device. */ static void ltc1446_put(uint16_t data) { uint16_t mask; uint8_t bits = 12; /* 12 bit resolution */ /* The bits are shifted MSB to LSB into the device. */ mask = (1 << (bits - 1)); do { if (data & mask) LTC1446_PORT |= LTC1446_DIN; else LTC1446_PORT &= ~LTC1446_DIN; LTC1446_PORT |= LTC1446_CLK; _delay_us(1); LTC1446_PORT &= ~LTC1446_CLK; _delay_us(1); mask >>= 1; } while (--bits); } void ltc1446_init(void) { LTC1446_DDR |= (LTC1446_CLK | LTC1446_DIN | LTC1446_CS); LTC1446_PORT &= ~(LTC1446_CLK | LTC1446_DIN); LTC1446_PORT |= LTC1446_CS; _delay_ms(10); ltc1446_write(0, 0); } void ltc1446_write(uint16_t chan_a, uint16_t chan_b) { LTC1446_PORT &= ~LTC1446_CS; _delay_us(50); ltc1446_put(chan_a); ltc1446_put(chan_b); LTC1446_PORT |= LTC1446_CS; _delay_us(50); }