mille feuille / MCUGearM

Dependents:   MCUGear_Ver2

Fork of MCUGear by mille feuille

Committer:
Info
Date:
Fri Feb 28 17:47:43 2014 +0000
Revision:
4:9b2ea7fc3173
Parent:
2:7b4657c7b996
I deleted some comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Info 2:7b4657c7b996 1 /* MCU Gear Library, only for testing MCUGear without any circuit you connected.
Info 2:7b4657c7b996 2 * Copyright (c) 2013, NestEgg Inc., http://www.mcugear.com/
Info 2:7b4657c7b996 3 *
Info 2:7b4657c7b996 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Info 2:7b4657c7b996 5 * of this software and associated documentation files (the "Software"), to deal
Info 2:7b4657c7b996 6 * in the Software without restriction, including without limitation the rights
Info 2:7b4657c7b996 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Info 2:7b4657c7b996 8 * copies of the Software, and to permit persons to whom the Software is
Info 2:7b4657c7b996 9 * furnished to do so, subject to the following conditions:
Info 2:7b4657c7b996 10 *
Info 2:7b4657c7b996 11 * The above copyright notice and this permission notice shall be included in
Info 2:7b4657c7b996 12 * all copies or substantial portions of the Software.
Info 2:7b4657c7b996 13 *
Info 2:7b4657c7b996 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Info 2:7b4657c7b996 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Info 2:7b4657c7b996 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Info 2:7b4657c7b996 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Info 2:7b4657c7b996 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Info 2:7b4657c7b996 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Info 2:7b4657c7b996 20 * THE SOFTWARE.
Info 2:7b4657c7b996 21 */
Info 2:7b4657c7b996 22
Info 2:7b4657c7b996 23
Info 2:7b4657c7b996 24 #include "mbed.h"
Info 2:7b4657c7b996 25 #include "MCUGearM.h"
Info 2:7b4657c7b996 26 #include "MCUGearBaseM.h"
Info 2:7b4657c7b996 27
Info 2:7b4657c7b996 28 #ifdef DEBUG
Info 2:7b4657c7b996 29 Serial MCUGear_pc(USBTX, USBRX); // tx, rx
Info 2:7b4657c7b996 30 #endif
Info 2:7b4657c7b996 31
Info 2:7b4657c7b996 32 MCUGear::MCUGear(PinName scl, PinName sda, char addr)
Info 2:7b4657c7b996 33 : _i2c(scl, sda) {
Info 2:7b4657c7b996 34 _i2c.frequency(FPGA_I2C_CLOCK);
Info 2:7b4657c7b996 35 _addr = addr; //save address
Info 2:7b4657c7b996 36 write(0xff); //close Module gate
Info 2:7b4657c7b996 37 }
Info 2:7b4657c7b996 38
Info 2:7b4657c7b996 39 void MCUGear::disconnectModule(void){
Info 2:7b4657c7b996 40 write(0xff); //close module gate
Info 2:7b4657c7b996 41 }
Info 2:7b4657c7b996 42
Info 2:7b4657c7b996 43 void MCUGear::connectModule(void){
Info 2:7b4657c7b996 44 write(0xf8); //1111 1000
Info 2:7b4657c7b996 45 }
Info 2:7b4657c7b996 46
Info 2:7b4657c7b996 47 void MCUGear::fpga_write(unsigned char adr, unsigned char data) {
Info 2:7b4657c7b996 48 char cmd[2];
Info 2:7b4657c7b996 49 cmd[0] = adr;
Info 2:7b4657c7b996 50 cmd[1] = data;
Info 2:7b4657c7b996 51 _i2c.write(FPGA_I2C_ADR, cmd, 2);
Info 2:7b4657c7b996 52 }
Info 2:7b4657c7b996 53
Info 2:7b4657c7b996 54 void MCUGear::startReg(char bank){
Info 2:7b4657c7b996 55 _bank = bank;
Info 2:7b4657c7b996 56 fpga_write(0x0c,_bank); //End regist
Info 2:7b4657c7b996 57 }
Info 2:7b4657c7b996 58
Info 2:7b4657c7b996 59 uint8_t MCUGear::setWire(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO){
Info 2:7b4657c7b996 60
Info 2:7b4657c7b996 61 uint8_t location = ( _pnum + moduleIO );
Info 2:7b4657c7b996 62
Info 2:7b4657c7b996 63 if(moduleIO >= numMaxModuleIO){
Info 2:7b4657c7b996 64 return 255; //error
Info 2:7b4657c7b996 65 }
Info 2:7b4657c7b996 66
Info 2:7b4657c7b996 67 if(location >= numBaseboardIO){
Info 2:7b4657c7b996 68 location = location - numBaseboardIO;
Info 2:7b4657c7b996 69 }
Info 2:7b4657c7b996 70
Info 2:7b4657c7b996 71 fpga_write(mcuIO, (IO_REG_EN | (direction | (location))));
Info 2:7b4657c7b996 72 return location;
Info 2:7b4657c7b996 73 }
Info 2:7b4657c7b996 74
Info 2:7b4657c7b996 75
Info 2:7b4657c7b996 76 void MCUGear::endReg(void){
Info 2:7b4657c7b996 77 fpga_write(0x10,_bank);//init regist///////
Info 2:7b4657c7b996 78 }
Info 2:7b4657c7b996 79
Info 2:7b4657c7b996 80
Info 2:7b4657c7b996 81 //send I2C signal function
Info 2:7b4657c7b996 82 void MCUGear::write(uint8_t c){
Info 2:7b4657c7b996 83
Info 2:7b4657c7b996 84 char cmd[1];
Info 2:7b4657c7b996 85 cmd[0] = c;
Info 2:7b4657c7b996 86 _i2c.write(_addr, cmd, 1);
Info 2:7b4657c7b996 87
Info 2:7b4657c7b996 88 }
Info 2:7b4657c7b996 89
Info 2:7b4657c7b996 90 ////detect module
Info 2:7b4657c7b996 91 uint8_t MCUGear::detectModule(void) {
Info 2:7b4657c7b996 92
Info 2:7b4657c7b996 93 write(0x7f); //0111 1111 //1pin GND
Info 2:7b4657c7b996 94 _pnum = fpga_read(FPGA_I2C_ADR,FPGA_DETECT);//save location
Info 2:7b4657c7b996 95 write(0xff); //1111 1111 //close
Info 2:7b4657c7b996 96
Info 2:7b4657c7b996 97 return _pnum;
Info 2:7b4657c7b996 98
Info 2:7b4657c7b996 99 }
Info 2:7b4657c7b996 100