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 "FreeRTOS.h"
33 #include "semphr.h"
34 
47 #ifndef K_NUM_I2CS
48 #define K_NUM_I2CS YOTTA_CFG_HARDWARE_I2C_COUNT
49 #endif
50 
65 #ifndef DEFAULT_I2C
66 #define DEFAULT_I2C YOTTA_CFG_HARDWARE_I2C_DEFAULTS_BUS
67 #endif
68 
72 typedef enum {
73 #ifdef YOTTA_CFG_HARDWARE_I2C_I2C1
74  K_I2C1 = 0,
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 {
107  uint32_t clock_speed;
108 } KI2CConf;
109 
113 typedef struct {
116  SemaphoreHandle_t i2c_lock;
117 } KI2C;
118 
122 typedef enum {
123  I2C_OK = 0,
132 } KI2CStatus;
133 
139 void k_i2c_init(KI2CNum i2c, KI2CConf *conf);
140 
145 void k_i2c_terminate(KI2CNum i2c);
146 
152 
156 void k_i2c_default_init();
157 
163 
177 KI2CStatus k_i2c_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
178 
192 KI2CStatus k_i2c_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
193 
200 
206 void kprv_i2c_dev_init(KI2CNum i2c);
207 
214 
224 KI2CStatus kprv_i2c_master_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
225 
235 KI2CStatus kprv_i2c_master_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
236 
247 KI2CStatus kprv_i2c_slave_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
248 
259 KI2CStatus kprv_i2c_slave_read(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len);
260 
261 #endif
262 #endif
263 /* @} */
i2c bus data structure
Definition: i2c.h:113
Definition: i2c.h:123
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:128
Definition: i2c.h:89
uint32_t clock_speed
Definition: i2c.h:107
void kprv_i2c_dev_init(KI2CNum i2c)
Low level hal device initialization This is implemented by the device specific hal.
Definition: i2c.h:124
Definition: i2c.h:97
I2CRole role
Definition: i2c.h:106
Definition: i2c.h:131
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 k_i2c_write(KI2CNum i2c, uint16_t addr, uint8_t *ptr, int len)
Transmit data over i2c bus to specified address.
I2CAddressingMode addressing_mode
Definition: i2c.h:105
Definition: i2c.h:129
void k_i2c_default_dev_init(KI2CNum i2c)
Initialize i2c device with default config values.
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:115
Definition: i2c.h:80
void k_i2c_init(KI2CNum i2c, KI2CConf *conf)
Setup and enable i2c bus.
Definition: i2c.h:130
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:122
SemaphoreHandle_t i2c_lock
Definition: i2c.h:116
void kprv_i2c_dev_terminate(KI2CNum i2c)
Low level hal i2c termination This is implemented by the device specific hal.
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:114
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:125
I2CRole
Expected role of i2c bus.
Definition: i2c.h:96
Definition: i2c.h:98
i2c configuration structure
Definition: i2c.h:104
Definition: i2c.h:127
KI2C * kprv_i2c_get(KI2CNum i2c)
Fetches i2c bus data structure.
KI2CNum
Available i2c buses.
Definition: i2c.h:72
void k_i2c_default_init()
Init DEFAULT_I2C bus with default config values.
Definition: i2c.h:74
Definition: i2c.h:126