diff --git a/.gitignore b/.gitignore index 32d5a23..6e29dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ *.hex *.elf *.ld +*.i +*.s lpcrc diff --git a/Makefile b/Makefile index 34cc96c..751b017 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ 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 +OBJS += cmd_adc.o cmd_ssp.o VPATH += project/commands/drawing OBJS += cmd_backlight.o cmd_bmp.o cmd_button.o cmd_calibrate.o @@ -64,6 +65,9 @@ OBJS += eeprom.o mcp24aa.o VPATH += drivers/sensors/lm75b OBJS += lm75b.o +VPATH += drivers/sensors/ds18b20 +OBJS += ds18b20.o + # ISL12022M RTC VPATH += drivers/rtc/isl12022m OBJS += isl12022m.o diff --git a/core/ssp/ssp.c b/core/ssp/ssp.c index e1f31e2..3d1ef05 100644 --- a/core/ssp/ssp.c +++ b/core/ssp/ssp.c @@ -172,6 +172,12 @@ void sspInit (uint8_t portNum, sspClockPolarity_t polarity, sspClockPhase_t phas IOCON_PIO0_6 = IOCON_PIO0_6_FUNC_SCK; #endif + /* Set 0.6 to SSP SCK (2.11 and 0.10 can also be used) */ + #ifdef CFG_SSP0_SCKPIN_0_10 + IOCON_SCKLOC = IOCON_SCKLOC_SCKPIN_PIO0_10; + IOCON_JTAG_TCK_PIO0_10 = IOCON_JTAG_TCK_PIO0_10_FUNC_SCK; + #endif + /* Set P0.2/SSEL to GPIO output and high */ IOCON_PIO0_2 &= ~IOCON_PIO0_2_FUNC_MASK; IOCON_PIO0_2 |= IOCON_PIO0_2_FUNC_GPIO; diff --git a/drivers/sensors/ds18b20/ds18b20.c b/drivers/sensors/ds18b20/ds18b20.c index e4e4da2..e3ee53d 100644 --- a/drivers/sensors/ds18b20/ds18b20.c +++ b/drivers/sensors/ds18b20/ds18b20.c @@ -180,7 +180,7 @@ void ds18b20Init(uint32_t portNumber, uint32_t bitPosition, volatile uint32_t *i @note Reading is returned mutiplied by 10000 i.e. for 25.8750 degrees the result will be 258750 */ -uint32_t ds18b20GetTemparature(){ +uint32_t ds18b20GetTemperature(){ //Reset, skip ROM and start temperature conversion if(reset()) { printf("DS18B20 is not responding%s", CFG_PRINTF_NEWLINE); diff --git a/drivers/sensors/ds18b20/ds18b20.h b/drivers/sensors/ds18b20/ds18b20.h index 85640d4..974d51d 100644 --- a/drivers/sensors/ds18b20/ds18b20.h +++ b/drivers/sensors/ds18b20/ds18b20.h @@ -44,7 +44,7 @@ void ds18b20Init(uint32_t portNum, uint32_t bitPos, volatile uint32_t *ioconReg); -uint32_t ds18b20GetTemparature(); +uint32_t ds18b20GetTemperature(); #endif diff --git a/lpc134x.h b/lpc134x.h index 002f7cd..237b27c 100644 --- a/lpc134x.h +++ b/lpc134x.h @@ -2019,6 +2019,12 @@ static inline void NVIC_DisableIRQ(IRQn_t IRQn) NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); } +static inline void NVIC_SetIRQPriority(IRQn_t IRQn, uint8_t priority) +{ + NVIC->IP[(uint32_t)(IRQn)] = ((priority << 5) & 0xff); /* set Priority for device specific Interrupts */ +} + + /*############################################################################## ## GPIO - General Purpose I/O ##############################################################################*/ diff --git a/project/cmd_tbl.h b/project/cmd_tbl.h index 83d3880..323c3a9 100644 --- a/project/cmd_tbl.h +++ b/project/cmd_tbl.h @@ -97,6 +97,10 @@ void cmd_sd_dir(uint8_t argc, char **argv); void cmd_pwm(uint8_t argc, char **argv); #endif +void cmd_adc_read(uint8_t argc, char **argv); + +void cmd_ssp_write(uint8_t argc, char **argv); + #define CMD_NOPARAMS "This command has no parameters" /**************************************************************************/ @@ -114,7 +118,7 @@ cmd_t cmd_tbl[] = { "?", 0, 0, 0, cmd_help , "Help" , CMD_NOPARAMS }, { "V", 0, 0, 0, cmd_sysinfo , "System Info" , CMD_NOPARAMS }, { "Z", 0, 0, 0, cmd_reset , "Reset" , CMD_NOPARAMS }, - + { "adc", 1, 2, 0, cmd_adc_read , "ADC read" , "adc " }, #ifdef CFG_I2CEEPROM { "e", 1, 1, 0, cmd_i2ceeprom_read , "EEPROM Read" , "'e '" }, { "w", 2, 2, 0, cmd_i2ceeprom_write , "EEPROM Write" , "'w '" }, @@ -161,6 +165,7 @@ cmd_t cmd_tbl[] = #ifdef CFG_PWM { "M", 2, 2, 0, cmd_pwm , "PWM Control" , "'M [] []'" }, #endif + { "ssp", 1, 1, 0, cmd_ssp_write , "Write a byte to SSP" , "'ssp '"} }; #endif \ No newline at end of file diff --git a/project/commands/cmd_adc.c b/project/commands/cmd_adc.c new file mode 100644 index 0000000..082064a --- /dev/null +++ b/project/commands/cmd_adc.c @@ -0,0 +1,78 @@ +/**************************************************************************/ +/*! + @file cmd_adc.c + @author Miceuz + + @brief Code to execute for cmd_sysinfo in the 'core/cmd' + command-line interpretter. + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, 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 + +#include "projectconfig.h" +#include "core/cmd/cmd.h" +#include "project/commands.h" // Generic helper functions + +#include "core/adc/adc.h" + +/**************************************************************************/ +/*! + ADC command handler +*/ +/**************************************************************************/ + +void cmd_adc_read(uint8_t argc, char **argv) { + int32_t channel = 0; + int32_t numReads = 1; + + getNumber (argv[0], &channel); + if(channel < 0 || channel > 2) + { + printf("Invalid ADC channel, only channels [0..2] are avalable%s", CFG_PRINTF_NEWLINE); + return; + } + + if(argc > 1) { + getNumber (argv[1], &numReads); + if(numReads < 1) + { + printf("Invalid number of reads [1..65535]%s", CFG_PRINTF_NEWLINE); + return; + } + } + adcInit(); + int i = 0; + for(i = 0; i < numReads; i++) { + uint32_t result = adcReadSingle(channel); + printf("%d%s", (uint16_t)result, CFG_PRINTF_NEWLINE); + } +} \ No newline at end of file diff --git a/project/commands/cmd_ssp.c b/project/commands/cmd_ssp.c new file mode 100644 index 0000000..2252d6a --- /dev/null +++ b/project/commands/cmd_ssp.c @@ -0,0 +1,65 @@ +/**************************************************************************/ +/*! + @file cmd_ssp.c + @author Miceuz + + @brief SSP CLI command. + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, 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 + +#include "projectconfig.h" +#include "core/cmd/cmd.h" +#include "project/commands.h" // Generic helper functions + +#include "core/ssp/ssp.h" + +/**************************************************************************/ +/*! + SSP command handler +*/ +/**************************************************************************/ + +void cmd_ssp_write(uint8_t argc, char **argv) { + int32_t value = 0; + uint8_t request[SSP_FIFOSIZE]; + + getNumber (argv[0], &value); + + request[0]=(uint8_t) value; + + + sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); + ssp0Select(); + sspSend(0, (uint8_t *)&request, 1); + ssp0Deselect(); +} \ No newline at end of file diff --git a/projectconfig.h b/projectconfig.h index b0bf5be..7f95ac5 100644 --- a/projectconfig.h +++ b/projectconfig.h @@ -120,6 +120,12 @@ LPC1343 LPCXpresso board + CFG_BRD_LPC1343_CATNIP + ============================== + + LPC1343 CatNip board + + -----------------------------------------------------------------------*/ #define CFG_BRD_LPC1343_REFDESIGN // #define CFG_BRD_LPC1343_REFDESIGN_MINIMAL @@ -128,6 +134,7 @@ // #define CFG_BRD_LPC1343_802154USBSTICK // #define CFG_BRD_LPC1343_OLIMEX_P // #define CFG_BRD_LPC1343_LPCXPRESSO + // #define CFG_BRD_LPC1343_CATNIP /*=========================================================================*/ @@ -314,6 +321,14 @@ // #define GPIO_ENABLE_IRQ2 // #define GPIO_ENABLE_IRQ3 #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + // #define GPIO_ENABLE_IRQ0 + #define GPIO_ENABLE_IRQ1 + // #define GPIO_ENABLE_IRQ2 + // #define GPIO_ENABLE_IRQ3 + #endif + /*=========================================================================*/ @@ -384,6 +399,12 @@ #define CFG_UART_BAUDRATE (115200) #define CFG_UART_BUFSIZE (512) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_UART_BAUDRATE (115200) + #define CFG_UART_BUFSIZE (512) + #endif + /*=========================================================================*/ @@ -393,6 +414,7 @@ CFG_SSP0_SCKPIN_2_11 Indicates which pin should be used for SCK0 CFG_SSP0_SCKPIN_0_6 + CFG_SSP0_SCKPIN_0_10 -----------------------------------------------------------------------*/ #ifdef CFG_BRD_LPC1343_REFDESIGN @@ -424,6 +446,12 @@ #define CFG_SSP0_SCKPIN_2_11 // #define CFG_SSP0_SCKPIN_0_6 #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_SSP0_SCKPIN_0_10 + #endif + + /*=========================================================================*/ @@ -471,6 +499,12 @@ #define ADC_AVERAGING_ENABLE (0) #define ADC_AVERAGING_SAMPLES (5) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define ADC_AVERAGING_ENABLE (0) + #define ADC_AVERAGING_SAMPLES (5) + #endif + /*=========================================================================*/ @@ -525,6 +559,14 @@ #define CFG_LED_ON (0) #define CFG_LED_OFF (1) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_LED_PORT (2) + #define CFG_LED_PIN (10) + #define CFG_LED_ON (0) + #define CFG_LED_OFF (1) + #endif + /*=========================================================================*/ @@ -593,6 +635,14 @@ #define CFG_SDCARD_CDPORT (3) #define CFG_SDCARD_CDPIN (0) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + // #define CFG_SDCARD + #define CFG_SDCARD_READONLY (1) // Must be 0 or 1 + #define CFG_SDCARD_CDPORT (3) + #define CFG_SDCARD_CDPIN (0) + #endif + /*=========================================================================*/ @@ -617,9 +667,15 @@ CDC (see 'puts' in systeminit.c). -----------------------------------------------------------------------*/ - #define CFG_USB_VID (0x239A) - #define CFG_USB_PID (0x1002) - + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_USB_VID (0x1d50) + #define CFG_USB_PID (0x600c) + #else + #define CFG_USB_VID (0x239A) + #define CFG_USB_PID (0x1002) + #endif + #ifdef CFG_BRD_LPC1343_REFDESIGN // #define CFG_USBHID #define CFG_USBCDC @@ -675,6 +731,15 @@ #define CFG_USBCDC_INITTIMEOUT (5000) #define CFG_USBCDC_BUFFERSIZE (256) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + // #define CFG_USBHID + #define CFG_USBCDC + #define CFG_USBCDC_BAUDRATE (115200) + #define CFG_USBCDC_INITTIMEOUT (5000) + #define CFG_USBCDC_BUFFERSIZE (256) + #endif + /*=========================================================================*/ @@ -741,6 +806,14 @@ #define CFG_PRINTF_USBCDC #define CFG_PRINTF_NEWLINE "\r\n" #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_PRINTF_MAXSTRINGSIZE (255) + // #define CFG_PRINTF_UART + #define CFG_PRINTF_USBCDC + #define CFG_PRINTF_NEWLINE "\r\n" + #endif + /*=========================================================================*/ @@ -902,6 +975,21 @@ #define CFG_INTERFACE_CONFIRMREADY (0) #define CFG_INTERFACE_LONGSYSINFO (0) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_INTERFACE + #define CFG_INTERFACE_MAXMSGSIZE (256) + #define CFG_INTERFACE_PROMPT "CatNip >> " + #define CFG_INTERFACE_SILENTMODE (0) + #define CFG_INTERFACE_DROPCR (0) + #define CFG_INTERFACE_ENABLEIRQ (0) + #define CFG_INTERFACE_IRQPORT (0) + #define CFG_INTERFACE_IRQPIN (7) + #define CFG_INTERFACE_SHORTERRORS (0) + #define CFG_INTERFACE_CONFIRMREADY (0) + #define CFG_INTERFACE_LONGSYSINFO (0) + #endif + /*=========================================================================*/ @@ -926,6 +1014,9 @@ // #define CFG_PWM #define CFG_PWM_DEFAULT_PULSEWIDTH (CFG_CPU_CCLK / 1000) #define CFG_PWM_DEFAULT_DUTYCYCLE (50) + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_PWM + #endif /*=========================================================================*/ @@ -982,6 +1073,12 @@ // #define CFG_I2CEEPROM #define CFG_I2CEEPROM_SIZE (3072) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + #define CFG_I2CEEPROM + #define CFG_I2CEEPROM_SIZE (3072) + #endif + /*=========================================================================*/ @@ -1131,6 +1228,17 @@ #define CFG_CHIBI_PROMISCUOUS (0) #define CFG_CHIBI_BUFFERSIZE (128) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + // #define CFG_CHIBI + #define CFG_CHIBI_MODE (0) // OQPSK_868MHZ + #define CFG_CHIBI_POWER (0xE9) // CHB_PWR_EU2_3DBM + #define CFG_CHIBI_CHANNEL (0) // 868-868.6 MHz + #define CFG_CHIBI_PANID (0x1234) + #define CFG_CHIBI_PROMISCUOUS (0) + #define CFG_CHIBI_BUFFERSIZE (128) + #endif + /*=========================================================================*/ @@ -1220,6 +1328,15 @@ #define CFG_TFTLCD_TS_DEFAULTTHRESHOLD (50) #define CFG_TFTLCD_TS_KEYPADDELAY (100) #endif + + #ifdef CFG_BRD_LPC1343_CATNIP + // #define CFG_TFTLCD + #define CFG_TFTLCD_INCLUDESMALLFONTS (0) + #define CFG_TFTLCD_USEAAFONTS (0) + #define CFG_TFTLCD_TS_DEFAULTTHRESHOLD (50) + #define CFG_TFTLCD_TS_KEYPADDELAY (100) + #endif + /*=========================================================================*/ @@ -1284,8 +1401,9 @@ !defined CFG_BRD_LPC1343_TFTLCDSTANDALONE_UART && \ !defined CFG_BRD_LPC1343_802154USBSTICK && \ !defined CFG_BRD_LPC1343_OLIMEX_P && \ - !defined CFG_BRD_LPC1343_LPCXPRESSO - #error "You must defined a target board (CFG_BRD_LPC1343_REFDESIGN or CFG_BRD_LPC1343_REFDESIGN_MINIMAL or CFG_BRD_LPC1343_TFTLCDSTANDALONE or CFG_BRD_LPC1343_TFTLCDSTANDALONE_UART or CFG_BRD_LPC1343_802154USBSTICK or CFG_BRD_LPC1343_LPCXPRESSO)" + !defined CFG_BRD_LPC1343_LPCXPRESSO && \ + !defined CFG_BRD_LPC1343_CATNIP + #error "You must defined a target board (CFG_BRD_LPC1343_REFDESIGN or CFG_BRD_LPC1343_REFDESIGN_MINIMAL or CFG_BRD_LPC1343_TFTLCDSTANDALONE or CFG_BRD_LPC1343_TFTLCDSTANDALONE_UART or CFG_BRD_LPC1343_802154USBSTICK or CFG_BRD_LPC1343_LPCXPRESSO or CFG_BRD_LPC1343_CATNIP)" #endif #if defined CFG_PRINTF_USBCDC && defined CFG_PRINTF_UART @@ -1300,12 +1418,14 @@ #error "Only one USB class can be defined at a time (CFG_USBCDC or CFG_USBHID)" #endif -#if defined CFG_SSP0_SCKPIN_2_11 && defined CFG_SSP0_SCKPIN_0_6 +#if defined CFG_SSP0_SCKPIN_2_11 && defined CFG_SSP0_SCKPIN_0_6 || \ + defined CFG_SSP0_SCKPIN_2_11 && defined CFG_SSP0_SCKPIN_0_10 || \ + defined CFG_SSP0_SCKPIN_0_6 && defined CFG_SSP0_SCKPIN_0_10 #error "Only one SCK pin can be defined at a time for SSP0" #endif -#if !defined CFG_SSP0_SCKPIN_2_11 && !defined CFG_SSP0_SCKPIN_0_6 - #error "An SCK pin must be selected for SSP0 (CFG_SSP0_SCKPIN_2_11 or CFG_SSP0_SCKPIN_0_6)" +#if !defined CFG_SSP0_SCKPIN_2_11 && !defined CFG_SSP0_SCKPIN_0_6 && !defined CFG_SSP0_SCKPIN_0_10 + #error "An SCK pin must be selected for SSP0 (CFG_SSP0_SCKPIN_2_11 or CFG_SSP0_SCKPIN_0_6 or CFG_SSP0_SCKPIN_0_10)" #endif #ifdef CFG_INTERFACE