class pah8011 for mbed
Diff: pah8011/pah_comm_i2c.c
- Revision:
- 0:242cf8f28bf2
diff -r 000000000000 -r 242cf8f28bf2 pah8011/pah_comm_i2c.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pah8011/pah_comm_i2c.c Thu Oct 26 02:49:44 2017 +0000 @@ -0,0 +1,62 @@ +/*============================================================================== +* 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; +}