Ben Willems / Mbed 2 deprecated MLX90418_I2C_master_bwi

Dependencies:   mbed

i2c_mbed_fpga.cpp

Committer:
wuliqunyy
Date:
2021-01-22
Revision:
5:daab0e0e67e2
Parent:
0:fe3c7dde9771
Child:
6:019ab407ac3c

File content as of revision 5:daab0e0e67e2:

#include "mbed.h"
#include "i2c_mbed_fpga.h"


/** i2c write to slave DUT
*
*  @param i2c_master specifies the i2c interface
*  @param word is considered as 4byte char data
*/
int i2c_mbed_fpga::i2c_word_write(char *word){
    int ack;
    ack = i2c_master.write(i2c_slave_addr, word, 4, 0);
    wait_us(100); 
    return ack; 
}


/** i2c read from slave DUT
*
*  @param i2c_master specifies the i2c interface
*  @param word is 4byte, first 2bytes as addr, the rest 2bytes to store data
*/
int i2c_mbed_fpga::i2c_word_read(char *word){
    int ack;
    ack = i2c_master.write(i2c_slave_addr, word, 2, 1);
    ack += i2c_master.read(i2c_slave_addr, word+2, 2, 0);
    wait_us(100); 
    return (ack == 0) ? 0 : 1; 
}


/** i2c enter key to open I2C window
*
*  @param specifc key needed to enter i2c mode of DUT
*/
int i2c_mbed_fpga::i2c_window_open(){
    char i2cKey[4] = {0x13, 0xA4, 0xD0, 0xD0};
    return i2c_word_write(i2cKey);
}

/** i2c enter key to Start the motor
*
*  @param specifc key needed to enter i2c mode of DUT
*/
int i2c_mbed_fpga::i2c_motor_start(){
    char i2cKey[4] = {0x13, 0xA4, 0xCA, 0xFE};
    return i2c_word_write(i2cKey);
}