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
MCUGearALPC1114.cpp@3:69b10f9cdd14, 2014-05-06 (annotated)
- Committer:
- Info
- Date:
- Tue May 06 15:53:05 2014 +0000
- Revision:
- 3:69b10f9cdd14
- Parent:
- 2:aa2e471e8317
Added command; void clear(void); It can clear saved IO setting.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Info | 0:12d93184b350 | 1 | /* MCU Gear Library, only for testing MCUGear without any circuit you connected. |
Info | 0:12d93184b350 | 2 | * Copyright (c) 2013, NestEgg Inc., http://www.mcugear.com/ |
Info | 0:12d93184b350 | 3 | * |
Info | 0:12d93184b350 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Info | 0:12d93184b350 | 5 | * of this software and associated documentation files (the "Software"), to deal |
Info | 0:12d93184b350 | 6 | * in the Software without restriction, including without limitation the rights |
Info | 0:12d93184b350 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Info | 0:12d93184b350 | 8 | * copies of the Software, and to permit persons to whom the Software is |
Info | 0:12d93184b350 | 9 | * furnished to do so, subject to the following conditions: |
Info | 0:12d93184b350 | 10 | * |
Info | 0:12d93184b350 | 11 | * The above copyright notice and this permission notice shall be included in |
Info | 0:12d93184b350 | 12 | * all copies or substantial portions of the Software. |
Info | 0:12d93184b350 | 13 | * |
Info | 0:12d93184b350 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Info | 0:12d93184b350 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Info | 0:12d93184b350 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Info | 0:12d93184b350 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Info | 0:12d93184b350 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Info | 0:12d93184b350 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Info | 0:12d93184b350 | 20 | * THE SOFTWARE. |
Info | 0:12d93184b350 | 21 | */ |
Info | 0:12d93184b350 | 22 | |
Info | 0:12d93184b350 | 23 | |
Info | 0:12d93184b350 | 24 | #include "mbed.h" |
Info | 2:aa2e471e8317 | 25 | #include "MCUGearALPC1114.h" |
Info | 2:aa2e471e8317 | 26 | #include "MCUGearBaseALPC1114.h" |
Info | 0:12d93184b350 | 27 | |
Info | 0:12d93184b350 | 28 | MCUGear::MCUGear(PinName scl, PinName sda, char addr) |
Info | 0:12d93184b350 | 29 | : _i2c(scl, sda) { |
Info | 3:69b10f9cdd14 | 30 | _i2c.frequency(FPGA_I2C_CLOCK); |
Info | 0:12d93184b350 | 31 | _addr = addr; //save address |
Info | 0:12d93184b350 | 32 | write(0xff); //close Module gate |
Info | 0:12d93184b350 | 33 | _counter = 0; |
Info | 0:12d93184b350 | 34 | } |
Info | 0:12d93184b350 | 35 | |
Info | 0:12d93184b350 | 36 | void MCUGear::disconnectModule(void){ |
Info | 0:12d93184b350 | 37 | write(0xff); //close module gate |
Info | 0:12d93184b350 | 38 | deleteBank(0); |
Info | 0:12d93184b350 | 39 | } |
Info | 0:12d93184b350 | 40 | |
Info | 0:12d93184b350 | 41 | void MCUGear::connectModuleA(void){ |
Info | 0:12d93184b350 | 42 | int i = 0; |
Info | 0:12d93184b350 | 43 | |
Info | 0:12d93184b350 | 44 | //make circuit |
Info | 0:12d93184b350 | 45 | if(_counter!=0){ |
Info | 0:12d93184b350 | 46 | |
Info | 0:12d93184b350 | 47 | startReg(0); |
Info | 0:12d93184b350 | 48 | |
Info | 0:12d93184b350 | 49 | for(i = 0; i < _counter; ++i){ |
Info | 0:12d93184b350 | 50 | fpga_write(_mcuIO[i], _moduleIO[i]); |
Info | 0:12d93184b350 | 51 | } |
Info | 0:12d93184b350 | 52 | |
Info | 0:12d93184b350 | 53 | endReg(); |
Info | 0:12d93184b350 | 54 | |
Info | 0:12d93184b350 | 55 | changeBank(0); |
Info | 0:12d93184b350 | 56 | } |
Info | 0:12d93184b350 | 57 | |
Info | 0:12d93184b350 | 58 | write(0xf8); //1111 1000 |
Info | 0:12d93184b350 | 59 | } |
Info | 0:12d93184b350 | 60 | |
Info | 0:12d93184b350 | 61 | void MCUGear::fpga_write(unsigned char adr, unsigned char data) { |
Info | 0:12d93184b350 | 62 | char cmd[2]; |
Info | 0:12d93184b350 | 63 | cmd[0] = adr; |
Info | 0:12d93184b350 | 64 | cmd[1] = data; |
Info | 0:12d93184b350 | 65 | _i2c.write(FPGA_I2C_ADR, cmd, 2); |
Info | 0:12d93184b350 | 66 | } |
Info | 0:12d93184b350 | 67 | |
Info | 0:12d93184b350 | 68 | void MCUGear::startReg(char bank){ |
Info | 0:12d93184b350 | 69 | _bank = bank; |
Info | 0:12d93184b350 | 70 | fpga_write(0x0c,_bank); //End regist |
Info | 0:12d93184b350 | 71 | } |
Info | 0:12d93184b350 | 72 | |
Info | 0:12d93184b350 | 73 | uint8_t MCUGear::setWireA(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO){ |
Info | 0:12d93184b350 | 74 | |
Info | 0:12d93184b350 | 75 | uint8_t location = ( _pnum + moduleIO ); |
Info | 0:12d93184b350 | 76 | |
Info | 0:12d93184b350 | 77 | if(moduleIO >= numMaxModuleIO){ |
Info | 0:12d93184b350 | 78 | return 255; //error |
Info | 0:12d93184b350 | 79 | } |
Info | 0:12d93184b350 | 80 | |
Info | 0:12d93184b350 | 81 | if(location >= numBaseboardIO){ |
Info | 0:12d93184b350 | 82 | location = location - numBaseboardIO; |
Info | 0:12d93184b350 | 83 | } |
Info | 0:12d93184b350 | 84 | |
Info | 0:12d93184b350 | 85 | //fpga_write(mcuIO, (IO_REG_EN | (direction | (location)))); |
Info | 0:12d93184b350 | 86 | saveWire(mcuIO, (IO_REG_EN | (direction | (location)))); |
Info | 0:12d93184b350 | 87 | |
Info | 0:12d93184b350 | 88 | return location; |
Info | 0:12d93184b350 | 89 | } |
Info | 0:12d93184b350 | 90 | |
Info | 0:12d93184b350 | 91 | void MCUGear::saveWire(uint8_t mcuIO, uint8_t moduleIO){ |
Info | 0:12d93184b350 | 92 | _mcuIO[_counter] = mcuIO; |
Info | 0:12d93184b350 | 93 | _moduleIO[_counter] = moduleIO; |
Info | 0:12d93184b350 | 94 | ++_counter; |
Info | 0:12d93184b350 | 95 | } |
Info | 0:12d93184b350 | 96 | |
Info | 0:12d93184b350 | 97 | void MCUGear::endReg(void){ |
Info | 0:12d93184b350 | 98 | fpga_write(0x10,_bank);//init regist/////// |
Info | 0:12d93184b350 | 99 | } |
Info | 0:12d93184b350 | 100 | |
Info | 3:69b10f9cdd14 | 101 | void MCUGear::clear(void){ |
Info | 3:69b10f9cdd14 | 102 | _counter = 0; |
Info | 3:69b10f9cdd14 | 103 | } |
Info | 0:12d93184b350 | 104 | |
Info | 0:12d93184b350 | 105 | //send I2C signal function |
Info | 0:12d93184b350 | 106 | void MCUGear::write(uint8_t c){ |
Info | 0:12d93184b350 | 107 | |
Info | 0:12d93184b350 | 108 | char cmd[1]; |
Info | 0:12d93184b350 | 109 | cmd[0] = c; |
Info | 0:12d93184b350 | 110 | _i2c.write(_addr, cmd, 1); |
Info | 0:12d93184b350 | 111 | |
Info | 0:12d93184b350 | 112 | } |
Info | 0:12d93184b350 | 113 | |
Info | 0:12d93184b350 | 114 | ////detect module |
Info | 0:12d93184b350 | 115 | uint8_t MCUGear::detectModule(void) { |
Info | 0:12d93184b350 | 116 | |
Info | 0:12d93184b350 | 117 | write(0x7f); //0111 1111 //1pin GND |
Info | 0:12d93184b350 | 118 | _pnum = fpga_read(FPGA_I2C_ADR,FPGA_DETECT);//save location |
Info | 0:12d93184b350 | 119 | write(0xff); //1111 1111 //close |
Info | 0:12d93184b350 | 120 | |
Info | 0:12d93184b350 | 121 | _counter = 0; |
Info | 0:12d93184b350 | 122 | |
Info | 0:12d93184b350 | 123 | return _pnum; |
Info | 0:12d93184b350 | 124 | |
Info | 0:12d93184b350 | 125 | } |
Info | 0:12d93184b350 | 126 |