XCORE SDK
XCORE Software Development Kit
rtos_i2c_master.h
1 // Copyright 2020-2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 
4 #ifndef RTOS_I2C_MASTER_H_
5 #define RTOS_I2C_MASTER_H_
6 
14 #include "i2c.h"
15 
16 #include "rtos_osal.h"
17 #include "rtos_driver_rpc.h"
18 
23 
30  rtos_driver_rpc_t *rpc_config;
31 
32  __attribute__((fptrgroup("rtos_i2c_master_write_fptr_grp")))
33  i2c_res_t (*write)(rtos_i2c_master_t *, uint8_t, uint8_t buf[], size_t, size_t *, int);
34 
35  __attribute__((fptrgroup("rtos_i2c_master_read_fptr_grp")))
36  i2c_res_t (*read)(rtos_i2c_master_t *, uint8_t, uint8_t buf[], size_t, int);
37 
38  __attribute__((fptrgroup("rtos_i2c_master_stop_bit_send_fptr_grp")))
39  void (*stop_bit_send)(rtos_i2c_master_t *);
40 
41  __attribute__((fptrgroup("rtos_i2c_master_reg_write_fptr_grp")))
42  i2c_regop_res_t (*reg_write)(rtos_i2c_master_t *, uint8_t, uint8_t, uint8_t);
43 
44  __attribute__((fptrgroup("rtos_i2c_master_reg_read_fptr_grp")))
45  i2c_regop_res_t (*reg_read)(rtos_i2c_master_t *, uint8_t, uint8_t, uint8_t *);
46 
47  i2c_master_t ctx;
48 
49  rtos_osal_mutex_t lock;
50 };
51 
52 #include "rtos_i2c_master_rpc.h"
53 
86  rtos_i2c_master_t *ctx,
87  uint8_t device_addr,
88  uint8_t buf[],
89  size_t n,
90  size_t *num_bytes_sent,
91  int send_stop_bit)
92 {
93  return ctx->write(ctx, device_addr, buf, n, num_bytes_sent, send_stop_bit);
94 }
95 
114  rtos_i2c_master_t *ctx,
115  uint8_t device_addr,
116  uint8_t buf[],
117  size_t n,
118  int send_stop_bit)
119 {
120  return ctx->read(ctx, device_addr, buf, n, send_stop_bit);
121 }
122 
123 
135  rtos_i2c_master_t *ctx)
136 {
137  ctx->stop_bit_send(ctx);
138 }
139 
158  rtos_i2c_master_t *ctx,
159  uint8_t device_addr,
160  uint8_t reg_addr,
161  uint8_t data)
162 {
163  return ctx->reg_write(ctx, device_addr, reg_addr, data);
164 }
165 
186  rtos_i2c_master_t *ctx,
187  uint8_t device_addr,
188  uint8_t reg_addr,
189  uint8_t *data)
190 {
191  return ctx->reg_read(ctx, device_addr, reg_addr, data);
192 }
193 
207  rtos_i2c_master_t *i2c_master_ctx);
208 
232  rtos_i2c_master_t *i2c_master_ctx,
233  const port_t p_scl,
234  const uint32_t scl_bit_position,
235  const uint32_t scl_other_bits_mask,
236  const port_t p_sda,
237  const uint32_t sda_bit_position,
238  const uint32_t sda_other_bits_mask,
239  hwtimer_t tmr,
240  const unsigned kbits_per_second);
241 
244 #endif /* RTOS_I2C_MASTER_H_ */
i2c_res_t
Definition: i2c.h:21
i2c_regop_res_t
Definition: i2c_reg.h:20
i2c_regop_res_t rtos_i2c_master_reg_read(rtos_i2c_master_t *ctx, uint8_t device_addr, uint8_t reg_addr, uint8_t *data)
Definition: rtos_i2c_master.h:185
void rtos_i2c_master_stop_bit_send(rtos_i2c_master_t *ctx)
Definition: rtos_i2c_master.h:134
i2c_regop_res_t rtos_i2c_master_reg_write(rtos_i2c_master_t *ctx, uint8_t device_addr, uint8_t reg_addr, uint8_t data)
Definition: rtos_i2c_master.h:157
i2c_res_t rtos_i2c_master_read(rtos_i2c_master_t *ctx, uint8_t device_addr, uint8_t buf[], size_t n, int send_stop_bit)
Definition: rtos_i2c_master.h:113
i2c_res_t rtos_i2c_master_write(rtos_i2c_master_t *ctx, uint8_t device_addr, uint8_t buf[], size_t n, size_t *num_bytes_sent, int send_stop_bit)
Definition: rtos_i2c_master.h:85
void rtos_i2c_master_init(rtos_i2c_master_t *i2c_master_ctx, const port_t p_scl, const uint32_t scl_bit_position, const uint32_t scl_other_bits_mask, const port_t p_sda, const uint32_t sda_bit_position, const uint32_t sda_other_bits_mask, hwtimer_t tmr, const unsigned kbits_per_second)
Definition: rtos_i2c_master.c:149
void rtos_i2c_master_start(rtos_i2c_master_t *i2c_master_ctx)
Definition: rtos_i2c_master.c:139
Definition: i2c.h:38
Definition: rtos_driver_rpc.h:23
Definition: rtos_i2c_master.h:29