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: PCA9956A_Hello pca9956b_two_demoboards PCA9955A_Gradation_control PCA9955A_Gradation_control ... more
PCA995xA.cpp
00001 #include "mbed.h" 00002 #include "PCA995xA.h" 00003 00004 PCA995xA::PCA995xA( PinName i2c_sda, PinName i2c_scl, char i2c_address ) 00005 : i2c_p( new I2C( i2c_sda, i2c_scl ) ), i2c( *i2c_p ), address( i2c_address ) 00006 { 00007 } 00008 00009 PCA995xA::PCA995xA( I2C &i2c_, char i2c_address ) 00010 : i2c_p( NULL ), i2c( i2c_ ), address( i2c_address ) 00011 { 00012 } 00013 00014 PCA995xA::~PCA995xA() 00015 { 00016 if ( NULL != i2c_p ) 00017 delete i2c_p; 00018 } 00019 00020 void PCA995xA::reset( void ) 00021 { 00022 char v = 0x06; 00023 i2c.write( 0x00, &v, 1 ); 00024 } 00025 00026 void PCA995xA::pwm( int port, float v ) 00027 { 00028 char reg_addr; 00029 00030 reg_addr = pwm_register_access( port ); 00031 write( reg_addr, (char)(v * 255.0) ); 00032 } 00033 00034 void PCA995xA::pwm( float *vp ) 00035 { 00036 int n_of_ports = number_of_ports(); 00037 char data[ n_of_ports + 1 ]; 00038 00039 *data = pwm_register_access( 0 ); 00040 00041 for ( int i = 1; i <= n_of_ports; i++ ) 00042 data[ i ] = (char)(*vp++ * 255.0); 00043 00044 write( data, sizeof( data ) ); 00045 } 00046 00047 void PCA995xA::current( int port, float v ) 00048 { 00049 char reg_addr; 00050 00051 reg_addr = current_register_access( port ); 00052 write( reg_addr, (char)(v * 255.0) ); 00053 } 00054 00055 void PCA995xA::current( float *vp ) 00056 { 00057 int n_of_ports = number_of_ports(); 00058 char data[ n_of_ports + 1 ]; 00059 00060 *data = pwm_register_access( 0 ); 00061 00062 for ( int i = 1; i <= n_of_ports; i++ ) 00063 data[ i ] = (char)(*vp++ * 255.0); 00064 00065 write( data, sizeof( data ) ); 00066 } 00067 00068 void PCA995xA::write( char *data, int length ) 00069 { 00070 *data |= AUTO_INCREMENT; 00071 i2c.write( address, data, length ); 00072 } 00073 00074 void PCA995xA::write( char reg_addr, char data ) 00075 { 00076 char c[2]; 00077 00078 c[0] = reg_addr; 00079 c[1] = data; 00080 00081 i2c.write( address, c, 2 ); 00082 } 00083 00084 void PCA995xA::read( char reg_addr, char *data, int length ) 00085 { 00086 reg_addr |= 0x80; 00087 i2c.write( address, (char *)(®_addr), 1, true ); 00088 i2c.read( address, data, length ); 00089 } 00090 00091 char PCA995xA::read( char reg_addr ) 00092 { 00093 i2c.write( address, (char *)(®_addr), 1, true ); 00094 i2c.read( address, (char *)(®_addr), 1 ); 00095 00096 return ( reg_addr ); 00097 }
Generated on Wed Jul 13 2022 08:07:57 by
