Firmware for MAXREFES1265

Dependencies:   max32625pico SerialInterface maxim-dev USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************/
00032 //==============================================================================
00033 //This code is only suitable for single switch press not simultaneous switch press
00034 //The following code needs maxim-dev library to run. The complete package is available in the GITHUB
00035 //==============================================================================
00036 //Header files
00037 #include "mbed.h"
00038 #include "USBSerial.h"
00039 #include "max32625pico.h"
00040 #include "SerialInterface.h"
00041 
00042 
00043 const int Slave_address                   = 0x70; // MAX7360 I2C slave address
00044 const int max_key                         = 63;
00045 
00046 // Virtual serial port over USB
00047 USBSerial microUSB(0x0B6A, 0x4360);
00048 
00049 DigitalIn nINTK(P4_5); // Key switch interrupt configures as GPIO, refer to page 11 of DS for more info
00050 
00051 //The following line of code is optional and please uncomment if you are using rotary encoder
00052 //DigitalIn nINTI(P4_4); // Interrupt for rotary switch configuration, refer to page 14 for more info
00053 
00054 //The following line of code sets all the GPIO to 1.8 volts
00055 MAX32625PICO pico(MAX32625PICO::IOH_DIP_IN, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_1V8);
00056 
00057 // Serial Interfaces
00058 I2C i2c(P1_6, P1_7);
00059 
00060 
00061 
00062 int main()
00063 {
00064 
00065 
00066 //--------Register configuration for the MAX7360--------------------------------
00067 //Please refer to page 10 and table 8 of the data sheet
00068 
00069 //Writing the configuration register (0x01) of MAX7360.
00070 
00071 
00072     char Datawrite_config[2];
00073     Datawrite_config[0]   = 0x01; //Address of the register
00074     Datawrite_config[1]   = 0x20; //Configuring the register for Interrupt by making D5 to 1 and all the other bits to 0
00075     i2c.write( Slave_address, Datawrite_config, 2 );
00076 
00077 //Writing the Key switch interrupt register (0x03) MAX7360.
00078 //Please refer to table 10 of the data sheet
00079 //The interrupt register contains information related to the
00080 //settings of the interrupt request function, as well as the
00081 //status of the INTK output, which can also be configured
00082 //as a GPIO
00083     char Datawrite_Key_Switch_Interrupt[2];
00084     Datawrite_Key_Switch_Interrupt[0]   = 0x03; //Address of the register
00085     Datawrite_Key_Switch_Interrupt[1]   = 0x08; //Configuring the TIME-BASED INTK bits to get 8 debounce cycles
00086     i2c.write( Slave_address, Datawrite_Key_Switch_Interrupt, 2 );
00087 
00088 
00089 //Writing the auto sleep register (0x06)MAX7360 Autosleep Register no autosleep
00090     char Autosleep[2];
00091     Autosleep[0]   = 0x06; //Address of the register
00092     Autosleep[1]   = 0x00; //AUTOSHUTDOWN TIME to no autosleep, refer to page 25 of DS
00093     i2c.write( Slave_address, Autosleep, 2 );
00094 
00095 
00096 //Writing the GPIO Global Configuration (0x40)
00097 //Enable rotary encoder and normal GPIO operation
00098     char GlobalConfig[2];
00099     GlobalConfig[0]   = 0x40; //Address of the register
00100     GlobalConfig[1]   = 0x90; //Enabling the I2C timeout interrupt and rotary switch by setting D7 and D5 to 1 and all others to zero
00101     i2c.write( Slave_address, GlobalConfig, 2 );
00102 
00103 //==============================================================================
00104 //Uncomment below if you would like ot use rotary encoder
00105 //==============================================================================
00106 //Writing GPIO Control Register
00107 //    char GPIOControl[2];
00108 //    GPIOControl[0]   = 0x41; //Address
00109 //    GPIOControl[1]   = 0x3F; //Registrer configuration, All GPIOs configured as output, except ports 6 and 7, because they are connected to the rotary encoder
00110 //   i2c.write( Slave_address, GPIOControl, 2 );
00111 //Writing the Rotatory switch configuration (0x46).  Please refer to table 20 of the data sheet
00112 //    char Datawrite_Rotatory_Switch_configuration[2];
00113 //Rotary Switch Configuration Register   nINTI asserted 25ms after first debounced event, no debounce cycle time
00114 //   Datawrite_Rotatory_Switch_configuration[0]   = 0x46;
00115 //   Datawrite_Rotatory_Switch_configuration[1]   = 0x90;  // Rotary Switch Configuration Register   nINTI asserted 25ms after first debounced event, no debounce cycle time
00116 //Datawrite_Rotatory_Switch_configuration[1]   = 0x11;
00117 //   i2c.write( Slave_address, Datawrite_Rotatory_Switch_configuration, 2 );
00118 
00119     /*
00120     // Writing PORT6 Configuration Register   mask interrupt  (0x5E)
00121         char Port6[2];
00122         Port6[0]   = 0x5E; // Address
00123         Port6[1]   = 0x80;// masking the interrupt by enabling the D7 to 1  refer to page 30 of DS
00124         i2c.write( Slave_address, Port6, 2 );
00125 
00126     // Writing PORT7 Configuration Register   mask interrupt  (0x5F)
00127         char Port7[2];
00128         Port7[0]   = 0x5F; //Address
00129         Port7[1]   = 0x80; // masking of the interrupt by making D7 to 1 refer to page 30 of DS
00130         i2c.write( Slave_address, Port7, 2 );
00131     */
00132 //-----------------------------------------------------------------------------
00133 //Default register values
00134 //-----------------------------------------------------------------------------
00135 //writeMAX7360(0x02,0xFF);// Debounce Register only column 0 enabled, debounce set to 40ms
00136 //  writeMAX7360(0x04,0xFE);          // Ports Register
00137 //  writeMAX7360(0x05,0x00);            // Autorepeat Register
00138 //  writeMAX7360(0x42,0x00);            // GPIO Debounce Configuration Register
00139 //  writeMAX7360(0x43,0xC0);            // GPIO Constant-Current Setting Register
00140 //  writeMAX7360(0x44,0x00);            // GPIO Output Mode Register
00141 //  writeMAX7360(0x45,0x00);            // Common PWM Register
00142 
00143 //------------------End of Register configuration for MAX7360-----------------//
00144 
00145 
00146     while(1) {
00147 
00148 
00149 
00150 //Reading the Key FIFO register (0x00) from MAX7360.
00151 //Please refer to page 10 and table 7 of the data sheet
00152         char KeyFIFOData;
00153         char l = 0x00;
00154         i2c.write( Slave_address, &l, 1 );
00155         i2c.read( Slave_address, &KeyFIFOData, 1 );
00156 
00157 
00158         if(KeyFIFOData!= max_key) {
00159             microUSB.printf("KeyFIFOData = %d \n\r", KeyFIFOData);
00160         }
00161 
00162         //      wait_ms(50);  This may be necessary for console printing
00163 
00164 //==============================================================================
00165 //Uncomment the code below for rotary encoder
00166 //==============================================================================
00167 ////Reading the Rotatory switch count register (0x4A).  Please refer to page 12 and table 23 of the data sheet
00168 //
00169 //               char RotaryData;
00170 //               char m = 0x4A;
00171 //               if(!nINTI) {
00172 //                   i2c.write( Slave_address, &m, 1 );
00173 //                   i2c.read( Slave_address, &RotaryData, 1 );
00174 //
00175 //                   if(RotaryData!= 0) {
00176 //
00177 //                       microUSB.printf("RotaryData = %x \r\n", RotaryData);
00178 //                   }
00179 //
00180 //        //         wait_ms(100); This may be necessary for console printing
00181 //
00182 //                 }
00183 
00184     }
00185 }
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194