2020-05-05 16:22:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 DarkMatterCore
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __USB_H__
|
|
|
|
#define __USB_H__
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
2020-05-06 15:04:10 +01:00
|
|
|
#define USB_TRANSFER_BUFFER_SIZE 0x800000 /* 8 MiB */
|
2020-05-05 16:22:16 +01:00
|
|
|
|
2020-05-06 15:04:10 +01:00
|
|
|
/// Initializes the USB interface, input and output endpoints and allocates an internal transfer buffer.
|
2020-05-05 16:22:16 +01:00
|
|
|
bool usbInitialize(void);
|
|
|
|
|
|
|
|
/// Closes the USB interface, input and output endpoints and frees the transfer buffer.
|
|
|
|
void usbExit(void);
|
|
|
|
|
2020-05-07 12:08:54 +01:00
|
|
|
/// Returns a pointer to a heap-allocated, page-aligned memory buffer that's suitable for USB transfers.
|
|
|
|
void *usbAllocatePageAlignedBuffer(size_t size);
|
2020-05-05 16:22:16 +01:00
|
|
|
|
2020-05-13 15:09:51 +01:00
|
|
|
/// Used to check if the console has been connected to an USB host device and if a valid USB session has been established.
|
|
|
|
/// Bear in mind this call will block the calling thread if the console is connected to an USB host device but no USB session has been established.
|
|
|
|
/// If the console is disconnected during this block, the function will return false.
|
|
|
|
bool usbIsReady(void);
|
2020-05-05 16:22:16 +01:00
|
|
|
|
2020-05-13 15:09:51 +01:00
|
|
|
/// Sends file properties to the host device before starting a file data transfer. Must be called before usbSendFileData().
|
2020-05-05 16:22:16 +01:00
|
|
|
bool usbSendFileProperties(u64 file_size, const char *filename);
|
|
|
|
|
2020-05-07 12:08:54 +01:00
|
|
|
/// Performs a file data transfer. Must be continuously called after usbSendFileProperties() until all file data has been transferred.
|
2020-05-05 16:22:16 +01:00
|
|
|
/// Data chunk size must not exceed USB_TRANSFER_BUFFER_SIZE.
|
2020-05-07 12:08:54 +01:00
|
|
|
bool usbSendFileData(void *data, u64 data_size);
|
2020-05-05 16:22:16 +01:00
|
|
|
|
|
|
|
#endif /* __USB_H__ */
|