pcf8574.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2018-11-21 SummerGift first version
  10. * 2018-11-22 flybreak Make the first version of pcf8574's package
  11. */
  12. #ifndef __PCF8574_H
  13. #define __PCF8574_H
  14. #include <rtthread.h>
  15. #include <rtdevice.h>
  16. #define PCF8574_ADDR_DEFAULT 0x20
  17. /* pcf8574 device structure */
  18. struct pcf8574_device
  19. {
  20. struct rt_i2c_bus_device *bus;
  21. rt_uint8_t i2c_addr;
  22. };
  23. typedef struct pcf8574_device *pcf8574_device_t;
  24. /**
  25. * This function initialize the pcf8574 device.
  26. *
  27. * @param dev_name the name of i2c bus device
  28. * @param i2c_addr the i2c device address for i2c communication,RT_NULL use default address
  29. *
  30. * @return the pointer of device structure, RT_NULL reprensents initialization failed.
  31. */
  32. pcf8574_device_t pcf8574_init(const char *dev_name, rt_uint8_t i2c_addr);
  33. /**
  34. * This function releases memory
  35. *
  36. * @param dev the pointer of device structure
  37. */
  38. void pcf8574_deinit(struct pcf8574_device *dev);
  39. /**
  40. * This function read the data port of pcf8574.
  41. *
  42. * @param dev the pointer of device structure
  43. *
  44. * @return the state of data port. 0xFF meas all pin is high.
  45. */
  46. rt_uint8_t pcf8574_port_read(pcf8574_device_t dev);
  47. /**
  48. * This function sets the status of the data port.
  49. *
  50. * @param dev the pointer of device structure
  51. * @param port_val the port value you want to set, 0xFF meas all pin output high.
  52. */
  53. void pcf8574_port_write(pcf8574_device_t dev, rt_uint8_t port_val);
  54. /**
  55. * This function read the specified port pin of the pcf8574.
  56. *
  57. * @param dev the pointer of device structure
  58. * @param pin the specified pin of the data port
  59. *
  60. * @return the status of the specified data port pin, 0 is low, 1 is high.
  61. */
  62. rt_uint8_t pcf8574_pin_read(pcf8574_device_t dev, rt_uint8_t pin);
  63. /**
  64. * This function sets the status of the specified port pin.
  65. *
  66. * @param dev the pointer of device structure
  67. * @param pin_val the specified pin value you want to set, 0 is low, 1 is high.
  68. */
  69. void pcf8574_pin_write(pcf8574_device_t dev, rt_uint8_t pin, rt_uint8_t pin_val);
  70. #endif