2 * This file is part of the libjaylink project.
4 * Copyright (C) 2016 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libjaylink.h"
29 * String utility functions.
33 * Convert a string representation of a serial number to an integer.
35 * The string representation of the serial number must be in decimal form.
37 * @param[in] str String representation to convert.
38 * @param[out] serial_number Serial number on success, and undefined on
41 * @retval JAYLINK_OK Success.
42 * @retval JAYLINK_ERR_ARG Invalid arguments.
43 * @retval JAYLINK_ERR Conversion error. Serial number is invalid or string
44 * representation contains invalid character(s).
48 JAYLINK_API
int jaylink_parse_serial_number(const char *str
,
49 uint32_t *serial_number
)
52 unsigned long long tmp
;
54 if (!str
|| !serial_number
)
55 return JAYLINK_ERR_ARG
;
58 tmp
= strtoull(str
, &end_ptr
, 10);
60 if (*end_ptr
!= '\0' || errno
!= 0 || tmp
> UINT32_MAX
)
69 * Get the string representation of a hardware type.
71 * @param[in] type Hardware type.
73 * @return The string representation of the given hardware type, or NULL
74 * for an unknown type.
78 JAYLINK_API
const char *jaylink_hardware_type_string(
79 enum jaylink_hardware_type type
)
82 case JAYLINK_HW_TYPE_JLINK
:
84 case JAYLINK_HW_TYPE_FLASHER
:
86 case JAYLINK_HW_TYPE_JLINK_PRO
:
96 * Get the string representation of a target interface.
98 * @param[in] iface Target interface.
100 * @return The string representation of the given target interface, or NULL
101 * for an unknown interface.
105 JAYLINK_API
const char *jaylink_target_interface_string(
106 enum jaylink_target_interface iface
)
109 case JAYLINK_TIF_JTAG
:
111 case JAYLINK_TIF_SWD
:
113 case JAYLINK_TIF_BDM3
:
115 case JAYLINK_TIF_FINE
:
117 case JAYLINK_TIF_2W_JTAG_PIC32
:
118 return "2-wire JTAG for PIC32";
119 case JAYLINK_TIF_SPI
:
123 case JAYLINK_TIF_CJTAG
: