Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+41 -16
View File
@@ -1,5 +1,5 @@
#include <windows.h>
#include <setupapi.h>
#include <windows.h>
#include "ezusb/ezusb.h"
#include "ezusb/ezusbsys2.h"
@@ -36,39 +36,54 @@ static bool ezusb_reset(HANDLE handle, bool hold)
req.index = 0x0000;
}
if (!DeviceIoControl(handle, IOCTL_Ezusb_VENDOR_REQUEST, &req,
sizeof(req), &req, sizeof(req), &outpkt, NULL)) {
if (!DeviceIoControl(
handle,
IOCTL_Ezusb_VENDOR_REQUEST,
&req,
sizeof(req),
&req,
sizeof(req),
&outpkt,
NULL)) {
return false;
}
return true;
}
static bool ezusb_write_firmware(HANDLE handle, const void* buffer,
uint16_t ram_offset, uint32_t size)
static bool ezusb_write_firmware(
HANDLE handle, const void *buffer, uint16_t ram_offset, uint32_t size)
{
ANCHOR_DOWNLOAD_CONTROL req;
DWORD outpkt;
req.Offset = ram_offset;
if (!DeviceIoControl(handle, IOCTL_EZUSB_ANCHOR_DOWNLOAD, &req,
sizeof(req), (void*) buffer, size, &outpkt, NULL)) {
if (!DeviceIoControl(
handle,
IOCTL_EZUSB_ANCHOR_DOWNLOAD,
&req,
sizeof(req),
(void *) buffer,
size,
&outpkt,
NULL)) {
return false;
}
return true;
}
HANDLE ezusb_open(const char* path)
HANDLE
ezusb_open(const char *path)
{
log_assert(path);
return CreateFileA(path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
return CreateFileA(
path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident)
bool ezusb_get_ident(HANDLE handle, struct ezusb_ident *ident)
{
USB_DEVICE_DESCRIPTOR desc;
DWORD outpkt;
@@ -77,8 +92,15 @@ bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident)
log_assert(handle != INVALID_HANDLE_VALUE);
log_assert(ident);
if (!DeviceIoControl(handle, IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, &desc,
sizeof(desc), &desc, sizeof(desc), &outpkt, NULL)) {
if (!DeviceIoControl(
handle,
IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR,
&desc,
sizeof(desc),
&desc,
sizeof(desc),
&outpkt,
NULL)) {
return false;
}
@@ -89,7 +111,7 @@ bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident)
return true;
}
bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw)
bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware *fw)
{
log_assert(handle);
log_assert(handle != INVALID_HANDLE_VALUE);
@@ -100,8 +122,11 @@ bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw)
}
for (uint16_t i = 0; i < fw->segment_count; i++) {
if (!ezusb_write_firmware(handle, fw->segments[i]->data,
fw->segments[i]->offset, fw->segments[i]->size)) {
if (!ezusb_write_firmware(
handle,
fw->segments[i]->data,
fw->segments[i]->offset,
fw->segments[i]->size)) {
return false;
}
}
+17 -14
View File
@@ -1,17 +1,17 @@
/**
* Module for fundamental communication with a legacy Ezusb board, e.g.
* IIDX C02 IO.
*
*
* This module does not implement any sort of higher level protocol which is
* required by the games to exchange data with the device, e.g. getting input
* states of keys and setting light outputs. Further modules are utilizing this
* base layer to implement higher level communication.
*
*
* Note: This module requires the old "cyusb" driver which is NOT compatible
* with anything newer than WinXP and does not support 64-bit systems. The newer
* "cyusb3" driver does NOT work with this.
*
* @author icex2
*
* @author icex2
*/
#ifndef EZUSB_H
#define EZUSB_H
@@ -23,7 +23,10 @@
#include "ezusb/util.h"
static const GUID EZUSB_GUID = {0xAE18AA60, 0x7F6A, 0x11D4,
static const GUID EZUSB_GUID = {
0xAE18AA60,
0x7F6A,
0x11D4,
{0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}};
/* Used by IIDX instead of scanning for the device */
@@ -47,38 +50,38 @@ static const GUID EZUSB_GUID = {0xAE18AA60, 0x7F6A, 0x11D4,
* \\\\.\\Ezusb-3
* \\\\.\\Ezusb-4
* \\\\.\\Ezusb-5
*
*
* Where \\\\.\\Ezusb-X is used if slot X-1 is still occupied, e.g. when
* flashing the device and after a usb re-enumerate.
*
*
* @param device_path Path to the Ezusb device.
* @return A valid handle to the device on success, INVALID_HANDLE_VALUE on
* @return A valid handle to the device on success, INVALID_HANDLE_VALUE on
* error.
*/
HANDLE ezusb_open(const char* path);
HANDLE ezusb_open(const char *path);
/**
* Get identifier information of the device.
*
*
* @param handle Valid device handle.
* @param ident Pointer to memory to write the identifier information to.
* @return True if successful and identifier information was written to the
* the struct, false on error.
*/
bool ezusb_get_ident(HANDLE handle, struct ezusb_ident* ident);
bool ezusb_get_ident(HANDLE handle, struct ezusb_ident *ident);
/**
* Download a firmware to the ezusb device.
*
*
* @param handle Valid device handle.
* @param fw Firmware to write to the target ezusb device.
* @return True on success, false on failure.
*/
bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware* fw);
bool ezusb_download_firmware(HANDLE handle, struct ezusb_firmware *fw);
/**
* Close an opened ezusb device handle.
*
*
* @param handle Valid handle to close.
*/
void ezusb_close(HANDLE handle);
+411 -532
View File
File diff suppressed because it is too large Load Diff
+8 -9
View File
@@ -1,9 +1,9 @@
#ifndef EZUSB_EZUSBSYS2_H
#define EZUSB_EZUSBSYS2_H
#include <windows.h>
#include <setupapi.h>
#include <usb100.h>
#include <windows.h>
#include "ezusbsys.h"
@@ -11,29 +11,28 @@
so we have to redefine these macros here */
#ifndef CTL_CODE
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
#define CTL_CODE(DeviceType, Function, Method, Access) \
(((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
#endif
#ifndef FILE_DEVICE_UNKNOWN
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_UNKNOWN 0x00000022
#endif
#ifndef METHOD_BUFFERED
#define METHOD_BUFFERED 0
#define METHOD_BUFFERED 0
#endif
#ifndef METHOD_IN_DIRECT
#define METHOD_IN_DIRECT 1
#define METHOD_IN_DIRECT 1
#endif
#ifndef METHOD_OUT_DIRECT
#define METHOD_OUT_DIRECT 2
#define METHOD_OUT_DIRECT 2
#endif
#ifndef FILE_ANY_ACCESS
#define FILE_ANY_ACCESS 0
#define FILE_ANY_ACCESS 0
#endif
#endif
+32 -29
View File
@@ -3,16 +3,16 @@
#include "ezusb/util.h"
#include "util/log.h"
#include "util/crc.h"
#include "util/fs.h"
#include "util/log.h"
#include "util/mem.h"
struct ezusb_firmware* ezusb_firmware_load(const char* file)
struct ezusb_firmware *ezusb_firmware_load(const char *file)
{
void* buffer;
void *buffer;
size_t buffer_size;
struct ezusb_firmware* fw;
struct ezusb_firmware *fw;
size_t pos;
log_assert(file);
@@ -25,19 +25,19 @@ struct ezusb_firmware* ezusb_firmware_load(const char* file)
fw = xmalloc(sizeof(struct ezusb_firmware));
fw->crc = ((struct ezusb_firmware*) buffer)->crc;
fw->segment_count = ((struct ezusb_firmware*) buffer)->segment_count;
fw->crc = ((struct ezusb_firmware *) buffer)->crc;
fw->segment_count = ((struct ezusb_firmware *) buffer)->segment_count;
pos += sizeof(uint16_t) * 2;
fw->segments = xmalloc(
sizeof(struct ezusb_firmware_segment) * fw->segment_count);
fw->segments =
xmalloc(sizeof(struct ezusb_firmware_segment) * fw->segment_count);
for (uint16_t i = 0; i < fw->segment_count; i++) {
uint16_t size = *((uint16_t*) (buffer + pos));
uint16_t size = *((uint16_t *) (buffer + pos));
pos += sizeof(uint16_t);
uint16_t offset = *((uint16_t*) (buffer + pos));
uint16_t offset = *((uint16_t *) (buffer + pos));
pos += sizeof(uint16_t);
fw->segments[i] = xmalloc(sizeof(uint16_t) * 2 + size);
@@ -51,10 +51,10 @@ struct ezusb_firmware* ezusb_firmware_load(const char* file)
return fw;
}
bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw)
bool ezusb_firmware_save(const char *file, struct ezusb_firmware *fw)
{
size_t size;
void* buffer;
void *buffer;
size_t pos;
bool res;
@@ -72,13 +72,15 @@ bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw)
buffer = xmalloc(size);
((struct ezusb_firmware*) buffer)->crc = fw->crc;
((struct ezusb_firmware*) buffer)->segment_count = fw->segment_count;
((struct ezusb_firmware *) buffer)->crc = fw->crc;
((struct ezusb_firmware *) buffer)->segment_count = fw->segment_count;
pos += sizeof(uint16_t) * 2;
for (uint16_t i = 0; i < fw->segment_count; i++) {
memcpy(buffer + pos, fw->segments[i],
memcpy(
buffer + pos,
fw->segments[i],
sizeof(uint16_t) * 2 + fw->segments[i]->size);
pos += sizeof(uint16_t) * 2 + fw->segments[i]->size;
}
@@ -89,9 +91,9 @@ bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw)
return res;
}
struct ezusb_firmware* ezusb_firmware_alloc()
struct ezusb_firmware *ezusb_firmware_alloc()
{
struct ezusb_firmware* fw;
struct ezusb_firmware *fw;
fw = xmalloc(sizeof(struct ezusb_firmware));
@@ -102,10 +104,10 @@ struct ezusb_firmware* ezusb_firmware_alloc()
return fw;
}
struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset,
uint16_t size, void* data)
struct ezusb_firmware_segment *
ezusb_firmware_segment_alloc(uint16_t offset, uint16_t size, void *data)
{
struct ezusb_firmware_segment* seg;
struct ezusb_firmware_segment *seg;
log_assert(size > 0);
log_assert(data);
@@ -119,18 +121,19 @@ struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset,
return seg;
}
void ezusb_firmware_add_segment(struct ezusb_firmware* fw,
struct ezusb_firmware_segment* segment)
void ezusb_firmware_add_segment(
struct ezusb_firmware *fw, struct ezusb_firmware_segment *segment)
{
struct ezusb_firmware_segment** tmp;
struct ezusb_firmware_segment **tmp;
log_assert(fw);
log_assert(segment);
fw->segment_count++;
tmp = xrealloc(fw->segments,
sizeof(struct ezusb_firmware_segment*) * fw->segment_count);
tmp = xrealloc(
fw->segments,
sizeof(struct ezusb_firmware_segment *) * fw->segment_count);
if (tmp != NULL) {
fw->segments = tmp;
@@ -139,7 +142,7 @@ void ezusb_firmware_add_segment(struct ezusb_firmware* fw,
fw->segments[fw->segment_count - 1] = segment;
}
uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw)
uint16_t ezusb_firmware_crc(struct ezusb_firmware *fw)
{
uint16_t crc;
@@ -148,14 +151,14 @@ uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw)
crc = 0;
for (uint16_t i = 0; i < fw->segment_count; i++) {
crc = crc16(fw->segments[i],
sizeof(uint16_t) * 2 + fw->segments[i]->size, crc);
crc = crc16(
fw->segments[i], sizeof(uint16_t) * 2 + fw->segments[i]->size, crc);
}
return crc;
}
void ezusb_firmware_free(struct ezusb_firmware* fw)
void ezusb_firmware_free(struct ezusb_firmware *fw)
{
log_assert(fw);
+22 -22
View File
@@ -1,7 +1,7 @@
/**
* Utility module for ezusb1 (legacy) and ezusb2 (FX2) device handling.
*
* @author icex2
*
* @author icex2
*/
#ifndef EZUSB_UTIL_H
#define EZUSB_UTIL_H
@@ -33,69 +33,69 @@ struct ezusb_firmware_segment {
struct ezusb_firmware {
uint16_t crc;
uint16_t segment_count;
struct ezusb_firmware_segment** segments;
struct ezusb_firmware_segment **segments;
};
/**
* Load a firmware binary file into memory.
*
*
* @oaram file Path to firmware binary file.
* @return Valid firmware structure on success, NULL on failure.
*/
struct ezusb_firmware* ezusb_firmware_load(const char* file);
struct ezusb_firmware *ezusb_firmware_load(const char *file);
/**
* Save the in-memory firmware to a file.
*
*
* @param file Target file to save to.
* @param fw Valid firmware structure to store to disk.
* @return True on success, false on error.
*/
bool ezusb_firmware_save(const char* file, struct ezusb_firmware* fw);
bool ezusb_firmware_save(const char *file, struct ezusb_firmware *fw);
/**
* Allocate and initialize a new (empty = no segments) ezusb firmware structure.
*
*
* @return Allocated and initialized structure.
*/
struct ezusb_firmware* ezusb_firmware_alloc();
struct ezusb_firmware *ezusb_firmware_alloc();
/**
* Allocate and initialize a new firmware segment.
*
*
* @param offset Offset of the segment.
* @param size Size of the segment
* @param data Pointer to a buffer with firmware data of at least the
* @param data Pointer to a buffer with firmware data of at least the
* specified size.
* @return Allocated and initialized structure.
*/
struct ezusb_firmware_segment* ezusb_firmware_segment_alloc(uint16_t offset,
uint16_t size, void* data);
struct ezusb_firmware_segment *
ezusb_firmware_segment_alloc(uint16_t offset, uint16_t size, void *data);
/**
* Add a segment to a firmware structure.
*
*
* @param fw Valid firmware structure to add the segment to.
* @param segment Valid segment to add to the end of the segment list of the
* firmware.
* firmware.
*/
void ezusb_firmware_add_segment(struct ezusb_firmware* fw,
struct ezusb_firmware_segment* segment);
void ezusb_firmware_add_segment(
struct ezusb_firmware *fw, struct ezusb_firmware_segment *segment);
/**
* Calculate the checksum of the provided firmware.
*
*
* @param fw Firmware to checksum.
* @return CRC16 of firmware.
*/
uint16_t ezusb_firmware_crc(struct ezusb_firmware* fw);
uint16_t ezusb_firmware_crc(struct ezusb_firmware *fw);
/**
* Free a previously allocated firmware structure (also cleans up all
* Free a previously allocated firmware structure (also cleans up all
* referenced segments).
*
*
* @param fw Firmware struct to free.
*/
void ezusb_firmware_free(struct ezusb_firmware* fw);
void ezusb_firmware_free(struct ezusb_firmware *fw);
#endif