ata6571  2.0.0.0
ata6571.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 ATA6571_H
29 #define ATA6571_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 ATA6571_OPERATING_MODE_SLEEP 0x00
70 #define ATA6571_OPERATING_MODE_STANDBY 0x01
71 #define ATA6571_OPERATING_MODE_SILENT 0x02
72 #define ATA6571_OPERATING_MODE_NORMAL 0x03
73 
78 #define ATA6571_PIN_STATE_LOW 0x00
79 #define ATA6571_PIN_STATE_HIGH 0x01
80 
86 #define DRV_BUFFER_SIZE 200
87  // ata6571_set
89 
104 #define ATA6571_MAP_MIKROBUS( cfg, mikrobus ) \
105  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
106  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
107  cfg.nstb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108  cfg.nerr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS );
110  // ata6571_map // ata6571
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t nstb;
122  digital_out_t en;
124  // Input pins
125  digital_in_t nerr;
127  // Modules
128  uart_t uart;
130  // Buffers
131  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
132  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
134 } ata6571_t;
135 
140 typedef struct
141 {
142  // Communication gpio pins
143  pin_name_t rx_pin;
144  pin_name_t tx_pin;
146  // Additional gpio pins
147  pin_name_t nstb;
148  pin_name_t nerr;
149  pin_name_t en;
151  // Static variable
152  uint32_t baud_rate;
154  uart_data_bits_t data_bit;
155  uart_parity_t parity_bit;
156  uart_stop_bits_t stop_bit;
158 } ata6571_cfg_t;
159 
164 typedef enum
165 {
167  ATA6571_ERROR = -1
168 
170 
187 
202 err_t ata6571_init ( ata6571_t *ctx, ata6571_cfg_t *cfg );
203 
217 err_t ata6571_generic_write ( ata6571_t *ctx, char *data_buf, uint16_t len );
218 
232 err_t ata6571_generic_read ( ata6571_t *ctx, char *data_buf, uint16_t max_len );
233 
243 void ata6571_set_nstb_pin ( ata6571_t *ctx, uint8_t state );
244 
254 void ata6571_set_en_pin ( ata6571_t *ctx, uint8_t state );
255 
265 
278 void ata6571_set_operating_mode ( ata6571_t *ctx, uint8_t op_mode );
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // ATA6571_H
284  // ata6571
286 
287 // ------------------------------------------------------------------------ END
ata6571_cfg_setup
void ata6571_cfg_setup(ata6571_cfg_t *cfg)
ATA6571 configuration object setup function.
ATA6571_OK
@ ATA6571_OK
Definition: ata6571.h:166
ata6571_get_nerr_pin
uint8_t ata6571_get_nerr_pin(ata6571_t *ctx)
ATA6571 get error and power-on indication output function.
ata6571_set_nstb_pin
void ata6571_set_nstb_pin(ata6571_t *ctx, uint8_t state)
ATA6571 set standby mode control function.
ata6571_generic_read
err_t ata6571_generic_read(ata6571_t *ctx, char *data_buf, uint16_t max_len)
ATA6571 data reading function.
ata6571_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ata6571.h:154
ata6571_return_value_t
ata6571_return_value_t
ATA6571 Click return value data.
Definition: ata6571.h:165
ata6571_cfg_t::uart_blocking
bool uart_blocking
Definition: ata6571.h:153
ata6571_t::uart
uart_t uart
Definition: ata6571.h:128
ata6571_t
ATA6571 Click context object.
Definition: ata6571.h:119
ATA6571_ERROR
@ ATA6571_ERROR
Definition: ata6571.h:167
ata6571_t::nstb
digital_out_t nstb
Definition: ata6571.h:121
ata6571_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ata6571.h:144
ata6571_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ata6571.h:155
ata6571_cfg_t
ATA6571 Click configuration object.
Definition: ata6571.h:141
ata6571_generic_write
err_t ata6571_generic_write(ata6571_t *ctx, char *data_buf, uint16_t len)
ATA6571 data writing function.
ata6571_t::en
digital_out_t en
Definition: ata6571.h:122
ata6571_cfg_t::nerr
pin_name_t nerr
Definition: ata6571.h:148
ata6571_cfg_t::nstb
pin_name_t nstb
Definition: ata6571.h:147
ata6571_set_en_pin
void ata6571_set_en_pin(ata6571_t *ctx, uint8_t state)
ATA6571 set power control function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
ATA6571 driver buffer size.
Definition: ata6571.h:86
ata6571_t::nerr
digital_in_t nerr
Definition: ata6571.h:125
ata6571_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ata6571.h:143
ata6571_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ata6571.h:156
ata6571_cfg_t::en
pin_name_t en
Definition: ata6571.h:149
ata6571_cfg_t::baud_rate
uint32_t baud_rate
Definition: ata6571.h:152
ata6571_set_operating_mode
void ata6571_set_operating_mode(ata6571_t *ctx, uint8_t op_mode)
ATA6571 set operating mode function.
ata6571_init
err_t ata6571_init(ata6571_t *ctx, ata6571_cfg_t *cfg)
ATA6571 initialization function.