This Automatic mode is the most simple lib for MCU Gear with LPC1114FN28. You don't need to think about Bank.

Dependents:   MCUGearALPC1114FN28

Fork of MCUGearA by mille feuille

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MCUGearBaseALPC1114.cpp Source File

MCUGearBaseALPC1114.cpp

00001 /* MCU Gear Library, only for testing MCUGear without any circuit you connected.
00002  * Copyright (c) 2013, NestEgg Inc., http://www.mcugear.com/
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 #include "mbed.h"
00024 #include "MCUGearBaseALPC1114.h"
00025 
00026 I2C fpga_i2c(dp5, dp27);
00027 
00028 void fpga_write(int dev_adr,unsigned char adr, unsigned char data) {
00029   char cmd[2];
00030   cmd[0] = adr;
00031   cmd[1] = data;
00032   //fpga_i2c.frequency (FPGA_I2C_CLOCK);
00033   fpga_i2c.write(dev_adr, cmd, 2);
00034 
00035 }
00036 
00037 unsigned char fpga_read(int dev_adr,unsigned char adr) {
00038   char cmd[2];
00039   cmd[0] = adr;
00040   fpga_i2c.write(dev_adr, cmd, 1);
00041   fpga_i2c.read(dev_adr, cmd, 1);
00042   return cmd[0];
00043 }
00044 
00045 void initBase(void){
00046 
00047     // FPGA reg clear
00048      for (int i=0;i<20;i++)
00049        fpga_write(FPGA_I2C_ADR,0x80+i,0);
00050      
00051     // read FPGA registers
00052     fpga_read(FPGA_I2C_ADR,FPGA_SYSINFO_0);
00053     fpga_read(FPGA_I2C_ADR,FPGA_SYSINFO_0+1);
00054     fpga_read(FPGA_I2C_ADR,FPGA_SYSINFO_0+2);
00055     fpga_read(FPGA_I2C_ADR,FPGA_SYSINFO_0+3);
00056     // FPGA enable
00057     fpga_write(FPGA_I2C_ADR,FPGA_ENABLE,1);   
00058 }
00059 
00060 void I2Cwrite(char addr, char data){
00061 
00062     char cmd[1];
00063     cmd[0] = data;
00064     fpga_i2c.write(addr, cmd, 1);
00065     //wait(0.01);
00066     
00067 }
00068 
00069 void changeBank(uint8_t bank){
00070     fpga_write(FPGA_I2C_ADR,0x10,bank);
00071 }
00072 
00073 void deleteBank(uint8_t bank){
00074     fpga_write(FPGA_I2C_ADR,0x0c,(bank|0x80));
00075     fpga_write(FPGA_I2C_ADR,0x10, bank);
00076 }
00077 /*
00078 void startReg(uint8_t bank){
00079     fpga_write(FPGA_I2C_ADR,0x0c,bank);
00080 }
00081 
00082 void endReg(uint8_t bank){
00083     fpga_write(FPGA_I2C_ADR,0x10, (bank|0x04));
00084 }
00085 */
00086 
00087