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
48typedef void (*i2c_device_address_cb_t)(uint8_t sercom, bool direction);
49
53typedef void (*i2c_device_data_received_cb_t)(uint8_t sercom, uint8_t data);
54
58typedef uint8_t (*i2c_device_data_requested_cb_t)(uint8_t sercom);
59
62typedef void (*i2c_device_stop_cb_t)(uint8_t sercom);
63
66typedef void (*i2c_device_error_cb_t)(uint8_t sercom);
67
68#if defined(I2C_SERCOM)
69
75void i2c_device_init(uint8_t address);
76
80void i2c_device_enable(void);
81
86bool i2c_device_is_enabled(void);
87
96void i2c_device_set_callbacks(
97 i2c_device_address_cb_t on_address_match,
98 i2c_device_data_received_cb_t on_data_received,
99 i2c_device_data_requested_cb_t on_data_requested,
100 i2c_device_stop_cb_t on_stop,
101 i2c_device_error_cb_t on_error);
102
106void i2c_device_disable(void);
107
108#endif
109
116void i2c_device_init_instance(uint8_t sercom, uint8_t address);
117
122void i2c_device_enable_instance(uint8_t sercom);
123
129bool i2c_device_is_enabled_instance(uint8_t sercom);
130
141 uint8_t sercom,
142 i2c_device_address_cb_t on_address_match,
143 i2c_device_data_received_cb_t on_data_received,
144 i2c_device_data_requested_cb_t on_data_requested,
145 i2c_device_stop_cb_t on_stop,
146 i2c_device_error_cb_t on_error);
147
152void i2c_device_disable_instance(uint8_t sercom);
153
160void i2c_device_irq_handler(uint8_t sercom);
161
bool i2c_device_is_enabled_instance(uint8_t sercom)
Checks if I2C device mode is enabled on the given SERCOM.
Definition i2cd.c:108
void(* i2c_device_stop_cb_t)(uint8_t sercom)
Called when the controller sends a stop condition, ending the transaction.
Definition i2cd.h:62
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:58
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:112
void(* i2c_device_error_cb_t)(uint8_t sercom)
Called when a bus error occurs.
Definition i2cd.h:66
void(* i2c_device_address_cb_t)(uint8_t sercom, bool direction)
Called when a controller addresses this device.
Definition i2cd.h:48
void i2c_device_enable_instance(uint8_t sercom)
Enables I2C device mode on the given SERCOM.
Definition i2cd.c:104
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:53
void i2c_device_disable_instance(uint8_t sercom)
Disables I2C device mode on the given SERCOM.
Definition i2cd.c:127
void i2c_device_irq_handler(uint8_t sercom)
I2C device mode IRQ handler.
Definition i2cd.c:132
void i2c_device_init_instance(uint8_t sercom, uint8_t address)
Initializes I2C device mode on the given SERCOM.
Definition i2cd.c:68