-##########################################################################
-# User configuration and firmware specific object files
-##########################################################################
-
-# The target, flash and ram of the LPC1xxx microprocessor.
-# Use for the target the value: LPC11xx, LPC13xx or LPC17xx
-TARGET = LPC13xx
-FLASH = 32K
-SRAM = 8K
-
-# For USB HID support the LPC134x reserves 384 bytes from the sram,
-# if you don't want to use the USB features, just use 0 here.
-SRAM_USB = 384
-
-VPATH =
-OBJS = main.o
-
-##########################################################################
-# Debug settings
-##########################################################################
-
-# Set DEBUGBUILD to 'TRUE' for full debugging (larger, slower binaries),
-# or to 'FALSE' for release builds (smallest, fastest binaries)
-DEBUGBUILD = FALSE
-
-##########################################################################
-# IDE Flags (Keeps various IDEs happy)
-##########################################################################
-
-OPTDEFINES = -D __NEWLIB__
-
-##########################################################################
-# Project-specific files
-##########################################################################
-
-VPATH += project
-OBJS += commands.o
-
-VPATH += project/commands
-OBJS += cmd_chibi_addr.o cmd_chibi_tx.o
-OBJS += cmd_i2ceeprom_read.o cmd_i2ceeprom_write.o cmd_lm75b_gettemp.o
-OBJS += cmd_reset.o cmd_sd_dir.o cmd_sysinfo.o cmd_uart.o
-OBJS += cmd_roundedcorner.o cmd_pwm.o
-
-VPATH += project/commands/drawing
-OBJS += cmd_backlight.o cmd_bmp.o cmd_button.o cmd_calibrate.o
-OBJS += cmd_circle.o cmd_clear.o cmd_line.o cmd_orientation.o
-OBJS += cmd_pixel.o cmd_progress.o cmd_rectangle.o cmd_text.o
-OBJS += cmd_textw.o cmd_tsthreshhold.o cmd_tswait.o cmd_triangle.o
-
-##########################################################################
-# Optional driver files
-##########################################################################
-
-# Chibi Light-Weight Wireless Stack (AT86RF212)
-VPATH += drivers/rf/chibi
-OBJS += chb.o chb_buf.o chb_drvr.o chb_eeprom.o chb_spi.o
-
-# 4K EEPROM
-VPATH += drivers/storage/eeprom drivers/storage/eeprom/mcp24aa
-OBJS += eeprom.o mcp24aa.o
-
-# LM75B temperature sensor
-VPATH += drivers/sensors/lm75b
-OBJS += lm75b.o
-
-# ISL12022M RTC
-VPATH += drivers/rtc/isl12022m
-OBJS += isl12022m.o
-
-# TFT LCD support
-VPATH += drivers/displays/tft drivers/displays/tft/hw
-OBJS += drawing.o touchscreen.o colors.o theme.o bmp.o
-
-# GUI Controls
-VPATH += drivers/displays/tft/controls
-OBJS += button.o hsbchart.o huechart.o label.o
-OBJS += labelcentered.o progressbar.o
-
-# Bitmap (non-AA) fonts
-VPATH += drivers/displays/tft/fonts
-OBJS += fonts.o
-OBJS += dejavusans9.o dejavusansbold9.o dejavusanscondensed9.o
-OBJS += dejavusansmono8.o dejavusansmonobold8.o
-OBJS += verdana9.o verdana14.o verdanabold14.o
-
-# Anti-aliased fonts
-VPATH += drivers/displays/tft/aafonts/aa2 drivers/displays/tft/aafonts/aa4
-OBJS += aafonts.o
-OBJS += DejaVuSansCondensed14_AA2.o DejaVuSansCondensedBold14_AA2.o
-OBJS += DejaVuSansMono10_AA2.o DejaVuSansMono13_AA2.o DejaVuSansMono14_AA2.o
-
-# LCD Driver (Only one can be included at a time!)
-# OBJS += hx8340b.o
-OBJS += ILI9328.o
-# OBJS += ILI9325.o
-# OBJS += ssd1331.o
-# OBJS += ssd1351.o
-# OBJS += st7735.o
-# OBJS += st7783.o
-
-# Bitmap/Monochrome LCD support (ST7565, SSD1306, etc.)
-VPATH += drivers/displays
-VPATH += drivers/displays/bitmap/sharpmem
-VPATH += drivers/displays/bitmap/st7565
-VPATH += drivers/displays/bitmap/ssd1306
-OBJS += smallfonts.o sharpmem.o st7565.o ssd1306.o
-
-#Character Displays (VFD text displays, etc.)
-VPATH += drivers/displays/character/samsung_20T202DA2JA
-OBJS += samsung_20T202DA2JA.o
-
-# ChaN FatFS and SD card support
-VPATH += drivers/fatfs
-OBJS += ff.o mmc.o
-
-# Motors
-VPATH += drivers/motor/stepper
-OBJS += stepper.o
-
-# RSA Encryption/Descryption
-VPATH += drivers/rsa
-OBJS += rsa.o
-
-# DAC
-VPATH += drivers/dac/mcp4725
-OBJS += mcp4725.o
-
-# RFID/NFC
-VPATH += drivers/rf/pn532 drivers/rf/pn532/helpers
-OBJS += pn532.o pn532_bus_i2c.o pn532_bus_uart.o
-OBJS += pn532_mifare_classic.o pn532_mifare_ultralight.o
-
-# TAOS Light Sensors
-VPATH += drivers/sensors/tcs3414 drivers/sensors/tsl2561
-OBJS += tcs3414.o tsl2561.o
-
-# SPI Flash
-VPATH += drivers/storage/spiflash/w25q16bv
-OBJS += w25q16bv.o
-
-# FM Radio
-VPATH += drivers/audio/tea5767
-OBJS += tea5767.o
-
-##########################################################################
-# Library files
-##########################################################################
-
-VPATH += core core/adc core/cmd core/cpu core/gpio core/i2c core/pmu
-VPATH += core/ssp core/systick core/timer16 core/timer32 core/uart
-VPATH += core/usbhid-rom core/wdt core/usbcdc core/pwm core/iap
-VPATH += core/libc
-OBJS += stdio.o string.o
-OBJS += adc.o cpu.o cmd.o gpio.o i2c.o pmu.o ssp.o systick.o timer16.o
-OBJS += timer32.o uart.o uart_buf.o usbconfig.o usbhid.o
-OBJS += wdt.o cdcuser.o cdc_buf.o usbcore.o usbdesc.o usbhw.o usbuser.o
-OBJS += sysinit.o pwm.o iap.o
-
-##########################################################################
-# GNU GCC compiler prefix and location
-##########################################################################
-
-CROSS_COMPILE = arm-none-eabi-
-AS = $(CROSS_COMPILE)gcc
-CC = $(CROSS_COMPILE)gcc
-LD = $(CROSS_COMPILE)gcc
-SIZE = $(CROSS_COMPILE)size
-OBJCOPY = $(CROSS_COMPILE)objcopy
-OBJDUMP = $(CROSS_COMPILE)objdump
-OUTFILE = firmware
-LPCRC = ./lpcrc
-
-##########################################################################
-# GNU GCC compiler flags
-##########################################################################
-ROOT_PATH = .
-INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/project
-
-##########################################################################
-# Startup files
-##########################################################################
-
-LD_PATH = lpc1xxx
-LD_SCRIPT = $(LD_PATH)/linkscript.ld
-LD_TEMP = $(LD_PATH)/memory.ld
-
-ifeq (LPC11xx,$(TARGET))
- CORTEX_TYPE=m0
-else
- CORTEX_TYPE=m3
-endif
-
-CPU_TYPE = cortex-$(CORTEX_TYPE)
-VPATH += lpc1xxx
-OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o
-
-##########################################################################
-# Compiler settings, parameters and flags
-##########################################################################
-ifeq (TRUE,$(DEBUGBUILD))
- CFLAGS = -c -g -O0 $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin $(OPTDEFINES)
- ASFLAGS = -c -g -O0 $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -D__ASSEMBLY__ -x assembler-with-cpp
-else
- CFLAGS = -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin $(OPTDEFINES)
- ASFLAGS = -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -D__ASSEMBLY__ -x assembler-with-cpp
-endif
-
-LDFLAGS = -nostartfiles -mthumb -mcpu=$(CPU_TYPE) -Wl,--gc-sections
-LDLIBS = -lm
-OCFLAGS = --strip-unneeded
-
-all: firmware
-
-%.o : %.c
- $(CC) $(CFLAGS) -o $@ $<
-
-%.o : %.s
- $(AS) $(ASFLAGS) -o $@ $<
-
-firmware: $(OBJS) $(SYS_OBJS)
- -@echo "MEMORY" > $(LD_TEMP)
- -@echo "{" >> $(LD_TEMP)
- -@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP)
- -@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)" >> $(LD_TEMP)
- -@echo "}" >> $(LD_TEMP)
- -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP)
- $(LD) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS)
- -@echo ""
- $(SIZE) $(OUTFILE).elf
- -@echo ""
- $(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin
- $(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin
- $(OBJCOPY) $(OCFLAGS) -O ihex $(OUTFILE).elf $(OUTFILE).hex
- -@echo ""
- $(LPCRC) firmware.bin
-
-clean:
- rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex
+##########################################################################\r
+# User configuration and firmware specific object files \r
+##########################################################################\r
+\r
+# The target, flash and ram of the LPC1xxx microprocessor.\r
+# Use for the target the value: LPC11xx, LPC13xx or LPC17xx\r
+TARGET = LPC13xx\r
+FLASH = 32K\r
+SRAM = 8K\r
+\r
+# For USB HID support the LPC134x reserves 384 bytes from the sram,\r
+# if you don't want to use the USB features, just use 0 here.\r
+SRAM_USB = 384\r
+\r
+VPATH = \r
+OBJS = main.o\r
+\r
+##########################################################################\r
+# Debug settings\r
+##########################################################################\r
+\r
+# Set DEBUGBUILD to 'TRUE' for full debugging (larger, slower binaries), \r
+# or to 'FALSE' for release builds (smallest, fastest binaries)\r
+DEBUGBUILD = FALSE\r
+\r
+##########################################################################\r
+# IDE Flags (Keeps various IDEs happy)\r
+##########################################################################\r
+\r
+OPTDEFINES = -D __NEWLIB__\r
+\r
+##########################################################################\r
+# Project-specific files \r
+##########################################################################\r
+\r
+VPATH += project\r
+OBJS += commands.o\r
+\r
+VPATH += project/commands\r
+OBJS += cmd_chibi_addr.o cmd_chibi_tx.o\r
+OBJS += cmd_i2ceeprom_read.o cmd_i2ceeprom_write.o cmd_lm75b_gettemp.o\r
+OBJS += cmd_reset.o cmd_sd_dir.o cmd_sysinfo.o cmd_uart.o \r
+OBJS += cmd_roundedcorner.o cmd_pwm.o\r
+\r
+VPATH += project/commands/drawing\r
+OBJS += cmd_backlight.o cmd_bmp.o cmd_button.o cmd_calibrate.o\r
+OBJS += cmd_circle.o cmd_clear.o cmd_line.o cmd_orientation.o\r
+OBJS += cmd_pixel.o cmd_progress.o cmd_rectangle.o cmd_text.o\r
+OBJS += cmd_textw.o cmd_tsthreshhold.o cmd_tswait.o cmd_triangle.o\r
+\r
+##########################################################################\r
+# Optional driver files \r
+##########################################################################\r
+\r
+# Chibi Light-Weight Wireless Stack (AT86RF212)\r
+VPATH += drivers/rf/chibi\r
+OBJS += chb.o chb_buf.o chb_drvr.o chb_eeprom.o chb_spi.o\r
+\r
+# 4K EEPROM\r
+VPATH += drivers/storage/eeprom drivers/storage/eeprom/mcp24aa\r
+OBJS += eeprom.o mcp24aa.o\r
+\r
+# LM75B temperature sensor\r
+VPATH += drivers/sensors/lm75b\r
+OBJS += lm75b.o\r
+\r
+# ISL12022M RTC\r
+VPATH += drivers/rtc/isl12022m\r
+OBJS += isl12022m.o\r
+\r
+# TFT LCD support\r
+VPATH += drivers/displays/tft drivers/displays/tft/hw \r
+OBJS += drawing.o touchscreen.o colors.o theme.o bmp.o\r
+\r
+# GUI Controls\r
+VPATH += drivers/displays/tft/controls\r
+OBJS += button.o hsbchart.o huechart.o label.o\r
+OBJS += labelcentered.o progressbar.o\r
+\r
+# Bitmap (non-AA) fonts\r
+VPATH += drivers/displays/tft/fonts\r
+OBJS += fonts.o \r
+OBJS += dejavusans9.o dejavusansbold9.o dejavusanscondensed9.o\r
+OBJS += dejavusansmono8.o dejavusansmonobold8.o\r
+OBJS += verdana9.o verdana14.o verdanabold14.o \r
+\r
+# Anti-aliased fonts\r
+VPATH += drivers/displays/tft/aafonts/aa2 drivers/displays/tft/aafonts/aa4\r
+OBJS += aafonts.o \r
+OBJS += DejaVuSansCondensed14_AA2.o DejaVuSansCondensedBold14_AA2.o\r
+OBJS += DejaVuSansMono10_AA2.o DejaVuSansMono13_AA2.o DejaVuSansMono14_AA2.o\r
+\r
+# LCD Driver (Only one can be included at a time!)\r
+# OBJS += hx8340b.o\r
+OBJS += ILI9328.o\r
+# OBJS += ILI9325.o\r
+# OBJS += ssd1331.o\r
+# OBJS += ssd1351.o\r
+# OBJS += st7735.o\r
+# OBJS += st7783.o\r
+\r
+# Bitmap/Monochrome LCD support (ST7565, SSD1306, etc.)\r
+VPATH += drivers/displays\r
+VPATH += drivers/displays/bitmap/sharpmem\r
+VPATH += drivers/displays/bitmap/st7565\r
+VPATH += drivers/displays/bitmap/ssd1306\r
+OBJS += smallfonts.o sharpmem.o st7565.o ssd1306.o\r
+\r
+#Character Displays (VFD text displays, etc.)\r
+VPATH += drivers/displays/character/samsung_20T202DA2JA\r
+OBJS += samsung_20T202DA2JA.o\r
+\r
+# ChaN FatFS and SD card support\r
+VPATH += drivers/fatfs\r
+OBJS += ff.o mmc.o\r
+\r
+# Motors\r
+VPATH += drivers/motor/stepper\r
+OBJS += stepper.o\r
+\r
+# RSA Encryption/Descryption\r
+VPATH += drivers/rsa\r
+OBJS += rsa.o\r
+\r
+# DAC\r
+VPATH += drivers/dac/mcp4725 drivers/dac/mcp4901\r
+OBJS += mcp4725.o mcp4901.o\r
+\r
+# RFID/NFC\r
+VPATH += drivers/rf/pn532 drivers/rf/pn532/helpers\r
+OBJS += pn532.o pn532_bus_i2c.o pn532_bus_uart.o\r
+OBJS += pn532_mifare_classic.o pn532_mifare_ultralight.o\r
+\r
+# TAOS Light Sensors\r
+VPATH += drivers/sensors/tcs3414 drivers/sensors/tsl2561\r
+OBJS += tcs3414.o tsl2561.o\r
+\r
+# SPI Flash\r
+VPATH += drivers/storage/spiflash/w25q16bv\r
+OBJS += w25q16bv.o\r
+\r
+# FM Radio\r
+VPATH += drivers/audio/tea5767\r
+OBJS += tea5767.o\r
+\r
+##########################################################################\r
+# Library files \r
+##########################################################################\r
+\r
+VPATH += core core/adc core/cmd core/cpu core/gpio core/i2c core/pmu\r
+VPATH += core/ssp core/systick core/timer16 core/timer32 core/uart\r
+VPATH += core/usbhid-rom core/wdt core/usbcdc core/pwm core/iap\r
+VPATH += core/libc\r
+OBJS += stdio.o string.o\r
+OBJS += adc.o cpu.o cmd.o gpio.o i2c.o pmu.o ssp.o systick.o timer16.o\r
+OBJS += timer32.o uart.o uart_buf.o usbconfig.o usbhid.o\r
+OBJS += wdt.o cdcuser.o cdc_buf.o usbcore.o usbdesc.o usbhw.o usbuser.o \r
+OBJS += sysinit.o pwm.o iap.o\r
+\r
+##########################################################################\r
+# GNU GCC compiler prefix and location\r
+##########################################################################\r
+\r
+CROSS_COMPILE = arm-none-eabi-\r
+AS = $(CROSS_COMPILE)gcc\r
+CC = $(CROSS_COMPILE)gcc\r
+LD = $(CROSS_COMPILE)gcc\r
+SIZE = $(CROSS_COMPILE)size\r
+OBJCOPY = $(CROSS_COMPILE)objcopy\r
+OBJDUMP = $(CROSS_COMPILE)objdump\r
+OUTFILE = firmware\r
+LPCRC = ./lpcrc\r
+\r
+##########################################################################\r
+# GNU GCC compiler flags\r
+##########################################################################\r
+ROOT_PATH = .\r
+INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/project\r
+\r
+##########################################################################\r
+# Startup files\r
+##########################################################################\r
+\r
+LD_PATH = lpc1xxx\r
+LD_SCRIPT = $(LD_PATH)/linkscript.ld\r
+LD_TEMP = $(LD_PATH)/memory.ld\r
+\r
+ifeq (LPC11xx,$(TARGET))\r
+ CORTEX_TYPE=m0\r
+else\r
+ CORTEX_TYPE=m3\r
+endif\r
+\r
+CPU_TYPE = cortex-$(CORTEX_TYPE)\r
+VPATH += lpc1xxx\r
+OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o\r
+\r
+##########################################################################\r
+# Compiler settings, parameters and flags\r
+##########################################################################\r
+ifeq (TRUE,$(DEBUGBUILD))\r
+ CFLAGS = -c -g -O0 $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin $(OPTDEFINES)\r
+ ASFLAGS = -c -g -O0 $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -D__ASSEMBLY__ -x assembler-with-cpp\r
+else\r
+ CFLAGS = -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -fno-builtin $(OPTDEFINES)\r
+ ASFLAGS = -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -D__ASSEMBLY__ -x assembler-with-cpp\r
+endif\r
+\r
+LDFLAGS = -nostartfiles -mthumb -mcpu=$(CPU_TYPE) -Wl,--gc-sections\r
+LDLIBS = -lm\r
+OCFLAGS = --strip-unneeded\r
+\r
+all: firmware\r
+\r
+%.o : %.c\r
+ $(CC) $(CFLAGS) -o $@ $<\r
+\r
+%.o : %.s\r
+ $(AS) $(ASFLAGS) -o $@ $<\r
+\r
+firmware: $(OBJS) $(SYS_OBJS)\r
+ -@echo "MEMORY" > $(LD_TEMP)\r
+ -@echo "{" >> $(LD_TEMP)\r
+ -@echo " flash(rx): ORIGIN = 0x00000000, LENGTH = $(FLASH)" >> $(LD_TEMP)\r
+ -@echo " sram(rwx): ORIGIN = 0x10000000+$(SRAM_USB), LENGTH = $(SRAM)-$(SRAM_USB)" >> $(LD_TEMP)\r
+ -@echo "}" >> $(LD_TEMP)\r
+ -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP)\r
+ $(LD) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS)\r
+ -@echo ""\r
+ $(SIZE) $(OUTFILE).elf\r
+ -@echo ""\r
+ $(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin\r
+ $(OBJCOPY) $(OCFLAGS) -O binary $(OUTFILE).elf $(OUTFILE).bin\r
+ $(OBJCOPY) $(OCFLAGS) -O ihex $(OUTFILE).elf $(OUTFILE).hex\r
+ -@echo ""\r
+ $(LPCRC) firmware.bin\r
+\r
+clean:\r
+ rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex\r
--- /dev/null
+/**************************************************************************/\r
+/*!\r
+ @file mcp4901.c\r
+ @author Tauon\r
+\r
+ @section LICENSE\r
+\r
+ Software License Agreement (BSD License)\r
+\r
+ Copyright (c) 2012, Tauon\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without\r
+ modification, are permitted provided that the following conditions are met:\r
+ 1. Redistributions of source code must retain the above copyright\r
+ notice, this list of conditions and the following disclaimer.\r
+ 2. Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in the\r
+ documentation and/or other materials provided with the distribution.\r
+ 3. Neither the name of the copyright holders nor the\r
+ names of its contributors may be used to endorse or promote products\r
+ derived from this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY\r
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY\r
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+/**************************************************************************/\r
+#include "mcp4901.h"\r
+\r
+#define DAC_BUF 0\r
+#define DAC_GA 1\r
+#define DAC_SHDN 1\r
+#define DAC_BITS8\r
+\r
+uint16_t settings;\r
+\r
+// Control pins\r
+#define MCP4901_GPIODATAREG (*(pREG32 (0x50023FFC))) // GPIO2DATA\r
+#define MCP4901_PORT (2)\r
+\r
+#define MCP4901_LDAC (0)\r
+#define MCP4901_CS_PIN (6)\r
+#define MCP4901_SCL_PIN (7)\r
+#define MCP4901_SDI_PIN (8)\r
+\r
+// Macros for control line state\r
+#define CLR_SDI do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_SDI_PIN); } while(0)\r
+#define SET_SDI do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_SDI_PIN); MCP4901_GPIODATAREG |= (1<<MCP4901_SDI_PIN); } while(0)\r
+#define CLR_SCL do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_SCL_PIN); } while(0)\r
+#define SET_SCL do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_SCL_PIN); MCP4901_GPIODATAREG |= (1<<MCP4901_SCL_PIN); } while(0)\r
+#define CLR_CS do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_CS_PIN); } while(0)\r
+#define SET_CS do { MCP4901_GPIODATAREG &= ~(1<<MCP4901_CS_PIN); MCP4901_GPIODATAREG |= (1<<MCP4901_CS_PIN); } while(0)\r
+\r
+/*************************************************/\r
+\r
+void mcpWriteData(uint8_t data)\r
+{\r
+ uint8_t i = 0;\r
+ for (i=0; i<8; i++)\r
+ {\r
+ if (data & 0x80)\r
+ {\r
+ SET_SDI;\r
+ }\r
+ else\r
+ {\r
+\r
+ CLR_SDI;\r
+ }\r
+ data <<= 1;\r
+ CLR_SCL;\r
+ SET_SCL;\r
+ }\r
+}\r
+\r
+/*************************************************/\r
+void mcpWriteData16(uint16_t data)\r
+{\r
+ mcpWriteData((data>>8) & 0xFF);\r
+ mcpWriteData(data & 0xFF);\r
+}\r
+\r
+void mcp4901Init()\r
+{\r
+ settings = (DAC_BUF << 2 | DAC_GA << 1 | DAC_SHDN) << 12;\r
+ gpioSetDir(MCP4901_PORT, MCP4901_LDAC , gpioDirection_Output);\r
+ gpioSetDir(MCP4901_PORT, MCP4901_CS_PIN , gpioDirection_Output);\r
+ gpioSetDir(MCP4901_PORT, MCP4901_SCL_PIN, gpioDirection_Output);\r
+ gpioSetDir(MCP4901_PORT, MCP4901_SDI_PIN, gpioDirection_Output);\r
+}\r
+void mcp4901ChangeSettings(bool BUFFER, bool GAIN, bool SHUTDOWN)\r
+{\r
+ settings = (BUFFER << 2 | GAIN << 1 | (!SHUTDOWN)) << 12;\r
+}\r
+void mcp4901LDAC(void)\r
+{\r
+ gpioSetValue(MCP4901_PORT,MCP4901_LDAC,0);\r
+ gpioSetValue(MCP4901_PORT,MCP4901_LDAC,1);\r
+}\r
+void mcp4901SetVoltage( uint8_t output)\r
+{\r
+ uint16_t data;\r
+ #ifdef DAC_BITS8\r
+ data = settings | (output << 4);\r
+ #endif\r
+\r
+ #ifdef DAC_BITS10\r
+ data = settings | (output << 2);\r
+ #endif\r
+\r
+ #ifdef DAC_BITS12\r
+ data = settings | output;\r
+ #endif\r
+ CLR_CS;\r
+ mcpWriteData16(data);\r
+ SET_CS;\r
+}\r
+\r
+\r