Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "subsystems/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

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

#define SOFTI2C0_DIVIDER   1

Definition at line 45 of file softi2c.c.

Referenced by softi2c_event().

#define SOFTI2C1_DIVIDER   1

Definition at line 48 of file softi2c.c.

Referenced by softi2c_event().

Function Documentation

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, softi2c_process_transaction(), i2c_periph::trans, i2c_periph::trans_extract_idx, and i2c_periph::trans_insert_idx.

Referenced by softi2c_event(), and softi2c_spin().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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:

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:

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:

static bool softi2c_idle ( struct i2c_periph periph)
static
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:

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:

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

Definition at line 669 of file softi2c.c.

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(), and softi2c_gpio_highz().

+ Here is the call graph for this function:

static void softi2c_spin ( struct i2c_periph p)
static

Definition at line 645 of file softi2c.c.

References i2c_periph::reg_addr, softi2c_device_event(), and sys_time_usleep().

+ Here is the call graph for this function:

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:

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:

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:

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:

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: