cake
/
libcasio
Archived
1
1
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libcasio/include/libcasio/link.h

223 lines
6.9 KiB
C

/* ****************************************************************************
* libcasio/link.h -- libcasio communications part.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.0 of the License,
* or (at your option) any later version.
*
* libcasio 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 Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_LINK_H
# define LIBCASIO_LINK_H
# include "cdefs.h"
# include "stream.h"
# include "mcs.h"
# include "fs.h"
# include "version.h"
# include "picture.h"
# include "iter.h"
# ifndef LIBCASIO_DISABLED_FILE
# include <stdio.h>
# endif
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_link, casio_link_t)
CASIO_STRUCT(casio_link_info, casio_link_info_t)
CASIO_STRUCT(casio_screen, casio_screen_t)
/* ---
* Link and link information.
* --- */
/* The link structure is private, as it contains diiiirty things.
* You should only manipulate pointers to it (unless you're contributing
* to libcasio). */
/* Link information.
* This is basically the identification information sent by the calculator,
* only in Protocol 7.00 (Graph 85 and following) and CAS100 (AFX,
* Graph 100).
*
* TODO: make flags for other information not available for AFX? */
# define casio_link_info_flag_preprog 0x0001
# define casio_link_info_flag_bootcode 0x0002
# define casio_link_info_flag_os 0x0004
struct casio_link_info {
unsigned long casio_link_info_flags;
/* Preprogrammed ROM information. */
unsigned long casio_link_info_rom_capacity;
casio_version_t casio_link_info_rom_version;
/* Flash ROM and RAM information. */
unsigned long casio_link_info_flash_rom_capacity;
unsigned long casio_link_info_ram_capacity;
/* Bootcode information. */
casio_version_t casio_link_info_bootcode_version;
unsigned long casio_link_info_bootcode_offset;
unsigned long casio_link_info_bootcode_size;
/* OS information. */
casio_version_t casio_link_info_os_version;
unsigned long casio_link_info_os_offset;
unsigned long casio_link_info_os_size;
/* Other information. */
char casio_link_info_product_id[17];
char casio_link_info_username[17];
char casio_link_info_hwid[9];
char casio_link_info_cpuid[17];
};
/* ---
* Basic callbacks.
* --- */
/* The user shall confirm or not a link action. */
typedef CASIO_HOOK_TYPE(int) casio_link_confirm_t
OF((void *casio__cookie));
/* This callback is for displaying the progress of an operation (usually
* file/data transfer). It receives the packet ID and the total number of
* packets. For initialization of the display, this callback is called
* with a packet ID superior to the number of packets. */
typedef CASIO_HOOK_TYPE(void) casio_link_progress_t
OF((void *casio__cookie, unsigned int casio__id,
unsigned int casio__total));
/* ---
* Basic link handle operations.
* --- */
/* Useful flags for when opening a link.
*
* These are read if the connexion is serial (which means that the
* protocol cannot be determined and that the user needs to say which one
* they want to use):
*
* `CASIO_LINKFLAG_CAS40`: CAS40 (very old protocol).
* `CASIO_LINKFLAG_CAS50`: CAS50 (old protocol).
* `CASIO_LINKFLAG_CAS100`: CAS100 (not so old protocol used on the AFX).
* `CASIO_LINKFLAG_P7`: protocol 7.00 (starting to get old but still there).
*
* These are read if the protocol is protocol 7.00:
*
* `CASIO_LINKFLAG_PASSIVE`: start off as active.
* `CASIO_LINKFLAG_NOCHECK`: check (initial packet).
* `CASIO_LINKFLAG_NODISC`: if we are checking, no environment discovery.
* `CASIO_LINKFLAG_TERM`: terminate. */
# define CASIO_LINKFLAG_P7 0x00000100
# define CASIO_LINKFLAG_CAS40 0x00000200
# define CASIO_LINKFLAG_CAS50 0x00000400
# define CASIO_LINKFLAG_CAS100 0x00000600
# define CASIO_LINKFLAG_SCSI 0x00000800
# define CASIO_LINKFLAG_PASSIVE 0x00000001
# define CASIO_LINKFLAG_NOCHECK 0x00000002
# define CASIO_LINKFLAG_NODISC 0x00000004
# define CASIO_LINKFLAG_NOSHIFT 0x00000008
# define CASIO_LINKFLAG_TERM 0x00000010
CASIO_BEGIN_DECLS
/* Open a link. */
CASIO_EXTERN(int) casio_open_link
OF((casio_link_t **casio__h, unsigned long casio__flags,
tio_stream_t *casio__stream));
CASIO_EXTERN(int) casio_open_serial
OF((casio_link_t **casio__h, unsigned long casio__flags,
char const *casio__path, tio_serial_attrs_t const *casio__attributes));
CASIO_EXTERN(int) casio_open_usb
OF((casio_link_t **casio__h, unsigned long casio__flags,
int casio__bus, int casio__address));
/* De-initialize. */
CASIO_EXTERN(void) casio_close_link
OF((casio_link_t *casio__h));
/* Lock and unlock the associated mutex. */
CASIO_EXTERN(int) casio_lock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN(int) casio_trylock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN(void) casio_unlock_link
OF((casio_link_t *casio__h));
/* Getters. */
CASIO_EXTERN(casio_link_info_t const *) casio_get_link_info
OF((casio_link_t *casio__handle));
/* ---
* General-purpose link operations.
* --- */
/* Set the link settings. */
CASIO_EXTERN(int) casio_setlink
OF((casio_link_t *casio__handle, tio_serial_attrs_t const *casio__attrs));
/* Receive and free a screen streaming frame.
* The screen is a double pointer because it is allocated or reallocated
* when required only. */
CASIO_EXTERN(int) casio_get_screen
OF((casio_link_t *casio__handle, casio_picture_t **casio__screen));
/* Backup the ROM. */
CASIO_EXTERN(int) casio_backup_rom
OF((casio_link_t *casio__handle, tio_stream_t *casio__buffer,
casio_link_progress_t *casio__progress, void *casio__pcookie));
# ifndef LIBTIO_DISABLED_FILE
CASIO_EXTERN(int) casio_backup_rom_file
OF((casio_link_t *casio__handle, FILE *casio__file,
casio_link_progress_t *casio__progress, void *casio__pcookie));
# endif
/* Upload and run an executable. */
CASIO_EXTERN(int) casio_upload_and_run
OF((casio_link_t *casio__handle, tio_stream_t *casio__buffer,
unsigned long casio__loadaddr, unsigned long casio__straddr,
casio_link_progress_t *casio__disp, void *casio__pcookie));
# ifndef LIBTIO_DISABLED_FILE
CASIO_EXTERN(int) casio_upload_and_run_file
OF((casio_link_t *casio__handle, FILE *casio__program,
unsigned long casio__loadaddr, unsigned long casio__straddr,
casio_link_progress_t *casio__disp, void *casio__pcookie));
# endif
CASIO_END_DECLS
CASIO_END_NAMESPACE
# include "protocol/legacy.h"
# include "protocol/seven.h"
#endif /* LIBCASIO_LINK_H */