This Automatic mode is the most simple lib for MCU Gear. You don't need to think about Bank.
Embed:
(wiki syntax)
Show/hide line numbers
MCUGearA.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 "MCUGearA.h" 00026 #include "MCUGearBaseA.h" 00027 00028 MCUGear::MCUGear(PinName scl, PinName sda, char addr) 00029 : _i2c(scl, sda) { 00030 _i2c.frequency(FPGA_I2C_CLOCK); 00031 _addr = addr; //save address 00032 write(0xff); //close Module gate 00033 _counter = 0; 00034 } 00035 00036 void MCUGear::disconnectModule(void){ 00037 write(0xff); //close module gate 00038 deleteBank(0); 00039 } 00040 00041 void MCUGear::connectModuleA(void){ 00042 int i = 0; 00043 00044 //make circuit 00045 if(_counter!=0){ 00046 00047 startReg(0); 00048 00049 for(i = 0; i < _counter; ++i){ 00050 fpga_write(_mcuIO[i], _moduleIO[i]); 00051 } 00052 00053 endReg(); 00054 00055 changeBank(0); 00056 } 00057 00058 write(0xf8); //1111 1000 00059 } 00060 00061 void MCUGear::fpga_write(unsigned char adr, unsigned char data) { 00062 char cmd[2]; 00063 cmd[0] = adr; 00064 cmd[1] = data; 00065 _i2c.write(FPGA_I2C_ADR, cmd, 2); 00066 } 00067 00068 void MCUGear::startReg(char bank){ 00069 _bank = bank; 00070 fpga_write(0x0c,_bank); //End regist 00071 } 00072 00073 uint8_t MCUGear::setWireA(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO){ 00074 00075 uint8_t location = ( _pnum + moduleIO ); 00076 00077 if(moduleIO >= numMaxModuleIO){ 00078 return 255; //error 00079 } 00080 00081 if(location >= numBaseboardIO){ 00082 location = location - numBaseboardIO; 00083 } 00084 00085 //fpga_write(mcuIO, (IO_REG_EN | (direction | (location)))); 00086 saveWire(mcuIO, (IO_REG_EN | (direction | (location)))); 00087 00088 return location; 00089 } 00090 00091 void MCUGear::saveWire(uint8_t mcuIO, uint8_t moduleIO){ 00092 _mcuIO[_counter] = mcuIO; 00093 _moduleIO[_counter] = moduleIO; 00094 ++_counter; 00095 } 00096 00097 void MCUGear::endReg(void){ 00098 fpga_write(0x10,_bank);//init regist/////// 00099 } 00100 00101 00102 //send I2C signal function 00103 void MCUGear::write(uint8_t c){ 00104 00105 char cmd[1]; 00106 cmd[0] = c; 00107 _i2c.write(_addr, cmd, 1); 00108 00109 } 00110 00111 ////detect module 00112 uint8_t MCUGear::detectModule(void) { 00113 00114 write(0x7f); //0111 1111 //1pin GND 00115 _pnum = fpga_read(FPGA_I2C_ADR,FPGA_DETECT);//save location 00116 write(0xff); //1111 1111 //close 00117 00118 _counter = 0; 00119 00120 return _pnum; 00121 00122 } 00123
Generated on Thu Jul 14 2022 04:34:19 by 1.7.2