i2c_s.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. #ifndef _IIC_SLAVE_H
  29. #define _IIC_SLAVE_H
  30. #define I2CS_RX_MAX_SIZE 64
  31. #define I2CS_TX_MAX_SIZE 64
  32. //i2cs working state
  33. enum{
  34. I2CSST_IDLE = 0,
  35. I2CSST_XMITING
  36. };
  37. typedef enum{
  38. I2CS_0 = 1,
  39. I2CS_1,
  40. }i2cs_channel_t;
  41. typedef enum{
  42. I2CS_MODE_REG_8BIT = 1,
  43. I2CS_MODE_REG_16BIT,
  44. I2CS_MODE_RAW
  45. }i2cs_mode_t;
  46. enum{
  47. I2CS_EVT_REG_REQ_READ = 1, //register mode read, master read request
  48. I2CS_EVT_REG_REQ_READ_CMPL, //register mode read, read completed
  49. I2CS_EVT_REG_RECV, //register mode write, recieved data
  50. I2CS_ET_RAW_RECV, //master write data to slave
  51. I2CS_ET_RAW_TX_CMPL, //master read data from slave completed
  52. };//event type
  53. typedef struct{
  54. uint8_t type;
  55. uint8_t reg_u8;
  56. uint16_t reg_u16;
  57. uint8_t* dat;
  58. }i2cs_evt_t;
  59. typedef void (*i2cs_hdl_t)(i2cs_evt_t *pev);
  60. void __attribute__((weak)) hal_I2C0_IRQHandler(void);
  61. void __attribute__((weak)) hal_I2C1_IRQHandler(void);
  62. int i2cs_init(
  63. i2cs_channel_t ch_id,
  64. i2cs_mode_t mode,
  65. uint8_t saddr, //slave address
  66. GPIO_Pin_e cs, //if need not cs, choose GPIO_DUMMY_PIN
  67. GPIO_Pin_e sda,
  68. GPIO_Pin_e scl,
  69. i2cs_hdl_t evt_handler);
  70. #endif