2020-08-20 10:36:01 +00:00
|
|
|
/*
|
2020-08-20 13:29:57 +00:00
|
|
|
twi.h - Stripped-down TWI/I2C library
|
2020-08-20 10:36:01 +00:00
|
|
|
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2020-08-20 13:29:57 +00:00
|
|
|
#pragma once
|
2020-08-20 10:36:01 +00:00
|
|
|
|
2020-08-20 13:29:57 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <compat/twi.h>
|
|
|
|
|
|
|
|
#ifndef TWI_FREQ
|
|
|
|
#define TWI_FREQ 400000L
|
2020-08-20 10:36:01 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-20 13:29:57 +00:00
|
|
|
/*
|
|
|
|
* Function twi_init
|
|
|
|
* Desc readys twi pins and sets twi bitrate
|
|
|
|
* Input none
|
|
|
|
* Output none
|
|
|
|
*/
|
|
|
|
void twi_init(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function twi_disable
|
|
|
|
* Desc disables twi pins
|
|
|
|
* Input none
|
|
|
|
* Output none
|
|
|
|
*/
|
|
|
|
void twi_disable(void);
|
|
|
|
|
|
|
|
/*
|
2020-09-28 18:21:07 +00:00
|
|
|
* Function twi_r8
|
|
|
|
* Desc read a single byte from a device
|
2020-08-20 13:29:57 +00:00
|
|
|
* Input address: 7bit i2c device address
|
2020-09-28 18:21:07 +00:00
|
|
|
* reg: register address
|
|
|
|
* data: pointer to byte for result
|
2020-08-20 13:29:57 +00:00
|
|
|
* Output 0 on success
|
|
|
|
*/
|
2020-09-28 18:21:07 +00:00
|
|
|
uint8_t twi_r8(uint8_t address, uint8_t reg, uint8_t* data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function twi_w8
|
|
|
|
* Desc write a single byte from a device
|
|
|
|
* Input address: 7bit i2c device address
|
|
|
|
* reg: register address
|
|
|
|
* data: byte to write
|
|
|
|
* Output 0 on success
|
|
|
|
*/
|
|
|
|
uint8_t twi_w8(uint8_t address, uint8_t reg, uint8_t data);
|