Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
softi2c.c File Reference

Platform-independent software I2C implementation. More...

#include "mcu_periph/softi2c.h"
#include "mcu_arch.h"
#include "mcu_periph/gpio.h"
#include "mcu_periph/sys_time.h"
#include "modules/datalink/telemetry.h"
#include <stdbool.h>
+ Include dependency graph for softi2c.c:

Go to the source code of this file.

Data Structures

struct  softi2c_device
 

Macros

#define SOFTI2C0_DIVIDER   1
 
#define SOFTI2C1_DIVIDER   1
 

Functions

static bool softi2c_idle (struct i2c_periph *periph)
 
static bool softi2c_submit (struct i2c_periph *periph, struct i2c_transaction *t)
 
static void softi2c_setbitrate (struct i2c_periph *periph, int bitrate)
 
static void softi2c_spin (struct i2c_periph *p)
 
static void softi2c_gpio_highz (gpio_port_t port, uint16_t pin)
 
static bool softi2c_gpio_read (gpio_port_t port, uint16_t pin)
 
static void softi2c_gpio_drive_low (gpio_port_t port, uint16_t pin)
 
static void softi2c_setup_gpio (gpio_port_t sda_port, uint16_t sda_pin, gpio_port_t scl_port, uint16_t scl_pin)
 
static bool softi2c_write_start (struct softi2c_device *d)
 
static bool softi2c_write_bit (struct softi2c_device *d, bool bit)
 
static bool softi2c_read_bit (struct softi2c_device *d, bool *bit)
 
static bool softi2c_write_restart (struct softi2c_device *d)
 
static bool softi2c_write_stop (struct softi2c_device *d)
 
static bool softi2c_write_byte (struct softi2c_device *d, uint8_t byte, bool *ack)
 
static bool softi2c_read_byte (struct softi2c_device *d, uint8_t *byte, bool ack)
 
static bool softi2c_process_transaction (struct softi2c_device *d, struct i2c_transaction *t)
 
static void softi2c_device_event (struct softi2c_device *d)
 
void softi2c_event (void)
 

Detailed Description

Platform-independent software I2C implementation.

Can be used transparently in place of the hardware I2C in i2c.h.

This implementation can only be used as the (only) master on the I2C bus.

Definition in file softi2c.c.


Data Structure Documentation

◆ softi2c_device

struct softi2c_device

Definition at line 52 of file softi2c.c.

+ Collaboration diagram for softi2c_device:
Data Fields
uint8_t bit_state
uint8_t byte_state
struct i2c_periph * periph
uint16_t scl_pin
gpio_port_t scl_port
uint16_t sda_pin
gpio_port_t sda_port

Macro Definition Documentation

◆ SOFTI2C0_DIVIDER

#define SOFTI2C0_DIVIDER   1

Definition at line 45 of file softi2c.c.

◆ SOFTI2C1_DIVIDER

#define SOFTI2C1_DIVIDER   1

Definition at line 48 of file softi2c.c.

Function Documentation

◆ softi2c_device_event()

static void softi2c_device_event ( struct softi2c_device d)
static

Definition at line 608 of file softi2c.c.

References I2C_TRANSACTION_QUEUE_LEN, p, softi2c_device::periph, and softi2c_process_transaction().

Referenced by softi2c_event(), and softi2c_spin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_event()

void softi2c_event ( void  )

Definition at line 624 of file softi2c.c.

References SOFTI2C0_DIVIDER, SOFTI2C1_DIVIDER, and softi2c_device_event().

Referenced by mcu_event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_gpio_drive_low()

static void softi2c_gpio_drive_low ( gpio_port_t  port,
uint16_t  pin 
)
static

Definition at line 185 of file softi2c.c.

References gpio_clear(), and gpio_setup_output().

Referenced by softi2c_read_bit(), softi2c_write_bit(), softi2c_write_restart(), softi2c_write_start(), and softi2c_write_stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_gpio_highz()

static void softi2c_gpio_highz ( gpio_port_t  port,
uint16_t  pin 
)
static

Definition at line 166 of file softi2c.c.

References gpio_set(), gpio_setup_input(), and gpio_setup_input_pullup().

Referenced by softi2c_gpio_read(), softi2c_read_bit(), softi2c_setup_gpio(), softi2c_write_bit(), softi2c_write_restart(), and softi2c_write_stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_gpio_read()

