Merge branch 'master' of git://github.com/microbuilder/LPC1343CodeBase
authorMiceuz <mic@hardcore.lt>
Tue, 29 May 2012 21:32:39 +0000 (23:32 +0200)
committerMiceuz <mic@hardcore.lt>
Tue, 29 May 2012 21:32:39 +0000 (23:32 +0200)
32 files changed:
ChangeLog.txt
Makefile
build/codelite/LPC1343 Workspace.workspace.session
build/codelite/LPC1343_CodeBase.project
build/crossworks/LPC1343_CodeBase.hzp
build/crossworks/LPC1343_CodeBase.hzs
core/adc/adc.c
core/adc/adc.h
core/i2c/i2c.h
core/pwm/pwm.c
drivers/dac/mcp4725/mcp4725.h
drivers/dac/mcp4901/mcp4901.c [new file with mode: 0644]
drivers/dac/mcp4901/mcp4901.h [new file with mode: 0644]
drivers/displays/tft/controls/button.c
drivers/displays/tft/hw/hx8347d.c [new file with mode: 0644]
drivers/displays/tft/hw/hx8347d.h [new file with mode: 0644]
drivers/displays/tft/hw/readme.txt
drivers/sensors/ina219/ina219.c [new file with mode: 0644]
drivers/sensors/ina219/ina219.h [new file with mode: 0644]
main.c
project/cmd_tbl.h
project/commands/cmd_pwm.c
projectconfig.h
tools/testfirmware/LPC1343_LCDStandalone_UART_LF.bin [deleted file]
tools/testfirmware/LPC1343_LCDStandalone_USB_CRLF.bin [deleted file]
tools/testfirmware/blinky.bin [deleted file]
tools/testfirmware/blinky_usbcli.bin [new file with mode: 0644]
tools/testfirmware/uartcli.bin [deleted file]
tools/validation/startupdelay/StartupTime_CrossworksForARM.png [new file with mode: 0644]
tools/validation/startupdelay/StartupTime_GCCMakefile.png [new file with mode: 0644]
tools/validation/startupdelay/main.c [new file with mode: 0644]
tools/validation/startupdelay/readme.txt [new file with mode: 0644]

index e083124..830c427 100644 (file)
@@ -2,7 +2,12 @@ v1.1.2 - ongoing
 ==============================================================================
 NEW FEATURES
 ------------------------------------------------------------------------------
+- Added drivers/sensors/ina219/ina219.c (work in progress!)
+- Added drivers/displays/tft/hw/hx8347d.C (courtesy tauonteilchen again)
+- Added drivers/dac/mcp4901 (courtesy tauonteilchen, thanks!)
+- Cleaned up /tools/testfirmware to include more recent blinky, etc.
 - Added basic TEA5767 drive
+- Added core/cmd/ansi.h (rediscover the joy of ANSI graphics codes :)
 - Added fastHLine and fastVLine to lcdProperties_t for all lcd drivers (to
   known whether an accelerated vertical or horizontal line drawing function
   is present in the driver or not)
@@ -10,6 +15,11 @@ NEW FEATURES
 - Added PWM command to CLI (thanks Miceuz)
 - Added optional callback in 32-bit timer ISR (thanks again Miceuz)
 
+BUG FIXES/OPTIMISATIONS/ETC.
+------------------------------------------------------------------------------
+- Minor accuracy improvement to pwm.c (off by 1 error)
+- Fixed typos in cmd_pwm.c and cmd_tbl.h
+- Changed I2C default speed to 400kHz (from 100kHz)
 
 v1.1.1 - 14 April 2012
 ==============================================================================
index 482caea..a3aa928 100644 (file)
--- a/Makefile
+++ b/Makefile
-##########################################################################
-# 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 += hx8347d.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
+# IN219 Current Sensor\r
+VPATH += drivers/sensors/ina219\r
+OBJS += ina219.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
index b59e362..c047e00 100644 (file)
     </TabInfo>
     <TabInfo>
       <wxString Value="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" Name="FileName"/>
-      <int Value="0" Name="FirstVisibleLine"/>
-      <int Value="6" Name="CurrentLine"/>
+      <int Value="40" Name="FirstVisibleLine"/>
+      <int Value="60" Name="CurrentLine"/>
+      <wxArrayString Name="Bookmarks"/>
+    </TabInfo>
+    <TabInfo>
+      <wxString Value="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\displays\tft\controls\button.c" Name="FileName"/>
+      <int Value="43" Name="FirstVisibleLine"/>
+      <int Value="56" Name="CurrentLine"/>
       <wxArrayString Name="Bookmarks"/>
     </TabInfo>
   </TabInfoArray>
   <SerializedObject Name="m_breakpoints">
-    <long Value="1" Name="Count"/>
+    <long Value="4" Name="Count"/>
     <SerializedObject Name="Breakpoint0">
       <wxString Value="C:\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" Name="file"/>
       <int Value="60" Name="lineno"/>
       <wxString Value="" Name="conditions"/>
       <int Value="0" Name="origin"/>
     </SerializedObject>
+    <SerializedObject Name="Breakpoint1">
+      <wxString Value="C:\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" Name="file"/>
+      <int Value="60" Name="lineno"/>
+      <wxString Value="" Name="function_name"/>
+      <wxString Value="" Name="memory_address"/>
+      <int Value="1" Name="bp_type"/>
+      <int Value="0" Name="watchpoint_type"/>
+      <wxString Value="" Name="watchpt_data"/>
+      <CData Name="commandlist"/>
+      <bool Value="0" Name="regex"/>
+      <bool Value="0" Name="is_temp"/>
+      <bool Value="1" Name="is_enabled"/>
+      <int Value="0" Name="ignore_number"/>
+      <wxString Value="" Name="conditions"/>
+      <int Value="0" Name="origin"/>
+    </SerializedObject>
+    <SerializedObject Name="Breakpoint2">
+      <wxString Value="C:\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" Name="file"/>
+      <int Value="60" Name="lineno"/>
+      <wxString Value="" Name="function_name"/>
+      <wxString Value="" Name="memory_address"/>
+      <int Value="1" Name="bp_type"/>
+      <int Value="0" Name="watchpoint_type"/>
+      <wxString Value="" Name="watchpt_data"/>
+      <CData Name="commandlist"/>
+      <bool Value="0" Name="regex"/>
+      <bool Value="0" Name="is_temp"/>
+      <bool Value="1" Name="is_enabled"/>
+      <int Value="0" Name="ignore_number"/>
+      <wxString Value="" Name="conditions"/>
+      <int Value="0" Name="origin"/>
+    </SerializedObject>
+    <SerializedObject Name="Breakpoint3">
+      <wxString Value="C:\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" Name="file"/>
+      <int Value="60" Name="lineno"/>
+      <wxString Value="" Name="function_name"/>
+      <wxString Value="" Name="memory_address"/>
+      <int Value="1" Name="bp_type"/>
+      <int Value="0" Name="watchpoint_type"/>
+      <wxString Value="" Name="watchpt_data"/>
+      <CData Name="commandlist"/>
+      <bool Value="0" Name="regex"/>
+      <bool Value="0" Name="is_temp"/>
+      <bool Value="1" Name="is_enabled"/>
+      <int Value="0" Name="ignore_number"/>
+      <wxString Value="" Name="conditions"/>
+      <int Value="0" Name="origin"/>
+    </SerializedObject>
   </SerializedObject>
 </Session>
index 10d1983..d2b88b4 100644 (file)
       </Linker>
       <ResourceCompiler Options=""/>
     </GlobalSettings>
-    <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger Cortex M3" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
+    <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
       <Compiler Options="-g" C_Options="-g" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
         <IncludePath Value="."/>
       </Compiler>
       <Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
         <![CDATA[]]>
       </Environment>
-      <Debugger IsRemote="yes" RemoteHostName="localhost" RemoteHostPort="2331" DebuggerPath="arm-none-eabi-gdb.exe">
+      <Debugger IsRemote="yes" RemoteHostName="localhost" RemoteHostPort="2331" DebuggerPath="C:\yagarto\bin\arm-none-eabi-gdb.exe">
         <PostConnectCommands/>
         <StartupCommands># Make sure that we are using SWD
 monitor interface SWD
index 49398d9..636619f 100644 (file)
@@ -73,6 +73,7 @@
             <configuration Name="THUMB Flash Debug" build_exclude_from_build="No"/>
             <configuration Name="THUMB Flash Release" build_exclude_from_build="No"/>
           </file>
+          <file file_name="../../core/cmd/ansi.h"/>
         </folder>
         <folder Name="usbcdc">
           <file file_name="../../core/usbcdc/cdcuser.c">
           <folder Name="tcs3414">
             <file file_name="../../drivers/sensors/tcs3414/tcs3414.c"/>
           </folder>
+          <folder Name="ina219">
+            <file file_name="../../drivers/sensors/ina219/ina219.c"/>
+          </folder>
         </folder>
         <folder Name="displays" file_name="">
           <folder Name="bitmap">
                 <configuration Name="THUMB Flash Debug" build_exclude_from_build="Yes"/>
                 <configuration Name="THUMB Flash Release" build_exclude_from_build="Yes"/>
               </file>
+              <file file_name="../../drivers/displays/tft/hw/hx8347d.c">
+                <configuration Name="THUMB Flash Release" build_exclude_from_build="Yes"/>
+                <configuration Name="THUMB Flash Debug" build_exclude_from_build="Yes"/>
+              </file>
             </folder>
             <folder Name="fonts">
               <file file_name="../../drivers/displays/tft/fonts/dejavusans9.c">
           <folder Name="mcp4725">
             <file file_name="../../drivers/dac/mcp4725/mcp4725.c"/>
           </folder>
+          <folder Name="mcp4901">
+            <file file_name="../../drivers/dac/mcp4901/mcp4901.c"/>
+          </folder>
         </folder>
         <folder Name="rtc">
           <folder Name="isl12022m">
index d03e981..61c5d6a 100644 (file)
@@ -24,7 +24,9 @@
   <ProjectSessionItem path="LPC1343_CodeBase" name="unnamed" />
   <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase" name="unnamed" />
   <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase;Source Files" name="unnamed" />
-  <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase;System Files" name="unnamed" />
+  <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase;Source Files;drivers" name="unnamed" />
+  <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase;Source Files;drivers;dac" name="unnamed" />
+  <ProjectSessionItem path="LPC1343_CodeBase;LPC1343_CodeBase;Source Files;drivers;dac;mcp4725" name="unnamed" />
  </Project>
  <Register1>
   <RegisterWindow openNodes="GPIO2" binaryNodes="" hiddenNodes="" unsignedNodes="" visibleGroups="CPU;CoreDebug;GPIO2" decimalNodes="" octalNodes="" asciiNodes="" />
  </TraceWindow>
  <Watch1>
   <Watches active="1" update="Each Second" >
