/* tests/test_enums.cpp -- enumerations Copyright (c) 2016 Wenzel Jakob All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ #include "pybind11_tests.h" TEST_SUBMODULE(enums, m) { // test_unscoped_enum enum UnscopedEnum { EOne = 1, ETwo, EThree }; py::enum_(m, "UnscopedEnum", py::arithmetic(), "An unscoped enumeration") .value("EOne", EOne, "Docstring for EOne") .value("ETwo", ETwo, "Docstring for ETwo") .value("EThree", EThree, "Docstring for EThree") .export_values(); // test_scoped_enum enum class ScopedEnum { Two = 2, Three }; py::enum_(m, "ScopedEnum", py::arithmetic()) .value("Two", ScopedEnum::Two) .value("Three", ScopedEnum::Three); m.def("test_scoped_enum", [](ScopedEnum z) { return "ScopedEnum::" + std::string(z == ScopedEnum::Two ? "Two" : "Three"); }); // test_binary_operators enum Flags { Read = 4, Write = 2, Execute = 1 }; py::enum_(m, "Flags", py::arithmetic()) .value("Read", Flags::Read) .value("Write", Flags::Write) .value("Execute", Flags::Execute) .export_values(); // test_implicit_conversion class ClassWithUnscopedEnum { public: enum EMode { EFirstMode = 1, ESecondMode }; static EMode test_function(EMode mode) { return mode; } }; py::class_ exenum_class(m, "ClassWithUnscopedEnum"); exenum_class.def_static("test_function", &ClassWithUnscopedEnum::test_function); py::enum_(exenum_class, "EMode") .value("EFirstMode", ClassWithUnscopedEnum::EFirstMode) .value("ESecondMode", ClassWithUnscopedEnum::ESecondMode) .export_values(); // test_enum_to_int m.def("test_enum_to_int", [](int) {}); m.def("test_enum_to_uint", [](uint32_t) {}); m.def("test_enum_to_long_long", [](long long) {}); // test_duplicate_enum_name enum SimpleEnum { ONE, TWO, THREE }; m.def("register_bad_enum", [m]() { py::enum_(m, "SimpleEnum") .value("ONE", SimpleEnum::ONE) // NOTE: all value function calls are called with the // same first parameter value .value("ONE", SimpleEnum::TWO) .value("ONE", SimpleEnum::THREE) .export_values(); }); // test_enum_scalar enum UnscopedUCharEnum : unsigned char {}; enum class ScopedShortEnum : short {}; enum class ScopedLongEnum : long {}; enum UnscopedUInt64Enum : std::uint64_t {}; static_assert( py::detail::all_of< std::is_same::Scalar, unsigned char>, std::is_same::Scalar, short>, std::is_same::Scalar, long>, std::is_same::Scalar, std::uint64_t>>::value, "Error during the deduction of enum's scalar type with normal integer underlying"); // test_enum_scalar_with_char_underlying enum class ScopedCharEnum : char { Zero, Positive }; enum class ScopedWCharEnum : wchar_t { Zero, Positive }; enum class ScopedChar32Enum : char32_t { Zero, Positive }; enum class ScopedChar16Enum : char16_t { Zero, Positive }; // test the scalar of char type enums according to chapter 'Character types' // from https://en.cppreference.com/w/cpp/language/types static_assert( py::detail::any_of< std::is_same::Scalar, signed char>, // e.g. gcc on x86 std::is_same::Scalar, unsigned char> // e.g. arm linux >::value, "char should be cast to either signed char or unsigned char"); static_assert(sizeof(py::enum_::Scalar) == 2 || sizeof(py::enum_::Scalar) == 4, "wchar_t should be either 16 bits (Windows) or 32 (everywhere else)"); static_assert( py::detail::all_of< std::is_same::Scalar, std::uint_least32_t>, std::is_same::Scalar, std::uint_least16_t>>::value, "char32_t, char16_t (and char8_t)'s size, signedness, and alignment is determined"); #if defined(PYBIND11_HAS_U8STRING) enum class ScopedChar8Enum : char8_t { Zero, Positive }; static_assert(std::is_same::Scalar, unsigned char>::value); #endif // test_char_underlying_enum py::enum_(m, "ScopedCharEnum") .value("Zero", ScopedCharEnum::Zero) .value("Positive", ScopedCharEnum::Positive); py::enum_(m, "ScopedWCharEnum") .value("Zero", ScopedWCharEnum::Zero) .value("Positive", ScopedWCharEnum::Positive); py::enum_(m, "ScopedChar32Enum") .value("Zero", ScopedChar32Enum::Zero) .value("Positive", ScopedChar32Enum::Positive); py::enum_(m, "ScopedChar16Enum") .value("Zero", ScopedChar16Enum::Zero) .value("Positive", ScopedChar16Enum::Positive); // test_bool_underlying_enum enum class ScopedBoolEnum : bool { FALSE, TRUE }; // bool is unsigned (std::is_signed returns false) and 1-byte long, so represented with u8 static_assert(std::is_same::Scalar, std::uint8_t>::value, ""); py::enum_(m, "ScopedBoolEnum") .value("FALSE", ScopedBoolEnum::FALSE) .value("TRUE", ScopedBoolEnum::TRUE); } d='n65' href='#n65'>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
/*
             LUFA Library
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

/*
  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)

  Permission to use, copy, modify, distribute, and sell this
  software and its documentation for any purpose is hereby granted
  without fee, provided that the above copyright notice appear in
  all copies and that both that the copyright notice and this
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
  software without specific, written prior permission.

  The author disclaims all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *
 *  Header file for SCSI.c.
 */

#ifndef _SCSI_H_
#define _SCSI_H_

	/* Includes: */
		#include <avr/io.h>
		#include <avr/pgmspace.h>

		#include <LUFA/Drivers/USB/USB.h>

		#include "../TempDataLogger.h"
		#include "../Descriptors.h"
		#include "DataflashManager.h"
		#include "Config/AppConfig.h"

	/* Macros: */
		/** Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This
		 *  is for convenience, as it allows for all three sense values (returned upon request to the host to give information about
		 *  the last command failure) in a quick and easy manner.
		 *
		 *  \param[in] Key    New SCSI sense key to set the sense code to
		 *  \param[in] Acode  New SCSI additional sense key to set the additional sense code to
		 *  \param[in] Aqual  New SCSI additional sense key qualifier to set the additional sense qualifier code to
		 */
		#define SCSI_SET_SENSE(Key, Acode, Aqual)  do { SenseData.SenseKey                 = (Key);   \
		                                                SenseData.AdditionalSenseCode      = (Acode); \
		                                                SenseData.AdditionalSenseQualifier = (Aqual); } while (0)

		/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be read from the storage medium. */
		#define DATA_READ           true

		/** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be written to the storage medium. */
		#define DATA_WRITE          false

		/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a Block Media device. */
		#define DEVICE_TYPE_BLOCK   0x00

		/** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a CD-ROM device. */
		#define DEVICE_TYPE_CDROM   0x05

	/* Function Prototypes: */
		bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);

		#if defined(INCLUDE_FROM_SCSI_C)
			static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
			static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
			static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
			static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
			static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
			                                      const bool IsDataRead);
			static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo);
		#endif

#endif