LP-551 Remove popup - Increase neutral diff levels for alarm
[librepilot.git] / flight / pios / inc / pios_i2c_priv.h
blob70e0840eb066405e968194d043dcb3862b3ad2e6
1 /**
2 ******************************************************************************
4 * @file pios_i2c_priv.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief I2C private definitions.
7 * @see The GNU Public License (GPL) Version 3
9 *****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifndef PIOS_I2C_PRIV_H
27 #define PIOS_I2C_PRIV_H
29 #include <pios.h>
30 #include <pios_stm32.h>
31 #include <stdbool.h>
33 struct pios_i2c_adapter_cfg {
34 I2C_TypeDef *regs;
35 uint32_t remapSDA;
36 uint32_t remapSCL;
37 I2C_InitTypeDef init;
39 uint32_t transfer_timeout_ms;
40 struct stm32_gpio scl;
41 struct stm32_gpio sda;
42 struct stm32_irq event;
43 struct stm32_irq error;
46 enum pios_i2c_adapter_magic {
47 PIOS_I2C_DEV_MAGIC = 0xa9a9b8b8,
50 struct pios_i2c_adapter {
51 enum pios_i2c_adapter_magic magic;
52 const struct pios_i2c_adapter_cfg *cfg;
53 #ifdef PIOS_INCLUDE_FREERTOS
54 xSemaphoreHandle sem_busy;
55 xSemaphoreHandle sem_ready;
56 #else
57 uint8_t busy;
58 #endif
60 /* variables for transfer timeouts */
61 uint32_t transfer_delay_uS; // approx time to transfer one byte, calculated later basen on setting use here time based on 100 kbits/s
62 uint32_t transfer_timeout_ticks; // take something tha makes sense for small transaction, calculated later based upon transmission desired
64 bool bus_error;
65 bool nack;
67 volatile uint8_t curr_state;
68 const struct pios_i2c_txn *first_txn;
69 const struct pios_i2c_txn *active_txn;
70 const struct pios_i2c_txn *last_txn;
72 pios_i2c_callback callback;
74 uint8_t *active_byte;
75 uint8_t *last_byte;
77 enum pios_i2c_transfer_result *transfer_result;
80 int32_t PIOS_I2C_Init(uint32_t *i2c_id, const struct pios_i2c_adapter_cfg *cfg);
82 #endif /* PIOS_I2C_PRIV_H */