twi.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #define TWI_TIMEOUT_MS 100
  23. /*
  24. * Function twi_init
  25. * Desc readys twi pins and sets twi bitrate
  26. * Input none
  27. * Output none
  28. */
  29. void twi_init(void);
  30. /*
  31. * Function twi_disable
  32. * Desc disables twi pins
  33. * Input none
  34. * Output none
  35. */
  36. void twi_disable(void);
  37. /*
  38. * Function twi_r8
  39. * Desc read a single byte from a device
  40. * Input address: 7bit i2c device address
  41. * reg: register address
  42. * data: pointer to byte for result
  43. * Output 0 on success
  44. */
  45. uint8_t twi_r8(uint8_t address, uint8_t reg, uint8_t* data);
  46. /*
  47. * Function twi_w8
  48. * Desc write a single byte from a device
  49. * Input address: 7bit i2c device address
  50. * reg: register address
  51. * data: byte to write
  52. * Output 0 on success
  53. */
  54. uint8_t twi_w8(uint8_t address, uint8_t reg, uint8_t data);