Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SC18IS606_Hello SC18IS606_EEPROM_access_test SC18IS606_OS6_Hello
SC18IS606.cpp@2:4e64923032ad, 2021-07-14 (annotated)
- Committer:
- okano
- Date:
- Wed Jul 14 03:00:18 2021 +0000
- Revision:
- 2:4e64923032ad
- Parent:
- 1:b44f801ac9f2
- Child:
- 3:47f1f22747cc
buffer write/read splitted
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| okano | 1:b44f801ac9f2 | 1 | /* | 
| okano | 1:b44f801ac9f2 | 2 | * SC18IS606 library | 
| okano | 1:b44f801ac9f2 | 3 | * | 
| okano | 1:b44f801ac9f2 | 4 | * @author Akifumi (Tedd) OKANO, NXP Semiconductors | 
| okano | 1:b44f801ac9f2 | 5 | * @version 0.1 | 
| okano | 1:b44f801ac9f2 | 6 | * @date 13-July-2021 | 
| okano | 1:b44f801ac9f2 | 7 | * | 
| okano | 1:b44f801ac9f2 | 8 | * SC18IS606 is an "I2C-bus to SPI bridge" | 
| okano | 1:b44f801ac9f2 | 9 | * http://www.nxp.com/ (product infomation page will be updated later) | 
| okano | 1:b44f801ac9f2 | 10 | */ | 
| okano | 1:b44f801ac9f2 | 11 | |
| okano | 1:b44f801ac9f2 | 12 | #include "mbed.h" | 
| okano | 1:b44f801ac9f2 | 13 | #include "SC18IS606.h" | 
| okano | 1:b44f801ac9f2 | 14 | |
| okano | 1:b44f801ac9f2 | 15 | SC18IS606::SC18IS606( PinName sda, PinName scl, char i2c_address ) | 
| okano | 1:b44f801ac9f2 | 16 | : i2c_p( new I2C( sda, scl ) ), i2c( *i2c_p ), device_address( i2c_address ) | 
| okano | 1:b44f801ac9f2 | 17 | { | 
| okano | 1:b44f801ac9f2 | 18 | init(); | 
| okano | 1:b44f801ac9f2 | 19 | } | 
| okano | 1:b44f801ac9f2 | 20 | |
| okano | 1:b44f801ac9f2 | 21 | SC18IS606::SC18IS606( I2C &i2c_, char i2c_address ) | 
| okano | 1:b44f801ac9f2 | 22 | : i2c_p( NULL ), i2c( i2c_ ), device_address( i2c_address ) | 
| okano | 1:b44f801ac9f2 | 23 | { | 
| okano | 1:b44f801ac9f2 | 24 | init(); | 
| okano | 1:b44f801ac9f2 | 25 | } | 
| okano | 1:b44f801ac9f2 | 26 | |
| okano | 1:b44f801ac9f2 | 27 | SC18IS606::~SC18IS606() | 
| okano | 1:b44f801ac9f2 | 28 | { | 
| okano | 1:b44f801ac9f2 | 29 | if ( NULL != i2c_p ) | 
| okano | 1:b44f801ac9f2 | 30 | delete i2c_p; | 
| okano | 1:b44f801ac9f2 | 31 | } | 
| okano | 1:b44f801ac9f2 | 32 | |
| okano | 1:b44f801ac9f2 | 33 | int SC18IS606::init( void ) | 
| okano | 1:b44f801ac9f2 | 34 | { | 
| okano | 1:b44f801ac9f2 | 35 | return 0; // dummy | 
| okano | 1:b44f801ac9f2 | 36 | } | 
| okano | 1:b44f801ac9f2 | 37 | |
| okano | 2:4e64923032ad | 38 | int SC18IS606::transfer( int slave_select_num, char *send_data_ptr, int length ) | 
| okano | 1:b44f801ac9f2 | 39 | { | 
| okano | 1:b44f801ac9f2 | 40 | char *p; | 
| okano | 1:b44f801ac9f2 | 41 | p = new char[ length + 1 ]; | 
| okano | 1:b44f801ac9f2 | 42 | |
| okano | 2:4e64923032ad | 43 | *p = SPI_read_and_write | (0x1 << slave_select_num); | 
| okano | 1:b44f801ac9f2 | 44 | memcpy( p + 1, send_data_ptr, length ); | 
| okano | 1:b44f801ac9f2 | 45 | i2c.write( device_address, p, length + 1 ); | 
| okano | 1:b44f801ac9f2 | 46 | delete[] p; | 
| okano | 2:4e64923032ad | 47 | |
| okano | 2:4e64923032ad | 48 | return 0; // dummy | 
| okano | 2:4e64923032ad | 49 | } | 
| okano | 2:4e64923032ad | 50 | |
| okano | 2:4e64923032ad | 51 | int SC18IS606::read_buffer( char *receive_data_ptr, int length ) | 
| okano | 2:4e64923032ad | 52 | { | 
| okano | 1:b44f801ac9f2 | 53 | if ( receive_data_ptr ) | 
| okano | 1:b44f801ac9f2 | 54 | i2c.read( device_address, receive_data_ptr, length ); | 
| okano | 1:b44f801ac9f2 | 55 | |
| okano | 1:b44f801ac9f2 | 56 | return 0; // dummy | 
| okano | 1:b44f801ac9f2 | 57 | } | 
| okano | 1:b44f801ac9f2 | 58 | |
| okano | 1:b44f801ac9f2 | 59 | int SC18IS606::config( FunctionID fid, char data ) | 
| okano | 1:b44f801ac9f2 | 60 | { | 
| okano | 1:b44f801ac9f2 | 61 | char s[ 2 ]; | 
| okano | 1:b44f801ac9f2 | 62 | s[ 0 ] = fid; | 
| okano | 1:b44f801ac9f2 | 63 | s[ 1 ] = data; | 
| okano | 1:b44f801ac9f2 | 64 | i2c.write( device_address, s, sizeof( s ) ); | 
| okano | 1:b44f801ac9f2 | 65 | |
| okano | 1:b44f801ac9f2 | 66 | return 0; // dummy | 
| okano | 1:b44f801ac9f2 | 67 | } | 
| okano | 1:b44f801ac9f2 | 68 | |
| okano | 1:b44f801ac9f2 | 69 | int SC18IS606::clear_interrupt( void ) | 
| okano | 1:b44f801ac9f2 | 70 | { | 
| okano | 1:b44f801ac9f2 | 71 | char c = Clear_Interrupt; | 
| okano | 1:b44f801ac9f2 | 72 | i2c.write( device_address, &c, sizeof( c ) ); | 
| okano | 1:b44f801ac9f2 | 73 | |
| okano | 1:b44f801ac9f2 | 74 | return 0; // dummy | 
| okano | 1:b44f801ac9f2 | 75 | } | 
| okano | 2:4e64923032ad | 76 | |
| okano | 2:4e64923032ad | 77 | #if 0 | 
| okano | 2:4e64923032ad | 78 | void SC18IS606::wait_transfer_done( void ) | 
| okano | 2:4e64923032ad | 79 | { | 
| okano | 2:4e64923032ad | 80 | char func_id = 0x01; | 
| okano | 2:4e64923032ad | 81 | while ( i2c.write( device_address, &func_id, 1 ) ) | 
| okano | 2:4e64923032ad | 82 | ; | 
| okano | 2:4e64923032ad | 83 | } | 
| okano | 2:4e64923032ad | 84 | #endif |