|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +// Copyright (c) 2025 The Pybricks Authors |
| 3 | + |
| 4 | +/** |
| 5 | + * @addtogroup SystemHost System: Host |
| 6 | + * @{ |
| 7 | + */ |
| 8 | + |
| 9 | +#ifndef _PBSYS_HOST_H_ |
| 10 | +#define _PBSYS_HOST_H_ |
| 11 | + |
| 12 | +#include <stdbool.h> |
| 13 | +#include <stdint.h> |
| 14 | + |
| 15 | +#include <pbio/error.h> |
| 16 | +#include <pbsys/config.h> |
| 17 | + |
| 18 | +/** |
| 19 | + * Callback function to handle stdin events. |
| 20 | + * @param [in] c the character received |
| 21 | + * @return *true* if the character was handled and should not be placed |
| 22 | + * in the stdin buffer, otherwise *false*. |
| 23 | + */ |
| 24 | +typedef bool (*pbsys_host_stdin_event_callback_t)(uint8_t c); |
| 25 | + |
| 26 | +#if PBSYS_CONFIG_HOST |
| 27 | + |
| 28 | +void pbsys_host_init(void); |
| 29 | +void pbsys_host_rx_set_callback(pbsys_host_stdin_event_callback_t callback); |
| 30 | +void pbsys_host_rx_flush(void); |
| 31 | +uint32_t pbsys_host_rx_get_available(void); |
| 32 | +uint32_t pbsys_host_rx_get_free(void); |
| 33 | +void pbsys_host_rx_write(const uint8_t *data, uint32_t size); |
| 34 | +pbio_error_t pbsys_host_rx(uint8_t *data, uint32_t *size); |
| 35 | +pbio_error_t pbsys_host_tx(const uint8_t *data, uint32_t *size); |
| 36 | +bool pbsys_host_tx_is_idle(void); |
| 37 | + |
| 38 | +#else // PBSYS_CONFIG_HOST |
| 39 | + |
| 40 | +#define pbsys_host_init() |
| 41 | +#define pbsys_host_rx_set_callback(callback) |
| 42 | +#define pbsys_host_rx_flush() |
| 43 | +#define pbsys_host_rx_get_available() 0 |
| 44 | +#define pbsys_host_rx_get_free() 0 |
| 45 | +#define pbsys_host_rx_write(data, size) |
| 46 | + |
| 47 | +static inline pbio_error_t pbsys_host_rx(uint8_t *data, uint32_t *size) { |
| 48 | + return PBIO_ERROR_NOT_SUPPORTED; |
| 49 | +} |
| 50 | +static inline pbio_error_t pbsys_host_tx(const uint8_t *data, uint32_t *size) { |
| 51 | + return PBIO_ERROR_NOT_SUPPORTED; |
| 52 | +} |
| 53 | +static inline bool pbsys_host_tx_is_idle(void) { |
| 54 | + return false; |
| 55 | +} |
| 56 | + |
| 57 | +#endif // PBSYS_CONFIG_HOST |
| 58 | + |
| 59 | +#endif // _PBSYS_HOST_H_ |
| 60 | + |
| 61 | +/** @} */ |
0 commit comments