-   <Watchpoint linenumber="66" radix="10" name="msTicks" expression="msTicks" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/core/systick/systick.c" />
-   <Watchpoint linenumber="138" radix="16" name="timer32_0_counter" expression="timer32_0_counter" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/core/timer32/timer32.c" />
-   <Watchpoint linenumber="155" radix="-1" name="xTickCount" expression="xTickCount" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/freertos/tasks.c" />
    <Watchpoint linenumber="155" radix="16" name="Tick" expression="Tick" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/freertos/tasks.c" />
+   <Watchpoint linenumber="155" radix="-1" name="xTickCount" expression="xTickCount" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/freertos/tasks.c" />
+   <Watchpoint linenumber="138" radix="16" name="timer32_0_counter" expression="timer32_0_counter" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/core/timer32/timer32.c" />
+   <Watchpoint linenumber="66" radix="10" name="msTicks" expression="msTicks" filename="c:/documents and settings/kevin/my documents/my dropbox/microbuilder/code/lpc1343/lpc1343_codebase/core/systick/systick.c" />
   </Watches>
  </Watch1>
  <Watch2>
   <Watches active="0" update="Never" />
  </Watch4>
  <Files>
-  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" y="0" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" left="0" selected="1" name="unnamed" top="36" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="3" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" y="69" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\main.c" left="0" selected="1" name="unnamed" top="54" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\adc\adc.c" y="30" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\adc\adc.c" left="0" selected="0" name="unnamed" top="0" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\dropbox\microbuilder\code\lpc1343\lpc1343_codebase_git\drivers\sensors\ina219\ina219.c" y="115" path="C:\dropbox\microbuilder\code\lpc1343\lpc1343_codebase_git\drivers\sensors\ina219\ina219.c" left="0" selected="0" name="unnamed" top="81" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\sensors\ina219\ina219.h" y="133" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\sensors\ina219\ina219.h" left="0" selected="0" name="unnamed" top="117" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\cmd\cmd.c" y="314" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\cmd\cmd.c" left="0" selected="0" name="unnamed" top="270" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="72" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\dac\mcp4725\mcp4725.c" y="43" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\dac\mcp4725\mcp4725.c" left="0" selected="0" name="unnamed" top="30" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\i2c\i2c.c" y="0" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\i2c\i2c.c" left="0" selected="0" name="unnamed" top="351" />
+  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\i2c\i2c.h" y="92" path="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\core\i2c\i2c.h" left="0" selected="0" name="unnamed" top="54" />
  </Files>
- <ARMCrossStudioWindow activeProject="LPC1343_CodeBase" autoConnectTarget="SEGGER J-Link" debugSearchFileMap="" fileDialogInitialDirectory="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\audio\tea5767" fileDialogDefaultFilter="*.c" autoConnectCapabilities="388991" debugSearchPath="" buildConfiguration="THUMB Flash Debug" />
+ <ARMCrossStudioWindow activeProject="LPC1343_CodeBase" autoConnectTarget="SEGGER J-Link" debugSearchFileMap="" fileDialogInitialDirectory="C:\Dropbox\microBuilder\Code\LPC1343\LPC1343_CodeBase_GIT\drivers\dac\mcp4901" fileDialogDefaultFilter="*.c" autoConnectCapabilities="388991" debugSearchPath="" buildConfiguration="THUMB Flash Release" />
 </session>
index 5728545..0a6dd39 100644 (file)
@@ -162,6 +162,48 @@ uint32_t adcReadSingle (uint8_t channelNum)
   return (adcData);
 }
 
+/**************************************************************************/
+/*! 
+ @brief Returns the oversampled conversion results on the specified ADC channel.
+ This function will manually start A/D conversions on a single
+ channel sum and divide results to get a value of increased resolution. 
+ Read more: AVR121: Enhancing ADC resolution by oversampling [http://www.atmel.com/Images/doc8003.pdf]
+ @param[in]  channelNum
+ The A/D channel [0..7] that will be used during the A/D 
+ conversion.  (Note that only A/D channel's 0..3 are 
+ configured by default in adcInit.)
+
+ @param[in] extraBits
+ Additional bits you want to add to resolution. Hardware resolution is
+ 10bits, if 6 is psecified as extraBits, the resolution will be increated to
+ 16 bit. 
+ @return     0 if an overrun error occured, otherwise a 10-bit value
+ containing the A/D conversion results.
+ @warning    Only AD channels 0..3 are configured for A/D in adcInit.
+ If you wish to use A/D pins 4..7 they will also need to
+ be added to the adcInit function.
+ */
+/**************************************************************************/
+
+uint32_t adcReadOversampled (uint8_t channelNum, uint8_t extraBits) {
+    uint32_t sampleCount = 1 << (extraBits * 2);
+    uint16_t i;
+    uint32_t adcOversampled = 0;
+    
+    for(i = 0; i < sampleCount; i++) {
+        uint16_t adcValue = adcReadSingle(channelNum);
+        adcOversampled += adcValue;
+    }
+    
+    adcOversampled = adcOversampled >> extraBits;
+    return adcOversampled;
+}
+
 /**************************************************************************/
 /*! 
     @brief Returns the conversion results on the specified ADC channel.
index 29e168d..a1c3879 100644 (file)
@@ -42,6 +42,8 @@
 #include "projectconfig.h"
 
 uint32_t   adcRead (uint8_t channelNum);
-void  adcInit (void);
+uint32_t   adcReadOversampled (uint8_t channelNum, uint8_t extraBits);
+uint32_t   adcReadSingle(uint8_t channelNum);
+void       adcInit (void);
 
 #endif
index 5e16c82..bdf5b70 100644 (file)
@@ -89,8 +89,8 @@
    Fast Mode       (400KHz) = CFG_CPU_CCLK / 800000
    Fast- Mode Plus (1MHz)   = CFG_CPU_CCLK / 2000000       */
 
-#define I2SCLH_SCLH       CFG_CPU_CCLK / 200000  /* Standard Mode I2C SCL Duty Cycle High (400KHz) */
-#define I2SCLL_SCLL       CFG_CPU_CCLK / 200000  /* Fast Mode I2C SCL Duty Cycle Low (400KHz) */
+#define I2SCLH_SCLH       CFG_CPU_CCLK / 800000  /* Standard Mode I2C SCL Duty Cycle High (400KHz) */
+#define I2SCLL_SCLL       CFG_CPU_CCLK / 800000  /* Fast Mode I2C SCL Duty Cycle Low (400KHz) */
 #define I2SCLH_HS_SCLH    CFG_CPU_CCLK / 2000000  /* Fast Plus I2C SCL Duty Cycle High Reg */
 #define I2SCLL_HS_SCLL    CFG_CPU_CCLK / 2000000  /* Fast Plus I2C SCL Duty Cycle Low Reg */
 
index 7f1e2e5..a27b666 100644 (file)
@@ -178,7 +178,7 @@ int pwmSetDutyCycle(uint32_t percentage)
   }
 
   /* Set Duty Cycle (MR0) */
-  TMR_TMR16B1MR0 = ((pwmPulseWidth * (100 - (pwmDutyCycle = percentage))) / 100) + 1;
+  TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - (pwmDutyCycle = percentage))) / 100;
 
   return 0;
 }
@@ -246,7 +246,7 @@ int pwmSetFrequencyInMicroseconds(uint16_t us)
   TMR_TMR16B1MR3 = (pwmPulseWidth = ticks - 1);
 
   /* Adjust Duty Cycle (MR0) */
-  TMR_TMR16B1MR0 = ((pwmPulseWidth * (100 - pwmDutyCycle)) / 100) + 1;
+  TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - pwmDutyCycle)) / 100;
 
   return 0;  
 }
index 71100cc..bb91b3e 100644 (file)
@@ -39,7 +39,8 @@
 
 #include "projectconfig.h"
 
-#define MCP4725_ADDRESS                 (0xC0)   // 1100000x - Assumes A0 is GND and A2,A1 are 0 (MCP4725A0T-E/CH)
+//#define MCP4725_ADDRESS                 (0xC0)   // 1100000x - Assumes A0 is GND and A2,A1 are 00 (MCP4725A0T-E/CH)
+#define MCP4725_ADDRESS                 (0xC4)   // 1100010x - Assumes A0 is GND and A2,A1 are 01 (MCP4725A1T-E/CH)
 #define MCP4725_READ                    (0x01)
 #define MCP4726_CMD_WRITEDAC            (0x40)  // Writes data to the DAC
 #define MCP4726_CMD_WRITEDACEEPROM      (0x60)  // Writes data to the DAC and the EEPROM (persisting the assigned value after reset)
