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
pca95x4.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #include "peripherals/pca95x4.h"
28 
29 // Init function
30 void pca95x4_init(struct pca95x4 *dev, struct i2c_periph *i2c_p, uint8_t addr)
31 {
32  /* set i2c_peripheral */
33  dev->i2c_p = i2c_p;
34 
35  /* slave address */
36  dev->i2c_trans.slave_addr = addr;
37  /* set initial status: Done */
39 }
40 
41 // Configure function
42 bool pca95x4_configure(struct pca95x4 *dev, uint8_t val, bool blocking)
43 {
44  if (dev->i2c_trans.status != I2CTransDone &&
47  return false; // previous transaction not finished
48  }
49  // send config value
51  dev->i2c_trans.buf[1] = val;
52  if (blocking) {
53  return i2c_blocking_transmit(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2);
54  } else {
55  return i2c_transmit(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2);
56  }
57 }
58 
59 // Set output function
60 bool pca95x4_set_output(struct pca95x4 *dev, uint8_t mask, bool blocking)
61 {
62  if (dev->i2c_trans.status != I2CTransDone &&
65  return false; // previous transaction not finished
66  }
67  // send mask value
69  dev->i2c_trans.buf[1] = mask;
70  if (blocking) {
71  return i2c_blocking_transmit(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2);
72  } else {
73  return i2c_transmit(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2);
74  }
75 }
76 
PCA95X4 structure.
Definition: pca95x4.h:53
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
Driver for the 8-bit I/O expander based on i2c.
transaction successfully finished by I2C driver
Definition: i2c.h:57
bool pca95x4_set_output(struct pca95x4 *dev, uint8_t mask, bool blocking)
Set output value.
Definition: pca95x4.c:60
void pca95x4_init(struct pca95x4 *dev, struct i2c_periph *i2c_p, uint8_t addr)
Init PCA95X4.
Definition: pca95x4.c:30
#define PCA95X4_OUTPUT_REG
Definition: pca95x4.h:36
transaction set to done by user level
Definition: i2c.h:59
struct i2c_transaction i2c_trans
Definition: pca95x4.h:55
uint16_t val[TCOUPLE_NB]
#define PCA95X4_CONFIG_REG
Definition: pca95x4.h:38
struct i2c_periph * i2c_p
Definition: pca95x4.h:54
transaction failed
Definition: i2c.h:58
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:324
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
bool pca95x4_configure(struct pca95x4 *dev, uint8_t val, bool blocking)
Configure PCA95X4.
Definition: pca95x4.c:42
unsigned char uint8_t
Definition: types.h:14
bool i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction and wait for it to complete.
Definition: i2c.c:359