test version 0.2

Dependents:   SC18IS606_Hello SC18IS606_EEPROM_access_test SC18IS606_OS6_Hello

SC18IS606.cpp

Committer:
okano
Date:
2021-07-14
Revision:
2:4e64923032ad
Parent:
1:b44f801ac9f2
Child:
3:47f1f22747cc

File content as of revision 2:4e64923032ad:

/*
 *  SC18IS606 library
 *
 *  @author     Akifumi (Tedd) OKANO, NXP Semiconductors
 *  @version    0.1
 *  @date       13-July-2021
 *
 *  SC18IS606 is an "I2C-bus to SPI bridge"
 *  http://www.nxp.com/ (product infomation page will be updated later)
 */

#include    "mbed.h"
#include    "SC18IS606.h"

SC18IS606::SC18IS606( PinName sda, PinName scl, char i2c_address )
    : i2c_p( new I2C( sda, scl ) ), i2c( *i2c_p ), device_address( i2c_address )
{
    init();
}

SC18IS606::SC18IS606( I2C &i2c_, char i2c_address )
    : i2c_p( NULL ), i2c( i2c_ ), device_address( i2c_address )
{
    init();
}

SC18IS606::~SC18IS606()
{
    if ( NULL != i2c_p )
        delete  i2c_p;
}

int SC18IS606::init( void )
{
    return 0;   //  dummy
}

int SC18IS606::transfer( int slave_select_num, char *send_data_ptr, int length )
{
    char    *p;
    p   = new char[ length + 1 ];
    
    *p  = SPI_read_and_write | (0x1 << slave_select_num);
    memcpy( p + 1, send_data_ptr, length );
    i2c.write( device_address, p, length + 1 );
    delete[]    p;

    return 0;   //  dummy
}

int SC18IS606::read_buffer( char *receive_data_ptr, int length )
{
    if ( receive_data_ptr )
        i2c.read( device_address, receive_data_ptr, length );
    
    return 0;   //  dummy
}

int SC18IS606::config( FunctionID fid, char data )
{
    char    s[ 2 ];
    s[ 0 ]  = fid;
    s[ 1 ]  = data;
    i2c.write( device_address, s, sizeof( s ) );
    
    return 0;   //  dummy
}

int SC18IS606::clear_interrupt( void )
{
    char    c   = Clear_Interrupt;
    i2c.write( device_address, &c, sizeof( c ) );    

    return 0;   //  dummy
}

#if 0
void SC18IS606::wait_transfer_done( void )
{
    char    func_id = 0x01;
    while ( i2c.write( device_address, &func_id, 1 ) )
        ;
}
#endif