i2c.h
Go to the documentation of this file.
1 /*
2  * KubOS HAL
3  * Copyright (C) 2016 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
27 #if (defined YOTTA_CFG_HARDWARE_I2C) && (YOTTA_CFG_HARDWARE_I2C_COUNT > 0)
28 #ifndef K_I2C_H
29 #define K_I2C_H
30 
31 #include <stdint.h>
32 #include <csp/arch/csp_semaphore.h>
33 
46 #ifndef K_NUM_I2CS
47 #define K_NUM_I2CS YOTTA_CFG_HARDWARE_I2C_COUNT
48 #endif
49 
64 #ifndef DEFAULT_I2C
65 #define DEFAULT_I2C YOTTA_CFG_HARDWARE_I2C_DEFAULTS_BUS
66 #endif
67 
71 typedef enum {
73 #ifdef YOTTA_CFG_HARDWARE_I2C_I2C1
75 #endif
76 #ifdef YOTTA_CFG_HARDWARE_I2C_I2C2
78 #endif
79 #ifdef YOTTA_CFG_HARDWARE_I2C_I2C3
81 #endif
82 } KI2CNum;
83 
87 typedef enum {
91 
96 typedef enum {
97  K_MASTER = 0,
99 } I2CRole;
100 
104 typedef struct {
119  uint32_t clock_speed;
120 } KI2CConf;
121 
125 typedef struct {
128  csp_mutex_t i2c_lock;
129 } KI2C;
130 
134 typedef enum {
135  I2C_OK = 0,
145 } KI2CStatus;
146 
152 void k_i2c_init(KI2CNum i2c, KI2CConf *conf);
153 
158 void k_i2c_terminate(KI2CNum i2c);
159 
165 
169 void k_i2c_default_init();
170 
176 
190 KI2CStatus k_i2c_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
191 
205 KI2CStatus k_i2c_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
206 
213 
221 
229 
239 KI2CStatus kprv_i2c_master_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
240 
250 KI2CStatus kprv_i2c_master_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
251 
262 KI2CStatus kprv_i2c_slave_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
263 
274 KI2CStatus kprv_i2c_slave_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
275 
276 #endif
277 #endif
278 /* @} */
i2c bus data structure
Definition: i2c.h:125
Definition: i2c.h:135
KI2CStatus kprv_i2c_dev_init(KI2CNum i2c)
Low level hal device initialization This is implemented by the device specific hal.
Definition: i2c.h:77
KI2CStatus kprv_i2c_slave_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Low level hal i2c read (as slave) This is implemented by the device specific hal. ...
Definition: i2c.h:140
Definition: i2c.h:89
Definition: i2c.h:72
uint32_t clock_speed
The clock speed of the i2c bus.
Definition: i2c.h:119
Definition: i2c.h:136
Definition: i2c.h:97
I2CRole role
The role of the i2c bus.
Definition: i2c.h:115
Definition: i2c.h:143
I2CAddressingMode
Expected addressing mode of i2c bus.
Definition: i2c.h:87
KI2CStatus kprv_i2c_slave_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Low level hal i2c write (as slave) This is implemented by the device specific hal.
KI2CStatus kprv_i2c_dev_terminate(KI2CNum i2c)
Low level hal i2c termination This is implemented by the device specific hal.
KI2CStatus k_i2c_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Transmit data over i2c bus to specified address.
Definition: i2c.h:144
I2CAddressingMode addressing_mode
The size of the slave address.
Definition: i2c.h:109
Definition: i2c.h:141
void k_i2c_default_dev_init(KI2CNum i2c)
Initialize i2c device with default config values.
csp_mutex_t i2c_lock
Definition: i2c.h:128
KI2CStatus kprv_i2c_master_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Low level hal i2c write (as master) This is implemented by the device specific hal.
KI2CConf conf
Definition: i2c.h:127
Definition: i2c.h:80
void k_i2c_init(KI2CNum i2c, KI2CConf *conf)
Setup and enable i2c bus.
Definition: i2c.h:142
Definition: i2c.h:88
KI2CStatus k_i2c_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Read data over i2c bus from specified address.
KI2CStatus
i2c function status
Definition: i2c.h:134
void k_i2c_terminate(KI2CNum i2c)
Terminate i2c bus.
KI2CConf k_i2c_conf_defaults(void)
Generate KI2CConf with default I2C values.
KI2CNum bus_num
Definition: i2c.h:126
KI2CStatus kprv_i2c_master_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Low level hal i2c read (as master) This is implemented by the device specific hal.
Definition: i2c.h:137
I2CRole
Expected role of i2c bus.
Definition: i2c.h:96
Definition: i2c.h:98
i2c configuration structure
Definition: i2c.h:104
Definition: i2c.h:139
KI2C * kprv_i2c_get(KI2CNum i2c)
Fetches i2c bus data structure.
KI2CNum
Available i2c buses.
Definition: i2c.h:71
void k_i2c_default_init()
Init DEFAULT_I2C bus with default config values.
Definition: i2c.h:74
Definition: i2c.h:138