test version 0.2

Dependents:   SC18IS606_Hello SC18IS606_EEPROM_access_test SC18IS606_OS6_Hello

SC18IS606.h

Committer:
okano
Date:
2021-07-25
Revision:
4:ac0aef91fd94
Parent:
3:47f1f22747cc
Child:
5:436b2c7854e8

File content as of revision 4:ac0aef91fd94:

/*
 *  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"

#ifndef        MBED_SC18IS606
#define        MBED_SC18IS606


/** SC18IS606 class
 *
 *  This is a driver code for the SC18IS606:  *
 *  Example:
 *  @code
 *  #include "mbed.h"
 *  @endcode
 */

class SC18IS606
{
public:

    /** Function IDs */
    typedef enum {
        SPI_read_and_write      = 0x00,
        Configure_SPI_Interface = 0xF0,
        Clear_Interrupt,
        Idle_mode,
        GPIO_Write              = 0xF4,
        GPIO_Read,
        GPIO_Enable,
        GPIO_Configuration
    }
    FunctionID;

    /** Create a SC18IS606 instance connected to specified I2C pins with specified address
     *
     *  @param I2C_sda      I2C-bus SDA pin
     *  @param I2C_scl      I2C-bus SCL pin
     */
    SC18IS606( PinName sda, PinName scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS );

    /** Create a SC18IS606 instance connected to specified I2C pins with specified address
     *
     *  @param i2c          I2C object (instance)
     */
    SC18IS606( I2C &i2c, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS );

    /** Destractor
     */
    ~SC18IS606();

    void install_wait_func( void (*block)( void ) )
    {
        wait_transfer_completion    = block;
        }

    /** Transfer (send data)
     *
     *  @param slave_select_num SPI slave select number (0 ~ 2)
     *  @param send_ptr         Send_data_ptr
     *  @param length           Length of data array
     *  @return                 dummy
     */
    int transfer( int slave_select_num, char *send_data_ptr, int length );

    /** Read buffer (reading out received data from buffer)
     *
     *  @param receive_ptr      Receive_data_ptr
     *  @param length           Length of data array
     *  @return                 dummy
     */
    int read_buffer( char *receive_data_ptr, int length );

    /** Set congiguration
     *
     *  @param data     Donfig data byte
     *  @return         dummy
     */
    int     config( FunctionID fid, char data );

    /** Clear interrupt
     *
     *  @return         dummy
     */
    int     clear_interrupt( void );

private:

    enum {
        DEFAULT_I2C_SLAVE_ADDRESS   = 0x50
    };

    int     init( void);

    I2C     *i2c_p;
    I2C     &i2c;
    char    device_address;
    void    (*wait_transfer_completion)( void );
};

#endif  // end of "#ifndef MBED_SC18IS606"