android
2024-07-10 94101a2cd9baed60360f68096033dc75cbb1dcb3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*********************************************************************************
 *      Copyright:  (C) 2014 Guo Wenxue<guowenxue@gmail.com>
 *                  All rights reserved.
 *
 *       Filename:  gpio_i2c.h
 *    Description:  STM8 GPIOÄ£ÄâI2C´úÂë
 *                 
 *        Version:  1.0.0(09/28/2014)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "09/28/2014 10:58:17 PM"
 *                 
********************************************************************************/
#include "stm8s.h"
#ifndef __GPIO_I2C_H_
#define __GPIO_I2C_H_
 
#define I2C_GPIO_BASE    GPIOC
 
#define I2C_ACK          0
#define I2C_NAK          1
 
#define I2C_OK           0
#define I2C_ERROR        -1
 
#define I2C_DIR_READ    1
#define I2C_DIR_WRITE   0
 
 /*PC7: I2C SDA */
#define SDA_MODE_OUT   I2C_GPIO_BASE->DDR |= GPIO_PIN_7
#define SDA_HIGH       I2C_GPIO_BASE->ODR |= GPIO_PIN_7
#define SDA_LOW        I2C_GPIO_BASE->ODR &= (uint8_t)(~(GPIO_PIN_7))
 
#define SDA_MODE_IN    I2C_GPIO_BASE->DDR &= (uint8_t)(~(GPIO_PIN_7))
#define SDA_DAT        I2C_GPIO_BASE->IDR & (uint8_t)GPIO_PIN_7
 
/*PC6: I2C SCL */
#define SCL_HIGH       I2C_GPIO_BASE->ODR |= GPIO_PIN_6
#define SCL_LOW        I2C_GPIO_BASE->ODR &= (uint8_t)(~(GPIO_PIN_6))
 
extern void gpio_i2c_init(void);
extern void gpio_i2c_start(void);
extern void gpio_i2c_stop(void);
extern uint8_t gpio_i2c_write_byte(uint8_t byte);
extern uint8_t gpio_i2c_read_byte(void);
extern uint8_t gpio_i2c_read(uint8_t addr, uint8_t reg_addr);
extern int gpio_i2c_write(uint8_t addr, uint8_t reg_addr, uint8_t data);
 
#endif /* __GPIO_I2C_H_ */