From: Miceuz Date: Thu, 10 May 2012 20:25:50 +0000 (+0200) Subject: Merge branch 'master' of git://github.com/microbuilder/LPC1343CodeBase X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/b7864004487e7cc6129c3775dd66f8ad9a07528f?hp=e7290b9b8ad5b061ac1c9dd71bc4a6b33223d8ee Merge branch 'master' of git://github.com/microbuilder/LPC1343CodeBase --- diff --git a/ChangeLog.txt b/ChangeLog.txt index a62048e..e083124 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,10 +2,11 @@ v1.1.2 - ongoing ============================================================================== NEW FEATURES ------------------------------------------------------------------------------ +- Added basic TEA5767 drive - 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). -- Updated all LCD drivers to include the fastHLine and fastVLine flags. + is present in the driver or not) +- Updated all LCD drivers to include the fastHLine and fastVLine flags - Added PWM command to CLI (thanks Miceuz) - Added optional callback in 32-bit timer ISR (thanks again Miceuz) diff --git a/Makefile b/Makefile index a8f39b5..482caea 100644 --- a/Makefile +++ b/Makefile @@ -40,8 +40,7 @@ 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 -OBJS += cmd_pwm.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 @@ -140,6 +139,10 @@ OBJS += tcs3414.o tsl2561.o VPATH += drivers/storage/spiflash/w25q16bv OBJS += w25q16bv.o +# FM Radio +VPATH += drivers/audio/tea5767 +OBJS += tea5767.o + ########################################################################## # Library files ########################################################################## diff --git a/Readme.md b/Readme.md index e198551..459b1d1 100644 --- a/Readme.md +++ b/Readme.md @@ -1,14 +1,67 @@ # LPC1343 Code Base +## Overview + This software library is based on the freely available LPC1343 Reference -Design available at http://www.microBuilder.eu. Unless otherwise stated, -all files are licensed under the BSD license (see license.txt for details). +Design from http://www.microBuilder.eu, and is based around the **ARM Cortex M3 +LPC1343** from NXP. + +The LPC1343 is a modern, entry level 32-bit ARM Cortex M3 processor with +**32KB flash, 8KB SRAM**, and can be run at up to **72MHz**. It also includes +full-speed USB 2.0, along with all the main peripherals you'd expect to find +(I2C, SPI, PWM, ADC, UART, etc.). + +The LPC1000 family from NXP contains a wide variety of ARM Cortex M0 and +Cortex M3 cores, but the LPC1343 is particularly attractive in situations +where price is an issue, but a decent amount of performance is needed. It has +an efficient instruction set (most commands execute in a single clock cycle, +including single-cycle multiply, etc.), and excellent code-density thanks to +the Thumb-2 instruction set, meaning 32KB stretches a lot further than it +did with the older ARM7 or ARM9 cores even in Thumb mode. + +The ARM Cortex M0 based LPC1114 is cheaper (ridiculously cheap!), and represents +one of the best values out there when both price and power consumption are an issue, +but the Cortex M0 has a minor performance bottleneck compared to the Cortex M3 that +may or may not be important to you: The smaller, lighter-weight M0 LPC1114 is based +on a Von Nuemann architecture with a single pipeline for both instructions and +data. This means that it usually takes two clock cycles to do something on the M0 that can +be done in one clock cycle on the ARM Cortex M3 LPC1343. The M3 LPC1343 implements +a Harvard architecture with a three-stage pipeline, meaning seperate pipelines for +instructions, data and peripherals that can all be filled in the same clock cycle. + +This means that in certain situations 72MHz on the M3 LPC1343 can +actually be more than twice as fast as the 50MHz LPC1114, though this comes at the +expense of a larger and more complicated core that consumes more power and requires a +slightly larger die due to the increased gate count. + +> **M0 Sidenote:** The single-pipeline bottleneck on the M0 is addressed in the recently announced +ARM Cortex M0+, which will contain a dual pipeline, while still maintaining a very +light-weight, efficient and inexpensive core. This is probably the most important +change in the M0+ since it offers much better performance per clock cycle, meaning +you can switch back to a low-power sleep mode that much quicker for better battery life. + +If you need to get the best possible performance for your money and are doing +computationally intensive tasks or maybe a lot of rapid memory access and pin state +reads/writes, etc., the LPC1343 will be a better fit. If you need to get the lowest +possible cost and power consumption, the LPC1114 is probably the better choice, though +the LPC1343 has reasonably good power numbers as well. + +One of the biggest advantages of the LPC1343 and LPC1114, though, is that they are +99% register compatible with each other if you want or need to switch to one +or the other, and learning one makes using the other trivial. While the LPC1343 Code +Base tends to be slightly more actively maintained, there is a parallel LPC1114 Code +Base that mirrors the LPC1343 library here, and it should be painless to switch between +the two. For more information see: https://github.com/microbuilder/LPC1114CodeBase + +## License + +Unless otherwise stated, all files are generally licensed +under a modified **BSD license** (see license.txt for details). ## Downloads -The latest version of the software is always available on github at: - -https://github.com/microbuilder/LPC1343CodeBase +The latest development version of the software is always available on github at: +>https://github.com/microbuilder/LPC1343CodeBase ## Development Status @@ -20,30 +73,30 @@ and may have been abandoned once the basic features were working (setting pixels on a display, etc.), but they should serve as a good starting point for a wide variety of peripherals. -## How Can Someone Support This Project - -A lot of the recent development in this library was done -thanks to the financial support of Adafruit Industries (paying -me a salary to keep providing this stuff). If you find this library -useful, please consider ordering something from the people that -make this financially possible: http://www.adafruit.com +The code base is definately imperfect, and some growing pains and faulty early +assumptions are evident throughout, but it hopefully at least +partially fulfills the goal of providing a genuinely open source +code base for the LPC1343 and GCC with no dependencies on any one +commercial toolchain or IDE. -## Toolchains +## Supported Toolchains/IDEs -The entire LPC1343 Code Base is based around GCC, and can be built -from the command-line using only free tools like the Yagarto -distribution for Windows or the Mac, etc. +The entire LPC1343 Code Base is based around **GCC**, and can be built +from the command-line using only free tools like the **Yagarto** +distribution for Windows or the Mac, or using GCC on Linux, etc. +> http://www.yagarto.de/ -Nonetheless, it's often more productive to develop in an IDE with a +Nonetheless, it's sometimes more productive to develop in an IDE with a full set of debugging tools at your disposal, and the code base also -includes project files for Rowley Associate's Crossworks for ARM, as -well as project files for the free and open source CodeLite, which can +includes project files for Rowley Associate's **Crossworks for ARM**, as +well as project files for the free and open source **CodeLite**, which can be used in combination with a Segger J-Link for ARM and GDB Server. +Project files for these two IDEs are stored in the /build folder. -Project files for the two IDEs are stored in the /build folder, and -project files for the free LPCXpresso IDE are stored in root (see -http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/DebuggingWithLPCXpresso.aspx -for more information on using LPCXpresso). +Project files for the free (but commercial) **LPCXpresso** IDE are stored in the +root folder, and this probably represents the cheapest means to do real step-through +HW debugging. For more information on using LPCXpresso with the LPC1343 Code Base see: +>http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/DebuggingWithLPCXpresso.aspx ## Documentation @@ -53,11 +106,25 @@ inconsistencies are present since parts of the library have been reorganized working towards a 1.0.0 release. The graphics library in particular has been reorganized quite a bit. -General API Documentation: -http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/CodeBaseDocumentation.aspx +**General API Documentation:** +>http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/CodeBaseDocumentation.aspx -TFT/OLED Graphics Sub-System: -http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/TFTLCDAPI_v1_1_0.aspx +**TFT/OLED Graphics Sub-System:** +>http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign/TFTLCDAPI_v1_1_0.aspx + +**Other tutorials and links:** +>http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign.aspx + +## How Can Someone Support This Project? + +A lot of the recent development in this library was done +thanks to the financial support of **Adafruit Industries** (paying +my salary to keep working on this stuff!). If you find this library +useful, please consider ordering something from the people that +make this financially possible: http://www.adafruit.com -Other tutorials and links: -http://www.microbuilder.eu/Projects/LPC1343ReferenceDesign.aspx +Any additions, suggestions or bug fixes are always welcome, and this +is in fact one of the main incentives behind making this library +open source. If you have anything to contribute, using the feedback +mechanisms on Github is probably the best and most orderly way to +do this. diff --git a/build/crossworks/LPC1343_CodeBase.hzp b/build/crossworks/LPC1343_CodeBase.hzp index 0f312e8..49398d9 100644 --- a/build/crossworks/LPC1343_CodeBase.hzp +++ b/build/crossworks/LPC1343_CodeBase.hzp @@ -144,7 +144,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -317,6 +317,11 @@ + + + + + diff --git a/build/crossworks/LPC1343_CodeBase.hzs b/build/crossworks/LPC1343_CodeBase.hzs index 2b310b0..d03e981 100644 --- a/build/crossworks/LPC1343_CodeBase.hzs +++ b/build/crossworks/LPC1343_CodeBase.hzs @@ -24,10 +24,7 @@ - - - - + @@ -63,7 +60,7 @@ - + - + diff --git a/core/cmd/ansi.h b/core/cmd/ansi.h new file mode 100644 index 0000000..623e126 --- /dev/null +++ b/core/cmd/ansi.h @@ -0,0 +1,76 @@ +/**************************************************************************/ +/*! + @file ansi.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012 K. 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 __ANSI_H__ +#define __ANSI_H__ + +#include "projectconfig.h" + +// See: http://www.inwap.com/pdp10/ansicode.txt + +// Ex: printf("%s%s%s Bold Black Inverted Text %s \r\n", ANSICODES_GRAPHICS_STYLE_BOLD, ANSICODES_GRAPHICS_FORECOLOR_BLACK, ANSICODES_GRAPHICS_STYLE_NEGATIVE, ANSICODES_GRAPHICS_CLEARALL); + +#define ANSICODES_GRAPHICS_CLEARALL "\e[0m" +#define ANSICODES_GRAPHICS_STYLE_BOLD "\e[1m" +#define ANSICODES_GRAPHICS_STYLE_DIM "\e[2m" +#define ANSICODES_GRAPHICS_STYLE_ITALIC "\e[3m" +#define ANSICODES_GRAPHICS_STYLE_UNDERSCORE "\e[4m" +#define ANSICODES_GRAPHICS_STYLE_SLOWBLINK "\e[5m" +#define ANSICODES_GRAPHICS_STYLE_FASTBLINK "\e[6m" +#define ANSICODES_GRAPHICS_STYLE_NEGATIVE "\e[7m" +#define ANSICODES_GRAPHICS_STYLE_CONCEALED "\e[8m" // Do not display character +#define ANSICODES_GRAPHICS_STYLE_CANCELBOLDDIM "\e[22m" +#define ANSICODES_GRAPHICS_STYLE_CANCELUNDERLINE "\e[24m" +#define ANSICODES_GRAPHICS_STYLE_CANCELBLINK "\e[25m" +#define ANSICODES_GRAPHICS_STYLE_CANCELNEGATIVE "\e[27m" +#define ANSICODES_GRAPHICS_FORECOLOR_BLACK "\e[30m" +#define ANSICODES_GRAPHICS_FORECOLOR_RED "\e[31m" +#define ANSICODES_GRAPHICS_FORECOLOR_GREEN "\e[32m" +#define ANSICODES_GRAPHICS_FORECOLOR_YELLOW "\e[33m" +#define ANSICODES_GRAPHICS_FORECOLOR_BLUE "\e[34m" +#define ANSICODES_GRAPHICS_FORECOLOR_MAGENTA "\e[35m" +#define ANSICODES_GRAPHICS_FORECOLOR_CYAN "\e[36m" +#define ANSICODES_GRAPHICS_FORECOLOR_WHITE "\e[37m" +#define ANSICODES_GRAPHICS_BACKCOLOR_BLACK "\e[40m" +#define ANSICODES_GRAPHICS_BACKCOLOR_RED "\e[41m" +#define ANSICODES_GRAPHICS_BACKCOLOR_GREEN "\e[42m" +#define ANSICODES_GRAPHICS_BACKCOLOR_YELLOW "\e[43m" +#define ANSICODES_GRAPHICS_BACKCOLOR_BLUE "\e[44m" +#define ANSICODES_GRAPHICS_BACKCOLOR_MAGENTA "\e[45m" +#define ANSICODES_GRAPHICS_BACKCOLOR_CYAN "\e[46m" +#define ANSICODES_GRAPHICS_BACKCOLOR_WHITE "\e[47m" + +#endif \ No newline at end of file diff --git a/core/pwm/pwm.c b/core/pwm/pwm.c index b94329f..7f1e2e5 100644 --- a/core/pwm/pwm.c +++ b/core/pwm/pwm.c @@ -178,7 +178,7 @@ int pwmSetDutyCycle(uint32_t percentage) } /* Set Duty Cycle (MR0) */ - TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - (pwmDutyCycle = percentage))) / 100; + TMR_TMR16B1MR0 = ((pwmPulseWidth * (100 - (pwmDutyCycle = percentage))) / 100) + 1; return 0; } @@ -202,7 +202,7 @@ int pwmSetFrequencyInTicks(uint16_t ticks) } /* Set Pulse Width (MR3)*/ - TMR_TMR16B1MR3 = (pwmPulseWidth = ticks); + TMR_TMR16B1MR3 = (pwmPulseWidth = ticks - 1); /* Adjust Duty Cycle (MR0) */ TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - pwmDutyCycle)) / 100; @@ -224,8 +224,8 @@ int pwmSetFrequencyInTicks(uint16_t ticks) @Warning Because a 16-bit timer is used here by default, the maximum frequency is quite small. Running at 36MHz, the largest possible pulse-width/frequency is ~1,82mS or - 1820 microSeconds. At 12MHz its 5461 uS, and at 48MHz - its 1365 uS. + 1820 microSeconds. At 12MHz its 5461 uS, at 48MHz + its 1365 uS, at 72MHz its 909uS. */ /**************************************************************************/ int pwmSetFrequencyInMicroseconds(uint16_t us) @@ -243,10 +243,10 @@ int pwmSetFrequencyInMicroseconds(uint16_t us) } /* Set Pulse Width (MR3)*/ - TMR_TMR16B1MR3 = (pwmPulseWidth = ticks); + TMR_TMR16B1MR3 = (pwmPulseWidth = ticks - 1); /* Adjust Duty Cycle (MR0) */ - TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - pwmDutyCycle)) / 100; + TMR_TMR16B1MR0 = ((pwmPulseWidth * (100 - pwmDutyCycle)) / 100) + 1; return 0; } diff --git a/core/pwm/pwm_100us_50percent.png b/core/pwm/pwm_100us_50percent.png deleted file mode 100644 index efed5f4..0000000 Binary files a/core/pwm/pwm_100us_50percent.png and /dev/null differ diff --git a/core/pwm/pwmtest_100ticks_50percent.png b/core/pwm/pwmtest_100ticks_50percent.png new file mode 100644 index 0000000..42a9eeb Binary files /dev/null and b/core/pwm/pwmtest_100ticks_50percent.png differ diff --git a/core/timer32/timer32.c b/core/timer32/timer32.c index 31e5b01..d25638f 100644 --- a/core/timer32/timer32.c +++ b/core/timer32/timer32.c @@ -351,6 +351,39 @@ void timer32Init(uint8_t timerNum, uint32_t timerInterval) /**************************************************************************/ /*! @brief Sets the optional callback function for 32-bit timer 0 + + @section EXAMPLE + + @code + #include "core/timer32/timer32.h" + + static volatile int32_t timerCounter; + + // Callback function for 32-bit timer 0 + void ct32b0Callback(void) + { + timerCounter++; + } + + int main(void) + { + // Configure cpu and mandatory peripherals + systemInit(); + + // Init timer 0 with 1ms delay + timer32Init(0, TIMER32_CCLK_1MS); + + // Setup the interrupt callback + timer32SetIntHandler(ct32b0Callback); + + // Enable the timer + timer32Enable(0); + + while (1) + { + } + } + @endcode */ /**************************************************************************/ void timer32SetIntHandler(void (*handler)(void)) diff --git a/drivers/audio/tea5767/tea5767.c b/drivers/audio/tea5767/tea5767.c new file mode 100644 index 0000000..4e141bf --- /dev/null +++ b/drivers/audio/tea5767/tea5767.c @@ -0,0 +1,279 @@ +/**************************************************************************/ +/*! + @file tea5767.c + @author K. Townsend + + @brief Driver for the TEA5767 FM receiver. + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. 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 "tea5767.h" +#include "core/i2c/i2c.h" +#include "core/systick/systick.h" + +extern volatile uint8_t I2CMasterBuffer[I2C_BUFSIZE]; +extern volatile uint8_t I2CSlaveBuffer[I2C_BUFSIZE]; + +static bool _tea5767Initialised = false; + +/**************************************************************************/ +/*! + @brief Sends 5 bytes over I2C +*/ +/**************************************************************************/ +void tea5767SendData(uint8_t * bytes) +{ + // Clear write buffers + uint32_t i; + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + } + + I2CWriteLength = 6; + I2CReadLength = 0; + I2CMasterBuffer[0] = TEA5767_ADDRESS; + I2CMasterBuffer[1] = bytes[0]; + I2CMasterBuffer[2] = bytes[1]; + I2CMasterBuffer[3] = bytes[2]; + I2CMasterBuffer[4] = bytes[3]; + I2CMasterBuffer[5] = bytes[4]; + i2cEngine(); +} + +/**************************************************************************/ +/*! + @brief Reads 5 bytes over I2C +*/ +/**************************************************************************/ +void tea5767ReadData(uint8_t * bytes) +{ + // Clear buffers + uint32_t i; + for ( i = 0; i < I2C_BUFSIZE; i++ ) + { + I2CMasterBuffer[i] = 0x00; + I2CSlaveBuffer[i] = 0x00; + } + + I2CWriteLength = 1; + I2CReadLength = 5; + I2CMasterBuffer[0] = TEA5767_ADDRESS | TEA5767_READ; + i2cEngine(); + + bytes[0] = I2CSlaveBuffer[0]; + bytes[1] = I2CSlaveBuffer[1]; + bytes[2] = I2CSlaveBuffer[2]; + bytes[3] = I2CSlaveBuffer[3]; + bytes[4] = I2CSlaveBuffer[4]; +} + +/**************************************************************************/ +/*! + @brief This is a test function to evaluate the quality of crystals + used on 3rd party modules. Most modules use cheap 32.768kHz + crystals which are prone to de-tuning. Checking the IF bits + at 81.4MHz can check if the crystal is problematic or not. + + @returns True (1) if the IF bits are equal to 0x37 (good), otherwise + false (0). The device may still function if the IF values + are slightly off, but auto-scan and tuning will likely be + less reliable. +*/ +/**************************************************************************/ +bool tea5767CheckCrystal(void) +{ + /* AN10133 (p.38) states: + + The choice of 32768Hz reference frequency makes it possible to use a + cheap 32.768kHz watch crystal. A drawback of these clocks is that they + have a very high second order temperature coefficient. This may result + in de-tuning the radio or a search action may fail. + + Care should be taken when using this crystal. The accuracy of the + 32768Hz crystal can be checked by tuning the radio to 81.4 MHz + with high/low side injection and reading the IF via the bus. The IF + must be 37Hex. + + An other issue when using this crystal is the grid position. It is + not possible to create a 100kHz grid position, but 98.304kHz + (3*32768Hz). This should not be a problem if this is resolved in + software. + + The motional capacitance of the 32768Hz crystal should be between + 1.5fF and 3fF. Shunt capacitance must be max 3.5pF. The series + resistance should not exceed 75KOhm. + + Further, the frequency accuracy of this crystal must not exceed ±20 + ppm, while the temperature drift should be in the order of ±50 ppm + over a temperature range of –10oC to +60oC. + */ + + uint8_t ifValue = 0; + uint8_t buffer[5] = { 0, 0, 0, 0, 0 }; + + // Set the frequency to 81.4MHz + tea5767SetFrequency(81400000); + systickDelay(100); + + // Read back the IF bits + tea5767ReadData(&buffer[0]); + ifValue = buffer[2] & 0x7F; + + // Reconfigure the chip to a known frequency to avoid user problems + // tea5767SetFrequency(TEA5767_FMBANDSTART_JAPAN); + tea5767SetFrequency(TEA5767_FMBANDSTART_US_EUROPE); + + // Return true if the crystal is OK (IF = 0x37 @ 81.4MHz), + // false if it's something else + if (0x37 == ifValue) + return true; + else + return false; +} + +/**************************************************************************/ +/*! + @brief Initialises I2C for the TEA5767. +*/ +/**************************************************************************/ +uint32_t tea5767Init() +{ + // Initialise I2C + if (i2cInit(I2CMASTER) == false) + { + /* Fatal error */ + return -1; + } + + /* Set initialisation flag */ + _tea5767Initialised = true; + + // Set the frequency to a known value to make sure the PLL is properly configured + // tea5767SetFrequency(TEA5767_FMBANDSTART_JAPAN); + tea5767SetFrequency(TEA5767_FMBANDSTART_US_EUROPE); + + return 0; +} + +/**************************************************************************/ +/*! + @brief Sets the frequency to the specified value in Hz + + @param[in] frequency + The frequency in Hz, meaning that 95.7MHz = 97,500,000 + 101.4 MHz = 101,400,000 etc. +*/ +/**************************************************************************/ +void tea5767SetFrequency( uint32_t frequency ) +{ + uint32_t pllValue; + uint8_t buffer[5] = { 0, 0, 0, 0, 0 }; + + // Make sure I2C is initialised + if (!_tea5767Initialised) tea5767Init(); + + // Calculate PLL word for high side injection mode + // NDEC = (4*(FRF + FIF)) / FREFS + // where: + // FRF = Desired tuning frequency in Hz + // FIF = Intermediate frequency in Hz (225kHz) + // FREFS = Reference frequency in Hz (32.768kHz) + pllValue = (4 * (frequency + 225000)) / 32768; + + buffer[0] = (pllValue >> 8) & 0x3F; // Upper 6 PLL bits (also turns mute and search mode off!) + buffer[1] = (pllValue & 0xFF); // Lower 8 PLL bits + buffer[2] = TEA5767_WBYTE3_HLSI; // High side injection mode + buffer[3] = TEA5767_WBYTE4_XTAL; // XTAL bit = 1 for 32.768kHz crystal + buffer[4] = 0; // PLLREF bit = 0 for 32.768kHz crystal + + // Send data over I2C + tea5767SendData(buffer); +} + +/**************************************************************************/ +/*! + @brief Returns the current frequency in Hz (meaning 97.5MHz will be + returned as 97,500,000 etc. +*/ +/**************************************************************************/ +uint32_t tea5767GetFrequency( void ) +{ + uint32_t frequency = 0; + uint8_t buffer[5] = { 0, 0, 0, 0, 0 }; + + if (!_tea5767Initialised) tea5767Init(); + + tea5767ReadData(&buffer[0]); + + // Retrieve the raw 14-bit PLL value from word 1 and 2 + frequency = ((buffer[0] & 0x3F) << 8) + buffer[1]; + // Determine the current frequency using the same high side formula as above + frequency = frequency * 32768 / 4 - 225000; + + return frequency; +} + +/**************************************************************************/ +/*! + @brief Starts the auto-scan process from the current frequency + + @param[in] scanDirection + Set this to 0 to scan down, or one to scan up, starting + at the current frequency. +*/ +/**************************************************************************/ +void tea5767Scan( uint8_t scanDirection ) +{ + uint8_t rbuffer[5] = { 0, 0, 0, 0, 0 }; + uint8_t wbuffer[5] = { 0, 0, 0, 0, 0 }; + + // Make sure I2C is initialised + if (!_tea5767Initialised) tea5767Init(); + + // First we need to get the current PLL word to know where to start from + tea5767ReadData(&rbuffer[0]); + + // Set the PLL value again and append the search enable bu + wbuffer[0] = TEA5767_WBYTE1_SEARCHMODE + // Search mode enabled + (rbuffer[0] & 0x3F); // Upper PLL bits + wbuffer[1] = rbuffer[1]; // Lower PLL bits + wbuffer[2] = TEA5767_WBYTE3_SEARCHSTOPLEVEL_MID | // Mid level ADC for search steps + TEA5767_WBYTE3_HLSI; // HLSI (must be 1 for PLL) + wbuffer[3] = TEA5767_WBYTE4_XTAL; // Must be 1 for 32.768kHz crystal + wbuffer[4] = 0x00; + + // Set the scan direction bit to 1 (scan up) if scanDirection is non-zero + if (scanDirection) wbuffer[2] |= TEA5767_WBYTE3_SEARCHUPDOWN; + + // Send data over I2C + tea5767SendData(wbuffer); +} diff --git a/drivers/audio/tea5767/tea5767.h b/drivers/audio/tea5767/tea5767.h new file mode 100644 index 0000000..f2a4869 --- /dev/null +++ b/drivers/audio/tea5767/tea5767.h @@ -0,0 +1,149 @@ +/**************************************************************************/ +/*! + @file tea5767.h + @author K. Townsend + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. 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 _TEA5767_H_ +#define _TEA5767_H_ + +#include "projectconfig.h" + +#define TEA5767_FMBANDSTART_US_EUROPE (87500000) // 87.5 MHz to 108 MHz +#define TEA5767_FMBANDSTART_JAPAN (76000000) // 76 MHz to 91 MHz plus TV audio at 108 MHz + +/*========================================================================= + I2C ADDRESS/BITS + -----------------------------------------------------------------------*/ + #define TEA5767_ADDRESS (0xC0) // 1100000x + #define TEA5767_READ (0x01) +/*=========================================================================*/ + +/*========================================================================= + WRITE BYTE 1 + MUTE | SEARCHMODE | PLL13 | PLL12 | PLL11 | PLL10 | PLL9 | PLL8 + -----------------------------------------------------------------------*/ + #define TEA5767_WBYTE1_MUTE (1<<7) // 1 = mute, 0 = output enabled (mute enabled after reset) + #define TEA5767_WBYTE1_SEARCHMODE (1<<6) // 1 = Search mode enabled +/*=========================================================================*/ + +/*========================================================================= + WRITE BYTE 2 + PLL7 | PLL6 | PLL5 | PLL4 | PLL3 | PLL2 | PLL1 | PLL0 + -----------------------------------------------------------------------*/ + +/*=========================================================================*/ + +/*========================================================================= + WRITE BYTE 3 + SUD | SSL1 | SSL0 | HLSI | MS | MR | ML | SWP1 + -----------------------------------------------------------------------*/ + #define TEA5767_WBYTE3_SEARCHUPDOWN (1<<7) // 1 = search up, 0 = search down + #define TEA5767_WBYTE3_SEARCHSTOPLEVEL1 (1<<6) // 10 = mid level (ADC = 7), 11 = high level (ADC = 10) + #define TEA5767_WBYTE3_SEARCHSTOPLEVEL0 (1<<5) // 00 = invalid, 01 = low level (ADC = 5) + #define TEA5767_WBYTE3_SEARCHSTOPLEVELMASK (3<<5) + #define TEA5767_WBYTE3_HLSI (1<<4) // 1 = high side LO injection, 0 = low side LO injection + #define TEA5767_WBYTE3_MONOTOSTEREO (1<<3) // 1 = force mono, 0 = stereo on + #define TEA5767_WBYTE3_MUTERIGHT (1<<2) // 1 = mute right audio, 0 = enabled + #define TEA5767_WBYTE3_MUTELEFT (1<<1) // 1 = mute left audio, 0 = enabled + /*---------------------------------------------------------------------*/ + #define TEA5767_WBYTE3_SEARCHSTOPLEVEL_LOW (0x20) // ADC output = 5 (bit: 01) + #define TEA5767_WBYTE3_SEARCHSTOPLEVEL_MID (0x40) // ADC output = 7 (bit: 10) + #define TEA5767_WBYTE3_SEARCHSTOPLEVEL_HIGH (0x60) // ADC output = 10 (bit: 11) +/*=========================================================================*/ + +/*========================================================================= + WRITE BYTE 4 + SWP2 | STBY | BL | XTAL | SMUTE | HCC | SNC | SI + -----------------------------------------------------------------------*/ + #define TEA5767_WBYTE4_STANDBY (1<<6) // 1 = standby mode + #define TEA5767_WBYTE4_BANDLIMITS (1<<5) // 1 = Japanese FM band, 0 = US/Europe + #define TEA5767_WBYTE4_XTAL (1<<4) // Combined with PLLREF in byte 5 (set to 1 for 32.768kHz crystal) + #define TEA5767_WBYTE4_SOFTMUTE (1<<3) // 1 = soft mute enabled + #define TEA5767_WBYTE4_HIGHCUTCONTROL (1<<2) // 1 = HCC enabled + #define TEA5767_WBYTE4_STEREONOISECANCEL (1<<1) // 1 = stereo noise cancelling enabled +/*=========================================================================*/ + +/*========================================================================= + WRITE BYTE 5 + PLLREF | DTC | - | - | - | - | - | - + -----------------------------------------------------------------------*/ + #define TEA5767_WBYTE5_PLLREF (1<<7) // 1 = 6.5MHz PLL ref freq. enabled (set to 0 for 32.768kHz crystal) + #define TEA5767_WBYTE5_DEEMPHASISTIMECONST (1<<6) // 1 = DTC is 75µs, 0 = 50µs +/*=========================================================================*/ + + +/*========================================================================= + READ BYTE 1 + RF | BLF | PLL13 | PLL12 | PLL11 | PLL 10 | PLL9 | PLL8 + -----------------------------------------------------------------------*/ + #define TEA5767_RBYTE1_READYFLAG (1<<7) // 1 = station found or band-limit reached, 0 = no station found + #define TEA5767_RBYTE1_BANDLIMITFLAG (1<<6) // 1 = band limit has been reached, 0 = band limit not reached +/*=========================================================================*/ + +/*========================================================================= + READ BYTE 2 + PLL7 | PLL6 | PLL5 | PLL4 | PLL3 | PLL2 | PLL1 | PLL0 + -----------------------------------------------------------------------*/ + +/*=========================================================================*/ + +/*========================================================================= + READ BYTE 3 + STEREO | IF6 | IF5 | IF4 | IF3 | IF2 | IF1 | IF0 + -----------------------------------------------------------------------*/ + #define TEA5767_RBYTE3_STEREOINDICATOR (1<<7) // 1 = stereo reception, 0 = mono reception +/*=========================================================================*/ + +/*========================================================================= + READ BYTE 4 + LEV3 | LEV2 | LEV1 | LEV0 | CI3 | CI2 | CI1 | - + -----------------------------------------------------------------------*/ + #define TEA5767_RBYTE4_ADCLEVELOUTPUTMASK (0xF0) // ADC output level + #define TEA5767_RBYTE4_CHIPIDMASK (0x0F) // These bits must be set to 0! +/*=========================================================================*/ + +/*========================================================================= + READ BYTE 5 + - | - | - | - | - | - | - | - + -----------------------------------------------------------------------*/ + +/*=========================================================================*/ + +uint32_t tea5767Init( void ); +void tea5767SetFrequency( uint32_t ); +uint32_t tea5767GetFrequency( void ); +void tea5767Scan( uint8_t ); +void tea5767Mute( bool ); + +#endif \ No newline at end of file diff --git a/drivers/displays/bitmap/readme.txt b/drivers/displays/bitmap/readme.txt index 8b144a0..6a747ba 100644 --- a/drivers/displays/bitmap/readme.txt +++ b/drivers/displays/bitmap/readme.txt @@ -6,7 +6,8 @@ or text-only displays. They are placed in a seperate folder because the drawing routines are handled quite differently than the generic drawing code for 16-bit TFT LCDs. +SHARPMEM Basic driver for Sharp memory displays. ST7565 Driver for 128x64 pixel I2C-based displays (available from Adafruit Industries, for example). SSD1306 Driver for 128x64 pixel OLED displays (also available from - Adafruit Industries). + Adafruit Industries). Supports I2C and SPI. diff --git a/drivers/displays/bitmap/ssd1306/ssd1306.c b/drivers/displays/bitmap/ssd1306/ssd1306.c index f8e4ee4..fd5ac22 100644 --- a/drivers/displays/bitmap/ssd1306/ssd1306.c +++ b/drivers/displays/bitmap/ssd1306/ssd1306.c @@ -490,7 +490,7 @@ uint8_t ssd1306GetPixel(uint8_t x, uint8_t y) /**************************************************************************/ void ssd1306ClearScreen() { - memset(_ssd1306buffer, 0, 1024); + memset(_ssd1306buffer, 0x00, 1024); } /**************************************************************************/ diff --git a/drivers/displays/bitmap/ssd1306/ssd1306.h b/drivers/displays/bitmap/ssd1306/ssd1306.h index d0f096b..538cd4d 100644 --- a/drivers/displays/bitmap/ssd1306/ssd1306.h +++ b/drivers/displays/bitmap/ssd1306/ssd1306.h @@ -53,8 +53,8 @@ SSD1306_BUS_I2C Use HW I2C -----------------------------------------------------------------------*/ - #define SSD1306_BUS_SPI - // #define SSD1306_BUS_I2C + // #define SSD1306_BUS_SPI + #define SSD1306_BUS_I2C #if defined SSD1306_BUS_SPI && defined SSD1306_BUS_I2C #error "Only one SSD1306 bus interface can be specified at once in ssd1306.h" diff --git a/drivers/displays/tft/touchscreen.c b/drivers/displays/tft/touchscreen.c index 1ac7821..381976a 100644 --- a/drivers/displays/tft/touchscreen.c +++ b/drivers/displays/tft/touchscreen.c @@ -413,20 +413,9 @@ tsTouchError_t tsRead(tsTouchData_t* data, uint8_t calibrating) tsPoint_t location, touch; touch.x = x1; touch.y = y1; - // Only calculate the relative LCD value if this isn't for calibration - if (!calibrating) - { - getDisplayPoint( &location, &touch, &_tsMatrix) ; - data->xlcd = location.x; - data->ylcd = location.y; - } - else - { - // Assign some false values, but only xraw and yraw are - // used for calibration - data->xlcd = 0; - data->ylcd = 0; - } + getDisplayPoint( &location, &touch, &_tsMatrix) ; + data->xlcd = location.x; + data->ylcd = location.y; data->valid = true; return TS_ERROR_NONE; diff --git a/project/cmd_tbl.h b/project/cmd_tbl.h index 022f1ac..639503c 100644 --- a/project/cmd_tbl.h +++ b/project/cmd_tbl.h @@ -159,7 +159,7 @@ cmd_t cmd_tbl[] = #endif #ifdef CFG_PWM - { "M", 0, 2, 0, cmd_pwm , "PWM Control" , "'M [] []'" }, + { "M", 0, 2, 0, cmd_pwm , "PWM Control" , "'M [] []'" }, #endif }; diff --git a/project/commands/cmd_pwm.c b/project/commands/cmd_pwm.c index c327a0a..505470d 100644 --- a/project/commands/cmd_pwm.c +++ b/project/commands/cmd_pwm.c @@ -81,9 +81,9 @@ void cmd_pwm(uint8_t argc, char **argv) { pwmInit(); } - printf("Setting frequency ticks to %u%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE); + printf("Setting frequency: %u ticks%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE); pwmSetFrequencyInTicks(frequencyTicks); - printf("Setting duty cycle to %u%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE); + printf("Setting duty cycle: %u%%%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE); pwmSetDutyCycle(dutyCycle); if(! pwmStarted) { pwmStart(); diff --git a/projectconfig.h b/projectconfig.h index 449cc59..4bc4aec 100644 --- a/projectconfig.h +++ b/projectconfig.h @@ -195,11 +195,13 @@ ISL12022M (SRAM) 0xAE 1010111x LM75B 0x90 1001000x MCP24AA 0xA0 1010000x - MCP4725 0xC0 1100000x + MCP4725 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 [1] Alternative addresses may exists, but the addresses listed in this table are the values used in the code base diff --git a/tools/validation/pwm/pwmtest_100ticks_50percent.png b/tools/validation/pwm/pwmtest_100ticks_50percent.png new file mode 100644 index 0000000..42a9eeb Binary files /dev/null and b/tools/validation/pwm/pwmtest_100ticks_50percent.png differ