cxpi 2.0.0.0
cxpi.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2021 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CXPI_H
29#define CXPI_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define CXPI_PIN_STATE_DISABLE 0x00
74#define CXPI_PIN_STATE_ENABLE 0x01
75
81#define DRV_BUFFER_SIZE 200
82
83 // cxpi_cmd
84
99#define CXPI_MAP_MIKROBUS( cfg, mikrobus ) \
100 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
101 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
102 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
103 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
104 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
105
106 // cxpi_map
107 // cxpi
108
113typedef struct
114{
115 // Output pins
116 digital_out_t en;
117 digital_out_t pwm;
119 // Input pins
120 digital_in_t int_pin;
122 // Modules
123 uart_t uart;
125 // Buffers
126 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
127 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
129} cxpi_t;
130
135typedef struct
136{
137 // Communication gpio pins
138 pin_name_t rx_pin;
139 pin_name_t tx_pin;
141 // Additional gpio pins
142 pin_name_t en;
143 pin_name_t pwm;
144 pin_name_t int_pin;
146 // Static variable
147 uint32_t baud_rate;
149 uart_data_bits_t data_bit;
150 uart_parity_t parity_bit;
151 uart_stop_bits_t stop_bit;
153} cxpi_cfg_t;
154
159typedef enum
160{
162 CXPI_ERROR = -1
163
165
182
196err_t cxpi_init ( cxpi_t *ctx, cxpi_cfg_t *cfg );
197
212
225err_t cxpi_generic_write ( cxpi_t *ctx, char *data_buf, uint16_t len );
226
239err_t cxpi_generic_read ( cxpi_t *ctx, char *data_buf, uint16_t max_len );
240
249void cxpi_write_byte ( cxpi_t *ctx, uint8_t input );
250
258uint8_t cxpi_read_byte ( cxpi_t *ctx );
259
267uint8_t cxpi_byte_ready ( cxpi_t *ctx );
268
277void cxpi_send_command ( cxpi_t *ctx, char *command );
278
288void cxpi_set_nslp_pin_state ( cxpi_t *ctx, uint8_t pin_state );
289
300void cxpi_set_pwm_pin_state ( cxpi_t *ctx, uint8_t pin_state );
301
312
313#ifdef __cplusplus
314}
315#endif
316#endif // CXPI_H
317
318 // cxpi
319
320// ------------------------------------------------------------------------ END
cxpi_return_value_t
CXPI Click return value data.
Definition cxpi.h:160
@ CXPI_ERROR
Definition cxpi.h:162
@ CXPI_OK
Definition cxpi.h:161
#define DRV_BUFFER_SIZE
CXPI driver buffer size.
Definition cxpi.h:81
err_t cxpi_generic_read(cxpi_t *ctx, char *data_buf, uint16_t max_len)
CXPI data reading function.
void cxpi_set_nslp_pin_state(cxpi_t *ctx, uint8_t pin_state)
Set NSLP pin state function.
err_t cxpi_init(cxpi_t *ctx, cxpi_cfg_t *cfg)
CXPI initialization function.
void cxpi_set_pwm_pin_state(cxpi_t *ctx, uint8_t pin_state)
Set PWM pin state function.
void cxpi_send_command(cxpi_t *ctx, char *command)
Send command.
err_t cxpi_default_cfg(cxpi_t *ctx)
CXPI default configuration function.
err_t cxpi_generic_write(cxpi_t *ctx, char *data_buf, uint16_t len)
CXPI data writing function.
uint8_t cxpi_byte_ready(cxpi_t *ctx)
Check for new byte received.
void cxpi_set_through_mode(cxpi_t *ctx)
Set through mode function.
void cxpi_write_byte(cxpi_t *ctx, uint8_t input)
Write Single Byte.
void cxpi_cfg_setup(cxpi_cfg_t *cfg)
CXPI configuration object setup function.
uint8_t cxpi_read_byte(cxpi_t *ctx)
Read Single Byte.
CXPI Click configuration object.
Definition cxpi.h:136
uint32_t baud_rate
Definition cxpi.h:147
bool uart_blocking
Definition cxpi.h:148
uart_data_bits_t data_bit
Definition cxpi.h:149
pin_name_t tx_pin
Definition cxpi.h:139
pin_name_t rx_pin
Definition cxpi.h:138
uart_stop_bits_t stop_bit
Definition cxpi.h:151
pin_name_t en
Definition cxpi.h:142
pin_name_t int_pin
Definition cxpi.h:144
pin_name_t pwm
Definition cxpi.h:143
uart_parity_t parity_bit
Definition cxpi.h:150
CXPI Click context object.
Definition cxpi.h:114
digital_out_t pwm
Definition cxpi.h:117
uart_t uart
Definition cxpi.h:123
digital_in_t int_pin
Definition cxpi.h:120
digital_out_t en
Definition cxpi.h:116