Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
softi2c.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
30
31#include "mcu_periph/softi2c.h"
32
33#include "mcu_arch.h"
34#include "mcu_periph/gpio.h"
35#include "mcu_periph/sys_time.h"
36
37#if PERIODIC_TELEMETRY
39#endif
40
41#include <stdbool.h>
42
43
44#ifndef SOFTI2C0_DIVIDER
45#define SOFTI2C0_DIVIDER 1
46#endif
47#ifndef SOFTI2C1_DIVIDER
48#define SOFTI2C1_DIVIDER 1
49#endif
50
51
58 /* Bit-level state machine */
60 /* Byte-level state machine */
62 /* Transaction-level state machine */
63 // periph->status
64 // periph->idx_buf
65};
66
67
68static bool softi2c_idle(struct i2c_periph *periph) __attribute__((unused));
69static bool softi2c_submit(struct i2c_periph *periph, struct i2c_transaction *t) __attribute__((unused));
70static void softi2c_setbitrate(struct i2c_periph *periph, int bitrate) __attribute__((unused));
71static void softi2c_spin(struct i2c_periph *p) __attribute__((unused));
72
73
74#if USE_SOFTI2C0 && ( \
75 !defined(SOFTI2C0_SDA_GPIO) || !defined(SOFTI2C0_SDA_PIN) || \
76 !defined(SOFTI2C0_SCL_GPIO) || !defined(SOFTI2C0_SCL_PIN))
77#error "SDA and SCL pins must be configured for SOFTI2C0!"
78#endif
79
80#if USE_SOFTI2C1 && ( \
81 !defined(SOFTI2C1_SDA_GPIO) || !defined(SOFTI2C1_SDA_PIN) || \
82 !defined(SOFTI2C1_SCL_GPIO) || !defined(SOFTI2C1_SCL_PIN))
83#error "SDA and SCL pins must be configured for SOFTI2C1!"
84#endif
85
86
87#if USE_SOFTI2C0
88struct i2c_periph softi2c0;
89static struct softi2c_device softi2c0_device;
90void softi2c0_init(void) {
91 i2c_init(&softi2c0);
92 softi2c0_hw_init();
93}
94#if PERIODIC_TELEMETRY
95void send_softi2c0_err(struct transport_tx *trans, struct link_device *dev)
96{
97 uint16_t i2c0_wd_reset_cnt = softi2c0.errors->wd_reset_cnt;
98 uint16_t i2c0_queue_full_cnt = softi2c0.errors->queue_full_cnt;
99 uint16_t i2c0_ack_fail_cnt = softi2c0.errors->ack_fail_cnt;
100 uint16_t i2c0_miss_start_stop_cnt = softi2c0.errors->miss_start_stop_cnt;
101 uint16_t i2c0_arb_lost_cnt = softi2c0.errors->arb_lost_cnt;
102 uint16_t i2c0_over_under_cnt = softi2c0.errors->over_under_cnt;
103 uint16_t i2c0_pec_recep_cnt = softi2c0.errors->pec_recep_cnt;
104 uint16_t i2c0_timeout_tlow_cnt = softi2c0.errors->timeout_tlow_cnt;
105 uint16_t i2c0_smbus_alert_cnt = softi2c0.errors->smbus_alert_cnt;
106 uint16_t i2c0_unexpected_event_cnt = softi2c0.errors->unexpected_event_cnt;
107 uint32_t i2c0_last_unexpected_event = softi2c0.errors->last_unexpected_event;
108 uint8_t _bus0 = 10;
109 pprz_msg_send_I2C_ERRORS(trans, dev, AC_ID,
110 &i2c0_wd_reset_cnt,
111 &i2c0_queue_full_cnt,
112 &i2c0_ack_fail_cnt,
113 &i2c0_miss_start_stop_cnt,
114 &i2c0_arb_lost_cnt,
115 &i2c0_over_under_cnt,
116 &i2c0_pec_recep_cnt,
117 &i2c0_timeout_tlow_cnt,
118 &i2c0_smbus_alert_cnt,
119 &i2c0_unexpected_event_cnt,
120 &i2c0_last_unexpected_event,
121 &_bus0);
122}
123#endif
124#endif /* USE_SOFTI2C0 */
125
126#if USE_SOFTI2C1
127struct i2c_periph softi2c1;
128static struct softi2c_device softi2c1_device;
129void softi2c1_init(void) {
130 i2c_init(&softi2c1);
131 softi2c1_hw_init();
132}
133#if PERIODIC_TELEMETRY
134void send_softi2c1_err(struct transport_tx *trans, struct link_device *dev)
135{
136 uint16_t i2c1_wd_reset_cnt = softi2c1.errors->wd_reset_cnt;
137 uint16_t i2c1_queue_full_cnt = softi2c1.errors->queue_full_cnt;
138 uint16_t i2c1_ack_fail_cnt = softi2c1.errors->ack_fail_cnt;
139 uint16_t i2c1_miss_start_stop_cnt = softi2c1.errors->miss_start_stop_cnt;
140 uint16_t i2c1_arb_lost_cnt = softi2c1.errors->arb_lost_cnt;
141 uint16_t i2c1_over_under_cnt = softi2c1.errors->over_under_cnt;
142 uint16_t i2c1_pec_recep_cnt = softi2c1.errors->pec_recep_cnt;
143 uint16_t i2c1_timeout_tlow_cnt = softi2c1.errors->timeout_tlow_cnt;
144 uint16_t i2c1_smbus_alert_cnt = softi2c1.errors->smbus_alert_cnt;
145 uint16_t i2c1_unexpected_event_cnt = softi2c1.errors->unexpected_event_cnt;
146 uint32_t i2c1_last_unexpected_event = softi2c1.errors->last_unexpected_event;
147 uint8_t _bus1 = 11;
148 pprz_msg_send_I2C_ERRORS(trans, dev, AC_ID,
149 &i2c1_wd_reset_cnt,
150 &i2c1_queue_full_cnt,
151 &i2c1_ack_fail_cnt,
152 &i2c1_miss_start_stop_cnt,
153 &i2c1_arb_lost_cnt,
154 &i2c1_over_under_cnt,
155 &i2c1_pec_recep_cnt,
156 &i2c1_timeout_tlow_cnt,
157 &i2c1_smbus_alert_cnt,
158 &i2c1_unexpected_event_cnt,
159 &i2c1_last_unexpected_event,
160 &_bus1);
161}
162#endif
163#endif /* USE_SOFTI2C1 */
164
165
167#if defined(CHIBIOS_MCU_ARCH_H)
168 /* Arch's with input_pullup */
169 gpio_setup_input_pullup(port, pin);
170#else
171 /* Arch's without input_pullup */
172 // Gpio_set might enable pullup on some architectures (e.g. arduino), not sure
173 // if it works here. If not, an external pull-up resistor is required on the
174 // I2C lines.
175 gpio_setup_input(port, pin);
176 gpio_set(port, pin);
177#endif /* arch with/without input_pullup */
178}
179
180static bool softi2c_gpio_read(gpio_port_t port, uint16_t pin) {
181 softi2c_gpio_highz(port, pin);
182 return gpio_get(port, pin);
183}
184
186 gpio_setup_output(port, pin);
187 gpio_clear(port, pin);
188}
189
190static void softi2c_setup_gpio(
192 gpio_port_t scl_port, uint16_t scl_pin) __attribute__((unused));
193
200
201
202#if USE_SOFTI2C0
203struct i2c_errors softi2c0_errors;
204
205void softi2c0_hw_init(void) {
206 softi2c0.idle = softi2c_idle;
207 softi2c0.submit = softi2c_submit;
208 softi2c0.setbitrate = softi2c_setbitrate;
209 softi2c0.spin = softi2c_spin;
210 softi2c0.reg_addr = (void *) &softi2c0_device;
211 softi2c0.errors = &softi2c0_errors;
212 ZEROS_ERR_COUNTER(softi2c0_errors);
213
214 softi2c0_device.periph = &softi2c0;
215 softi2c0_device.sda_port = SOFTI2C0_SDA_GPIO;
216 softi2c0_device.sda_pin = SOFTI2C0_SDA_PIN;
217 softi2c0_device.scl_port = SOFTI2C0_SCL_GPIO;
218 softi2c0_device.scl_pin = SOFTI2C0_SCL_PIN;
219
220 /* Set up GPIO */
222 SOFTI2C0_SDA_GPIO, SOFTI2C0_SDA_PIN,
223 SOFTI2C0_SCL_GPIO, SOFTI2C0_SCL_PIN);
224}
225#endif /* USE_SOFTI2C0 */
226
227#if USE_SOFTI2C1
228struct i2c_errors softi2c1_errors;
229
230void softi2c1_hw_init(void) {
231 softi2c1.idle = softi2c_idle;
232 softi2c1.submit = softi2c_submit;
233 softi2c1.setbitrate = softi2c_setbitrate;
234 softi2c1.spin = softi2c_spin;
235 softi2c1.reg_addr = (void *) &softi2c1_device;
236 softi2c1.errors = &softi2c1_errors;
237 ZEROS_ERR_COUNTER(softi2c1_errors);
238
239 softi2c1_device.periph = &softi2c1;
240 softi2c1_device.sda_port = SOFTI2C1_SDA_GPIO;
241 softi2c1_device.sda_pin = SOFTI2C1_SDA_PIN;
242 softi2c1_device.scl_port = SOFTI2C1_SCL_GPIO;
243 softi2c1_device.scl_pin = SOFTI2C1_SCL_PIN;
244
245 /* Set up GPIO */
247 SOFTI2C1_SDA_GPIO, SOFTI2C1_SDA_PIN,
248 SOFTI2C1_SCL_GPIO, SOFTI2C1_SCL_PIN);
249}
250#endif /* USE_SOFTI2C1 */
251
252
253/*
254 * I2C implementation
255 */
256// Some notes about timing:
257// The I2C standard lists timing requirements in the order of microseconds. This
258// is difficult to explicitly implement for two reasons:
259// - The event loop spins at a ~20 us period.
260// - The sys time clock has a resolution of ~200 us. (Can be set higher, but
261// can cause lockups when set to ~2us or lower.)
262// This module handles timing by returning to the event loop at every pause.
263// The event loop runs slow enough to satisfy all I2C standard mode minimum
264// timings. Because the event loop takes longer than the minimum timing, the
265// maximum bitrate is reduced. However, *software*-i2c should not be used for
266// high-bitrate applications anyway.
267// (Experimental code where usleep was used for in-bit timing had only little
268// performance benefit (~20kHz vs ~15kHz). Because sleeping in the event loop
269// can have other negative consequences, this option was removed.)
270// Pauses *between* bits also use the time between event calls as a delay. As a
271// result, the bitrate is an integer fraction of the event rate and cannot be
272// set exactly. The bitrate can be coarsely adjusted per softi2c device by
273// setting SOFTI2CX_DIVIDER.
274
275
276// Bit read/write functions
277// Should be called continuously from event function.
278// Return true upon completion.
279// The bit functions start by setting SCL low and end at the last transition
280// before SCL is set low again. The time between event calls is used to space
281// this last transition and the new SCL low edge, thereby setting the bus
282// frequency.
283
284static bool softi2c_write_start(struct softi2c_device *d) {
286 return true; // > T_HD_STA_MIN
287}
288
289// Note: write_bit may also be used to write the ACK bit (T_VD_ACK == T_VD_DAT)
290static bool softi2c_write_bit(struct softi2c_device *d, bool bit) {
291 switch (d->bit_state) {
292 case 0:
293 // Start of bit
295 d->bit_state++;
296 return false;
297 case 1:
298 // After SCL fall time and data hold time
299 if (bit) {
301 } else {
303 }
304 d->bit_state++;
305 return false;
306 case 2:
307 // After SDA rise(/fall) and data set-up time
309 d->bit_state++;
310 /* Falls through. */
311 case 3:
312 if (!gpio_get(d->scl_port, d->scl_pin)) return false;
313 // After SCL rise time and confirmed high (clock stretching)
314 d->bit_state = 0;
315 return true; // > T_HIGH_MIN
316 default: return false;
317 }
318}
319
320// Note: read_bit may also be used to read the ACK bit (T_VD_ACK == T_VD_DAT)
321static bool softi2c_read_bit(struct softi2c_device *d, bool *bit) {
322 switch (d->bit_state) {
323 case 0:
324 // Start of bit
326 d->bit_state++;
327 return false;
328 case 1:
329 // After SCL fall time and data hold time
330 softi2c_gpio_highz(d->sda_port, d->sda_pin); // SDA may be driven low by slave.
331 // After SCL(!) fall time and minimum low time (== T_HD_DAT_MIN)
333 d->bit_state++;
334 /* Falls through. */
335 case 2:
336 if (!gpio_get(d->scl_port, d->scl_pin)) return false;
337 // After SCL rise time and confirmed high (clock stretching)
338 *bit = softi2c_gpio_read(d->sda_port, d->sda_pin);
339 d->bit_state = 0;
340 return true; // > T_HIGH_MIN
341 default: return false;
342 }
343}
344
345static bool softi2c_write_restart(struct softi2c_device *d) {
346 switch (d->bit_state) {
347 case 0:
348 // Start of bit
350 d->bit_state++;
351 return false;
352 case 1:
353 // After SCL fall time and data hold time
355 d->bit_state++;
356 return false;
357 case 2:
358 // After SDA rise time and data set-up time
360 d->bit_state++;
361 /* Falls through. */
362 case 3:
363 if (!gpio_get(d->scl_port, d->scl_pin)) return false;
364 // After SCL rise time and confirmed high (clock stretching)
365 d->bit_state++;
366 return false;
367 case 4:
368 // After restart set-up time
370 d->bit_state = 0;
371 return true; // > T_HD_STA_MIN
372 default: return false;
373 }
374}
375
376static bool softi2c_write_stop(struct softi2c_device *d) {
377 switch (d->bit_state) {
378 case 0:
379 // Start of bit
381 d->bit_state++;
382 return false;
383 case 1:
384 // After SCL fall time and data hold time
386 d->bit_state++;
387 return false;
388 case 2:
389 // After SDA fall time and data set-up time
391 d->bit_state++;
392 /* Falls through. */
393 case 3:
394 if (!gpio_get(d->scl_port, d->scl_pin)) return false;
395 // After SCL rise time and confirmed high (clock stretching)
396 d->bit_state++;
397 return false;
398 case 4:
399 // After stop set-up time
401 d->bit_state = 0;
402 return true; // > T_BUF_MIN
403 default: return false;
404 }
405}
406
407// Byte read/write functions
408// Should be called continuously from event function.
409// Return true upon completion.
410
411// write_byte:
412// starts with SCL <= low for first bit (start bit is not included!)
413// ends at SCL allowed low
414static bool softi2c_write_byte(struct softi2c_device *d, uint8_t byte, bool *ack) {
415 bool bit;
416 switch (d->byte_state) {
417 case 0:
418 case 1:
419 case 2:
420 case 3:
421 case 4:
422 case 5:
423 case 6:
424 case 7:
425 // Write bit
426 bit = byte & (0x80 >> d->byte_state); // MSB first
427 if (!softi2c_write_bit(d, bit)) return false; // Write bit in progress
428 d->byte_state++;
429 return false;
430 case 8:
431 // Read ACK
432 if (!softi2c_read_bit(d, ack)) return false; // Read bit in progress
433 *ack = !*ack; // Inverted, low = acknowledge
434 d->byte_state = 0;
435 return true;
436 default: return false;
437 }
438}
439
440// read_byte:
441// starts with SCL <= low for first bit (start bit is not included!)
442// ends at SCL allowed low
443// Note: ack should be false when reading last byte (UM10204 3.1.10)
444static bool softi2c_read_byte(struct softi2c_device *d, uint8_t *byte, bool ack) {
445 bool bit;
446 switch (d->byte_state) {
447 case 0:
448 case 1:
449 case 2:
450 case 3:
451 case 4:
452 case 5:
453 case 6:
454 case 7:
455 // Read bit
456 if (!softi2c_read_bit(d, &bit)) return false; // Read bit in progress
457 if (bit) {
458 *byte |= (0x80 >> d->byte_state); // MSB first
459 } else {
460 *byte &= ~(0x80 >> d->byte_state); // MSB first
461 }
462 d->byte_state++;
463 return false;
464 case 8:
465 // Write ACK
466 // Note: inverted logic, low = acknowledge.
467 if (!softi2c_write_bit(d, !ack)) return false; // Write bit in progress
468 d->byte_state = 0;
469 return true;
470 default: return false;
471 }
472}
473
474// Transaction handling
475// Should be called continously from event function.
476// Returns true upon completion.
477#pragma GCC diagnostic push
478#pragma GCC diagnostic ignored "-Wcast-qual"
480 uint8_t byte;
481 bool ack;
482 switch (d->periph->status) {
483 case I2CIdle:
484 // Start of transaction
487 d->periph->idx_buf = 0;
488 return false;
489
491 // Send start bit
492 if (!softi2c_write_start(d)) return false;
493 // Start bit sent
494 if (t->type == I2CTransRx) {
496 } else {
498 }
499 return false;
500
501 case I2CAddrWrSent:
502 // Send write address
503 if (!softi2c_write_byte(d, t->slave_addr, &ack)) return false;
504 // Write address sent
505 if (!ack) {
507 d->periph->status = I2CFailed;
508 return false;
509 }
511 return false;
512
513 case I2CSendingByte:
514 // Check remaining bytes
515 if (d->periph->idx_buf >= t->len_w) {
516 d->periph->idx_buf = 0;
517 if (t->type == I2CTransTxRx) {
519 } else {
521 }
522 return false;
523 }
524 // Send byte
525 if (!softi2c_write_byte(d, t->buf[d->periph->idx_buf], &ack)) return false;
526 // Byte sent
527 if (!ack) {
529 d->periph->status = I2CFailed;
530 return true;
531 }
532 d->periph->idx_buf++;
533 return false;
534
536 // Send restart bit
537 if (!softi2c_write_restart(d)) return false;
538 // Restart bit sent
540 return false;
541
542 case I2CAddrRdSent:
543 // Send read address
544 byte = t->slave_addr | 0x01;
545 if (!softi2c_write_byte(d, byte, &ack)) return false;
546 // Read address sent
547 if (!ack) {
549 d->periph->status = I2CFailed;
550 return true;
551 }
553 return false;
554
555 case I2CReadingByte:
556 // Check remaining bytes
557 if (d->periph->idx_buf >= t->len_r - 1) {
559 return false;
560 }
561 // Read byte
562 if (!softi2c_read_byte(d, (uint8_t *) &(t->buf[d->periph->idx_buf]), true)) return false;
563 // Byte read
564 d->periph->idx_buf++;
565 return false;
566
568 // Check remaining bytes
569 if (d->periph->idx_buf >= t->len_r) {
570 d->periph->idx_buf = 0;
572 return false;
573 }
574 // Read last byte (no ACK!)
575 if (!softi2c_read_byte(d, (uint8_t *) &(t->buf[d->periph->idx_buf]), false)) return false;
576 // Byte read
577 d->periph->idx_buf++;
578 return false;
579
580 case I2CStopRequested:
581 // Send stop bit
582 if (!softi2c_write_stop(d)) return false;
583 // Stop bit sent
585 d->periph->status = I2CIdle;
586 return true;
587
588 default:
589 case I2CFailed:
590 // Something went wrong
591 // Send stop bit
592 if (!softi2c_write_stop(d)) return false;
593 // Stop bit sent
595 d->periph->status = I2CIdle;
596 return true;
597 }
598}
599#pragma GCC diagnostic pop
600
601// Per-device event function
602static void softi2c_device_event(struct softi2c_device *d) __attribute__((unused));
603
604static void softi2c_device_event(struct softi2c_device *d) {
605 struct i2c_periph *p = d->periph;
606 if (p->trans_insert_idx != p->trans_extract_idx) {
607 // Transaction(s) in queue
608 struct i2c_transaction *t = p->trans[p->trans_extract_idx];
609 if (softi2c_process_transaction(d, t)) {
610 // Transaction finished
611 p->trans_extract_idx = (p->trans_extract_idx + 1) % I2C_TRANSACTION_QUEUE_LEN;
612 }
613 }
614}
615
616
617/*
618 * Paparazzi functions
619 */
620void softi2c_event(void) {
621#if USE_SOFTI2C0
622 static int softi2c0_cnt = 1;
623 if (softi2c0_cnt == SOFTI2C0_DIVIDER) {
624 softi2c_device_event(&softi2c0_device);
625 softi2c0_cnt = 1;
626 } else {
627 softi2c0_cnt++;
628 }
629#endif
630#if USE_SOFTI2C1
631 static int softi2c1_cnt = 1;
632 if (softi2c1_cnt == SOFTI2C1_DIVIDER) {
633 softi2c_device_event(&softi2c1_device);
634 softi2c1_cnt = 1;
635 } else {
636 softi2c1_cnt++;
637 }
638#endif
639}
640
641static void softi2c_spin(struct i2c_periph *p) {
642 softi2c_device_event((struct softi2c_device *) p->reg_addr);
643// sys_time_usleep(5); // For I2C timing. // TvD 2020-08-18: Hangs? Interrupt issue when called from SPI?
644}
645
646static bool softi2c_idle(struct i2c_periph *p) {
647 return (p->status == I2CIdle) && (p->trans_insert_idx == p->trans_extract_idx);
648}
649
650static bool softi2c_submit(struct i2c_periph *p, struct i2c_transaction *t) {
651 uint8_t next_idx = (p->trans_insert_idx + 1) % I2C_TRANSACTION_QUEUE_LEN;
652 if (next_idx == p->trans_extract_idx) {
653 // queue full
654 p->errors->queue_full_cnt++;
656 return false;
657 }
659 /* put transaction in queue */
660 p->trans[p->trans_insert_idx] = t;
661 p->trans_insert_idx = next_idx;
662 return true;
663}
664
665static void softi2c_setbitrate(struct i2c_periph *p __attribute__((unused)), int bitrate __attribute__((unused))) {
666 /* Do nothing */
667}
void gpio_setup_input_pullup(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull up resistor enabled.
Definition gpio_arch.c:47
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition gpio_arch.c:33
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition gpio_arch.c:40
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
Definition gpio_arch.h:104
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
Definition gpio_arch.h:114
ioportid_t gpio_port_t
Abstract gpio port type for hardware independent part.
Definition gpio_arch.h:39
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
Definition gpio_arch.h:94
static struct uart_periph * dev
Some architecture independent helper functions for GPIOs.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:123
struct i2c_errors * errors
Definition i2c.h:164
uint16_t len_r
Number of bytes to read/receive.
Definition i2c.h:111
volatile uint16_t ack_fail_cnt
Definition i2c.h:173
enum I2CTransactionType type
Transaction type.
Definition i2c.h:99
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:127
volatile uint8_t idx_buf
Definition i2c.h:161
uint8_t slave_addr
Slave address.
Definition i2c.h:105
enum I2CStatus status
Definition i2c.h:160
uint8_t len_w
Number of bytes to write/transmit.
Definition i2c.h:117
#define ZEROS_ERR_COUNTER(_i2c_err)
Definition i2c.h:186
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
Definition i2c.h:138
void i2c_init(struct i2c_periph *p)
Initialize I2C peripheral.
Definition i2c.c:188
@ I2CStopRequested
Definition i2c.h:75
@ I2CAddrRdSent
Definition i2c.h:70
@ I2CFailed
Definition i2c.h:78
@ I2CAddrWrSent
Definition i2c.h:69
@ I2CIdle
Definition i2c.h:67
@ I2CStartRequested
Definition i2c.h:68
@ I2CReadingByte
Definition i2c.h:73
@ I2CSendingByte
Definition i2c.h:71
@ I2CReadingLastByte
Definition i2c.h:74
@ I2CRestartRequested
Definition i2c.h:76
@ I2CTransRunning
transaction is currently ongoing
Definition i2c.h:57
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:58
@ I2CTransFailed
transaction failed
Definition i2c.h:59
@ I2CTransPending
transaction is pending in queue
Definition i2c.h:56
@ I2CTransRx
receive only transaction
Definition i2c.h:49
@ I2CTransTxRx
transmit and receive transaction
Definition i2c.h:50
I2C errors counter.
Definition i2c.h:170
I2C transaction structure.
Definition i2c.h:94
static float p[2][2]
void softi2c_event(void)
Definition softi2c.c:620
#define SOFTI2C1_DIVIDER
Definition softi2c.c:48
static bool softi2c_write_restart(struct softi2c_device *d)
Definition softi2c.c:345
static void softi2c_device_event(struct softi2c_device *d)
Definition softi2c.c:604
#define SOFTI2C0_DIVIDER
Definition softi2c.c:45
static bool softi2c_submit(struct i2c_periph *periph, struct i2c_transaction *t)
Definition softi2c.c:650
static bool softi2c_idle(struct i2c_periph *periph)
Definition softi2c.c:646
uint8_t byte_state
Definition softi2c.c:61
gpio_port_t scl_port
Definition softi2c.c:56
static bool softi2c_read_bit(struct softi2c_device *d, bool *bit)
Definition softi2c.c:321
static void softi2c_setbitrate(struct i2c_periph *periph, int bitrate)
Definition softi2c.c:665
static void softi2c_gpio_drive_low(gpio_port_t port, uint16_t pin)
Definition softi2c.c:185
static void softi2c_gpio_highz(gpio_port_t port, uint16_t pin)
Definition softi2c.c:166
struct i2c_periph * periph
Definition softi2c.c:53
static bool softi2c_gpio_read(gpio_port_t port, uint16_t pin)
Definition softi2c.c:180
static bool softi2c_write_byte(struct softi2c_device *d, uint8_t byte, bool *ack)
Definition softi2c.c:414
static void softi2c_setup_gpio(gpio_port_t sda_port, uint16_t sda_pin, gpio_port_t scl_port, uint16_t scl_pin)
Definition softi2c.c:194
static bool softi2c_write_bit(struct softi2c_device *d, bool bit)
Definition softi2c.c:290
uint16_t scl_pin
Definition softi2c.c:57
uint8_t bit_state
Definition softi2c.c:59
uint16_t sda_pin
Definition softi2c.c:55
static bool softi2c_process_transaction(struct softi2c_device *d, struct i2c_transaction *t)
Definition softi2c.c:479
gpio_port_t sda_port
Definition softi2c.c:54
static bool softi2c_write_start(struct softi2c_device *d)
Definition softi2c.c:284
static bool softi2c_write_stop(struct softi2c_device *d)
Definition softi2c.c:376
static void softi2c_spin(struct i2c_periph *p)
Definition softi2c.c:641
static bool softi2c_read_byte(struct softi2c_device *d, uint8_t *byte, bool ack)
Definition softi2c.c:444
Platform-independent software I2C implementation.
Architecture independent timing functions.
Periodic telemetry system header (includes downlink utility and generated code).
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.