~aleteoryx/muditaos

muditaos/module-bluetooth/Bluetooth/glucode/btstack_uart_block_rt1051.cpp -rw-r--r-- 3.5 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <bsp/bluetooth/Bluetooth.hpp>
#include <log/log.hpp>

using namespace bsp;

extern "C"
{
#include "btstack_uart_block_rt1051.h"
#include <hci_transport.h>
#include <btstack_run_loop.h>
#include <btstack_uart_block.h>
#include <btstack_run_loop_freertos.h>
}

// #define DEBUG_UART

namespace
{
    // and it's hci_transport_config_uart_t which is a bit different...
    int uart_rt1051_init([[maybe_unused]] const btstack_uart_config_t *config)
    {
        LOG_INFO("Create BlueKitchen interface");
        BlueKitchen::getInstance();
        return 0;
    }

    int uart_rt1051_open()
    {
        LOG_INFO("BlueKitchen UART open");
        BlueKitchen::getInstance().open();
        return 0;
    }

    int uart_rt1051_close()
    {
        LOG_INFO("BlueKitchen UART close");
        BlueKitchen::getInstance().close();
        return 0;
    }

    void uart_rt1051_set_block_received(void (*handler)())
    {
        BlueKitchen::getInstance().readReadyCallback = handler;
    }

    void uart_rt1051_set_block_sent(void (*handler)())
    {
        BlueKitchen::getInstance().writeDoneCallback = handler;
    }

    int uart_rt1051_set_baudrate(std::uint32_t baudrate)
    {
        BlueKitchen::getInstance().setBaudrate(baudrate);
        return 0;
    }

    int uart_rt1051_set_parity(int parity)
    {
        // Not implemented
        LOG_INFO("BlueKitchen set pairity: %d", parity);
        return 0;
    }

    void uart_rt1051_receive_block(std::uint8_t *buffer, std::uint16_t len)
    {
#ifdef DEBUG_UART
        LOG_DEBUG("<-- read: %d", len);
#endif
        BlueKitchen::getInstance().read(buffer, len);
    }

    void uart_rt1051_send_block(const uint8_t *buffer, uint16_t length)
    {
#ifdef DEBUG_UART
        LOG_DEBUG("--> write: %d", length);
#endif
        BlueKitchen::getInstance().write(buffer, length);
    }

    int btstack_uart_rt1051_get_supported_sleep_modes()
    {
        return BTSTACK_UART_SLEEP_MASK_RTS_HIGH_WAKE_ON_CTS_PULSE;
    }

    void btstack_uart_rt1051_set_sleep([[maybe_unused]] btstack_uart_sleep_mode_t sleep_mode)
    {}

    void btstack_uart_rt1051_set_wakeup_handler([[maybe_unused]] void (*wakeup_handler)())
    {}

    const btstack_uart_block_t btstack_uart_posix = {
        /* int  (*init)(hci_transport_config_uart_t * config); */ uart_rt1051_init,
        /* int  (*open)(void); */ uart_rt1051_open,
        /* int  (*close)(void); */ uart_rt1051_close,
        /* void (*set_block_received)(void (*handler)(void)); */ uart_rt1051_set_block_received,
        /* void (*set_block_sent)(void (*handler)(void)); */ uart_rt1051_set_block_sent,
        /* int  (*set_baudrate)(uint32_t baudrate); */ uart_rt1051_set_baudrate,
        /* int  (*set_parity)(int parity); */ uart_rt1051_set_parity,
        /* int  (*set_flowcontrol)(int flowcontrol); */ nullptr,
        /* void (*receive_block)(uint8_t *buffer, uint16_t len); */ uart_rt1051_receive_block,
        /* void (*send_block)(const uint8_t *buffer, uint16_t length); */ uart_rt1051_send_block,
        /* int (*get_supported_sleep_modes)(); */ btstack_uart_rt1051_get_supported_sleep_modes,
        /* void (*set_sleep)(btstack_uart_sleep_mode_t sleep_mode); */ btstack_uart_rt1051_set_sleep,
        /* void (*set_wakeup_handler)(void (*handler)(void)); */ btstack_uart_rt1051_set_wakeup_handler,
    };
} // namespace

const btstack_uart_block_t *btstack_uart_block_rt1051_instance()
{
    return &btstack_uart_posix;
}