• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

mTouch_eeprom.c

Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2012 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    mTouch Framework v2.1
00005  *  FileName:        mTouch_eeprom.c
00006  *  Dependencies:    mTouch.h
00007  *  Processor:       See documentation for supported PIC® microcontrollers 
00008  *  Compiler:        HI-TECH Ver. 9.81 or later
00009  *  IDE:             MPLAB® IDE v8.50 (or later) or MPLAB® X                        
00010  *  Hardware:         
00011  *  Company:         
00012  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00013  *  Description:     mTouch EEPROM Functions
00014  *                   - Implements the mTouch EEPROM initialization and
00015  *                     editing process. 
00016  *                   - See the documentation for more information about
00017  *                     implementing the framework with your application.
00018  *************************************************************************/
00019 /**************************************************************************
00020  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00021  * any derivatives created by any person or entity by or on your behalf, 
00022  * exclusively with Microchip's products in accordance with applicable
00023  * software license terms and conditions, a copy of which is provided for
00024  * your referencein accompanying documentation. Microchip and its licensors 
00025  * retain all ownership and intellectual property rights in the 
00026  * accompanying software and in all derivatives hereto. 
00027  * 
00028  * This software and any accompanying information is for suggestion only. 
00029  * It does not modify Microchip's standard warranty for its products. You 
00030  * agree that you are solely responsible for testing the software and 
00031  * determining its suitability. Microchip has no obligation to modify, 
00032  * test, certify, or support the software. 
00033  * 
00034  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00035  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00036  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00037  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00038  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00039  * APPLICATION. 
00040  * 
00041  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00042  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00043  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00044  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00045  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00046  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00047  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00048  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00049  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00050  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00051  * 
00052  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00053  * THESE TERMS. 
00054  *************************************************************************/
00055  
00056 #include "mTouch.h"
00057 
00058 #if defined(MTOUCH_EEPROM_ENABLED)
00059 
00060 
00061     #if defined(MTOUCH_EEPROM_ENABLED)
00062     
00063     // At compile-time, initialize the first 8 bytes of EEPROM to 0xFF.
00064     // This erases the mTouch initialization byte, allowing a new configuration to be loaded on power-up.
00065     #if !defined(MTOUCH_EEPROM_STORED_IN_RAM)
00066     __EEPROM_DATA(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);             // Must write 8 bytes at a time.
00067     #endif
00068     
00069     //
00070     // NOTE: Do not change the order of these values without also editing the address calculations in mTouch_eeprom.h
00071     //       New values can be safely added to the end without causing calculation errors.
00072     //   
00073     
00074     const uint8_t   mTouch_EEPROM_default       [MTOUCH_EEPROM_SIZE]    =   {
00075                                                                                 (uint8_t)(MTOUCH_DEBOUNCE_PRESS & 0xFF),                
00076                                                                                 (uint8_t)(MTOUCH_DEBOUNCE_PRESS >> 8),                  
00077                                                                                 (uint8_t)(MTOUCH_DEBOUNCE_RELEASE & 0xFF),              
00078                                                                                 (uint8_t)(MTOUCH_DEBOUNCE_RELEASE >> 8),                
00079                                                                                 (uint8_t)(MTOUCH_JITTER_MASK),                                         
00080                                                                                 (uint8_t)(MTOUCH_BASELINE_WEIGHT),                       
00081                                                                                 (uint8_t)(MTOUCH_BASELINE_RATE & 0xFF),                 
00082                                                                                 (uint8_t)(MTOUCH_BASELINE_RATE >> 8),                   
00083                                                                                 (uint8_t)(MTOUCH_BUTTON_TIMEOUT & 0xFF),                
00084                                                                                 (uint8_t)(MTOUCH_BUTTON_TIMEOUT >> 8),                  
00085                                                                                 (uint8_t)(MTOUCH_SAMPLES_PER_SCAN & 0xFF),              
00086                                                                                 (uint8_t)(MTOUCH_SAMPLES_PER_SCAN >> 8),                
00087                                                                                 (uint8_t)(MTOUCH_SCALING),                               
00088                                                                                 (uint8_t)(MTOUCH_DECIMATION_MAX_STEP & 0xFF),           
00089                                                                                 (uint8_t)(MTOUCH_DECIMATION_MAX_STEP >> 8)           // Lack of comma is intentional: provided in threshold macro.
00090                                                                                 MTOUCH_EEPROM_THRESHOLDS                                
00091                                                                             };
00092     #endif
00093     
00094           #if defined(MTOUCH_EEPROM_STORED_IN_RAM)
00095           uint8_t   mTouch_configOptions        [MTOUCH_EEPROM_START_ADR + MTOUCH_EEPROM_SIZE];
00096           #endif
00097     
00098     // Function Prototypes
00099     void mTouch_EEPROM_Init(void);
00100     void mTouch_EEPROM_Reset(void);
00101 
00102     // Initializes the EEPROM
00103     void mTouch_EEPROM_Init()
00104     {
00105         // Only writes the default values to the EEPROM if the mTouch initialization
00106         // value is not present at the starting address. This ensures configuration
00107         // settings and edits are (both) non-volatile and reset when programmed.
00108         //  So...
00109         //      Programming the Microcontroller:        Resets EEPROM values
00110         //      Powering on/off the Microcontroller:    No change to EEPROM values
00111 
00112         __delay_ms(1);
00113         
00114         if (MTOUCH_EEPROM_read(0x01) != MTOUCH_EEPROM_INIT_VALUE)                                
00115         {   
00116             MTOUCH_EEPROM_write(0x01, MTOUCH_EEPROM_INIT_VALUE);    // Initialization Value
00117             mTouch_EEPROM_Reset();                                  // mTouch EEPROM Block
00118         }
00119     }
00120     
00121     // Resets the EEPROM
00122     void mTouch_EEPROM_Reset()
00123     {
00124     
00125         // 
00126         // The default EEPROM values are stored in constant memory. Loop to initialize.
00127         //
00128     
00129         for (uint8_t i = 0; i < MTOUCH_EEPROM_SIZE; i++)
00130         {
00131             MTOUCH_EEPROM_write(MTOUCH_EEPROM_START_ADR + i, mTouch_EEPROM_default[i]);
00132         }
00133     }
00134     
00135 #endif

mTouch Framework v2.1 documentation by  Click here to visit our website at www.microchip.com