void super_serious_function(const int & input_value) {
// input_value++; // can't be changed
// [...] big magic happens here [...]
std::cout << input_value;
// [...] more unicorn code [...]
}
prevents modifying read only variablesconst std::array values = {1,2,3,4,5,6,7,8,9,10,12,13,14,15};
int main() {
std::cout << values[4];
return 0;
}
Optimizer removes 60 bytes! (15 x 4 Bytes)struct first {
constexpr static int device_ram_size = 1; };
struct middle {
constexpr static int device_ram_size = 21; };
struct last {
constexpr static int device_ram_size = 42; };
int main() {
using this_config = last;
std::cout << this_config::device_ram_size ;
return 0;
};
GODBOLT
struct first {
using connection = GW_t; };
struct last {
using connection = IP_t<192,168,0,8>; };
GODBOLT
SET( Environment_configs "first" "last" "middle")
# for each device/config-version create own target
foreach( current_Environment ${Environment_configs} )
# create this specific target
add_executable(Example_${current_Environment}.elf
main.cpp)
# every target gets own definevalue
target_compile_definitions(Example_${current_Environment}.elf
PUBLIC CONFIG_DEFINE=${current_Environment})
endforeach()
0x09, /* bLength: Configuation Descriptor size */
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
USB_CDC_CONFIG_DESC_SIZ,
0x00,
0x02, /* bNumInterfaces: 2 interfaces */
0x01, /* bConfigurationValue: */
0x04, /* iConfiguration: */
0xC0, /* bmAttributes: */
0x32, /* MaxPower 100 mA */
/*Interface Descriptor */
0x09, /* bLength: Interface Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
/* Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x00, /* bDescriptorSubtype: Header Func Desc */
0x10, /* bcdCDC: spec release number */
0x01,
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubtype: Call Management Func Desc */
0x00, /* bmCapabilities: D0+D1 */
0x01, /* bDataInterface: 1 */
/*ACM Functional Descriptor*/
0x04, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubtype: Union func desc */
0x00, /* bMasterInterface: Communication class interface */
0x01, /* bSlaveInterface0: Data Class Interface */
/*Endpoint 2 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */
CDC_CMD_EP, /* bEndpointAddress */
0x03, /* bmAttributes: Interrupt */
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_CMD_PACKET_SIZE),
0xFF, /* bInterval: */
/*---------------------------------------------------------------------------*/
/*Data class interface descriptor*/
0x09, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
0x01, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints: Two endpoints used */
0x0A, /* bInterfaceClass: CDC */
0x00, /* bInterfaceSubClass: */
0x00, /* bInterfaceProtocol: */
0x00, /* iInterface: */
/*Endpoint OUT Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
CDC_OUT_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00, /* bInterval: ignore for Bulk transfer */
/*Endpoint IN Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
CDC_IN_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00 /* bInterval */
};
namespace hw {
struct stm32f723k_hs {
static constexpr uint8_t usb_high = 02;
static constexpr uint8_t usb_low = 01;
static constexpr uint8_t maxpacketsize = 64;
};
}
source
enum descriptor_type_t : uint8_t {
null = 0x00,
device = 0x01,
configuration = 0x02,
string = 0x03,
interface = 0x04,
endpoint = 0x05
};
source
template<typename HW_t, int _Vendor_t = 0x4242, int _Product_t = 0x4242>
struct device_desc_t {
uint8_t size = sizeof(*this);
descriptor_type_t descriptor_type = device;
uint8_t usb_high = HW_t::usb_high;
uint8_t usb_low = HW_t::usb_low;
class_t uclass = class_t::class_by_interface;
subclass_t subclass = subclass_t::subclass_by_interface;
protocol_t protocol = protocol_t::bla;
uint8_t maxpacketsize = HW_t::maxpacketsize;
source
cat test.json
{
"meetingembedded" : 2019
}
xxd -i test.json | \
> sed 's/unsigned char/constexpr uint8_t/' |\
> sed 's/unsigned int/constexpr size_t/'
constexpr uint8_t test_json[] = {
0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x6d, 0x65, 0x65, 0x74,
0x69, 0x6e, 0x67, 0x65, 0x6d, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x22,
0x20, 0x3a, 0x20, 0x32, 0x30, 0x31, 0x39, 0x0d, 0x0a, 0x7d
};
constexpr size_t test_json_len = 34;