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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define CXPI_PIN_STATE_DISABLE 0x00
60 #define CXPI_PIN_STATE_ENABLE 0x01
61 
67 #define DRV_BUFFER_SIZE 200
68  // cxpi_cmd
70 
85 #define CXPI_MAP_MIKROBUS( cfg, mikrobus ) \
86  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
87  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
88  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
89  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
90  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
91  // cxpi_map // cxpi
94 
99 typedef struct
100 {
101  // Output pins
102  digital_out_t en;
103  digital_out_t pwm;
105  // Input pins
106  digital_in_t int_pin;
108  // Modules
109  uart_t uart;
111  // Buffers
112  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
113  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
115 } cxpi_t;
116 
121 typedef struct
122 {
123  // Communication gpio pins
124  pin_name_t rx_pin;
125  pin_name_t tx_pin;
127  // Additional gpio pins
128  pin_name_t en;
129  pin_name_t pwm;
130  pin_name_t int_pin;
132  // Static variable
133  uint32_t baud_rate;
134  bool uart_blocking;
135  uart_data_bits_t data_bit;
136  uart_parity_t parity_bit;
137  uart_stop_bits_t stop_bit;
139 } cxpi_cfg_t;
140 
145 typedef enum
146 {
147  CXPI_OK = 0,
148  CXPI_ERROR = -1
149 
151 
167 void cxpi_cfg_setup ( cxpi_cfg_t *cfg );
168 
182 err_t cxpi_init ( cxpi_t *ctx, cxpi_cfg_t *cfg );
183 
197 err_t cxpi_default_cfg ( cxpi_t *ctx );
198 
211 err_t cxpi_generic_write ( cxpi_t *ctx, char *data_buf, uint16_t len );
212 
225 err_t cxpi_generic_read ( cxpi_t *ctx, char *data_buf, uint16_t max_len );
226 
235 void cxpi_write_byte ( cxpi_t *ctx, uint8_t input );
236 
244 uint8_t cxpi_read_byte ( cxpi_t *ctx );
245 
253 uint8_t cxpi_byte_ready ( cxpi_t *ctx );
254 
263 void cxpi_send_command ( cxpi_t *ctx, char *command );
264 
274 void cxpi_set_nslp_pin_state ( cxpi_t *ctx, uint8_t pin_state );
275 
286 void cxpi_set_pwm_pin_state ( cxpi_t *ctx, uint8_t pin_state );
287 
297 void cxpi_set_through_mode ( cxpi_t *ctx );
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // CXPI_H
303  // cxpi
305 
306 // ------------------------------------------------------------------------ END
cxpi_generic_write
err_t cxpi_generic_write(cxpi_t *ctx, char *data_buf, uint16_t len)
CXPI data writing function.
CXPI_OK
Definition: cxpi.h:146
cxpi_set_nslp_pin_state
void cxpi_set_nslp_pin_state(cxpi_t *ctx, uint8_t pin_state)
Set NSLP pin state function.
cxpi_byte_ready
uint8_t cxpi_byte_ready(cxpi_t *ctx)
Check for new byte received.
cxpi_set_through_mode
void cxpi_set_through_mode(cxpi_t *ctx)
Set through mode function.
cxpi_cfg_setup
void cxpi_cfg_setup(cxpi_cfg_t *cfg)
CXPI configuration object setup function.
cxpi_generic_read
err_t cxpi_generic_read(cxpi_t *ctx, char *data_buf, uint16_t max_len)
CXPI data reading function.
cxpi_set_pwm_pin_state
void cxpi_set_pwm_pin_state(cxpi_t *ctx, uint8_t pin_state)
Set PWM pin state function.
cxpi_read_byte
uint8_t cxpi_read_byte(cxpi_t *ctx)
Read Single Byte.
cxpi_send_command
void cxpi_send_command(cxpi_t *ctx, char *command)
Send command.
cxpi_write_byte
void cxpi_write_byte(cxpi_t *ctx, uint8_t input)
Write Single Byte.
cxpi_default_cfg
err_t cxpi_default_cfg(cxpi_t *ctx)
CXPI default configuration function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
CXPI driver buffer size.
Definition: cxpi.h:66
cxpi_init
err_t cxpi_init(cxpi_t *ctx, cxpi_cfg_t *cfg)
CXPI initialization function.
cxpi_return_value_t
cxpi_return_value_t
CXPI Click return value data.
Definition: cxpi.h:144
cxpi_cfg_t
CXPI Click configuration object.
Definition: cxpi.h:120
CXPI_ERROR
Definition: cxpi.h:147
cxpi_t
CXPI Click context object.
Definition: cxpi.h:98