--- /dev/null
+/**
+ * \file
+ * <!--
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * -->
+ *
+ * \version $Id$
+ *
+ * \brief MCP41xxx digital potentiomenter driver (implementation)
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#include <drv/timer.h>
+
+#include <cfg/macros.h>
+#include <cfg/cpu.h>
+#include <cfg/compiler.h>
+
+#include <hw_mcp41.h>
+#include <drv/mcp41.h>
+#include <drv/ser.h>
+
+static Serial *spi_ser;
+
+/**
+ * Set resitance for digital pot \a dev
+ */
+void mcp41_setResistance(Mcp41Dev dev, mcp41_res_t res)
+{
+ MCP41_ON(dev);
+ /* send command byte */
+ ser_putchar(MCP41_WRITE_DATA, spi_ser);
+ ser_putchar(((MCP41_HW_MAX * (uint32_t)res) + (MCP41_MAX / 2)) / MCP41_MAX, spi_ser);
+ ser_drain(spi_ser);
+
+ MCP41_OFF(dev);
+}
+
+
+/**
+ * Initialize mcp41 potentiometer driver
+ */
+void mcp41_init(Serial *spi_port)
+{
+ Mcp41Dev dev;
+
+ /* Init all potentiometer ports */
+ for (dev = 0; dev < MCP41_CNT; dev++)
+ {
+ SET_MCP41_DDR(dev);
+ MCP41_OFF(dev);
+ }
+
+ spi_ser = spi_port;
+}
--- /dev/null
+/**
+ * \file
+ * <!--
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * -->
+ *
+ * \version $Id$
+ *
+ * \brief MCP41xxx digital potentiomenter driver (interface)
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#ifndef DRV_MCP41_H
+#define DRV_MCP41_H
+
+#include <hw/mcp41_map.h>
+#include <cfg/compiler.h>
+#include <drv/ser.h>
+
+#define MCP41_WRITE_DATA 0x11
+#define MCP41_HW_MAX 255
+#define MCP41_MAX 999
+
+/**
+ * Type for digital potentiometer resistance.
+ */
+typedef uint16_t mcp41_res_t;
+
+void mcp41_setResistance(Mcp41Dev dev, mcp41_res_t res);
+void mcp41_init(Serial *spi_port);
+
+#endif /* DRV_MCP41_H */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * -->
+ *
+ * \version $Id$
+ *
+ * \brief MCP41 hardware-specific definitions
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#include <hw_mcp41.h>
+
+#include <cfg/macros.h>
+#include <cfg/compiler.h>
+
+#include <avr/io.h>
+
+
+const uint16_t mcp41_ports[MCP41_CNT] = {
+ _SFR_IO_ADDR(PORTB), /** Led pot */
+ _SFR_IO_ADDR(PORTB), /** Photometer pot */
+ };
+const uint8_t mcp41_pins [MCP41_CNT] = {
+ BV(PB7),
+ BV(PB6),
+ };
--- /dev/null
+/**
+ * \file
+ * <!--
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * -->
+ *
+ * \version $Id$
+ *
+ * \brief MCP41 hardware-specific definitions
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#ifndef HW_MCP41_H
+#define HW_MCP41_H
+
+#include <mcp41_map.h>
+#include <cfg/compiler.h>
+#include <cfg/cpu.h>
+#include <avr/io.h>
+
+extern const uint16_t mcp41_ports[MCP41_CNT];
+extern const uint8_t mcp41_pins[MCP41_CNT];
+
+/**
+ * Set MCP41 port associated with \a dev to output.
+ */
+INLINE void SET_MCP41_DDR(Mcp41Dev dev)
+{
+ /* DDR port is 1 address before PORT */
+ ATOMIC(_SFR_IO8(mcp41_ports[dev] - 1) |= mcp41_pins[dev]);
+}
+
+INLINE void MCP41_ON(Mcp41Dev i)
+{
+ ATOMIC(_SFR_IO8(mcp41_ports[i]) &= ~mcp41_pins[i]);
+}
+
+INLINE void MCP41_OFF(Mcp41Dev i)
+{
+ ATOMIC(_SFR_IO8(mcp41_ports[i]) |= mcp41_pins[i]);
+}
+
+
+#endif /* HW_MCP41_H */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief MCP41 digital potentiometer map definitions.
+ *
+ * \version $Id$
+ *
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#ifndef MCP41_MAP_H
+#define MCP41_MAP_H
+
+/** \name Enum for mcp41 pot evices.
+ * \{
+ */
+typedef enum Mcp41Dev
+{
+ MCP41_LED,
+ MCP41_PHOTO_GAIN,
+
+ MCP41_CNT,
+} Mcp41Dev;
+/* \} */
+
+#endif /* MCP41_MAP_H */