gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
i2c.h
1
2/*
3 Cribbed from the Castor & Pollux Gemini firmware:
4 https://github.com/wntrblm/Castor_and_Pollux/
5 Copyright (c) 2021 Alethea Katherine Flowers.
6 Published under the standard MIT License.
7 Full text available at: https://opensource.org/licenses/MIT
8*/
9
10#pragma once
11
12/* Routines for interacting with I2C devices. */
13
14#include <stdint.h>
15#include <stdbool.h>
16#include <stddef.h>
17
24typedef enum {
25 I2C_RESULT_SUCCESS = 0,
26 I2C_RESULT_ERR_ADDR_NACK = -1,
27 I2C_RESULT_ERR_BUSSTATE = -2,
28 I2C_RESULT_ERR_BUSERR = -3,
29 I2C_RESULT_ERR_DATA_NACK = -4,
30} i2c_result_t;
31
39void i2c_init(void);
40
44void i2c_enable(void);
45
52i2c_result_t i2c_write(uint8_t address, uint8_t* data, size_t len);
53
60i2c_result_t i2c_read(uint8_t address, uint8_t* data, size_t len);
61
65void i2c_disable(void);
66
75void i2c_init_instance(uint8_t sercom, uint32_t baud);
76
81void i2c_enable_instance(uint8_t sercom);
82
90i2c_result_t i2c_write_instance(uint8_t sercom, uint8_t address, uint8_t* data, size_t len);
91
99i2c_result_t i2c_read_instance(uint8_t sercom, uint8_t address, uint8_t* data, size_t len);
100
105void i2c_disable_instance(uint8_t sercom);
106
i2c_result_t i2c_write_instance(uint8_t sercom, uint8_t address, uint8_t *data, size_t len)
Writes data to an I2C device on the given SERCOM at the provided address.
Definition i2c.c:91
void i2c_init(void)
Initializes the I2C peripheral for a board with a defined I2C_SERCOM.
void i2c_enable(void)
Enables the I2C peripheral for a board with a defined I2C_SERCOM.
i2c_result_t i2c_write(uint8_t address, uint8_t *data, size_t len)
Writes data to an I2C device at the provided address.
i2c_result_t i2c_read_instance(uint8_t sercom, uint8_t address, uint8_t *data, size_t len)
Reads data from an I2C device on the given SERCOM at the provided address.
Definition i2c.c:144
void i2c_enable_instance(uint8_t sercom)
Enables the I2C peripheral on the given SERCOM.
Definition i2c.c:83
void i2c_disable_instance(uint8_t sercom)
Disables the I2C peripheral on the given SERCOM.
Definition i2c.c:190
void i2c_disable(void)
Disables the I2C peripheral for a board with defined SDA/SCL pins.
void i2c_init_instance(uint8_t sercom, uint32_t baud)
Initializes an I2C peripheral on the given SERCOM.
Definition i2c.c:44
i2c_result_t i2c_read(uint8_t address, uint8_t *data, size_t len)
Reads data from an I2C device at the provided address.