Midnight Sun Firmware
Loading...
Searching...
No Matches
i2c.h
1#pragma once
2
3/************************************************************************************************
4 * @file i2c.h
5 *
6 * @brief I2C Library Header file
7 *
8 * @date 2024-11-02
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stddef.h>
14#include <stdint.h>
15
16/* Inter-component Headers */
17
18/* Intra-component Headers */
19#include "gpio.h"
20#include "status.h"
21
29#define I2C_TIMEOUT_MS 100U
31#define I2C_MAX_NUM_DATA 32U
32
34typedef uint8_t I2CAddress;
35
37typedef enum {
41} I2CPort;
42
44typedef enum {
48} I2CSpeed;
49
55typedef struct {
60
70StatusCode i2c_init(I2CPort i2c, const I2CSettings *settings);
71
83StatusCode i2c_read(I2CPort i2c, I2CAddress addr, uint8_t *rx_data, size_t rx_len);
84
96StatusCode i2c_write(I2CPort i2c, I2CAddress addr, uint8_t *tx_data, size_t tx_len);
97
110StatusCode i2c_read_reg(I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *rx_data, size_t rx_len);
111
124StatusCode i2c_write_reg(I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *tx_data, size_t tx_len);
125
126#ifdef MS_PLATFORM_X86
127
136StatusCode i2c_set_rx_data(I2CPort i2c, uint8_t *data, size_t len);
137
146StatusCode i2c_get_tx_data(I2CPort i2c, uint8_t *data, size_t len);
147
148#endif
149
StatusCode i2c_write_reg(I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *tx_data, size_t tx_len)
Writes data using the I2C port to the specified address and register.
Definition: i2c.c:276
uint8_t I2CAddress
I2C address type.
Definition: i2c.h:34
StatusCode i2c_read(I2CPort i2c, I2CAddress addr, uint8_t *rx_data, size_t rx_len)
Reads data using the I2C port from the specified address.
Definition: i2c.c:263
StatusCode i2c_init(I2CPort i2c, const I2CSettings *settings)
Initialize I2C instance.
Definition: i2c.c:194
I2CPort
I2C Port selection.
Definition: i2c.h:37
I2CSpeed
I2C speed type.
Definition: i2c.h:44
StatusCode i2c_read_reg(I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *rx_data, size_t rx_len)
Reads data using the I2C port from the specified address and register.
Definition: i2c.c:271
StatusCode i2c_write(I2CPort i2c, I2CAddress addr, uint8_t *tx_data, size_t tx_len)
Writes data using the I2C port to the specified address.
Definition: i2c.c:267
@ I2C_PORT_1
Definition: i2c.h:38
@ I2C_PORT_2
Definition: i2c.h:39
@ NUM_I2C_PORTS
Definition: i2c.h:40
@ NUM_I2C_SPEEDS
Definition: i2c.h:47
@ I2C_SPEED_STANDARD
Definition: i2c.h:45
@ I2C_SPEED_FAST
Definition: i2c.h:46
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Port and pin data.
Definition: gpio.h:112
I2C settings struct.
Definition: i2c.h:55
GpioAddress scl
Definition: i2c.h:58
I2CSpeed speed
Definition: i2c.h:56
GpioAddress sda
Definition: i2c.h:57