twi.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. twi.h - Stripped-down TWI/I2C library
  3. Copyright (c) 2006 Nicholas Zambetti. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #pragma once
  17. #include <inttypes.h>
  18. #include <compat/twi.h>
  19. #ifndef TWI_FREQ
  20. #define TWI_FREQ 400000L
  21. #endif
  22. /*
  23. * Function twi_init
  24. * Desc readys twi pins and sets twi bitrate
  25. * Input none
  26. * Output none
  27. */
  28. void twi_init(void);
  29. /*
  30. * Function twi_disable
  31. * Desc disables twi pins
  32. * Input none
  33. * Output none
  34. */
  35. void twi_disable(void);
  36. /*
  37. * Function twi_r8
  38. * Desc read a single byte from a device
  39. * Input address: 7bit i2c device address
  40. * reg: register address
  41. * data: pointer to byte for result
  42. * Output 0 on success
  43. */
  44. uint8_t twi_r8(uint8_t address, uint8_t reg, uint8_t* data);
  45. /*
  46. * Function twi_w8
  47. * Desc write a single byte from a device
  48. * Input address: 7bit i2c device address
  49. * reg: register address
  50. * data: byte to write
  51. * Output 0 on success
  52. */
  53. uint8_t twi_w8(uint8_t address, uint8_t reg, uint8_t data);