Home Page : http://www.mcugear.com/en/ MCU Gear manual mode (circuit quick changer!) You can save 8 schematic(bank 0-7) manually and change it quickly.

Dependents:   MCUGear_Ver2

Fork of MCUGear by mille feuille

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MCUGearM.cpp Source File

MCUGearM.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 
00024 #include "mbed.h"
00025 #include "MCUGearM.h"
00026 #include "MCUGearBaseM.h"
00027 
00028 #ifdef DEBUG
00029 Serial MCUGear_pc(USBTX, USBRX); // tx, rx
00030 #endif
00031 
00032 MCUGear::MCUGear(PinName scl, PinName sda, char addr)
00033      : _i2c(scl, sda) {
00034     _i2c.frequency(FPGA_I2C_CLOCK);
00035     _addr = addr;   //save address
00036     write(0xff);    //close Module gate    
00037 }
00038 
00039 void MCUGear::disconnectModule(void){
00040     write(0xff);    //close module gate
00041 }
00042 
00043 void MCUGear::connectModule(void){
00044     write(0xf8);    //1111 1000
00045 }
00046 
00047 void MCUGear::fpga_write(unsigned char adr, unsigned char data) {
00048   char cmd[2];
00049   cmd[0] = adr;
00050   cmd[1] = data;
00051   _i2c.write(FPGA_I2C_ADR, cmd, 2);
00052 }
00053 
00054 void MCUGear::startReg(char bank){
00055     _bank = bank;
00056     fpga_write(0x0c,_bank); //End regist
00057 }
00058 
00059 uint8_t MCUGear::setWire(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO){
00060     
00061     uint8_t location = ( _pnum + moduleIO );
00062     
00063     if(moduleIO >= numMaxModuleIO){
00064         return 255; //error
00065     }
00066     
00067     if(location >= numBaseboardIO){
00068         location = location - numBaseboardIO;
00069     }
00070     
00071     fpga_write(mcuIO, (IO_REG_EN | (direction | (location))));
00072     return location;
00073 }
00074 
00075 
00076 void MCUGear::endReg(void){
00077     fpga_write(0x10,_bank);//init regist///////
00078 }
00079 
00080 
00081 //send I2C signal function
00082 void MCUGear::write(uint8_t c){
00083 
00084     char cmd[1];
00085     cmd[0] = c;
00086     _i2c.write(_addr, cmd, 1);
00087     
00088 }
00089 
00090 ////detect module
00091 uint8_t MCUGear::detectModule(void) {
00092     
00093     write(0x7f);   //0111 1111  //1pin GND
00094     _pnum = fpga_read(FPGA_I2C_ADR,FPGA_DETECT);//save location
00095     write(0xff);    //1111 1111 //close
00096         
00097     return _pnum;
00098 
00099 }
00100