test version 0.2
Dependents: SC18IS606_Hello SC18IS606_EEPROM_access_test SC18IS606_OS6_Hello
Revision 5:436b2c7854e8, committed 2021-07-28
- Comitter:
- okano
- Date:
- Wed Jul 28 01:26:27 2021 +0000
- Parent:
- 4:ac0aef91fd94
- Child:
- 6:cfe7ec4f2b59
- Commit message:
- doxygen comment added
Changed in this revision
SC18IS606.cpp | Show annotated file Show diff for this revision Revisions of this file |
SC18IS606.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SC18IS606.cpp Sun Jul 25 08:30:08 2021 +0000 +++ b/SC18IS606.cpp Wed Jul 28 01:26:27 2021 +0000 @@ -32,50 +32,63 @@ int SC18IS606::init( void ) { + int err; + wait_transfer_completion = NULL; - clear_interrupt(); + err = clear_interrupt(); - return 0; // dummy + return err; } int SC18IS606::transfer( int slave_select_num, char *send_data_ptr, int length ) { char *p; + int err; + 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 ); + err = i2c.write( device_address, p, length + 1 ); delete[] p; + if ( err ) + return err; + if ( NULL != wait_transfer_completion ) (*wait_transfer_completion)(); - return 0; // dummy + return err; } int SC18IS606::read_buffer( char *receive_data_ptr, int length ) { + int err; + if ( receive_data_ptr ) - i2c.read( device_address, receive_data_ptr, length ); + err = i2c.read( device_address, receive_data_ptr, length ); - return 0; // dummy + return err; } int SC18IS606::config( FunctionID fid, char data ) { char s[ 2 ]; + int err; + s[ 0 ] = fid; s[ 1 ] = data; - i2c.write( device_address, s, sizeof( s ) ); + err = i2c.write( device_address, s, sizeof( s ) ); - return 0; // dummy + return err; } int SC18IS606::clear_interrupt( void ) { char c = Clear_Interrupt; - i2c.write( device_address, &c, sizeof( c ) ); + int err; + + err = i2c.write( device_address, &c, sizeof( c ) ); - return 0; // dummy + return err; }
--- a/SC18IS606.h Sun Jul 25 08:30:08 2021 +0000 +++ b/SC18IS606.h Wed Jul 28 01:26:27 2021 +0000 @@ -2,8 +2,8 @@ * SC18IS606 library * * @author Akifumi (Tedd) OKANO, NXP Semiconductors - * @version 0.1 - * @date 13-July-2021 + * @version 0.2 + * @date 28-July-2021 * * SC18IS606 is an "I2C-bus to SPI bridge" * http://www.nxp.com/ (product infomation page will be updated later) @@ -14,13 +14,76 @@ #ifndef MBED_SC18IS606 #define MBED_SC18IS606 - /** SC18IS606 class * * This is a driver code for the SC18IS606: * * Example: * @code * #include "mbed.h" + * #include "SC18IS606.h" + * + * I2C i2c( p28, p27 ); + * InterruptIn int_line( p21 ); + * SC18IS606 bridge( i2c ); // make a SC18IS606 instance as "bridge" + * + * #define I2C_FREQUENCY (400 * 1000) // Hz + * #define SLAVE_SELECT_NUM 0 + * #define DATA_LENGTH 256 + * + * void data_check( char *data, int length ); + * + * volatile int int_flag = false; + * + * void int_handler() + * { + * int_flag = true; + * } + * + * void wait_transfer_done( void ) + * { + * while ( !int_flag ) + * ; + * + * bridge.clear_interrupt(); + * int_flag = false; + * } + * + * void hardware_settings( void ) + * { + * int_line.mode( PullUp ); + * int_line.fall( &int_handler ); + * i2c.frequency( I2C_FREQUENCY ); + * } + * + * int main() + * { + * printf( "SC18IS606 Hello\r\n" ); + * + * hardware_settings(); + * bridge.install_wait_func( wait_transfer_done ); + * + * char snd_data[ DATA_LENGTH ]; + * char rcv_data[ DATA_LENGTH ]; + * + * for ( int i = 0; i < DATA_LENGTH; i++ ) { + * snd_data[ i ] = i; + * } + * + * while(1) { + * bridge.transfer( SLAVE_SELECT_NUM, snd_data, sizeof( snd_data ) ); + * bridge.read_buffer( rcv_data, sizeof( rcv_data ) ); + * data_check( rcv_data, DATA_LENGTH ); + * } + * } + * + * void data_check( char *data, int length ) + * { + * for ( int i = 0; i < length; i++ ) { + * if ( !(i % 16) ) + * printf( "\r\n %02X :", i ); + * printf( " %02X", data[ i ] ); + * } + * } * @endcode */ @@ -41,16 +104,24 @@ } FunctionID; - /** Create a SC18IS606 instance connected to specified I2C pins with specified address + /** Error Code */ + typedef enum { + NO_ERROR = 0x00, + } + ErrorCode; + + /** Create a SC18IS606 instance connected to specified I2C pins * - * @param I2C_sda I2C-bus SDA pin - * @param I2C_scl I2C-bus SCL pin + * @param sda I2C-bus SDA pin + * @param scl I2C-bus SCL pin + * @param i2c_address I2C slave address (option, default = 0x50) */ SC18IS606( PinName sda, PinName scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); - /** Create a SC18IS606 instance connected to specified I2C pins with specified address + /** Create a SC18IS606 instance connected to specified I2C instance * * @param i2c I2C object (instance) + * @param i2c_address I2C slave address (option, default = 0x50) */ SC18IS606( I2C &i2c, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); @@ -58,15 +129,20 @@ */ ~SC18IS606(); + /** Installing "wait function" for "SC18IS606::transfer()" + * "SC18IS606::transfer()" will callback install function to monitor SPI transfer completion + * + * @param block pointer to a function to monitor SPI transfer completion + */ void install_wait_func( void (*block)( void ) ) { wait_transfer_completion = block; } - /** Transfer (send data) + /** Transfer (execute SPI transfer) * * @param slave_select_num SPI slave select number (0 ~ 2) - * @param send_ptr Send_data_ptr + * @param send_data_ptr Send_data_ptr * @param length Length of data array * @return dummy */ @@ -74,7 +150,7 @@ /** Read buffer (reading out received data from buffer) * - * @param receive_ptr Receive_data_ptr + * @param receive_data_ptr Receive_data_ptr * @param length Length of data array * @return dummy */