diff --git a/drivers/dac/mcp4901/mcp4901.c b/drivers/dac/mcp4901/mcp4901.c
new file mode 100644 (file)
index 0000000..faed8bd
--- /dev/null
@@ -0,0 +1,127 @@
+/**************************************************************************/\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
diff --git a/drivers/dac/mcp4901/mcp4901.h b/drivers/dac/mcp4901/mcp4901.h
new file mode 100644 (file)
index 0000000..930e3bf
--- /dev/null
@@ -0,0 +1,48 @@
+/**************************************************************************/\r
+/*!\r
+    @file     mcp4901.h\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
+\r
+#ifndef _MCP4901_H_\r
+#define _MCP4901_H_\r
+\r
+#include "projectconfig.h"\r
+#include "core/gpio/gpio.h"\r
+\r
+void mcp4901Init(void);\r
+void mcp4901SetVoltage( uint8_t output);\r
+void mcp4901LDAC(void);\r
+void mcp4901ChangeSettings(bool BUFFER, bool GAIN, bool SHUTDOWN);\r
+\r
+#endif\r
index db29382..c657823 100644 (file)
@@ -59,9 +59,6 @@
 /**************************************************************************/
 void buttonRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t fontColor, char *text, theme_t theme)
 {
-  uint16_t brighter, darker;
-  uint16_t buttonEnd;
-
   // Draw background gradient then outline
   drawGradient(x+2, y+2, x+width-2, y+height-2, theme.colorFill, theme.colorBorder);
   drawRoundedRectangle(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL);
diff --git a/drivers/displays/tft/hw/hx8347d.c b/drivers/displays/tft/hw/hx8347d.c
new file mode 100644 (file)
index 0000000..dd115f6
--- /dev/null
@@ -0,0 +1,703 @@
+/**************************************************************************/\r
+/*!\r
+    @file     hx8347d.c\r
+    @author   Tauon {TauonTeilchen} Jabber ID Tauon[at]jabber.ccc.de\r
+\r
+    @section  DESCRIPTION\r
+       Driver for hx8347h 240x320 pixel TFT LCD displays.\r
+    Is written for MI0283QT-2 LCD from watterott.com\r
+    More infos: http://www.watterott.com/de/MI0283QT-2-Adapter\r
+    http://www.watterott.com/index.php?page=product&info=1597&dl_media=3202\r
+\r
+    @section  LICENSE\r
+\r
+    Software License Agreement (BSD License)\r
+\r
+    Copyright (c) 2012, TauonTeilchen \r
+    ----------------------------------------------------------------------------\r
+    "THE ClubMate-WARE LICENSE" (Revision 42):\r
+    JID: <Tauon@jabber.ccc.de> wrote this file. As long as you retain this notice you\r
+    can do whatever you want with this stuff. If we meet some day, and you think\r
+    this stuff is worth it, you can buy me a ClubMate in return Tauon\r
+    ----------------------------------------------------------------------------\r
+    ----------------------------------------------------------------------------\r
+    "THE ClubMate-WARE LICENSE" (Revision 42):\r
+    JID: <Tauon@jabber.ccc.de> schrieb diese Datei. Solange Sie diesen Vermerk nicht entfernen, k�nnen\r
+    Sie mit dem Material machen, was Sie m�chten. Wenn wir uns eines Tages treffen und Sie\r
+    denken, das Material ist es wert, k�nnen Sie mir daf�r ein ClubMate ausgeben. Tauon\r
+    ----------------------------------------------------------------------------\r
+\r
+*/\r
+/**************************************************************************/\r
+#include "drivers/displays/tft/hw/hx8347d.h"\r
+\r
+#define LCD_ID                      (0x00)\r
+#define LCD_DATA                    ((0x72)|(LCD_ID<<2))\r
+#define LCD_REGISTER                ((0x70)|(LCD_ID<<2))\r
+\r
+#define LCD_BACK_LIGHT              6\r
+#define LCD_RST                     5\r
+#define LCD_CS                      4\r
+\r
+// Macros for control line state\r
+#define LCD_CS_ENABLE()             GPIO_GPIO2DATA &= ~0x10  // gpioSetValue(2, 4, 0)\r
+#define LCD_CS_DISABLE()            GPIO_GPIO2DATA |=  0x10  // gpioSetValue(2, 4, 1)\r
+#define LCD_RST_ENABLE()            GPIO_GPIO2DATA &=  ~0x20 // gpioSetValue(2, 5, 0)\r
+#define LCD_RST_DISABLE()           GPIO_GPIO2DATA |=   0x20 // gpioSetValue(2, 5, 1)\r
+\r
+#define Himax ID                    0x00\r
+#define Display_Mode_Control        0x01\r
+\r
+#define Column_Address_Start_2      0x02\r
+#define Column_Address_Start_1      0x03\r
+#define Column_Address_End_2        0x04\r
+#define Column_Address_End_1        0x05\r
+\r
+#define Row_Address_Start_2         0x06\r
+#define Row_Address_Start_1         0x07\r
+#define Row_Address_End_2           0x08\r
+#define Row_Address_End_1           0x09\r
+\r
+#define Partial_Area_Start_Row_2    0x0A\r
+#define Partial_Area_Start_Row_1    0x0B\r
+#define Partial_Area_End_Row_2      0x0C\r
+#define Partial_Area_End_Row_1      0x0D\r
+\r
+#define TFA_REGISTER                0x0E\r
+#define VSA_REGISTER                0x10\r
+#define BFA_REGISTER                0x12\r
+#define VSP_REGISTER                0x14\r
+\r
+#define COLMOD                      0x17\r
+#define OSC_Control_1               0x18\r
+#define OSC_Control_2               0x19\r
+#define Power_Control_1             0x1A\r
+#define Power_Control_2             0x1B\r
+#define Power_Control_3             0x1C\r
+#define Power_Control_4             0x1D\r
+#define Power_Control_5             0x1E\r
+#define Power_Control_6             0x1F\r
+#define VCOM_Control_1              0x23\r
+#define VCOM_Control_2              0x24\r
+#define VCOM_Control_3              0x25\r
+#define Display_Control_1           0x26\r
+#define Display_Control_2           0x27\r
+#define Display_Control_3           0x28\r
+#define Source_OP_Control_Normal    0xE8\r
+#define Source_OP_Control_IDLE      0xE9\r
+#define Power_Control_Internal_1    0xEA\r
+#define Power_Control_Internal_2    0xEB\r
+#define Source_Control_Internal_1   0xEC\r
+#define Source_Control_Internal_2   0xED\r
+\r
+#define OSC_Control_2_OSC_EN        0x01\r
+#define Display_Control_3_GON       0x20\r
+#define Display_Control_3_DTE       0x10\r
+#define Display_Control_3_D0        0x04\r
+#define Display_Control_3_D1        0x08\r
+#define Power_Control_6_STB         0x01\r
+#define Display_Mode_Control_DP_STB_S 0x40\r
+#define Display_Mode_Control_DP_STB 0x80\r
+\r
+uint16_t offset;\r
+\r
+/*************************************************/\r
+/* Private Methods                               */\r
+/*************************************************/\r
+void lcd_drawstart(void);\r
+void lcd_cmd(uint16_t reg, uint16_t param);\r
+void lcd_clear(uint16_t color);\r
+void lcd_draw(uint16_t color);\r
+void lcd_drawstart(void);\r
+void lcd_drawstop(void);\r
+void hx8347d_DisplayOnFlow(void);\r
+void hx8347d_DisplayOffFlow(void);\r
+void lcd_area(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);\r
+\r
+\r
+void hx8347d_Scroll(uint16_t tfa,uint16_t vsa,uint16_t bfa, uint16_t vsp)\r
+{\r
+  lcd_cmd(TFA_REGISTER    , tfa >> 8);\r
+  lcd_cmd(TFA_REGISTER + 1, tfa & 0xFF);\r
+\r
+  lcd_cmd(VSA_REGISTER    , vsa >> 8);\r
+  lcd_cmd(VSA_REGISTER + 1, vsa & 0xFF);\r
+\r
+  lcd_cmd(BFA_REGISTER    , bfa >> 8);\r
+  lcd_cmd(BFA_REGISTER + 1, bfa & 0xFF);\r
+\r
+  lcd_cmd(VSP_REGISTER    , vsp>> 8);\r
+  lcd_cmd(VSP_REGISTER + 1, vsp & 0xFF);\r
+  lcd_cmd(0x01, 0x08); //scroll on\r
+}\r
+\r
+void displayOnFlow(void)\r
+{\r
+  lcd_cmd(Display_Control_3, 0x0038);\r
+  systickDelay(4);\r
+  lcd_cmd(Display_Control_3, 0x003C);\r
+}\r
+void displayOffFlow(void)\r
+{\r
+  lcd_cmd(Display_Control_3, Display_Control_3_GON | Display_Control_3_DTE | Display_Control_3_D1);\r
+  systickDelay(4);\r
+  lcd_cmd(Display_Control_3, Display_Control_3_D0);\r
+}\r
+\r
+void lcd_cmd(uint16_t reg, uint16_t param)\r
+{\r
+  uint8_t b_first[2];\r
+  uint8_t b_sec[2];\r
+  LCD_CS_ENABLE();\r
+\r
+  b_first[0] = LCD_REGISTER;\r
+  b_first[1] = reg;\r
+\r
+  sspSend(0, b_first, 2);\r
+  LCD_CS_DISABLE();\r
+\r
+  b_sec[0] = LCD_DATA;\r
+  b_sec[1] = param;\r
+  LCD_CS_ENABLE();\r
+\r
+  sspSend(0, b_sec, 2);\r
+  LCD_CS_DISABLE();\r
+\r
+  return;\r
+}\r
+\r
+void lcd_clear(uint16_t color)\r
+{\r
+  unsigned int i;\r
+\r
+  lcd_area(0, 0, (hx8347dProperties.width -1), (hx8347dProperties.height-1));\r
+\r
+  lcd_drawstart();\r
+  for(i=(hx8347dProperties.width*hx8347dProperties.height/8); i!=0; i--)\r
+  {\r
+    lcd_draw(color); //1\r
+    lcd_draw(color); //2\r
+    lcd_draw(color); //3\r
+    lcd_draw(color); //4\r
+    lcd_draw(color); //5\r
+    lcd_draw(color); //6\r
+    lcd_draw(color); //7\r
+    lcd_draw(color); //8\r
+  }\r
+  lcd_drawstop();\r
+\r
+  return;\r
+}\r
+\r
+void lcd_draw(uint16_t color)\r
+{\r
+  // Writing data in 16Bit mode for saving a lot of time\r
+  /* Move on only if NOT busy and TX FIFO not full. */\r
+  while ((SSP_SSP0SR & (SSP_SSP0SR_TNF_NOTFULL | SSP_SSP0SR_BSY_BUSY)) != SSP_SSP0SR_TNF_NOTFULL);\r
+  SSP_SSP0DR = color;\r
+\r
+  while ( (SSP_SSP0SR & (SSP_SSP0SR_BSY_BUSY|SSP_SSP0SR_RNE_NOTEMPTY)) != SSP_SSP0SR_RNE_NOTEMPTY );\r
+  /* Whenever a byte is written, MISO FIFO counter increments, Clear FIFO\r
+  on MISO. Otherwise, when SSP0Receive() is called, previous data byte\r
+  is left in the FIFO. */\r
+  uint8_t Dummy = SSP_SSP0DR;\r
+  return;\r
+}\r
+\r
+void lcd_drawstop(void)\r
+{\r
+  while ((SSP_SSP0SR &  SSP_SSP0SR_TFE_MASK ) != SSP_SSP0SR_TFE_EMPTY );\r
+  LCD_CS_DISABLE();\r
+\r
+  // init 8Bit SPI Mode\r
+  SSP_SSP0CR0 &= ~SSP_SSP0CR0_DSS_MASK;\r
+  SSP_SSP0CR0 |= SSP_SSP0CR0_DSS_8BIT;\r
+\r
+  return;\r
+}\r
+\r
+void lcd_drawstart(void)\r
+{\r
+  LCD_CS_ENABLE();\r
+  uint8_t b_first[2];\r
+  uint8_t b_sec[1];\r
+  b_first[0] = LCD_REGISTER;\r
+  b_first[1] = 0x22;\r
+  sspSend(0, b_first, 2);\r
+  LCD_CS_DISABLE();\r
+\r
+  LCD_CS_ENABLE();\r
+  b_sec[0] = LCD_DATA;\r
+  sspSend(0, b_sec, 1);\r
+\r
+\r
+  // Assign config values to SSP0CR0\r
+  // init 16Bit SPI Mode for fast data transmitting\r
+  SSP_SSP0CR0 &= ~SSP_SSP0CR0_DSS_MASK;\r
+  SSP_SSP0CR0 |= SSP_SSP0CR0_DSS_16BIT;\r
+\r
+  return;\r
+}\r
+\r
+void lcd_area(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)\r
+{\r
+  if(hx8347dPOrientation == LCD_ORIENTATION_PORTRAIT)\r
+  {\r
+    y0 = ((320-offset)+ y0) % 320;\r
+    y1 = ((320-offset)+ y1) % 320;\r
+  }\r
+  else\r
+  {\r
+    x0 = ((320-offset)+ x0) % 320;\r
+    x1 = ((320-offset)+ x1) % 320;             \r
+  }\r
+  lcd_cmd(Column_Address_Start_1, (x0>>0)); //set x0\r
+  lcd_cmd(Column_Address_Start_2, (x0>>8)); //set x0\r
+  lcd_cmd(Column_Address_End_1  , (x1>>0)); //set x1\r
+  lcd_cmd(Column_Address_End_2  , (x1>>8)); //set x1\r
+  lcd_cmd(Row_Address_Start_1   , (y0>>0)); //set y0\r
+  lcd_cmd(Row_Address_Start_2   , (y0>>8)); //set y0\r
+  lcd_cmd(Row_Address_End_1     , (y1>>0)); //set y1\r
+  lcd_cmd(Row_Address_End_2     , (y1>>8)); //set y1\r
+\r
+  return;\r
+}\r
+\r
+void lcd_cursor(uint16_t x, uint16_t y)\r
+{\r
+  lcd_area(x, y, x, y);\r
+  return;\r
+}\r
+\r
+void lcd_data(uint16_t c)\r
+{\r
+  LCD_CS_ENABLE();\r
+  uint8_t b[3];\r
+  b[0] = LCD_DATA;\r
+  b[1] = c>>8;\r
+  b[2] = c;\r
+  sspSend(0, b, 3);\r
+\r
+  LCD_CS_DISABLE();\r
+\r
+  return;\r
+}\r
+\r
+void fillRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)\r
+{\r
+  uint32_t size;\r
+  uint16_t tmp, i;\r
+\r
+  if(x0 > x1)\r
+  {\r
+    tmp = x0;\r
+    x0  = x1;\r
+    x1  = tmp;\r
+  }\r
+  if(y0 > y1)\r
+  {\r
+    tmp = y0;\r
+    y0  = y1;\r
+    y1  = tmp;\r
+  }\r
+\r
+  if(x1 >= hx8347dProperties.width)\r
+  {\r
+    x1 = hx8347dProperties.width-1;\r
+  }\r
+  if(y1 >=  hx8347dProperties.height)\r
+  {\r
+    y1 =  hx8347dProperties.height-1;\r
+  }\r
+\r
+  lcd_area(x0, y0, x1, y1);\r
+\r
+  lcd_drawstart();\r
+  size = (uint32_t)(1+(x1-x0)) * (uint32_t)(1+(y1-y0));\r
+  tmp  = size/8;\r
+  if(tmp != 0)\r
+  {\r
+    for(i=tmp; i!=0; i--)\r
+    {\r
+       lcd_draw(color); //1\r
+       lcd_draw(color); //2\r
+       lcd_draw(color); //3\r
+       lcd_draw(color); //4\r
+       lcd_draw(color); //5\r
+       lcd_draw(color); //6\r
+       lcd_draw(color); //7\r
+       lcd_draw(color); //8\r
+    }\r
+    for(i=size-tmp; i!=0; i--)\r
+    {\r
+       lcd_draw(color);\r
+    }\r
+  }\r
+  else\r
+  {\r
+    for(i=size; i!=0; i--)\r
+    {\r
+       lcd_draw(color);\r
+    }\r
+  }\r
+  lcd_drawstop();\r
+\r
+  return;\r
+}\r
+\r
+/*************************************************/\r
+/* Public Methods                                */\r
+/*************************************************/\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Configures any pins or HW and initialises the LCD controller\r
+*/\r
+/**************************************************************************/\r
+void lcdInit(void)\r
+{\r
+  sspInit(0,0,0);\r
+\r
+  gpioSetDir(2, LCD_CS, gpioDirection_Output);\r
+  gpioSetDir(2, LCD_RST, gpioDirection_Output);\r
+  gpioSetDir(2, LCD_BACK_LIGHT, gpioDirection_Output);\r
+\r
+  //reset\r
+  LCD_CS_DISABLE();\r
+  systickDelay(1);\r
+  LCD_RST_ENABLE();\r
+  systickDelay(50);\r
+  LCD_RST_DISABLE();\r
+  systickDelay(50);\r
+\r
+  //driving ability\r
+  lcd_cmd(Power_Control_Internal_1 , 0x0000);\r
+  lcd_cmd(Power_Control_Internal_2 , 0x0020);\r
+  lcd_cmd(Source_Control_Internal_1, 0x000C);\r
+  lcd_cmd(Source_Control_Internal_2, 0x00C4);\r
+  lcd_cmd(Source_OP_Control_Normal , 0x0040);\r
+  lcd_cmd(Source_OP_Control_IDLE   , 0x0038);\r
+  lcd_cmd(0xF1, 0x0001);\r
+  lcd_cmd(0xF2, 0x0010);\r
+  lcd_cmd(0x27, 0x00A3);\r
+\r
+  //power voltage\r
+  lcd_cmd(Power_Control_2, 0x001B);\r
+  lcd_cmd(Power_Control_1, 0x0001);\r
+  lcd_cmd(VCOM_Control_2 , 0x002F);\r
+  lcd_cmd(VCOM_Control_3 , 0x0057);\r
+\r
+  //VCOM offset\r
+  lcd_cmd(VCOM_Control_1, 0x008D); //for flicker adjust\r
+\r
+  //power on\r
+  lcd_cmd(OSC_Control_1       , 0x0036);\r
+  lcd_cmd(OSC_Control_2       , 0x0001);        //start osc\r
+  lcd_cmd(Display_Mode_Control, 0x0000); //wakeup\r
+  lcd_cmd(Power_Control_6     , 0x0088);\r
+  systickDelay(5);\r
+  lcd_cmd(Power_Control_6, 0x0080);\r
+  systickDelay(5);\r
+  lcd_cmd(Power_Control_6, 0x0090);\r
+  systickDelay(5);\r
+  lcd_cmd(Power_Control_6, 0x00D0);\r
+  systickDelay(5);\r
+\r
+  //color selection\r
+  lcd_cmd(COLMOD, 0x0005); //0x0005=65k, 0x0006=262k\r
+\r
+  //panel characteristic\r
+  lcd_cmd(0x36, 0x0000);\r
+\r
+  //display on\r
+  lcd_cmd(0x28, 0x0038);\r
+  systickDelay(40);\r
+  lcd_cmd(0x28, 0x003C);\r
+\r
+  lcdSetOrientation(hx8347dPOrientation);\r
+  offset = 0;\r
+  return;\r
+}\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Enables or disables the LCD backlight\r
+*/\r
+/**************************************************************************/\r
+void lcdBacklight(bool state)\r
+{\r
+  gpioSetValue(2, LCD_BACK_LIGHT, state);\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Renders a simple test pattern on the LCD\r
+*/\r
+/**************************************************************************/\r
+void lcdTest(void)\r
+{\r
+  lcdFillRGB(COLOR_CYAN);\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Fills the LCD with the specified 16-bit color\r
+*/\r
+/**************************************************************************/\r
+void lcdFillRGB(uint16_t data)\r
+{\r
+  lcd_clear(data);\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Draws a single pixel at the specified X/Y location\r
+*/\r
+/**************************************************************************/\r
+void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color)\r
+{\r
+  if((x >= hx8347dProperties.width) ||\r
+     (y >= hx8347dProperties.height))\r
+  {\r
+    return;\r
+  }\r
+\r
+  fillRect(x,y,x,y,color);\r
+\r
+  return;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Draws an array of consecutive RGB565 pixels (much\r
+            faster than addressing each pixel individually)\r
+*/\r
+/**************************************************************************/\r
+void lcdDrawPixels(uint16_t x, uint16_t y, uint16_t *data, uint32_t len)\r
+{\r
+  lcd_area(x, y, x + len, y);\r
+  int i;\r
+  lcd_drawstart();\r
+  for(i = 0; i < len; i++)\r
+  {\r
+    lcd_draw(*data);\r
+    data++;\r
+  }\r
+  lcd_drawstop();\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Optimised routine to draw a horizontal line faster than\r
+            setting individual pixels\r
+*/\r
+/**************************************************************************/\r
+void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color)\r
+{\r
+  if (x1 < x0)\r
+  {\r
+    // Switch x1 and x0\r
+    uint16_t x;\r
+    x = x1;\r
+    x1 = x0;\r
+    x0 = x;\r
+  }\r
+\r
+  if(x0 >= hx8347dProperties.width)\r
+  {\r
+    x0 = hx8347dProperties.width-1;\r
+  }\r
+  if(x1 >= hx8347dProperties.width)\r
+  {\r
+    x1 = hx8347dProperties.width-1;\r
+  }\r
+  if(y >= hx8347dProperties.height)\r
+  {\r
+    y = hx8347dProperties.height-1;\r
+  }\r
+\r
+  fillRect(x0, y, x1, y, color);\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Optimised routine to draw a vertical line faster than\r
+            setting individual pixels\r
+*/\r
+/**************************************************************************/\r
+void lcdDrawVLine(uint16_t x, uint16_t y0, uint16_t y1, uint16_t color)\r
+{\r
+  if (y1 < y0)\r
+  {\r
+    // Switch y1 and y0\r
+    uint16_t y;\r
+    y = y1;\r
+    y1 = y0;\r
+    y0 = y;\r
+  }\r
+\r
+  if(x >= hx8347dProperties.width)\r
+  {\r
+    x = hx8347dProperties.width-1;\r
+  }\r
+\r
+  if(y0 >= hx8347dProperties.height)\r
+  {\r
+    y0 = hx8347dProperties.height-1;\r
+  }\r
+  if(y1 >= hx8347dProperties.height)\r
+  {\r
+    y1 = hx8347dProperties.height-1;\r
+  }\r
+\r
+  fillRect(x, y0, x, y1, color);\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Gets the 16-bit color of the pixel at the specified location\r
+*/\r
+/**************************************************************************/\r
+uint16_t lcdGetPixel(uint16_t x, uint16_t y)\r
+{\r
+  return 0;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Sets the LCD orientation to horizontal and vertical\r
+*/\r
+/**************************************************************************/\r
+void  lcdSetOrientation(lcdOrientation_t orientation)\r
+{\r
+  if(orientation == LCD_ORIENTATION_LANDSCAPE)\r
+  {\r
+    lcd_cmd(0x16, 0x00A8); //MY=1 MX=0 MV=1 ML=0 BGR=1\r
+    hx8347dProperties.width  = 320;\r
+    hx8347dProperties.height = 240;\r
+  }\r
+  else\r
+  {\r
+    //lcd_cmd(0x16, 0x0008); //MY=0 MX=0 MV=0 ML=0 BGR=1\r
+    lcd_cmd(0x16, 0x00C8); //MY=1 MX=0 MV=1 ML=0 BGR=1\r
+    hx8347dProperties.width  = 240;\r
+    hx8347dProperties.height = 320;\r
+  }\r
+  hx8347dPOrientation = orientation;\r
+  lcd_area(0, 0, (hx8347dProperties.width-1), (hx8347dProperties.height-1));\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Gets the current screen orientation (horizontal or vertical)\r
+*/\r
+/**************************************************************************/\r
+lcdOrientation_t lcdGetOrientation(void)\r
+{\r
+  return hx8347dPOrientation;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Gets the width in pixels of the LCD screen (varies depending\r
+            on the current screen orientation)\r
+*/\r
+/**************************************************************************/\r
+uint16_t lcdGetWidth(void)\r
+{\r
+  return hx8347dProperties.width;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Gets the height in pixels of the LCD screen (varies depending\r
+            on the current screen orientation)\r
+*/\r
+/**************************************************************************/\r
+uint16_t lcdGetHeight(void)\r
+{\r
+  return hx8347dProperties.height;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Scrolls the contents of the LCD screen vertically the\r
+            specified number of pixels using a HW optimised routine\r
+*/\r
+/**************************************************************************/\r
+\r
+void lcdScroll(int16_t pixels, uint16_t fillColor)\r
+{\r
+  hx8347d_Scroll(0,320,0,(offset + pixels) % 320);\r
+  if(hx8347dPOrientation == LCD_ORIENTATION_PORTRAIT)\r
+  {\r
+    fillRect(0, hx8347dProperties.height-pixels, hx8347dProperties.width, hx8347dProperties.height, fillColor);\r
+  }\r
+  else\r
+  {\r
+    fillRect(hx8347dProperties.width-pixels, 0, hx8347dProperties.width, hx8347dProperties.height, fillColor);\r
+  }\r
+  offset = (offset + pixels) % 320;\r
+}\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Set LCD into standby\r
+            In deep standby: LCD has lower power consumption\r
+*/\r
+/**************************************************************************/\r
+void hx8347d_Standby(bool deep)\r
+{\r
+  displayOffFlow();\r
+  lcd_cmd(Power_Control_6     , Power_Control_6_STB);\r
+  if(deep)\r
+  {\r
+    lcd_cmd(Display_Mode_Control,Display_Mode_Control_DP_STB_S);\r
+    lcd_cmd(Display_Mode_Control, Display_Mode_Control_DP_STB);\r
+  }\r
+  lcd_cmd(OSC_Control_2, ~OSC_Control_2_OSC_EN);\r
+}\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Wakeup  LCD from standby\r
+            Wakeup from deep standby you need min. 20ms\r
+*/\r
+/**************************************************************************/\r
+void hx8347d_Wakeup(bool deep)\r
+{\r
+  lcd_cmd(OSC_Control_2, OSC_Control_2_OSC_EN);\r
+\r
+  if(deep)\r
+  {\r
+    lcd_cmd(Display_Mode_Control,0x0000);\r
+    systickDelay(20);\r
+    lcd_cmd(Display_Mode_Control, 0x0000);\r
+  }\r
+  else\r
+  {\r
+    systickDelay(5);\r
+  }\r
+\r
+  lcd_cmd(Power_Control_6, 0x00D0);\r
+  displayOnFlow();\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Gets the controller's 16-bit (4 hexdigit) ID\r
+*/\r
+/**************************************************************************/\r
+uint16_t lcdGetControllerID(void)\r
+{\r
+  return 0x0;\r
+}\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Returns the LCDs 'lcdProperties_t' that describes the LCDs\r
+            generic capabilities and dimensions\r
+*/\r
+/**************************************************************************/\r
+lcdProperties_t lcdGetProperties(void)\r
+{\r
+  return hx8347dProperties;\r
+}\r
+\r
diff --git a/drivers/displays/tft/hw/hx8347d.h b/drivers/displays/tft/hw/hx8347d.h
new file mode 100644 (file)
index 0000000..e86a984
--- /dev/null
@@ -0,0 +1,86 @@
+/**************************************************************************/\r
+/*!\r
+    @file     hx8347d.h\r
+    @author   Tauon {TauonTeilchen} Jabber ID Tauon[at]jabber.ccc.de\r
+\r
+    @section  LICENSE\r
+\r
+    Software License Agreement (BSD License)\r
+\r
+    Copyright (c) 2012, TauonTeilchen \r
+    ----------------------------------------------------------------------------\r
+    "THE BEER-WARE LICENSE" (Revision 42):\r
+    JID: <Tauon@jabber.ccc.de> wrote this file. As long as you retain this notice you\r
+    can do whatever you want with this stuff. If we meet some day, and you think\r
+    this stuff is worth it, you can buy me a ClubMate in return Tauon\r
+    ----------------------------------------------------------------------------\r
+    ----------------------------------------------------------------------------\r
+     "THE ClubMate-WARE LICENSE" (Revision 42):\r
+     JID: <Tauon@jabber.ccc.de> schrieb diese Datei. Solange Sie diesen Vermerk nicht entfernen, koennen\r
+     Sie mit dem Material machen, was Sie möechten. Wenn wir uns eines Tages treffen und Sie\r
+     denken, das Material ist es wert, koennen Sie mir dafuer ein ClubMate ausgeben. Tauon\r
+    ----------------------------------------------------------------------------\r
+*/\r
+/**************************************************************************/\r
+\r
+/**************************************************************************/\r
+// LCD BACK_LIGHT       Pin 6 of Port 2\r
+// LCD CS               Pin 5 of Port 2\r
+// LCD RESET            Pin 4 of Port 2\r
+// More infos           https://github.com/watterott/MI0283QT-Adapter/raw/master/img/connecting-uno.jpg\r
+//\r
+/**************************************************************************/\r
+#include "core/systick/systick.h"\r
+#include "drivers/displays/tft/touchscreen.h"\r
+#include "core/ssp/ssp.h"\r
+#include "projectconfig.h"\r
+#include "drivers/displays/tft/lcd.h"\r
+\r
+\r
+\r
+// Screen width, height, has touchscreen, support orientation changes, support hw scrolling\r
+static lcdOrientation_t hx8347dPOrientation = LCD_ORIENTATION_LANDSCAPE;\r
+\r
+// Screen width, height, has touchscreen, support orientation changes, support hw scrolling\r
+static lcdProperties_t hx8347dProperties = { 320, 240, false, true, true };\r
+\r
+/*************************************************/\r
+/* Private Methods                               */\r
+/*************************************************/\r
+\r
+\r
+/*************************************************/\r
+/* Public Methods                                */\r
+/*************************************************/\r
+\r
+// The following functions add need to be written to match the generic\r
+// lcd interface defined by lcd.h\r
+\r
+/**************************************************************************/\r
+/*!\r
+    @brief  Configures any pins or HW and initialises the LCD controller\r
+*/\r
+/**************************************************************************/\r
+\r
+void lcdInit(void);\r
+void lcdBacklight(bool state);\r
+void lcdTest(void);\r
+void lcdFillRGB(uint16_t data);\r
+void lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color);\r
+void lcdDrawPixels(uint16_t x, uint16_t y, uint16_t *data, uint32_t len);\r
+void lcdDrawHLine(uint16_t x0, uint16_t x1, uint16_t y, uint16_t color);\r
+void lcdDrawVLine(uint16_t x, uint16_t y0, uint16_t y1, uint16_t color);\r
+uint16_t lcdGetPixel(uint16_t x, uint16_t y);\r
+void lcdSetOrientation(lcdOrientation_t orientation);\r
+lcdOrientation_t lcdGetOrientation(void);\r
+uint16_t lcdGetWidth(void);\r
+uint16_t lcdGetHeight(void);\r
+void lcdScroll(int16_t pixels, uint16_t fillColor);\r
+uint16_t lcdGetControllerID(void);\r
+lcdProperties_t lcdGetProperties(void);\r
+\r
+void hx8347d_Scroll(uint16_t tfa,uint16_t vsa,uint16_t bfa, uint16_t vsp);\r
+void hx8347d_Standby(bool deep);\r
+void hx8347d_Wakeup(bool deep);\r
+\r
+\r
index 9635fc6..e8c0cd9 100644 (file)
@@ -2,6 +2,8 @@ HW-Specific TFT and RGB OLED Drivers
 ====================================
 
 hx8340b   - 176x220 16-bit display (Bit-banged SPI interface)
+hx8347g   - 240x320 16-bit display (8-bit interface)
+hx8347h   - 240x320 16-bit display (Hardware SPI via SSP0)
 ILI9325   - 240x320 16-bit display  (8-bit interface)
 ILI9328   - 240x320 16-bit display  (8-bit interface)
 st7735    - 128x160 16-bit display  (Bit-banged SPI interface)
diff --git a/drivers/sensors/ina219/ina219.c b/drivers/sensors/ina219/ina219.c
new file mode 100644 (file)
index 0000000..9bdc5dd
--- /dev/null
@@ -0,0 +1,569 @@
+/**************************************************************************/
+/*! 
+    @file     ina219.c
+    @author   K. Townsend (microBuilder.eu)
+       
+    @brief    Driver for the TI INA219 current/power monitor
+
+    @section DESCRIPTION
+
+    The INA219 is an I2C-based current/power monitor that monitors the
+       voltage drop across a shunt resistor, as well as the supply voltage.
+
+    @section EXAMPLE
+    @code
+    ina219Init();
+
+    int16_t current = 0;
+    int16_t power = 0;
+    int16_t current_mA = 0;
+    int16_t power_mW = 0;
+    int16_t busvoltage = 0;
+    int16_t shuntvoltage = 0;
+    int16_t loadVoltage = 0;
+
+    while(1)
+    {
+      shuntvoltage  = ina219GetShuntVoltage();
+      busvoltage    = ina219GetBusVoltage();
+      power         = ina219GetPower();
+      current       = ina219GetCurrent();
+      power_mW      = ina219GetPower_mW();
+      current_mA    = ina219GetCurrent_mA();
+      loadVoltage   = busvoltage + (shuntvoltage / 100);
+      printf("%-15s %6d = %d.%dmV (%duV) \r\n", "Shunt Voltage:", shuntvoltage, shuntvoltage / 100, shuntvoltage % 100, shuntvoltage * 10);
+      printf("%-15s %6d = %d.%dV \r\n",         "Bus Voltage:",   busvoltage, busvoltage / 1000, busvoltage % 1000);
+      printf("%-15s %6d = %d.%dV \r\n",         "Load Voltage:",  loadVoltage, loadVoltage / 1000, loadVoltage % 1000);
+      printf("%-15s %6d = %dmW \r\n",           "Power:",         power, power_mW);
+      printf("%-15s %6d = %dmA \r\n",           "Current:",       current, current_mA);
+      printf("\r\n");
+      systickDelay(5000);
+    }
+    @endcode
+
+    @section LICENSE
+
+    Software License Agreement (BSD License)
+
+    Copyright (c) 2012 Kevin Townsend
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+    1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+    3. Neither the name of the copyright holders nor the
+    names of its contributors may be used to endorse or promote products
+    derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/**************************************************************************/
+#include "ina219.h"
+#include "core/systick/systick.h"
+
+extern volatile uint8_t   I2CMasterBuffer[I2C_BUFSIZE];
+extern volatile uint8_t   I2CSlaveBuffer[I2C_BUFSIZE];
+
+// The following multipliers are used to convert raw current and power
+// values to mA and mW, taking into account the current config settings
+uint32_t ina219_currentDivider_mA = 0;
+uint32_t ina219_powerDivider_mW   = 0;
+
+/**************************************************************************/
+/*! 
+    @brief  Sends a single command byte over I2C
+*/
+/**************************************************************************/
+static void ina219WriteRegister (uint8_t reg, uint16_t value)
+{
+  // Clear write buffers
+  uint32_t i;
+  for ( i = 0; i < I2C_BUFSIZE; i++ )
+  {
+    I2CMasterBuffer[i] = 0x00;
+  }
+
+  I2CWriteLength = 4;
+  I2CReadLength = 0;
+  I2CMasterBuffer[0] = INA219_ADDRESS;        // I2C device address
+  I2CMasterBuffer[1] = reg;                   // Register
+  I2CMasterBuffer[2] = value >> 8;            // Upper 8-bits
+  I2CMasterBuffer[3] = value & 0xFF;          // Lower 8-bits
+  i2cEngine();
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Reads a 16 bit values over I2C
+*/
+/**************************************************************************/
+static void ina219Read16(uint8_t reg, uint16_t *value)
+{
+  // Clear write buffers
+  uint32_t i;
+  for ( i = 0; i < I2C_BUFSIZE; i++ )
+  {
+    I2CMasterBuffer[i] = 0x00;
+  }
+
+  I2CWriteLength = 2;
+  I2CReadLength = 2;
+  I2CMasterBuffer[0] = INA219_ADDRESS;            // I2C device address
+  I2CMasterBuffer[1] = reg;                       // Command register
+  // Append address w/read bit
+  I2CMasterBuffer[2] = INA219_ADDRESS | INA219_READ;  
+  i2cEngine();
+
+  // Shift values to create properly formed integer
+  *value = ((I2CSlaveBuffer[0] << 8) | I2CSlaveBuffer[1]);
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Configures to INA219 to be able to measure up to 32V and 2A
+            of current.  Each unit of current corresponds to 100uA, and
+            each unit of power corresponds to 2mW. Counter overflow
+            occurs at 3.2A.
+                       
+    @note   These calculations assume a 0.1 ohm resistor is present
+*/
+/**************************************************************************/
+void ina219SetCalibration_32V_2A(void)
+{
+  // By default we use a pretty huge range for the input voltage,
+  // which probably isn't the most appropriate choice for system
+  // that don't use a lot of power.  But all of the calculations
+  // are shown below if you want to change the settings.  You will
+  // also need to change any relevant register settings, such as
+  // setting the VBUS_MAX to 16V instead of 32V, etc.
+
+  // VBUS_MAX = 32V             (Assumes 32V, can also be set to 16V)
+  // VSHUNT_MAX = 0.32          (Assumes Gain 8, 320mV, can also be 0.16, 0.08, 0.04)
+  // RSHUNT = 0.1               (Resistor value in ohms)
+  
+  // 1. Determine max possible current
+  // MaxPossible_I = VSHUNT_MAX / RSHUNT
+  // MaxPossible_I = 3.2A
+  
+  // 2. Determine max expected current
+  // MaxExpected_I = 2.0A
+  
+  // 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
+  // MinimumLSB = MaxExpected_I/32767
+  // MinimumLSB = 0.000061              (61µA per bit)
+  // MaximumLSB = MaxExpected_I/4096
+  // MaximumLSB = 0,000488              (488µA per bit)
+  
+  // 4. Choose an LSB between the min and max values
+  //    (Preferrably a roundish number close to MinLSB)
+  // CurrentLSB = 0.0001 (100µA per bit)
+  
+  // 5. Compute the calibration register
+  // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
+  // Cal = 4096 (0x1000)
+  
+  // 6. Calculate the power LSB
+  // PowerLSB = 20 * CurrentLSB
+  // PowerLSB = 0.002 (2mW per bit)
+  
+  // 7. Compute the maximum current and shunt voltage values before overflow
+  //
+  // Max_Current = Current_LSB * 32767
+  // Max_Current = 3.2767A before overflow
+  //
+  // If Max_Current > Max_Possible_I then
+  //    Max_Current_Before_Overflow = MaxPossible_I
+  // Else
+  //    Max_Current_Before_Overflow = Max_Current
+  // End If
+  //
+  // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
+  // Max_ShuntVoltage = 0.32V
+  //
+  // If Max_ShuntVoltage >= VSHUNT_MAX
+  //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
+  // Else
+  //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
+  // End If
+  
+  // 8. Computer the Maximum Power
+  // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
+  // MaximumPower = 3.2 * 32V
+  // MaximumPower = 102.4W
+  
+  // Set multipliers to convert raw current/power values
+  ina219_currentDivider_mA = 10;  // Current LSB = 100uA per bit (1000/100 = 10)
+  ina219_powerDivider_mW = 2;     // Power LSB = 1mW per bit (2/1)
+
+  // Set Calibration register to 'Cal' calculated above        
+  ina219WriteRegister(INA219_REG_CALIBRATION, 0x1000);
+
+  // Set Config register to take into account the settings above
+  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
+                    INA219_CONFIG_GAIN_8_320MV |
+                    INA219_CONFIG_BADCRES_12BIT |
+                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
+                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
+  ina219WriteRegister(INA219_REG_CONFIG, config);
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Configures to INA219 to be able to measure up to 32V and 1A
+            of current.  Each unit of current corresponds to 40uA, and each
+            unit of power corresponds to 800µW. Counter overflow occurs at
+            1.3A.
+                       
+    @note   These calculations assume a 0.1 ohm resistor is present
+*/
+/**************************************************************************/
+void ina219SetCalibration_32V_1A(void)
+{
+  // By default we use a pretty huge range for the input voltage,
+  // which probably isn't the most appropriate choice for system
+  // that don't use a lot of power.  But all of the calculations
+  // are shown below if you want to change the settings.  You will
+  // also need to change any relevant register settings, such as
+  // setting the VBUS_MAX to 16V instead of 32V, etc.
+
+  // VBUS_MAX = 32V            (Assumes 32V, can also be set to 16V)
+  // VSHUNT_MAX = 0.32 (Assumes Gain 8, 320mV, can also be 0.16, 0.08, 0.04)
+  // RSHUNT = 0.1                      (Resistor value in ohms)
+
+  // 1. Determine max possible current
+  // MaxPossible_I = VSHUNT_MAX / RSHUNT
+  // MaxPossible_I = 3.2A
+
+  // 2. Determine max expected current
+  // MaxExpected_I = 1.0A
+
+  // 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
+  // MinimumLSB = MaxExpected_I/32767
+  // MinimumLSB = 0.0000305             (30.5µA per bit)
+  // MaximumLSB = MaxExpected_I/4096
+  // MaximumLSB = 0.000244              (244µA per bit)
+
+  // 4. Choose an LSB between the min and max values
+  //    (Preferrably a roundish number close to MinLSB)
+  // CurrentLSB = 0.0000400 (40µA per bit)
+
+  // 5. Compute the calibration register
+  // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
+  // Cal = 10240 (0x2800)
+
+  // 6. Calculate the power LSB
+  // PowerLSB = 20 * CurrentLSB
+  // PowerLSB = 0.0008 (800µW per bit)
+
+  // 7. Compute the maximum current and shunt voltage values before overflow
+  //
+  // Max_Current = Current_LSB * 32767
+  // Max_Current = 1.31068A before overflow
+  //
+  // If Max_Current > Max_Possible_I then
+  //    Max_Current_Before_Overflow = MaxPossible_I
+  // Else
+  //    Max_Current_Before_Overflow = Max_Current
+  // End If
+  //
+  // ... In this case, we're good though since Max_Current is less than MaxPossible_I
+  //
+  // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
+  // Max_ShuntVoltage = 0.131068V
+  //
+  // If Max_ShuntVoltage >= VSHUNT_MAX
+  //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
+  // Else
+  //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
+  // End If
+
+  // 8. Computer the Maximum Power
+  // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
+  // MaximumPower = 1.31068 * 32V
+  // MaximumPower = 41.94176W
+
+  // Set multipliers to convert raw current/power values
+  ina219_currentDivider_mA = 25;      // Current LSB = 40uA per bit (1000/40 = 25)
+  ina219_powerDivider_mW = 1;         // Power LSB = 800µW per bit
+
+  // Set Calibration register to 'Cal' calculated above        
+  ina219WriteRegister(INA219_REG_CALIBRATION, 0x2800);
+
+  // Set Config register to take into account the settings above
+  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
+                    INA219_CONFIG_GAIN_8_320MV |
+                    INA219_CONFIG_BADCRES_12BIT |
+                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
+                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
+  ina219WriteRegister(INA219_REG_CONFIG, config);
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Configures to INA219 to be able to measure up to 16V and 500mA
+            of current.  Each unit of current corresponds to 25uA, and each
+            unit of power corresponds to 500µW. Counter overflow occurs at
+            800mA.
+                       
+    @note   These calculations assume a 0.1 ohm resistor is present
+*/
+/**************************************************************************/
+void ina219SetCalibration_16V_500mA(void)
+{
+  // VBUS_MAX = 16V
+  // VSHUNT_MAX = 0.08 (Assumes Gain 2, 80mV, can also be 0.32, 0.16, 0.04)
+  // RSHUNT = 0.1                      (Resistor value in ohms)
+
+  // 1. Determine max possible current
+  // MaxPossible_I = VSHUNT_MAX / RSHUNT
+  // MaxPossible_I = 0.8A
+
+  // 2. Determine max expected current
+  // MaxExpected_I = 0.5A
+
+  // 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
+  // MinimumLSB = MaxExpected_I/32767
+  // MinimumLSB = 0.0000153             (15.3µA per bit)
+  // MaximumLSB = MaxExpected_I/4096
+  // MaximumLSB = 0.0001221             (122µA per bit)
+
+  // 4. Choose an LSB between the min and max values
+  //    (Preferrably a roundish number close to MinLSB)
+  // CurrentLSB = 0.0000250 (25µA per bit)
+
+  // 5. Compute the calibration register
+  // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
+  // Cal = 16384 (0x4000)
+
+  // 6. Calculate the power LSB
+  // PowerLSB = 20 * CurrentLSB
+  // PowerLSB = 0.0005 (500µW per bit)
+
+  // 7. Compute the maximum current and shunt voltage values before overflow
+  //
+  // Max_Current = Current_LSB * 32767
+  // Max_Current = 0.819175 (819 mA before overflow)
+  //
+  // If Max_Current > Max_Possible_I then
+  //    Max_Current_Before_Overflow = MaxPossible_I
+  // Else
+  //    Max_Current_Before_Overflow = Max_Current
+  // End If
+  //
+  // Max_Current_Before_Overflow = 0.8A
+  //
+  // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
+  // Max_ShuntVoltage = 0.8 * 0.1
+  // Max_ShuntVoltage = 0.08V
+  //
+  // If Max_ShuntVoltage >= VSHUNT_MAX
+  //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
+  // Else
+  //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
+  // End If
+
+  // 8. Computer the Maximum Power
+  // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
+  // MaximumPower = 0.8 * 16V
+  // MaximumPower = 12.8W
+
+  // Set multipliers to convert raw current/power values
+  ina219_currentDivider_mA = 40;    // Current LSB = 25uA per bit (1000/25 = 40)
+  ina219_powerDivider_mW =    1;    // Power LSB = 500µW per bit
+
+  // Set Calibration register to 'Cal' calculated above        
+  ina219WriteRegister(INA219_REG_CALIBRATION, 0x4000);
+
+  // Set Config register to take into account the settings above
+  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_16V |
+                    INA219_CONFIG_GAIN_2_80MV |
+                    INA219_CONFIG_BADCRES_12BIT |
+                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
+                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
+  ina219WriteRegister(INA219_REG_CONFIG, config);
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Configures to INA219 to be able to measure up to 16V and 200mA
+            of current.  Each unit of current corresponds to 10uA, and each
+            unit of power corresponds to 200µW. Counter overflow occurs at
+            327mA.
+                       
+    @note   These calculations assume a 0.1 ohm resistor is present
+*/
+/**************************************************************************/
+void ina219SetCalibration_16V_200mA(void)
+{
+  // VBUS_MAX = 16V
+  // VSHUNT_MAX = 0.04 (Assumes Gain 1, 40mV, can also be 0.32, 0.16, 0.08)
+  // RSHUNT = 0.1                      (Resistor value in ohms)
+
+  // 1. Determine max possible current
+  // MaxPossible_I = VSHUNT_MAX / RSHUNT
+  // MaxPossible_I = 0.4A
+
+  // 2. Determine max expected current
+  // MaxExpected_I = 0.2A
+
+  // 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
+  // MinimumLSB = MaxExpected_I/32767
+  // MinimumLSB = 0.000006104            (6.104µA per bit)
+  // MaximumLSB = MaxExpected_I/4096
+  // MaximumLSB = 0,000048828           (48.82µA per bit)
+
+  // 4. Choose an LSB between the min and max values
+  // CurrentLSB = 0.000010 (10µA per bit)
+
+  // 5. Compute the calibration register
+  // Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
+  // Cal = 40960 (0xA000)
+
+  // 6. Calculate the power LSB
+  // PowerLSB = 20 * CurrentLSB
+  // PowerLSB = 0.0002 (200µW per bit)
+
+  // 7. Compute the maximum current and shunt voltage values before overflow
+  //
+  // Max_Current = Current_LSB * 32767
+  // Max_Current = 0.32767 (328 mA before overflow)
+  //
+  // If Max_Current > Max_Possible_I then
+  //    Max_Current_Before_Overflow = MaxPossible_I
+  // Else
+  //    Max_Current_Before_Overflow = Max_Current
+  // End If
+  //
+  // Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
+  // Max_ShuntVoltage = 0.032767V
+  //
+  // If Max_ShuntVoltage >= VSHUNT_MAX
+  //    Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
+  // Else
+  //    Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
+  // End If
+
+  // 8. Computer the Maximum Power
+  // MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
+  // MaximumPower = 0.32767 * 16V
+  // MaximumPower = 5.24W
+
+  // Set multipliers to convert raw current/power values
+  ina219_currentDivider_mA = 100;      // Current LSB = 10uA per bit (1000/10 = 100)
+  ina219_powerDivider_mW =     1;      // Power LSB = 200µW per bit
+
+  // Set Calibration register to 'Cal' calculated above        
+  ina219WriteRegister(INA219_REG_CALIBRATION, 0xA000);
+
+  // Set Config register to take into account the settings above
+  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_16V |
+                    INA219_CONFIG_GAIN_1_40MV |
+                    INA219_CONFIG_BADCRES_12BIT |
+                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
+                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
+  ina219WriteRegister(INA219_REG_CONFIG, config);
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Initialises the I2C block
+*/
+/**************************************************************************/
+void ina219Init(void)
+{
+  // Reset INA219 (set to default values)
+  ina219WriteRegister(INA219_REG_CONFIG, INA219_CONFIG_RESET);
+
+  // Setup chip for 32V and 2A by default
+  ina219SetCalibration_32V_2A();
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the shunt voltage (16-bit signed integer, so +-32767)
+*/
+/**************************************************************************/
+int16_t ina219GetShuntVoltage(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_SHUNTVOLTAGE, &value);
+  return value;
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the shunt voltage (16-bit signed integer, so +-32767)
+*/
+/**************************************************************************/
+int16_t ina219GetBusVoltage(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_BUSVOLTAGE, &value);
+  // Shift to the right 3 to drop CNVR and OVF and then multiply by LSB
+  return (value >> 3) * 4;
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the raw power value (16-bit signed integer, so +-32767)
+*/
+/**************************************************************************/
+int16_t ina219GetPower(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_POWER, &value);
+  return value;
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the power value in mW, taking into account the config
+            settings and power LSB
+*/
+/**************************************************************************/
+int16_t ina219GetPower_mW(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_POWER, &value);
+  return value / ina219_powerDivider_mW;
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the raw current value (16-bit signed integer, so +-32767)
+*/
+/**************************************************************************/
+int16_t ina219GetCurrent(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_CURRENT, &value);
+  return value;
+}
+
+/**************************************************************************/
+/*! 
+    @brief  Gets the current value in mA, taking into account the
+            config settings and current LSB
+*/
+/**************************************************************************/
+int16_t ina219GetCurrent_mA(void)
+{
+  uint16_t value;
+  ina219Read16(INA219_REG_CURRENT, &value);
+  return value / ina219_currentDivider_mA;
+}
+
+
diff --git a/drivers/sensors/ina219/ina219.h b/drivers/sensors/ina219/ina219.h
new file mode 100644 (file)
index 0000000..69dfdbc
--- /dev/null
@@ -0,0 +1,137 @@
+/**************************************************************************/
+/*! 
+    @file     ina219.h
+    @author   K. Townsend (microBuilder.eu)
+
+    @section LICENSE
+
+    Software License Agreement (BSD License)
+
+    Copyright (c) 2012 Kevin Townsend
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+    1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+    3. Neither the name of the copyright holders nor the
+    names of its contributors may be used to endorse or promote products
+    derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/**************************************************************************/
+
+#ifndef _INA219_H_
+#define _INS219_H_
+
+#include "projectconfig.h"
+#include "core/i2c/i2c.h"
+
+/*=========================================================================
+    I2C ADDRESS/BITS
+    -----------------------------------------------------------------------*/
+    #define INA219_ADDRESS                         (0x80)  // 1000000x (A0+A1=GND)
+    #define INA219_READ                            (0x01)
+/*=========================================================================*/
+
+/*=========================================================================
+    CONFIG REGISTER (R/W)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_CONFIG                      (0x00)
+    /*---------------------------------------------------------------------*/
+    #define INA219_CONFIG_RESET                    (0x8000)  // Reset Bit
+       
+    #define INA219_CONFIG_BVOLTAGERANGE_MASK       (0x4000)  // Bus Voltage Range Mask
+    #define INA219_CONFIG_BVOLTAGERANGE_16V        (0x0000)  // 0-16V Range
+    #define INA219_CONFIG_BVOLTAGERANGE_32V        (0x4000)  // 0-32V Range
+       
+    #define INA219_CONFIG_GAIN_MASK                (0x1800)  // Gain Mask
+    #define INA219_CONFIG_GAIN_1_40MV              (0x0000)  // Gain 1, 40mV Range
+    #define INA219_CONFIG_GAIN_2_80MV              (0x0800)  // Gain 2, 80mV Range
+    #define INA219_CONFIG_GAIN_4_160MV             (0x1000)  // Gain 4, 160mV Range
+    #define INA219_CONFIG_GAIN_8_320MV             (0x1800)  // Gain 8, 320mV Range
+       
+    #define INA219_CONFIG_BADCRES_MASK             (0x0780)  // Bus ADC Resolution Mask
+    #define INA219_CONFIG_BADCRES_9BIT             (0x0080)  // 9-bit bus res = 0..511
+    #define INA219_CONFIG_BADCRES_10BIT            (0x0100)  // 10-bit bus res = 0..1023
+    #define INA219_CONFIG_BADCRES_11BIT            (0x0200)  // 11-bit bus res = 0..2047
+    #define INA219_CONFIG_BADCRES_12BIT            (0x0400)  // 12-bit bus res = 0..4097
+    
+    #define INA219_CONFIG_SADCRES_MASK             (0x0078)  // Shunt ADC Resolution and Averaging Mask
+    #define INA219_CONFIG_SADCRES_9BIT_1S_84US     (0x0000)  // 1 x 9-bit shunt sample
+    #define INA219_CONFIG_SADCRES_10BIT_1S_148US   (0x0008)  // 1 x 10-bit shunt sample
+    #define INA219_CONFIG_SADCRES_11BIT_1S_276US   (0x0010)  // 1 x 11-bit shunt sample
+    #define INA219_CONFIG_SADCRES_12BIT_1S_532US   (0x0018)  // 1 x 12-bit shunt sample
+    #define INA219_CONFIG_SADCRES_12BIT_2S_1060US  (0x0048)     // 2 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_4S_2130US  (0x0050)  // 4 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_8S_4260US  (0x0058)  // 8 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_16S_8510US (0x0060)  // 16 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_32S_17MS   (0x0068)  // 32 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_64S_34MS   (0x0070)  // 64 x 12-bit shunt samples averaged together
+    #define INA219_CONFIG_SADCRES_12BIT_128S_69MS  (0x0078)  // 128 x 12-bit shunt samples averaged together
+       
+    #define INA219_CONFIG_MODE_MASK                (0x0007)  // Operating Mode Mask
+    #define INA219_CONFIG_MODE_POWERDOWN           (0x0000)
+    #define INA219_CONFIG_MODE_SVOLT_TRIGGERED     (0x0001)
+    #define INA219_CONFIG_MODE_BVOLT_TRIGGERED     (0x0002)
+    #define INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED (0x0003)
+    #define INA219_CONFIG_MODE_ADCOFF              (0x0004)
+    #define INA219_CONFIG_MODE_SVOLT_CONTINUOUS    (0x0005)
+    #define INA219_CONFIG_MODE_BVOLT_CONTINUOUS    (0x0006)
+    #define INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS (0x0007)   
+/*=========================================================================*/
+
+/*=========================================================================
+    SHUNT VOLTAGE REGISTER (R)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_SHUNTVOLTAGE                (0x01)
+/*=========================================================================*/
+
+/*=========================================================================
+    BUS VOLTAGE REGISTER (R)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_BUSVOLTAGE                  (0x02)
+/*=========================================================================*/
+
+/*=========================================================================
+    POWER REGISTER (R)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_POWER                       (0x03)
+/*=========================================================================*/
+
+/*=========================================================================
+    CURRENT REGISTER (R)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_CURRENT                     (0x04)
+/*=========================================================================*/
+
+/*=========================================================================
+    CALIBRATION REGISTER (R/W)
+    -----------------------------------------------------------------------*/
+    #define INA219_REG_CALIBRATION                 (0x05)
+/*=========================================================================*/
+
+void    ina219Init(void);
+int16_t ina219GetShuntVoltage(void);
+int16_t ina219GetBusVoltage(void);
+int16_t ina219GetPower(void);
+int16_t ina219GetPower_mW(void);
+int16_t ina219GetCurrent(void);
+int16_t ina219GetCurrent_mA(void);
+
+#endif
+
+
diff --git a/main.c b/main.c
index bb2c280..80c0e8e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,7 +7,7 @@
 
     Software License Agreement (BSD License)
 
-    Copyright (c) 2012, microBuilder SARL
+    Copyright (c) 2011, microBuilder SARL
     All rights reserved.
 
     Redistribution and use in source and binary forms, with or without
     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 /**************************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "projectconfig.h"
 #include "sysinit.h"
 
@@ -56,7 +60,7 @@ int main(void)
 
   uint32_t currentSecond, lastSecond;
   currentSecond = lastSecond = 0;
-
+  
   while (1)
   {
     // Toggle LED once per second
index 639503c..83d3880 100644 (file)
@@ -159,7 +159,7 @@ cmd_t cmd_tbl[] =
   #endif
 
   #ifdef CFG_PWM
-  { "M",    0,  2,  0,  cmd_pwm              , "PWM Control"                    , "'M [<dutycycle(%)>] [<frequency(ticks)>]'" },
+  { "M",    2,  2,  0,  cmd_pwm              , "PWM Control"                    , "'M [<dutycycle(%)>] [<frequency(ticks)>]'" },
   #endif
 };
 
index 505470d..3d070d5 100644 (file)
@@ -56,38 +56,29 @@ void cmd_pwm(uint8_t argc, char **argv) {
     int32_t frequencyTicks = 65535;\r
     int32_t dutyCycle = CFG_PWM_DEFAULT_DUTYCYCLE;\r
     \r
-    if(argc > 0) {\r
-        getNumber (argv[0], &dutyCycle);\r
-        if(dutyCycle < 1 || dutyCycle > 100) {\r
-            printf("Invalid duty cycle [1..65535]%s", CFG_PRINTF_NEWLINE);\r
-            return;\r
-        }\r
-\r
-        if(argc > 1) {\r
-            getNumber (argv[1], &frequencyTicks);\r
-            if(frequencyTicks < 0 || frequencyTicks > 0xffff) {\r
-                printf("Invalid frequency [1..65535]%s", CFG_PRINTF_NEWLINE);\r
-                return;\r
-            }\r
-        } else {\r
-            frequencyTicks = 65535;\r
-        }\r
-    } else {\r
-        dutyCycle = CFG_PWM_DEFAULT_DUTYCYCLE;\r
+    getNumber (argv[0], &dutyCycle);\r
+    if(dutyCycle < 1 || dutyCycle > 100) \r
+    {\r
+      printf("Invalid duty cycle [1..65535]%s", CFG_PRINTF_NEWLINE);\r
+      return;\r
     }\r
 \r
-    if(! pwmStarted) {\r
-        printf("Initializing PWM%s", CFG_PRINTF_NEWLINE);\r
-        pwmInit();\r
+    getNumber (argv[1], &frequencyTicks);\r
+    if(frequencyTicks < 0 || frequencyTicks > 0xffff) \r
+    {\r
+      printf("Invalid frequency [1..65535]%s", CFG_PRINTF_NEWLINE);\r
+      return;\r
     }\r
-    \r
+\r
     printf("Setting frequency: %u ticks%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE);\r
     pwmSetFrequencyInTicks(frequencyTicks);\r
     printf("Setting duty cycle: %u%%%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE);\r
     pwmSetDutyCycle(dutyCycle);\r
-    if(! pwmStarted) {\r
-        pwmStart();\r
-        pwmStarted = 1;\r
+    if(! pwmStarted) \r
+    {\r
+      printf("Initializing PWM%s", CFG_PRINTF_NEWLINE);\r
+      pwmStart();\r
+      pwmStarted = 1;\r
     }\r
 }\r
 #endif\r
index 1d3c92f..f9f1e3f 100644 (file)
     LM75B                       0x90      1001000x
     MCP24AA                     0xA0      1010000x
     MCP4725                     0xC0      1100000x ***
-       TEA5767                     0xC0      1100000x ***
+    TEA5767                     0xC0      1100000x ***
     TSL2561                     0x72      0111001x
     TCS3414                     0x72      0111001x
     PN532                       0x48      0100100x
     SSD1306_I2C                 0x78      0111100x  // Assumes SA0 = GND
-       INA219                      0xF0      10000000x // Assumes A0+A1 = GND
+    INA219                      0xF0      10000000x // Assumes A0+A1 = GND
 
     [1]  Alternative addresses may exists, but the addresses listed in this
          table are the values used in the code base
diff --git a/tools/testfirmware/LPC1343_LCDStandalone_UART_LF.bin b/tools/testfirmware/LPC1343_LCDStandalone_UART_LF.bin
deleted file mode 100644 (file)
index c9fda07..0000000
Binary files a/tools/testfirmware/LPC1343_LCDStandalone_UART_LF.bin and /dev/null differ
diff --git a/tools/testfirmware/LPC1343_LCDStandalone_USB_CRLF.bin b/tools/testfirmware/LPC1343_LCDStandalone_USB_CRLF.bin
deleted file mode 100644 (file)
index bc623c4..0000000
Binary files a/tools/testfirmware/LPC1343_LCDStandalone_USB_CRLF.bin and /dev/null differ
diff --git a/tools/testfirmware/blinky.bin b/tools/testfirmware/blinky.bin
deleted file mode 100644 (file)
index bacaf86..0000000
Binary files a/tools/testfirmware/blinky.bin and /dev/null differ
diff --git a/tools/testfirmware/blinky_usbcli.bin b/tools/testfirmware/blinky_usbcli.bin
new file mode 100644 (file)
index 0000000..5cd75fe
Binary files /dev/null and b/tools/testfirmware/blinky_usbcli.bin differ
diff --git a/tools/testfirmware/uartcli.bin b/tools/testfirmware/uartcli.bin
deleted file mode 100644 (file)
index 263ef63..0000000
Binary files a/tools/testfirmware/uartcli.bin and /dev/null differ
diff --git a/tools/validation/startupdelay/StartupTime_CrossworksForARM.png b/tools/validation/startupdelay/StartupTime_CrossworksForARM.png
new file mode 100644 (file)
index 0000000..9393c6e
Binary files /dev/null and b/tools/validation/startupdelay/StartupTime_CrossworksForARM.png differ
diff --git a/tools/validation/startupdelay/StartupTime_GCCMakefile.png b/tools/validation/startupdelay/StartupTime_GCCMakefile.png
new file mode 100644 (file)
index 0000000..00c4297
Binary files /dev/null and b/tools/validation/startupdelay/StartupTime_GCCMakefile.png differ
diff --git a/tools/validation/startupdelay/main.c b/tools/validation/startupdelay/main.c
new file mode 100644 (file)
index 0000000..8b49653
--- /dev/null
@@ -0,0 +1,71 @@
+/**************************************************************************/
+/*! 
+    @file     main.c
+    @author   K. Townsend (microBuilder.eu)
+
+    @section LICENSE
+
+    Software License Agreement (BSD License)
+
+    Copyright (c) 2011, microBuilder SARL
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+    1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+    3. Neither the name of the copyright holders nor the
+    names of its contributors may be used to endorse or promote products
+    derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/**************************************************************************/
+#include "projectconfig.h"
+
+#include "core/gpio/gpio.h"
+
+/**************************************************************************/
+/*! 
+    As soon as the chip comes out of reset and the startup code has
+    finished executing, sets up GPIO pin 2.1 as an ouput and high.
+
+    This can be used to determine the startup delay, by measuring the
+    time between reset be deasserted and the GPIO pin going high, minus
+    the GPIO overhead of a few clock cycles.
+
+    HW Setup: Set channel one of the oscilliscope to the reset pin, and
+              channel two of the oscilliscope to GPIO pin 2.1.
+
+              Set a trigger on the rising edge of the reset pin, and
+              measure the delay between the rising edge of reset and the
+              rising edge of GPIO 2.1.
+*/
+/**************************************************************************/
+int main(void)
+{
+  /* Enable AHB clock to the GPIO domain. */
+  SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_GPIO);
+
+  /* Set 2.1 to output and high */
+  GPIO_GPIO2DIR  |= (1 << 1);    // pin 1 = Output
+  GPIO_GPIO2DATA |= (1 << 1);    // pin 1 = High
+
+  while(1)
+  {
+  }
+
+  return 0;
+}
diff --git a/tools/validation/startupdelay/readme.txt b/tools/validation/startupdelay/readme.txt
new file mode 100644 (file)
index 0000000..923cd79
--- /dev/null
@@ -0,0 +1,16 @@
+This simple code can be used to test the startup delay, or more precisely
+the delay between the moment that reset is deasserted and code execution
+begins in main().
+
+GPIO pin 2.1 is set to output and high as soon as main is entered, so you
+simply need to monitor the reset line and GPIO 2.1 on a two-channel
+oscilliloscope, and measure the delay between the two rising edges.
+
+Two sample tests results are showing for GCC with a Makefile and with
+Crossworks for ARM.  Both examples are included since the startup code
+for both project types is slightly different, with Crossworks using a
+custom startup file provided by Rowley Associates, and the LPC1343 
+Code Base using it's own startup code when compiling with make and GCC.
+
+Note: This code is only useful for measuring the time coming out of
+reset, not from a cold boot (applying power to an unpowered device).
\ No newline at end of file
This page took 0.097721 seconds and 4 git commands to generate.