Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_sensorif.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Cascoda Ltd.
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  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
40 #ifndef CASCODA_SENSORIF_H
41 #define CASCODA_SENSORIF_H
42 
44 #include "ca821x_api.h"
45 #include "cascoda_chili_config.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* declarations */
52 #define SENSORIF_I2C_TIMEOUT 100 /* I2C bus access time-out time in [ms] */
53 #define SENSORIF_I2C_CLK_FREQUENCY 100000 /* I2C SCL frequency [Hz], 100kHz (full-speed) */
54 #define SENSORIF_INT_PULLUPS 0 /* I2C use internal pull-ups flag */
55 #define SENSORIF_SPI_CLK_FREQUENCY 4000000 /* SPI CLK frequency [Hz], 4MHz (max frequency for E-paper display) */
56 #define SENSORIF_SPI_DATA_WIDTH 8
57 #define UART_SENSORIF_BAUDRATE 115200
58 
59 #if defined(CASCODA_CHILI2_CONFIG)
61 void SENSORIF_SECURE_I2C_Config(u32_t portnum);
62 void SENSORIF_SECURE_SPI_Config(u32_t portnum);
64 #endif
65 
66 /* Note: most internal GPIO pull-ups have a value of around 50kOhms which is usually
67  * too high for I2C pull-up values, depending on number of peripherals connected and
68  * overall load capacitance. The SCL clock frequency might have to be lowered to below
69  * full-speed if no external pull-ups on SDA and SCL are available.
70  */
71 
74 {
94 };
95 
96 /* PWM type to indicate whether Basic PWM or Extended PWM is used */
97 typedef enum
98 {
102 } PWM_type_t;
103 
104 /* functions for platform implementation */
105 
106 /******************************************************************************/
107 /***************************************************************************/
111 void SENSORIF_I2C_Init(void);
112 
113 /******************************************************************************/
114 /***************************************************************************/
118 void SENSORIF_I2C_Deinit(void);
119 
120 /******************************************************************************/
121 /***************************************************************************/
130 enum sensorif_i2c_status SENSORIF_I2C_Write(u8_t slaveaddr, u8_t *data, u32_t *len);
131 
132 /******************************************************************************/
133 /***************************************************************************/
143 enum sensorif_i2c_status SENSORIF_I2C_Read(u8_t slaveaddr, u8_t *pdata, u32_t *plen);
144 
145 /******************************************************************************/
146 /***************************************************************************/
153 void SENSORIF_SPI_Init(bool is_eink_display_present);
154 
155 /******************************************************************************/
156 /***************************************************************************/
160 void SENSORIF_SPI_Deinit(void);
161 
162 /************************************************************************************************************/
163 /*********************************************************************************************************/
171 
172 /************************************************************************************************************/
173 /*********************************************************************************************************/
181 void SENSORIF_SPI_FULL_DUPLEX_RXONLY(u8_t *RxBuf, u8_t RxLen);
182 
183 /************************************************************************************************************/
184 /*********************************************************************************************************/
197 void SENSORIF_SPI_WRITE_THEN_READ(u8_t *RxBuf, u8_t *TxBuf, u8_t RxLen, u8_t TxLen);
198 
199 /******************************************************************************/
200 /***************************************************************************/
204 void SENSORIF_UART_Init(void);
205 
206 /******************************************************************************/
207 /***************************************************************************/
211 void SENSORIF_UART_Deinit(void);
212 
213 /************************************************************************************************************/
214 /*********************************************************************************************************/
222 u32_t SENSORIF_UART_Write(u8_t *out_data, u32_t writebytes);
223 
224 /************************************************************************************************************/
225 /*********************************************************************************************************/
233 u32_t SENSORIF_UART_Read(u8_t *in_data, u32_t readbytes);
234 
235 /************************************************************************************************************/
236 /*********************************************************************************************************/
241 void SENSORIF_I2C_Config(u32_t portnum);
242 
243 /************************************************************************************************************/
244 /*********************************************************************************************************/
249 void SENSORIF_SPI_Config(u32_t portnum);
250 
251 /************************************************************************************************************/
252 /*********************************************************************************************************/
257 void SENSORIF_UART_Config(u32_t portnum);
258 
259 /******************************************************************************/
260 /***************************************************************************/
276 ca_error SENSORIF_PWM_Init(u8_t pin, u32_t u32Frequency, u32_t u32DutyCycle);
277 
278 /******************************************************************************/
279 /***************************************************************************/
283 void SENSORIF_PWM_Deinit(void);
284 
285 /******************************************************************************/
286 /***************************************************************************/
291 void SENSORIF_PWM_SetDutyCycle(u32_t u32DutyCycle);
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 
301 #endif // CASCODA_SENSORIF_H
The main ca821x-api include file.
u8_t SENSORIF_SPI_Chip_Select()
Definition: cascoda_sensorif_m2351.c:136
__NONSECURE_ENTRY void SENSORIF_SECURE_SPI_Config(u32_t portnum)
Definition: cascoda_sensorif_secure.c:188
__NONSECURE_ENTRY void SENSORIF_SECURE_I2C_Config(u32_t portnum)
Definition: cascoda_sensorif_secure.c:175
__NONSECURE_ENTRY void SENSORIF_SECURE_UART_Config(u32_t portnum)
Definition: cascoda_sensorif_secure.c:202
Type definitions used by Cascoda baremetal drivers.
unsigned long u32_t
Definition: cascoda_types.h:50
unsigned char u8_t
Definition: cascoda_types.h:46
void SENSORIF_I2C_Init(void)
Initialises and enables I2C interface.
Definition: cascoda_sensorif_nano120.c:201
enum sensorif_i2c_status SENSORIF_I2C_Read(u8_t slaveaddr, u8_t *pdata, u32_t *plen)
Reads bytes from I2C slave.
Definition: cascoda_sensorif_nano120.c:132
ca_error SENSORIF_SPI_Write(u8_t out_data)
Writes bytes to SPI slave.
Definition: cascoda_sensorif_m2351.c:333
enum sensorif_i2c_status SENSORIF_I2C_Write(u8_t slaveaddr, u8_t *data, u32_t *len)
Writes bytes to I2C slave.
Definition: cascoda_sensorif_nano120.c:70
u32_t SENSORIF_UART_Read(u8_t *in_data, u32_t readbytes)
Read bytes to UART slave.
Definition: cascoda_sensorif_m2351.c:421
void SENSORIF_PWM_Deinit(void)
Deinitialises and disables PWM.
Definition: cascoda_sensorif_secure.c:518
ca_error SENSORIF_PWM_Init(u8_t pin, u32_t u32Frequency, u32_t u32DutyCycle)
Initialises and enables PWM for the specified frequency and duty cycle.
Definition: cascoda_sensorif_secure.c:463
void SENSORIF_UART_Init(void)
Initialises and enables UART interface.
Definition: cascoda_sensorif_secure.c:431
void SENSORIF_I2C_Deinit(void)
Disables I2C interface.
Definition: cascoda_sensorif_nano120.c:238
sensorif_i2c_status
I2C master status enumerations.
Definition: cascoda_sensorif.h:74
void SENSORIF_UART_Deinit(void)
Disables UART interface.
Definition: cascoda_sensorif_secure.c:456
void SENSORIF_SPI_WRITE_THEN_READ(u8_t *RxBuf, u8_t *TxBuf, u8_t RxLen, u8_t TxLen)
Exchange bytes between SPI slave and master.
Definition: cascoda_sensorif_m2351.c:354
u32_t SENSORIF_UART_Write(u8_t *out_data, u32_t writebytes)
Writes bytes to UART slave.
Definition: cascoda_sensorif_m2351.c:405
void SENSORIF_UART_Config(u32_t portnum)
Set UART Configuration.
Definition: cascoda_sensorif_m2351.c:177
void SENSORIF_SPI_Init(bool is_eink_display_present)
Initialises and enables SPI interface.
Definition: cascoda_sensorif_secure.c:340
PWM_type_t
Definition: cascoda_sensorif.h:98
void SENSORIF_SPI_Deinit(void)
Disables SPI interface.
Definition: cascoda_sensorif_secure.c:420
void SENSORIF_SPI_FULL_DUPLEX_RXONLY(u8_t *RxBuf, u8_t RxLen)
Read data in the RX while sending IDLE data to TX.
Definition: cascoda_sensorif_m2351.c:345
void SENSORIF_SPI_Config(u32_t portnum)
Set SPI Configuration.
Definition: cascoda_sensorif_m2351.c:156
void SENSORIF_PWM_SetDutyCycle(u32_t u32DutyCycle)
Changes the duty cycle of the PWM.
Definition: cascoda_sensorif_secure.c:544
void SENSORIF_I2C_Config(u32_t portnum)
Set I2C Configuration.
Definition: cascoda_sensorif_nano120.c:60
@ SENSORIF_I2C_ST_BUS_ERROR
bus error re-mapped from 0x00 for status return
Definition: cascoda_sensorif.h:93
@ SENSORIF_I2C_ST_START
start
Definition: cascoda_sensorif.h:75
@ SENSORIF_I2C_ST_TX_AD_NACK
transmit address NACKed
Definition: cascoda_sensorif.h:78
@ SENSORIF_I2C_ST_RELEASED
bus released
Definition: cascoda_sensorif.h:88
@ SENSORIF_I2C_ST_TX_DT_ACK
transmit data ACKed
Definition: cascoda_sensorif.h:79
@ SENSORIF_I2C_ST_RX_AD_ACK
receive address ACKed
Definition: cascoda_sensorif.h:82
@ SENSORIF_I2C_ST_RX_DT_NACK
receive data NACKed
Definition: cascoda_sensorif.h:85
@ SENSORIF_I2C_ST_RX_DT_ACK
receive data ACKed
Definition: cascoda_sensorif.h:84
@ SENSORIF_I2C_ST_ARB_LOST
arbitration lost
Definition: cascoda_sensorif.h:81
@ SENSORIF_I2C_ST_RX_AD_NACK
receive address NACKed
Definition: cascoda_sensorif.h:83
@ SENSORIF_I2C_ST_TX_AD_ACK
transmit address ACKed
Definition: cascoda_sensorif.h:77
@ SENSORIF_I2C_ST_STOP
on reset or stop
Definition: cascoda_sensorif.h:87
@ SENSORIF_I2C_ST_RSTART
repeat start
Definition: cascoda_sensorif.h:76
@ SENSORIF_I2C_ST_SUCCESS
successful transfer
Definition: cascoda_sensorif.h:91
@ SENSORIF_I2C_ST_TX_DT_NACK
transmit data NACKed
Definition: cascoda_sensorif.h:80
@ SENSORIF_I2C_ST_BUS_ERROR_RAW
bus error code transmitted over wire
Definition: cascoda_sensorif.h:86
@ SENSORIF_I2C_ST_NOT_IMPLEMENTED
not implemented
Definition: cascoda_sensorif.h:90
@ SENSORIF_I2C_ST_TIMEOUT
bus access time-out
Definition: cascoda_sensorif.h:92
@ USING_EPWM
Definition: cascoda_sensorif.h:101
@ USING_BPWM
Definition: cascoda_sensorif.h:100
@ NOT_INITIALISED
Definition: cascoda_sensorif.h:99
ca_error
Cascoda error type.
Definition: ca821x_error.h:51