ph  2.0.0.0
ph.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 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 PH_H
29 #define PH_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 PH_CMD_CNG_BAUD_RATE "Baud,"
70 #define PH_CMD_CHK_BAUD_RATE "Baud,?"
71 #define PH_CMD_SET_CONT_READ "C,"
72 #define PH_CMD_CHK_CONT_READ "C,?"
73 #define PH_CMD_CALIB_PERF "Cal"
74 #define PH_CMD_CALIB_MID ",mid,"
75 #define PH_CMD_CALIB_LOW ",low,"
76 #define PH_CMD_CALIB_HIGH ",high,"
77 #define PH_CMD_CHK_CALIB "Cal,?"
78 #define PH_CMD_CALIB_EXP "Export"
79 #define PH_CMD_CHK_CALIB_EXP "Export,?"
80 #define PH_CMD_CALIB_IMP "Import,"
81 #define PH_CMD_EN_FTY_RST "Factory"
82 #define PH_CMD_DEV_FIND "Find"
83 #define PH_CMD_DEV_INFO "i"
84 #define PH_CMD_CNG_I2C "I2C,"
85 #define PH_CMD_EN_LED "L,"
86 #define PH_CMD_CHK_LED "L,?"
87 #define PH_CMD_SET_DEV_NAME "Name,"
88 #define PH_CMD_GET_DEV_NAME "Name,?"
89 #define PH_CMD_PROTOCOL_LOCK "Plock,"
90 #define PH_CMD_PROTOCOL_CKH "Plock,?"
91 #define PH_CMD_SET_SNGL_READ "r"
92 #define PH_CMD_ENTER_SLEEP "Sleep"
93 #define PH_CMD_RET_SLOPE "Slope,?"
94 #define PH_CMD_READ_STATUS "Status"
95 #define PH_CMD_TEMP_COMP "T,"
96 #define PH_CMD_CHK_TEMP_COMP "T,?"
97 #define PH_CMD_RSP_CODES "*OK"
98 #define PH_CMD_EN_RSP_CODES "*OK,1"
99 #define PH_CMD_DIS_RSP_CODES "*OK,0"
100 #define PH_CMD_CHK_RSP_CODES "*OK,?"
101 #define PH_CMD_END_COMMAND "\r"
102 
107 #define PH_RSP_CODE_ERROR "*ER"
108 #define PH_RSP_CODE_OV_VOLT "*OV"
109 #define PH_RSP_CODE_UN_VOLT "*UV"
110 #define PH_RSP_CODE_RESET "*RS"
111 #define PH_RSP_CODE_READY "*RE"
112 #define PH_RSP_CODE_SLEEP_EN "*SL"
113 #define PH_RSP_CODE_WAKE_UP "*WA"
114 #define PH_RSP_CODE_ALL_GOOD "*OK"
115 // Restart codes list
116 
121 #define PH_RST_CODE_POW_OFF "P"
122 #define PH_RST_CODE_SW_RST "S"
123 #define PH_RST_CODE_BRWN_OUT "B"
124 #define PH_RST_CODE_WTD "W"
125 #define PH_RST_CODE_UNKNOWN "U"
126 
131 #define PH_BAUD_RATE_300 "300"
132 #define PH_BAUD_RATE_1200 "1200"
133 #define PH_BAUD_RATE_2400 "2400"
134 #define PH_BAUD_RATE_9600 "9600"
135 #define PH_BAUD_RATE_19200 "19200"
136 #define PH_BAUD_RATE_38400 "38400"
137 #define PH_BAUD_RATE_57600 "57600"
138 #define PH_BAUD_RATE_115200 "115200"
139 
145 #define DRV_BUFFER_SIZE 200
146  // ph_cmd
148 
163 #define PH_MAP_MIKROBUS( cfg, mikrobus ) \
164  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
165  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
166  // ph_map // ph
168 
173 typedef struct
174 {
175  // Modules
176  uart_t uart;
178  // Buffers
179  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
180  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
182 } ph_t;
183 
188 typedef struct
189 {
190  // Communication gpio pins
191  pin_name_t rx_pin;
192  pin_name_t tx_pin;
194  // Static variable
195  uint32_t baud_rate;
197  uart_data_bits_t data_bit;
198  uart_parity_t parity_bit;
199  uart_stop_bits_t stop_bit;
201 } ph_cfg_t;
202 
207 typedef enum
208 {
209  PH_OK = 0,
210  PH_ERROR = -1
211 
213 
229 void ph_cfg_setup ( ph_cfg_t *cfg );
230 
244 err_t ph_init ( ph_t *ctx, ph_cfg_t *cfg );
245 
259 err_t ph_default_cfg ( ph_t *ctx );
260 
273 err_t ph_generic_write ( ph_t *ctx, uint8_t *data_buf, uint16_t len );
274 
287 err_t ph_generic_read ( ph_t *ctx, uint8_t *data_buf, uint16_t max_len );
288 
297 void ph_uart_write ( ph_t *ctx, uint8_t input );
298 
308 void ph_uart_read_until ( ph_t *ctx, char *p_rx_data, char *delim );
309 
318 void ph_send_cmd ( ph_t *ctx, char *p_cmd );
319 
329 void ph_send_cmd_resp ( ph_t *ctx, char *p_cmd, char *p_resp );
330 
342 void ph_send_cmd_w_num ( ph_t *ctx, char *p_cmd, char *flt_val, char *p_resp );
343 
353 void ph_get_cmd_resp ( ph_t *ctx, char *p_cmd, char *p_resp );
354 
364 void ph_switch_led ( ph_t *ctx, uint8_t state, char *p_resp );
365 
374 void ph_chk_led_state ( ph_t *ctx, char *p_resp );
375 
386 void ph_find_dev ( ph_t *ctx, char *p_resp );
387 
399 void ph_cont_read ( ph_t *ctx, uint8_t time, char *p_resp );
400 
409 void ph_chk_cont_read ( ph_t *ctx, char *p_resp );
410 
425 void ph_perf_calib ( ph_t *ctx, char *point, float flt_val, char *p_resp );
426 
440 void ph_chk_calib ( ph_t *ctx, char *p_resp );
441 
450 void ph_chk_slope ( ph_t *ctx, char *p_resp );
451 
462 void ph_get_calib_exp_bytes_num ( ph_t *ctx, char *p_resp );
463 
475 void ph_import_calib ( ph_t *ctx, uint8_t *in_calib, char *p_resp );
476 
485 void ph_factory_rst ( ph_t *ctx, char *p_resp );
486 
499 void ph_set_temp_comp ( ph_t *ctx, float flt_val, char *p_resp );
500 
511 void ph_get_temp_comp ( ph_t *ctx, char *p_resp );
512 
524 void ph_set_name ( ph_t *ctx, char *p_dev_name, char *p_resp );
525 
534 void ph_show_name ( ph_t *ctx, char *p_dev_name );
535 
544 void ph_get_dev_info ( ph_t *ctx, char *p_resp );
545 
554 void ph_check_status ( ph_t *ctx, char *p_resp );
555 
563 void ph_sleep ( ph_t *ctx );
564 
576 void ph_chng_baud_rate ( ph_t *ctx, char *baud_rate, char *p_resp );
577 
588 void ph_chk_baud_rate ( ph_t *ctx, char *p_resp );
589 
599 void ph_protocol_lock ( ph_t *ctx, uint8_t state, char *p_resp );
600 
609 void ph_check_protocol_lock ( ph_t *ctx, char *p_resp );
610 
622 void ph_chng_i2c_adr ( ph_t *ctx, uint32_t i2c_adr, char *p_resp );
623 
632 void ph_single_read ( ph_t *ctx, char *p_resp );
633 
642 uint8_t ph_response ( ph_t *ctx, char *p_resp );
643 
650 void ph_clr_log_buf ( char *p_str );
651 
652 #ifdef __cplusplus
653 }
654 #endif
655 #endif // PH_H
656  // ph
658 
659 // ------------------------------------------------------------------------ END
ph_chng_i2c_adr
void ph_chng_i2c_adr(ph_t *ctx, uint32_t i2c_adr, char *p_resp)
Change Device's I2C slave address function.
ph_get_calib_exp_bytes_num
void ph_get_calib_exp_bytes_num(ph_t *ctx, char *p_resp)
Export calibration data function.
ph_get_cmd_resp
void ph_get_cmd_resp(ph_t *ctx, char *p_cmd, char *p_resp)
Send get response function.
ph_protocol_lock
void ph_protocol_lock(ph_t *ctx, uint8_t state, char *p_resp)
Protocol Lock enable/disable function.
ph_chk_calib
void ph_chk_calib(ph_t *ctx, char *p_resp)
Check if Calibration was performed function.
ph_send_cmd_resp
void ph_send_cmd_resp(ph_t *ctx, char *p_cmd, char *p_resp)
Send command and get response function.
ph_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ph.h:192
ph_send_cmd_w_num
void ph_send_cmd_w_num(ph_t *ctx, char *p_cmd, char *flt_val, char *p_resp)
Send command with number and get response function.
ph_t::uart
uart_t uart
Definition: ph.h:176
ph_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ph.h:191
ph_cont_read
void ph_cont_read(ph_t *ctx, uint8_t time, char *p_resp)
Set Continous read function.
ph_response
uint8_t ph_response(ph_t *ctx, char *p_resp)
pH Response handler function
ph_chk_led_state
void ph_chk_led_state(ph_t *ctx, char *p_resp)
Check LED state function.
ph_set_name
void ph_set_name(ph_t *ctx, char *p_dev_name, char *p_resp)
Set name function.
ph_cfg_t::uart_blocking
bool uart_blocking
Definition: ph.h:196
ph_find_dev
void ph_find_dev(ph_t *ctx, char *p_resp)
Find device function.
ph_chk_slope
void ph_chk_slope(ph_t *ctx, char *p_resp)
Check slope function.
ph_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ph.h:199
ph_set_temp_comp
void ph_set_temp_comp(ph_t *ctx, float flt_val, char *p_resp)
Set Temperature Compensation function.
ph_clr_log_buf
void ph_clr_log_buf(char *p_str)
Clear log buffer function.
ph_uart_read_until
void ph_uart_read_until(ph_t *ctx, char *p_rx_data, char *delim)
UART read until delimiter function.
PH_ERROR
@ PH_ERROR
Definition: ph.h:210
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
pH driver buffer size.
Definition: ph.h:145
ph_check_protocol_lock
void ph_check_protocol_lock(ph_t *ctx, char *p_resp)
Check Protocol Lock function.
ph_get_dev_info
void ph_get_dev_info(ph_t *ctx, char *p_resp)
Get Device Information function.
ph_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ph.h:198
ph_get_temp_comp
void ph_get_temp_comp(ph_t *ctx, char *p_resp)
Get Temperature Compensation function.
ph_import_calib
void ph_import_calib(ph_t *ctx, uint8_t *in_calib, char *p_resp)
Import calibration data function.
ph_switch_led
void ph_switch_led(ph_t *ctx, uint8_t state, char *p_resp)
Toggle LED function.
ph_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ph.h:197
ph_chk_cont_read
void ph_chk_cont_read(ph_t *ctx, char *p_resp)
Check Continous read settings function.
ph_factory_rst
void ph_factory_rst(ph_t *ctx, char *p_resp)
Perform Factory Reset function.
ph_check_status
void ph_check_status(ph_t *ctx, char *p_resp)
Check Device Status function.
ph_generic_write
err_t ph_generic_write(ph_t *ctx, uint8_t *data_buf, uint16_t len)
pH data writing function.
ph_uart_write
void ph_uart_write(ph_t *ctx, uint8_t input)
UART Write Single Byte function.
ph_t
pH Click context object.
Definition: ph.h:174
PH_OK
@ PH_OK
Definition: ph.h:209
ph_perf_calib
void ph_perf_calib(ph_t *ctx, char *point, float flt_val, char *p_resp)
Perform Calibration function.
ph_cfg_t::baud_rate
uint32_t baud_rate
Definition: ph.h:195
ph_single_read
void ph_single_read(ph_t *ctx, char *p_resp)
Perform single read function.
ph_cfg_setup
void ph_cfg_setup(ph_cfg_t *cfg)
pH configuration object setup function.
ph_generic_read
err_t ph_generic_read(ph_t *ctx, uint8_t *data_buf, uint16_t max_len)
pH data reading function.
ph_sleep
void ph_sleep(ph_t *ctx)
Enter Sleep mode function.
ph_chng_baud_rate
void ph_chng_baud_rate(ph_t *ctx, char *baud_rate, char *p_resp)
Change Baud Rate function.
ph_return_value_t
ph_return_value_t
pH Click return value data.
Definition: ph.h:208
ph_chk_baud_rate
void ph_chk_baud_rate(ph_t *ctx, char *p_resp)
Check Baud Rate applied function.
ph_default_cfg
err_t ph_default_cfg(ph_t *ctx)
pH default configuration function.
ph_show_name
void ph_show_name(ph_t *ctx, char *p_dev_name)
Show Device Name function.
ph_init
err_t ph_init(ph_t *ctx, ph_cfg_t *cfg)
pH initialization function.
ph_cfg_t
pH Click configuration object.
Definition: ph.h:189
ph_send_cmd
void ph_send_cmd(ph_t *ctx, char *p_cmd)
Send command function.