class pah8011 for mbed
pah8011/pah_comm_i2c.c@0:242cf8f28bf2, 2017-10-26 (annotated)
- Committer:
- bell_huang
- Date:
- Thu Oct 26 02:49:44 2017 +0000
- Revision:
- 0:242cf8f28bf2
Init version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bell_huang | 0:242cf8f28bf2 | 1 | /*============================================================================== |
bell_huang | 0:242cf8f28bf2 | 2 | * Edit History |
bell_huang | 0:242cf8f28bf2 | 3 | * |
bell_huang | 0:242cf8f28bf2 | 4 | * This section contains comments describing changes made to the module. Notice |
bell_huang | 0:242cf8f28bf2 | 5 | * that changes are listed in reverse chronological order. Please use ISO format |
bell_huang | 0:242cf8f28bf2 | 6 | * for dates. |
bell_huang | 0:242cf8f28bf2 | 7 | * |
bell_huang | 0:242cf8f28bf2 | 8 | * when who what, where, why |
bell_huang | 0:242cf8f28bf2 | 9 | * ---------- --- ----------------------------------------------------------- |
bell_huang | 0:242cf8f28bf2 | 10 | * 2016-10-18 bh - Add pah_comm_get_bus_type() function. |
bell_huang | 0:242cf8f28bf2 | 11 | * 2016-04-12 bh - Add license information and revision information |
bell_huang | 0:242cf8f28bf2 | 12 | * 2016-04-07 bh - Initial revision. |
bell_huang | 0:242cf8f28bf2 | 13 | ==============================================================================*/ |
bell_huang | 0:242cf8f28bf2 | 14 | |
bell_huang | 0:242cf8f28bf2 | 15 | #include "pah_comm.h" |
bell_huang | 0:242cf8f28bf2 | 16 | |
bell_huang | 0:242cf8f28bf2 | 17 | // platform support |
bell_huang | 0:242cf8f28bf2 | 18 | #include "pah_platform_functions.h" |
bell_huang | 0:242cf8f28bf2 | 19 | |
bell_huang | 0:242cf8f28bf2 | 20 | |
bell_huang | 0:242cf8f28bf2 | 21 | /*============================================================================ |
bell_huang | 0:242cf8f28bf2 | 22 | STATIC VARIABLE DEFINITIONS |
bell_huang | 0:242cf8f28bf2 | 23 | ============================================================================*/ |
bell_huang | 0:242cf8f28bf2 | 24 | |
bell_huang | 0:242cf8f28bf2 | 25 | // valid bank range: 0x00 ~ 0x03 |
bell_huang | 0:242cf8f28bf2 | 26 | static uint8_t _curr_bank = 0xFF; |
bell_huang | 0:242cf8f28bf2 | 27 | |
bell_huang | 0:242cf8f28bf2 | 28 | |
bell_huang | 0:242cf8f28bf2 | 29 | /*============================================================================ |
bell_huang | 0:242cf8f28bf2 | 30 | PUBLIC FUNCTION DEFINITIONS |
bell_huang | 0:242cf8f28bf2 | 31 | ============================================================================*/ |
bell_huang | 0:242cf8f28bf2 | 32 | bool pah_comm_write(uint8_t addr, uint8_t data) |
bell_huang | 0:242cf8f28bf2 | 33 | { |
bell_huang | 0:242cf8f28bf2 | 34 | if (addr == 0x7F) |
bell_huang | 0:242cf8f28bf2 | 35 | { |
bell_huang | 0:242cf8f28bf2 | 36 | if (_curr_bank == data) |
bell_huang | 0:242cf8f28bf2 | 37 | return true; |
bell_huang | 0:242cf8f28bf2 | 38 | |
bell_huang | 0:242cf8f28bf2 | 39 | if (!i2c_write_reg(0x7F, data)) |
bell_huang | 0:242cf8f28bf2 | 40 | return false; |
bell_huang | 0:242cf8f28bf2 | 41 | |
bell_huang | 0:242cf8f28bf2 | 42 | _curr_bank = data; |
bell_huang | 0:242cf8f28bf2 | 43 | return true; |
bell_huang | 0:242cf8f28bf2 | 44 | } |
bell_huang | 0:242cf8f28bf2 | 45 | |
bell_huang | 0:242cf8f28bf2 | 46 | return i2c_write_reg(addr, data); |
bell_huang | 0:242cf8f28bf2 | 47 | } |
bell_huang | 0:242cf8f28bf2 | 48 | |
bell_huang | 0:242cf8f28bf2 | 49 | bool pah_comm_read(uint8_t addr, uint8_t *data) |
bell_huang | 0:242cf8f28bf2 | 50 | { |
bell_huang | 0:242cf8f28bf2 | 51 | return i2c_read_reg(addr, data); |
bell_huang | 0:242cf8f28bf2 | 52 | } |
bell_huang | 0:242cf8f28bf2 | 53 | |
bell_huang | 0:242cf8f28bf2 | 54 | bool pah_comm_burst_read(uint8_t addr, uint8_t *data, uint16_t num) |
bell_huang | 0:242cf8f28bf2 | 55 | { |
bell_huang | 0:242cf8f28bf2 | 56 | return i2c_burst_read_reg(addr, data, num); |
bell_huang | 0:242cf8f28bf2 | 57 | } |
bell_huang | 0:242cf8f28bf2 | 58 | |
bell_huang | 0:242cf8f28bf2 | 59 | pah_comm_bus_e pah_comm_get_bus_type(void) |
bell_huang | 0:242cf8f28bf2 | 60 | { |
bell_huang | 0:242cf8f28bf2 | 61 | return pah_comm_bus_i2c; |
bell_huang | 0:242cf8f28bf2 | 62 | } |