/** * \file * * * * \brief MCP41xxx digital potentiomenter driver (implementation) * * \author Francesco Sacchi */ #include "hw/hw_mcp41.h" #include #include #include #include #include static KFile *ch; /** * Set resitance for digital pot \a dev */ void mcp41_setResistance(Mcp41Dev dev, mcp41_res_t res) { MCP41_ON(dev); /* send command byte */ kfile_putc(MCP41_WRITE_DATA, ch); kfile_putc(((MCP41_HW_MAX * (uint32_t)res) + (MCP41_MAX / 2)) / MCP41_MAX, ch); kfile_flush(ch); MCP41_OFF(dev); } /** * Initialize mcp41 potentiometer driver */ void mcp41_init(KFile *_ch) { Mcp41Dev dev; /* Init all potentiometer ports */ for (dev = 0; dev < MCP41_CNT; dev++) { SET_MCP41_DDR(dev); MCP41_OFF(dev); } ch = _ch; }