class pah8011 for mbed

pah8011/pah_comm_i2c.c

Committer:
bell_huang
Date:
2017-10-26
Revision:
0:242cf8f28bf2

File content as of revision 0:242cf8f28bf2:

/*==============================================================================
* Edit History
* 
* This section contains comments describing changes made to the module. Notice
* that changes are listed in reverse chronological order. Please use ISO format
* for dates.
* 
* when       who       what, where, why
* ---------- ---       -----------------------------------------------------------
* 2016-10-18 bh        - Add pah_comm_get_bus_type() function.
* 2016-04-12 bh        - Add license information and revision information
* 2016-04-07 bh        - Initial revision.
==============================================================================*/

#include "pah_comm.h"

// platform support
#include "pah_platform_functions.h"


/*============================================================================
STATIC VARIABLE DEFINITIONS
============================================================================*/

// valid bank range: 0x00 ~ 0x03
static uint8_t _curr_bank = 0xFF;


/*============================================================================
PUBLIC FUNCTION DEFINITIONS
============================================================================*/
bool pah_comm_write(uint8_t addr, uint8_t data)
{
    if (addr == 0x7F)
    {
        if (_curr_bank == data)
            return true;

        if (!i2c_write_reg(0x7F, data))
            return false;

        _curr_bank = data;
        return true;
    }

    return i2c_write_reg(addr, data);
}

bool pah_comm_read(uint8_t addr, uint8_t *data)
{
    return i2c_read_reg(addr, data);
}

bool pah_comm_burst_read(uint8_t addr, uint8_t *data, uint16_t num)
{
    return i2c_burst_read_reg(addr, data, num);
}

pah_comm_bus_e pah_comm_get_bus_type(void)
{
    return pah_comm_bus_i2c;
}