static bool softi2c_gpio_read ( gpio_port_t  port,
uint16_t  pin 
)
static

Definition at line 180 of file softi2c.c.

References gpio_get(), and softi2c_gpio_highz().

Referenced by softi2c_read_bit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_idle()

static bool softi2c_idle ( struct i2c_periph periph)
static

Definition at line 650 of file softi2c.c.

References I2CIdle, and p.

◆ softi2c_process_transaction()

◆ softi2c_read_bit()

static bool softi2c_read_bit ( struct softi2c_device d,
bool *  bit 
)
static

Definition at line 325 of file softi2c.c.

References softi2c_device::bit_state, gpio_get(), softi2c_device::scl_pin, softi2c_device::scl_port, softi2c_device::sda_pin, softi2c_device::sda_port, softi2c_gpio_drive_low(), softi2c_gpio_highz(), and softi2c_gpio_read().

Referenced by softi2c_read_byte(), and softi2c_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_read_byte()

static bool softi2c_read_byte ( struct softi2c_device d,
uint8_t byte,
bool  ack 
)
static

Definition at line 448 of file softi2c.c.

References softi2c_device::byte_state, softi2c_read_bit(), and softi2c_write_bit().

Referenced by softi2c_process_transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_setbitrate()

static void softi2c_setbitrate ( struct i2c_periph periph,
int  bitrate 
)
static

Definition at line 669 of file softi2c.c.

◆ softi2c_setup_gpio()

static void softi2c_setup_gpio ( gpio_port_t  sda_port,
uint16_t  sda_pin,
gpio_port_t  scl_port,
uint16_t  scl_pin 
)
static

Definition at line 194 of file softi2c.c.

References gpio_enable_clock(), softi2c_device::scl_pin, softi2c_device::scl_port, softi2c_device::sda_pin, softi2c_device::sda_port, and softi2c_gpio_highz().

+ Here is the call graph for this function:

◆ softi2c_spin()

static void softi2c_spin ( struct i2c_periph p)
static

Definition at line 645 of file softi2c.c.

References p, and softi2c_device_event().

+ Here is the call graph for this function:

◆ softi2c_submit()

static bool softi2c_submit ( struct i2c_periph periph,
struct i2c_transaction t 
)
static

◆ softi2c_write_bit()

static bool softi2c_write_bit ( struct softi2c_device d,
bool  bit 
)
static

Definition at line 294 of file softi2c.c.

References softi2c_device::bit_state, gpio_get(), softi2c_device::scl_pin, softi2c_device::scl_port, softi2c_device::sda_pin, softi2c_device::sda_port, softi2c_gpio_drive_low(), and softi2c_gpio_highz().

Referenced by softi2c_read_byte(), and softi2c_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_write_byte()

static bool softi2c_write_byte ( struct softi2c_device d,
uint8_t  byte,
bool *  ack 
)
static

Definition at line 418 of file softi2c.c.

References softi2c_device::byte_state, softi2c_read_bit(), and softi2c_write_bit().

Referenced by softi2c_process_transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_write_restart()

static bool softi2c_write_restart ( struct softi2c_device d)
static

Definition at line 349 of file softi2c.c.

References softi2c_device::bit_state, gpio_get(), softi2c_device::scl_pin, softi2c_device::scl_port, softi2c_device::sda_pin, softi2c_device::sda_port, softi2c_gpio_drive_low(), and softi2c_gpio_highz().

Referenced by softi2c_process_transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_write_start()

static bool softi2c_write_start ( struct softi2c_device d)
static

Definition at line 288 of file softi2c.c.

References softi2c_device::sda_pin, softi2c_device::sda_port, and softi2c_gpio_drive_low().

Referenced by softi2c_process_transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ softi2c_write_stop()

static bool softi2c_write_stop ( struct softi2c_device d)
static

Definition at line 380 of file softi2c.c.

References softi2c_device::bit_state, gpio_get(), softi2c_device::scl_pin, softi2c_device::scl_port, softi2c_device::sda_pin, softi2c_device::sda_port, softi2c_gpio_drive_low(), and softi2c_gpio_highz().

Referenced by softi2c_process_transaction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: