class pah8011 for mbed
pah8011/pah_comm.c@6:d196b612b14a, 2019-01-23 (annotated)
- Committer:
- bell_huang
- Date:
- Wed Jan 23 08:01:57 2019 +0000
- Revision:
- 6:d196b612b14a
Remove mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bell_huang | 6:d196b612b14a | 1 | #include "pah_comm.h" |
bell_huang | 6:d196b612b14a | 2 | |
bell_huang | 6:d196b612b14a | 3 | #include "pah_util.h" |
bell_huang | 6:d196b612b14a | 4 | |
bell_huang | 6:d196b612b14a | 5 | |
bell_huang | 6:d196b612b14a | 6 | /*============================================================================ |
bell_huang | 6:d196b612b14a | 7 | STATIC VARIABLE DEFINITIONS |
bell_huang | 6:d196b612b14a | 8 | ============================================================================*/ |
bell_huang | 6:d196b612b14a | 9 | static bool _has_drv_comm = false; |
bell_huang | 6:d196b612b14a | 10 | static pah_drv_comm_s _drv_comm; |
bell_huang | 6:d196b612b14a | 11 | |
bell_huang | 6:d196b612b14a | 12 | |
bell_huang | 6:d196b612b14a | 13 | /*============================================================================ |
bell_huang | 6:d196b612b14a | 14 | PUBLIC FUNCTION DEFINITIONS |
bell_huang | 6:d196b612b14a | 15 | ============================================================================*/ |
bell_huang | 6:d196b612b14a | 16 | void pah_comm_set_drv_comm(const pah_drv_comm_s *drv_comm) |
bell_huang | 6:d196b612b14a | 17 | { |
bell_huang | 6:d196b612b14a | 18 | memcpy(&_drv_comm, drv_comm, sizeof(*drv_comm)); |
bell_huang | 6:d196b612b14a | 19 | _has_drv_comm = true; |
bell_huang | 6:d196b612b14a | 20 | } |
bell_huang | 6:d196b612b14a | 21 | |
bell_huang | 6:d196b612b14a | 22 | bool pah_comm_write(uint8_t addr, uint8_t data) |
bell_huang | 6:d196b612b14a | 23 | { |
bell_huang | 6:d196b612b14a | 24 | if (!_has_drv_comm) |
bell_huang | 6:d196b612b14a | 25 | return false; |
bell_huang | 6:d196b612b14a | 26 | |
bell_huang | 6:d196b612b14a | 27 | if (_drv_comm.type == pah_drv_comm_spi) |
bell_huang | 6:d196b612b14a | 28 | PAH_CLEAR_BIT(addr, 7); //write, bit7 = 0 |
bell_huang | 6:d196b612b14a | 29 | |
bell_huang | 6:d196b612b14a | 30 | return PAH_SUCCEEDED(_drv_comm.write(&_drv_comm, addr, data)); |
bell_huang | 6:d196b612b14a | 31 | } |
bell_huang | 6:d196b612b14a | 32 | |
bell_huang | 6:d196b612b14a | 33 | bool pah_comm_read(uint8_t addr, uint8_t *data) |
bell_huang | 6:d196b612b14a | 34 | { |
bell_huang | 6:d196b612b14a | 35 | if (!_has_drv_comm) |
bell_huang | 6:d196b612b14a | 36 | return false; |
bell_huang | 6:d196b612b14a | 37 | |
bell_huang | 6:d196b612b14a | 38 | if (_drv_comm.type == pah_drv_comm_spi) |
bell_huang | 6:d196b612b14a | 39 | PAH_SET_BIT(addr, 7); //read, bit7 = 1 |
bell_huang | 6:d196b612b14a | 40 | |
bell_huang | 6:d196b612b14a | 41 | return PAH_SUCCEEDED(_drv_comm.read(&_drv_comm, addr, data)); |
bell_huang | 6:d196b612b14a | 42 | } |
bell_huang | 6:d196b612b14a | 43 | |
bell_huang | 6:d196b612b14a | 44 | bool pah_comm_burst_read(uint8_t addr, uint8_t *data, uint16_t num) |
bell_huang | 6:d196b612b14a | 45 | { |
bell_huang | 6:d196b612b14a | 46 | if (!_has_drv_comm) |
bell_huang | 6:d196b612b14a | 47 | return false; |
bell_huang | 6:d196b612b14a | 48 | |
bell_huang | 6:d196b612b14a | 49 | if (_drv_comm.type == pah_drv_comm_spi) |
bell_huang | 6:d196b612b14a | 50 | PAH_SET_BIT(addr, 7); //read, bit7 = 1 |
bell_huang | 6:d196b612b14a | 51 | |
bell_huang | 6:d196b612b14a | 52 | return PAH_SUCCEEDED(_drv_comm.burst_read(&_drv_comm, addr, data, num)); |
bell_huang | 6:d196b612b14a | 53 | } |
bell_huang | 6:d196b612b14a | 54 | |
bell_huang | 6:d196b612b14a | 55 | pah_comm_bus_e pah_comm_get_bus_type(void) |
bell_huang | 6:d196b612b14a | 56 | { |
bell_huang | 6:d196b612b14a | 57 | if (_drv_comm.type == pah_drv_comm_spi) |
bell_huang | 6:d196b612b14a | 58 | return pah_comm_bus_spi; |
bell_huang | 6:d196b612b14a | 59 | return pah_comm_bus_i2c; |
bell_huang | 6:d196b612b14a | 60 | } |