Add ATTR_* macros in the newly created attributes.h and use them wherever possible for improved readability.

This commit is contained in:
László Monda
2017-10-04 22:26:48 +02:00
parent f348aec97a
commit 4295793fb9
12 changed files with 40 additions and 23 deletions

View File

@@ -1,10 +1,11 @@
#include "config_globals.h" #include "config_globals.h"
#include "attributes.h"
static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE]; static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE];
config_buffer_t HardwareConfigBuffer = {hardwareConfig}; config_buffer_t HardwareConfigBuffer = {hardwareConfig};
static uint8_t userConfig1[USER_CONFIG_SIZE]; static uint8_t userConfig1[USER_CONFIG_SIZE];
static uint8_t __attribute__((section (".m_data_2"))) userConfig2[USER_CONFIG_SIZE]; static uint8_t ATTR_DATA2 userConfig2[USER_CONFIG_SIZE];
config_buffer_t ValidatedUserConfigBuffer = { userConfig1 }; config_buffer_t ValidatedUserConfigBuffer = { userConfig1 };
config_buffer_t StagingUserConfigBuffer = { userConfig2 }; config_buffer_t StagingUserConfigBuffer = { userConfig2 };

View File

@@ -4,6 +4,7 @@
// Includes: // Includes:
#include <stdint.h> #include <stdint.h>
#include "attributes.h"
#include "lufa/HIDClassCommon.h" #include "lufa/HIDClassCommon.h"
#include "usb_composite_device.h" #include "usb_composite_device.h"
#include "main.h" #include "main.h"
@@ -69,24 +70,24 @@
uint8_t longPressAction; uint8_t longPressAction;
uint8_t modifiers; uint8_t modifiers;
uint16_t scancode; uint16_t scancode;
} __attribute__ ((packed)) keystroke; } ATTR_PACKED keystroke;
struct { struct {
mouse_button_t buttonActions; mouse_button_t buttonActions;
mouse_scroll_t scrollActions; mouse_scroll_t scrollActions;
mouse_move_action_t moveActions; mouse_move_action_t moveActions;
} __attribute__ ((packed)) mouse; } ATTR_PACKED mouse;
struct { struct {
bool isToggle; bool isToggle;
uint8_t layer; uint8_t layer;
} __attribute__ ((packed)) switchLayer; } ATTR_PACKED switchLayer;
struct { struct {
uint8_t keymapId; uint8_t keymapId;
} __attribute__ ((packed)) switchKeymap; } ATTR_PACKED switchKeymap;
struct { struct {
uint8_t macroId; uint8_t macroId;
} __attribute__ ((packed)) playMacro; } ATTR_PACKED playMacro;
}; };
} __attribute__ ((packed)) key_action_t; } ATTR_PACKED key_action_t;
// Variables: // Variables:

View File

@@ -41,29 +41,29 @@
keystroke_type_t type; keystroke_type_t type;
uint8_t scancode; uint8_t scancode;
uint8_t modifierMask; uint8_t modifierMask;
} __attribute__ ((packed)) key; } ATTR_PACKED key;
struct { struct {
macro_sub_action_t action; macro_sub_action_t action;
uint8_t mouseButtonsMask; uint8_t mouseButtonsMask;
} __attribute__ ((packed)) mouseButton; } ATTR_PACKED mouseButton;
struct { struct {
int16_t x; int16_t x;
int16_t y; int16_t y;
} __attribute__ ((packed)) moveMouse; } ATTR_PACKED moveMouse;
struct { struct {
int16_t x; int16_t x;
int16_t y; int16_t y;
} __attribute__ ((packed)) scrollMouse; } ATTR_PACKED scrollMouse;
struct { struct {
int16_t delay; int16_t delay;
} __attribute__ ((packed)) delay; } ATTR_PACKED delay;
struct { struct {
const char *text; const char *text;
uint16_t textLen; uint16_t textLen;
} __attribute__ ((packed)) text; } ATTR_PACKED text;
}; };
macro_action_type_t type; macro_action_type_t type;
} __attribute__ ((packed)) macro_action_t; } ATTR_PACKED macro_action_t;
// Variables: // Variables:

View File

@@ -4,6 +4,7 @@
// Includes: // Includes:
#include "fsl_common.h" #include "fsl_common.h"
#include "attributes.h"
#include "usb_api.h" #include "usb_api.h"
#include "usb_descriptors/usb_descriptor_basic_keyboard_report.h" #include "usb_descriptors/usb_descriptor_basic_keyboard_report.h"
@@ -26,7 +27,7 @@
uint8_t modifiers; uint8_t modifiers;
uint8_t reserved; // Always must be 0 uint8_t reserved; // Always must be 0
uint8_t scancodes[USB_BASIC_KEYBOARD_MAX_KEYS]; uint8_t scancodes[USB_BASIC_KEYBOARD_MAX_KEYS];
} __attribute__ ((packed)) usb_basic_keyboard_report_t; } ATTR_PACKED usb_basic_keyboard_report_t;
// Variables: // Variables:

View File

@@ -24,7 +24,7 @@
typedef struct { typedef struct {
uint16_t scancodes[USB_MEDIA_KEYBOARD_MAX_KEYS]; uint16_t scancodes[USB_MEDIA_KEYBOARD_MAX_KEYS];
} __attribute__ ((packed)) usb_media_keyboard_report_t; } ATTR_PACKED usb_media_keyboard_report_t;
// Variables: // Variables:

View File

@@ -27,7 +27,7 @@
int16_t y; int16_t y;
int8_t wheelX; int8_t wheelX;
int8_t wheelY; int8_t wheelY;
} __attribute__ ((packed)) usb_mouse_report_t; } ATTR_PACKED usb_mouse_report_t;
// Variables: // Variables:

View File

@@ -4,6 +4,7 @@
// Includes: // Includes:
#include "fsl_common.h" #include "fsl_common.h"
#include "attributes.h"
#include "usb_api.h" #include "usb_api.h"
#include "usb_descriptors/usb_descriptor_system_keyboard_report.h" #include "usb_descriptors/usb_descriptor_system_keyboard_report.h"
@@ -24,7 +25,7 @@
typedef struct { typedef struct {
uint8_t scancodes[USB_SYSTEM_KEYBOARD_MAX_KEYS]; uint8_t scancodes[USB_SYSTEM_KEYBOARD_MAX_KEYS];
} __attribute__ ((packed)) usb_system_keyboard_report_t; } ATTR_PACKED usb_system_keyboard_report_t;
// Variables: // Variables:

View File

@@ -1,3 +1,3 @@
#include "wormhole.h" #include "wormhole.h"
wormhole_t Wormhole NO_INIT_GCC; wormhole_t ATTR_NO_INIT Wormhole;

View File

@@ -4,11 +4,11 @@
// Includes: // Includes:
#include <stdint.h> #include <stdint.h>
#include "attributes.h"
// Macros: // Macros:
#define WORMHOLE_MAGIC_NUMBER 0x3b04cd9e94521f9a #define WORMHOLE_MAGIC_NUMBER 0x3b04cd9e94521f9a
#define NO_INIT_GCC __attribute__ ((section (".noinit")))
// Typedefs: // Typedefs:
@@ -26,6 +26,6 @@
// Variables: // Variables:
extern wormhole_t Wormhole NO_INIT_GCC; extern wormhole_t ATTR_NO_INIT Wormhole;
#endif #endif

11
shared/attributes.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef __ATTRIBUTES_H__
#define __ATTRIBUTES_H__
// Macros:
#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_NO_INIT __attribute__ ((section (".noinit")))
#define ATTR_DATA2 __attribute__((section (".m_data_2")))
#define ATTR_BOOTLOADER_CONFIG __attribute__((used, section(".BootloaderConfig")))
#endif

View File

@@ -5,6 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "attributes.h"
#include "i2c_addresses.h" #include "i2c_addresses.h"
// Macros: // Macros:
@@ -14,7 +15,7 @@
#define CLOCK_FLAG_HIGH_SPEED_MODE 0x01 #define CLOCK_FLAG_HIGH_SPEED_MODE 0x01
#define DEFINE_BOOTLOADER_CONFIG_AREA(address) \ #define DEFINE_BOOTLOADER_CONFIG_AREA(address) \
__attribute__((used, section(".BootloaderConfig"))) const bootloader_config_t BootloaderConfig = { \ const ATTR_BOOTLOADER_CONFIG bootloader_config_t BootloaderConfig = { \
.tag = BOOTLOADER_TAG, \ .tag = BOOTLOADER_TAG, \
.enabledPeripherals = EnabledBootloaderPeripherial_I2c, \ .enabledPeripherals = EnabledBootloaderPeripherial_I2c, \
.i2cSlaveAddress = address, \ .i2cSlaveAddress = address, \

View File

@@ -4,6 +4,7 @@
// Includes: // Includes:
#include "fsl_common.h" #include "fsl_common.h"
#include "attributes.h"
// Macros: // Macros:
@@ -38,7 +39,7 @@
uint8_t length; uint8_t length;
uint16_t crc; uint16_t crc;
uint8_t data[I2C_MESSAGE_MAX_PAYLOAD_LENGTH]; uint8_t data[I2C_MESSAGE_MAX_PAYLOAD_LENGTH];
} __attribute__ ((packed)) i2c_message_t; } ATTR_PACKED i2c_message_t;
// Variables: // Variables: