gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
i2cd.h
1
2/*
3 * MIT License
4 *
5 * Copyright (c) 2026 Joey Castillo
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#pragma once
27
28#include <stdint.h>
29#include <stdbool.h>
30#include <stddef.h>
31
51typedef void (*i2c_device_address_cb_t)(uint8_t sercom, bool direction);
52
56typedef void (*i2c_device_data_received_cb_t)(uint8_t sercom, uint8_t data);
57
61typedef uint8_t (*i2c_device_data_requested_cb_t)(uint8_t sercom);
62
65typedef void (*i2c_device_stop_cb_t)(uint8_t sercom);
66
69typedef void (*i2c_device_error_cb_t)(uint8_t sercom);
70
71#if defined(I2C_SERCOM)
72
78void i2c_device_init(uint8_t address);
79
83void i2c_device_enable(void);
84
89bool i2c_device_is_enabled(void);
90
99void i2c_device_set_callbacks(
100 i2c_device_address_cb_t on_address_match,
101 i2c_device_data_received_cb_t on_data_received,
102 i2c_device_data_requested_cb_t on_data_requested,
103 i2c_device_stop_cb_t on_stop,
104 i2c_device_error_cb_t on_error);
105
109void i2c_device_disable(void);
110
111#endif
112
119void i2c_device_init_instance(uint8_t sercom, uint8_t address);
120
125void i2c_device_enable_instance(uint8_t sercom);
126
132bool i2c_device_is_enabled_instance(uint8_t sercom);
133
144 uint8_t sercom,
145 i2c_device_address_cb_t on_address_match,
146 i2c_device_data_received_cb_t on_data_received,
147 i2c_device_data_requested_cb_t on_data_requested,
148 i2c_device_stop_cb_t on_stop,
149 i2c_device_error_cb_t on_error);
150
155void i2c_device_disable_instance(uint8_t sercom);
156
163void i2c_device_irq_handler(uint8_t sercom);
164
bool i2c_device_is_enabled_instance(uint8_t sercom)
Checks if I2C device mode is enabled on the given SERCOM.
Definition i2cd.c:110
void(* i2c_device_stop_cb_t)(uint8_t sercom)
Called when the controller sends a stop condition, ending the transaction.
Definition i2cd.h:65
uint8_t(* i2c_device_data_requested_cb_t)(uint8_t sercom)
Called when the controller wants to read a byte from this device.
Definition i2cd.h:61
void i2c_device_set_callbacks_instance(uint8_t sercom, i2c_device_address_cb_t on_address_match, i2c_device_data_received_cb_t on_data_received, i2c_device_data_requested_cb_t on_data_requested, i2c_device_stop_cb_t on_stop, i2c_device_error_cb_t on_error)
Sets callbacks for I2C device mode events on the given SERCOM.
Definition i2cd.c:114
void(* i2c_device_error_cb_t)(uint8_t sercom)
Called when a bus error occurs.
Definition i2cd.h:69
void(* i2c_device_address_cb_t)(uint8_t sercom, bool direction)
Called when a controller addresses this device.
Definition i2cd.h:51
void i2c_device_enable_instance(uint8_t sercom)
Enables I2C device mode on the given SERCOM.
Definition i2cd.c:106
void(* i2c_device_data_received_cb_t)(uint8_t sercom, uint8_t data)
Called when the controller has written a byte to this device.
Definition i2cd.h:56
void i2c_device_disable_instance(uint8_t sercom)
Disables I2C device mode on the given SERCOM.
Definition i2cd.c:129
void i2c_device_irq_handler(uint8_t sercom)
I2C device mode IRQ handler.
Definition i2cd.c:136
void i2c_device_init_instance(uint8_t sercom, uint8_t address)
Initializes I2C device mode on the given SERCOM.
Definition i2cd.c:68