hal_nca9555.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef __HAL_NCA9555_H__
  2. #define __HAL_NCA9555_H__
  3. #include "hc32_ll_gpio.h"
  4. #include "hc32_ll_fcg.h"
  5. #include "hc32_ll_interrupts.h"
  6. #include "hc32_ll_tmr0.h"
  7. #include "ring_buf.h"
  8. #include "hc32_ll_aos.h"
  9. /***************************************************IIC 驱动部门**********************************************************/
  10. #define IIC_SCL_GPIO_PORT gpioPortB
  11. #define IIC_SCL_GPIO_PIN 1
  12. #define IIC_SDA_GPIO_PORT gpioPortB
  13. #define IIC_SDA_GPIO_PIN 2
  14. #define IIC_SCL_SET_GPIO_OUTPUT_STATUS(status) if(status == 1) GPIO_PinOutSet(IIC_SCL_GPIO_PORT, IIC_SCL_GPIO_PIN);\
  15. else if(status == 0) GPIO_PinOutClear(IIC_SCL_GPIO_PORT, IIC_SCL_GPIO_PIN);
  16. #define IIC_SDA_SET_GPIO_OUTPUT_STATUS(status) if(status == 1) GPIO_PinOutSet(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN);\
  17. else if(status == 0) GPIO_PinOutClear(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN);
  18. #define IIC_SDA_GET_GPIO_INPUT_STATUS GPIO_PinInGet(IIC_SDA_GPIO_PORT, IIC_SDA_GPIO_PIN)
  19. void IIC_gpio_init(void);
  20. void IIC_start(void);
  21. void IIC_stop(void);
  22. uint8_t IIC_wait_ack(void);
  23. void IIC_ack(void);
  24. void IIC_nack(void);
  25. void IIC_send_byte(uint8_t txd);
  26. void IIC_send_byte(uint8_t txd);
  27. uint8_t IIC_read_byte(unsigned char ack);
  28. void iic3_init(void);
  29. void nca9555_set_output_mode(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  30. void nca9555_set_gpio_output_status(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num, uint8_t status);
  31. void nca9555_set_input_mode(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  32. uint8_t nca9555_get_gpio_status(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  33. /***********************************************************IIC 驱动 END**********************************************************************/
  34. /************************************************************NCA9555 驱动***********************************************************/
  35. #define SUCCESS 0
  36. #define ERROR 1
  37. #define SLAVE_ADDR0 0x40
  38. #define SLAVE_ADDR1 0x42
  39. #define SLAVE_ADDR2 0x44
  40. #define HOST_WRITE_COMMAND 0x00
  41. #define HOST_READ_COMMAND 0x01
  42. /*输入相关*/
  43. #define INPUT_PORT_REGISTER0 0x00 /* 输入端口寄存器0,负责IO00-IO07 */
  44. #define INPUT_PORT_REGISTER1 0x01 /* 输入端口寄存器1,负责IO10-IO17 */
  45. //#define POLARITY_INVERSION_PORT_REGISTER0 0x04 /* 输入端口寄存器0,负责IO00-IO07 */
  46. //#define POLARITY_INVERSION_PORT_REGISTER1 0x05 /* 输入端口寄存器1,负责IO10-IO17 */
  47. /*输出相关*/
  48. #define OUTPUT_PORT_REGISTER0 0x02 /* 输入端口寄存器0,负责IO00-IO07 */
  49. #define OUTPUT_PORT_REGISTER1 0x03 /* 输入端口寄存器1,负责IO10-IO17 */
  50. #define CONFIG_PORT_REGISTER0 0x06 /* 输入端口寄存器0,负责IO00-IO07 */
  51. #define CONFIG_PORT_REGISTER1 0x07 /* 输入端口寄存器1,负责IO10-IO17 */
  52. #define GPIO_PORT0 0
  53. #define GPIO_PORT1 1
  54. #define GPIO_Pin00 0x01
  55. #define GPIO_Pin01 0x02
  56. #define GPIO_Pin02 0x04
  57. #define GPIO_Pin03 0x08
  58. #define GPIO_Pin04 0x10
  59. #define GPIO_Pin05 0x20
  60. #define GPIO_Pin06 0x40
  61. #define GPIO_Pin07 0x80
  62. #define HIGH 1
  63. #define LOW 0
  64. #define NCA9555_WAIT_IS_RETURN_SUCCESS(flag, tips) if(flag != SUCCESS)\
  65. { \
  66. printf("%s", tips); \
  67. return ERROR;\
  68. }
  69. void nca9555_init(void);
  70. void nca9555_read_wtite_test(void);
  71. void nca9555_set_output_mode(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  72. void nca9555_set_gpio_output_status(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num, uint8_t status);
  73. void nca9555_set_input_mode(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  74. uint8_t nca9555_get_gpio_status(uint8_t slave_num, uint8_t gpio_port, uint8_t gpio_num);
  75. void nca9555_task(void *argv);
  76. /************************************************************NCA9555 驱动 END***********************************************************/
  77. #endif