Skip to content

Commit 3869193

Browse files
committed
Wrap macros in do-while construct as needed
1 parent 0a1ca37 commit 3869193

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/ce/include/sys/lcd.h

+22-9
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ extern "C" {
7575

7676
/** Sets up the hardware cursor. */
7777
#define lcd_CrsrSetup() \
78+
do { \
7879
lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_WIDTH - 1) << 16; \
7980
lcd_CrsrConfig = 0; \
8081
lcd_CrsrPalette0 = 0x00000000; \
8182
lcd_CrsrPalette1 = 0x00FFFFFF; \
8283
lcd_CrsrXY = 0; \
83-
lcd_CrsrClip = 0;
84+
lcd_CrsrClip = 0; \
85+
} while (0)
8486

8587
/**
8688
* Hardware cursor sizes.
@@ -97,16 +99,17 @@ typedef enum {
9799
* @see lcd_cursor_size_t
98100
*/
99101
#define lcd_CrsrSetSize(size) \
100-
(lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1))
102+
do { \
103+
lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1); \
104+
} while (0)
101105

102106
/**
103107
* Gets cursor size.
104108
*
105109
* @returns The cursor size.
106110
* @see lcd_cursor_size_t
107111
*/
108-
#define lcd_CrsrGetSize() \
109-
((lcd_cursor_size_t)(lcd_CrsrConfig & 1))
112+
#define lcd_CrsrGetSize() ((lcd_cursor_size_t)(lcd_CrsrConfig & 1))
110113

111114
/**
112115
* Sets cursor image.
@@ -120,7 +123,9 @@ typedef enum {
120123
* to your image(s).
121124
*/
122125
#define lcd_CrsrSetImage(data) \
123-
(memcpy(lcd_CrsrImage, data, lcd_CrsrGetSize() == LCD_CURSOR_SIZE_LARGE ? lcd_CrsrImageLen64 : lcd_CrsrImageLen32))
126+
do { \
127+
memcpy(lcd_CrsrImage, data, lcd_CrsrGetSize() == LCD_CURSOR_SIZE_LARGE ? lcd_CrsrImageLen64 : lcd_CrsrImageLen32); \
128+
} while (0)
124129

125130
/**
126131
* Sets the position of the cursor on screen.
@@ -129,20 +134,28 @@ typedef enum {
129134
* @param[in] y Y coordinate.
130135
*/
131136
#define lcd_CrsrSetPosition(x, y) \
137+
do { \
132138
lcd_CrsrX = x; \
133-
lcd_CrsrY = y;
139+
lcd_CrsrY = y; \
140+
} while (0)
134141

135142
/** Shows the cursor. */
136143
#define lcd_CrsrShow() \
137-
lcd_CrsrCtrl = 1;
144+
do { \
145+
lcd_CrsrCtrl = 1; \
146+
} while (0)
138147

139148
/** Hides the cursor. */
140149
#define lcd_CrsrHide() \
141-
lcd_CrsrCtrl = 0;
150+
do { \
151+
lcd_CrsrCtrl = 0; \
152+
} while (0)
142153

143154
#define lcd_CrsrCleanup() \
155+
do { \
144156
lcd_CrsrHide(); \
145-
lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_HEIGHT - 1) << 16;
157+
lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_HEIGHT - 1) << 16; \
158+
} while (0)
146159

147160
#ifdef __cplusplus
148161
}

0 commit comments

Comments
 (0)