xref: /btstack/src/btstack_uart_block.h (revision 084ad01c1a9e12f0da3d2691f48405bf30ddf87a)
1b52fe020SMatthias Ringwald /*
2b52fe020SMatthias Ringwald  * Copyright (C) 2016 BlueKitchen GmbH
3b52fe020SMatthias Ringwald  *
4b52fe020SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5b52fe020SMatthias Ringwald  * modification, are permitted provided that the following conditions
6b52fe020SMatthias Ringwald  * are met:
7b52fe020SMatthias Ringwald  *
8b52fe020SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9b52fe020SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10b52fe020SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11b52fe020SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12b52fe020SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13b52fe020SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14b52fe020SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15b52fe020SMatthias Ringwald  *    from this software without specific prior written permission.
16b52fe020SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17b52fe020SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18b52fe020SMatthias Ringwald  *    monetary gain.
19b52fe020SMatthias Ringwald  *
20b52fe020SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21b52fe020SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22b52fe020SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23b52fe020SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24b52fe020SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25b52fe020SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26b52fe020SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27b52fe020SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28b52fe020SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29b52fe020SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30b52fe020SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b52fe020SMatthias Ringwald  * SUCH DAMAGE.
32b52fe020SMatthias Ringwald  *
33b52fe020SMatthias Ringwald  * Please inquire about commercial licensing options at
34b52fe020SMatthias Ringwald  * [email protected]
35b52fe020SMatthias Ringwald  *
36b52fe020SMatthias Ringwald  */
37b52fe020SMatthias Ringwald 
38b52fe020SMatthias Ringwald /*
39b52fe020SMatthias Ringwald  *  btstack_uart_block.h
40b52fe020SMatthias Ringwald  *
41b52fe020SMatthias Ringwald  *  Common code to access serial port via asynchronous block read/write commands
42b52fe020SMatthias Ringwald  *
43b52fe020SMatthias Ringwald  */
44b52fe020SMatthias Ringwald 
45b52fe020SMatthias Ringwald #ifndef __BTSTACK_UART_BLOCK_H
46b52fe020SMatthias Ringwald #define __BTSTACK_UART_BLOCK_H
47b52fe020SMatthias Ringwald 
48b52fe020SMatthias Ringwald #include <stdint.h>
49*084ad01cSMatthias Ringwald 
50*084ad01cSMatthias Ringwald typedef struct {
51*084ad01cSMatthias Ringwald     uint32_t   baudrate;
52*084ad01cSMatthias Ringwald     int        flowcontrol;
53*084ad01cSMatthias Ringwald     const char *device_name;
54*084ad01cSMatthias Ringwald } btstack_uart_config_t;
55b52fe020SMatthias Ringwald 
56b52fe020SMatthias Ringwald typedef struct {
57b52fe020SMatthias Ringwald     /**
58b52fe020SMatthias Ringwald      * init transport
59*084ad01cSMatthias Ringwald      * @param uart_config
60b52fe020SMatthias Ringwald      */
61*084ad01cSMatthias Ringwald     int (*init)(const btstack_uart_config_t * uart_config);
62b52fe020SMatthias Ringwald 
63b52fe020SMatthias Ringwald     /**
64b52fe020SMatthias Ringwald      * open transport connection
65b52fe020SMatthias Ringwald      */
66b52fe020SMatthias Ringwald     int (*open)(void);
67b52fe020SMatthias Ringwald 
68b52fe020SMatthias Ringwald     /**
69b52fe020SMatthias Ringwald      * close transport connection
70b52fe020SMatthias Ringwald      */
71b52fe020SMatthias Ringwald     int (*close)(void);
72b52fe020SMatthias Ringwald 
73b52fe020SMatthias Ringwald     /**
74b52fe020SMatthias Ringwald      * set callback for block received
75b52fe020SMatthias Ringwald      */
76b52fe020SMatthias Ringwald     void (*set_block_received)(void (*block_handler)(void));
77b52fe020SMatthias Ringwald 
78b52fe020SMatthias Ringwald     /**
79b52fe020SMatthias Ringwald      * set callback for sent
80b52fe020SMatthias Ringwald      */
81b52fe020SMatthias Ringwald     void (*set_block_sent)(void (*block_handler)(void));
82b52fe020SMatthias Ringwald 
83b52fe020SMatthias Ringwald     /**
84b52fe020SMatthias Ringwald      * set baudrate
85b52fe020SMatthias Ringwald      */
86b52fe020SMatthias Ringwald     int (*set_baudrate)(uint32_t baudrate);
87b52fe020SMatthias Ringwald 
88b52fe020SMatthias Ringwald     /**
89b52fe020SMatthias Ringwald      * set parity
90b52fe020SMatthias Ringwald      */
91b52fe020SMatthias Ringwald     int  (*set_parity)(int parity);
92b52fe020SMatthias Ringwald 
93b52fe020SMatthias Ringwald     /**
94b52fe020SMatthias Ringwald      * receive block
95b52fe020SMatthias Ringwald      */
96b52fe020SMatthias Ringwald     void (*receive_block)(uint8_t *buffer, uint16_t len);
97b52fe020SMatthias Ringwald 
98b52fe020SMatthias Ringwald     /**
99b52fe020SMatthias Ringwald      * send block
100b52fe020SMatthias Ringwald      */
101b52fe020SMatthias Ringwald     void (*send_block)(const uint8_t *buffer, uint16_t length);
102b52fe020SMatthias Ringwald 
103b52fe020SMatthias Ringwald     // void hal_uart_dma_set_sleep(uint8_t sleep);
104b52fe020SMatthias Ringwald     // void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void));
105b52fe020SMatthias Ringwald 
106b52fe020SMatthias Ringwald } btstack_uart_block_t;
107b52fe020SMatthias Ringwald 
108b52fe020SMatthias Ringwald // common implementations
109b52fe020SMatthias Ringwald const btstack_uart_block_t * btstack_uart_block_posix_instance(void);
110*084ad01cSMatthias Ringwald const btstack_uart_block_t * btstack_uart_block_embedded_instance(void);
111b52fe020SMatthias Ringwald 
112b52fe020SMatthias Ringwald #endif
113