mini board PCU9669 (and PCA9665) sample code
Dependencies: mbed PCU9669 utility PCA9665 I2C_slaves parallel_bus
Fork of mini_board_PCU9669_old by
Sample code for PCU9669 (PCU9661, PCA9663, PCA9661 and PCA9665) evaluation board.
PCU9669 evaluation board: Mini board PCU9669
User manual is available -> http://www.nxp.com/documents/user_manual/UM10580.pdf
mini_board_libs/PCU9669/PCU9669_access.c
- Committer:
- nxp_ip
- Date:
- 2012-03-28
- Revision:
- 8:6120bbbe3636
File content as of revision 8:6120bbbe3636:
/** A sample code for "mini board PCU9669/PCA9665" * * @author Akifumi (Tedd) OKANO, NXP Semiconductors * @version 1.0 * @date 26-Mar-2012 * * Released under the MIT License: http://mbed.org/license/mit * * An operation sample of PCU9669/PCA9665 I2C bus controller. * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging. * The bit-banging is poerformed by PortInOut function of mbed library. * * To make the code porting easier, all codes are partitioned into layers to abstract other parts. * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*". * This module may need to be modified for the porting. * * All other upper layers are writen in standard-C. * * base code is written from 05-Sep-2011 to 09-Sep-2011. * And demo code has been build on 11-Sep-2011. * Debug and code adjustment has been done on 08-Sep-2011. * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011 * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012 * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012. * * Before builidng the code, please edit the file mini_board_PCU9669/config.h * Un-comment the target name what you want to target. */ /* * "PCU9669_access" module abstracts PCU9669 register and data buffer access. * This gives simple interface to the bus controller. * All this interface works on "hardware_abs" module. */ #include "PCU9669_access.h" // PCU9669 chip access interface #include "hardware_abs.h" // Using hardware abstraction interface // // prototypes (module private function prototypes) // int is_bus_controller_ready( void ); int check_device_ID( char target_id ); void registers_initialize( void ); // variables char device_id_code; // keeps CHIP_ID value char ch_ofst[] = { OFFSET_CH0, OFFSET_CH1, OFFSET_CH2 }; // Address offsets of channel registers // Channel register writing function void write_ch_register( char ch, char reg, char val ) { write_data( ch_ofst[ ch ] + reg, val ); } // Channel register reading function char read_ch_register( char ch, char reg ) { return( read_data( ch_ofst[ ch ] + reg ) ); } // Start routine: It checks the bus controller can be accessed, chip-ID value and initializes registers. int start_bus_controller( char target_id ) { if ( is_bus_controller_ready() ) return 1; if ( check_device_ID( target_id ) ) return 2; registers_initialize(); return 0; } // (module private finction, called by start_bus_controller) // checks if the bus controller can be accessed int is_bus_controller_ready( void ) { return ( read_data( CTRLRDY ) ); } // (module private finction, called by start_bus_controller) // checks if chip-ID value is same as expected. The "TARGET_BUS_CONTROLLER" value can be modified in "PCU9669_access.h" int check_device_ID( char target_id ) { device_id_code = read_data( DEVICE_ID ); // printf( "Target chip: PC%c96%02X, ID register value = 0x%02X\r\n", device_id_code & 0x80 ? 'U' : 'A', device_id_code & 0x7F, device_id_code ); return ( target_id == device_id_code ) ? 0 : -1; } // (module private finction, called by start_bus_controller) // register initializations. void registers_initialize( void ) { // The PCU9669 does not require any specical register initializations. // It can start data transfer with default register settings. // // Or, if you need to have specific settings modify this function like following sample. #if 0 write_ch_register( CH_UFM1, SCLPER, 32 ); write_ch_register( CH_UFM1, SDADLY, 2 ); write_ch_register( CH_UFM2, SCLPER, 32 ); write_ch_register( CH_UFM2, SDADLY, 2 ); #endif } // Next functions are option. // if the BURST_DATA_ACCESS is defined in "hardware_abs.h", it is propagated to define "PCU9969_BURST_DATA_ACCESS" // These interface may be useful for table and buffer access #ifdef PCU9969_BURST_DATA_ACCESS void write_ch_register_burst( char ch, char reg, char *vp, char length ) { write_data_burst( ch_ofst[ ch ] + reg, vp, length ); } void read_ch_register_burst( char ch, char reg, char *vp, char length ) { read_data_burst( ch_ofst[ ch ] + reg, vp, length ); } #endif