From 044ad7c3987460ede48ff27afd6bdb0ca05a0432 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 4 Jul 2011 20:52:54 +0200 Subject: import at91lib from at91lib_20100901_softpack_1_9_v_1_0_svn_v15011 it's sad to see that atmel doesn't publish their svn repo or has a centralized location or even puts proper version/release info into the library itself --- components/ads7843/ads7843.c | 264 +++++++++++ components/ads7843/ads7843.dir | 41 ++ components/ads7843/ads7843.h | 69 +++ components/codec-ad1981b/ad1981b.h | 135 ++++++ components/codec-ak4641/ak4641.c | 225 ++++++++++ components/codec-ak4641/ak4641.h | 82 ++++ components/codec-uda1342/uda1342.c | 160 +++++++ components/codec-uda1342/uda1342.dir | 41 ++ components/codec-uda1342/uda1342.h | 157 +++++++ components/codec-wm8731/wm8731.c | 159 +++++++ components/codec-wm8731/wm8731.dir | 41 ++ components/codec-wm8731/wm8731.h | 215 +++++++++ components/codec-wm9711/wm9711.h | 124 ++++++ components/components.dir | 40 ++ components/dac-at73c213/at73c213.c | 337 ++++++++++++++ components/dac-at73c213/at73c213.h | 80 ++++ components/hx8347/hx8347.c | 415 +++++++++++++++++ components/hx8347/hx8347.dir | 41 ++ components/hx8347/hx8347.h | 90 ++++ components/iso7816/iso7816.dir | 45 ++ components/iso7816/iso7816_4.c | 620 ++++++++++++++++++++++++++ components/iso7816/iso7816_4.h | 87 ++++ components/kbmatrix/kbmatrix.c | 304 +++++++++++++ components/kbmatrix/kbmatrix.h | 106 +++++ components/kbmatrix/s7lekkbm/s7lekkbm.c | 119 +++++ components/kbmatrix/s7lekkbm/s7lekkbm.h | 113 +++++ components/omnivision/omnivision.c | 326 ++++++++++++++ components/omnivision/omnivision.dir | 43 ++ components/omnivision/omnivision.h | 82 ++++ components/omnivision/ov2640/2640_yuv_cif.h | 239 ++++++++++ components/omnivision/ov2640/2640_yuv_qvga.h | 243 ++++++++++ components/omnivision/ov2640/2640_yuv_sxga.h | 204 +++++++++ components/omnivision/ov2640/2640_yuv_vga.h | 238 ++++++++++ components/omnivision/ov2640/ov2640.c | 143 ++++++ components/omnivision/ov2640/ov2640.dir | 46 ++ components/omnivision/ov9655/9655_yuv_cif.h | 165 +++++++ components/omnivision/ov9655/9655_yuv_qcif.h | 162 +++++++ components/omnivision/ov9655/9655_yuv_qqcif.h | 163 +++++++ components/omnivision/ov9655/9655_yuv_qqvga.h | 169 +++++++ components/omnivision/ov9655/9655_yuv_qvga.h | 166 +++++++ components/omnivision/ov9655/9655_yuv_sxga.h | 164 +++++++ components/omnivision/ov9655/9655_yuv_vga.h | 168 +++++++ components/omnivision/ov9655/ov9655.c | 163 +++++++ components/omnivision/ov9655/ov9655.dir | 46 ++ components/sensors/ms5540b/ms5540b.c | 327 ++++++++++++++ components/sensors/ms5540b/ms5540b.h | 52 +++ components/slcd/s7leklcd/s7leklcd.c | 271 +++++++++++ components/slcd/s7leklcd/s7leklcd.dir | 40 ++ components/slcd/s7leklcd/s7leklcd.h | 321 +++++++++++++ components/slcd/s7lstklcd/font.h | 71 +++ components/slcd/s7lstklcd/font1.c | 306 +++++++++++++ components/slcd/s7lstklcd/s7lstklcd.c | 187 ++++++++ components/slcd/s7lstklcd/s7lstklcd.dir | 40 ++ components/slcd/s7lstklcd/s7lstklcd.h | 83 ++++ components/tv-encoder/CH7024.c | 292 ++++++++++++ components/tv-encoder/CH7024.h | 73 +++ components/tv-encoder/tv-encoder.dir | 42 ++ 57 files changed, 9145 insertions(+) create mode 100644 components/ads7843/ads7843.c create mode 100644 components/ads7843/ads7843.dir create mode 100644 components/ads7843/ads7843.h create mode 100644 components/codec-ad1981b/ad1981b.h create mode 100644 components/codec-ak4641/ak4641.c create mode 100644 components/codec-ak4641/ak4641.h create mode 100644 components/codec-uda1342/uda1342.c create mode 100644 components/codec-uda1342/uda1342.dir create mode 100644 components/codec-uda1342/uda1342.h create mode 100644 components/codec-wm8731/wm8731.c create mode 100644 components/codec-wm8731/wm8731.dir create mode 100644 components/codec-wm8731/wm8731.h create mode 100644 components/codec-wm9711/wm9711.h create mode 100644 components/components.dir create mode 100644 components/dac-at73c213/at73c213.c create mode 100644 components/dac-at73c213/at73c213.h create mode 100644 components/hx8347/hx8347.c create mode 100644 components/hx8347/hx8347.dir create mode 100644 components/hx8347/hx8347.h create mode 100644 components/iso7816/iso7816.dir create mode 100644 components/iso7816/iso7816_4.c create mode 100644 components/iso7816/iso7816_4.h create mode 100644 components/kbmatrix/kbmatrix.c create mode 100644 components/kbmatrix/kbmatrix.h create mode 100644 components/kbmatrix/s7lekkbm/s7lekkbm.c create mode 100644 components/kbmatrix/s7lekkbm/s7lekkbm.h create mode 100644 components/omnivision/omnivision.c create mode 100644 components/omnivision/omnivision.dir create mode 100644 components/omnivision/omnivision.h create mode 100644 components/omnivision/ov2640/2640_yuv_cif.h create mode 100644 components/omnivision/ov2640/2640_yuv_qvga.h create mode 100644 components/omnivision/ov2640/2640_yuv_sxga.h create mode 100644 components/omnivision/ov2640/2640_yuv_vga.h create mode 100644 components/omnivision/ov2640/ov2640.c create mode 100644 components/omnivision/ov2640/ov2640.dir create mode 100644 components/omnivision/ov9655/9655_yuv_cif.h create mode 100644 components/omnivision/ov9655/9655_yuv_qcif.h create mode 100644 components/omnivision/ov9655/9655_yuv_qqcif.h create mode 100644 components/omnivision/ov9655/9655_yuv_qqvga.h create mode 100644 components/omnivision/ov9655/9655_yuv_qvga.h create mode 100644 components/omnivision/ov9655/9655_yuv_sxga.h create mode 100644 components/omnivision/ov9655/9655_yuv_vga.h create mode 100644 components/omnivision/ov9655/ov9655.c create mode 100644 components/omnivision/ov9655/ov9655.dir create mode 100644 components/sensors/ms5540b/ms5540b.c create mode 100644 components/sensors/ms5540b/ms5540b.h create mode 100644 components/slcd/s7leklcd/s7leklcd.c create mode 100644 components/slcd/s7leklcd/s7leklcd.dir create mode 100644 components/slcd/s7leklcd/s7leklcd.h create mode 100644 components/slcd/s7lstklcd/font.h create mode 100644 components/slcd/s7lstklcd/font1.c create mode 100644 components/slcd/s7lstklcd/s7lstklcd.c create mode 100644 components/slcd/s7lstklcd/s7lstklcd.dir create mode 100644 components/slcd/s7lstklcd/s7lstklcd.h create mode 100644 components/tv-encoder/CH7024.c create mode 100644 components/tv-encoder/CH7024.h create mode 100644 components/tv-encoder/tv-encoder.dir (limited to 'components') diff --git a/components/ads7843/ads7843.c b/components/ads7843/ads7843.c new file mode 100644 index 0000000..9ef1f17 --- /dev/null +++ b/components/ads7843/ads7843.c @@ -0,0 +1,264 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// ADS7843 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include + +#ifdef BOARD_TSC_ADS7843 + +#include +#include + +#include "ads7843.h" + +//------------------------------------------------------------------------------ +// Defines +//------------------------------------------------------------------------------ + +#define ADS_CTRL_PD0 (1 << 0) // PD0 +#define ADS_CTRL_PD1 (1 << 1) // PD1 +#define ADS_CTRL_DFR (1 << 2) // SER/DFR +#define ADS_CTRL_EIGHT_BITS_MOD (1 << 3) // Mode +#define ADS_CTRL_START (1 << 7) // Start Bit +#define ADS_CTRL_SWITCH_SHIFT 4 // Address setting + +#if defined(cortexm3) +// Get X position command +#define CMD_Y_POSITION ((1 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START | ADS_CTRL_PD0 | ADS_CTRL_PD1) +// Get Y position command +#define CMD_X_POSITION ((5 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START | ADS_CTRL_PD0 | ADS_CTRL_PD1) +#else +// Get X position command +#define CMD_X_POSITION ((1 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START | ADS_CTRL_PD0 | ADS_CTRL_PD1) +// Get Y position command +#define CMD_Y_POSITION ((5 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START | ADS_CTRL_PD0 | ADS_CTRL_PD1) +#endif + +// Enable penIRQ +#define CMD_ENABLE_PENIRQ ((1 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START) + + +#define AT91C_TOUCHSCREEN_TIMEOUT 5000000 + +#define DELAY_BEFORE_SPCK (200 << 16) // 2us min (tCSS) <=> 200/100 000 000 = 2us +#define DELAY_BETWEEN_CONS_COM (0xf << 24) // 5us min (tCSH) <=> (32 * 15) / (100 000 000) = 5us + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// Pins used by SPI +static const Pin pinsSPI[] = {BOARD_TSC_SPI_PINS, BOARD_TSC_NPCS_PIN}; + +/// Touch screen BUSY pin +static const Pin pinBusy[] = {PIN_TCS_BUSY}; +/// Touch screen CS pin +static const Pin pinNss[] = {BOARD_TSC_NPCS_PIN}; + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +/// Generic function to send a command to the touchscreen controller +/// \param bCmd command to send +/// \return command result +//----------------------------------------------------------------------------- +static unsigned int SendCommand(unsigned char bCmd) +{ +#if defined(cortexm3) + int i; + AT91S_SPI *spi = BOARD_TSC_SPI_BASE; + unsigned int uResult = 0; + // (volatile declaration needed for code optimisation by compiler) + volatile unsigned char bufferRX[3]; + volatile unsigned char bufferTX[3]; + + bufferRX[0] = 0; + bufferRX[1] = 0; + bufferRX[2] = 0; + + bufferTX[0] = bCmd; + bufferTX[1] = 0; + bufferTX[2] = 0; + + // Send command + i = 0; + while ((spi->SPI_SR & AT91C_SPI_TXEMPTY) == 0); + spi->SPI_TDR = bufferTX[i] | SPI_PCS(BOARD_TSC_NPCS); + while ((spi->SPI_SR & AT91C_SPI_TDRE) == 0); + + while (PIO_Get(pinBusy) == 1); + while ((spi->SPI_SR & AT91C_SPI_RDRF) == 0); + bufferRX[i] = spi->SPI_RDR & 0xFFFF; + + // Read data + for (i = 1; i < 3; i++) { + + while ((spi->SPI_SR & AT91C_SPI_TXEMPTY) == 0); + spi->SPI_TDR = bufferTX[i] | SPI_PCS(BOARD_TSC_NPCS); + while ((spi->SPI_SR & AT91C_SPI_TDRE) == 0); + + while ((spi->SPI_SR & AT91C_SPI_RDRF) == 0); + bufferRX[i] = spi->SPI_RDR & 0xFFFF; + } + + uResult = ((unsigned int)bufferRX[1] << 8) | (unsigned int)bufferRX[2]; + uResult = uResult >> 4; + + return uResult; + +#else // AT91SAM7, SAM9 + + unsigned int uResult = 0; + unsigned int uTimeout = 0; + // (volatile declaration needed for code optimisation by compiler) + volatile unsigned char bufferRX[3]; + volatile unsigned char bufferTX[3]; + + AT91PS_PDC pPdc = (AT91PS_PDC) &(AT91C_BASE_SPI0->SPI_RPR); + unsigned int dStatus; + + bufferRX[0] = 0; + bufferRX[1] = 0; + bufferRX[2] = 0; + + bufferTX[0] = bCmd; + bufferTX[1] = 0; + bufferTX[2] = 0;//bCmd; + + // Send Command and data through the SPI + pPdc->PDC_PTCR = AT91C_PDC_RXTDIS; + pPdc->PDC_RPR = (unsigned int) bufferRX; + pPdc->PDC_RCR = 3; + + pPdc->PDC_PTCR = AT91C_PDC_TXTDIS; + pPdc->PDC_TPR = (unsigned int) bufferTX; + pPdc->PDC_TCR = 3; + + pPdc->PDC_PTCR = AT91C_PDC_RXTEN; + pPdc->PDC_PTCR = AT91C_PDC_TXTEN; + + do { + dStatus = AT91C_BASE_SPI0->SPI_SR; + uTimeout++; + } + while ((( dStatus & AT91C_SPI_RXBUFF) != AT91C_SPI_RXBUFF) && (uTimeout < AT91C_TOUCHSCREEN_TIMEOUT)); + + pPdc->PDC_PTCR = AT91C_PDC_RXTDIS; + pPdc->PDC_PTCR = AT91C_PDC_TXTDIS; + + uResult = ((unsigned int)bufferRX[1] << 8) | (unsigned int)bufferRX[2]; + uResult = uResult >> 4; + + return uResult; +#endif +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +/// Get position of the pen by ask the ADS controller (SPI) +/// \param px_pos pointer to the horizontal position +/// \param py_pos pointer to the vertical position +//----------------------------------------------------------------------------- +void ADS7843_GetPosition(unsigned int* px_pos, unsigned int* py_pos) +{ + // Get X position + *px_pos = SendCommand(CMD_X_POSITION); + // Get Y position + *py_pos = SendCommand(CMD_Y_POSITION); + // Switch to full power mode + SendCommand(CMD_ENABLE_PENIRQ); +} + + +//----------------------------------------------------------------------------- +/// Initialization of the SPI for communication with ADS7843 component +//----------------------------------------------------------------------------- +void ADS7843_Initialize(void) +{ + volatile unsigned int uDummy; + + // Configure pins + PIO_Configure(pinsSPI, PIO_LISTSIZE(pinsSPI)); + + PIO_Configure(pinBusy, PIO_LISTSIZE(pinBusy)); + + SPI_Configure(AT91C_BASE_SPI0, + AT91C_ID_SPI0, + AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | SPI_PCS(BOARD_TSC_NPCS) // Value of the SPI configuration register. + ); + +#if defined(cortexm3) + SPI_ConfigureNPCS(AT91C_BASE_SPI0, BOARD_TSC_NPCS, + AT91C_SPI_NCPHA | (AT91C_SPI_DLYBS & DELAY_BEFORE_SPCK) | AT91C_SPI_CSAAT | + (AT91C_SPI_DLYBCT & DELAY_BETWEEN_CONS_COM) | (0xC8 << 8) ); +#else // AT91SAM7, SAM9 + SPI_ConfigureNPCS(AT91C_BASE_SPI0, BOARD_TSC_NPCS, + AT91C_SPI_NCPHA | (AT91C_SPI_DLYBS & DELAY_BEFORE_SPCK) | + (AT91C_SPI_DLYBCT & DELAY_BETWEEN_CONS_COM) | (0xC8 << 8) ); +#endif + + SPI_Enable(AT91C_BASE_SPI0); + + for (uDummy=0; uDummy<100000; uDummy++); + + uDummy = AT91C_BASE_SPI0->SPI_SR; + uDummy = AT91C_BASE_SPI0->SPI_RDR; + + SendCommand(CMD_ENABLE_PENIRQ); +} + +//----------------------------------------------------------------------------- +/// Reset the ADS7843 +//----------------------------------------------------------------------------- +void ADS7843_Reset(void) +{ + // Disable SPI 0 + SPI_Disable(AT91C_BASE_SPI0); +} + +#endif //#ifdef BOARD_TSC_ADS7843 diff --git a/components/ads7843/ads7843.dir b/components/ads7843/ads7843.dir new file mode 100644 index 0000000..c065103 --- /dev/null +++ b/components/ads7843/ads7843.dir @@ -0,0 +1,41 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains APIs for ADS7843. +/// +/// !!!Contents +/// +/// - ads7843.h api definition for ADS7843. +/// - ads7843.c driver for ADS7843. +//------------------------------------------------------------------------------ diff --git a/components/ads7843/ads7843.h b/components/ads7843/ads7843.h new file mode 100644 index 0000000..4cdcdfa --- /dev/null +++ b/components/ads7843/ads7843.h @@ -0,0 +1,69 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Definition of methods for ADS7843 driver. +/// +/// !!!Usage +/// +/// -# ADS7843_Initialize +/// -# ADS7843_Reset +/// -# ADS7843_GetPosition +//------------------------------------------------------------------------------ + +#ifndef ADS7843_H +#define ADS7843_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include + +#ifdef BOARD_TSC_ADS7843 + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void ADS7843_Initialize(void); + +extern void ADS7843_Reset(void); + +extern void ADS7843_GetPosition(unsigned int* px_pos, unsigned int* py_pos); + +#endif //#ifdef BOARD_TSC_ADS7843 +#endif //#ifndef ADS7843_H diff --git a/components/codec-ad1981b/ad1981b.h b/components/codec-ad1981b/ad1981b.h new file mode 100644 index 0000000..9ee2653 --- /dev/null +++ b/components/codec-ad1981b/ad1981b.h @@ -0,0 +1,135 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 AC97_AD1981B_H +#define AC97_AD1981B_H + +//------------------------------------------------------------------------------ +// External constants +//------------------------------------------------------------------------------ +#define AD1981B_CMD(cmd, data) (((cmd << 16) & AT91C_AC97C_CADDR) | data) + +#define AD1981B_RESET 0x00 // Reset + #define AD1981B_RESET_ID0 (1 << 0) + #define AD1981B_RESET_ID1 (1 << 1) + #define AD1981B_RESET_ID2 (1 << 2) + #define AD1981B_RESET_ID3 (1 << 3) + #define AD1981B_RESET_ID4 (1 << 4) + #define AD1981B_RESET_ID5 (1 << 5) + #define AD1981B_RESET_ID6 (1 << 6) + #define AD1981B_RESET_ID7 (1 << 7) + #define AD1981B_RESET_ID8 (1 << 8) + #define AD1981B_RESET_ID9 (1 << 9) + +#define AD1981B_MASTER 0x02 // Master Volume + #define AD1981B_MASTER_RMV0 (1 << 0) + #define AD1981B_MASTER_RMV1 (1 << 1) + #define AD1981B_MASTER_RMV2 (1 << 2) + #define AD1981B_MASTER_RMV3 (1 << 3) + #define AD1981B_MASTER_RMV4 (1 << 4) + #define AD1981B_MASTER_RM (1 << 7) + #define AD1981B_MASTER_LMV0 (1 << 8) + #define AD1981B_MASTER_LMV1 (1 << 9) + #define AD1981B_MASTER_LMV2 (1 << 10) + #define AD1981B_MASTER_LMV3 (1 << 11) + #define AD1981B_MASTER_LMV4 (1 << 12) + #define AD1981B_MASTER_MM (1 << 15) + +#define AD1981B_HEADPHONE 0x04 // Headphone Volume (optional) + #define AD1981B_HEADPHONE_RHV0 (1 << 0) + #define AD1981B_HEADPHONE_RHV1 (1 << 1) + #define AD1981B_HEADPHONE_RHV2 (1 << 2) + #define AD1981B_HEADPHONE_RHV3 (1 << 3) + #define AD1981B_HEADPHONE_RHV4 (1 << 4) + #define AD1981B_HEADPHONE_RM (1 << 7) + #define AD1981B_HEADPHONE_LHV0 (1 << 8) + #define AD1981B_HEADPHONE_LHV1 (1 << 9) + #define AD1981B_HEADPHONE_LHV2 (1 << 10) + #define AD1981B_HEADPHONE_LHV3 (1 << 11) + #define AD1981B_HEADPHONE_LHV4 (1 << 12) + #define AD1981B_HEADPHONE_HPM (1 << 15) + +#define AD1981B_MASTER_MONO 0x06 // Master Volume Mono (optional) + +#define AD1981B_MASTER_TONE 0x08 // Master Tone (Bass & Treble) (optional) +#define AD1981B_PC_BEEP 0x0a // PC Beep Volume (optinal) +#define AD1981B_PHONE 0x0c // Phone Volume (optional) +#define AD1981B_MIC 0x0e // MIC Volume +#define AD1981B_LINE 0x10 // Line In Volume +#define AD1981B_CD 0x12 // CD Volume +#define AD1981B_VIDEO 0x14 // Video Volume (optional) +#define AD1981B_AUX 0x16 // AUX Volume (optional) +#define AD1981B_PCM 0x18 // PCM Volume +#define AD1981B_REC_SEL 0x1a // Record Select +#define AD1981B_REC_GAIN 0x1c // Record Gain +#define AD1981B_REC_GAIN_MIC 0x1e // Record Gain MIC (optional) +#define AD1981B_GENERAL_PURPOSE 0x20 // General Purpose (optional) +#define AD1981B_3D_CONTROL 0x22 // 3D Control (optional) +#define AD1981B_INT_PAGING 0x24 // Audio Interrupt & Paging (AC'97 2.3) +#define AD1981B_POWERDOWN 0x26 // Powerdown control / status +#define AD1981B_GENPURPOSE_LPBK (1 << 7) +#define AD1981B_GENPURPOSE_LPBK_NO (0 << 7) +#define AD1981B_GENPURPOSE_LPBK_YES (1 << 7) +#define AD1981B_GENPURPOSE_MS (1 << 8) +#define AD1981B_GENPURPOSE_MS_MIC1 (0 << 8) +#define AD1981B_GENPURPOSE_MS_MIC2 (1 << 8) +#define AD1981B_GENPURPOSE_MIX (1 << 9) +#define AD1981B_GENPURPOSE_MIX_MONO (0 << 9) +#define AD1981B_GENPURPOSE_MIX_MIC1 (1 << 9) + +#define AD1981B_EXTAUDIO 0x2A + #define AD1981B_EXTAUDIO_VRA (1 << 0) // Variable Rate Audio + #define AD1981B_EXTAUDIO_SPDIF (1 << 2) // Subsystem Enable/Disable + #define AD1981B_EXTAUDIO_SPSA (3 << 4) // SPDIF Slot Assignment + #define AD1981B_EXTAUDIO_SPCV (1 << 10) // SPDIF Configuration Valid + #define AD1981B_EXTAUDIO_VFORCE (1 << 15) // Validity Force Bit + +#define AD1981B_PMC_DAC 0x2C +#define AD1981B_PMC_ADC 0x32 + +#define AD1981B_SERIAL_CONFIG 0x74 // Serial configuration + #define AD1981B_SERIAL_CONFIG_SPLNK (1 << 0) // SPDIF Link + #define AD1981B_SERIAL_CONFIG_REGM0 (1 << 12) // Master Codec REG Mask + #define AD1981B_SERIAL_CONFIG_REGM1 (1 << 13) // Slave1 Codec REG Mask + #define AD1981B_SERIAL_CONFIG_REGM2 (1 << 14) // Slave2 Codec REG Mask + +#define AD1981B_MISC_CONTROL 0x76 // Miscellaneous control + #define AD1981B_MISC_CONTROL_FMXE (1 << 9) // Front DAC into Mixer Enable + +#define AD1981B_SAMPLE_RATE_0 0x78 // set up the equalizer coefficients. +#define AD1981B_SAMPLE_RATE_1 0x7A // set up the equalizer coefficients. + +#define AD1981B_VENDOR_ID1 0x7C // Vendor 1 +#define AD1981B_VENDOR_ID2 0x7E // Vendor 2 + +#define AD1981B_ID_1 0x4144 +#define AD1981B_ID_2 0x5374 + +#endif //#ifndef AC97_AD1981B_H diff --git a/components/codec-ak4641/ak4641.c b/components/codec-ak4641/ak4641.c new file mode 100644 index 0000000..f53a08d --- /dev/null +++ b/components/codec-ak4641/ak4641.c @@ -0,0 +1,225 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include +#include "ak4641.h" + +//------------------------------------------------------------------------------ +// Internal definitions +//------------------------------------------------------------------------------ + +// 5-bit address of an AK4641 component on the TWI interface +#define AK4641_SLAVEADDRESS 0x12 + +// Register addresses +// Power management 1 register address +#define AK4641_POWMGT1 0x00 +// Power management 2 register address +#define AK4641_POWMGT2 0x01 +// Signal select 2 register address +#define AK4641_SIGSEL2 0x03 +// DAC control register address +#define AK4641_DACCTRL 0x06 +// MIC control register address +#define AK4641_MICCTRL 0x07 + +// Register field values +// Power management 1 register +// Powers up the ADC block of the stereo CODEC +#define AK4641_POWMGT1_PMADC (1 << 0) +// Powers up the MIC in block of the stereo CODEC +#define AK4641_POWMGT1_PMMIC (1 << 1) +// Powers up the AUX in block of the stereo CODEC +#define AK4641_POWMGT1_PMAUX (1 << 2) +// Powers up the Mont out block of the stereo CODEC +#define AK4641_POWMGT1_PMMO (1 << 3) +// Powers up the Line out block of the stereo CODEC +#define AK4641_POWMGT1_PMLO (1 << 4) +// Powers up the VCOM block of the stereo DEOC +#define AK4641_POWMGT1_PMVCM (1 << 7) + +// Power management 2 register +// Powers up the DAC block of the stereo CODEC +#define AK4641_POWMGT2_PMDAC (1 << 0) +// Powers up the Mono out 2 block of the stereo CODEC +#define AK4641_POWMGT2_PMMO2 (1 << 3) +// Sets the master clock input mode to AC-coupling +#define AK4641_POWMGT2_MCKAC (1 << 4) +// Disables the master clock input buffer control +#define AK4641_POWMGT2_MCKPD (1 << 7) + +// Signal select 2 register +// Selects the right channel line output +#define AK4641_SIGSEL2_PSLOR (1 << 0) +// Selects the left channel line output +#define AK4641_SIGSEL2_PSLOL (1 << 1) +// Selects AUX single-ended output +#define AK4641_SIGSEL2_AUXSI (1 << 2) +// Sets MIC in as the line out mixer output +#define AK4641_SIGSEL2_MICL (1 << 4) +// Sets AUX in as the line out mixer output +#define AK4641_SIGSEL2_AUXL (1 << 5) +// Sets the DAC as the line out mixer output +#define AK4641_SIGSEL2_DACL (1 << 7) + +// DAC control register +// De-emphasis filter for a 44.1kHz sample rate +#define AK4641_DACCTRL_DEM44_1 0 +// Disables the de-emphasis filter +#define AK4641_DACCTRL_DEMDIS 1 +// De-emphasis filter for a 48kHz sample rate +#define AK4641_DACCTRL_DEM48 2 +// De-emphasis filter for a 32kHz sample rate +#define AK4641_DACCTRL_DEM32 3 +// Attenuator level for left & right channels controlled by the ATTL6-0 bits +#define AK4641_DACCTRL_DATTC (1 << 4) +// Soft-mutes the DAC +#define AK4641_DACCTRL_SMUTE (1 << 5) +// Sets the soft mute time setting to 256/Fs +#define AK4641_DACCTRL_TM (1 << 6) + +// MIC control register +// Enables the 20dB gain on the microphone input +#define AK4641_MICCTRL_MGAIN (1 << 0) +// Select the microphone as the ADC input +#define AK4641_MICCTRL_MICAD (1 << 2) +// Enables the power supply input for the internal microphone +#define AK4641_MICCTRL_MPWRI (1 << 3) + +//------------------------------------------------------------------------------ +// Internal functions +//------------------------------------------------------------------------------ +/*! + Reads data (using the given \a twi peripheral) from an AK4146 starting with + a particular \a registerAddress and stores it in the provided \a buffer. + Data is read until the buffer is filled to its \a bufferSize. + + This function returns true if the read operation was successful; otherwise + it returns false. + */ +inline unsigned char AK4641_Read(AT91S_TWI *twi, + void *buffer, + unsigned int bufferSize, + unsigned char registerAddress) +{ + return TWI_Read(twi, + buffer, + bufferSize, + AK4641_SLAVEADDRESS, + registerAddress, + 1); +} + +/*! + Writes (through a \a twi interface) the content of the provided \a buffer + in the registers of an AK4641 component, starting at the specified + \a registerAddress. + + This function returns true if the write operation was successful; otherwise + it returns false. + */ +inline unsigned char AK4641_Write(AT91S_TWI *twi, + void *buffer, + unsigned int bufferSize, + unsigned char registerAddress) +{ + return TWI_Write(twi, + buffer, + bufferSize, + AK4641_SLAVEADDRESS, + registerAddress, + 1); +} + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +/*! + Configures an external AK4641 component, through the specified \a twi + interface. + + The TWI interface and the AK4641 master clock must both be already + configured properly before calling this method. + */ +inline void AK4641_Configure(AT91S_TWI *twi) +{ + unsigned char value; + unsigned char values[20]; + + // Power up the ADC and VCOM blocks + value = AK4641_POWMGT1_PMADC | AK4641_POWMGT1_PMVCM; + AK4641_Write(twi, &value, 1, AK4641_POWMGT1); + + // Power up the DAC + value = AK4641_POWMGT2_PMDAC; + AK4641_Write(twi, &value, 1, AK4641_POWMGT2); + + // Select the right and left channel outputs, enable the DAC output + value = AK4641_SIGSEL2_PSLOR | AK4641_SIGSEL2_PSLOL | AK4641_SIGSEL2_DACL; + AK4641_Write(twi, &value, 1, AK4641_SIGSEL2); + + // Disable the de-emphasis filter + value = AK4641_DACCTRL_DEMDIS;// | AK4641_DACCTRL_SMUTE; + AK4641_Write(twi, &value, 1, AK4641_DACCTRL); + + // Enable the MIC 20dB gain and the internal MIC power supply + value = AK4641_MICCTRL_MGAIN | AK4641_MICCTRL_MICAD | AK4641_MICCTRL_MPWRI; + AK4641_Write(twi, &value, 1, AK4641_MICCTRL); + + // Power up the Line out and Mic blocks + value = AK4641_POWMGT1_PMMIC | AK4641_POWMGT1_PMADC + | AK4641_POWMGT1_PMVCM | AK4641_POWMGT1_PMLO; + AK4641_Write(twi, &value, 1, AK4641_POWMGT1); +} + +/*! + Mutes or unmutes an external AK4641 component connected to the given \a twi + peripheral, depending on the value of the \a muted parameter. + */ +inline void AK4641_SetMuted(AT91S_TWI *twi, unsigned char muted) +{ + if (muted) { + + unsigned char value = AK4641_DACCTRL_DEMDIS | AK4641_DACCTRL_SMUTE; + AK4641_Write(twi, &value, 1, AK4641_DACCTRL); + } + else { + + unsigned char value = AK4641_DACCTRL_DEMDIS; + AK4641_Write(twi, &value, 1, AK4641_DACCTRL); + } +} + diff --git a/components/codec-ak4641/ak4641.h b/components/codec-ak4641/ak4641.h new file mode 100644 index 0000000..5eebc45 --- /dev/null +++ b/components/codec-ak4641/ak4641.h @@ -0,0 +1,82 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 AK4641_H +#define AK4641_H + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +/*! Calculates the SSC Transmit Clock Mode Register value given the desired + \a sampleSize (in bytes) and \a numChannels */ +#define AK4641_TCMR(sampleSize, numChannels) \ + (0x02 /* LibV3 constant is not valid */ \ + | AT91C_SSC_CKO_NONE \ + | AT91C_SSC_START_FALL_RF \ + | SSC_STTDLY(1) \ + | SSC_PERIOD(sampleSize * 8 * numChannels)) + +/*! Calculates the SSC Transmit Frame Mode Register value given the desired + \a sampleSize (in bytes) and \a numChannels */ +#define AK4641_TFMR(sampleSize, numChannels) \ + (SSC_DATLEN(sampleSize * 8) \ + | AT91C_SSC_MSBF \ + | SSC_DATNB(numChannels) \ + | SSC_FSLEN(sampleSize * 8) \ + | AT91C_SSC_FSOS_NEGATIVE) + +/*! Calculates the SSC Received Clock Mode Register value given the desired + \a sampleSize (in bytes) and \a numChannels */ +#define AK4641_RCMR(sampleSize, numChannels) \ + (AT91C_SSC_CKS_TK \ + | AT91C_SSC_CKO_NONE \ + | AT91C_SSC_CKI \ + | AT91C_SSC_START_TX \ + | SSC_STTDLY(1) \ + | SSC_PERIOD(sampleSize * 8 * numChannels)) + +/*! Calculates the SSC Receive Frame Mode Register value given the desired + \a sampleSize (in bytes) and \a numChannels. */ +#define AK4641_RFMR(sampleSize, numChannels) \ + (SSC_DATLEN(sampleSize *8) \ + | AT91C_SSC_MSBF \ + | SSC_DATNB(numChannels) \ + | SSC_FSLEN(sampleSize * 8) \ + | AT91C_SSC_FSOS_NEGATIVE) + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern inline void AK4641_Configure(AT91S_TWI *twi); +extern inline void AK4641_SetMuted(AT91S_TWI *twi, unsigned char muted); + +#endif //#ifndef AK4641_H + diff --git a/components/codec-uda1342/uda1342.c b/components/codec-uda1342/uda1342.c new file mode 100644 index 0000000..79cc212 --- /dev/null +++ b/components/codec-uda1342/uda1342.c @@ -0,0 +1,160 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + + //------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// UDA1342 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include "uda1342.h" +#include +#include + +#define TWITIMEOUTMAX 50000 + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +typedef struct { + const char* name; + unsigned char address; + unsigned short defvalue; +} t_register; + +t_register tab_uda1342_register[] = +{ + { "SYSTEM ", UDA1342_REG_SYSTEM , 0x1A02 }, + { "SUB_SYSTEM ", UDA1342_REG_SUB_SYSTEM , 0x0000 }, + { "DAC_FEATURE ", UDA1342_REG_DAC_FEATURE , 0x0000 }, + { "DAC_MASTER_VOLUME", UDA1342_REG_DAC_MASTER_VOLUME, 0x0000 }, + { "DAC_MIXER_VOLUME ", UDA1342_REG_DAC_MIXER_VOLUME , 0x0000 }, + { "GAIN_CH1 ", UDA1342_REG_GAIN_CH1 , 0x0000 }, + { "GAIN_CH2 ", UDA1342_REG_GAIN_CH2 , 0x0000 }, + { "EVALUATION ", UDA1342_REG_EVALUATION , 0x0000 }, +}; + +#define TAB_UDA1342_SIZE (sizeof(tab_uda1342_register)/sizeof(tab_uda1342_register[0])) + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Read data from UDA1342 Register. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +/// \param regAddr register address to read. +//------------------------------------------------------------------------------ +unsigned short UDA1342_Read( + Twid *pTwid, + unsigned char device, + unsigned char regAddr) +{ + unsigned short bitsDataRegister; + unsigned char Tdata[2]={0,0}; + + TWID_Read(pTwid, device, regAddr, 1, Tdata, 2, 0); + bitsDataRegister = (Tdata[0] << 8) | Tdata[1]; + return bitsDataRegister; +} + +//------------------------------------------------------------------------------ +/// Write data to UDA1342 Register. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +/// \param regAddr register address to read. +/// \param data data to write +//------------------------------------------------------------------------------ +void UDA1342_Write( + Twid *pTwid, + unsigned char device, + unsigned char regAddr, + unsigned short data) +{ + unsigned char tmpData[2]; + tmpData[0] = (data & 0xff00) >> 8; + tmpData[1] = data & 0xff; + TWID_Write(pTwid, device, regAddr, 1, tmpData, 2, 0); +} + +//------------------------------------------------------------------------------ +/// Init UDA1342 to DAC mode. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +//------------------------------------------------------------------------------ +unsigned char UDA1342_DAC_Init( + Twid *pTwid, + unsigned int device, + unsigned char isClock384) +{ + // reset all registers to default values + // and set system register + if(isClock384) + UDA1342_Write(pTwid, device, UDA1342_REG_SYSTEM, 0x9A22); + else + UDA1342_Write(pTwid, device, UDA1342_REG_SYSTEM, 0x9A02); + + return 0; +} + +//------------------------------------------------------------------------------ +/// Display component registers +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +//------------------------------------------------------------------------------ +void UDA1342_DisplayRegisters( + Twid *pTwid, + unsigned int device) +{ + unsigned int i; + + TRACE_PERM_WP("UDA1342 registers values\n\r"); + TRACE_PERM_WP("------------------------------------\n\r"); + + for(i=0;i +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +// Master Clock Selector +#define UDA1342_MCK_SEL_256_FS 0 +#define UDA1342_MCK_SEL_384_FS 1 + +//------------------------------------------------------------------------------ +// Register definition +//------------------------------------------------------------------------------ + +// DAC user interface register addresses + +/// \internal UDA1342 system register address +#define UDA1342_REG_SYSTEM 0x00 +/// \internal UDA1342 sub system register address +#define UDA1342_REG_SUB_SYSTEM 0x01 +/// \internal UDA1342 DAC feature register address +#define UDA1342_REG_DAC_FEATURE 0x10 +/// \internal UDA1342 DAC master volume register address +#define UDA1342_REG_DAC_MASTER_VOLUME 0x11 +/// \internal UDA1342 DAC mixer volume register address +#define UDA1342_REG_DAC_MIXER_VOLUME 0x12 +/// \internal UDA1342 DAC ADC input and mixer gain channel 1 register address +#define UDA1342_REG_GAIN_CH1 0x20 +/// \internal UDA1342 DAC ADC input and mixer gain channel 2 register address +#define UDA1342_REG_GAIN_CH2 0x21 +/// \internal UDA1342 DAC evaluation register address +#define UDA1342_REG_EVALUATION 0x30 + +// Register field values +// REG_SYSTEM +#define UDA1342_BIT_SYSTEM_RST (1 << 15) +#define UDA1342_BIT_SYSTEM_QS (1 << 14) +#define UDA1342_BIT_SYSTEM_MDC (1 << 13) +#define UDA1342_BIT_SYSTEM_DC (1 << 12) +#define UDA1342_BIT_SYSTEM_AM2 (1 << 11) +#define UDA1342_BIT_SYSTEM_AM1 (1 << 10) +#define UDA1342_BIT_SYSTEM_AM0 (1 << 9) +#define UDA1342_BIT_SYSTEM_PAD (1 << 8) +#define UDA1342_BIT_SYSTEM_SC1 (1 << 6) +#define UDA1342_BIT_SYSTEM_SC0 (1 << 5) +#define UDA1342_BIT_SYSTEM_IF2 (1 << 4) +#define UDA1342_BIT_SYSTEM_IF1 (1 << 3) +#define UDA1342_BIT_SYSTEM_IF0 (1 << 2) +#define UDA1342_BIT_SYSTEM_DP (1 << 1) +#define UDA1342_BIT_SYSTEM_PDA (1 << 0) + +#define UDA1342_BIT_DAC_FEATURE_DM (1 << 5) + +/* +RST FUNCTION +0 no reset +1 reset registers to default + +SC1 SC0 FUNCTION +0 0 256fs +0 1 384fs +1 0 512fs +1 1 768fs + +IF2 IF1 IF0 FUNCTION + +0 0 0 I S-bus +0 0 1 LSB-justified16 bits +0 1 0 LSB-justified 20 bits +0 1 1 LSB-justified 24 bits +1 0 0 MSB-justified +1 0 1 LSB-justified 16 bits input and MSB-justified output +1 1 0 LSB-justified 20 bits input and MSB-justified output +1 1 1 LSB-justified 24 bits input and MSB-justified output + +MT/MTA/MTB FUNCTION (mute) +0 no muting +1 muting + +QM FUNCTION (quick mute mode) +0 soft mute mode +1 quick mute mode +*/ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern unsigned short UDA1342_Read( + Twid *pTwid, + unsigned char device, + unsigned char regAddr); + +extern void UDA1342_Write( + Twid *pTwid, + unsigned char device, + unsigned char regAddr, + unsigned short data); + +extern unsigned char UDA1342_DAC_Init( + Twid *pTwid, + unsigned int device, + unsigned char isClock384); + +void UDA1342_DisplayRegisters( + Twid *pTwid, + unsigned int device); + +#endif // UDA1342_H + diff --git a/components/codec-wm8731/wm8731.c b/components/codec-wm8731/wm8731.c new file mode 100644 index 0000000..5b5a4e6 --- /dev/null +++ b/components/codec-wm8731/wm8731.c @@ -0,0 +1,159 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + + //------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// WM8731 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include "wm8731.h" +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Internal functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Read data from WM8731 Register. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +/// \param regAddr register address to read. +//------------------------------------------------------------------------------ +unsigned short WM8731_Read(Twid *pTwid, + unsigned int device, + unsigned int regAddr) +{ + unsigned short bitsDataRegister; + unsigned char Tdata[2]={0,0}; + + TWID_Read(pTwid, device, regAddr, 0, Tdata, 2, 0); + bitsDataRegister = (Tdata[0] << 8) | Tdata[1]; + return bitsDataRegister; +} + +//------------------------------------------------------------------------------ +/// Write data to WM8731 Register. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +/// \param regAddr register address to read. +/// \param data data to write +//------------------------------------------------------------------------------ +void WM8731_Write(Twid *pTwid, + unsigned int device, + unsigned int regAddr, + unsigned short data) +{ + unsigned char tmpData[2]; + unsigned short tmp; + tmp = ((regAddr & 0x7f) << 9) | (data & 0x1ff); + + tmpData[0] = (tmp & 0xff00) >> 8; + tmpData[1] = tmp & 0xff; + TWID_Write(pTwid, device, regAddr, 0, tmpData, 2, 0); +} + +//------------------------------------------------------------------------------ +/// Init WM8731 to DAC mode. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +//------------------------------------------------------------------------------ +unsigned char WM8731_DAC_Init(Twid *pTwid, + unsigned int device) +{ + // reset + WM8731_Write(pTwid, device, WM8731_REG_RESET, 0); + + // analogue audio path control + WM8731_Write(pTwid, device, WM8731_REG_ANALOGUE_PATH_CTRL, 0x12); + + // digital audio path control + WM8731_Write(pTwid, device, WM8731_REG_DIGITAL_PATH_CTRL, 0x00); + + // power down control + WM8731_Write(pTwid, device, WM8731_REG_PWDOWN_CTRL, 0x7); + + // Active control + WM8731_Write(pTwid, device, WM8731_REG_ACTIVE_CTRL, 0x01); + + return 0; +} + +//------------------------------------------------------------------------------ +/// Power down WM8731 DAC. +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +//------------------------------------------------------------------------------ +void WM8731_DAC_PD(Twid *pTwid, + unsigned int device) +{ + // power down control + WM8731_Write(pTwid, device, WM8731_REG_PWDOWN_CTRL, 0xf); +} + + +//------------------------------------------------------------------------------ +/// Set WM8731 volume +/// \param pTwid pointer to twi driver structure +/// \param device twi slave address +/// \param register register address +/// \param value register value, valid value is between 0x30 to 0x7f +//------------------------------------------------------------------------------ +unsigned char WM8731_VolumeSet(Twid *pTwid, + unsigned int device, + unsigned short value) +{ + unsigned short regValue; + + value &= WM8731_LHPVOL_BITS; + regValue = WM8731_LRHPBOTH_BIT | WM8731_LZCEN_BIT | value; + WM8731_Write(pTwid, device, WM8731_REG_LEFT_HPOUT, regValue); + regValue = WM8731_RZCEN_BIT | WM8731_RLHPBOTH_BIT | value; + WM8731_Write(pTwid, device, WM8731_REG_RIGHT_HPOUT, value); + + return 0; +} + diff --git a/components/codec-wm8731/wm8731.dir b/components/codec-wm8731/wm8731.dir new file mode 100644 index 0000000..58a29b9 --- /dev/null +++ b/components/codec-wm8731/wm8731.dir @@ -0,0 +1,41 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains APIs for WM8731 Codec. +/// +/// !!!Contents +/// +/// - wm8731.h api definition for WM8731 Codec. +/// - wm8731.c driver for WM8731 Codec. +//------------------------------------------------------------------------------ diff --git a/components/codec-wm8731/wm8731.h b/components/codec-wm8731/wm8731.h new file mode 100644 index 0000000..9cb60e5 --- /dev/null +++ b/components/codec-wm8731/wm8731.h @@ -0,0 +1,215 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Definition of methods for WM8731 driver. +/// +/// !!!Usage +/// +/// -# WM8731_Read +/// -# WM8731_Write +/// -# WM8731_DAC_Init +//------------------------------------------------------------------------------ + +#ifndef WM8731_H +#define WM8731_H + +#include "board.h" +#include "twi/twid.h" + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +#define WM8731_CSB_STATE (0x0 << 0) + +/// Slave address +//#define WM8731_SLAVE_ADDRESS 0x1a | WM8731_CSB_STATE +#define WM8731_SLAVE_ADDRESS 0x1b + + +/// Reset register +#define WM8731_REG_RESET 0x0F + +/// Left Line in register +#define WM8731_REG_LEFT_lINEIN 0x0 +/// Left line input volume control +#define WM8731_LINVOL_BITS (0x1f << 0) +/// Left line input mute to ADC +#define WM8731_LINMUTE_BIT (0x1 << 7) +/// Left to right channel line input volume and mute data load control +#define WM8731_LRINBOTH_BIT (0x0 << 8) + +/// Right Line in register +#define WM8731_REG_RIGHT_lINEIN 0x1 +/// Right line input volume control +#define WM8731_RINVOL_BITS (0x1f << 0) +/// Right line input mute to ADC +#define WM8731_RINMUTE_BIT (0x1 << 7) +/// Right to right channel line input volume and mute data load control +#define WM8731_RLINBOTH_BIT (0x0 << 8) + +/// Left Headphone out register +#define WM8731_REG_LEFT_HPOUT 0x2 +/// Left chnnel headphone output volume control +#define WM8731_LHPVOL_BITS (0x7f << 0) +/// Left channel zero cross detect enable +#define WM8731_LZCEN_BIT (0x1 << 7) +/// Left to right channel headphone volume, mute and zero cross data load control +#define WM8731_LRHPBOTH_BIT (0x1 << 8) + +/// Right Headphone out register +#define WM8731_REG_RIGHT_HPOUT 0x3 +/// Right chnnel headphone output volume control +#define WM8731_RHPVOL_BITS (0x7f << 0) +/// Right channel zero cross detect enable +#define WM8731_RZCEN_BIT (0x1 << 7) +/// Right to right channel headphone volume, mute and zero cross data load control +#define WM8731_RLHPBOTH_BIT (0x1 << 8) + +/// Analogue audio path control register +#define WM8731_REG_ANALOGUE_PATH_CTRL 0x4 + +/// Digital audio path control register +#define WM8731_REG_DIGITAL_PATH_CTRL 0x5 + +/// Power down control register +#define WM8731_REG_PWDOWN_CTRL 0x6 +/// LineIn power down +#define WM8731_LINEINPD_BIT (0x1 << 0) +#define WM8731_ENABLE_LINEINPD (0x1 << 0) +#define WM8731_DISABLE_LINEINPD (0x0 << 0) +/// Mic power down +#define WM8731_MICPD_BIT (0x1 << 1) +#define WM8731_ENABLE_MICPD (0x1 << 1) +#define WM8731_DISABLE_MICPD (0x0 << 1) +/// ADC power down +#define WM8731_ADCPD_BIT (0x1 << 2) +#define WM8731_ENABLE_ADCPD (0x1 << 2) +#define WM8731_DISABLE_ADCPD (0x0 << 2) +/// DAC power down +#define WM8731_DACPD_BIT (0x1 << 3) +#define WM8731_ENABLE_DACPD (0x1 << 3) +#define WM8731_DISABLE_DACPD (0x0 << 3) +/// OUT power down +#define WM8731_OUTPD_BIT (0x1 << 4) +#define WM8731_ENABLE_OUTPD (0x1 << 4) +#define WM8731_DISABLE_OUTPD (0x0 << 4) +/// OSC power down +#define WM8731_OSCBIT (0x1 << 5) +#define WM8731_ENABLE_OSCPD (0x1 << 5) +#define WM8731_DISABLE_OSCPD (0x0 << 5) +/// CLKOUT powerdown +#define WM8731_CLKOUTPD_BIT (0x1 << 6) +#define WM8731_ENABLE_CLKOUTPD (0x1 << 6) +#define WM8731_DISABLE_CLKOUTPD (0x0 << 6) +/// Power off device +#define WM8731_POWEROFF_BIT (0x1 << 7) +#define WM8731_DEV_POWER_OFF (0x1 << 7) +#define WM8731_DEV_POWER_ON (0x0 << 7) + +/// Interface format register +#define WM8731_REG_DA_INTERFACE_FORMAT 0x7 +/// Format +#define WM8731_FORMAT_BITS (0x3 << 0) +#define WM8731_FORMAT_MSB_LEFT_JUSTIFIED (0x0 << 0) +#define WM8731_FORMAT_MSB_RIGHT_JUSTIFIED (0x1 << 0) +#define WM8731_FORMAT_I2S (0x2 << 0) +#define WM8731_FORMAT_DSP (0x3 << 0) +/// Input audio data bit length select +#define WM8731_IWL_BITS (0x3 << 2) +#define WM8731_IWL_16_BIT (0x0 << 2) +#define WM8731_IWL_20_BIT (0x1 << 2) +#define WM8731_IWL_24_BIT (0x2 << 2) +#define WM8731_IWL_32_BIT (0x3 << 2) +/// DACLRC phase control +#define WM8731_IRP_BITS (0x1 << 4) +/// DAC Left right clock swap +#define WM8731_IRSWAP_BIT (0x1 << 5) +/// Master slave mode control +#define WM8731_MS_BIT (0x1 << 6) +#define WM8731_ENABLE_MASTER_MODE (0x1 << 6) +#define WM8731_ENABLE_SLAVE_MODE (0x0 << 6) +/// Bit clock invert +#define WM8731_BCLKINV_BIT (0x1 << 7) + +/// Sampling control +#define WM8731_REG_SAMPLECTRL 0x8 +/// Mode select, usb mode, normal mode +#define WM8731_USBNORMAL_BIT (0x1 << 0) +#define WM8731_NORMAL_MODE (0x1 << 0) +#define WM8731_USB_MODE (0x1 << 1) +/// Base over-sampling rate +#define WM8731_BOSR_BIT (0x1 << 1) +#define WM8731_USB_250FS (0x0 << 1) +#define WM8731_USB_272FS (0x1 << 1) +#define WM8731_NORMAL_256FS (0x0 << 1) +#define WM8731_NORMAL_128_192_384_FS (0x1 << 1) +/// Sample rate control +#define WM8731_SR_BITS (0xf << 2) +/// +#define WM8731_CLKIDIV2_BIT (0x1 << 6) +/// +#define WM8731_CLKODIV2_BIT (0x1 << 7) + +/// Active control register +#define WM8731_REG_ACTIVE_CTRL 0x9 +/// Activate interface +#define WM8731_ACTIVE_BIT (0x1 << 0) +#define WM8731_ACTIVE_INTERFACE_ACTIVE (0x1 << 1) +#define WM8731_ACTIVE_INTERFACE_INACTIVE (0x0 << 1) + + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern unsigned short WM8731_Read(Twid *pTwid, + unsigned int device, + unsigned int register); + +extern void WM8731_Write(Twid *pTwid, + unsigned int device, + unsigned int register, + unsigned short data); + +extern unsigned char WM8731_DAC_Init(Twid *pTwid, + unsigned int device); +extern void WM8731_DAC_PD(Twid *pTwid, + unsigned int device); +extern unsigned char WM8731_VolumeSet(Twid *pTwid, + unsigned int device, + unsigned short value); + +#endif // WM8731_H + diff --git a/components/codec-wm9711/wm9711.h b/components/codec-wm9711/wm9711.h new file mode 100644 index 0000000..52b3c5a --- /dev/null +++ b/components/codec-wm9711/wm9711.h @@ -0,0 +1,124 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2009, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 AC97_WM9711_H +#define AC97_WM9711_H + +//------------------------------------------------------------------------------ +// External constants +//------------------------------------------------------------------------------ +#define WM9711_CMD(cmd, data) (((cmd << 16) & AT91C_AC97C_CADDR) | data) + + +#define WM9711_RESET 0x00 + +#define WM9711_LRVOLUME 0x02 + +#define WM9711_HPVOLUME 0x04 + +#define WM9711_MONOVOLUME 0x06 + +#define WM9711_DACTONECTL 0x08 + +#define WM9711_PCBEEPINPUT 0x0A + +#define WM9711_PHONEVOLUME 0x0C + +#define WM9711_MICVOLUME 0x0E + +#define WM9711_LINEINVOLUME 0x10 + +#define WM9711_AUXDACVOLUME 0x12 + +#define WM9711_SIDETONEVOLUME 0x14 + +#define WM9711_OUT3VOLUME 0x16 + +#define WM9711_DACVOLUME 0x18 + +#define WM9711_RECORDSEL 0x1A + +#define WM9711_RECORDGAIN 0x1C + +#define WM9711_GENERALPURPOSE 0x20 + +#define WM9711_DAC3DCTL 0x22 + +#define WM9711_POWERDOWN 0x24 + +#define WM9711_POWERDOWNCTL 0x26 + +#define WM9711_EXAUDIOID 0x28 + +#define WM9711_EXAUDIOCTL 0x2A + +#define WM9711_DACSAMPLERATE 0x2C + +#define WM9711_AUXDACSAMPLERATE 0x2E + +#define WM9711_ADCSAMPLERATE 0x32 + +#define WM9711_SPDIFCTL 0x3A + +#define WM9711_PINCONFIG 0x4C + +#define WM9711_PINPOL 0x4E + +#define WM9711_PINSTICKY 0x50 + +#define WM9711_PINWAKEUP 0x52 + +#define WM9711_PINSTATUS 0x54 + +#define WM9711_PINASSIGNMENT 0x56 + +#define WM9711_PINFUNCTIONS 0x58 + +#define WM9711_VENDORRESERVED1 0x5A + +#define WM9711_FUNCTIONCTL 0x5C + +#define WM9711_VENDORRESERVED2 0x5E + +#define WM9711_ALCCTL 0x60 + +#define WM9711_NOISECTL 0x62 + +#define WM9711_AUXDACINPUT 0x64 + +#define WM9711_VENDOR_ID1 0x7C // Vendor 1 + +#define WM9711_VENDOR_ID2 0x7E // Vendor 2 + +#define WM9711_ID_1 0x574D //ASCII "W" "M" + +#define WM9711_ID_2 0x4C12 //ASCII "L" number "12" + +#endif //#ifndef AC97_WM9711_H diff --git a/components/components.dir b/components/components.dir new file mode 100644 index 0000000..8c850f2 --- /dev/null +++ b/components/components.dir @@ -0,0 +1,40 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains several sub-directories, each one corresponding to +/// a components driver. +/// +/// Each components driver is used for a external components used by AT91 chips +/// (like DACs, etc.) but not directly integrated. +//------------------------------------------------------------------------------ \ No newline at end of file diff --git a/components/dac-at73c213/at73c213.c b/components/dac-at73c213/at73c213.c new file mode 100644 index 0000000..0ace517 --- /dev/null +++ b/components/dac-at73c213/at73c213.c @@ -0,0 +1,337 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "at73c213.h" +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// \internal Calculates the SSC Transmit Clock Mode Register value given the +/// desired sample size (in bytes) and number of channels. +#define AT73C213_TCMR(sampleSize, numChannels) \ + (AT91C_SSC_CKS_DIV \ + | AT91C_SSC_CKO_DATA_TX \ + | AT91C_SSC_START_FALL_RF \ + | SSC_STTDLY(1) \ + | SSC_PERIOD(sampleSize * 8 * numChannels)) + +/// \internal Calculates the SSC Transmit Frame Mode Register value given the +/// desired sample size (in bytes) and number of channels. +#define AT73C213_TFMR(sampleSize, numChannels) \ + (SSC_DATLEN(sampleSize * 8) \ + | AT91C_SSC_MSBF \ + | SSC_DATNB(numChannels) \ + | SSC_FSLEN(sampleSize * 8) \ + | AT91C_SSC_FSOS_NEGATIVE) + +/// \internal Maximum bitrate of AT73C213 SPI interface +#define AT73C213_SPCK_MAX 250000 + +/// \internal Calculates the SPI chip select configuration, given the system +/// master clock. +#define AT73C213_SPI_NPCSCONFIG(masterClock) \ + (AT91C_SPI_BITS_16 \ + | SPI_SCBR(AT73C213_SPCK_MAX, masterClock) \ + | SPI_DLYBS(50, masterClock) \ + | SPI_DLYBCT(0, masterClock)) + +// DAC user interface register addresses +/// \internal AT73C213 DAC control register address +#define AT73C213_DAC_CTRL 0x00 +/// \internal AT73C213 DAC left line in gain register address +#define AT73C213_DAC_LLIG 0x01 +/// \internal AT73C213 DAC right line in gain register address +#define AT73C213_DAC_RLIG 0x02 +/// \internal AT73C213 DAC left master playback gain register address +#define AT73C213_DAC_LMPG 0x03 +/// \internal AT73C213 DAC right master playback gain register address +#define AT73C213_DAC_RMPG 0x04 +/// \internal AT73C213 DAC left line out gain register address +#define AT73C213_DAC_LLOG 0x05 +/// \internal AT73C213 DAC right line out gain register address +#define AT73C213_DAC_RLOG 0x06 +/// \internal AT73C213 DAC output level control register address +#define AT73C213_DAC_OLC 0x07 +/// \internal AT73C213 DAC mixer control register address +#define AT73C213_DAC_MC 0x08 +/// \internal AT73C213 DAC clock and sampling frequency control register address +#define AT73C213_DAC_CSFC 0x09 +/// \internal AT73C213 DAC miscellaneous register address +#define AT73C213_DAC_MISC 0x0A +/// \internal AT73C213 DAC precharge control register address +#define AT73C213_DAC_PRECH 0x0C +/// \internal AT73C213 DAC auxiliary input gain control register address +#define AT73C213_DAC_AUXG 0x0D +/// \internal AT73C213 DAC reset register address +#define AT73C213_DAC_RST 0x10 +/// \internal AT73C213 power amplifier control register address +#define AT73C213_PA_CTRL 0x11 + +// Register field values +// DAC_CTRL +/// \internal Left channel line in amplifier enable +#define AT73C213_DAC_CTRL_ONLNIL (1 << 0) +/// \internal Right channel line in amplifier enable +#define AT73C213_DAC_CTRL_ONLNIR (1 << 1) +/// \internal Left channel line out driver enable +#define AT73C213_DAC_CTRL_ONLNOL (1 << 2) +/// \internal Right channel line out driver enable +#define AT73C213_DAC_CTRL_ONLNOR (1 << 3) +/// \internal Left channel DAC enable +#define AT73C213_DAC_CTRL_ONDACL (1 << 4) +/// \internal Right channel DAC enable +#define AT73C213_DAC_CTRL_ONDACR (1 << 5) +/// \internal Differential mono auxiliary input amplifier enable +#define AT73C213_DAC_CTRL_ONAUXIN (1 << 6) +/// \internal Differential mono power amplifier driver enable +#define AT73C213_DAC_CTRL_ONPADRV (1 << 7) + +// DAC_LLOG +/// \internal Digital gain of 0dB +#define AT73C213_DAC_LLOG_GAIN_0 0x00 +/// \internal Digital gain of -10.5dB +#define AT73C213_DAC_LLOG_GAIN_10_5N 0x07 +/// \internal Channel muted +#define AT73C213_DAC_LLOG_GAIN_MUTE 0x3F + +// DAC_RLOG +/// \internal Digital gain of 0dB +#define AT73C213_DAC_RLOG_GAIN_0 0x00 +/// \internal Digital gain of -10.5dB +#define AT73C213_DAC_RLOG_GAIN_10_5N 0x07 +/// \internal Channel muted +#define AT73C213_DAC_RLOG_GAIN_MUTE 0x3F + +// DAC_CSFC +/// \internal Master clock selector +#define AT73C213_DAC_CSFC_OVRSEL (1 << 4) + +// DAC_PRECH +/// \internal Master power on control +#define AT73C213_DAC_PRECH_ONMSTR (1 << 0) +/// \internal Precharge all mask +#define AT73C213_DAC_PRECH_ALL 0xFE + +// DAC_RST +/// \internal Active low reset of the audio codec +#define AT73C213_DAC_RST_RSTZ (1 << 0) +/// \internal Active low reset of the audio codec filter +#define AT73C213_DAC_RST_RESFILZ (1 << 1) +/// \internal Active high reset mask of the audio codec +#define AT73C213_DAC_RST_RESMASK (1 << 2) + +// PA_CTRL +/// \internal Audio power amplifier gain: -22dB +#define AT73C213_PA_CTRL_APAGAIN_22N 0xF +/// \internal Audio power amplifier gain: 8dB +#define AT73C213_PA_CTRL_APAGAIN_8 0x5 +/// \internal Audio power amplifier gain: -1dB +#define AT73C213_PA_CTRL_APAGAIN_1N 0x8 +/// \internal Audio power amplifier precharge bit +#define AT73C213_PA_CTRL_APAPRECH (1 << 5) +/// \internal Audio power amplifier on bit +#define AT73C213_PA_CTRL_APAON (1 << 6) + +//------------------------------------------------------------------------------ +// Internal functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Writes a byte of data at the given address of the DAC SPI user interface. +/// \param address Register address to write. +/// \param data New register value. +//------------------------------------------------------------------------------ +void AT73C213_Write(unsigned char address, unsigned char data) +{ + SPI_Write(BOARD_AT73C213_SPI, + BOARD_AT73C213_SPI_NPCS, + ((address & 0x7F) << 8) | (data & 0xFF)); +} + +//------------------------------------------------------------------------------ +/// Reads and returns a byte of data read at the given address of the DAC SPI +/// user interface. +/// \param address Register address to read. +//------------------------------------------------------------------------------ +unsigned char AT73C213_Read(unsigned char address) +{ + SPI_Write(BOARD_AT73C213_SPI, + BOARD_AT73C213_SPI_NPCS, + (1 << 15) | ((address & 0x7F) << 8)); + return SPI_Read(BOARD_AT73C213_SPI) & 0xFF; +} + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Enables the AT73C213 DAC to operate using the specified sample frequency (in +/// Hz), sample size (in bytes) and number of channels. If the master clock +/// sent to the DAC is equal to 384*Fs, then isClock384 must be 1; otherwise it +/// must be 0. +/// \param Fs Desired sampling frequency in Hz. +/// \param sampleSize Size of one sample in bytes. +/// \param numChannels Number of audio channels used. +/// \param isClock384 Must be 1 if DACmck = 384*Fs, 0 if DACmck = 256*Fs. +/// \param masterClock Frequency of the system master clock. +//------------------------------------------------------------------------------ +void AT73C213_Enable(unsigned int Fs, + unsigned int sampleSize, + unsigned int numChannels, + unsigned char isClock384, + unsigned int masterClock) +{ + // Configure the SPI peripheral chip select + SPI_ConfigureNPCS(BOARD_AT73C213_SPI, + BOARD_AT73C213_SPI_NPCS, + AT73C213_SPI_NPCSCONFIG(masterClock)); + + // DAC startup sequence + // De-assert reset + AT73C213_Write(AT73C213_DAC_RST, + AT73C213_DAC_RST_RSTZ + | AT73C213_DAC_RST_RESFILZ); + + // Precharge and turn on master power + AT73C213_Write(AT73C213_DAC_PRECH, + AT73C213_DAC_PRECH_ONMSTR + | AT73C213_DAC_PRECH_ALL); + + // Enable line out drivers + AT73C213_Write(AT73C213_DAC_CTRL, + AT73C213_DAC_CTRL_ONLNOL + | AT73C213_DAC_CTRL_ONLNOR); + + // TODO 500 ms delay + + // Stop precharging + AT73C213_Write(AT73C213_DAC_PRECH, AT73C213_DAC_PRECH_ONMSTR); + + // TODO 1ms delay + + // Enable DACs + AT73C213_Write(AT73C213_DAC_CTRL, + AT73C213_DAC_CTRL_ONLNOL + | AT73C213_DAC_CTRL_ONLNOR + | AT73C213_DAC_CTRL_ONDACL + | AT73C213_DAC_CTRL_ONDACR); + + // Select master clock speed + if (isClock384) { + + AT73C213_Write(AT73C213_DAC_CSFC, AT73C213_DAC_CSFC_OVRSEL); + } + + // Output DAC register values + unsigned int i; + TRACE_DEBUG_WP("DAC register values:\n\r"); + for (i=0; i <= AT73C213_PA_CTRL; i++) { + + TRACE_DEBUG_WP(" - @0x%02X = 0x%02X\n\r", i, AT73C213_Read(i)); + } + + // Unmute channels + AT73C213_SetMuteStatus(0, 0); + + // Configure the SSC + SSC_Configure(BOARD_AT73C213_SSC, + BOARD_AT73C213_SSC_ID, + Fs * sampleSize * 8 * numChannels, + masterClock); + SSC_ConfigureTransmitter(BOARD_AT73C213_SSC, + AT73C213_TCMR(sampleSize, numChannels), + AT73C213_TFMR(sampleSize, numChannels)); + SSC_EnableTransmitter(BOARD_AT73C213_SSC); +} + +//------------------------------------------------------------------------------ +/// Disables the AT73C213 DAC. +//------------------------------------------------------------------------------ +void AT73C213_Disable() +{ + // Set gain to -22dB + AT73C213_Write(AT73C213_PA_CTRL, + AT73C213_PA_CTRL_APAGAIN_22N | + AT73C213_PA_CTRL_APAON); + + // Turn off power amplifier + AT73C213_Write(AT73C213_PA_CTRL, AT73C213_PA_CTRL_APAGAIN_22N); + + // Disable DACs + AT73C213_Write(AT73C213_DAC_CTRL, + AT73C213_DAC_CTRL_ONLNOL + | AT73C213_DAC_CTRL_ONLNOR); + + // Disable master power + AT73C213_Write(AT73C213_DAC_PRECH, 0); + + // TODO 1ms delay + + // Power off everything + AT73C213_Write(AT73C213_DAC_CTRL, 0); +} + +//------------------------------------------------------------------------------ +/// Mutes or unmutes the left and/or right channel. +/// \param leftChannelMuted Indicates the new status of the left audio channel. +/// \param rightChannelMuted New status of the right audio channel. +//------------------------------------------------------------------------------ +void AT73C213_SetMuteStatus(unsigned char leftChannelMuted, + unsigned char rightChannelMuted) +{ + // Update left channel status + if (leftChannelMuted) { + + AT73C213_Write(AT73C213_DAC_LLOG, AT73C213_DAC_LLOG_GAIN_MUTE); + } + else { + + AT73C213_Write(AT73C213_DAC_LLOG, AT73C213_DAC_LLOG_GAIN_10_5N); + } + + // Update right channel status + if (rightChannelMuted) { + + AT73C213_Write(AT73C213_DAC_RLOG, AT73C213_DAC_RLOG_GAIN_MUTE); + } + else { + + AT73C213_Write(AT73C213_DAC_RLOG, AT73C213_DAC_RLOG_GAIN_10_5N); + } +} + diff --git a/components/dac-at73c213/at73c213.h b/components/dac-at73c213/at73c213.h new file mode 100644 index 0000000..897a40f --- /dev/null +++ b/components/dac-at73c213/at73c213.h @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// !Purpose +/// +/// Definitions and methods for using a single external AT73C213 DAC. Several +/// constants must be declared at the board.h level for that: +/// - BOARD_AT73C213_SPI +/// - BOARD_AT73C213_SPI_ID +/// - BOARD_AT73C213_NPCS +/// - BOARD_AT73C213_SSC +/// - BOARD_AT73C213_SSC_ID +/// +/// !Usage +/// +/// -# Configure the mode register of the SPI associated with the DAC and +/// enable the SPI peripheral (see spi.h). +/// -# Enable the master clock of the DAC (usually, it will be connected to +/// a programmable clock output). +/// -# Call the AT73C213_Enable function with the desired parameters. This +/// function configures the associated NPCS register of the SPI for correct +/// interfacing with the DAC, starts the DAC and configures the SSC. +/// -# Send audio data to the DAC using the SSC, with SSC_WriteBuffer or +/// SSC_Write. +//------------------------------------------------------------------------------ + +#ifndef AT73C213_H +#define AT73C213_H + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +// Master Clock Selector +#define AT73C213_MCK_SEL_256_FS 0 +#define AT73C213_MCK_SEL_384_FS 1 + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ + +extern void AT73C213_Enable(unsigned int Fs, + unsigned int sampleSize, + unsigned int numChannels, + unsigned char isClock384, + unsigned int masterClock); +extern void AT73C213_Disable(); +extern void AT73C213_SetMuteStatus(unsigned char leftChannelMuted, + unsigned char rightChannelMuted); + +#endif //#ifndef AT73C213_H + diff --git a/components/hx8347/hx8347.c b/components/hx8347/hx8347.c new file mode 100644 index 0000000..bc80d08 --- /dev/null +++ b/components/hx8347/hx8347.c @@ -0,0 +1,415 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// HX8347 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include +#include + +#ifdef BOARD_LCD_HX8347 + +#include "hx8347.h" + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ +typedef volatile unsigned short REG16; + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// LCD index register address +#define LCD_IR(baseAddr) (*((REG16 *)(baseAddr))) +/// LCD status register address +#define LCD_SR(baseAddr) (*((REG16 *)(baseAddr))) +/// LCD data address +#define LCD_D(baseAddr) (*((REG16 *)((unsigned int)(baseAddr) + BOARD_LCD_RS))) + +/// HX8347 ID code +#define HX8347_HIMAXID_CODE 0x47 + +/// HX8347 LCD Registers +#define HX8347_R00H 0x00 +#define HX8347_R01H 0x01 +#define HX8347_R02H 0x02 +#define HX8347_R03H 0x03 +#define HX8347_R04H 0x04 +#define HX8347_R05H 0x05 +#define HX8347_R06H 0x06 +#define HX8347_R07H 0x07 +#define HX8347_R08H 0x08 +#define HX8347_R09H 0x09 +#define HX8347_R0AH 0x0A +#define HX8347_R0CH 0x0C +#define HX8347_R0DH 0x0D +#define HX8347_R0EH 0x0E +#define HX8347_R0FH 0x0F +#define HX8347_R10H 0x10 +#define HX8347_R11H 0x11 +#define HX8347_R12H 0x12 +#define HX8347_R13H 0x13 +#define HX8347_R14H 0x14 +#define HX8347_R15H 0x15 +#define HX8347_R16H 0x16 +#define HX8347_R18H 0x18 +#define HX8347_R19H 0x19 +#define HX8347_R1AH 0x1A +#define HX8347_R1BH 0x1B +#define HX8347_R1CH 0x1C +#define HX8347_R1DH 0x1D +#define HX8347_R1EH 0x1E +#define HX8347_R1FH 0x1F +#define HX8347_R20H 0x20 +#define HX8347_R21H 0x21 +#define HX8347_R22H 0x22 +#define HX8347_R23H 0x23 +#define HX8347_R24H 0x24 +#define HX8347_R25H 0x25 +#define HX8347_R26H 0x26 +#define HX8347_R27H 0x27 +#define HX8347_R28H 0x28 +#define HX8347_R29H 0x29 +#define HX8347_R2AH 0x2A +#define HX8347_R2BH 0x2B +#define HX8347_R2CH 0x2C +#define HX8347_R2DH 0x2D +#define HX8347_R35H 0x35 +#define HX8347_R36H 0x36 +#define HX8347_R37H 0x37 +#define HX8347_R38H 0x38 +#define HX8347_R39H 0x39 +#define HX8347_R3AH 0x3A +#define HX8347_R3BH 0x3B +#define HX8347_R3CH 0x3C +#define HX8347_R3DH 0x3D +#define HX8347_R3EH 0x3E +#define HX8347_R40H 0x40 +#define HX8347_R41H 0x41 +#define HX8347_R42H 0x42 +#define HX8347_R43H 0x43 +#define HX8347_R44H 0x44 +#define HX8347_R45H 0x45 +#define HX8347_R46H 0x46 +#define HX8347_R47H 0x47 +#define HX8347_R48H 0x48 +#define HX8347_R49H 0x49 +#define HX8347_R4AH 0x4A +#define HX8347_R4BH 0x4B +#define HX8347_R4CH 0x4C +#define HX8347_R4DH 0x4D +#define HX8347_R4EH 0x4E +#define HX8347_R4FH 0x4F +#define HX8347_R50H 0x50 +#define HX8347_R51H 0x51 +#define HX8347_R64H 0x64 +#define HX8347_R65H 0x65 +#define HX8347_R66H 0x66 +#define HX8347_R67H 0x67 +#define HX8347_R70H 0x70 +#define HX8347_R72H 0x72 +#define HX8347_R90H 0x90 +#define HX8347_R91H 0x91 +#define HX8347_R93H 0x93 +#define HX8347_R94H 0x94 +#define HX8347_R95H 0x95 + +//------------------------------------------------------------------------------ +// External functions +//------------------------------------------------------------------------------ +// External delay 1 ms function +extern void DelayMS(unsigned int ms); +#define Delay(ms) DelayMS(ms) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Write data to LCD Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \param data Data to be written. +//------------------------------------------------------------------------------ +void LCD_WriteReg(void *pLcdBase, unsigned char reg, unsigned short data) +{ + LCD_IR(pLcdBase) = reg; + LCD_D(pLcdBase) = data; +} + +//------------------------------------------------------------------------------ +/// Read data from LCD Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \return data Data to be read. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadReg(void *pLcdBase, unsigned char reg) +{ + LCD_IR(pLcdBase) = reg; + return LCD_D(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Read LCD status Register. +/// \param pLcdBase LCD base address. +/// \param reg Register address. +/// \return data Status Data. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadStatus(void *pLcdBase) +{ + return LCD_SR(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Prepare to write GRAM data. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_WriteRAM_Prepare(void *pLcdBase) +{ + LCD_IR(pLcdBase) = HX8347_R22H; +} + +//------------------------------------------------------------------------------ +/// Write data to LCD GRAM. +/// \param pLcdBase LCD base address. +/// \param color 16-bits RGB color. +//------------------------------------------------------------------------------ +void LCD_WriteRAM(void *pLcdBase, unsigned short color) +{ + // Write 16-bit GRAM Reg + LCD_D(pLcdBase) = color; +} + +//------------------------------------------------------------------------------ +/// Prepare to read GRAM data. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_ReadRAM_Prepare(void *pLcdBase) +{ + LCD_IR(pLcdBase) = HX8347_R22H; +} + +//------------------------------------------------------------------------------ +/// Read GRAM data. +/// \param pLcdBase LCD base address. +/// \return 16-bits RGB color. +//------------------------------------------------------------------------------ +unsigned short LCD_ReadRAM(void *pLcdBase) +{ + // Read 16-bit GRAM Reg + return LCD_D(pLcdBase); +} + +//------------------------------------------------------------------------------ +/// Dump register data. +/// \param pLcdBase LCD base address. +/// \param startAddr Register start address. +/// \param endAddr Register end address. +//------------------------------------------------------------------------------ +void LCD_DumpReg(void *pLcdBase, unsigned char startAddr, unsigned char endAddr) +{ + unsigned short tmp; + unsigned char addr; + + for (addr = startAddr; addr <= endAddr; addr++) { + + tmp = LCD_ReadReg(pLcdBase, addr); + printf("LCD.r 0x%x = 0x%x\n\r", addr, tmp); + } +} + +//------------------------------------------------------------------------------ +/// Initialize the LCD controller. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_Initialize(void *pLcdBase) +{ + unsigned short chipid; + + // Check HX8347 chipid + chipid = LCD_ReadReg(pLcdBase, HX8347_R67H); + if(chipid != HX8347_HIMAXID_CODE) { + + printf("Read HX8347 chip ID error, skip initialization.\r\n"); + return ; + } + + // Start internal OSC + LCD_WriteReg(pLcdBase, HX8347_R19H, 0x49); // OSCADJ=10 0000, OSD_EN=1 //60Hz + LCD_WriteReg(pLcdBase, HX8347_R93H, 0x0C); // RADJ=1100 + + // Power on flow + LCD_WriteReg(pLcdBase, HX8347_R44H, 0x4D); // VCM=100 1101 + LCD_WriteReg(pLcdBase, HX8347_R45H, 0x11); // VDV=1 0001 + LCD_WriteReg(pLcdBase, HX8347_R20H, 0x40); // BT=0100 + LCD_WriteReg(pLcdBase, HX8347_R1DH, 0x07); // VC1=111 + LCD_WriteReg(pLcdBase, HX8347_R1EH, 0x00); // VC3=000 + LCD_WriteReg(pLcdBase, HX8347_R1FH, 0x04); // VRH=0100 + + LCD_WriteReg(pLcdBase, HX8347_R1CH, 0x04); // AP=100 + LCD_WriteReg(pLcdBase, HX8347_R1BH, 0x10); // GASENB=0, PON=1, DK=0, XDK=0, DDVDH_TRI=0, STB=0 + Delay(50); + + LCD_WriteReg(pLcdBase, HX8347_R43H, 0x80); // Set VCOMG=1 + Delay(50); + + // Gamma for CMO 2.8 + LCD_WriteReg(pLcdBase, HX8347_R46H, 0x95); + LCD_WriteReg(pLcdBase, HX8347_R47H, 0x51); + LCD_WriteReg(pLcdBase, HX8347_R48H, 0x00); + LCD_WriteReg(pLcdBase, HX8347_R49H, 0x36); + LCD_WriteReg(pLcdBase, HX8347_R4AH, 0x11); + LCD_WriteReg(pLcdBase, HX8347_R4BH, 0x66); + LCD_WriteReg(pLcdBase, HX8347_R4CH, 0x14); + LCD_WriteReg(pLcdBase, HX8347_R4DH, 0x77); + LCD_WriteReg(pLcdBase, HX8347_R4EH, 0x13); + LCD_WriteReg(pLcdBase, HX8347_R4FH, 0x4C); + LCD_WriteReg(pLcdBase, HX8347_R50H, 0x46); + LCD_WriteReg(pLcdBase, HX8347_R51H, 0x46); + + //240x320 window setting + LCD_WriteReg(pLcdBase, HX8347_R02H, 0x00); // Column address start2 + LCD_WriteReg(pLcdBase, HX8347_R03H, 0x00); // Column address start1 + LCD_WriteReg(pLcdBase, HX8347_R04H, 0x00); // Column address end2 + LCD_WriteReg(pLcdBase, HX8347_R05H, 0xEF); // Column address end1 + LCD_WriteReg(pLcdBase, HX8347_R06H, 0x00); // Row address start2 + LCD_WriteReg(pLcdBase, HX8347_R07H, 0x00); // Row address start1 + LCD_WriteReg(pLcdBase, HX8347_R08H, 0x01); // Row address end2 + LCD_WriteReg(pLcdBase, HX8347_R09H, 0x3F); // Row address end1 + + // Display Setting + LCD_WriteReg(pLcdBase, HX8347_R01H, 0x06); // IDMON=0, INVON=1, NORON=1, PTLON=0 + LCD_WriteReg(pLcdBase, HX8347_R16H, 0xC8); // MY=1, MX=1, MV=0, BGR=1 + LCD_WriteReg(pLcdBase, HX8347_R23H, 0x95); // N_DC=1001 0101 + LCD_WriteReg(pLcdBase, HX8347_R24H, 0x95); // P_DC=1001 0101 + LCD_WriteReg(pLcdBase, HX8347_R25H, 0xFF); // I_DC=1111 1111 + LCD_WriteReg(pLcdBase, HX8347_R27H, 0x06); // N_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R28H, 0x06); // N_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R29H, 0x06); // P_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2AH, 0x06); // P_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2CH, 0x06); // I_BP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R2DH, 0x06); // I_FP=0000 0110 + LCD_WriteReg(pLcdBase, HX8347_R3AH, 0x01); // N_RTN=0000, N_NW=001 + LCD_WriteReg(pLcdBase, HX8347_R3BH, 0x01); // P_RTN=0000, P_NW=001 + LCD_WriteReg(pLcdBase, HX8347_R3CH, 0xF0); // I_RTN=1111, I_NW=000 + LCD_WriteReg(pLcdBase, HX8347_R3DH, 0x00); // DIV=00 + LCD_WriteReg(pLcdBase, HX8347_R3EH, 0x38); // SON=38h + LCD_WriteReg(pLcdBase, HX8347_R40H, 0x0F); // GDON=0Fh + LCD_WriteReg(pLcdBase, HX8347_R41H, 0xF0); // GDOF=F0h +} + +//------------------------------------------------------------------------------ +/// Turn on the LCD. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_On(void *pLcdBase) +{ + // Display ON Setting + LCD_WriteReg(pLcdBase, HX8347_R90H, 0x7F); // SAP=0111 1111 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x04); // GON=0, DTE=0, D=01 + Delay(100); + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x24); // GON=1, DTE=0, D=01 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x2C); // GON=1, DTE=0, D=11 + Delay(100); + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x3C); // GON=1, DTE=1, D=11 +} + +//------------------------------------------------------------------------------ +/// Turn off the LCD. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCD_Off(void *pLcdBase) +{ + LCD_WriteReg(pLcdBase, HX8347_R90H, 0x00); // SAP=0000 0000 + LCD_WriteReg(pLcdBase, HX8347_R26H, 0x00); // GON=0, DTE=0, D=00 +} + +//------------------------------------------------------------------------------ +/// Set cursor of LCD srceen. +/// \param pLcdBase LCD base address. +/// \param x X-coordinate of upper-left corner on LCD. +/// \param y Y-coordinate of upper-left corner on LCD. +//------------------------------------------------------------------------------ +void LCD_SetCursor(void *pLcdBase, unsigned short x, unsigned short y) +{ + unsigned char x1, x2, y1, y2; + + x1 = x & 0xff; + x2 = (x & 0xff00) >>8; + y1 = y & 0xff; + y2 = (y & 0xff00) >>8; + LCD_WriteReg(pLcdBase, HX8347_R02H, x2); // column high + LCD_WriteReg(pLcdBase, HX8347_R03H, x1); // column low + LCD_WriteReg(pLcdBase, HX8347_R06H, y2); // row high + LCD_WriteReg(pLcdBase, HX8347_R07H, y1); // row low +} + +//------------------------------------------------------------------------------ +/// Set the window size user can access. +/// \param pLcdBase LCD base address. +/// \param x_start X-coordinate of upper-left corner on LCD. +/// \param y_start Y-coordinate of upper-left corner on LCD. +/// \param x_end X-coordinate of bottom-right corner on LCD. +/// \param y_end Y-coordinate of bottom-right corner on LCD. +//------------------------------------------------------------------------------ +void LCD_SetWindow(void *pLcdBase,unsigned short x_start, unsigned short y_start,unsigned short x_end, unsigned short y_end) +{ + unsigned char x1, x2, y1, y2; + + x1 = x_start & 0xff; + x2 = (x_start & 0xff00) >>8; + y1 = y_start & 0xff; + y2 = (y_start & 0xff00) >>8; + LCD_WriteReg(pLcdBase, 0x02, x2); // column high + LCD_WriteReg(pLcdBase, 0x03, x1); // column low + LCD_WriteReg(pLcdBase, 0x06, y2); // row high + LCD_WriteReg(pLcdBase, 0x07, y1); // row low + + x1 = x_end & 0xff; + x2 = (x_end & 0xff00) >>8; + y1 = y_end & 0xff; + y2 = (y_end & 0xff00) >>8; + LCD_WriteReg(pLcdBase, 0x04, x2); // column high + LCD_WriteReg(pLcdBase, 0x05, x1); // column low + LCD_WriteReg(pLcdBase, 0x08, y2); // row high + LCD_WriteReg(pLcdBase, 0x09, y1); // row low +} +#endif //#ifdef BOARD_LCD_HX8347 diff --git a/components/hx8347/hx8347.dir b/components/hx8347/hx8347.dir new file mode 100644 index 0000000..7936f04 --- /dev/null +++ b/components/hx8347/hx8347.dir @@ -0,0 +1,41 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains APIs for HX8347 LCD Controller. +/// +/// !!!Contents +/// +/// - hx8347.h api definition for HX8347 LCD Controller. +/// - hx8347.c driver for HX8347 LCD Controller. +//------------------------------------------------------------------------------ diff --git a/components/hx8347/hx8347.h b/components/hx8347/hx8347.h new file mode 100644 index 0000000..2025405 --- /dev/null +++ b/components/hx8347/hx8347.h @@ -0,0 +1,90 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Definition of methods for HX8347 driver. +/// +/// !!!Usage +/// +/// -# LCD_WriteReg +/// -# LCD_ReadReg +/// -# LCD_ReadStatus +/// -# LCD_DumpReg +/// -# LCD_WriteRAM_Prepare +/// -# LCD_WriteRAM +/// -# LCD_ReadRAM_Prepare +/// -# LCD_ReadRAM +/// -# LCD_Initialize +/// -# LCD_SetCursor +/// -# LCD_On +/// -# LCD_Off +//------------------------------------------------------------------------------ + +#ifndef HX8347_H +#define HX8347_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ +#include + +#ifdef BOARD_LCD_HX8347 + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// Convert 24-bits color to 16-bits color +#define RGB24ToRGB16(color) (((color >> 8) & 0xF800) | \ + ((color >> 5) & 0x7E0) | \ + ((color >> 3) & 0x1F)) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +void LCD_WriteReg(void *pLcdBase, unsigned char reg, unsigned short data); +unsigned short LCD_ReadReg(void *pLcdBase, unsigned char reg); +unsigned short LCD_ReadStatus(void *pLcdBase); +void LCD_DumpReg(void *pLcdBase, unsigned char startAddr, unsigned char endAddr); +void LCD_WriteRAM_Prepare(void *pLcdBase); +void LCD_WriteRAM(void *pLcdBase, unsigned short color); +void LCD_ReadRAM_Prepare(void *pLcdBase); +unsigned short LCD_ReadRAM(void *pLcdBase); +void LCD_Initialize(void *pLcdBase); +void LCD_SetCursor(void *pLcdBase, unsigned short x, unsigned short y); +void LCD_On(void *pLcdBase); +void LCD_Off(void *pLcdBase); +void LCD_SetWindow(void *pLcdBase,unsigned short x_start, unsigned short y_start,unsigned short x_end, unsigned short y_end); + +#endif //#ifdef BOARD_LCD_HX8347 +#endif //#ifndef HX8347_H diff --git a/components/iso7816/iso7816.dir b/components/iso7816/iso7816.dir new file mode 100644 index 0000000..433a418 --- /dev/null +++ b/components/iso7816/iso7816.dir @@ -0,0 +1,45 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !Purpose +/// +/// This directory contains an API for ISO 7816-3 and ISO 7816-4 +/// +/// !Contents +/// +/// The definitions and functions provided are dispatched inside a number of +/// files: +/// - iso7816_4.h api definition for iso 7816-4 +/// - iso7816_4.c driver iso 7816-4 +/// +//------------------------------------------------------------------------------ + diff --git a/components/iso7816/iso7816_4.c b/components/iso7816/iso7816_4.c new file mode 100644 index 0000000..7731dff --- /dev/null +++ b/components/iso7816/iso7816_4.c @@ -0,0 +1,620 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// ISO 7816 driver +/// +/// !Usage +/// +/// Explanation on the usage of the code made available through the header file. +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include +#include +#include +#include +#include "iso7816_4.h" + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ +/// Case for APDU commands +#define CASE1 1 +#define CASE2 2 +#define CASE3 3 + +/// Flip flop for send and receive char +#define USART_SEND 0 +#define USART_RCV 1 + +//------------------------------------------------------------------------------ +// Internal variables +//------------------------------------------------------------------------------ +/// Variable for state of send and receive froom USART +static unsigned char StateUsartGlobal = USART_RCV; +/// Pin reset master card +static Pin st_pinIso7816RstMC; + +//----------------------------------------------------------------------------- +// Internal functions +//----------------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +/// Get a character from ISO7816 +/// \param pCharToReceive Pointer for store the received char +/// \return 0: if timeout else status of US_CSR +//------------------------------------------------------------------------------ +static unsigned int ISO7816_GetChar( unsigned char *pCharToReceive ) +{ + unsigned int status; + unsigned int timeout=0; + + if( StateUsartGlobal == USART_SEND ) { + while((AT91C_BASE_US0->US_CSR & AT91C_US_TXEMPTY) == 0) {} + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK; + StateUsartGlobal = USART_RCV; + } + + // Wait USART ready for reception + while( ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) == 0) ) { + if(timeout++ > 12000 * (BOARD_MCK/1000000)) { + TRACE_DEBUG("TimeOut\n\r"); + return( 0 ); + } + } + + TRACE_DEBUG("T: %d\n\r", timeout); + + + // At least one complete character has been received and US_RHR has not yet been read. + + // Get a char + *pCharToReceive = ((AT91C_BASE_US0->US_RHR) & 0xFF); + + status = (AT91C_BASE_US0->US_CSR&(AT91C_US_OVRE|AT91C_US_FRAME| + AT91C_US_PARE|AT91C_US_TIMEOUT|AT91C_US_NACK| + (1<<10))); + + if (status != 0 ) { + // TRACE_DEBUG("R:0x%X\n\r", status); + TRACE_DEBUG("R:0x%X\n\r", AT91C_BASE_US0->US_CSR); + TRACE_DEBUG("Nb:0x%X\n\r", AT91C_BASE_US0->US_NER ); + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA; + } + + // Return status + return( status ); +} + + +//------------------------------------------------------------------------------ +/// Send a char to ISO7816 +/// \param CharToSend char to be send +/// \return status of US_CSR +//------------------------------------------------------------------------------ +static unsigned int ISO7816_SendChar( unsigned char CharToSend ) +{ + unsigned int status; + + if( StateUsartGlobal == USART_RCV ) { + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK; + StateUsartGlobal = USART_SEND; + } + + // Wait USART ready for transmit + while((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) == 0) {} + // There is no character in the US_THR + + // Transmit a char + AT91C_BASE_US0->US_THR = CharToSend; + + status = (AT91C_BASE_US0->US_CSR&(AT91C_US_OVRE|AT91C_US_FRAME| + AT91C_US_PARE|AT91C_US_TIMEOUT|AT91C_US_NACK| + (1<<10))); + + if (status != 0 ) { + TRACE_DEBUG("E:0x%X\n\r", AT91C_BASE_US0->US_CSR); + TRACE_DEBUG("Nb:0x%X\n\r", AT91C_BASE_US0->US_NER ); + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA; + } + + // Return status + return( status ); +} + + +//------------------------------------------------------------------------------ +/// Iso 7816 ICC power on +//------------------------------------------------------------------------------ +static void ISO7816_IccPowerOn( void ) +{ + // Set RESET Master Card + PIO_Set(&st_pinIso7816RstMC); +} + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +/// Iso 7816 ICC power off +//------------------------------------------------------------------------------ +void ISO7816_IccPowerOff( void ) +{ + // Clear RESET Master Card + PIO_Clear(&st_pinIso7816RstMC); +} + +//------------------------------------------------------------------------------ +/// Transfert Block TPDU T=0 +/// \param pAPDU APDU buffer +/// \param pMessage Message buffer +/// \param wLength Block length +/// \return Message index +//------------------------------------------------------------------------------ +unsigned short ISO7816_XfrBlockTPDU_T0(const unsigned char *pAPDU, + unsigned char *pMessage, + unsigned short wLength ) +{ + unsigned short NeNc; + unsigned short indexApdu = 4; + unsigned short indexMessage = 0; + unsigned char SW1 = 0; + unsigned char procByte; + unsigned char cmdCase; + + TRACE_DEBUG("pAPDU[0]=0x%X\n\r",pAPDU[0]); + TRACE_DEBUG("pAPDU[1]=0x%X\n\r",pAPDU[1]); + TRACE_DEBUG("pAPDU[2]=0x%X\n\r",pAPDU[2]); + TRACE_DEBUG("pAPDU[3]=0x%X\n\r",pAPDU[3]); + TRACE_DEBUG("pAPDU[4]=0x%X\n\r",pAPDU[4]); + TRACE_DEBUG("pAPDU[5]=0x%X\n\r",pAPDU[5]); + TRACE_DEBUG("wlength=%d\n\r",wLength); + + ISO7816_SendChar( pAPDU[0] ); // CLA + ISO7816_SendChar( pAPDU[1] ); // INS + ISO7816_SendChar( pAPDU[2] ); // P1 + ISO7816_SendChar( pAPDU[3] ); // P2 + ISO7816_SendChar( pAPDU[4] ); // P3 + + // Handle the four structures of command APDU + indexApdu = 4; + + if( wLength == 4 ) { + cmdCase = CASE1; + NeNc = 0; + } + else if( wLength == 5) { + cmdCase = CASE2; + NeNc = pAPDU[4]; // C5 + if (NeNc == 0) { + NeNc = 256; + } + } + else if( wLength == 6) { + NeNc = pAPDU[4]; // C5 + cmdCase = CASE3; + } + else if( wLength == 7) { + NeNc = pAPDU[4]; // C5 + if( NeNc == 0 ) { + cmdCase = CASE2; + NeNc = (pAPDU[5]<<8)+pAPDU[6]; + } + else { + cmdCase = CASE3; + } + } + else { + NeNc = pAPDU[4]; // C5 + if( NeNc == 0 ) { + cmdCase = CASE3; + NeNc = (pAPDU[5]<<8)+pAPDU[6]; + } + else { + cmdCase = CASE3; + } + } + + TRACE_DEBUG("CASE=0x%X NeNc=0x%X\n\r", cmdCase, NeNc); + + // Handle Procedure Bytes + do { + ISO7816_GetChar(&procByte); + // Handle NULL + if ( procByte == ISO_NULL_VAL ) { + TRACE_DEBUG("INS\n\r"); + continue; + } + // Handle SW1 + else if ( ((procByte & 0xF0) ==0x60) || ((procByte & 0xF0) ==0x90) ) { + TRACE_DEBUG("SW1\n\r"); + SW1 = 1; + } + // Handle INS + else if ( pAPDU[1] == procByte) { + TRACE_DEBUG("HdlINS\n\r"); + if (cmdCase == CASE2) { + // receive data from card + do { + ISO7816_GetChar(&pMessage[indexMessage++]); + } while( 0 != --NeNc ); + } + else { + // Send data + do { + ISO7816_SendChar(pAPDU[indexApdu++]); + } while( 0 != --NeNc ); + } + } + // Handle INS ^ 0xff + else if ( pAPDU[1] == (procByte ^ 0xff)) { + TRACE_DEBUG("HdlINS+\n\r"); + if (cmdCase == CASE2) { + // receive data from card + ISO7816_GetChar(&pMessage[indexMessage++]); + } + else { + ISO7816_SendChar(pAPDU[indexApdu++]); + } + NeNc--; + } + else { + // ?? + TRACE_DEBUG("procByte=0x%X\n\r", procByte); + break; + } + } while (NeNc != 0); + + // Status Bytes + if (SW1 == 0) { + ISO7816_GetChar(&pMessage[indexMessage++]); // SW1 + } + else { + pMessage[indexMessage++] = procByte; + } + ISO7816_GetChar(&pMessage[indexMessage++]); // SW2 + + return( indexMessage ); + +} + +//------------------------------------------------------------------------------ +/// Escape ISO7816 +//------------------------------------------------------------------------------ +void ISO7816_Escape( void ) +{ + TRACE_DEBUG("For user, if needed\n\r"); +} + +//------------------------------------------------------------------------------ +/// Restart clock ISO7816 +//------------------------------------------------------------------------------ +void ISO7816_RestartClock( void ) +{ + TRACE_DEBUG("ISO7816_RestartClock\n\r"); + AT91C_BASE_US0->US_BRGR = 13; +} + +//------------------------------------------------------------------------------ +/// Stop clock ISO7816 +//------------------------------------------------------------------------------ +void ISO7816_StopClock( void ) +{ + TRACE_DEBUG("ISO7816_StopClock\n\r"); + AT91C_BASE_US0->US_BRGR = 0; +} + +//------------------------------------------------------------------------------ +/// T0 APDU +//------------------------------------------------------------------------------ +void ISO7816_toAPDU( void ) +{ + TRACE_DEBUG("ISO7816_toAPDU\n\r"); + TRACE_DEBUG("Not supported at this time\n\r"); +} + +//---------------------------------------------------------------------- +/// Answer To Reset (ATR) +/// \param pAtr ATR buffer +/// \param pLength Pointer for store the ATR length +//---------------------------------------------------------------------- +void ISO7816_Datablock_ATR( unsigned char* pAtr, unsigned char* pLength ) +{ + unsigned int i; + unsigned int j; + unsigned int y; + + *pLength = 0; + + // Read ATR TS + ISO7816_GetChar(&pAtr[0]); + // Read ATR T0 + ISO7816_GetChar(&pAtr[1]); + y = pAtr[1] & 0xF0; + i = 2; + + // Read ATR Ti + while (y) { + + if (y & 0x10) { // TA[i] + ISO7816_GetChar(&pAtr[i++]); + } + if (y & 0x20) { // TB[i] + ISO7816_GetChar(&pAtr[i++]); + } + if (y & 0x40) { // TC[i] + ISO7816_GetChar(&pAtr[i++]); + } + if (y & 0x80) { // TD[i] + ISO7816_GetChar(&pAtr[i]); + y = pAtr[i++] & 0xF0; + } + else { + y = 0; + } + } + + // Historical Bytes + y = pAtr[1] & 0x0F; + for( j=0; j < y; j++ ) { + ISO7816_GetChar(&pAtr[i++]); + } + + TRACE_DEBUG_WP("Length = %d", i); + TRACE_DEBUG_WP("ATR = "); + + for (j=0; j < i; j++) { + TRACE_DEBUG_WP("%02x ", pAtr[j]); + } + + + TRACE_DEBUG_WP("\n\r"); + + *pLength = i; + +} + +//---------------------------------------------------------------------- +/// Set data rate and clock frequency +/// \param dwClockFrequency ICC clock frequency in KHz. +/// \param dwDataRate ICC data rate in bpd +//---------------------------------------------------------------------- +void ISO7816_SetDataRateandClockFrequency( unsigned int dwClockFrequency, unsigned int dwDataRate ) +{ + unsigned char ClockFrequency; + + // Define the baud rate divisor register + // CD = MCK / SCK + // SCK = FIDI x BAUD = 372 x 9600 + // BOARD_MCK + // CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 + AT91C_BASE_US0->US_BRGR = BOARD_MCK / (dwClockFrequency*1000); + + ClockFrequency = BOARD_MCK / AT91C_BASE_US0->US_BRGR; + + AT91C_BASE_US0->US_FIDI = (ClockFrequency)/dwDataRate; + +} + +//------------------------------------------------------------------------------ +/// Pin status for ISO7816 RESET +/// \return 1 if the Pin RstMC is high; otherwise 0. +//------------------------------------------------------------------------------ +unsigned char ISO7816_StatusReset( void ) +{ + return PIO_Get(&st_pinIso7816RstMC); +} + +//------------------------------------------------------------------------------ +/// cold reset +//------------------------------------------------------------------------------ +void ISO7816_cold_reset( void ) +{ + volatile unsigned int i; + + // tb: wait 400 cycles, 3.58MHz => 80µs 48000000Hz (3840) + for( i=0; i<(120*(BOARD_MCK/1000000)); i++ ) { + } + + AT91C_BASE_US0->US_RHR; + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK; + + ISO7816_IccPowerOn(); +} + +//------------------------------------------------------------------------------ +/// Warm reset +//------------------------------------------------------------------------------ +void ISO7816_warm_reset( void ) +{ + volatile unsigned int i; + + ISO7816_IccPowerOff(); + + // tb: wait 400 cycles, 3.58MHz => 80µs 48000000Hz (3840) + for( i=0; i<(120*(BOARD_MCK/1000000)); i++ ) { + } + + AT91C_BASE_US0->US_RHR; + AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA | AT91C_US_RSTIT | AT91C_US_RSTNACK; + + ISO7816_IccPowerOn(); +} + +//---------------------------------------------------------------------- +/// Decode ATR trace +/// \param pAtr pointer on ATR buffer +//---------------------------------------------------------------------- +void ISO7816_Decode_ATR( unsigned char* pAtr ) +{ + unsigned int i; + unsigned int j; + unsigned int y; + unsigned char offset; + + TRACE_INFO_WP("ATR: Answer To Reset:\n\r"); + TRACE_INFO_WP("TS = 0x%X Initial caracter ",pAtr[0]); + if( pAtr[0] == 0x3B ) { + + TRACE_INFO_WP("Direct Convention\n\r"); + } + else { + if( pAtr[0] == 0x3F ) { + + TRACE_INFO_WP("Inverse Convention\n\r"); + } + else { + TRACE_INFO_WP("BAD Convention\n\r"); + } + } + + TRACE_INFO_WP("T0 = 0x%X Format caracter\n\r",pAtr[1]); + TRACE_INFO_WP(" Number of historical bytes: K = %d\n\r", pAtr[1]&0x0F); + TRACE_INFO_WP(" Presence further interface byte:\n\r"); + if( pAtr[1]&0x80 ) { + TRACE_INFO_WP("TA "); + } + if( pAtr[1]&0x40 ) { + TRACE_INFO_WP("TB "); + } + if( pAtr[1]&0x20 ) { + TRACE_INFO_WP("TC "); + } + if( pAtr[1]&0x10 ) { + TRACE_INFO_WP("TD "); + } + if( pAtr[1] != 0 ) { + TRACE_INFO_WP(" present\n\r"); + } + + i = 2; + y = pAtr[1] & 0xF0; + + // Read ATR Ti + offset = 1; + while (y) { + + if (y & 0x10) { // TA[i] + TRACE_INFO_WP("TA[%d] = 0x%X ", offset, pAtr[i]); + if( offset == 1 ) { + TRACE_INFO_WP("FI = %d ", (pAtr[i]>>8)); + TRACE_INFO_WP("DI = %d", (pAtr[i]&0x0F)); + } + TRACE_INFO_WP("\n\r"); + i++; + } + if (y & 0x20) { // TB[i] + TRACE_INFO_WP("TB[%d] = 0x%X\n\r", offset, pAtr[i]); + i++; + } + if (y & 0x40) { // TC[i] + TRACE_INFO_WP("TC[%d] = 0x%X ", offset, pAtr[i]); + if( offset == 1 ) { + TRACE_INFO_WP("Extra Guard Time: N = %d", pAtr[i]); + } + TRACE_INFO_WP("\n\r"); + i++; + } + if (y & 0x80) { // TD[i] + TRACE_INFO_WP("TD[%d] = 0x%X\n\r", offset, pAtr[i]); + y = pAtr[i++] & 0xF0; + } + else { + y = 0; + } + offset++; + } + + // Historical Bytes + TRACE_INFO_WP("Historical bytes:\n\r"); + y = pAtr[1] & 0x0F; + for( j=0; j < y; j++ ) { + + TRACE_INFO_WP(" 0x%X", pAtr[i]); + if( (pAtr[i] > 0x21) && (pAtr[i] < 0x7D) ) { // ASCII + TRACE_INFO_WP("(%c) ", pAtr[i]); + } + i++; + } + TRACE_INFO_WP("\n\r"); + +} + +//------------------------------------------------------------------------------ +// Initializes a ISO driver +/// \param pPinIso7816RstMC Pin ISO 7816 Rst MC +//------------------------------------------------------------------------------ +void ISO7816_Init( const Pin pPinIso7816RstMC ) +{ + TRACE_DEBUG("ISO_Init\n\r"); + + // Pin ISO7816 initialize + st_pinIso7816RstMC = pPinIso7816RstMC; + + USART_Configure( AT91C_BASE_US0, + AT91C_US_USMODE_ISO7816_0 + | AT91C_US_CLKS_CLOCK + | AT91C_US_NBSTOP_1_BIT + | AT91C_US_PAR_EVEN + | AT91C_US_CHRL_8_BITS + | AT91C_US_CKLO + | (3<<24), // MAX_ITERATION + 1, + 0); + + // Configure USART0 + AT91C_BASE_PMC->PMC_PCER = ((unsigned int) 1 << AT91C_ID_US0); + // Disable interrupts + AT91C_BASE_US0->US_IDR = (unsigned int) -1; + + AT91C_BASE_US0->US_FIDI = 372; // by default + // Define the baud rate divisor register + // CD = MCK / SCK + // SCK = FIDI x BAUD = 372 x 9600 + // BOARD_MCK + // CD = MCK/(FIDI x BAUD) = 48000000 / (372x9600) = 13 + AT91C_BASE_US0->US_BRGR = BOARD_MCK / (372*9600); + + // Write the Timeguard Register + AT91C_BASE_US0->US_TTGR = 5; + + USART_SetTransmitterEnabled(AT91C_BASE_US0, 1); + USART_SetReceiverEnabled(AT91C_BASE_US0, 1); + +} + diff --git a/components/iso7816/iso7816_4.h b/components/iso7816/iso7816_4.h new file mode 100644 index 0000000..cd46b80 --- /dev/null +++ b/components/iso7816/iso7816_4.h @@ -0,0 +1,87 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !Purpose +/// +/// Definition of methods for ISO7816 driver. +/// +/// !Usage +/// +/// -# ISO7816_Init +/// -# ISO7816_IccPowerOff +/// -# ISO7816_XfrBlockTPDU_T0 +/// -# ISO7816_Escape +/// -# ISO7816_RestartClock +/// -# ISO7816_StopClock +/// -# ISO7816_toAPDU +/// -# ISO7816_Datablock_ATR +/// -# ISO7816_SetDataRateandClockFrequency +/// -# ISO7816_StatusReset +/// -# ISO7816_cold_reset +/// -# ISO7816_warm_reset +/// -# ISO7816_Decode_ATR +//------------------------------------------------------------------------------ + +#ifndef ISO7816_4_H +#define ISO7816_4_H + +//------------------------------------------------------------------------------ +// Constants Definition +//------------------------------------------------------------------------------ + +/// Size max of Answer To Reset +#define ATR_SIZE_MAX 55 + +/// NULL byte to restart byte procedure +#define ISO_NULL_VAL 0x60 + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern void ISO7816_Init( const Pin pPinIso7816RstMC ); +extern void ISO7816_IccPowerOff(void); +extern unsigned short ISO7816_XfrBlockTPDU_T0(const unsigned char *pAPDU, + unsigned char *pMessage, + unsigned short wLength ); +extern void ISO7816_Escape( void ); +extern void ISO7816_RestartClock(void); +extern void ISO7816_StopClock( void ); +extern void ISO7816_toAPDU( void ); +extern void ISO7816_Datablock_ATR( unsigned char* pAtr, unsigned char* pLength ); +extern void ISO7816_SetDataRateandClockFrequency( unsigned int dwClockFrequency, unsigned int dwDataRate ); +extern unsigned char ISO7816_StatusReset( void ); +extern void ISO7816_cold_reset( void ); +extern void ISO7816_warm_reset( void ); +extern void ISO7816_Decode_ATR( unsigned char* pAtr ); + +#endif // ISO7816_4_H + diff --git a/components/kbmatrix/kbmatrix.c b/components/kbmatrix/kbmatrix.c new file mode 100644 index 0000000..1f0ad54 --- /dev/null +++ b/components/kbmatrix/kbmatrix.c @@ -0,0 +1,304 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "kbmatrix.h" +#include +#include +#include +#include + +#include + +//----------------------------------------------------------------------------- +// Local functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Initializes a KeyState instance by setting all keys are released. +/// \param pKeyState Pointer to a KeyState instance to initialize. +//----------------------------------------------------------------------------- +static void KEYSTATE_Initialize(KeyState *pKeyState) +{ + SANITY_CHECK(pKeyState); + + memset(pKeyState->pState, 0, sizeof(KeyState)); +} + +//----------------------------------------------------------------------------- +/// Sets the status of a key given its index in the key state. +/// \param pKeyState Pointer to a KeyState instance. +/// \param key Key index. +/// \param state New key state. +//----------------------------------------------------------------------------- +static void KEYSTATE_SetKeyState( + KeyState *pKeyState, + unsigned int key, + unsigned char state) +{ + unsigned int byte = key / 8; + unsigned int bit = key % 8; + + SANITY_CHECK(pKeyState); + SANITY_CHECK(key < KBMATRIX_MAX_NUMKEYS); + + if (state) { + + pKeyState->pState[byte] |= (1 << bit); + } + else { + + pKeyState->pState[byte] &= ~(1 << bit); + } +} + +//----------------------------------------------------------------------------- +/// Returns 1 if the given key is currently pressed; otherwise returns 0. +/// \param pKeyState Pointer to a KeyState instance. +/// \param key Key index. +//----------------------------------------------------------------------------- +static unsigned char KEYSTATE_GetKeyState(KeyState *pKeyState, unsigned int key) +{ + unsigned int byte = key / 8; + unsigned int bit = key % 8; + + SANITY_CHECK(pKeyState); + SANITY_CHECK(key < KBMATRIX_MAX_NUMKEYS); + + return ((pKeyState->pState[byte] >> bit) & 1); +} + +//----------------------------------------------------------------------------- +/// Performs a AND operation between two KeyState instance, storing the result +/// in a third instance. +/// \param pA Pointer to the first state to AND. +/// \param pB Pointer to the second state to AND. +/// \param pResult Pointer to the resulting KeyState. +//----------------------------------------------------------------------------- +static void KEYSTATE_And(KeyState *pA, KeyState *pB, KeyState *pResult) +{ + unsigned int i; + + for (i=0; i < sizeof(KeyState); i++) { + + pResult->pState[i] = pA->pState[i] & pB->pState[i]; + } +} + +//----------------------------------------------------------------------------- +/// Performs a OR operation between two KeyState instance, storing the result +/// in a third instance. +/// \param pA Pointer to the first state to OR. +/// \param pB Pointer to the second state to OR. +/// \param pResult Pointer to the resulting KeyState. +//----------------------------------------------------------------------------- +static void KEYSTATE_Or(KeyState *pA, KeyState *pB, KeyState *pResult) +{ + unsigned int i; + + for (i=0; i < sizeof(KeyState); i++) { + + pResult->pState[i] = pA->pState[i] | pB->pState[i]; + } +} + +//----------------------------------------------------------------------------- +/// Performs a XOR operation between two KeyState instance, storing the result +/// in a third instance. +/// \param pA Pointer to the first state to XOR. +/// \param pB Pointer to the second state to XOR. +/// \param pResult Pointer to the resulting KeyState. +//----------------------------------------------------------------------------- +static void KEYSTATE_Xor(KeyState *pA, KeyState *pB, KeyState *pResult) +{ + unsigned int i; + + for (i=0; i < sizeof(KeyState); i++) { + + pResult->pState[i] = pA->pState[i] ^ pB->pState[i]; + } +} + +//----------------------------------------------------------------------------- +/// Computes the new debounced key state and trigger key events if necessary. +/// The debouncing is done both when the key is pressed and when it is released. +/// Returns 1 if changes have been detected; otherwise returns 0. +/// \param pKbMatrix Pointer to a KbMatrix instance. +//----------------------------------------------------------------------------- +unsigned char Debounce(KbMatrix *pKbMatrix) +{ + KeyState pressed; + KeyState released; + KeyState new; + KeyState changed; + unsigned int i; + unsigned char event = 0; + + SANITY_CHECK(pKbMatrix); + + // Debounce pressed keys + memcpy(&pressed, &(pKbMatrix->sampledKeyStates[0]), sizeof(KeyState)); + for (i=1; i < KBMATRIX_NUM_SAMPLES; i++) { + + KEYSTATE_And(&pressed, &(pKbMatrix->sampledKeyStates[i]), &pressed); + } + + // Debounce released keys + memcpy(&released, &(pKbMatrix->sampledKeyStates[0]), sizeof(KeyState)); + for (i=1; i < KBMATRIX_NUM_SAMPLES; i++) { + + KEYSTATE_And(&released, &(pKbMatrix->sampledKeyStates[i]), &released); + } + + // Compute new key status + KEYSTATE_Or(&(pKbMatrix->currentKeyState), &pressed, &new); + KEYSTATE_And(&new, &released, &new); + + // Compare with existing status + KEYSTATE_Xor(&new, &(pKbMatrix->currentKeyState), &changed); + + // Process each pending event + for (i=0; i < (pKbMatrix->numRows * pKbMatrix->numCols); i++) { + + if (KEYSTATE_GetKeyState(&changed, i)) { + + event = 1; + + // Trigger callback + if (pKbMatrix->callback) { + + pKbMatrix->callback(i, KEYSTATE_GetKeyState(&new, i)); + } + } + } + + // Save new key state + memcpy(&(pKbMatrix->currentKeyState), &new, sizeof(KeyState)); + + return event; +} + +//----------------------------------------------------------------------------- +/// Retrieves a new debounce sample by reading the current state of the +/// keyboard. +/// \param pKbMatrix Pointer to a KbMatrix instance. +//----------------------------------------------------------------------------- +void Fetch(KbMatrix *pKbMatrix) +{ + KeyState *pKeyState = &(pKbMatrix->sampledKeyStates[pKbMatrix->sample]); + unsigned int row; + unsigned int col; + volatile unsigned int i; + + SANITY_CHECK(pKbMatrix); + + // Scan the current keyboard status + for (row=0; row < pKbMatrix->numRows; row++) { + + // Enable row + PIO_Clear(&(pKbMatrix->pRows[row])); + + // Scan each column + for (col=0; col < pKbMatrix->numCols; col++) { + + KEYSTATE_SetKeyState(pKeyState, + row * pKbMatrix->numCols + col, + !PIO_Get(&(pKbMatrix->pCols[col]))); + } + + // Disable row (and wait for level to become 1) + PIO_Set(&(pKbMatrix->pRows[row])); + for (i=0; i < 100; i++); // Dirty but works + } + + // Update sample index + pKbMatrix->sample = (pKbMatrix->sample + 1) % KBMATRIX_NUM_SAMPLES; +} + +//----------------------------------------------------------------------------- +// Exported functions +//----------------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +/// Initializes a keyboard matrix driver instance. +/// \param pKbMatrix Pointer to a KbMatrix instance. +/// \param pRows Pointer to the list of row pins. +/// \param numRows Number of rows in matrix. +/// \param pCols Pointer to the list of column pins. +/// \param numCols Number of columns in matrix. +/// \param callback Optional callback for receiving key events. +//------------------------------------------------------------------------------ +void KBMATRIX_Initialize( + KbMatrix * pKbMatrix, + const Pin * pRows, + unsigned char numRows, + const Pin * pCols, + unsigned char numCols, + KeyEventCallback callback) +{ + unsigned int i; + + ASSERT(numRows * numCols <= KBMATRIX_MAX_NUMKEYS, + "KBMATRIX_Initialize: too many keys (change KBMATRIX_MAX_NUMKEYS)\n\r"); + + // Initialize structure members + pKbMatrix->pRows = pRows; + pKbMatrix->numRows = numRows; + pKbMatrix->pCols = pCols; + pKbMatrix->numCols = numCols; + pKbMatrix->callback = callback; + + // Initialize key states + KEYSTATE_Initialize(&(pKbMatrix->currentKeyState)); + for (i=0; i < KBMATRIX_NUM_SAMPLES; i++) { + + KEYSTATE_Initialize(&(pKbMatrix->sampledKeyStates[i])); + } + pKbMatrix->sample = 0; +} + +//----------------------------------------------------------------------------- +/// Scans the keyboard matrix for key events (key pressed or released). Takes +/// care of debouncing. +/// Returns 1 if changes have been detected on the keyboard; otherwise return +/// 0. +/// \param pKbMatrix Pointer to a KbMatrix instance. +//----------------------------------------------------------------------------- +unsigned char KBMATRIX_Scan(KbMatrix *pKbMatrix) +{ + // Fetch new debounce sample + Fetch(pKbMatrix); + + // Compute the new debounced key state, triggering events if necessary + return Debounce(pKbMatrix); +} + diff --git a/components/kbmatrix/kbmatrix.h b/components/kbmatrix/kbmatrix.h new file mode 100644 index 0000000..02a19cb --- /dev/null +++ b/components/kbmatrix/kbmatrix.h @@ -0,0 +1,106 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 KBMATRIX_H +#define KBMATRIX_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//----------------------------------------------------------------------------- +// Definitions +//----------------------------------------------------------------------------- + +/// Size of circular key buffer. +#define KBMATRIX_BUFFER_SIZE 10 + +/// Maximum number of keys that can be handled by the driver. +#define KBMATRIX_MAX_NUMKEYS 40 + +/// Number of samples that are necessary to debounce a keypress. +#define KBMATRIX_NUM_SAMPLES 10 + +//----------------------------------------------------------------------------- +// Types +//----------------------------------------------------------------------------- + +/// Key event callback. +typedef void (*KeyEventCallback)(unsigned int key, unsigned char pressed); + +/// Key mapping structure, indicating the state of each key in keyboard matrix. +typedef struct _KeyState { + + unsigned char pState[KBMATRIX_MAX_NUMKEYS / 8]; + +} KeyState; + +/// Keyboard matrix driver structure. Holds information about the row & column +/// pins used to create the matrix and stores the internal debouncing status. +typedef struct _KbMatrix { + + /// List of keyboard matrix row pins. + const Pin *pRows; + /// Number of rows in matrix. + unsigned char numRows; + /// List of keyboard matrix column pins. + const Pin *pCols; + /// Number of columns in matrix. + unsigned char numCols; + + /// Current debounced key state mapping. + KeyState currentKeyState; + /// Debouncing samples. + KeyState sampledKeyStates[KBMATRIX_NUM_SAMPLES]; + /// Current debouncing sample. + unsigned char sample; + + /// Key pressed/released callback. + KeyEventCallback callback; + +} KbMatrix; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void KBMATRIX_Initialize( + KbMatrix * pKbMatrix, + const Pin * pRows, + unsigned char numRows, + const Pin * pCols, + unsigned char numCols, + KeyEventCallback callback); + +extern unsigned char KBMATRIX_Scan(KbMatrix *pKbMatrix); + +#endif //#ifndef KBMATRIX_H + diff --git a/components/kbmatrix/s7lekkbm/s7lekkbm.c b/components/kbmatrix/s7lekkbm/s7lekkbm.c new file mode 100644 index 0000000..c9c5373 --- /dev/null +++ b/components/kbmatrix/s7lekkbm/s7lekkbm.c @@ -0,0 +1,119 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "s7lekkbm.h" + +//------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------ + +/// Keyboard matrix natural key mapping. +const unsigned char gpKeyboardMatrix[S7LEKKBM_NUMKEYS] = { + + S7LEKKBM_SQUAREROOT, + S7LEKKBM_PERCENTAGE, + S7LEKKBM_SIGN, + S7LEKKBM_INVERSE, + S7LEKKBM_X_POWER_Y, + S7LEKKBM_MODE, + S7LEKKBM_2NDF, + '7', + '8', + '9', + S7LEKKBM_DIVIDE, + S7LEKKBM_EXP, + S7LEKKBM_HEXDECBIN, + S7LEKKBM_2NDF_LOCK, + '4', + '5', + '6', + S7LEKKBM_MULTIPLY, + S7LEKKBM_LOG, + S7LEKKBM_UPARROW, + S7LEKKBM_ESCAPE, + '1', + '2', + '3', + S7LEKKBM_MINUS, + S7LEKKBM_LEFTARROW, + S7LEKKBM_OK, + S7LEKKBM_RIGHTARROW, + '0', + S7LEKKBM_DOT, + S7LEKKBM_EQUAL, + S7LEKKBM_PLUS, + S7LEKKBM_LN, + S7LEKKBM_DOWNARROW, + S7LEKKBM_DELETE +}; + +/// Keyboard matrix alternative key mapping (2ndF key pressed). +const unsigned char gpKeyboardMatrixAlt[S7LEKKBM_NUMKEYS] = { + + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + S7LEKKBM_2NDF, + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + S7LEKKBM_2NDF_LOCK, + 'M', + 'N', + 'O', + 'P', + 'Q', + S7LEKKBM_PAUSE, + S7LEKKBM_ESCAPE, + 'R', + 'S', + 'T', + 'U', + S7LEKKBM_LEFTARROW, + S7LEKKBM_PLAY, + S7LEKKBM_RIGHTARROW, + 'V', + 'W', + 'X', + 'Y', + 'Z', + S7LEKKBM_STOP, + S7LEKKBM_DELETE +}; + diff --git a/components/kbmatrix/s7lekkbm/s7lekkbm.h b/components/kbmatrix/s7lekkbm/s7lekkbm.h new file mode 100644 index 0000000..d3bd131 --- /dev/null +++ b/components/kbmatrix/s7lekkbm/s7lekkbm.h @@ -0,0 +1,113 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 S7LEKKBM_H +#define S7LEKKBM_H + +//------------------------------------------------------------------------------ +// Global definitions +//------------------------------------------------------------------------------ + +/// Number of keys in keyboard matrix. +#define S7LEKKBM_NUMKEYS 35 + +/// Square root key. +#define S7LEKKBM_SQUAREROOT 128 +/// Percentage key. +#define S7LEKKBM_PERCENTAGE 129 +/// Plus/minus sign key. +#define S7LEKKBM_SIGN 130 +/// Inverse (1/x) key. +#define S7LEKKBM_INVERSE 131 +/// Power key (x^y). +#define S7LEKKBM_X_POWER_Y 132 +/// Mode key. +#define S7LEKKBM_MODE 133 +/// 2nd function key. +#define S7LEKKBM_2NDF 134 +/// Divide key. +#define S7LEKKBM_DIVIDE 135 +/// Exponential key. +#define S7LEKKBM_EXP 136 +/// Hex/dec/bin key. +#define S7LEKKBM_HEXDECBIN 137 +/// 2nd function lock key. +#define S7LEKKBM_2NDF_LOCK 138 +/// Multiply key. +#define S7LEKKBM_MULTIPLY 139 +/// Logarithm key. +#define S7LEKKBM_LOG 140 +/// Up arrow key. +#define S7LEKKBM_UPARROW 141 +/// Pause key. +#define S7LEKKBM_PAUSE 142 +/// Escape key. +#define S7LEKKBM_ESCAPE 143 +/// Minus key. +#define S7LEKKBM_MINUS 144 +/// Left arrow key. +#define S7LEKKBM_LEFTARROW 145 +/// Ok key. +#define S7LEKKBM_OK 146 +/// Play key. +#define S7LEKKBM_PLAY 147 +/// Right arrow key. +#define S7LEKKBM_RIGHTARROW 148 +/// Dot key. +#define S7LEKKBM_DOT 149 +/// Equal key. +#define S7LEKKBM_EQUAL 150 +/// Plus key. +#define S7LEKKBM_PLUS 151 +/// Natural logarithm key. +#define S7LEKKBM_LN 152 +/// Down arrow key. +#define S7LEKKBM_DOWNARROW 153 +/// Stop key. +#define S7LEKKBM_STOP 154 +/// Delete key. +#define S7LEKKBM_DELETE 155 + +//------------------------------------------------------------------------------ +// Global macros +//------------------------------------------------------------------------------ + +/// Returns 1 if the key is a special key; otherwise returns 0. +#define S7LEKKBM_SPECIALKEY(key) ((key >= 128) ? 1 : 0) + +//------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------ + +extern const unsigned char gpKeyboardMatrix[S7LEKKBM_NUMKEYS]; + +extern const unsigned char gpKeyboardMatrixAlt[S7LEKKBM_NUMKEYS]; + +#endif //#ifndef S7LEKKBM_H + diff --git a/components/omnivision/omnivision.c b/components/omnivision/omnivision.c new file mode 100644 index 0000000..4216169 --- /dev/null +++ b/components/omnivision/omnivision.c @@ -0,0 +1,326 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- +#include +#include +#include +#include + +/// Slave address of OMNIVISION chips. +#define OV_CAPTOR_ADDRESS (0x60>>1) + + +/// terminating list entry for register in configuration file +#define OV_REG_TERM 0xFF +/// terminating list entry for value in configuration file +#define OV_VAL_TERM 0xFF + +//----------------------------------------------------------------------------- +// Local Functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Reset using ctrl signal +/// \param pCtrl1 PIO interface +//----------------------------------------------------------------------------- +static void ov_reset(const Pin *pCtrl1) +{ + volatile unsigned int i; + + if(pCtrl1->id == 0) + return; + + pCtrl1->pio->PIO_CODR = pCtrl1->mask; + for(i=0; i<6000; i++ ); + pCtrl1->pio->PIO_SODR = pCtrl1->mask; + for(i=0; i<6000; i++ ); +} + +//----------------------------------------------------------------------------- +/// Read PID and VER +/// \param pTwid TWI interface +/// \return VER | (PID<<8) +//----------------------------------------------------------------------------- +static unsigned short ov_id(Twid *pTwid) +{ + unsigned char id=0; + unsigned char ver=0; + + // OV_PID + ov_read_reg(pTwid, 0x0A, &id); + TRACE_INFO("PID = 0x%X\n\r", id); + + // OV_VER + ov_read_reg(pTwid, 0x0B, &ver); + TRACE_INFO("VER = 0x%X\n\r", ver); + + return((unsigned short)(id <<8) | ver); +} + +//----------------------------------------------------------------------------- +/// Read Manufacturer +/// \param pTwid TWI interface +/// \return 0 if error; 1 if the good captor is present +//----------------------------------------------------------------------------- +static unsigned char ov_Manufacturer(Twid *pTwid) +{ + unsigned char midh=0; + unsigned char midl=0; + unsigned status = 0; + + // OV_MIDH + ov_read_reg(pTwid, 0x1C, &midh); + TRACE_DEBUG("MIDH = 0x%X\n\r", midh); + + // OV_MIDL + ov_read_reg(pTwid, 0x1D, &midl); + TRACE_DEBUG("MIDL = 0x%X\n\r", midl); + + if(( midh == 0x7F) && (midl == 0xA2)) { + status = 1; + } + return(status); +} +//----------------------------------------------------------------------------- +/// ov_TestWrite +/// \param pTwid TWI interface +/// \return 1 if the write is correct; 0 otherwise +//----------------------------------------------------------------------------- +static unsigned char ov_TestWrite(Twid *pTwid) +{ + unsigned char value=0; + unsigned char oldvalue=0; + + // OV_BLUE + ov_read_reg(pTwid, 0x01, &oldvalue); + ov_write_reg(pTwid, 0x01, 0xAD); + ov_read_reg(pTwid, 0x01, &value); + if( value != 0xAD ) { + return(0); + } + // return old value + ov_write_reg(pTwid, 0x01, oldvalue); + ov_read_reg(pTwid, 0x01, &value); + if( value != oldvalue ) { + return(0); + } + return(1); +} + +//----------------------------------------------------------------------------- +// Global Functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Read a value from a register in an OV9650 sensor device. +/// \param pTwid TWI interface +/// \param reg Register to be read +/// \param pData Data read +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +unsigned char ov_read_reg(Twid *pTwid, unsigned char reg, unsigned char *pData) +{ + unsigned char status; + + status = TWID_Write( pTwid, OV_CAPTOR_ADDRESS, 0, 0, ®, 1, 0); + status |= TWID_Read( pTwid, OV_CAPTOR_ADDRESS, 0, 0, pData, 1, 0); + //status = TWID_Read(pTwid, OV_CAPTOR_ADDRESS, reg, 1, pData, 1, 0); + if( status != 0 ) { + TRACE_ERROR("ov_read_reg pb"); + } + return status; +} + +//----------------------------------------------------------------------------- +/// Write a value to a register in an OV9650 sensor device. +/// \param pTwid TWI interface +/// \param reg Register to be write +/// \param val Value to be writte +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +unsigned char ov_write_reg(Twid *pTwid, unsigned char reg, unsigned char val) +{ + unsigned char status; + + status = TWID_Write(pTwid, OV_CAPTOR_ADDRESS, reg, 1, &val, 1, 0); + if( status != 0 ) { + TRACE_ERROR("ov_write_reg pb"); + } + + return status; +} + +//----------------------------------------------------------------------------- +/// Initialize a list of OV registers. +/// The list of registers is terminated by the pair of values +/// { OV_REG_TERM, OV_VAL_TERM }. +/// Returns zero if successful, or non-zero otherwise. +/// \param pTwid TWI interface +/// \param pReglist Register list to be written +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +int ov_write_regs(Twid *pTwid, const struct ov_reg* pReglist) +{ + int err; + int size=0; + const struct ov_reg *pNext = pReglist; + unsigned int i=0; + + TRACE_DEBUG("ov_write_regs:"); + while (!((pNext->reg == OV_REG_TERM) && (pNext->val == OV_VAL_TERM))) { + err = ov_write_reg(pTwid, pNext->reg, pNext->val); + TRACE_DEBUG_WP("+(%d) ", size); + size++; + + //delay(1); + for(i=0; i<6000; i++ ) { + *(unsigned int*)0x20400000 = 0; + } + + if (err == TWID_ERROR_BUSY){ + TRACE_ERROR("ov_write_regs: TWI ERROR\n\r"); + return err; + } + pNext++; + } + TRACE_DEBUG_WP("\n\r"); + return 0; +} + +//----------------------------------------------------------------------------- +/// Dump all register +/// \param pTwid TWI interface +/// \param ovType Sensor type +//----------------------------------------------------------------------------- +void ov_DumpRegisters(Twid *pTwid, unsigned char ovType) +{ + int i; + unsigned char value; + unsigned char regNum; + + switch(ovType){ + + case BOARD_OV9655: + regNum = 0xDA; + break; + + case BOARD_OV2640: + regNum = 0x5C; + break; + + default: + printf("Omnivision type %d not supported. \r\n", ovType); + return ; + break; + } + TRACE_INFO_WP("Dump all camera register\n\r"); + for(i = 0; i <= regNum; i++) { + value = 0; + ov_read_reg(pTwid, i, &value); + TRACE_INFO_WP("[0x%02x]=0x%02x ", i, value); + if( ((i+1)%5) == 0 ) { + TRACE_INFO_WP("\n\r"); + } + } + TRACE_INFO_WP("\n\r"); +} + +//----------------------------------------------------------------------------- +/// Sequence For correct operation of the sensor +/// \param pTwid TWI interface +/// \param pCtrl1 Ctrl1 signal +/// \param ovType Sensor type +/// \return 1 if initialization ok, otherwise 0 +//----------------------------------------------------------------------------- +unsigned char ov_init(Twid *pTwid, const Pin *pCtrl1, unsigned char ovType) +{ + unsigned short id=0; + unsigned short bdId; + + switch(ovType){ + + case BOARD_OV9655: + bdId = 0x96; + break; + + case BOARD_OV2640: + bdId = 0x26; + ov_reset(pCtrl1); + break; + + default: + printf("Omnivision type %d not supported. \r\n", ovType); + return 0; + break; + } + + id = ov_id(pTwid); + if( (id>>8) == bdId ) { + TRACE_DEBUG("ID and PID OK\n\r"); + if( ov_Manufacturer(pTwid) == 1 ) { + TRACE_DEBUG("Manufacturer OK\n\r"); + if( ov_TestWrite(pTwid) == 1 ) { + return 1; + } + else { + TRACE_ERROR("Problem captor: bad write\n\r"); + } + } + else { + TRACE_ERROR("Problem captor: bad Manufacturer\n\r"); + } + } + else { + TRACE_ERROR("Problem captor: bad PID\n\r"); + } + TRACE_INFO("Problem: captor not responding\n\r"); + return 0; +} + +//----------------------------------------------------------------------------- +/// Power control using ctrl2 signal +/// \param pCtrl2 PIO interface +/// \param power on, off +//----------------------------------------------------------------------------- +void ov_pwd(const Pin *pCtrl2, unsigned char power) +{ + volatile unsigned int i; + + if(pCtrl2->id == 0) + return; + + if(power == OV_CTRL2_POWER_OFF) + pCtrl2->pio->PIO_CODR = pCtrl2->mask; + else if (power == OV_CTRL2_POWER_ON) + pCtrl2->pio->PIO_SODR = pCtrl2->mask; +} + diff --git a/components/omnivision/omnivision.dir b/components/omnivision/omnivision.dir new file mode 100644 index 0000000..b363042 --- /dev/null +++ b/components/omnivision/omnivision.dir @@ -0,0 +1,43 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !Purpose +/// +/// This directory contains an API for OmniVision captor +/// +/// !Contents +/// +/// - omnivision.h api definition for omnivision captor +/// - omnivision.c driver for omnivision captor +/// - directory for specific file for OV9655 captor +//------------------------------------------------------------------------------ + diff --git a/components/omnivision/omnivision.h b/components/omnivision/omnivision.h new file mode 100644 index 0000000..1b7f220 --- /dev/null +++ b/components/omnivision/omnivision.h @@ -0,0 +1,82 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Interface for configuration the Omnivision captor. +/// +/// !!!Usage +/// +/// -# Initialize captor +/// -# Write Omnivision configuration +//------------------------------------------------------------------------------ + + +#ifndef OMNIVISION_H +#define OMNIVISION_H + +/// define a structure for monivision register initialization values +struct ov_reg +{ + /// Register to be written + unsigned char reg; + /// Value to be written in the register + unsigned char val; +}; + +/// Captor capture size +struct capture_size { + unsigned long width; + unsigned long height; +}; + +/// Omnivision sensor type +#define BOARD_OV9655 0 +#define BOARD_OV2640 1 + +/// Omnivision power control +#define OV_CTRL2_POWER_OFF 0 +#define OV_CTRL2_POWER_ON 1 + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern unsigned char ov_init(Twid *pTwid, const Pin *pCtrl1, unsigned char ovType); +extern void ov_DumpRegisters(Twid *pTwid, unsigned char ovType); +extern int ov_write_regs(Twid *pTwid, const struct ov_reg* pReglist); +extern unsigned char ov_read_reg(Twid *pTwid, unsigned char reg, unsigned char *pData); +extern unsigned char ov_write_reg(Twid *pTwid, unsigned char reg, unsigned char val); +extern void ov_configure(Twid *pTwid, unsigned int width, unsigned int heigth); +extern void ov_pwd(const Pin *pCtrl2, unsigned char power); + +#endif + diff --git a/components/omnivision/ov2640/2640_yuv_cif.h b/components/omnivision/ov2640/2640_yuv_cif.h new file mode 100644 index 0000000..55c4e2a --- /dev/null +++ b/components/omnivision/ov2640/2640_yuv_cif.h @@ -0,0 +1,239 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov2640_yuv_cif[]= { + +{0xff, 0x01}, +{0x12, 0x80}, +{0xff, 0x00}, +{0x2c, 0xff}, +{0x2e, 0xdf}, +{0xff, 0x01}, +{0x3c, 0x32}, +{0x11, 0x00}, +{0x09, 0x02}, +{0x04, 0x28}, +{0x13, 0xe5}, +{0x14, 0x48}, +{0x2c, 0x0c}, +{0x33, 0x78}, +{0x3a, 0x33}, +{0x3b, 0xfb}, +{0x3e, 0x00}, +{0x43, 0x11}, +{0x16, 0x10}, +{0x39, 0x02}, +{0x35, 0x88}, +{0x22, 0x0a}, +{0x37, 0x40}, +{0x23, 0x00}, +{0x34, 0xa0}, +{0x36, 0x1a}, +{0x06, 0x02}, +{0x07, 0xc0}, +{0x0d, 0xb7}, +{0x0e, 0x01}, +{0x4c, 0x00}, +{0x4a, 0x81}, +{0x21, 0x99}, +{0x24, 0x3a}, +{0x25, 0x32}, +{0x26, 0x82}, +{0x5c, 0x00}, +{0x63, 0x00}, +{0x5d, 0x55}, +{0x5e, 0x7d}, +{0x5f, 0x7d}, +{0x60, 0x55}, +{0x61, 0x70}, +{0x62, 0x80}, +{0x7c, 0x05}, +{0x20, 0x80}, +{0x28, 0x30}, +{0x6c, 0x00}, +{0x6d, 0x80}, +{0x6e, 0x00}, +{0x70, 0x02}, +{0x71, 0x94}, +{0x73, 0xc1}, +{0x3d, 0x34}, +{0x5a, 0x57}, +{0x4f, 0xbb}, +{0x50, 0x9c}, +{0xff, 0x00}, +{0xe5, 0x7f}, +{0xf9, 0xc0}, +{0x41, 0x24}, +{0xe0, 0x14}, +{0x76, 0xff}, +{0x33, 0xa0}, +{0x42, 0x20}, +{0x43, 0x18}, +{0x4c, 0x00}, +{0x87, 0xd0}, +{0x88, 0x3f}, +{0xd7, 0x03}, +{0xd9, 0x10}, +{0xd3, 0x82}, +{0xc8, 0x08}, +{0xc9, 0x80}, +{0x7c, 0x00}, +{0x7d, 0x02}, +{0x7c, 0x03}, +{0x7d, 0x48}, +{0x7d, 0x48}, +{0x7c, 0x08}, +{0x7d, 0x20}, +{0x7d, 0x10}, +{0x7d, 0x0e}, +{0x90, 0x00}, +{0x91, 0x0e}, +{0x91, 0x1a}, +{0x91, 0x31}, +{0x91, 0x5a}, +{0x91, 0x69}, +{0x91, 0x75}, +{0x91, 0x7e}, +{0x91, 0x88}, +{0x91, 0x8f}, +{0x91, 0x96}, +{0x91, 0xa3}, +{0x91, 0xaf}, +{0x91, 0xc4}, +{0x91, 0xd7}, +{0x91, 0xe8}, +{0x91, 0x20}, +{0x92, 0x00}, +{0x93, 0x06}, +{0x93, 0xe3}, +{0x93, 0x05}, +{0x93, 0x05}, +{0x93, 0x00}, +{0x93, 0x02}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x96, 0x00}, +{0x97, 0x08}, +{0x97, 0x19}, +{0x97, 0x02}, +{0x97, 0x0c}, +{0x97, 0x24}, +{0x97, 0x30}, +{0x97, 0x28}, +{0x97, 0x26}, +{0x97, 0x02}, +{0x97, 0x98}, +{0x97, 0x80}, +{0x97, 0x00}, +{0x97, 0x00}, +{0xc3, 0xed}, +{0xa4, 0x00}, +{0xa8, 0x00}, +{0xc5, 0x11}, +{0xc6, 0x51}, +{0xbf, 0x80}, +{0xc7, 0x10}, +{0xb6, 0x66}, +{0xb8, 0xa5}, +{0xb7, 0x64}, +{0xb9, 0x7c}, +{0xb3, 0xaf}, +{0xb4, 0x97}, +{0xb5, 0xff}, +{0xb0, 0xc5}, +{0xb1, 0x94}, +{0xb2, 0x0f}, +{0xc4, 0x5c}, +{0xc0, 0xc8}, +{0xc1, 0x96}, +{0x86, 0x1d}, +{0x50, 0x00}, +{0x51, 0x90}, +{0x52, 0x18}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x88}, +{0x57, 0x00}, +{0x5a, 0x90}, +{0x5b, 0x18}, +{0x5c, 0x05}, +{0xc3, 0xed}, +{0x7f, 0x00}, +{0xda, 0x04}, +{0xe5, 0x1f}, +{0xe1, 0x67}, +{0xe0, 0x00}, +{0xdd, 0xff}, +{0x05, 0x00}, +{0xff, 0x01}, +{0x11, 0x01}, +{0xff, 0x01}, +{0x12, 0x40}, +{0x17, 0x11}, +{0x18, 0x43}, +{0x19, 0x00}, +{0x1a, 0x4b}, +{0x32, 0x09}, +{0x4f, 0xca}, +{0x50, 0xa8}, +{0x5a, 0x23}, +{0x6d, 0x00}, +{0x3d, 0x38}, +{0x39, 0x12}, +{0x35, 0xda}, +{0x22, 0x1a}, +{0x37, 0xc3}, +{0x23, 0x00}, +{0x34, 0xc0}, +{0x36, 0x1a}, +{0x06, 0x88}, +{0x07, 0xc0}, +{0x0d, 0x87}, +{0x0e, 0x41}, +{0x4c, 0x00}, +{0x48, 0x00}, +{0x5B, 0x00}, +{0x42, 0x03}, +{0xff, 0x00}, +{0xe0, 0x04}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x1D}, +{0xd3, 0x82}, +{0xe0, 0x00}, +{0xff, 0x00}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x3D}, +{0x50, 0x89}, +{0x51, 0xC8}, +{0x52, 0x96}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x00}, +{0x5a, 0x50}, +{0x5b, 0x3C}, +{0x5c, 0x00}, +{0xd3, 0x04}, +{0xFF, 0x00}, +{0xE0, 0x04}, +{0xE1, 0x67}, +{0xD7, 0x01}, +{0xDA, 0x00}, +{0xD3, 0x82}, +{0xE0, 0x00} + +,{0xFF, 0xFF} + +}; + diff --git a/components/omnivision/ov2640/2640_yuv_qvga.h b/components/omnivision/ov2640/2640_yuv_qvga.h new file mode 100644 index 0000000..5082c9b --- /dev/null +++ b/components/omnivision/ov2640/2640_yuv_qvga.h @@ -0,0 +1,243 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov2640_yuv_qvga[]= { + +{0xff, 0x01}, +{0x12, 0x80}, +{0xff, 0x00}, +{0x2c, 0xff}, +{0x2e, 0xdf}, +{0xff, 0x01}, +{0x3c, 0x32}, +{0x11, 0x00}, +{0x09, 0x02}, +{0x04, 0x28}, +{0x13, 0xe5}, +{0x14, 0x48}, +{0x2c, 0x0c}, +{0x33, 0x78}, +{0x3a, 0x33}, +{0x3b, 0xfb}, +{0x3e, 0x00}, +{0x43, 0x11}, +{0x16, 0x10}, +{0x39, 0x02}, +{0x35, 0x88}, +{0x22, 0x0a}, +{0x37, 0x40}, +{0x23, 0x00}, +{0x34, 0xa0}, +{0x36, 0x1a}, +{0x06, 0x02}, +{0x07, 0xc0}, +{0x0d, 0xb7}, +{0x0e, 0x01}, +{0x4c, 0x00}, +{0x4a, 0x81}, +{0x21, 0x99}, +{0x24, 0x3a}, +{0x25, 0x32}, +{0x26, 0x82}, +{0x5c, 0x00}, +{0x63, 0x00}, +{0x5d, 0x55}, +{0x5e, 0x7d}, +{0x5f, 0x7d}, +{0x60, 0x55}, +{0x61, 0x70}, +{0x62, 0x80}, +{0x7c, 0x05}, +{0x20, 0x80}, +{0x28, 0x30}, +{0x6c, 0x00}, +{0x6d, 0x80}, +{0x6e, 0x00}, +{0x70, 0x02}, +{0x71, 0x94}, +{0x73, 0xc1}, +{0x3d, 0x34}, +{0x5a, 0x57}, +{0x4f, 0xbb}, +{0x50, 0x9c}, +{0xff, 0x00}, +{0xe5, 0x7f}, +{0xf9, 0xc0}, +{0x41, 0x24}, +{0xe0, 0x14}, +{0x76, 0xff}, +{0x33, 0xa0}, +{0x42, 0x20}, +{0x43, 0x18}, +{0x4c, 0x00}, +{0x87, 0xd0}, +{0x88, 0x3f}, +{0xd7, 0x03}, +{0xd9, 0x10}, +{0xd3, 0x82}, +{0xc8, 0x08}, +{0xc9, 0x80}, +{0x7c, 0x00}, +{0x7d, 0x02}, +{0x7c, 0x03}, +{0x7d, 0x48}, +{0x7d, 0x48}, +{0x7c, 0x08}, +{0x7d, 0x20}, +{0x7d, 0x10}, +{0x7d, 0x0e}, +{0x90, 0x00}, +{0x91, 0x0e}, +{0x91, 0x1a}, +{0x91, 0x31}, +{0x91, 0x5a}, +{0x91, 0x69}, +{0x91, 0x75}, +{0x91, 0x7e}, +{0x91, 0x88}, +{0x91, 0x8f}, +{0x91, 0x96}, +{0x91, 0xa3}, +{0x91, 0xaf}, +{0x91, 0xc4}, +{0x91, 0xd7}, +{0x91, 0xe8}, +{0x91, 0x20}, +{0x92, 0x00}, +{0x93, 0x06}, +{0x93, 0xe3}, +{0x93, 0x05}, +{0x93, 0x05}, +{0x93, 0x00}, +{0x93, 0x02}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x96, 0x00}, +{0x97, 0x08}, +{0x97, 0x19}, +{0x97, 0x02}, +{0x97, 0x0c}, +{0x97, 0x24}, +{0x97, 0x30}, +{0x97, 0x28}, +{0x97, 0x26}, +{0x97, 0x02}, +{0x97, 0x98}, +{0x97, 0x80}, +{0x97, 0x00}, +{0x97, 0x00}, +{0xc3, 0xed}, +{0xa4, 0x00}, +{0xa8, 0x00}, +{0xc5, 0x11}, +{0xc6, 0x51}, +{0xbf, 0x80}, +{0xc7, 0x10}, +{0xb6, 0x66}, +{0xb8, 0xa5}, +{0xb7, 0x64}, +{0xb9, 0x7c}, +{0xb3, 0xaf}, +{0xb4, 0x97}, +{0xb5, 0xff}, +{0xb0, 0xc5}, +{0xb1, 0x94}, +{0xb2, 0x0f}, +{0xc4, 0x5c}, +{0xc0, 0xc8}, +{0xc1, 0x96}, +{0x86, 0x1d}, +{0x50, 0x00}, +{0x51, 0x90}, +{0x52, 0x18}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x88}, +{0x57, 0x00}, +{0x5a, 0x90}, +{0x5b, 0x18}, +{0x5c, 0x05}, +{0xc3, 0xed}, +{0x7f, 0x00}, +{0xda, 0x04}, +{0xe5, 0x1f}, +{0xe1, 0x67}, +{0xe0, 0x00}, +{0xdd, 0xff}, +{0x05, 0x00}, +{0xff, 0x01}, +{0x11, 0x01}, +{0xff, 0x01}, +{0x12, 0x40}, +{0x17, 0x11}, +{0x18, 0x43}, +{0x19, 0x00}, +{0x1a, 0x4b}, +{0x32, 0x09}, +{0x4f, 0xca}, +{0x50, 0xa8}, +{0x5a, 0x23}, +{0x6d, 0x00}, +{0x3d, 0x38}, +{0x39, 0x12}, +{0x35, 0xda}, +{0x22, 0x1a}, +{0x37, 0xc3}, +{0x23, 0x00}, +{0x34, 0xc0}, +{0x36, 0x1a}, +{0x06, 0x88}, +{0x07, 0xc0}, +{0x0d, 0x87}, +{0x0e, 0x41}, +{0x4c, 0x00}, +{0x48, 0x00}, +{0x5B, 0x00}, +{0x42, 0x03}, +{0xff, 0x00}, +{0xe0, 0x04}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x1D}, +{0xd3, 0x82}, +{0xe0, 0x00}, +{0xff, 0x00}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x3D}, +{0x50, 0x89}, +{0x51, 0xC8}, +{0x52, 0x96}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x00}, +{0x5a, 0x50}, +{0x5b, 0x3C}, +{0x5c, 0x00}, +{0xd3, 0x04}, +{0xFF, 0x00}, +{0xE0, 0x04}, +{0xE1, 0x67}, +{0xD7, 0x01}, + +//{0xDA, 0x00}, +//leon +{0xDA, 0x00}, + +{0xD3, 0x82}, +{0xE0, 0x00} + +,{0xFF, 0xFF} + +}; + diff --git a/components/omnivision/ov2640/2640_yuv_sxga.h b/components/omnivision/ov2640/2640_yuv_sxga.h new file mode 100644 index 0000000..dfedefa --- /dev/null +++ b/components/omnivision/ov2640/2640_yuv_sxga.h @@ -0,0 +1,204 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov2640_yuv_sxga[]= { + +{0xff, 0x01}, +{0x12, 0x80}, +{0xff, 0x00}, +{0x2c, 0xff}, +{0x2e, 0xdf}, +{0xff, 0x01}, +{0x3c, 0x32}, +{0x11, 0x00}, +{0x09, 0x02}, +{0x04, 0x28}, +{0x13, 0xe5}, +{0x14, 0x48}, +{0x2c, 0x0c}, +{0x33, 0x78}, +{0x3a, 0x33}, +{0x3b, 0xfb}, +{0x3e, 0x00}, +{0x43, 0x11}, +{0x16, 0x10}, +{0x39, 0x02}, +{0x35, 0x88}, +{0x22, 0x0a}, +{0x37, 0x40}, +{0x23, 0x00}, +{0x34, 0xa0}, +{0x36, 0x1a}, +{0x06, 0x02}, +{0x07, 0xc0}, +{0x0d, 0xb7}, +{0x0e, 0x01}, +{0x4c, 0x00}, +{0x4a, 0x81}, +{0x21, 0x99}, +{0x24, 0x3a}, +{0x25, 0x32}, +{0x26, 0x82}, +{0x5c, 0x00}, +{0x63, 0x00}, +{0x5d, 0x55}, +{0x5e, 0x7d}, +{0x5f, 0x7d}, +{0x60, 0x55}, +{0x61, 0x70}, +{0x62, 0x80}, +{0x7c, 0x05}, +{0x20, 0x80}, +{0x28, 0x30}, +{0x6c, 0x00}, +{0x6d, 0x80}, +{0x6e, 0x00}, +{0x70, 0x02}, +{0x71, 0x94}, +{0x73, 0xc1}, +{0x3d, 0x34}, +{0x5a, 0x57}, +{0x4f, 0xbb}, +{0x50, 0x9c}, +{0xff, 0x00}, +{0xe5, 0x7f}, +{0xf9, 0xc0}, +{0x41, 0x24}, +{0xe0, 0x14}, +{0x76, 0xff}, +{0x33, 0xa0}, +{0x42, 0x20}, +{0x43, 0x18}, +{0x4c, 0x00}, +{0x87, 0xd0}, +{0x88, 0x3f}, +{0xd7, 0x03}, +{0xd9, 0x10}, +{0xd3, 0x82}, +{0xc8, 0x08}, +{0xc9, 0x80}, +{0x7c, 0x00}, +{0x7d, 0x02}, +{0x7c, 0x03}, +{0x7d, 0x48}, +{0x7d, 0x48}, +{0x7c, 0x08}, +{0x7d, 0x20}, +{0x7d, 0x10}, +{0x7d, 0x0e}, +{0x90, 0x00}, +{0x91, 0x0e}, +{0x91, 0x1a}, +{0x91, 0x31}, +{0x91, 0x5a}, +{0x91, 0x69}, +{0x91, 0x75}, +{0x91, 0x7e}, +{0x91, 0x88}, +{0x91, 0x8f}, +{0x91, 0x96}, +{0x91, 0xa3}, +{0x91, 0xaf}, +{0x91, 0xc4}, +{0x91, 0xd7}, +{0x91, 0xe8}, +{0x91, 0x20}, +{0x92, 0x00}, +{0x93, 0x06}, +{0x93, 0xe3}, +{0x93, 0x05}, +{0x93, 0x05}, +{0x93, 0x00}, +{0x93, 0x02}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x96, 0x00}, +{0x97, 0x08}, +{0x97, 0x19}, +{0x97, 0x02}, +{0x97, 0x0c}, +{0x97, 0x24}, +{0x97, 0x30}, +{0x97, 0x28}, +{0x97, 0x26}, +{0x97, 0x02}, +{0x97, 0x98}, +{0x97, 0x80}, +{0x97, 0x00}, +{0x97, 0x00}, +{0xc3, 0xed}, +{0xa4, 0x00}, +{0xa8, 0x00}, +{0xc5, 0x11}, +{0xc6, 0x51}, +{0xbf, 0x80}, +{0xc7, 0x10}, +{0xb6, 0x66}, +{0xb8, 0xa5}, +{0xb7, 0x64}, +{0xb9, 0x7c}, +{0xb3, 0xaf}, +{0xb4, 0x97}, +{0xb5, 0xff}, +{0xb0, 0xc5}, +{0xb1, 0x94}, +{0xb2, 0x0f}, +{0xc4, 0x5c}, +{0xc0, 0xc8}, +{0xc1, 0x96}, +{0x86, 0x1d}, +{0x50, 0x00}, +{0x51, 0x90}, +{0x52, 0x18}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x88}, +{0x57, 0x00}, +{0x5a, 0x90}, +{0x5b, 0x18}, +{0x5c, 0x05}, +{0xc3, 0xed}, +{0x7f, 0x00}, +{0xda, 0x04}, +{0xe5, 0x1f}, +{0xe1, 0x67}, +{0xe0, 0x00}, +{0xdd, 0xff}, +{0x05, 0x00}, +{0xff, 0x01}, +{0x11, 0x00}, +{0xff, 0x00}, +{0xc0, 0xC8}, +{0xc1, 0x96}, +{0x8c, 0x00}, +{0x86, 0x3D}, +{0x50, 0x00}, +{0x51, 0x90}, +{0x52, 0x2C}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x88}, +{0x5a, 0x40}, +{0x5b, 0x00}, +{0x5c, 0x05}, +{0xd3, 0x82}, +{0xFF, 0x00}, +{0xE0, 0x04}, +{0xE1, 0x67}, +{0xD7, 0x01}, +{0xDA, 0x00}, +{0xD3, 0x82}, +{0xE0, 0x00} + +,{0xFF, 0xFF} + +}; + diff --git a/components/omnivision/ov2640/2640_yuv_vga.h b/components/omnivision/ov2640/2640_yuv_vga.h new file mode 100644 index 0000000..37581e4 --- /dev/null +++ b/components/omnivision/ov2640/2640_yuv_vga.h @@ -0,0 +1,238 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.2 +//; +#include + +const struct ov_reg ov2640_yuv_vga[]= { + +{0xff, 0x01}, +{0x12, 0x80}, +{0xff, 0x00}, +{0x2c, 0xff}, +{0x2e, 0xdf}, +{0xff, 0x01}, +{0x3c, 0x32}, +{0x11, 0x00}, +{0x09, 0x02}, +{0x04, 0x28}, +{0x13, 0xe5}, +{0x14, 0x48}, +{0x2c, 0x0c}, +{0x33, 0x78}, +{0x3a, 0x33}, +{0x3b, 0xfb}, +{0x3e, 0x00}, +{0x43, 0x11}, +{0x16, 0x10}, +{0x39, 0x02}, +{0x35, 0x88}, +{0x22, 0x0a}, +{0x37, 0x40}, +{0x23, 0x00}, +{0x34, 0xa0}, +{0x36, 0x1a}, +{0x06, 0x02}, +{0x07, 0xc0}, +{0x0d, 0xb7}, +{0x0e, 0x01}, +{0x4c, 0x00}, +{0x4a, 0x81}, +{0x21, 0x99}, +{0x24, 0x3a}, +{0x25, 0x32}, +{0x26, 0x82}, +{0x5c, 0x00}, +{0x63, 0x00}, +{0x5d, 0x55}, +{0x5e, 0x7d}, +{0x5f, 0x7d}, +{0x60, 0x55}, +{0x61, 0x70}, +{0x62, 0x80}, +{0x7c, 0x05}, +{0x20, 0x80}, +{0x28, 0x30}, +{0x6c, 0x00}, +{0x6d, 0x80}, +{0x6e, 0x00}, +{0x70, 0x02}, +{0x71, 0x94}, +{0x73, 0xc1}, +{0x3d, 0x34}, +{0x5a, 0x57}, +{0x4f, 0xbb}, +{0x50, 0x9c}, +{0xff, 0x00}, +{0xe5, 0x7f}, +{0xf9, 0xc0}, +{0x41, 0x24}, +{0xe0, 0x14}, +{0x76, 0xff}, +{0x33, 0xa0}, +{0x42, 0x20}, +{0x43, 0x18}, +{0x4c, 0x00}, +{0x87, 0xd0}, +{0x88, 0x3f}, +{0xd7, 0x03}, +{0xd9, 0x10}, +{0xd3, 0x82}, +{0xc8, 0x08}, +{0xc9, 0x80}, +{0x7c, 0x00}, +{0x7d, 0x02}, +{0x7c, 0x03}, +{0x7d, 0x48}, +{0x7d, 0x48}, +{0x7c, 0x08}, +{0x7d, 0x20}, +{0x7d, 0x10}, +{0x7d, 0x0e}, +{0x90, 0x00}, +{0x91, 0x0e}, +{0x91, 0x1a}, +{0x91, 0x31}, +{0x91, 0x5a}, +{0x91, 0x69}, +{0x91, 0x75}, +{0x91, 0x7e}, +{0x91, 0x88}, +{0x91, 0x8f}, +{0x91, 0x96}, +{0x91, 0xa3}, +{0x91, 0xaf}, +{0x91, 0xc4}, +{0x91, 0xd7}, +{0x91, 0xe8}, +{0x91, 0x20}, +{0x92, 0x00}, +{0x93, 0x06}, +{0x93, 0xe3}, +{0x93, 0x05}, +{0x93, 0x05}, +{0x93, 0x00}, +{0x93, 0x02}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x93, 0x00}, +{0x96, 0x00}, +{0x97, 0x08}, +{0x97, 0x19}, +{0x97, 0x02}, +{0x97, 0x0c}, +{0x97, 0x24}, +{0x97, 0x30}, +{0x97, 0x28}, +{0x97, 0x26}, +{0x97, 0x02}, +{0x97, 0x98}, +{0x97, 0x80}, +{0x97, 0x00}, +{0x97, 0x00}, +{0xc3, 0xed}, +{0xa4, 0x00}, +{0xa8, 0x00}, +{0xc5, 0x11}, +{0xc6, 0x51}, +{0xbf, 0x80}, +{0xc7, 0x10}, +{0xb6, 0x66}, +{0xb8, 0xa5}, +{0xb7, 0x64}, +{0xb9, 0x7c}, +{0xb3, 0xaf}, +{0xb4, 0x97}, +{0xb5, 0xff}, +{0xb0, 0xc5}, +{0xb1, 0x94}, +{0xb2, 0x0f}, +{0xc4, 0x5c}, +{0xc0, 0xc8}, +{0xc1, 0x96}, +{0x86, 0x1d}, +{0x50, 0x00}, +{0x51, 0x90}, +{0x52, 0x18}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x88}, +{0x57, 0x00}, +{0x5a, 0x90}, +{0x5b, 0x18}, +{0x5c, 0x05}, +{0xc3, 0xed}, +{0x7f, 0x00}, +{0xda, 0x04}, +{0xe5, 0x1f}, +{0xe1, 0x67}, +{0xe0, 0x00}, +{0xdd, 0xff}, +{0x05, 0x00}, +{0xff, 0x01}, +{0x11, 0x01}, +{0xff, 0x01}, +{0x12, 0x40}, +{0x17, 0x11}, +{0x18, 0x43}, +{0x19, 0x00}, +{0x1a, 0x4b}, +{0x32, 0x09}, +{0x4f, 0xca}, +{0x50, 0xa8}, +{0x5a, 0x23}, +{0x6d, 0x00}, +{0x3d, 0x38}, +{0x39, 0x12}, +{0x35, 0xda}, +{0x22, 0x1a}, +{0x37, 0xc3}, +{0x23, 0x00}, +{0x34, 0xc0}, +{0x36, 0x1a}, +{0x06, 0x88}, +{0x07, 0xc0}, +{0x0d, 0x87}, +{0x0e, 0x41}, +{0x4c, 0x00}, +{0x48, 0x00}, +{0x5B, 0x00}, +{0x42, 0x03}, +{0xff, 0x00}, +{0xe0, 0x04}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x1D}, +{0xd3, 0x82}, +{0xe0, 0x00}, +{0xff, 0x00}, +{0xc0, 0x64}, +{0xc1, 0x4B}, +{0x8c, 0x00}, +{0x86, 0x3D}, +{0x50, 0x00}, +{0x51, 0xC8}, +{0x52, 0x96}, +{0x53, 0x00}, +{0x54, 0x00}, +{0x55, 0x00}, +{0x5a, 0xA0}, +{0x5b, 0x78}, +{0x5c, 0x00}, +{0xd3, 0x04}, +{0xFF, 0x00}, +{0xE0, 0x04}, +{0xE1, 0x67}, +{0xD7, 0x01}, +{0xDA, 0x00}, +{0xD3, 0x82}, +{0xE0, 0x00} + +,{0xFF, 0xFF} + +}; + diff --git a/components/omnivision/ov2640/ov2640.c b/components/omnivision/ov2640/ov2640.c new file mode 100644 index 0000000..ccb10e2 --- /dev/null +++ b/components/omnivision/ov2640/ov2640.c @@ -0,0 +1,143 @@ +// ---------------------------------------------------------------------------- +// ATMEL Microcontroller Software Support - ROUSSET - +// ---------------------------------------------------------------------------- +// Copyright (c) 2009, Atmel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the disclaimer below. +// +// Atmel's name may not be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +// DISCLAIMED. IN NO EVENT SHALL ATMEL 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 + +#if defined(BOARD_CAPTOR_OV2640) + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Specific configuration for Omnivision OV2640 captor +/// +/// !!!Usage +/// +/// -# Different files are been provided by Omnivision: +/// - 2640_yuv_cif.h +/// - 2640_yuv_qcif.h +/// - 2640_yuv_qqcif.h +/// - 2640_yuv_qqvga.h +/// - 2640_yuv_qvga.h +/// - 2640_yuv_sxga.h +/// - 2640_yuv_vga.h +/// -# Configure the captor using theses files +//-------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- +#include +#include + +#include + +#include "2640_yuv_cif.h" +#include "2640_yuv_qvga.h" +#include "2640_yuv_sxga.h" +#include "2640_yuv_vga.h" + +//------------------------------------------------------------------------------ +/// Array of image sizes supported by OV264x +//------------------------------------------------------------------------------ +const static struct capture_size ov264x_sizes[] = { +// {width, height} + /// QVGA + { 320, 240 }, + /// CIF + { 352, 288 }, + /// VGA + { 640, 480 }, + /// SXGA + {1280, 1024 } +}; + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +/// Configure the OV9650 for a specified image size, pixel format, +/// and frame period. +//----------------------------------------------------------------------------- +void ov_configure(Twid *pTwid, unsigned int width, unsigned int heigth) +{ + const struct ov_reg *reg_conf; + unsigned char goodCaptureSize = 0; + unsigned char i; + + TRACE_DEBUG("ov264x_configure\n\r"); + for( i=0; i + +const struct ov_reg ov9655_yuv_cif[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x09 }, // Vertical Control Frame + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + { 0x12, 0x62 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x18 }, + { 0x18, 0x0c }, + { 0x19, 0x01 }, + { 0x1a, 0x81 }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xe4 }, + { 0x33, 0x00 }, + { 0x34, 0x3f }, + { 0x35, 0x00 }, + { 0x36, 0x3a }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0e }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x01 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + + { 0x52, 0x28 }, // Matrix Coefficient 4 + { 0x53, 0x88 }, // Matrix Coefficient 5 + { 0x54, 0xb0 }, // Matrix Coefficient 6 + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x00 }, // Pixel Output Index + { 0x73, 0x01 }, // Horizontal Scaling Down Coefficients + { 0x74, 0x3a }, + { 0x75, 0x35 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + + { 0x8c, 0x80 }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x81 }, // Common control 24 + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_qcif.h b/components/omnivision/ov9655/9655_yuv_qcif.h new file mode 100644 index 0000000..5eb8c33 --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_qcif.h @@ -0,0 +1,162 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov9655_yuv_qcif[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x12 }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + { 0x12, 0x62 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x18 }, + { 0x18, 0x0c }, + { 0x19, 0x01 }, + { 0x1a, 0x81 }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xa4 }, + { 0x33, 0x00 }, + { 0x34, 0x3f }, + { 0x35, 0x00 }, + { 0x36, 0x3a }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0e }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x01 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + + + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x11 }, + { 0x73, 0x02 }, + { 0x74, 0x3a }, + { 0x75, 0x35 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + { 0x8a, 0x24 }, + { 0x8c, 0x80 }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x82 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_qqcif.h b/components/omnivision/ov9655/9655_yuv_qqcif.h new file mode 100644 index 0000000..e327635 --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_qqcif.h @@ -0,0 +1,163 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov9655_yuv_qqcif[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x12 }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + { 0x12, 0x62 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x3a }, + { 0x18, 0x02 }, + { 0x19, 0x01 }, + { 0x1a, 0x3d }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xbf }, + { 0x33, 0x00 }, + { 0x34, 0x3f }, + { 0x35, 0x00 }, + { 0x36, 0x3a }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x02 }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x01 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + { 0x59, 0x85 }, + { 0x5a, 0xa9 }, + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x22 }, + { 0x73, 0x02 }, + { 0x74, 0x3a }, + { 0x75, 0x35 }, + { 0x76, 0x29 }, + { 0x77, 0x02 }, + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + + + { 0x8a, 0x24 }, + { 0x8c, 0x80 }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x82 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_qqvga.h b/components/omnivision/ov9655/9655_yuv_qqvga.h new file mode 100644 index 0000000..f30b5b9 --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_qqvga.h @@ -0,0 +1,169 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov9655_yuv_qqvga[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x02 }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + { 0x12, 0x62 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x18 }, + { 0x18, 0x04 }, + { 0x19, 0x01 }, + { 0x1a, 0x81 }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xa4 }, + { 0x33, 0x00 }, + { 0x34, 0x3f }, + { 0x35, 0x00 }, + { 0x36, 0x3a }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0e }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x01 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + + + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + + + + { 0x59, 0x85 }, + { 0x5a, 0xa9 }, + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x22 }, + { 0x73, 0x02 }, + { 0x74, 0x10 }, + { 0x75, 0x10 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + + + { 0x8a, 0x24 }, + + { 0x8c, 0x80 }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x82 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_qvga.h b/components/omnivision/ov9655/9655_yuv_qvga.h new file mode 100644 index 0000000..c2bc02d --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_qvga.h @@ -0,0 +1,166 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov9655_yuv_qvga[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x02 }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + { 0x12, 0x62 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x18 }, + { 0x18, 0x04 }, + { 0x19, 0x01 }, + { 0x1a, 0x81 }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0x24 }, + { 0x33, 0x00 }, + { 0x34, 0x3f }, + { 0x35, 0x00 }, + { 0x36, 0x3a }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0e }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x01 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + + { 0x59, 0x85 }, + { 0x5a, 0xa9 }, + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x11 }, + { 0x73, 0x01 }, + { 0x74, 0x10 }, + { 0x75, 0x10 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + + + { 0x8a, 0x24 }, + { 0x8c, 0x80 }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x81 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_sxga.h b/components/omnivision/ov9655/9655_yuv_sxga.h new file mode 100644 index 0000000..9ee1aa4 --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_sxga.h @@ -0,0 +1,164 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.1 +//; + +#include + +const struct ov_reg ov9655_yuv_sxga[]= { + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x1b }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x00 }, + { 0x12, 0x02 }, + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x1d }, + { 0x18, 0xbd }, + { 0x19, 0x01 }, + { 0x1a, 0x81 }, + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xff }, + { 0x33, 0x00 }, + { 0x34, 0x3d }, + { 0x35, 0x00 }, + { 0x36, 0xf8 }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0c }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x00 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x00 }, + { 0x58, 0x1a }, + { 0x58, 0x1a }, + { 0x59, 0x85 }, + { 0x5a, 0xa9 }, + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x16 }, + { 0x66, 0x01 }, + { 0x69, 0x02 }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x00 }, + { 0x73, 0x01 }, + { 0x74, 0x3a }, + { 0x75, 0x35 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + + + { 0x8a, 0x03 }, + { 0x8c, 0x0d }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x03 }, + { 0x9e, 0x04 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xe2 }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x80 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/9655_yuv_vga.h b/components/omnivision/ov9655/9655_yuv_vga.h new file mode 100644 index 0000000..adddf08 --- /dev/null +++ b/components/omnivision/ov9655/9655_yuv_vga.h @@ -0,0 +1,168 @@ +//; Generated by Sensor Tool +//; Ver: 1.2.2 +//; +#include + +const struct ov_reg ov9655_yuv_vga[]= { + + { 0x12, 0x80 }, + { 0x00, 0x00 }, + { 0x01, 0x80 }, + { 0x02, 0x80 }, + { 0x03, 0x12 }, + { 0x04, 0x03 }, + { 0x0e, 0x61 }, + { 0x0f, 0x42 }, + { 0x11, 0x01 }, + + { 0x12, 0x62 }, // YUV 30fps + { 0x13, 0xe7 }, + { 0x14, 0x3a }, + { 0x16, 0x24 }, + { 0x17, 0x16 }, + { 0x18, 0x02 }, + { 0x19, 0x01 }, + { 0x1a, 0x3d }, + + { 0x1e, 0x04 }, + { 0x24, 0x3c }, + { 0x25, 0x36 }, + { 0x26, 0x72 }, + { 0x27, 0x08 }, + + { 0x28, 0x08 }, + { 0x29, 0x15 }, + { 0x2a, 0x00 }, + { 0x2b, 0x00 }, + { 0x2c, 0x08 }, + { 0x32, 0xff }, + { 0x33, 0x00 }, + { 0x34, 0x3F }, + + { 0x35, 0x00 }, + { 0x36, 0xfa }, + { 0x38, 0x72 }, + { 0x39, 0x57 }, + // { 0x3a, 0x80 }, // YUYV output sequence + { 0x3a, 0x00 }, // No delay + + { 0x3b, 0x04 }, + { 0x3d, 0x99 }, + { 0x3e, 0x0c }, + { 0x3f, 0xc1 }, + { 0x40, 0xc0 }, + { 0x41, 0x00 }, + { 0x42, 0xc0 }, + { 0x43, 0x0a }, + { 0x44, 0xf0 }, + { 0x45, 0x46 }, + { 0x46, 0x62 }, + { 0x47, 0x2a }, + { 0x48, 0x3c }, + { 0x4a, 0xfc }, + { 0x4b, 0xfc }, + { 0x4c, 0x7f }, + { 0x4d, 0x7f }, + { 0x4e, 0x7f }, + + { 0x52, 0x28 }, + { 0x53, 0x88 }, + { 0x54, 0xb0 }, + { 0x4f, 0x98 }, + { 0x50, 0x98 }, + { 0x51, 0x0 }, + { 0x58, 0x1a }, + + { 0x59, 0x85 }, + { 0x5a, 0xa9 }, + { 0x5b, 0x64 }, + { 0x5c, 0x84 }, + { 0x5d, 0x53 }, + { 0x5e, 0x0e }, + { 0x5f, 0xf0 }, + { 0x60, 0xf0 }, + { 0x61, 0xf0 }, + { 0x62, 0x00 }, + { 0x63, 0x00 }, + { 0x64, 0x02 }, + { 0x65, 0x20 }, + { 0x66, 0x00 }, + { 0x69, 0x0a }, + { 0x6b, 0x5a }, //bypass internal regulator +// { 0x6b, 0x4a }, // use internal regulator + { 0x6c, 0x04 }, + { 0x6d, 0x55 }, + { 0x6e, 0x00 }, + { 0x6f, 0x9d }, + { 0x70, 0x21 }, + { 0x71, 0x78 }, + { 0x72, 0x00 }, + { 0x73, 0x00 }, + { 0x74, 0x3a }, + { 0x75, 0x35 }, + { 0x76, 0x01 }, + { 0x77, 0x02 }, + + { 0x7a, 0x12 }, + { 0x7b, 0x08 }, + { 0x7c, 0x15 }, + { 0x7d, 0x24 }, + { 0x7e, 0x45 }, + { 0x7f, 0x55 }, + { 0x80, 0x6a }, + { 0x81, 0x78 }, + { 0x82, 0x87 }, + { 0x83, 0x96 }, + { 0x84, 0xa3 }, + { 0x85, 0xb4 }, + { 0x86, 0xc3 }, + { 0x87, 0xd6 }, + { 0x88, 0xe6 }, + { 0x89, 0xf2 }, + + { 0x8c, 0x8d }, + { 0x90, 0x7d }, + { 0x91, 0x7b }, + { 0x9d, 0x02 }, + { 0x9e, 0x02 }, + { 0x9f, 0x7a }, + { 0xa0, 0x79 }, + { 0xa1, 0x40 }, + { 0xa4, 0x50 }, + { 0xa5, 0x68 }, + { 0xa6, 0x4a }, + { 0xa8, 0xc1 }, + { 0xa9, 0xef }, + { 0xaa, 0x92 }, + { 0xab, 0x04 }, + { 0xac, 0x80 }, + { 0xad, 0x80 }, + { 0xae, 0x80 }, + { 0xaf, 0x80 }, + { 0xb2, 0xf2 }, + { 0xb3, 0x20 }, + { 0xb4, 0x20 }, + { 0xb5, 0x00 }, + { 0xb6, 0xaf }, + { 0xbb, 0xae }, + { 0xbc, 0x7f }, + { 0xbd, 0x7f }, + { 0xbe, 0x7f }, + { 0xbf, 0x7f }, + { 0xc0, 0xaa }, + { 0xc1, 0xc0 }, + { 0xc2, 0x01 }, + { 0xc3, 0x4e }, + { 0xc6, 0x05 }, + { 0xc7, 0x80 }, + { 0xc9, 0xe0 }, + { 0xca, 0xe8 }, + { 0xcb, 0xf0 }, + { 0xcc, 0xd8 }, + { 0xcd, 0x93 }, + { 0xcd, 0x93 } + + ,{ 0xFF, 0xFF } +}; + + diff --git a/components/omnivision/ov9655/ov9655.c b/components/omnivision/ov9655/ov9655.c new file mode 100644 index 0000000..6ee9873 --- /dev/null +++ b/components/omnivision/ov9655/ov9655.c @@ -0,0 +1,163 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 + +#if defined(BOARD_CAPTOR_OV9650) +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Specific configuration for Omnivision OV6555 captor +/// +/// !!!Usage +/// +/// -# Different files are been provided by Omnivision: +/// - 9655_yuv_cif.h +/// - 9655_yuv_qcif.h +/// - 9655_yuv_qqcif.h +/// - 9655_yuv_qqvga.h +/// - 9655_yuv_qvga.h +/// - 9655_yuv_sxga.h +/// - 9655_yuv_vga.h +/// -# Configure the captor using theses files +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- +#include +#include + +#include + +#include "9655_yuv_cif.h" +#include "9655_yuv_qcif.h" +#include "9655_yuv_qqcif.h" +#include "9655_yuv_qvga.h" +#include "9655_yuv_qqvga.h" +#include "9655_yuv_sxga.h" +#include "9655_yuv_vga.h" + +//------------------------------------------------------------------------------ +/// Array of image sizes supported by OV965x +//------------------------------------------------------------------------------ +const static struct capture_size ov965x_sizes[] = { +// {width, height} + /// QQCIF + { 88, 72 }, + /// QQVGA + { 160, 120 }, + /// QCIF + { 176, 144 }, + /// QVGA + { 320, 240 }, + /// CIF + { 352, 288 }, + /// VGA + { 640, 480 }, + /// SXGA + {1280, 1024 } +}; + +//------------------------------------------------------------------------------ +// Global Functions +//------------------------------------------------------------------------------ + +//----------------------------------------------------------------------------- +/// Configure the OV9650 for a specified image size, pixel format, +/// and frame period. +//----------------------------------------------------------------------------- +void ov_configure(Twid *pTwid, unsigned int width, unsigned int heigth) +{ + const struct ov_reg *reg_conf; + unsigned char goodCaptureSize = 0; + unsigned char i; + + TRACE_DEBUG("ov965x_configure\n\r"); + for( i=0; i +#include +#include + +//------------------------------------------------------------------------------ +// Local definitions +//------------------------------------------------------------------------------ + +/// Baudrate divisor value. +#define SCBR (0xFF << 8) + +/// Command for retrieving calibration word 1. +#define CMD_WORD_1 /*0x0EA8*/ 0x1D50 +/// Command for retrieving calibration word 2. +#define CMD_WORD_2 /*0x0EB0*/ 0x1D60 +/// Command for retrieving calibration word 3. +#define CMD_WORD_3 /*0x0EC8*/ 0x1D90 +/// Command for retrieving calibration word 4. +#define CMD_WORD_4 /*0x0ED0*/ 0x1DA0 +/// Command for starting a pressure conversion. +#define CMD_PRES 0x0F40 +/// Command for starting a temperature conversion. +#define CMD_TEMP 0x0F20 + +/// Driver is idle. +#define STATE_IDLE 0 +/// Driver is performing a temperature conversion. +#define STATE_TEMP 1 +/// Driver is performing a pressure conversion. +#define STATE_PRES 2 + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// SPI peripheral used to connect to the MS5540B. +static AT91S_SPI *lpSpi; + +/// Chip select configured for the sensor. +static unsigned int lCs; + +/// Calibration coefficients. +static unsigned short lCoeffs[6]; + +/// Current driver state. +static unsigned char lState; + +/// Last temperature measurement made. +static unsigned short lD2 = 0; + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Reads & returns the result of the last command. +//------------------------------------------------------------------------------ +unsigned short Fetch(void) +{ + unsigned short result; + + // Configure SPI to receive the first 8 data bytes + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_BITS_8 | SCBR); + + // Read the first 8 bytes + SPI_Write(lpSpi, lCs, 0); + while (!SPI_IsFinished(lpSpi)); + result = (SPI_Read(lpSpi) & 0xFF) << 8; + + // Configure SPI to receive the next 8 bytes (with one dummy byte) + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_BITS_9 | SCBR); + + // Read the last 8 bytes + SPI_Write(lpSpi, lCs, 0); + while (!SPI_IsFinished(lpSpi)); + result |= (SPI_Read(lpSpi) >> 1) & 0xFF; + + TRACE_DEBUG("MS5540B_Fetch: Result = %d\n\r", result); + + return result; +} + +//------------------------------------------------------------------------------ +/// Resets the sensor. +//------------------------------------------------------------------------------ +static void Reset() +{ + const unsigned short pCommand[] = {0x00AA, 0x1540}; + + SANITY_CHECK(SPI_IsFinished(lpSpi)); + + TRACE_DEBUG("MS5540B_Reset()\n\r"); + + // Configure chip select for 8 bits transfer + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_NCPHA | AT91C_SPI_BITS_8 | SCBR); + + // Transfer first 8 bits + SPI_Write(lpSpi, lCs, pCommand[0]); + while (!SPI_IsFinished(lpSpi)); + + // Configure chip select for 13 bits transfer + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_NCPHA | AT91C_SPI_BITS_13 | SCBR); + + // Transfer remaining 13 bits + SPI_Write(lpSpi, lCs, pCommand[1]); + while (!SPI_IsFinished(lpSpi)); +} + +//------------------------------------------------------------------------------ +/// Reads and returns a calibration word from the sensor. +/// \param cmd Command to retrieve desired word (CMD_WORD_1 ... CMD_WORD_4). +//------------------------------------------------------------------------------ +static unsigned short ReadCalibrationWord(unsigned short cmd) +{ + TRACE_DEBUG("MS5540B_ReadCalibrationWord(0x%04X)\n\r", cmd); + + SANITY_CHECK((cmd == CMD_WORD_1) + || (cmd == CMD_WORD_2) + || (cmd == CMD_WORD_3) + || (cmd == CMD_WORD_4)); + SANITY_CHECK(SPI_IsFinished(lpSpi)); + + // Configure SPI to send the command + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_NCPHA | AT91C_SPI_BITS_13 | SCBR); + + // Transfer command + SPI_Write(lpSpi, lCs, cmd); + while (!SPI_IsFinished(lpSpi)); + + // Read & return result + return Fetch(); +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes a MS5540B sensor. The provided SPI peripheral is configured +/// for the sensor (using the given chip select), and the calibration data +/// is extracted. +/// The sensor MUST BE CLOCKED before calling this function. It can then be +/// unclocked in-between measurements. +/// In addition, the SPI peripheral must be configured properly prior to calling +/// this function. +/// \param pSpi Pointer to the SPI peripheral connected to the MS5540B. +/// \param cs Chip select value to use. +//------------------------------------------------------------------------------ +void MS5540B_Initialize(AT91S_SPI *pSpi, unsigned char cs) +{ + unsigned short word1, word2, word3, word4; + + SANITY_CHECK(pSpi); + + TRACE_DEBUG("MS5540B_Initialize(0x%08X, %d)\n\r", pSpi, cs); + + // Store SPI information + lpSpi = pSpi; + lCs = cs; + lState = STATE_IDLE; + + // Reset the sensor + Reset(); + + // Extract calibration data from the sensor + word1 = ReadCalibrationWord(CMD_WORD_1); + word2 = ReadCalibrationWord(CMD_WORD_2); + word3 = ReadCalibrationWord(CMD_WORD_3); + word4 = ReadCalibrationWord(CMD_WORD_4); + + TRACE_DEBUG("Word1 = %d\n\r", word1); + TRACE_DEBUG("Word2 = %d\n\r", word2); + TRACE_DEBUG("Word3 = %d\n\r", word3); + TRACE_DEBUG("Word4 = %d\n\r", word4); + + // Compute coefficients + lCoeffs[0] = (word1 >> 1) & 0x7FFF; + lCoeffs[1] = (word4 & 0x003F) | ((word3 & 0x003F) << 6); + lCoeffs[2] = (word4 >> 6) & 0x03FF; + lCoeffs[3] = (word3 >> 6) & 0x03FF; + lCoeffs[4] = ((word2 >> 6) | ((word1 & 0x0001) << 10)) & 0x07FF; + lCoeffs[5] = word2 & 0x003F; + + TRACE_DEBUG("C1 = %d\n\r", lCoeffs[0]); + TRACE_DEBUG("C2 = %d\n\r", lCoeffs[1]); + TRACE_DEBUG("C3 = %d\n\r", lCoeffs[2]); + TRACE_DEBUG("C4 = %d\n\r", lCoeffs[3]); + TRACE_DEBUG("C5 = %d\n\r", lCoeffs[4]); + TRACE_DEBUG("C6 = %d\n\r", lCoeffs[5]); +} + +//------------------------------------------------------------------------------ +/// Starts a temperature acquisition. This function returns as soon as the +/// command has been sent. +/// The conversion must be completed by calling MS5540B_ConversionFinished() +/// whenever the device signals the end-of-conversion. +//------------------------------------------------------------------------------ +void MS5540B_AcquireTemperature(void) +{ + SANITY_CHECK(lState == STATE_IDLE); + + TRACE_DEBUG("MS5540B_AcquireTemperature()\n\r"); + + // Configure SPI for 12 bits transfers + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_NCPHA | AT91C_SPI_BITS_12 | AT91C_SPI_CSAAT | SCBR); + + // Send command + SPI_Write(lpSpi, lCs, CMD_TEMP); + while (!SPI_IsFinished(lpSpi)); + + // Update driver state + lState = STATE_TEMP; +} + +//------------------------------------------------------------------------------ +/// Starts a pressure acquisition. This function returns as soon as the +/// command has been sent. +/// The conversion must be completed by calling MS5540B_ConversionFinished() +/// whenever the device signals the end-of-conversion. +/// A temperature measurement must have been performed prior to calling this +/// function. +//------------------------------------------------------------------------------ +void MS5540B_AcquirePressure(void) +{ + SANITY_CHECK(lState == STATE_IDLE); + SANITY_CHECK(lD2 != 0); + + TRACE_DEBUG("MS5540B_AcquirePressure()\n\r"); + + // Configure SPI for 12 bits transfers + SPI_ConfigureNPCS(lpSpi, lCs, AT91C_SPI_NCPHA | AT91C_SPI_BITS_12 | AT91C_SPI_CSAAT | SCBR); + + // Send command + SPI_Write(lpSpi, lCs, CMD_PRES); + while (!SPI_IsFinished(lpSpi)); + + // Update driver state + lState = STATE_PRES; +} + +//------------------------------------------------------------------------------ +/// Fetches and returns the result of the last conversion from the sensor. This +/// function must only be called whenever the MS5540B signals that the +/// conversion is completed with the DOUT signal line. +/// The temperature returned is 10*C° (e.g. 31.4°C -> 314). +//------------------------------------------------------------------------------ +unsigned short MS5540B_ConversionFinished(void) +{ + signed short result; + signed short dT; + unsigned short offset, sensitivity, x; + + SANITY_CHECK((lState == STATE_TEMP) || (lState == STATE_PRES)); + + TRACE_DEBUG("MS5540B_ConversionFinished()\n\r"); + + // Retrieve conversion result + result = (signed short) Fetch(); + + // Correct result using calibration data + if (lState == STATE_TEMP) { + + lD2 = result; + dT = result - 8 * lCoeffs[4] - 20224; + result = 200 + dT * (lCoeffs[5] + 50) / 1024; + TRACE_DEBUG("D2 = %d\n\r", lD2); + TRACE_DEBUG("dT = %d\n\r", dT); + TRACE_DEBUG("TEMP = %d\n\r", result); + } + else { + + TRACE_DEBUG("D1 = %d\n\r", result); + dT = lD2 - 8 * lCoeffs[4] - 20224; + offset = lCoeffs[1] * 4 + ((lCoeffs[3] - 512) * dT) / 4096; + sensitivity = lCoeffs[0] + (lCoeffs[2] * dT) / 1024 + 24576; + x = (sensitivity * (result - 7168)) / 16384 - offset; + result = x * 10 / 32 + 2500; + TRACE_DEBUG("dT = %d\n\r", dT); + TRACE_DEBUG("OFF = %d\n\r", offset); + TRACE_DEBUG("SENS = %d\n\r", sensitivity); + TRACE_DEBUG("X = %d\n\r", x); + TRACE_DEBUG("P = %d\n\r", result); + } + + // Update driver state + lState = STATE_IDLE; + + return result; +} + diff --git a/components/sensors/ms5540b/ms5540b.h b/components/sensors/ms5540b/ms5540b.h new file mode 100644 index 0000000..3057f09 --- /dev/null +++ b/components/sensors/ms5540b/ms5540b.h @@ -0,0 +1,52 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 MS5540B_H +#define MS5540B_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void MS5540B_Initialize(AT91S_SPI *pSpi, unsigned char cs); + +extern void MS5540B_AcquireTemperature(void); + +extern void MS5540B_AcquirePressure(void); + +extern unsigned short MS5540B_ConversionFinished(void); + +#endif //#ifndef MS5540B_H + diff --git a/components/slcd/s7leklcd/s7leklcd.c b/components/slcd/s7leklcd/s7leklcd.c new file mode 100644 index 0000000..aa3c894 --- /dev/null +++ b/components/slcd/s7leklcd/s7leklcd.c @@ -0,0 +1,271 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "s7leklcd.h" +#include +#include + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// List of the 26 SLCD upper chars ( A ~ Z ) +static const unsigned short pLcdUpperChars[26] = { + S7LEKLCD_A, S7LEKLCD_B, S7LEKLCD_C, S7LEKLCD_D, + S7LEKLCD_E, S7LEKLCD_F, S7LEKLCD_G, S7LEKLCD_H, + S7LEKLCD_I, S7LEKLCD_J, S7LEKLCD_K, S7LEKLCD_L, + S7LEKLCD_M, S7LEKLCD_N, S7LEKLCD_O, S7LEKLCD_P, + S7LEKLCD_Q, S7LEKLCD_R, S7LEKLCD_S, S7LEKLCD_T, + S7LEKLCD_U, S7LEKLCD_V, S7LEKLCD_W, S7LEKLCD_X, + S7LEKLCD_Y, S7LEKLCD_Z +}; + +/// List of the 26 SLCD lower chars ( a ~ z ) +static const unsigned short pLcdLowerChars[26] = { + S7LEKLCD_a, S7LEKLCD_b, S7LEKLCD_c, S7LEKLCD_d, + S7LEKLCD_e, S7LEKLCD_f, S7LEKLCD_g, S7LEKLCD_h, + S7LEKLCD_i, S7LEKLCD_j, S7LEKLCD_k, S7LEKLCD_l, + S7LEKLCD_m, S7LEKLCD_n, S7LEKLCD_o, S7LEKLCD_p, + S7LEKLCD_q, S7LEKLCD_r, S7LEKLCD_s, S7LEKLCD_t, + S7LEKLCD_u, S7LEKLCD_v, S7LEKLCD_w, S7LEKLCD_x, + S7LEKLCD_y, S7LEKLCD_z +}; + +/// List of the 10 SLCD numbers ( 0 ~ 9 ) +static const unsigned short pLcdNumbers[10] = { + S7LEKLCD_0, S7LEKLCD_1, S7LEKLCD_2, S7LEKLCD_3, + S7LEKLCD_4, S7LEKLCD_5, S7LEKLCD_6, S7LEKLCD_7, + S7LEKLCD_8, S7LEKLCD_9 +}; + +//------------------------------------------------------------------------------ +// Local functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Returns the LCD character code to display given an input character. +/// \param c Character to display. +/// \param dot Indicates if the character should be dotted or not. +//------------------------------------------------------------------------------ +static unsigned short GetSLcdChar(unsigned char c, unsigned char dot) +{ + unsigned short symbol = 0; + + // Add dot if needed + if (dot) { + + symbol = S7LEKLCD_DOT; + } + + // Find corresponding symbol for character + // Space + if (c == ' ') { + + symbol |= S7LEKLCD_NONE; + } + // Single dot + else if (c == '.') { + + symbol |= S7LEKLCD_NONE | S7LEKLCD_DOT; + } + // Number + else if ((c >= '0') && (c <= '9')) { + + symbol |= pLcdNumbers[c - '0']; + } + // Lower-case letter + else if ((c >= 'a') && (c <= 'z')) { + + symbol |= pLcdLowerChars[c - 'a']; + } + // Upper case letter + else if ((c >= 'A') && (c <= 'Z')) { + + symbol |= pLcdUpperChars[c - 'A']; + } + // Special characters + else { + switch (c) { + case '+': symbol |= S7LEKLCD_PLUS; break; + case '-': symbol |= S7LEKLCD_MINUS; break; + case '=': symbol |= S7LEKLCD_EQUAL; break; + case '>': symbol |= S7LEKLCD_LARGE; break; + case '<': symbol |= S7LEKLCD_LESS; break; + case '\\': symbol |= S7LEKLCD_SLASH; break; + case '/': symbol |= S7LEKLCD_BACKSLASH; break; + case '$': symbol |= S7LEKLCD_DOLLAR; break; + case '|': symbol |= S7LEKLCD_OR; break; + case ',': symbol |= S7LEKLCD_COMMA; break; + case '\'': symbol |= S7LEKLCD_INVCOMMA1; break; + case '"': symbol |= S7LEKLCD_INVCOMMA2; break; + case '_': symbol |= D; break; + default: symbol = S7LEKLCD_NONE; + } + } + + return symbol; +} + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Switches a symbol of the LCD on or off. +/// \param symbol Symbol Index in the LCD buffer matrix. +/// \param set If 1, the symbol is turned on; otherwise it is turned off. +//------------------------------------------------------------------------------ +void S7LEKLCD_Symbol(unsigned short symbol, unsigned char set) +{ + unsigned int common = symbol / 40; + unsigned int reg = (symbol % 40) / 32; + unsigned int bit = (symbol % 40) % 32; + + if (set) { + + AT91C_BASE_SLCDC->SLCDC_MEM[common * 2 + reg] |= 1 << bit; + } + else { + + AT91C_BASE_SLCDC->SLCDC_MEM[common * 2 + reg] &= ~(1 << bit); + } +} + +//------------------------------------------------------------------------------ +/// Switches a pixel of the matrix on or off. +/// \param x Horizontal pixel coordinate. +/// \param y Vertical pixel coordinate. +/// \param set If true, the pixel is switched on; otherwise it is switched off. +//------------------------------------------------------------------------------ +void S7LEKLCD_Pixel(unsigned char x, unsigned char y, unsigned char set) +{ + SANITY_CHECK(x < 12); + SANITY_CHECK(y < 10); + + S7LEKLCD_Symbol((x + 1) + (40 * (9 - y)), set); +} + +//------------------------------------------------------------------------------ +/// Displays a character at the given position on the LCD. +/// \param c Character definition. +/// \param index Position of the character on the LCD ([0...11]). +//------------------------------------------------------------------------------ +void S7LEKLCD_Char(unsigned short c, unsigned char index) +{ + SANITY_CHECK(index < 12); + + S7LEKLCD_Symbol((40 * 2) + 37 - index * 2 , (c & A) != 0); + S7LEKLCD_Symbol((40 * 4) + 37 - index * 2 , (c & B) != 0); + S7LEKLCD_Symbol((40 * 6) + 37 - index * 2 , (c & C) != 0); + S7LEKLCD_Symbol((40 * 8) + 38 - index * 2 , (c & D) != 0); + S7LEKLCD_Symbol((40 * 6) + 38 - index * 2 , (c & E) != 0); + S7LEKLCD_Symbol((40 * 4) + 38 - index * 2 , (c & F) != 0); + S7LEKLCD_Symbol((40 * 5) + 38 - index * 2 , (c & G) != 0); + S7LEKLCD_Symbol((40 * 5) + 37 - index * 2 , (c & H) != 0); + S7LEKLCD_Symbol((40 * 3) + 38 - index * 2 , (c & I) != 0); + S7LEKLCD_Symbol((40 * 2) + 38 - index * 2 , (c & J) != 0); + S7LEKLCD_Symbol((40 * 3) + 37 - index * 2 , (c & K) != 0); + S7LEKLCD_Symbol((40 * 7) + 38 - index * 2 , (c & L) != 0); + S7LEKLCD_Symbol((40 * 8) + 37 - index * 2 , (c & M) != 0); + S7LEKLCD_Symbol((40 * 7) + 37 - index * 2 , (c & N) != 0); + S7LEKLCD_Symbol((40 * 9) + 37 - index * 2 , (c & P) != 0); +} + +//------------------------------------------------------------------------------ +/// Displays a clock number at the given position. +/// \param c Number definition. +/// \param index Position of the character to be displayed ([0..3]). +//------------------------------------------------------------------------------ +void S7LEKLCD_ClockNumber(unsigned short c, unsigned char index) +{ + SANITY_CHECK(index < 4); + + S7LEKLCD_Symbol((40 * 0) + 30 - index * 4 , (c & A) != 0); + S7LEKLCD_Symbol((40 * 0) + 29 - index * 4 , (c & B) != 0); + S7LEKLCD_Symbol((40 * 0) + 27 - index * 4 , (c & C) != 0); + S7LEKLCD_Symbol((40 * 1) + 27 - index * 4 , (c & D) != 0); + S7LEKLCD_Symbol((40 * 1) + 28 - index * 4 , (c & E) != 0); + S7LEKLCD_Symbol((40 * 1) + 29 - index * 4 , (c & F) != 0); + S7LEKLCD_Symbol((40 * 0) + 28 - index * 4 , (c & G) != 0); +} + +//------------------------------------------------------------------------------ +/// Displays a string on the SLCD starting at the specified character index. +/// \param pString String to display. +/// \param index Starting index of string. +//------------------------------------------------------------------------------ +void S7LEKLCD_PutString(const char *pString, unsigned char index) +{ + unsigned char i; + unsigned char j; + unsigned char dot; + + // Clear characters before index + for (i=0; i < index; i++) { + + S7LEKLCD_Char(S7LEKLCD_NONE, i); + } + + // Display string + j = 0; + dot = 0; + while ((i < S7LEKLCD_MAX_CHARS) && (pString[j] != 0)) { + + // Check if next character is a dot + if (pString[j+1] == '.') { + + dot = 1; + } + + // Skip dots + if (pString[j] == '.') { + + j++; + } + // Display character + else { + + S7LEKLCD_Char(GetSLcdChar(pString[j], dot), i); + dot = 0; + i++; + j++; + } + } + + // Clear characters at end of string + for (; i < S7LEKLCD_MAX_CHARS; i++) { + + S7LEKLCD_Char(S7LEKLCD_NONE, i); + } +} + diff --git a/components/slcd/s7leklcd/s7leklcd.dir b/components/slcd/s7leklcd/s7leklcd.dir new file mode 100644 index 0000000..0b88b5d --- /dev/null +++ b/components/slcd/s7leklcd/s7leklcd.dir @@ -0,0 +1,40 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains APIs for segment LCD display of AT91SAM7L-EK board. +/// +/// !!!Contents +/// +/// Contains code for display symbol, pixel of the matrix, char, clock number and string. +//------------------------------------------------------------------------------ \ No newline at end of file diff --git a/components/slcd/s7leklcd/s7leklcd.h b/components/slcd/s7leklcd/s7leklcd.h new file mode 100644 index 0000000..336ee47 --- /dev/null +++ b/components/slcd/s7leklcd/s7leklcd.h @@ -0,0 +1,321 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Interface for displaying on segment LCD of AT91SAM7L-EK board.. +/// +/// !!!Usage +/// +/// -# call corresponding function to display symbol, pixel of the matrix, char, +/// clock number and string. +//------------------------------------------------------------------------------ + +#ifndef _S7LEKLCD_H +#define _S7LEKLCD_H + +//------------------------------------------------------------------------------ +// Global Constants +//------------------------------------------------------------------------------ + +/// Maximum number of characters that can be displayed on the LCD. +#define S7LEKLCD_MAX_CHARS 12 + +//------------------------------------------------------------------------------ +/// \page "SAM7L-EK SLCD Segments" +/// This page lists the segment constants used to describe letters on the +/// SAM7L-EK segment LCD display. +/// +/// !Constants +/// - A +/// - B +/// - C +/// - D +/// - E +/// - F +/// - G +/// - H +/// - I +/// - J +/// - K +/// - L +/// - M +/// - N +/// - P + +/// A segment definition. +#define A (1 << 0) +/// B segment definition. +#define B (1 << 1) +/// C segment definition. +#define C (1 << 2) +/// D segment definition. +#define D (1 << 3) +/// E segment definition. +#define E (1 << 4) +/// F segment definition. +#define F (1 << 5) +/// G segment definition. +#define G (1 << 6) +/// H segment definition. +#define H (1 << 7) +/// I segment definition. +#define I (1 << 8) +/// J segment definition. +#define J (1 << 9) +/// K segment definition. +#define K (1 << 10) +/// L segment definition. +#define L (1 << 11) +/// M segment definition. +#define M (1 << 12) +/// N segment definition. +#define N (1 << 13) +/// P segment definition. +#define P (1 << 14) +//------------------------------------------------------------------------------ + +/// Enables all the segments of one LCD slot. +#define S7LEKLCD_ALL (A | B | C | D | E | F | G | H | I |J | K | L | M | N) +/// Disables all the segments of one LCD slot. +#define S7LEKLCD_NONE 0 +/// Dot definition. +#define S7LEKLCD_DOT P + +// Upper-case letters. +#define S7LEKLCD_A (A | B | C | E | F | G | H) +#define S7LEKLCD_B (A | B | C | D | H | J | M) +#define S7LEKLCD_C (A | D | E | F) +#define S7LEKLCD_D (A | B | C | D | J | M) +#define S7LEKLCD_E (A | D | E | F | G | H) +#define S7LEKLCD_F (A | E | F | G | H) +#define S7LEKLCD_G (A | C | D | E | F | H) +#define S7LEKLCD_H (B | C | E | F | G | H) +#define S7LEKLCD_I (A | J | M | D) +#define S7LEKLCD_J (B | C | D | E) +#define S7LEKLCD_K (E | F | G | K | N) +#define S7LEKLCD_L (D | E | F ) +#define S7LEKLCD_M (B | C | E | F | I | K ) +#define S7LEKLCD_N (B | C | E | F | I | N) +#define S7LEKLCD_O (A | B | C | D | E | F) +#define S7LEKLCD_P (A | B | E | F | G | H) +#define S7LEKLCD_Q (A | B | C | D | E | F | N) +#define S7LEKLCD_R (A | B | E | F | G | H | N) +#define S7LEKLCD_S (A | C | D | F | G | H) +#define S7LEKLCD_T (A | J | M ) +#define S7LEKLCD_U (B | C | D | E | F) +#define S7LEKLCD_V (E | F | K | L) +#define S7LEKLCD_W (B | C | E | F | J | L | N) +#define S7LEKLCD_X (I | K | L | N) +#define S7LEKLCD_Y (I | K | M) +#define S7LEKLCD_Z (A | D | K | L) + +// Lower-case letters. +#define S7LEKLCD_a (D | E | G | M) +#define S7LEKLCD_b (E | F | G | L) +#define S7LEKLCD_c (D | E | G ) +#define S7LEKLCD_d (B | C | H | N) +#define S7LEKLCD_e (D | E | G | L) +#define S7LEKLCD_f (A | E | F | G) +#define S7LEKLCD_g (A | B | C | D | H | J) +#define S7LEKLCD_h (E | F | G | M) +#define S7LEKLCD_i (M) +#define S7LEKLCD_j (J | L) +#define S7LEKLCD_k (J | K | M | N) +#define S7LEKLCD_l (J | M ) +#define S7LEKLCD_m (C | E | G | H | M) +#define S7LEKLCD_n (C | E | G | H) +#define S7LEKLCD_o (C | D | E | G | H) +#define S7LEKLCD_p (A | E | F | G | K) +#define S7LEKLCD_q (A | B | C | F | H | I) +#define S7LEKLCD_r (J | K | M) +#define S7LEKLCD_s (D | H | N) +#define S7LEKLCD_t (G | H | J | N) +#define S7LEKLCD_u (C | D | E) +#define S7LEKLCD_v (E | H | L) +#define S7LEKLCD_w (C | E | L | N) +#define S7LEKLCD_x (I | J | L | N) +#define S7LEKLCD_y (I | K | L) +#define S7LEKLCD_z (D | G | L) + +// Numbers. +#define S7LEKLCD_0 (A | B | C | D | E | F) +#define S7LEKLCD_1 (J | M) +#define S7LEKLCD_2 (A | B | D | E | G | H) +#define S7LEKLCD_3 (A | B | C | D | G | H) +#define S7LEKLCD_4 (F | G | H | J | M) +#define S7LEKLCD_5 (A | C | D | F | G | H) +#define S7LEKLCD_6 (A | C | D | E | F | G| H) +#define S7LEKLCD_7 (A | B | C) +#define S7LEKLCD_8 (A | B | C | D | E | F | G | H) +#define S7LEKLCD_9 (A | B | C | D | F | G | H) + +// Clock numbers. +#define S7LEKLCD_C0 (A | B | C | D | E | F) +#define S7LEKLCD_C1 (B | C) +#define S7LEKLCD_C2 (A | B | D | E | G ) +#define S7LEKLCD_C3 (A | B | C | D | G ) +#define S7LEKLCD_C4 (B | C | F | G) +#define S7LEKLCD_C5 (A | C | D | F | G ) +#define S7LEKLCD_C6 (A | C | D | E | F | G) +#define S7LEKLCD_C7 (A | B | C) +#define S7LEKLCD_C8 (A | B | C | D | E | F | G ) +#define S7LEKLCD_C9 (A | B | C | D | F | G ) + +// Symbols +#define S7LEKLCD_PLUS (G | H | J | M) +#define S7LEKLCD_MINUS (G | H) +#define S7LEKLCD_LARGE (I | L) +#define S7LEKLCD_LESS (K | N) +#define S7LEKLCD_SLASH (K | L) +#define S7LEKLCD_BACKSLASH (I | M) +#define S7LEKLCD_DOLLAR (A | C | D | F | G | H | J | M) +#define S7LEKLCD_OR (J | M) +#define S7LEKLCD_COMMA L +#define S7LEKLCD_UNDERSCORE D +#define S7LEKLCD_INVCOMMA1 I +#define S7LEKLCD_INVCOMMA2 K +#define S7LEKLCD_EQUAL (D | G |H) +#define S7LEKLCD_MULTIPLY (G | H | I | J | K | L | M | N) +#define S7LEKLCD_AT (A | B | C | D | E | G |M) + +/// Symbols definitions +/// Each symbol is defined by the bit offset in the 400 bits matrix +#define S7LEKLCD_ARROW1 (40 * 0 ) +#define S7LEKLCD_ARROW2 (40 * 1 ) +#define S7LEKLCD_ARROW3 (40 * 2 ) +#define S7LEKLCD_Q2 (40 * 3 ) +#define S7LEKLCD_Q1 (40 * 4 ) +#define S7LEKLCD_Q0 (40 * 5 ) +#define S7LEKLCD_Q4 (40 * 6 ) +#define S7LEKLCD_Q3 (40 * 7 ) +#define S7LEKLCD_KEY (40 * 8 ) +#define S7LEKLCD_SOUND (40 * 9 ) + +#define S7LEKLCD_S0 (40 * 1 + 39) +#define S7LEKLCD_S1 (40 * 0 + 39) +#define S7LEKLCD_S2 (40 * 1 + 39) +#define S7LEKLCD_S3 (40 * 2 + 39) +#define S7LEKLCD_S4 (40 * 3 + 39) +#define S7LEKLCD_S5 (40 * 4 + 39) +#define S7LEKLCD_S6 (40 * 5 + 39) +#define S7LEKLCD_S7 (40 * 6 + 39) +#define S7LEKLCD_S8 (40 * 7 + 39) +#define S7LEKLCD_S9 (40 * 8 + 39) +#define S7LEKLCD_S10 (40 * 9 + 39) +#define S7LEKLCD_COLON (40 * 0 + 38) +#define S7LEKLCD_LINE (40 * 1 + 38) +#define S7LEKLCD_HEX (40 * 9 + 38) + +#define S7LEKLCD_ATMEL (40 * 0 + 37) + +#define S7LEKLCD_SNOW (40 * 0 + 36) +#define S7LEKLCD_FIRE (40 * 1 + 36) + +#define S7LEKLCD_BIN (40 * 9 + 36) +#define S7LEKLCD_DEC (40 * 9 + 34) +#define S7LEKLCD_AUTO (40 * 9 + 32) +#define S7LEKLCD_TIME (40 * 9 + 30) +#define S7LEKLCD_DATE (40 * 9 + 26) +#define S7LEKLCD_PROG (40 * 9 + 24) +#define S7LEKLCD_SETUP (40 * 9 + 20) +#define S7LEKLCD_2NDF (40 * 9 + 16) + +#define S7LEKLCD_1P (40 * 9 + 37) +#define S7LEKLCD_2P (40 * 9 + 35) +#define S7LEKLCD_3P (40 * 9 + 33) +#define S7LEKLCD_4P (40 * 9 + 31) +#define S7LEKLCD_5P (40 * 9 + 29) +#define S7LEKLCD_6P (40 * 9 + 27) +#define S7LEKLCD_7P (40 * 9 + 25) +#define S7LEKLCD_8P (40 * 9 + 23) +#define S7LEKLCD_9P (40 * 9 + 21) +#define S7LEKLCD_10P (40 * 9 + 19) +#define S7LEKLCD_11P (40 * 9 + 17) +#define S7LEKLCD_12P (40 * 9 + 15) + +#define S7LEKLCD_V0 (40 * 0 + 35) +#define S7LEKLCD_VOL (40 * 1 + 35) +#define S7LEKLCD_V1 (40 * 0 + 34) +#define S7LEKLCD_V2 (40 * 1 + 34) +#define S7LEKLCD_V4 (40 * 0 + 33) +#define S7LEKLCD_V3 (40 * 1 + 33) + +#define S7LEKLCD_CLOCK (40 * 0 + 32) +#define S7LEKLCD_TOOL (40 * 1 + 32) + +#define S7LEKLCD_AM (40 * 0 + 31) +#define S7LEKLCD_PM (40 * 1 + 31) + +#define S7LEKLCD_COL1 (40 * 9 + 28) +#define S7LEKLCD_COL2 (40 * 9 + 22) +#define S7LEKLCD_COL3 (40 * 9 + 18) +#define S7LEKLCD_COL4 (40 * 1 + 30) + +#define S7LEKLCD_DMM (40 * 0 + 13) +#define S7LEKLCD_TMP (40 * 1 + 13) +#define S7LEKLCD_BARO (40 * 2 + 13) +#define S7LEKLCD_HZ (40 * 3 + 13) +#define S7LEKLCD_MHZ (40 * 4 + 13) +#define S7LEKLCD_INHG (40 * 5 + 13) +#define S7LEKLCD_KHZ (40 * 6 + 13) +#define S7LEKLCD_HPA (40 * 7 + 13) +#define S7LEKLCD_OHM (40 * 8 + 13) +#define S7LEKLCD_SUN (40 * 9 + 13) + +#define S7LEKLCD_CALC (40 * 0 + 14) +#define S7LEKLCD_FAHRENHEIT (40 * 1 + 14) +#define S7LEKLCD_CELSIUS (40 * 2 + 14) +#define S7LEKLCD_PENSENT (40 * 3 + 14) +#define S7LEKLCD_AMPS (40 * 4 + 14) +#define S7LEKLCD_VOLTS (40 * 5 + 14) +#define S7LEKLCD_KWH (40 * 6 + 14) +#define S7LEKLCD_FINE (40 * 7 + 14) +#define S7LEKLCD_CLOUD (40 * 8 + 14) +#define S7LEKLCD_RAIN (40 * 9 + 14) + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void S7LEKLCD_Symbol(unsigned short symbol, unsigned char set); + +extern void S7LEKLCD_Pixel(unsigned char x, unsigned char y, unsigned char set); + +extern void S7LEKLCD_Char(unsigned short c, unsigned char index); + +extern void S7LEKLCD_ClockNumber(unsigned short c, unsigned char index); + +extern void S7LEKLCD_PutString(const char *pString, unsigned char index); + +#endif //#ifndef _S7LEKLCD_H + diff --git a/components/slcd/s7lstklcd/font.h b/components/slcd/s7lstklcd/font.h new file mode 100644 index 0000000..ae5b27f --- /dev/null +++ b/components/slcd/s7lstklcd/font.h @@ -0,0 +1,71 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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 FONT_H +#define FONT_H + +//----------------------------------------------------------------------------- +// Definitions +//----------------------------------------------------------------------------- + +/// Maximum character width in pixels. +#define FONT_CHAR_MAX_WIDTH 8 + +//----------------------------------------------------------------------------- +// Types +//----------------------------------------------------------------------------- + +/// Font information structure. +typedef struct _Font { + + // Font width in pixels. + unsigned char width; + // Font height in pixels. + unsigned char height; + // First character in font data. + unsigned char firstCharacter; + // Last character in font data. + unsigned char lastCharacter; + // Font data, containing (lastCharacter - firstCharacter) characters, + // (height) bytes per character, each byte corresponding + // to one line of the character. Bits are ordered as follow: + // MSB ------------------------------------ LSB + // Leftmost bit - ... - Rightmost bit - Padding + const unsigned char *pData; + +} Font; + +//----------------------------------------------------------------------------- +// Global variables +//----------------------------------------------------------------------------- + +extern const Font gFont; + +#endif //#ifndef FONT_H + diff --git a/components/slcd/s7lstklcd/font1.c b/components/slcd/s7lstklcd/font1.c new file mode 100644 index 0000000..d1c60f2 --- /dev/null +++ b/components/slcd/s7lstklcd/font1.c @@ -0,0 +1,306 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "font.h" + +//----------------------------------------------------------------------------- +// Local variables +//----------------------------------------------------------------------------- + +/// Font data. +static const unsigned char pData[] = { + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x70, 0x88, 0xD8, 0x88, 0xF8, 0xA8, 0x88, 0x70, + 0x70, 0xF8, 0xA8, 0xF8, 0x88, 0xD8, 0x88, 0x70, + 0x00, 0x50, 0xF8, 0xF8, 0xF8, 0x70, 0x20, 0x00, + 0x00, 0x20, 0x70, 0xF8, 0x70, 0x20, 0x00, 0x00, + 0x20, 0x70, 0x70, 0xD8, 0x70, 0x20, 0x20, 0x70, + 0x20, 0x70, 0xF8, 0xF8, 0x70, 0x20, 0x20, 0x70, + 0x00, 0x00, 0x20, 0x70, 0x70, 0x20, 0x00, 0x00, + 0xF8, 0xF8, 0xD8, 0x88, 0x88, 0xD8, 0xF8, 0xF8, + 0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x00, 0x00, + 0xF8, 0xF8, 0xD8, 0xA8, 0xA8, 0xD8, 0xF8, 0xF8, + 0x38, 0x18, 0x28, 0x60, 0x90, 0x90, 0x60, 0x00, + 0x70, 0x88, 0x88, 0x70, 0x20, 0xF8, 0x20, 0x20, + 0x38, 0x28, 0x20, 0x20, 0x20, 0x60, 0xE0, 0x40, + 0x78, 0x48, 0x78, 0x48, 0x48, 0x58, 0xD8, 0xC0, + 0x20, 0xA8, 0x70, 0xD8, 0x70, 0xA8, 0x20, 0x00, + 0x40, 0x60, 0x70, 0x78, 0x70, 0x60, 0x40, 0x00, + 0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10, 0x00, + 0x20, 0x70, 0xF8, 0x20, 0x20, 0xF8, 0x70, 0x20, + 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x50, 0x50, + 0x78, 0xA8, 0xA8, 0xA8, 0x68, 0x28, 0x28, 0x28, + 0x30, 0x48, 0x20, 0x50, 0x20, 0x90, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, + 0x20, 0x70, 0xF8, 0x20, 0xF8, 0x70, 0x20, 0xF8, + 0x20, 0x70, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xF8, 0x70, 0x20, + 0x00, 0x20, 0x30, 0xF8, 0x30, 0x20, 0x00, 0x00, + 0x00, 0x20, 0x60, 0xF8, 0x60, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x60, 0x60, 0x78, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x50, 0xF8, 0x50, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x70, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF8, 0x70, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, + 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x50, 0xF8, 0x50, 0xF8, 0x50, 0x00, 0x00, + 0x20, 0x78, 0x80, 0x60, 0x30, 0x08, 0xF0, 0x20, + 0x00, 0xC0, 0xC8, 0x10, 0x20, 0x40, 0x98, 0x18, + 0x60, 0x90, 0x90, 0x60, 0x68, 0x90, 0x90, 0x68, + 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x20, 0x40, 0x40, 0x40, 0x40, 0x20, 0x10, + 0x40, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x40, + 0x20, 0xA8, 0x70, 0xF8, 0x70, 0xA8, 0x20, 0x00, + 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, + 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, + 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, + 0x70, 0x88, 0x98, 0xA8, 0xA8, 0xC8, 0x88, 0x70, + 0x20, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, + 0x70, 0x88, 0x08, 0x08, 0x10, 0x20, 0x40, 0xF8, + 0x70, 0x88, 0x08, 0x30, 0x08, 0x08, 0x88, 0x70, + 0x10, 0x30, 0x50, 0x90, 0xF8, 0x10, 0x10, 0x10, + 0xF8, 0x80, 0x80, 0xF0, 0x08, 0x08, 0x88, 0x70, + 0x70, 0x88, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x70, + 0xF8, 0x08, 0x08, 0x10, 0x20, 0x20, 0x20, 0x20, + 0x70, 0x88, 0x88, 0x70, 0x88, 0x88, 0x88, 0x70, + 0x70, 0x88, 0x88, 0x78, 0x08, 0x08, 0x88, 0x70, + 0x00, 0x60, 0x60, 0x00, 0x00, 0x60, 0x60, 0x00, + 0x00, 0x60, 0x60, 0x00, 0x00, 0x60, 0x60, 0xC0, + 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x00, + 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, + 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00, + 0x70, 0x88, 0x08, 0x10, 0x20, 0x20, 0x00, 0x20, + 0x70, 0x88, 0xB8, 0xA8, 0xA8, 0xB8, 0x80, 0x78, + 0x70, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x88, + 0xF0, 0x88, 0x88, 0xF0, 0x88, 0x88, 0x88, 0xF0, + 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, 0x88, 0x70, + 0xF0, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF0, + 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0xF8, + 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x80, + 0x70, 0x88, 0x80, 0xB8, 0x88, 0x88, 0x88, 0x70, + 0x88, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x88, + 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x90, 0x90, 0x60, + 0x88, 0x90, 0xA0, 0xC0, 0xC0, 0xA0, 0x90, 0x88, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, + 0x88, 0xD8, 0xA8, 0xA8, 0xA8, 0x88, 0x88, 0x88, + 0x88, 0xC8, 0xC8, 0xA8, 0xA8, 0x98, 0x98, 0x88, + 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0xF0, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x80, + 0x70, 0x88, 0x88, 0x88, 0x88, 0xA8, 0x90, 0x68, + 0xF0, 0x88, 0x88, 0xF0, 0xC0, 0xA0, 0x90, 0x88, + 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, 0x88, 0x70, + 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x50, 0x20, + 0x88, 0x88, 0x88, 0xA8, 0xA8, 0xA8, 0xD8, 0x88, + 0x88, 0x88, 0x50, 0x20, 0x20, 0x50, 0x88, 0x88, + 0x88, 0x88, 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xF8, 0x08, 0x10, 0x20, 0x20, 0x40, 0x80, 0xF8, + 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, + 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, + 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x60, + 0x20, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, + 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x78, 0x00, + 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x00, + 0x00, 0x00, 0x70, 0x88, 0x80, 0x88, 0x70, 0x00, + 0x08, 0x08, 0x78, 0x88, 0x88, 0x88, 0x78, 0x00, + 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x78, 0x00, + 0x30, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x00, 0x00, 0x78, 0x88, 0x88, 0x78, 0x08, 0xF0, + 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0xA0, 0x40, + 0x80, 0x80, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00, 0x00, 0x50, 0xA8, 0xA8, 0x88, 0x88, 0x00, + 0x00, 0x00, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x00, + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00, 0x00, 0xE0, 0x90, 0x90, 0xE0, 0x80, 0x80, + 0x00, 0x00, 0x70, 0x90, 0x90, 0x70, 0x10, 0x10, + 0x00, 0x00, 0xB0, 0xC0, 0x80, 0x80, 0x80, 0x00, + 0x00, 0x00, 0x78, 0x80, 0x70, 0x08, 0xF0, 0x00, + 0x40, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x60, 0x00, + 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x00, + 0x00, 0x00, 0x88, 0x88, 0xA8, 0xA8, 0x50, 0x00, + 0x00, 0x00, 0x88, 0x50, 0x20, 0x50, 0x88, 0x00, + 0x00, 0x00, 0x88, 0x88, 0x88, 0x78, 0x08, 0xF0, + 0x00, 0x00, 0xF8, 0x10, 0x20, 0x40, 0xF8, 0x00, + 0x10, 0x20, 0x20, 0x40, 0x40, 0x20, 0x20, 0x10, + 0x20, 0x20, 0x20, 0x00, 0x00, 0x20, 0x20, 0x20, + 0x40, 0x20, 0x20, 0x10, 0x10, 0x20, 0x20, 0x40, + 0x50, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x60, 0x90, 0x90, 0xF0, + 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x20, 0x60, + 0x50, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x10, 0x20, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, + 0x30, 0x48, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, + 0x50, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, + 0x40, 0x20, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, + 0x20, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, + 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x20, 0x60, + 0x20, 0x50, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, + 0x50, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, + 0x40, 0x20, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, + 0x50, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x50, 0x00, 0x70, 0x88, 0x88, 0xF8, 0x88, 0x88, + 0x20, 0x00, 0x70, 0x88, 0x88, 0xF8, 0x88, 0x88, + 0x20, 0x40, 0xF8, 0x80, 0xE0, 0x80, 0x80, 0xF8, + 0x00, 0x00, 0x50, 0xA8, 0x38, 0x60, 0xA8, 0x70, + 0x78, 0xA0, 0xA0, 0xF0, 0xA0, 0xA0, 0xA0, 0xB8, + 0x20, 0x50, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x88, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x40, 0x20, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x20, 0x50, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x40, 0x20, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x50, 0x00, 0x88, 0x50, 0x20, 0x20, 0x20, 0x20, + 0x88, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x50, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x20, 0x70, 0xA8, 0xA0, 0xA0, 0xA8, 0x70, 0x20, + 0x70, 0x88, 0x80, 0x40, 0x70, 0x40, 0x88, 0xF0, + 0x88, 0x50, 0x20, 0x70, 0x20, 0x70, 0x20, 0x20, + 0xF0, 0x88, 0x88, 0xF0, 0xA0, 0xF0, 0xA8, 0xB0, + 0x30, 0x28, 0x20, 0x70, 0x20, 0xA0, 0xA0, 0x40, + 0x10, 0x20, 0x70, 0x88, 0x78, 0x88, 0x88, 0x78, + 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x10, 0x20, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x10, 0x20, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, + 0x50, 0xA8, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x88, + 0x50, 0xA8, 0x88, 0xC8, 0xA8, 0xA8, 0x98, 0x88, + 0x00, 0x70, 0x88, 0x78, 0x88, 0x78, 0x00, 0xF8, + 0x00, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00, 0xF8, + 0x20, 0x00, 0x20, 0x20, 0x40, 0x88, 0x88, 0x70, + 0x00, 0x00, 0x00, 0x78, 0x40, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x00, 0x00, + 0x40, 0xC8, 0x50, 0xE0, 0x50, 0xA8, 0x10, 0x38, + 0x40, 0xC8, 0x50, 0xE0, 0x50, 0xD0, 0x78, 0x10, + 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, + 0x00, 0x10, 0x28, 0x50, 0xA0, 0x50, 0x28, 0x10, + 0x00, 0x40, 0xA0, 0x50, 0x28, 0x50, 0xA0, 0x40, + 0x20, 0x90, 0x48, 0x20, 0x90, 0x48, 0x20, 0x90, + 0x56, 0xAE, 0x51, 0xAC, 0x55, 0xA8, 0x50, 0xA8, + 0x68, 0xD8, 0xB0, 0x68, 0xD8, 0xB6, 0x6F, 0xD8, + 0x20, 0x20, 0x27, 0x22, 0x23, 0x22, 0x24, 0x20, + 0x20, 0x22, 0x27, 0xE2, 0x25, 0x23, 0x24, 0x20, + 0x23, 0x24, 0xE5, 0x23, 0xE4, 0x27, 0x23, 0x20, + 0x21, 0x25, 0x24, 0xE5, 0x23, 0x24, 0x23, 0x20, + 0x01, 0x05, 0x04, 0xFE, 0x2D, 0x28, 0x2F, 0x28, + 0x06, 0x03, 0xE0, 0x20, 0xE0, 0x20, 0x23, 0x20, + 0x2F, 0x2D, 0xE8, 0x0E, 0xE9, 0x2C, 0x28, 0x28, + 0x2F, 0x2B, 0x28, 0x2F, 0x2F, 0x28, 0x28, 0x28, + 0x03, 0x00, 0x06, 0xFC, 0x0A, 0xED, 0x2B, 0x28, + 0x2C, 0x2E, 0x2D, 0xE8, 0x08, 0xF8, 0x00, 0x00, + 0x29, 0x28, 0x28, 0xF8, 0x03, 0x01, 0x00, 0x00, + 0x22, 0xE0, 0x20, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x05, 0xE3, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x3E, 0x04, 0x01, 0x04, 0x00, + 0x21, 0x20, 0x20, 0xF8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0xF8, 0x20, 0x23, 0x21, 0x20, + 0x27, 0x24, 0x20, 0x38, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x24, 0x38, 0x20, 0x38, 0x20, 0x20, 0x20, + 0xA0, 0xA0, 0xA2, 0xB8, 0xA0, 0xA0, 0xA2, 0xA0, + 0xA0, 0xA4, 0xA0, 0xB8, 0x80, 0xFF, 0x06, 0x00, + 0x07, 0x06, 0x04, 0xFD, 0x80, 0xBF, 0xA0, 0xA0, + 0x50, 0x53, 0x50, 0xD9, 0x05, 0xF9, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xF8, 0x00, 0xD8, 0x50, 0x50, + 0x50, 0x50, 0x50, 0x58, 0x40, 0x58, 0x50, 0x50, + 0x00, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x00, + 0x50, 0x50, 0x50, 0xD8, 0x00, 0xD8, 0x50, 0x50, + 0x20, 0x20, 0x20, 0xF8, 0x00, 0xF8, 0x00, 0x00, + 0x50, 0x50, 0x50, 0x50, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x20, 0x20, + 0x00, 0x00, 0x00, 0xF8, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0x78, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x38, 0x20, 0x38, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x38, 0x20, 0x38, 0x20, 0x20, + 0x00, 0x00, 0x00, 0x78, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0xD8, 0x50, 0x50, 0x50, 0x50, + 0x20, 0x20, 0xF8, 0x00, 0xF8, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x20, + 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, + 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, + 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, + 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, + 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x68, 0x90, 0x68, 0x00, 0x00, + 0x60, 0x90, 0x90, 0xE0, 0x90, 0x88, 0xC8, 0xB0, + 0xF8, 0x88, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0xF8, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x58, + 0xF8, 0x88, 0x80, 0x40, 0x20, 0x40, 0x88, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x90, 0x90, 0x60, + 0x00, 0x00, 0x00, 0x88, 0x88, 0x98, 0xE8, 0x80, + 0x00, 0x00, 0x00, 0x58, 0xA0, 0x20, 0x20, 0x20, + 0xF8, 0x70, 0xA8, 0xA8, 0xA8, 0xA8, 0x70, 0xF8, + 0x70, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x70, + 0x70, 0x88, 0x88, 0x88, 0x50, 0x50, 0x50, 0xD8, + 0x70, 0x88, 0x80, 0x40, 0x70, 0x88, 0x88, 0x70, + 0x00, 0x00, 0x00, 0x88, 0xD8, 0xA8, 0xD8, 0x88, + 0x00, 0x00, 0x00, 0x70, 0x98, 0xA8, 0xC8, 0x70, + 0x38, 0x40, 0x80, 0xE0, 0x80, 0x80, 0x40, 0x38, + 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0xF8, 0x00, + 0x00, 0x20, 0x70, 0x20, 0x20, 0x00, 0xF8, 0x00, + 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0xF8, + 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0xF8, + 0x10, 0x28, 0x28, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xA0, 0x40, + 0x00, 0x20, 0x00, 0x70, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x50, 0xA8, 0x00, 0x50, 0xA8, 0x00, 0x00, + 0x20, 0x50, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x70, 0x70, 0x70, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x38, 0x20, 0x20, 0x20, 0x20, 0xA0, 0x60, 0x20, + 0x40, 0xA0, 0xA0, 0xA0, 0x00, 0x00, 0x00, 0x00, + 0x40, 0xA0, 0x40, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +//----------------------------------------------------------------------------- +// Global variables +//----------------------------------------------------------------------------- + +const Font gFont = {5, 8, 0, 255, pData}; + diff --git a/components/slcd/s7lstklcd/s7lstklcd.c b/components/slcd/s7lstklcd/s7lstklcd.c new file mode 100644 index 0000000..7ab1671 --- /dev/null +++ b/components/slcd/s7lstklcd/s7lstklcd.c @@ -0,0 +1,187 @@ +/* --------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- + +#include "s7lstklcd.h" +#include "font.h" +#include +#include +#include + +//----------------------------------------------------------------------------- +// Global functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Switches a pixel on the SLCD on or off. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \param set If 1, pixel is displayed; otherwise it is hidden. +//----------------------------------------------------------------------------- +void S7LSTKLCD_Pixel(unsigned char x, unsigned char y, unsigned char set) +{ + unsigned int symbol = y * S7LSTKLCD_WIDTH + x; + unsigned int common = symbol / S7LSTKLCD_NUM_SEGMENTS; + unsigned int segment = symbol % S7LSTKLCD_NUM_SEGMENTS; + unsigned int reg = segment / 32; + unsigned int bit = segment % 32; + + SANITY_CHECK(x < S7LSTKLCD_WIDTH); + SANITY_CHECK(y < S7LSTKLCD_HEIGHT); + + if (set) { + + AT91C_BASE_SLCDC->SLCDC_MEM[common * 2 + reg] |= (1 << bit); + } + else { + + AT91C_BASE_SLCDC->SLCDC_MEM[common * 2 + reg] &= ~(1 << bit); + } +} + +//----------------------------------------------------------------------------- +/// Displays a character at the given position on the SLCD. The character is +/// clipped according to the SLCD dimensions. +/// Note that x and y can be negative (upper-left part of character will be +/// clipped). +/// \param x X-coordinate of upper-left corner of character. +/// \param y Y-coordinate of upper-left corner of character. +/// \param c Character to display. +//----------------------------------------------------------------------------- +void S7LSTKLCD_Char(signed int x, signed int y, unsigned char c) +{ + const unsigned char *pChar; + signed int i, j; + + SANITY_CHECK(c >= gFont.firstCharacter); + SANITY_CHECK(c <= gFont.lastCharacter); + + // Optimization: return if coordinates are out of bounds + if ((x > S7LSTKLCD_WIDTH) || ((x+gFont.width) < 0) + || (y > S7LSTKLCD_HEIGHT) || ((y+gFont.height) < 0)) { + + return; + } + + // Get pointer to character in font data + pChar = &(gFont.pData[(c - gFont.firstCharacter) * gFont.height]); + + // Display character at requested location + for (j=0; j < gFont.height; j++) { + for (i=0; i < gFont.width; i++) { + + if (((x+i) >= 0) && ((x+i) < S7LSTKLCD_WIDTH) + && ((y+i >= 0)) && ((y+i) < S7LSTKLCD_HEIGHT)) { + + S7LSTKLCD_Pixel(x+i, y+j, (pChar[j] & (1 << (FONT_CHAR_MAX_WIDTH-i-1)))); + } + } + } +} + +//----------------------------------------------------------------------------- +/// Displays a string on the SLCD given the top-left corner coordinates. String +/// is clipped according to the SLCD dimensions. +/// X and Y can be negative (top-left clipping). +/// \param x X-coordinate of top-left corner. +/// \param y Y-coordinate of top-left corner. +/// \param pString String to display. +//----------------------------------------------------------------------------- +void S7LSTKLCD_String(signed int x, signed int y, const char *pString) +{ + signed int j; + while (*pString != 0) { + + // Display character + S7LSTKLCD_Char(x, y, *pString); + x += gFont.width + 1; + pString++; + + // Vertical blank line + if ((*pString != 0) && ((x-1) < S7LSTKLCD_WIDTH) && ((x-1) > 0)) { + + for (j=0; j < gFont.height; j++) { + + if (((j+y) >= 0) && ((j+y) < S7LSTKLCD_HEIGHT)) { + + S7LSTKLCD_Pixel(x-1, y+j, 0); + } + } + } + } +} + +//----------------------------------------------------------------------------- +/// Returns the height and width in pixels of the given string. +/// \param pString String to examinate. +/// \param pWidth Width of string in pixels. +/// \param pHeight Height of string in pixels. +//----------------------------------------------------------------------------- +void S7LSTKLCD_GetStringSize( + const char *pString, + signed int *pWidth, + signed int *pHeight) +{ + unsigned int size = 0; + + // Get string size + while (*pString != 0) { + + size++; + pString++; + } + + // Return size in pixel + if (pWidth) { + + *pWidth = size * (gFont.width + 1) - 1; + } + if (pHeight) { + + *pHeight = gFont.height; + } +} + +//----------------------------------------------------------------------------- +/// Displays the given string on the SLCD, centered along the X and Y axis +/// (this may result in the string being clipped). +/// \param pString String to display. +//----------------------------------------------------------------------------- +void S7LSTKLCD_PutString(const char *pString) +{ + signed int width, height; + SANITY_CHECK(pString); + + S7LSTKLCD_GetStringSize(pString, &width, &height); + S7LSTKLCD_String((S7LSTKLCD_WIDTH - width) / 2, (S7LSTKLCD_HEIGHT - height) / 2, pString); +} + diff --git a/components/slcd/s7lstklcd/s7lstklcd.dir b/components/slcd/s7lstklcd/s7lstklcd.dir new file mode 100644 index 0000000..145e4d3 --- /dev/null +++ b/components/slcd/s7lstklcd/s7lstklcd.dir @@ -0,0 +1,40 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains APIs for segment LCD display of AT91SAM7L-STK board. +/// +/// !!!Contents +/// +/// Contains code for display pixel, char and string. +//------------------------------------------------------------------------------ \ No newline at end of file diff --git a/components/slcd/s7lstklcd/s7lstklcd.h b/components/slcd/s7lstklcd/s7lstklcd.h new file mode 100644 index 0000000..e5614df --- /dev/null +++ b/components/slcd/s7lstklcd/s7lstklcd.h @@ -0,0 +1,83 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + + //------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Interface for displaying on segment LCD of AT91SAM7L-STK board. +/// +/// !!!Usage +/// +/// -# call corresponding function to display pixel, char and string. +//------------------------------------------------------------------------------ + +#ifndef S7LSTKLCD_H +#define S7LSTKLCD_H + +//----------------------------------------------------------------------------- +// Defines +//----------------------------------------------------------------------------- + +/// Number of segments in SLCD +#define S7LSTKLCD_NUM_SEGMENTS 40 +/// Number of commons in SLCD +#define S7LSTKLCD_NUM_COMMONS 10 + +/// SLCD width in pixels. +#define S7LSTKLCD_WIDTH 40 +/// SLCD height in pixels. +#define S7LSTKLCD_HEIGHT 10 + +//----------------------------------------------------------------------------- +// Global Functions +//----------------------------------------------------------------------------- + +extern void S7LSTKLCD_Pixel( + unsigned char x, + unsigned char y, + unsigned char set); + +extern void S7LSTKLCD_Char( + signed int x, + signed int y, + unsigned char c); + +extern void S7LSTKLCD_String(signed int x, signed int y, const char *pString); + +extern void S7LSTKLCD_GetStringSize( + const char *pString, + signed int *pWidth, + signed int *pHeight); + +extern void S7LSTKLCD_PutString(const char *pString); + +#endif + diff --git a/components/tv-encoder/CH7024.c b/components/tv-encoder/CH7024.c new file mode 100644 index 0000000..4e7c45c --- /dev/null +++ b/components/tv-encoder/CH7024.c @@ -0,0 +1,292 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//----------------------------------------------------------------------------- +// Headers +//----------------------------------------------------------------------------- +#include +#include +#include "CH7024.h" + +/// Slave address of Chrontel CH7024 chip. +#define CH7024_ADDRESS 0x76 + +/// terminating list entry for register in configuration file +#define CH7024_REG_TERM 0xFF +/// terminating list entry for value in configuration file +#define CH7024_VAL_TERM 0xFF + +/// CH7024 register configure value +const struct ch7024_reg ch7024_config[]= { + //POWER ON&DAC OFF + {0x04,0x0C}, // Power Management: DAC1 and DAC2 are power down + + //HUE + {0x05,0x30}, // adjust hue setting of the image + //SATURATION + {0x06,0x30}, // adjust the color saturation of the image + //CONTRAST + {0x07,0x48}, // adjust the contrast level of the image + //BRIGHTNESS + {0x08,0x80}, // adjusts the brightness level of the image + //SHARPNESS + {0x09,0x04}, // control the sharpness adjustment of the image + + {0x0B,0x04}, // Crystal Register: 4: 13MHz + {0x0C,0x00}, // Outputs are not dual CVBS + + //RGB888 + {0x0D,0x00}, // IDF[2:0] (bits 2-0) define the input data format + + //SLAVE + {0x0E,0x0C}, // SYNC Control: Horizontal and vertical polarity are positive + + {0x0F,0x00}, // auxiliary bit to help latch input data correctly + //{0x10, 0x01}, // TV Adaptive Flicker Filter Control + + //output setting + {0x1E,0x05}, // Horizontal Scaling + {0x1F,0x00}, // Horizontal Scaling + {0x20,0x00}, // TV vertical position adjustment + {0x21,0x81}, // TV vertical position adjustment + {0x22,0x00}, // TV horizontal position adjustment + {0x23,0x76}, // TV horizontal position adjustment + + //REG[34]TO[37] will be use to + //set calculate the sub-carrier frequency + {0x1C,0x90}, // Disables Dot Crawl reduction + + //NTSC_M + {0x0A,0x10}, + //HTI=1002=720+; (LCDC)1002=07+250+720+25 + {0x11,0x1A}, // Input Horizontal Total Pixels //HT[10][9][8]HA[10][9][8] + {0x12,0xD0}, // Input Horizontal Active Pixels //HA(0x2D0) + {0x13,0xEA}, // Input Horizontal Total Pixels //HT(0x3EA) + {0x14,0x00}, // Input Horizontal Sync Offset + {0x15,0x19}, // Input Horizontal Sync Offset //HO + {0x16,0x07}, // Input Horizontal Sync Offset //HW + + //VTI=555=480+ ; (LCDC)VW=08 555=70+480+05 + {0x17,0x09}, // Input Vertical Active Pixels + Input Vertical Sync Offset //VT[9][8]VA[9][8] + {0x18,0xE0}, // Input Vertical Active Pixels //VA(0X1E0) + {0x19,0x2B}, // VTI //VTI(0X22B) + {0x1A,0x05}, // Input Vertical Sync Offset //VO + {0x1B,0x08}, // Input Vertical Sync Offset //VW + + //PLL ratio R1,R2,R3,R4,R5 + {0x30,0x1B}, + {0x31,0x12}, + + //P + {0x28,0x00}, + {0x29,0xAB}, + {0x2A,0x90}, + + //N + {0x2B,0x36}, + {0x2C,0xFC}, + {0x2D,0x90}, + + //T + {0x2E,0x4F}, + + //sub carrier frequency r1-r4 + {0x34,0x01}, // SCFREQ[26:0], the Sub-carrier Frequency Value + {0x35,0x19}, // SCFREQ[26:0], the Sub-carrier Frequency Value + {0x36,0xF5}, // SCFREQ[26:0], the Sub-carrier Frequency Value + {0x37,0x8D}, // SCFREQ[26:0], the Sub-carrier Frequency Value + + //enable test mode + //{0x02,0x01}, + //{0x04,0x44}, + //{0x02,0x00}, + + //POWER ON&DAC ON + {0x04,0x00}, + + //register end + {0xFF,0xFF} +}; + +//----------------------------------------------------------------------------- +// Local Functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Global Functions +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/// Read a value from a register in an CH7024 device. +/// \param pTwid TWI interface +/// \param reg Register to be read +/// \param pData Data read +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +unsigned char ch7024_read_reg(Twid *pTwid, unsigned char reg, unsigned char *pData) +{ + unsigned char status; + + status = TWID_Read( pTwid, CH7024_ADDRESS, reg, 1, pData, 1, 0); + if( status != 0 ) { + TRACE_INFO("ch7023_read_reg pb"); + } + return status; +} + +//----------------------------------------------------------------------------- +/// Write a value to a register in an CH7024 device. +/// \param pTwid TWI interface +/// \param reg Register to be write +/// \param val Value to be writte +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +unsigned char ch7024_write_reg(Twid *pTwid, unsigned char reg, unsigned char val) +{ + unsigned char status = 0; + + status = TWID_Write(pTwid, CH7024_ADDRESS, reg, 1, &val, 1, 0); + if( status != 0 ) { + TRACE_INFO("ch7024_write_reg pb"); + } + return status; +} + +//----------------------------------------------------------------------------- +/// Sequence For correct operation of the TV encoder +/// Following the steps below to identify CH7023/CH7024 chip. +/// Step 1: Read the value of register 0x00; +/// If value is 0x45, CH7023/CH7024 is present. +/// Other value, none of CH7023/CH7024 is present; +/// Step 2: Write '1' to bit 1 of register 0x40(set 0x40[1]=1) and read back; +/// If the bit is '0' the chip present is CH7024; +/// Else the bit is '1' the chip present is CH7023. +/// +/// \param pTwid TWI interface +/// \return 1 if initialization ok, otherwise 0 +//----------------------------------------------------------------------------- +unsigned char ch7024_init(Twid *pTwid) +{ + unsigned char id=0; + + // Device ID Register [0x00] + if( 0 == ch7024_read_reg(pTwid, 0x00, &id) ) { + TRACE_DEBUG("[0x00]= 0x%X\n\r", id); + if( id == 0x45 ) { + TRACE_INFO("TV encoder detected!\n\r"); + return 1; + } + else { + TRACE_INFO("Problem captor: bad PID\n\r"); + } + } + else { + TRACE_INFO("Problem: TV encoder not responding\n\r"); + } + return 0; +} + +//----------------------------------------------------------------------------- +/// Initialize a list of ch7024 registers. +/// The list of registers is terminated by the pair of values +/// { CH7024_REG_TERM, CH7024_VAL_TERM }. +/// Returns zero if successful, or non-zero otherwise. +/// \param pTwid TWI interface +/// \param pReglist Register list to be written +/// \return 0 if no error, otherwize TWID_ERROR_BUSY +//----------------------------------------------------------------------------- +int ch7024_write_regs(Twid *pTwid, const struct ch7024_reg* pReglist) +{ + int err; + int size=0; + const struct ch7024_reg *pNext = pReglist; + unsigned int i=0; + + TRACE_DEBUG("ch7024_write_regs:"); + while (!((pNext->reg == CH7024_REG_TERM) && (pNext->val == CH7024_VAL_TERM))) { + err = ch7024_write_reg(pTwid, pNext->reg, pNext->val); + TRACE_DEBUG("+(%d) ", size); + size++; + + //delay + for(i=0; i<6000; i++ ); + + if (err == TWID_ERROR_BUSY){ + TRACE_INFO("-\n\rE- ch7024_write_regs: TWI ERROR\n\r"); + return err; + } + pNext++; + } + TRACE_DEBUG("\n\r"); + return 0; +} + +//----------------------------------------------------------------------------- +/// Configure the CH7024 +//----------------------------------------------------------------------------- +void ch7024_configure(Twid *pTwid) +{ + const struct ch7024_reg *reg_conf; + reg_conf = ch7024_config; + TRACE_INFO("TV encoder configure\n\r"); + ch7024_write_regs(pTwid, reg_conf); +} + +//----------------------------------------------------------------------------- +/// Reset the CH7024 +//----------------------------------------------------------------------------- +void ch7024_reset(Twid *pTwid) +{ + int i; + TRACE_INFO("TV encoder reset\n\r"); + ch7024_write_reg(pTwid, 0x03, 0x00); + for(i=0;i<10000;i++); + ch7024_write_reg(pTwid, 0x03, 0x03); +} + +//----------------------------------------------------------------------------- +/// Dump all register +/// \param pTwid TWI interface +//----------------------------------------------------------------------------- +void ch7024_DumpRegisters(Twid *pTwid) +{ + int i; + unsigned char value; + + TRACE_INFO("Dump all TV encoder register\n\r"); + for(i = 0; i <= 0x7F; i++) { + value = 0; + ch7024_read_reg(pTwid, i, &value); + TRACE_INFO("[0x%02x]=0x%02x ", i, value); + if( ((i+1)%5) == 0 ) { + TRACE_INFO("\n\r"); + } + } + TRACE_INFO("\n\r"); +} diff --git a/components/tv-encoder/CH7024.h b/components/tv-encoder/CH7024.h new file mode 100644 index 0000000..2834603 --- /dev/null +++ b/components/tv-encoder/CH7024.h @@ -0,0 +1,73 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Interface for configuration the Chrontel TV Encoder. +/// +/// !!!Usage +/// +/// -# Configure pins +/// -# Configure clock +/// -# Initialize TV Encoder +/// -# Reset +/// -# Enable interrupt if needed +/// -# Enable +//------------------------------------------------------------------------------ + +#ifndef CH7024_H +#define CH7024_H + +//------------------------------------------------------------------------------ +// Types +//------------------------------------------------------------------------------ +/// define a structure for ch7024 register initialization values +struct ch7024_reg +{ + /// Register to be written + unsigned char reg; + /// Value to be written in the register + unsigned char val; +}; + +//------------------------------------------------------------------------------ +// Exported functions +//------------------------------------------------------------------------------ +extern unsigned char ch7024_read_reg(Twid *pTwid, unsigned char reg, unsigned char *pData); +extern unsigned char ch7024_write_reg(Twid *pTwid, unsigned char reg, unsigned char val); +extern unsigned char ch7024_init(Twid *pTwid); +extern void ch7024_configure(Twid *pTwid); +extern void ch7024_DumpRegisters(Twid *pTwid); +extern void ch7024_reset(Twid *pTwid); + +#endif //#ifndef CH7024_H + diff --git a/components/tv-encoder/tv-encoder.dir b/components/tv-encoder/tv-encoder.dir new file mode 100644 index 0000000..fbdfd23 --- /dev/null +++ b/components/tv-encoder/tv-encoder.dir @@ -0,0 +1,42 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL 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. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Purpose +/// +/// This directory contains an API for Chrontel 7024 TV encoder +/// +/// !!!Contents +/// +/// Contains code for initialize, read or write registers, dump all registers, +/// write configuration. +//------------------------------------------------------------------------------ + -- cgit v1.2.3