i2c_master.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*********************************************************************
  2. *
  3. * i2c master library for Fraise pic18f device
  4. *********************************************************************
  5. * Author Date Comment
  6. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. * Antoine Rousseau october 2013 adapted from Vangelis Rokas's sdcc i2c lib.
  8. ********************************************************************/
  9. /*
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. # MA 02110-1301, USA.
  23. */
  24. #ifndef __I2CM_H__
  25. #define __I2CM_H__
  26. #include <config.h>
  27. #define _I2CPARAM_SPEC __data
  28. /* I2C modes of operation */
  29. #define I2C_SLAVE10B_INT 0x0f
  30. #define I2C_SLAVE7B_INT 0x0e
  31. #define I2C_SLAVE_IDLE 0x0b
  32. #define I2C_MASTER 0x08
  33. #define I2C_SLAVE10B 0x07
  34. #define I2C_SLAVE7B 0x06
  35. /* slew rate control */
  36. #define I2C_SLEW_OFF 0x80
  37. #define I2C_SLEW_ON 0x00
  38. /* stop */
  39. void i2cm_stop(void);
  40. /* start */
  41. void i2cm_start(void);
  42. /* restart */
  43. void i2cm_restart(void);
  44. /* not acknowledge */
  45. void i2cm_nack(void);
  46. /* acknowledge */
  47. void i2cm_ack(void);
  48. /* wait until I2C goes idle */
  49. void i2cm_idle(void);
  50. /* is character ready in I2C buffer ?? */
  51. unsigned char i2cm_drdy(void);
  52. /* read a character from I2C module */
  53. unsigned char i2cm_readchar(void);
  54. /* read a string from I2C module */
  55. char i2cm_readstr(_I2CPARAM_SPEC unsigned char *ptr, unsigned char len);
  56. /* write a character to I2C module */
  57. char i2cm_writechar(unsigned char dat);
  58. /* write a string to I2C module */
  59. char i2cm_writestr(unsigned char *ptr);
  60. /* begin communication to I2C module */
  61. void i2cm_begin(unsigned char address, unsigned char doread);
  62. /* configure I2C port for operation */
  63. void i2cm_init(unsigned char mode, unsigned char slew, unsigned char addr_brd);
  64. void i2cm_close(void);
  65. #endif /* __I2C_H__ */