BSPACM  20150113
Board Support Package for ARM Cortex-M Microcontrollers
twi.h
Go to the documentation of this file.
1 /* Copyright 2015, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
45 #ifndef BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_TWI_H
46 #define BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_TWI_H
47 
48 #include <bspacm/core.h>
49 
50 /* Certain negative error codes convey information. For those cases,
51  * the absolute value is taken from the ERRORSRC register augmented by
52  * several flags for other error conditions. */
53 
57 #define BSPACM_NRF_TWI_BUS_ERROR_TIMEOUT 0x100
58 
62 #define BSPACM_NRF_TWI_BUS_ERROR_CLEAR_FAILED 0x200
63 
67 #define BSPACM_NRF_TWI_BUS_ERROR_UNKNOWN 0x400
68 
69 #ifndef BSPACM_NRF_APPLY_PAN_36
70 
77 #define BSPACM_NRF_APPLY_PAN_36 1
78 #endif /* BSPACM_NRF_APPLY_PAN_36 */
79 
80 #ifndef BSPACM_NRF_APPLY_PAN_56
81 
95 #define BSPACM_NRF_APPLY_PAN_56 1
96 #endif /* BSPACM_NRF_APPLY_PAN_56 */
97 
100 #define BSPACM_I2C_MINIMUM_BUS_TIMEOUT_us 100
101 
102 typedef struct sBSPACMi2cBus {
104  NRF_TWI_Type * twi;
105 
130  unsigned int timeout_utt;
131 
134  uint32_t frequency;
135 
137  uint8_t sda_pin;
138 
140  uint8_t scl_pin;
141 
142 #if (BSPACM_NRF_APPLY_PAN_36 - 0)
143 
145  int8_t ppi_chidx;
146 #endif /* BSPACM_NRF_APPLY_PAN_36 */
147 } sBSPACMi2cBus;
148 
150 typedef const sBSPACMi2cBus * hBSPACMi2cBus;
151 
192  NRF_TWI_Type * twi,
193  int sda_pin,
194  int scl_pin,
195  int ppi_chidx,
196  uint32_t frequency,
197  unsigned int timeout_us);
198 
204 int
206  bool enabled);
207 
221 int
223  unsigned int addr,
224  uint8_t * dp,
225  size_t len);
226 
240 int
242  unsigned int addr,
243  const uint8_t * sp,
244  size_t len);
245 
246 #endif /* BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_TWI_H */
int iBSPACMi2cSetEnabled(hBSPACMi2cBus tpp, bool enabled)
uint32_t frequency
Definition: twi.h:134
int iBSPACMi2cWrite(hBSPACMi2cBus tpp, unsigned int addr, const uint8_t *sp, size_t len)
uint8_t scl_pin
Definition: twi.h:140
const sBSPACMi2cBus * hBSPACMi2cBus
Definition: twi.h:150
Common header included by all BSPACM leaf headers.
NRF_TWI_Type * twi
Definition: twi.h:104
uint8_t sda_pin
Definition: twi.h:137
int iBSPACMi2cRead(hBSPACMi2cBus tpp, unsigned int addr, uint8_t *dp, size_t len)
unsigned int timeout_utt
Definition: twi.h:130
hBSPACMi2cBus hBSPACMi2cConfigureBus(sBSPACMi2cBus *tpp, NRF_TWI_Type *twi, int sda_pin, int scl_pin, int ppi_chidx, uint32_t frequency, unsigned int timeout_us)
Definition: twi.h:102
int8_t ppi_chidx
Definition: twi.h:145