aboutsummaryrefslogtreecommitdiff
path: root/arch/casiowin/fxlib/include/fxlib/comm.h
blob: ec8ba6d6d7e3c706aae1aeb8e94ea12594f4594e (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* ****************************************************************************
 * fxlib/comm.h -- fxlib's communication management.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'casiowin/fxlib' module,
 * in libcarrot, an experimental modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include <fxlib/cdefs.h>
#include <commbios.h>
#if __USE_FXLIB_UNOFFICIAL
__BEGIN_NAMESPACE_FXLIB
__BEGIN_DECLS

/* ************************************************************************* */
/*  Basic functions                                                          */
/* ************************************************************************* */
/* Open the communication, using flags */
extern int Comm_Open _OF((unsigned short __flags)) __THROW;
extern int Comm_OpenSerial _OF((unsigned short __flags)) __THROW;
# define Serial_OpenFromComm(_FLAGS) Comm_OpenSerial(_FLAGS)
# define Serial_Open2(_FLAGS)        Comm_OpenSerial(_FLAGS)

/* Close the communication */
extern int Comm_Close _OF((int __immediate)) __THROW;

/* Check the communication status */
extern int Comm_IsUSB _OF((void)) __THROW;
# define Comm_GetCurrentSelector() Comm_IsUSB()
/* ************************************************************************* */
/*  Raw communication utilities                                              */
/* ************************************************************************* */
/* receive data */
extern __nonnull(1, __result) int Comm_SpyByte   _OF((unsigned char *__result))
	__THROW;
extern __nonnull(1, __result) int Comm_ReadByte  _OF((unsigned char *__result))
	__THROW;
extern __nonnull(1, __buffer) int Comm_ReadBytes _OF((char *__buffer,
	int __count)) __THROW;
# define Comm_Spy0thByte(_RES) \
	Comm_SpyByte(_RES)
# define Comm_ReadOneByte(__BUF) \
	Comm_ReadByte(__BUF)
# define Comm_WaitForAndReadNBytes(__BUF, __COUNT) \
	Comm_ReadBytes(__BUF, __COUNT)

/* send data */
extern int Comm_SendByte  _OF((unsigned char __byte)) __THROW;
extern __nonnull(1, __buffer) int Comm_SendBytes OF((unsigned char *__buffer,
	int requested_count)) __THROW;
# define Comm_TransmitOneByte(_BYTE) \
	Comm_SendByte(_BYTE)
# define Comm_TransmitNBytes(__BUF, __COUNT) \
	Comm_SendBytes(__BUF, __COUNT)
# define Comm_TransmitBytes(__BUF, __COUNT) \
	Comm_TransmitBytes(__BUF, __COUNT)

/* wait for data to be transmitted, or for a buffer to be sent */
extern int Comm_WaitForAnyBuffer _OF((int __timeout, int __receive,
	int *__time)) __THROW;
# define Comm_Drain(__TIMEOUT, __TIME) \
	Comm_WaitForAnyBuffer(__TIMEOUT, 0, __TIME)
# define Comm_Wait(__TIMEOUT, __TIME) \
	Comm_WaitForAnyBuffer(__TIMEOUT, 1, __TIME)
/* ************************************************************************* */
/*  Protocol 7 utilities                                                     */
/* ************************************************************************* */
/* ASCII-HEX/binary conversions */
extern __nonnull(1, __value) __nonnull(2, __result)
void Comm_HexToByte _OF((unsigned char  *__value,
	unsigned char *__result)) __THROW;
extern __nonnull(1, __value) __nonnull(2, __result)
void Comm_HexToWord _OF((unsigned short *__value,
	unsigned short *__result)) __THROW;
extern __nonnull(2, __result)
void Comm_ByteToHex _OF((unsigned char   __value,
	unsigned char *__result)) __THROW;
extern __nonnull(2, __result)
void Comm_WordToHex _OF((unsigned short  __value,
	unsigned char *__result)) __THROW;

/* And some macros */
# define HexToByte(_VAL, _RES) Comm_HexToByte(_VAL, _RES)
# define HexToWord(_VAL, _RES) Comm_HexToWord(_VAL, _RES)
# define ByteToHex(_VAL, _RES) Comm_ByteToHex(_VAL, _RES)
# define WordToHex(_VAL, _RES) Comm_WordToHex(_VAL, _RES)

/* Padding utilities (useful for data packet content) */
extern __nonnull(1, __source) __nonnull(3, __dest) __nonnull(4, __count)
int Comm_Padding_5C _OF((const unsigned char *__source,
	unsigned short __n, unsigned char *__dest, unsigned short *__count))
	__THROW;
extern __nonnull(1, __source) __nonnull(3, __dest) __nonnull(4, __count)
int Comm_ReversePadding_5C _OF((const unsigned char *__source,
	unsigned short __n, unsigned char *__dest, unsigned short *__count))
	__THROW;
/* ************************************************************************* */
/*  Protocol 7 packet management functions                                   */
/* ************************************************************************* */
/* Get a packet */
extern __nonnull(1, __type)
int Comm_IsValidPacketAvailable _OF((unsigned char *__type)) __THROW;
extern __nonnull(1, __packet)
int Comm_GetPacket _OF((comm_packet_t *__packet)) __THROW;

/* Prepare a packet */
extern __nonnull(1, __packet) __nonnull(3, __data)
int Comm_PrepareAckPacket _OF((comm_packet_t *__packet,
	unsigned char __subtype, void *__data, unsigned short __size)) __THROW;
extern __nonnull(1, __packet)
int Comm_PrepareErrorPacket _OF((comm_packet_t *__packet,
	unsigned char __subtype)) __THROW;
extern __nonnull(1, __packet)
int Comm_PrepareTerminatePacket _OF((comm_packet_t *__packet,
	unsigned char __subtype)) __THROW;
extern __nonnull(1, __packet)
int Comm_PrepareRoleswapPacket _OF((comm_packet_t *__packet,
	unsigned char __subtype)) __THROW;
extern __nonnull(1, __packet)
int Comm_PrepareCheckPacket _OF((comm_packet_t *__packet,
	unsigned char __subtype)) __THROW;
extern __nonnull(1, __packet) __nonnull(3, __data)
int Comm_PrepareCommandPacket _OF((comm_packet_t *__packet,
	unsigned char __subtype, void *__data, unsigned short __size)) __THROW;
extern __nonnull(1, __packet) __nonnull(3, __data)
int Comm_PrepareDataPacket _OF((comm_packet_t *__packet,
	unsigned char subtype, void *__data, unsigned short __size)) __THROW;

/* Send a prepared packet */
extern int Comm_SendPacket _OF((comm_packet_t *__packet));

/* Send an OHP (TYP01) packet */
extern void AutoImageTransfer_OHP _OF((void));
extern void USB_CaptureDisplay    _OF((void));

__END_DECLS
__END_NAMESPACE_FXLIB
#endif