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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define CXPI_PIN_STATE_DISABLE 0x00
70 #define CXPI_PIN_STATE_ENABLE 0x01
71 
77 #define DRV_BUFFER_SIZE 200
78  // cxpi_cmd
80 
95 #define CXPI_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
97  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
98  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
99  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
100  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
101  // cxpi_map // cxpi
104 
109 typedef struct
110 {
111  // Output pins
112  digital_out_t en;
113  digital_out_t pwm;
115  // Input pins
116  digital_in_t int_pin;
118  // Modules
119  uart_t uart;
121  // Buffers
122  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
123  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
125 } cxpi_t;
126 
131 typedef struct
132 {
133  // Communication gpio pins
134  pin_name_t rx_pin;
135  pin_name_t tx_pin;
137  // Additional gpio pins
138  pin_name_t en;
139  pin_name_t pwm;
140  pin_name_t int_pin;
142  // Static variable
143  uint32_t baud_rate;
145  uart_data_bits_t data_bit;
146  uart_parity_t parity_bit;
147  uart_stop_bits_t stop_bit;
149 } cxpi_cfg_t;
150 
155 typedef enum
156 {
157  CXPI_OK = 0,
158  CXPI_ERROR = -1
159 
161 
178 
192 err_t cxpi_init ( cxpi_t *ctx, cxpi_cfg_t *cfg );
193 
207 err_t cxpi_default_cfg ( cxpi_t *ctx );
208 
221 err_t cxpi_generic_write ( cxpi_t *ctx, char *data_buf, uint16_t len );
222 
235 err_t cxpi_generic_read ( cxpi_t *ctx, char *data_buf, uint16_t max_len );
236 
245 void cxpi_write_byte ( cxpi_t *ctx, uint8_t input );
246 
254 uint8_t cxpi_read_byte ( cxpi_t *ctx );
255 
263 uint8_t cxpi_byte_ready ( cxpi_t *ctx );
264 
273 void cxpi_send_command ( cxpi_t *ctx, char *command );
274 
284 void cxpi_set_nslp_pin_state ( cxpi_t *ctx, uint8_t pin_state );
285 
296 void cxpi_set_pwm_pin_state ( cxpi_t *ctx, uint8_t pin_state );
297 
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 #endif // CXPI_H
313  // cxpi
315 
316 // ------------------------------------------------------------------------ END
cxpi_generic_write
err_t cxpi_generic_write(cxpi_t *ctx, char *data_buf, uint16_t len)
CXPI data writing function.
CXPI_OK
@ CXPI_OK
Definition: cxpi.h:157
cxpi_set_nslp_pin_state
void cxpi_set_nslp_pin_state(cxpi_t *ctx, uint8_t pin_state)
Set NSLP pin state function.
cxpi_t::uart
uart_t uart
Definition: cxpi.h:119
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_cfg_t::rx_pin
pin_name_t rx_pin
Definition: cxpi.h:134
cxpi_cfg_t::uart_blocking
bool uart_blocking
Definition: cxpi.h:144
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_cfg_t::pwm
pin_name_t pwm
Definition: cxpi.h:139
cxpi_t::en
digital_out_t en
Definition: cxpi.h:112
cxpi_cfg_t::int_pin
pin_name_t int_pin
Definition: cxpi.h:140
cxpi_read_byte
uint8_t cxpi_read_byte(cxpi_t *ctx)
Read Single Byte.
cxpi_t::int_pin
digital_in_t int_pin
Definition: cxpi.h:116
cxpi_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: cxpi.h:147
cxpi_send_command
void cxpi_send_command(cxpi_t *ctx, char *command)
Send command.
cxpi_cfg_t::en
pin_name_t en
Definition: cxpi.h:138
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:77
cxpi_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: cxpi.h:145
cxpi_t::pwm
digital_out_t pwm
Definition: cxpi.h:113
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:156
cxpi_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: cxpi.h:146
cxpi_cfg_t::baud_rate
uint32_t baud_rate
Definition: cxpi.h:143
cxpi_cfg_t
CXPI Click configuration object.
Definition: cxpi.h:132
CXPI_ERROR
@ CXPI_ERROR
Definition: cxpi.h:158
cxpi_t
CXPI Click context object.
Definition: cxpi.h:110
cxpi_cfg_t::tx_pin
pin_name_t tx_pin
Definition: cxpi.h:135