libnile
Loading...
Searching...
No Matches
cdc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, 2024, 2025 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
23#ifndef NILE_MCU_CDC_H_
24#define NILE_MCU_CDC_H_
25
26#include "../mcu.h"
27
28static inline int16_t nile_mcu_native_cdc_read_sync(void __wf_cram* buffer, uint16_t buflen) {
29 int16_t result;
30 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x40, buflen), NULL, 0)) < 0) return result;
31 return nile_mcu_native_recv_cmd(buffer, buflen);
32}
33
34static inline int16_t nile_mcu_native_cdc_write_sync(const void __far* buffer, uint16_t buflen) {
35 int16_t result, bytes = 0;
36 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x41, buflen), buffer, buflen)) < 0) return result;
37 if ((result = nile_mcu_native_recv_cmd(&bytes, 2)) <= 0) return result;
38 return bytes;
39}
40
41static inline int16_t nile_mcu_native_cdc_write_async_start(const void __far* buffer, uint16_t buflen) {
42 int16_t result;
43 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x41, buflen), buffer, buflen)) < 0) return result;
45}
46#define nile_mcu_native_cdc_write_async_finish nile_mcu_native_recv_cmd_response_int16
47
48static inline int16_t nile_mcu_native_cdc_available_sync(void) {
49 int16_t result, bytes = 0;
50 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x43, 0), NULL, 0)) < 0) return result;
51 if ((result = nile_mcu_native_recv_cmd(&bytes, 2)) <= 0) return result;
52 return bytes;
53}
54
55static inline int16_t nile_mcu_native_cdc_available_async_start(void) {
56 int16_t result;
57 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x43, 0), NULL, 0)) < 0) return result;
59}
60#define nile_mcu_native_cdc_available_async_finish nile_mcu_native_recv_cmd_response_int16
61
62static inline int16_t nile_mcu_native_cdc_clear_sync(void) {
63 int16_t result;
64 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x44, 0xFF), NULL, 0)) < 0) return result;
65 return nile_mcu_native_recv_cmd(NULL, 0);
66}
67
68#endif /* NILE_MCU_CDC_H_ */
static int16_t nile_mcu_native_cdc_available_async_start(void)
Definition cdc.h:55
static int16_t nile_mcu_native_cdc_write_async_start(const void __far *buffer, uint16_t buflen)
Definition cdc.h:41
static int16_t nile_mcu_native_cdc_write_sync(const void __far *buffer, uint16_t buflen)
Definition cdc.h:34
static int16_t nile_mcu_native_cdc_read_sync(void __wf_cram *buffer, uint16_t buflen)
Definition cdc.h:28
static int16_t nile_mcu_native_cdc_available_sync(void)
Definition cdc.h:48
static int16_t nile_mcu_native_cdc_clear_sync(void)
Definition cdc.h:62
int16_t nile_mcu_native_recv_cmd(void __far *buffer, uint16_t buflen)
Receive the response of a "native protocol" MCU command synchronously.
#define NILE_MCU_NATIVE_CMD(cmd, arg)
Definition mcu.h:55
int16_t nile_mcu_native_recv_cmd_start(uint16_t resplen)
Start receiving the response of a "native protocol" MCU command asynchronously.
static int16_t nile_mcu_native_send_cmd(uint16_t cmd, const void __far *buffer, int buflen)
Send a "native protocol" MCU command asynchronously.
Definition mcu.h:163