mini board PCU9669 (and PCA9665) sample code

Dependencies:   mbed PCU9669 utility PCA9665 I2C_slaves parallel_bus

Fork of mini_board_PCU9669_old by InetrfaceProducts NXP

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

Committer:
nxp_ip
Date:
Mon Mar 26 06:17:23 2012 +0000
Revision:
5:57c345099873
tempolary version for trouble shooting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 5:57c345099873 1 /** A sample code for "mini board PCU9669/PCA9665"
nxp_ip 5:57c345099873 2 *
nxp_ip 5:57c345099873 3 * @author Tedd OKANO, NXP Semiconductors
nxp_ip 5:57c345099873 4 * @version 0.9
nxp_ip 5:57c345099873 5 * @date 14-Feb-2011
nxp_ip 5:57c345099873 6 *
nxp_ip 5:57c345099873 7 * Released under the MIT License: http://mbed.org/license/mit
nxp_ip 5:57c345099873 8 *
nxp_ip 5:57c345099873 9 * An operation sample of PCU9669/PCA9665 I2C bus controller.
nxp_ip 5:57c345099873 10 * The mbed accesses the bus controller's parallel port (8/2 bit address and 8 bit data) by bit-banging.
nxp_ip 5:57c345099873 11 * The bit-banging is poerformed by PortInOut function of mbed library.
nxp_ip 5:57c345099873 12 *
nxp_ip 5:57c345099873 13 * To make the code porting easier, all codes are partitioned into layers to abstract other parts.
nxp_ip 5:57c345099873 14 * The mbed specific parts are concentrated in lowest layer: "hardware_abs.*".
nxp_ip 5:57c345099873 15 * This module may need to be modified for the porting.
nxp_ip 5:57c345099873 16 *
nxp_ip 5:57c345099873 17 * All other upper layers are writen in standard-C.
nxp_ip 5:57c345099873 18 *
nxp_ip 5:57c345099873 19 * base code is written from 05-Sep-2011 to 09-Sep-2011.
nxp_ip 5:57c345099873 20 * And demo code has been build on 11-Sep-2011.
nxp_ip 5:57c345099873 21 * Debug and code adjustment has been done on 08-Sep-2011.
nxp_ip 5:57c345099873 22 * Small sanitization for main.cpp. All mbed related codes are moved in to "hardware_abs.*". 13-Oct-2011
nxp_ip 5:57c345099873 23 * hardware_abs are moved into parallel_bus library folder, 3 LED driver operation sample 13-Feb.-2012
nxp_ip 5:57c345099873 24 * PCU9669 and PCA9665 codes are packed in a project 14-Feb-2012.
nxp_ip 5:57c345099873 25 *
nxp_ip 5:57c345099873 26 * Before builidng the code, please edit the file mini_board_PCU9669/config.h
nxp_ip 5:57c345099873 27 * Uncomment the target name what you want to target.
nxp_ip 5:57c345099873 28 */
nxp_ip 5:57c345099873 29
nxp_ip 5:57c345099873 30 /*
nxp_ip 5:57c345099873 31 * "PCU9669_access" module abstracts PCU9669 register and data buffer access.
nxp_ip 5:57c345099873 32 * This gives simple interface to the bus controller.
nxp_ip 5:57c345099873 33 * All this interface works on "hardware_abs" module.
nxp_ip 5:57c345099873 34 */
nxp_ip 5:57c345099873 35
nxp_ip 5:57c345099873 36 #include "PCU9669_access.h" // PCU9669 chip access interface
nxp_ip 5:57c345099873 37 #include "hardware_abs.h" // Using hardware abstraction interface
nxp_ip 5:57c345099873 38
nxp_ip 5:57c345099873 39 //
nxp_ip 5:57c345099873 40 // prototypes (module private function prototypes)
nxp_ip 5:57c345099873 41 //
nxp_ip 5:57c345099873 42
nxp_ip 5:57c345099873 43 int is_bus_controller_ready( void );
nxp_ip 5:57c345099873 44 int check_device_ID( char target_id );
nxp_ip 5:57c345099873 45 void registers_initialize( void );
nxp_ip 5:57c345099873 46
nxp_ip 5:57c345099873 47 // variables
nxp_ip 5:57c345099873 48
nxp_ip 5:57c345099873 49 char device_id_code; // keeps CHIP_ID value
nxp_ip 5:57c345099873 50 char ch_ofst[] = { OFFSET_CH0, OFFSET_CH1, OFFSET_CH2 }; // Address offsets of channel registers
nxp_ip 5:57c345099873 51
nxp_ip 5:57c345099873 52 // Channel register writing function
nxp_ip 5:57c345099873 53
nxp_ip 5:57c345099873 54 void write_ch_register( char ch, char reg, char val ) {
nxp_ip 5:57c345099873 55 write_data( ch_ofst[ ch ] + reg, val );
nxp_ip 5:57c345099873 56 }
nxp_ip 5:57c345099873 57
nxp_ip 5:57c345099873 58 // Channel register reading function
nxp_ip 5:57c345099873 59
nxp_ip 5:57c345099873 60 char read_ch_register( char ch, char reg ) {
nxp_ip 5:57c345099873 61 return( read_data( ch_ofst[ ch ] + reg ) );
nxp_ip 5:57c345099873 62 }
nxp_ip 5:57c345099873 63
nxp_ip 5:57c345099873 64 // Start routine: It checks the bus controller can be accessed, chip-ID value and initializes registers.
nxp_ip 5:57c345099873 65
nxp_ip 5:57c345099873 66 int start_bus_controller( char target_id ) {
nxp_ip 5:57c345099873 67 if ( is_bus_controller_ready() )
nxp_ip 5:57c345099873 68 return 1;
nxp_ip 5:57c345099873 69
nxp_ip 5:57c345099873 70 if ( check_device_ID( target_id ) )
nxp_ip 5:57c345099873 71 return 2;
nxp_ip 5:57c345099873 72
nxp_ip 5:57c345099873 73 registers_initialize();
nxp_ip 5:57c345099873 74
nxp_ip 5:57c345099873 75 return 0;
nxp_ip 5:57c345099873 76 }
nxp_ip 5:57c345099873 77
nxp_ip 5:57c345099873 78 // (module private finction, called by start_bus_controller)
nxp_ip 5:57c345099873 79 // checks if the bus controller can be accessed
nxp_ip 5:57c345099873 80
nxp_ip 5:57c345099873 81 int is_bus_controller_ready( void ) {
nxp_ip 5:57c345099873 82 return ( read_data( CTRLRDY ) );
nxp_ip 5:57c345099873 83 }
nxp_ip 5:57c345099873 84
nxp_ip 5:57c345099873 85 // (module private finction, called by start_bus_controller)
nxp_ip 5:57c345099873 86 // checks if chip-ID value is same as expected. The "TARGET_BUS_CONTROLLER" value can be modified in "PCU9669_access.h"
nxp_ip 5:57c345099873 87
nxp_ip 5:57c345099873 88 int check_device_ID( char target_id ) {
nxp_ip 5:57c345099873 89 device_id_code = read_data( DEVICE_ID );
nxp_ip 5:57c345099873 90 // 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 );
nxp_ip 5:57c345099873 91
nxp_ip 5:57c345099873 92 return ( target_id == device_id_code ) ? 0 : -1;
nxp_ip 5:57c345099873 93 }
nxp_ip 5:57c345099873 94
nxp_ip 5:57c345099873 95 // (module private finction, called by start_bus_controller)
nxp_ip 5:57c345099873 96 // register initializations.
nxp_ip 5:57c345099873 97
nxp_ip 5:57c345099873 98 void registers_initialize( void ) {
nxp_ip 5:57c345099873 99
nxp_ip 5:57c345099873 100 // The PCU9669 does not require any specical register initializations.
nxp_ip 5:57c345099873 101 // It can start data transfer with default register settings.
nxp_ip 5:57c345099873 102 //
nxp_ip 5:57c345099873 103 // Or, if you need to have specific settings modify this function like following sample.
nxp_ip 5:57c345099873 104
nxp_ip 5:57c345099873 105 #if 0
nxp_ip 5:57c345099873 106 write_ch_register( CH_UFM1, SCLPER, 32 );
nxp_ip 5:57c345099873 107 write_ch_register( CH_UFM1, SDADLY, 2 );
nxp_ip 5:57c345099873 108 write_ch_register( CH_UFM2, SCLPER, 32 );
nxp_ip 5:57c345099873 109 write_ch_register( CH_UFM2, SDADLY, 2 );
nxp_ip 5:57c345099873 110 #endif
nxp_ip 5:57c345099873 111 }
nxp_ip 5:57c345099873 112
nxp_ip 5:57c345099873 113 // Next functions are option.
nxp_ip 5:57c345099873 114 // if the BURST_DATA_ACCESS is defined in "hardware_abs.h", it is propagated to define "PCU9969_BURST_DATA_ACCESS"
nxp_ip 5:57c345099873 115 // These interface may be useful for table and buffer access
nxp_ip 5:57c345099873 116
nxp_ip 5:57c345099873 117 #ifdef PCU9969_BURST_DATA_ACCESS
nxp_ip 5:57c345099873 118
nxp_ip 5:57c345099873 119 void write_ch_register_burst( char ch, char reg, char *vp, char length ) {
nxp_ip 5:57c345099873 120 write_data_burst( ch_ofst[ ch ] + reg, vp, length );
nxp_ip 5:57c345099873 121 }
nxp_ip 5:57c345099873 122
nxp_ip 5:57c345099873 123 void read_ch_register_burst( char ch, char reg, char *vp, char length ) {
nxp_ip 5:57c345099873 124 read_data_burst( ch_ofst[ ch ] + reg, vp, length );
nxp_ip 5:57c345099873 125 }
nxp_ip 5:57c345099873 126
nxp_ip 5:57c345099873 127 #endif
nxp_ip 5:57c345099873 128
nxp_ip 5:57c345099873 129
nxp_ip 5:57c345099873 130